From acad85f29e3064759a3e5d18aff9e5eafc1045f6 Mon Sep 17 00:00:00 2001 From: Rin Date: Sat, 21 Aug 2021 21:02:12 +0100 Subject: [PATCH] Add GameMode:fastUpdate --- main.lua | 6 ++++++ scene.lua | 1 + scene/game.lua | 4 ++++ tetris/modes/gamemode.lua | 7 +++++++ 4 files changed, 18 insertions(+) diff --git a/main.lua b/main.lua index bb45e20..0d73d78 100644 --- a/main.lua +++ b/main.lua @@ -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 diff --git a/scene.lua b/scene.lua index efa6d56..2f47b88 100644 --- a/scene.lua +++ b/scene.lua @@ -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 diff --git a/scene/game.lua b/scene/game.lua index 5bc08f0..75061d3 100644 --- a/scene/game.lua +++ b/scene/game.lua @@ -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 diff --git a/tetris/modes/gamemode.lua b/tetris/modes/gamemode.lua index 32caef7..2512d40 100644 --- a/tetris/modes/gamemode.lua +++ b/tetris/modes/gamemode.lua @@ -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