34 lines
842 B
Lua
34 lines
842 B
Lua
|
local ThreadNode = Node:extend('ThreadNode', {
|
||
|
threadFile = nil,
|
||
|
threadChannel = nil,
|
||
|
updateInterval = 5,
|
||
|
lastUpdate = 0,
|
||
|
state = nil,
|
||
|
})
|
||
|
|
||
|
function ThreadNode:update(dt)
|
||
|
if not self.state then self:checkUpdate() end
|
||
|
end
|
||
|
|
||
|
function ThreadNode:checkUpdate()
|
||
|
if self.threadFile and self.threadChannel then
|
||
|
if self.lastUpdate < love.timer.getTime() - self.updateInterval or
|
||
|
(not self.state and self.lastUpdate < love.timer.getTime() - 5) then
|
||
|
self.lastUpdate = love.timer.getTime()
|
||
|
print(self.threadChannel, "Updating...")
|
||
|
|
||
|
local updateThread = love.thread.newThread(self.threadFile)
|
||
|
updateThread:start()
|
||
|
end
|
||
|
|
||
|
self.state = love.thread.getChannel(self.threadChannel):pop() or self.state
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function ThreadNode:afterExit()
|
||
|
print('exit')
|
||
|
self:checkUpdate()
|
||
|
end
|
||
|
|
||
|
return ThreadNode
|