Minor refactoring qstring.h

This commit is contained in:
s1lent 2017-10-13 07:04:37 +07:00 committed by Dmitry Novikov
parent e52f307950
commit e88dae7bb9
10 changed files with 347 additions and 361 deletions

View File

@ -36,7 +36,7 @@ void CItemAirBox::Spawn()
pev->movetype = MOVETYPE_NOCLIP;
if (!m_iszSpriteName.IsEmpty())
if (!m_iszSpriteName.IsNull())
{
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);
@ -75,7 +75,7 @@ void CItemAirBox::Precache()
{
CArmoury::Precache();
if (!m_iszSpriteName.IsEmpty()) {
if (!m_iszSpriteName.IsNull()) {
PRECACHE_MODEL(m_iszSpriteName);
}
}

View File

@ -26,6 +26,8 @@
*
*/
#pragma once
class CItemAirBox: public CArmoury {
public:
void Spawn();

View File

@ -26,6 +26,8 @@
*
*/
#pragma once
#include "precompiled.h"
#define SF_SETORIGIN_CONST_UPDATE BIT(0) // The entity will constantly update position if set

View File

@ -1447,7 +1447,7 @@ void CBaseEntity::SUB_FadeOut()
void OnFreeEntPrivateData(edict_t *pEnt)
{
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE(pEnt);
CBaseEntity *pEntity = GET_PRIVATE<CBaseEntity>(pEnt);
if (!pEntity)
return;

File diff suppressed because it is too large Load Diff

View File

@ -950,7 +950,6 @@ void packPlayerItem(CBasePlayer *pPlayer, CBasePlayerItem *pItem, bool packAmmo)
bool CanSeeUseable(CBasePlayer *me, CBaseEntity *entity);
void FixPlayerCrouchStuck(edict_t *pPlayer);
BOOL IsSpawnPointValid(CBaseEntity *pPlayer, CBaseEntity *pSpot);
CBaseEntity *FindZombieSpawn(CBaseEntity *player, bool forceSpawn);
CBaseEntity *FindEntityForward(CBaseEntity *pMe);
float_precision GetPlayerPitch(const edict_t *pEdict);
float_precision GetPlayerYaw(const edict_t *pEdict);

View File

@ -30,19 +30,25 @@
#define QSTRING_DEFINE
constexpr auto iStringNull = 0u;
constexpr unsigned int iStringNull = {0};
// Quake string (helper class)
template <typename T = unsigned int>
class QString final
{
public:
QString(): m_string(iStringNull) {};
QString(T string): m_string(string) {};
using qstring_t = unsigned int;
bool IsEmpty() const;
bool operator==(T string) const;
bool operator==(const QString<T> &s) const;
QString(): m_string(iStringNull) {};
QString(qstring_t string): m_string(string) {};
bool IsNull() const;
bool IsNullOrEmpty() const;
// Copy the array
QString &operator=(const QString &other);
bool operator==(qstring_t string) const;
bool operator==(const QString &s) const;
bool operator==(const char *pszString) const;
operator const char *() const;
@ -50,11 +56,11 @@ public:
const char *str() const;
private:
T m_string;
qstring_t m_string;
};
#ifdef USE_QSTRING
#define string_t QString<>
#define string_t QString
#endif
#include "const.h"
@ -68,44 +74,48 @@ extern globalvars_t *gpGlobals;
#define MAKE_STRING(str) ((unsigned int)(str) - (unsigned int)(STRING(0)))
// Inlines
template <typename T>
inline bool QString<T>::IsEmpty() const
inline bool QString::IsNull() const
{
return m_string == iStringNull;
}
template <typename T>
inline bool QString<T>::operator==(T string) const
inline bool QString::IsNullOrEmpty() const
{
return IsNull() || (&gpGlobals->pStringBase[m_string])[0] == '\0';
}
inline QString &QString::operator=(const QString &other)
{
m_string = other.m_string;
return (*this);
}
inline bool QString::operator==(qstring_t string) const
{
return m_string == string;
}
template <typename T>
inline bool QString<T>::operator==(const QString<T> &s) const
inline bool QString::operator==(const QString &s) const
{
return m_string == s.m_string;
}
template <typename T>
inline bool QString<T>::operator==(const char *pszString) const
inline bool QString::operator==(const char *pszString) const
{
return FStrEq(&gpGlobals->pStringBase[m_string], pszString);
return Q_strcmp(&gpGlobals->pStringBase[m_string], pszString) == 0;
}
template <typename T>
inline const char *QString<T>::str() const
inline const char *QString::str() const
{
return &gpGlobals->pStringBase[m_string];
}
template <typename T>
inline QString<T>::operator const char *() const
inline QString::operator const char *() const
{
return str();
}
template <typename T>
inline QString<T>::operator unsigned int() const
inline QString::operator unsigned int() const
{
return m_string;
}

View File

@ -1547,20 +1547,14 @@ void UTIL_Remove(CBaseEntity *pEntity)
if (!pEntity)
return;
#if 0
// TODO: Some safe checks.
if (pEntity == VARS(eoNullEntity))
#ifdef REGAMEDLL_FIXES
if (pEntity->pev == VARS(eoNullEntity) || pEntity->IsPlayer() || (pEntity->pev->flags & FL_KILLME) == FL_KILLME)
return;
if (pEntity->IsPlayer())
{
pEntity->pev->health = 1.0f;
pEntity->TakeDamage(VARS(eoNullEntity), VARS(eoNullEntity), 9999, DMG_ALWAYSGIB);
return;
}
#endif
pEntity->UpdateOnRemove();
pEntity->pev->solid = SOLID_NOT;
pEntity->pev->flags |= FL_KILLME;
pEntity->pev->targetname = 0;
}

View File

@ -38,36 +38,36 @@ public:
Vector2D(const Vector2D &v) { *(int *)&x = *(int *)&v.x; *(int *)&y = *(int *)&v.y; }
// Operators
inline decltype(auto) operator-() const { return Vector2D(-x, -y); }
inline bool operator==(const Vector2D &v) const { return x == v.x && y == v.y; }
inline bool operator!=(const Vector2D &v) const { return !(*this == v); }
decltype(auto) operator-() const { return Vector2D(-x, -y); }
bool operator==(const Vector2D &v) const { return x == v.x && y == v.y; }
bool operator!=(const Vector2D &v) const { return !(*this == v); }
inline decltype(auto) operator+(const Vector2D &v) const { return Vector2D(x + v.x, y + v.y); }
inline decltype(auto) operator-(const Vector2D &v) const { return Vector2D(x - v.x, y - v.y); }
inline decltype(auto) operator*(const Vector2D &v) const { return Vector2D(x * v.x, y * v.y); }
inline decltype(auto) operator/(const Vector2D &v) const { return Vector2D(x / v.x, y / v.y); }
decltype(auto) operator+(const Vector2D &v) const { return Vector2D(x + v.x, y + v.y); }
decltype(auto) operator-(const Vector2D &v) const { return Vector2D(x - v.x, y - v.y); }
decltype(auto) operator*(const Vector2D &v) const { return Vector2D(x * v.x, y * v.y); }
decltype(auto) operator/(const Vector2D &v) const { return Vector2D(x / v.x, y / v.y); }
inline decltype(auto) operator+=(const Vector2D &v) { return (*this = *this + v); }
inline decltype(auto) operator-=(const Vector2D &v) { return (*this = *this - v); }
inline decltype(auto) operator*=(const Vector2D &v) { return (*this = *this * v); }
inline decltype(auto) operator/=(const Vector2D &v) { return (*this = *this / v); }
decltype(auto) operator+=(const Vector2D &v) { return (*this = *this + v); }
decltype(auto) operator-=(const Vector2D &v) { return (*this = *this - v); }
decltype(auto) operator*=(const Vector2D &v) { return (*this = *this * v); }
decltype(auto) operator/=(const Vector2D &v) { return (*this = *this / v); }
inline decltype(auto) operator+(float fl) const { return Vector2D(x + fl, y + fl); }
inline decltype(auto) operator-(float fl) const { return Vector2D(x - fl, y - fl); }
decltype(auto) operator+(float fl) const { return Vector2D(x + fl, y + fl); }
decltype(auto) operator-(float fl) const { return Vector2D(x - fl, y - fl); }
// TODO: FIX ME!!
#ifdef PLAY_GAMEDLL
inline decltype(auto) operator*(float fl) const { return Vector2D(vec_t(x * fl), vec_t(y * fl)); }
inline decltype(auto) operator/(float fl) const { return Vector2D(vec_t(x / fl), vec_t(y / fl)); }
decltype(auto) operator*(float fl) const { return Vector2D(vec_t(x * fl), vec_t(y * fl)); }
decltype(auto) operator/(float fl) const { return Vector2D(vec_t(x / fl), vec_t(y / fl)); }
#else
inline decltype(auto) operator*(float fl) const { return Vector2D(x * fl, y * fl); }
inline decltype(auto) operator/(float fl) const { return Vector2D(x / fl, y / fl); }
decltype(auto) operator*(float fl) const { return Vector2D(x * fl, y * fl); }
decltype(auto) operator/(float fl) const { return Vector2D(x / fl, y / fl); }
#endif
inline decltype(auto) operator+=(float fl) { return (*this = *this + fl); }
inline decltype(auto) operator-=(float fl) { return (*this = *this - fl); }
inline decltype(auto) operator*=(float fl) { return (*this = *this * fl); }
inline decltype(auto) operator/=(float fl) { return (*this = *this / fl); }
decltype(auto) operator+=(float fl) { return (*this = *this + fl); }
decltype(auto) operator-=(float fl) { return (*this = *this - fl); }
decltype(auto) operator*=(float fl) { return (*this = *this * fl); }
decltype(auto) operator/=(float fl) { return (*this = *this / fl); }
// Methods
inline void CopyToArray(float *rgfl) const { *(int *)&rgfl[0] = *(int *)&x; *(int *)&rgfl[1] = *(int *)&y; }
@ -140,36 +140,36 @@ public:
Vector(const float rgfl[3]) { *(int *)&x = *(int *)&rgfl[0]; *(int *)&y = *(int *)&rgfl[1]; *(int *)&z = *(int *)&rgfl[2]; }
// Operators
inline decltype(auto) operator-() const { return Vector(-x, -y, -z); }
inline bool operator==(const Vector &v) const { return x == v.x && y == v.y && z == v.z; }
inline bool operator!=(const Vector &v) const { return !(*this == v); }
decltype(auto) operator-() const { return Vector(-x, -y, -z); }
bool operator==(const Vector &v) const { return x == v.x && y == v.y && z == v.z; }
bool operator!=(const Vector &v) const { return !(*this == v); }
inline decltype(auto) operator+(const Vector &v) const { return Vector(x + v.x, y + v.y, z + v.z); }
inline decltype(auto) operator-(const Vector &v) const { return Vector(x - v.x, y - v.y, z - v.z); }
inline decltype(auto) operator*(const Vector &v) const { return Vector(x * v.x, y * v.y, z * v.z); }
inline decltype(auto) operator/(const Vector &v) const { return Vector(x / v.x, y / v.y, z / v.z); }
decltype(auto) operator+(const Vector &v) const { return Vector(x + v.x, y + v.y, z + v.z); }
decltype(auto) operator-(const Vector &v) const { return Vector(x - v.x, y - v.y, z - v.z); }
decltype(auto) operator*(const Vector &v) const { return Vector(x * v.x, y * v.y, z * v.z); }
decltype(auto) operator/(const Vector &v) const { return Vector(x / v.x, y / v.y, z / v.z); }
inline decltype(auto) operator+=(const Vector &v) { return (*this = *this + v); }
inline decltype(auto) operator-=(const Vector &v) { return (*this = *this - v); }
inline decltype(auto) operator*=(const Vector &v) { return (*this = *this * v); }
inline decltype(auto) operator/=(const Vector &v) { return (*this = *this / v); }
decltype(auto) operator+=(const Vector &v) { return (*this = *this + v); }
decltype(auto) operator-=(const Vector &v) { return (*this = *this - v); }
decltype(auto) operator*=(const Vector &v) { return (*this = *this * v); }
decltype(auto) operator/=(const Vector &v) { return (*this = *this / v); }
inline decltype(auto) operator+(float fl) const { return Vector(x + fl, y + fl, z + fl); }
inline decltype(auto) operator-(float fl) const { return Vector(x - fl, y - fl, z - fl); }
decltype(auto) operator+(float fl) const { return Vector(x + fl, y + fl, z + fl); }
decltype(auto) operator-(float fl) const { return Vector(x - fl, y - fl, z - fl); }
// TODO: FIX ME!!
#ifdef PLAY_GAMEDLL
inline decltype(auto) operator*(float fl) const { return Vector(vec_t(x * fl), vec_t(y * fl), vec_t(z * fl)); }
inline decltype(auto) operator/(float fl) const { return Vector(vec_t(x / fl), vec_t(y / fl), vec_t(z / fl)); }
decltype(auto) operator*(float fl) const { return Vector(vec_t(x * fl), vec_t(y * fl), vec_t(z * fl)); }
decltype(auto) operator/(float fl) const { return Vector(vec_t(x / fl), vec_t(y / fl), vec_t(z / fl)); }
#else
inline decltype(auto) operator*(float fl) const { return Vector(x * fl, y * fl, z * fl); }
inline decltype(auto) operator/(float fl) const { return Vector(x / fl, y / fl, z / fl); }
decltype(auto) operator*(float fl) const { return Vector(x * fl, y * fl, z * fl); }
decltype(auto) operator/(float fl) const { return Vector(x / fl, y / fl, z / fl); }
#endif
inline decltype(auto) operator+=(float fl) { return (*this = *this + fl); }
inline decltype(auto) operator-=(float fl) { return (*this = *this - fl); }
inline decltype(auto) operator*=(float fl) { return (*this = *this * fl); }
inline decltype(auto) operator/=(float fl) { return (*this = *this / fl); }
decltype(auto) operator+=(float fl) { return (*this = *this + fl); }
decltype(auto) operator-=(float fl) { return (*this = *this - fl); }
decltype(auto) operator*=(float fl) { return (*this = *this * fl); }
decltype(auto) operator/=(float fl) { return (*this = *this / fl); }
void CopyToArray(float *rgfl) const
{

View File

@ -118,7 +118,7 @@ enum NavRelativeDirType
NUM_RELATIVE_DIRECTIONS
};
const double GenerationStepSize = 25.0; // (30) was 20, but bots can't fit always fit
const double GenerationStepSize = 25.0; // (30) was 20, but bots can't always fit
const float StepHeight = 18.0f; // if delta Z is greater than this, we have to jump to get up
const float JumpHeight = 41.8f; // if delta Z is less than this, we can jump up on it
const float JumpCrouchHeight = 58.0f; // (48) if delta Z is less than or equal to this, we can jumpcrouch up on it