still writing this thing

This commit is contained in:
2018-11-06 06:39:14 -05:00
parent 72dcc95400
commit 040d8842a2
8 changed files with 492 additions and 96 deletions
+7 -1
View File
@@ -37,6 +37,7 @@ multi.OnMouseMoved = multi:newConnection()
multi.OnDraw = multi:newConnection()
multi.OnTextInput = multi:newConnection()
multi.OnUpdate = multi:newConnection()
multi.OnQuit = multi:newConnection()
multi.OnPreLoad(function()
local function Hook(func,conn)
if love[func]~=nil then
@@ -51,6 +52,7 @@ multi.OnPreLoad(function()
end
end
end
Hook("quit",multi.OnQuit)
Hook("keypressed",multi.OnKeyPressed)
Hook("keyreleased",multi.OnKeyReleased)
Hook("mousepressed",multi.OnMousePressed)
@@ -67,4 +69,8 @@ multi.OnPreLoad(function()
end
end)
end)
return multi
multi.OnQuit(function()
multi.Stop()
love.event.quit()
end)
return multi
+60 -9
View File
@@ -551,10 +551,18 @@ function multi:newTimer()
self:create(c)
return c
end
function multi:newConnection(protect)
function multi:newConnection(protect,func)
local c={}
c.callback = func
c.Parent=self
setmetatable(c,{__call=function(self,...) return self:connect(...) end})
setmetatable(c,{__call=function(self,...)
local t = ...
if type(t)=="table" and t.Type ~= nil then
return self:Fire(args,select(2,...))
else
return self:connect(...)
end
end})
c.Type='connector'
c.func={}
c.ID=0
@@ -661,6 +669,9 @@ function multi:newConnection(protect)
if name then
self.connections[name]=temp
end
if self.callback then
self.callback(temp)
end
return temp
end
c.Connect=c.connect
@@ -1057,7 +1068,29 @@ function multi:newTStep(start,reset,count,set)
return c
end
function multi:newTimeStamper()
local c=self:newBase()
local c=self:newUpdater(self.Priority_Idle)
c:OnUpdate(function()
c:Run()
end)
local feb = 28
local leap = tonumber(os.date("%Y"))%4==0 and (tonumber(os.date("%Y"))%100~=0 or tonumber(os.date("%Y"))%400==0)
if leap then
feb = 29
end
local dInM = {
["01"] = 31,
["02"] = feb,
["03"] = 31,
["04"] = 30,
["05"] = 31,
["06"] = 30,
["07"] = 31, -- This is dumb, why do we still follow this double 31 days!?
["08"] = 31,
["09"] = 30,
["10"] = 31,
["11"] = 30,
["12"] = 31,
}
c.Type='timestamper'
c.Priority=self.Priority_Idle
c.hour = {}
@@ -1067,7 +1100,7 @@ function multi:newTimeStamper()
c.day = {}
c.month = {}
c.year = {}
function c:Act()
function c:Run()
for i=1,#self.hour do
if self.hour[i][1]==os.date("%H") and self.hour[i][3] then
self.hour[i][2](self)
@@ -1101,10 +1134,14 @@ function multi:newTimeStamper()
self.day[i][3]=true
end
else
if string.format("%02d",self.day[i][1])==os.date("%d") and self.day[i][3] then
local dday = self.day[i][1]
if dday < 0 then
dday = dInM[os.date("%m")]+(dday+1)
end
if string.format("%02d",dday)==os.date("%d") and self.day[i][3] then
self.day[i][2](self)
self.day[i][3]=false
elseif string.format("%02d",self.day[i][1])~=os.date("%d") and not self.day[i][3] then
elseif string.format("%02d",dday)~=os.date("%d") and not self.day[i][3] then
self.day[i][3]=true
end
end
@@ -1243,8 +1280,23 @@ function thread.waitFor(name)
thread.hold(function() return thread.get(name)~=nil end)
return thread.get(name)
end
function thread.testFor(name,val,sym)
thread.hold(function() return thread.get(name)~=nil end)
function thread.testFor(name,_val,sym)
thread.hold(function()
local val = thread.get(name)~=nil
if val then
if sym == "==" or sym == "=" then
return _val==val
elseif sym == ">" then
return _val>val
elseif sym == "<" then
return _val<val
elseif sym == "<=" then
return _val<=val
elseif sym == ">=" then
return _val>=val
end
end
end)
return thread.get(name)
end
function multi:newTBase(name)
@@ -1676,7 +1728,6 @@ function multi:newThreadedProcess(name)
setmetatable(c, multi)
function c:newBase(ins)
local ct = {}
setmetatable(ct, self.Parent)
ct.Active=true
ct.func={}
ct.ender={}
+42 -30
View File
@@ -23,7 +23,7 @@ SOFTWARE.
]]
local multi = require("multi")
local net = require("net")
require("bin")
local bin = require("bin")
bin.setBitsInterface(infinabits) -- the bits interface does not work so well, another bug to fix
-- Commands that the master and node will respect, max of 256 commands
@@ -142,17 +142,20 @@ function multi:nodeManager(port)
server.OnDataRecieved(function(server,data,cid,ip,port)
local cmd = data:sub(1,1)
if cmd == "R" then
multi:newTLoop(function(loop)
if server.timeouts[cid]==true then
server.OnNodeRemoved:Fire(server.nodes[cid])
server.nodes[cid] = nil
server.timeouts[cid] = nil
loop:Destroy()
return
multi:newThread("Test",function(loop)
while true do
if server.timeouts[cid]==true then
server.OnNodeRemoved:Fire(server.nodes[cid])
server.nodes[cid] = nil
server.timeouts[cid] = nil
thread.kill()
else
server.timeouts[cid] = true
server:send(cid,"ping")
end
thread.sleep(1)
end
server.timeouts[cid] = true
server:send(cid,"ping")
end,1)
end)
server.nodes[cid]=data:sub(2,-1)
server.OnNodeAdded:Fire(server.nodes[cid])
elseif cmd == "G" then
@@ -436,12 +439,15 @@ function multi:newMaster(settings) -- You will be able to have more than one mas
name = self:getRandomNode()
end
if name==nil then
multi:newTLoop(function(loop)
if name~=nil then
self:sendTo(name,char(CMD_TASK)..len..aData..len2..fData)
loop:Desrtoy()
multi:newThread("Test",function(loop)
while true do
if name~=nil then
self:sendTo(name,char(CMD_TASK)..len..aData..len2..fData)
thread.kill()
end
thread.sleep(.1)
end
end,.1)
end)
else
self:sendTo(name,char(CMD_TASK)..len..aData..len2..fData)
end
@@ -455,12 +461,15 @@ function multi:newMaster(settings) -- You will be able to have more than one mas
name = "NODE_"..name
end
if self.connections[name]==nil then
multi:newTLoop(function(loop)
if self.connections[name]~=nil then
self.connections[name]:send(data)
loop:Destroy()
multi:newThread("Test",function(loop)
while true do
if self.connections[name]~=nil then
self.connections[name]:send(data)
thread.kill()
end
thread.sleep(.1)
end
end,.1)
end)
else
self.connections[name]:send(data)
end
@@ -495,16 +504,19 @@ function multi:newMaster(settings) -- You will be able to have more than one mas
client.OnClientReady(function()
client:send(char(CMD_INITMASTER)..master.name) -- Tell the node that you are a master trying to connect
if not settings.managerDetails then
multi:newTLoop(function(loop)
if master.timeouts[name]==true then
master.timeouts[name] = nil
master.connections[name] = nil
loop:Destroy()
return
multi:newThread("Test",function(loop)
while true do
if master.timeouts[name]==true then
master.timeouts[name] = nil
master.connections[name] = nil
thread.kill()
else
master.timeouts[name] = true
master:sendTo(name,char(CMD_PING))
end
thread.sleep(1)
end
master.timeouts[name] = true
master:sendTo(name,char(CMD_PING))
end,1)
end)
end
client.name = name
client.OnDataRecieved(function(client,data)