X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fnet.qh;h=56c80e02d1b13ca5dcf66105aa597bb7c28d67f3;hb=d492869ab1f18e05121529b7bcffcb637d13994c;hp=4e09d4b01043363a619153154f90dd08baf5ba6d;hpb=3220cab5a7b69ced4a641504a6a5f4eccf2d3bfc;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/net.qh b/qcsrc/lib/net.qh index 4e09d4b01..56c80e02d 100644 --- a/qcsrc/lib/net.qh +++ b/qcsrc/lib/net.qh @@ -98,6 +98,9 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } .int Version; // deprecated, use SendFlags .int SendFlags; + IntrusiveList g_uncustomizables; + STATIC_INIT(g_uncustomizables) { g_uncustomizables = IL_NEW(); } + void Net_LinkEntity(entity e, bool docull, float dt, bool(entity this, entity to, int sendflags) sendfunc) { if (e.classname == "") e.classname = "net_linked"; @@ -130,16 +133,18 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } .void(entity this) uncustomizeentityforclient; .float uncustomizeentityforclient_set; - void SetCustomizer(entity e, bool(entity this) customizer, void(entity this) uncustomizer) + void SetCustomizer(entity e, bool(entity this, entity client) customizer, void(entity this) uncustomizer) { setcefc(e, customizer); e.uncustomizeentityforclient = uncustomizer; e.uncustomizeentityforclient_set = !!uncustomizer; + if(uncustomizer) + IL_PUSH(g_uncustomizables, e); } void UncustomizeEntitiesRun() { - FOREACH_ENTITY_FLOAT(uncustomizeentityforclient_set, true, it.uncustomizeentityforclient(it)); + IL_EACH(g_uncustomizables, it.uncustomizeentityforclient_set, it.uncustomizeentityforclient(it)); } STRING_ITERATOR(g_buf, string_null, 0); @@ -156,13 +161,13 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } { entity reader = C2S_Protocol_from(C2S); if (reader && reader.m_read && reader.m_read(NULL, sender, true)) continue; - LOG_SEVEREF("Net_ClientCommand() with malformed C2S=%d\n", C2S); + LOG_SEVEREF("Net_ClientCommand() with malformed C2S=%d", C2S); return; } g_buf_i--; int expected = strlen(buf); - if (g_buf_i > expected) LOG_WARNINGF("Underflow: %d", g_buf_i - expected); - if (g_buf_i < expected) LOG_WARNINGF("Overrflow: %d", expected - g_buf_i); + if (g_buf_i > expected) LOG_WARNF("Underflow: %d", g_buf_i - expected); + if (g_buf_i < expected) LOG_WARNF("Overrflow: %d", expected - g_buf_i); } #endif @@ -176,7 +181,7 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } } MACRO_END #define Net_Reject() \ MACRO_BEGIN { \ - if (this) remove(this); \ + if (this) delete(this); \ } MACRO_END string g_buf; @@ -203,6 +208,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) @@ -239,12 +292,13 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } #define Read_string() ReadString() #define Write_string(to, f) WriteString(to, f) -#ifndef MENUQC +#ifdef GAMEQC const float APPROXPASTTIME_ACCURACY_REQUIREMENT = 0.05; #define APPROXPASTTIME_MAX (16384 * APPROXPASTTIME_ACCURACY_REQUIREMENT) #define APPROXPASTTIME_RANGE (64 * APPROXPASTTIME_ACCURACY_REQUIREMENT) #ifdef CSQC + float servertime; entity ReadCSQCEntity() { int f = ReadShort(); @@ -260,7 +314,7 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } #define ReadInt48_t() vec3(ReadInt24_t(), ReadInt24_t(), 0) #define ReadInt72_t() vec3(ReadInt24_t(), ReadInt24_t(), ReadInt24_t()) - int _ReadSByte; + noref int _ReadSByte; #define ReadSByte() (_ReadSByte = ReadByte(), (_ReadSByte & BIT(7) ? -128 : 0) + (_ReadSByte & BITS(7))) #define ReadFloat() ReadCoord() #define ReadVector() vec3(ReadFloat(), ReadFloat(), ReadFloat())