Updated tracing with loading static and improved SCHEDULER

- Tracing is by default switched off when using Moose in static mode.
- SCHEDULER is now correctly rescheduling when repeating the loop.
- Modified the loaders, adding the default trace on in case of dynamic
and off in case of static loading.
This commit is contained in:
FlightControl 2016-06-15 05:54:21 +02:00
parent 37510ab647
commit 5bd0595b35
28 changed files with 470 additions and 331 deletions

View File

@ -37,12 +37,6 @@
-- @module Client -- @module Client
-- @author FlightControl -- @author FlightControl
--- The CLIENT class --- The CLIENT class
-- @type CLIENT -- @type CLIENT
-- @extends Unit#UNIT -- @extends Unit#UNIT
@ -131,7 +125,7 @@ function CLIENT:Register( ClientName )
self.ClientAlive2 = false 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 ) self.AliveCheckScheduler = SCHEDULER:New( self, self._AliveCheckScheduler, { "Client Alive " .. ClientName }, 1, 5 )
self:E( self ) self:E( self )
return self return self
@ -241,10 +235,11 @@ function CLIENT:Alive( CallBackFunction, ... )
end end
--- @param #CLIENT self --- @param #CLIENT self
function CLIENT:_AliveCheckScheduler() function CLIENT:_AliveCheckScheduler( SchedulerName )
self:F( { self.ClientName, self.ClientAlive2, self.ClientBriefingShown, self.ClientCallBack } ) self:E( SchedulerName )
self:F( { SchedulerName, self.ClientName, self.ClientAlive2, self.ClientBriefingShown, self.ClientCallBack } )
if self:IsAlive() then -- Polymorphic call of UNIT if self:IsAlive() then
if self.ClientAlive2 == false then if self.ClientAlive2 == false then
self:ShowBriefing() self:ShowBriefing()
if self.ClientCallBack then if self.ClientCallBack then

View File

