Enemy sprite rendering routine call

By Metalion

Paragon (1350)

Metalion's picture

30-12-2020, 11:31

Hi everyone,

I'm working on a game, and I would like some advice about how to tackle a specific problem.

Here is the global context :
- After player input, the screen rendering takes between 3 and 4 frames, including 16 out of 32 sprites (they are part of the decor).
- The other 16 sprites (enemy) need to be updated independently than the screen rendering (because their movement is not related to player input). But they cannot be rendered at every frame, because their position depend on screen rendering final result.

My first thought was to
- use a flag ("render_done") that would signal the end of rendering. And it would stay raised when there's no player input.
- call the enemy sprites rendering routine on VBLANK, and check that flag before updating the sprites on screen.
But that would mean that if the screen rendering is finished, let's say, just at the begining of the 3rd frame, I would loose almost a full frame before rendering the sprites, which could show some lag on screen.

My second thought was to
- call the enemy rendering routine after rendering (when there's a rendering).
- include a frame counter that would be polled in the waiting loop for player input, and upon a change of frame, call the enemy sprite rendering routine (so that it would be called when there's no player input).

What would be your advice ?
Thanks.

Login or register to post comments

By geijoenr

Master (233)

geijoenr's picture

30-12-2020, 12:00

My advice would be to try both and see which one works better.

By thegeps

Paladin (736)

thegeps's picture

30-12-2020, 14:04

Set a flag variable: 0 to render 1 to update sprites
Set a frame variable
Sprites update in the ISR:
If flag=1 do other ISR hooked tasks then ret
If flag=0 execute the whole ISR hooked tasks, set flag=1 then ret

Split the rendering routine in several frames (say 4)
Render routine:
Check frame number, then jump to right frame render routine
At the beginning of each render frame check the flag: if it is 0 don't update frame counter and ret
If it is 1 do the render frame, then update frame counter, set flag=0 and ret

I did something like this in Freedom Fighter except the frame thing because there weren't relation between sprites and background update: simply I had to call the scrolling routine and do the flag check 3 times: 1-nametable update, 2 tiles' shape redef, 3 tiles' colors redef

Check

By Dolphin101546015

Champion (303)

Dolphin101546015's picture

30-12-2020, 16:38

What you mean under "rendering"?
You update SPT?

By Daemos

Paragon (1939)

Daemos's picture

30-12-2020, 17:11

Only update spritedata if the sprite does an animation? The object to which the sprite is attached can request a spriteupdate from the engine for that particular sprite. Only then the spritedata is uploaded to the VRAM.

By Metalion

Paragon (1350)

Metalion's picture

30-12-2020, 17:36

Dolphin101546015 wrote:

What you mean under "rendering"?
You update SPT?

I mean drawing the screen and updating SPT only for the sprites which are part of the decor.

Daemos wrote:

Only update spritedata if the sprite does an animation? The object to which the sprite is attached can request a spriteupdate from the engine for that particular sprite. Only then the spritedata is uploaded to the VRAM.

It's not an animation.

The enemy sprites are moving according to their own speed. Their coordinates are function of that movement but it is also relative to the result of the rendered screen. If there is no player input, the screen is static, and they move relative to that screen. If there's a player input, the screen rendering occurs, and they continue to move, but now in relation to the newly rendered screen.