mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Optimized the scheduler
This commit is contained in:
@@ -80,6 +80,7 @@ Include.File( "Database" )
|
||||
Include.File( "Group" )
|
||||
Include.File( "Zone" )
|
||||
Include.File( "Event" )
|
||||
Include.File( "Scheduler" )
|
||||
|
||||
--- SPAWN Class
|
||||
-- @type SPAWN
|
||||
@@ -323,8 +324,8 @@ function SPAWN:CleanUp( SpawnCleanUpInterval )
|
||||
|
||||
self.SpawnCleanUpInterval = SpawnCleanUpInterval
|
||||
self.SpawnCleanUpTimeStamps = {}
|
||||
self.CleanUpFunction = routines.scheduleFunction( self._SpawnCleanUpScheduler, { self }, timer.getTime() + 1, SpawnCleanUpInterval )
|
||||
|
||||
--self.CleanUpFunction = routines.scheduleFunction( self._SpawnCleanUpScheduler, { self }, timer.getTime() + 1, SpawnCleanUpInterval )
|
||||
self.CleanUpScheduler = SCHEDULER:New( self, self._SpawnCleanUpScheduler, {}, 1, SpawnCleanUpInterval, 0.2 )
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -502,20 +503,30 @@ function SPAWN:SpawnScheduled( SpawnTime, SpawnTimeVariation )
|
||||
self.SpawnCurrentTimer = 0 -- The internal timer counter to trigger a scheduled spawning of SpawnTemplatePrefix.
|
||||
self.SpawnSetTimer = 0 -- The internal timer value when a scheduled spawning of SpawnTemplatePrefix occurs.
|
||||
self.AliveFactor = 1 --
|
||||
self.SpawnLowTimer = 0
|
||||
self.SpawnHighTimer = 0
|
||||
|
||||
if SpawnTime ~= nil and SpawnTimeVariation ~= nil then
|
||||
self.SpawnLowTimer = SpawnTime - SpawnTime / 2 * SpawnTimeVariation
|
||||
self.SpawnHighTimer = SpawnTime + SpawnTime / 2 * SpawnTimeVariation
|
||||
self:SpawnScheduleStart()
|
||||
self.SpawnScheduler = SCHEDULER:New( self, self._Scheduler, {}, 1, SpawnTime, SpawnTimeVariation )
|
||||
end
|
||||
|
||||
self:T( { self.SpawnLowTimer, self.SpawnHighTimer } )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Will re-start the spawning scheduler.
|
||||
-- Note: This function is only required to be called when the schedule was stopped.
|
||||
function SPAWN:SpawnScheduleStart()
|
||||
self:F( { self.SpawnTemplatePrefix } )
|
||||
|
||||
self.SpawnScheduler:Start()
|
||||
end
|
||||
|
||||
--- Will stop the scheduled spawning scheduler.
|
||||
function SPAWN:SpawnScheduleStop()
|
||||
self:F( { self.SpawnTemplatePrefix } )
|
||||
|
||||
self.SpawnScheduler:Stop()
|
||||
end
|
||||
|
||||
|
||||
--- Allows to place a CallFunction hook when a new group spawns.
|
||||
-- The provided function will be called when a new group is spawned, including its given parameters.
|
||||
-- The first parameter of the SpawnFunction is the @{Group#GROUP} that was spawned.
|
||||
@@ -537,30 +548,6 @@ end
|
||||
|
||||
|
||||
|
||||
--- Will start the spawning scheduler.
|
||||
-- Note: This function is called automatically when @{#SPAWN.Scheduled} is called.
|
||||
function SPAWN:SpawnScheduleStart()
|
||||
self:F( { self.SpawnTemplatePrefix } )
|
||||
|
||||
--local ClientUnit = #AlivePlayerUnits()
|
||||
|
||||
self.AliveFactor = 10 -- ( 10 - ClientUnit ) / 10
|
||||
|
||||
if self.SpawnIsScheduled == false then
|
||||
self.SpawnIsScheduled = true
|
||||
self.SpawnInit = true
|
||||
self.SpawnSetTimer = math.random( self.SpawnLowTimer * self.AliveFactor / 10 , self.SpawnHighTimer * self.AliveFactor / 10 )
|
||||
|
||||
self.SpawnFunction = routines.scheduleFunction( self._Scheduler, { self }, timer.getTime() + 1, 1 )
|
||||
end
|
||||
end
|
||||
|
||||
--- Will stop the scheduled spawning scheduler.
|
||||
function SPAWN:SpawnScheduleStop()
|
||||
self:F( { self.SpawnTemplatePrefix } )
|
||||
|
||||
self.SpawnIsScheduled = false
|
||||
end
|
||||
|
||||
--- Will spawn a group from a hosting unit. This function is mostly advisable to be used if you want to simulate spawning from air units, like helicopters, which are dropping infantry into a defined Landing Zone.
|
||||
-- Note that each point in the route assigned to the spawning group is reset to the point of the spawn.
|
||||
@@ -1240,19 +1227,10 @@ end
|
||||
function SPAWN:_Scheduler()
|
||||
self:F( { "_Scheduler", self.SpawnTemplatePrefix, self.SpawnAliasPrefix, self.SpawnIndex, self.SpawnMaxGroups, self.SpawnMaxUnitsAlive } )
|
||||
|
||||
if self.SpawnInit or self.SpawnCurrentTimer == self.SpawnSetTimer then
|
||||
-- Validate if there are still groups left in the batch...
|
||||
self:Spawn()
|
||||
self.SpawnInit = false
|
||||
if self.SpawnIsScheduled == true then
|
||||
--local ClientUnit = #AlivePlayerUnits()
|
||||
self.AliveFactor = 1 -- ( 10 - ClientUnit ) / 10
|
||||
self.SpawnCurrentTimer = 0
|
||||
self.SpawnSetTimer = math.random( self.SpawnLowTimer * self.AliveFactor , self.SpawnHighTimer * self.AliveFactor )
|
||||
end
|
||||
else
|
||||
self.SpawnCurrentTimer = self.SpawnCurrentTimer + 1
|
||||
end
|
||||
-- Validate if there are still groups left in the batch...
|
||||
self:Spawn()
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function SPAWN:_SpawnCleanUpScheduler()
|
||||
@@ -1284,4 +1262,6 @@ function SPAWN:_SpawnCleanUpScheduler()
|
||||
|
||||
end
|
||||
|
||||
return true -- Repeat
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user