-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chopping - Revise deletion of plants (#134)
* Move deletion of loadtime entities to a game mode component and use entity IDs instead of positions * Replicate deleted entity IDs as ints * Use wrapper instead of ints for EntityID
- Loading branch information
Showing
9 changed files
with
298 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SCR_BaseGameMode { | ||
ID "56B2B479C6B96951" | ||
components { | ||
ACE_LoadtimeEntityManager "{62FC19C3B5BE2C5F}" { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
MetaFileClass { | ||
Name "{0F307326459A1395}Prefabs/MP/Modes/GameMode_Base.et" | ||
Configurations { | ||
EntityTemplateResourceClass PC { | ||
} | ||
EntityTemplateResourceClass XBOX_ONE : PC { | ||
} | ||
EntityTemplateResourceClass XBOX_SERIES : PC { | ||
} | ||
EntityTemplateResourceClass PS4 : PC { | ||
} | ||
EntityTemplateResourceClass PS5 : PC { | ||
} | ||
EntityTemplateResourceClass HEADLESS : PC { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
addons/core/scripts/Game/ACE_Core/GameMode/Components/ACE_LoadtimeEntityManager.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
//------------------------------------------------------------------------------------------------ | ||
class ACE_LoadtimeEntityManagerClass : SCR_BaseGameModeComponentClass | ||
{ | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
//! Methods for manipulating unreplicated loadtime entities | ||
class ACE_LoadtimeEntityManager : SCR_BaseGameModeComponent | ||
{ | ||
// array<EntityID> can't be properly replicated (see https://feedback.bistudio.com/T186903) so we use a wrapper instead | ||
[RplProp(onRplName: "DeleteInitialEntities")] | ||
protected ref array<ref ACE_EntityIdWrapper> m_aDeletedEntityIDs = {}; | ||
|
||
protected static ACE_LoadtimeEntityManager s_pInstance; | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
void ACE_LoadtimeEntityManager(IEntityComponentSource src, IEntity ent, IEntity parent) | ||
{ | ||
s_pInstance = this; | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
static ACE_LoadtimeEntityManager GetInstance() | ||
{ | ||
return s_pInstance; | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
//! Ensures that already deleted unreplicated entities are deleted for JIPs | ||
void DeleteInitialEntities() | ||
{ | ||
foreach (ACE_EntityIdWrapper idWrapper : m_aDeletedEntityIDs) | ||
{ | ||
DeleteEntityByIdLocal(idWrapper.GetID()); | ||
} | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
//! Deletes unreplicated entities by ID for all machines | ||
//! Can only be called on the server | ||
[RplRpc(RplChannel.Reliable, RplRcver.Server)] | ||
void DeleteEntitiesByIdGlobal(notnull array<EntityID> entityIDs) | ||
{ | ||
array<ref ACE_EntityIdWrapper> newIDs = {}; | ||
newIDs.Reserve(entityIDs.Count()); | ||
m_aDeletedEntityIDs.Reserve(m_aDeletedEntityIDs.Count() + newIDs.Count()); | ||
|
||
foreach (EntityID entityID : entityIDs) | ||
{ | ||
ACE_EntityIdWrapper idWrapper = ACE_EntityIdWrapper.CreateID(entityID); | ||
newIDs.Insert(idWrapper); | ||
m_aDeletedEntityIDs.Insert(idWrapper); | ||
} | ||
|
||
Rpc(RpcDo_DeleteEntityByBitsBroadcast, newIDs); | ||
RpcDo_DeleteEntityByBitsBroadcast(newIDs); | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
[RplRpc(RplChannel.Reliable, RplRcver.Broadcast)] | ||
protected void RpcDo_DeleteEntityByBitsBroadcast(array<ref ACE_EntityIdWrapper> newIDs) | ||
{ | ||
foreach (ACE_EntityIdWrapper idWrapper : newIDs) | ||
{ | ||
DeleteEntityByIdLocal(idWrapper.GetID()); | ||
} | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
//! Deletes unreplicated entity by ID on a local machine | ||
void DeleteEntityByIdLocal(EntityID entityID) | ||
{ | ||
IEntity entity = GetGame().GetWorld().FindEntityByID(entityID); | ||
if (entity) | ||
delete entity; | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
//! Return all deleted unreplicated entity IDs | ||
//! Can only be called on the server | ||
array<EntityID> GetDeletedEntityIDs() | ||
{ | ||
array<EntityID> entityIDs = {}; | ||
entityIDs.Reserve(m_aDeletedEntityIDs.Count()); | ||
|
||
foreach (ACE_EntityIdWrapper idWrapper : m_aDeletedEntityIDs) | ||
{ | ||
entityIDs.Insert(idWrapper.GetID()); | ||
} | ||
|
||
return entityIDs; | ||
} | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
//! Temporary workaround for https://feedback.bistudio.com/T186903 | ||
class ACE_EntityIdWrapper : Managed | ||
{ | ||
static const int SNAPSHOT_SIZE_VALUE = 8; //--- EntityID is 64 bit integer | ||
protected EntityID m_iID; | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
static ACE_EntityIdWrapper CreateID(EntityID id) | ||
{ | ||
ACE_EntityIdWrapper instance = new ACE_EntityIdWrapper(); | ||
instance.m_iID = id; | ||
return instance; | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
EntityID GetID() | ||
{ | ||
return m_iID; | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
static void Encode(SSnapSerializerBase snapshot, ScriptCtx hint, ScriptBitSerializer packet) | ||
{ | ||
snapshot.Serialize(packet, SNAPSHOT_SIZE_VALUE); | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
static bool Decode(ScriptBitSerializer packet, ScriptCtx hint, SSnapSerializerBase snapshot) | ||
{ | ||
return snapshot.Serialize(packet, SNAPSHOT_SIZE_VALUE); | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
static bool SnapCompare(SSnapSerializerBase lhs, SSnapSerializerBase rhs, ScriptCtx hint) | ||
{ | ||
return lhs.CompareSnapshots(rhs, SNAPSHOT_SIZE_VALUE); | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
static bool PropCompare(ACE_EntityIdWrapper prop, SSnapSerializerBase snapshot, ScriptCtx hint) | ||
{ | ||
return snapshot.Compare(prop.m_iID, SNAPSHOT_SIZE_VALUE); | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
static bool Extract(ACE_EntityIdWrapper prop, ScriptCtx hint, SSnapSerializerBase snapshot) | ||
{ | ||
snapshot.SerializeBytes(prop.m_iID, SNAPSHOT_SIZE_VALUE); | ||
return true; | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
static bool Inject(SSnapSerializerBase snapshot, ScriptCtx hint, ACE_EntityIdWrapper prop) | ||
{ | ||
return Extract(prop, hint, snapshot); | ||
} | ||
} |
48 changes: 0 additions & 48 deletions
48
addons/core/scripts/Game/ACE_Core/GameMode/SCR_BaseGameMode.c
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
addons/core/scripts/Game/ACE_Core/Global/ACE_EntityIdHelper.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//------------------------------------------------------------------------------------------------ | ||
class ACE_EntityIdHelper | ||
{ | ||
//------------------------------------------------------------------------------------------------ | ||
static array<int> ToInt(EntityID id) | ||
{ | ||
return ACE_HexTools.HexStringToInt(ToString(id)); | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
static EntityID FromString(string str) | ||
{ | ||
array<int> bits = ACE_HexTools.HexStringToInt(str); | ||
if (bits.Count() < 2) | ||
return EntityID.INVALID; | ||
|
||
return EntityID.FromInt(bits[0], bits[1]); | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
static string ToString(EntityID id) | ||
{ | ||
// Drop the last three characters, which are " {}" | ||
return id.ToString().Substring(0, 18); | ||
} | ||
} |
Oops, something went wrong.