1 #define ENABLE_BASE_DESTRUCTION
12 protected RplId m_RplId = RplId.Invalid();
13 protected int m_iIndex = -1;
16 void SetIndex(
int index)
22 void SetRplId(RplId rplId)
30 m_EntityID = entityID;
34 RplId GetRplId(out
int index)
45 BaseWorld world =
GetGame().GetWorld();
47 return world.FindEntityByID(m_EntityID);
56 static void Encode(SSnapSerializerBase snapshot, ScriptCtx ctx, ScriptBitSerializer packet)
58 snapshot.Serialize(packet, 16);
62 static bool Decode(ScriptBitSerializer packet, ScriptCtx ctx, SSnapSerializerBase snapshot)
64 return snapshot.Serialize(packet, 16);
68 static bool SnapCompare(SSnapSerializerBase lhs, SSnapSerializerBase rhs, ScriptCtx ctx)
70 return lhs.CompareSnapshots(rhs, 16);
76 return snapshot.Compare(prop.m_EntityID, 8)
77 && snapshot.Compare(prop.m_RplId, 4)
78 && snapshot.Compare(prop.m_iIndex, 4);
84 snapshot.SerializeBytes(prop.m_EntityID, 8);
85 snapshot.SerializeBytes(prop.m_RplId, 4);
86 snapshot.SerializeBytes(prop.m_iIndex, 4);
94 snapshot.SerializeBytes(prop.m_EntityID, 8);
95 snapshot.SerializeBytes(prop.m_RplId, 4);
96 snapshot.SerializeBytes(prop.m_iIndex, 4);
105 #ifdef ENABLE_BASE_DESTRUCTION
106 [
Attribute(
"", UIWidgets.Auto,
desc:
"AudioSourceConfiguration shared by all MPDDestruction sounds")]
107 ref SCR_AudioSourceConfiguration m_AudioSourceConfiguration;
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";
114 static bool s_bInitialized =
false;
116 protected ref array<EntityID> m_ChangedDestructibles =
new array<EntityID>();
117 protected ref array<EntityID> m_DeletedDestructibles =
new array<EntityID>();
118 protected ref map<RplId, ref array<SCR_DestructionDamageManagerComponent>> m_mDynamicallySpawnedDestructibles =
new map<RplId, ref array<SCR_DestructionDamageManagerComponent>>();
119 protected ref map<RplId, ref array<int>> m_mChangedDynamicallySpawnedDestructibles =
new map<RplId, ref array<int>>();
120 protected ref map<RplId, ref array<int>> m_mDeletedDynamicallySpawnedDestructibles =
new map<RplId, ref array<int>>();
121 protected ref array<SCR_DestructionBaseHandler> m_aDestroyInFrame = {};
122 protected RplComponent m_RplComponent;
125 static bool IsInitialized()
127 return s_bInitialized;
135 Resource resource = Resource.Load(DESTRUCTION_MANAGER_PREFAB);
138 Print(
"SCR_MPDestructionManager::CreateInstance(): Failed to create instance! Destruction of objects will not be synched!", LogLevel.ERROR);
142 GetGame().SpawnEntityPrefab(resource);
145 s_bInitialized =
true;
164 protected void DestroyDelayed()
166 for (
int i = m_aDestroyInFrame.Count() - 1; i >= 0; i--)
170 handler.HandleDestruction();
172 m_aDestroyInFrame.Remove(i);
179 m_aDestroyInFrame.Insert(handler);
180 SetEventMask(EntityEvent.FRAME);
185 override bool RplLoad(ScriptBitReader reader)
187 SCR_DestructionDamageManagerComponent.SetReadingInit(
true);
191 reader.ReadInt(numDeleted);
192 for (
int i = 0; i < numDeleted; i++)
195 reader.ReadEntityId(entID);
197 IEntity entity = GetWorld().FindEntityByID(entID);
201 SCR_DestructionDamageManagerComponent
destructible = SCR_DestructionDamageManagerComponent.Cast(entity.FindComponent(SCR_DestructionDamageManagerComponent));
209 int numDestructibles;
210 reader.ReadInt(numDestructibles);
211 for (
int i = 0; i < numDestructibles; i++)
214 reader.ReadEntityId(entID);
216 IEntity entity = GetWorld().FindEntityByID(entID);
220 SCR_DestructionDamageManagerComponent
destructible = SCR_DestructionDamageManagerComponent.Cast(entity.FindComponent(SCR_DestructionDamageManagerComponent));
227 SCR_DestructionDamageManagerComponent.SetReadingInit(
false);
233 override bool RplSave(ScriptBitWriter writer)
236 int numDeleted = m_DeletedDestructibles.Count();
237 writer.WriteInt(numDeleted);
238 for (
int i = 0; i < numDeleted; i++)
240 writer.WriteEntityId(m_DeletedDestructibles[i]);
244 int numChanged = m_ChangedDestructibles.Count();
245 writer.WriteInt(numChanged);
246 for (
int i = 0; i < numChanged; i++)
248 EntityID entID = m_ChangedDestructibles[i];
249 IEntity entity = GetWorld().FindEntityByID(entID);
253 SCR_DestructionDamageManagerComponent
destructible = SCR_DestructionDamageManagerComponent.Cast(entity.FindComponent(SCR_DestructionDamageManagerComponent));
257 writer.WriteEntityId(entID);
265 SCR_AudioSourceConfiguration GetAudioSourceConfiguration()
271 protected override void EOnFrame(IEntity owner,
float timeSlice)
273 ClearEventMask(EntityEvent.FRAME);
278 override void EOnInit(IEntity owner)
284 int RegisterDynamicallySpawnedDestructible(notnull SCR_DestructionDamageManagerComponent
destructible, RplId rplId)
286 array<SCR_DestructionDamageManagerComponent> destructibles = m_mDynamicallySpawnedDestructibles.Get(rplId);
289 destructibles =
new array<SCR_DestructionDamageManagerComponent>();
290 m_mDynamicallySpawnedDestructibles.Insert(rplId, destructibles);
297 SCR_DestructionDamageManagerComponent FindDynamicallySpawnedDestructibleByIndex(RplId rplId,
int index)
299 array<SCR_DestructionDamageManagerComponent> destructibles = m_mDynamicallySpawnedDestructibles.Get(rplId);
303 if (
index >= 0 &&
index < destructibles.Count())
304 return destructibles[
index];
310 int FindDynamicallySpawnedDestructibleIndex(RplId rplId, SCR_DestructionDamageManagerComponent
destructible)
312 array<SCR_DestructionDamageManagerComponent> destructibles = m_mDynamicallySpawnedDestructibles.Get(rplId);
320 void RegisterDeletedDynamicallySpawnedDestructible(notnull SCR_DestructionDamageManagerComponent
destructible, RplId rplId)
325 array<int> deletedDestructibles = m_mDeletedDynamicallySpawnedDestructibles.Get(rplId);
326 if (!deletedDestructibles)
328 deletedDestructibles =
new array<int>();
329 m_mDeletedDynamicallySpawnedDestructibles.Insert(rplId, deletedDestructibles);
332 deletedDestructibles.Insert(
index);
337 void RegisterChangedDynamicallySpawnedDestructible(notnull SCR_DestructionDamageManagerComponent
destructible, RplId rplId)
342 array<int> changedDestructibles = m_mChangedDynamicallySpawnedDestructibles.Get(rplId);
343 if (!changedDestructibles)
345 changedDestructibles =
new array<int>();
346 m_mChangedDynamicallySpawnedDestructibles.Insert(rplId, changedDestructibles);
349 changedDestructibles.Insert(
index);
358 SetEventMask(EntityEvent.INIT);
361 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_SOUNDS_MPDESTRUCTION_SHOW_IMPULSEVALUES,
"",
"Show MPD Impulse Values",
"Sounds");
369 DiagMenu.Unregister(
SCR_DebugMenuID.DEBUGUI_SOUNDS_MPDESTRUCTION_SHOW_IMPULSEVALUES);