Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ResourceSystem.c
Go to the documentation of this file.
2{
3 override static void InitInfo(WorldSystemInfo outInfo)
4 {
5 outInfo
6 .SetAbstract(false)
7 .SetUnique(true);
8 }
9
10 static const int SUBSCRIBED_INTERACTORS_MAX_FRAME_BUDGET = 10;
11 static const int CONTAINERS_MAX_FRAME_BUDGET = 10;
12
14 protected int m_iContainersPivot;
15
16 protected ref array<SCR_ResourceInteractor> m_aSubscribedInteractors = {};
17 protected ref array<SCR_ResourceContainer> m_aContainers = {};
20
21 //------------------------------------------------------------------------------------------------
22 bool IsRegistered(notnull SCR_ResourceContainer container)
23 {
24 return m_aContainers.Contains(container);
25 }
26
27 //------------------------------------------------------------------------------------------------
28 override protected void OnUpdatePoint(WorldUpdatePointArgs args)
29 {
30 if (args.GetPoint() != ESystemPoint.FixedFrame)
31 return;
32
33 // 1. Cleanup and setup.
34 m_aContainers.RemoveItem(null);
35 m_aSubscribedInteractors.RemoveItem(null);
36 m_ResourceSystemSubscriptionManager.ProcessGracefulHandles();
37 m_ResourceGrid.ProcessFlaggedItems();
38 m_ResourceGrid.ResetFrameBudget();
39
40 // 2. Update.
41 m_ResourceGrid.Update();
42
43 for (int i = 0; i < SCR_ResourceSystem.CONTAINERS_MAX_FRAME_BUDGET && !m_aContainers.IsEmpty(); ++i)
44 {
45 m_aContainers[m_iContainersPivot++ % m_aContainers.Count()].Update(GetWorld().GetTimestamp());
46 }
47
48
49 for (int i = 0; i < SCR_ResourceSystem.SUBSCRIBED_INTERACTORS_MAX_FRAME_BUDGET && !m_aSubscribedInteractors.IsEmpty(); ++i)
50 {
52
53 if (m_ResourceGrid.GetFrameBudget() <= 0)
54 break;
55 }
56
57 // 3. Replicate.
58 m_ResourceSystemSubscriptionManager.ReplicateListeners();
59 }
60
61 //------------------------------------------------------------------------------------------------
62 override protected void OnDiag(float timeSlice)
63 {
64 DbgUI.Begin(ClassName());
65 DbgUI.Text("Containers: " + m_aContainers.Count());
66 DbgUI.Text("Subscribed interactors: " + m_aSubscribedInteractors.Count());
67
68 if (DbgUI.Button("Dump active components"))
69 {
70 foreach (SCR_ResourceContainer container : m_aContainers)
71 {
72 Print(container.GetOwner(), LogLevel.ERROR);
73 }
74
75 foreach (SCR_ResourceInteractor interactor : m_aSubscribedInteractors)
76 {
77 Print(interactor.GetOwner(), LogLevel.ERROR);
78 }
79 }
80
81 DbgUI.End();
82 }
83
84 //------------------------------------------------------------------------------------------------
86 {
87 const RplComponent rplComponent = container.GetComponent().GetReplicationComponent();
88
89 if (rplComponent.Role() != RplRole.Authority || m_aContainers.Contains(container))
90 return;
91
92 container.SetLastUpdateTimestamp(GetWorld().GetTimestamp());
93 m_aContainers.Insert(container);
94 }
95
96 //------------------------------------------------------------------------------------------------
97 void RegisterSubscribedInteractor(notnull SCR_ResourceInteractor interactor)
98 {
99 if (!m_aSubscribedInteractors.Contains(interactor))
100 m_aSubscribedInteractors.Insert(interactor);
101 }
102
103 //------------------------------------------------------------------------------------------------
105 {
106 m_aContainers.RemoveItem(container);
107 }
108
109 //------------------------------------------------------------------------------------------------
110 void UnregisterSubscribedInteractor(notnull SCR_ResourceInteractor interactor)
111 {
112 m_aSubscribedInteractors.RemoveItem(interactor);
113 }
114
115 //------------------------------------------------------------------------------------------------
116 override event protected void OnStarted()
117 {
118 m_ResourceGrid = GetGame().GetResourceGrid();
119 m_ResourceSystemSubscriptionManager = GetGame().GetResourceSystemSubscriptionManager();
120
121 }
122}
ArmaReforgerScripted GetGame()
Definition game.c:1398
proto native owned external string ClassName()
Definition DbgUI.c:66
ref array< SCR_ResourceContainer > m_aContainers
void OnUpdatePoint(WorldUpdatePointArgs args)
void UnregisterContainer(notnull SCR_ResourceContainer container)
void UnregisterSubscribedInteractor(notnull SCR_ResourceInteractor interactor)
ref array< SCR_ResourceInteractor > m_aSubscribedInteractors
void RegisterContainer(notnull SCR_ResourceContainer container)
void RegisterSubscribedInteractor(notnull SCR_ResourceInteractor interactor)
ref SCR_ResourceGrid m_ResourceGrid
void OnDiag(float timeSlice)
SCR_ResourceSystemSubscriptionManager m_ResourceSystemSubscriptionManager
bool IsRegistered(notnull SCR_ResourceContainer container)
Structure holding world system meta-information required by the engine.
Structure holding extra data of WorldSystem update point.
WorldSystemPoint ESystemPoint
Definition gameLib.c:7
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
RplRole
Role of replicated node (and all items in it) within the replication system.
Definition RplRole.c:14