Skip to content

Commit

Permalink
合并过小的进度条更新
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Dec 26, 2016
1 parent fdd6deb commit 45bbfcd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions script/progress.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ local min_rate = 0
local max_rate = 1
local min = {}
local max = {}
local progress = 0

local function send_progress()
local newprogress = current * (max_rate - min_rate) + min_rate
if progress + 0.01 < newprogress then
message('-progress', newprogress)
progress = newprogress
end
end

local function refresh_rate()
min_rate = 0
Expand All @@ -15,7 +24,6 @@ local function refresh_rate()
min_rate = min_rate * (max[i] - min[i]) + min[i]
max_rate = max_rate * (max[i] - min[i]) + min[i]
end
message('-progress', current * (max_rate - min_rate) + min_rate)
end

-- 开启新任务,新任务完成时当前任务的完成进度
Expand All @@ -32,12 +40,13 @@ function mt:finish()
current = max[level]
level = level - 1
refresh_rate()
send_progress()
end

-- 设置当前任务进度
function mt:__call(n)
current = n
message('-progress', current * (max_rate - min_rate) + min_rate)
send_progress()
end

return mt

0 comments on commit 45bbfcd

Please sign in to comment.