Cleanly removing everything?
Posted: Mon Jun 25, 2012 4:17 pm
I wanted to double check if my methods to clean memory were correct.
Basically I just have a couple of arrays that hold everything in the game, from fonts to images to objects. And all I do to clean memory it set them all to nil.
But some objects have properties or possibly other objects inside of them. For example:
And ob is automatically added to my "RenderArray" when it is created. So when I set RenderArray to nil, I don't have to worry about any of that?
--------------------------------------------------
While we're on the topic of memory, I'm trying to make my game as lag free as possible while at the same time having huge levels.
I noticed I had some lag with about ~2000 or so tiles in my game, not all displayed at once. After some testing I discovered I could get about 50k moving tiles in a separate file at 60 fps by simply not rendering those offscreen.
Going back to my game however, with 2k tiles it seems like the entire process of rendering is negligible to performance. On my laptop the game currently works at 50 fps, and removing the rendering, it's still at 50 fps. Removing the function that loops through the rendering array brings the fps up to 55. Why would a simple loop do that? This is all the code of the loop below:
Any general optimization tips would also be welcome!
Basically I just have a couple of arrays that hold everything in the game, from fonts to images to objects. And all I do to clean memory it set them all to nil.
But some objects have properties or possibly other objects inside of them. For example:
Code: Select all
--Creating a game object
local ob = GameObject:init(0,0,"Images/Test.png")
print(ob.x) -- outputs the x
print(ob.sprite) -- outputs the image used to draw this object
--------------------------------------------------
While we're on the topic of memory, I'm trying to make my game as lag free as possible while at the same time having huge levels.
I noticed I had some lag with about ~2000 or so tiles in my game, not all displayed at once. After some testing I discovered I could get about 50k moving tiles in a separate file at 60 fps by simply not rendering those offscreen.
Going back to my game however, with 2k tiles it seems like the entire process of rendering is negligible to performance. On my laptop the game currently works at 50 fps, and removing the rendering, it's still at 50 fps. Removing the function that loops through the rendering array brings the fps up to 55. Why would a simple loop do that? This is all the code of the loop below:
Code: Select all
for i=1,max,1 do
local obj = renderArray[i]
if (obj.b2Object ~= nil) then
obj.b2Object.body:applyForce(0,obj.b2Object.gravityPull * gravity * 10)
obj.x = obj.b2Object.body:getX()
obj.y = obj.b2Object.body:getY()
obj.angle = obj.b2Object.body:getAngle() ;
end
local x,y = cam:worldCoords(obj.x,obj.y,scrW,scrH)
if(math.abs(camx - x) < 10000 and math.abs(camy - y) < 10000) then
obj:render()
end
end