inexplicable slowdown in draw loop
Posted: Sun Apr 07, 2013 4:50 pm
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)
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.
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
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.