From 38f14ccd560142fcfe2d968ef5926a0c9812da64 Mon Sep 17 00:00:00 2001 From: Boondorl Date: Sat, 20 Apr 2024 10:43:34 -0400 Subject: [PATCH] Tweaked net ID file management Should now be easier to stub network entity functions for Raze. --- src/common/objects/dobject.cpp | 72 +--------------------------- src/common/objects/dobject.h | 1 + src/d_net.cpp | 85 ++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 71 deletions(-) diff --git a/src/common/objects/dobject.cpp b/src/common/objects/dobject.cpp index 15400ce239c..b66029a5355 100644 --- a/src/common/objects/dobject.cpp +++ b/src/common/objects/dobject.cpp @@ -218,8 +218,6 @@ CCMD (dumpclasses) // //========================================================================== -#include "d_net.h" - void DObject::InPlaceConstructor (void *mem) { new ((EInPlace *)mem) DObject; @@ -319,7 +317,7 @@ void DObject::Release() void DObject::Destroy () { - NetworkEntityManager::RemoveNetworkEntity(this); + RemoveFromNetwork(); // 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) @@ -596,74 +594,6 @@ 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) { ACTION_RETURN_INT((uint32_t)I_msTime()); diff --git a/src/common/objects/dobject.h b/src/common/objects/dobject.h index ed5fc996b3e..f193379c11d 100644 --- a/src/common/objects/dobject.h +++ b/src/common/objects/dobject.h @@ -361,6 +361,7 @@ class DObject inline uint32_t GetNetworkID() const { return _networkID; } void SetNetworkID(const uint32_t id); void ClearNetworkID(); + void RemoveFromNetwork(); virtual void EnableNetworking(const bool enable); }; diff --git a/src/d_net.cpp b/src/d_net.cpp index 2536739cf77..ca45da4ef99 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -2965,6 +2965,12 @@ int Net_GetLatency(int *ld, int *ad) return severity; } +//========================================================================== +// +// +// +//========================================================================== + void NetworkEntityManager::InitializeNetworkEntities() { if (!s_netEntities.Size()) @@ -3048,6 +3054,85 @@ DObject* NetworkEntityManager::GetNetworkEntity(const uint32_t id) return s_netEntities[id]; } +//========================================================================== +// +// +// +//========================================================================== + +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); +} + +void DObject::RemoveFromNetwork() +{ + 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)); +} + +//========================================================================== +// +// +// +//========================================================================== + // [RH] List "ping" times CCMD (pings) {