Renamed WriteAngles to WriteAngle. Made use of WriteAngle and WriteVector

This commit is contained in:
Jordan Cristiano 2015-07-13 23:19:55 -04:00
parent fed62e14a4
commit d3b8873481
7 changed files with 35 additions and 46 deletions

View File

@ -33,11 +33,11 @@ void DemoJsonWriter::WriteCmdInfo(base::JsonWriterFile& writer,
writer.StartObject("democmdinfo"); writer.StartObject("democmdinfo");
writer.WriteInt32("flags", split.flags); writer.WriteInt32("flags", split.flags);
WriteVector(writer, "viewOrigin", split.viewOrigin); WriteVector(writer, "viewOrigin", split.viewOrigin);
WriteAngles(writer, "viewAngles", split.viewAngles); WriteAngle(writer, "viewAngles", split.viewAngles);
WriteAngles(writer, "localViewAngles", split.localViewAngles); WriteAngle(writer, "localViewAngles", split.localViewAngles);
WriteVector(writer, "viewOrigin2", split.viewOrigin2); WriteVector(writer, "viewOrigin2", split.viewOrigin2);
WriteAngles(writer, "viewAngles2", split.viewAngles2); WriteAngle(writer, "viewAngles2", split.viewAngles2);
WriteAngles(writer, "localViewAngles2", split.localViewAngles2); WriteAngle(writer, "localViewAngles2", split.localViewAngles2);
writer.EndObject(); writer.EndObject();
} }
@ -59,7 +59,7 @@ void DemoJsonWriter::WriteVector(base::JsonWriterFile& writer, const char* name,
writer.EndObject(); writer.EndObject();
} }
void DemoJsonWriter::WriteAngles(base::JsonWriterFile& writer, const char* name, const QAngle& angles) void DemoJsonWriter::WriteAngle(base::JsonWriterFile& writer, const char* name, const QAngle& angles)
{ {
writer.StartObject(name); writer.StartObject(name);
writer.WriteFloat("pitch", angles.x); writer.WriteFloat("pitch", angles.x);

View File

@ -17,5 +17,5 @@ namespace DemoJsonWriter
void WriteCmdInfo(base::JsonWriterFile& writer, const democmdinfo_t& info); void WriteCmdInfo(base::JsonWriterFile& writer, const democmdinfo_t& info);
void WriteUserCmd(base::JsonWriterFile& writer, int32_t cmdNum, const uint8_t* buffer, int32_t length); void WriteUserCmd(base::JsonWriterFile& writer, int32_t cmdNum, const uint8_t* buffer, int32_t length);
void WriteVector(base::JsonWriterFile& writer, const char* name, const Vector& vec); void WriteVector(base::JsonWriterFile& writer, const char* name, const Vector& vec);
void WriteAngles(base::JsonWriterFile& writer, const char* name, const QAngle& angles); void WriteAngle(base::JsonWriterFile& writer, const char* name, const QAngle& angle);
}; }

View File

