From eecf12bb0159901b6752c362ed4d0b5e03aff21a Mon Sep 17 00:00:00 2001 From: div0 Date: Fri, 4 Sep 2009 06:52:19 +0000 Subject: [PATCH] change the values networked as "long" in scores and race times to "int24_t" (3 bytes instead of 4). Range is now: -8388608..8388607 In time, at 100Hz timer: 83886.07 seconds (a bit less than a day) ;) git-svn-id: svn://svn.icculus.org/nexuiz/trunk@7622 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/client/Main.qc | 14 +++++++------- data/qcsrc/common/util.qc | 18 ++++++++++++++++++ data/qcsrc/common/util.qh | 8 ++++++++ data/qcsrc/server/race.qc | 14 +++++++------- data/qcsrc/server/scores.qc | 4 ++-- 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/data/qcsrc/client/Main.qc b/data/qcsrc/client/Main.qc index 9f59fc7df..28f5fd823 100644 --- a/data/qcsrc/client/Main.qc +++ b/data/qcsrc/client/Main.qc @@ -630,7 +630,7 @@ void Ent_ReadPlayerScore() if(sf & p) { if(lf & p) - o.(scores[i]) = ReadLong(); + o.(scores[i]) = ReadInt24_t(); else o.(scores[i]) = ReadChar(); } @@ -662,7 +662,7 @@ void Ent_ReadTeamScore() if(sf & p) { if(lf & p) - o.(teamscores[i]) = ReadLong(); + o.(teamscores[i]) = ReadInt24_t(); else o.(teamscores[i]) = ReadChar(); } @@ -932,8 +932,8 @@ void Net_ReadRace() { case RACE_NET_CHECKPOINT_HIT_QUALIFYING: race_checkpoint = ReadByte(); - race_time = ReadLong(); - race_previousbesttime = ReadLong(); + race_time = ReadInt24_t(); + race_previousbesttime = ReadInt24_t(); if(race_previousbestname) strunzone(race_previousbestname); race_previousbestname = strzone(ColorTranslateRGB(ReadString())); @@ -960,7 +960,7 @@ void Net_ReadRace() case RACE_NET_CHECKPOINT_NEXT_QUALIFYING: race_nextcheckpoint = ReadByte(); - race_nextbesttime = ReadLong(); + race_nextbesttime = ReadInt24_t(); if(race_nextbestname) strunzone(race_nextbestname); race_nextbestname = strzone(ColorTranslateRGB(ReadString())); @@ -969,7 +969,7 @@ void Net_ReadRace() case RACE_NET_CHECKPOINT_HIT_RACE: race_mycheckpoint = ReadByte(); race_mycheckpointtime = time; - race_mycheckpointdelta = ReadLong(); + race_mycheckpointdelta = ReadInt24_t(); race_mycheckpointlapsdelta = ReadByte(); if(race_mycheckpointlapsdelta >= 128) race_mycheckpointlapsdelta -= 256; @@ -981,7 +981,7 @@ void Net_ReadRace() case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT: race_othercheckpoint = ReadByte(); race_othercheckpointtime = time; - race_othercheckpointdelta = ReadLong(); + race_othercheckpointdelta = ReadInt24_t(); race_othercheckpointlapsdelta = ReadByte(); if(race_othercheckpointlapsdelta >= 128) race_othercheckpointlapsdelta -= 256; diff --git a/data/qcsrc/common/util.qc b/data/qcsrc/common/util.qc index 9e4e8b88b..cd2af5806 100644 --- a/data/qcsrc/common/util.qc +++ b/data/qcsrc/common/util.qc @@ -1627,3 +1627,21 @@ string getcurrentmod() else return argv(n - 1); } + +#ifndef MENUQC +#ifdef CSQC +float ReadInt24_t() +{ + float v; + v = ReadShort() * 256; // note: this is signed + v += ReadByte(); // note: this is unsigned +} +#else +void WriteInt24_t(float dest, float val) +{ + float v; + WriteShort((v = floor(val / 256))); + WriteByte(val - v * 256); // 0..255 +} +#endif +#endif diff --git a/data/qcsrc/common/util.qh b/data/qcsrc/common/util.qh index 45ebad53d..1a5976d40 100644 --- a/data/qcsrc/common/util.qh +++ b/data/qcsrc/common/util.qh @@ -194,3 +194,11 @@ vector healtharmor_maxdamage(float h, float a, float armorblock); // returns vec vector healtharmor_applydamage(float a, float armorblock, float damage); // returns vector: take, save, 0 string getcurrentmod(); + +#ifndef MENUQC +#ifdef CSQC +float ReadInt24_t(); +#else +void WriteInt24_t(float dest, float val); +#endif +#endif diff --git a/data/qcsrc/server/race.qc b/data/qcsrc/server/race.qc index c75535366..549aba28d 100644 --- a/data/qcsrc/server/race.qc +++ b/data/qcsrc/server/race.qc @@ -80,7 +80,7 @@ void race_SendNextCheckpoint(entity e, float spec) else WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_NEXT_QUALIFYING); WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player will be at next - WriteLong(MSG_ONE, recordtime); + WriteInt24_t(MSG_ONE, recordtime); WriteString(MSG_ONE, recordholder); }); } @@ -217,8 +217,8 @@ void race_SendTime(entity e, float cp, float t, float tvalid) WriteByte(MSG_ONE, TE_CSQC_RACE); WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_QUALIFYING); WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at - WriteLong(MSG_ONE, t); // time to that intermediate - WriteLong(MSG_ONE, recordtime); // previously best time + WriteInt24_t(MSG_ONE, t); // time to that intermediate + WriteInt24_t(MSG_ONE, recordtime); // previously best time WriteString(MSG_ONE, recordholder); // record holder }); } @@ -245,13 +245,13 @@ void race_SendTime(entity e, float cp, float t, float tvalid) WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at if(e == oth) { - WriteLong(MSG_ONE, 0); + WriteInt24_t(MSG_ONE, 0); WriteByte(MSG_ONE, 0); WriteString(MSG_ONE, ""); } else { - WriteLong(MSG_ONE, TIME_ENCODE(time - race_checkpoint_lasttimes[cp])); + WriteInt24_t(MSG_ONE, TIME_ENCODE(time - race_checkpoint_lasttimes[cp])); WriteByte(MSG_ONE, lself - lother); WriteString(MSG_ONE, oth.netname); // record holder } @@ -269,13 +269,13 @@ void race_SendTime(entity e, float cp, float t, float tvalid) WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at if(e == oth) { - WriteLong(MSG_ONE, 0); + WriteInt24_t(MSG_ONE, 0); WriteByte(MSG_ONE, 0); WriteString(MSG_ONE, ""); } else { - WriteLong(MSG_ONE, TIME_ENCODE(time - othtime)); + WriteInt24_t(MSG_ONE, TIME_ENCODE(time - othtime)); WriteByte(MSG_ONE, lother - lself); WriteString(MSG_ONE, e.netname); // record holder } diff --git a/data/qcsrc/server/scores.qc b/data/qcsrc/server/scores.qc index 85e02f495..d21ab9596 100644 --- a/data/qcsrc/server/scores.qc +++ b/data/qcsrc/server/scores.qc @@ -70,7 +70,7 @@ float TeamScore_SendEntity(entity to, float sendflags) if(sendflags & p) { if(longflags & p) - WriteLong(MSG_ENTITY, self.teamscores[i]); + WriteInt24_t(MSG_ENTITY, self.teamscores[i]); else WriteChar(MSG_ENTITY, self.teamscores[i]); } @@ -230,7 +230,7 @@ float PlayerScore_SendEntity(entity to, float sendflags) if(sendflags & p) { if(longflags & p) - WriteLong(MSG_ENTITY, self.scores[i]); + WriteInt24_t(MSG_ENTITY, self.scores[i]); else WriteChar(MSG_ENTITY, self.scores[i]); } -- 2.39.2