Anyways, in looking for a solution to his lag (I can't even get the game to lag on my machine), I saw this map has around 1,500 32x32 terrain block objects. In our engine, like many engines, these blocks are not visible and have no events. We've always had a large number of objects like this so I figured I should try, again, to fix it.
I decided this time to compress all the blocks into two objects: a block and a slope.
This is my code:
//Create surfaces
_blocks = surface_create(room_width, room_height);
_slopes = surface_create(room_width, room_height);
//Go through the terrain objects
with objSolid{
if (object_index = objBlock){ //normal 32x32 block
surface_set_target(other._blocks); //set drawing target to the block surface
draw_sprite(sprite_index, 0, x, y); //draw 32x32 block
instance_destroy(); //destroy unneeded block object
}
if (object_index = objSlope_left || object_index = objSlope_right){ //slopes
surface_set_target(other._slopes);
draw_sprite(sprite_index, 0, x, y);
instance_destroy();
}
}
surface_reset_target(); //set normal drawing mode
//create a sprite for the new block object
_spr = sprite_create_from_surface(_blocks, 0, 0, room_width, room_height, 0, 0, 0, 0);
//create the block and set the sprite
(instance_create(0, 0, objBlock)).sprite_index = _spr;
//same for slopes
_spr = sprite_create_from_surface(_slopes, 0, 0, room_width, room_height, 0, 0, 0, 0);
(instance_create(0, 0, objSlope)).sprite_index = _spr;
//free the unneeded surfaces
surface_free(_blocks);
surface_free(_slopes);Which reduces the object count by around 1,500 with a memory impact (two 5000x5000 sprites). I know I can trim a few thousand pixels from the sprites but I'll wait for the other coder to see how his PC handles this script before I go into it further.
Memory*:
18.993152mb, before
19.857408mb, after
*Note: cleanmem dll is run after this script
So, this reduces the object count by 1,500 but I don't know how well this code will run on other computers. Any thoughts on the method I'm using?
Edited by Killpill, 08 May 2012 - 05:09 AM.











