Add GameMode:fastUpdate

This commit is contained in:
Rin 2021-08-21 21:02:12 +01:00
parent 33b69abbb8
commit acad85f29e
4 changed files with 18 additions and 0 deletions

View File

@ -381,7 +381,13 @@ function love.run()
if u_tacc >= 1 / TARGET_UPS then
runsystem.updatefps = 1 / u_tacc
if scene and scene.fastUpdate then
scene:fastUpdate(u_tacc)
end
u_tacc = 0
love.event.pump()
for n, a, b, c, d, e, f in love.event.poll() do
if n == 'quit' then

View File

@ -4,6 +4,7 @@ Scene = Object:extend()
function Scene:new() end
function Scene:update() end
function Scene:fastUpdate(dt) end -- Equivalent to GameMode:fastUpdate(dt)
function Scene:render() end
function Scene:onInputPress() end
function Scene:onInputRelease() end

View File

@ -45,6 +45,10 @@ function GameScene:render()
self.game:draw(self.paused)
end
function GameScene:fastUpdate(d)
self.game:fastUpdate(d) -- Propagate the fast updates
end
function GameScene:onInputPress(e)
if (
self.game.game_over or self.game.completed

View File

@ -952,4 +952,11 @@ function GameMode:provideSettings()
return {}
end
-- This function is called on every love.event.poll
-- aka up to the UPS specified in main.lua.
-- By default this is 1000, so this function will run
-- up to 1000 times per second! Don't do anything
-- expensive in here, as this WILL slow the game down.
function GameMode:fastUpdate(deltaTime) end
return GameMode