From 688875dca58029e304726f338411e33fafec92c3 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Fri, 7 Jul 2017 08:23:22 +0200 Subject: [PATCH] Fixed performance issue Problem was in BASE. I added a field "ParentClass", which was a mistake... at every deepcopy it started to copy ParentClass contents too! My god! No wonder it suddenly went all slow. --- Moose Development/Moose/Core/Base.lua | 17 +++++++++-------- Moose Development/Moose/Core/Fsm.lua | 14 +++++++------- Moose Development/Moose/Tasking/Task.lua | 1 - 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Moose Development/Moose/Core/Base.lua b/Moose Development/Moose/Core/Base.lua index 511610786..441e83ec1 100644 --- a/Moose Development/Moose/Core/Base.lua +++ b/Moose Development/Moose/Core/Base.lua @@ -234,9 +234,9 @@ function BASE:New() -- This is for "private" methods... -- When a __ is passed to a method as "self", the __index will search for the method on the public method list too! - if rawget( self, "__" ) then - setmetatable( self, { __index = self.__ } ) - end +-- if rawget( self, "__" ) then + --setmetatable( self, { __index = self.__ } ) +-- end return self end @@ -250,7 +250,6 @@ function BASE:Inherit( Child, Parent ) local Child = routines.utils.deepCopy( Child ) if Child ~= nil then - Child.ClassParent = Parent -- This is for "private" methods... -- When a __ is passed to a method as "self", the __index will search for the method on the public method list of the same object too! @@ -261,10 +260,8 @@ function BASE:Inherit( Child, Parent ) setmetatable( Child, { __index = Parent } ) end - --Child:_SetDestructor() end - --self:T( 'Inherited from ' .. Parent.ClassName ) return Child end @@ -278,8 +275,12 @@ end -- @param #BASE Child is the Child class from which the Parent class needs to be retrieved. -- @return #BASE function BASE:GetParent( Child ) - local Parent = Child.ClassParent --- env.info('Inherited class of ' .. Child.ClassName .. ' is ' .. Parent.ClassName ) + local Parent + if rawget( Child, "__" ) then + Parent = getmetatable( Child.__ ).__Index + else + Parent = getmetatable( Child ).__Index + end return Parent end diff --git a/Moose Development/Moose/Core/Fsm.lua b/Moose Development/Moose/Core/Fsm.lua index efd15901e..d934f68ad 100644 --- a/Moose Development/Moose/Core/Fsm.lua +++ b/Moose Development/Moose/Core/Fsm.lua @@ -418,7 +418,7 @@ do -- 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. function FSM:AddProcess( From, Event, Process, ReturnEvents ) - self:T( { From, Event, Process, ReturnEvents } ) + self:T( { From, Event } ) local Sub = {} Sub.From = From @@ -541,7 +541,7 @@ do -- FSM end function FSM:_submap( subs, sub, name ) - self:F( { sub = sub, name = name } ) + --self:F( { sub = sub, name = name } ) subs[sub.From] = subs[sub.From] or {} subs[sub.From][sub.Event] = subs[sub.From][sub.Event] or {} @@ -844,7 +844,7 @@ do -- FSM_CONTROLLABLE -- @param Wrapper.Controllable#CONTROLLABLE FSMControllable -- @return #FSM_CONTROLLABLE function FSM_CONTROLLABLE:SetControllable( FSMControllable ) - self:F( FSMControllable ) + --self:F( FSMControllable:GetName() ) self.Controllable = FSMControllable end @@ -904,7 +904,7 @@ do -- FSM_PROCESS local self = BASE:Inherit( self, FSM_CONTROLLABLE:New() ) -- Core.Fsm#FSM_PROCESS - self:F( Controllable, Task ) + --self:F( Controllable ) self:Assign( Controllable, Task ) @@ -960,7 +960,7 @@ do -- FSM_PROCESS -- Copy Processes for ProcessID, Process in pairs( self:GetProcesses() ) do - self:E( { Process} ) + --self:E( { Process:GetName() } ) local FsmProcess = NewFsm:AddProcess( Process.From, Process.Event, Process.fsm:Copy( Controllable, Task ), Process.ReturnEvents ) end @@ -1062,7 +1062,7 @@ end -- @param Wrapper.Unit#UNIT ProcessUnit -- @return #FSM_PROCESS self function FSM_PROCESS:Assign( ProcessUnit, Task ) - self:T( { Task, ProcessUnit } ) + --self:T( { Task:GetName(), ProcessUnit:GetName() } ) self:SetControllable( ProcessUnit ) self:SetTask( Task ) @@ -1092,7 +1092,7 @@ end -- @param #string From -- @param #string To function FSM_PROCESS:onstatechange( ProcessUnit, Task, From, Event, To, Dummy ) - self:T( { ProcessUnit, From, Event, To, Dummy, self:IsTrace() } ) + self:T( { ProcessUnit:GetName(), From, Event, To, Dummy, self:IsTrace() } ) if self:IsTrace() then --MESSAGE:New( "@ Process " .. self:GetClassNameAndID() .. " : " .. Event .. " changed to state " .. To, 2 ):ToAll() diff --git a/Moose Development/Moose/Tasking/Task.lua b/Moose Development/Moose/Tasking/Task.lua index 93522f3f0..a56d3fc8e 100644 --- a/Moose Development/Moose/Tasking/Task.lua +++ b/Moose Development/Moose/Tasking/Task.lua @@ -574,7 +574,6 @@ function TASK:AssignToUnit( TaskUnit ) -- Assign a new FsmUnit to TaskUnit. local FsmUnit = self:SetStateMachine( TaskUnit, FsmTemplate:Copy( TaskUnit, self ) ) -- Core.Fsm#FSM_PROCESS - self:E({"Address FsmUnit", tostring( FsmUnit ) } ) FsmUnit:SetStartState( "Planned" )