The Background:
There is an entity spawning system, so enemies that haven't been seen yet (or have strayed too far off screen) don't take up any RAM or CPU. When they get spawned into existence, some of them use GetVsyncCounter() in order to know the global time so things like sprite animations can remain in sync with the sprite animation of an entity right next to it that may have been spawned into existence at a slightly different time. More importantly, the major rotation of the firebars is tied to this counter value, so if you walk offscreen and the firebar despawns, when you get near that section of the level again it spawns back in with the same "position on the clock" as if it had never been despawned at all.
The Problem:
Press START to bring up the pause menu while a firebar is onscreen, and then press START again to close the pause menu. It will immediately jump to a different clock position as if the game had never been paused. Because for it, and anything in the game that uses GetVsyncCounter() to keep track of world time, the world time didn't stop when the game was paused.
The Solution:
Code: Select all
// Begin to display pause menu
uint16_t backupVsyncCounter = GetVsyncCounter();
...
// (pause menu stuff)
...
// About to close pause menu
// Restore the backed up VsyncCounter so time doesn't advance for the entities while the game is paused
// (For this to compile, you need to add ".global vsync_counter" to the top of uzeboxVideoEngineCore.s)
extern uint16_t vsync_counter;
vsync_counter = backupVsyncCounter;
Code: Select all
;Public variables
.global sync_pulse
.global sync_phase
.global sync_flags
.global joypad1_status_lo
.global joypad2_status_lo
.global joypad1_status_hi
.global joypad2_status_hi
.global first_render_line
.global render_lines_count
.global vsync_counter