From 0e7e4e527797decf984c68638fee5c3ca656f958 Mon Sep 17 00:00:00 2001 From: terencehill Date: Fri, 16 Jun 2017 16:34:37 +0200 Subject: [PATCH] Use a shared array to dump config settings of weapons and turrets, reducing number of globals by 257 --- qcsrc/common/constants.qh | 5 +++++ qcsrc/common/turrets/config.qc | 20 ++++++++++---------- qcsrc/common/turrets/config.qh | 3 --- qcsrc/common/weapons/config.qc | 18 +++++++++--------- qcsrc/common/weapons/config.qh | 5 +---- 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index e7c0f946b..98710d25b 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -256,6 +256,11 @@ vector autocvar_sv_player_crouch_maxs = '16 16 25'; vector autocvar_sv_player_crouch_mins = '-16 -16 -24'; vector autocvar_sv_player_crouch_viewoffset = '0 0 20'; //vector autocvar_sv_player_headsize = '24 24 12'; + +// temporary array used to dump weapon and turret settings +const int MAX_CONFIG_SETTINGS = 256; +string config_queue[MAX_CONFIG_SETTINGS]; + #endif diff --git a/qcsrc/common/turrets/config.qc b/qcsrc/common/turrets/config.qc index 68cac0846..7d1a81d49 100644 --- a/qcsrc/common/turrets/config.qc +++ b/qcsrc/common/turrets/config.qc @@ -5,9 +5,9 @@ void T_Config_Queue_Swap(float root, float child, entity pass) { - string oldroot = tur_config_queue[root]; - tur_config_queue[root] = tur_config_queue[child]; - tur_config_queue[child] = oldroot; + string oldroot = config_queue[root]; + config_queue[root] = config_queue[child]; + config_queue[child] = oldroot; } float T_Config_Queue_Compare(float root, float child, entity pass) @@ -16,8 +16,8 @@ float T_Config_Queue_Compare(float root, float child, entity pass) for(i = 1; i <= 100; ++i) { - r = str2chr(tur_config_queue[root], i); - c = str2chr(tur_config_queue[child], i); + r = str2chr(config_queue[root], i); + c = str2chr(config_queue[child], i); if(r == c) { continue; } else if(c > r) { return -1; } else { return 1; } @@ -32,8 +32,8 @@ void Dump_Turret_Settings() FOREACH(Turrets, it != TUR_Null, { // step 1: clear the queue TUR_CONFIG_COUNT = 0; - for(int j = 0; j <= MAX_TUR_CONFIG; ++j) - { tur_config_queue[j] = string_null; } + for(int j = 0; j <= MAX_CONFIG_SETTINGS; ++j) + config_queue[j] = string_null; // step 2: build new queue it.tr_config(it); @@ -44,7 +44,7 @@ void Dump_Turret_Settings() // step 4: write queue TUR_CONFIG_WRITETOFILE(sprintf("// {{{ #%d: %s\n", i, it.turret_name)) for(int j = 0; j <= TUR_CONFIG_COUNT; ++j) - { TUR_CONFIG_WRITETOFILE(tur_config_queue[j]) } + TUR_CONFIG_WRITETOFILE(config_queue[j]) TUR_CONFIG_WRITETOFILE("// }}}\n") // step 5: debug info @@ -54,8 +54,8 @@ void Dump_Turret_Settings() // clear queue now that we're finished TUR_CONFIG_COUNT = 0; - for(int j = 0; j <= MAX_TUR_CONFIG; ++j) - { tur_config_queue[j] = string_null; } + for(int j = 0; j <= MAX_CONFIG_SETTINGS; ++j) + config_queue[j] = string_null; // extra information LOG_INFO(sprintf("Totals: %d turrets, %d settings\n", (Turrets_COUNT - 1), totalsettings)); diff --git a/qcsrc/common/turrets/config.qh b/qcsrc/common/turrets/config.qh index caa68a864..ac09e9e37 100644 --- a/qcsrc/common/turrets/config.qh +++ b/qcsrc/common/turrets/config.qh @@ -6,10 +6,7 @@ void Dump_Turret_Settings(); float tur_config_file; float tur_config_alsoprint; -const int MAX_TUR_CONFIG = 256; float TUR_CONFIG_COUNT; -string tur_config_queue[MAX_TUR_CONFIG]; - #define TUR_CONFIG_WRITETOFILE(a) { \ fputs(tur_config_file, a); \ if(tur_config_alsoprint) { LOG_INFO(a); } } diff --git a/qcsrc/common/weapons/config.qc b/qcsrc/common/weapons/config.qc index 4f6177b47..7f87388db 100644 --- a/qcsrc/common/weapons/config.qc +++ b/qcsrc/common/weapons/config.qc @@ -12,14 +12,14 @@ void W_Config_Queue_Swap(int root, int child, entity pass) { - string oldroot = wep_config_queue[root]; - wep_config_queue[root] = wep_config_queue[child]; - wep_config_queue[child] = oldroot; + string oldroot = config_queue[root]; + config_queue[root] = config_queue[child]; + config_queue[child] = oldroot; } float W_Config_Queue_Compare(int root, int child, entity pass) { - return strcmp(wep_config_queue[root], wep_config_queue[child]); + return strcmp(config_queue[root], config_queue[child]); } void Dump_Weapon_Settings() @@ -28,8 +28,8 @@ void Dump_Weapon_Settings() FOREACH(Weapons, it != WEP_Null, { // step 1: clear the queue WEP_CONFIG_COUNT = 0; - for (int x = 0; x <= MAX_WEP_CONFIG; ++x) - { wep_config_queue[x] = string_null; } + for (int x = 0; x <= MAX_CONFIG_SETTINGS; ++x) + config_queue[x] = string_null; // step 2: build new queue it.wr_config(it); @@ -44,7 +44,7 @@ void Dump_Weapon_Settings() it.m_name, ((it.spawnflags & WEP_FLAG_MUTATORBLOCKED) ? " (MUTATOR WEAPON)" : "") )); - for (int x = 0; x <= WEP_CONFIG_COUNT; ++x) { WEP_CONFIG_WRITETOFILE(wep_config_queue[x]); } + for (int x = 0; x <= WEP_CONFIG_COUNT; ++x) { WEP_CONFIG_WRITETOFILE(config_queue[x]); } WEP_CONFIG_WRITETOFILE("// }}}\n"); // step 5: debug info @@ -55,8 +55,8 @@ void Dump_Weapon_Settings() // clear queue now that we're finished WEP_CONFIG_COUNT = 0; - for(int x = 0; x <= MAX_WEP_CONFIG; ++x) - { wep_config_queue[x] = string_null; } + for(int x = 0; x <= MAX_CONFIG_SETTINGS; ++x) + config_queue[x] = string_null; // extra information LOG_INFO(sprintf("Totals: %d weapons, %d settings\n", totalweapons, totalsettings)); diff --git a/qcsrc/common/weapons/config.qh b/qcsrc/common/weapons/config.qh index 753147307..948984365 100644 --- a/qcsrc/common/weapons/config.qh +++ b/qcsrc/common/weapons/config.qh @@ -9,12 +9,9 @@ void Dump_Weapon_Settings(); int wep_config_file; bool wep_config_alsoprint; -const int MAX_WEP_CONFIG = 256; int WEP_CONFIG_COUNT; -string wep_config_queue[MAX_WEP_CONFIG]; - #define WEP_CONFIG_QUEUE(a) { \ - wep_config_queue[WEP_CONFIG_COUNT] = a; \ + config_queue[WEP_CONFIG_COUNT] = a; \ ++WEP_CONFIG_COUNT; } #define WEP_CONFIG_WRITETOFILE(a) MACRO_BEGIN { \ -- 2.39.2