unit: implemented a temporary fix for unit redrawing failing
authorLukas Krickl <lukas@krickl.dev>
Wed, 21 May 2025 16:23:22 +0000 (18:23 +0200)
committerLukas Krickl <lukas@krickl.dev>
Wed, 21 May 2025 16:23:22 +0000 (18:23 +0200)
This fix currently pauses all obj updates while a unit is moving.
This is not a great solution and will need to be addressed properly
later.

State machine transitions are causing unit redraws to not happen.
Maybe a proper solution would be to have a few sprites for units in
motion that are not affected by the regular unit updates.

src/defs.s
src/sys.s
src/unit.s
src/wram.s

index 232845ab5f612f8b83def07cf8d5c6e167030e5e..4e97540662517cca8f9d0da608a3af329ba127da 100644 (file)
   ; draw flags
 .se 1
 .de DRAWF_UPDATE_UI, 1
+  ; if set to 1, return 
+  ; an invalid object from soam 
+  ; when units want to draw
+.de DRAWF_SKIP_UNIT_OBJS, 2
 
   ; gameplay flags
 .se 1
index 500aac407a00e28096e92221ebc957f761fd358c..078879ddc28732bac8fd5dd5b4256c1ec966c9ae 100644 (file)
--- a/src/sys.s
+++ b/src/sys.s
@@ -65,6 +65,10 @@ load_scroll:
   ; returns;
   ;   hl: current unit sprite
 load_unit_obj:
+  ld a, [draw_flags]
+  and a, DRAWF_SKIP_UNIT_OBJS 
+  jr nz, @load_unit_empty REL
+
   ld a, [unit_sprite]
   
 
@@ -79,3 +83,6 @@ load_unit_obj:
   ld [unit_sprite], a
 
   ret
+@load_unit_empty:
+  ld hl, empty_oam
+  ret
index ffe9524b8b05885693a63a93ef3b2d30f1c14bca..c856bf24cf8605a7bd8d2cf55918eced4657c509 100644 (file)
@@ -84,9 +84,6 @@ unit_demo_1_draw:
   ; inputs:
   ;   de: actor
 unit_demo_1_delay_to_active:
-  push de
-  call unit_demo_1_draw
-  pop de
   jp unit_delay_to_active
 
   ; draws any unit
@@ -267,6 +264,9 @@ unit_use_move:
 
   dec a
   ld [hl], a
+  
+  call unit_pause_objs
+
   ; we need the z flag to not be set ehre
   ; so just do something that will always unset it
   or a, 1
@@ -562,6 +562,7 @@ unit_reset_all_moves:
   ; inputs:
   ;   de: unit
 unit_delay_to_active:
+  call unit_resume_objs
   ld hl, act_moves
   add hl, de ; hl = moves
   ld a, [hl]
@@ -570,6 +571,20 @@ unit_delay_to_active:
   ldnull bc
   ret
 
+  ; pauses object redraws
+  ; until unpause is called
+unit_pause_objs:
+  ld a, [draw_flags]
+  or a, DRAWF_SKIP_UNIT_OBJS
+  ld [draw_flags], a
+  ret
+  
+  ; resumes obj updates
+unit_resume_objs:
+  ld a, [draw_flags]
+  and a, ~DRAWF_SKIP_UNIT_OBJS & 0xFF
+  ld [draw_flags], a
+  ret
 
 unit_demo_1:
   st_def 0x00, unit_demo_1_init, st_unit_demo_1_idle
index c7cc74b89f46a9c12c847ed030a89a1930f7648d..3940f9bf4b852ef137475f3686299e8a4a8e6f7f 100644 (file)
@@ -35,6 +35,9 @@ bg_update_queue: .adv bge_size * BGE_MAX
 draw_flags: .adv 1
 gameplay_flags: .adv 1
 
+; dummy oam 
+; same memory as empty_unit
+empty_oam: .adv 0
 ; a dummy unit 
 p_empty_unit: .adv act_size