Added game object pool allocator for accessories

This commit is contained in:
blondie7575 2018-12-29 17:13:03 -07:00
parent 32c622afbe
commit 364ae0de32
5 changed files with 158 additions and 17 deletions

View File

@ -65,6 +65,7 @@ JD_NEW = 142
JD_STATIC = 144
JD_OWNER = 146
JD_FACING = 148
JD_SCRATCH = 150
MAXPROJECTILES = 3

29
fan.s
View File

@ -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

View File

@ -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

Binary file not shown.

View File

@ -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