Skip to content

Commit 1630d32

Browse files
author
Björn Ritzl
committed
flow.update() now requires dt
This is required to make sure that delay respects dt when time_step is manipulated
1 parent 535d8db commit 1630d32

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

examples/flow/flow.gui_script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function final(self)
1717
end
1818

1919
function update(self, dt)
20-
flow.update()
20+
flow.update(dt)
2121
end
2222

2323
function on_message(self, message_id, message, sender)

examples/flow/flow.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function final(self)
102102
end
103103

104104
function update(self, dt)
105-
flow.update()
105+
flow.update(dt)
106106
end
107107

108108
function on_message(self, message_id, message, sender)

ludobits/m/flow.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ end
133133
function M.delay(seconds)
134134
assert(seconds, "You must provide a delay")
135135
local instance = create_or_get(coroutine.running())
136-
local now = socket.gettime()
137136
instance.state = WAITING
138-
instance.condition = function()
139-
return socket.gettime() > (now + seconds)
137+
instance.condition = function(dt)
138+
seconds = seconds - dt
139+
return seconds <= 0
140140
end
141141
return coroutine.yield()
142142
end
@@ -323,7 +323,11 @@ end
323323

324324

325325
--- Call this as often as needed (every frame)
326-
function M.update()
326+
function M.update(dt)
327+
if not dt then
328+
print("WARN: flow.update() now requires dt. Assuming 0.0167 for now.")
329+
dt = 0.0167
330+
end
327331
local url = msg.url()
328332
for co,instance in pairs(instances) do
329333
if instance.url == url then
@@ -332,7 +336,7 @@ function M.update()
332336
instances[co] = nil
333337
else
334338
if instance.state == WAITING and instance.condition then
335-
if instance.condition() then
339+
if instance.condition(dt) then
336340
instance.condition = nil
337341
instance.on_message = nil
338342
instance.state = READY

0 commit comments

Comments
 (0)