From a51a70c2254b27a68e5fe74cc5985b02dc36e1e9 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Sun, 21 Jun 2020 19:54:20 +0000 Subject: [PATCH 1/1] Revert "Initialize console commands and cvars before anything else" This reverts commit c29be2ab7e92f63b899fcc6ac5a2db1ac6707f12. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12709 d7cf8633-e32d-0410-b094-e92efae38249 --- cmd.c | 2 +- cmd.h | 2 +- collision.c | 6 +----- collision.h | 1 - console.c | 36 +++++++++++++++------------------ host.c | 54 +++++++++++++++++++++++-------------------------- host_cmd.c | 4 ++-- model_shared.c | 19 ++++++++--------- model_shared.h | 1 - netconn.c | 15 +++++--------- netconn.h | 1 - progsvm.h | 2 +- prvm_edict.c | 15 ++++++-------- quakedef.h | 2 +- server.h | 1 - sv_main.c | 16 +++++++-------- utf8lib.c | 2 +- utf8lib.h | 2 +- world.c | 55 ++++++++++++++++++++------------------------------ world.h | 1 - 20 files changed, 98 insertions(+), 139 deletions(-) diff --git a/cmd.c b/cmd.c index 880eb9d4..f3d0a1cb 100644 --- a/cmd.c +++ b/cmd.c @@ -1520,7 +1520,7 @@ void Cmd_Init(void) cmd_serverfromclient.userdefined = &cmd_userdefined_null; } -void Cmd_Init_Commands(void) +void Cmd_Init_Commands(qboolean dedicated_server) { // // register our commands diff --git a/cmd.h b/cmd.h index 281b6523..8badf436 100644 --- a/cmd.h +++ b/cmd.h @@ -151,7 +151,7 @@ extern qboolean host_stuffcmdsrun; void Cbuf_Lock(cmd_state_t *cmd); void Cbuf_Unlock(cmd_state_t *cmd); -void Cmd_Init_Commands(void); +void Cmd_Init_Commands(qboolean dedicated_server); /*! as new commands are generated from the console or keybindings, * the text is added to the end of the command buffer. diff --git a/collision.c b/collision.c index 25ebb664..4f90e33f 100644 --- a/collision.c +++ b/collision.c @@ -22,7 +22,7 @@ cvar_t collision_bih_fullrecursion = {CVAR_CLIENT | CVAR_SERVER, "collision_bih_ mempool_t *collision_mempool; -void Collision_Init_Commands (void) +void Collision_Init (void) { Cvar_RegisterVariable(&collision_impactnudge); Cvar_RegisterVariable(&collision_extendmovelength); @@ -33,10 +33,6 @@ void Collision_Init_Commands (void) Cvar_RegisterVariable(&collision_triangle_bevelsides); Cvar_RegisterVariable(&collision_triangle_axialsides); Cvar_RegisterVariable(&collision_bih_fullrecursion); -} - -void Collision_Init (void) -{ collision_mempool = Mem_AllocPool("collision cache", 0, NULL); Collision_Cache_Init(collision_mempool); } diff --git a/collision.h b/collision.h index bee78b1f..9984a166 100644 --- a/collision.h +++ b/collision.h @@ -67,7 +67,6 @@ typedef struct trace_s } trace_t; -void Collision_Init_Commands(void); void Collision_Init(void); void Collision_ClipTrace_Box(trace_t *trace, const vec3_t cmins, const vec3_t cmaxs, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, int boxsupercontents, int boxq3surfaceflags, const texture_t *boxtexture); void Collision_ClipTrace_Point(trace_t *trace, const vec3_t cmins, const vec3_t cmaxs, const vec3_t start, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, int boxsupercontents, int boxq3surfaceflags, const texture_t *boxtexture); diff --git a/console.c b/console.c index 6b3545e8..45509faa 100644 --- a/console.c +++ b/console.c @@ -842,8 +842,23 @@ void Con_Clear_f(cmd_state_t *cmd) if (con_mutex) Thread_UnlockMutex(con_mutex); } -void Con_Init_Commands(void) +/* +================ +Con_Init +================ +*/ +void Con_Init (void) { + con_linewidth = 80; + ConBuffer_Init(&con, CON_TEXTSIZE, CON_MAXLINES, zonemempool); + if (Thread_HasThreads()) + con_mutex = Thread_CreateMutex(); + + // Allocate a log queue, this will be freed after configs are parsed + logq_size = MAX_INPUTLINE; + logqueue = (unsigned char *)Mem_Alloc (tempmempool, logq_size); + logq_ind = 0; + Cvar_RegisterVariable (&sys_colortranslation); Cvar_RegisterVariable (&sys_specialcharactertranslation); @@ -894,25 +909,6 @@ void Con_Init_Commands(void) Cmd_AddCommand(CMD_SHARED, "maps", Con_Maps_f, "list information about available maps"); Cmd_AddCommand(CMD_SHARED, "condump", Con_ConDump_f, "output console history to a file (see also log_file)"); -} - -/* -================ -Con_Init -================ -*/ -void Con_Init (void) -{ - con_linewidth = 80; - ConBuffer_Init(&con, CON_TEXTSIZE, CON_MAXLINES, zonemempool); - if (Thread_HasThreads()) - con_mutex = Thread_CreateMutex(); - - // Allocate a log queue, this will be freed after configs are parsed - logq_size = MAX_INPUTLINE; - logqueue = (unsigned char *)Mem_Alloc (tempmempool, logq_size); - logq_ind = 0; - con_initialized = true; Con_DPrint("Console initialized.\n"); } diff --git a/host.c b/host.c index b264324d..a50e5a27 100644 --- a/host.c +++ b/host.c @@ -222,7 +222,7 @@ void Host_SaveConfig_f(cmd_state_t *cmd); void Host_LoadConfig_f(cmd_state_t *cmd); extern cvar_t sv_writepicture_quality; extern cvar_t r_texture_jpeg_fastpicmip; -static void Host_InitLocal_Commands (void) +static void Host_InitLocal (void) { Cmd_AddCommand(CMD_SHARED, "saveconfig", Host_SaveConfig_f, "save settings to config.cfg (or a specified filename) immediately (also automatic when quitting)"); Cmd_AddCommand(CMD_SHARED, "loadconfig", Host_LoadConfig_f, "reset everything and reload configs"); @@ -1089,16 +1089,12 @@ qboolean sys_nostdout = false; static qfile_t *locksession_fh = NULL; static qboolean locksession_run = false; -static void Host_InitSession_Commands(void) -{ - Cvar_RegisterVariable(&sessionid); - Cvar_RegisterVariable(&locksession); -} - static void Host_InitSession(void) { int i; char *buf; + Cvar_RegisterVariable(&sessionid); + Cvar_RegisterVariable(&locksession); // load the session ID into the read-only cvar if ((i = COM_CheckParm("-sessionid")) && (i + 1 < sys.argc)) @@ -1164,6 +1160,7 @@ static void Host_Init (void) int i; const char* os; char vabuf[1024]; + qboolean dedicated_server = COM_CheckParm("-dedicated") || !cl_available; cmd_state_t *cmd = &cmd_client; host.state = host_init; @@ -1211,33 +1208,26 @@ static void Host_Init (void) if (COM_CheckParm("-nostdout")) sys_nostdout = 1; - // Stage 0 - Initialize core subsystems (memory management, command interpreters) - Memory_Init(); // used by everything - Cmd_Init(); // initialize console command/cvar/alias/command execution systems - - // Stage 1 - Initialize all commands and cvars - Cmd_Init_Commands(); + // used by everything + Memory_Init(); + + // initialize console command/cvar/alias/command execution systems + Cmd_Init(); + + Cmd_Init_Commands(dedicated_server); + + // initialize memory subsystem cvars/commands Memory_Init_Commands(); - Con_Init_Commands(); - u8_Init_Commands(); + + // initialize console and logging and its cvars/commands + Con_Init(); + + // initialize various cvars that could not be initialized earlier + u8_Init(); Curl_Init_Commands(); Sys_Init_Commands(); COM_Init_Commands(); FS_Init_Commands(); - NetConn_Init_Commands(); - Crypto_Init_Commands(); - PRVM_Init_Commands(); - Mod_Init_Commands(); - World_Init_Commands(); - SV_Init_Commands(); - V_Init(); // some cvars needed by server player physics (cl_rollangle etc) - Host_Init_Commands(); - Host_InitSession_Commands(); // register the cvars for session locking - Host_InitLocal_Commands(); - TaskQueue_Init(); - - // initialize console and logging and its cvars/commands - Con_Init(); // initialize console window (only used by sys_win.c) Sys_InitConsole(); @@ -1262,10 +1252,12 @@ static void Host_Init (void) // initialize filesystem (including fs_basedir, fs_gamedir, -game, scr_screenshot_name) FS_Init(); + // register the cvars for session locking Host_InitSession(); // must be after FS_Init Crypto_Init(); + Crypto_Init_Commands(); NetConn_Init(); Curl_Init(); @@ -1273,9 +1265,13 @@ static void Host_Init (void) Mod_Init(); World_Init(); SV_Init(); + V_Init(); // some cvars needed by server player physics (cl_rollangle etc) + Host_InitCommands(); + Host_InitLocal(); Host_ServerOptions(); Thread_Init(); + TaskQueue_Init(); CL_Init(); diff --git a/host_cmd.c b/host_cmd.c index d25b0e18..07750479 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -2995,10 +2995,10 @@ static void Host_PingPLReport_f(cmd_state_t *cmd) /* ================== -Host_Init_Commands +Host_InitCommands ================== */ -void Host_Init_Commands (void) +void Host_InitCommands (void) { dpsnprintf(cls.userinfo, sizeof(cls.userinfo), "\\name\\player\\team\\none\\topcolor\\0\\bottomcolor\\0\\rate\\10000\\msg\\1\\noaim\\1\\*ver\\dp"); diff --git a/model_shared.c b/model_shared.c index 2836a107..077197aa 100644 --- a/model_shared.c +++ b/model_shared.c @@ -152,8 +152,15 @@ static void Mod_Print_f(cmd_state_t *cmd); static void Mod_Precache_f(cmd_state_t *cmd); static void Mod_Decompile_f(cmd_state_t *cmd); static void Mod_GenerateLightmaps_f(cmd_state_t *cmd); -void Mod_Init_Commands (void) +void Mod_Init (void) { + mod_mempool = Mem_AllocPool("modelinfo", 0, NULL); + Mem_ExpandableArray_NewArray(&models, mod_mempool, sizeof(dp_model_t), 16); + + Mod_BrushInit(); + Mod_AliasInit(); + Mod_SpriteInit(); + Cvar_RegisterVariable(&r_mipskins); Cvar_RegisterVariable(&r_mipnormalmaps); Cvar_RegisterVariable(&mod_generatelightmaps_unitspersample); @@ -173,16 +180,6 @@ void Mod_Init_Commands (void) Cmd_AddCommand(CMD_CLIENT, "mod_generatelightmaps", Mod_GenerateLightmaps_f, "rebuilds lighting on current worldmodel"); } -void Mod_Init (void) -{ - mod_mempool = Mem_AllocPool("modelinfo", 0, NULL); - Mem_ExpandableArray_NewArray(&models, mod_mempool, sizeof(dp_model_t), 16); - - Mod_BrushInit(); - Mod_AliasInit(); - Mod_SpriteInit(); -} - void Mod_RenderInit(void) { R_RegisterModule("Models", mod_start, mod_shutdown, mod_newmap, NULL, NULL); diff --git a/model_shared.h b/model_shared.h index 68833b80..0226e701 100644 --- a/model_shared.h +++ b/model_shared.h @@ -1086,7 +1086,6 @@ extern cvar_t mod_q3bsp_lightgrid_texture; extern cvar_t mod_q3bsp_lightgrid_world_surfaces; extern cvar_t mod_q3bsp_lightgrid_bsp_surfaces; -void Mod_Init_Commands (void); void Mod_Init (void); void Mod_Reload (void); dp_model_t *Mod_LoadModel(dp_model_t *mod, qboolean crash, qboolean checkdisk); diff --git a/netconn.c b/netconn.c index d6e122da..a2b259b6 100755 --- a/netconn.c +++ b/netconn.c @@ -3866,8 +3866,11 @@ void Net_SlistQW_f(cmd_state_t *cmd) } #endif -void NetConn_Init_Commands(void) +void NetConn_Init(void) { + int i; + lhnetaddress_t tempaddress; + netconn_mempool = Mem_AllocPool("network connections", 0, NULL); Cmd_AddCommand(CMD_SHARED, "net_stats", Net_Stats_f, "print network statistics"); #ifdef CONFIG_MENU Cmd_AddCommand(CMD_CLIENT, "net_slist", Net_Slist_f, "query dp master servers and print all server information"); @@ -3910,19 +3913,11 @@ void NetConn_Init_Commands(void) Cvar_RegisterVariable(&sv_public); Cvar_RegisterVariable(&sv_public_rejectreason); Cvar_RegisterVariable(&sv_heartbeatperiod); - for (int i = 0;sv_masters[i].name;i++) + for (i = 0;sv_masters[i].name;i++) Cvar_RegisterVariable(&sv_masters[i]); Cvar_RegisterVariable(&gameversion); Cvar_RegisterVariable(&gameversion_min); Cvar_RegisterVariable(&gameversion_max); -} - -void NetConn_Init(void) -{ - int i; - lhnetaddress_t tempaddress; - netconn_mempool = Mem_AllocPool("network connections", 0, NULL); - // COMMANDLINEOPTION: Server: -ip sets the ip address of this machine for purposes of networking (default 0.0.0.0 also known as INADDR_ANY), use only if you have multiple network adapters and need to choose one specifically. if ((i = COM_CheckParm("-ip")) && i + 1 < sys.argc) { diff --git a/netconn.h b/netconn.h index ca46851e..7120c531 100755 --- a/netconn.h +++ b/netconn.h @@ -441,7 +441,6 @@ void NetConn_OpenServerPorts(int opennetports); void NetConn_UpdateSockets(void); lhnetsocket_t *NetConn_ChooseClientSocketForAddress(lhnetaddress_t *address); lhnetsocket_t *NetConn_ChooseServerSocketForAddress(lhnetaddress_t *address); -void NetConn_Init_Commands(void); void NetConn_Init(void); void NetConn_Shutdown(void); netconn_t *NetConn_Open(lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress); diff --git a/progsvm.h b/progsvm.h index ae40e003..26517494 100644 --- a/progsvm.h +++ b/progsvm.h @@ -780,7 +780,7 @@ void MVM_reset_cmd(prvm_prog_t *prog); void VM_Cmd_Init(prvm_prog_t *prog); void VM_Cmd_Reset(prvm_prog_t *prog); //============================================================================ -void PRVM_Init_Commands (void); + void PRVM_Init (void); #ifdef PROFILING diff --git a/prvm_edict.c b/prvm_edict.c index d6f4573b..f5c59429 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -2907,7 +2907,12 @@ static void PRVM_EdictWatchpoint_f(cmd_state_t *cmd) PRVM_UpdateBreakpoints(prog); } -void PRVM_Init_Commands (void) +/* +=============== +PRVM_Init +=============== +*/ +void PRVM_Init (void) { Cmd_AddCommand(CMD_SHARED, "prvm_edict", PRVM_ED_PrintEdict_f, "print all data about an entity number in the selected VM (server, client, menu)"); Cmd_AddCommand(CMD_SHARED, "prvm_edicts", PRVM_ED_PrintEdicts_f, "prints all data about all entities in the selected VM (server, client, menu)"); @@ -2948,15 +2953,7 @@ void PRVM_Init_Commands (void) Cvar_RegisterVariable (&prvm_garbagecollection_scan_limit); Cvar_RegisterVariable (&prvm_garbagecollection_strings); Cvar_RegisterVariable (&prvm_stringdebug); -} -/* -=============== -PRVM_Init -=============== -*/ -void PRVM_Init (void) -{ // COMMANDLINEOPTION: PRVM: -norunaway disables the runaway loop check (it might be impossible to exit DarkPlaces if used!) prvm_runawaycheck = !COM_CheckParm("-norunaway"); diff --git a/quakedef.h b/quakedef.h index 5a5037ed..5f7f839b 100644 --- a/quakedef.h +++ b/quakedef.h @@ -537,7 +537,7 @@ typedef struct host_s extern host_t host; -void Host_Init_Commands(void); +void Host_InitCommands(void); void Host_Main(void); void Host_Shutdown(void); void Host_StartVideo(void); diff --git a/server.h b/server.h index 33a88acb..46c12463 100644 --- a/server.h +++ b/server.h @@ -512,7 +512,6 @@ extern client_t *host_client; //=========================================================== -void SV_Init_Commands(void); void SV_Init (void); void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count); diff --git a/sv_main.c b/sv_main.c index d8b29cb1..376d7fd8 100644 --- a/sv_main.c +++ b/sv_main.c @@ -430,7 +430,12 @@ static void SV_AreaStats_f(cmd_state_t *cmd) World_PrintAreaStats(&sv.world, "server"); } -void SV_Init_Commands(void) +/* +=============== +SV_Init +=============== +*/ +void SV_Init (void) { // init the csqc progs cvars, since they are updated/used by the server code // TODO: fix this since this is a quick hack to make some of [515]'s broken code run ;) [9/13/2006 Black] @@ -438,6 +443,7 @@ void SV_Init_Commands(void) extern cvar_t csqc_progcrc; extern cvar_t csqc_progsize; extern cvar_t csqc_usedemoprogs; + Cvar_RegisterVariable(&sv_worldmessage); Cvar_RegisterVariable(&sv_worldname); Cvar_RegisterVariable(&sv_worldnamenoextension); @@ -619,15 +625,7 @@ void SV_Init_Commands(void) Cvar_RegisterVariable (&halflifebsp); Cvar_RegisterVariable (&sv_mapformat_is_quake2); Cvar_RegisterVariable (&sv_mapformat_is_quake3); -} -/* -=============== -SV_Init -=============== -*/ -void SV_Init (void) -{ sv_mempool = Mem_AllocPool("server", 0, NULL); } diff --git a/utf8lib.c b/utf8lib.c index ebb06776..4099d0a7 100644 --- a/utf8lib.c +++ b/utf8lib.c @@ -9,7 +9,7 @@ Initialization of UTF-8 support and new cvars. // for compatibility this defaults to 0 cvar_t utf8_enable = {CVAR_CLIENT | CVAR_SERVER | CVAR_SAVE, "utf8_enable", "0", "Enable UTF-8 support. For compatibility, this is disabled by default in most games."}; -void u8_Init_Commands(void) +void u8_Init(void) { Cvar_RegisterVariable(&utf8_enable); } diff --git a/utf8lib.h b/utf8lib.h index 5af25558..543fbfc0 100644 --- a/utf8lib.h +++ b/utf8lib.h @@ -27,7 +27,7 @@ typedef U_int32 Uchar; // u8_byteofs() and u8_charidx() will simply return whatever is passed as index parameter // u8_getchar() will will just return the next byte, u8_fromchar will write one byte, ... extern cvar_t utf8_enable; -void u8_Init_Commands(void); +void u8_Init(void); size_t u8_strlen(const char*); size_t u8_strnlen(const char*, size_t); diff --git a/world.c b/world.c index b65a7bbb..fe3e0b60 100644 --- a/world.c +++ b/world.c @@ -30,14 +30,8 @@ entities never clip against themselves, or their owner line of sight checks trace->inopen and trace->inwater, but bullets don't */ -static void World_Physics_Init_Commands(void); -static void World_Physics_Init(void); -void World_Init_Commands(void) -{ - Collision_Init_Commands(); - World_Physics_Init_Commands(); -} +static void World_Physics_Init(void); void World_Init(void) { Collision_Init(); @@ -1477,9 +1471,29 @@ dllhandle_t ode_dll = NULL; #endif #endif -static void World_Physics_Init_Commands(void) +static void World_Physics_Init(void) { #ifdef USEODE +#ifndef LINK_TO_LIBODE + const char* dllnames [] = + { +# if defined(WIN32) + "libode3.dll", + "libode2.dll", + "libode1.dll", +# elif defined(MACOSX) + "libode.3.dylib", + "libode.2.dylib", + "libode.1.dylib", +# else + "libode.so.3", + "libode.so.2", + "libode.so.1", +# endif + NULL + }; +#endif + Cvar_RegisterVariable(&physics_ode_quadtree_depth); Cvar_RegisterVariable(&physics_ode_contactsurfacelayer); Cvar_RegisterVariable(&physics_ode_worldstep_iterations); @@ -1509,31 +1523,6 @@ static void World_Physics_Init_Commands(void) Cvar_RegisterVariable(&physics_ode_printstats); Cvar_RegisterVariable(&physics_ode_allowconvex); Cvar_RegisterVariable(&physics_ode); -#endif -} - -static void World_Physics_Init(void) -{ -#ifdef USEODE -#ifndef LINK_TO_LIBODE - const char* dllnames [] = - { -# if defined(WIN32) - "libode3.dll", - "libode2.dll", - "libode1.dll", -# elif defined(MACOSX) - "libode.3.dylib", - "libode.2.dylib", - "libode.1.dylib", -# else - "libode.so.3", - "libode.so.2", - "libode.so.1", -# endif - NULL - }; -#endif #ifndef LINK_TO_LIBODE // Load the DLL diff --git a/world.h b/world.h index 54d54477..e43ebd14 100644 --- a/world.h +++ b/world.h @@ -96,7 +96,6 @@ void World_ClearLink(link_t *l); void World_RemoveLink(link_t *l); void World_InsertLinkBefore(link_t *l, link_t *before, int entitynumber); -void World_Init_Commands(void); void World_Init(void); void World_Shutdown(void); -- 2.39.2