Skip to content

Commit

Permalink
Remove old debug-only fields from plKeyData
Browse files Browse the repository at this point in the history
The debugging message in the destructor was unconditionally disabled and
no longer compiles if manually enabled. The debugging check in
plKeyImp::SetObjectPtr can be rewritten to not require any extra fields
(also making it a bit faster by removing the string comparison).

This uncovered missing includes in multiple places due to plKey.h not
including <string_theory/string> anymore.
  • Loading branch information
dgelessus committed Jan 2, 2024
1 parent f05a9ed commit 10f93bb
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfGameScoreMgr/pfGameScoreMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "HeadSpin.h"
#include "hsRefCnt.h"

#include <string_theory/string>

#include "pnKeyedObject/plKey.h"
#include "pnNetBase/pnNetBase.h"

namespace ST { class string; }

// TODO: Rank List (seems to be unused in regular gameplay though...)
// That's some strange stuff...

Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/NucleusLib/inc/plTimerCallbackManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#ifndef plTimerCallbackManager_Defined
#define plTimerCallbackManager_Defined

#include <vector>

#include "pnKeyedObject/hsKeyedObject.h"

Expand Down
8 changes: 1 addition & 7 deletions Sources/Plasma/NucleusLib/pnKeyedObject/plKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include "HeadSpin.h"
#include "plRefFlags.h"
#include <string_theory/string>

class hsKeyedObject;
class plRefMsg;
class plUoid;
class hsBitVector;
namespace ST { class string; }

//// plKey ///////////////////////////////////////////////////////////////////
// Pointer to a plKeyData struct, which is a handle to a keyedObject
Expand Down Expand Up @@ -141,12 +141,6 @@ class plKeyData
plKeyData();
virtual ~plKeyData();

#ifdef HS_DEBUGGING
// Debugging info fields
ST::string fIDName;
const char* fClassType;
#endif

//// RefCount Stuff //////////////////////////////////////////////////////////
// The refcounts on plKeyData/plKeyImps are zero-based. When you first create
// a new plKeyImp (which should ONLY ever be done inside the resMgr), it gets
Expand Down
42 changes: 4 additions & 38 deletions Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "plgDispatch.h"

#if defined(HS_DEBUGGING) || defined(LOG_ACTIVE_REFS)
#include <string_theory/format>
#include "pnFactory/plFactory.h"
#endif

Expand Down Expand Up @@ -88,11 +89,7 @@ plKeyImp::plKeyImp() :
fDataLen(-1),
fNumActiveRefs(),
fPendingRefs(1)
{
#ifdef HS_DEBUGGING
fClassType = nullptr;
#endif
}
{}

plKeyImp::plKeyImp(plUoid u, uint32_t pos,uint32_t len):
fUoid(std::move(u)),
Expand All @@ -103,24 +100,12 @@ plKeyImp::plKeyImp(plUoid u, uint32_t pos,uint32_t len):
fPendingRefs(1)
{
plProfile_NewMem(KeyMem, CalcKeySize(this));

#ifdef HS_DEBUGGING
fIDName = fUoid.GetObjectName();
fClassType = plFactory::GetNameOfClass( fUoid.GetClassType() );
#endif
}

plKeyImp::~plKeyImp()
{
plProfile_DelMem(KeyMem, CalcKeySize(this));

#if defined(HS_DEBUGGING) && 0
// Colin debugging
char buf[512];
sprintf(buf, "0x%x %s %s\n", this, fIDName, fClassType);
hsStatusMessage(buf);
#endif

hsAssert(fObjectPtr == nullptr, "Deleting non-nil key! Bad idea!");

if (fCloneOwner != nullptr)
Expand All @@ -144,10 +129,6 @@ plKeyImp::~plKeyImp()
void plKeyImp::SetUoid(const plUoid& uoid)
{
fUoid = uoid;
#ifdef HS_DEBUGGING
fIDName = fUoid.GetObjectName();
fClassType = plFactory::GetNameOfClass(fUoid.GetClassType());
#endif
}

ST::string plKeyImp::GetName() const
Expand All @@ -171,11 +152,6 @@ void plKeyImp::CopyForClone(const plKeyImp *p, uint32_t playerID, uint32_t clone
fObjectPtr = nullptr; // the clone object start as nil
fUoid = p->GetUoid(); // we will set the UOID the same to start

#ifdef HS_DEBUGGING
fIDName = fUoid.GetObjectName();
fClassType = plFactory::GetNameOfClass( fUoid.GetClassType() );
#endif

fStartPos = p->GetStartPos();
fDataLen = p->GetDataLen();
fUoid.SetClone(playerID, cloneID);
Expand All @@ -200,11 +176,6 @@ void plKeyImp::Read(hsStream* s)
s->ReadLE32(&fDataLen);

plProfile_NewMem(KeyMem, CalcKeySize(this));

#ifdef HS_DEBUGGING
fIDName = fUoid.GetObjectName();
fClassType = plFactory::GetNameOfClass(fUoid.GetClassType());
#endif
}

void plKeyImp::SkipRead(hsStream* s)
Expand Down Expand Up @@ -310,14 +281,9 @@ hsKeyedObject* plKeyImp::SetObjectPtr(hsKeyedObject* p)
if (p)
{
#ifdef HS_DEBUGGING
if (fClassType)
{
char str[2048];
sprintf(str, "Mismatch of class (we are a %s, given a %s)", fClassType, p->ClassName());
hsAssert(fClassType == p->ClassName() || strcmp(fClassType, p->ClassName()) == 0, str); // points to static
if (fUoid.GetClassType() != p->ClassIndex()) {
hsAssert(false, ST::format("Mismatch of class (we are a {}, given a {})", plFactory::GetNameOfClass(fUoid.GetClassType()), p->ClassName()).c_str());
}
else
fClassType = p->ClassName();
#endif

hsAssert(!fObjectPtr, "Setting an ObjectPtr thats already Set!");
Expand Down
3 changes: 3 additions & 0 deletions Sources/Plasma/NucleusLib/pnMessage/plMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#ifndef plMessage_inc
#define plMessage_inc

#include <string>
#include <vector>

#include "pnFactory/plCreatable.h"
#include "pnKeyedObject/plKey.h"

Expand Down
2 changes: 2 additions & 0 deletions Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include "plMessage.h"

#include <string_theory/string>

#include "hsGeometry3.h"


Expand Down
3 changes: 3 additions & 0 deletions Sources/Plasma/NucleusLib/pnTimer/plTimerCallbackManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include "HeadSpin.h"
#include "plTimerCallbackManager.h"

#include <algorithm>

#include "pnMessage/plTimeMsg.h"
#include "plgDispatch.h"
#include "pnKeyedObject/plFixedKey.h"
Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/PubUtilLib/plMessage/plInputEventMsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "pnInputCore/plControlDefinition.h"
#include "hsGeometry3.h"

#include <string_theory/string>
#include <utility>

class plKeyEventMsg;
Expand Down

0 comments on commit 10f93bb

Please sign in to comment.