Page 1 of 1

Using own's FPS handler, but FPS still 60?

Posted: Wed Jun 14, 2017 10:17 am
by Ortimh
I replaced LOVE's internal code (which is love.run) with my own, but FPS still 60. Is it V-Sync in effect? Because I wonder if I could set the FPS more than 60, like 120. But I guess I'm asking something that has been asked like million times, right?

Code: Select all

...
Game.TimePerFrame = 1 / 30
...
function Game:run()
	lmath.setRandomSeed(os.time())
	
	local currentTime, previousTime = ltimer.getTime(), ltimer.getTime()
	local timeSinceLastUpdate = 0
	
	while lwindow.isOpen() do
		local deltaTime = currentTime - previousTime
		previousTime = currentTime
		currentTime = ltimer.getTime()
		timeSinceLastUpdate = timeSinceLastUpdate + deltaTime
		
		print(deltaTime) -- around 0.016666666666666666667 or 1 / 60
		
		while timeSinceLastUpdate > self.TimePerFrame do
			timeSinceLastUpdate = timeSinceLastUpdate - self.TimePerFrame
			
			self:_handleEvent()
			self:_update(self.TimePerFrame)
			
			if self._stateStack:isEmpty() then
				lwindow.close()
			end
		end
		
		self:_draw()
	end
end
No sleep, no step... just nothing. I wanted to follow wiki's sample, but I wanted to see what would happen if I use mine. If you're wondering, I followed SFML's code to handle FPS. Also if you need the LOVE file, I'll give it to you.

Re: Using own's FPS handler, but FPS still 60?

Posted: Wed Jun 14, 2017 11:33 am
by s-ol
Game:run? it looks like you are using a gamestate lib. Your gamestate lib won't handle :run(), since there can only be one infinite outer loop. Instead overload love.run directly.

Re: Using own's FPS handler, but FPS still 60?

Posted: Wed Jun 14, 2017 12:20 pm
by Ortimh
Oops, I didn't tell where Game:run is called, did I? It's basically called in love.run, but I guess I need to upload my LOVE then (small pun there). Edit: And... Game:run is in game.lua which is called by love.run in main.lua.

Re: Using own's FPS handler, but FPS still 60?

Posted: Wed Jun 14, 2017 1:20 pm
by zorg
Yes, it's vsync; if you have it enabled or you're not using threads, you can't have the game loop run faster than that; you can try turning off vsync and manually adjusting how fast you update and draw, using deltatime.

Re: Using own's FPS handler, but FPS still 60?

Posted: Wed Jun 14, 2017 1:31 pm
by Ortimh
Damn, I only could adjust the FPS at around 1-60, huh? So even though I don't use anything that block the while loop, V-Sync could still block it. Thanks!

Re: Using own's FPS handler, but FPS still 60?

Posted: Wed Jun 14, 2017 2:44 pm
by zorg
I mean, without vsync, you can get about 1000 fps, with the default love.run (love.timer.sleep(0.001) limits it to that), with vsync on, i believe love.graphics.present does the blocking (which you need, and can't avoid).