mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Finalized the SCHEDULER and SCHEDULERDISPATCHER
- Done, time to remerge the work.
This commit is contained in:
parent
84e2361829
commit
365034ad69
@ -726,7 +726,7 @@ function EVENT:onEvent( Event )
|
|||||||
Event.IniUnit = UNIT:FindByName( Event.IniDCSUnitName )
|
Event.IniUnit = UNIT:FindByName( Event.IniDCSUnitName )
|
||||||
if not Event.IniUnit then
|
if not Event.IniUnit then
|
||||||
-- Unit can be a CLIENT. Most likely this will be the case ...
|
-- Unit can be a CLIENT. Most likely this will be the case ...
|
||||||
Event.IniUnit = CLIENT:FindByName( Event.IniDCSUnitName )
|
Event.IniUnit = CLIENT:FindByName( Event.IniDCSUnitName, '', true )
|
||||||
end
|
end
|
||||||
Event.IniDCSGroupName = ""
|
Event.IniDCSGroupName = ""
|
||||||
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then
|
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then
|
||||||
|
|||||||
@ -66,7 +66,7 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
|
|||||||
-- If the object used as the key is nil, then the garbage collector will remove the item from the Functions array.
|
-- If the object used as the key is nil, then the garbage collector will remove the item from the Functions array.
|
||||||
self.ObjectSchedulers = self.ObjectSchedulers or setmetatable( {}, { __mode = "v" } )
|
self.ObjectSchedulers = self.ObjectSchedulers or setmetatable( {}, { __mode = "v" } )
|
||||||
|
|
||||||
if Scheduler.TimeEventObject then
|
if Scheduler.SchedulerObject then
|
||||||
self.ObjectSchedulers[self.CallID] = Scheduler
|
self.ObjectSchedulers[self.CallID] = Scheduler
|
||||||
self:T3( { self.CallID, self.ObjectSchedulers[self.CallID] } )
|
self:T3( { self.CallID, self.ObjectSchedulers[self.CallID] } )
|
||||||
else
|
else
|
||||||
@ -111,8 +111,8 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr
|
|||||||
|
|
||||||
self:T( { Schedule = Schedule } )
|
self:T( { Schedule = Schedule } )
|
||||||
|
|
||||||
local ScheduleObject = Scheduler.TimeEventObject
|
local ScheduleObject = Scheduler.SchedulerObject
|
||||||
--local ScheduleObjectName = Scheduler.TimeEventObject:GetNameAndClassID()
|
--local ScheduleObjectName = Scheduler.SchedulerObject:GetNameAndClassID()
|
||||||
local ScheduleFunction = Schedule.Function
|
local ScheduleFunction = Schedule.Function
|
||||||
local ScheduleArguments = Schedule.Arguments
|
local ScheduleArguments = Schedule.Arguments
|
||||||
local Start = Schedule.Start
|
local Start = Schedule.Start
|
||||||
|
|||||||
@ -54,23 +54,23 @@ SCHEDULER = {
|
|||||||
|
|
||||||
--- SCHEDULER constructor.
|
--- SCHEDULER constructor.
|
||||||
-- @param #SCHEDULER self
|
-- @param #SCHEDULER self
|
||||||
-- @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 #table SchedulerObject 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 #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 TimeEventFunctionArguments Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }.
|
-- @param #table SchedulerArguments 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 Start 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 Repeat 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 RandomizeFactor Specifies a randomization factor between 0 and 1 to randomize the Repeat.
|
||||||
-- @param #number StopSeconds 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.
|
||||||
-- @return #SCHEDULER self
|
-- @return #SCHEDULER self
|
||||||
-- @return #number The ScheduleID of the planned schedule.
|
-- @return #number The ScheduleID of the planned schedule.
|
||||||
function SCHEDULER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds )
|
function SCHEDULER:New( SchedulerObject, SchedulerFunction, SchedulerArguments, Start, Repeat, RandomizeFactor, Stop )
|
||||||
local self = BASE:Inherit( self, BASE:New() )
|
local self = BASE:Inherit( self, BASE:New() )
|
||||||
self:F2( { StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds } )
|
self:F2( { Start, Repeat, RandomizeFactor, Stop } )
|
||||||
|
|
||||||
local ScheduleID = nil
|
local ScheduleID = nil
|
||||||
|
|
||||||
if TimeEventFunction then
|
if SchedulerFunction then
|
||||||
ScheduleID = self:Schedule( TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds )
|
ScheduleID = self:Schedule( SchedulerObject, SchedulerFunction, SchedulerArguments, Start, Repeat, RandomizeFactor, Stop )
|
||||||
end
|
end
|
||||||
|
|
||||||
return self, ScheduleID
|
return self, ScheduleID
|
||||||
@ -84,29 +84,29 @@ end
|
|||||||
|
|
||||||
--- Schedule a new time event. Note that the schedule will only take place if the scheduler is *started*. Even for a single schedule event, the scheduler needs to be started also.
|
--- Schedule a new time event. Note that the schedule will only take place if the scheduler is *started*. Even for a single schedule event, the scheduler needs to be started also.
|
||||||
-- @param #SCHEDULER self
|
-- @param #SCHEDULER self
|
||||||
-- @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 #table SchedulerObject 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 #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 TimeEventFunctionArguments Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }.
|
-- @param #table SchedulerArguments 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 Start 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 Repeat 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 RandomizeFactor Specifies a randomization factor between 0 and 1 to randomize the Repeat.
|
||||||
-- @param #number StopSeconds 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.
|
||||||
-- @return #number The ScheduleID of the planned schedule.
|
-- @return #number The ScheduleID of the planned schedule.
|
||||||
function SCHEDULER:Schedule( TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds )
|
function SCHEDULER:Schedule( SchedulerObject, SchedulerFunction, SchedulerArguments, Start, Repeat, RandomizeFactor, Stop )
|
||||||
self:F2( { StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds } )
|
self:F2( { Start, Repeat, RandomizeFactor, Stop } )
|
||||||
self:T3( { TimeEventFunctionArguments } )
|
self:T3( { SchedulerArguments } )
|
||||||
|
|
||||||
|
|
||||||
self.TimeEventObject = TimeEventObject
|
self.SchedulerObject = SchedulerObject
|
||||||
|
|
||||||
local ScheduleID = _SCHEDULEDISPATCHER:AddSchedule(
|
local ScheduleID = _SCHEDULEDISPATCHER:AddSchedule(
|
||||||
self,
|
self,
|
||||||
TimeEventFunction,
|
SchedulerFunction,
|
||||||
TimeEventFunctionArguments,
|
SchedulerArguments,
|
||||||
StartSeconds,
|
Start,
|
||||||
RepeatSecondsInterval,
|
Repeat,
|
||||||
RandomizationFactor,
|
RandomizeFactor,
|
||||||
StopSeconds
|
Stop
|
||||||
)
|
)
|
||||||
|
|
||||||
self.Schedules[#self.Schedules+1] = ScheduleID
|
self.Schedules[#self.Schedules+1] = ScheduleID
|
||||||
|
|||||||
@ -92,6 +92,7 @@ end
|
|||||||
-- @param #CLIENT self
|
-- @param #CLIENT self
|
||||||
-- @param #string ClientName Name of the DCS **Unit** as defined within the Mission Editor.
|
-- @param #string ClientName Name of the DCS **Unit** as defined within the Mission Editor.
|
||||||
-- @param #string ClientBriefing Text that describes the briefing of the mission when a Player logs into the Client.
|
-- @param #string ClientBriefing Text that describes the briefing of the mission when a Player logs into the Client.
|
||||||
|
-- @param #boolean Error A flag that indicates whether an error should be raised if the CLIENT cannot be found. By default an error will be raised.
|
||||||
-- @return #CLIENT
|
-- @return #CLIENT
|
||||||
-- @usage
|
-- @usage
|
||||||
-- -- Create new Clients.
|
-- -- Create new Clients.
|
||||||
@ -102,7 +103,7 @@ end
|
|||||||
-- Mission:AddClient( CLIENT:FindByName( 'RU MI-8MTV2*RAMP-Deploy Troops 3' ):Transport() )
|
-- Mission:AddClient( CLIENT:FindByName( 'RU MI-8MTV2*RAMP-Deploy Troops 3' ):Transport() )
|
||||||
-- Mission:AddClient( CLIENT:FindByName( 'RU MI-8MTV2*HOT-Deploy Troops 2' ):Transport() )
|
-- Mission:AddClient( CLIENT:FindByName( 'RU MI-8MTV2*HOT-Deploy Troops 2' ):Transport() )
|
||||||
-- Mission:AddClient( CLIENT:FindByName( 'RU MI-8MTV2*RAMP-Deploy Troops 4' ):Transport() )
|
-- Mission:AddClient( CLIENT:FindByName( 'RU MI-8MTV2*RAMP-Deploy Troops 4' ):Transport() )
|
||||||
function CLIENT:FindByName( ClientName, ClientBriefing )
|
function CLIENT:FindByName( ClientName, ClientBriefing, Error )
|
||||||
local ClientFound = _DATABASE:FindClient( ClientName )
|
local ClientFound = _DATABASE:FindClient( ClientName )
|
||||||
|
|
||||||
if ClientFound then
|
if ClientFound then
|
||||||
@ -113,8 +114,10 @@ function CLIENT:FindByName( ClientName, ClientBriefing )
|
|||||||
return ClientFound
|
return ClientFound
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not Error then
|
||||||
error( "CLIENT not found for: " .. ClientName )
|
error( "CLIENT not found for: " .. ClientName )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function CLIENT:Register( ClientName )
|
function CLIENT:Register( ClientName )
|
||||||
local self = BASE:Inherit( self, UNIT:Register( ClientName ) )
|
local self = BASE:Inherit( self, UNIT:Register( ClientName ) )
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,41 @@
|
|||||||
|
--- Simple repeat scheduling of a function.
|
||||||
|
--
|
||||||
|
-- ===
|
||||||
|
--
|
||||||
|
-- Author: FlightControl
|
||||||
|
-- Date Created: 14 Dec 2016
|
||||||
|
--
|
||||||
|
-- # Situation
|
||||||
|
-- Uses the Tracing functions from BASE within the DCS.log file. Check the DCS.log file for the results.
|
||||||
|
-- Create a new SCHEDULER object.
|
||||||
|
-- Check the DCS.log.
|
||||||
|
--
|
||||||
|
-- Start a schedule called TestScheduler. TestScheduler will repeat the words "Hello World Repeat" every second in the log.
|
||||||
|
-- After 10 seconds, TestScheduler will stop the scheduler.
|
||||||
|
-- After 20 seconds, TestScheduler will restart the scheduler.
|
||||||
|
--
|
||||||
|
-- # Test cases:
|
||||||
|
--
|
||||||
|
-- 1. Check that the "Hello World Repeat" lines are consistent with the scheduling timing. They should stop showing after 10 seconds, and restart after 20 seconds.
|
||||||
|
--
|
||||||
|
--
|
||||||
|
-- # Status: TESTED - 14 Dec 2016
|
||||||
|
|
||||||
|
local TestScheduler = SCHEDULER:New( nil,
|
||||||
|
function()
|
||||||
|
BASE:E( timer.getTime() .. " - Hello World Repeat")
|
||||||
|
end, {}, 1, 1
|
||||||
|
)
|
||||||
|
|
||||||
|
SCHEDULER:New( nil,
|
||||||
|
function()
|
||||||
|
TestScheduler:Stop()
|
||||||
|
end, {}, 10
|
||||||
|
)
|
||||||
|
|
||||||
|
SCHEDULER:New( nil,
|
||||||
|
function()
|
||||||
|
TestScheduler:Start()
|
||||||
|
end, {}, 20
|
||||||
|
)
|
||||||
|
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user