Skip to content

Commit

Permalink
flow.update() now requires dt
Browse files Browse the repository at this point in the history
This is required to make sure that delay respects dt when time_step is
manipulated
  • Loading branch information
Björn Ritzl committed Oct 10, 2016
1 parent 535d8db commit 1630d32
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/flow/flow.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function final(self)
end

function update(self, dt)
flow.update()
flow.update(dt)
end

function on_message(self, message_id, message, sender)
Expand Down
2 changes: 1 addition & 1 deletion examples/flow/flow.script
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function final(self)
end

function update(self, dt)
flow.update()
flow.update(dt)
end

function on_message(self, message_id, message, sender)
Expand Down
14 changes: 9 additions & 5 deletions ludobits/m/flow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ end
function M.delay(seconds)
assert(seconds, "You must provide a delay")
local instance = create_or_get(coroutine.running())
local now = socket.gettime()
instance.state = WAITING
instance.condition = function()
return socket.gettime() > (now + seconds)
instance.condition = function(dt)
seconds = seconds - dt
return seconds <= 0
end
return coroutine.yield()
end
Expand Down Expand Up @@ -323,7 +323,11 @@ end


--- Call this as often as needed (every frame)
function M.update()
function M.update(dt)
if not dt then
print("WARN: flow.update() now requires dt. Assuming 0.0167 for now.")
dt = 0.0167
end
local url = msg.url()
for co,instance in pairs(instances) do
if instance.url == url then
Expand All @@ -332,7 +336,7 @@ function M.update()
instances[co] = nil
else
if instance.state == WAITING and instance.condition then
if instance.condition() then
if instance.condition(dt) then
instance.condition = nil
instance.on_message = nil
instance.state = READY
Expand Down

0 comments on commit 1630d32

Please sign in to comment.