From: Lukas Krickl Date: Wed, 23 Apr 2025 19:20:29 +0000 (+0200) Subject: cells: cells now have a timer just like states X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=c4d1d79ca3c2a89c14a5086f28d1c52a97141c46;p=gbrg%2F.git cells: cells now have a timer just like states This allows easier scheduling e.g. for build timers --- diff --git a/src/buildings.s b/src/buildings.s index 3b47999..bebaa13 100644 --- a/src/buildings.s +++ b/src/buildings.s @@ -23,10 +23,6 @@ build_road: ld bc, c_size call memcpy - call cursor_get_tile - ld a, BUILDING_ROAD_NORTH_SOUTH - call bg_update_queue_push - ldnull bc ret diff --git a/src/cells.s b/src/cells.s index afffd51..2946925 100644 --- a/src/cells.s +++ b/src/cells.s @@ -5,17 +5,28 @@ ; de: cell ptr ; bc: screen ptr cell_update: + push de + inc de + inc de inc de ; de = flags ld a, [de] ; a = head offset and a, CF_HEAD + pop de ; if not head cell return ret z ; save cell ptr - dec de ; de is c_type push de - - inc de + + ; check timer + ld a, [de] ; a = timer + cp a, 0 + jr z, @update REL ; if timer is 0 update + dec a ; otherwise timer-- + ld [de], a + pop de + ret +@update: inc de ; de = c_st_routine ld a, [de] @@ -39,7 +50,6 @@ cell_update: or a, c ret z - inc de inc de ; de = c_st_routine @@ -61,8 +71,13 @@ cell_road_update: ; updates the tiles ; by pushing tile updates cell_road_init: + push bc + pop hl ; hl = ptr to tile + ld a, BUILDING_ROAD_NORTH_SOUTH + call bg_update_queue_push + ld bc, cell_road_update ret cell_template_road: - c_def C_ROAD, CF_HEAD, cell_road_init + c_def 0, cell_road_init, CF_HEAD diff --git a/src/defs.s b/src/defs.s index 8f4d458..4011df4 100644 --- a/src/defs.s +++ b/src/defs.s @@ -51,14 +51,14 @@ ; game state cell struct ; this holds all the information ; a cell on the map has + ; cells are a reduced version of states + ; without a default next value and additional flags .se 0 - ; cell type/cell gfx -.de c_type, 1 -.de c_flags, 1 - ; if c_st_rotuine - ; is unsued (true for all non-head cells) - ; this space can be used by the head cell - ; to store data + ; cell delay timer only used for head cell + ; when it reaches 0 the next state is called +.de c_time, 1 + ; type/gfx or custom data for non-head cells +.de c_type, 0 .de c_st_data, 0 ; this is the same as st routine, ; but tiles do not have a timer or @@ -73,6 +73,11 @@ ; de: cell ptr ; bc: screen ptr .de c_st_routine, 2 +.de c_flags, 1 + ; if c_st_rotuine + ; is unsued (true for all non-head cells) + ; this space can be used by the head cell + ; to store data .de c_size, 0 ; cell type enum @@ -87,7 +92,11 @@ #define CURSOR_MIN_Y 0 #define CURSOR_MAX_Y 0xB8 - ; state struct + ; state struct + ; states are intended to + ; be used as part of a larger + ; struct + ; e.g. player state .se 0 ; time until next state .de st_time, 1 diff --git a/src/macros.inc b/src/macros.inc index a4f6367..b1fefaa 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -130,13 +130,13 @@ ; defines a new cell template ; inputs: - ; $1: c_type - ; $3: c_flags + ; $1: c_time ; $2: c_st_routine + ; $3: c_flags #macro c_def .db $1 - .db $2 - dw $3 + dw $2 + .db $3 #endmacro ; loads NULL into a 16 bit register diff --git a/src/simulation.s b/src/simulation.s index dd2f8a0..857a09a 100644 --- a/src/simulation.s +++ b/src/simulation.s @@ -41,17 +41,16 @@ sim_update: ld a, SIM_UPDATE_MAX+1 push af @loop: - - ; advance to next cell - .rep i, c_size, 1, inc de - inc bc - push de push bc call cell_update pop bc pop de pop af + + ; advance to next cell + .rep i, c_size, 1, inc de + inc bc ; loop counter-- dec a