@ -2,6 +2,7 @@
#include "svc_bspdecal.h" #include "svc_bspdecal.h"
#include "base/bitfile.h" #include "base/bitfile.h"
#include "base/jsonfile.h" #include "base/jsonfile.h"
#include "demofile/demojson.h"
#include "netcontants.h" #include "netcontants.h"
namespace NetHandlers namespace NetHandlers
@ -50,11 +51,7 @@ namespace NetHandlers
bool SVC_BSPDecal_JsonWrite_Internal(JsonWrite& jsonbuf, const SourceGameContext& context, NetMsg::SVC_BSPDecal* data) bool SVC_BSPDecal_JsonWrite_Internal(JsonWrite& jsonbuf, const SourceGameContext& context, NetMsg::SVC_BSPDecal* data)
{ {
jsonbuf.StartObject("svc_bspdecal"); jsonbuf.StartObject("svc_bspdecal");
jsonbuf.StartObject("position"); DemoJsonWriter::WriteVector(jsonbuf, "position", data->position);
jsonbuf.WriteFloat("x", data->position.x);
jsonbuf.WriteFloat("y", data->position.y);
jsonbuf.WriteFloat("z", data->position.z);
jsonbuf.EndObject();
jsonbuf.WriteUInt32("decalTextureIndex", data->decalTextureIndex); jsonbuf.WriteUInt32("decalTextureIndex", data->decalTextureIndex);
jsonbuf.WriteUInt32("entIndex", data->entIndex); jsonbuf.WriteUInt32("entIndex", data->entIndex);
jsonbuf.WriteUInt32("modelIndex", data->modelIndex); jsonbuf.WriteUInt32("modelIndex", data->modelIndex);

View File

@ -2,23 +2,24 @@
#include "svc_crosshairangle.h" #include "svc_crosshairangle.h"
#include "base/bitfile.h" #include "base/bitfile.h"
#include "base/jsonfile.h" #include "base/jsonfile.h"
#include "demofile/demojson.h"
#include <iomanip> #include <iomanip>
namespace NetHandlers namespace NetHandlers
{ {
bool SVC_CrosshairAngle_BitRead_Internal(BitRead& bitbuf, SourceGameContext& context, NetMsg::SVC_CrosshairAngle* data) bool SVC_CrosshairAngle_BitRead_Internal(BitRead& bitbuf, SourceGameContext& context, NetMsg::SVC_CrosshairAngle* data)
{ {
data->x = bitbuf.ReadBitAngle(16); data->angle.x = bitbuf.ReadBitAngle(16);
data->y = bitbuf.ReadBitAngle(16); data->angle.y = bitbuf.ReadBitAngle(16);
data->z = bitbuf.ReadBitAngle(16); data->angle.z = bitbuf.ReadBitAngle(16);
return !bitbuf.IsOverflowed(); return !bitbuf.IsOverflowed();
} }
bool SVC_CrosshairAngle_BitWrite_Internal(BitWrite& bitbuf, const SourceGameContext& context, NetMsg::SVC_CrosshairAngle* data) bool SVC_CrosshairAngle_BitWrite_Internal(BitWrite& bitbuf, const SourceGameContext& context, NetMsg::SVC_CrosshairAngle* data)
{ {
bitbuf.WriteBitAngle(data->x, 16); bitbuf.WriteBitAngle(data->angle.x, 16);
bitbuf.WriteBitAngle(data->y, 16); bitbuf.WriteBitAngle(data->angle.y, 16);
bitbuf.WriteBitAngle(data->z, 16); bitbuf.WriteBitAngle(data->angle.z, 16);
return !bitbuf.IsOverflowed(); return !bitbuf.IsOverflowed();
} }
@ -30,11 +31,7 @@ namespace NetHandlers
bool SVC_CrosshairAngle_JsonWrite_Internal(JsonWrite& jsonbuf, const SourceGameContext& context, NetMsg::SVC_CrosshairAngle* data) bool SVC_CrosshairAngle_JsonWrite_Internal(JsonWrite& jsonbuf, const SourceGameContext& context, NetMsg::SVC_CrosshairAngle* data)
{ {
jsonbuf.StartObject("svc_crosshairangle"); jsonbuf.StartObject("svc_crosshairangle");
jsonbuf.StartObject("angle"); DemoJsonWriter::WriteAngle(jsonbuf, "angle", data->angle);
jsonbuf.WriteFloat("pitch", data->x);
jsonbuf.WriteFloat("yaw", data->y);
jsonbuf.WriteFloat("roll", data->z);
jsonbuf.EndObject();
jsonbuf.EndObject(); jsonbuf.EndObject();
return true; return true;
} }
@ -44,9 +41,9 @@ namespace NetHandlers
const std::streamsize oldPrecision = out.precision(); const std::streamsize oldPrecision = out.precision();
out << "svc_CrosshairAngle:" out << "svc_CrosshairAngle:"
<< std::setprecision(1) << std::fixed << std::setprecision(1) << std::fixed
<< " (" << data->x << " (" << data->angle.x
<< " " << data->y << " " << data->angle.y
<< " " << data->z << ")" << " " << data->angle.z << ")"
<< std::setprecision(oldPrecision); << std::setprecision(oldPrecision);
out.unsetf(std::ios_base::floatfield); out.unsetf(std::ios_base::floatfield);
} }

View File

@ -2,14 +2,13 @@
#pragma once #pragma once
#include "nethandlers.h" #include "nethandlers.h"
#include "sourcesdk/vector.h"
namespace NetMsg namespace NetMsg
{ {
struct SVC_CrosshairAngle struct SVC_CrosshairAngle
{ {
float x; QAngle angle;
float y;
float z;
}; };
} }

View File

@ -2,6 +2,7 @@
#include "svc_fixangle.h" #include "svc_fixangle.h"
#include "base/bitfile.h" #include "base/bitfile.h"
#include "base/jsonfile.h" #include "base/jsonfile.h"
#include "demofile/demojson.h"
#include <iomanip> #include <iomanip>
namespace NetHandlers namespace NetHandlers
@ -9,18 +10,18 @@ namespace NetHandlers
bool SVC_FixAngle_BitRead_Internal(BitRead& bitbuf, SourceGameContext& context, NetMsg::SVC_FixAngle* data) bool SVC_FixAngle_BitRead_Internal(BitRead& bitbuf, SourceGameContext& context, NetMsg::SVC_FixAngle* data)
{ {
data->relative = bitbuf.ReadOneBit() != 0; data->relative = bitbuf.ReadOneBit() != 0;
data->x = bitbuf.ReadBitAngle(16); data->angle.x = bitbuf.ReadBitAngle(16);
data->y = bitbuf.ReadBitAngle(16); data->angle.y = bitbuf.ReadBitAngle(16);
data->z = bitbuf.ReadBitAngle(16); data->angle.z = bitbuf.ReadBitAngle(16);
return !bitbuf.IsOverflowed(); return !bitbuf.IsOverflowed();
} }
bool SVC_FixAngle_BitWrite_Internal(BitWrite& bitbuf, const SourceGameContext& context, NetMsg::SVC_FixAngle* data) bool SVC_FixAngle_BitWrite_Internal(BitWrite& bitbuf, const SourceGameContext& context, NetMsg::SVC_FixAngle* data)
{ {
bitbuf.WriteOneBit(data->relative); bitbuf.WriteOneBit(data->relative);
bitbuf.WriteBitAngle(data->x, 16); bitbuf.WriteBitAngle(data->angle.x, 16);
bitbuf.WriteBitAngle(data->y, 16); bitbuf.WriteBitAngle(data->angle.y, 16);
bitbuf.WriteBitAngle(data->z, 16); bitbuf.WriteBitAngle(data->angle.z, 16);
return !bitbuf.IsOverflowed(); return !bitbuf.IsOverflowed();
} }
@ -33,11 +34,7 @@ namespace NetHandlers
{ {
jsonbuf.StartObject("svc_fixangle"); jsonbuf.StartObject("svc_fixangle");
jsonbuf.WriteBool("relative", data->relative); jsonbuf.WriteBool("relative", data->relative);
jsonbuf.StartObject("angle"); DemoJsonWriter::WriteAngle(jsonbuf, "angle", data->angle);
jsonbuf.WriteFloat("pitch", data->x);
jsonbuf.WriteFloat("yaw", data->y);
jsonbuf.WriteFloat("roll", data->z);
jsonbuf.EndObject();
jsonbuf.EndObject(); jsonbuf.EndObject();
return true; return true;
} }
@ -47,9 +44,9 @@ namespace NetHandlers
const std::streamsize oldPrecision = out.precision(); const std::streamsize oldPrecision = out.precision();
out << "svc_FixAngle: " << (data->relative ? "relative" : "absolute") out << "svc_FixAngle: " << (data->relative ? "relative" : "absolute")
<< std::setprecision(1) << std::fixed << std::setprecision(1) << std::fixed
<< " " << data->x << " " << data->angle.x
<< " " << data->y << " " << data->angle.y
<< " " << data->z << " " << data->angle.z
<< std::setprecision(oldPrecision); << std::setprecision(oldPrecision);
out.unsetf(std::ios_base::floatfield); out.unsetf(std::ios_base::floatfield);
} }

View File

@ -2,15 +2,14 @@
#pragma once #pragma once
#include "nethandlers.h" #include "nethandlers.h"
#include "sourcesdk/vector.h"
namespace NetMsg namespace NetMsg
{ {
struct SVC_FixAngle struct SVC_FixAngle
{ {
bool relative; bool relative;
float x; QAngle angle;
float y;
float z;
}; };
} }