From 4b7ecdf74a2ce15316879bcdb0c4d0e646d61100 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 23 Feb 2020 15:56:36 +0900 Subject: [PATCH] Make PR_Init take an instance to initialize This allows internal sub-systems to do per-instance initializations without other engine systems having to know about them. --- include/QF/pr_comp.h | 2 +- include/QF/progs.h | 8 ++++++-- libs/console/menu.c | 2 ++ libs/gamecode/pr_debug.c | 2 +- libs/gamecode/pr_load.c | 7 ++++--- libs/gamecode/pr_opcode.c | 4 ++++ libs/ruamoko/rua_init.c | 1 - nq/source/host.c | 5 ----- nq/source/sv_progs.c | 5 +++++ qw/source/cl_main.c | 4 +--- qw/source/sv_main.c | 3 --- qw/source/sv_progs.c | 6 ++++++ tools/qfcc/source/qfprogs.c | 3 ++- tools/qfcc/test/test-harness.c | 2 +- tools/qwaq/main.c | 2 +- tools/qwaq/qwaq.c | 2 +- 16 files changed, 35 insertions(+), 23 deletions(-) diff --git a/include/QF/pr_comp.h b/include/QF/pr_comp.h index d1865d1cc..9df0416d3 100644 --- a/include/QF/pr_comp.h +++ b/include/QF/pr_comp.h @@ -409,7 +409,7 @@ typedef struct opcode_s { extern opcode_t pr_opcodes[]; opcode_t *PR_Opcode (pr_short_t opcode); -void PR_Opcode_Init (void); +void PR_Opcode_Init (void); // idempotent typedef struct dstatement_s { pr_opcode_e op:16; diff --git a/include/QF/progs.h b/include/QF/progs.h index a413b2f25..a07f70534 100644 --- a/include/QF/progs.h +++ b/include/QF/progs.h @@ -53,8 +53,12 @@ typedef struct edict_s edict_t; ///@{ /** Initialize the progs engine. + + The first call will initialize subsystems common to all progs instances. + + \param pr The progs engine instance to initialize. */ -void PR_Init (void); +void PR_Init (progs_t *pr); /** Initialize the Cvars for the progs engine. Call before calling PR_Init(). */ @@ -1488,7 +1492,7 @@ void *PR_Zone_Realloc (progs_t *pr, void *ptr, pr_int_t size); /// \addtogroup debug ///@{ -void PR_Debug_Init (void); +void PR_Debug_Init (progs_t *pr); void PR_Debug_Init_Cvars (void); int PR_LoadDebug (progs_t *pr); void PR_Debug_Watch (progs_t *pr, const char *expr); diff --git a/libs/console/menu.c b/libs/console/menu.c index 8320bc405..3ebf1d60a 100644 --- a/libs/console/menu.c +++ b/libs/console/menu.c @@ -583,6 +583,8 @@ Menu_Init (void) menu_pr_state.max_edicts = 0; menu_pr_state.zone_size = 1024 * 1024; + PR_Init (&menu_pr_state); + menu_hash = Hash_NewTable (61, menu_get_key, menu_free, 0); PR_RegisterBuiltins (&menu_pr_state, builtins); diff --git a/libs/gamecode/pr_debug.c b/libs/gamecode/pr_debug.c index 0c388eaff..8f05793b9 100644 --- a/libs/gamecode/pr_debug.c +++ b/libs/gamecode/pr_debug.c @@ -200,7 +200,7 @@ error: } void -PR_Debug_Init (void) +PR_Debug_Init (progs_t *pr) { file_hash = Hash_NewTable (1024, file_get_key, file_free, 0); } diff --git a/libs/gamecode/pr_load.c b/libs/gamecode/pr_load.c index 99136ed4f..a7dced537 100644 --- a/libs/gamecode/pr_load.c +++ b/libs/gamecode/pr_load.c @@ -466,10 +466,11 @@ PR_Init_Cvars (void) } VISIBLE void -PR_Init (void) +PR_Init (progs_t *pr) { - PR_Opcode_Init (); - PR_Debug_Init (); + PR_Opcode_Init (); // idempotent + PR_Resources_Init (pr); + PR_Debug_Init (pr); } VISIBLE void diff --git a/libs/gamecode/pr_opcode.c b/libs/gamecode/pr_opcode.c index 0ad3fab4b..26ce130cb 100644 --- a/libs/gamecode/pr_opcode.c +++ b/libs/gamecode/pr_opcode.c @@ -1493,6 +1493,10 @@ PR_Opcode_Init (void) { opcode_t *op; + if (opcode_table) { + // already initialized + return; + } opcode_table = Hash_NewTable (1021, 0, 0, 0); Hash_SetHashCompare (opcode_table, opcode_get_hash, opcode_compare); diff --git a/libs/ruamoko/rua_init.c b/libs/ruamoko/rua_init.c index ab973b569..bbfc67525 100644 --- a/libs/ruamoko/rua_init.c +++ b/libs/ruamoko/rua_init.c @@ -56,7 +56,6 @@ RUA_Init (progs_t *pr, int secure) { size_t i; - PR_Resources_Init (pr); for (i = 0; i < sizeof (init_funcs) / sizeof (init_funcs[0]); i++) init_funcs[i] (pr, secure); } diff --git a/nq/source/host.c b/nq/source/host.c index f6b59cf8b..67b55507b 100644 --- a/nq/source/host.c +++ b/nq/source/host.c @@ -896,14 +896,9 @@ Host_Init (void) Game_Init (); - PR_Init_Cvars (); - SV_Progs_Init_Cvars (); - if (!isDedicated) CL_InitCvars (); - PR_Init (); - if (isDedicated) { PI_RegisterPlugins (server_plugin_list); Con_Init ("server"); diff --git a/nq/source/sv_progs.c b/nq/source/sv_progs.c index 60ee75368..8626ade59 100644 --- a/nq/source/sv_progs.c +++ b/nq/source/sv_progs.c @@ -521,6 +521,8 @@ SV_LoadProgs (void) void SV_Progs_Init (void) { + SV_Progs_Init_Cvars (); + pr_gametype = "netquake"; sv_pr_state.edicts = &sv.edicts; sv_pr_state.num_edicts = &sv.num_edicts; @@ -531,6 +533,8 @@ SV_Progs_Init (void) sv_pr_state.bi_map = bi_map; sv_pr_state.resolve = resolve; + PR_Init (&sv_pr_state); + SV_PR_Cmds_Init (); Cmd_AddCommand ("edict", ED_PrintEdict_f, "Report information on a given " @@ -548,6 +552,7 @@ SV_Progs_Init (void) void SV_Progs_Init_Cvars (void) { + PR_Init_Cvars (); sv_progs = Cvar_Get ("sv_progs", "", CVAR_NONE, NULL, "Override the default game progs."); sv_progs_zone = Cvar_Get ("sv_progs_zone", "256", CVAR_NONE, NULL, diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index 09fb1aec2..aa223736f 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -1804,12 +1804,10 @@ Host_Init (void) Netchan_Init_Cvars (); - PR_Init_Cvars (); + PR_Init_Cvars (); // FIXME location CL_Init_Cvars (); - PR_Init (); - CL_Chat_Init (); CL_Cmd_Init (); diff --git a/qw/source/sv_main.c b/qw/source/sv_main.c index c69e23594..d764c012f 100644 --- a/qw/source/sv_main.c +++ b/qw/source/sv_main.c @@ -2523,8 +2523,6 @@ SV_Init (void) Mod_Init_Cvars (); Netchan_Init_Cvars (); Pmove_Init_Cvars (); - SV_Progs_Init_Cvars (); - PR_Init_Cvars (); // and now reprocess the cmdline's sets for overrides Cmd_StuffCmds (sv_cbuf); @@ -2534,7 +2532,6 @@ SV_Init (void) Game_Init (); - PR_Init (); SV_Progs_Init (); Mod_Init (); diff --git a/qw/source/sv_progs.c b/qw/source/sv_progs.c index f5abeed3f..2c4ff5c3f 100644 --- a/qw/source/sv_progs.c +++ b/qw/source/sv_progs.c @@ -544,6 +544,8 @@ SV_LoadProgs (void) void SV_Progs_Init (void) { + SV_Progs_Init_Cvars (); + pr_gametype = "quakeworld"; sv_pr_state.edicts = &sv.edicts; sv_pr_state.num_edicts = &sv.num_edicts; @@ -556,6 +558,8 @@ SV_Progs_Init (void) sv_pr_state.bi_map = bi_map; sv_pr_state.resolve = resolve; + PR_Init (&sv_pr_state); + SV_PR_Cmds_Init (); SV_PR_QWE_Init (&sv_pr_state); SV_PR_CPQW_Init (&sv_pr_state); @@ -575,6 +579,8 @@ SV_Progs_Init (void) void SV_Progs_Init_Cvars (void) { + PR_Init_Cvars (); + r_skyname = Cvar_Get ("r_skyname", "", CVAR_NONE, NULL, "Default name of skybox if none given by map"); sv_progs = Cvar_Get ("sv_progs", "", CVAR_NONE, NULL, diff --git a/tools/qfcc/source/qfprogs.c b/tools/qfcc/source/qfprogs.c index 42c91b9ed..64dab879a 100644 --- a/tools/qfcc/source/qfprogs.c +++ b/tools/qfcc/source/qfprogs.c @@ -236,7 +236,6 @@ init_qf (void) Cvar_Get ("pr_debug", va ("%d", 1+verbosity), 0, 0, ""); Cvar_Get ("pr_source_path", source_path, 0, 0, ""); PR_Init_Cvars (); - PR_Init (); pr.edicts = &edicts; pr.num_edicts = &num_edicts; @@ -246,6 +245,8 @@ init_qf (void) pr.allocate_progs_mem = allocate_progs_mem; pr.free_progs_mem = free_progs_mem; + PR_Init (&pr); + func_tab = Hash_NewTable (1021, 0, 0, 0); Hash_SetHashCompare (func_tab, func_hash, func_compare); } diff --git a/tools/qfcc/test/test-harness.c b/tools/qfcc/test/test-harness.c index 78c657d05..cabef6ab7 100644 --- a/tools/qfcc/test/test-harness.c +++ b/tools/qfcc/test/test-harness.c @@ -154,7 +154,7 @@ init_qf (void) pr.pr_trace = options.trace; PR_Init_Cvars (); - PR_Init (); + PR_Init (&pr); RUA_Init (&pr, 0); PR_Cmds_Init(&pr); BI_Init (&pr); diff --git a/tools/qwaq/main.c b/tools/qwaq/main.c index 035e4f73b..1ab7c027e 100644 --- a/tools/qwaq/main.c +++ b/tools/qwaq/main.c @@ -117,7 +117,7 @@ init_qf (void) pr.no_exec_limit = 1; PR_Init_Cvars (); - PR_Init (); + PR_Init (&pr); RUA_Init (&pr, 0); PR_Cmds_Init(&pr); BI_Init (&pr); diff --git a/tools/qwaq/qwaq.c b/tools/qwaq/qwaq.c index 24a14d217..b446a02dd 100644 --- a/tools/qwaq/qwaq.c +++ b/tools/qwaq/qwaq.c @@ -128,7 +128,7 @@ init_qf (void) pr.no_exec_limit = 1; PR_Init_Cvars (); - PR_Init (); + PR_Init (&pr); RUA_Init (&pr, 0); PR_Cmds_Init (&pr); BI_Init (&pr);