Skip to content

Commit

Permalink
Server: WRITE_FLOAT, remove type punning with union
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedSnark committed May 28, 2024
1 parent 40354d9 commit 61ba8fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
13 changes: 13 additions & 0 deletions src/game/server/enginecallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ inline void MESSAGE_BEGIN(int msg_dest, int msg_type, const float *pOrigin = NUL
#define WRITE_COORD (*g_engfuncs.pfnWriteCoord)
#define WRITE_STRING (*g_engfuncs.pfnWriteString)
#define WRITE_ENTITY (*g_engfuncs.pfnWriteEntity)

inline void WRITE_FLOAT(float val)
{
char bytes[sizeof(val)];
std::memcpy(bytes, &val, sizeof(bytes));

for (int i = 0; i < sizeof(bytes); i++)
{
g_engfuncs.pfnWriteByte(bytes[i]);
}
}

#define CVAR_REGISTER (*g_engfuncs.pfnCVarRegister)
#define CVAR_GET_FLOAT (*g_engfuncs.pfnCVarGetFloat)
#define CVAR_GET_STRING (*g_engfuncs.pfnCVarGetString)
Expand All @@ -91,6 +103,7 @@ inline void MESSAGE_BEGIN(int msg_dest, int msg_type, const float *pOrigin = NUL
#define ALERT (*g_engfuncs.pfnAlertMessage)
#define ENGINE_FPRINTF (*g_engfuncs.pfnEngineFprintf)
#define ALLOC_PRIVATE (*g_engfuncs.pfnPvAllocEntPrivateData)

inline void *GET_PRIVATE(edict_t *pent)
{
if (pent)
Expand Down
14 changes: 1 addition & 13 deletions src/game/server/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4105,23 +4105,11 @@ void CBasePlayer ::UpdateClientData(void)
int g = clamp(int(pFog->pev->rendercolor[1]), 0, 255);
int b = clamp(int(pFog->pev->rendercolor[2]), 0, 255);

union
{
float f;
char b[4];

} density;

density.f = pFog->m_fDensity;

MESSAGE_BEGIN(MSG_ONE, gmsgFog, nullptr, pev);
WRITE_BYTE(r);
WRITE_BYTE(g);
WRITE_BYTE(b);
WRITE_BYTE(density.b[0]);
WRITE_BYTE(density.b[1]);
WRITE_BYTE(density.b[2]);
WRITE_BYTE(density.b[3]);
WRITE_FLOAT(pFog->m_fDensity);
MESSAGE_END();
}

Expand Down

0 comments on commit 61ba8fc

Please sign in to comment.