Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_ResourceGrid.c
Go to the documentation of this file.
1
class
SCR_ResourceGrid
: AABGridMap
2
{
3
static
const
int
MAX_FRAME_BUDGET = 20;
4
5
protected
ref array<SCR_ResourceComponent>
m_aFlaggedItems
= {};
6
protected
ref set<SCR_ResourceContainer>
m_aQueriedContainers
=
new
set<SCR_ResourceContainer>();
7
protected
int
m_iGridUpdateId
=
int
.MIN;
8
protected
int
m_iFrameBudget
;
9
10
//------------------------------------------------------------------------------------------------
12
int
GetGridUpdateId
()
13
{
14
return
m_iGridUpdateId
;
15
}
16
17
//------------------------------------------------------------------------------------------------
20
int
GetFrameBudget
()
21
{
22
return
m_iFrameBudget
;
23
}
24
25
//------------------------------------------------------------------------------------------------
26
void
ResetFrameBudget
()
27
{
28
m_iFrameBudget
=
SCR_ResourceGrid
.MAX_FRAME_BUDGET;
29
}
30
31
//------------------------------------------------------------------------------------------------
35
int
IncreaseGridUpdateId
()
36
{
37
if
(++
m_iGridUpdateId
==
int
.
MAX
)
38
Debug
.Error2(
ClassName
(),
"Maximum grid update id has been reached."
);
39
40
return
m_iGridUpdateId
;
41
}
42
43
//------------------------------------------------------------------------------------------------
47
void
FlagResourceItem
(notnull SCR_ResourceComponent item)
48
{
49
m_aFlaggedItems
.Insert(item);
50
}
51
52
//------------------------------------------------------------------------------------------------
56
void
UnflagResourceItem
(notnull SCR_ResourceComponent item)
57
{
58
m_aFlaggedItems
.RemoveItem(item);
59
}
60
61
//------------------------------------------------------------------------------------------------
63
void
ProcessFlaggedItems
()
64
{
65
if
(
m_aFlaggedItems
.IsEmpty())
66
return
;
67
68
IncreaseGridUpdateId
();
69
70
// Clear out null flagged items.
71
m_aFlaggedItems
.RemoveItem(null);
72
73
foreach
(SCR_ResourceComponent item:
m_aFlaggedItems
)
74
{
75
ProcessResourceItem
(item);
76
}
77
78
m_aFlaggedItems
.Clear();
79
}
80
81
//------------------------------------------------------------------------------------------------
85
void
UpdateResourceItem
(notnull SCR_ResourceComponent item)
86
{
87
const
IEntity
owner = item.GetOwner();
88
89
if
(!owner)
90
return
;
91
92
vector
boundsMins, boundsMaxs;
93
94
item.SetGridUpdateId(
m_iGridUpdateId
);
95
item.GetGridContainersBoundingBox(boundsMins, boundsMaxs);
96
UpdatePosition
(owner, owner.
GetOrigin
());
97
UpdateAABB(owner, boundsMins, boundsMaxs);
98
}
99
100
//------------------------------------------------------------------------------------------------
104
protected
bool
ProcessResourceItem
(notnull SCR_ResourceComponent item)
105
{
106
const
IEntity
owner = item.GetOwner();
107
108
if
(!owner)
109
return
false
;
110
111
vector
boundsMins, boundsMaxs;
112
const
Physics
phys = owner.
GetPhysics
();
113
114
item.GetGridContainersBoundingBox(boundsMins, boundsMaxs);
115
116
if
(phys)
117
Insert(owner, boundsMins, boundsMaxs, phys.IsDynamic());
118
else
119
Insert(owner, boundsMins, boundsMaxs,
false
);
120
121
item.SetGridUpdateId(
m_iGridUpdateId
);
122
123
return
true
;
124
}
125
126
//------------------------------------------------------------------------------------------------
130
void
UnregisterResourceItem
(notnull SCR_ResourceComponent item)
131
{
132
item.SetGridUpdateId(
int
.MIN);
133
134
const
IEntity
owner = item.GetOwner();
135
136
if
(!owner)
137
return
;
138
139
Remove(owner);
140
}
141
142
//------------------------------------------------------------------------------------------------
150
void
UpdateInteractor
(notnull SCR_ResourceInteractor interactor,
bool
useFrameBudget =
false
)
151
{
152
// This check is to prevent nested calls of UpdateInteractor function
153
if
(!
m_aQueriedContainers
.IsEmpty())
154
return
;
155
156
const
vector
interactorOrigin = interactor.GetOwnerOrigin();
157
158
if
(
vector
.DistanceSq(interactorOrigin, interactor.GetLastPosition()) <= SCR_ResourceComponent.UPDATE_DISTANCE_TRESHOLD_SQUARE
159
&& interactor.GetGridUpdateId() ==
m_iGridUpdateId
160
|| interactor.IsIsolated())
161
return
;
162
163
array<IEntity> foundEntities = {};
164
const
float
resourceGridRange = interactor.GetResourceGridRange();
165
SCR_ResourceContainer
resourceContainer;
166
const
SCR_ResourceContainerQueueBase
containerQueue = interactor.GetContainerQueue();
167
168
FindEntitiesInRange(foundEntities, interactorOrigin, resourceGridRange);
169
containerQueue.
CopyContainers
(
m_aQueriedContainers
);
170
171
foreach
(
IEntity
entity : foundEntities)
172
{
173
m_aQueriedContainers
.Insert(SCR_ResourceComponent.Cast(entity.FindComponent(SCR_ResourceComponent)).GetContainer(interactor.GetResourceType()));
174
}
175
176
m_aQueriedContainers
.RemoveItem(null);
177
178
const
int
containerCount =
m_aQueriedContainers
.Count();
179
180
if
(useFrameBudget)
181
m_iFrameBudget
-= containerCount;
182
183
for
(
int
idx
= containerCount - 1;
idx
>= 0; --
idx
)
184
{
185
resourceContainer =
m_aQueriedContainers
[
idx
];
186
187
if
(resourceContainer.
IsIsolated
())
188
continue
;
189
190
if
(interactor.CanInteractWith(resourceContainer) && resourceContainer.
IsInRange
(interactorOrigin, resourceGridRange))
191
{
192
if
(!resourceContainer.
IsInteractorLinked
(interactor))
193
interactor.RegisterContainerForced(resourceContainer);
194
}
195
else
196
interactor.UnregisterContainer(resourceContainer);
197
}
198
199
interactor.OnResourceGridUpdated(
this
);
200
m_aQueriedContainers
.Clear();
201
}
202
}
idx
int idx
Definition
AIControlComponentSerializer.c:13
UpdatePosition
void UpdatePosition()
Update light position.
Definition
SCR_MapLightUI.c:149
ClassName
proto native owned external string ClassName()
Debug
Definition
Debug.c:13
IEntity
Definition
IEntity.c:13
IEntity::GetOrigin
proto external vector GetOrigin()
IEntity::GetPhysics
proto external Physics GetPhysics()
Physics
Definition
Physics.c:22
SCR_ResourceContainer
Definition
SCR_ResourceContainer.c:35
SCR_ResourceContainer::IsInRange
bool IsInRange(vector origin, float range)
Definition
SCR_ResourceContainer.c:275
SCR_ResourceContainer::IsIsolated
override bool IsIsolated()
Definition
SCR_ResourceContainer.c:269
SCR_ResourceContainer::IsInteractorLinked
bool IsInteractorLinked(notnull SCR_ResourceInteractor interactor)
Definition
SCR_ResourceContainer.c:223
SCR_ResourceContainerQueueBase
Definition
SCR_ResourceContainerQueue.c:3
SCR_ResourceContainerQueueBase::CopyContainers
void CopyContainers(inout notnull set< SCR_ResourceContainer > containers)
Definition
SCR_ResourceContainerQueue.c:105
SCR_ResourceGrid
Definition
SCR_ResourceGrid.c:2
SCR_ResourceGrid::m_iFrameBudget
int m_iFrameBudget
Definition
SCR_ResourceGrid.c:8
SCR_ResourceGrid::UnflagResourceItem
void UnflagResourceItem(notnull SCR_ResourceComponent item)
Definition
SCR_ResourceGrid.c:56
SCR_ResourceGrid::m_aFlaggedItems
ref array< SCR_ResourceComponent > m_aFlaggedItems
Definition
SCR_ResourceGrid.c:5
SCR_ResourceGrid::UpdateInteractor
void UpdateInteractor(notnull SCR_ResourceInteractor interactor, bool useFrameBudget=false)
Definition
SCR_ResourceGrid.c:150
SCR_ResourceGrid::UpdateResourceItem
void UpdateResourceItem(notnull SCR_ResourceComponent item)
Definition
SCR_ResourceGrid.c:85
SCR_ResourceGrid::FlagResourceItem
void FlagResourceItem(notnull SCR_ResourceComponent item)
Definition
SCR_ResourceGrid.c:47
SCR_ResourceGrid::m_aQueriedContainers
ref set< SCR_ResourceContainer > m_aQueriedContainers
Definition
SCR_ResourceGrid.c:6
SCR_ResourceGrid::IncreaseGridUpdateId
int IncreaseGridUpdateId()
Definition
SCR_ResourceGrid.c:35
SCR_ResourceGrid::ResetFrameBudget
void ResetFrameBudget()
Definition
SCR_ResourceGrid.c:26
SCR_ResourceGrid::ProcessFlaggedItems
void ProcessFlaggedItems()
Registers all resource components that are flagged into the grid.
Definition
SCR_ResourceGrid.c:63
SCR_ResourceGrid::GetGridUpdateId
int GetGridUpdateId()
Definition
SCR_ResourceGrid.c:12
SCR_ResourceGrid::m_iGridUpdateId
int m_iGridUpdateId
Definition
SCR_ResourceGrid.c:7
SCR_ResourceGrid::ProcessResourceItem
bool ProcessResourceItem(notnull SCR_ResourceComponent item)
Definition
SCR_ResourceGrid.c:104
SCR_ResourceGrid::GetFrameBudget
int GetFrameBudget()
Definition
SCR_ResourceGrid.c:20
SCR_ResourceGrid::UnregisterResourceItem
void UnregisterResourceItem(notnull SCR_ResourceComponent item)
Definition
SCR_ResourceGrid.c:130
vector
Definition
vector.c:13
MAX
@ MAX
Definition
ETurretContextID.c:19
scripts
Game
Sandbox
Resources
SCR_ResourceGrid.c
Generated by
1.17.0