mirror of
https://github.com/rayaman/multi.git
synced 2026-09-05 07:27:35 -04:00
Working on issue with love threaded functions not waiting when in a thread
This commit is contained in:
@@ -20,8 +20,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
]]
|
||||
if ISTHREAD then
|
||||
]] if ISTHREAD then
|
||||
error("You cannot require the loveManager from within a thread!")
|
||||
end
|
||||
local ThreadFileData = [[
|
||||
@@ -49,50 +48,46 @@ local multi, thread = require("multi"):init()
|
||||
local THREAD = {}
|
||||
__THREADID__ = 0
|
||||
__THREADNAME__ = "MainThread"
|
||||
multi.integration={}
|
||||
multi.integration = {}
|
||||
local THREAD = require("multi.integration.loveManager.threads")
|
||||
local GLOBAL = THREAD.getGlobal()
|
||||
local THREAD_ID = 1
|
||||
local OBJECT_ID = 0
|
||||
local stf = 0
|
||||
|
||||
function multi:newSystemThread(name,func,...)
|
||||
function multi:newSystemThread(name, func, ...)
|
||||
local c = {}
|
||||
c.name = name
|
||||
c.ID=THREAD_ID
|
||||
c.thread=love.thread.newThread(ThreadFileData)
|
||||
c.thread:start(THREAD.dump(func),c.ID,c.name,...)
|
||||
c.stab = THREAD.createStaticTable(name)
|
||||
c.OnDeath = multi:newConnection()
|
||||
c.OnError = multi:newConnection()
|
||||
GLOBAL["__THREAD_"..c.ID] = {ID=c.ID, Name=c.name, Thread=c.thread}
|
||||
c.ID = THREAD_ID
|
||||
c.thread = love.thread.newThread(ThreadFileData)
|
||||
c.thread:start(THREAD.dump(func), c.ID, c.name, ...)
|
||||
c.stab = THREAD.createStaticTable(name .. c.ID)
|
||||
c.OnDeath = multi:newConnection()
|
||||
c.OnError = multi:newConnection()
|
||||
GLOBAL["__THREAD_" .. c.ID] = {ID = c.ID, Name = c.name, Thread = c.thread}
|
||||
GLOBAL["__THREAD_COUNT"] = THREAD_ID
|
||||
THREAD_ID=THREAD_ID + 1
|
||||
function c:getName()
|
||||
return c.name
|
||||
end
|
||||
THREAD_ID = THREAD_ID + 1
|
||||
function c:getName() return c.name end
|
||||
thread:newThread(function()
|
||||
if name == "TempSystemThread" then
|
||||
local status_channel = love.thread.getChannel("__"..c.ID.."__MULTI__STATUS_CHANNEL__")
|
||||
local status_channel = love.thread.getChannel("STATCHAN_" .. c.ID)
|
||||
thread.hold(function()
|
||||
-- While the thread is running we might as well do something in the loop
|
||||
local status = status_channel
|
||||
if status:peek()~=nil then
|
||||
if status:peek() ~= nil then
|
||||
c.statusconnector:Fire(unpack(status:pop()))
|
||||
end
|
||||
return not c.thread:isRunning()
|
||||
end)
|
||||
else
|
||||
thread.hold(function()
|
||||
return not c.thread:isRunning()
|
||||
end)
|
||||
thread.hold(function() return not c.thread:isRunning() end)
|
||||
end
|
||||
-- If the thread is not running let's handle that.
|
||||
local thread_err = c.thread:getError()
|
||||
if thread_err == "Thread Killed!\1" then
|
||||
c.OnDeath:Fire("Thread Killed!")
|
||||
elseif thread_err then
|
||||
c.OnError:Fire(c,thread_err)
|
||||
c.OnError:Fire(c, thread_err)
|
||||
elseif c.stab.returns then
|
||||
c.OnDeath:Fire(unpack(c.stab.returns))
|
||||
c.stab.returns = nil
|
||||
@@ -102,21 +97,19 @@ function multi:newSystemThread(name,func,...)
|
||||
end
|
||||
|
||||
function THREAD:newFunction(func, holdme)
|
||||
return thread:newFunctionBase(function(...)
|
||||
return multi:newSystemThread("TempSystemThread", func, ...)
|
||||
end, holdme)()
|
||||
return thread:newFunctionBase(function(...)
|
||||
return multi:newSystemThread("TempSystemThread", func, ...)
|
||||
end, holdme)()
|
||||
end
|
||||
|
||||
THREAD.newSystemThread = multi.newSystemThread
|
||||
|
||||
function love.threaderror(thread, errorstr)
|
||||
multi.print("Thread error!\n"..errorstr)
|
||||
multi.print("Thread error!\n" .. errorstr)
|
||||
end
|
||||
|
||||
multi.integration.GLOBAL = GLOBAL
|
||||
multi.integration.THREAD = THREAD
|
||||
require("multi.integration.loveManager.extensions")
|
||||
multi.print("Integrated Love Threading!")
|
||||
return {init=function()
|
||||
return GLOBAL,THREAD
|
||||
end}
|
||||
return {init = function() return GLOBAL, THREAD end}
|
||||
|
||||
Reference in New Issue
Block a user