From dcef5e812c54dd67d5eff9590e2ad6e698614e9d Mon Sep 17 00:00:00 2001 From: div0 Date: Tue, 27 Jan 2009 13:21:55 +0000 Subject: [PATCH] make TE_CSQC_INIT and TE_CSQC_SCORESINFO shared entities. Should fix their issues with savegames. git-svn-id: svn://svn.icculus.org/nexuiz/trunk@5676 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/client/Main.qc | 26 +++++++++++++------------- data/qcsrc/common/constants.qh | 3 +-- data/qcsrc/server/cl_client.qc | 29 ++++++++++++++--------------- data/qcsrc/server/g_world.qc | 3 +++ data/qcsrc/server/scores.qc | 32 ++++++++++++++++++++------------ data/qcsrc/server/scores.qh | 8 +------- 6 files changed, 52 insertions(+), 49 deletions(-) diff --git a/data/qcsrc/client/Main.qc b/data/qcsrc/client/Main.qc index fb7e5f70c..3c315c62e 100644 --- a/data/qcsrc/client/Main.qc +++ b/data/qcsrc/client/Main.qc @@ -482,6 +482,8 @@ void Ent_Nagger() // 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 Ent_RadarLink(); +void Ent_Init(); +void Ent_ScoresInfo(); void(float bIsNewEntity) CSQC_Ent_Update = { float t; @@ -528,6 +530,10 @@ void(float bIsNewEntity) CSQC_Ent_Update = Ent_DamageInfo(); else if(self.enttype == ENT_CLIENT_CASING) Ent_Casing(); + else if(self.enttype == ENT_CLIENT_INIT) + Ent_Init(); + else if(self.enttype == ENT_CLIENT_SCORES_INFO) + Ent_ScoresInfo(); else error(strcat("unknown entity type in CSQC_Ent_Update: ", ftos(self.enttype), "\n")); @@ -648,7 +654,7 @@ void Net_ReadFog() } void Gamemode_Init(); -void Net_ReadScoresInfo() +void Ent_ScoresInfo() { float i; gametype = ReadByte(); @@ -666,9 +672,11 @@ void Net_ReadScoresInfo() Gamemode_Init(); } -void Net_ReadInit() +void Ent_Init() { float i; + self.classname = "ent_client_init"; + csqc_revision = ReadShort(); maxclients = ReadByte(); for(i = 0; i < 24; ++i) @@ -677,6 +685,9 @@ void Net_ReadInit() hook_shotorigin_y = ReadCoord(); hook_shotorigin_z = ReadCoord(); CSQC_CheckRevision(); + + if(!postinit) + PostInit(); } string Net_ReadPicture() @@ -832,10 +843,6 @@ float CSQC_Parse_TempEntity() // NOTE: Could just do return instead of break... switch(nTEID) { - case TE_CSQC_INIT: - Net_ReadInit(); - bHandled = true; - break; case TE_CSQC_MAPVOTE: Net_Mapvote(); bHandled = true; @@ -844,10 +851,6 @@ float CSQC_Parse_TempEntity() Net_Config(); bHandled = true; break; - case TE_CSQC_SCORESINFO: - Net_ReadScoresInfo(); - bHandled = true; - break; case TE_CSQC_RACE: Net_ReadRace(); bHandled = true; @@ -889,9 +892,6 @@ float CSQC_Parse_TempEntity() bHandled = false; break; } - - if(!postinit) - PostInit(); return bHandled; } diff --git a/data/qcsrc/common/constants.qh b/data/qcsrc/common/constants.qh index 1c6787271..624eeeaa0 100644 --- a/data/qcsrc/common/constants.qh +++ b/data/qcsrc/common/constants.qh @@ -58,6 +58,7 @@ const float ENT_CLIENT_PROJECTILE = 12; const float ENT_CLIENT_GIBSPLASH = 13; const float ENT_CLIENT_DAMAGEINFO = 14; const float ENT_CLIENT_CASING = 15; +const float ENT_CLIENT_INIT = 16; const float SPRITERULE_DEFAULT = 0; const float SPRITERULE_TEAMPLAY = 1; @@ -213,11 +214,9 @@ const float ENTCS_MSG_ONS_GPS = 1; const float ENTCS_MSG_ONS_REMOVE = 2; const float ENTCS_MSG_INIT = 3; -const float TE_CSQC_INIT = 100; // TODO get rid of this 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_SCORESINFO = 108; // TODO turn into shared ent const float TE_CSQC_RACE = 109; const float TE_CSQC_FORCESCOREBOARD = 110; // TODO turn into shared ent const float TE_CSQC_SPECTATING = 111; // TODO turn into shared ent diff --git a/data/qcsrc/server/cl_client.qc b/data/qcsrc/server/cl_client.qc index 9e07e2d6f..83d5f25b7 100644 --- a/data/qcsrc/server/cl_client.qc +++ b/data/qcsrc/server/cl_client.qc @@ -823,21 +823,10 @@ void PutClientInServer (void) // ctf_playerchanged(); } -/* -============= -SendCSQCInfo - -Send whatever CSQC needs NOW and cannot wait for SendServerInfo to happen... -============= -*/ -void SendCSQCInfo(void) +float ClientInit_SendEntity(entity to, float sf) { float i; - if(clienttype(self) != CLIENTTYPE_REAL) - return; - msg_entity = self; - WriteByte(MSG_ONE, SVC_TEMPENTITY); - WriteByte(MSG_ONE, TE_CSQC_INIT); + WriteByte(MSG_ENTITY, ENT_CLIENT_INIT); WriteShort(MSG_ONE, CSQC_REVISION); WriteByte(MSG_ONE, maxclients); for(i = 1; i <= 24; ++i) @@ -845,6 +834,17 @@ void SendCSQCInfo(void) WriteCoord(MSG_ONE, hook_shotorigin_x); WriteCoord(MSG_ONE, hook_shotorigin_y); WriteCoord(MSG_ONE, hook_shotorigin_z); + return TRUE; +} + +void ClientInit_Spawn() +{ + entity e; + e = spawn(); + e.classname = "ent_client_init"; + e.SendEntity = ClientInit_SendEntity; + setmodel(e, "null"); + e.effects = EF_NODEPTHTEST; } /* @@ -1267,14 +1267,13 @@ void ClientConnect (void) if(clienttype(self) == CLIENTTYPE_REAL) { sprint(self, strcat("nexuiz-csqc protocol ", ftos(CSQC_REVISION), "\n")); - SendCSQCInfo(); + msg_entity = self; if(mapvote_initialized && !cvar("g_maplist_textonly")) { MapVote_SendData(MSG_ONE); MapVote_UpdateData(MSG_ONE); } - ScoreInfo_Write(MSG_ONE); if(inWarmupStage) { diff --git a/data/qcsrc/server/g_world.qc b/data/qcsrc/server/g_world.qc index d6e4f421d..df4f3edff 100644 --- a/data/qcsrc/server/g_world.qc +++ b/data/qcsrc/server/g_world.qc @@ -301,6 +301,7 @@ void detect_maptype() float world_already_spawned; void RegisterWeapons(); void Nagger_Init(); +void ClientInit_Spawn(); void spawnfunc_worldspawn (void) { float fd, l, i, j, n; @@ -555,6 +556,8 @@ void spawnfunc_worldspawn (void) records_reply = strzone(getrecords()); + ClientInit_Spawn(); + world_initialized = 1; } diff --git a/data/qcsrc/server/scores.qc b/data/qcsrc/server/scores.qc index 2a4218281..612e399e4 100644 --- a/data/qcsrc/server/scores.qc +++ b/data/qcsrc/server/scores.qc @@ -150,29 +150,38 @@ void ScoreInfo_SetLabel_TeamScore(float i, string label, float scoreflags) } } -void ScoreInfo_Write(float targ) +float ScoreInfo_SendEntity(entity to, float sf) { float i; - if not(scores_initialized) - return; - WriteByte(targ, SVC_TEMPENTITY); - WriteByte(targ, TE_CSQC_SCORESINFO); - WriteByte(targ, game); + WriteByte(MSG_ENTITY, ENT_CLIENT_SCORES_INFO); + WriteByte(MSG_ENTITY, game); for(i = 0; i < MAX_SCORE; ++i) { - WriteString(targ, scores_label[i]); - WriteByte(targ, scores_flags[i]); + WriteString(MSG_ENTITY, scores_label[i]); + WriteByte(MSG_ENTITY, scores_flags[i]); } for(i = 0; i < MAX_TEAMSCORE; ++i) { - WriteString(targ, teamscores_label[i]); - WriteByte(targ, teamscores_flags[i]); + WriteString(MSG_ENTITY, teamscores_label[i]); + WriteByte(MSG_ENTITY, teamscores_flags[i]); } + return TRUE; } void ScoreInfo_Init(float teams) { - scores_initialized = 1; + if(scores_initialized) + { + scores_initialized.SendFlags |= 1; // force a resend + } + else + { + scores_initialized = spawn(); + scores_initialized.classname = "ent_client_scoreinfo"; + scores_initialized.SendEntity = ScoreInfo_SendEntity; + setmodel(scores_initialized, "null"); + scores_initialized.effects = EF_NODEPTHTEST; + } if(teams >= 1) TeamScore_Spawn(COLOR_TEAM1, "Red"); if(teams >= 2) @@ -181,7 +190,6 @@ void ScoreInfo_Init(float teams) TeamScore_Spawn(COLOR_TEAM3, "Yellow"); if(teams >= 4) TeamScore_Spawn(COLOR_TEAM4, "Pink"); - ScoreInfo_Write(MSG_ALL); } /* diff --git a/data/qcsrc/server/scores.qh b/data/qcsrc/server/scores.qh index d6d89eff5..2edea35fd 100644 --- a/data/qcsrc/server/scores.qh +++ b/data/qcsrc/server/scores.qh @@ -1,4 +1,4 @@ -float scores_initialized; // 1 when scores labels/rules have been set +entity scores_initialized; // non-world when scores labels/rules have been set .float scores[MAX_SCORE]; .float teamscores[MAX_TEAMSCORE]; @@ -74,12 +74,6 @@ void ScoreInfo_SetLabel_PlayerScore(float i, string label, float scoreflags); */ void ScoreInfo_Init(float teams); -/** - * Writes the scores info to the given stream. Use this in ClientConnect to - * notify newly connecting players. - */ -void ScoreInfo_Write(float targ); - /** * Clear ALL scores (for ready-restart). */ -- 2.39.2