Why dt? [QUESTIONS ANSWERED, RESUME YOUR DAILY LIVES]

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: Why dt?

Post by Puzzlem00n »

Yup, I think I've got my head around it.

It's a funny thing, I've been pretty good with programming for a little less than a year now (and been trying to be good even longer) yet there seems to always be something new coming up that I don't know. I've been able to code an (albeit glitchy) rudimentary platformer engine in a day for months, yet I'm only getting this now.

Of course, I suppose I never really tried to learn the back-end stuff, anyway. I've been focusing on the code I have to write. If you asked me to explain how LÖVE works internally, I'd tell you I never really looked in to it. Maybe I should try and get a better understanding of this stuff.

I guess the chosen framerate works for Flash because trying to take advantage of as much framerate as possible would just slow it back down... Such is the way of browser games.
I LÖVE, therefore I am.
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Why dt?

Post by Inny »

I meant to say that a more complex timer could be created. Without having to overwrite love.run, you can do this in love.update

Code: Select all

local clock = 0
local rate = 1.0 / 30
local skip = rate * 2

function love.update(dt)
  if dt > skip then dt = skip end -- discard system hiccups

  clock = clock + dt
  while clock > rate do
    clock = clock - rate

    MyGame:update() -- your fixed rate logic here

  end
end
This clock has a fixed 30fps rate, and a single frameskip in order to catchup a bit. Since no logic should be happening in love.draw, it'll end up redrawing the same static frame over and over. This isn't really a problem, unless you're doing some complex drawing. Maybe look into canvases if you are.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Why dt?

Post by Nixola »

I HATE flash games because, as a netbook user, I'll never be able to play one at full speed.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Why dt?

Post by T-Bone »

If it ain't broke, don't fix it. The dt way works great on all platforms on both slow and fast computers. And it's really simple to use.
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: Why dt?

Post by Puzzlem00n »

T-Bone wrote:If it ain't broke, don't fix it. The dt way works great on all platforms on both slow and fast computers. And it's really simple to use.
Like I said, I had sort of anticipated from the beginning that there was something I wasn't getting, and for these reason, I never called for fixing it, and now I know.
Nixola wrote:I HATE flash games because, as a netbook user, I'll never be able to play one at full speed.
That's quite a shame. A lot of the best games I've ever played were in flash. (I have strange tastes. Call me hipster. :cool:)




Well, thank you to everyone for what's been said here. I've really learned a lot.
I LÖVE, therefore I am.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Why dt?

Post by Nixola »

The worst thing about flash games is that I like many of them, but I'm not able to play them here >.<
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Why dt?

Post by Ref »

Now that I finally figured out (with help) how to load a modified love.run, I can now easily set a fixed frame rate from within my script. Sure, if drawing takes longer than the frame rate, the script will run without any additional delay.
To use, all that is needed is to add:

Code: Select all

require 'love_run'
and anywhere in your script you can change the frame rate (on the fly) by:

Code: Select all

frame_rate = desired frames per second
love.Enable('fps', frame_rate)
and to run at maximum frame rate:

Code: Select all

love.Disable('fps')
(Also enable 'love.Enable('clear_draw') and love.Disable('clear_draw') -see attached file)
Attachments
love_run_mod.love
bastardize love.run example
(1.6 KiB) Downloaded 66 times
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: Why dt?

Post by Puzzlem00n »

Ref wrote:Now that I finally figured out (with help) how to load a modified love.run, I can now easily set a fixed frame rate from within my script. Sure, if drawing takes longer than the frame rate, the script will run without any additional delay.
To use, all that is needed is to add:

Code: Select all

require 'love_run'
and anywhere in your script you can change the frame rate (on the fly) by:

Code: Select all

frame_rate = desired frames per second
love.Enable('fps', frame_rate)
and to run at maximum frame rate:

Code: Select all

love.Disable('fps')
(Also enable 'love.Enable('clear_draw') and love.Disable('clear_draw') -see attached file)
So this basically sets it up as a fixed rate environment, like Flash? Hmm...

I'm getting some mixed responses here. I sort of thought it was over after everyone explained why dt is a better solution... Now I'm getting ways to implement fixed rate. To be clear, I don't need this code. It would be fun to experiment with... But I can't see myself needing to modify love.run. There is a small chance I may want to use Inny's second code example some day, but I don't even really need it, either.

So, despite your work being very, very cool, I can't guarantee it will be put to use. I'm very sorry if you thought I was intent on making a fixed rate game, and you thought I wanted someone to make this for me. I just wanted someone to explain things.
I LÖVE, therefore I am.
Post Reply

Who is online

Users browsing this forum: No registered users and 38 guests