]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_main.c
Initial implementation of cvar aliases, with slowmo as a starting example
[xonotic/darkplaces.git] / sv_main.c
index 19d267505397cf825b218ef83904bd1841de49bb..874174780ee9551e5a14e46e9df60da70acb6e48 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -47,7 +47,8 @@ cvar_t pausable = {CVAR_SERVER, "pausable","1", "allow players to pause or not (
 cvar_t pr_checkextension = {CVAR_SERVER | CVAR_READONLY, "pr_checkextension", "1", "indicates to QuakeC that the standard quakec extensions system is available (if 0, quakec should not attempt to use extensions)"};
 cvar_t samelevel = {CVAR_SERVER | CVAR_NOTIFY, "samelevel","0", "repeats same level if level ends (due to timelimit or someone hitting an exit)"};
 cvar_t skill = {CVAR_SERVER, "skill","1", "difficulty level of game, affects monster layouts in levels, 0 = easy, 1 = normal, 2 = hard, 3 = nightmare (same layout as hard but monsters fire twice)"};
-cvar_t slowmo = {CVAR_CLIENT | CVAR_SERVER, "slowmo", "1.0", "controls game speed, 0.5 is half speed, 2 is double speed"};
+cvar_t host_timescale = {CVAR_CLIENT | CVAR_SERVER, "host_timescale", "1.0", "controls game speed, 0.5 is half speed, 2 is double speed"};
+cvar_t slowmo = {CVAR_ALIAS, "slowmo"};
 
 cvar_t sv_accelerate = {CVAR_SERVER, "sv_accelerate", "10", "rate at which a player accelerates to sv_maxspeed"};
 cvar_t sv_aim = {CVAR_SERVER | CVAR_SAVE, "sv_aim", "2", "maximum cosine angle for quake's vertical autoaim, a value above 1 completely disables the autoaim, quake used 0.93"};
@@ -204,7 +205,7 @@ server_static_t svs;
 
 mempool_t *sv_mempool = NULL;
 
-extern cvar_t slowmo;
+extern cvar_t host_timescale;
 extern float           scr_centertime_off;
 
 // MUST match effectnameindex_t in client.h
@@ -413,7 +414,14 @@ prvm_required_field_t sv_reqglobals[] =
 #undef PRVM_DECLARE_function
 };
 
+static void Host_Timescale_c(char *string)
+{
+       double value;
+       value = atof(string);
 
+       if(value < 0.00001 && value != 0)
+               string[0] = '0', string[1] = 0;
+}
 
 //============================================================================
 
@@ -447,7 +455,9 @@ void SV_Init (void)
        Cvar_RegisterVariable (&csqc_usedemoprogs);
 
        Cmd_AddCommand(&cmd_server, "sv_saveentfile", SV_SaveEntFile_f, "save map entities to .ent file (to allow external editing)");
+       Cmd_AddCommand(&cmd_client, "sv_saveentfile", SV_SaveEntFile_f, "save map entities to .ent file (to allow external editing)");
        Cmd_AddCommand(&cmd_server, "sv_areastats", SV_AreaStats_f, "prints statistics on entity culling during collision traces");
+       Cmd_AddCommand(&cmd_client, "sv_areastats", SV_AreaStats_f, "prints statistics on entity culling during collision traces");
        Cmd_AddCommand(&cmd_serverfromclient, "sv_startdownload", SV_StartDownload_f, "begins sending a file to the client (network protocol use only)");
        Cmd_AddCommand(&cmd_serverfromclient, "download", SV_Download_f, "downloads a specified file from the server");
        Cmd_AddCommand(&cmd_client, "sv_startdownload", Cmd_ForwardToServer_f, "begins sending a file to the client (network protocol use only)");
@@ -464,7 +474,9 @@ void SV_Init (void)
        Cvar_RegisterVariable (&pr_checkextension);
        Cvar_RegisterVariable (&samelevel);
        Cvar_RegisterVariable (&skill);
-       Cvar_RegisterVariable (&slowmo);
+       Cvar_RegisterVariable (&host_timescale);
+       Cvar_RegisterCallback (&host_timescale, Host_Timescale_c);
+       Cvar_RegisterAlias (&slowmo, &host_timescale);
        Cvar_RegisterVariable (&sv_accelerate);
        Cvar_RegisterVariable (&sv_aim);
        Cvar_RegisterVariable (&sv_airaccel_qw);
@@ -2030,7 +2042,7 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t
                // angle fixing was requested by global thinking code...
                // so store the current angles for later use
                VectorCopy(PRVM_serveredictvector(ent, angles), host_client->fixangle_angles);
-               host_client->fixangle_angles_set = TRUE;
+               host_client->fixangle_angles_set = true;
 
                // and clear fixangle for the next frame
                PRVM_serveredictfloat(ent, fixangle) = 0;
@@ -2041,7 +2053,7 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t
                MSG_WriteByte (msg, svc_setangle);
                for (i=0 ; i < 3 ; i++)
                        MSG_WriteAngle (msg, host_client->fixangle_angles[i], sv.protocol);
-               host_client->fixangle_angles_set = FALSE;
+               host_client->fixangle_angles_set = false;
        }
 
        // the runes are in serverflags, pack them into the items value, also pack
@@ -2115,7 +2127,7 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t
                | (sv_gameplayfix_gravityunaffectedbyticrate.integer ? MOVEFLAG_GRAVITYUNAFFECTEDBYTICRATE : 0)
        ;
        statsf[STAT_MOVEVARS_TICRATE] = sys_ticrate.value;
-       statsf[STAT_MOVEVARS_TIMESCALE] = slowmo.value;
+       statsf[STAT_MOVEVARS_TIMESCALE] = host_timescale.value;
        statsf[STAT_MOVEVARS_GRAVITY] = sv_gravity.value;
        statsf[STAT_MOVEVARS_STOPSPEED] = sv_stopspeed.value;
        statsf[STAT_MOVEVARS_MAXSPEED] = sv_maxspeed.value;
@@ -3599,7 +3611,7 @@ static void SVVM_end_increase_edicts(prvm_prog_t *prog)
 
        // link every entity except world
        for (i = 1, ent = prog->edicts;i < prog->num_edicts;i++, ent++)
-               if (!ent->priv.server->free)
+               if (!ent->priv.server->free && !VectorCompare(PRVM_serveredictvector(ent, absmin), PRVM_serveredictvector(ent, absmax)))
                        SV_LinkEdict(ent);
 }
 
@@ -4030,7 +4042,7 @@ static int SV_ThreadFunc(void *voiddata)
 
                        // only advance time if not paused
                        // the game also pauses in singleplayer when menu or console is used
-                       sv.frametime = advancetime * slowmo.value;
+                       sv.frametime = advancetime * host_timescale.value;
                        if (host_framerate.value)
                                sv.frametime = host_framerate.value;
                        if (sv.paused || (cl.islocalgame && (key_dest != key_game || key_consoleactive || cl.csqc_paused)))