OPS and SCHEDULER

This commit is contained in:
Frank 2021-08-05 00:23:25 +02:00
parent 1a53f58540
commit f67cf99477
9 changed files with 59 additions and 31 deletions

View File

@ -873,7 +873,7 @@ do -- Scheduling
-- @param #number Start Specifies the amount of seconds that will be waited before the scheduling is started, and the event function is called. -- @param #number Start Specifies the amount of seconds that will be waited before the scheduling is started, and the event function is called.
-- @param #function SchedulerFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in SchedulerArguments. -- @param #function SchedulerFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in SchedulerArguments.
-- @param #table ... Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }. -- @param #table ... Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }.
-- @return #number The ScheduleID of the planned schedule. -- @return #string The Schedule ID of the planned schedule.
function BASE:ScheduleOnce( Start, SchedulerFunction, ... ) function BASE:ScheduleOnce( Start, SchedulerFunction, ... )
self:F2( { Start } ) self:F2( { Start } )
self:T3( { ... } ) self:T3( { ... } )
@ -887,6 +887,8 @@ do -- Scheduling
self.Scheduler = SCHEDULER:New( self ) self.Scheduler = SCHEDULER:New( self )
end end
-- FF this was wrong!
--[[
local ScheduleID = _SCHEDULEDISPATCHER:AddSchedule( local ScheduleID = _SCHEDULEDISPATCHER:AddSchedule(
self, self,
SchedulerFunction, SchedulerFunction,
@ -896,6 +898,10 @@ do -- Scheduling
nil, nil,
nil nil
) )
]]
-- NOTE: MasterObject (first parameter) needs to be nil or it will be the first argument passed to the SchedulerFunction!
local ScheduleID = self.Scheduler:Schedule(nil, SchedulerFunction, {...}, Start, nil, nil, nil)
self._.Schedules[#self._.Schedules+1] = ScheduleID self._.Schedules[#self._.Schedules+1] = ScheduleID
@ -910,7 +916,7 @@ do -- Scheduling
-- @param #number Stop Specifies the amount of seconds when the scheduler will be stopped. -- @param #number Stop Specifies the amount of seconds when the scheduler will be stopped.
-- @param #function SchedulerFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in SchedulerArguments. -- @param #function SchedulerFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in SchedulerArguments.
-- @param #table ... Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }. -- @param #table ... Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }.
-- @return #number The ScheduleID of the planned schedule. -- @return #string The Schedule ID of the planned schedule.
function BASE:ScheduleRepeat( Start, Repeat, RandomizeFactor, Stop, SchedulerFunction, ... ) function BASE:ScheduleRepeat( Start, Repeat, RandomizeFactor, Stop, SchedulerFunction, ... )
self:F2( { Start } ) self:F2( { Start } )
self:T3( { ... } ) self:T3( { ... } )
@ -924,6 +930,7 @@ do -- Scheduling
self.Scheduler = SCHEDULER:New( self ) self.Scheduler = SCHEDULER:New( self )
end end
-- NOTE: MasterObject (first parameter) should(!) be nil as it will be the first argument passed to the SchedulerFunction!
local ScheduleID = self.Scheduler:Schedule( local ScheduleID = self.Scheduler:Schedule(
self, self,
SchedulerFunction, SchedulerFunction,
@ -942,13 +949,13 @@ do -- Scheduling
--- Stops the Schedule. --- Stops the Schedule.
-- @param #BASE self -- @param #BASE self
-- @param #function SchedulerFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in SchedulerArguments. -- @param #string SchedulerID (Optional) Scheduler ID to be stopped. If nil, all pending schedules are stopped.
function BASE:ScheduleStop( SchedulerFunction ) function BASE:ScheduleStop( SchedulerID )
self:F3( { "ScheduleStop:" } ) self:F3( { "ScheduleStop:" } )
if self.Scheduler then if self.Scheduler then
_SCHEDULEDISPATCHER:Stop( self.Scheduler, self._.Schedules[SchedulerFunction] ) --_SCHEDULEDISPATCHER:Stop( self.Scheduler, self._.Schedules[SchedulerFunction] )
_SCHEDULEDISPATCHER:Stop(self.Scheduler, SchedulerID)
end end
end end

View File

@ -1431,7 +1431,7 @@ do -- FSM_SET
-- @param #FSM_SET self -- @param #FSM_SET self
-- @return Core.Set#SET_BASE -- @return Core.Set#SET_BASE
function FSM_SET:Get() function FSM_SET:Get()
return self.Controllable return self.Set
end end
function FSM_SET:_call_handler( step, trigger, params, EventName ) function FSM_SET:_call_handler( step, trigger, params, EventName )

View File

@ -317,7 +317,7 @@ end
--- Stop dispatcher. --- Stop dispatcher.
-- @param #SCHEDULEDISPATCHER self -- @param #SCHEDULEDISPATCHER self
-- @param Core.Scheduler#SCHEDULER Scheduler Scheduler object. -- @param Core.Scheduler#SCHEDULER Scheduler Scheduler object.
-- @param #table CallID Call ID. -- @param #string CallID (Optional) Scheduler Call ID. If nil, all pending schedules are stopped recursively.
function SCHEDULEDISPATCHER:Stop( Scheduler, CallID ) function SCHEDULEDISPATCHER:Stop( Scheduler, CallID )
self:F2( { Stop = CallID, Scheduler = Scheduler } ) self:F2( { Stop = CallID, Scheduler = Scheduler } )

View File

@ -238,7 +238,7 @@ end
-- @param #number Stop Time interval in seconds after which the scheduler will be stoppe. -- @param #number Stop Time interval in seconds after which the scheduler will be stoppe.
-- @param #number TraceLevel Trace level [0,3]. Default 3. -- @param #number TraceLevel Trace level [0,3]. Default 3.
-- @param Core.Fsm#FSM Fsm Finite state model. -- @param Core.Fsm#FSM Fsm Finite state model.
-- @return #table The ScheduleID of the planned schedule. -- @return #string The Schedule ID of the planned schedule.
function SCHEDULER:Schedule( MasterObject, SchedulerFunction, SchedulerArguments, Start, Repeat, RandomizeFactor, Stop, TraceLevel, Fsm ) function SCHEDULER:Schedule( MasterObject, SchedulerFunction, SchedulerArguments, Start, Repeat, RandomizeFactor, Stop, TraceLevel, Fsm )
self:F2( { Start, Repeat, RandomizeFactor, Stop } ) self:F2( { Start, Repeat, RandomizeFactor, Stop } )
self:T3( { SchedulerArguments } ) self:T3( { SchedulerArguments } )

View File

@ -3989,10 +3989,22 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
-- Destroy group if it is alive. -- Destroy group if it is alive.
if group:IsAlive()==true then if group:IsAlive()==true then
self:_DebugMessage(string.format("Removing group %s", group:GetName()), 5) self:_DebugMessage(string.format("Removing group %s", group:GetName()), 5)
local opsgroup=_DATABASE:GetOpsGroup(group:GetName())
if opsgroup then
opsgroup:Despawn(0)
opsgroup:__Stop(-0.01)
else
-- Setting parameter to false, i.e. creating NO dead or remove unit event, seems to not confuse the dispatcher logic. -- Setting parameter to false, i.e. creating NO dead or remove unit event, seems to not confuse the dispatcher logic.
-- TODO: It would be nice, however, to have the remove event. -- TODO: It would be nice, however, to have the remove event.
group:Destroy() --(false) group:Destroy() --(false)
end end
else
local opsgroup=_DATABASE:GetOpsGroup(group:GetName())
if opsgroup then
opsgroup:Stop()
end
end
else else
self:E(self.lid.."ERROR: Unknown group added as asset!") self:E(self.lid.."ERROR: Unknown group added as asset!")
@ -8766,7 +8778,7 @@ end
-- @param #number duration Message display duration in seconds. Default 20 sec. If duration is zero, no message is displayed. -- @param #number duration Message display duration in seconds. Default 20 sec. If duration is zero, no message is displayed.
function WAREHOUSE:_DebugMessage(text, duration) function WAREHOUSE:_DebugMessage(text, duration)
duration=duration or 20 duration=duration or 20
if duration>0 then if self.Debug and duration>0 then
MESSAGE:New(text, duration):ToAllIf(self.Debug) MESSAGE:New(text, duration):ToAllIf(self.Debug)
end end
self:T(self.lid..text) self:T(self.lid..text)

View File

@ -1178,7 +1178,7 @@ function ARMYGROUP:_InitGroup(Template)
self:SetDefaultRadio(self.radio.Freq, self.radio.Modu, self.radio.On) self:SetDefaultRadio(self.radio.Freq, self.radio.Modu, self.radio.On)
-- Set default formation from first waypoint. -- Set default formation from first waypoint.
self.optionDefault.Formation=self:GetWaypoint(1).action self.optionDefault.Formation=template.route.points[1].action --self:GetWaypoint(1).action
-- Default TACAN off. -- Default TACAN off.
self:SetDefaultTACAN(nil, nil, nil, nil, true) self:SetDefaultTACAN(nil, nil, nil, nil, true)

View File

@ -1970,6 +1970,7 @@ function FLIGHTGROUP:onafterArrived(From, Event, To)
else else
-- Depawn after 5 min. Important to trigger dead events before DCS despawns on its own without any notification. -- Depawn after 5 min. Important to trigger dead events before DCS despawns on its own without any notification.
self:T(self.lid..string.format("Despawning group in 5 minutes after arrival!"))
self:Despawn(5*60) self:Despawn(5*60)
end end
end end

View File

@ -546,7 +546,7 @@ function OPSGROUP:New(group)
-- From State --> Event --> To State -- From State --> Event --> To State
self:AddTransition("InUtero", "Spawned", "Spawned") -- The whole group was spawned. self:AddTransition("InUtero", "Spawned", "Spawned") -- The whole group was spawned.
self:AddTransition("*", "Respawn", "InUtero") -- Respawn group. self:AddTransition("*", "Respawn", "InUtero") -- Respawn group.
self:AddTransition("*", "Dead", "Dead") -- The whole group is dead. self:AddTransition("*", "Dead", "InUtero") -- The whole group is dead and goes back to mummy.
self:AddTransition("*", "InUtero", "InUtero") -- Deactivated group goes back to mummy. self:AddTransition("*", "InUtero", "InUtero") -- Deactivated group goes back to mummy.
self:AddTransition("*", "Stop", "Stopped") -- Stop FSM. self:AddTransition("*", "Stop", "Stopped") -- Stop FSM.
@ -1326,9 +1326,11 @@ end
function OPSGROUP:Despawn(Delay, NoEventRemoveUnit) function OPSGROUP:Despawn(Delay, NoEventRemoveUnit)
if Delay and Delay>0 then if Delay and Delay>0 then
self:ScheduleOnce(Delay, OPSGROUP.Despawn, self, 0, NoEventRemoveUnit) self.scheduleIDDespawn=self:ScheduleOnce(Delay, OPSGROUP.Despawn, self, 0, NoEventRemoveUnit)
else else
self:I(self.lid..string.format("Despawning Group!"))
local DCSGroup=self:GetDCSGroup() local DCSGroup=self:GetDCSGroup()
if DCSGroup then if DCSGroup then
@ -1750,16 +1752,11 @@ function OPSGROUP:IsSpawned()
return is return is
end end
--- Check if group is dead. --- Check if group is dead. Could be destroyed or despawned. FSM state of dead group is `InUtero` though.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @return #boolean If true, all units/elements of the group are dead. -- @return #boolean If true, all units/elements of the group are dead.
function OPSGROUP:IsDead() function OPSGROUP:IsDead()
if self.isDead then return self.isDead
return true
else
local is=self:Is("Dead")
return is
end
end end
--- Check if group was destroyed. --- Check if group was destroyed.
@ -4960,6 +4957,16 @@ function OPSGROUP:_Respawn(Delay, Template, Reset)
return self return self
end end
--- On after "InUtero" event.
-- @param #OPSGROUP self
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function OPSGROUP:onafterInUtero(From, Event, To)
self:T(self.lid..string.format("Group inutero at t=%.3f", timer.getTime()))
--TODO: set element status to inutero
end
--- On after "Destroyed" event. --- On after "Destroyed" event.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #string From From state. -- @param #string From From state.
@ -5032,7 +5039,6 @@ function OPSGROUP:onafterDead(From, Event, To)
-- No current cargo transport. -- No current cargo transport.
self.cargoTransport=nil self.cargoTransport=nil
-- Stop in a sec. -- Stop in a sec.
--self:__Stop(-5) --self:__Stop(-5)
end end
@ -5083,6 +5089,9 @@ function OPSGROUP:onafterStop(From, Event, To)
-- Stop FSM scheduler. -- Stop FSM scheduler.
self.CallScheduler:Clear() self.CallScheduler:Clear()
if self.Scheduler then
self.Scheduler:Clear()
end
if self:IsAlive() and not (self:IsDead() or self:IsStopped()) then if self:IsAlive() and not (self:IsDead() or self:IsStopped()) then
local life, life0=self:GetLifePoints() local life, life0=self:GetLifePoints()

View File

@ -338,8 +338,7 @@ end
-- If the first @{Wrapper.Unit} of the group is inactive, it will return false. -- If the first @{Wrapper.Unit} of the group is inactive, it will return false.
-- --
-- @param #GROUP self -- @param #GROUP self
-- @return #boolean true if the group is alive and active. -- @return #boolean `true` if the group is alive *and* active, `false` if the group is alive but inactive or `#nil` if the group does not exist anymore.
-- @return #boolean false if the group is alive but inactive or #nil if the group does not exist anymore.
function GROUP:IsAlive() function GROUP:IsAlive()
self:F2( self.GroupName ) self:F2( self.GroupName )
@ -361,7 +360,7 @@ end
--- Returns if the group is activated. --- Returns if the group is activated.
-- @param #GROUP self -- @param #GROUP self
-- @return #boolean true if group is activated or #nil The group is not existing or alive. -- @return #boolean `true` if group is activated or `#nil` The group is not existing or alive.
function GROUP:IsActive() function GROUP:IsActive()
self:F2( self.GroupName ) self:F2( self.GroupName )