Working on some nice features

This commit is contained in:
Ryan Ward 2022-10-06 18:36:45 -04:00
parent 4c088b9080
commit 7353fde799
3 changed files with 52 additions and 45 deletions

View File

@ -97,8 +97,10 @@ Added
Changed Changed
--- ---
- All actors now use fastmode on connections
- Performance enhancement with processes that are pumped instead of automatically running, by suppressing the creation of an internal loop object that would manage the process
- `Connection:fastMode() or Connection:SetHelper()` now returns a reference to itself
- `Connection:[connect, hasConnections, getConnection]` changed to be `Connection:[Connect, HasConnections, getConnections]`. This was done in an attempt to follow a consistent naming scheme. The old methods still will work to prevent old code breaking. - `Connection:[connect, hasConnections, getConnection]` changed to be `Connection:[Connect, HasConnections, getConnections]`. This was done in an attempt to follow a consistent naming scheme. The old methods still will work to prevent old code breaking.
- `Connections when added(+) together now act like 'or', to get the 'and' feature multiply(*) them together.` - `Connections when added(+) together now act like 'or', to get the 'and' feature multiply(*) them together.`
**Note:** This is a potentially breaking change for using connections. **Note:** This is a potentially breaking change for using connections.
@ -139,6 +141,7 @@ Removed
Fixed Fixed
--- ---
- SystemThreaded Objects variables weren't consistent. - SystemThreaded Objects variables weren't consistent.
- Issue with connections being multiplied only being able to have a combined fire once
ToDo ToDo
--- ---

View File

@ -160,12 +160,14 @@ function multi:newConnection(protect,func,kill)
cn.__count = cn.__count + 1 cn.__count = cn.__count + 1
if cn.__count == cn.__hasInstances then if cn.__count == cn.__hasInstances then
cn:Fire(...) cn:Fire(...)
cn.__count = 0
end end
end) end)
c2(function(...) c2(function(...)
cn.__count = cn.__count + 1 cn.__count = cn.__count + 1
if cn.__count == cn.__hasInstances then if cn.__count == cn.__hasInstances then
cn:Fire(...) cn:Fire(...)
cn.__count = 0
end end
end) end)
return cn return cn
@ -237,6 +239,7 @@ function multi:newConnection(protect,func,kill)
function self:Connect(func) function self:Connect(func)
table.insert(fast,func) table.insert(fast,func)
end end
return self
end end
function c:Bind(t) function c:Bind(t)
@ -335,6 +338,7 @@ function multi:newConnection(protect,func,kill)
function c:SetHelper(func) function c:SetHelper(func)
conn_helper = func conn_helper = func
return self
end end
c.connect=c.Connect c.connect=c.Connect
@ -584,7 +588,7 @@ function multi:newEvent(task)
task=func task=func
return self return self
end end
c.OnEvent = self:newConnection() c.OnEvent = self:newConnection():fastMode()
self:setPriority("core") self:setPriority("core")
c:SetName(c.Type) c:SetName(c.Type)
multi:create(c) multi:create(c)
@ -607,7 +611,7 @@ function multi:newUpdater(skip)
skip=n skip=n
return self return self
end end
c.OnUpdate = self:newConnection() c.OnUpdate = self:newConnection():fastMode()
c:SetName(c.Type) c:SetName(c.Type)
multi:create(c) multi:create(c)
return c return c
@ -639,7 +643,7 @@ function multi:newAlarm(set)
t = clock() t = clock()
return self return self
end end
c.OnRing = self:newConnection() c.OnRing = self:newConnection():fastMode()
function c:Pause() function c:Pause()
count = clock() count = clock()
self.Parent.Pause(self) self.Parent.Pause(self)
@ -663,10 +667,7 @@ function multi:newLoop(func,notime)
self.OnLoop:Fire(self,clock()-start) self.OnLoop:Fire(self,clock()-start)
end end
end end
c.OnLoop = self:newConnection() c.OnLoop = self:newConnection():fastMode()
function c:fastMode()
self.OnLoop:fastMode()
end
if func then if func then
c.OnLoop(func) c.OnLoop(func)
@ -713,9 +714,9 @@ function multi:newStep(start,reset,count,skip)
end end
end end
c.Reset=c.Resume c.Reset=c.Resume
c.OnStart = self:newConnection() c.OnStart = self:newConnection():fastMode()
c.OnStep = self:newConnection() c.OnStep = self:newConnection():fastMode()
c.OnEnd = self:newConnection() c.OnEnd = self:newConnection():fastMode()
function c:Break() function c:Break()
self.Active=nil self.Active=nil
return self return self
@ -763,7 +764,7 @@ function multi:newTLoop(func,set)
self.Parent.Pause(self) self.Parent.Pause(self)
return self return self
end end
c.OnLoop = self:newConnection() c.OnLoop = self:newConnection():fastMode()
if func then if func then
c.OnLoop(func) c.OnLoop(func)
end end
@ -883,25 +884,28 @@ function multi:newProcessor(name,nothread)
c.Type = "process" c.Type = "process"
local Active = nothread or false local Active = nothread or false
c.Name = name or "" c.Name = name or ""
c.pump = false
c.threads = {} c.threads = {}
c.startme = {} c.startme = {}
c.parent = self c.parent = self
local handler = c:createHandler(c.threads,c.startme) local handler = c:createHandler(c.threads,c.startme)
if not nothread then -- Don't create a loop if we are triggering this manually
c.process = self:newLoop(function() c.process = self:newLoop(function()
if Active then if Active then
c:uManager() c:uManager()
handler() handler()
end end
end) end)
c.process.__ignore = true c.process.__ignore = true
c.process.isProcessThread = true c.process.isProcessThread = true
c.process.PID = sandcount c.process.PID = sandcount
c.OnError = c.process.OnError c.OnError = c.process.OnError
else
c.OnError = multi:newConnection()
end
function c:getThreads() function c:getThreads()
return c.threads return c.threads
@ -930,10 +934,8 @@ function multi:newProcessor(name,nothread)
function c.run() function c.run()
if not Active then return end if not Active then return end
c.pump = true
c:uManager() c:uManager()
handler() handler()
c.pump = false
return c return c
end end

