Files
snakePlus/include/game_bg.h
T
phillipandAntigravity 496de1a31f fix: decouple VBlank ISR and main loop to prevent IRQ stack overflow
- Make handle_vblank strictly increment frame counter (frame++)
- Move heavy frame logic (background updates, OAM updates, palette animations, and console stats) to update_frame() on the main thread synchronized with swiWaitForVBlank()
- Eliminate 256-byte ARM9 IRQ stack (sp_irq) overflow caused by bg_update and iprintf that was corrupting DTCM stack and causing data aborts
- Preserve all playfield entities on game over with top-screen defeat summary and smooth background deceleration

Co-authored-by: Antigravity <antigravity@google.com>
2026-10-04 00:21:09 +02:00

36 lines
1.1 KiB
C

#ifndef GAME_BG_H
#define GAME_BG_H
#include <nds.h>
#include "game_state.h"
struct BackgroundContext {
int bg_main_id = -1;
int bg_sub_id = -1;
// Fixed-point (8.8) scroll accumulators for smooth 60fps drift
uint16_t scroll_main_x_fp = 0;
uint16_t scroll_main_y_fp = 0;
uint16_t scroll_sub_x_fp = 0;
uint16_t scroll_sub_y_fp = 0;
// Animation frame counter & timers
uint8_t anim_phase = 0;
uint16_t anim_phase_fp = 0; // Fixed-point (8.8) phase accumulator
uint8_t pulse_timer = 0; // Triggered when an apple is eaten
// Cached state to optimize updates
bool hard_mode = false;
bool is_cursed = false;
bool game_over = false;
uint8_t game_over_fade = 0;
Scene scene = Scene::Menu;
};
void bg_setup(BackgroundContext &bg_ctx, int top_console_bg_id, int bottom_console_bg_id);
void bg_update(BackgroundContext &bg_ctx, const GameState &state, uint8_t frame);
void bg_trigger_pulse(BackgroundContext &bg_ctx);
void bg_set_scene(BackgroundContext &bg_ctx, Scene scene, bool hard_mode);
#endif // GAME_BG_H