Page 1 of 1

inexplicable slowdown in draw loop

Posted: Sun Apr 07, 2013 4:50 pm
by yarlesp
Hi, I'm making a little strategy game about being a landlord in 19th century england. Right now I'm just trying to get the scrolling map working right. When the game was in a single file I didn't have problems, but when I re-designed the game to spread things out across several files I started running into serious slowdown issues. I can't click anywhere on my map without the game coming to a crawl. I think I've isolated the slowdown to this piece of code (when 'get_selected' returns nil the game runs smoothly) but I have some profiler output and the full source all the same.

This function is in main.lua and it calls a function in land.lua (land.get_selected)

Code: Select all

function draw_gui()
  love.graphics.print("IT IS "..season[game.season].." CORN: 0  SEED CORN: 2  POPULATION: 10", 10, 5, 0, 1, 1, 0, 0)
  if land.get_selected() then
    love.graphics.print( land.get_selected(), 10, (display_h * tile_height) - 20, 0, 1, 1, 0, 0) --get selected
  end
end
My guess is that it has something to do with the fact that I'm calling a function across two lua files, and I'm doing it a few times a second. I've thought about creating some sort of function that would pass the values back to main, where they would be stored as variables and then put into a string which would itself be passed to the gui function, so that the gui still gets drawn every second but it isn't constantly dereferencing. But that seems too complicated, surely it isn't supposed to be a huge deal to call a function from outside of its immediate context? I must be missing something obvious here. First week or so using lua btw so I'm sure it will be a bonehead mistake. Thanks for taking a look.

Here's the output from the profiler I had running, just for kicks: http://pastebin.com/raw.php?i=B0gXefP6

And I attached the game below. Left click to select a piece of land, right click to de-select, arrow keys to scroll around.

Re: inexplicable slowdown in draw loop

Posted: Sun Apr 07, 2013 5:18 pm
by Jackim
I don't get any slowdowns, what are your specs?

Re: inexplicable slowdown in draw loop

Posted: Sun Apr 07, 2013 5:42 pm
by yarlesp
win 7 64bit, 6gb ram, amd athalon x2 250, radeon 6800

but to be honest this code should run fine on a pentium 2. It doesn't seem that intense

Re: inexplicable slowdown in draw loop

Posted: Mon Apr 08, 2013 1:07 am
by Xgoff
i'd make sure your graphics drivers are updated, just to rule that out.

other than that, there's nothing immediately obvious as to what would cause that much slowdown. i'd watch your variable usage in the land.lua file; you have a ton of globals that probably should go into the land table instead

Re: inexplicable slowdown in draw loop

Posted: Mon Apr 08, 2013 7:13 am
by Plu
I'm running much lower specs and it's going fine with no slowdown on anything. Might very well be a driver issue.

Re: inexplicable slowdown in draw loop

Posted: Mon Apr 08, 2013 11:00 pm
by yarlesp
Well the driver update did actually solve the problem. Thanks guys. Hopefully next time I'll have a more interesting question.