From: TimePath Date: Sun, 19 Jun 2016 08:52:12 +0000 (+1000) Subject: Add serialization primitives X-Git-Tag: xonotic-v0.8.2~776 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f197e605a3569ee2f9ecffcdbbca0a674197524f;p=xonotic%2Fxonotic-data.pk3dir.git Add serialization primitives --- diff --git a/qcsrc/lib/net.qh b/qcsrc/lib/net.qh index 4e09d4b01..537e04e05 100644 --- a/qcsrc/lib/net.qh +++ b/qcsrc/lib/net.qh @@ -203,6 +203,54 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } } MACRO_END #endif +// serialization: new style + +USING(Stream, int); +#if defined(SVQC) + #define stream_reading(stream) false + #define stream_writing(stream) true +#elif defined(CSQC) + #define stream_reading(stream) true + #define stream_writing(stream) false +#endif + +#define serialize(T, stream, ...) serialize_##T(stream, __VA_ARGS__) + +#if defined(SVQC) + #define serialize_byte(stream, this) \ + MACRO_BEGIN \ + WriteByte(stream, this); \ + MACRO_END +#elif defined(CSQC) + #define serialize_byte(stream, this) \ + MACRO_BEGIN \ + this = ReadByte(); \ + MACRO_END +#endif + +#if defined(SVQC) + #define serialize_float(stream, this) \ + MACRO_BEGIN \ + WriteCoord(stream, this); \ + MACRO_END +#elif defined(CSQC) + #define serialize_float(stream, this) \ + MACRO_BEGIN \ + this = ReadCoord(); \ + MACRO_END +#endif + +#define serialize_vector(stream, this) \ + MACRO_BEGIN \ + vector _v = this; \ + serialize_float(stream, _v.x); \ + serialize_float(stream, _v.y); \ + serialize_float(stream, _v.z); \ + this = _v; \ + MACRO_END + +// serialization: old + #define ReadRegistered(r) r##_from(Read_byte()) #define WriteRegistered(r, to, it) Write_byte(to, it.m_id)