Cleanup of logging volume in fsm.lua

-- replaced all self:E with self:T
This commit is contained in:
FlightControl 2017-01-23 14:16:24 +01:00
parent faa64c9f4e
commit d4497fbf5e

View File

@ -150,7 +150,7 @@
-- The following example provides a little demonstration on the difference between synchronous and asynchronous Event Triggering. -- The following example provides a little demonstration on the difference between synchronous and asynchronous Event Triggering.
-- --
-- function FSM:OnAfterEvent( From, Event, To, Amount ) -- function FSM:OnAfterEvent( From, Event, To, Amount )
-- self:E( { Amount = Amount } ) -- self:T( { Amount = Amount } )
-- end -- end
-- --
-- local Amount = 1 -- local Amount = 1
@ -198,7 +198,7 @@
-- ![Transition Flow](..\Presentations\FSM\Dia7.JPG) -- ![Transition Flow](..\Presentations\FSM\Dia7.JPG)
-- --
-- function FsmDemo:OnAfterSwitch( From, Event, To, FsmUnit ) -- function FsmDemo:OnAfterSwitch( From, Event, To, FsmUnit )
-- self:E( { From, Event, To, FsmUnit } ) -- self:T( { From, Event, To, FsmUnit } )
-- --
-- if From == "Green" then -- if From == "Green" then
-- FsmUnit:Flare(FLARECOLOR.Green) -- FsmUnit:Flare(FLARECOLOR.Green)
@ -221,7 +221,7 @@
-- --
-- For debugging reasons the received parameters are traced within the DCS.log. -- For debugging reasons the received parameters are traced within the DCS.log.
-- --
-- self:E( { From, Event, To, FsmUnit } ) -- self:T( { From, Event, To, FsmUnit } )
-- --
-- The method will check if the From state received is either "Green" or "Red" and will flare the respective color from the FsmUnit. -- The method will check if the From state received is either "Green" or "Red" and will flare the respective color from the FsmUnit.
-- --
@ -365,7 +365,7 @@ do -- FSM
Transition.Event = Event Transition.Event = Event
Transition.To = To Transition.To = To
self:E( Transition ) self:T( Transition )
self._Transitions[Transition] = Transition self._Transitions[Transition] = Transition
self:_eventmap( self.Events, Transition ) self:_eventmap( self.Events, Transition )
@ -387,7 +387,7 @@ do -- FSM
-- @param #table ReturnEvents A table indicating for which returned events of the SubFSM which Event must be triggered in the FSM. -- @param #table ReturnEvents A table indicating for which returned events of the SubFSM which Event must be triggered in the FSM.
-- @return Core.Fsm#FSM_PROCESS The SubFSM. -- @return Core.Fsm#FSM_PROCESS The SubFSM.
function FSM:AddProcess( From, Event, Process, ReturnEvents ) function FSM:AddProcess( From, Event, Process, ReturnEvents )
self:E( { From, Event, Process, ReturnEvents } ) self:T( { From, Event, Process, ReturnEvents } )
local Sub = {} local Sub = {}
Sub.From = From Sub.From = From
@ -417,7 +417,7 @@ do -- FSM
for ProcessID, Process in pairs( self:GetProcesses() ) do for ProcessID, Process in pairs( self:GetProcesses() ) do
if Process.From == From and Process.Event == Event then if Process.From == From and Process.Event == Event then
self:E( Process ) self:T( Process )
return Process.fsm return Process.fsm
end end
end end
@ -468,7 +468,7 @@ do -- FSM
local Process = self:GetProcess( From, Event ) local Process = self:GetProcess( From, Event )
self:E( { Process = Process._Name, Scores = Process._Scores, State = State, ScoreText = ScoreText, Score = Score } ) self:T( { Process = Process._Name, Scores = Process._Scores, State = State, ScoreText = ScoreText, Score = Score } )
Process._Scores[State] = Process._Scores[State] or {} Process._Scores[State] = Process._Scores[State] or {}
Process._Scores[State].ScoreText = ScoreText Process._Scores[State].ScoreText = ScoreText
Process._Scores[State].Score = Score Process._Scores[State].Score = Score
@ -528,7 +528,7 @@ do -- FSM
function FSM:_call_handler(handler, params) function FSM:_call_handler(handler, params)
if self[handler] then if self[handler] then
self:E( "Calling " .. handler ) self:T( "Calling " .. handler )
local Value = self[handler]( self, unpack(params) ) local Value = self[handler]( self, unpack(params) )
return Value return Value
end end
@ -547,16 +547,16 @@ do -- FSM
local params = { from, EventName, to, ... } local params = { from, EventName, to, ... }
if self.Controllable then if self.Controllable then
self:E( "FSM Transition for " .. self.Controllable.ControllableName .. " :" .. self.current .. " --> " .. EventName .. " --> " .. to ) self:T( "FSM Transition for " .. self.Controllable.ControllableName .. " :" .. self.current .. " --> " .. EventName .. " --> " .. to )
else else
self:E( "FSM Transition:" .. self.current .. " --> " .. EventName .. " --> " .. to ) self:T( "FSM Transition:" .. self.current .. " --> " .. EventName .. " --> " .. to )
end end
if ( self:_call_handler("onbefore" .. EventName, params) == false ) if ( self:_call_handler("onbefore" .. EventName, params) == false )
or ( self:_call_handler("OnBefore" .. EventName, params) == false ) or ( self:_call_handler("OnBefore" .. EventName, params) == false )
or ( self:_call_handler("onleave" .. from, params) == false ) or ( self:_call_handler("onleave" .. from, params) == false )
or ( self:_call_handler("OnLeave" .. from, params) == false ) then or ( self:_call_handler("OnLeave" .. from, params) == false ) then
self:E( "Cancel Transition" ) self:T( "Cancel Transition" )
return false return false
end end
@ -570,7 +570,7 @@ do -- FSM
-- self:F2( "nextevent = " .. sub.nextevent ) -- self:F2( "nextevent = " .. sub.nextevent )
-- self[sub.nextevent]( self ) -- self[sub.nextevent]( self )
--end --end
self:E( "calling sub start event: " .. sub.StartEvent ) self:T( "calling sub start event: " .. sub.StartEvent )
sub.fsm.fsmparent = self sub.fsm.fsmparent = self
sub.fsm.ReturnEvents = sub.ReturnEvents sub.fsm.ReturnEvents = sub.ReturnEvents
sub.fsm[sub.StartEvent]( sub.fsm ) sub.fsm[sub.StartEvent]( sub.fsm )
@ -602,31 +602,29 @@ do -- FSM
self:_call_handler("onstatechange", params) self:_call_handler("onstatechange", params)
end end
else else
self:E( "Cannot execute transition." ) self:T( "Cannot execute transition." )
self:E( { From = self.current, Event = EventName, To = to, Can = Can } ) self:T( { From = self.current, Event = EventName, To = to, Can = Can } )
end end
return nil return nil
end end
function FSM:_delayed_transition( EventName ) function FSM:_delayed_transition( EventName )
self:E( { EventName = EventName } )
return function( self, DelaySeconds, ... ) return function( self, DelaySeconds, ... )
self:T( "Delayed Event: " .. EventName ) self:T2( "Delayed Event: " .. EventName )
local CallID = self.CallScheduler:Schedule( self, self._handler, { EventName, ... }, DelaySeconds or 1 ) local CallID = self.CallScheduler:Schedule( self, self._handler, { EventName, ... }, DelaySeconds or 1 )
self:T( { CallID = CallID } ) self:T2( { CallID = CallID } )
end end
end end
function FSM:_create_transition( EventName ) function FSM:_create_transition( EventName )
self:E( { Event = EventName } )
return function( self, ... ) return self._handler( self, EventName , ... ) end return function( self, ... ) return self._handler( self, EventName , ... ) end
end end
function FSM:_gosub( ParentFrom, ParentEvent ) function FSM:_gosub( ParentFrom, ParentEvent )
local fsmtable = {} local fsmtable = {}
if self.subs[ParentFrom] and self.subs[ParentFrom][ParentEvent] then if self.subs[ParentFrom] and self.subs[ParentFrom][ParentEvent] then
self:E( { ParentFrom, ParentEvent, self.subs[ParentFrom], self.subs[ParentFrom][ParentEvent] } ) self:T( { ParentFrom, ParentEvent, self.subs[ParentFrom], self.subs[ParentFrom][ParentEvent] } )
return self.subs[ParentFrom][ParentEvent] return self.subs[ParentFrom][ParentEvent]
else else
return {} return {}
@ -636,17 +634,17 @@ do -- FSM
function FSM:_isendstate( Current ) function FSM:_isendstate( Current )
local FSMParent = self.fsmparent local FSMParent = self.fsmparent
if FSMParent and self.endstates[Current] then if FSMParent and self.endstates[Current] then
self:E( { state = Current, endstates = self.endstates, endstate = self.endstates[Current] } ) self:T( { state = Current, endstates = self.endstates, endstate = self.endstates[Current] } )
FSMParent.current = Current FSMParent.current = Current
local ParentFrom = FSMParent.current local ParentFrom = FSMParent.current
self:E( ParentFrom ) self:T( ParentFrom )
self:E( self.ReturnEvents ) self:T( self.ReturnEvents )
local Event = self.ReturnEvents[Current] local Event = self.ReturnEvents[Current]
self:E( { ParentFrom, Event, self.ReturnEvents } ) self:T( { ParentFrom, Event, self.ReturnEvents } )
if Event then if Event then
return FSMParent, Event return FSMParent, Event
else else
self:E( { "Could not find parent event name for state ", ParentFrom } ) self:T( { "Could not find parent event name for state ", ParentFrom } )
end end
end end
@ -781,14 +779,14 @@ do -- FSM_PROCESS
end end
function FSM_PROCESS:Init( FsmProcess ) function FSM_PROCESS:Init( FsmProcess )
self:E( "No Initialisation" ) self:T( "No Initialisation" )
end end
--- Creates a new FSM_PROCESS object based on this FSM_PROCESS. --- Creates a new FSM_PROCESS object based on this FSM_PROCESS.
-- @param #FSM_PROCESS self -- @param #FSM_PROCESS self
-- @return #FSM_PROCESS -- @return #FSM_PROCESS
function FSM_PROCESS:Copy( Controllable, Task ) function FSM_PROCESS:Copy( Controllable, Task )
self:E( { self:GetClassNameAndID() } ) self:T( { self:GetClassNameAndID() } )
local NewFsm = self:New( Controllable, Task ) -- Core.Fsm#FSM_PROCESS local NewFsm = self:New( Controllable, Task ) -- Core.Fsm#FSM_PROCESS
@ -807,19 +805,19 @@ do -- FSM_PROCESS
-- Copy Processes -- Copy Processes
for ProcessID, Process in pairs( self:GetProcesses() ) do for ProcessID, Process in pairs( self:GetProcesses() ) do
self:E( { Process} ) self:T( { Process} )
local FsmProcess = NewFsm:AddProcess( Process.From, Process.Event, Process.fsm:Copy( Controllable, Task ), Process.ReturnEvents ) local FsmProcess = NewFsm:AddProcess( Process.From, Process.Event, Process.fsm:Copy( Controllable, Task ), Process.ReturnEvents )
end end
-- Copy End States -- Copy End States
for EndStateID, EndState in pairs( self:GetEndStates() ) do for EndStateID, EndState in pairs( self:GetEndStates() ) do
self:E( EndState ) self:T( EndState )
NewFsm:AddEndState( EndState ) NewFsm:AddEndState( EndState )
end end
-- Copy the score tables -- Copy the score tables
for ScoreID, Score in pairs( self:GetScores() ) do for ScoreID, Score in pairs( self:GetScores() ) do
self:E( Score ) self:T( Score )
NewFsm:AddScore( ScoreID, Score.ScoreText, Score.Score ) NewFsm:AddScore( ScoreID, Score.ScoreText, Score.Score )
end end
@ -889,7 +887,7 @@ end
-- @param Wrapper.Unit#UNIT ProcessUnit -- @param Wrapper.Unit#UNIT ProcessUnit
-- @return #FSM_PROCESS self -- @return #FSM_PROCESS self
function FSM_PROCESS:Assign( ProcessUnit, Task ) function FSM_PROCESS:Assign( ProcessUnit, Task )
self:E( { Task, ProcessUnit } ) self:T( { Task, ProcessUnit } )
self:SetControllable( ProcessUnit ) self:SetControllable( ProcessUnit )
self:SetTask( Task ) self:SetTask( Task )
@ -916,19 +914,19 @@ end
end end
function FSM_PROCESS:onenterAssigned( ProcessUnit ) function FSM_PROCESS:onenterAssigned( ProcessUnit )
self:E( "Assign" ) self:T( "Assign" )
self.Task:Assign() self.Task:Assign()
end end
function FSM_PROCESS:onenterFailed( ProcessUnit ) function FSM_PROCESS:onenterFailed( ProcessUnit )
self:E( "Failed" ) self:T( "Failed" )
self.Task:Fail() self.Task:Fail()
end end
function FSM_PROCESS:onenterSuccess( ProcessUnit ) function FSM_PROCESS:onenterSuccess( ProcessUnit )
self:E( "Success" ) self:T( "Success" )
self.Task:Success() self.Task:Success()
end end
@ -940,13 +938,13 @@ end
-- @param #string From -- @param #string From
-- @param #string To -- @param #string To
function FSM_PROCESS:onstatechange( ProcessUnit, From, Event, To, Dummy ) function FSM_PROCESS:onstatechange( ProcessUnit, From, Event, To, Dummy )
self:E( { ProcessUnit, From, Event, To, Dummy, self:IsTrace() } ) self:T( { ProcessUnit, From, Event, To, Dummy, self:IsTrace() } )
if self:IsTrace() then if self:IsTrace() then
MESSAGE:New( "@ Process " .. self:GetClassNameAndID() .. " : " .. Event .. " changed to state " .. To, 2 ):ToAll() MESSAGE:New( "@ Process " .. self:GetClassNameAndID() .. " : " .. Event .. " changed to state " .. To, 2 ):ToAll()
end end
self:E( self.Scores[To] ) self:T( self.Scores[To] )
-- TODO: This needs to be reworked with a callback functions allocated within Task, and set within the mission script from the Task Objects... -- TODO: This needs to be reworked with a callback functions allocated within Task, and set within the mission script from the Task Objects...
if self.Scores[To] then if self.Scores[To] then
@ -987,7 +985,7 @@ do -- FSM_TASK
function FSM_TASK:_call_handler( handler, params ) function FSM_TASK:_call_handler( handler, params )
if self[handler] then if self[handler] then
self:E( "Calling " .. handler ) self:T( "Calling " .. handler )
return self[handler]( self, unpack( params ) ) return self[handler]( self, unpack( params ) )
end end
end end