Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AnimatedBeltSystem.c
Go to the documentation of this file.
1/*
2System to move any ammobelt UV's that are currently being fired
3*/
4
6{
7 override static void InitInfo(WorldSystemInfo outInfo)
8 {
9 outInfo
10 .SetAbstract(false)
11 .AddPoint(ESystemPoint.Frame);
12 }
13
14 protected ref array<SCR_AnimatedBeltComponent> m_aComponents = {};
15 protected ref array<SCR_AnimatedBeltComponent> m_aComponentsToAdd = {};
16 protected ref array<SCR_AnimatedBeltComponent> m_aComponentsToDel = {};
17 private bool m_bSimulationRunning;
18
19 //------------------------------------------------------------------------------------------------
20 protected override void OnInit()
21 {
22 Enable(false);
23 }
24
25 //------------------------------------------------------------------------------------------------
27 {
28 float timeSlice = args.GetTimeSliceSeconds();
29 bool nullValuePresent;
30
31 m_bSimulationRunning = true;
32 foreach (SCR_AnimatedBeltComponent comp : m_aComponents)
33 {
34 if (!comp)
35 {
36 nullValuePresent = true;
37 continue;
38 }
39
40 comp.Update(timeSlice);
41 }
42 m_bSimulationRunning = false;
43
44 // Remove any null referenes
45 if (nullValuePresent)
46 {
47 for (int i = m_aComponents.Count() - 1; i >= 0; i--)
48 {
49 if (!m_aComponents[i])
50 m_aComponents.Remove(i);
51 }
52 }
53
54 // Simulation stopped running, time to update m_aComponents if necessary
55 foreach (SCR_AnimatedBeltComponent comp : m_aComponentsToAdd)
56 {
57 if (comp)
58 RegisterInternal(comp);
59 }
60 foreach (SCR_AnimatedBeltComponent comp : m_aComponentsToDel)
61 {
62 if (comp)
63 UnregisterInternal(comp);
64 }
65 m_aComponentsToAdd.Clear();
66 m_aComponentsToDel.Clear();
67 }
68
69 //------------------------------------------------------------------------------------------------
70 private void RegisterInternal(notnull SCR_AnimatedBeltComponent component)
71 {
72 int index = component.GetBeltSystemIdx();
73 if (index >= 0)
74 return;
75
76 index = m_aComponents.Insert(component);
77 component.SetBeltSystemIdx(index);
78
79 if (!IsEnabled())
80 Enable(true);
81 }
82
83 //------------------------------------------------------------------------------------------------
84 void Register(notnull SCR_AnimatedBeltComponent component)
85 {
86 if (m_bSimulationRunning)
87 {
88 m_aComponentsToAdd.Insert(component);
89 return;
90 }
91
92 RegisterInternal(component);
93 }
94
95 //------------------------------------------------------------------------------------------------
96 private void UnregisterInternal(notnull SCR_AnimatedBeltComponent component)
97 {
98 int index = component.GetBeltSystemIdx();
99 if (index < 0)
100 return;
101
102 // Assign the last item in the array out current system index if possible
103 if (!m_aComponents.IsEmpty() && m_aComponents[m_aComponents.Count()-1] != component)
104 m_aComponents[m_aComponents.Count()-1].SetBeltSystemIdx(index);
105 // Swap indices with the last item in the array
106 m_aComponents.Remove(index);
107 // Invalidate current component's index
108 component.SetBeltSystemIdx(-1);
109
110 if (m_aComponents.IsEmpty())
111 Enable(false);
112 }
113
114 //------------------------------------------------------------------------------------------------
115 void Unregister(notnull SCR_AnimatedBeltComponent component)
116 {
117 if (m_bSimulationRunning)
118 {
119 m_aComponentsToDel.Insert(component);
120 return;
121 }
122
123 UnregisterInternal(component);
124 }
125}
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
void Enable(bool enable)
ref array< SCR_AnimatedBeltComponent > m_aComponentsToAdd
ref array< SCR_AnimatedBeltComponent > m_aComponents
ref array< SCR_AnimatedBeltComponent > m_aComponentsToDel
override void OnUpdatePoint(WorldUpdatePointArgs args)
Structure holding world system meta-information required by the engine.
Structure holding extra data of WorldSystem update point.
WorldSystemPoint ESystemPoint
Definition gameLib.c:7
int IsEnabled()
Returns true if the light is enabled.