]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Weapons: fix cvar networking for late joins
authorTimePath <andrew.hardaker1995@gmail.com>
Fri, 11 Dec 2015 08:08:02 +0000 (19:08 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Fri, 11 Dec 2015 08:08:02 +0000 (19:08 +1100)
qcsrc/common/weapons/all.qh
qcsrc/server/cl_client.qc

index 429dfbd792d4a9f23d402f3d2d5bc559b498b5b2..7972e7f0f2c90906d1ca09bd296d4c90a61c34e5 100644 (file)
@@ -97,22 +97,26 @@ GENERIC_COMMAND(dumpweapons, "Dump all weapons into weapons_dump.txt") // WEAPON
 #ifdef SVQC
 entity W_PROP_reloader;
 float autocvar_w_prop_interval = 0;
-.void(Weapon this) wr_net;
-void W_PROP_reload()
+.void(Weapon this, int) wr_net;
+void W_PROP_reload(int chan, entity to)
 {
-    SELFPARAM();
-    this.nextthink = time + autocvar_w_prop_interval;
+    W_PROP_reloader.nextthink = time + autocvar_w_prop_interval;
+    msg_entity = to;
     FOREACH(Weapons, true, {
         it.wr_update(it);
-        void(Weapon) f = it.wr_net;
-        if (f) f(it);
+        void(Weapon, int) f = it.wr_net;
+        if (f) f(it, chan);
     });
 }
+void W_PROP_think()
+{
+    W_PROP_reload(MSG_ALL, NULL);
+}
 STATIC_INIT_LATE(W_PROP_reloader)
 {
     entity e = W_PROP_reloader = new(W_PROP_reloader);
     make_pure(e);
-    WITH(entity, self, e, (e.think = W_PROP_reload)());
+    WITH(entity, self, e, (e.think = W_PROP_think)());
 }
 #endif
 
@@ -241,28 +245,22 @@ X(reload_time, float)
         #define W_NET_END() }
     #elif defined(SVQC)
         #define W_NET_BEGIN(class) \
-            METHOD(class, wr_net, void(class this)) \
+            METHOD(class, wr_net, void(class this, int chan)) \
             { \
-                int chan = MSG_INIT; \
-                for (;;) \
+                bool commit = false; \
+                int i = 0;
+    #define _W_NET(class, fld, T, wepname) \
                 { \
-                    bool commit = false; \
-                    int i = 0;
-        #define _W_NET(class, fld, T, wepname) \
+                    ++i; \
+                    T it = this.wepvar_##fld; \
+                    if (chan == MSG_ONE || it != this.baseline.wepvar_##fld) \
                     { \
-                        ++i; \
-                        T it = this.wepvar_##fld; \
-                        if (it != this.baseline.wepvar_##fld) \
-                        { \
-                            if (!commit) { commit = true; WriteHeader(chan, WeaponUpdate); WriteByte(chan, this.m_id); } \
-                            WriteByte(chan, i); Write_##T(chan, it); \
-                        } \
-                    }
-        #define W_NET_END() \
-                    if (commit) WriteByte(chan, 0); \
-                    if (chan == MSG_INIT) chan = MSG_ALL; \
-                    else break; \
-                } \
+                        if (!commit) { commit = true; WriteHeader(chan, WeaponUpdate); WriteByte(chan, this.m_id); } \
+                        WriteByte(chan, i); Write_##T(chan, it); \
+                    } \
+                }
+    #define W_NET_END() \
+                if (commit) WriteByte(chan, 0); \
             }
     #else
         #define W_NET_BEGIN(class)
index 953f79c844f2265008b8421d81c7d76498b06ecc..ad5b5fc9e2562f41b9326aa0f7041a7175abe793 100644 (file)
@@ -630,6 +630,8 @@ void PutClientInServer()
        }
 }
 
+void ClientInit_misc();
+
 .float ebouncefactor, ebouncestop; // electro's values
 // TODO do we need all these fields, or should we stop autodetecting runtime
 // changes and just have a console command to update this?
@@ -638,7 +640,15 @@ bool ClientInit_SendEntity(entity this, entity to, int sf)
        WriteHeader(MSG_ENTITY, _ENT_CLIENT_INIT);
        return = true;
        msg_entity = to;
+       // MSG_INIT replacement
+       // TODO: make easier to use
        Registry_send_all();
+       W_PROP_reload(MSG_ONE, to);
+       ClientInit_misc();
+       MUTATOR_CALLHOOK(Ent_Init);
+}
+void ClientInit_misc()
+{
        int channel = MSG_ONE;
        WriteHeader(channel, ENT_CLIENT_INIT);
        WriteByte(channel, g_nexball_meter_period * 32);
@@ -658,8 +668,6 @@ bool ClientInit_SendEntity(entity this, entity to, int sf)
        WriteByte(channel, self.count * 255.0); // g_balance_armor_blockpercent
        WriteByte(channel, serverflags); // client has to know if it should zoom or not
        WriteCoord(channel, autocvar_g_trueaim_minrange);
-
-       MUTATOR_CALLHOOK(Ent_Init);
 }
 
 void ClientInit_CheckUpdate()