-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.0.0b] Fixed tick rate error by using https://github.com/bjornbytes…
- Loading branch information
Showing
4 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
-- tick | ||
-- https://github.com/bjornbytes/tick | ||
-- MIT License | ||
|
||
local tick = { | ||
framerate = nil, | ||
rate = .03, | ||
timescale = 1, | ||
sleep = .001, | ||
dt = 0, | ||
accum = 0, | ||
tick = 1, | ||
frame = 1 | ||
} | ||
|
||
local timer = love.timer | ||
local graphics = love.graphics | ||
|
||
love.run = function() | ||
if not timer then | ||
error('love.timer is required for tick') | ||
end | ||
|
||
if love.load then love.load(love.arg.parseGameArguments(arg), arg) end | ||
timer.step() | ||
local lastframe = 0 | ||
|
||
if love.update then love.update(0) end | ||
|
||
return function() | ||
tick.dt = timer.step() * tick.timescale | ||
tick.accum = tick.accum + tick.dt | ||
while tick.accum >= tick.rate do | ||
tick.accum = tick.accum - tick.rate | ||
|
||
if love.event then | ||
love.event.pump() | ||
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 | ||
return a or 0 | ||
end | ||
end | ||
|
||
love.handlers[name](a, b, c, d, e, f) | ||
end | ||
end | ||
|
||
tick.tick = tick.tick + 1 | ||
if love.update then love.update(tick.rate) end | ||
end | ||
|
||
while tick.framerate and timer.getTime() - lastframe < 1 / tick.framerate do | ||
timer.sleep(.0005) | ||
end | ||
|
||
lastframe = timer.getTime() | ||
if graphics and graphics.isActive() then | ||
graphics.origin() | ||
graphics.clear(graphics.getBackgroundColor()) | ||
tick.frame = tick.frame + 1 | ||
if love.draw then love.draw() end | ||
graphics.present() | ||
end | ||
|
||
timer.sleep(tick.sleep) | ||
end | ||
end | ||
|
||
return tick |