]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
csqcplayers: network death_time
authorRudolf Polzer <divverent@alientrap.org>
Mon, 9 Jan 2012 18:08:26 +0000 (19:08 +0100)
committerRudolf Polzer <divverent@alientrap.org>
Mon, 9 Jan 2012 18:09:52 +0000 (19:09 +0100)
qcsrc/client/csqcmodel_hooks.qc
qcsrc/common/csqcmodel_settings.qh
qcsrc/common/util.qc
qcsrc/common/util.qh
qcsrc/server/cl_client.qc
qcsrc/server/cl_player.qc
qcsrc/server/defs.qh

index 5e4d27ac5ec9d1c7888161441333047b95132f1f..089c914f83b11d4ce08fe7916defdbbc3f222e86 100644 (file)
@@ -208,7 +208,6 @@ void CSQCPlayer_ForceModel_Apply(float islocalplayer)
 .float csqcmodel_framecount;
 
 .float csqcmodel_isdead; // for utility code
-.float csqcmodel_deathtime; // for utility code
 
 #define IS_DEAD_FRAME(f) ((f) == 0 || (f) == 1)
 void CSQCPlayer_FallbackFrame_PreUpdate(void)
@@ -232,7 +231,7 @@ void CSQCPlayer_FallbackFrame_PostUpdate(float isnew)
 #define FIX_FRAMETIME(f,ft) \
                if(IS_DEAD_FRAME(self.f)) \
                { \
-                       self.ft = 0; \
+                       self.ft = self.death_time; \
                }
                FIX_FRAMETIME(frame, frame1time)
                FIX_FRAMETIME(frame2, frame2time)
@@ -240,8 +239,6 @@ void CSQCPlayer_FallbackFrame_PostUpdate(float isnew)
                FIX_FRAMETIME(frame4, frame4time)
        }
        self.csqcmodel_isdead = IS_DEAD_FRAME(self.frame);
-       if(self.csqcmodel_isdead)
-               self.csqcmodel_deathtime = self.frame1time;
 }
 float CSQCPlayer_FallbackFrame(float f)
 {
index 34d0634c4d751f7d6022c0dac5ed52bd79ab51ba..5a05a67888ba68f55721b06e876fb938b45280e9 100644 (file)
        CSQCMODEL_PROPERTY(4, float, ReadByte, WriteByte, modelflags) \
        CSQCMODEL_PROPERTY_SCALED(8, float, ReadByte, WriteByte, alpha, 254, -1, 254) \
        CSQCMODEL_PROPERTY(16, float, ReadByte, WriteByte, skin) \
-       CSQCMODEL_IF(isplayer) \
-       CSQCMODEL_ENDIF \
+       CSQCMODEL_PROPERTY(32, float, ReadApproxPastTime, WriteApproxPastTime, death_time) \
        CSQCMODEL_IF(!isplayer) \
-               CSQCMODEL_PROPERTY(32, TAG_ENTITY_TYPE, ReadShort, WriteEntity, TAG_ENTITY_NAME) \
-               CSQCMODEL_PROPERTY_SCALED(64, float, ReadByte, WriteByte, glowmod_x, 255, 0, 255) \
-               CSQCMODEL_PROPERTY_SCALED(64, float, ReadByte, WriteByte, glowmod_y, 255, 0, 255) \
-               CSQCMODEL_PROPERTY_SCALED(64, float, ReadByte, WriteByte, glowmod_z, 255, 0, 255) \
+               CSQCMODEL_PROPERTY(64, TAG_ENTITY_TYPE, ReadShort, WriteEntity, TAG_ENTITY_NAME) \
+               CSQCMODEL_PROPERTY_SCALED(128, float, ReadByte, WriteByte, glowmod_x, 255, 0, 255) \
+               CSQCMODEL_PROPERTY_SCALED(128, float, ReadByte, WriteByte, glowmod_y, 255, 0, 255) \
+               CSQCMODEL_PROPERTY_SCALED(128, float, ReadByte, WriteByte, glowmod_z, 255, 0, 255) \
        CSQCMODEL_ENDIF
 // TODO get rid of colormod/glowmod here, find good solution for nex charge glowmod hack; also get rid of some useless properties on non-players that only exist for CopyBody
 
index 8f190f163cecb958f035910209175828383ae80a..356f5b3e7b6771d5bcd1b139edf95d1727962be2 100644 (file)
@@ -2174,3 +2174,41 @@ void m_shutdown()
        }
        cvar_settemp_restore(); // this must be done LAST, but in any case
 }
