LOG_INFO(_("^3ping^7 Ping time"));
LOG_INFO(_("^3pl^7 Packet loss"));
LOG_INFO(_("^3elo^7 Player ELO"));
+ LOG_INFO(_("^3fps^7 Player FPS"));
LOG_INFO(_("^3kills^7 Number of kills"));
LOG_INFO(_("^3deaths^7 Number of deaths"));
LOG_INFO(_("^3suicides^7 Number of suicides"));
// otherwise the previous exclusive rule warns anyway
// e.g. -teams,rc,cts,lms/kills ?+rc/kills
#define SCOREBOARD_DEFAULT_COLUMNS \
-"ping pl name |" \
+"ping pl fps name |" \
" -teams,rc,cts,inv,lms/kills +ft,tdm/kills ?+rc,inv/kills" \
" -teams,lms/deaths +ft,tdm/deaths" \
" +tdm/sum" \
case "elo": sbt_field[sbt_num_fields] = SP_ELO; break;
case "dmg": case "damage": sbt_field[sbt_num_fields] = SP_DMG; break;
case "dmgtaken": case "damagetaken": sbt_field[sbt_num_fields] = SP_DMGTAKEN; break;
+ case "fps": sbt_field[sbt_num_fields] = SP_FPS; break;
default:
{
FOREACH(Scores, true, {
}
}
+ case SP_FPS:
+ {
+ float fps = pl.(scores(SP_FPS));
+ if(fps == 0)
+ {
+ sbt_field_rgb = '1 1 1';
+ return ((pl.ping == 0) ? _("N/A") : "..."); // if 0 ping, either connecting or bot (either case can't show proper score)
+ }
+ //sbt_field_rgb = HUD_Get_Num_Color(fps, 200);
+ sbt_field_rgb = '1 0 0' + '0 1 1' * (bound(0, fps, 60) / 60);
+ return ftos(fps);
+ }
+
case SP_DMG: case SP_DMGTAKEN:
return sprintf("%.1f k", pl.(scores(field)) / 1000);
viewmodels[slot] = new(viewmodel);
}
+float showfps_prevfps;
+float showfps_prevfps_time;
+int showfps_framecounter;
+
+void fpscounter_update()
+{
+ if(!STAT(SHOWFPS))
+ return;
+
+ float currentTime = gettime(GETTIME_REALTIME);
+ showfps_framecounter += 1;
+ if(currentTime - showfps_prevfps_time > STAT(SHOWFPS))
+ {
+ showfps_prevfps = showfps_framecounter/(currentTime - showfps_prevfps_time);
+ showfps_framecounter = 0;
+ showfps_prevfps_time = currentTime;
+
+ int channel = MSG_C2S;
+ WriteHeader(channel, fpsreport);
+ WriteShort(channel, bound(0, rint(showfps_prevfps), 65535)); // prevent insane fps values
+ }
+}
+
+STATIC_INIT(fpscounter_init)
+{
+ float currentTime = gettime(GETTIME_REALTIME);
+ showfps_prevfps_time = currentTime; // we must initialize it to avoid an instant low frame sending
+}
+
void Porto_Draw(entity this);
STATIC_INIT(Porto)
{
TargetMusic_Advance();
Fog_Force();
+ fpscounter_update();
if(drawtime == 0)
drawframetime = 0.01666667; // when we don't know fps yet, we assume 60fps
REGISTER_NET_LINKED(ENT_CLIENT_WALL)
#include <lib/csqcmodel/net.qh>
+
+REGISTER_NET_C2S(fpsreport)
REGISTER_SP(ELO);
+REGISTER_SP(FPS);
+
// TODO: move to common mutators
REGISTER_SP(RACE_TIME);
REGISTER_STAT(ITEMSTIME, int, autocvar_sv_itemstime)
REGISTER_STAT(KILL_TIME, float)
+#ifdef SVQC
+float autocvar_sv_showfps = 5;
+#endif
+REGISTER_STAT(SHOWFPS, float, autocvar_sv_showfps)
+
#ifdef SVQC
bool autocvar_g_ctf_leaderboard;
#endif
if (g_buf) strunzone(g_buf);
g_buf = strzone(tmp);
}
+ void WriteShort(int to, int b)
+ {
+ WriteByte(to, (b >> 8) & 0xFF);
+ WriteByte(to, b & 0xFF);
+ }
#elif defined(SVQC)
int ReadByte()
{
ydec_single(g_buf, ret);
return ret;
}
+ int ReadShort()
+ {
+ return (ReadByte() << 8) | (ReadByte());
+ }
void WriteByte(int to, int b);
#endif
store.v_angle = this.v_angle;
store.movement = this.movement;
}
+
+NET_HANDLE(fpsreport, bool)
+{
+ int fps = ReadShort();
+ PlayerScore_Set(sender, SP_FPS, fps);
+ return true;
+}
return s.(scores(scorefield));
}
+float PlayerScore_Set(entity player, PlayerScoreField scorefield, float score)
+{
+ if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
+ entity s = CS(player).scorekeeper;
+ if(!s)
+ {
+ if(game_stopped)
+ return 0;
+ LOG_WARN("Setting score of unknown player!");
+ return 0;
+ }
+
+ float oldscore = s.(scores(scorefield));
+ if(oldscore == score)
+ return oldscore;
+
+ if(scores_label(scorefield) != "")
+ s.SendFlags |= (2 ** (scorefield.m_id % 16));
+ s.(scores(scorefield)) = score;
+ return s.(scores(scorefield));
+}
+
float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tscorefield, float score)
{
float r;
*/
float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score);
+/**
+ * Sets the player's score to the score parameter.
+ * NEVER call this if PlayerScore_Attach has not been called yet!
+ * Means: FIXME make players unable to join the game when not called ClientConnect yet.
+ * Returns the new (or old if unchanged) score.
+ */
+float PlayerScore_Set(entity player, PlayerScoreField scorefield, float score);
+
/**
* \brief Returns the player's score.
* \param[in] player Player to inspect.
ScoreInfo_SetLabel_PlayerScore(SP_DMG, "dmg", 0);
ScoreInfo_SetLabel_PlayerScore(SP_DMGTAKEN, "dmgtaken", SFL_LOWER_IS_BETTER);
ScoreInfo_SetLabel_PlayerScore(SP_ELO, "elo", 0);
+
+ if(STAT(SHOWFPS))
+ ScoreInfo_SetLabel_PlayerScore(SP_FPS, "fps", 0);
}
void ScoreRules_basics_end()
{
set sv_showspectators 1 "Show who's spectating who in the player info panel when client has cl_showspectators on. Shouldn't be used on competitive servers, also disable when watching a suspected cheater"
set sv_damagetext 2 "<= 0: disabled, >= 1: visible to spectators, >= 2: visible to attacker, >= 3: all players see everyone's damage"
+
+set sv_showfps 5 "Show player's FPS counters in the scoreboard. This setting acts as a delay in seconds between updates"