From 7353fde7998b3620de0ff4c8373bc2a19af34e69 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Thu, 6 Oct 2022 18:36:45 -0400 Subject: [PATCH] Working on some nice features --- changes.md | 5 ++++- multi/init.lua | 54 ++++++++++++++++++++++++++------------------------ test.lua | 38 ++++++++++++++++++----------------- 3 files changed, 52 insertions(+), 45 deletions(-) diff --git a/changes.md b/changes.md index fa53381..edcf885 100644 --- a/changes.md +++ b/changes.md @@ -97,8 +97,10 @@ Added 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. - - `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. @@ -139,6 +141,7 @@ Removed Fixed --- - SystemThreaded Objects variables weren't consistent. +- Issue with connections being multiplied only being able to have a combined fire once ToDo --- diff --git a/multi/init.lua b/multi/init.lua index fe73b0e..4b7aab6 100644 --- a/multi/init.lua +++ b/multi/init.lua @@ -160,12 +160,14 @@ function multi:newConnection(protect,func,kill) cn.__count = cn.__count + 1 if cn.__count == cn.__hasInstances then cn:Fire(...) + cn.__count = 0 end end) c2(function(...) cn.__count = cn.__count + 1 if cn.__count == cn.__hasInstances then cn:Fire(...) + cn.__count = 0 end end) return cn @@ -237,6 +239,7 @@ function multi:newConnection(protect,func,kill) function self:Connect(func) table.insert(fast,func) end + return self end function c:Bind(t) @@ -335,6 +338,7 @@ function multi:newConnection(protect,func,kill) function c:SetHelper(func) conn_helper = func + return self end c.connect=c.Connect @@ -584,7 +588,7 @@ function multi:newEvent(task) task=func return self end - c.OnEvent = self:newConnection() + c.OnEvent = self:newConnection():fastMode() self:setPriority("core") c:SetName(c.Type) multi:create(c) @@ -607,7 +611,7 @@ function multi:newUpdater(skip) skip=n return self end - c.OnUpdate = self:newConnection() + c.OnUpdate = self:newConnection():fastMode() c:SetName(c.Type) multi:create(c) return c @@ -639,7 +643,7 @@ function multi:newAlarm(set) t = clock() return self end - c.OnRing = self:newConnection() + c.OnRing = self:newConnection():fastMode() function c:Pause() count = clock() self.Parent.Pause(self) @@ -663,15 +667,12 @@ function multi:newLoop(func,notime) self.OnLoop:Fire(self,clock()-start) end end - c.OnLoop = self:newConnection() - function c:fastMode() - self.OnLoop:fastMode() - end + c.OnLoop = self:newConnection():fastMode() if func then c.OnLoop(func) end - + multi:create(c) c:SetName(c.Type) return c @@ -713,9 +714,9 @@ function multi:newStep(start,reset,count,skip) end end c.Reset=c.Resume - c.OnStart = self:newConnection() - c.OnStep = self:newConnection() - c.OnEnd = self:newConnection() + c.OnStart = self:newConnection():fastMode() + c.OnStep = self:newConnection():fastMode() + c.OnEnd = self:newConnection():fastMode() function c:Break() self.Active=nil return self @@ -763,7 +764,7 @@ function multi:newTLoop(func,set) self.Parent.Pause(self) return self end - c.OnLoop = self:newConnection() + c.OnLoop = self:newConnection():fastMode() if func then c.OnLoop(func) end @@ -883,25 +884,28 @@ function multi:newProcessor(name,nothread) c.Type = "process" local Active = nothread or false c.Name = name or "" - c.pump = false c.threads = {} c.startme = {} c.parent = self local handler = c:createHandler(c.threads,c.startme) - c.process = self:newLoop(function() - if Active then - c:uManager() - handler() - end - end) + if not nothread then -- Don't create a loop if we are triggering this manually + c.process = self:newLoop(function() + if Active then + c:uManager() + handler() + end + end) + c.process.__ignore = true + c.process.isProcessThread = true + c.process.PID = sandcount + c.OnError = c.process.OnError + else + c.OnError = multi:newConnection() + end + - c.process.__ignore = true - - c.process.isProcessThread = true - c.process.PID = sandcount - c.OnError = c.process.OnError function c:getThreads() return c.threads @@ -930,10 +934,8 @@ function multi:newProcessor(name,nothread) function c.run() if not Active then return end - c.pump = true c:uManager() handler() - c.pump = false return c end diff --git a/test.lua b/test.lua index e4bebde..f9e93e6 100644 --- a/test.lua +++ b/test.lua @@ -3,25 +3,27 @@ package.cpath = "lua5.4/lib/lua/5.4/?/core.dll;"--..package.cpath multi, thread = require("multi"):init{print=true} -- GLOBAL, THREAD = require("multi.integration.lanesManager"):init() -local conn1, conn2, conn3 = multi:newConnection(), multi:newConnection(), multi:newConnection() -thread:newThread(function() - print("Awaiting status") - thread.hold(conn1 + (conn2 * conn3)) - print("Conn or Conn2 and Conn3") -end) +-- local conn1, conn2, conn3 = multi:newConnection(), multi:newConnection(), multi:newConnection() +-- thread:newThread(function() +-- print("Awaiting status") +-- thread.hold(conn1 + (conn2 * conn3)) +-- print("Conn or Conn2 and Conn3") +-- 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()