r3775 - in trunk/data/qcsrc: client common server
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Fri Jul 4 12:43:41 EDT 2008
Author: blub0
Date: 2008-07-04 12:43:40 -0400 (Fri, 04 Jul 2008)
New Revision: 3775
Modified:
trunk/data/qcsrc/client/Main.qc
trunk/data/qcsrc/client/View.qc
trunk/data/qcsrc/client/main.qh
trunk/data/qcsrc/client/sbar.qc
trunk/data/qcsrc/common/constants.qh
trunk/data/qcsrc/server/ent_cs.qc
trunk/data/qcsrc/server/teamplay.qc
Log:
using the clientinfo entities for the ping times
also changed the network traffic of them a bit, it was a bit of a mess before
changed the "pingbuf" to be a more general "databuf" with numeric offsets
like: DATABUF_PING + <playernumber>
Modified: trunk/data/qcsrc/client/Main.qc
===================================================================
--- trunk/data/qcsrc/client/Main.qc 2008-07-04 14:56:23 UTC (rev 3774)
+++ trunk/data/qcsrc/client/Main.qc 2008-07-04 16:43:40 UTC (rev 3775)
@@ -2,7 +2,6 @@
// BEGIN REQUIRED CSQC FUNCTIONS
//include "main.qh"
-
void() menu_show_error =
{
drawstring('0 200', "ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!", '8 8 0', '1 0 0', 1, 0);
@@ -15,26 +14,18 @@
{
};
-float last_pingrequest;
-float parse_ping;
-float ping_line;
-entity pingList;
-float pingbuf;
+// let's make this a general data buffer...
+float databuf;
+float using_gps;
void CSQC_Init(void)
{
float i;
- last_pingrequest = 0;
- parse_ping = 0;
- ping_line = 0;
- pingList = spawn();
- pingList.sort_next = NULL;
- pingList.sort_prev = NULL;
-
menu_visible = FALSE;
menu_show = menu_show_error;
menu_action = menu_sub_null;
+ using_gps = false;
//ctf_temp_1 = "";
localcmd("alias order \"cmd order $*\"");
//registercmd("ctf_menu");
@@ -47,24 +38,16 @@
gps_start = world;
- pingbuf = buf_create();
+ databuf = buf_create();
for(i = 0; i < maxclients; ++i)
- bufstr_add(pingbuf, "-", false);
+ bufstr_set(databuf, DATABUF_PING + i, "N/A");
}
// CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)
void CSQC_Shutdown(void)
{
entity next;
- buf_del(pingbuf);
-
- while(pingList.sort_next)
- {
- next = pingList.sort_next;
- pingList.sort_next = next.sort_next;
- remove(next);
- }
- remove(pingList);
+ buf_del(databuf);
}
// CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercmd" function
@@ -114,24 +97,52 @@
// --------------------------------------------------------------------------
// BEGIN OPTIONAL CSQC FUNCTIONS
+void ReadPings()
+{
+ float plnum, ping;
+ for(plnum = ReadByte(); plnum != 0; plnum = ReadByte())
+ {
+ ping = ReadShort();
+ bufstr_set(databuf, DATABUF_PING + plnum-1, ftos(ping));
+ }
+}
+
+void ReadONS(float bIsNewEntity)
+{
+ using_gps = true;
+
+ self.origin_x = ReadCoord();
+ self.origin_y = ReadCoord();
+ self.angles_y = ReadCoord();
+ self.origin_z = self.angles_x = self.angles_z = 0;
+
+ if(bIsNewEntity)
+ {
+ //print(strcat("Adding entity: ", ftos(self.sv_entnum), "\n"));
+ self.chain = gps_start;
+ gps_start = self;
+ }
+}
+
// CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.
// The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.
void(float bIsNewEntity) CSQC_Ent_Update =
{
+ float tmp, plnum, msg;
self.enttype = ReadByte();
if(self.enttype == ENT_CLIENT_ENTCS)
{
- self.sv_entnum = ReadByte();
- self.origin_x = ReadCoord();
- self.origin_y = ReadCoord();
- self.angles_y = ReadCoord();
- self.origin_z = self.angles_x = self.angles_z = 0;
+ self.sv_entnum = ReadByte()-1;
- if(bIsNewEntity)
+ for(msg = ReadByte(); msg != ENTCS_MSG_END; msg = ReadByte())
{
- //print(strcat("Adding entity: ", ftos(self.sv_entnum), "\n"));
- self.chain = gps_start;
- gps_start = self;
+ switch(msg)
+ {
+ case ENTCS_MSG_PING: ReadPings(); break;
+ case ENTCS_MSG_ONS: ReadONS(bIsNewEntity); break;
+ default:
+ error("unknown ENTCS_MSG type\n");
+ };
}
}
else
@@ -143,17 +154,20 @@
{
if(self.enttype == ENT_CLIENT_ENTCS)
{
- if(gps_start == self)
- gps_start = self.chain;
- else
+ if(using_gps) //gametype == GAME_ONSLAUGHT)
{
- local entity ent;
- ent = gps_start;
+ if(gps_start == self)
+ gps_start = self.chain;
+ else
+ {
+ local entity ent;
+ ent = gps_start;
- while(ent.chain != self && ent.chain != world)
- ent = ent.chain;
- if(ent.chain == self)
- ent.chain = self.chain;
+ while(ent.chain != self && ent.chain != world)
+ ent = ent.chain;
+ if(ent.chain == self)
+ ent.chain = self.chain;
+ }
}
}
remove(self);
@@ -228,75 +242,10 @@
Gamemode_Init();
}
}
-
-void PingRequest()
-{
- float i;
- entity next;
-
- last_pingrequest = time + 5;
-
- parse_ping = 0;
- ping_line = 0;
- for(i = 0; i < maxclients; ++i)
- {
- if(strlen(getplayerkey(i, "name")))
- ++parse_ping;
- }
-
- while(pingList.sort_next)
- {
- next = pingList.sort_next;
- pingList.sort_next = next.sort_next;
- remove(next);
- }
- pingList.sort_prev = NULL;
-
- localcmd("\nping\n");
-}
-
// CSQC_Parse_Print : Provides the print string in the first parameter that the server provided. To execute standard behavior, simply execute print with the string.
void CSQC_Parse_Print(string strMessage)
{
- if(!parse_ping)
- print(strMessage);
- else if(strMessage != "Client ping times:\n")
- {
- float ping, i, p;
- entity tmp;
-
- // pingList.sort_prev = last element
-
- ping = stof(strMessage);
-
- /*strMessage = substring(strMessage, 5, 999);
- print(strcat("Ping for # ", ftos(ping_line), " of ", ftos(parse_ping), " = ", ftos(ping), " player: "));
- print(strMessage);
- print(" searching... ");*/
- for(i = 0; i < maxclients; ++i)
- {
- if(strlen(getplayerkey(i, "name"))) {
- ++p;
- if(p > ping_line)
- break;
- }
- }
- if(i >= maxclients)
- i = maxclients-1;
-
- bufstr_set(pingbuf, i, ftos(ping));
- /*print(getplayerkey(i, "name"));
- print("\n");*/
-
- /*tmp = spawn();
- tmp.sort_next = tmp.sort_prev = NULL;
- pingList.sort_prev.sort_next = tmp;
- pingList.sort_prev = tmp;*/
-
- ++ping_line;
- if(ping_line >= parse_ping)
- parse_ping = false;
- }
+ print(strMessage);
}
// CSQC_Parse_CenterPrint : Provides the centerprint string in the first parameter that the server provided. To execute standard behavior, simply execute cprint with the string.
void CSQC_Parse_CenterPrint(string strMessage)
Modified: trunk/data/qcsrc/client/View.qc
===================================================================
--- trunk/data/qcsrc/client/View.qc 2008-07-04 14:56:23 UTC (rev 3774)
+++ trunk/data/qcsrc/client/View.qc 2008-07-04 16:43:40 UTC (rev 3775)
@@ -26,10 +26,6 @@
last_weapon = activeweapon;
}
- if(last_pingrequest < time) {
- PingRequest();
- }
-
// ALWAYS Clear Current Scene First
R_ClearScene();
Modified: trunk/data/qcsrc/client/main.qh
===================================================================
--- trunk/data/qcsrc/client/main.qh 2008-07-04 14:56:23 UTC (rev 3774)
+++ trunk/data/qcsrc/client/main.qh 2008-07-04 16:43:40 UTC (rev 3775)
@@ -1,6 +1,9 @@
// --------------------------------------------------------------------------
// MENU Functionality
+#define DATABUF_PING 0
+#define DATABUF_SAMPLE (1*maxclients)
+
void() menu_show_error;
void() menu_sub_null;
Modified: trunk/data/qcsrc/client/sbar.qc
===================================================================
--- trunk/data/qcsrc/client/sbar.qc 2008-07-04 14:56:23 UTC (rev 3774)
+++ trunk/data/qcsrc/client/sbar.qc 2008-07-04 16:43:40 UTC (rev 3775)
@@ -224,7 +224,7 @@
tmp_y = tmp_z = 0;
pos_x += 56;
- str = bufstr_get(pingbuf, pl.sb_player);
+ str = bufstr_get(databuf, DATABUF_PING + pl.sb_player);
tmp_x = 4*8 - strlen(str) * 8 - 56;
drawstring(pos + tmp, str, '8 8 0', '0.8 0.8 0.8', 0.8, 0);
@@ -602,7 +602,7 @@
sbar_x = (vid_conwidth - 640.0)*0.5;
sbar_y = vid_conheight - 47;
//Sbar_DrawAlphaPic (sbar_x, sbar_y, sb_scorebar, sbar_alpha_bg.value);
- drawpic('0 0', "gfx/scorebar", '0 0 0', '1 1 1', cvar("sbar_alpha_bg"), 0);
+ //drawpic('0 0', "gfx/scorebar", '0 0 0', '1 1 1', cvar("sbar_alpha_bg"), 0);
Sbar_DrawScoreboard ();
}
else
Modified: trunk/data/qcsrc/common/constants.qh
===================================================================
--- trunk/data/qcsrc/common/constants.qh 2008-07-04 14:56:23 UTC (rev 3774)
+++ trunk/data/qcsrc/common/constants.qh 2008-07-04 16:43:40 UTC (rev 3775)
@@ -152,3 +152,7 @@
const float K_MOUSE14 = 527;
const float K_MOUSE15 = 528;
const float K_MOUSE16 = 529;
+
+const float ENTCS_MSG_END = 0;
+const float ENTCS_MSG_PING = 1;
+const float ENTCS_MSG_ONS = 2;
Modified: trunk/data/qcsrc/server/ent_cs.qc
===================================================================
--- trunk/data/qcsrc/server/ent_cs.qc 2008-07-04 14:56:23 UTC (rev 3774)
+++ trunk/data/qcsrc/server/ent_cs.qc 2008-07-04 16:43:40 UTC (rev 3775)
@@ -16,9 +16,11 @@
.float(entity to) SendEntity;
.float Version;
+.float pingtime;
+
entity entcs_start;
-void() entcs_init =
+void entcs_init()
{
print("Initializing ClientSide information entities\n");
entcs_start = spawn();
@@ -26,7 +28,7 @@
entcs_start.chain = world;
};
-entity(float num) get_entcs_ent =
+entity get_entcs_ent(float num)
{
entity entcs;
entcs = spawn();
@@ -35,32 +37,64 @@
return entcs;
};
-
-float(entity to) entcs_send =
+void entcs_ons(entity to)
{
if(to == self.owner || self.team != to.team)
- return FALSE;
+ return;
if(self.owner.classname == "observer" || to.classname == "observer")
- return FALSE;
-
- WriteByte(MSG_ENTITY, ENT_CLIENT_ENTCS);
- WriteByte(MSG_ENTITY, self.health); // serves as entitynumber
+ return;
+ WriteByte(MSG_ENTITY, ENTCS_MSG_ONS);
WriteCoord(MSG_ENTITY, self.owner.origin_x);
WriteCoord(MSG_ENTITY, self.owner.origin_y);
WriteCoord(MSG_ENTITY, self.owner.angles_y);
- // write health maybe?
+}
+
+void entcs_common_self()
+{
+ entity pl;
+ if(self.pingtime < time)
+ {
+ self.pingtime = time + 9; // keep it 1 below the non-ons update intervall
+ // just to be safe... (blah)
+ WriteByte(MSG_ENTITY, ENTCS_MSG_PING);
+ FOR_EACH_REALCLIENT(pl)
+ {
+ WriteByte(MSG_ENTITY, num_for_edict(pl));
+ WriteShort(MSG_ENTITY, pl.ping);
+ }
+ WriteByte(MSG_ENTITY, 0);
+ }
+}
+
+float entcs_send(entity to)
+{
+ WriteByte(MSG_ENTITY, ENT_CLIENT_ENTCS);
+ WriteByte(MSG_ENTITY, self.health); // serves as entitynumber
+
+ if(to == self.owner)
+ {
+ entcs_common_self();
+ }
+
+ if(game == GAME_ONSLAUGHT)
+ entcs_ons(to);
+
+ WriteByte(MSG_ENTITY, ENTCS_MSG_END);
return TRUE;
};
-void() entcs_think =
+void entcs_think()
{
self.team = self.owner.team;
self.Version++;
setorigin(self, self.owner.origin);
- self.nextthink = time + 0.1;
+ if(game == GAME_ONSLAUGHT)
+ self.nextthink = time + 0.1;
+ else
+ self.nextthink = time + 10; // update pings every 10 seconds
};
-void() attach_entcs =
+void attach_entcs()
{
local float num;
local entity ent;
@@ -80,11 +114,13 @@
ent.model = "entcs_sender";
ent.modelindex = 1;
setsize(ent, '0 0 0', '0 0 0');
+
+ ent.pingtime = time + 5;
ent.SendEntity = entcs_send;
};
-void() detach_entcs =
+void detach_entcs()
{
local float num;
local entity ent;
Modified: trunk/data/qcsrc/server/teamplay.qc
===================================================================
--- trunk/data/qcsrc/server/teamplay.qc 2008-07-04 14:56:23 UTC (rev 3774)
+++ trunk/data/qcsrc/server/teamplay.qc 2008-07-04 16:43:40 UTC (rev 3775)
@@ -326,8 +326,8 @@
tdm_init();
else if (game == GAME_KEYHUNT)//cvar("g_keyhunt"))
kh_init();
- else if (game == GAME_ONSLAUGHT)
- entcs_init();
+ //else if (game == GAME_ONSLAUGHT)
+ entcs_init();
}
string GetClientVersionMessage(float v) {
More information about the nexuiz-commits
mailing list