From 60ad9e2df80a6be555a219a575ade9f225130a09 Mon Sep 17 00:00:00 2001 From: s1lent Date: Fri, 13 Oct 2017 02:54:10 +0700 Subject: [PATCH] Enhanced qstring.h --- regamedll/dlls/addons/item_airbox.cpp | 8 ++++---- regamedll/dlls/player.cpp | 2 +- regamedll/dlls/qstring.h | 11 ++++++++++- regamedll/dlls/util.cpp | 4 ++-- regamedll/dlls/util.h | 1 - 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/regamedll/dlls/addons/item_airbox.cpp b/regamedll/dlls/addons/item_airbox.cpp index d09e9624..0419c983 100644 --- a/regamedll/dlls/addons/item_airbox.cpp +++ b/regamedll/dlls/addons/item_airbox.cpp @@ -36,9 +36,9 @@ void CItemAirBox::Spawn() pev->movetype = MOVETYPE_NOCLIP; - if (!FStringNull(m_iszSpriteName)) + if (!m_iszSpriteName.IsEmpty()) { - m_pSprite = CSprite::SpriteCreate(STRING(m_iszSpriteName), pev->origin, FALSE); + m_pSprite = CSprite::SpriteCreate(m_iszSpriteName, pev->origin, FALSE); m_pSprite->SetTransparency(m_rendermode, m_rendercolor.x, m_rendercolor.y, m_rendercolor.z, m_renderamt, m_renderfx); m_pSprite->SetScale(m_scale); m_pSprite->SetAttachment(edict(), pev->body); @@ -75,8 +75,8 @@ void CItemAirBox::Precache() { CArmoury::Precache(); - if (!FStringNull(m_iszSpriteName)) { - PRECACHE_MODEL(STRING(m_iszSpriteName)); + if (!m_iszSpriteName.IsEmpty()) { + PRECACHE_MODEL(m_iszSpriteName); } } diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 71c2d9ed..39668ba3 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -5761,7 +5761,7 @@ CBaseEntity *CBasePlayer::GiveNamedItemEx(const char *pszName) if (FNullEnt(pent)) { - ALERT(at_console, "NULL Ent in GiveNamedItemEx!\n"); + ALERT(at_console, "NULL Ent in GiveNamedItemEx classname `%s`!\n", pszName); return nullptr; } diff --git a/regamedll/dlls/qstring.h b/regamedll/dlls/qstring.h index 13223e9d..80edb751 100644 --- a/regamedll/dlls/qstring.h +++ b/regamedll/dlls/qstring.h @@ -30,14 +30,17 @@ #define QSTRING_DEFINE +constexpr auto iStringNull = 0u; + // Quake string (helper class) template class QString final { public: - QString(): m_string(0) {}; + QString(): m_string(iStringNull) {}; QString(T string): m_string(string) {}; + bool IsEmpty() const; bool operator==(T string) const; bool operator==(const QString &s) const; bool operator==(const char *pszString) const; @@ -65,6 +68,12 @@ extern globalvars_t *gpGlobals; #define MAKE_STRING(str) ((unsigned int)(str) - (unsigned int)(STRING(0))) // Inlines +template +inline bool QString::IsEmpty() const +{ + return m_string == iStringNull; +} + template inline bool QString::operator==(T string) const { diff --git a/regamedll/dlls/util.cpp b/regamedll/dlls/util.cpp index 8d8ecdf6..2c2a52a5 100644 --- a/regamedll/dlls/util.cpp +++ b/regamedll/dlls/util.cpp @@ -1578,7 +1578,7 @@ void UTIL_PrecacheOther(const char *szClassname) edict_t *pent = CREATE_NAMED_ENTITY(MAKE_STRING(szClassname)); if (FNullEnt(pent)) { - ALERT(at_console, "NULL Ent in UTIL_PrecacheOther\n"); + ALERT(at_console, "NULL Ent in UTIL_PrecacheOther classname `%s`\n", szClassname); return; } @@ -1594,7 +1594,7 @@ void UTIL_PrecacheOther(const char *szClassname) void UTIL_RestartOther(const char *szClassname) { CBaseEntity *pEntity = nullptr; - while ((pEntity = UTIL_FindEntityByClassname(pEntity, szClassname)) != nullptr) + while ((pEntity = UTIL_FindEntityByClassname(pEntity, szClassname))) { pEntity->Restart(); } diff --git a/regamedll/dlls/util.h b/regamedll/dlls/util.h index 0869db8c..43ed24a7 100644 --- a/regamedll/dlls/util.h +++ b/regamedll/dlls/util.h @@ -104,7 +104,6 @@ } const EOFFSET eoNullEntity = (EOFFSET)0; // Testing the three types of "entity" for nullity -const string_t iStringNull = (string_t)0; // Testing strings for nullity class UTIL_GroupTrace {