PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

sprites load too slow

I'd eventually have to face this problem. My current game uses quite a lot of sprites(more than 500 already and growing). So, it takes about a full minute to load all of them. On faster PPCs it would be half a minite, but it's still a problem.
Well, I'll finally split them into those loaded in a game start and those in a level loading. I'll only load necessary sprites. Still too long. The user will have to wait about 20 second while game is loaded and 15-20 second to load a level.
All sprites are located in a file system as png files. Now they are temporary gifs, but it's for development in Visual Studio.

I see several sollutions for this problem and I want you to help me estimate their efficacy. I have no idea how much speed I win with them, so maybe you know it better.

1. Join several sprites together in one "spriteset".
Cons: It will be harder to manage them, they should be of one size - it's a lot of pain trying to work with a sprite consisting 5 sprites - 8x8, 16x16, 32x32, 48x48, 64x64. I have several such particles.

2. Add sprites as resources to exe file(as pngs anyway).
Cons: Much harder to manage them, graphics artist will have troubles working with game graphics. Big(6-8mb) exe file is not something I like a lot. Not sure if it win any time. Not sure if exe file won't grow too much compared to separated pngs.

3. Implement pnglib.
Cons: Don't know if it help.

How do people do this? I've seen many games loaded in no time and most of them load very fast or at least acceptable.
I'm curious as to what you are doing that requires so many different sprites?

at the end of the day I agree with you about keeping the resources external to the exe, bloating the exe is the wrong thing to do imho

loading as required is also the right thing to do, from a loading speed and memory aspect

writing your own png decoder or implementing pnglib is a big step - trust me I looked into it - as well as adding the extra size of the pnglib dll's

at the end of the day compressed formats have the advantage of being smaller and the disadvantage of taking time to decompress - with that many sprites there is probably no way to avoid compression and still keep the package size small

