Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_RegionalDestructionManager.c
Go to the documentation of this file.
4
5class SCR_RegionalDestructionManager : RegionalDestructionManager
6{
7 ref array<ref SCR_DestructionInteriorBoundingBox> m_aInteriorBoxes = {};
8
9 //------------------------------------------------------------------------------------------------
10 override bool OnSave(notnull ScriptBitWriter writer)
11 {
12 writer.WriteInt(m_aInteriorBoxes.Count());
14 {
15 if (!boundingBox)
16 {
17 writer.WriteBool(false);
18 continue;
19 }
20 writer.WriteBool(true);
21 boundingBox.OnSave(writer);
22 }
23
24 return true;
25 }
26
27 //------------------------------------------------------------------------------------------------
28 override bool OnLoad(notnull ScriptBitReader reader)
29 {
30 m_aInteriorBoxes.Clear();
31
32 int count;
33 reader.ReadInt(count);
34
35 ref array<ref vector> boxesPositions = {};
36 SCR_DestructionManager manager = SCR_DestructionManager.GetDestructionManagerInstance();
37
38 if (manager)
39 {
40 bool exists = manager.m_RegionalManagerHandledBoxes.Find(GetRplID(), boxesPositions);
41 if (!exists)
42 {
43 boxesPositions = new array<ref vector>;
44 manager.m_RegionalManagerHandledBoxes.Insert(GetRplID(), boxesPositions);
45 }
46 }
47
48 for (int i = 0; i < count; i++)
49 {
50 bool hasBB;
51 reader.ReadBool(hasBB);
52 if (!hasBB)
53 continue;
54
56 boundingBox.OnLoad(reader);
57
58 //check if box was handled already
59 if (boxesPositions && boxesPositions.Contains(boundingBox.m_vMatrix[3] + boundingBox.m_center))
60 continue;
61
62 m_aInteriorBoxes.Insert(boundingBox);
63 boxesPositions.Insert(boundingBox.m_vMatrix[3] + boundingBox.m_center);
64 }
65
67
68 return true;
69 }
70
71 //------------------------------------------------------------------------------------------------
74 {
76 {
77 QueryEntities(boundingBox.m_vMin, boundingBox.m_vMax, boundingBox.m_vMatrix);
78 }
79
80 SCR_BuildingInteriorDeletinator.QueueDeletionsThisFrame();
81 }
82
83 //------------------------------------------------------------------------------------------------
85 {
87 boundingBox.m_vMatrix = m_vStartMatrix;
88
89 boundingBox.SetBounds(mins, maxs);
90 boundingBox.m_center = center;
91 m_aInteriorBoxes.Insert(boundingBox);
92 }
93
94 //------------------------------------------------------------------------------------------------
95 void QueryEntities(vector min, vector max, vector m_vMatrix[4])
96 {
97 EQueryEntitiesFlags queryFlags = EQueryEntitiesFlags.STATIC | EQueryEntitiesFlags.NO_PROXIES;
98 BaseWorld world = GetGame().GetWorld();
99
100 //TODO GET THIS OUT OF THIS CLASS PLZ
101 world.QueryEntitiesByOBB(min, max, m_vMatrix, AddEntityCallback, QueryFilterCallback, queryFlags);
102 }
103
104 //------------------------------------------------------------------------------------------------
106 protected bool AddEntityCallback(notnull IEntity e)
107 {
108 // There shouldn't really be any physical hierchies created on buildings and alike,
109 // so more than anything, this check is just a precaution.
110 // I wish it was just a precaution - Mour
111 if (!e.GetPhysics() && !e.GetChildren())
112 return true;
113
114 // Exclude static entities such as trees, rocks, ruins etc. and other destructible buildings
115 SCR_BuildingDestructionManagerComponent manager = GetGame().GetBuildingDestructionManager();
116 foreach (typename typeName : manager.GetExcludedQueryTypes())
117 {
118 if (e.IsInherited(typeName) && e.Type() != SCR_PowerPole)
119 return true;
120 }
121
122 SCR_EditorLinkComponent linkComp = SCR_EditorLinkComponent.Cast(e.FindComponent(SCR_EditorLinkComponent));
123 if (linkComp)
124 return true;
125
126 SCR_BuildingInteriorDeletinator.InsertEntitiesToDelete(e);
127 return true;
128 }
129
131 protected bool QueryFilterCallback(notnull IEntity entity)
132 {
133 RplComponent rplComp = RplComponent.Cast(entity.FindComponent(RplComponent));
134 if (rplComp)
135 return true;
136
137 IEntity entityParent = entity.GetParent();
138
139 // Exclude the owner && children of other objects
140 if (entityParent)
141 return false;
142
143 return true;
144 }
145
146 //------------------------------------------------------------------------------------------------
147 static DestructionManager GetDestructionManager(BaseWorld world)
148 {
149 ChimeraWorld chimeraWorld = ChimeraWorld.CastFrom(world);
150 if (chimeraWorld)
151 return chimeraWorld.GetDestructionManager();
152
153 return null;
154 }
155
157 {
158 BaseRplComponent component = BaseRplComponent.Cast(FindComponent(BaseRplComponent));
159
160 //all regional managers should have rpl component, no need to double-check
161 return component.Id();
162 }
163}
164
166{
167 bool m_bIsHandled;
168 vector m_vMin;
169 vector m_vMax;
170
171 vector m_center;
172
173 vector m_vMatrix[4];
174
175 //------------------------------------------------------------------------------------------------
176 void OnSave(notnull ScriptBitWriter writer)
177 {
178 writer.WriteVector(m_vMatrix[0]);
179 writer.WriteVector(m_vMatrix[1]);
180 writer.WriteVector(m_vMatrix[2]);
181 writer.WriteVector(m_vMatrix[3]);
182
183 writer.WriteVector(m_vMin);
184 writer.WriteVector(m_vMax);
185 writer.WriteVector(m_center);
186 }
187
188 //------------------------------------------------------------------------------------------------
189 void OnLoad(notnull ScriptBitReader reader)
190 {
191 for (int i = 0; i < 4; i++)
192 {
193 vector value;
194 reader.ReadVector(value);
195 m_vMatrix[i] = value;
196 }
197
198 reader.ReadVector(m_vMin);
199 reader.ReadVector(m_vMax);
200 reader.ReadVector(m_center);
201 }
202
203 //------------------------------------------------------------------------------------------------`
204 void SetBounds (vector min_, vector max_)
205 {
206 m_vMin = min_;
207 m_vMax = max_;
208 }
209}
210
211class SCR_BuildingInteriorDeletinator
212{
213 static int s_iDeletionsThisFrame = 0;
214 static const int MAX_DELETIONS_PER_FRAME = 30;
215 static bool s_bDeletionsQueued = false;
216
217 static ref array<IEntity> s_aEntitiesToDelete = {};
218
219 //------------------------------------------------------------------------------------------------
220 static void InsertEntitiesToDelete(IEntity entityToDelete)
221 {
222 s_aEntitiesToDelete.Insert(entityToDelete);
223 }
224
225 //------------------------------------------------------------------------------------------------
226 static void QueueDeletionsThisFrame()
227 {
228 if (s_bDeletionsQueued)
229 return;
230
231 s_bDeletionsQueued = true;
232 GetGame().GetCallqueue().CallLater(SCR_BuildingInteriorDeletinator.DeleteInteriorEntities);
233 }
234
235 //------------------------------------------------------------------------------------------------
236 // Handles deletion of the interior entities
237 static void DeleteInteriorEntities()
238 {
239 IEntity entityToDelete;
240
241 int lastElementIndex = s_aEntitiesToDelete.Count() -1;
242 int previousSize = s_aEntitiesToDelete.Count();
243
244 for (int index = lastElementIndex; s_iDeletionsThisFrame < MAX_DELETIONS_PER_FRAME; s_iDeletionsThisFrame++)
245 {
246 int indexToDelete = lastElementIndex - s_iDeletionsThisFrame;
247 if (indexToDelete < 0)
248 break;
249
250 entityToDelete = s_aEntitiesToDelete[indexToDelete];
251
252 if (!entityToDelete)
253 continue;
254
255 //Even if they don't have rpl component, DeleteRplEntity will delete the entity for this client
256 RplComponent.DeleteRplEntity(entityToDelete, false);
257 }
258
259 if (s_aEntitiesToDelete.Count() != previousSize)
260 {
261 Print("SCR_BuildingInteriorDeletinator::While deleting building interiors new entities where added to the array of entities to delete, this is a HUGE issue!", LogLevel.ERROR);
262 s_bDeletionsQueued = false;
263 QueueDeletionsThisFrame();
264 return;
265 }
266
267 s_aEntitiesToDelete.Resize(previousSize - s_iDeletionsThisFrame);
268
270
271 //deletions have already been done here
272 s_bDeletionsQueued = false;
273
274 if (!s_aEntitiesToDelete.IsEmpty())
275 QueueDeletionsThisFrame();
276 }
277}
CheckGUIDRequest exists
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
void SCR_PowerPole(IEntitySource src, IEntity parent)
override bool OnLoad(notnull ScriptBitReader reader)
bool AddEntityCallback(notnull IEntity e)
Filters what entities should be handled.
bool QueryFilterCallback(notnull IEntity entity)
Used to filter out entities that are not meant to be handled in AddEntityCallback.
override bool OnSave(notnull ScriptBitWriter writer)
void QueryEntities(vector min, vector max, vector m_vMatrix[4])
SCR_RegionalDestructionManagerClass m_aInteriorBoxes
class SCR_DestructionInteriorBoundingBox s_iDeletionsThisFrame
void RegisterInteriorBoundingBox(vector m_vStartMatrix[4], vector mins, vector maxs, vector center)
void ProcessInteriorBoundingBoxes()
CGoes through the interior boxes registered in regional manager to query entities in them for destruc...
enum EVehicleType IEntity
proto external IEntity GetParent()
Replication item identifier.
Definition RplId.c:14
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
EQueryEntitiesFlags