From 5e49383b6f8696d44d3e280590c0ff8b3be22256 Mon Sep 17 00:00:00 2001 From: TimePath Date: Wed, 19 Aug 2015 21:38:52 +1000 Subject: [PATCH] Menu support --- mod/client/main.qc | 9 +++++++++ mod/menu/main.qc | 9 +++++++++ mod/menu/progs.inc | 3 +++ qcsrc/client/main.qc | 2 ++ qcsrc/common/mutators/base.qh | 33 ++++++++++++++++++++----------- qcsrc/menu/menu.qc | 1 + qcsrc/menu/progs.src | 2 ++ qcsrc/server/mutators/mutators.qc | 4 ---- 8 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 mod/menu/main.qc create mode 100644 mod/menu/progs.inc diff --git a/mod/client/main.qc b/mod/client/main.qc index e69de29bb..d84239c0b 100644 --- a/mod/client/main.qc +++ b/mod/client/main.qc @@ -0,0 +1,9 @@ +REGISTER_MUTATOR(mutator_mod, cvar("g_mod")); + +MUTATOR_HOOKFUNCTION(mutator_mod, BuildMutatorsString) { + ret_string = strcat(ret_string, ":mod"); +} + +MUTATOR_HOOKFUNCTION(mutator_mod, BuildMutatorsPrettyString) { + ret_string = strcat(ret_string, ", Mod"); +} diff --git a/mod/menu/main.qc b/mod/menu/main.qc new file mode 100644 index 000000000..d84239c0b --- /dev/null +++ b/mod/menu/main.qc @@ -0,0 +1,9 @@ +REGISTER_MUTATOR(mutator_mod, cvar("g_mod")); + +MUTATOR_HOOKFUNCTION(mutator_mod, BuildMutatorsString) { + ret_string = strcat(ret_string, ":mod"); +} + +MUTATOR_HOOKFUNCTION(mutator_mod, BuildMutatorsPrettyString) { + ret_string = strcat(ret_string, ", Mod"); +} diff --git a/mod/menu/progs.inc b/mod/menu/progs.inc new file mode 100644 index 000000000..ae91a9e1c --- /dev/null +++ b/mod/menu/progs.inc @@ -0,0 +1,3 @@ +#if BUILD_MOD +#include "main.qc" +#endif diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index b56887878..2c6320edc 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -40,6 +40,8 @@ #include "../common/items/all.qh" +#include "../common/mutators/base.qh" + #include "../common/weapons/all.qh" #include "../csqcmodellib/cl_model.qh" diff --git a/qcsrc/common/mutators/base.qh b/qcsrc/common/mutators/base.qh index 270e1d874..83945528c 100644 --- a/qcsrc/common/mutators/base.qh +++ b/qcsrc/common/mutators/base.qh @@ -46,9 +46,9 @@ CLASS(CallbackChain, Object) ATTRIB(CallbackChain, cbc_next, CallbackNode, NULL) ATTRIB(CallbackChain, cbc_order, int, 0) - CONSTRUCTOR(CallbackChain, string name) { + CONSTRUCTOR(CallbackChain, string _name) { CONSTRUCT(CallbackChain); - this.netname = name; + this.netname = _name; return this; } @@ -120,6 +120,10 @@ ENDCLASS(CallbackChain) #define _MUTATOR_HANDLE_POPTMP(type, id) id = tmp_##id; #define _MUTATOR_HANDLE_POPOUT(type, id) id = out_##id; +void RegisterHooks() {}; +void RegisterCallbacks() {}; +void RegisterMutators() {}; + #define _MUTATOR_HOOKABLE(id, ...) CallbackChain HOOK_##id; bool __Mutator_Send_##id(__VA_ARGS__) #define MUTATOR_HOOKABLE(id, params) \ _MUTATOR_HOOKABLE(id, int params(_MUTATOR_HANDLE_PARAMS, _MUTATOR_HANDLE_NOP)) { \ @@ -131,7 +135,7 @@ ENDCLASS(CallbackChain) params(_MUTATOR_HANDLE_NOP, _MUTATOR_HANDLE_POPOUT) \ return ret; \ } \ - STATIC_INIT(HOOK_##id) { HOOK_##id = NEW(CallbackChain, #id); } + [[accumulate]] void RegisterHooks() { HOOK_##id = NEW(CallbackChain, #id); } #define MUTATOR_CALLHOOK(id, ...) APPLY(__Mutator_Send_##id, 0, ##__VA_ARGS__) enum { @@ -146,10 +150,10 @@ CLASS(Mutator, Object) ATTRIB(Mutator, m_id, int, 0) ATTRIB(Mutator, mutatorname, string, string_null) ATTRIB(Mutator, mutatorfunc, mutatorfunc_t, func_null) - METHOD(Mutator, mutatorcheck, bool()) - CONSTRUCTOR(Mutator, string name, mutatorfunc_t func) { + ATTRIB(Mutator, mutatorcheck, bool(), func_null) + CONSTRUCTOR(Mutator, string _name, mutatorfunc_t func) { CONSTRUCT(Mutator); - this.mutatorname = name; + this.mutatorname = _name; this.mutatorfunc = func; return this; } @@ -207,13 +211,12 @@ void Mutator_Remove(Mutator mut) Mutator MUTATOR_##name #define MUTATOR_DEFINITION(name) \ bool MUTATORFUNCTION_##name(int mode); \ - STATIC_INIT(MUTATOR_##name) { MUTATOR_##name = NEW(Mutator, #name, MUTATORFUNCTION_##name); } \ + [[accumulate]] void RegisterMutators() { MUTATOR_##name = NEW(Mutator, #name, MUTATORFUNCTION_##name); } \ [[last]] bool MUTATORFUNCTION_##name(int mode) -void RegisterMutators(); const int MUTATORS_MAX = MAX_MUTATORS; -entity MUTATORS[MUTATORS_MAX], MUTATORS_first, MUTATORS_last; -int MUTATORS_COUNT; +noref entity MUTATORS[MUTATORS_MAX], MUTATORS_first, MUTATORS_last; +noref int MUTATORS_COUNT; #define REGISTER_MUTATOR(id, dependence) \ bool MUTATORFUNCTION_##id##_hooks(int mode) { return = false; } \ bool MUTATORFUNCTION_##id(int mode) { \ @@ -224,7 +227,13 @@ int MUTATORS_COUNT; REGISTER(RegisterMutators, MUTATOR, MUTATORS, MUTATORS_COUNT, id, m_id, NEW(Mutator, #id, MUTATORFUNCTION_##id)) \ { this.mutatorcheck = MUTATOR_##id##_check; } \ [[accumulate]] bool MUTATORFUNCTION_##id(int mode) -REGISTER_REGISTRY(RegisterMutators) + +STATIC_INIT(Mutators) { + RegisterHooks(); + RegisterCallbacks(); + RegisterMutators(); + FOREACH(MUTATORS, it.mutatorcheck(), LAMBDA(Mutator_Add(it))); +} #define MUTATOR_ONADD if (mode == MUTATOR_ADDING) #define MUTATOR_ONREMOVE if (mode == MUTATOR_REMOVING) @@ -236,7 +245,7 @@ REGISTER_REGISTRY(RegisterMutators) #define _MUTATOR_CALLBACK(name, func) \ Callback CALLBACK_##name; \ bool func(); \ - STATIC_INIT(CALLBACK_##name) { CALLBACK_##name = NEW(Callback, func); } + [[accumulate]] void RegisterCallbacks() { CALLBACK_##name = NEW(Callback, func); } #define MUTATOR_HOOKFUNCTION(...) \ OVERLOAD(MUTATOR_HOOKFUNCTION, __VA_ARGS__) diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index b2a85093c..bc7234d4a 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -5,6 +5,7 @@ #include "../common/items/all.qh" #include "../common/weapons/all.qh" #include "../common/mapinfo.qh" +#include "../common/mutators/base.qh" /////////////////////////////////////////////// // Menu Source File diff --git a/qcsrc/menu/progs.src b/qcsrc/menu/progs.src index a35fd484f..64f12478d 100644 --- a/qcsrc/menu/progs.src +++ b/qcsrc/menu/progs.src @@ -29,3 +29,5 @@ xonotic/util.qc ../common/weapons/all.qc // TODO ../warpzonelib/mathlib.qc + +../../mod/menu/progs.inc diff --git a/qcsrc/server/mutators/mutators.qc b/qcsrc/server/mutators/mutators.qc index b039cf37f..0c6301532 100644 --- a/qcsrc/server/mutators/mutators.qc +++ b/qcsrc/server/mutators/mutators.qc @@ -34,9 +34,5 @@ void mutators_add() CHECK_MUTATOR_ADD("g_overkill", mutator_overkill, !cvar("g_instagib") && !g_nexball && cvar_string("g_mod_balance") == "Overkill"); CHECK_MUTATOR_ADD("g_buffs", mutator_buffs, 1); - FOREACH(MUTATORS, it.mutatorcheck(), LAMBDA( - Mutator_Add(it) - )); - #undef CHECK_MUTATOR_ADD } -- 2.39.2