]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/net.qh
Add missing SELFPARAM()
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / net.qh
index d870ef1f9639ee91b252f64b5da1f3414b5aacb4..47d6af7186144f1dfc41a157ffa7867c3358096a 100644 (file)
@@ -1,5 +1,4 @@
-#ifndef NET_H
-#define NET_H
+#pragma once
 
 #include "registry.qh"
 #include "sort.qh"
@@ -43,8 +42,7 @@ STATIC_INIT(RegisterTempEntities_renumber) { FOREACH(TempEntities, true, it.m_id
                [[accumulate]] NET_HANDLE(id, bool isnew) \
                { \
                        this = self; \
-                       this.sourceLocFile = __FILE__; \
-                       this.sourceLocLine = __LINE__; \
+                       this.sourceLoc = __FILE__ ":" STR(__LINE__); \
                        if (!this) isnew = true; \
                } \
                REGISTER(LinkedEntities, NET, id, m_id, new_pure(net_linked_packet)) \
@@ -103,13 +101,13 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); }
        /** return false to remove from the client */
        .bool(entity this, entity to, int sendflags) SendEntity3;
 
-       bool SendEntity_self(entity to, int sendflags) { return self.SendEntity3(self, to, sendflags); }
+       bool SendEntity_self(entity to, int sendflags) { SELFPARAM(); return this.SendEntity3(this, to, sendflags); }
 
        void Net_LinkEntity(entity e, bool docull, float dt, bool(entity this, entity to, int sendflags) sendfunc)
        {
                if (e.classname == "") e.classname = "net_linked";
 
-               if (e.model == "" || self.modelindex == 0)
+               if (e.model == "" || e.modelindex == 0)
                {
                        vector mi = e.mins;
                        vector ma = e.maxs;
@@ -147,9 +145,8 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); }
 
        void UncustomizeEntitiesRun()
        {
-               FOREACH_ENTITY_FLOAT(uncustomizeentityforclient_set, true, LAMBDA(
-                       WITH(entity, self, it, it.uncustomizeentityforclient());
-               ));
+           SELFPARAM();
+               FOREACH_ENTITY_FLOAT(uncustomizeentityforclient_set, true, WITH(entity, self, it, it.uncustomizeentityforclient()));
        }
 
        STRING_ITERATOR(g_buf, string_null, 0);
@@ -267,28 +264,14 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); }
                        v += ReadByte();          // note: this is unsigned
                        return v;
                }
-               vector ReadInt48_t()
-               {
-                       vector v;
-                       v.x = ReadInt24_t();
-                       v.y = ReadInt24_t();
-                       v.z = 0;
-                       return v;
-               }
-               vector ReadInt72_t()
-               {
-                       vector v;
-                       v.x = ReadInt24_t();
-                       v.y = ReadInt24_t();
-                       v.z = ReadInt24_t();
-                       return v;
-               }
+               #define ReadInt48_t() vec3(ReadInt24_t(), ReadInt24_t(), 0)
+               #define ReadInt72_t() vec3(ReadInt24_t(), ReadInt24_t(), ReadInt24_t())
 
                int _ReadSByte;
                #define ReadSByte() (_ReadSByte = ReadByte(), (_ReadSByte & BIT(7) ? -128 : 0) + (_ReadSByte & BITS(7)))
                #define ReadFloat() ReadCoord()
-        vector ReadVector() { vector v; v.x = ReadFloat(); v.y = ReadFloat(); v.z = ReadFloat(); return v; }
-               vector ReadVector2D() { vector v; v.x = ReadFloat(); v.y = ReadFloat(); v.z = 0; return v; }
+               #define ReadVector() vec3(ReadFloat(), ReadFloat(), ReadFloat())
+               #define ReadVector2D() vec3(ReadFloat(), ReadFloat(), 0)
 
                float ReadApproxPastTime()
                {
@@ -346,21 +329,17 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); }
                }
 
                // allow writing to also pass through to spectators (like so spectators see the same centerprints as players for example)
-               #define WRITESPECTATABLE_MSG_ONE_VARNAME(varname, statement) \
-                       entity varname; varname = msg_entity; \
-                       FOR_EACH_REALCLIENT(msg_entity) \
-                       if (msg_entity == varname || (msg_entity.classname == STR_SPECTATOR && msg_entity.enemy == varname)) \
-                               statement msg_entity = varname
-               #define WRITESPECTATABLE_MSG_ONE(statement) \
-                       MACRO_BEGIN \
-                       { \
-                               WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement); \
-                       } MACRO_END
-               #define WRITESPECTATABLE(msg, statement) \
-                       if (msg == MSG_ONE) WRITESPECTATABLE_MSG_ONE(statement); \
-                       else \
-                               statement float WRITESPECTATABLE_workaround = 0
+               #define WRITESPECTATABLE_MSG_ONE(to, statement) MACRO_BEGIN { \
+                       entity prev = msg_entity; \
+                       entity dst = to; \
+                       FOREACH_CLIENT(IS_REAL_CLIENT(it), { \
+                               if (it == dst || (it.classname == STR_SPECTATOR && it.enemy == dst)) \
+                               { \
+                                       msg_entity = it; \
+                                       LAMBDA(statement); \
+                               } \
+                       }); \
+                       msg_entity = prev; \
+               } MACRO_END
        #endif
 #endif
-
-#endif