double buffered sprite engine ?

Since we do not have native C compilers on the Oric, this forum will be mostly be used by people using CC65 or the OSDK. But any general C related post will be welcome !
Post Reply
User avatar
goyo
2nd Star Corporal
Posts: 31
Joined: Sat Jan 12, 2019 10:16 am

double buffered sprite engine ?

Post by goyo »

Hello,

I would like to get a sprite engine that à saw on youtube :

Is there anyone who knows or owns the source code ?

I think its very interessant to make an Isometric Game or a platform game.

:)

User avatar
Iapetus
Flying Officer
Posts: 134
Joined: Thu Mar 19, 2009 10:47 pm

Re: double buffered sprite engine ?

Post by Iapetus »

Hello,

Unfortunately I have not published any code of mine yet.

The sprite engine does this basically:

- restore background for each sprite
- save background for each sprite
- paint the masked sprites (pixel data and masks are already pre-shifted in RAM)
- copy buffer to screen
- calculate sprite data(where to paint sprite, which gfx and mask to use etc)
- repeat

You can make it faster by having an extra buffer with the background and then you don't need the "save background" step. Also in my latest version of the sprite engine which is quite faster than this one I copy only what moved on the buffer so I don't need to copy the whole buffer to the screen every time.

I hope this helps.
Last edited by Iapetus on Sat Aug 22, 2020 9:19 pm, edited 3 times in total.
Twitter: @newIapetus
Ko-fi:iapetusretrostuff
itch.io: Iapetus
Youtube: Iapetus Retro Stuff

User avatar
ibisum
Wing Commander
Posts: 1308
Joined: Fri Apr 03, 2009 8:56 am
Location: Vienna, Austria
Contact:

Re: double buffered sprite engine ?

Post by ibisum »

Looks pretty smooth .. what did you mean by this, though?

>- paint the masked sprites (pixel data and masks are pre-shifted)


to 6-bits, or .. ?

User avatar
Iapetus
Flying Officer
Posts: 134
Joined: Thu Mar 19, 2009 10:47 pm

Re: double buffered sprite engine ?

Post by Iapetus »

ibisum wrote:
Sat Aug 22, 2020 8:43 pm
Looks pretty smooth .. what did you mean by this, though?

>- paint the masked sprites (pixel data and masks are pre-shifted)


to 6-bits, or .. ?
For each sprite I need to store in RAM the gfx and mask for 6 possible positions as we have 6 pixels per byte on the Oric (this allows the sprite to move at one pixel precision, if your sprites move at 2 pixel steps you need to store only 3 possible positions).

for example

Code: Select all

shift0
000000
100000
100000
000000
shift1
000000
010000
010000
000000
shift2
000000
001000
001000
000000
shift3
000000
000100
000100
000000
shift4
000000
000010
000010
000000
shift5
000000
000001
000001
000000
and then the mask
[...]
Twitter: @newIapetus
Ko-fi:iapetusretrostuff
itch.io: Iapetus
Youtube: Iapetus Retro Stuff

User avatar
goyo
2nd Star Corporal
Posts: 31
Joined: Sat Jan 12, 2019 10:16 am

Re: double buffered sprite engine ?

Post by goyo »

I am sorry I don't understand all of your response bc i don't speak very well in english. Do you speak french ?

If I understand, you precalculate all of 6 sprites position for each sprite before put in the sprite buffer ?. It must take much memory ?

In my example(joint file) i dont precalculate the sprite position but i use many tables of shift. That is generic for all graphic sprite.

I would like to understand and find the complete flowchart process of double buffering technical. I dont see on internet any technical information of this subjet.

Is it for one buffer of a sprite ? :

(1) clear the buffer -> (2) [put background in the buffer] -> (3) [put the mask in the buffer] -> (4) [put the sprite in the buffer] ->

(5) [copy the buffer to the visible screen at the sprite position(byte) ] :o
Attachments
spr_and_key3.zip
little sprite that can move with the keyboard
(47.04 KiB) Downloaded 21 times

User avatar
Iapetus
Flying Officer
Posts: 134
Joined: Thu Mar 19, 2009 10:47 pm

Re: double buffered sprite engine ?

Post by Iapetus »

I am sorry although I can understand written formal French I can't explain this stuff en Français :(

I am not using a buffer for each sprite, I use a big buffer where I paint the game screen, with tiles, sprites, objects etc. And then I copy the the buffer to screen after finishing updating the buffer once per game loop. (The buffer in that video is a buffer bigger than the play area so it allows for sprite clipping and in that case I only copy the visible area)

These links might be of help regarding sprites although they are not Oric specific the general theory applies to any computer:
https://spectrumcomputing.co.uk/forums/viewtopic.php?t=256&start=20
https://stardot.org.uk/forums/viewtopic.php?f=54&t=19717&hilit=masked+sprites
Twitter: @newIapetus
Ko-fi:iapetusretrostuff
itch.io: Iapetus
Youtube: Iapetus Retro Stuff

