微调task模块功能
This commit is contained in:
@@ -538,7 +538,7 @@ function love.run()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Draw network working
|
--Draw network working
|
||||||
if TASK.netTaskCount>0 then
|
if TASK.netTaskCount()>0 then
|
||||||
setFont(30)
|
setFont(30)
|
||||||
gc.setColor(COLOR.rainbow(t*5))
|
gc.setColor(COLOR.rainbow(t*5))
|
||||||
gc.print("E",SCR.safeW-18,17,.26+.355*math.sin(t*6.26),nil,nil,8,20)
|
gc.print("E",SCR.safeW-18,17,.26+.355*math.sin(t*6.26),nil,nil,8,20)
|
||||||
|
|||||||
@@ -2,20 +2,22 @@ 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={}
|
||||||
netTaskCount=0,
|
|
||||||
}
|
|
||||||
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
|
if T.net then
|
||||||
TASK.netTaskCount=TASK.netTaskCount-1
|
netTaskCount=netTaskCount-1
|
||||||
end
|
end
|
||||||
rem(tasks,i)
|
rem(tasks,i)
|
||||||
end
|
end
|
||||||
@@ -43,12 +45,13 @@ function TASK.newNet(code,...)
|
|||||||
net=true,
|
net=true,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
netTaskCount=netTaskCount+1
|
||||||
end
|
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
|
if tasks[i].net then
|
||||||
TASK.netTaskCount=TASK.netTaskCount-1
|
netTaskCount=netTaskCount-1
|
||||||
end
|
end
|
||||||
rem(tasks,i)
|
rem(tasks,i)
|
||||||
end
|
end
|
||||||
@@ -58,7 +61,7 @@ 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
|
if tasks[i].net then
|
||||||
TASK.netTaskCount=TASK.netTaskCount-1
|
netTaskCount=netTaskCount-1
|
||||||
end
|
end
|
||||||
rem(tasks,i)
|
rem(tasks,i)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user