Pre-load frames in memory

Hi!

I am doing a game. I want to pre-load all animations in memory at the
beginning of the game in order to have good performance.

I have a total of 36 animation of 80 frames to load (I use IMG_Load). Each
frame (jpg file) have 22K. It gives 1760 K per animation. But when a load an
animation, my memory goes down by 62 MB … 62 MB per animation… I have 36 !!!

Please help ! How can I do this pre-load ???

THANK !

talie wrote:

Hi!

I am doing a game. I want to pre-load all animations in memory at the
beginning of the game in order to have good performance.

I have a total of 36 animation of 80 frames to load (I use IMG_Load). Each
frame (jpg file) have 22K. It gives 1760 K per animation. But when a load an
animation, my memory goes down by 62 MB … 62 MB per animation… I have 36 !!!

Please help ! How can I do this pre-load ???

THANK !

Hi,

Firstly, JPG is probably a bad file format for your graphics, as it uses
a “lossy” compression algorthm so you lose image quality. Try PNG.

Secondly, the size of an image file on disk is not a representation of
how large it will be once loaded into a surface. For example a small 8
bit image (image with 256 colours) that is “loaded” into a 32 bit
surface will be much much larger in memory than on disk, due to the 32
bits rather than 8, that is used to store each pixel.

Check that you are not using surfaces that use far more colours than you
need. An 8 bit surface may be enough if you can keep your colour usage
down to 256 in your images. This will help to make the problem go away.

  • Tom

talie wrote:

Hi!

I am doing a game. I want to pre-load all animations in memory at the
beginning of the game in order to have good performance.

I have a total of 36 animation of 80 frames to load (I use IMG_Load). Each
frame (jpg file) have 22K. It gives 1760 K per animation. But when a load an
animation, my memory goes down by 62 MB … 62 MB per animation… I have 36 !!!

Please help ! How can I do this pre-load ???

THANK !

Another thing, try putting all of your images for an animation onto one
image, rather than an image for each frame.

The extra memory used for each Surface struct will soon add up if you
have 36 x 80 frames.

  • Tom

talie wrote:

I have a total of 36 animation of 80 frames to load (I use IMG_Load).
Each frame (jpg file) have 22K. It gives 1760 K per animation. But
when a load an animation, my memory goes down by 62 MB … 62 MB per
animation… I have 36 !!!

you know that jpg is a compressed iamge format?

SDL surfaces are stroing data as 32bit/16bit/8bit images. So it is only the
total pixel size of the images (not the file size) that you need to
calculte.
So if you have a 100x100 pixel and 32 bits per pixel then you will use more
than 312KB per image.

When you say frame, it makes me think that your image size is atleast
640x480. Usually games can have only 5-10 images of that size, using them as
backround. Having full screen animated images is not a good idea.> ----- Original Message -----

From: sdl-bounces+admin=windows-games.com@libsdl.org
[mailto:sdl-bounces+admin=windows-games.com at libsdl.org]On Behalf Of
talie
Sent: Sunday, June 12, 2005 4:16 PM
To: sdl at libsdl.org
Subject: [SDL] pre-load frames in memory

Hi!

I am doing a game. I want to pre-load all animations in memory at the
beginning of the game in order to have good performance.

I have a total of 36 animation of 80 frames to load (I use IMG_Load). Each
frame (jpg file) have 22K. It gives 1760 K per animation. But when a load
an
animation, my memory goes down by 62 MB … 62 MB per animation… I have 36
!!!

Please help ! How can I do this pre-load ???

THANK !


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Windows-Games wrote:

So if you have a 100x100 pixel and 32 bits per pixel then you will use more
than 312KB per image.

No, that’s wrong. In 32-bit, each pixel requires 4 bytes (32 / 8 = 4).
So, 100x100 32-bit would occupy 100 * 100 * 4 = 40000 bytes, about 39k.

