移除task模块对联网任务的计数处理
This commit is contained in:
@@ -2,23 +2,16 @@ local rem=table.remove
|
|||||||
local ct=coroutine
|
local ct=coroutine
|
||||||
local assert=assert
|
local assert=assert
|
||||||
local tasks={}
|
local tasks={}
|
||||||
local netTaskCount=0
|
|
||||||
|
|
||||||
local TASK={}
|
local TASK={}
|
||||||
function TASK.getCount()
|
function TASK.getCount()
|
||||||
return #tasks
|
return #tasks
|
||||||
end
|
end
|
||||||
function TASK.netTaskCount()
|
|
||||||
return netTaskCount
|
|
||||||
end
|
|
||||||
function TASK.update()
|
function TASK.update()
|
||||||
for i=#tasks,1,-1 do
|
for i=#tasks,1,-1 do
|
||||||
local T=tasks[i]
|
local T=tasks[i]
|
||||||
assert(ct.resume(T.thread))
|
assert(ct.resume(T.thread))
|
||||||
if ct.status(T.thread)=="dead"then
|
if ct.status(T.thread)=="dead"then
|
||||||
if T.net then
|
|
||||||
netTaskCount=netTaskCount-1
|
|
||||||
end
|
|
||||||
rem(tasks,i)
|
rem(tasks,i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -34,25 +27,9 @@ function TASK.new(code,...)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function TASK.newNet(code,...)
|
|
||||||
local thread=ct.create(code)
|
|
||||||
ct.resume(thread,...)
|
|
||||||
if ct.status(thread)~="dead"then
|
|
||||||
tasks[#tasks+1]={
|
|
||||||
thread=thread,
|
|
||||||
code=code,
|
|
||||||
args={...},
|
|
||||||
net=true,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
netTaskCount=netTaskCount+1
|
|
||||||
end
|
|
||||||
function TASK.removeTask_code(code)
|
function TASK.removeTask_code(code)
|
||||||
for i=#tasks,1,-1 do
|
for i=#tasks,1,-1 do
|
||||||
if tasks[i].code==code then
|
if tasks[i].code==code then
|
||||||
if tasks[i].net then
|
|
||||||
netTaskCount=netTaskCount-1
|
|
||||||
end
|
|
||||||
rem(tasks,i)
|
rem(tasks,i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -60,9 +37,6 @@ end
|
|||||||
function TASK.removeTask_iterate(func,...)
|
function TASK.removeTask_iterate(func,...)
|
||||||
for i=#tasks,1,-1 do
|
for i=#tasks,1,-1 do
|
||||||
if func(tasks[i],...)then
|
if func(tasks[i],...)then
|
||||||
if tasks[i].net then
|
|
||||||
netTaskCount=netTaskCount-1
|
|
||||||
end
|
|
||||||
rem(tasks,i)
|
rem(tasks,i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user