Skip to content

Commit

Permalink
Tweaked net ID file management
Browse files Browse the repository at this point in the history
Should now be easier to stub network entity functions for Raze.
  • Loading branch information
Boondorl authored and madame-rachelle committed Apr 20, 2024
1 parent 8d0d130 commit 38f14cc
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 71 deletions.
72 changes: 1 addition & 71 deletions src/common/objects/dobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ CCMD (dumpclasses)
//
//==========================================================================

#include "d_net.h"

void DObject::InPlaceConstructor (void *mem)
{
new ((EInPlace *)mem) DObject;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions src/common/objects/dobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
85 changes: 85 additions & 0 deletions src/d_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2965,6 +2965,12 @@ int Net_GetLatency(int *ld, int *ad)
return severity;
}

//==========================================================================
//
//
//
//==========================================================================

void NetworkEntityManager::InitializeNetworkEntities()
{
if (!s_netEntities.Size())
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 38f14cc

Please sign in to comment.