r5678 - in trunk/data/qcsrc: client common server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Jan 27 09:49:40 EST 2009


Author: div0
Date: 2009-01-27 09:49:40 -0500 (Tue, 27 Jan 2009)
New Revision: 5678

Modified:
   trunk/data/qcsrc/client/Main.qc
   trunk/data/qcsrc/client/mapvoting.qc
   trunk/data/qcsrc/common/constants.qh
   trunk/data/qcsrc/server/cl_client.qc
   trunk/data/qcsrc/server/g_world.qc
Log:
make mapvote a shared ent too


Modified: trunk/data/qcsrc/client/Main.qc
===================================================================
--- trunk/data/qcsrc/client/Main.qc	2009-01-27 13:27:10 UTC (rev 5677)
+++ trunk/data/qcsrc/client/Main.qc	2009-01-27 14:49:40 UTC (rev 5678)
@@ -534,6 +534,8 @@
 		Ent_Init();
 	else if(self.enttype == ENT_CLIENT_SCORES_INFO)
 		Ent_ScoresInfo();
+	else if(self.enttype == ENT_CLIENT_MAPVOTE)
+		Ent_MapVote();
 	else
 		error(strcat("unknown entity type in CSQC_Ent_Update: ", ftos(self.enttype), "\n"));
 	
@@ -844,8 +846,8 @@
 		// NOTE: Could just do return instead of break...
 	switch(nTEID)
 	{
-		case TE_CSQC_MAPVOTE:
-			Net_Mapvote();
+		case TE_CSQC_PICTURE:
+			Net_MapVote_Picture();
 			bHandled = true;
 			break;
 		case TE_CSQC_CONFIG:

Modified: trunk/data/qcsrc/client/mapvoting.qc
===================================================================
--- trunk/data/qcsrc/client/mapvoting.qc	2009-01-27 13:27:10 UTC (rev 5677)
+++ trunk/data/qcsrc/client/mapvoting.qc	2009-01-27 14:49:40 UTC (rev 5678)
@@ -10,6 +10,7 @@
 float mv_ownvote;
 float mv_detail;
 float mv_timeout;
+float mv_maps_mask;
 
 string MapVote_FormatMapItem(float id, string map, float count, float maxwidth)
 {
@@ -259,10 +260,12 @@
 void MapVote_Init()
 {
 	float i, power, m;
-	string map, pk3;
+	string map, pk3, ssdir;
 
 	registercmd("+showscores");
 	registercmd("-showscores");
+
+	ssdir = ReadString();
 	
 	mv_num_maps = min(MAPVOTE_COUNT, ReadByte());
 	mv_abstain = ReadByte();
@@ -291,7 +294,7 @@
 			pk3 = strzone(ReadString());
 			mv_maps[i] = map;
 			mv_pk3[i] = pk3;
-			map = strzone(strcat(config_get("mv_screenshot_dir", "maps"), "/", map));
+			map = strzone(strcat(ssdir, "/", map));
 			mv_pics[i] = map;
 
 			mv_preview[i] = false;
@@ -307,19 +310,25 @@
 			mv_preview[i] = false;
 		}
 	}
+
+	// do we NEED this, or can we handle key presses directly in CSQC?
+	localcmd("\nin_bind 7 1 \"impulse 1\"; in_bind 7 2 \"impulse 2\"; in_bind 7 3 \"impulse 3\"; in_bind 7 4 \"impulse 4\"; in_bind 7 5 \"impulse 5\"; in_bind 7 6 \"impulse 6\"; in_bind 7 7 \"impulse 7\"; in_bind 7 8 \"impulse 8\"; in_bind 7 9 \"impulse 9\"; in_bind 7 0 \"impulse 10\"; in_bind 7 KP_1 \"impulse 1\"; in_bind 7 KP_2 \"impulse 2\"; in_bind 7 KP_3 \"impulse 3\"; in_bind 7 KP_4 \"impulse 4\"; in_bind 7 KP_5 \"impulse 5\"; in_bind 7 KP_6 \"impulse 6\"; in_bind 7 KP_7 \"impulse 7\"; in_bind 7 KP_8 \"impulse 8\"; in_bind 7 KP_9 \"impulse 9\"; in_bind 7 KP_0 \"impulse 10\"; in_bindmap 7 0\n");
 }
 
