updated love2d compat
This commit is contained in:
parent
fae39b79e7
commit
dce6ea201e
@ -10,11 +10,14 @@ Update: 2.0.0 Big update (Lots of additions some changes)
|
|||||||
- `master = multi:newMaster(tbl: settings)`
|
- `master = multi:newMaster(tbl: settings)`
|
||||||
- `multi:nodeManager(port)`
|
- `multi:nodeManager(port)`
|
||||||
- `thread.isThread()` -- for coroutine based threads
|
- `thread.isThread()` -- for coroutine based threads
|
||||||
- New setting to the main loop,stopOnError which defaults to true. This will cause the object that crashes when under protect to be destroyed, so the error does not keep happening.
|
- New setting to the main loop, stopOnError which defaults to true. This will cause the objects that crash, when under protect, to be destroyed. So the error does not keep happening.
|
||||||
- multi:threadloop(settings) works just like mainloop, but prioritizes (corutine based) threads. Regular multi-objects will still work. This improves the preformance of (coroutine based) threads greatly.
|
- multi:threadloop(settings) works just like mainloop, but prioritizes (corutine based) threads. Regular multi-objects will still work. This improves the preformance of (coroutine based) threads greatly.
|
||||||
|
- multi.OnPreLoad -- an event that is triggered right before the mainloop starts
|
||||||
|
|
||||||
Changed:
|
Changed:
|
||||||
- When a (corutine based)thread errors it does not print anymore! Conect to multi.OnError() to get errors when they happen!
|
- When a (corutine based)thread errors it does not print anymore! Conect to multi.OnError() to get errors when they happen!
|
||||||
|
- Connections get yet another update. Connect takes an additional argument now which is the position in the table that the func should be called. Note: Fire calls methods backwards so 1 is the back and the # of connections (the default value) is the beginning of the call table
|
||||||
|
- The love2d compat layer has now been revamped allowing module creators to connect to events without the user having to add likes of code for those events. Its all done automagically
|
||||||
|
|
||||||
#Node:
|
#Node:
|
||||||
- node:sendTo(name,data)
|
- node:sendTo(name,data)
|
||||||
@ -36,6 +39,9 @@ Changed:
|
|||||||
- master:pop()
|
- master:pop()
|
||||||
- master:OnError(nodename, error) -- if a node has an error this is triggered.
|
- master:OnError(nodename, error) -- if a node has an error this is triggered.
|
||||||
|
|
||||||
|
#Bugs
|
||||||
|
- Fixed a small typo I made which caused a hard crash when a (coroutine) thread crashes. This only happened if protect was false. Which is now the defualt value for speed reasons.
|
||||||
|
|
||||||
#Going forward:
|
#Going forward:
|
||||||
- Improve Performance
|
- Improve Performance
|
||||||
- Fix supporting libraries (Bin, and net need tons of work)
|
- Fix supporting libraries (Bin, and net need tons of work)
|
||||||
|
|||||||
@ -1,37 +1,47 @@
|
|||||||
--[[
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2017 Ryan Ward
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
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.
|
|
||||||
]]
|
|
||||||
local multi = require("multi")
|
local multi = require("multi")
|
||||||
os.sleep=love.timer.sleep
|
os.sleep=love.timer.sleep
|
||||||
multi.drawF={}
|
multi.drawF={}
|
||||||
function multi.dManager()
|
|
||||||
for ii=1,#multi.drawF do
|
|
||||||
love.graphics.setColor(255,255,255,255)
|
|
||||||
multi.drawF[ii]()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function multi:onDraw(func,i)
|
function multi:onDraw(func,i)
|
||||||
i=i or 1
|
i=i or 1
|
||||||
table.insert(self.drawF,i,func)
|
table.insert(self.drawF,i,func)
|
||||||
end
|
end
|
||||||
|
multi.OnKeyPressed = multi:newConnection()
|
||||||
|
multi.OnKeyReleased = multi:newConnection()
|
||||||
|
multi.OnMousePressed = multi:newConnection()
|
||||||
|
multi.OnMouseReleased = multi:newConnection()
|
||||||
|
multi.OnMouseWheelMoved = multi:newConnection()
|
||||||
|
multi.OnMouseMoved = multi:newConnection()
|
||||||
|
multi.OnDraw = multi:newConnection()
|
||||||
|
multi.OnTextInput = multi:newConnection()
|
||||||
|
multi.OnUpdate = multi:newConnection()
|
||||||
|
multi.OnPreLoad(function()
|
||||||
|
local function Hook(func,conn)
|
||||||
|
if love[func]~=nil then
|
||||||
|
love[func] = Library.convert(love[func])
|
||||||
|
love[func]:inject(function(...)
|
||||||
|
conn:Fire(...)
|
||||||
|
return {...}
|
||||||
|
end,1)
|
||||||
|
elseif love[func]==nil then
|
||||||
|
love[func] = function(...)
|
||||||
|
conn:Fire(...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Hook("keypressed",multi.OnKeyPressed)
|
||||||
|
Hook("keyreleased",multi.OnKeyReleased)
|
||||||
|
Hook("mousepressed",multi.OnMousePressed)
|
||||||
|
Hook("mousereleased",multi.OnMouseReleased)
|
||||||
|
Hook("wheelmoved",multi.OnMouseWheelMoved)
|
||||||
|
Hook("mousemoved",multi.OnMouseMoved)
|
||||||
|
Hook("draw",multi.OnDraw)
|
||||||
|
Hook("textinput",multi.OnTextInput)
|
||||||
|
Hook("update",multi.OnUpdate)
|
||||||
|
multi.OnDraw(function()
|
||||||
|
for i=1,#multi.drawF do
|
||||||
|
love.graphics.setColor(255,255,255,255)
|
||||||
|
multi.drawF[i]()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
return multi
|
return multi
|
||||||
@ -133,11 +133,11 @@ function multi:setPriority(s)
|
|||||||
self.Priority=self.Priority_Core
|
self.Priority=self.Priority_Core
|
||||||
elseif s:lower()=='high' or s:lower()=='h' then
|
elseif s:lower()=='high' or s:lower()=='h' then
|
||||||
self.Priority=self.Priority_High
|
self.Priority=self.Priority_High
|
||||||
elseif s:lower()=='above' or s:lower()=='an' then
|
elseif s:lower()=='above' or s:lower()=='a' then
|
||||||
self.Priority=self.Priority_Above_Normal
|
self.Priority=self.Priority_Above_Normal
|
||||||
elseif s:lower()=='normal' or s:lower()=='n' then
|
elseif s:lower()=='normal' or s:lower()=='n' then
|
||||||
self.Priority=self.Priority_Normal
|
self.Priority=self.Priority_Normal
|
||||||
elseif s:lower()=='below' or s:lower()=='bn' then
|
elseif s:lower()=='below' or s:lower()=='b' then
|
||||||
self.Priority=self.Priority_Below_Normal
|
self.Priority=self.Priority_Below_Normal
|
||||||
elseif s:lower()=='low' or s:lower()=='l' then
|
elseif s:lower()=='low' or s:lower()=='l' then
|
||||||
self.Priority=self.Priority_Low
|
self.Priority=self.Priority_Low
|
||||||
@ -637,9 +637,9 @@ function multi:newConnection(protect)
|
|||||||
function c:Remove()
|
function c:Remove()
|
||||||
self.func={}
|
self.func={}
|
||||||
end
|
end
|
||||||
function c:connect(func,name)
|
function c:connect(func,name,num)
|
||||||
self.ID=self.ID+1
|
self.ID=self.ID+1
|
||||||
table.insert(self.func,1,{func,self.ID})
|
table.insert(self.func,num or #self.func+1,{func,self.ID})
|
||||||
local temp = {
|
local temp = {
|
||||||
Link=self.func,
|
Link=self.func,
|
||||||
func=func,
|
func=func,
|
||||||
@ -749,6 +749,7 @@ function multi:newCondition(func)
|
|||||||
self:create(c)
|
self:create(c)
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
|
multi.OnPreLoad=multi:newConnection()
|
||||||
multi.NewCondition=multi.newCondition
|
multi.NewCondition=multi.newCondition
|
||||||
function multi:threadloop(settings)
|
function multi:threadloop(settings)
|
||||||
multi.scheduler:Destroy() -- destroy is an interesting thing... if you dont set references to nil, then you only remove it from the mainloop
|
multi.scheduler:Destroy() -- destroy is an interesting thing... if you dont set references to nil, then you only remove it from the mainloop
|
||||||
@ -816,6 +817,8 @@ function multi:threadloop(settings)
|
|||||||
end
|
end
|
||||||
function multi:mainloop(settings)
|
function multi:mainloop(settings)
|
||||||
multi.defaultSettings = settings or multi.defaultSettings
|
multi.defaultSettings = settings or multi.defaultSettings
|
||||||
|
self.uManager=self.uManagerRef
|
||||||
|
multi.OnPreLoad:Fire()
|
||||||
if not multi.isRunning then
|
if not multi.isRunning then
|
||||||
local protect = false
|
local protect = false
|
||||||
local priority = false
|
local priority = false
|
||||||
@ -915,6 +918,7 @@ function multi:mainloop(settings)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function multi:uManager(settings)
|
function multi:uManager(settings)
|
||||||
|
multi.OnPreLoad:Fire()
|
||||||
if settings then
|
if settings then
|
||||||
if settings.preLoop then
|
if settings.preLoop then
|
||||||
settings.preLoop(self)
|
settings.preLoop(self)
|
||||||
@ -1464,7 +1468,7 @@ function thread.yeild()
|
|||||||
coroutine.yield({"_sleep_",0})
|
coroutine.yield({"_sleep_",0})
|
||||||
end
|
end
|
||||||
function thread.isThread()
|
function thread.isThread()
|
||||||
return coroutine.running()
|
return coroutine.running()~=nil
|
||||||
end
|
end
|
||||||
function thread.getCores()
|
function thread.getCores()
|
||||||
return thread.__CORES
|
return thread.__CORES
|
||||||
@ -1568,7 +1572,7 @@ multi.scheduler:OnLoop(function(self)
|
|||||||
_,ret=coroutine.resume(self.Threads[i].thread,self.Globals)
|
_,ret=coroutine.resume(self.Threads[i].thread,self.Globals)
|
||||||
end
|
end
|
||||||
if _==false then
|
if _==false then
|
||||||
self.Parent.OnError:Fire(Threads[i],"Error in thread: <"..Threads[i].Name.."> "..ret)
|
self.Parent.OnError:Fire(self.Threads[i],"Error in thread: <"..self.Threads[i].Name.."> "..ret)
|
||||||
end
|
end
|
||||||
if ret==true or ret==false then
|
if ret==true or ret==false then
|
||||||
print("Thread Ended!!!")
|
print("Thread Ended!!!")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user