Added Event Reset for SPAWN, GROUP and UNIT on SPAWN:ReSpawn()

This commit is contained in:
FlightControl
2017-04-11 08:19:06 +02:00
parent 321a33f0f6
commit 51c1da3557
5 changed files with 59 additions and 32 deletions
+30 -30
View File
@@ -424,13 +424,6 @@ function EVENT:New()
return self return self
end end
function EVENT:EventText( EventID )
local EventText = _EVENTMETA[EventID].Text
return EventText
end
--- Initializes the Events structure for the event --- Initializes the Events structure for the event
-- @param #EVENT self -- @param #EVENT self
@@ -442,7 +435,7 @@ function EVENT:Init( EventID, EventClass )
if not self.Events[EventID] then if not self.Events[EventID] then
-- Create a WEAK table to ensure that the garbage collector is cleaning the event links when the object usage is cleaned. -- Create a WEAK table to ensure that the garbage collector is cleaning the event links when the object usage is cleaned.
self.Events[EventID] = setmetatable( {}, { __mode = "k" } ) self.Events[EventID] = {}
end end
-- Each event has a subtable of EventClasses, ordered by EventPriority. -- Each event has a subtable of EventClasses, ordered by EventPriority.
@@ -457,44 +450,51 @@ function EVENT:Init( EventID, EventClass )
return self.Events[EventID][EventPriority][EventClass] return self.Events[EventID][EventPriority][EventClass]
end end
--- Removes an Events entry --- Removes a subscription
-- @param #EVENT self -- @param #EVENT self
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is. -- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param Dcs.DCSWorld#world.event EventID -- @param Dcs.DCSWorld#world.event EventID
-- @return #EVENT.Events -- @return #EVENT.Events
function EVENT:Remove( EventClass, EventID ) function EVENT:Remove( EventClass, EventID )
self:F3( { EventClass, _EVENTMETA[EventID].Text } )
local EventClass = EventClass self:E( { "Removing subscription for class: ", EventClass:GetClassNameAndID() } )
local EventPriority = EventClass:GetEventPriority() local EventPriority = EventClass:GetEventPriority()
self.EventsDead = self.EventsDead or {}
self.EventsDead[EventID] = self.EventsDead[EventID] or {}
self.EventsDead[EventID][EventPriority] = self.EventsDead[EventID][EventPriority] or {}
self.EventsDead[EventID][EventPriority][EventClass] = self.Events[EventID][EventPriority][EventClass]
self.Events[EventID][EventPriority][EventClass] = nil self.Events[EventID][EventPriority][EventClass] = nil
end end
--- Removes an Events entry for a UNIT. --- Resets subscriptions
-- @param #EVENT self -- @param #EVENT self
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is. -- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param Dcs.DCSWorld#world.event EventID -- @param Dcs.DCSWorld#world.event EventID
-- @return #EVENT.Events -- @return #EVENT.Events
function EVENT:RemoveForUnit( EventClass, EventID ) function EVENT:Reset( EventObject )
self:F3( { EventClass, _EVENTMETA[EventID].Text } )
local EventClass = EventClass self:E( { "Resetting subscriptions for class: ", EventObject:GetClassNameAndID() } )
local EventPriority = EventClass:GetEventPriority()
self.Events[EventID][EventPriority][EventClass] = nil local EventPriority = EventObject:GetEventPriority()
for EventID, EventData in pairs( self.Events ) do
if self.EventsDead then
if self.EventsDead[EventID] then
if self.EventsDead[EventID][EventPriority] then
if self.EventsDead[EventID][EventPriority][EventObject] then
self.Events[EventID][EventPriority][EventObject] = self.EventsDead[EventID][EventPriority][EventObject]
end
end
end
end
end
end end
--- Removes an Events entry for a GROUP.
-- @param #EVENT self
-- @param Core.Base#BASE EventClass The self instance of the class for which the event is.
-- @param Dcs.DCSWorld#world.event EventID
-- @return #EVENT.Events
function EVENT:RemoveForGroup( EventClass, EventID )
self:F3( { EventClass, _EVENTMETA[EventID].Text } )
local EventClass = EventClass
local EventPriority = EventClass:GetEventPriority()
self.Events[EventID][EventPriority][EventClass] = nil
end
--- Clears all event subscriptions for a @{Base#BASE} derived object. --- Clears all event subscriptions for a @{Base#BASE} derived object.
-- @param #EVENT self -- @param #EVENT self
@@ -869,7 +869,7 @@ function EVENT:onEvent( Event )
end end
else else
-- The EventClass is not alive anymore, we remove it from the EventHandlers... -- The EventClass is not alive anymore, we remove it from the EventHandlers...
self:RemoveForUnit( EventClass, Event.id ) self:Remove( EventClass, Event.id )
end end
else else
@@ -917,7 +917,7 @@ function EVENT:onEvent( Event )
end end
else else
-- The EventClass is not alive anymore, we remove it from the EventHandlers... -- The EventClass is not alive anymore, we remove it from the EventHandlers...
self:RemoveForGroup( EventClass, Event.id ) self:Remove( EventClass, Event.id )
end end
else else
@@ -759,6 +759,8 @@ function SPAWN:ReSpawn( SpawnIndex )
SpawnGroup:ReSpawnFunction() SpawnGroup:ReSpawnFunction()
end end
SpawnGroup:ResetEvents()
return SpawnGroup return SpawnGroup
end end
+15 -1
View File
@@ -1077,7 +1077,21 @@ do -- Event Handling
-- @return #GROUP -- @return #GROUP
function GROUP:UnHandleEvent( Event ) function GROUP:UnHandleEvent( Event )
self:EventDispatcher():RemoveForGroup( self:GetName(), self, Event ) self:EventDispatcher():Remove( self, Event )
return self
end
--- Reset the subscriptions.
-- @param #GROUP self
-- @return #GROUP
function GROUP:ResetEvents( Event )
self:EventDispatcher():Reset( self )
for UnitID, UnitData in pairs( self:GetUnits() ) do
UnitData:ResetEvents()
end
return self return self
end end
+11
View File
@@ -991,4 +991,15 @@ do -- Event Handling
return self return self
end end
--- Reset the subscriptions.
-- @param #UNIT self
-- @return #UNIT
function UNIT:ResetEvents( Event )
self:EventDispatcher():Reset( self )
return self
end
end end
+1 -1
View File
@@ -1,5 +1,5 @@
env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' ) env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170411_0630' ) env.info( 'Moose Generation Timestamp: 20170411_0812' )
local base = _G local base = _G