-void MapVote_Update()
+void MapVote_UpdateMask()
 {
-	float i, power;
-	float m;
 	if(mv_num_maps <= 8)
-		m = ReadByte();
+		mv_maps_mask = ReadByte();
 	else
-		m = ReadShort();
+		mv_maps_mask = ReadShort();
+}
+
+void MapVote_UpdateVotes()
+{
+	float i, power;
 	for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
 	{
-		if(m & power)
+		if(mv_maps_mask & power)
 		{
 			if(mv_detail)
 				mv_votes[i] = ReadByte();
@@ -329,30 +338,29 @@
 		else
 			mv_votes[i] = -1;
 	}
+
+	mv_ownvote = ReadByte()-1;
 }
 
+void Ent_MapVote()
+{
+	float sf;
+
+	if(sf & 1)
+		MapVote_Init();
+
+	if(sf & 2)
+		MapVote_UpdateMask();
+
+	if(sf & 4)
+		MapVote_UpdateVotes();
+}
+
 string Net_ReadPicture();
-void Net_Mapvote()
+void Net_MapVote_Picture()
 {
 	float type;
 	type = ReadByte();
-	switch(type)
-	{
-	case MAPVOTE_NET_INIT:
-		MapVote_Init();
-		// do we NEED this, or can we handle key presses directly in CSQC?
-		localcmd("\nin_bind 7 1 \"impulse 1\"; in_bind 7 2 \"impulse 2\"; in_bind 7 3 \"impulse 3\"; in_bind 7 4 \"impulse 4\"; in_bind 7 5 \"impulse 5\"; in_bind 7 6 \"impulse 6\"; in_bind 7 7 \"impulse 7\"; in_bind 7 8 \"impulse 8\"; in_bind 7 9 \"impulse 9\"; in_bind 7 0 \"impulse 10\"; in_bind 7 KP_1 \"impulse 1\"; in_bind 7 KP_2 \"impulse 2\"; in_bind 7 KP_3 \"impulse 3\"; in_bind 7 KP_4 \"impulse 4\"; in_bind 7 KP_5 \"impulse 5\"; in_bind 7 KP_6 \"impulse 6\"; in_bind 7 KP_7 \"impulse 7\"; in_bind 7 KP_8 \"impulse 8\"; in_bind 7 KP_9 \"impulse 9\"; in_bind 7 KP_0 \"impulse 10\"; in_bindmap 7 0\n");
-		break;
-	case MAPVOTE_NET_UPDATE:
-		MapVote_Update();
-		break;
-	case MAPVOTE_NET_OWNVOTE:
-		mv_ownvote = ReadByte()-1;
-		break;
-	case MAPVOTE_NET_PIC:
-		type = ReadByte();
-		mv_preview[type] = true;
-		mv_pics[type] = strzone(Net_ReadPicture());
-		break;
-	}
+	mv_preview[type] = true;
+	mv_pics[type] = strzone(Net_ReadPicture());
 }

Modified: trunk/data/qcsrc/common/constants.qh
===================================================================
--- trunk/data/qcsrc/common/constants.qh	2009-01-27 13:27:10 UTC (rev 5677)
+++ trunk/data/qcsrc/common/constants.qh	2009-01-27 14:49:40 UTC (rev 5678)
@@ -59,6 +59,7 @@
 const float ENT_CLIENT_DAMAGEINFO = 14;
 const float ENT_CLIENT_CASING = 15;
 const float ENT_CLIENT_INIT = 16;
+const float ENT_CLIENT_MAPVOTE = 17;
 
 const float SPRITERULE_DEFAULT = 0;
 const float SPRITERULE_TEAMPLAY = 1;
@@ -215,7 +216,6 @@
 const float ENTCS_MSG_INIT = 3;
 
 const float TE_CSQC_PICTURE = 105;
-const float TE_CSQC_MAPVOTE = 106; // TODO turn into shared ent
 const float TE_CSQC_CONFIG = 107; // TODO maybe turn into shared ent
 const float TE_CSQC_RACE = 109;
 const float TE_CSQC_FORCESCOREBOARD = 110; // TODO turn into shared ent
@@ -239,10 +239,6 @@
 // moved that here so the client knows the max.
 // # of maps, I'll use arrays for them :P
 #define MAPVOTE_COUNT 10
-const float MAPVOTE_NET_INIT = 0;
-const float MAPVOTE_NET_UPDATE = 1;
-const float MAPVOTE_NET_PIC = 2;
-const float MAPVOTE_NET_OWNVOTE = 3;
 
 const float RACE_NET_CHECKPOINT_HIT_QUALIFYING = 0; // byte checkpoint, short time, short recordtime, string recordholder
 const float RACE_NET_CHECKPOINT_CLEAR = 1;

Modified: trunk/data/qcsrc/server/cl_client.qc
===================================================================
--- trunk/data/qcsrc/server/cl_client.qc	2009-01-27 13:27:10 UTC (rev 5677)
+++ trunk/data/qcsrc/server/cl_client.qc	2009-01-27 14:49:40 UTC (rev 5678)
@@ -1269,11 +1269,6 @@
 		sprint(self, strcat("nexuiz-csqc protocol ", ftos(CSQC_REVISION), "\n"));
 
 		msg_entity = self;
-		if(mapvote_initialized && !cvar("g_maplist_textonly"))
-		{
-			MapVote_SendData(MSG_ONE);
-			MapVote_UpdateData(MSG_ONE);
-		}
 
 		if(inWarmupStage)
 		{

Modified: trunk/data/qcsrc/server/g_world.qc
===================================================================
--- trunk/data/qcsrc/server/g_world.qc	2009-01-27 13:27:10 UTC (rev 5677)
+++ trunk/data/qcsrc/server/g_world.qc	2009-01-27 14:49:40 UTC (rev 5678)
@@ -1888,7 +1888,6 @@
 float mapvote_run;
 float mapvote_detail;
 float mapvote_abstain;
-float mapvote_dirty;
 .float mapvote;
 
 void MapVote_ClearAllVotes()
@@ -1950,7 +1949,7 @@
 	mapvote_count += 1;
 }
 
-void MapVote_SendData(float target);
+void MapVote_Spawn();
 void MapVote_Init()
 {
 	float i;
@@ -2003,16 +2002,14 @@
 		mapvote_screenshot_dir = "maps";
 	mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
 
-	if(!cvar("g_maplist_textonly"))
-		MapVote_SendData(MSG_ALL);
+	MapVote_Spawn();
 }
 
 void MapVote_SendPicture(float id)
 {
 	msg_entity = self;
 	WriteByte(MSG_ONE, SVC_TEMPENTITY);
-	WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
-	WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
+	WriteByte(MSG_ONE, TE_CSQC_PICTURE);
 	WriteByte(MSG_ONE, id);
 	WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
 }
@@ -2021,13 +2018,11 @@
 {
 	if(!intermission_running)
 		return FALSE;
-	if(!cvar("g_maplist_textonly"))
+
+	if(cmd == "mv_getpic")
 	{
-		if(cmd == "mv_getpic")
-		{
-			MapVote_SendPicture(stof(argv(1)));
-			return TRUE;
-		}
+		MapVote_SendPicture(stof(argv(1)));
+		return TRUE;
 	}
 
 	return FALSE;
@@ -2043,68 +2038,83 @@
 	return mask;
 }
 
-void MapVote_SendData(float targ)
+entity mapvote_ent;
+void MapVote_SendEntity(entity to, float sf)
 {
 	string mapfile, pakfile;
 	float i, o;
-	WriteByte(targ, SVC_TEMPENTITY);
-	WriteByte(targ, TE_CSQC_CONFIG);
-	WriteString(targ, "mv_screenshot_dir");
-	WriteString(targ, mapvote_screenshot_dir);
 
-	WriteByte(targ, SVC_TEMPENTITY);
-	WriteByte(targ, TE_CSQC_MAPVOTE);
-	WriteByte(targ, MAPVOTE_NET_INIT);
+	WriteByte(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
+	WriteByte(MSG_ENTITY, sf);
 
-  	WriteByte(targ, mapvote_count);
-  	WriteByte(targ, mapvote_abstain);
-  	WriteByte(targ, mapvote_detail);
-	WriteCoord(targ, mapvote_timeout);
- 	if(mapvote_count <= 8)
- 		WriteByte(targ, MapVote_GetMapMask());
- 	else
- 		WriteShort(targ, MapVote_GetMapMask());
- 	for(i = 0; i < mapvote_count; ++i)
-		if(mapvote_maps[i] != "")
-		{
-			WriteString(targ, mapvote_maps[i]);
-			mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
-			pakfile = whichpack(strcat(mapfile, ".tga"));
-			if(pakfile == "")
-				pakfile = whichpack(strcat(mapfile, ".jpg"));
-			if(pakfile == "")
-				pakfile = whichpack(strcat(mapfile, ".png"));
-			print("pakfile is ", pakfile, "\n");
-			for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
-				pakfile = substring(pakfile, o, 999);
-			WriteString(targ, pakfile);
-		}
+	if(sf & 1)
+	{
+		// flag 1 == initialization
+		WriteString(MSG_ENTITY, mapvote_screenshot_dir);
+		WriteByte(MSG_ENTITY, mapvote_count);
+		WriteByte(MSG_ENTITY, mapvote_abstain);
+		WriteByte(MSG_ENTITY, mapvote_detail);
+		WriteCoord(MSG_ENTITY, mapvote_timeout);
+		if(mapvote_count <= 8)
+			WriteByte(MSG_ENTITY, MapVote_GetMapMask());
+		else
+			WriteShort(MSG_ENTITY, MapVote_GetMapMask());
+		for(i = 0; i < mapvote_count; ++i)
+			if(mapvote_maps[i] != "")
+			{
+				WriteString(MSG_ENTITY, mapvote_maps[i]);
+				mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
+				pakfile = whichpack(strcat(mapfile, ".tga"));
+				if(pakfile == "")
+					pakfile = whichpack(strcat(mapfile, ".jpg"));
+				if(pakfile == "")
+					pakfile = whichpack(strcat(mapfile, ".png"));
+				print("pakfile is ", pakfile, "\n");
+				for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
+					pakfile = substring(pakfile, o, 999);
+				WriteString(MSG_ENTITY, pakfile);
+			}
+	}
+
+	if(sf & 2)
+	{
+		// flag 2 == update of mask
+		if(mapvote_count <= 8)
+			WriteByte(MSG_ENTITY, MapVote_GetMapMask());
+		else
+			WriteShort(MSG_ENTITY, MapVote_GetMapMask());
+	}
+
+	if(sf & 4)
+	{
+		if(mapvote_detail)
+			for(i = 0; i < mapvote_count; ++i)
+				if(mapvote_maps[i] != "")
+					WriteByte(MSG_ENTITY, mapvote_votes[i]);
+
+		WriteByte(MSG_ENTITY, to.mapvote);
+	}
 }
 
-void MapVote_UpdateData(float targ)
+void MapVote_Spawn()
 {
-	float i;
-	WriteByte(targ, SVC_TEMPENTITY);
-	WriteByte(targ, TE_CSQC_MAPVOTE);
-	WriteByte(targ, MAPVOTE_NET_UPDATE);
-	if(mapvote_count <= 8)
-		WriteByte(targ, MapVote_GetMapMask());
-	else
-		WriteShort(targ, MapVote_GetMapMask());
-	if(mapvote_detail)
-		for(i = 0; i < mapvote_count; ++i)
-			if(mapvote_maps[i] != "")
-				WriteByte(targ, mapvote_votes[i]);
+	mapvote_ent = spawn();
+	mapvote_ent.classname = "ent_client_mapvote";
+	mapvote_ent.SendEntity = MapVote_SendEntity;
+	setmodel(mapvote_ent, "null");
+	mapvote_ent.effects = EF_NODEPTHTEST;
 }
 
-void MapVote_TellVote(float targ, float vote)
+void MapVote_TouchMask()
 {
-	WriteByte(targ, SVC_TEMPENTITY);
-	WriteByte(targ, TE_CSQC_MAPVOTE);
-	WriteByte(targ, MAPVOTE_NET_OWNVOTE);
-	WriteByte(targ, vote);
+	mapvote_ent.SendFlags |= 2;
 }
 
+void MapVote_TouchVotes(entity voter)
+{
+	mapvote_ent.SendFlags |= 4;
+}
+
 float MapVote_Finished(float mappos)
 {
 	string result;
@@ -2203,7 +2213,7 @@
 		if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
 		{
 			float didntvote;
-			mapvote_dirty = TRUE;
+			MapVote_TouchMask();
 			mapvote_message = "Now decide between the TOP TWO!";
 			mapvote_keeptwotime = 0;
 			result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
@@ -2257,9 +2267,6 @@
 			other.impulse = 0;
 			if(clienttype(other) == CLIENTTYPE_REAL)
 			{
-				if(cvar("g_maplist_textonly"))
-					stuffcmd(other, "\nin_bind 7 1 \"impulse 1\"; in_bind 7 2 \"impulse 2\"; in_bind 7 3 \"impulse 3\"; in_bind 7 4 \"impulse 4\"; in_bind 7 5 \"impulse 5\"; in_bind 7 6 \"impulse 6\"; in_bind 7 7 \"impulse 7\"; in_bind 7 8 \"impulse 8\"; in_bind 7 9 \"impulse 9\"; in_bind 7 0 \"impulse 10\"; in_bind 7 KP_1 \"impulse 1\"; in_bind 7 KP_2 \"impulse 2\"; in_bind 7 KP_3 \"impulse 3\"; in_bind 7 KP_4 \"impulse 4\"; in_bind 7 KP_5 \"impulse 5\"; in_bind 7 KP_6 \"impulse 6\"; in_bind 7 KP_7 \"impulse 7\"; in_bind 7 KP_8 \"impulse 8\"; in_bind 7 KP_9 \"impulse 9\"; in_bind 7 KP_0 \"impulse 10\"; in_bindmap 7 0\n");
-
 				msg_entity = other;
 				WriteByte(MSG_ONE, SVC_FINALE);
 				WriteString(MSG_ONE, "");
@@ -2278,11 +2285,7 @@
 			if(mapvote_maps[other.impulse - 1] != "")
 			{
 				other.mapvote = other.impulse;
-				if(mapvote_detail)
-					mapvote_dirty = TRUE;
-
-				msg_entity = other;
-				MapVote_TellVote(MSG_ONE, other.mapvote);
+				MapVote_TouchVotes(other);
 			}
 		other.impulse = 0;
 
@@ -2291,63 +2294,6 @@
 	}
 
 	MapVote_CheckRules_1(); // just count
-
-	if(!cvar("g_maplist_textonly"))
-	if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
-	{
-		MapVote_UpdateData(MSG_BROADCAST);
-		mapvote_dirty = FALSE;
-	}
-
-	if(cvar("g_maplist_textonly"))
-	{
-		FOR_EACH_REALCLIENT(other)
-		{
-			// display voting screen
-			msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
-			msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
-			if(mapvote_abstain)
-				msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
-			msgstr = strcat(msgstr, mapvote_message);
-			msgstr = strcat(msgstr, "\n\n");
-			for(i = 0; i < mapvote_count; ++i)
-				if(mapvote_maps[i] == "")
-					msgstr = strcat(msgstr, "\n");
-				else
-				{
-					tmp = mapvote_maps[i];
-					tmp = strpad(mapvote_maxlen, tmp);
-					tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
-					if(mapvote_detail)
-					{
-						tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
-						if(mapvote_votes[i] != 1)
-							tmp = strcat(tmp, "s");
-						tmp = strcat(tmp, ")");
-						tmp = strpad(mapvote_maxlen + 15, tmp);
-					}
-					if(mapvote_abstain)
-						if(i == mapvote_count - 1)
-							msgstr = strcat(msgstr, "\n");
-					if(other.mapvote == i + 1)
-						msgstr = strcat(msgstr, "^3> ", tmp, "\n");
-					else
-						msgstr = strcat(msgstr, "^7  ", tmp, "\n");
-				}
-
-			msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
-			if(totalvotes != 1)
-				msgstr = strcat(msgstr, "s");
-			msgstr = strcat(msgstr, " cast");
-			i = ceil(mapvote_timeout - time);
-			msgstr = strcat(msgstr, "\n", ftos(i), " second");
-			if(i != 1)
-				msgstr = strcat(msgstr, "s");
-			msgstr = strcat(msgstr, " left");
-
-			centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
-		}
-	}
 }
 void MapVote_Start()
 {




More information about the nexuiz-commits mailing list