Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MPDestructionManager.c
Go to the documentation of this file.
1#define ENABLE_BASE_DESTRUCTION
2//------------------------------------------------------------------------------------------------
3[EntityEditorProps(category: "GameScripted/Destruction", description: "Manager for destructibles", color: "0 0 255 255")]
4class SCR_MPDestructionManagerClass: GenericEntityClass
5{
6};
7
8//------------------------------------------------------------------------------------------------
10{
11 protected EntityID m_EntityID = EntityID.INVALID;
12 protected RplId m_RplId = RplId.Invalid();
13 protected int m_iIndex = -1;
14
15 //------------------------------------------------------------------------------------------------
16 void SetIndex(int index)
17 {
19 }
20
21 //------------------------------------------------------------------------------------------------
22 void SetRplId(RplId rplId)
23 {
24 m_RplId = rplId;
25 }
26
27 //------------------------------------------------------------------------------------------------
28 void SetEntityID(EntityID entityID)
29 {
30 m_EntityID = entityID;
31 }
32
33 //------------------------------------------------------------------------------------------------
35 {
37 return m_RplId;
38 }
39
40 //------------------------------------------------------------------------------------------------
42 {
43 if (m_EntityID != EntityID.INVALID)
44 {
45 BaseWorld world = GetGame().GetWorld();
46 if (world)
47 return world.FindEntityByID(m_EntityID);
48 }
49
50 return null;
51 }
52
53 //################################################################################################
55 //------------------------------------------------------------------------------------------------
56 static void Encode(SSnapSerializerBase snapshot, ScriptCtx ctx, ScriptBitSerializer packet)
57 {
58 snapshot.Serialize(packet, 16);
59 }
60
61 //------------------------------------------------------------------------------------------------
62 static bool Decode(ScriptBitSerializer packet, ScriptCtx ctx, SSnapSerializerBase snapshot)
63 {
64 return snapshot.Serialize(packet, 16);
65 }
66
67 //------------------------------------------------------------------------------------------------
69 {
70 return lhs.CompareSnapshots(rhs, 16);
71 }
72
73 //------------------------------------------------------------------------------------------------
75 {
76 return snapshot.Compare(prop.m_EntityID, 8)
77 && snapshot.Compare(prop.m_RplId, 4)
78 && snapshot.Compare(prop.m_iIndex, 4);
79 }
80
81 //------------------------------------------------------------------------------------------------
83 {
84 snapshot.SerializeBytes(prop.m_EntityID, 8);
85 snapshot.SerializeBytes(prop.m_RplId, 4);
86 snapshot.SerializeBytes(prop.m_iIndex, 4);
87
88 return true;
89 }
90
91 //------------------------------------------------------------------------------------------------
93 {
94 snapshot.SerializeBytes(prop.m_EntityID, 8);
95 snapshot.SerializeBytes(prop.m_RplId, 4);
96 snapshot.SerializeBytes(prop.m_iIndex, 4);
97
98 return true;
99 }
100};
101
102//------------------------------------------------------------------------------------------------
104{
105#ifdef ENABLE_BASE_DESTRUCTION
106 [Attribute("", UIWidgets.Auto, desc: "AudioSourceConfiguration shared by all MPDDestruction sounds")]
107 ref SCR_AudioSourceConfiguration m_AudioSourceConfiguration;
108
109 static const string ENTITY_SIZE_SIGNAL_NAME = "EntitySize";
110 static const string PHASES_TO_DESTROYED_PHASE_SIGNAL_NAME = "PhasesToDestroyed";
111 static const string COLLISIONDV_SIGNAL_NAME = "CollisionDV";
112 static const ResourceName DESTRUCTION_MANAGER_PREFAB = "{9BB369F2803C6F71}Prefabs/MP/MPDestructionManager.et";
113 static private SCR_MPDestructionManager s_Instance = null;
114 static bool s_bInitialized = false;
115
116 protected ref array<EntityID> m_ChangedDestructibles = new array<EntityID>();
117 protected ref array<EntityID> m_DeletedDestructibles = new array<EntityID>();
121 protected ref array<SCR_DestructionBaseHandler> m_aDestroyInFrame = {};
122 protected RplComponent m_RplComponent;
123
124 //------------------------------------------------------------------------------------------------
125 static bool IsInitialized()
126 {
127 return s_bInitialized;
128 }
129
130 //------------------------------------------------------------------------------------------------
132 {
133 if (!s_Instance)
134 {
135 Resource resource = Resource.Load(DESTRUCTION_MANAGER_PREFAB);
136 if (!resource)
137 {
138 Print("SCR_MPDestructionManager::CreateInstance(): Failed to create instance! Destruction of objects will not be synched!", LogLevel.ERROR);
140 }
141
142 GetGame().SpawnEntityPrefab(resource);
143 }
144
145 s_bInitialized = true;
146 return s_Instance;
147 }
148
149 //------------------------------------------------------------------------------------------------
152 {
153 return s_Instance;
154 }
155
156 //------------------------------------------------------------------------------------------------
158 bool IsProxy()
159 {
160 return (m_RplComponent && m_RplComponent.IsProxy());
161 }
162
163 //------------------------------------------------------------------------------------------------
164 protected void DestroyDelayed()
165 {
166 for (int i = m_aDestroyInFrame.Count() - 1; i >= 0; i--)
167 {
169 if (handler)
170 handler.HandleDestruction();
171
172 m_aDestroyInFrame.Remove(i);
173 }
174 }
175
176 //------------------------------------------------------------------------------------------------
178 {
179 m_aDestroyInFrame.Insert(handler);
181 }
182
183 //------------------------------------------------------------------------------------------------
185 override bool RplLoad(ScriptBitReader reader)
186 {
187 SCR_DestructionDamageManagerComponent.SetReadingInit(true);
188
189 // First read IDs for deleted destructibles on the server and delete them locally
190 int numDeleted;
191 reader.ReadInt(numDeleted); // Read num deleted
192 for (int i = 0; i < numDeleted; i++)
193 {
194 EntityID entID;
195 reader.ReadEntityId(entID); // Read entity ID of each deleted destructible
196
197 IEntity entity = GetWorld().FindEntityByID(entID);
198 if (!entity)
199 continue;
200
201 SCR_DestructionDamageManagerComponent destructible = SCR_DestructionDamageManagerComponent.Cast(entity.FindComponent(SCR_DestructionDamageManagerComponent));
202 if (!destructible)
203 continue;
204
205 destructible.DeleteDestructibleDelayed();
206 }
207
208 // Now pass data from server destructibles to local ones
209 int numDestructibles;
210 reader.ReadInt(numDestructibles); // Read num destructibles sent
211 for (int i = 0; i < numDestructibles; i++)
212 {
213 bool hasEntityID;
214 reader.ReadBool(hasEntityID);
215
216 if (!hasEntityID)
217 continue;
218
219 EntityID entID;
220 reader.ReadEntityId(entID); // Read entity ID of each destructible to be read
221
222 IEntity entity = GetWorld().FindEntityByID(entID);
223 if (!entity)
224 continue; // this shouldn't happen
225
226 SCR_DestructionDamageManagerComponent destructible = SCR_DestructionDamageManagerComponent.Cast(entity.FindComponent(SCR_DestructionDamageManagerComponent));
227 if (!destructible)
228 continue; // this shouldn't happen
229
230 destructible.NetReadInit(reader);
231 }
232
233 SCR_DestructionDamageManagerComponent.SetReadingInit(false);
234 return true;
235 }
236
237 //------------------------------------------------------------------------------------------------
239 override bool RplSave(ScriptBitWriter writer)
240 {
241 // First send all the destructibles that have been deleted
242 int numDeleted = m_DeletedDestructibles.Count();
243 writer.WriteInt(numDeleted); // Write num deleted
244 for (int i = 0; i < numDeleted; i++)
245 {
246 writer.WriteEntityId(m_DeletedDestructibles[i]); // Write entity ID of each deleted destructible
247 }
248
249 // Send destructibles' data
250 int numChanged = m_ChangedDestructibles.Count();
251 writer.WriteInt(numChanged); // Write num destructibles
252 for (int i = 0; i < numChanged; i++)
253 {
255 IEntity entity = GetWorld().FindEntityByID(entID);
256 if (!entity)
257 {
258 writer.WriteBool(false);
259 continue;
260 }
261
262 SCR_DestructionDamageManagerComponent destructible = SCR_DestructionDamageManagerComponent.Cast(entity.FindComponent(SCR_DestructionDamageManagerComponent));
263 if (!destructible)
264 {
265 writer.WriteBool(false);
266 continue;
267 }
268
269 writer.WriteBool(true);
270 writer.WriteEntityId(entID); // Write entity ID of each destructible to be sent
271 destructible.NetWriteInit(writer); // Tell destructible to write its data
272
273 }
274
275 return true;
276 }
277
278 //------------------------------------------------------------------------------------------------
279 SCR_AudioSourceConfiguration GetAudioSourceConfiguration()
280 {
281 return m_AudioSourceConfiguration;
282 }
283
284 //------------------------------------------------------------------------------------------------
285 protected override void EOnFrame(IEntity owner, float timeSlice)
286 {
289 }
290
291 //------------------------------------------------------------------------------------------------
292 override void EOnInit(IEntity owner)
293 {
294 m_RplComponent = RplComponent.Cast(FindComponent(RplComponent));
295 }
296
297 //------------------------------------------------------------------------------------------------
298 int RegisterDynamicallySpawnedDestructible(notnull SCR_DestructionDamageManagerComponent destructible, RplId rplId)
299 {
300 array<SCR_DestructionDamageManagerComponent> destructibles = m_mDynamicallySpawnedDestructibles.Get(rplId);
301 if (!destructibles)
302 {
303 destructibles = new array<SCR_DestructionDamageManagerComponent>();
304 m_mDynamicallySpawnedDestructibles.Insert(rplId, destructibles);
305 }
306
307 return destructibles.Insert(destructible);
308 }
309
310 //------------------------------------------------------------------------------------------------
311 SCR_DestructionDamageManagerComponent FindDynamicallySpawnedDestructibleByIndex(RplId rplId, int index)
312 {
313 array<SCR_DestructionDamageManagerComponent> destructibles = m_mDynamicallySpawnedDestructibles.Get(rplId);
314 if (!destructibles)
315 return null;
316
317 if (index >= 0 && index < destructibles.Count())
318 return destructibles[index];
319
320 return null;
321 }
322
323 //------------------------------------------------------------------------------------------------
324 int FindDynamicallySpawnedDestructibleIndex(RplId rplId, SCR_DestructionDamageManagerComponent destructible)
325 {
326 array<SCR_DestructionDamageManagerComponent> destructibles = m_mDynamicallySpawnedDestructibles.Get(rplId);
327 if (!destructibles)
328 return -1;
329
330 return destructibles.Find(destructible);
331 }
332
333 //------------------------------------------------------------------------------------------------
334 void RegisterDeletedDynamicallySpawnedDestructible(notnull SCR_DestructionDamageManagerComponent destructible, RplId rplId)
335 {
337 if (index != -1)
338 {
339 array<int> deletedDestructibles = m_mDeletedDynamicallySpawnedDestructibles.Get(rplId);
340 if (!deletedDestructibles)
341 {
342 deletedDestructibles = new array<int>();
343 m_mDeletedDynamicallySpawnedDestructibles.Insert(rplId, deletedDestructibles);
344 }
345
346 deletedDestructibles.Insert(index);
347 }
348 }
349
350 //------------------------------------------------------------------------------------------------
351 void RegisterChangedDynamicallySpawnedDestructible(notnull SCR_DestructionDamageManagerComponent destructible, RplId rplId)
352 {
354 if (index != -1)
355 {
356 array<int> changedDestructibles = m_mChangedDynamicallySpawnedDestructibles.Get(rplId);
357 if (!changedDestructibles)
358 {
359 changedDestructibles = new array<int>();
360 m_mChangedDynamicallySpawnedDestructibles.Insert(rplId, changedDestructibles);
361 }
362
363 changedDestructibles.Insert(index);
364 }
365 }
366
367 //------------------------------------------------------------------------------------------------
369 {
370 s_Instance = this;
371
373
374 #ifdef ENABLE_DIAG
375 DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_SOUNDS_MPDESTRUCTION_SHOW_IMPULSEVALUES, "", "Show MPD Impulse Values", "Sounds");
376 #endif
377 }
378
379 //------------------------------------------------------------------------------------------------
381 {
382 #ifdef ENABLE_DIAG
383 DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_SOUNDS_MPDESTRUCTION_SHOW_IMPULSEVALUES);
384 #endif
385 }
386#endif
387};
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ArmaReforgerScripted GetGame()
Definition game.c:1398
IEntity SpawnEntity(ResourceName entityResourceName, notnull IEntity slotOwner)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
SCR_DestructionDamageManagerComponent destructible
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Diagnostic and developer menu system.
Definition DiagMenu.c:18
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
proto external EntityEvent SetEventMask(EntityEvent e)
proto external Managed FindComponent(typename typeName)
proto external EntityEvent ClearEventMask(EntityEvent e)
proto external BaseWorld GetWorld()
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
Replication item identifier.
Definition RplId.c:14
static bool SnapCompare(SSnapSerializerBase lhs, SSnapSerializerBase rhs, ScriptCtx ctx)
static bool Decode(ScriptBitSerializer packet, ScriptCtx ctx, SSnapSerializerBase snapshot)
static bool PropCompare(SCR_DestructibleIdentificator prop, SSnapSerializerBase snapshot, ScriptCtx ctx)
static bool Extract(SCR_DestructibleIdentificator prop, ScriptCtx ctx, SSnapSerializerBase snapshot)
static bool Inject(SSnapSerializerBase snapshot, ScriptCtx ctx, SCR_DestructibleIdentificator prop)
static void Encode(SSnapSerializerBase snapshot, ScriptCtx ctx, ScriptBitSerializer packet)
Codec methods.
static notnull SCR_MPDestructionManager InitializeDestructionManager()
void SCR_MPDestructionManager(IEntitySource src, IEntity parent)
override void EOnInit(IEntity owner)
ref array< SCR_DestructionBaseHandler > m_aDestroyInFrame
ref map< RplId, ref array< SCR_DestructionDamageManagerComponent > > m_mDynamicallySpawnedDestructibles
override bool RplLoad(ScriptBitReader reader)
Called when Item is initialized from replication stream. Carries the data from Master.
void RegisterChangedDynamicallySpawnedDestructible(notnull SCR_DestructionDamageManagerComponent destructible, RplId rplId)
override void EOnFrame(IEntity owner, float timeSlice)
override bool RplSave(ScriptBitWriter writer)
Called when Item is getting replicated from Master to Slave connection. The data will be delivered to...
ref map< RplId, ref array< int > > m_mDeletedDynamicallySpawnedDestructibles
void DestroyInFrame(SCR_DestructionBaseHandler handler)
SCR_DestructionDamageManagerComponent FindDynamicallySpawnedDestructibleByIndex(RplId rplId, int index)
void RegisterDeletedDynamicallySpawnedDestructible(notnull SCR_DestructionDamageManagerComponent destructible, RplId rplId)
static SCR_MPDestructionManager GetInstance()
Returns the instance of the destruction manager.
ref map< RplId, ref array< int > > m_mChangedDynamicallySpawnedDestructibles
ref array< EntityID > m_ChangedDestructibles
bool IsProxy()
Checks if this entity is locally owned.
int FindDynamicallySpawnedDestructibleIndex(RplId rplId, SCR_DestructionDamageManagerComponent destructible)
SCR_AudioSourceConfiguration GetAudioSourceConfiguration()
ref array< EntityID > m_DeletedDestructibles
int RegisterDynamicallySpawnedDestructible(notnull SCR_DestructionDamageManagerComponent destructible, RplId rplId)
Definition Types.c:486
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
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14