From 4d7d93294bbf49a66621b41a18be0250db8799e4 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 1 Feb 2025 13:07:30 +0100 Subject: [PATCH] state: Added state machine stub for future acotr/player updates --- src/actor.s | 4 ---- src/animation.s | 36 ------------------------------------ src/defs.s | 22 +++++++--------------- src/main.s | 1 + src/mem.s | 1 - src/player.s | 1 + src/state.s | 23 +++++++++++++++++++++++ src/wram.s | 7 +------ 8 files changed, 33 insertions(+), 62 deletions(-) create mode 100644 src/state.s diff --git a/src/actor.s b/src/actor.s index b5036e1..29357d6 100644 --- a/src/actor.s +++ b/src/actor.s @@ -527,8 +527,4 @@ who_next: @no_player: ld [who], a - ; advance some other values - ; related to the next turn starting - call anim_next - ret diff --git a/src/animation.s b/src/animation.s index e30f763..f432c89 100644 --- a/src/animation.s +++ b/src/animation.s @@ -2,42 +2,6 @@ ; each frame the latest animation is ; updated - ; animation functions: - ; inputs: - ; hl: actor ptr - ; bc: anim ptr - - ; sets up animation ptr -anim_init: - ld hl, anim_table - ld a, l - ld [anim_ptr], a - ld a, h - ld [anim_ptr+1], a - ret - - ; advances animation ptr to - ; its next value -anim_next: - ld a, [who] - cp a, 0 - jp z, anim_init - - ld a, [anim_ptr] - ld l, a - ld a, [anim_ptr+1] - ld h, a - - ld de, anim_size - add hl, de ; hl = next animation ptr - - ld a, l - ld [anim_ptr], a - ld a, h - ld [anim_ptr+1], a - - ret - anim_walk_north: ret diff --git a/src/defs.s b/src/defs.s index fe2b933..41ec347 100644 --- a/src/defs.s +++ b/src/defs.s @@ -195,20 +195,12 @@ .de GM_PAUSE, 1 .de GAME_OVER, 1 - - ; animation flags enum -.se 1 - - -; animation table entries + ; struct state .se 0 -.de ANIM_TNOP, 1 -.de ANIM_TWALK_SIMPLE, 1 +.de sm_state, 1 +.de sm_param, 2 +.de sm_size, 0 - ; anim entry struct -.se 0 -.de anim_type, 1 -.de anim_step, 1 -.de anim_flags, 1 -.de anim_p0, 1 -.de anim_size, 0 +; state table entries +.se 1 +.de smt_end_turn, 1 diff --git a/src/main.s b/src/main.s index 21bf3a7..ca38790 100644 --- a/src/main.s +++ b/src/main.s @@ -66,6 +66,7 @@ main: #include "audio.s" #include "animation.s" #include "combat.s" +#include "state.s" #include "tiles.inc" diff --git a/src/mem.s b/src/mem.s index df73aa6..7e24aab 100644 --- a/src/mem.s +++ b/src/mem.s @@ -6,7 +6,6 @@ mem_init: call memset call rand_init - call anim_init ; copy shadow oam dma function ld de, shadow_oam_to_oam diff --git a/src/player.s b/src/player.s index 5a048ee..1e0a216 100644 --- a/src/player.s +++ b/src/player.s @@ -219,6 +219,7 @@ player_update: ld e, a ; e = target x + 8 to center on tile call player_collision_check +@update_end: @skip_input: ; hl should be player_y here diff --git a/src/state.s b/src/state.s new file mode 100644 index 0000000..259fd76 --- /dev/null +++ b/src/state.s @@ -0,0 +1,23 @@ +; the state machine can be used by the current actor (who) +; to store their current state and call small re-usable routines + + ; table of all states +state_table: + dw sm_nop + dw sm_end_turn + +sm_nop: + ret + +sm_end_turn: + call sm_clear + ret + + ; clears the state machine +sm_clear: + xor a, a + ld hl, state_machine + ld a, [hl+] + ld a, [hl+] + ld a, [hl+] + ret diff --git a/src/wram.s b/src/wram.s index 2ab803b..1ec0924 100644 --- a/src/wram.s +++ b/src/wram.s @@ -103,12 +103,7 @@ anim_step_x: .adv 1 anim_target_y: .adv 1 anim_target_x: .adv 1 - ; pointing to current animation - ; advanced in who_next - ; l/h ptr -anim_ptr: .adv 2 - ; 1 animation buffer for each actor + player -anim_table: .adv anim_size * (ACTORS_MAX + 1) +state_machine: .adv sm_size ; collision tile tmp values ct_poy: .adv 1 -- 2.30.2