+
+#define APPROXPASTTIME_ACCURACY_REQUIREMENT 0.05
+#define APPROXPASTTIME_MAX (16384 * APPROXPASTTIME_ACCURACY_REQUIREMENT)
+#define APPROXPASTTIME_RANGE (64 * APPROXPASTTIME_ACCURACY_REQUIREMENT)
+// this will use the value:
+//   128
+// accuracy near zero is APPROXPASTTIME_MAX/(256*255)
+// accuracy at x is 1/derivative, i.e.
+//   APPROXPASTTIME_MAX * (1 + 256 * (dt / APPROXPASTTIME_MAX))^2 / 65536
+#ifdef SVQC
+void WriteApproxPastTime(float dst, float t)
+{
+       float dt = t - time;
+
+       // warning: this is approximate; do not resend when you don't have to!
+       // be careful with sendflags here!
+       // we want: 0 -> 0.05, 1 -> 0.1, ..., 255 -> 12.75
+
+       // map to range...
+       dt = 256 * (dt / ((APPROXPASTTIME_MAX / 256) + dt));
+
+       // round...
+       dt = rint(bound(0, dt, 255));
+
+       WriteByte(dst, dt);
+}
+#endif
+#ifdef CSQC
+float ReadApproxPastTime()
+{
+       float dt = ReadByte();
+
+       // map from range...PPROXPASTTIME_MAX / 256
+       dt = (APPROXPASTTIME_MAX / 256) * (dt / (256 - dt));
+
+       return servertime + dt;
+}
+#endif
index dc8b8708b616a3307384301b9d71584fd24e4c28..4b0526815d65763eb11f2cbe7b51e2596a060ec4 100644 (file)
@@ -290,3 +290,10 @@ float InterpretBoolean(string input);
 
 // generic shutdown handler
 void Shutdown();
+
+#ifdef SVQC
+void WriteApproxPastTime(float dst, float t);
+#endif
+#ifdef CSQC
+float ReadApproxPastTime();
+#endif
index 1db0e928a471e82e916ec4daf88b1115fbc797bd..d0001b9d39a4845e3b1cd1406ef1d2c29fd787d8 100644 (file)
@@ -466,6 +466,7 @@ void PutObserverInServer (void)
        self.pauseregen_finished = 0;
        self.damageforcescale = 0;
        self.death_time = 0;
+       self.respawn_time = 0;
        self.alpha = 0;
        self.scale = 0;
        self.fade_time = 0;
@@ -774,6 +775,7 @@ void PutClientInServer (void)
                }
                self.damageforcescale = 2;
                self.death_time = 0;
+               self.respawn_time = 0;
                self.scale = 0;
                self.fade_time = 0;
                self.pain_frame = 0;
@@ -2256,13 +2258,13 @@ void ShowRespawnCountdown()
                return;
        else
        {
-               number = ceil(self.death_time - time);
+               number = ceil(self.respawn_time - time);
                if(number <= 0)
                        return;
                if(number <= self.respawn_countdown)
                {
                        self.respawn_countdown = number - 1;
-                       if(ceil(self.death_time - (time + 0.5)) == number) // only say it if it is the same number even in 0.5s; to prevent overlapping sounds
+                       if(ceil(self.respawn_time - (time + 0.5)) == number) // only say it if it is the same number even in 0.5s; to prevent overlapping sounds
                                AnnounceTo(self, strcat(ftos(number), ""));
                }
        }
@@ -2638,9 +2640,9 @@ void PlayerPreThink (void)
                        float button_pressed, force_respawn;
                        if(self.personal && g_race_qualifying)
                        {
-                               if(time > self.death_time)
+                               if(time > self.respawn_time)
                                {
-                                       self.death_time = time + 1; // only retry once a second
+                                       self.respawn_time = time + 1; // only retry once a second
                                        respawn();
                                        self.impulse = 141;
                                }
@@ -2670,9 +2672,9 @@ void PlayerPreThink (void)
                                }
                                else if (self.deadflag == DEAD_RESPAWNING)
                                {
-                                       if(time > self.death_time)
+                                       if(time > self.respawn_time)
                                        {
-                                               self.death_time = time + 1; // only retry once a second
+                                               self.respawn_time = time + 1; // only retry once a second
                                                respawn();
                                        }
                                }
index ae09df2975baf0eaac2f9442a7f0265b4c0ae2bf..e4415d631401db434d32e95debbedf5a68718498 100644 (file)
@@ -760,13 +760,14 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                if(!waves)
                        waves = autocvar_g_respawn_waves;
                if(waves)
-                       self.death_time = ceil((time + sdelay) / waves) * waves;
+                       self.respawn_time = ceil((time + sdelay) / waves) * waves;
                else
-                       self.death_time = time + sdelay;
-               if((sdelay + waves >= 5.0) && (self.death_time - time > 1.75))
+                       self.respawn_time = time + sdelay;
+               if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
                        self.respawn_countdown = 10; // first number to count down from is 10
                else
                        self.respawn_countdown = -1; // do not count down
+               self.death_time = time;
                if (random() < 0.5)
                        setanim(self, self.anim_die1, FALSE, TRUE, TRUE);
                else
index 7aa2fa1664d0ef60ddf4f9dc08afd11e9efafbcd..865d39b10eef9c3369ca63942b29fbd771b09f43 100644 (file)
@@ -104,6 +104,7 @@ float maxclients;
 //.float cnt2;
 
 .float play_time;
+.float respawn_time;
 .float death_time;
 .float fade_time;
 .float fade_rate;