New API for assigning unique network ids to objects

This commit is contained in:
Boondorl 2024-02-19 13:35:01 -05:00 committed by Rachael Alexanderson
commit 8d0d130dc9
No known key found for this signature in database
GPG key ID: 26A8ACCE97115EE0
11 changed files with 233 additions and 1 deletions

View file

@ -218,6 +218,8 @@ CCMD (dumpclasses)
//
//==========================================================================
#include "d_net.h"
void DObject::InPlaceConstructor (void *mem)
{
new ((EInPlace *)mem) DObject;
@ -317,6 +319,8 @@ void DObject::Release()
void DObject::Destroy ()
{
NetworkEntityManager::RemoveNetworkEntity(this);
// We cannot call the VM during shutdown because all the needed data has been or is in the process of being deleted.
if (PClass::bVMOperational)
{
@ -569,8 +573,15 @@ void DObject::Serialize(FSerializer &arc)
SerializeFlag("justspawned", OF_JustSpawned);
SerializeFlag("spawned", OF_Spawned);
SerializeFlag("networked", OF_Networked);
ObjectFlags |= OF_SerialSuccess;
if (arc.isReading() && (ObjectFlags & OF_Networked))
{
ClearNetworkID();
EnableNetworking(true);
}
}
void DObject::CheckIfSerialized () const
@ -585,6 +596,73 @@ void DObject::CheckIfSerialized () const
}
}
//==========================================================================
//
//
//
//==========================================================================
void DObject::SetNetworkID(const uint32_t id)
{
if (!IsNetworked())
{
ObjectFlags |= OF_Networked;
_networkID = id;
}
}
void DObject::ClearNetworkID()
{
ObjectFlags &= ~OF_Networked;
_networkID = NetworkEntityManager::WorldNetID;
}
void DObject::EnableNetworking(const bool enable)
{
if (enable)
NetworkEntityManager::AddNetworkEntity(this);
else
NetworkEntityManager::RemoveNetworkEntity(this);
}
static unsigned int GetNetworkID(DObject* const self)
{
return self->GetNetworkID();
}
DEFINE_ACTION_FUNCTION_NATIVE(DObject, GetNetworkID, GetNetworkID)
{
PARAM_SELF_PROLOGUE(DObject);
ACTION_RETURN_INT(self->GetNetworkID());
}
static void EnableNetworking(DObject* const self, const bool enable)
{
self->EnableNetworking(enable);
}
DEFINE_ACTION_FUNCTION_NATIVE(DObject, EnableNetworking, EnableNetworking)
{
PARAM_SELF_PROLOGUE(DObject);
PARAM_BOOL(enable);
self->EnableNetworking(enable);
return 0;
}
static DObject* GetNetworkEntity(const unsigned int id)
{
return NetworkEntityManager::GetNetworkEntity(id);
}
DEFINE_ACTION_FUNCTION_NATIVE(DObject, GetNetworkEntity, GetNetworkEntity)
{
PARAM_PROLOGUE;
PARAM_UINT(id);
ACTION_RETURN_OBJECT(NetworkEntityManager::GetNetworkEntity(id));
}
DEFINE_ACTION_FUNCTION(DObject, MSTime)
{