From 364ae0de32aa78d703533f6e8e832659622e1136 Mon Sep 17 00:00:00 2001 From: blondie7575 Date: Sat, 29 Dec 2018 17:13:03 -0700 Subject: [PATCH] Added game object pool allocator for accessories --- equates.s | 1 + fan.s | 29 ++++++----- gameobject.s | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++- gscats.2mg | Bin 819264 -> 819264 bytes projectile.s | 11 +++-- 5 files changed, 158 insertions(+), 17 deletions(-) diff --git a/equates.s b/equates.s index 582fa32..d5d5f01 100644 --- a/equates.s +++ b/equates.s @@ -65,6 +65,7 @@ JD_NEW = 142 JD_STATIC = 144 JD_OWNER = 146 JD_FACING = 148 +JD_SCRATCH = 150 MAXPROJECTILES = 3 diff --git a/fan.s b/fan.s index 3d9d4ec..2647e1d 100644 --- a/fan.s +++ b/fan.s @@ -58,17 +58,26 @@ updateFan: beq updateFanDone ; Once fan is in place, make it static + lda projectileData+GO_POSY,y + inc + sta projectileData+GO_POSY,y lda #1 sta projectileData+JD_STATIC,y jsr endProjectile ; Now set up the stand + jsr allocGameObject + cpx #-1 +BREAK + beq updateFanDone + txa + sta projectileData+JD_SCRATCH,y ; Remember where our stand is lda projectileData+GO_POSX,y - sta standGameObjectData+GO_POSX + sta gameObjectPool+GO_POSX,x lda projectileData+GO_POSY,y sec sbc #GAMEOBJECTHEIGHT - sta standGameObjectData+GO_POSY,y + sta gameObjectPool+GO_POSY,x updateFanDone: RESTORE_AXY @@ -123,7 +132,11 @@ renderFan: beq renderFanDone ; Don't render the stand until we're static ; Render the stand under the fan - lda #standGameObjectData + lda projectileData+JD_SCRATCH,y + sta PARAML0 + clc + lda #gameObjectPool + adc PARAML0 sta PARAML0 lda #14 jsr renderGameObject @@ -131,13 +144,3 @@ renderFan: renderFanDone: RESTORE_AXY rts - - -; Fake game object for rendering the stand -standGameObjectData: - .word 40 ; X pos in pixels (from right terrain edge) - .word 38 ; Y pos in pixels (from bottom terrain edge) - .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background 64 bytes - .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 diff --git a/gameobject.s b/gameobject.s index 53d7aed..7bf1940 100644 --- a/gameobject.s +++ b/gameobject.s @@ -7,12 +7,14 @@ GAMEOBJECTWIDTH = 16 GAMEOBJECTHEIGHT = 16 +MAXGAMEOBJECTS = 6 ; Size of general purpose object pool + ; Base class sample: ;gameobjectData: ; .word 40 ; X pos in pixels (from right terrain edge) ; .word 38 ; Y pos in pixels (from bottom terrain edge) -; .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background 64 bytes +; .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background 128 bytes ; .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 @@ -712,3 +714,133 @@ unrenderGameobjectBackground: unrenderGameobjectDone: RESTORE_AXY rts + + +.macro GAMEOBJECTPTR_X + txa ; Pointer to game object type structure from index + asl + asl + asl + asl + asl + asl + asl + asl + tax +.endmacro + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; allocGameObject +; +; Returns offset of gameobject structure in X, or -1 if none available +; +allocGameObject: + SAVE_AY + ldy #0 + +allocGameObjectLoop: + tyx + GAMEOBJECTPTR_X + lda gameObjectPool+GO_POSX,x + bmi allocGameObjectDone + iny + cpy #MAXGAMEOBJECTS + bne allocGameObjectLoop + ldx #-1 + +allocGameObjectDone: + RESTORE_AY + rts + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; deleteGameObject +; +; Deletes the game object at offset X +; +deleteGameObject: + pha + lda #-1 + sta gameObjectPool+GO_POSX,x + pla + rts + + +; A general purpose pool allocator for game objects. Useful +; for those times you need an object, but not a full fledged +; Player, Projectile, or other subclass. +gameObjectPool: + .word -1 ; X pos in pixels (from right terrain edge) + .word 0 ; Y pos in pixels (from bottom terrain edge) + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background 128 bytes + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + .repeat 124 + .byte 0 ; Padding to 256-byte boundary + .endrepeat + + + .word -1 ; X pos in pixels (from right terrain edge) + .word 0 ; Y pos in pixels (from bottom terrain edge) + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background 128 bytes + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + .repeat 124 + .byte 0 ; Padding to 256-byte boundary + .endrepeat + + + .word -1 ; X pos in pixels (from right terrain edge) + .word 0 ; Y pos in pixels (from bottom terrain edge) + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background 128 bytes + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + .repeat 124 + .byte 0 ; Padding to 256-byte boundary + .endrepeat + + + .word -1 ; X pos in pixels (from right terrain edge) + .word 0 ; Y pos in pixels (from bottom terrain edge) + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background 128 bytes + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + .repeat 124 + .byte 0 ; Padding to 256-byte boundary + .endrepeat + + + .word -1 ; X pos in pixels (from right terrain edge) + .word 0 ; Y pos in pixels (from bottom terrain edge) + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background 128 bytes + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + .repeat 124 + .byte 0 ; Padding to 256-byte boundary + .endrepeat + + + .word -1 ; X pos in pixels (from right terrain edge) + .word 0 ; Y pos in pixels (from bottom terrain edge) + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background 64 bytes + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + .repeat 124 + .byte 0 ; Padding to 256-byte boundary + .endrepeat + + + diff --git a/gscats.2mg b/gscats.2mg index d2c1b25ea6e7af68ff3121b96f28c58fca32c6bb..392534c33485848af95d7a2ae111889da46da19e 100644 GIT binary patch delta 2455 zcma)8Z)_9i8Gr8_U;Q^Rqh)6k!aE3%P}be}GPm8<(2W&3+9hfub;i;>bU6C_=ugOYY?EtM&o*oI_GRxZs{6)wzPa=1 z9nXJz=a&TmA;gWNucPX2M5U=(k?4t8tIIIO_g|c_{)S_!dPJAnBfBc!u(>lfH?#kz z?3Dv*G|AMm?ZHek$sA#q)lCjaLT#$@SPGwxecco0vNoF0x&J*>6Q_PEOG_2YNn6Ipv zBug!!T~mQ46H%@3)LOshYPbzD%>zsW$Y#_5sx%zz`JTdOCI*@74K+83XQTf*NqGI* z80uruT~1h?`z7*JI)<{duVg-6V4kd~5A-24a>!ABhO&#zf_-e1L;0Kig+dH0YK6kF z#paff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8M!Gy{yid=QG_dqNbvDmtdUe8hW}z#Z|%mJ9?oPo<1Cf!eY7z@K{A zy;|U^`L`sw&1p`_{K^Hg&AMnSGC$W9b$gj;Ytm@yI^*_EATP#|7qs^l(Nf-jcAa)Z z!FQc?iyHskTHspAe*U_&I|%~yGRwN~3YSQe>RjQ1r?gvv61Gx~MULlj7Q1HX3-5J< zZ*#_HGxTIw`VX>|jR=it7n4Jae412W`?PR8|6z&uxP#2z9OcJ?P)jD+=}72kcjb{3q(ZcB=BZ_3qh6` z#9Mfw0EslG!vY_XrExgIpO@`CF?^mMAclQ|cz_?0mG|)wf05{7gZLspD(hl+G>xcs z{G~z`zKU<-5#cTl18skKL>f;UFwX~N%7T0=E#g)n&Om#CxTH*2QX$Ke#+KD8C5ww3 zS%j*X6afx%K-_y&nmbaY&@@+yG)r9RBbx5V6q;gvKvPQWl^MHLF4aX){(Ks3-fgZMgsCnen(Ls8@jlKz9g z783X(zMn>u=V_igfS*d-A@gO%$Db-Hph>bSghX1UNJOFO-K4b9u8?PgYJ!q`QK_Hd zUWJ(9Ub(6!fi{+qODYctddNR1q>WY}$7%y|xFr5kNOCv^+(0u7r4^7uL=3}Dz>oO` zVp5INjw7U%l zAsXPECEi4+A4wk;jGBa!Ce*pzIlp+8C diff --git a/projectile.s b/projectile.s index 7c6a40c..97376ca 100644 --- a/projectile.s +++ b/projectile.s @@ -24,8 +24,9 @@ projectileData: .word 0 ; Static? .word 0 ; Owner (player index) .word 0 ; Facing (0,1) = (+X,-X) + .word 0 ; Scratch space for subclasses - .repeat 106 + .repeat 104 .byte 0 ; Padding to 256-byte boundary .endrepeat @@ -47,8 +48,9 @@ projectileData: .word 0 ; Static? .word 0 ; Owner (player index) .word 0 ; Facing (0,1) = (+X,-X) + .word 0 ; Scratch space for subclasses - .repeat 106 + .repeat 104 .byte 0 ; Padding to 256-byte boundary .endrepeat @@ -70,8 +72,9 @@ projectileData: .word 0 ; Static? .word 0 ; Owner (player index) .word 0 ; Facing (0,1) = (+X,-X) + .word 0 ; Scratch space for subclasses - .repeat 106 + .repeat 104 .byte 0 ; Padding to 256-byte boundary .endrepeat @@ -530,6 +533,8 @@ updateProjectileCollisionsTerrainHit: ; endDeleteProjectile: lda #projectileData + clc + adc projectileActive sta PARAML0 jsr unrenderGameObject ldy projectileActive