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

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sun Oct 11 06:27:17 EDT 2009


Author: fruitiex
Date: 2009-10-11 06:27:17 -0400 (Sun, 11 Oct 2009)
New Revision: 8091

Modified:
   trunk/data/qcsrc/client/Defs.qc
   trunk/data/qcsrc/client/Main.qc
   trunk/data/qcsrc/client/sbar.qc
   trunk/data/qcsrc/common/constants.qh
   trunk/data/qcsrc/server/cl_client.qc
   trunk/data/qcsrc/server/race.qc
Log:
show server record on the hud (race/cts)


Modified: trunk/data/qcsrc/client/Defs.qc
===================================================================
--- trunk/data/qcsrc/client/Defs.qc	2009-10-11 08:26:05 UTC (rev 8090)
+++ trunk/data/qcsrc/client/Defs.qc	2009-10-11 10:27:17 UTC (rev 8091)
@@ -192,6 +192,7 @@
 float race_penaltyeventtime; // time when the player got the penalty
 float race_penaltytime; // duration of penalty time, in tenths
 string race_penaltyreason; // reason for penalty
+float race_server_record; // server record
 
 // RACE
 float race_mycheckpoint;

Modified: trunk/data/qcsrc/client/Main.qc
===================================================================
--- trunk/data/qcsrc/client/Main.qc	2009-10-11 08:26:05 UTC (rev 8090)
+++ trunk/data/qcsrc/client/Main.qc	2009-10-11 10:27:17 UTC (rev 8091)
@@ -1027,6 +1027,10 @@
 				strunzone(race_penaltyreason);
 			race_penaltyreason = strzone(ReadString());
 			break;
+
+		case RACE_NET_SERVER_RECORD:
+			race_server_record = ReadInt24_t();
+			break;
 	}
 }
 

Modified: trunk/data/qcsrc/client/sbar.qc
===================================================================
--- trunk/data/qcsrc/client/sbar.qc	2009-10-11 08:26:05 UTC (rev 8090)
+++ trunk/data/qcsrc/client/sbar.qc	2009-10-11 10:27:17 UTC (rev 8091)
@@ -3038,14 +3038,22 @@
 
 float crecordtime_prev; // last remembered crecordtime
 float crecordtime_change_time; // time when crecordtime last changed
+float srecordtime_prev; // last remembered srecordtime
+float srecordtime_change_time; // time when srecordtime last changed
 void CSQC_race_hud(void) 
 {
 	entity me;
 	me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
-	float crecordtime, score;
+	float crecordtime, srecordtime, score;
 	float f; // yet another function has this
 	score = me.(scores[ps_primary]);
 
+	drawfont = sbar_bigfont;
+	vector pos;
+	pos_x = 2;
+	pos_y = vid_conheight - 48;
+
+	// clientside personal record
 	string rr;
 	if(gametype == GAME_CTS)
 		rr = CTS_RECORD;
@@ -3062,26 +3070,47 @@
 	}
 	f = time - crecordtime_change_time;
 
-	vector pos;
-	pos_x = 2;
-	pos_y = vid_conheight - 48;
+	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;
 
-	float pmin, psec, pmsec;
-	pmin = floor(crecordtime/(60 * TIME_FACTOR));
-	psec = floor((crecordtime - pmin*(60 * TIME_FACTOR))/TIME_FACTOR);
-	pmsec = crecordtime - pmin*60*TIME_FACTOR - psec*TIME_FACTOR;
-	drawfont = sbar_bigfont;
-
 	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(pmin),":", ftos(psec),":",ftos(pmsec)),'14 14 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);
 	} else {
 		drawstring(pos, "Personal best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
-		drawstring(pos + '0 10 0', strcat(ftos(pmin),":", ftos(psec),":",ftos(pmsec)),'14 14 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);
 
 		// 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(pmin),":", ftos(psec),":",ftos(pmsec)),'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, strcat(ftos(cmin),":", ftos(csec),":",ftos(cmsec)),'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;
+		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);
+	} 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);
+
+		// 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);
+	}
 	drawfont = sbar_font;
 }

Modified: trunk/data/qcsrc/common/constants.qh
===================================================================
--- trunk/data/qcsrc/common/constants.qh	2009-10-11 08:26:05 UTC (rev 8090)
+++ trunk/data/qcsrc/common/constants.qh	2009-10-11 10:27:17 UTC (rev 8091)
@@ -59,6 +59,7 @@
 const float RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING = 5; // byte nextcheckpoint, float laptime, short recordtime, string recordholder
 const float RACE_NET_PENALTY_RACE = 6; // byte penaltytime, string reason
 const float RACE_NET_PENALTY_QUALIFYING = 7; // byte penaltytime, string reason
+const float RACE_NET_SERVER_RECORD = 8; // server record, sent to client
 
 const float ENT_CLIENT = 0;
 const float ENT_CLIENT_DEAD = 1;

Modified: trunk/data/qcsrc/server/cl_client.qc
===================================================================
--- trunk/data/qcsrc/server/cl_client.qc	2009-10-11 08:26:05 UTC (rev 8090)
+++ trunk/data/qcsrc/server/cl_client.qc	2009-10-11 10:27:17 UTC (rev 8091)
@@ -1,3 +1,5 @@
+void race_send_recordtime();
+
 float ClientData_Send(entity to, float sf)
 {
 	if(to != self.owner)
@@ -1283,6 +1285,9 @@
 	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");

Modified: trunk/data/qcsrc/server/race.qc
===================================================================
--- trunk/data/qcsrc/server/race.qc	2009-10-11 08:26:05 UTC (rev 8090)
+++ trunk/data/qcsrc/server/race.qc	2009-10-11 10:27:17 UTC (rev 8091)
@@ -18,6 +18,8 @@
 float race_highest_checkpoint;
 float race_timed_checkpoint;
 
+void race_send_recordtime();
+
 float race_NextCheckpoint(float f)
 {
 	if(f >= race_highest_checkpoint)
@@ -138,7 +140,6 @@
 
 	float recordtime;
 	string recordholder;
-
 	if(g_race_qualifying)
 	{
 		if(tvalid)
@@ -174,6 +175,7 @@
 						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();
 					}
 					else if(t < grecordtime)
 					{
@@ -184,6 +186,7 @@
 						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();
 					}
 					else
 					{
@@ -764,3 +767,19 @@
 	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