2
0
mirror of https://github.com/rehlds/metamod-r.git synced 2024-12-27 23:25:36 +03:00
metamod-r/metamod/src/sdk_util.cpp

65 lines
1.5 KiB
C++
Raw Normal View History

2016-07-26 03:22:47 +03:00
#include "precompiled.h"
2017-05-09 19:31:09 +03:00
char* UTIL_VarArgs(const char* format, ...)
2016-07-26 03:22:47 +03:00
{
2016-07-26 19:31:47 +03:00
va_list argptr;
static char string[1024];
2016-07-26 03:22:47 +03:00
va_start(argptr, format);
2017-01-17 00:30:02 +03:00
Q_vsnprintf(string, sizeof string, format, argptr);
2016-07-26 03:22:47 +03:00
va_end(argptr);
return string;
}
short FixedSigned16(float value, float scale)
2016-07-26 03:22:47 +03:00
{
2017-11-18 18:53:18 +03:00
return (short)Q_clamp(int(value * scale), SHRT_MIN, SHRT_MAX);
}
unsigned short FixedUnsigned16(float value, float scale)
{
2017-11-18 18:53:18 +03:00
return (unsigned short)Q_clamp(int(value * scale), 0, USHRT_MAX);
}
2017-05-09 19:31:09 +03:00
void UTIL_HudMessage(edict_t* pEntity, const hudtextparms_t& textparms, const char* pMessage)
{
if (FNullEnt(pEntity) || pEntity->free)
return;
2017-05-05 19:36:56 +03:00
MESSAGE_BEGIN(MSG_ONE, SVC_TEMPENTITY, nullptr, pEntity);
WRITE_BYTE(TE_TEXTMESSAGE);
WRITE_BYTE(textparms.channel & 0xFF);
WRITE_SHORT(FixedSigned16(textparms.x, 1 << 13));
WRITE_SHORT(FixedSigned16(textparms.y, 1 << 13));
WRITE_BYTE(textparms.effect);
WRITE_BYTE(textparms.r1);
WRITE_BYTE(textparms.g1);
WRITE_BYTE(textparms.b1);
WRITE_BYTE(textparms.a1);
WRITE_BYTE(textparms.r2);
WRITE_BYTE(textparms.g2);
WRITE_BYTE(textparms.b2);
WRITE_BYTE(textparms.a2);
WRITE_SHORT(FixedUnsigned16(textparms.fadeinTime, 1 << 8));
WRITE_SHORT(FixedUnsigned16(textparms.fadeoutTime, 1 << 8));
WRITE_SHORT(FixedUnsigned16(textparms.holdTime, 1 << 8));
if (textparms.effect == 2)
2017-05-09 19:31:09 +03:00
WRITE_SHORT(FixedUnsigned16(textparms.fxTime, 1 << 8));
2016-07-26 03:22:47 +03:00
2017-11-18 18:53:18 +03:00
if (Q_strlen(pMessage) < 512) {
WRITE_STRING(pMessage);
}
else {
char tmp[512];
2017-11-18 18:53:18 +03:00
Q_strlcpy(tmp, pMessage);
WRITE_STRING(tmp);
}
MESSAGE_END();
2016-07-26 03:22:47 +03:00
}