mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
First prototype of the scheduler dispatcher is ready... It works, but the code was very difficult...
So, when the Scheduler that is passed to the AddScheduler is nillified, the internal arrays that keep the Scheduler reference are also nillified. And it does what i need for further utilization in MOOSE classes. When the Scheduler is nillified, but, a schedule was planned for that Scheduler, once the scheduler fires off, it will ignore that call... cool. Sven
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
--- Simple function scheduling
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- Author: FlightControl
|
||||
-- Date Created: 12 Dec 2016
|
||||
--
|
||||
-- # Situation
|
||||
-- Uses the Tracing functions from BASE within the DCS.log file. Check the DCS.log file for the results.
|
||||
-- Create a new SCHEDULER object.
|
||||
-- Check the DCS.log.
|
||||
--
|
||||
-- # Test cases:
|
||||
--
|
||||
-- 1. The log should contain a "Hello World" line that is fired off 10 seconds after mission start.
|
||||
--
|
||||
--
|
||||
-- # Status: TESTED - 12 Dec 2016
|
||||
|
||||
local TestScheduler = SCHEDULER:New( nil,
|
||||
function()
|
||||
BASE:E( "Hello World")
|
||||
end, {}, 1
|
||||
)
|
||||
Binary file not shown.
@@ -0,0 +1,34 @@
|
||||
--- Simple Object Scheduling
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- Author: FlightControl
|
||||
-- Date Created: 12 Dec 2016
|
||||
--
|
||||
-- # Situation
|
||||
-- Uses the Tracing functions from BASE within the DCS.log file. Check the DCS.log file for the results.
|
||||
-- Create a new SCHEDULER object.
|
||||
-- Check the DCS.log.
|
||||
--
|
||||
-- # Test cases:
|
||||
--
|
||||
-- 1. Tracing of a scheduler in an Object.
|
||||
-- The log should contain a "Hello World" line of the object, that is fired off 1 seconds after mission start.
|
||||
--
|
||||
-- # Status: TESTED - 12 Dec 2016
|
||||
|
||||
local TEST_BASE = {
|
||||
ClassName = "TEST_BASE",
|
||||
}
|
||||
|
||||
function TEST_BASE:New( Message )
|
||||
self = BASE:Inherit( self, BASE:New() )
|
||||
|
||||
local TestScheduler = SCHEDULER:New( self,
|
||||
function( Object, Message )
|
||||
Object:E( Message )
|
||||
end, { Message }, 1
|
||||
)
|
||||
end
|
||||
|
||||
local Test = TEST_BASE:New( "Hello World" )
|
||||
Binary file not shown.
@@ -1,8 +0,0 @@
|
||||
GroupTest = GROUP:FindByName("Test")
|
||||
|
||||
TestScheduler = SCHEDULER:New( nil,
|
||||
function()
|
||||
|
||||
MESSAGE:New("Hello World", 5 ):ToAll()
|
||||
|
||||
end, {}, 10, 10 )
|
||||
@@ -1,28 +0,0 @@
|
||||
-- This test will schedule the same function 2 times.
|
||||
|
||||
SpawnTest = SPAWN:New( "Test" )
|
||||
TestZone = ZONE:New( "TestZone" )
|
||||
|
||||
local function MessageTest2()
|
||||
|
||||
SpawnTest:SpawnInZone( TestZone, true )
|
||||
|
||||
end
|
||||
|
||||
local function MessageTest1()
|
||||
|
||||
SpawnTest:SpawnInZone( TestZone, true )
|
||||
|
||||
-- The second after 10 seconds
|
||||
SCHEDULER:New( nil, MessageTest2, {}, 5 )
|
||||
|
||||
-- The third after 15 seconds
|
||||
SCHEDULER:New( nil, MessageTest2, {}, 10 )
|
||||
|
||||
end
|
||||
|
||||
-- The first after 5 seconds
|
||||
SCHEDULER:New( nil, MessageTest1, {}, 5 )
|
||||
|
||||
-- The fourth after 20 seconds
|
||||
SCHEDULER:New( nil, MessageTest1, {}, 20 )
|
||||
@@ -0,0 +1,56 @@
|
||||
--- No Object Scheduling because of garbage collect and Object nillification.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- Author: FlightControl
|
||||
-- Date Created: 12 Dec 2016
|
||||
--
|
||||
-- # Situation
|
||||
-- Uses the Tracing functions from BASE within the DCS.log file. Check the DCS.log file for the results.
|
||||
-- Create a new SCHEDULER object.
|
||||
-- Check the DCS.log.
|
||||
--
|
||||
-- A Test object is created.
|
||||
-- It is nillified directly after the Schedule has been planned.
|
||||
-- There should be no schedule fired.
|
||||
-- The Test object should be garbage collected!
|
||||
--
|
||||
-- THIS IS A VERY IMPORTANT TEST!
|
||||
--
|
||||
-- # Test cases:
|
||||
--
|
||||
-- 1. No schedule should be fired! The destructors of the Test object should be shown.
|
||||
-- 2. Commend the nillification of the Test object in the source, and test again.
|
||||
-- The schedule should now be fired and Hello World should be logged through the Test object.
|
||||
--
|
||||
-- # Status: STARTED - 12 Dec 2016
|
||||
|
||||
local TEST_BASE = {
|
||||
ClassName = "TEST_BASE",
|
||||
}
|
||||
|
||||
function TEST_BASE:New( Message )
|
||||
self = BASE:Inherit( self, BASE:New() )
|
||||
|
||||
self.TestScheduler = SCHEDULER:New( self,
|
||||
function( Object, Message )
|
||||
Object:E( Message )
|
||||
end, { Message }, 1
|
||||
)
|
||||
return self
|
||||
end
|
||||
|
||||
do
|
||||
local Test1 = TEST_BASE:New( "Hello World Test 1" )
|
||||
end
|
||||
|
||||
local Test2 = TEST_BASE:New( "Hello World Test 2" )
|
||||
Test2 = nil
|
||||
|
||||
local Test3 = TEST_BASE:New( "Hello World Test 3" )
|
||||
|
||||
collectgarbage()
|
||||
|
||||
BASE:E( "Collect Garbage executed." )
|
||||
BASE:E( "You should only now see Test 3!" )
|
||||
BASE:E( "Check if Test 1 and Test 2 are garbage collected!" )
|
||||
Binary file not shown.
@@ -1,16 +0,0 @@
|
||||
-- This test will schedule the same function 2 times.
|
||||
|
||||
SpawnTest = SPAWN:New( "Test" )
|
||||
TestZone = ZONE:New( "TestZone" )
|
||||
|
||||
local function MessageTest()
|
||||
|
||||
SpawnTest:SpawnInZone( TestZone, true )
|
||||
|
||||
end
|
||||
|
||||
-- The first after 5 seconds
|
||||
TestScheduler1 = SCHEDULER:New( nil, MessageTest, {}, 5 )
|
||||
|
||||
-- The second after 10 seconds
|
||||
TestScheduler2 = SCHEDULER:New( nil, MessageTest, {}, 10 )
|
||||
@@ -31,6 +31,7 @@ Mission:AddScoring( Scoring )
|
||||
|
||||
-- Define the set of group of planes that can be assigned to the Mission object.
|
||||
local SEADSet = SET_GROUP:New():FilterPrefixes( "Test SEAD"):FilterStart()
|
||||
SEADSet:Flush()
|
||||
|
||||
-- Define the set of units that are the targets.
|
||||
-- Note that I use FilterOnce, which means that the set will be defined only once,
|
||||
@@ -132,9 +133,11 @@ function FsmSEADTemplate:onenterUpdated( TaskUnit )
|
||||
end
|
||||
|
||||
|
||||
--local TaskSEAD2 = TASK_BASE:New( Mission, SEADSet, "SEAD Radars Vector 2", "SEAD" ) -- Tasking.Task#TASK_BASE
|
||||
--TaskSEAD2:SetFsmTemplate( TaskSEAD:GetFsmTemplate():Copy() )
|
||||
--Mission:AddTask( TaskSEAD2 )
|
||||
local TaskSEAD2 = TASK_BASE:New( Mission, SEADSet, "SEAD Radars Vector 2", "SEAD" ) -- Tasking.Task#TASK_BASE
|
||||
TaskSEAD2:SetFsmTemplate( TaskSEAD:GetFsmTemplate():Copy() )
|
||||
Mission:AddTask( TaskSEAD2 )
|
||||
|
||||
Mission:RemoveTask(TaskSEAD)
|
||||
|
||||
TaskSEAD = nil
|
||||
FsmSEADTemplate = nil
|
||||
|
||||
Reference in New Issue
Block a user