@ -1,34 +1,34 @@
--- Models time events calling event handing functions. --- Models time events calling event handing functions.
-- --
-- @{SCHEDULER} class -- @{SCHEDULER} class
-- =================== -- ===================
-- The @{SCHEDULER} class models time events calling given event handling functions. -- The @{SCHEDULER} class models time events calling given event handling functions.
-- --
-- SCHEDULER constructor -- SCHEDULER constructor
-- ===================== -- =====================
-- The SCHEDULER class is quite easy to use: -- The SCHEDULER class is quite easy to use:
-- --
-- * @{#SCHEDULER.New}: Setup a new scheduler and start it with the specified parameters. -- * @{#SCHEDULER.New}: Setup a new scheduler and start it with the specified parameters.
-- --
-- SCHEDULER timer methods -- SCHEDULER timer methods
-- ======================= -- =======================
-- The SCHEDULER can be stopped and restarted with the following methods: -- The SCHEDULER can be stopped and restarted with the following methods:
-- --
-- * @{#SCHEDULER.Start}: (Re-)Start the scheduler. -- * @{#SCHEDULER.Start}: (Re-)Start the scheduler.
-- * @{#SCHEDULER.Start}: Stop the scheduler. -- * @{#SCHEDULER.Start}: Stop the scheduler.
-- --
-- @module Scheduler -- @module Scheduler
-- @author FlightControl -- @author FlightControl
--- The SCHEDULER class --- The SCHEDULER class
-- @type SCHEDULER -- @type SCHEDULER
-- @field #number ScheduleID the ID of the scheduler.
-- @extends Base#BASE -- @extends Base#BASE
SCHEDULER = { SCHEDULER = {
ClassName = "SCHEDULER", ClassName = "SCHEDULER",
} }
--- SCHEDULER constructor.
--- 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 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 #function TimeEventFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in TimeEventFunctionArguments.
@ -63,10 +63,10 @@ function SCHEDULER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionArg
if StopSeconds then if StopSeconds then
self.StopSeconds = StopSeconds self.StopSeconds = StopSeconds
end end
self.StartTime = timer.getTime() self.StartTime = timer.getTime()
self:Start() self:Start()
return self return self
@ -77,12 +77,12 @@ end
-- @return #SCHEDULER self -- @return #SCHEDULER self
function SCHEDULER:Start() function SCHEDULER:Start()
self:F2( self.TimeEventObject ) self:F2( self.TimeEventObject )
if self.RepeatSecondsInterval ~= 0 then if self.RepeatSecondsInterval ~= 0 then
self.Repeat = true self.Repeat = true
end end
timer.scheduleFunction( self._Scheduler, self, timer.getTime() + self.StartSeconds + .01 ) self.ScheduleID = timer.scheduleFunction( self._Scheduler, self, timer.getTime() + self.StartSeconds + .01 )
return self return self
end end
@ -91,17 +91,20 @@ end
-- @return #SCHEDULER self -- @return #SCHEDULER self
function SCHEDULER:Stop() function SCHEDULER:Stop()
self:F2( self.TimeEventObject ) self:F2( self.TimeEventObject )
self.Repeat = false self.Repeat = false
timer.removeFunction( self.ScheduleID )
self.ScheduleID = nil
return self return self
end end
-- Private Functions -- Private Functions
--- @param #SCHEDULER self
function SCHEDULER:_Scheduler() function SCHEDULER:_Scheduler()
self:F2( self.TimeEventFunctionArguments ) self:F2( self.TimeEventFunctionArguments )
local ErrorHandler = function( errmsg ) local ErrorHandler = function( errmsg )
env.info( "Error in SCHEDULER function:" .. errmsg ) env.info( "Error in SCHEDULER function:" .. errmsg )
@ -110,27 +113,37 @@ function SCHEDULER:_Scheduler()
return errmsg return errmsg
end end
local Status, Result local Status, Result
if self.TimeEventObject then if self.TimeEventObject then
Status, Result = xpcall( function() return self.TimeEventFunction( self.TimeEventObject, unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler ) Status, Result = xpcall( function() return self.TimeEventFunction( self.TimeEventObject, unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler )
else else
Status, Result = xpcall( function() return self.TimeEventFunction( unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler ) Status, Result = xpcall( function() return self.TimeEventFunction( unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler )
end end
self:T( { Status, Result, self.StartTime, self.RepeatSecondsInterval, self.RandomizationFactor, self.StopSeconds } ) self:T( { self.TimeEventFunctionArguments, Status, Result, self.StartTime, self.RepeatSecondsInterval, self.RandomizationFactor, self.StopSeconds } )
if Status and ( ( Result == nil ) or ( Result and Result ~= false ) ) then if Status and ( ( Result == nil ) or ( Result and Result ~= false ) ) then
if self.Repeat and ( not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) ) then if self.Repeat and ( not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) ) then
local ScheduleTime = timer.getTime() + self.RepeatSecondsInterval + math.random( - ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ), ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ) ) + 0.01 local ScheduleTime =
self:T( { timer.getTime(), ScheduleTime } ) timer.getTime() +
timer.scheduleFunction( self.RepeatSecondsInterval +
self._Scheduler, math.random(
self, - ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ),
ScheduleTime ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 )
) ) +
0.01
self:T( { self.TimeEventFunctionArguments, "Repeat:", timer.getTime(), ScheduleTime } )
return ScheduleTime -- returns the next time the function needs to be called.
else
timer.removeFunction( self.ScheduleID )
self.ScheduleID = nil
end end
else
timer.removeFunction( self.ScheduleID )
self.ScheduleID = nil
end end
return nil
end end
@ -140,3 +153,11 @@ end

View File

@ -155,13 +155,13 @@ function UNIT:FindByName( UnitName )
end end
function UNIT:GetDCSUnit() function UNIT:GetDCSUnit()
local DCSUnit = Unit.getByName( self.UnitName ) local DCSUnit = Unit.getByName( self.UnitName )
if DCSUnit then if DCSUnit then
return DCSUnit return DCSUnit
end end
self:E( "Unit " .. self.UnitName .. " not found!" )
return nil return nil
end end

View File

@ -0,0 +1,2 @@
BASE:TraceOnOff( true )

View File

@ -1,13 +1,7 @@
local base = _G local base = _G
Include = {} Include = {}
Include.Files = {}
Include.Path = function()
local str = debug.getinfo(2, "S").source
return str:match("(.*/)"):sub(1,-2):gsub("\\","/")
end
Include.File = function( IncludeFile ) Include.File = function( IncludeFile )
end end
Include.Files = {}

View File

@ -0,0 +1,2 @@
BASE:TraceOnOff( false )

View File

@ -1,18 +1,12 @@
env.info( '*** MOOSE STATIC INCLUDE START *** ' ) env.info( '*** MOOSE STATIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20160614_1531' ) env.info( 'Moose Generation Timestamp: 20160615_0552' )
local base = _G local base = _G
Include = {} Include = {}
Include.Files = {}
Include.Path = function()
local str = debug.getinfo(2, "S").source
return str:match("(.*/)"):sub(1,-2):gsub("\\","/")
end
Include.File = function( IncludeFile ) Include.File = function( IncludeFile )
end end
Include.Files = {}
--- Various routines --- Various routines
-- @module routines -- @module routines
-- @author Flightcontrol -- @author Flightcontrol
@ -2533,35 +2527,40 @@ end
env.info(( 'Init: Scripts Loaded v1.1' )) env.info(( 'Init: Scripts Loaded v1.1' ))
--- BASE classes. --- This module contains the BASE class.
-- --
-- @{#BASE} class -- 1) @{#BASE} class
-- ============== -- =================
-- The @{#BASE} class is the super class for most of the classes defined within MOOSE. -- The @{#BASE} class is the super class for all the classes defined within MOOSE.
-- --
-- It handles: -- It handles:
-- --
-- * The construction and inheritance of child classes. -- * The construction and inheritance of child classes.
-- * The tracing of objects during mission execution within the DCS.log file (under saved games folder). -- * The tracing of objects during mission execution within the **DCS.log** file, under the **"Saved Games\DCS\Logs"** folder.
-- --
-- Note: Normally you would not use the BASE class unless you are extending the MOOSE framework with new classes. -- Note: Normally you would not use the BASE class unless you are extending the MOOSE framework with new classes.
-- --
-- BASE Trace functionality -- 1.1) BASE constructor
-- ======================== -- ---------------------
-- Any class derived from BASE, must use the @{Base#BASE.New) constructor within the @{Base#BASE.Inherit) method.
-- See an example at the @{Base#BASE.New} method how this is done.
--
-- 1.2) BASE Trace functionality
-- -----------------------------
-- The BASE class contains trace methods to trace progress within a mission execution of a certain object. -- The BASE class contains trace methods to trace progress within a mission execution of a certain object.
-- Note that these trace methods are inherited by each MOOSE class interiting BASE. -- Note that these trace methods are inherited by each MOOSE class interiting BASE.
-- As such, each object created from derived class from BASE can use the tracing functions to trace its execution. -- As such, each object created from derived class from BASE can use the tracing functions to trace its execution.
-- --
-- Trace a function call -- 1.2.1) Tracing functions
-- --------------------- -- ------------------------
-- There are basically 3 types of tracing methods available within BASE: -- There are basically 3 types of tracing methods available within BASE:
-- --
-- * @{#BASE.F}: Trace the beginning of a function and its given parameters. -- * @{#BASE.F}: Trace the beginning of a function and its given parameters. An F is indicated at column 44 in the DCS.log file.
-- * @{#BASE.T}: Trace further logic within a function giving optional variables or parameters. -- * @{#BASE.T}: Trace further logic within a function giving optional variables or parameters. A T is indicated at column 44 in the DCS.log file.
-- * @{#BASE.E}: Trace an execption within a function giving optional variables or parameters. An exception will always be traced. -- * @{#BASE.E}: Trace an exception within a function giving optional variables or parameters. An E is indicated at column 44 in the DCS.log file. An exception will always be traced.
-- --
-- Tracing levels -- 1.2.2) Tracing levels
-- -------------- -- ---------------------
-- There are 3 tracing levels within MOOSE. -- There are 3 tracing levels within MOOSE.
-- These tracing levels were defined to avoid bulks of tracing to be generated by lots of objects. -- These tracing levels were defined to avoid bulks of tracing to be generated by lots of objects.
-- --
@ -2572,8 +2571,8 @@ env.info(( 'Init: Scripts Loaded v1.1' ))
-- * @{#BASE.T2}: Trace further logic within a function giving optional variables or parameters with tracing level 2. -- * @{#BASE.T2}: Trace further logic within a function giving optional variables or parameters with tracing level 2.
-- * @{#BASE.T3}: Trace further logic within a function giving optional variables or parameters with tracing level 3. -- * @{#BASE.T3}: Trace further logic within a function giving optional variables or parameters with tracing level 3.
-- --
-- BASE Inheritance support -- 1.3) BASE Inheritance support
-- ======================== -- ===========================
-- The following methods are available to support inheritance: -- The following methods are available to support inheritance:
-- --
-- * @{#BASE.Inherit}: Inherits from a class. -- * @{#BASE.Inherit}: Inherits from a class.
@ -2590,16 +2589,19 @@ env.info(( 'Init: Scripts Loaded v1.1' ))
local _TraceOn = true local _TraceOnOff = true
local _TraceLevel = 1 local _TraceLevel = 1
local _TraceAll = false local _TraceAll = false
local _TraceClass = {} local _TraceClass = {}
local _TraceClassMethod = {} local _TraceClassMethod = {}
local _ClassID = 0
--- The BASE Class --- The BASE Class
-- @type BASE -- @type BASE
-- @field ClassName The name of the class. -- @field ClassName The name of the class.
-- @field ClassID The ID number of the class. -- @field ClassID The ID number of the class.
-- @field ClassNameAndID The name of the class concatenated with the ID number of the class.
BASE = { BASE = {
ClassName = "BASE", ClassName = "BASE",
ClassID = 0, ClassID = 0,
@ -2621,27 +2623,29 @@ FORMATION = {
-- @param #BASE self -- @param #BASE self
-- @return #BASE The new instance of the BASE class. -- @return #BASE The new instance of the BASE class.
-- @usage -- @usage
-- function TASK:New() -- -- This declares the constructor of the class TASK, inheriting from BASE.
-- --- TASK constructor
-- -- @param #TASK self
-- -- @param Parameter The parameter of the New constructor.
-- -- @return #TASK self
-- function TASK:New( Parameter )
-- --
-- local self = BASE:Inherit( self, BASE:New() ) -- local self = BASE:Inherit( self, BASE:New() )
-- --
-- -- assign Task default values during construction -- self.Variable = Parameter
-- self.TaskBriefing = "Task: No Task."
-- self.Time = timer.getTime()
-- self.ExecuteStage = _TransportExecuteStage.NONE
-- --
-- return self -- return self
-- end -- end
-- @todo need to investigate if the deepCopy is really needed... Don't think so. -- @todo need to investigate if the deepCopy is really needed... Don't think so.
function BASE:New() function BASE:New()
local Child = routines.utils.deepCopy( self ) local self = routines.utils.deepCopy( self ) -- Create a new self instance
local Parent = {} local MetaTable = {}
setmetatable( Child, Parent ) setmetatable( self, MetaTable )
Child.__index = Child self.__index = self
self.ClassID = self.ClassID + 1 _ClassID = _ClassID + 1
Child.ClassID = self.ClassID self.ClassID = _ClassID
--Child.AddEvent( Child, S_EVENT_BIRTH, Child.EventBirth ) self.ClassNameAndID = string.format( '%s#%09d', self.ClassName, self.ClassID )
return Child return self
end end
--- This is the worker method to inherit from a parent class. --- This is the worker method to inherit from a parent class.
@ -2677,7 +2681,7 @@ end
-- @param #BASE self -- @param #BASE self
-- @return #string The ClassName + ClassID of the class instance. -- @return #string The ClassName + ClassID of the class instance.
function BASE:GetClassNameAndID() function BASE:GetClassNameAndID()
return string.format( '%s#%09d', self:GetClassName(), self:GetClassID() ) return self.ClassNameAndID
end end
--- Get the ClassName of the class instance. --- Get the ClassName of the class instance.
@ -2863,11 +2867,12 @@ end
function BASE:SetState( Object, StateName, State ) function BASE:SetState( Object, StateName, State )
local ClassNameAndID = Object:GetClassNameAndID() local ClassNameAndID = Object:GetClassNameAndID()
if not self.States[ClassNameAndID] then if not self.States[ClassNameAndID] then
self.States[ClassNameAndID] = {} self.States[ClassNameAndID] = {}
end end
self.States[ClassNameAndID][StateName] = State self.States[ClassNameAndID][StateName] = State
self:E( { ClassNameAndID, StateName, State } ) self:F2( { ClassNameAndID, StateName, State } )
return self.States[ClassNameAndID][StateName] return self.States[ClassNameAndID][StateName]
end end
@ -2875,10 +2880,10 @@ end
function BASE:GetState( Object, StateName ) function BASE:GetState( Object, StateName )
local ClassNameAndID = Object:GetClassNameAndID() local ClassNameAndID = Object:GetClassNameAndID()
self:E( { ClassNameAndID } )
if self.States[ClassNameAndID] then if self.States[ClassNameAndID] then
local State = self.States[ClassNameAndID][StateName] local State = self.States[ClassNameAndID][StateName]
self:E( { ClassNameAndID, StateName, State } ) self:F2( { ClassNameAndID, StateName, State } )
return State return State
end end
@ -2898,6 +2903,23 @@ end
-- Log a trace (only shown when trace is on) -- Log a trace (only shown when trace is on)
-- TODO: Make trace function using variable parameters. -- TODO: Make trace function using variable parameters.
--- Set trace on or off
-- Note that when trace is off, no debug statement is performed, increasing performance!
-- When Moose is loaded statically, (as one file), tracing is switched off by default.
-- So tracing must be switched on manually in your mission if you are using Moose statically.
-- When moose is loading dynamically (for moose class development), tracing is switched on by default.
-- @param BASE self
-- @param #boolean TraceOnOff Switch the tracing on or off.
-- @usage
-- -- Switch the tracing On
-- BASE:TraceOn( true )
--
-- -- Switch the tracing Off
-- BASE:TraceOn( false )
function BASE:TraceOnOff( TraceOnOff )
_TraceOnOff = TraceOnOff
end
--- Set trace level --- Set trace level
-- @param #BASE self -- @param #BASE self
-- @param #number Level -- @param #number Level
@ -2942,12 +2964,12 @@ function BASE:TraceClassMethod( Class, Method )
self:E( "Tracing method " .. Method .. " of class " .. Class ) self:E( "Tracing method " .. Method .. " of class " .. Class )
end end
--- Trace a function call. Must be at the beginning of the function logic. --- Trace a function call. This function is private.
-- @param #BASE self -- @param #BASE self
-- @param Arguments A #table or any field. -- @param Arguments A #table or any field.
function BASE:F( Arguments, DebugInfoCurrentParam, DebugInfoFromParam ) function BASE:_F( Arguments, DebugInfoCurrentParam, DebugInfoFromParam )
if _TraceOn and ( ( _TraceAll == true ) or ( _TraceClass[self.ClassName] or _TraceClassMethod[self.ClassName] ) ) then if ( _TraceAll == true ) or ( _TraceClass[self.ClassName] or _TraceClassMethod[self.ClassName] ) then
local DebugInfoCurrent = DebugInfoCurrentParam and DebugInfoCurrentParam or debug.getinfo( 2, "nl" ) local DebugInfoCurrent = DebugInfoCurrentParam and DebugInfoCurrentParam or debug.getinfo( 2, "nl" )
local DebugInfoFrom = DebugInfoFromParam and DebugInfoFromParam or debug.getinfo( 3, "l" ) local DebugInfoFrom = DebugInfoFromParam and DebugInfoFromParam or debug.getinfo( 3, "l" )
@ -2971,18 +2993,35 @@ function BASE:F( Arguments, DebugInfoCurrentParam, DebugInfoFromParam )
end end
end end
--- Trace a function call. Must be at the beginning of the function logic.
-- @param #BASE self
-- @param Arguments A #table or any field.
function BASE:F( Arguments )
if _TraceOnOff then
local DebugInfoCurrent = debug.getinfo( 2, "nl" )
local DebugInfoFrom = debug.getinfo( 3, "l" )
if _TraceLevel >= 1 then
self:_F( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
end
end
--- Trace a function call level 2. Must be at the beginning of the function logic. --- Trace a function call level 2. Must be at the beginning of the function logic.
-- @param #BASE self -- @param #BASE self
-- @param Arguments A #table or any field. -- @param Arguments A #table or any field.
function BASE:F2( Arguments ) function BASE:F2( Arguments )
local DebugInfoCurrent = debug.getinfo( 2, "nl" ) if _TraceOnOff then
local DebugInfoFrom = debug.getinfo( 3, "l" ) local DebugInfoCurrent = debug.getinfo( 2, "nl" )
local DebugInfoFrom = debug.getinfo( 3, "l" )
if _TraceLevel >= 2 then
self:F( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
if _TraceLevel >= 2 then
self:_F( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
end
end end
--- Trace a function call level 3. Must be at the beginning of the function logic. --- Trace a function call level 3. Must be at the beginning of the function logic.
@ -2990,13 +3029,14 @@ end
-- @param Arguments A #table or any field. -- @param Arguments A #table or any field.
function BASE:F3( Arguments ) function BASE:F3( Arguments )
local DebugInfoCurrent = debug.getinfo( 2, "nl" ) if _TraceOnOff then
local DebugInfoFrom = debug.getinfo( 3, "l" ) local DebugInfoCurrent = debug.getinfo( 2, "nl" )
local DebugInfoFrom = debug.getinfo( 3, "l" )
if _TraceLevel >= 3 then
self:F( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
if _TraceLevel >= 3 then
self:_F( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
end
end end
--- Trace a function logic. --- Trace a function logic.
@ -3004,7 +3044,7 @@ end
-- @param Arguments A #table or any field. -- @param Arguments A #table or any field.
function BASE:_T( Arguments, DebugInfoCurrentParam, DebugInfoFromParam ) function BASE:_T( Arguments, DebugInfoCurrentParam, DebugInfoFromParam )
if _TraceOn and ( ( _TraceAll == true ) or ( _TraceClass[self.ClassName] or _TraceClassMethod[self.ClassName] ) ) then if ( _TraceAll == true ) or ( _TraceClass[self.ClassName] or _TraceClassMethod[self.ClassName] ) then
local DebugInfoCurrent = DebugInfoCurrentParam and DebugInfoCurrentParam or debug.getinfo( 2, "nl" ) local DebugInfoCurrent = DebugInfoCurrentParam and DebugInfoCurrentParam or debug.getinfo( 2, "nl" )
local DebugInfoFrom = DebugInfoFromParam and DebugInfoFromParam or debug.getinfo( 3, "l" ) local DebugInfoFrom = DebugInfoFromParam and DebugInfoFromParam or debug.getinfo( 3, "l" )
@ -3033,13 +3073,14 @@ end
-- @param Arguments A #table or any field. -- @param Arguments A #table or any field.
function BASE:T( Arguments ) function BASE:T( Arguments )
local DebugInfoCurrent = debug.getinfo( 2, "nl" ) if _TraceOnOff then
local DebugInfoFrom = debug.getinfo( 3, "l" ) local DebugInfoCurrent = debug.getinfo( 2, "nl" )
local DebugInfoFrom = debug.getinfo( 3, "l" )
if _TraceLevel >= 1 then
self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
if _TraceLevel >= 1 then
self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
end
end end
@ -3048,13 +3089,14 @@ end
-- @param Arguments A #table or any field. -- @param Arguments A #table or any field.
function BASE:T2( Arguments ) function BASE:T2( Arguments )
local DebugInfoCurrent = debug.getinfo( 2, "nl" ) if _TraceOnOff then
local DebugInfoFrom = debug.getinfo( 3, "l" ) local DebugInfoCurrent = debug.getinfo( 2, "nl" )
local DebugInfoFrom = debug.getinfo( 3, "l" )
if _TraceLevel >= 2 then
self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
if _TraceLevel >= 2 then
self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
end
end end
--- Trace a function logic level 3. Can be anywhere within the function logic. --- Trace a function logic level 3. Can be anywhere within the function logic.
@ -3062,13 +3104,14 @@ end
-- @param Arguments A #table or any field. -- @param Arguments A #table or any field.
function BASE:T3( Arguments ) function BASE:T3( Arguments )
local DebugInfoCurrent = debug.getinfo( 2, "nl" ) if _TraceOnOff then
local DebugInfoFrom = debug.getinfo( 3, "l" ) local DebugInfoCurrent = debug.getinfo( 2, "nl" )
local DebugInfoFrom = debug.getinfo( 3, "l" )
if _TraceLevel >= 3 then
self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
if _TraceLevel >= 3 then
self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
end
end end
--- Log an exception which will be traced always. Can be anywhere within the function logic. --- Log an exception which will be traced always. Can be anywhere within the function logic.
@ -3096,36 +3139,36 @@ end
--- Models time events calling event handing functions. --- Models time events calling event handing functions.
-- --
-- @{SCHEDULER} class -- @{SCHEDULER} class
-- =================== -- ===================
-- The @{SCHEDULER} class models time events calling given event handling functions. -- The @{SCHEDULER} class models time events calling given event handling functions.
-- --
-- SCHEDULER constructor -- SCHEDULER constructor
-- ===================== -- =====================
-- The SCHEDULER class is quite easy to use: -- The SCHEDULER class is quite easy to use:
-- --
-- * @{#SCHEDULER.New}: Setup a new scheduler and start it with the specified parameters. -- * @{#SCHEDULER.New}: Setup a new scheduler and start it with the specified parameters.
-- --
-- SCHEDULER timer methods -- SCHEDULER timer methods
-- ======================= -- =======================
-- The SCHEDULER can be stopped and restarted with the following methods: -- The SCHEDULER can be stopped and restarted with the following methods:
-- --
-- * @{#SCHEDULER.Start}: (Re-)Start the scheduler. -- * @{#SCHEDULER.Start}: (Re-)Start the scheduler.
-- * @{#SCHEDULER.Start}: Stop the scheduler. -- * @{#SCHEDULER.Start}: Stop the scheduler.
-- --
-- @module Scheduler -- @module Scheduler
-- @author FlightControl -- @author FlightControl
--- The SCHEDULER class --- The SCHEDULER class
-- @type SCHEDULER -- @type SCHEDULER
-- @field #number ScheduleID the ID of the scheduler.
-- @extends Base#BASE -- @extends Base#BASE
SCHEDULER = { SCHEDULER = {
ClassName = "SCHEDULER", ClassName = "SCHEDULER",
} }
--- SCHEDULER constructor.
--- 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 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 #function TimeEventFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in TimeEventFunctionArguments.
@ -3160,10 +3203,10 @@ function SCHEDULER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionArg
if StopSeconds then if StopSeconds then
self.StopSeconds = StopSeconds self.StopSeconds = StopSeconds
end end
self.StartTime = timer.getTime() self.StartTime = timer.getTime()
self:Start() self:Start()
return self return self
@ -3174,12 +3217,12 @@ end
-- @return #SCHEDULER self -- @return #SCHEDULER self
function SCHEDULER:Start() function SCHEDULER:Start()
self:F2( self.TimeEventObject ) self:F2( self.TimeEventObject )
if self.RepeatSecondsInterval ~= 0 then if self.RepeatSecondsInterval ~= 0 then
self.Repeat = true self.Repeat = true
end end
timer.scheduleFunction( self._Scheduler, self, timer.getTime() + self.StartSeconds + .01 ) self.ScheduleID = timer.scheduleFunction( self._Scheduler, self, timer.getTime() + self.StartSeconds + .01 )
return self return self
end end
@ -3188,17 +3231,20 @@ end
-- @return #SCHEDULER self -- @return #SCHEDULER self
function SCHEDULER:Stop() function SCHEDULER:Stop()
self:F2( self.TimeEventObject ) self:F2( self.TimeEventObject )
self.Repeat = false self.Repeat = false
timer.removeFunction( self.ScheduleID )
self.ScheduleID = nil
return self return self
end end
-- Private Functions -- Private Functions
--- @param #SCHEDULER self
function SCHEDULER:_Scheduler() function SCHEDULER:_Scheduler()
self:F2( self.TimeEventFunctionArguments ) self:F2( self.TimeEventFunctionArguments )
local ErrorHandler = function( errmsg ) local ErrorHandler = function( errmsg )
env.info( "Error in SCHEDULER function:" .. errmsg ) env.info( "Error in SCHEDULER function:" .. errmsg )
@ -3207,27 +3253,37 @@ function SCHEDULER:_Scheduler()
return errmsg return errmsg
end end
local Status, Result local Status, Result
if self.TimeEventObject then if self.TimeEventObject then
Status, Result = xpcall( function() return self.TimeEventFunction( self.TimeEventObject, unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler ) Status, Result = xpcall( function() return self.TimeEventFunction( self.TimeEventObject, unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler )
else else
Status, Result = xpcall( function() return self.TimeEventFunction( unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler ) Status, Result = xpcall( function() return self.TimeEventFunction( unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler )
end end
self:T( { Status, Result, self.StartTime, self.RepeatSecondsInterval, self.RandomizationFactor, self.StopSeconds } ) self:T( { self.TimeEventFunctionArguments, Status, Result, self.StartTime, self.RepeatSecondsInterval, self.RandomizationFactor, self.StopSeconds } )
if Status and ( ( Result == nil ) or ( Result and Result ~= false ) ) then if Status and ( ( Result == nil ) or ( Result and Result ~= false ) ) then
if self.Repeat and ( not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) ) then if self.Repeat and ( not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) ) then
local ScheduleTime = timer.getTime() + self.RepeatSecondsInterval + math.random( - ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ), ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ) ) + 0.01 local ScheduleTime =
self:T( { timer.getTime(), ScheduleTime } ) timer.getTime() +
timer.scheduleFunction( self.RepeatSecondsInterval +
self._Scheduler, math.random(
self, - ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ),
ScheduleTime ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 )
) ) +
0.01
self:T( { self.TimeEventFunctionArguments, "Repeat:", timer.getTime(), ScheduleTime } )
return ScheduleTime -- returns the next time the function needs to be called.
else
timer.removeFunction( self.ScheduleID )
self.ScheduleID = nil
end end
else
timer.removeFunction( self.ScheduleID )
self.ScheduleID = nil
end end
return nil
end end
@ -3237,6 +3293,14 @@ end
--- The EVENT class models an efficient event handling process between other classes and its units, weapons. --- The EVENT class models an efficient event handling process between other classes and its units, weapons.
-- @module Event -- @module Event
-- @author FlightControl -- @author FlightControl
@ -7011,13 +7075,13 @@ function UNIT:FindByName( UnitName )
end end
function UNIT:GetDCSUnit() function UNIT:GetDCSUnit()
local DCSUnit = Unit.getByName( self.UnitName ) local DCSUnit = Unit.getByName( self.UnitName )
if DCSUnit then if DCSUnit then
return DCSUnit return DCSUnit
end end
self:E( "Unit " .. self.UnitName .. " not found!" )
return nil return nil
end end
@ -8173,12 +8237,6 @@ end
-- @module Client -- @module Client
-- @author FlightControl -- @author FlightControl
--- The CLIENT class --- The CLIENT class
-- @type CLIENT -- @type CLIENT
-- @extends Unit#UNIT -- @extends Unit#UNIT
@ -8267,7 +8325,7 @@ function CLIENT:Register( ClientName )
self.ClientAlive2 = false 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 ) self.AliveCheckScheduler = SCHEDULER:New( self, self._AliveCheckScheduler, { "Client Alive " .. ClientName }, 1, 5 )
self:E( self ) self:E( self )
return self return self
@ -8377,10 +8435,11 @@ function CLIENT:Alive( CallBackFunction, ... )
end end
--- @param #CLIENT self --- @param #CLIENT self
function CLIENT:_AliveCheckScheduler() function CLIENT:_AliveCheckScheduler( SchedulerName )
self:F( { self.ClientName, self.ClientAlive2, self.ClientBriefingShown, self.ClientCallBack } ) self:E( SchedulerName )
self:F( { SchedulerName, self.ClientName, self.ClientAlive2, self.ClientBriefingShown, self.ClientCallBack } )
if self:IsAlive() then -- Polymorphic call of UNIT if self:IsAlive() then
if self.ClientAlive2 == false then if self.ClientAlive2 == false then
self:ShowBriefing() self:ShowBriefing()
if self.ClientCallBack then if self.ClientCallBack then
@ -20064,4 +20123,6 @@ end
BASE:TraceOnOff( false )
env.info( '*** MOOSE INCLUDE END *** ' ) env.info( '*** MOOSE INCLUDE END *** ' )

View File

@ -1,18 +1,12 @@
env.info( '*** MOOSE STATIC INCLUDE START *** ' ) env.info( '*** MOOSE STATIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20160614_1531' ) env.info( 'Moose Generation Timestamp: 20160615_0552' )
local base = _G local base = _G
Include = {} Include = {}
Include.Files = {}
Include.Path = function()
local str = debug.getinfo(2, "S").source
return str:match("(.*/)"):sub(1,-2):gsub("\\","/")
end
Include.File = function( IncludeFile ) Include.File = function( IncludeFile )
end end
Include.Files = {}
--- Various routines --- Various routines
-- @module routines -- @module routines
-- @author Flightcontrol -- @author Flightcontrol
@ -2533,35 +2527,40 @@ end
env.info(( 'Init: Scripts Loaded v1.1' )) env.info(( 'Init: Scripts Loaded v1.1' ))
--- BASE classes. --- This module contains the BASE class.
-- --
-- @{#BASE} class -- 1) @{#BASE} class
-- ============== -- =================
-- The @{#BASE} class is the super class for most of the classes defined within MOOSE. -- The @{#BASE} class is the super class for all the classes defined within MOOSE.
-- --
-- It handles: -- It handles:
-- --
-- * The construction and inheritance of child classes. -- * The construction and inheritance of child classes.
-- * The tracing of objects during mission execution within the DCS.log file (under saved games folder). -- * The tracing of objects during mission execution within the **DCS.log** file, under the **"Saved Games\DCS\Logs"** folder.
-- --
-- Note: Normally you would not use the BASE class unless you are extending the MOOSE framework with new classes. -- Note: Normally you would not use the BASE class unless you are extending the MOOSE framework with new classes.
-- --
-- BASE Trace functionality -- 1.1) BASE constructor
-- ======================== -- ---------------------
-- Any class derived from BASE, must use the @{Base#BASE.New) constructor within the @{Base#BASE.Inherit) method.
-- See an example at the @{Base#BASE.New} method how this is done.
--
-- 1.2) BASE Trace functionality
-- -----------------------------
-- The BASE class contains trace methods to trace progress within a mission execution of a certain object. -- The BASE class contains trace methods to trace progress within a mission execution of a certain object.
-- Note that these trace methods are inherited by each MOOSE class interiting BASE. -- Note that these trace methods are inherited by each MOOSE class interiting BASE.
-- As such, each object created from derived class from BASE can use the tracing functions to trace its execution. -- As such, each object created from derived class from BASE can use the tracing functions to trace its execution.
-- --
-- Trace a function call -- 1.2.1) Tracing functions
-- --------------------- -- ------------------------
-- There are basically 3 types of tracing methods available within BASE: -- There are basically 3 types of tracing methods available within BASE:
-- --
-- * @{#BASE.F}: Trace the beginning of a function and its given parameters. -- * @{#BASE.F}: Trace the beginning of a function and its given parameters. An F is indicated at column 44 in the DCS.log file.
-- * @{#BASE.T}: Trace further logic within a function giving optional variables or parameters. -- * @{#BASE.T}: Trace further logic within a function giving optional variables or parameters. A T is indicated at column 44 in the DCS.log file.
-- * @{#BASE.E}: Trace an execption within a function giving optional variables or parameters. An exception will always be traced. -- * @{#BASE.E}: Trace an exception within a function giving optional variables or parameters. An E is indicated at column 44 in the DCS.log file. An exception will always be traced.
-- --
-- Tracing levels -- 1.2.2) Tracing levels
-- -------------- -- ---------------------
-- There are 3 tracing levels within MOOSE. -- There are 3 tracing levels within MOOSE.
-- These tracing levels were defined to avoid bulks of tracing to be generated by lots of objects. -- These tracing levels were defined to avoid bulks of tracing to be generated by lots of objects.
-- --
@ -2572,8 +2571,8 @@ env.info(( 'Init: Scripts Loaded v1.1' ))
-- * @{#BASE.T2}: Trace further logic within a function giving optional variables or parameters with tracing level 2. -- * @{#BASE.T2}: Trace further logic within a function giving optional variables or parameters with tracing level 2.
-- * @{#BASE.T3}: Trace further logic within a function giving optional variables or parameters with tracing level 3. -- * @{#BASE.T3}: Trace further logic within a function giving optional variables or parameters with tracing level 3.
-- --
-- BASE Inheritance support -- 1.3) BASE Inheritance support
-- ======================== -- ===========================
-- The following methods are available to support inheritance: -- The following methods are available to support inheritance:
-- --
-- * @{#BASE.Inherit}: Inherits from a class. -- * @{#BASE.Inherit}: Inherits from a class.
@ -2590,16 +2589,19 @@ env.info(( 'Init: Scripts Loaded v1.1' ))
local _TraceOn = true local _TraceOnOff = true
local _TraceLevel = 1 local _TraceLevel = 1
local _TraceAll = false local _TraceAll = false
local _TraceClass = {} local _TraceClass = {}
local _TraceClassMethod = {} local _TraceClassMethod = {}
local _ClassID = 0
--- The BASE Class --- The BASE Class
-- @type BASE -- @type BASE
-- @field ClassName The name of the class. -- @field ClassName The name of the class.
-- @field ClassID The ID number of the class. -- @field ClassID The ID number of the class.
-- @field ClassNameAndID The name of the class concatenated with the ID number of the class.
BASE = { BASE = {
ClassName = "BASE", ClassName = "BASE",
ClassID = 0, ClassID = 0,
@ -2621,27 +2623,29 @@ FORMATION = {
-- @param #BASE self -- @param #BASE self
-- @return #BASE The new instance of the BASE class. -- @return #BASE The new instance of the BASE class.
-- @usage -- @usage
-- function TASK:New() -- -- This declares the constructor of the class TASK, inheriting from BASE.
-- --- TASK constructor
-- -- @param #TASK self
-- -- @param Parameter The parameter of the New constructor.
-- -- @return #TASK self
-- function TASK:New( Parameter )
-- --
-- local self = BASE:Inherit( self, BASE:New() ) -- local self = BASE:Inherit( self, BASE:New() )
-- --
-- -- assign Task default values during construction -- self.Variable = Parameter
-- self.TaskBriefing = "Task: No Task."
-- self.Time = timer.getTime()
-- self.ExecuteStage = _TransportExecuteStage.NONE
-- --
-- return self -- return self
-- end -- end
-- @todo need to investigate if the deepCopy is really needed... Don't think so. -- @todo need to investigate if the deepCopy is really needed... Don't think so.
function BASE:New() function BASE:New()
local Child = routines.utils.deepCopy( self ) local self = routines.utils.deepCopy( self ) -- Create a new self instance
local Parent = {} local MetaTable = {}
setmetatable( Child, Parent ) setmetatable( self, MetaTable )
Child.__index = Child self.__index = self
self.ClassID = self.ClassID + 1 _ClassID = _ClassID + 1
Child.ClassID = self.ClassID self.ClassID = _ClassID
--Child.AddEvent( Child, S_EVENT_BIRTH, Child.EventBirth ) self.ClassNameAndID = string.format( '%s#%09d', self.ClassName, self.ClassID )
return Child return self
end end
--- This is the worker method to inherit from a parent class. --- This is the worker method to inherit from a parent class.
@ -2677,7 +2681,7 @@ end
-- @param #BASE self -- @param #BASE self
-- @return #string The ClassName + ClassID of the class instance. -- @return #string The ClassName + ClassID of the class instance.
function BASE:GetClassNameAndID() function BASE:GetClassNameAndID()
return string.format( '%s#%09d', self:GetClassName(), self:GetClassID() ) return self.ClassNameAndID
end end
--- Get the ClassName of the class instance. --- Get the ClassName of the class instance.
@ -2863,11 +2867,12 @@ end
function BASE:SetState( Object, StateName, State ) function BASE:SetState( Object, StateName, State )
local ClassNameAndID = Object:GetClassNameAndID() local ClassNameAndID = Object:GetClassNameAndID()
if not self.States[ClassNameAndID] then if not self.States[ClassNameAndID] then
self.States[ClassNameAndID] = {} self.States[ClassNameAndID] = {}
end end
self.States[ClassNameAndID][StateName] = State self.States[ClassNameAndID][StateName] = State
self:E( { ClassNameAndID, StateName, State } ) self:F2( { ClassNameAndID, StateName, State } )
return self.States[ClassNameAndID][StateName] return self.States[ClassNameAndID][StateName]
end end
@ -2875,10 +2880,10 @@ end
function BASE:GetState( Object, StateName ) function BASE:GetState( Object, StateName )
local ClassNameAndID = Object:GetClassNameAndID() local ClassNameAndID = Object:GetClassNameAndID()
self:E( { ClassNameAndID } )
if self.States[ClassNameAndID] then if self.States[ClassNameAndID] then
local State = self.States[ClassNameAndID][StateName] local State = self.States[ClassNameAndID][StateName]
self:E( { ClassNameAndID, StateName, State } ) self:F2( { ClassNameAndID, StateName, State } )
return State return State
end end
@ -2898,6 +2903,23 @@ end
-- Log a trace (only shown when trace is on) -- Log a trace (only shown when trace is on)
-- TODO: Make trace function using variable parameters. -- TODO: Make trace function using variable parameters.
--- Set trace on or off
-- Note that when trace is off, no debug statement is performed, increasing performance!
-- When Moose is loaded statically, (as one file), tracing is switched off by default.
-- So tracing must be switched on manually in your mission if you are using Moose statically.
-- When moose is loading dynamically (for moose class development), tracing is switched on by default.
-- @param BASE self
-- @param #boolean TraceOnOff Switch the tracing on or off.
-- @usage
-- -- Switch the tracing On
-- BASE:TraceOn( true )
--
-- -- Switch the tracing Off
-- BASE:TraceOn( false )
function BASE:TraceOnOff( TraceOnOff )
_TraceOnOff = TraceOnOff
end
--- Set trace level --- Set trace level
-- @param #BASE self -- @param #BASE self
-- @param #number Level -- @param #number Level
@ -2942,12 +2964,12 @@ function BASE:TraceClassMethod( Class, Method )
self:E( "Tracing method " .. Method .. " of class " .. Class ) self:E( "Tracing method " .. Method .. " of class " .. Class )
end end
--- Trace a function call. Must be at the beginning of the function logic. --- Trace a function call. This function is private.
-- @param #BASE self -- @param #BASE self
-- @param Arguments A #table or any field. -- @param Arguments A #table or any field.
function BASE:F( Arguments, DebugInfoCurrentParam, DebugInfoFromParam ) function BASE:_F( Arguments, DebugInfoCurrentParam, DebugInfoFromParam )
if _TraceOn and ( ( _TraceAll == true ) or ( _TraceClass[self.ClassName] or _TraceClassMethod[self.ClassName] ) ) then if ( _TraceAll == true ) or ( _TraceClass[self.ClassName] or _TraceClassMethod[self.ClassName] ) then
local DebugInfoCurrent = DebugInfoCurrentParam and DebugInfoCurrentParam or debug.getinfo( 2, "nl" ) local DebugInfoCurrent = DebugInfoCurrentParam and DebugInfoCurrentParam or debug.getinfo( 2, "nl" )
local DebugInfoFrom = DebugInfoFromParam and DebugInfoFromParam or debug.getinfo( 3, "l" ) local DebugInfoFrom = DebugInfoFromParam and DebugInfoFromParam or debug.getinfo( 3, "l" )
@ -2971,18 +2993,35 @@ function BASE:F( Arguments, DebugInfoCurrentParam, DebugInfoFromParam )
end end
end end
--- Trace a function call. Must be at the beginning of the function logic.
-- @param #BASE self
-- @param Arguments A #table or any field.
function BASE:F( Arguments )
if _TraceOnOff then
local DebugInfoCurrent = debug.getinfo( 2, "nl" )
local DebugInfoFrom = debug.getinfo( 3, "l" )
if _TraceLevel >= 1 then
self:_F( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
end
end
--- Trace a function call level 2. Must be at the beginning of the function logic. --- Trace a function call level 2. Must be at the beginning of the function logic.
-- @param #BASE self -- @param #BASE self
-- @param Arguments A #table or any field. -- @param Arguments A #table or any field.
function BASE:F2( Arguments ) function BASE:F2( Arguments )
local DebugInfoCurrent = debug.getinfo( 2, "nl" ) if _TraceOnOff then
local DebugInfoFrom = debug.getinfo( 3, "l" ) local DebugInfoCurrent = debug.getinfo( 2, "nl" )
local DebugInfoFrom = debug.getinfo( 3, "l" )
if _TraceLevel >= 2 then
self:F( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
if _TraceLevel >= 2 then
self:_F( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
end
end end
--- Trace a function call level 3. Must be at the beginning of the function logic. --- Trace a function call level 3. Must be at the beginning of the function logic.
@ -2990,13 +3029,14 @@ end
-- @param Arguments A #table or any field. -- @param Arguments A #table or any field.
function BASE:F3( Arguments ) function BASE:F3( Arguments )
local DebugInfoCurrent = debug.getinfo( 2, "nl" ) if _TraceOnOff then
local DebugInfoFrom = debug.getinfo( 3, "l" ) local DebugInfoCurrent = debug.getinfo( 2, "nl" )
local DebugInfoFrom = debug.getinfo( 3, "l" )
if _TraceLevel >= 3 then
self:F( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
if _TraceLevel >= 3 then
self:_F( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
end
end end
--- Trace a function logic. --- Trace a function logic.
@ -3004,7 +3044,7 @@ end
-- @param Arguments A #table or any field. -- @param Arguments A #table or any field.
function BASE:_T( Arguments, DebugInfoCurrentParam, DebugInfoFromParam ) function BASE:_T( Arguments, DebugInfoCurrentParam, DebugInfoFromParam )
if _TraceOn and ( ( _TraceAll == true ) or ( _TraceClass[self.ClassName] or _TraceClassMethod[self.ClassName] ) ) then if ( _TraceAll == true ) or ( _TraceClass[self.ClassName] or _TraceClassMethod[self.ClassName] ) then
local DebugInfoCurrent = DebugInfoCurrentParam and DebugInfoCurrentParam or debug.getinfo( 2, "nl" ) local DebugInfoCurrent = DebugInfoCurrentParam and DebugInfoCurrentParam or debug.getinfo( 2, "nl" )
local DebugInfoFrom = DebugInfoFromParam and DebugInfoFromParam or debug.getinfo( 3, "l" ) local DebugInfoFrom = DebugInfoFromParam and DebugInfoFromParam or debug.getinfo( 3, "l" )
@ -3033,13 +3073,14 @@ end
-- @param Arguments A #table or any field. -- @param Arguments A #table or any field.
function BASE:T( Arguments ) function BASE:T( Arguments )
local DebugInfoCurrent = debug.getinfo( 2, "nl" ) if _TraceOnOff then
local DebugInfoFrom = debug.getinfo( 3, "l" ) local DebugInfoCurrent = debug.getinfo( 2, "nl" )
local DebugInfoFrom = debug.getinfo( 3, "l" )
if _TraceLevel >= 1 then
self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
if _TraceLevel >= 1 then
self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
end
end end
@ -3048,13 +3089,14 @@ end
-- @param Arguments A #table or any field. -- @param Arguments A #table or any field.
function BASE:T2( Arguments ) function BASE:T2( Arguments )
local DebugInfoCurrent = debug.getinfo( 2, "nl" ) if _TraceOnOff then
local DebugInfoFrom = debug.getinfo( 3, "l" ) local DebugInfoCurrent = debug.getinfo( 2, "nl" )
local DebugInfoFrom = debug.getinfo( 3, "l" )
if _TraceLevel >= 2 then
self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
if _TraceLevel >= 2 then
self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
end
end end
--- Trace a function logic level 3. Can be anywhere within the function logic. --- Trace a function logic level 3. Can be anywhere within the function logic.
@ -3062,13 +3104,14 @@ end
-- @param Arguments A #table or any field. -- @param Arguments A #table or any field.
function BASE:T3( Arguments ) function BASE:T3( Arguments )
local DebugInfoCurrent = debug.getinfo( 2, "nl" ) if _TraceOnOff then
local DebugInfoFrom = debug.getinfo( 3, "l" ) local DebugInfoCurrent = debug.getinfo( 2, "nl" )
local DebugInfoFrom = debug.getinfo( 3, "l" )
if _TraceLevel >= 3 then
self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
if _TraceLevel >= 3 then
self:_T( Arguments, DebugInfoCurrent, DebugInfoFrom )
end
end
end end
--- Log an exception which will be traced always. Can be anywhere within the function logic. --- Log an exception which will be traced always. Can be anywhere within the function logic.
@ -3096,36 +3139,36 @@ end
--- Models time events calling event handing functions. --- Models time events calling event handing functions.
-- --
-- @{SCHEDULER} class -- @{SCHEDULER} class
-- =================== -- ===================
-- The @{SCHEDULER} class models time events calling given event handling functions. -- The @{SCHEDULER} class models time events calling given event handling functions.
-- --
-- SCHEDULER constructor -- SCHEDULER constructor
-- ===================== -- =====================
-- The SCHEDULER class is quite easy to use: -- The SCHEDULER class is quite easy to use:
-- --
-- * @{#SCHEDULER.New}: Setup a new scheduler and start it with the specified parameters. -- * @{#SCHEDULER.New}: Setup a new scheduler and start it with the specified parameters.
-- --
-- SCHEDULER timer methods -- SCHEDULER timer methods
-- ======================= -- =======================
-- The SCHEDULER can be stopped and restarted with the following methods: -- The SCHEDULER can be stopped and restarted with the following methods:
-- --
-- * @{#SCHEDULER.Start}: (Re-)Start the scheduler. -- * @{#SCHEDULER.Start}: (Re-)Start the scheduler.
-- * @{#SCHEDULER.Start}: Stop the scheduler. -- * @{#SCHEDULER.Start}: Stop the scheduler.
-- --
-- @module Scheduler -- @module Scheduler
-- @author FlightControl -- @author FlightControl
--- The SCHEDULER class --- The SCHEDULER class
-- @type SCHEDULER -- @type SCHEDULER
-- @field #number ScheduleID the ID of the scheduler.
-- @extends Base#BASE -- @extends Base#BASE
SCHEDULER = { SCHEDULER = {
ClassName = "SCHEDULER", ClassName = "SCHEDULER",
} }
--- SCHEDULER constructor.
--- 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 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 #function TimeEventFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in TimeEventFunctionArguments.
@ -3160,10 +3203,10 @@ function SCHEDULER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionArg
if StopSeconds then if StopSeconds then
self.StopSeconds = StopSeconds self.StopSeconds = StopSeconds
end end
self.StartTime = timer.getTime() self.StartTime = timer.getTime()
self:Start() self:Start()
return self return self
@ -3174,12 +3217,12 @@ end
-- @return #SCHEDULER self -- @return #SCHEDULER self
function SCHEDULER:Start() function SCHEDULER:Start()
self:F2( self.TimeEventObject ) self:F2( self.TimeEventObject )
if self.RepeatSecondsInterval ~= 0 then if self.RepeatSecondsInterval ~= 0 then
self.Repeat = true self.Repeat = true
end end
timer.scheduleFunction( self._Scheduler, self, timer.getTime() + self.StartSeconds + .01 ) self.ScheduleID = timer.scheduleFunction( self._Scheduler, self, timer.getTime() + self.StartSeconds + .01 )
return self return self
end end
@ -3188,17 +3231,20 @@ end
-- @return #SCHEDULER self -- @return #SCHEDULER self
function SCHEDULER:Stop() function SCHEDULER:Stop()
self:F2( self.TimeEventObject ) self:F2( self.TimeEventObject )
self.Repeat = false self.Repeat = false
timer.removeFunction( self.ScheduleID )
self.ScheduleID = nil
return self return self
end end
-- Private Functions -- Private Functions
--- @param #SCHEDULER self
function SCHEDULER:_Scheduler() function SCHEDULER:_Scheduler()
self:F2( self.TimeEventFunctionArguments ) self:F2( self.TimeEventFunctionArguments )
local ErrorHandler = function( errmsg ) local ErrorHandler = function( errmsg )
env.info( "Error in SCHEDULER function:" .. errmsg ) env.info( "Error in SCHEDULER function:" .. errmsg )
@ -3207,27 +3253,37 @@ function SCHEDULER:_Scheduler()
return errmsg return errmsg
end end
local Status, Result local Status, Result
if self.TimeEventObject then if self.TimeEventObject then
Status, Result = xpcall( function() return self.TimeEventFunction( self.TimeEventObject, unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler ) Status, Result = xpcall( function() return self.TimeEventFunction( self.TimeEventObject, unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler )
else else
Status, Result = xpcall( function() return self.TimeEventFunction( unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler ) Status, Result = xpcall( function() return self.TimeEventFunction( unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler )
end end
self:T( { Status, Result, self.StartTime, self.RepeatSecondsInterval, self.RandomizationFactor, self.StopSeconds } ) self:T( { self.TimeEventFunctionArguments, Status, Result, self.StartTime, self.RepeatSecondsInterval, self.RandomizationFactor, self.StopSeconds } )
if Status and ( ( Result == nil ) or ( Result and Result ~= false ) ) then if Status and ( ( Result == nil ) or ( Result and Result ~= false ) ) then
if self.Repeat and ( not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) ) then if self.Repeat and ( not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) ) then
local ScheduleTime = timer.getTime() + self.RepeatSecondsInterval + math.random( - ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ), ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ) ) + 0.01 local ScheduleTime =
self:T( { timer.getTime(), ScheduleTime } ) timer.getTime() +
timer.scheduleFunction( self.RepeatSecondsInterval +
self._Scheduler, math.random(
self, - ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 ),
ScheduleTime ( self.RandomizationFactor * self.RepeatSecondsInterval / 2 )
) ) +
0.01
self:T( { self.TimeEventFunctionArguments, "Repeat:", timer.getTime(), ScheduleTime } )
return ScheduleTime -- returns the next time the function needs to be called.
else
timer.removeFunction( self.ScheduleID )
self.ScheduleID = nil
end end
else
timer.removeFunction( self.ScheduleID )
self.ScheduleID = nil
end end
return nil
end end
@ -3237,6 +3293,14 @@ end
--- The EVENT class models an efficient event handling process between other classes and its units, weapons. --- The EVENT class models an efficient event handling process between other classes and its units, weapons.
-- @module Event -- @module Event
-- @author FlightControl -- @author FlightControl
@ -7011,13 +7075,13 @@ function UNIT:FindByName( UnitName )
end end
function UNIT:GetDCSUnit() function UNIT:GetDCSUnit()
local DCSUnit = Unit.getByName( self.UnitName ) local DCSUnit = Unit.getByName( self.UnitName )
if DCSUnit then if DCSUnit then
return DCSUnit return DCSUnit
end end
self:E( "Unit " .. self.UnitName .. " not found!" )
return nil return nil
end end
@ -8173,12 +8237,6 @@ end
-- @module Client -- @module Client
-- @author FlightControl -- @author FlightControl
--- The CLIENT class --- The CLIENT class
-- @type CLIENT -- @type CLIENT
-- @extends Unit#UNIT -- @extends Unit#UNIT
@ -8267,7 +8325,7 @@ function CLIENT:Register( ClientName )
self.ClientAlive2 = false 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 ) self.AliveCheckScheduler = SCHEDULER:New( self, self._AliveCheckScheduler, { "Client Alive " .. ClientName }, 1, 5 )
self:E( self ) self:E( self )
return self return self
@ -8377,10 +8435,11 @@ function CLIENT:Alive( CallBackFunction, ... )
end end
--- @param #CLIENT self --- @param #CLIENT self
function CLIENT:_AliveCheckScheduler() function CLIENT:_AliveCheckScheduler( SchedulerName )
self:F( { self.ClientName, self.ClientAlive2, self.ClientBriefingShown, self.ClientCallBack } ) self:E( SchedulerName )
self:F( { SchedulerName, self.ClientName, self.ClientAlive2, self.ClientBriefingShown, self.ClientCallBack } )
if self:IsAlive() then -- Polymorphic call of UNIT if self:IsAlive() then
if self.ClientAlive2 == false then if self.ClientAlive2 == false then
self:ShowBriefing() self:ShowBriefing()
if self.ClientCallBack then if self.ClientCallBack then
@ -20064,4 +20123,6 @@ end
BASE:TraceOnOff( false )
env.info( '*** MOOSE INCLUDE END *** ' ) env.info( '*** MOOSE INCLUDE END *** ' )

View File

@ -19,10 +19,11 @@ GOTO End
ECHO Dynamic Moose.lua ECHO Dynamic Moose.lua
REM Create a timestamp with is logged in the DCS.log file. REM Create a timestamp with is logged in the DCS.log file.
ECHO env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' ) > Moose.lua ECHO env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' ) > Moose.lua
ECHO env.info( 'Moose Generation Timestamp: %2' ) >> Moose.lua ECHO env.info( 'Moose Generation Timestamp: %2' ) >> Moose.lua
COPY /b Moose.lua + "Moose Create Dynamic\Moose_Dynamic_Loader.lua" Moose.lua COPY /b Moose.lua + "Moose Create Dynamic\Moose_Dynamic_Loader.lua" Moose.lua
COPY /b Moose.lua + "Moose Create Dynamic\Moose_Trace_On.lua" Moose.lua
GOTO End GOTO End
@ -34,49 +35,51 @@ REM Create a timestamp with is logged in the DCS.log file.
ECHO env.info( '*** MOOSE STATIC INCLUDE START *** ' ) > Moose.lua ECHO env.info( '*** MOOSE STATIC INCLUDE START *** ' ) > Moose.lua
ECHO env.info( 'Moose Generation Timestamp: %2' ) >> Moose.lua ECHO env.info( 'Moose Generation Timestamp: %2' ) >> Moose.lua
COPY /b Moose.lua + "Moose Create Static\Moose_Static_Loader.lua" Moose.lua COPY /b Moose.lua + "Moose Create Static\Moose_Static_Loader.lua" Moose.lua
COPY /b Moose.lua + %1\Routines.lua Moose.lua COPY /b Moose.lua + %1\Routines.lua Moose.lua
COPY /b Moose.lua + %1\Base.lua Moose.lua COPY /b Moose.lua + %1\Base.lua Moose.lua
COPY /b Moose.lua + %1\Scheduler.lua Moose.lua COPY /b Moose.lua + %1\Scheduler.lua Moose.lua
COPY /b Moose.lua + %1\Event.lua Moose.lua COPY /b Moose.lua + %1\Event.lua Moose.lua
COPY /b Moose.lua + %1\Menu.lua Moose.lua COPY /b Moose.lua + %1\Menu.lua Moose.lua
COPY /b Moose.lua + %1\Group.lua Moose.lua COPY /b Moose.lua + %1\Group.lua Moose.lua
COPY /b Moose.lua + %1\Unit.lua Moose.lua COPY /b Moose.lua + %1\Unit.lua Moose.lua
COPY /b Moose.lua + %1\Zone.lua Moose.lua COPY /b Moose.lua + %1\Zone.lua Moose.lua
COPY /b Moose.lua + %1\Client.lua Moose.lua COPY /b Moose.lua + %1\Client.lua Moose.lua
COPY /b Moose.lua + %1\Static.lua Moose.lua COPY /b Moose.lua + %1\Static.lua Moose.lua
COPY /b Moose.lua + %1\Database.lua Moose.lua COPY /b Moose.lua + %1\Database.lua Moose.lua
COPY /b Moose.lua + %1\Set.lua Moose.lua COPY /b Moose.lua + %1\Set.lua Moose.lua
COPY /b Moose.lua + %1\Point.lua Moose.lua COPY /b Moose.lua + %1\Point.lua Moose.lua
COPY /b Moose.lua + %1\Moose.lua Moose.lua COPY /b Moose.lua + %1\Moose.lua Moose.lua
COPY /b Moose.lua + %1\Scoring.lua Moose.lua COPY /b Moose.lua + %1\Scoring.lua Moose.lua
COPY /b Moose.lua + %1\Cargo.lua Moose.lua COPY /b Moose.lua + %1\Cargo.lua Moose.lua
COPY /b Moose.lua + %1\Message.lua Moose.lua COPY /b Moose.lua + %1\Message.lua Moose.lua
COPY /b Moose.lua + %1\Stage.lua Moose.lua COPY /b Moose.lua + %1\Stage.lua Moose.lua
COPY /b Moose.lua + %1\Task.lua Moose.lua COPY /b Moose.lua + %1\Task.lua Moose.lua
COPY /b Moose.lua + %1\GoHomeTask.lua Moose.lua COPY /b Moose.lua + %1\GoHomeTask.lua Moose.lua
COPY /b Moose.lua + %1\DestroyBaseTask.lua Moose.lua COPY /b Moose.lua + %1\DestroyBaseTask.lua Moose.lua
COPY /b Moose.lua + %1\DestroyGroupsTask.lua Moose.lua COPY /b Moose.lua + %1\DestroyGroupsTask.lua Moose.lua
COPY /b Moose.lua + %1\DestroyRadarsTask.lua Moose.lua COPY /b Moose.lua + %1\DestroyRadarsTask.lua Moose.lua
COPY /b Moose.lua + %1\DestroyUnitTypesTask.lua Moose.lua COPY /b Moose.lua + %1\DestroyUnitTypesTask.lua Moose.lua
COPY /b Moose.lua + %1\PickupTask.lua Moose.lua COPY /b Moose.lua + %1\PickupTask.lua Moose.lua
COPY /b Moose.lua + %1\DeployTask.lua Moose.lua COPY /b Moose.lua + %1\DeployTask.lua Moose.lua
COPY /b Moose.lua + %1\NoTask.lua Moose.lua COPY /b Moose.lua + %1\NoTask.lua Moose.lua
COPY /b Moose.lua + %1\RouteTask.lua Moose.lua COPY /b Moose.lua + %1\RouteTask.lua Moose.lua
COPY /b Moose.lua + %1\Mission.lua Moose.lua COPY /b Moose.lua + %1\Mission.lua Moose.lua
COPY /b Moose.lua + %1\CleanUp.lua Moose.lua COPY /b Moose.lua + %1\CleanUp.lua Moose.lua
COPY /b Moose.lua + %1\Spawn.lua Moose.lua COPY /b Moose.lua + %1\Spawn.lua Moose.lua
COPY /b Moose.lua + %1\Movement.lua Moose.lua COPY /b Moose.lua + %1\Movement.lua Moose.lua
COPY /b Moose.lua + %1\Sead.lua Moose.lua COPY /b Moose.lua + %1\Sead.lua Moose.lua
COPY /b Moose.lua + %1\Escort.lua Moose.lua COPY /b Moose.lua + %1\Escort.lua Moose.lua
COPY /b Moose.lua + %1\MissileTrainer.lua Moose.lua COPY /b Moose.lua + %1\MissileTrainer.lua Moose.lua
COPY /b Moose.lua + %1\AIBalancer.lua Moose.lua COPY /b Moose.lua + %1\AIBalancer.lua Moose.lua
COPY /b Moose.lua + "Moose Create Static\Moose_Trace_Off.lua" Moose.lua
GOTO End GOTO End
:End :End
ECHO env.info( '*** MOOSE INCLUDE END *** ' ) >> Moose.lua ECHO env.info( '*** MOOSE INCLUDE END *** ' ) >> Moose.lua
COPY Moose.lua %3 COPY Moose.lua %3