mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
SCHEDULER:New() implemented and routines.scheduleFunction removed
This commit is contained in:
parent
bed2a339a1
commit
9afe0acd8d
@ -4,6 +4,8 @@
|
||||
Include.File( "Routines" )
|
||||
Include.File( "Base" )
|
||||
Include.File( "Message" )
|
||||
Include.File( "Scheduler" )
|
||||
|
||||
|
||||
--- Clients are those Groups defined within the Mission Editor that have the skillset defined as "Client" or "Player".
|
||||
-- These clients are defined within the Mission Orchestration Framework (MOF)
|
||||
@ -673,7 +675,8 @@ function CARGO_GROUP:OnBoard( Client, LandingZone, OnBoardSide )
|
||||
end
|
||||
self:T( "TransportCargoOnBoard: Routing " .. self.CargoGroupName )
|
||||
|
||||
routines.scheduleFunction( routines.goRoute, { self.CargoGroupName, Points}, timer.getTime() + 4 )
|
||||
--routines.scheduleFunction( routines.goRoute, { self.CargoGroupName, Points}, timer.getTime() + 4 )
|
||||
SCHEDULER:New( self, routines.goRoute, { self.CargoGroupName, Points}, 4 )
|
||||
end
|
||||
|
||||
self:StatusLoading( Client )
|
||||
@ -884,7 +887,8 @@ function CARGO_PACKAGE:OnBoard( Client, LandingZone, OnBoardSide )
|
||||
end
|
||||
self:T( "Routing " .. CargoHostName )
|
||||
|
||||
routines.scheduleFunction( routines.goRoute, { CargoHostName, Points}, timer.getTime() + 4 )
|
||||
--routines.scheduleFunction( routines.goRoute, { CargoHostName, Points}, timer.getTime() + 4 )
|
||||
SCHEDULER:New( self, routines.goRoute, { CargoHostName, Points }, 4 )
|
||||
|
||||
return Valid
|
||||
|
||||
|
||||
@ -43,7 +43,8 @@ function CLEANUP:New( ZoneNames, TimeInterval ) local self = BASE:Inherit( self,
|
||||
|
||||
_EVENTDISPATCHER:OnBirth( self._OnEventBirth, self )
|
||||
|
||||
self.CleanUpScheduler = routines.scheduleFunction( self._CleanUpScheduler, { self }, timer.getTime() + 1, TimeInterval )
|
||||
--self.CleanUpScheduler = routines.scheduleFunction( self._CleanUpScheduler, { self }, timer.getTime() + 1, TimeInterval )
|
||||
self.CleanUpScheduler = SCHEDULER:New( self, self._CleanUpScheduler, {}, 1, TimeInterval )
|
||||
|
||||
return self
|
||||
end
|
||||
@ -170,7 +171,8 @@ function CLEANUP:_EventShot( Event )
|
||||
if ( CurrentLandingZoneID ) then
|
||||
-- Okay, the missile was fired within the CLEANUP.ZoneNames, destroy the fired weapon.
|
||||
--_SEADmissile:destroy()
|
||||
routines.scheduleFunction( CLEANUP._DestroyMissile, { self, Event.Weapon }, timer.getTime() + 0.1)
|
||||
--routines.scheduleFunction( CLEANUP._DestroyMissile, { self, Event.Weapon }, timer.getTime() + 0.1)
|
||||
SCHEDULER:New( self, CLEANUP._DestroyMissile, { Event.Weapon }, 0.1 )
|
||||
end
|
||||
end
|
||||
|
||||
@ -186,7 +188,8 @@ function CLEANUP:_EventHitCleanUp( Event )
|
||||
self:T( { "Life: ", Event.IniDCSUnitName, ' = ', Event.IniDCSUnit:getLife(), "/", Event.IniDCSUnit:getLife0() } )
|
||||
if Event.IniDCSUnit:getLife() < Event.IniDCSUnit:getLife0() then
|
||||
self:T( "CleanUp: Destroy: " .. Event.IniDCSUnitName )
|
||||
routines.scheduleFunction( CLEANUP._DestroyUnit, { self, Event.IniDCSUnit }, timer.getTime() + 0.1)
|
||||
--routines.scheduleFunction( CLEANUP._DestroyUnit, { self, Event.IniDCSUnit }, timer.getTime() + 0.1)
|
||||
SCHEDULER:New( self, CLEANUP._DestroyUnit, { Event.IniDCSUnit }, 0.1 )
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -196,7 +199,8 @@ function CLEANUP:_EventHitCleanUp( Event )
|
||||
self:T( { "Life: ", Event.TgtDCSUnitName, ' = ', Event.TgtDCSUnit:getLife(), "/", Event.TgtDCSUnit:getLife0() } )
|
||||
if Event.TgtDCSUnit:getLife() < Event.TgtDCSUnit:getLife0() then
|
||||
self:T( "CleanUp: Destroy: " .. Event.TgtDCSUnitName )
|
||||
routines.scheduleFunction( CLEANUP._DestroyUnit, { self, Event.TgtDCSUnit }, timer.getTime() + 0.1 )
|
||||
--routines.scheduleFunction( CLEANUP._DestroyUnit, { self, Event.TgtDCSUnit }, timer.getTime() + 0.1 )
|
||||
SCHEDULER:New( self, CLEANUP._DestroyUnit, { Event.TgtDCSUnit }, 0.1 )
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -319,5 +323,7 @@ function CLEANUP:_CleanUpScheduler()
|
||||
end
|
||||
end
|
||||
self:T(CleanUpCount)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
@ -130,7 +130,8 @@ function CLIENT:Register( ClientName )
|
||||
self.MessageSwitch = true
|
||||
self.ClientAlive2 = false
|
||||
|
||||
self.AliveCheckScheduler = routines.scheduleFunction( self._AliveCheckScheduler, { self }, timer.getTime() + 1, 5 )
|
||||
--self.AliveCheckScheduler = routines.scheduleFunction( self._AliveCheckScheduler, { self }, timer.getTime() + 1, 5 )
|
||||
self.AliveCheckScheduler = SCHEDULER:New( self, self._AliveCheckScheduler, {}, 1, 5 )
|
||||
|
||||
return self
|
||||
end
|
||||
@ -245,6 +246,8 @@ function CLIENT:_AliveCheckScheduler()
|
||||
self.ClientAlive2 = false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- Return the DCSGroup of a Client.
|
||||
|
||||
@ -527,7 +527,8 @@ function ESCORT:MenuReportTargets( Seconds )
|
||||
self.EscortMenuAttackNearbyTargets = MENU_CLIENT:New( self.EscortClient, "Attack targets", self.EscortMenu )
|
||||
|
||||
|
||||
self.ReportTargetsScheduler = routines.scheduleFunction( self._ReportTargetsScheduler, { self }, timer.getTime() + 1, Seconds )
|
||||
--self.ReportTargetsScheduler = routines.scheduleFunction( self._ReportTargetsScheduler, { self }, timer.getTime() + 1, Seconds )
|
||||
self.ReportTargetsScheduler = SCHEDULER:New( self, self._ReportTargetsScheduler, {}, 1, Seconds )
|
||||
|
||||
return self
|
||||
end
|
||||
@ -694,7 +695,8 @@ function ESCORT:JoinUpAndFollow( EscortGroup, EscortClient, Distance )
|
||||
|
||||
self.CT1 = 0
|
||||
self.GT1 = 0
|
||||
self.FollowScheduler = routines.scheduleFunction( self._FollowScheduler, { self, Distance }, timer.getTime() + 1, .5 )
|
||||
--self.FollowScheduler = routines.scheduleFunction( self._FollowScheduler, { self, Distance }, timer.getTime() + 1, .5 )
|
||||
self.FollowScheduler = SCHEDULER:New( self, self._FollowScheduler, { Distance }, 1, .5, .1 )
|
||||
EscortGroup:MessageToClient( "Rejoining and Following at " .. Distance .. "!", 30, EscortClient )
|
||||
end
|
||||
|
||||
@ -748,7 +750,8 @@ function ESCORT._SwitchReportNearbyTargets( MenuParam )
|
||||
|
||||
if self.ReportTargets then
|
||||
if not self.ReportTargetsScheduler then
|
||||
self.ReportTargetsScheduler = routines.scheduleFunction( self._ReportTargetsScheduler, { self }, timer.getTime() + 1, 30 )
|
||||
--self.ReportTargetsScheduler = routines.scheduleFunction( self._ReportTargetsScheduler, { self }, timer.getTime() + 1, 30 )
|
||||
self.ReportTargetsScheduler = SCHEDULER:New( self, self._ReportTargetsScheduler, {}, 1, 30 )
|
||||
end
|
||||
else
|
||||
routines.removeFunction( self.ReportTargetsScheduler )
|
||||
@ -772,31 +775,30 @@ function ESCORT._ScanTargets( MenuParam )
|
||||
self:T( { "FollowScheduler after removefunction: ", self.FollowScheduler } )
|
||||
|
||||
if EscortGroup:IsHelicopter() then
|
||||
routines.scheduleFunction( EscortGroup.PushTask,
|
||||
{ EscortGroup,
|
||||
EscortGroup:TaskControlled(
|
||||
SCHEDULER:New( EscortGroup, EscortGroup.PushTask,
|
||||
{ EscortGroup:TaskControlled(
|
||||
EscortGroup:TaskOrbitCircle( 200, 20 ),
|
||||
EscortGroup:TaskCondition( nil, nil, nil, nil, ScanDuration, nil )
|
||||
)
|
||||
},
|
||||
timer.getTime() + 1
|
||||
1
|
||||
)
|
||||
elseif EscortGroup:IsAirPlane() then
|
||||
routines.scheduleFunction( EscortGroup.PushTask,
|
||||
{ EscortGroup,
|
||||
EscortGroup:TaskControlled(
|
||||
SCHEDULER:New( EscortGroup, EscortGroup.PushTask,
|
||||
{ EscortGroup:TaskControlled(
|
||||
EscortGroup:TaskOrbitCircle( 1000, 500 ),
|
||||
EscortGroup:TaskCondition( nil, nil, nil, nil, ScanDuration, nil )
|
||||
)
|
||||
},
|
||||
timer.getTime() + 1
|
||||
1
|
||||
)
|
||||
end
|
||||
|
||||
EscortGroup:MessageToClient( "Scanning targets for " .. ScanDuration .. " seconds.", ScanDuration, EscortClient )
|
||||
|
||||
if self.EscortMode == ESCORT.MODE.FOLLOW then
|
||||
self.FollowScheduler = routines.scheduleFunction( self._FollowScheduler, { self, Distance }, timer.getTime() + ScanDuration, 1 )
|
||||
--self.FollowScheduler = routines.scheduleFunction( self._FollowScheduler, { self, Distance }, timer.getTime() + ScanDuration, 1 )
|
||||
self.FollowScheduler:Start()
|
||||
end
|
||||
|
||||
end
|
||||
@ -830,25 +832,42 @@ function ESCORT._AttackTarget( MenuParam )
|
||||
EscortGroup:OptionROEOpenFire()
|
||||
EscortGroup:OptionROTPassiveDefense()
|
||||
EscortGroup.Escort = self -- Need to do this trick to get the reference for the escort in the _Resume function.
|
||||
routines.scheduleFunction(
|
||||
-- routines.scheduleFunction(
|
||||
-- EscortGroup.PushTask,
|
||||
-- { EscortGroup,
|
||||
-- EscortGroup:TaskCombo(
|
||||
-- { EscortGroup:TaskAttackUnit( AttackUnit ),
|
||||
-- EscortGroup:TaskFunction( 1, 2, "_Resume", {"''"} )
|
||||
-- }
|
||||
-- )
|
||||
-- }, timer.getTime() + 10
|
||||
-- )
|
||||
SCHEDULER:New( EscortGroup,
|
||||
EscortGroup.PushTask,
|
||||
{ EscortGroup,
|
||||
EscortGroup:TaskCombo(
|
||||
{ EscortGroup:TaskCombo(
|
||||
{ EscortGroup:TaskAttackUnit( AttackUnit ),
|
||||
EscortGroup:TaskFunction( 1, 2, "_Resume", {"''"} )
|
||||
}
|
||||
)
|
||||
}, timer.getTime() + 10
|
||||
}, 10
|
||||
)
|
||||
else
|
||||
routines.scheduleFunction(
|
||||
-- routines.scheduleFunction(
|
||||
-- EscortGroup.PushTask,
|
||||
-- { EscortGroup,
|
||||
-- EscortGroup:TaskCombo(
|
||||
-- { EscortGroup:TaskFireAtPoint( AttackUnit:GetPointVec2(), 50 )
|
||||
-- }
|
||||
-- )
|
||||
-- }, timer.getTime() + 10
|
||||
-- )
|
||||
SCHEDULER:New( EscortGroup,
|
||||
EscortGroup.PushTask,
|
||||
{ EscortGroup,
|
||||
EscortGroup:TaskCombo(
|
||||
{ EscortGroup:TaskCombo(
|
||||
{ EscortGroup:TaskFireAtPoint( AttackUnit:GetPointVec2(), 50 )
|
||||
}
|
||||
)
|
||||
}, timer.getTime() + 10
|
||||
}, 10
|
||||
)
|
||||
end
|
||||
EscortGroup:MessageToClient( "Engaging Designated Unit!", 10, EscortClient )
|
||||
@ -875,25 +894,42 @@ function ESCORT._AssistTarget( MenuParam )
|
||||
if EscortGroupAttack:IsAir() then
|
||||
EscortGroupAttack:OptionROEOpenFire()
|
||||
EscortGroupAttack:OptionROTVertical()
|
||||
routines.scheduleFunction(
|
||||
-- routines.scheduleFunction(
|
||||
-- EscortGroupAttack.PushTask,
|
||||
-- { EscortGroupAttack,
|
||||
-- EscortGroupAttack:TaskCombo(
|
||||
-- { EscortGroupAttack:TaskAttackUnit( AttackUnit ),
|
||||
-- EscortGroupAttack:TaskOrbitCircle( 500, 350 )
|
||||
-- }
|
||||
-- )
|
||||
-- }, timer.getTime() + 10
|
||||
-- )
|
||||
SCHDULER:New( EscortGroupAttack,
|
||||
EscortGroupAttack.PushTask,
|
||||
{ EscortGroupAttack,
|
||||
EscortGroupAttack:TaskCombo(
|
||||
{ EscortGroupAttack:TaskCombo(
|
||||
{ EscortGroupAttack:TaskAttackUnit( AttackUnit ),
|
||||
EscortGroupAttack:TaskOrbitCircle( 500, 350 )
|
||||
}
|
||||
)
|
||||
}, timer.getTime() + 10
|
||||
}, 10
|
||||
)
|
||||
else
|
||||
routines.scheduleFunction(
|
||||
-- routines.scheduleFunction(
|
||||
-- EscortGroupAttack.PushTask,
|
||||
-- { EscortGroupAttack,
|
||||
-- EscortGroupAttack:TaskCombo(
|
||||
-- { EscortGroupAttack:TaskFireAtPoint( AttackUnit:GetPointVec2(), 50 )
|
||||
-- }
|
||||
-- )
|
||||
-- }, timer.getTime() + 10
|
||||
-- )
|
||||
SCHEDULER:New( EscortGroupAttack,
|
||||
EscortGroupAttack.PushTask,
|
||||
{ EscortGroupAttack,
|
||||
EscortGroupAttack:TaskCombo(
|
||||
{ EscortGroupAttack:TaskCombo(
|
||||
{ EscortGroupAttack:TaskFireAtPoint( AttackUnit:GetPointVec2(), 50 )
|
||||
}
|
||||
)
|
||||
}, timer.getTime() + 10
|
||||
}, 10
|
||||
)
|
||||
end
|
||||
EscortGroupAttack:MessageToClient( "Assisting with the destroying the enemy unit!", 10, EscortClient )
|
||||
@ -947,7 +983,8 @@ function ESCORT._ResumeMission( MenuParam )
|
||||
table.remove( WayPoints, 1 )
|
||||
end
|
||||
|
||||
routines.scheduleFunction( EscortGroup.SetTask, {EscortGroup, EscortGroup:TaskRoute( WayPoints ) }, timer.getTime() + 1 )
|
||||
--routines.scheduleFunction( EscortGroup.SetTask, {EscortGroup, EscortGroup:TaskRoute( WayPoints ) }, timer.getTime() + 1 )
|
||||
SCHEDULER:New( EscortGroup, EscortGroup.SetTask, { EscortGroup:TaskRoute( WayPoints ) }, 1 )
|
||||
|
||||
EscortGroup:MessageToClient( "Resuming mission from waypoint " .. WayPoint .. ".", 10, EscortClient )
|
||||
end
|
||||
@ -1036,6 +1073,8 @@ function ESCORT:_FollowScheduler( FollowDistance )
|
||||
|
||||
-- Now we can calculate the group destination vector GDV.
|
||||
local GDV = { x = DVu.x * CS * 8 + CVI.x, y = CVI.y, z = DVu.z * CS * 8 + CVI.z }
|
||||
|
||||
--trigger.action.smoke( GDV, trigger.smokeColor.Red )
|
||||
self:T2( { "CV2:", CV2 } )
|
||||
self:T2( { "CVI:", CVI } )
|
||||
self:T2( { "GDV:", GDV } )
|
||||
@ -1058,10 +1097,10 @@ function ESCORT:_FollowScheduler( FollowDistance )
|
||||
-- Now route the escort to the desired point with the desired speed.
|
||||
self.EscortGroup:TaskRouteToVec3( GDV, Speed / 3.6 ) -- DCS models speed in Mps (Miles per second)
|
||||
end
|
||||
else
|
||||
routines.removeFunction( self.FollowScheduler )
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
@ -1239,9 +1278,8 @@ function ESCORT:_ReportTargetsScheduler()
|
||||
MENU_CLIENT_COMMAND:New( self.EscortClient, "Waypoint " .. WayPointID .. " at " .. string.format( "%.2f", Distance ).. "km", self.EscortMenuResumeMission, ESCORT._ResumeMission, { ParamSelf = self, ParamWayPoint = WayPointID } )
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
routines.removeFunction( self.ReportTargetsScheduler )
|
||||
self.ReportTargetsScheduler = nil
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
@ -701,7 +701,8 @@ function GROUP:PushTask( DCSTask, WaitTime )
|
||||
-- Controller:pushTask( DCSTask )
|
||||
|
||||
if WaitTime then
|
||||
routines.scheduleFunction( Controller.pushTask, { Controller, DCSTask }, timer.getTime() + WaitTime )
|
||||
--routines.scheduleFunction( Controller.pushTask, { Controller, DCSTask }, timer.getTime() + WaitTime )
|
||||
SCHEDULER:New( Controller, Controller.pushTask, { DCSTask }, WaitTime )
|
||||
else
|
||||
Controller:pushTask( DCSTask )
|
||||
end
|
||||
@ -731,7 +732,8 @@ function GROUP:SetTask( DCSTask, WaitTime )
|
||||
if not WaitTime then
|
||||
WaitTime = 1
|
||||
end
|
||||
routines.scheduleFunction( Controller.setTask, { Controller, DCSTask }, timer.getTime() + WaitTime )
|
||||
--routines.scheduleFunction( Controller.setTask, { Controller, DCSTask }, timer.getTime() + WaitTime )
|
||||
SCHEDULER:New( Controller, Controller.setTask, { DCSTask }, WaitTime )
|
||||
|
||||
return self
|
||||
end
|
||||
@ -1275,7 +1277,8 @@ function GROUP:Route( GoPoints )
|
||||
local MissionTask = { id = 'Mission', params = { route = { points = Points, }, }, }
|
||||
local Controller = self:_GetController()
|
||||
--Controller.setTask( Controller, MissionTask )
|
||||
routines.scheduleFunction( Controller.setTask, { Controller, MissionTask}, timer.getTime() + 1 )
|
||||
--routines.scheduleFunction( Controller.setTask, { Controller, MissionTask}, timer.getTime() + 1 )
|
||||
SCHEDULER:New( Controller, Controller.setTask, { MissionTask }, 1 )
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
@ -187,7 +187,8 @@ function MESSAGEQUEUE:New( RefreshInterval )
|
||||
|
||||
self.RefreshInterval = RefreshInterval
|
||||
|
||||
self.DisplayFunction = routines.scheduleFunction( self._DisplayMessages, { self }, 0, RefreshInterval )
|
||||
--self.DisplayFunction = routines.scheduleFunction( self._DisplayMessages, { self }, 0, RefreshInterval )
|
||||
self.DisplayFunction = SCHEDULER:New( self, self._DisplayMessages, {}, 0, RefreshInterval )
|
||||
|
||||
return self
|
||||
end
|
||||
@ -240,6 +241,8 @@ function MESSAGEQUEUE:_DisplayMessages()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- The _MessageQueue object is created when the MESSAGE class module is loaded.
|
||||
|
||||
@ -520,12 +520,15 @@ function MISSIONSCHEDULER.Scheduler()
|
||||
Mission:ReportToAll()
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- Start the MISSIONSCHEDULER.
|
||||
function MISSIONSCHEDULER.Start()
|
||||
if MISSIONSCHEDULER ~= nil then
|
||||
MISSIONSCHEDULER.SchedulerId = routines.scheduleFunction( MISSIONSCHEDULER.Scheduler, { }, 0, 2 )
|
||||
--MISSIONSCHEDULER.SchedulerId = routines.scheduleFunction( MISSIONSCHEDULER.Scheduler, { }, 0, 2 )
|
||||
MISSIONSCHEDULER.SchedulerId = SCHEDULER:New( nil, MISSIONSCHEDULER.Scheduler, { }, 0, 2 )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -49,7 +49,8 @@ end
|
||||
--- Call this function to start the MOVEMENT scheduling.
|
||||
function MOVEMENT:ScheduleStart()
|
||||
self:F()
|
||||
self.MoveFunction = routines.scheduleFunction( self._Scheduler, { self }, timer.getTime() + 1, 120 )
|
||||
--self.MoveFunction = routines.scheduleFunction( self._Scheduler, { self }, timer.getTime() + 1, 120 )
|
||||
self.MoveFunction = SCHEDULER:New( self, self._Scheduler, {}, 1, 120 )
|
||||
end
|
||||
|
||||
--- Call this function to stop the MOVEMENT scheduling.
|
||||
@ -125,4 +126,5 @@ function MOVEMENT:_Scheduler()
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
@ -461,102 +461,6 @@ do
|
||||
end
|
||||
|
||||
|
||||
do
|
||||
local Tasks = {}
|
||||
local task_id = 0
|
||||
--[[ routines.scheduleFunction:
|
||||
int id = routines.schedule_task(f function, vars table, t number, rep number, st number)
|
||||
id - integer id of this function task
|
||||
f - function to run
|
||||
vars - table of vars for that function
|
||||
t - time to run function
|
||||
rep - time between repetitions of this function (OPTIONAL)
|
||||
st - time when repetitions of this function will stop automatically (OPTIONAL)
|
||||
]]
|
||||
|
||||
--- Schedule a function
|
||||
-- @param #function f
|
||||
-- @param #table parameters
|
||||
-- @param #Time t
|
||||
-- @param #Time rep seconds
|
||||
-- @param #Time st
|
||||
routines.scheduleFunction = function(f, vars, t, rep, st)
|
||||
--verify correct types
|
||||
assert(type(f) == 'function', 'variable 1, expected function, got ' .. type(f))
|
||||
assert(type(vars) == 'table' or vars == nil, 'variable 2, expected table or nil, got ' .. type(f))
|
||||
assert(type(t) == 'number', 'variable 3, expected number, got ' .. type(t))
|
||||
assert(type(rep) == 'number' or rep == nil, 'variable 4, expected number or nil, got ' .. type(rep))
|
||||
assert(type(st) == 'number' or st == nil, 'variable 5, expected number or nil, got ' .. type(st))
|
||||
if not vars then
|
||||
vars = {}
|
||||
end
|
||||
task_id = task_id + 1
|
||||
table.insert(Tasks, {f = f, vars = vars, t = t, rep = rep, st = st, id = task_id})
|
||||
return task_id
|
||||
end
|
||||
|
||||
-- removes a scheduled function based on the function's id. returns true if successful, false if not successful.
|
||||
routines.removeFunction = function(id)
|
||||
local i = 1
|
||||
while i <= #Tasks do
|
||||
if Tasks[i].id == id then
|
||||
table.remove(Tasks, i)
|
||||
else
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
routines.errhandler = function(errmsg)
|
||||
|
||||
env.info( "Error in scheduled function:" .. errmsg )
|
||||
env.info( debug.traceback() )
|
||||
|
||||
return errmsg
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------------
|
||||
-- not intended for users to use this function.
|
||||
routines.do_scheduled_functions = function()
|
||||
local i = 1
|
||||
while i <= #Tasks do
|
||||
if not Tasks[i].rep then -- not a repeated process
|
||||
if Tasks[i].t <= timer.getTime() then
|
||||
local Task = Tasks[i] -- local reference
|
||||
--env.info("do_scheduled_functions:call function " .. i )
|
||||
table.remove(Tasks, i)
|
||||
local err, errmsg = xpcall(function() Task.f( unpack(Task.vars, 1, table.maxn(Task.vars))) end, routines.errhandler )
|
||||
if not err then
|
||||
--env.info('routines.scheduleFunction, error in scheduled function: ' .. errmsg)
|
||||
end
|
||||
--Task.f(unpack(Task.vars, 1, table.maxn(Task.vars))) -- do the task, do not increment i
|
||||
else
|
||||
i = i + 1
|
||||
end
|
||||
else
|
||||
if Tasks[i].st and Tasks[i].st <= timer.getTime() then --if a stoptime was specified, and the stop time exceeded
|
||||
--env.info("do_scheduled_functions:remove repeated")
|
||||
table.remove(Tasks, i) -- stop time exceeded, do not execute, do not increment i
|
||||
elseif Tasks[i].t <= timer.getTime() then
|
||||
local Task = Tasks[i] -- local reference
|
||||
Task.t = timer.getTime() + Task.rep --schedule next run
|
||||
--env.info("do_scheduled_functions:call function " .. i )
|
||||
local err, errmsg = xpcall(function() Task.f( unpack(Task.vars, 1, table.maxn(Task.vars))) end, routines.errhandler )
|
||||
if not err then
|
||||
--env.info('routines.scheduleFunction, error in scheduled function: ' .. errmsg)
|
||||
end
|
||||
--Tasks[i].f(unpack(Tasks[i].vars, 1, table.maxn(Tasks[i].vars))) -- do the task
|
||||
i = i + 1
|
||||
else
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
do
|
||||
local idNum = 0
|
||||
|
||||
|
||||
@ -1,11 +1,27 @@
|
||||
--- Models time events calling event handing functions.
|
||||
--
|
||||
-- @{SCHEDULER} class
|
||||
-- ===================
|
||||
-- The @{SCHEDULER} class models time events calling given event handling functions.
|
||||
--
|
||||
-- SCHEDULER constructor
|
||||
-- =====================
|
||||
-- The SCHEDULER class is quite easy to use:
|
||||
--
|
||||
-- * @{#SCHEDULER.New}: Setup a new scheduler and start it with the specified parameters.
|
||||
--
|
||||
-- SCHEDULER timer methods
|
||||
-- =======================
|
||||
-- The SCHEDULER can be stopped and restarted with the following methods:
|
||||
--
|
||||
-- * @{#SCHEDULER.Start}: (Re-)Start the scheduler.
|
||||
-- * @{#SCHEDULER.Start}: Stop the scheduler.
|
||||
--
|
||||
-- @module Scheduler
|
||||
-- @author FlightControl
|
||||
|
||||
Include.File( "Routines" )
|
||||
Include.File( "Base" )
|
||||
Include.File( "Cargo" )
|
||||
Include.File( "Message" )
|
||||
|
||||
|
||||
--- The SCHEDULER class
|
||||
@ -16,19 +32,19 @@ SCHEDULER = {
|
||||
}
|
||||
|
||||
|
||||
--- SCHEDULER constructor.
|
||||
--- Constructor.
|
||||
-- @param #SCHEDULER self
|
||||
-- @param #table TimeEventObject
|
||||
-- @param #function TimeEventFunction
|
||||
-- @param #table TimeEventFunctionArguments
|
||||
-- @param #number StartSeconds
|
||||
-- @param #number RepeatSecondsInterval
|
||||
-- @param #number RandomizationFactor
|
||||
-- @param #number StopSeconds
|
||||
-- @return #SCHEDULER
|
||||
-- @param #table TimeEventObject Specified for which Moose object the timer is setup. If a value of nil is provided, a scheduler will be setup without an object reference.
|
||||
-- @param #function TimeEventFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in TimeEventFunctionArguments.
|
||||
-- @param #table TimeEventFunctionArguments Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }.
|
||||
-- @param #number StartSeconds Specifies the amount of seconds that will be waited before the scheduling is started, and the event function is called.
|
||||
-- @param #number RepeatSecondsInterval Specifies the interval in seconds when the scheduler will call the event function.
|
||||
-- @param #number RandomizationFactor Specifies a randomization factor between 0 and 1 to randomize the RepeatSecondsInterval.
|
||||
-- @param #number StopSeconds Specifies the amount of seconds when the scheduler will be stopped.
|
||||
-- @return #SCHEDULER self
|
||||
function SCHEDULER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds )
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
self:F( { TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds } )
|
||||
self:F2( { TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds } )
|
||||
|
||||
self.TimeEventObject = TimeEventObject
|
||||
self.TimeEventFunction = TimeEventFunction
|
||||
@ -60,8 +76,33 @@ function SCHEDULER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionArg
|
||||
return self
|
||||
end
|
||||
|
||||
function SCHEDULER:Scheduler()
|
||||
self:F( self.TimeEventFunctionArguments )
|
||||
--- (Re-)Starts the scheduler.
|
||||
-- @param #SCHEDULER self
|
||||
-- @return #SCHEDULER self
|
||||
function SCHEDULER:Start()
|
||||
self:F2( self.TimeEventObject )
|
||||
|
||||
self.Repeat = true
|
||||
timer.scheduleFunction( self._Scheduler, self, timer.getTime() + self.StartSeconds + .01 )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Stops the scheduler.
|
||||
-- @param #SCHEDULER self
|
||||
-- @return #SCHEDULER self
|
||||
function SCHEDULER:Stop()
|
||||
self:F2( self.TimeEventObject )
|
||||
|
||||
self.Repeat = false
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-- Private Functions
|
||||
|
||||
function SCHEDULER:_Scheduler()
|
||||
self:F2( self.TimeEventFunctionArguments )
|
||||
|
||||
local ErrorHandler = function( errmsg )
|
||||
|
||||
@ -83,7 +124,7 @@ function SCHEDULER:Scheduler()
|
||||
if Status and Status == true and Result and Result == true then
|
||||
if self.Repeat and ( not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) ) then
|
||||
timer.scheduleFunction(
|
||||
self.Scheduler,
|
||||
self._Scheduler,
|
||||
self,
|
||||
timer.getTime() + self.RepeatSecondsInterval + math.random( - ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ), ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ) ) + 0.01
|
||||
)
|
||||
@ -92,20 +133,7 @@ function SCHEDULER:Scheduler()
|
||||
|
||||
end
|
||||
|
||||
function SCHEDULER:Start()
|
||||
self:F( self.TimeEventObject )
|
||||
|
||||
self.Repeat = true
|
||||
timer.scheduleFunction( self.Scheduler, self, timer.getTime() + self.StartSeconds + .01 )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function SCHEDULER:Stop()
|
||||
self:F( self.TimeEventObject )
|
||||
|
||||
self.Repeat = false
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -62,7 +62,8 @@ function SCORING:New( GameName )
|
||||
_EVENTDISPATCHER:OnCrash( self._EventOnDeadOrCrash, self )
|
||||
_EVENTDISPATCHER:OnHit( self._EventOnHit, self )
|
||||
|
||||
self.SchedulerId = routines.scheduleFunction( SCORING._FollowPlayersScheduled, { self }, 0, 5 )
|
||||
--self.SchedulerId = routines.scheduleFunction( SCORING._FollowPlayersScheduled, { self }, 0, 5 )
|
||||
self.SchedulerId = SCHEDULER:New( self, self._FollowPlayersScheduled, {}, 0, 5 )
|
||||
|
||||
self:ScoreMenu()
|
||||
|
||||
@ -97,6 +98,8 @@ function SCORING:_FollowPlayersScheduled()
|
||||
self:_AddPlayerFromUnit( UnitData )
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -70,6 +70,29 @@
|
||||
|
||||
<p>Models time events calling event handing functions.</p>
|
||||
|
||||
|
||||
|
||||
<h1><a href="SCHEDULER.html">SCHEDULER</a> class</h1>
|
||||
<p>The <a href="SCHEDULER.html">SCHEDULER</a> class models time events calling given event handling functions.</p>
|
||||
|
||||
<h1>SCHEDULER constructor</h1>
|
||||
<p>The SCHEDULER class is quite easy to use:</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="##(SCHEDULER).New">SCHEDULER.New</a>: Setup a new scheduler and start it with the specified parameters.</li>
|
||||
</ul>
|
||||
|
||||
<h1>SCHEDULER timer methods</h1>
|
||||
<p>The SCHEDULER can be stopped and restarted with the following methods:</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="##(SCHEDULER).Start">SCHEDULER.Start</a>: (Re-)Start the scheduler.</li>
|
||||
<li><a href="##(SCHEDULER).Start">SCHEDULER.Start</a>: Stop the scheduler.</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
<h2>Global(s)</h2>
|
||||
<table class="function_list">
|
||||
<tr>
|
||||
@ -90,7 +113,13 @@
|
||||
<tr>
|
||||
<td class="name" nowrap="nowrap"><a href="##(SCHEDULER).New">SCHEDULER:New(TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds)</a></td>
|
||||
<td class="summary">
|
||||
<p>SCHEDULER constructor.</p>
|
||||
<p>Constructor.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap="nowrap"><a href="##(SCHEDULER).Repeat">SCHEDULER.Repeat</a></td>
|
||||
<td class="summary">
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -102,13 +131,13 @@
|
||||
<tr>
|
||||
<td class="name" nowrap="nowrap"><a href="##(SCHEDULER).Start">SCHEDULER:Start()</a></td>
|
||||
<td class="summary">
|
||||
|
||||
<p>(Re-)Starts the scheduler.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap="nowrap"><a href="##(SCHEDULER).Stop">SCHEDULER:Stop()</a></td>
|
||||
<td class="summary">
|
||||
|
||||
<p>Stops the scheduler.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@ -158,49 +187,70 @@
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<p>SCHEDULER constructor.</p>
|
||||
<p>Constructor.</p>
|
||||
|
||||
<h3>Parameters</h3>
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
<p><code><em>#table TimeEventObject </em></code>: </p>
|
||||
<p><code><em>#table TimeEventObject </em></code>:
|
||||
Specified for which Moose object the timer is setup. If a value of nil is provided, a scheduler will be setup without an object reference.</p>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<p><code><em>#function TimeEventFunction </em></code>: </p>
|
||||
<p><code><em>#function TimeEventFunction </em></code>:
|
||||
The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in TimeEventFunctionArguments.</p>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<p><code><em>#table TimeEventFunctionArguments </em></code>: </p>
|
||||
<p><code><em>#table TimeEventFunctionArguments </em></code>:
|
||||
Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }.</p>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<p><code><em>#number StartSeconds </em></code>: </p>
|
||||
<p><code><em>#number StartSeconds </em></code>:
|
||||
Specifies the amount of seconds that will be waited before the scheduling is started, and the event function is called.</p>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<p><code><em>#number RepeatSecondsInterval </em></code>: </p>
|
||||
<p><code><em>#number RepeatSecondsInterval </em></code>:
|
||||
Specifies the interval in seconds when the scheduler will call the event function.</p>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<p><code><em>#number RandomizationFactor </em></code>: </p>
|
||||
<p><code><em>#number RandomizationFactor </em></code>:
|
||||
Specifies a randomization factor between 0 and 1 to randomize the RepeatSecondsInterval.</p>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
|
||||
<p><code><em>#number StopSeconds </em></code>: </p>
|
||||
<p><code><em>#number StopSeconds </em></code>:
|
||||
Specifies the amount of seconds when the scheduler will be stopped.</p>
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
<h3>Return value</h3>
|
||||
|
||||
<p><em><a href="##(SCHEDULER)">#SCHEDULER</a>:</em></p>
|
||||
<p><em><a href="##(SCHEDULER)">#SCHEDULER</a>:</em>
|
||||
self</p>
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="function">
|
||||
<dt>
|
||||
|
||||
<em>#boolean</em>
|
||||
<a id="#(SCHEDULER).Repeat" >
|
||||
<strong>SCHEDULER.Repeat</strong>
|
||||
</a>
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
@ -227,7 +277,12 @@
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<p>(Re-)Starts the scheduler.</p>
|
||||
|
||||
<h3>Return value</h3>
|
||||
|
||||
<p><em><a href="##(SCHEDULER)">#SCHEDULER</a>:</em>
|
||||
self</p>
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
@ -240,7 +295,12 @@
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<p>Stops the scheduler.</p>
|
||||
|
||||
<h3>Return value</h3>
|
||||
|
||||
<p><em><a href="##(SCHEDULER)">#SCHEDULER</a>:</em>
|
||||
self</p>
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user