User avatar
Chema
Game master
Posts: 2686
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: double buffered sprite engine ?

Post by Chema »

Hi!

I have written quite a lot about this in the forums... I am quite sure I even put some code in the SkoolDaze and OASIS (the engine I made to program Blake's7) dev forums.

If you check the Space:1999 development thread (https://forum.defence-force.org/viewtop ... f=20&t=135) you will also find some interesting info on an isometric engine.

For newer games, I moved to pre-rotated graphics. If your Sprite has different animation frames, you ar not wasting too much memory and it is faster.

I used tables for mirroring, but never for rotations.

Hope this helps. Keep us informed of your progress!

User avatar
goyo
2nd Star Corporal
Posts: 31
Joined: Sat Jan 12, 2019 10:16 am

Re: double buffered sprite engine ?

Post by goyo »

thank you all for this information

And Chema, do you generate automatically the mask of sprite with an specific algorithm? for example to convex or concave shape ...? infos store in 2 left bits ?

User avatar
Dbug
Site Admin
Posts: 3377
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: double buffered sprite engine ?

Post by Dbug »

goyo wrote:
Mon Aug 24, 2020 5:44 pm
thank you all for this information

And Chema, do you generate automatically the mask of sprite with an specific algorithm? for example to convex or concave shape ...? infos store in 2 left bits ?
Twilighte actually did some tests with that in his Times of Lore prototype, using the two unused bits to provide some crude masking information, but that did work well enough I believe.

User avatar
Chema
Game master
Posts: 2686
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: double buffered sprite engine ?

Post by Chema »

goyo wrote:
Mon Aug 24, 2020 5:44 pm
thank you all for this information

And Chema, do you generate automatically the mask of sprite with an specific algorithm? for example to convex or concave shape ...? infos store in 2 left bits ?
Not really. I create both the graphic and mask manually (with some pixel paint program) and convert them to data to include in my sources.

User avatar
goyo
2nd Star Corporal
Posts: 31
Joined: Sat Jan 12, 2019 10:16 am

Re: double buffered sprite engine ?

Post by goyo »

Iapetus wrote:
Sun Aug 23, 2020 8:05 pm
I am sorry although I can understand written formal French I can't explain this stuff en Français :(

I am not using a buffer for each sprite, I use a big buffer where I paint the game screen, with tiles, sprites, objects etc. And then I copy the the buffer to screen after finishing updating the buffer once per game loop. (The buffer in that video is a buffer bigger than the play area so it allows for sprite clipping and in that case I only copy the visible area)

These links might be of help regarding sprites although they are not Oric specific the general theory applies to any computer:
https://spectrumcomputing.co.uk/forums/viewtopic.php?t=256&start=20
https://stardot.org.uk/forums/viewtopic.php?f=54&t=19717&hilit=masked+sprites
Which is the fastest ? use a one screen size buffer for all sprites or many buffer of sprite size ( like the game Knight Lore ... or Jack the Nipper https://www.retrogamer.net/retro_games8 ... he-nipper/
) ?

User avatar
Chema
Game master
Posts: 2686
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: double buffered sprite engine ?

Post by Chema »

Mmmm I'd say it depends. Using a screen size buffer will make rendering there faster (no coordinate adjustment or clipping needed), but you need more memory. Of course that is true only if you clear/draw/dump the areas that need updating.. This must be done with care to make it as fast as possible. Separate buffers may also.work well if done with care and avoid updating intersection areas more than once. Aome sort of dirty rectangles algorithm may do.

I used a single small buffer in Space:1999, but it was far from an optimal solution, as I failed to update the same area twice when sprites overlap.

In 1337 the whole play area is updated as everything changes, and it is a performance bottleneck.

In SkoolDaze, Oricium and Blake's7 I took a different approach, based on small tiles. The backbuffer in this case is just one tile, but they are updated only once and when really needed.

User avatar
Iapetus
Flying Officer
Posts: 134
Joined: Thu Mar 19, 2009 10:47 pm

Re: double buffered sprite engine ?

Post by Iapetus »

goyo wrote:
Wed Aug 26, 2020 10:54 am

Which is the fastest ? use a one screen size buffer for all sprites or many buffer of sprite size
I never used many small buffers I always use the big buffer and then I have two options, 1. I copy all the buffer to the screen at each game look iteration OR 2. I just copy what changed since the last game loop iteration. I find that the second option is faster BUT it depends of course, on the number and size of sprites, bullets(particles), objects, the speed(in pixels) the objects/sprites can move etc. You always have to assess which option will work the best, when coding for these old computers we must always make concessions.
Twitter: @newIapetus
Ko-fi:iapetusretrostuff
itch.io: Iapetus
Youtube: Iapetus Retro Stuff

User avatar
goyo
2nd Star Corporal
Posts: 31
Joined: Sat Jan 12, 2019 10:16 am

Re: double buffered sprite engine ?

Post by goyo »

In this following link i created an image to try to understand the display sprite process, is it the good algorithm that you used ? :
sprite_double_buffer_algo.png

Post Reply