From: Rudolf Polzer Date: Mon, 9 Jan 2012 18:08:26 +0000 (+0100) Subject: csqcplayers: network death_time X-Git-Tag: xonotic-v0.6.0~188^2~11 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=adec2a130491f1b59e05e22ce1a7f06097081216;p=xonotic%2Fxonotic-data.pk3dir.git csqcplayers: network death_time --- diff --git a/qcsrc/client/csqcmodel_hooks.qc b/qcsrc/client/csqcmodel_hooks.qc index 5e4d27ac5..089c914f8 100644 --- a/qcsrc/client/csqcmodel_hooks.qc +++ b/qcsrc/client/csqcmodel_hooks.qc @@ -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) { diff --git a/qcsrc/common/csqcmodel_settings.qh b/qcsrc/common/csqcmodel_settings.qh index 34d0634c4..5a05a6788 100644 --- a/qcsrc/common/csqcmodel_settings.qh +++ b/qcsrc/common/csqcmodel_settings.qh @@ -21,13 +21,12 @@ 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 diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 8f190f163..356f5b3e7 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -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 diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index dc8b8708b..4b0526815 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -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 diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 1db0e928a..d0001b9d3 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -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(); } } diff --git a/qcsrc/server/cl_player.qc b/qcsrc/server/cl_player.qc index ae09df297..e4415d631 100644 --- a/qcsrc/server/cl_player.qc +++ b/qcsrc/server/cl_player.qc @@ -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 diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index 7aa2fa166..865d39b10 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -104,6 +104,7 @@ float maxclients; //.float cnt2; .float play_time; +.float respawn_time; .float death_time; .float fade_time; .float fade_rate;