# Memory reduction

This topic is 4346 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, Probably you guys have experience with memory, since good old isometric games often had to be as small as possible on old systems. I'd like to know if there are some ways to bring down the size of my level files. A level is a 3D grid of 'cubes', kinda like GTA1/2. Each cube holds 5 faces (top,left, etc.), where each face has its own material. Furthermore, the cube uses a byte that describes the shape. Besides cubes, there are also slopes, walls, pillars, etc. The terrain is divided into what I call 'cells'. Each cell has 1 or more cubes stacked upon each other. So a cell has a byte that tells the height, and an array of cubes. When it comes down to the code, it looks something like this:

TFace = record
material  : Word; // unsigned int 16
end;

TCube = record
meshType : byte; // cube, slope, etctera.
face     : array[0..4] of TFace;
end;

TCell = record
height : byte;
stores : array of TCube; // height tells how big the array is
end;

TRaster = array of array of TCell; // 2D array with cells

It's Delphi code, but I think you get the idea. Now I'd like to store this stuff into a file, as small as possible. Now the size depends how many boxes are stacked. But let's say we have only 1 layer, the ground. And the raster is 100 x 100 cells. That would bring me to:
  cube_size = 5 faces(2 bytes each) + 1 byte = 11 bytes
cell_size, with 1 cube(store) = 11 + 1 = 12 bytes
raster    = 100 x 100 x 12 = ~117 kilobyte

It's not that much, but since these files need to be downloaded from internet, size really matters. I don't know how, but I have the feeling that it can be done smaller. I looked at some GTA2 levels (which are pretty big) and they were smaller in filesize I think. And probably those GTA2 'cubes' even had more properties, like the texture rotation. Most types are bytes, except the material. But probably there gonna be more than 256 materials. I could go bit-wise and remove some bits at some types... but I still don't think I can match with the GTA2 level sizes. How to shrink this? Greetings, Rick

##### Share on other sites
maybe you could look into some sort of compression. maybe you could do RLE or LZSS? I dont know...

##### Share on other sites
Why did that never came up into mind?! I tried to ZIP and RAR the file, for testing if it was worth it. 466 kb becomes 1 kb. That's exactly what I need, thanks for 'enlighten' me!

But... if somebody knows more tricks to reduce the memory, you're welcome! I'd like to know how to program this kind of stuff efficiently.

Greetings,
Rick

##### Share on other sites
Don't know any tricks for lowering your physical overhead. But when it comes to compression the best library I've found for Delphi is abbrevia: http://tpabbrevia.sourceforge.net/

It would help if you packed your record structures, and you could use custom stream read/write routines to lower space consumed in the cases where you don't fall on boundaries, but that would take quite a bit of work on your behalf.

- Jeremy