Commit a0ff76a
committed
core_run: skip game_ai_think when no override or debug is active
The HAVE_GAME_AI block in core_run called game_ai_think on every frame
regardless of whether any GameAI feature was actually requested. The
function itself always runs game_ai_lib_set_show_debug(ga, show_debug)
when an AI instance has been created (line 172 of ai/game_ai.c), which
is an indirect dispatch into the loaded GameAI library and runs even
when override_p1, override_p2, and show_debug are all false.
When the user has loaded a GameAI library but is not currently using
any of its overrides, this per-frame dispatch is wasted work.
Gate the call in core_run on at least one of the three settings being
active. When all are false:
- The function call is skipped (function-call overhead saved)
- The per-frame game_ai_lib_set_show_debug dispatch is skipped
(the meaningful win when an AI lib is loaded but unused)
- The internal g_frameCount counter doesn't tick, so when overrides
eventually flip on, the first think() may fire on the very next
frame rather than after the SKIPFRAMES delay. Harmless - the user
just enabled the feature; immediate AI input is the desired UX.
- The lazy 'ga' creation path inside game_ai_think (gated on
!ga && g_ram_ptr) is deferred until overrides actually turn on,
which is correct: no point creating an AI instance for a frame
that won't use it.
For builds without HAVE_GAME_AI, the entire block is removed by the
preprocessor and this change has no effect.
For builds with HAVE_GAME_AI but no GameAI library ever loaded, the
work skipped by the new gate is sub-microsecond per frame. For builds
with a GameAI library loaded but overrides currently off, the skip
avoids one per-frame indirect function-pointer dispatch into the
loaded shared library, which is a real per-frame win measured in
hundreds of cycles depending on the AI lib's implementation.1 parent 129a5ba commit a0ff76a
1 file changed
Lines changed: 21 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8267 | 8267 | | |
8268 | 8268 | | |
8269 | 8269 | | |
8270 | | - | |
8271 | | - | |
8272 | | - | |
8273 | | - | |
8274 | | - | |
8275 | | - | |
8276 | | - | |
8277 | | - | |
8278 | | - | |
8279 | | - | |
| 8270 | + | |
| 8271 | + | |
| 8272 | + | |
| 8273 | + | |
| 8274 | + | |
| 8275 | + | |
| 8276 | + | |
| 8277 | + | |
| 8278 | + | |
| 8279 | + | |
| 8280 | + | |
| 8281 | + | |
| 8282 | + | |
| 8283 | + | |
| 8284 | + | |
| 8285 | + | |
| 8286 | + | |
| 8287 | + | |
| 8288 | + | |
| 8289 | + | |
| 8290 | + | |
8280 | 8291 | | |
8281 | 8292 | | |
8282 | 8293 | | |
| |||
0 commit comments