PocketMatrix forums

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

Surface size : memory requirements

Hi, a bit of a newbie question here.

I need to be able to scroll right to left indefinitely.

I'm currently using a full screen surface that continues to be resized as the surface width requirements increase. As this happens I can see that the memory requirements continue to grow as well, which obviously, is a limited resource.

I'm not developing a game, but I suspect any side scroller might have the same issues. Is there a limit to how large a surface can be, or, is there a way to limit the memory requirements for off screen drawing?

I'm currently testing this as a stationary pc application on XP.

Thanks.
Hi NamGMan,

We recommend tiling of different surfaces when you need to scroll. For example, in a sidescroller the screen consists of tiles of 16x16 pixels and uses them to build up the screen. This way there is no need to have an extra large surface in memory.

For your application you may want to create bigger tiles (for example 256x256 pixels) and load/reload depending on the area that is currently visible.
Ok I see. I've read up a bit on tiling now and its making a lot of sense.

thanks :)
Hi,

I've tried to use 16x16 tiles for my background but I'm finding that the CPU usage is seemingly quite high, around 60% for a solid blue screen at 480x640 with 30 fps. If I up the limit on fps to 60, then the CPU usage jumps to 99%

Here is the routine that I'm testing. Pretty basic.

Code:

int surWid = this->surface->GetWidth();
int cols = width/surWid;
int surHei = this->surface->GetHeight();
int rows = height/surHei;

for (int i = 0; i < rows; i ++) {
for ( int j = 0; j < cols; j++) {
backSurface->BltFast(j*surWid,i*surHei,this->surface.get(),0);
}
}
}


If I change the surface size to 480x640 the CPU usage drops to ~2%. Of course then the memory usage goes up.

So are these numbers to be expected? If so, does that mean that I need to try and find a middle ground between memory and cpu? I have read some articles about tiling and it seems like my code is inline with the concepts, at least in a basic sense.


Thanks.
Hi NamGMan,

Drawing several small tiles is usually slower than drawing a big surface at once. I recommend doing several tests and see which tilesize works best for you.

In your test I recommend turning smartfps off, set maxfps to zero and display an fps counter (use the GetFPS() method of the framework to easily retrieve the fps value). In our own experiences, 32x32 is a good tilesize for a resolution of 480x640.