I want to limit how many times love.update runs to 20 ticks a second but i don't want it to impact my FPS how would I do that?
This is what Minecraft does, it only updates player data 20 times a second but you get up to unlimited frames.
Limit updates per second?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Limit updates per second?
This is how I've gone about doing it, but why would you want to limit? Slow motion effect?
Code: Select all
if not focus then return end
if dt > 1/30 then
dt = 1/30
end
Re: Limit updates per second?
Are you sure?Bigmacbook wrote: This is what Minecraft does, it only updates player data 20 times a second but you get up to unlimited frames.
Stuff like position update must be done per frame, else it will not be smooth...
Minecraft may send the player data to the server 20 times per second, but I think that clientside player position is updated per frame, and this includes the remote players – though the position is not send from the server per frame, the client moves the players between the last known two positions by interpolating them and updating the positions per frame.
Also prove that updating position 20 times per secound is not smooth even with high fps:
Code: Select all
function love.load()
x = 200
y = 50
r = 10
speedx = 200
speedy = 200
end
local dt2 = 0
function love.update(dt)
dt2 = dt2 + dt
if dt2 >= 1/20 then
x = x - speedx * dt2
y = y - speedy * dt2
if (x + r >= 800) and speedx < 0 then
left = not left
speedx = 0 - speedx
elseif (x - r <= 0) and speedx > 0 then
left = not left
speedx = 0 - speedx
end
if (y + r >= 600) and speedy < 0 then
down = not down
speedy = 0 - speedy
elseif (y - r <= 0) and speedy > 0 then
down = not down
speedy = 0 - speedy
end
dt2 = 0
end
end
function love.draw()
love.graphics.circle("fill",x,y,r);
end
Re: Limit updates per second?
If you want to do it the minecraft way, like Wojak says, you can't just limit how often the update function runs, because that would mean that while you have lots of frames, nothing would actually happen in the extra frames, because all of the animations and such run in update, which isn't called.
Instead what you want is to have two update loops, one that only does animation work and one that updates everything else. I'm guessing if you really want this that you'd either:
A) modify love.run to work with 2 distinct update loops, one for animations and tweening and one for heavy update work
B) make a seperate thread that does the heavy updating, and pull data from it into the main update thread at a fixed rate
Instead what you want is to have two update loops, one that only does animation work and one that updates everything else. I'm guessing if you really want this that you'd either:
A) modify love.run to work with 2 distinct update loops, one for animations and tweening and one for heavy update work
B) make a seperate thread that does the heavy updating, and pull data from it into the main update thread at a fixed rate
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: Limit updates per second?
Code: Select all
local timer = 0
function love.update(dt)
timer = timer + dt
while timer >= 0.05 do
timer = timer - 0.05
updateRedstone()
end
end
Then you can have a player function still update every frame, so movement remains smooth.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Semrush [Bot] and 8 guests