Fixed love2d STCs! Actually before new years :P
This commit is contained in:
parent
7ea6873c1f
commit
ec5bf74009
@ -27,7 +27,8 @@ if not ISTHREAD then
|
|||||||
GLOBAL = multi.integration.GLOBAL
|
GLOBAL = multi.integration.GLOBAL
|
||||||
THREAD = multi.integration.THREAD
|
THREAD = multi.integration.THREAD
|
||||||
else
|
else
|
||||||
|
GLOBAL = multi.integration.GLOBAL
|
||||||
|
THREAD = multi.integration.THREAD
|
||||||
end
|
end
|
||||||
|
|
||||||
function multi:newSystemThreadedQueue(name)
|
function multi:newSystemThreadedQueue(name)
|
||||||
@ -218,17 +219,17 @@ function multi:newSystemThreadedConnection(name)
|
|||||||
c.PING = 0x02
|
c.PING = 0x02
|
||||||
c.PONG = 0x03
|
c.PONG = 0x03
|
||||||
|
|
||||||
local subscribe = multi:newSystemThreadedQueue("SUB_STC_" .. name):init()
|
local subscribe = love.thread.getChannel("SUB_STC_" .. name)
|
||||||
|
|
||||||
function c:init()
|
function c:init()
|
||||||
|
|
||||||
self.subscribe = THREAD.waitFor("SUB_STC_" .. self.Name):init()
|
self.subscribe = love.thread.getChannel("SUB_STC_" .. self.Name)
|
||||||
|
|
||||||
function self:Fire(...)
|
function self:Fire(...)
|
||||||
local args = {...}
|
local args = {...}
|
||||||
if self.CID == THREAD.getID() then -- Host Call
|
if self.CID == THREAD.getID() then -- Host Call
|
||||||
for _, link in pairs(self.links) do
|
for _, link in pairs(self.links) do
|
||||||
link:push{self.TRIG, args}
|
love.thread.getChannel(link):push{self.TRIG, args}
|
||||||
end
|
end
|
||||||
self.proxy_conn:Fire(...)
|
self.proxy_conn:Fire(...)
|
||||||
else
|
else
|
||||||
@ -245,7 +246,7 @@ function multi:newSystemThreadedConnection(name)
|
|||||||
thread:newThread("STC_CONN_MAN" .. self.Name,function()
|
thread:newThread("STC_CONN_MAN" .. self.Name,function()
|
||||||
local item
|
local item
|
||||||
local string_self_ref = "LSF_" .. multi.randomString(16)
|
local string_self_ref = "LSF_" .. multi.randomString(16)
|
||||||
local link_self_ref = multi:newSystemThreadedQueue():init()
|
local link_self_ref = love.thread.getChannel(string_self_ref)
|
||||||
self.subscribe:push{self.CONN, string_self_ref}
|
self.subscribe:push{self.CONN, string_self_ref}
|
||||||
while true do
|
while true do
|
||||||
item = thread.hold(function()
|
item = thread.hold(function()
|
||||||
@ -256,7 +257,7 @@ function multi:newSystemThreadedConnection(name)
|
|||||||
link_self_ref:pop()
|
link_self_ref:pop()
|
||||||
elseif item[1] == self.CONN then
|
elseif item[1] == self.CONN then
|
||||||
if string_self_ref ~= item[2] then
|
if string_self_ref ~= item[2] then
|
||||||
table.insert(self.links, THREAD.waitFor(item[2]):init())
|
table.insert(self.links, love.thread.getChannel(item[2]))
|
||||||
end
|
end
|
||||||
link_self_ref:pop()
|
link_self_ref:pop()
|
||||||
elseif item[1] == self.TRIG then
|
elseif item[1] == self.TRIG then
|
||||||
@ -286,7 +287,7 @@ function multi:newSystemThreadedConnection(name)
|
|||||||
local ping
|
local ping
|
||||||
local pong = function(link, links)
|
local pong = function(link, links)
|
||||||
local res = thread.hold(function()
|
local res = thread.hold(function()
|
||||||
return link:peek()[1] == c.PONG
|
return love.thread.getChannel(link):peek()[1] == c.PONG
|
||||||
end,{sleep=3})
|
end,{sleep=3})
|
||||||
|
|
||||||
if not res then
|
if not res then
|
||||||
@ -297,7 +298,7 @@ function multi:newSystemThreadedConnection(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
link:pop()
|
love.thread.getChannel(link):pop()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -305,8 +306,8 @@ function multi:newSystemThreadedConnection(name)
|
|||||||
ping:Pause()
|
ping:Pause()
|
||||||
|
|
||||||
multi.ForEach(self.links, function(link) -- Sync new connections
|
multi.ForEach(self.links, function(link) -- Sync new connections
|
||||||
link:push{self.PING}
|
love.thread.getChannel(link):push{self.PING}
|
||||||
multi:newThread("pong Thread", pong, link, links)
|
multi:newThread("pong Thread", pong, link, self.links)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
thread.sleep(3)
|
thread.sleep(3)
|
||||||
@ -316,7 +317,7 @@ function multi:newSystemThreadedConnection(name)
|
|||||||
|
|
||||||
local function fire(...)
|
local function fire(...)
|
||||||
for _, link in pairs(c.links) do
|
for _, link in pairs(c.links) do
|
||||||
link:push {c.TRIG, {...}}
|
love.thread.getChannel(link):push {c.TRIG, {...}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -330,11 +331,12 @@ function multi:newSystemThreadedConnection(name)
|
|||||||
return c.subscribe:pop()
|
return c.subscribe:pop()
|
||||||
end)
|
end)
|
||||||
if item[1] == c.CONN then
|
if item[1] == c.CONN then
|
||||||
|
|
||||||
multi.ForEach(c.links, function(link) -- Sync new connections
|
multi.ForEach(c.links, function(link) -- Sync new connections
|
||||||
THREAD.waitFor(item[2]):init():push{c.CONN, link.Name}
|
love.thread.getChannel(item[2]):push{c.CONN, link}
|
||||||
end)
|
end)
|
||||||
print("Adding link")
|
c.links[#c.links+1] = item[2]
|
||||||
c.links[#c.links+1] = THREAD.waitFor(item[2]):init()
|
|
||||||
elseif item[1] == c.TRIG then
|
elseif item[1] == c.TRIG then
|
||||||
fire(unpack(item[2]))
|
fire(unpack(item[2]))
|
||||||
c.proxy_conn:Fire(unpack(item[2]))
|
c.proxy_conn:Fire(unpack(item[2]))
|
||||||
|
|||||||
@ -26,16 +26,23 @@ if ISTHREAD then
|
|||||||
end
|
end
|
||||||
local ThreadFileData = [[
|
local ThreadFileData = [[
|
||||||
ISTHREAD = true
|
ISTHREAD = true
|
||||||
THREAD = require("multi.integration.loveManager.threads") -- order is important!
|
THREAD = require("multi.integration.loveManager.threads")
|
||||||
sThread = THREAD
|
sThread = THREAD
|
||||||
__IMPORTS = {...}
|
__IMPORTS = {...}
|
||||||
__FUNC__=table.remove(__IMPORTS,1)
|
__FUNC__=table.remove(__IMPORTS,1)
|
||||||
__THREADID__=table.remove(__IMPORTS,1)
|
__THREADID__=table.remove(__IMPORTS,1)
|
||||||
__THREADNAME__=table.remove(__IMPORTS,1)
|
__THREADNAME__=table.remove(__IMPORTS,1)
|
||||||
|
math.randomseed(__THREADID__)
|
||||||
|
math.random()
|
||||||
|
math.random()
|
||||||
|
math.random()
|
||||||
stab = THREAD.createStaticTable(__THREADNAME__)
|
stab = THREAD.createStaticTable(__THREADNAME__)
|
||||||
GLOBAL = THREAD.getGlobal()
|
GLOBAL = THREAD.getGlobal()
|
||||||
multi, thread = require("multi").init()
|
multi, thread = require("multi").init()
|
||||||
print(pcall(require,"multi.integration.loveManager.extensions"))
|
multi.integration={}
|
||||||
|
multi.integration.GLOBAL = GLOBAL
|
||||||
|
multi.integration.THREAD = THREAD
|
||||||
|
pcall(require,"multi.integration.loveManager.extensions")
|
||||||
stab["returns"] = {THREAD.loadDump(__FUNC__)(unpack(__IMPORTS))}
|
stab["returns"] = {THREAD.loadDump(__FUNC__)(unpack(__IMPORTS))}
|
||||||
]]
|
]]
|
||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
@ -43,7 +50,6 @@ local THREAD = {}
|
|||||||
__THREADID__ = 0
|
__THREADID__ = 0
|
||||||
__THREADNAME__ = "MainThread"
|
__THREADNAME__ = "MainThread"
|
||||||
multi.integration={}
|
multi.integration={}
|
||||||
multi.integration.love2d={}
|
|
||||||
local THREAD = require("multi.integration.loveManager.threads")
|
local THREAD = require("multi.integration.loveManager.threads")
|
||||||
local GLOBAL = THREAD.getGlobal()
|
local GLOBAL = THREAD.getGlobal()
|
||||||
local THREAD_ID = 1
|
local THREAD_ID = 1
|
||||||
|
|||||||
182
tests/test.lua
182
tests/test.lua
@ -5,41 +5,41 @@ multi:getOptimizationConnection()(function(msg)
|
|||||||
print(msg)
|
print(msg)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local conn1, conn2, conn3 = multi:newConnection(), multi:newConnection():fastMode(), multi:newConnection()
|
-- local conn1, conn2, conn3 = multi:newConnection(), multi:newConnection():fastMode(), multi:newConnection()
|
||||||
|
|
||||||
local link = conn1(function()
|
-- local link = conn1(function()
|
||||||
print("Conn1, first")
|
-- print("Conn1, first")
|
||||||
end)
|
-- end)
|
||||||
|
|
||||||
local link2 = conn1(function()
|
-- local link2 = conn1(function()
|
||||||
print("Conn1, second")
|
-- print("Conn1, second")
|
||||||
end)
|
-- end)
|
||||||
|
|
||||||
local link3 = conn1(function()
|
-- local link3 = conn1(function()
|
||||||
print("Conn1, third")
|
-- print("Conn1, third")
|
||||||
end)
|
-- end)
|
||||||
|
|
||||||
local link4 = conn2(function()
|
-- local link4 = conn2(function()
|
||||||
print("Conn2, first")
|
-- print("Conn2, first")
|
||||||
end)
|
-- end)
|
||||||
|
|
||||||
local link5 = conn2(function()
|
-- local link5 = conn2(function()
|
||||||
print("Conn2, second")
|
-- print("Conn2, second")
|
||||||
end)
|
-- end)
|
||||||
|
|
||||||
local link6 = conn2(function()
|
-- local link6 = conn2(function()
|
||||||
print("Conn2, third")
|
-- print("Conn2, third")
|
||||||
end)
|
-- end)
|
||||||
|
|
||||||
print("All conns\n-------------")
|
-- print("All conns\n-------------")
|
||||||
conn1:Fire()
|
-- conn1:Fire()
|
||||||
conn2:Fire()
|
-- conn2:Fire()
|
||||||
|
|
||||||
conn1:Unconnect(link3)
|
-- conn1:Unconnect(link3)
|
||||||
conn2:Unconnect(link6)
|
-- conn2:Unconnect(link6)
|
||||||
print("All conns Edit\n---------------------")
|
-- print("All conns Edit\n---------------------")
|
||||||
conn1:Fire()
|
-- conn1:Fire()
|
||||||
conn2:Fire()
|
-- conn2:Fire()
|
||||||
|
|
||||||
-- thread:newThread(function()
|
-- thread:newThread(function()
|
||||||
-- print("Awaiting status")
|
-- print("Awaiting status")
|
||||||
@ -60,74 +60,74 @@ conn2:Fire()
|
|||||||
-- conn3:Fire()
|
-- conn3:Fire()
|
||||||
-- end)
|
-- end)
|
||||||
|
|
||||||
-- local conn = multi:newSystemThreadedConnection("conn"):init()
|
local conn = multi:newSystemThreadedConnection("conn"):init()
|
||||||
|
|
||||||
-- multi:newSystemThread("Thread_Test_1", function()
|
multi:newSystemThread("Thread_Test_1", function()
|
||||||
-- local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
-- local conn = GLOBAL["conn"]:init()
|
local conn = GLOBAL["conn"]:init()
|
||||||
-- local console = THREAD.getConsole()
|
local console = THREAD.getConsole()
|
||||||
-- conn(function(a,b,c)
|
conn(function(a,b,c)
|
||||||
-- console.print(THREAD:getName().." was triggered!",a,b,c)
|
console.print(THREAD:getName().." was triggered!",a,b,c)
|
||||||
-- end)
|
end)
|
||||||
-- multi:mainloop()
|
multi:mainloop()
|
||||||
-- end)
|
end)
|
||||||
|
|
||||||
-- multi:newSystemThread("Thread_Test_2", function()
|
multi:newSystemThread("Thread_Test_2", function()
|
||||||
-- local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
-- local conn = GLOBAL["conn"]:init()
|
local conn = GLOBAL["conn"]:init()
|
||||||
-- local console = THREAD.getConsole()
|
local console = THREAD.getConsole()
|
||||||
-- conn(function(a,b,c)
|
conn(function(a,b,c)
|
||||||
-- console.print(THREAD:getName().." was triggered!",a,b,c)
|
console.print(THREAD:getName().." was triggered!",a,b,c)
|
||||||
-- end)
|
end)
|
||||||
-- multi:newAlarm(2):OnRing(function()
|
multi:newAlarm(2):OnRing(function()
|
||||||
-- console.print("Fire 2!!!")
|
console.print("Fire 2!!!")
|
||||||
-- conn:Fire(4,5,6)
|
conn:Fire(4,5,6)
|
||||||
-- THREAD.kill()
|
THREAD.kill()
|
||||||
-- end)
|
end)
|
||||||
|
|
||||||
-- multi:mainloop()
|
multi:mainloop()
|
||||||
-- end)
|
end)
|
||||||
-- local console = THREAD.getConsole()
|
local console = THREAD.getConsole()
|
||||||
-- conn(function(a,b,c)
|
conn(function(a,b,c)
|
||||||
-- console.print("Mainloop conn got triggered!",a,b,c)
|
console.print("Mainloop conn got triggered!",a,b,c)
|
||||||
-- end)
|
end)
|
||||||
|
|
||||||
-- alarm = multi:newAlarm(1)
|
alarm = multi:newAlarm(1)
|
||||||
-- alarm:OnRing(function()
|
alarm:OnRing(function()
|
||||||
-- console.print("Fire 1!!!")
|
console.print("Fire 1!!!")
|
||||||
-- conn:Fire(1,2,3)
|
conn:Fire(1,2,3)
|
||||||
-- end)
|
end)
|
||||||
|
|
||||||
-- alarm = multi:newAlarm(3):OnRing(function()
|
alarm = multi:newAlarm(3):OnRing(function()
|
||||||
-- multi:newSystemThread("Thread_Test_3",function()
|
multi:newSystemThread("Thread_Test_3",function()
|
||||||
-- local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
-- local conn = GLOBAL["conn"]:init()
|
local conn = GLOBAL["conn"]:init()
|
||||||
-- local console = THREAD.getConsole()
|
local console = THREAD.getConsole()
|
||||||
-- conn(function(a,b,c)
|
conn(function(a,b,c)
|
||||||
-- console.print(THREAD:getName().." was triggered!",a,b,c)
|
console.print(THREAD:getName().." was triggered!",a,b,c)
|
||||||
-- end)
|
end)
|
||||||
-- multi:newAlarm(4):OnRing(function()
|
multi:newAlarm(4):OnRing(function()
|
||||||
-- console.print("Fire 3!!!")
|
console.print("Fire 3!!!")
|
||||||
-- conn:Fire(7,8,9)
|
conn:Fire(7,8,9)
|
||||||
-- end)
|
end)
|
||||||
-- multi:mainloop()
|
multi:mainloop()
|
||||||
-- end)
|
end)
|
||||||
-- end)
|
end)
|
||||||
|
|
||||||
-- multi:newSystemThread("Thread_Test_4",function()
|
multi:newSystemThread("Thread_Test_4",function()
|
||||||
-- local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
-- local conn = GLOBAL["conn"]:init()
|
local conn = GLOBAL["conn"]:init()
|
||||||
-- local conn2 = multi:newConnection()
|
local conn2 = multi:newConnection()
|
||||||
-- local console = THREAD.getConsole()
|
local console = THREAD.getConsole()
|
||||||
-- multi:newAlarm(2):OnRing(function()
|
multi:newAlarm(2):OnRing(function()
|
||||||
-- conn2:Fire()
|
conn2:Fire()
|
||||||
-- end)
|
end)
|
||||||
-- multi:newThread(function()
|
multi:newThread(function()
|
||||||
-- console.print("Conn Test!")
|
console.print("Conn Test!")
|
||||||
-- thread.hold(conn + conn2)
|
thread.hold(conn + conn2)
|
||||||
-- console.print("It held!")
|
console.print("It held!")
|
||||||
-- end)
|
end)
|
||||||
-- multi:mainloop()
|
multi:mainloop()
|
||||||
-- end)
|
end)
|
||||||
|
|
||||||
-- multi:mainloop()
|
multi:mainloop()
|
||||||
Loading…
x
Reference in New Issue
Block a user