Btw, note that because SDL 1.x uses 16-bit words for surface width and
height, you can’t have a surface wider than 16383 pixels, or higher than
65535 pixels. (There’s a bug in 1.2.8 that makes the height limit 16383
as well, but Sam’s fixed that in CVS). This might be a problem if
you’re putting many frames into the same surface.

  • Gerry

talie <cyber-girl cgocable.ca> writes:

Hi!

I am doing a game. I want to pre-load all animations in memory
at the
beginning of the game in order to have good performance.

I have a total of 36 animation of 80 frames to load (I use IMG_Load).
Each
frame (jpg file) have 22K. It gives 1760 K per animation.
But when a load an
animation, my memory goes down by 62 MB … 62 MB per animation…
I have 36 !!!

Please help ! How can I do this pre-load ???

THANK !

With the PNG format, it tooks me 176 MB
to load 1 animation (80 frames).
So it is worst. Now, I just think
to return to the JPG format,
and load 1 animation each time I need it,
but from memory with IMG_LoadRW…

Talie

With the PNG format, it tooks me 176 MB
to load 1 animation (80 frames).
So it is worst. Now, I just think
to return to the JPG format,
and load 1 animation each time I need it,
but from memory with IMG_LoadRW…

Talie

did you try 8 Bit PNG?

Hello,

I’m not an expert on how SDL stores RLE-compressed colour key data, but
the smallest format might be to pack all the frames onto one 8-bit
palettised surface, and call SDL_SetColorKey(surface, SDL_SRCCOLORKEY |
SDL_RLEACCEL, colourKey) on it.

I assume using RLE acceleration throws away the uncompressed data. (Of
course at some point both the compressed and uncompressed data will be
in memory at the same time, which could be a lot).

There are also various algorithms out there for packing lightmaps or
font characters onto surfaces and minimising the unused space.

At any rate, loading everything on startup seems to be a bit wasteful.
Perhaps some kind of background loading scheme could be used to load the
surrounding “rooms” (or whatever you call the areas of your map) so that
the data is ready when required. Kind of a “Just In Time” stock
management approach to loading data, instead of loading everything upfront.

But then it adds a whole lot of complexity to the problem -
multithreading, mutexes, which you probably don’t want to get into if
all you want to do is get your game finished.

Hope this helps.

Peter

P.S. I admit to not having read this thread from scratch, but what’s
wrong with a loading screen?

Tom Wilson wrote:>

With the PNG format, it tooks me 176 MB to load 1 animation (80
frames). So it is worst. Now, I just think to return to the JPG format,
and load 1 animation each time I need it, but from memory with
IMG_LoadRW…
Talie

did you try 8 Bit PNG?

Everything everyone else has said is good advice. But what about
something a bit more obvious… did you say 36 animations that are 80
frames each? Doesn’t this strike anyone else as being REALLY HUGE? I
rarely see games with specific animations that are more than 5 frames
in length. Though many games have many more animations than 36. And
usually these animations are very small in dimension. Talie, I
recommend rethinking your game. If you’re using lots of animations with
very large graphics, consider possibly using a vector graphic format,
so that your animations are merely point and line drawing data that can
be executed by your program using a library for drawing lines
(SDL_gfxPrimitives?)On Jun 12, 2005, at 12:18 PM, Talie wrote:

talie <cyber-girl cgocable.ca> writes:

Hi!

I am doing a game. I want to pre-load all animations in memory at the
beginning of the game in order to have good performance.

I have a total of 36 animation of 80 frames to load (I use IMG_Load).
Each
frame (jpg file) have 22K. It gives 1760 K per animation. But when a
load an
animation, my memory goes down by 62 MB … 62 MB per animation… I
have 36 !!!

Please help ! How can I do this pre-load ???

THANK !

With the PNG format, it tooks me 176 MB
to load 1 animation (80 frames).
So it is worst. Now, I just think
to return to the JPG format,
and load 1 animation each time I need it,
but from memory with IMG_LoadRW…

Talie


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl