]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Net: tempentity support
authorTimePath <andrew.hardaker1995@gmail.com>
Tue, 6 Oct 2015 23:38:30 +0000 (10:38 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Wed, 7 Oct 2015 00:46:28 +0000 (11:46 +1100)
qcsrc/client/main.qc
qcsrc/common/nades/all.qc
qcsrc/lib/net.qh

index e3f07b275c969a6dea7c9d6ff966f985d55f082c..d494050f060b025bb8fc6838ba16a0bf3d98096a 100644 (file)
@@ -835,7 +835,7 @@ void CSQC_Ent_Update(float bIsNewEntity)
 #endif
        self.enttype = t;
        bool done = false;
-       FOREACH(Linked, it.m_id == t, LAMBDA(
+       FOREACH(LinkedEntities, it.m_id == t, LAMBDA(
                it.m_read(self, bIsNewEntity);
                done = true;
                break;
@@ -1266,7 +1266,7 @@ void Net_WeaponComplain()
 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.
 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.
 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.
-float CSQC_Parse_TempEntity()
+bool CSQC_Parse_TempEntity()
 {
        // Acquire TE ID
        int nTEID = ReadByte();
@@ -1274,6 +1274,10 @@ float CSQC_Parse_TempEntity()
        if (autocvar_developer_csqcentities)
                LOG_INFOF("CSQC_Parse_TempEntity() with nTEID=%d\n", nTEID);
 
+       FOREACH(TempEntities, it.m_id == nTEID, LAMBDA(
+               it.m_read(NULL, true);
+               return true;
+       ));
        switch (nTEID)
        {
                case TE_CSQC_MUTATOR:
index 86e6d278b2555741ef4e26ff5720683ae82dfb20..33c1a7e181fb5b57b90ad625bc4a58b39fbc5db0 100644 (file)
@@ -51,9 +51,10 @@ void healer_setup(entity e)
 }
 #endif // CSQC
 
-REGISTER_LINKED(Nade_Heal, bool isNew)
+REGISTER_NET_LINKED(Nade_Heal, bool isNew)
 #ifdef CSQC
 {
+       Net_Accept();
        int sf = ReadByte();
        if (sf & 1) {
                this.origin_x = ReadCoord();
@@ -70,21 +71,22 @@ REGISTER_LINKED(Nade_Heal, bool isNew)
 #endif
 
 #ifdef SVQC
-float healer_send(entity to, int sf)
+bool healer_send(entity to, int sf)
 {
        SELFPARAM();
-       WriteByte(MSG_ENTITY, Linked_Nade_Heal.m_id);
-       WriteByte(MSG_ENTITY, sf);
+       int channel = MSG_ENTITY;
+       WriteHeader(channel, Nade_Heal);
+       WriteByte(channel, sf);
        if (sf & 1) {
-               WriteCoord(MSG_ENTITY, this.origin.x);
-               WriteCoord(MSG_ENTITY, this.origin.y);
-               WriteCoord(MSG_ENTITY, this.origin.z);
+               WriteCoord(channel, this.origin.x);
+               WriteCoord(channel, this.origin.y);
+               WriteCoord(channel, this.origin.z);
 
-               WriteByte(MSG_ENTITY, this.healer_lifetime);
+               WriteByte(channel, this.healer_lifetime);
                //WriteByte(MSG_ENTITY, this.ltime - time + 1);
-               WriteShort(MSG_ENTITY, this.healer_radius);
+               WriteShort(channel, this.healer_radius);
                // round time delta to a 1/10th of a second
-               WriteByte(MSG_ENTITY, (this.ltime - time)*10.0+0.5);
+               WriteByte(channel, (this.ltime - time)*10.0+0.5);
        }
        return true;
 }
index a41fae1443dd0429add1526545d839b33493bc97..ff18f0eaf34594393a1016eda44b3918ff443a5d 100644 (file)
@@ -49,32 +49,67 @@ void UncustomizeEntitiesRun()
 #include "registry.qh"
 #include "sort.qh"
 
-REGISTRY(Linked, 24)
-
 .string netname;
 .int m_id;
 .void(entity this, bool isNew) m_read;
 
 #ifdef CSQC
-    #define REGISTER_LINKED(id, param) \
+    #define Net_Accept() do { if (!this)    this = spawn(); } while (0)
+    #define Net_Reject() do { if (this)     remove(this);   } while (0)
+#else
+    #define WriteHeader(to, id) do { \
+        if (NET_##id##_istemp) WriteByte(to, SVC_TEMPENTITY); \
+        WriteByte(to, NET_##id.m_id); \
+    } while (0)
+#endif
+
+#ifdef CSQC
+    #define REGISTER_NET_LINKED(id, param) \
         void Ent_Read##id(entity this, param) { this = self; } \
-        REGISTER(RegisterLinked, Linked, Linked, Linked_COUNT, id, m_id, spawn()) { \
+        REGISTER(RegisterLinkedEntities, NET, LinkedEntities, LinkedEntities_COUNT, id, m_id, spawn()) { \
             this.netname = #id; \
             this.m_read = Ent_Read##id; \
         } \
         [[accumulate]] void Ent_Read##id(entity this, param)
 #else
-    #define REGISTER_LINKED(id, param) \
-        REGISTER(RegisterLinked, Linked, Linked, Linked_COUNT, id, m_id, spawn()) { \
+    #define REGISTER_NET_LINKED(id, param) \
+        const bool NET_##id##_istemp = false; \
+        REGISTER(RegisterLinkedEntities, NET, LinkedEntities, LinkedEntities_COUNT, id, m_id, spawn()) { \
+            this.netname = #id; \
+        }
+#endif
+
+REGISTRY(LinkedEntities, 24)
+REGISTER_REGISTRY(RegisterLinkedEntities)
+REGISTRY_SORT(LinkedEntities, netname, 0)
+STATIC_INIT(RegisterLinkedEntities_renumber) {
+    for (int i = 0; i < LinkedEntities_COUNT; ++i) {
+        LinkedEntities[i].m_id = 100 + i;
+    }
+}
+
+#ifdef CSQC
+    #define REGISTER_NET_TEMP(id, param) \
+        void Net_Read##id(entity this, param); \
+        REGISTER(RegisterTempEntities, NET, TempEntities, TempEntities_COUNT, id, m_id, spawn()) { \
+            this.netname = #id; \
+            this.m_read = Net_Read##id; \
+        } \
+        void Net_Read##id(entity this, param)
+#else
+    #define REGISTER_NET_TEMP(id, param) \
+        const bool NET_##id##_istemp = true; \
+        REGISTER(RegisterTempEntities, NET, TempEntities, TempEntities_COUNT, id, m_id, spawn()) { \
             this.netname = #id; \
         }
 #endif
 
-REGISTER_REGISTRY(RegisterLinked)
-REGISTRY_SORT(Linked, netname, 0)
-STATIC_INIT(RegisterLinked_renumber) {
-    for (int i = 0; i < Linked_COUNT; ++i) {
-        Linked[i].m_id = 100 + i;
+REGISTRY(TempEntities, 24)
+REGISTER_REGISTRY(RegisterTempEntities)
+REGISTRY_SORT(TempEntities, netname, 0)
+STATIC_INIT(RegisterTempEntities_renumber) {
+    for (int i = 0; i < TempEntities_COUNT; ++i) {
+        TempEntities[i].m_id = 115 + i;
     }
 }