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;
7 protected ref array<SCR_ResourceInteractor> m_aSubscribedInteractors = {};
8 protected ref array<SCR_ResourceComponent> m_aDynamicComponents = {};
9 protected ref array<SCR_ResourceContainer> m_aContainers = {};
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;
17 bool IsRegistered(notnull SCR_ResourceComponent component)
19 return m_aDynamicComponents.Contains(component);
25 return m_aContainers.Contains(container);
29 override protected void OnUpdate(ESystemPoint point)
31 float timeSlice = GetWorld().GetFixedTimeSlice();
43 container.Update(timeSlice);
49 m_aContainers.RemoveItem(container);
53 bool wasGridUpdateIdIncreased;
55 foreach (SCR_ResourceComponent component : m_DynamicComponentsBudgetManager.ProcessNextBatch())
61 if (!component && m_aDynamicComponents.RemoveItem(component))
64 if (vector.DistanceSq(component.GetOwner().GetOrigin(), component.GetLastPosition()) <= SCR_ResourceComponent.UPDATE_DISTANCE_TRESHOLD_SQUARE)
67 if (!wasGridUpdateIdIncreased)
71 wasGridUpdateIdIncreased =
true;
75 component.UpdateLastPosition();
81 foreach (SCR_ResourceInteractor interactor : m_SubscribedInteractorsBudgetManager.ProcessNextBatch())
87 if (!interactor && m_aSubscribedInteractors.RemoveItem(interactor))
101 override protected void OnDiag(
float timeSlice)
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());
108 if (DbgUI.Button(
"Dump active components"))
112 Print(container.GetOwner(), LogLevel.ERROR);
115 foreach (SCR_ResourceComponent component : m_aDynamicComponents)
117 Print(component.GetOwner(), LogLevel.ERROR);
120 foreach (SCR_ResourceInteractor interactor : m_aSubscribedInteractors)
122 Print(interactor.GetOwner(), LogLevel.ERROR);
130 void RegisterDynamicComponent(notnull SCR_ResourceComponent component)
132 if (!m_aDynamicComponents.Contains(component))
133 m_aDynamicComponents.Insert(component);
139 if (!m_aContainers.Contains(container))
140 m_aContainers.Insert(container);
144 void RegisterSubscribedInteractor(notnull SCR_ResourceInteractor interactor)
146 if (!m_aSubscribedInteractors.Contains(interactor))
147 m_aSubscribedInteractors.Insert(interactor);
151 void UnregisterDynamicComponent(notnull SCR_ResourceComponent component)
153 m_aDynamicComponents.RemoveItem(component);
159 m_aContainers.RemoveItem(container);
163 void UnregisterSubscribedInteractor(notnull SCR_ResourceInteractor interactor)
165 m_aSubscribedInteractors.RemoveItem(interactor);
169 override event protected void OnStarted()
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);