updated love2d compat

This commit is contained in:
2018-07-21 09:58:43 -04:00
parent fae39b79e7
commit dce6ea201e
3 changed files with 56 additions and 36 deletions
+39 -29
View File
@@ -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")
os.sleep=love.timer.sleep
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)
i=i or 1
table.insert(self.drawF,i,func)
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
+10 -6
View File
@@ -133,11 +133,11 @@ function multi:setPriority(s)
self.Priority=self.Priority_Core
elseif s:lower()=='high' or s:lower()=='h' then
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
elseif s:lower()=='normal' or s:lower()=='n' then
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
elseif s:lower()=='low' or s:lower()=='l' then
self.Priority=self.Priority_Low
@@ -637,9 +637,9 @@ function multi:newConnection(protect)
function c:Remove()
self.func={}
end
function c:connect(func,name)
function c:connect(func,name,num)
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 = {
Link=self.func,
func=func,
@@ -749,6 +749,7 @@ function multi:newCondition(func)
self:create(c)
return c
end
multi.OnPreLoad=multi:newConnection()
multi.NewCondition=multi.newCondition
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
@@ -816,6 +817,8 @@ function multi:threadloop(settings)
end
function multi:mainloop(settings)
multi.defaultSettings = settings or multi.defaultSettings
self.uManager=self.uManagerRef
multi.OnPreLoad:Fire()
if not multi.isRunning then
local protect = false
local priority = false
@@ -915,6 +918,7 @@ function multi:mainloop(settings)
end
end
function multi:uManager(settings)
multi.OnPreLoad:Fire()
if settings then
if settings.preLoop then
settings.preLoop(self)
@@ -1464,7 +1468,7 @@ function thread.yeild()
coroutine.yield({"_sleep_",0})
end
function thread.isThread()
return coroutine.running()
return coroutine.running()~=nil
end
function thread.getCores()
return thread.__CORES
@@ -1568,7 +1572,7 @@ multi.scheduler:OnLoop(function(self)
_,ret=coroutine.resume(self.Threads[i].thread,self.Globals)
end
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
if ret==true or ret==false then
print("Thread Ended!!!")