From 67adff8edca9e694b27f8b5c6830f49cfda94108 Mon Sep 17 00:00:00 2001 From: fruitiex Date: Tue, 13 Oct 2009 10:52:34 +0000 Subject: [PATCH] more cleanups and bugfixes to the race hud code git-svn-id: svn://svn.icculus.org/nexuiz/trunk@8117 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/client/sbar.qc | 38 +++++++++++++--------------------- data/qcsrc/server/cl_client.qc | 16 ++++++++++---- data/qcsrc/server/race.qc | 37 ++++++++++++++------------------- 3 files changed, 41 insertions(+), 50 deletions(-) diff --git a/data/qcsrc/client/sbar.qc b/data/qcsrc/client/sbar.qc index 6530be09f..34a1b47f0 100644 --- a/data/qcsrc/client/sbar.qc +++ b/data/qcsrc/client/sbar.qc @@ -3023,7 +3023,7 @@ void CSQC_race_hud(void) { entity me; me = playerslots[player_localentnum - 1]; - float crecordtime, srecordtime, score; + float t, score; float f; // yet another function has this score = me.(scores[ps_primary]); @@ -3041,58 +3041,48 @@ void CSQC_race_hud(void) rr = CTS_RECORD; else rr = RACE_RECORD; - crecordtime = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time"))); + t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time"))); - if(score && score < crecordtime || !crecordtime) + if(score && score < t || !t) db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score)); - if(crecordtime != crecordtime_prev) { - crecordtime_prev = crecordtime; + if(t != crecordtime_prev) { + crecordtime_prev = t; crecordtime_change_time = time; } f = time - crecordtime_change_time; - float cmin, csec, cmsec; - cmin = floor(crecordtime/(60 * TIME_FACTOR)); - csec = floor((crecordtime - cmin*(60 * TIME_FACTOR))/TIME_FACTOR); - cmsec = crecordtime - cmin*60*TIME_FACTOR - csec*TIME_FACTOR; - if (f > 1) { drawstring(pos, "Personal best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); - drawstring(pos + '0 10 0', strcat(ftos(cmin),":", ftos(csec),":",ftos(cmsec)),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); } else { drawstring(pos, "Personal best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); - drawstring(pos + '0 10 0', strcat(ftos(cmin),":", ftos(csec),":",ftos(cmsec)),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); // expanding drawstring(pos - '0 50 0' * f, "Personal best ", '10 10 0' + '30 30 0' * f, '1 1 1', sbar_alpha_fg * (1 - f), DRAWFLAG_NORMAL); - drawstring(pos + '0 10 0' - '0 30 0' * f, strcat(ftos(cmin),":", ftos(csec),":",ftos(cmsec)),'14 14 0' + '42 42 0' * f, '1 1 1', sbar_alpha_fg * (1 - f), DRAWFLAG_NORMAL); + drawstring(pos + '0 10 0' - '0 30 0' * f, TIME_ENCODED_TOSTRING(t),'14 14 0' + '42 42 0' * f, '1 1 1', sbar_alpha_fg * (1 - f), DRAWFLAG_NORMAL); } // server record pos_y += 26; - srecordtime = race_server_record; - if(srecordtime != srecordtime_prev) { - srecordtime_prev = srecordtime; + t = race_server_record; + if(t != srecordtime_prev) { + srecordtime_prev = t; srecordtime_change_time = time; } f = time - srecordtime_change_time; - float smin, ssec, smsec; - smin = floor(srecordtime/(60 * TIME_FACTOR)); - ssec = floor((srecordtime - smin*(60 * TIME_FACTOR))/TIME_FACTOR); - smsec = srecordtime - smin*60*TIME_FACTOR - ssec*TIME_FACTOR; - if (f > 1) { drawstring(pos, "Server best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); - drawstring(pos + '0 10 0', strcat(ftos(smin),":", ftos(ssec),":",ftos(smsec)),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); } else { drawstring(pos, "Server best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); - drawstring(pos + '0 10 0', strcat(ftos(smin),":", ftos(ssec),":",ftos(smsec)),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + drawstring(pos + '0 10 0', TIME_ENCODED_TOSTRING(t),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); // expanding drawstring(pos - '0 50 0' * f, "Server best ", '10 10 0' + '30 30 0' * f, '1 1 1', sbar_alpha_fg * (1 - f), DRAWFLAG_NORMAL); - drawstring(pos + '0 10 0' - '0 30 0' * f, strcat(ftos(smin),":", ftos(ssec),":",ftos(smsec)),'14 14 0' + '42 42 0' * f, '1 1 1', sbar_alpha_fg * (1 - f), DRAWFLAG_NORMAL); + drawstring(pos + '0 10 0' - '0 30 0' * f, TIME_ENCODED_TOSTRING(t),'14 14 0' + '42 42 0' * f, '1 1 1', sbar_alpha_fg * (1 - f), DRAWFLAG_NORMAL); } drawfont = sbar_font; } diff --git a/data/qcsrc/server/cl_client.qc b/data/qcsrc/server/cl_client.qc index 50a0fed61..b97e3aae7 100644 --- a/data/qcsrc/server/cl_client.qc +++ b/data/qcsrc/server/cl_client.qc @@ -1,4 +1,4 @@ -void race_send_recordtime(); +void race_send_recordtime(float t); float ClientData_Send(entity to, float sf) { @@ -1285,9 +1285,6 @@ void ClientConnect (void) local string s; float t; - if(g_race || g_cts) - race_send_recordtime(); - if(self.flags & FL_CLIENT) { print("Warning: ClientConnect, but already connected!\n"); @@ -1459,6 +1456,17 @@ void ClientConnect (void) } else self.hitplotfh = -1; + + if(g_race || g_cts) { + string rr; + if(g_cts) + rr = CTS_RECORD; + else + rr = RACE_RECORD; + t = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "time"))); + + race_send_recordtime(t); + } } /* diff --git a/data/qcsrc/server/race.qc b/data/qcsrc/server/race.qc index 1513a28cd..75f6ca176 100644 --- a/data/qcsrc/server/race.qc +++ b/data/qcsrc/server/race.qc @@ -18,8 +18,6 @@ entity race_checkpoint_lastplayers[MAX_CHECKPOINTS]; float race_highest_checkpoint; float race_timed_checkpoint; -void race_send_recordtime(); - float race_NextCheckpoint(float f) { if(f >= race_highest_checkpoint) @@ -95,6 +93,17 @@ void race_InitSpectator() race_SendNextCheckpoint(msg_entity.enemy, 1); } +void race_send_recordtime(float t) +{ + // send the server best time + WRITESPECTATABLE_MSG_ONE({ + WriteByte(MSG_ONE, SVC_TEMPENTITY); + WriteByte(MSG_ONE, TE_CSQC_RACE); + WriteByte(MSG_ONE, RACE_NET_SERVER_RECORD); + WriteInt24_t(MSG_ONE, t); + }); +} + void race_SendTime(entity e, float cp, float t, float tvalid) { float snew, l; @@ -175,18 +184,18 @@ void race_SendTime(entity e, float cp, float t, float tvalid) db_put(ServerProgsDB, strcat(GetMapname(), rr, "time"), ftos(t)); db_put(ServerProgsDB, strcat(GetMapname(), rr, "netname"), e.netname); write_recordmarker(e, time - TIME_DECODE(t), TIME_DECODE(t)); - race_send_recordtime(); + race_send_recordtime(t); } else if(t < grecordtime) { if(grecordholder == "") - bprint(e.netname, "^7 broke their all-time fastest lap record with ", TIME_ENCODED_TOSTRING(t), "\n"); + bprint(e.netname, "^7 broke their all-time fastest lap record ", TIME_ENCODED_TOSTRING(grecordtime), " with ", TIME_ENCODED_TOSTRING(t), "\n"); else - bprint(e.netname, "^7 broke ", grecordholder, "^7's all-time fastest lap record with ", TIME_ENCODED_TOSTRING(t), "\n"); + bprint(e.netname, "^7 broke ", grecordholder, "^7's all-time fastest lap record ", TIME_ENCODED_TOSTRING(grecordtime), " with ", TIME_ENCODED_TOSTRING(t), "\n"); db_put(ServerProgsDB, strcat(GetMapname(), rr, "time"), ftos(t)); db_put(ServerProgsDB, strcat(GetMapname(), rr, "netname"), e.netname); write_recordmarker(e, time - TIME_DECODE(t), TIME_DECODE(t)); - race_send_recordtime(); + race_send_recordtime(t); } else { @@ -767,19 +776,3 @@ void spawnfunc_trigger_race_penalty() if (!self.race_penalty) self.race_penalty = 5; } - -void race_send_recordtime() -{ - float grecordtime; - string rr; - if(g_cts) - rr = CTS_RECORD; - else - rr = RACE_RECORD; - grecordtime = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "time"))); - // send the server best time - WriteByte(MSG_ONE, SVC_TEMPENTITY); - WriteByte(MSG_ONE, TE_CSQC_RACE); - WriteByte(MSG_ONE, RACE_NET_SERVER_RECORD); - WriteInt24_t(MSG_ONE, grecordtime); -} -- 2.39.2