View File

@ -3,25 +3,27 @@ package.cpath = "lua5.4/lib/lua/5.4/?/core.dll;"--..package.cpath
multi, thread = require("multi"):init{print=true} multi, thread = require("multi"):init{print=true}
-- GLOBAL, THREAD = require("multi.integration.lanesManager"):init() -- GLOBAL, THREAD = require("multi.integration.lanesManager"):init()
local conn1, conn2, conn3 = multi:newConnection(), multi:newConnection(), multi:newConnection() -- local conn1, conn2, conn3 = multi:newConnection(), multi:newConnection(), multi:newConnection()
thread:newThread(function() -- thread:newThread(function()
print("Awaiting status") -- print("Awaiting status")
thread.hold(conn1 + (conn2 * conn3)) -- thread.hold(conn1 + (conn2 * conn3))
print("Conn or Conn2 and Conn3") -- print("Conn or Conn2 and Conn3")
end) -- end)
-- multi:newAlarm(1):OnRing(function()
-- print("Conn")
-- conn1:Fire()
-- end)
-- multi:newAlarm(2):OnRing(function()
-- print("Conn2")
-- conn2:Fire()
-- end)
-- multi:newAlarm(3):OnRing(function()
-- print("Conn3")
-- conn3:Fire()
-- end)
multi:newAlarm(1):OnRing(function()
print("Conn")
conn1:Fire()
end)
multi:newAlarm(2):OnRing(function()
print("Conn2")
conn2:Fire()
end)
multi:newAlarm(3):OnRing(function()
print("Conn3")
conn3:Fire()
end)
-- local conn = multi:newSystemThreadedConnection("conn"):init() -- local conn = multi:newSystemThreadedConnection("conn"):init()