[nexuiz-commits] r8117 - in trunk/data/qcsrc: client server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Oct 13 06:52:34 EDT 2009


Author: fruitiex
Date: 2009-10-13 06:52:34 -0400 (Tue, 13 Oct 2009)
New Revision: 8117

Modified:
   trunk/data/qcsrc/client/sbar.qc
   trunk/data/qcsrc/server/cl_client.qc
   trunk/data/qcsrc/server/race.qc
Log:
more cleanups and bugfixes to the race hud code


Modified: trunk/data/qcsrc/client/sbar.qc
===================================================================
--- trunk/data/qcsrc/client/sbar.qc	2009-10-13 08:20:42 UTC (rev 8116)
+++ trunk/data/qcsrc/client/sbar.qc	2009-10-13 10:52:34 UTC (rev 8117)
@@ -3023,7 +3023,7 @@
 {
 	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 @@
 		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;
 }

Modified: trunk/data/qcsrc/server/cl_client.qc
===================================================================
--- trunk/data/qcsrc/server/cl_client.qc	2009-10-13 08:20:42 UTC (rev 8116)
+++ trunk/data/qcsrc/server/cl_client.qc	2009-10-13 10:52:34 UTC (rev 8117)
@@ -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 @@
 	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 @@
 	}
 	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);
+	}
 }
 
 /*

Modified: trunk/data/qcsrc/server/race.qc
===================================================================
--- trunk/data/qcsrc/server/race.qc	2009-10-13 08:20:42 UTC (rev 8116)
+++ trunk/data/qcsrc/server/race.qc	2009-10-13 10:52:34 UTC (rev 8117)
@@ -18,8 +18,6 @@
 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 @@
 			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 @@
 						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 @@
 	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);
-}



More information about the nexuiz-commits mailing list