1- Scriptname HTG :ActivatorExt extends Activator
2- import HTG
3- import HTG :Structs
4- import HTG :SystemLogger
1+ ScriptName HTG :ActivatorExt Extends Activator
52
6- SystemUtilities Property SystemUtilities Auto Const Mandatory
3+ ;-- Variables ---------------------------------------
4+ Int _currentTimerCycle = 0
5+ Bool _initializeTimerStarted
6+ Bool _isInitialRun
7+ Bool _isInitialized
8+ Bool _mainTimerStarted
9+ Int _maxTimerCycle = 50
10+ Bool _readyTimerStarted
11+ htg :structs :systemtimerids _timerIds
12+ Float _timerInterval = 0.01
713
8- HTG :SystemLogger Property Logger Hidden
9- HTG :SystemLogger Function Get ()
10- return SystemUtilities . Logger
11- EndFunction
14+ ;-- Guards ------------------------------------------
15+ ;*** WARNING: Guard declaration syntax is EXPERIMENTAL, subject to change
16+ Guard _initializeTimerGuard
17+ Guard _mainTimerGuard
18+ Guard _readyTimerGuard
19+
20+ ;-- Properties --------------------------------------
21+ htg :systemutilities Property SystemUtilities Auto Const mandatory
22+ htg :systemlogger Property Logger hidden
23+ htg :systemlogger Function Get ()
24+ Return SystemUtilities . Logger ; #DEBUG_LINE_NO:10
25+ EndFunction
1226EndProperty
13-
14- Bool Property IsInitialized Hidden
15- Bool Function Get ()
16- return _isInitialized
17- EndFunction
27+ Bool Property IsInitialized hidden
28+ Bool Function Get ()
29+ Return _isInitialized ; #DEBUG_LINE_NO:16
30+ EndFunction
1831EndProperty
19-
20- Bool Property IsInitialRun Hidden
21- Bool Function Get ()
22- return _isInitialRun
23- EndFunction
32+ Bool Property IsInitialRun hidden
33+ Bool Function Get ()
34+ Return _isInitialRun ; #DEBUG_LINE_NO:22
35+ EndFunction
2436EndProperty
2537
26- Guard _initializeTimerGuard ProtectsFunctionLogic
27- Guard _readyTimerGuard ProtectsFunctionLogic
28- Guard _mainTimerGuard ProtectsFunctionLogic
29- SystemTimerIds _timerIds
30- Bool _isInitialized
31- Bool _isInitialRun
32- Bool _initializeTimerStarted
33- Bool _readyTimerStarted
34- Bool _mainTimerStarted
35- Float _timerInterval = 0.01
36- Int _maxTimerCycle = 50
37- Int _currentTimerCycle = 0
38-
39- CustomEvent OnInitialRun
40- CustomEvent OnMain
38+ ;-- Functions ---------------------------------------
4139
42- Event OnInit ()
43- RegisterForCustomEvent (Self , "OnInitialRun" )
44- RegisterForCustomEvent (Self , "OnMain" )
45- _isInitialRun = ! _isInitialized
46- _timerIds = new SystemTimerIds
47- StartTimer (_timerInterval , _timerIds . InitializeId )
40+ Event HTG:ActivatorExt.OnInitialRun (HTG :ActivatorExt akSender , Var [] akArgs )
41+ ; Empty function
4842EndEvent
4943
50- Event OnTimer (Int aiTimerID )
51- Int i = 0
52- Int count = 0
53-
54- If aiTimerID == _timerIds . InitializeId
55- If ! _isInitialRun || _initializeTimerStarted
56- LogObjectGlobal (Self , "InitializeTimer - Is Not Initial Run or Timer is already running. No need to proceed." )
57- return
58- EndIf
59-
60- Float itimerInterval = _timerInterval
61- Int timerId = - 1
62-
63- LockGuard _initializeTimerGuard
64- _initializeTimerStarted = True
65- If ! Initialize () && _currentTimerCycle < _maxTimerCycle
66- _currentTimerCycle += 1
67- timerId = _timerIds . InitializeId
68- ElseIf ! _isInitialized && _currentTimerCycle == _maxTimerCycle
69- LogErrorGlobal (Self , "HTG:SystemUtililities could not be Initialized" )
70- Else
71- Logger . Log ("InitializeTimer - Is Initialized. Starting ReadyTimer" )
72- timerId = SystemUtilities . Timers . SystemTimerIds . InitialRunId
73- EndIf
74- _initializeTimerStarted = False
75- EndLockGuard
76-
77- If timerid > - 1
78- StartTimer (itimerInterval , timerId )
79- EndIf
80- ElseIf aiTimerID == _timerIds . InitialRunId
81- If ! _isInitialRun || _readyTimerStarted
82- Logger . Log ("ReadyTimer - Is Not Initial Run or Timer is already running. No need to proceed." )
83- return
84- EndIf
85-
86- LockGuard _readyTimerGuard
87- _readyTimerStarted = True
88- SendCustomEvent ("OnInitialRun" )
89- _InitialRun ()
90- _isInitialRun = False
91- _readyTimerStarted = False
92- EndLockGuard
93-
94- Logger . Log ("ReadyTimer - Completed Initial Run." )
95- StartTimer (_timerInterval , _timerIds . MainId )
96- ElseIf aiTimerID == _timerIds . MainId
97- If _isInitialRun || _mainTimerStarted
98- Logger . Log ("MainTimer - Is Initial Run or Timer is already running. No need to proceed." )
99- return
100- EndIf
101-
102- Bool restartTimer
103- LockGuard _mainTimerGuard
104- _mainTimerStarted = True
105- SendCustomEvent ("OnMain" )
106- restartTimer = _Main ()
107- _mainTimerStarted = False
108- EndLockGuard
109-
110- If restartTimer
111- StartTimer (_timerInterval , _timerIds . MainId )
112- EndIf
113- EndIf
44+ Event HTG:ActivatorExt.OnMain (HTG :ActivatorExt akSender , Var [] akArgs )
45+ ; Empty function
11446EndEvent
11547
116- Event HTG:ActivatorExt.OnInitialRun (HTG :ActivatorExt akSender , Var [] akArgs )
117- EndEvent
48+ Function _InitialRun ()
49+ ; Empty function
50+ EndFunction
11851
119- Event HTG:ActivatorExt.OnMain (HTG :ActivatorExt akSender , Var [] akArgs )
52+ Event OnInit ()
53+ Self . RegisterForCustomEvent (Self as ScriptObject , "htg:activatorext_OnInitialRun" ) ; #DEBUG_LINE_NO:43
54+ Self . RegisterForCustomEvent (Self as ScriptObject , "htg:activatorext_OnMain" ) ; #DEBUG_LINE_NO:44
55+ _isInitialRun = ! _isInitialized ; #DEBUG_LINE_NO:45
56+ _timerIds = new htg :structs :systemtimerids ; #DEBUG_LINE_NO:46
57+ Self . StartTimer (_timerInterval , _timerIds . InitializeId ) ; #DEBUG_LINE_NO:47
12058EndEvent
12159
122- Bool Function Initialize ()
123- If ! _isInitialized
124- _isInitialized = _SetSystemUtilities ()
60+ Event OnTimer (Int aiTimerID )
61+ Int I = 0 ; #DEBUG_LINE_NO:51
62+ Int count = 0 ; #DEBUG_LINE_NO:52
63+ If aiTimerID == _timerIds . InitializeId ; #DEBUG_LINE_NO:54
64+ If ! _isInitialRun || _initializeTimerStarted ; #DEBUG_LINE_NO:55
65+ htg :systemlogger . LogObjectGlobal (Self as ScriptObject , "InitializeTimer - Is Not Initial Run or Timer is already running. No need to proceed." ) ; #DEBUG_LINE_NO:56
66+ Return ; #DEBUG_LINE_NO:57
67+ EndIf
68+ Float itimerInterval = _timerInterval ; #DEBUG_LINE_NO:60
69+ Int timerId = - 1 ; #DEBUG_LINE_NO:61
70+ Guard _initializeTimerGuard ;*** WARNING: Experimental syntax, may be incorrect: Guard ; #DEBUG_LINE_NO:63
71+ _initializeTimerStarted = True ; #DEBUG_LINE_NO:64
72+ If ! Self . Initialize () && _currentTimerCycle < _maxTimerCycle ; #DEBUG_LINE_NO:65
73+ _currentTimerCycle += 1 ; #DEBUG_LINE_NO:66
74+ timerId = _timerIds . InitializeId ; #DEBUG_LINE_NO:67
75+ ElseIf ! _isInitialized && _currentTimerCycle == _maxTimerCycle ; #DEBUG_LINE_NO:68
76+ htg :systemlogger . LogErrorGlobal (Self as ScriptObject , "HTG:SystemUtililities could not be Initialized" ) ; #DEBUG_LINE_NO:69
77+ Else
78+ Self . Logger . Log ("InitializeTimer - Is Initialized. Starting ReadyTimer" , 0 ) ; #DEBUG_LINE_NO:71
79+ timerId = SystemUtilities . Timers . SystemTimerIds . InitialRunId ; #DEBUG_LINE_NO:72
80+ EndIf
81+ _initializeTimerStarted = False ; #DEBUG_LINE_NO:74
82+ EndGuard ;*** WARNING: Experimental syntax, may be incorrect: EndGuard
83+ If timerId > - 1 ; #DEBUG_LINE_NO:77
84+ Self . StartTimer (itimerInterval , timerId ) ; #DEBUG_LINE_NO:78
85+ EndIf
86+ ElseIf aiTimerID == _timerIds . InitialRunId ; #DEBUG_LINE_NO:80
87+ If ! _isInitialRun || _readyTimerStarted ; #DEBUG_LINE_NO:81
88+ Self . Logger . Log ("ReadyTimer - Is Not Initial Run or Timer is already running. No need to proceed." , 0 ) ; #DEBUG_LINE_NO:82
89+ Return ; #DEBUG_LINE_NO:83
90+ EndIf
91+ Guard _readyTimerGuard ;*** WARNING: Experimental syntax, may be incorrect: Guard ; #DEBUG_LINE_NO:86
92+ _readyTimerStarted = True ; #DEBUG_LINE_NO:87
93+ Self . SendCustomEvent ("htg:activatorext_OnInitialRun" , None ) ; #DEBUG_LINE_NO:88
94+ Self . _InitialRun () ; #DEBUG_LINE_NO:89
95+ _isInitialRun = False ; #DEBUG_LINE_NO:90
96+ _readyTimerStarted = False ; #DEBUG_LINE_NO:91
97+ EndGuard ;*** WARNING: Experimental syntax, may be incorrect: EndGuard
98+ Self . Logger . Log ("ReadyTimer - Completed Initial Run." , 0 ) ; #DEBUG_LINE_NO:94
99+ Self . StartTimer (_timerInterval , _timerIds . MainId ) ; #DEBUG_LINE_NO:95
100+ ElseIf aiTimerID == _timerIds . MainId ; #DEBUG_LINE_NO:96
101+ If _isInitialRun || _mainTimerStarted ; #DEBUG_LINE_NO:97
102+ Self . Logger . Log ("MainTimer - Is Initial Run or Timer is already running. No need to proceed." , 0 ) ; #DEBUG_LINE_NO:98
103+ Return ; #DEBUG_LINE_NO:99
125104 EndIf
105+ Bool restartTimer = False ; #DEBUG_LINE_NO:102
106+ Guard _mainTimerGuard ;*** WARNING: Experimental syntax, may be incorrect: Guard ; #DEBUG_LINE_NO:103
107+ _mainTimerStarted = True ; #DEBUG_LINE_NO:104
108+ Self . SendCustomEvent ("htg:activatorext_OnMain" , None ) ; #DEBUG_LINE_NO:105
109+ restartTimer = Self . _Main () ; #DEBUG_LINE_NO:106
110+ _mainTimerStarted = False ; #DEBUG_LINE_NO:107
111+ EndGuard ;*** WARNING: Experimental syntax, may be incorrect: EndGuard
112+ If restartTimer ; #DEBUG_LINE_NO:110
113+ Self . StartTimer (_timerInterval , _timerIds . MainId ) ; #DEBUG_LINE_NO:111
114+ EndIf
115+ EndIf
116+ EndEvent
126117
127- return _isInitialized
118+ Bool Function Initialize ()
119+ If ! _isInitialized ; #DEBUG_LINE_NO:123
120+ _isInitialized = Self . _SetSystemUtilities () ; #DEBUG_LINE_NO:124
121+ EndIf
122+ Return _isInitialized ; #DEBUG_LINE_NO:127
128123EndFunction
129124
130125Function WaitForInitialized ()
131- If _isInitialized
132- return
126+ If _isInitialized ; #DEBUG_LINE_NO:131
127+ Return ; #DEBUG_LINE_NO:132
128+ EndIf
129+ Int currentCycle = 0 ; #DEBUG_LINE_NO:135
130+ Int maxCycle = 600 ; #DEBUG_LINE_NO:136
131+ Bool maxCycleHit = False ; #DEBUG_LINE_NO:137
132+ While ! maxCycleHit && ! _isInitialized ; #DEBUG_LINE_NO:140
133+ Utility . Wait (0.100000001 ) ; #DEBUG_LINE_NO:141
134+ If currentCycle < maxCycle ; #DEBUG_LINE_NO:143
135+ currentCycle += 1 ; #DEBUG_LINE_NO:144
136+ Else
137+ maxCycleHit = True ; #DEBUG_LINE_NO:146
133138 EndIf
134-
135- Int currentCycle = 0
136- Int maxCycle = 600
137- Bool maxCycleHit
138-
139- ; StartTimer(_timerInterval, _initializeTimerId)
140- While ! maxCycleHit && ! _isInitialized
141- Utility . Wait (0.1 )
142-
143- If currentCycle < maxCycle
144- currentCycle += 1
145- Else
146- maxCycleHit = True
147- EndIf
148- EndWhile
139+ EndWhile
149140EndFunction
150141
151142Bool Function _SetSystemUtilities ()
152- SystemUtilities . WaitForInitialized ()
153- return True
154- EndFunction
155-
156- Function _InitialRun ()
143+ SystemUtilities . WaitForInitialized () ; #DEBUG_LINE_NO:152
144+ Return True ; #DEBUG_LINE_NO:153
157145EndFunction
158146
159147Bool Function _Main ()
160- return False
161- EndFunction
148+ Return False ; #DEBUG_LINE_NO:160
149+ EndFunction
0 commit comments