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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Ortimh
Citizen
Posts: 90
Joined: Tue Sep 09, 2014 5:07 am
Location: Indonesia

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

Post by Ortimh » Wed Jun 14, 2017 10:17 am

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.

User avatar
s-ol
Party member
Posts: 1076
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

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

Post by s-ol » Wed Jun 14, 2017 11:33 am

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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end

User avatar
Ortimh
Citizen
Posts: 90
Joined: Tue Sep 09, 2014 5:07 am
Location: Indonesia

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

Post by Ortimh » Wed Jun 14, 2017 12:20 pm

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.
Attachments
Template.love
My LOVE
(8.53 KiB) Downloaded 20 times

User avatar
zorg
Party member
Posts: 2325
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post by zorg » Wed Jun 14, 2017 1:20 pm

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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

User avatar
Ortimh
Citizen
Posts: 90
Joined: Tue Sep 09, 2014 5:07 am
Location: Indonesia

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

Post by Ortimh » Wed Jun 14, 2017 1:31 pm

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!

User avatar
zorg
Party member
Posts: 2325
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post by zorg » Wed Jun 14, 2017 2:44 pm

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).
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Post Reply

Who is online

Users browsing this forum: Google [Bot], pragmaticus and 8 guests