Skip to content

Commit

Permalink
Fixes for client network IDs
Browse files Browse the repository at this point in the history
Fixed an off-by-one error on client IDs (these need to start at 1 as 0 is an invalid network ID). Morphing will now swap the client body's ID so it remains in the first 1 - MAXPLAYERS slots.
  • Loading branch information
Boondorl authored and RicardoLuis0 committed Apr 25, 2024
1 parent 566e03d commit cf6bad9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/common/objects/dobject.cpp
Expand Up @@ -637,10 +637,11 @@ void NetworkEntityManager::InitializeNetworkEntities()
}

// Clients need special handling since they always go in slots 1 - MAXPLAYERS.
void NetworkEntityManager::SetClientNetworkEntity(DObject* mo, const uint32_t id)
void NetworkEntityManager::SetClientNetworkEntity(DObject* mo, const unsigned int playNum)
{
// If resurrecting, we need to swap the corpse's position with the new pawn's
// position so it's no longer considered the client's body.
const uint32_t id = ClientNetIDStart + playNum;
DObject* const oldBody = s_netEntities[id];
if (oldBody != nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion src/common/objects/dobject.h
Expand Up @@ -502,7 +502,7 @@ class NetworkEntityManager
inline static uint32_t NetIDStart;// = MAXPLAYERS + 1u;

static void InitializeNetworkEntities();
static void SetClientNetworkEntity(DObject* mo, const uint32_t id);
static void SetClientNetworkEntity(DObject* mo, const unsigned int playNum);
static void AddNetworkEntity(DObject* const ent);
static void RemoveNetworkEntity(DObject* const ent);
static DObject* GetNetworkEntity(const uint32_t id);
Expand Down
4 changes: 4 additions & 0 deletions src/playsim/p_mobj.cpp
Expand Up @@ -5390,6 +5390,10 @@ int MorphPointerSubstitution(AActor* from, AActor* to)
{
to->player = from->player;
from->player = nullptr;

// Swap the new body into the right network slot if it's a client (this doesn't
// really matter for regular Actors since they grab any ID they can get anyway).
NetworkEntityManager::SetClientNetworkEntity(to, to->player - players);
}

if (from->alternative != nullptr)
Expand Down

0 comments on commit cf6bad9

Please sign in to comment.