From: Lukas Krickl Date: Fri, 28 Mar 2025 13:28:39 +0000 (+0100) Subject: game_state: game state updates now use the same state machine as actors X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=234e4507aa1c710dc8d28cd14922dca5f245a801;p=gbrg%2F.git game_state: game state updates now use the same state machine as actors --- diff --git a/src/defs.s b/src/defs.s index 6755a59..a8fc737 100644 --- a/src/defs.s +++ b/src/defs.s @@ -22,14 +22,6 @@ #define WINDOW_Y 120 #define WINDOW_X 1 - ; game modes - ; this is a direct index - ; into a pointer array - ; for update functions -.se 0 -.de GM_GAME, 1 -.de GM_PAUSE, 1 - ; game state cell struct ; this holds all the information ; a cell on the map has diff --git a/src/mem.s b/src/mem.s index 8136c5b..40037ad 100644 --- a/src/mem.s +++ b/src/mem.s @@ -14,13 +14,18 @@ mem_init: call memcpy ; set up game mode - ld a, GM_GAME - ld [game_mode], a + call game_init call mbc1_init ret +game_init: + ld de, st_update_game + ld hl, game_mode + ld bc, st_size + jp memcpy + ; copies memory from one location to another ; inputs: ; de: source diff --git a/src/state.s b/src/state.s index 8f103dc..2b3c136 100644 --- a/src/state.s +++ b/src/state.s @@ -85,3 +85,12 @@ st_cursor_draw: st_def 0x00, player_draw_cursor, st_cursor st_cursor_delay: st_def CURSOR_MOVE_TIMER, st_null_fn, st_cursor + +st_update_game: + st_def 0x00, update_game, st_update_game + +st_update_pause: + st_def 0x00, update_pause, st_update_pause + +st_update_game_over: + st_def 0x00, update_game_over, st_update_game_over diff --git a/src/update.s b/src/update.s index a8c505a..ce47edd 100644 --- a/src/update.s +++ b/src/update.s @@ -17,10 +17,12 @@ update_game: ; call player_update call sim_update + ldnull bc ret update_pause: call player_update + ldnull bc ret ; called after vblank @@ -29,8 +31,8 @@ update: inc a ld [frame_count], a - ld hl, update_table - ld a, [game_mode] - jp call_tbl + ld de, game_mode + jp st_update + diff --git a/src/wram.s b/src/wram.s index e93cfc5..db32aab 100644 --- a/src/wram.s +++ b/src/wram.s @@ -13,7 +13,7 @@ prev_inputs: .adv 1 -game_mode: .adv 1 +game_mode: .adv st_size ; 16 bit srand seed ; seed must never be 0