Added Threaded TLoops
Modified the benchmark command Fixed bugs in: Timer s Conditions and Ranges
This commit is contained in:
parent
9c3bef8d78
commit
0e36ec917d
@ -33,6 +33,7 @@ Constructors [ACTORS]
|
||||
eventObj=multi:newEvent([function: TASK defualt: function() end])
|
||||
alarmObj=multi:newAlarm([number: SET defualt: 0])
|
||||
loopObj=multi:newLoop([function: FUNC])
|
||||
tloopObj=multi:newTLoop([function: FUNC], number: n)
|
||||
stepObj=multi:newStep([number: START defualt: 0],[number: RESET defualt: inf],[number: COUNT defualt: 1],[number: SKIP defualt: 0])
|
||||
tstepObj=multi:newTStep([number: START defualt: 0],[number: RESET defualt: inf],[number: COUNT defualt: 1],[number: SET defualt: 1])
|
||||
updaterObj=multi:newUpdater([number: SKIP defualt: 0])
|
||||
|
||||
@ -311,9 +311,12 @@ function multi:fromfile(path,int)
|
||||
end
|
||||
return test2
|
||||
end
|
||||
function multi:benchMark(sec,p)
|
||||
function multi:benchMark(sec,p,pt)
|
||||
local temp=self:newLoop(function(t,self)
|
||||
if self.clock()-self.init>self.sec then
|
||||
if pt then
|
||||
print(pt.." "..self.c.." Steps in "..sec.." second(s)!")
|
||||
end
|
||||
self.tt(self.sec,self.c)
|
||||
self:Destroy()
|
||||
else
|
||||
@ -682,17 +685,24 @@ function multi:newTimer()
|
||||
c.Type='timer'
|
||||
c.time=0
|
||||
c.count=0
|
||||
c.paused=false
|
||||
function c:Start()
|
||||
self.time=os.clock()
|
||||
end
|
||||
function c:Get()
|
||||
if self:isPaused() then return self.time end
|
||||
return (os.clock()-self.time)+self.count
|
||||
end
|
||||
function c:isPaused()
|
||||
return c.paused
|
||||
end
|
||||
c.Reset=c.Start
|
||||
function c:Pause()
|
||||
self.time=self:Get()
|
||||
self.paused=true
|
||||
end
|
||||
function c:Resume()
|
||||
self.paused=false
|
||||
self.time=os.clock()-self.time
|
||||
end
|
||||
function c:tofile(path)
|
||||
@ -746,10 +756,10 @@ function multi:newConnection(protect)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
function c:bind(t)
|
||||
function c:Bind(t)
|
||||
self.func=t
|
||||
end
|
||||
function c:remove()
|
||||
function c:Remove()
|
||||
self.func={}
|
||||
end
|
||||
function c:connect(func,name)
|
||||
@ -775,7 +785,7 @@ function multi:newConnection(protect)
|
||||
return self.func(...)
|
||||
end
|
||||
end,
|
||||
remove=function(self)
|
||||
Remove=function(self)
|
||||
for i=1,#self.Link do
|
||||
if self.Link[i][2]~=nil then
|
||||
if self.Link[i][2]==self.ID then
|
||||
@ -794,6 +804,7 @@ function multi:newConnection(protect)
|
||||
end
|
||||
return temp
|
||||
end
|
||||
c.Connect=c.connect
|
||||
function c:tofile(path)
|
||||
local m=bin.new()
|
||||
m:addBlock(self.Type)
|
||||
|
||||
42
multi/threading/tloop.lua
Normal file
42
multi/threading/tloop.lua
Normal file
@ -0,0 +1,42 @@
|
||||
require("multi.threading")
|
||||
function multi:newThreadedTLoop(name,func,n)
|
||||
local c=self:newTBase()
|
||||
c.Type='tloopThread'
|
||||
c.restN=n or 1
|
||||
if func then
|
||||
c.func={func}
|
||||
end
|
||||
function c:tofile(path)
|
||||
local m=bin.new()
|
||||
m:addBlock(self.Type)
|
||||
m:addBlock(self.func)
|
||||
m:addBlock(self.Active)
|
||||
m:tofile(path)
|
||||
end
|
||||
function c:Resume()
|
||||
self.rest=false
|
||||
end
|
||||
function c:Pause()
|
||||
self.rest=true
|
||||
end
|
||||
function c:OnLoop(func)
|
||||
table.insert(self.func,func)
|
||||
end
|
||||
c.rest=false
|
||||
c.updaterate=0
|
||||
c.restRate=.75
|
||||
multi:newThread(name,function(ref)
|
||||
while true do
|
||||
if c.rest then
|
||||
thread.sleep(c.restRate) -- rest a bit more when a thread is paused
|
||||
else
|
||||
for i=1,#c.func do
|
||||
c.func[i](c)
|
||||
end
|
||||
thread.sleep(c.restN) -- lets rest a bit
|
||||
end
|
||||
end
|
||||
end)
|
||||
self:create(c)
|
||||
return c
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user