New API for assigning unique network ids to objects
This commit is contained in:
parent
4d1590ad82
commit
e37c19b5b4
11 changed files with 233 additions and 1 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
@ -504,8 +508,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
|
||||
|
|
@ -520,6 +531,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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -351,6 +351,17 @@ protected:
|
|||
friend T* Create(Args&&... args);
|
||||
|
||||
friend class JitCompiler;
|
||||
|
||||
private:
|
||||
// This is intentionally left unserialized.
|
||||
uint32_t _networkID;
|
||||
|
||||
public:
|
||||
inline bool IsNetworked() const { return (ObjectFlags & OF_Networked); }
|
||||
inline uint32_t GetNetworkID() const { return _networkID; }
|
||||
void SetNetworkID(const uint32_t id);
|
||||
void ClearNetworkID();
|
||||
virtual void EnableNetworking(const bool enable);
|
||||
};
|
||||
|
||||
// This is the only method aside from calling CreateNew that should be used for creating DObjects
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ enum EObjectFlags
|
|||
OF_Transient = 1 << 11, // Object should not be archived (references to it will be nulled on disk)
|
||||
OF_Spawned = 1 << 12, // Thinker was spawned at all (some thinkers get deleted before spawning)
|
||||
OF_Released = 1 << 13, // Object was released from the GC system and should not be processed by GC function
|
||||
OF_Networked = 1 << 14, // Object has a unique network identifier that makes it synchronizable between all clients.
|
||||
};
|
||||
|
||||
template<class T> class TObjPtr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue