mirror of
https://github.com/rayaman/multi.git
synced 2026-09-05 07:27:35 -04:00
Threading working in love2d
This commit is contained in:
+2
-21
@@ -1,22 +1,3 @@
|
||||
function love.conf(t)
|
||||
t.identity = nil -- The name of the save directory (string)
|
||||
t.version = "11.4" -- The LOVE version this game was made for (string)
|
||||
t.console = true -- Attach a console (boolean, Windows only)
|
||||
|
||||
t.window = false
|
||||
|
||||
t.modules.audio = false -- Enable the audio module (boolean)
|
||||
t.modules.event = false -- Enable the event module (boolean)
|
||||
t.modules.graphics = false -- Enable the graphics module (boolean)
|
||||
t.modules.image = false -- Enable the image module (boolean)
|
||||
t.modules.joystick = false -- Enable the joystick module (boolean)
|
||||
t.modules.keyboard = false -- Enable the keyboard module (boolean)
|
||||
t.modules.math = false -- Enable the math module (boolean)
|
||||
t.modules.mouse = false -- Enable the mouse module (boolean)
|
||||
t.modules.physics = false -- Enable the physics module (boolean)
|
||||
t.modules.sound = false -- Enable the sound module (boolean)
|
||||
t.modules.system = true -- Enable the system module (boolean)
|
||||
t.modules.timer = true -- Enable the timer module (boolean)
|
||||
t.modules.window = false -- Enable the window module (boolean)
|
||||
t.modules.thread = true -- Enable the thread module (boolean)
|
||||
end
|
||||
t.console = true
|
||||
end
|
||||
+6
-8
@@ -1,12 +1,10 @@
|
||||
package.path = "../?/init.lua;../?.lua;"..package.path
|
||||
require("runtests")
|
||||
require("threadtests")
|
||||
-- Allows you to run "love tests" which runs the tests
|
||||
|
||||
multi, thread = require("multi"):init()
|
||||
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
|
||||
require("lldebugger").start()
|
||||
end
|
||||
|
||||
GLOBAL, THREAD = require("multi.integration.loveManager"):init()
|
||||
|
||||
|
||||
function love.update()
|
||||
multi:uManager()
|
||||
end
|
||||
require("runtests")
|
||||
require("threadtests")
|
||||
|
||||
+33
-36
@@ -1,8 +1,9 @@
|
||||
package.path = "../?/init.lua;../?.lua;"..package.path
|
||||
multi, thread = require("multi"):init{print=true,warn=true,debugging=true}
|
||||
for i,v in pairs(thread) do
|
||||
print(i,v)
|
||||
end
|
||||
-- for i,v in pairs(thread) do
|
||||
-- print(i,v)
|
||||
-- end
|
||||
|
||||
-- require("multi.integration.priorityManager")
|
||||
|
||||
-- multi.debugging.OnObjectCreated(function(obj, process)
|
||||
@@ -14,10 +15,6 @@ end
|
||||
-- end)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- test = multi:newProcessor("Test")
|
||||
-- test:setPriorityScheme(multi.priorityScheme.TimeBased)
|
||||
|
||||
@@ -102,39 +99,39 @@ end
|
||||
|
||||
-- multi:mainloop()
|
||||
|
||||
multi:setTaskDelay(.05)
|
||||
multi:newTask(function()
|
||||
for i = 1, 10 do
|
||||
multi:newTask(function()
|
||||
print("Task "..i)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
-- multi:setTaskDelay(.05)
|
||||
-- multi:newTask(function()
|
||||
-- for i = 1, 10 do
|
||||
-- multi:newTask(function()
|
||||
-- print("Task "..i)
|
||||
-- end)
|
||||
-- end
|
||||
-- end)
|
||||
|
||||
local conn = multi:newConnection()
|
||||
conn(function() print("Test 1") end)
|
||||
conn(function() print("Test 2") end)
|
||||
conn(function() print("Test 3") end)
|
||||
conn(function() print("Test 4") end)
|
||||
-- local conn = multi:newConnection()
|
||||
-- conn(function() print("Test 1") end)
|
||||
-- conn(function() print("Test 2") end)
|
||||
-- conn(function() print("Test 3") end)
|
||||
-- conn(function() print("Test 4") end)
|
||||
|
||||
print("Fire 1")
|
||||
conn:Fire()
|
||||
conn = -conn
|
||||
print("Fire 2")
|
||||
conn:Fire()
|
||||
-- print("Fire 1")
|
||||
-- conn:Fire()
|
||||
-- conn = -conn
|
||||
-- print("Fire 2")
|
||||
-- conn:Fire()
|
||||
|
||||
print(#conn)
|
||||
-- print(#conn)
|
||||
|
||||
thread:newThread("Test thread", function()
|
||||
print("Starting thread!")
|
||||
thread.defer(function() -- Runs when the thread finishes execution
|
||||
print("Clean up time!")
|
||||
end)
|
||||
--[[
|
||||
Do lot's of stuff
|
||||
]]
|
||||
thread.sleep(3)
|
||||
end)
|
||||
-- thread:newThread("Test thread", function()
|
||||
-- print("Starting thread!")
|
||||
-- thread.defer(function() -- Runs when the thread finishes execution
|
||||
-- print("Clean up time!")
|
||||
-- end)
|
||||
-- --[[
|
||||
-- Do lot's of stuff
|
||||
-- ]]
|
||||
-- thread.sleep(3)
|
||||
-- end)
|
||||
|
||||
multi:mainloop()
|
||||
|
||||
|
||||
+29
-24
@@ -1,6 +1,6 @@
|
||||
package.path = "D:/VSCWorkspace/?/init.lua;D:/VSCWorkspace/?.lua;"..package.path
|
||||
package.cpath = "C:/luaInstalls/lua5.4/lib/lua/5.4/?/core.dll;" .. package.cpath
|
||||
multi, thread = require("multi"):init{error=true,warning=true,print=true}--{priority=true}
|
||||
multi, thread = require("multi"):init{error=true,warning=true,print=true, priority=true}
|
||||
proc = multi:newProcessor("Thread Test",true)
|
||||
local LANES, LOVE, PSEUDO = 1, 2, 3
|
||||
local env, we_good
|
||||
@@ -38,15 +38,15 @@ THREAD.setENV({
|
||||
})
|
||||
|
||||
multi:newThread("Scheduler Thread",function()
|
||||
-- multi:newThread(function()
|
||||
-- thread.sleep(30)
|
||||
-- print("Timeout tests took longer than 30 seconds")
|
||||
-- multi:Stop()
|
||||
-- os.exit(1)
|
||||
-- end)
|
||||
multi:newThread(function()
|
||||
thread.sleep(30)
|
||||
print("Timeout tests took longer than 30 seconds")
|
||||
multi:Stop()
|
||||
os.exit(1)
|
||||
end)
|
||||
|
||||
queue = multi:newSystemThreadedQueue("Test_Queue"):init()
|
||||
defer_queue = multi:newSystemThreadedQueue("Defer_Queue"):init()
|
||||
queue = multi:newSystemThreadedQueue("Test_Queue")
|
||||
defer_queue = multi:newSystemThreadedQueue("Defer_Queue")
|
||||
|
||||
multi:newSystemThread("Test_Thread_0", function()
|
||||
defer_queue = THREAD.waitFor("Defer_Queue"):init()
|
||||
@@ -63,13 +63,11 @@ multi:newThread("Scheduler Thread",function()
|
||||
end
|
||||
end)
|
||||
|
||||
thread:newThread(function()
|
||||
if thread.hold(function()
|
||||
return defer_queue:pop() == "done"
|
||||
end,{sleep=1}) == nil then
|
||||
multi.error("Thread.defer didn't work!")
|
||||
end
|
||||
end)
|
||||
if thread.hold(function()
|
||||
return defer_queue:pop() == "done"
|
||||
end,{sleep=3}) == nil then
|
||||
multi.error("Thread.defer didn't work!")
|
||||
end
|
||||
|
||||
th1 = multi:newSystemThread("Test_Thread_1", function(a,b,c,d,e,f)
|
||||
queue = THREAD.waitFor("Test_Queue"):init()
|
||||
@@ -135,7 +133,7 @@ multi:newThread("Scheduler Thread",function()
|
||||
|
||||
local ready = false
|
||||
|
||||
jq = multi:newSystemThreadedJobQueue(1) -- Job queue with 4 worker threads
|
||||
jq = multi:newSystemThreadedJobQueue(4) -- Job queue with 4 worker threads
|
||||
func2 = jq:newFunction("sleep",function(a,b)
|
||||
THREAD.sleep(.2)
|
||||
end)
|
||||
@@ -168,7 +166,7 @@ multi:newThread("Scheduler Thread",function()
|
||||
--print("Test")
|
||||
end, 1)
|
||||
|
||||
multi:newSystemThread("Testing proxy copy THREAD",function(tloop)
|
||||
multi:newSystemThread("PROX_THREAD",function(tloop)
|
||||
local multi, thread = require("multi"):init()
|
||||
tloop = tloop:init()
|
||||
multi.print("tloop type:",tloop.Type)
|
||||
@@ -176,19 +174,21 @@ multi:newThread("Scheduler Thread",function()
|
||||
thread:newThread(function()
|
||||
while true do
|
||||
thread.hold(tloop.OnLoop)
|
||||
--print(THREAD_NAME,"Loopy")
|
||||
print(THREAD_NAME,"Loopy")
|
||||
end
|
||||
end)
|
||||
tloop.OnLoop(function(a)
|
||||
--print(THREAD_NAME, "Got loop...")
|
||||
print(THREAD_NAME, "Got loop...")
|
||||
end)
|
||||
multi:mainloop()
|
||||
end, tloop:getTransferable())
|
||||
|
||||
local test = tloop:getTransferable()
|
||||
|
||||
multi.print("tloop", tloop.Type)
|
||||
multi.print("tloop.OnLoop", tloop.OnLoop.Type)
|
||||
|
||||
thread:newThread(function()
|
||||
thread:newThread("Proxy Test Thread",function()
|
||||
multi.print("Testing holding on a proxy connection!")
|
||||
thread.hold(tloop.OnLoop)
|
||||
multi.print("Held on proxy connection... once")
|
||||
@@ -197,17 +197,22 @@ multi:newThread("Scheduler Thread",function()
|
||||
thread.hold(tloop.OnLoop)
|
||||
multi.print("Held on proxy connection... finally")
|
||||
proxy_test = true
|
||||
end)
|
||||
end).OnError(print)
|
||||
|
||||
thread:newThread(function()
|
||||
thread.defer(function()
|
||||
multi.print("Something happened!")
|
||||
end)
|
||||
while true do
|
||||
thread.hold(tloop.OnLoop)
|
||||
--print(THREAD_NAME,"Local Loopy")
|
||||
multi.print(THREAD_NAME,"Local Loopy")
|
||||
end
|
||||
end).OnError(function(...)
|
||||
print("Error",...)
|
||||
end)
|
||||
|
||||
tloop.OnLoop(function()
|
||||
--print("OnLoop",THREAD_NAME)
|
||||
print("OnLoop", THREAD_NAME)
|
||||
end)
|
||||
|
||||
t, val = thread.hold(function()
|
||||
|
||||
Reference in New Issue
Block a user