Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ResourceSystem.c
Go to the documentation of this file.
2 {
3  static const int DYNAMIC_COMPONENTS_MAX_FRAME_BUDGET = 10;
4  static const int SUBSCRIBED_INTERACTORS_MAX_FRAME_BUDGET = 10;
5  static const int CONTAINERS_MAX_FRAME_BUDGET = 10;
6 
7  protected ref array<SCR_ResourceInteractor> m_aSubscribedInteractors = {};
8  protected ref array<SCR_ResourceComponent> m_aDynamicComponents = {};
9  protected ref array<SCR_ResourceContainer> m_aContainers = {};
10  protected SCR_ResourceSystemSubscriptionManager m_ResourceSystemSubscriptionManager;
11  protected ref SCR_ResourceGrid m_ResourceGrid;
12  protected ref SCR_ContainerBudgetManager<array<SCR_ResourceInteractor>, SCR_ResourceInteractor> m_SubscribedInteractorsBudgetManager;
13  protected ref SCR_ContainerBudgetManager<array<SCR_ResourceComponent>, SCR_ResourceComponent> m_DynamicComponentsBudgetManager;
14  protected ref SCR_ContainerBudgetManager<array<SCR_ResourceContainer>, SCR_ResourceContainer> m_ContainersBudgetManager;
15 
16  //------------------------------------------------------------------------------------------------
17  bool IsRegistered(notnull SCR_ResourceComponent component)
18  {
19  return m_aDynamicComponents.Contains(component);
20  }
21 
22  //------------------------------------------------------------------------------------------------
23  bool IsRegistered(notnull SCR_ResourceContainer container)
24  {
25  return m_aContainers.Contains(container);
26  }
27 
28  //------------------------------------------------------------------------------------------------
29  override protected void OnUpdate(ESystemPoint point)
30  {
31  float timeSlice = GetWorld().GetFixedTimeSlice();
32 
34  m_ResourceGrid.ProcessFlaggedItems();
35 
37  m_ResourceSystemSubscriptionManager.ProcessGracefulHandles();
38 
40  foreach (SCR_ResourceContainer container : m_aContainers)
41  {
42  if (container)
43  container.Update(timeSlice);
44  else
49  m_aContainers.RemoveItem(container);
50  }
51 
53  bool wasGridUpdateIdIncreased;
54 
55  foreach (SCR_ResourceComponent component : m_DynamicComponentsBudgetManager.ProcessNextBatch())
56  {
61  if (!component && m_aDynamicComponents.RemoveItem(component))
62  continue;
63 
64  if (vector.DistanceSq(component.GetOwner().GetOrigin(), component.GetLastPosition()) <= SCR_ResourceComponent.UPDATE_DISTANCE_TRESHOLD_SQUARE)
65  continue;
66 
67  if (!wasGridUpdateIdIncreased)
68  {
69  m_ResourceGrid.IncreaseGridUpdateId();
70 
71  wasGridUpdateIdIncreased = true;
72  }
73 
74  m_ResourceGrid.UpdateResourceDynamicItem(component);
75  component.UpdateLastPosition();
76  }
77 
79  m_ResourceGrid.ResetFrameBudget();
80 
81  foreach (SCR_ResourceInteractor interactor : m_SubscribedInteractorsBudgetManager.ProcessNextBatch())
82  {
87  if (!interactor && m_aSubscribedInteractors.RemoveItem(interactor))
88  continue;
89 
90  m_ResourceGrid.UpdateInteractor(interactor, true);
91 
92  if (m_ResourceGrid.GetFrameBudget() <= 0)
93  break;
94  }
95 
97  m_ResourceSystemSubscriptionManager.ReplicateListeners();
98  }
99 
100  //------------------------------------------------------------------------------------------------
101  override protected void OnDiag(float timeSlice)
102  {
103  DbgUI.Begin("SCR_ResourceSystem");
104  DbgUI.Text("Containers: " + m_aContainers.Count());
105  DbgUI.Text("Dynamic components: " + m_aDynamicComponents.Count());
106  DbgUI.Text("Subscribed interactors: " + m_aSubscribedInteractors.Count());
107 
108  if (DbgUI.Button("Dump active components"))
109  {
110  foreach (SCR_ResourceContainer container : m_aContainers)
111  {
112  Print(container.GetOwner(), LogLevel.ERROR);
113  }
114 
115  foreach (SCR_ResourceComponent component : m_aDynamicComponents)
116  {
117  Print(component.GetOwner(), LogLevel.ERROR);
118  }
119 
120  foreach (SCR_ResourceInteractor interactor : m_aSubscribedInteractors)
121  {
122  Print(interactor.GetOwner(), LogLevel.ERROR);
123  }
124  }
125 
126  DbgUI.End();
127  }
128 
129  //------------------------------------------------------------------------------------------------
130  void RegisterDynamicComponent(notnull SCR_ResourceComponent component)
131  {
132  if (!m_aDynamicComponents.Contains(component))
133  m_aDynamicComponents.Insert(component);
134  }
135 
136  //------------------------------------------------------------------------------------------------
137  void RegisterContainer(notnull SCR_ResourceContainer container)
138  {
139  if (!m_aContainers.Contains(container))
140  m_aContainers.Insert(container);
141  }
142 
143  //------------------------------------------------------------------------------------------------
144  void RegisterSubscribedInteractor(notnull SCR_ResourceInteractor interactor)
145  {
146  if (!m_aSubscribedInteractors.Contains(interactor))
147  m_aSubscribedInteractors.Insert(interactor);
148  }
149 
150  //------------------------------------------------------------------------------------------------
151  void UnregisterDynamicComponent(notnull SCR_ResourceComponent component)
152  {
153  m_aDynamicComponents.RemoveItem(component);
154  }
155 
156  //------------------------------------------------------------------------------------------------
157  void UnregisterContainer(notnull SCR_ResourceContainer container)
158  {
159  m_aContainers.RemoveItem(container);
160  }
161 
162  //------------------------------------------------------------------------------------------------
163  void UnregisterSubscribedInteractor(notnull SCR_ResourceInteractor interactor)
164  {
165  m_aSubscribedInteractors.RemoveItem(interactor);
166  }
167 
168  //------------------------------------------------------------------------------------------------
169  override event protected void OnStarted()
170  {
171  m_ResourceGrid = GetGame().GetResourceGrid();
172  m_ResourceSystemSubscriptionManager = GetGame().GetResourceSystemSubscriptionManager();
173 
174  m_SubscribedInteractorsBudgetManager = new SCR_ContainerBudgetManager<array<SCR_ResourceInteractor>, SCR_ResourceInteractor>(m_aSubscribedInteractors, SUBSCRIBED_INTERACTORS_MAX_FRAME_BUDGET);
175  m_DynamicComponentsBudgetManager = new SCR_ContainerBudgetManager<array<SCR_ResourceComponent>, SCR_ResourceComponent>(m_aDynamicComponents, DYNAMIC_COMPONENTS_MAX_FRAME_BUDGET);
176  m_ContainersBudgetManager = new SCR_ContainerBudgetManager<array<SCR_ResourceContainer>, SCR_ResourceContainer>(m_aContainers, CONTAINERS_MAX_FRAME_BUDGET);
177 
178  }
179 }
SCR_ResourceGrid
void SCR_ResourceGrid()
Definition: SCR_ResourceGrid.c:785
m_ResourceGrid
protected ref SCR_ResourceGrid m_ResourceGrid
Definition: game.c:78
m_ResourceSystemSubscriptionManager
protected ref SCR_ResourceSystemSubscriptionManager m_ResourceSystemSubscriptionManager
Definition: game.c:79
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ResourceSystemSubscriptionManager
Definition: SCR_ResourceSystemSubscriptionManager.c:1
GameSystem
Definition: GameSystem.c:12
SCR_ResourceSystem
Definition: SCR_ResourceSystem.c:1
SCR_ResourceContainer
Definition: SCR_ResourceContainer.c:34