From: cloudwalk Date: Sat, 20 Jun 2020 14:51:49 +0000 (+0000) Subject: Initialize console commands and cvars before anything else X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c29be2ab7e92f63b899fcc6ac5a2db1ac6707f12;p=xonotic%2Fdarkplaces.git Initialize console commands and cvars before anything else The idea is to divide initialization into stages. I'm starting with cvars and commands. Next will be memory allocations. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12706 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cmd.c b/cmd.c index f3d0a1cb..880eb9d4 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(qboolean dedicated_server) +void Cmd_Init_Commands(void) { // // register our commands diff --git a/cmd.h b/cmd.h index 8badf436..281b6523 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(qboolean dedicated_server); +void Cmd_Init_Commands(void); /*! 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 4f90e33f..25ebb664 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 (void) +void Collision_Init_Commands (void) { Cvar_RegisterVariable(&collision_impactnudge); Cvar_RegisterVariable(&collision_extendmovelength); @@ -33,6 +33,10 @@ void Collision_Init (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 9984a166..bee78b1f 100644 --- a/collision.h +++ b/collision.h @@ -67,6 +67,7 @@ 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 45509faa..6b3545e8 100644 --- a/console.c +++ b/console.c @@ -842,23 +842,8 @@ void Con_Clear_f(cmd_state_t *cmd) if (con_mutex) Thread_UnlockMutex(con_mutex); } -/* -================ -Con_Init -================ -*/ -void Con_Init (void) +void Con_Init_Commands(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); @@ -909,6 +894,25 @@ void Con_Init (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 a1d0a5b6..aa4a7f30 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 (void) +static void Host_InitLocal_Commands (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,12 +1089,16 @@ 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)) @@ -1160,7 +1164,6 @@ 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; @@ -1208,26 +1211,33 @@ static void Host_Init (void) if (COM_CheckParm("-nostdout")) sys_nostdout = 1; - // 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 + // 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(); Memory_Init_Commands(); - - // initialize console and logging and its cvars/commands - Con_Init(); - - // initialize various cvars that could not be initialized earlier - u8_Init(); + Con_Init_Commands(); + u8_Init_Commands(); 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(); @@ -1252,12 +1262,10 @@ 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(); @@ -1265,13 +1273,9 @@ 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 07750479..d25b0e18 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -2995,10 +2995,10 @@ static void Host_PingPLReport_f(cmd_state_t *cmd) /* ================== -Host_InitCommands +Host_Init_Commands ================== */ -void Host_InitCommands (void) +void Host_Init_Commands (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 077197aa..2836a107 100644 --- a/model_shared.c +++ b/model_shared.c @@ -152,15 +152,8 @@ 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 (void) +void Mod_Init_Commands (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); @@ -180,6 +173,16 @@ void Mod_Init (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 0226e701..68833b80 100644 --- a/model_shared.h +++ b/model_shared.h @@ -1086,6 +1086,7 @@ 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 a2b259b6..d6e122da 100755 --- a/netconn.c +++ b/netconn.c @@ -3866,11 +3866,8 @@ void Net_SlistQW_f(cmd_state_t *cmd) } #endif -void NetConn_Init(void) +void NetConn_Init_Commands(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"); @@ -3913,11 +3910,19 @@ void NetConn_Init(void) Cvar_RegisterVariable(&sv_public); Cvar_RegisterVariable(&sv_public_rejectreason); Cvar_RegisterVariable(&sv_heartbeatperiod); - for (i = 0;sv_masters[i].name;i++) + for (int 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 7120c531..ca46851e 100755 --- a/netconn.h +++ b/netconn.h @@ -441,6 +441,7 @@ 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 26517494..ae40e003 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 f5c59429..d6f4573b 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -2907,12 +2907,7 @@ static void PRVM_EdictWatchpoint_f(cmd_state_t *cmd) PRVM_UpdateBreakpoints(prog); } -/* -=============== -PRVM_Init -=============== -*/ -void PRVM_Init (void) +void PRVM_Init_Commands (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)"); @@ -2953,7 +2948,15 @@ void PRVM_Init (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 5f7f839b..5a5037ed 100644 --- a/quakedef.h +++ b/quakedef.h @@ -537,7 +537,7 @@ typedef struct host_s extern host_t host; -void Host_InitCommands(void); +void Host_Init_Commands(void); void Host_Main(void); void Host_Shutdown(void); void Host_StartVideo(void); diff --git a/server.h b/server.h index 46c12463..33a88acb 100644 --- a/server.h +++ b/server.h @@ -512,6 +512,7 @@ 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 376d7fd8..d8b29cb1 100644 --- a/sv_main.c +++ b/sv_main.c @@ -430,12 +430,7 @@ static void SV_AreaStats_f(cmd_state_t *cmd) World_PrintAreaStats(&sv.world, "server"); } -/* -=============== -SV_Init -=============== -*/ -void SV_Init (void) +void SV_Init_Commands(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] @@ -443,7 +438,6 @@ void SV_Init (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); @@ -625,7 +619,15 @@ void SV_Init (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 4099d0a7..ebb06776 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(void) +void u8_Init_Commands(void) { Cvar_RegisterVariable(&utf8_enable); } diff --git a/utf8lib.h b/utf8lib.h index 543fbfc0..5af25558 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(void); +void u8_Init_Commands(void); size_t u8_strlen(const char*); size_t u8_strnlen(const char*, size_t); diff --git a/world.c b/world.c index fe3e0b60..b65a7bbb 100644 --- a/world.c +++ b/world.c @@ -30,8 +30,14 @@ 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(); +} + void World_Init(void) { Collision_Init(); @@ -1471,29 +1477,9 @@ dllhandle_t ode_dll = NULL; #endif #endif -static void World_Physics_Init(void) +static void World_Physics_Init_Commands(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); @@ -1523,6 +1509,31 @@ static void World_Physics_Init(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 e43ebd14..54d54477 100644 --- a/world.h +++ b/world.h @@ -96,6 +96,7 @@ 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);