Skip to content

Commit 40a87a7

Browse files
committed
added watch for cvars
1 parent c2daa8b commit 40a87a7

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Assets/DebugOverlay/Console.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public class Console : IGameSystem
3737

3838
System.UInt32[] m_ConsoleBuffer;
3939

40+
// Watched cvars
41+
static List<CVarBase> watchedCvars = new List<CVarBase>();
42+
public static IEnumerable<CVarBase> WatchedCVars => watchedCvars;
43+
4044
public Console()
4145
{
4246
m_ConsoleBuffer = new System.UInt32[k_BufferSize];
@@ -95,6 +99,7 @@ public void Init()
9599
{
96100
Init(null);
97101
AddCommand("cvars", CmdCvars, "List all config variables");
102+
AddCommand("watch", CmdWatch, "Watch/unwatch a cvar on the overlay");
98103
}
99104

100105
public void Init(DebugOverlay debugOverlay)
@@ -507,5 +512,31 @@ void CmdCvars(string[] args)
507512
}
508513
}
509514

515+
void CmdWatch(string[] args)
516+
{
517+
if (args.Length < 1)
518+
{
519+
Write("Usage: watch <cvarname>\n");
520+
return;
521+
}
522+
var name = args[0];
523+
var cvar = CVarRegistry.Find(name);
524+
if (cvar == null)
525+
{
526+
Write("Unknown cvar: {0}\n", name);
527+
return;
528+
}
529+
if (watchedCvars.Contains(cvar))
530+
{
531+
watchedCvars.Remove(cvar);
532+
Write("Stopped watching {0}\n", name);
533+
}
534+
else
535+
{
536+
watchedCvars.Add(cvar);
537+
Write("Watching {0}\n", name);
538+
}
539+
}
540+
510541
DebugOverlay m_DebugOverlay;
511542
}

Assets/Game/Stats.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ void CalcStatistics(float[] data, out float mean, out float variance, out float
5959
float[] fpsHistory = new float[50];
6060
public void TickUpdate()
6161
{
62+
// Draw all watched cvars (always visible)
63+
int watchY = 5;
64+
foreach (var cvar in Console.WatchedCVars)
65+
{
66+
DebugOverlay.Write(1, watchY++, "{0} = {1}", cvar.name, cvar.GetValueString());
67+
}
68+
6269
if (m_ShowStats < 1)
6370
return;
6471

0 commit comments

Comments
 (0)