Skip to content

Commit

Permalink
Update for LÖVE 0.10.0;
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbytes committed Dec 25, 2015
1 parent 74b1b0a commit 07bcaf6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Usage

Copy the `tick.lua` file to a project directory and require it, which returns a table that includes all of the functionality.

```
```lua
local tick = require 'tick'

function love.load(arg)
Expand All @@ -27,9 +27,9 @@ These are simple variables that can be set on the `tick` table to change its beh

Sets the maximum number of frames per second that can occur. For example, setting framerate to 60 will limit the number of calls to `love.draw` to 60 per second. Can be set to -1 for unlimited framerate (the default).

- `tick.tickrate = .03`
- `tick.rate = .03`

Sets the tick rate of the fixed timestep model (in seconds per tick), which limits the number of calls to `love.update`. As a consequence, the `dt` argument passed to `love.update` will always be `tick.tickrate`. The default is 33 ticks per second.
Sets the tick rate of the fixed timestep model (in seconds per tick), which limits the number of calls to `love.update`. As a consequence, the `dt` argument passed to `love.update` will always be `tick.rate`. The default is 33 ticks per second.

- `tick.timescale = 1`

Expand All @@ -49,7 +49,7 @@ A read-only value representing the time elapsed since the last frame. This is *

- `tick.accum`

A read-only value representing an accumulation of time. In `love.draw` this will always be less than `tick.tickrate`.
A read-only value representing an accumulation of time. In `love.draw` this will always be less than `tick.rate`.

- `tick.tick`

Expand Down
31 changes: 14 additions & 17 deletions tick.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local tick = {
framerate = -1,
tickrate = .03,
framerate = nil,
rate = .03,
timescale = 1,
sleep = .001,
dt = 0,
Expand All @@ -15,53 +15,50 @@ local graphics = love.graphics
love.run = function()
if love.math then
love.math.setRandomSeed(os.time())
for i = 1, 3 do love.math.random() end
end

if love.event then love.event.pump() end
if love.load then love.load(arg) end
timer.step()
if timer then timer.step() end
local lastframe = 0

while true do
timer.step()
tick.dt = timer.getDelta() * tick.timescale
tick.accum = tick.accum + tick.dt
while tick.accum >= tick.tickrate do
tick.accum = tick.accum - tick.tickrate
while tick.accum >= tick.rate do
tick.accum = tick.accum - tick.rate

if love.event then
love.event.pump()
for e, a, b, c, d in love.event.poll() do
if e == 'quit' then
for name, a, b, c, d, e, f in love.event.poll() do
if name == 'quit' then
if not love.quit or not love.quit() then
if love.audio then love.audio.stop() end
return
return a
end
end

love.handlers[e](a, b, c, d)
love.handlers[name](a, b, c, d, e, f)
end
end

tick.tick = tick.tick + 1
if love.update then love.update(tick.tickrate) end
if love.update then love.update(tick.rate) end
end

while timer.getTime() - lastframe < 1 / tick.framerate do
while tick.framerate and timer.getTime() - lastframe < 1 / tick.framerate do
timer.sleep(.0005)
end

lastframe = timer.getTime()
if graphics and love.window and love.window.isCreated() then
graphics.clear()
if graphics and graphics.isActive() then
graphics.clear(graphics.getBackgroundColor())
graphics.origin()
tick.frame = tick.frame + 1
if love.draw then love.draw() end
graphics.present()
end

timer.sleep(tick.sleep)
if timer then timer.sleep(tick.sleep) end
end
end

Expand Down

0 comments on commit 07bcaf6

Please sign in to comment.