From: cloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Mon, 20 Jul 2020 17:35:01 +0000 (+0000)
Subject: host: Implement callback for host_framerate instead of checking it every frame
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=29c87fa780d2df4300778002a3768dd601652ce1;p=xonotic%2Fdarkplaces.git

host: Implement callback for host_framerate instead of checking it every frame

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12850 d7cf8633-e32d-0410-b094-e92efae38249
---

diff --git a/host.c b/host.c
index 67434773..dd48b2f0 100644
--- a/host.c
+++ b/host.c
@@ -217,6 +217,12 @@ static void Host_Version_f(cmd_state_t *cmd)
 	Con_Printf("Version: %s build %s\n", gamename, buildstring);
 }
 
+static void Host_Framerate_c(cvar_t *var)
+{
+	if (var->value < 0.00001 && var->value != 0)
+		Cvar_SetValueQuick(var, 0);
+}
+
 /*
 =======================
 Host_InitLocal
@@ -234,6 +240,7 @@ static void Host_InitLocal (void)
 	Cmd_AddCommand(CMD_SHARED, "loadconfig", Host_LoadConfig_f, "reset everything and reload configs");
 	Cvar_RegisterVariable (&cl_maxphysicsframesperserverframe);
 	Cvar_RegisterVariable (&host_framerate);
+	Cvar_RegisterCallback (&host_framerate, Host_Framerate_c);
 	Cvar_RegisterVariable (&host_speeds);
 	Cvar_RegisterVariable (&host_maxwait);
 
@@ -379,9 +386,6 @@ double Host_Frame(double time)
 	double sv_timer = 0;
 	static double wait;
 
-	if (host_framerate.value < 0.00001 && host_framerate.value != 0)
-		Cvar_SetValueQuick(&host_framerate, 0);
-
 	TaskQueue_Frame(false);
 
 	// keep the random time dependent, but not when playing demos/benchmarking