Skip to content

Commit

Permalink
Merge pull request #49 from lilith-avatar/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
endaye authored May 26, 2021
2 parents 3ebecce + 15194d2 commit 85ac29a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,30 @@ local tid = 0
local function CheckEvents()
-- now = os.time()
local now = Timer.GetTime()
local event
for i = #eventList, 1, -1 do
event = eventList[i]
for k, event in pairs(eventList) do
if event.triggerTime <= now then
activeEvents[event.id] = event
table.insert(activeEvents, event)
if event.loop then
event.triggerTime = event.triggerTime + event.delay
else
table.remove(eventList, i)
eventList[k] = nil
end
end
end
end

--- Trigger events
local function TriggerEvents()
local event
for i = #activeEvents, 1, -1 do
event = activeEvents[i]
for k, event in pairs(activeEvents) do
invoke(
function()
event.func()
end
)
table.remove(activeEvents, i)
activeEvents[k] = nil
end
assert(#activeEvents == 0, string.format('[TimeUtil] 有未执行的事件%s个', #activeEvents))
assert(next(activeEvents) == nil, string.format('[TimeUtil] 有未执行的事件%s个', table.nums(activeEvents)))
end

--- Update
Expand Down Expand Up @@ -99,17 +96,15 @@ function TimeUtil.SetTimeout(_func, _seconds)
invoke(_func)
return
end
tid = tid + 1
local timestamp = _seconds + Timer.GetTime()
table.insert(
eventList,
{
id = tid,
func = _func,
delay = _seconds,
triggerTime = timestamp
}
)
tid = tid + 1
eventList[tid] = {
id = tid,
func = _func,
delay = _seconds,
triggerTime = timestamp
}

return tid
end

Expand All @@ -123,36 +118,37 @@ function TimeUtil.SetInterval(_func, _seconds)
assert(_func, '[TimeUtil] TimeUtil.SetInterval() _func 不能为空')
assert(type(_func) == 'function', '[TimeUtil] TimeUtil.SetInterval() _func 类型不是function')
assert(_seconds > 0, '[TimeUtil] TimeUtil.SetInterval() 延迟时间需大于0')
local id = #eventList + 1
local timestamp = _seconds + Timer.GetTime()
tid = tid + 1
table.insert(
eventList,
{
id = tid,
func = _func,
delay = _seconds,
triggerTime = timestamp,
loop = true
}
)
eventList[tid] = {
id = tid,
func = _func,
delay = _seconds,
triggerTime = timestamp,
loop = true
}
return tid
end

--- Clear a timer set with the SetTimeout() method
--- @param _id timmer id
--- @param _tid timmer id
--- @see https://www.w3schools.com/jsref/met_win_cleartimeout.asp
function TimeUtil.ClearTimeout(_id)
for k, e in pairs(eventList) do
if e.id == _id then
table.remove(eventList, k)
break
end
end
function TimeUtil.ClearTimeout(_tid)
eventList[_tid] = nil
end

--- Clear a timer set with the SetInterval() method, used as ClearTimeout()
--- @see https://www.w3schools.com/jsref/met_win_clearinterval.asp
TimeUtil.ClearInterval = TimeUtil.ClearTimeout

--! TEST ONLY blow

-- Get current timer id
TimeUtil.GetTimerId = function()
return tid
end

--[[
print(TimeUtil.GetTimerId())
]]
return TimeUtil
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
--- This file is generated by ava-x2l.exe,
--- Don't change it manaully.
--- @copyright Lilith Games, Project Da Vinci(Avatar Team)
--- @see https://www.projectdavinci.com/
--- @see https://github.com/endaye/avatar-ava-xls2lua
--- @see Official Website: https://www.projectdavinci.com/
--- @see Dev Framework: https://github.com/lilith-avatar/avatar-ava
--- @see X2L Tool: https://github.com/lilith-avatar/avatar-ava-xls2lua
--- source file: ./Xls/ExampleTable1.xlsx

local Example1Xls = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
--- This file is generated by ava-x2l.exe,
--- Don't change it manaully.
--- @copyright Lilith Games, Project Da Vinci(Avatar Team)
--- @see https://www.projectdavinci.com/
--- @see https://github.com/endaye/avatar-ava-xls2lua
--- @see Official Website: https://www.projectdavinci.com/
--- @see Dev Framework: https://github.com/lilith-avatar/avatar-ava
--- @see X2L Tool: https://github.com/lilith-avatar/avatar-ava-xls2lua
--- source file: ./Xls/ExampleTable1.xlsx

local Example2Xls = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
--- This file is generated by ava-x2l.exe,
--- Don't change it manaully.
--- @copyright Lilith Games, Project Da Vinci(Avatar Team)
--- @see https://www.projectdavinci.com/
--- @see https://github.com/endaye/avatar-ava-xls2lua
--- @see Official Website: https://www.projectdavinci.com/
--- @see Dev Framework: https://github.com/lilith-avatar/avatar-ava
--- @see X2L Tool: https://github.com/lilith-avatar/avatar-ava-xls2lua
--- source file: ./Xls/GlobalSetting.xls

local GlobalSettingXls = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
--- This file is generated by ava-x2l.exe,
--- Don't change it manaully.
--- @copyright Lilith Games, Project Da Vinci(Avatar Team)
--- @see https://www.projectdavinci.com/
--- @see https://github.com/endaye/avatar-ava-xls2lua
--- @see Official Website: https://www.projectdavinci.com/
--- @see Dev Framework: https://github.com/lilith-avatar/avatar-ava
--- @see X2L Tool: https://github.com/lilith-avatar/avatar-ava-xls2lua
--- source file: ./Xls/LanguagePack.xls

local LanguagePackXls = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
--- This file is generated by ava-x2l.exe,
--- Don't change it manaully.
--- @copyright Lilith Games, Project Da Vinci(Avatar Team)
--- @see https://www.projectdavinci.com/
--- @see https://github.com/endaye/avatar-ava-xls2lua
--- @see Official Website: https://www.projectdavinci.com/
--- @see Dev Framework: https://github.com/lilith-avatar/avatar-ava
--- @see X2L Tool: https://github.com/lilith-avatar/avatar-ava-xls2lua
--- source file: ./Xls/Sound.xls

local SoundXls = {
Expand Down
Binary file modified Smap/avatar-ava.smap
Binary file not shown.

0 comments on commit 85ac29a

Please sign in to comment.