I still dont understand how u have so many different sprites unless each frame of animation is a separate sprite? in which case that's just a bad idea
Why don't you group all the images that are the same size into a big image and draw your sprites using a different source rectangle? This would be a lot easier and would save a lot of memory too. 500 little images in seperate files is not a good design, you will have to change that for sure!
A good ressource manager should enable the coder to dump a binary image of your loaded sprites in memory, then you simply have to compress this image (if the sprites are RLE encoded you'll gain space comparing to the png version) and loading all your sprite will be as easy as loading and uncompressing a single file.

You may need a custom handle based memory manager for this feature...
muff wrote:
I still dont understand how u have so many different sprites unless each frame of animation is a separate sprite? in which case that's just a bad idea


Yes, it is so. The reason for this is simple - it's much easier to manage and edit them.
I do understand that it's no good - I just wanted to know how exactly no good it is :). Can't find time to test it myself. I.e. compare 64 64x64 files to one 512x512.

writing your own png decoder or implementing pnglib is a big step - trust me I looked into it - as well as adding the extra size of the pnglib dll's

Well, pnglib is pretty tangled to me, but its not that really hard. Extra dll size is nothing compared to game size.

StephC wrote:
A good ressource manager should enable the coder to dump a binary image of your loaded sprites in memory, then you simply have to compress this image (if the sprites are RLE encoded you'll gain space comparing to the png version) and loading all your sprite will be as easy as loading and uncompressing a single file.
You may need a custom handle based memory manager for this feature...

I'm not good in memory manipulation and memory managers. Frankly, I have none at all experience implementing such a stuff, so it would be very very tricky to me.
In my !PyroManiA! game I have about 250 tiles per level(ground,wall,hanger,item) plus 2-5 NPC's sprites (about 320*240 in size), I have a hero sprite(334*480) and glutton sprite. I also have more than 20 sprites for special effects (animated) fire,smoke etc. I store all those tiles in specisally organized data files.

I load them: some once at the game start, some during the game, on the level loading, and on switching to game/main menu.

I also have a special mermory mangement that also loads/uloads up to 140 sounds during the game (when needed). It also loads big music files.

Even when I load them all from storage card this wouldn't take very much time, even for 200mhz PPC. Well, only if I have a lot of sound events plus AStar pathfinding in action this could drop fps to 10 or when I load music during the game.

So my question is: what the exaxt size (in pixels) do you load for each map and why you load them all on the level start,not during/in pauses on your level or even in action?

Maybe you use jpgs for background? Jpg decompression is much slower than png or gif.

P.S. I hope to release the demo of my game before the end of September,so you can try how it works in my game. In my public beta you also can see the same approach.
jaguard wrote:Yes, it is so. The reason for this is simple - it's much easier to manage and edit them.
I do understand that it's no good - I just wanted to know how exactly no good it is :). Can't find time to test it myself. I.e. compare 64 64x64 files to one 512x512.


the easy way to test this is just to create a dummy file - do a load of the 64x64 sheet 64 times and time it, then do the load of a 512x512 and see what time differences are

doesn't have to be actual final gfx data

and if your artist can't handle editting on a whole page of frames instead of individual ones then I'd ask the artist to learn - it's not difficult

StephC wrote:A good ressource manager should enable the coder to dump a binary image of your loaded sprites in memory, then you simply have to compress this image (if the sprites are RLE encoded you'll gain space comparing to the png version) and loading all your sprite will be as easy as loading and uncompressing a single file.
You may need a custom handle based memory manager for this feature...


the obvious downside here is that it's like saving uncompressed images - big files
Anonymous wrote:
the obvious downside here is that it's like saving uncompressed images - big files


No because you compress the dump file, in my experience there is a size gain...
sorry, didn't put name in on previous post

another note, if the timing are too quick to really tell then load the images more

i.e load 64x64 640 times and 512x512 10 times etc

you are just after some rough decompression numbers to see if the benefit is there
BIGBEN wrote:
Even when I load them all from storage card this wouldn't take very much time, even for 200mhz PPC. Well, only if I have a lot of sound events plus AStar pathfinding in action this could drop fps to 10 or when I load music during the game.

So my question is: what the exaxt size (in pixels) do you load for each map

I'll try to count :). Lets say a point is 320x240 sprite. Then, so game objects - 4 points, particles - 5 points, 1 for weapons, 2 for guns, 2 for backgrounds and about 3 for other stuff. So, about 17 total. Well, probably 10-15 seconds still. Plus sounds, music and other initialization - so up to 20 seconds in a worst case. Still not too fast.

and why you load them all on the level start,not during/in pauses on your level or even in action?


Loading sprites in menus is not the best thing - it takes up to 1 second to load 320x240 sprite, so it would be a noticeable slowdown.
Loading it in action is not good either - I don't have any speed reserves, and my game is pure action, unlike yours, so any lag would be noticeable.

Maybe you use jpgs for background? Jpg decompression is much slower than png or gif.

No, I dont.

Muff wrote:and if your artist can't handle editting on a whole page of frames instead of individual ones then I'd ask the artist to learn - it's not difficult

It's not that he CAN'T. It is that it will take extra time that would otherwise allowed him to create something beatiful :).
Yeah 2,5 mb of final sprite data is big enough to have a noticible slowdown...

jaguard wrote:
Loading sprites in menus is not the best thing - it takes up to 1 second to load 320x240 sprite, so it would be a noticeable slowdown.

Not the best, agreed, but as I noticed it wouldn't disturb much when switching from game to main menu takes less than a second.


Loading it in action is not good either - I don't have any speed reserves, and my game is pure action, unlike yours, so any lag would be noticeable.

Well of course I'm not talking about loading a 320*240 in action. It could be an easy solution for you -since you store all 64*64 frames as different files.
I load 64*32 as a maximum, which is 4 kb of final data, you wouldn't even notice this ;)


Muff wrote:and if your artist can't handle editting on a whole page of frames instead of individual ones then I'd ask the artist to learn - it's not difficult

It's not that he CAN'T. It is that it will take extra time that would otherwise allowed him to create something beatiful :).

I'm not going to agitate you or your artist for this,since he is much more experienced than me...

but in my experience it's much easier and saves time for me when I adjust color balance, brightness/contrast, fix some other stuff on my single sprite(about 320*240) of 72 NPC's frames.

I use Paint Shop Pro - arrange all frames in one file is very easy - just make a big surface, adjust grid settings, snap to grid and cut and paste. All for about 3 minutes...

It could be even easier in latest PSP versions where Photoshop-like action-recording/playing involved.
BIGBEN wrote:
I use Paint Shop Pro - arrange all frames in one file is very easy - just make a big surface, adjust grid settings, snap to grid and cut and paste. All for about 3 minutes...

I write small utility for gluing small sprites on to sprites sets. It supprort only tga file format (8, 16, 24, 32) but it helps me creating sprites sets. Some seconds instead minutes ;)
I can share it for free.
This utility has some bugs (i prefer say features ;)) but i do not plan to update it. I can share source code too (on source forge, for example).