mirror of
https://github.com/rayaman/multi.git
synced 2026-09-05 07:27:35 -04:00
Updated to version (1.8.2)
Added more example files Added SystemThreadedTables Some bug fixes
This commit is contained in:
@@ -23,19 +23,6 @@ SOFTWARE.
|
||||
]]
|
||||
require("multi")
|
||||
os.sleep=love.timer.sleep
|
||||
--~ function bin.load(file,s,r)
|
||||
--~ content, size = love.filesystem.read(file)
|
||||
--~ local temp=bin.new(content)
|
||||
--~ temp.filepath=file
|
||||
--~ return temp
|
||||
--~ end
|
||||
--~ function bin:tofile(filename)
|
||||
--~ if not(filename) or self.Stream then return nil end
|
||||
--~ love.filesystem.write(filename,self.data)
|
||||
--~ end
|
||||
--~ function bin.stream(file,l)
|
||||
--~ error("Sorry streaming is not available when using love2d :(, I am looking for a solution though :)")
|
||||
--~ end
|
||||
function love.run()
|
||||
if love.math then
|
||||
love.math.setRandomSeed(os.time())
|
||||
|
||||
+3
-2
@@ -45,7 +45,8 @@ function print(...)
|
||||
end
|
||||
end
|
||||
multi = {}
|
||||
multi.Version={1,8,1}
|
||||
multi.Version="1.8.2"
|
||||
multi._VERSION="1.8.2"
|
||||
multi.stage='stable'
|
||||
multi.__index = multi
|
||||
multi.Mainloop={}
|
||||
@@ -237,7 +238,7 @@ function multi:getChildren()
|
||||
return self.Mainloop
|
||||
end
|
||||
function multi:getVersion()
|
||||
return multi.Version[1].."."..multi.Version[2].."."..multi.Version[3]
|
||||
return multi.Version
|
||||
end
|
||||
function multi:getPlatform()
|
||||
if love then
|
||||
|
||||
@@ -13,9 +13,11 @@ require("multi.all")
|
||||
GLOBAL={}
|
||||
setmetatable(GLOBAL,{
|
||||
__index=function(t,k)
|
||||
__sync__()
|
||||
return __proxy__[k]
|
||||
end,
|
||||
__newindex=function(t,k,v)
|
||||
__sync__()
|
||||
__proxy__[k]=v
|
||||
if type(v)=="userdata" then
|
||||
__MainChan__:push(v)
|
||||
@@ -24,6 +26,23 @@ setmetatable(GLOBAL,{
|
||||
end
|
||||
end,
|
||||
})
|
||||
function __sync__()
|
||||
local data=__mythread__:pop()
|
||||
while data do
|
||||
if type(data)=="string" then
|
||||
local cmd,tp,name,d=data:match("(%S-) (%S-) (%S-) (.+)")
|
||||
if name=="__DIEPLZ"..__THREADNAME__.."__" then
|
||||
error("Thread: "..__THREADNAME__.." has been stopped!")
|
||||
end
|
||||
if cmd=="SYNC" then
|
||||
__proxy__[name]=resolveType(tp,d)
|
||||
end
|
||||
else
|
||||
__proxy__[name]=data
|
||||
end
|
||||
data=__mythread__:pop()
|
||||
end
|
||||
end
|
||||
function ToStr(val, name, skipnewlines, depth)
|
||||
skipnewlines = skipnewlines or false
|
||||
depth = depth or 0
|
||||
@@ -121,25 +140,7 @@ function sThread.get(name)
|
||||
return GLOBAL[name]
|
||||
end
|
||||
function sThread.waitFor(name)
|
||||
--print("Waiting:",__mythreadname__)
|
||||
local function wait()
|
||||
local data=__mythread__:pop()
|
||||
while data do
|
||||
if type(data)=="string" then
|
||||
local cmd,tp,name,d=data:match("(%S-) (%S-) (%S-) (.+)")
|
||||
if name=="__DIEPLZ"..__THREADNAME__.."__" then
|
||||
error("Thread: "..__THREADNAME__.." has been stopped!")
|
||||
end
|
||||
if cmd=="SYNC" then
|
||||
__proxy__[name]=resolveType(tp,d)
|
||||
end
|
||||
else
|
||||
__proxy__[name]=data
|
||||
end
|
||||
data=__mythread__:pop()
|
||||
end
|
||||
end
|
||||
repeat wait() until GLOBAL[name]
|
||||
repeat __sync__() until GLOBAL[name]
|
||||
return GLOBAL[name]
|
||||
end
|
||||
function sThread.getCores()
|
||||
@@ -149,24 +150,7 @@ function sThread.sleep(n)
|
||||
love.timer.sleep(n)
|
||||
end
|
||||
function sThread.hold(n)
|
||||
local function wait()
|
||||
local data=__mythread__:pop()
|
||||
while data do
|
||||
if type(data)=="string" then
|
||||
local cmd,tp,name,d=data:match("(%S-) (%S-) (%S-) (.+)")
|
||||
if name=="__DIEPLZ"..__THREADNAME__.."__" then
|
||||
error("Thread: "..__THREADNAME__.." has been stopped!")
|
||||
end
|
||||
if cmd=="SYNC" then
|
||||
__proxy__[name]=resolveType(tp,d)
|
||||
end
|
||||
else
|
||||
__proxy__[name]=data
|
||||
end
|
||||
data=__mythread__:pop()
|
||||
end
|
||||
end
|
||||
repeat wait() until n()
|
||||
repeat __sync__() until n()
|
||||
end
|
||||
updater=multi:newUpdater()
|
||||
updater:OnUpdate(function(self)
|
||||
|
||||
@@ -100,3 +100,77 @@ function multi:systemThreadedBenchmark(n,p)
|
||||
end)
|
||||
return c
|
||||
end
|
||||
function multi:newSystemThreadedTable(name)
|
||||
local c={} -- where we will store our object
|
||||
c.name=name -- set the name this is important for the love2d side
|
||||
if love then -- check love
|
||||
if love.thread then -- make sure we can use the threading module
|
||||
function c:init() -- create an init function so we can mimic on bith love2d and lanes
|
||||
self.tab={}
|
||||
self.chan=love.thread.getChannel(self.name) -- create channel by the name self.name
|
||||
function self:waitFor(name) -- pop from the channel
|
||||
repeat self:sync() until self[name]
|
||||
return self[name]
|
||||
end
|
||||
function self:sync()
|
||||
local data=self.chan:pop()
|
||||
while data do
|
||||
if type(data)=="string" then
|
||||
local cmd,tp,name,d=data:match("(%S-) (%S-) (%S-) (.+)")
|
||||
if cmd=="SYNC" then
|
||||
self.tab[name]=resolveType(tp,d) -- this is defined in the loveManager.lua file
|
||||
end
|
||||
else
|
||||
self.tab[name]=data
|
||||
end
|
||||
data=self.chan:pop()
|
||||
end
|
||||
end
|
||||
setmetatable(self,{
|
||||
__index=function(t,k)
|
||||
self:sync()
|
||||
return self.tab[k]
|
||||
end,
|
||||
__newindex=function(t,k,v)
|
||||
self:sync()
|
||||
self.tab[k]=v
|
||||
if type(v)=="userdata" then
|
||||
self.chan:push(v)
|
||||
else
|
||||
self.chan:push("SYNC "..type(v).." "..k.." "..resolveData(v)) -- this is defined in the loveManager.lua file
|
||||
end
|
||||
end,
|
||||
})
|
||||
GLOBAL[self.name]=self -- send the object to the thread through the global interface
|
||||
return self -- return the object
|
||||
end
|
||||
return c
|
||||
else
|
||||
error("Make sure you required the love.thread module!") -- tell the user if he/she didn't require said module
|
||||
end
|
||||
else
|
||||
c.linda=lanes.linda() -- lanes is a bit eaiser, create the linda on the main thread
|
||||
function c:waitFor(name)
|
||||
while self[name]==nil do
|
||||
-- Waiting
|
||||
end
|
||||
return self[name]
|
||||
end
|
||||
function c:sync()
|
||||
return -- just so we match the love2d side
|
||||
end
|
||||
function c:init() -- set the metatable
|
||||
setmetatable(self,{
|
||||
__index=function(t,k)
|
||||
return self.linda:get(k)
|
||||
end,
|
||||
__newindex=function(t,k,v)
|
||||
self.linda:set(k,v)
|
||||
end,
|
||||
})
|
||||
return self
|
||||
end
|
||||
multi.intergration.GLOBAL[name]=c -- send the object to the thread through the global interface
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user