demboyz/demboyz/netmessages/svc_fixangle.cpp

57 lines
1.9 KiB
C++
Raw Normal View History

#include "svc_fixangle.h"
#include "base/bitfile.h"
#include "base/jsonfile.h"
#include <iomanip>
namespace NetHandlers
{
bool SVC_FixAngle_BitRead_Internal(BitRead& bitbuf, SourceGameContext& context, NetMsg::SVC_FixAngle* data)
{
data->relative = bitbuf.ReadOneBit() != 0;
data->x = bitbuf.ReadBitAngle(16);
data->y = bitbuf.ReadBitAngle(16);
data->z = bitbuf.ReadBitAngle(16);
return !bitbuf.IsOverflowed();
}
bool SVC_FixAngle_BitWrite_Internal(BitWrite& bitbuf, const SourceGameContext& context, NetMsg::SVC_FixAngle* data)
{
bitbuf.WriteOneBit(data->relative);
bitbuf.WriteBitAngle(data->x, 16);
bitbuf.WriteBitAngle(data->y, 16);
bitbuf.WriteBitAngle(data->z, 16);
return !bitbuf.IsOverflowed();
}
bool SVC_FixAngle_JsonRead_Internal(JsonRead& jsonbuf, SourceGameContext& context, NetMsg::SVC_FixAngle* data)
{
return true;
}
bool SVC_FixAngle_JsonWrite_Internal(JsonWrite& jsonbuf, const SourceGameContext& context, NetMsg::SVC_FixAngle* data)
{
jsonbuf.StartObject("svc_fixangle");
jsonbuf.WriteBool("relative", data->relative);
jsonbuf.StartObject("angle");
jsonbuf.WriteFloat("pitch", data->x);
jsonbuf.WriteFloat("yaw", data->y);
jsonbuf.WriteFloat("roll", data->z);
jsonbuf.EndObject();
jsonbuf.EndObject();
return true;
}
void SVC_FixAngle_ToString_Internal(std::ostringstream& out, NetMsg::SVC_FixAngle* data)
{
const std::streamsize oldPrecision = out.precision();
out << "svc_FixAngle: " << (data->relative ? "relative" : "absolute")
<< std::setprecision(1) << std::fixed
<< " " << data->x
<< " " << data->y
<< " " << data->z
<< std::setprecision(oldPrecision);
out.unsetf(std::ios_base::floatfield);
}
}