Author Topic: Sprite data format  (Read 1975 times)

0 Members and 1 Guest are viewing this topic.

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.353
  • Country: au
    • index.php?action=treasury
  • Liked: 1016
  • Likes Given: 1196
Sprite data format
« on: 13:07, 03 May 11 »
Hi everyone.

Originally, my large Savage sprite for Chunky Pixel Collision was just defined as a series of values.
So, as it is a 64x64 sprite, it took 4K, which is completely unacceptable.

I came up with a different way of representing the sprite, which also required a complete rewrite of the sprite code.
It was just a list of colours, with the number of pixels to be painted each colour.

ie. reps1,colour1,reps2,colour2,...,repsN,colourN.

Still, Savage takes up almost 1.5K this way, which is still too much.

Does anyone have any amazingly clever ways to store sprite data, that can be used in realtime?
I need to think of another way to represent the data, that won't rob my game of the memory it needs.
I've got no issues at all with another sprite code rewrite, so let the crazy ideas flow!  ;D

Thanks for any help.
« Last Edit: 13:09, 03 May 11 by ervin »
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2274
  • Likes Given: 3478
Re: Sprite data format
« Reply #1 on: 13:10, 03 May 11 »
You could add a code for end of line if you don't have this already?
then you don't need to process transparent pixels on the right and you also have less data?

also for the left side you could do the same?

Ok, since each colour is one of 16 possibilities, store each colour in a nibble. You could also store the count in a nibble too allowing single runs of up to 16 pixels (0=16, 1-15 = their value)?

If you add the end of line code, you'd have less run, e.g. 0 = end of line, 1-15 = their value.

some ideas that could work?
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.353
  • Country: au
    • index.php?action=treasury
  • Liked: 1016
  • Likes Given: 1196
Re: Sprite data format
« Reply #2 on: 13:33, 03 May 11 »
Thanks for the quick reply!

I do indeed have beginning-of-line and end-of-line codes.
They help a lot, and speed up the sprite processing a bit as well.
Transparent pixels on the inside are also skipped by adding the required value to the relevant memory address.

The nibble idea though... I like it.
I don't know how I'll process it yet, but no doubt it involves ANDs or ORs or somesuch.
I'll give it a go!  8)

Thanks again.
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline redbox

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.751
  • Country: gb
    • redbox
  • Liked: 326
  • Likes Given: 267
Re: Sprite data format
« Reply #3 on: 13:44, 03 May 11 »
I don't know how I'll process it yet, but no doubt it involves ANDs or ORs or somesuch.


Or you can use shifting (SLA, SRL, RRC, etc.) and it's worth remembering that the carry flag can be used with these too (for conditional jumps like JR C,address etc).

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.353
  • Country: au
    • index.php?action=treasury
  • Liked: 1016
  • Likes Given: 1196
Re: Sprite data format
« Reply #4 on: 13:50, 03 May 11 »
Ah, I see.
Cool - thanks for that.

The more information, the better!
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline redbox

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.751
  • Country: gb
    • redbox
  • Liked: 326
  • Likes Given: 267
Re: Sprite data format
« Reply #5 on: 14:56, 03 May 11 »
I recently came up with the same idea as arnoldemu for compacting graphical data.

However, this idea does depend on the next pixel to print being less than 16 pixels away.  For example, if you store the byte and colour information as two nibbles in one byte, it could be

Code: [Select]
128 64 32 16 8 4 2 1
  1  1  0 1  1 0 1 1

Firstly, AND the above with %00001111 and this would leave you with:

Code: [Select]
128 64 32 16 8 4 2 1
  0  0  0 0  1 0 1 1


Which equals 8+2+1 = 11, and this can be your PEN colour.  Then, rotate right 4 times with RRA and you end up with:

Code: [Select]
128 64 32 16 8 4 2 1
  0  0  0 0  1 1 0 1

Which equals 8+4+1 = 13, and this could be the number of pixels/bytes to increase for the next pixel to display.

Sorry if this sucking eggs for you, but thought I would explain it for everyone....!  And there are ways you could optimise this further  ;)

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.353
  • Country: au
    • index.php?action=treasury
  • Liked: 1016
  • Likes Given: 1196
Re: Sprite data format
« Reply #6 on: 15:00, 03 May 11 »
I was thinking along similar lines, but having it explained like that is very helpful.
Thanks man.
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline Axelay

  • 6128 Plus
  • ******
  • Posts: 579
  • Country: au
  • Liked: 375
  • Likes Given: 87
Re: Sprite data format
« Reply #7 on: 15:37, 03 May 11 »
Well the good ideas appear to have been covered, but hey, you asked for crazy  ;)


If using a nibble type method, could a bit be set aside for indicating 'patterns' that you look up, so that commonly occurring groups of different coloured pixels that might take 3-4 bytes only need take one, though you are then limited to a maximum of 8 pixels of one colour in a row rather than 16, which might cause more repeats and eat as much memory as it might save.  I'm sure this would end up being slower too.


Another idea, I'm not sure how you would be translating the ink 0-15 indicator to screen data information (I mean because it isnt a straight nibble), but if whatever you're doing required a lookup table you could say, instead of having colour info stored in a 16 byte table at &8000-&800f, store them at &8000, &8010, &8020 and so on, taking a whole 256 byte 'page', but it means you could take the data byte AND &f for the pixel count, and only need to AND &f0 to get the position in the lookup table, saving on the need for any shifts.

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.353
  • Country: au
    • index.php?action=treasury
  • Liked: 1016
  • Likes Given: 1196
Re: Sprite data format
« Reply #8 on: 15:57, 03 May 11 »
The more crazy, the better!
Some very interesting ideas in there!
Thanks for all of that.

I'll give them a thinking through and see if I can use any of them.
Top stuff.  :)
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494