From 8a10e95d3765188046ecb946b2a5015ed08b30df Mon Sep 17 00:00:00 2001 From: TimePath Date: Thu, 27 Aug 2015 09:25:52 +1000 Subject: [PATCH] Expand /lib --- qcsrc/common/buffs.qh | 2 - qcsrc/common/items/all.qh | 2 - qcsrc/common/items/item.qh | 1 - qcsrc/common/monsters/all.qh | 2 - qcsrc/common/monsters/monster.qh | 1 - .../common/mutators/mutator/waypoints/all.qh | 2 - qcsrc/common/nades.qh | 2 - qcsrc/common/util-post.qh | 2 - qcsrc/common/util.qh | 67 ------------------- qcsrc/lib/Accumulate.qh | 52 ++++++++++++++ qcsrc/lib/Lazy.qh | 3 + qcsrc/lib/Nil.qh | 13 ++++ qcsrc/{common/oo.qh => lib/OO.qh} | 5 +- qcsrc/lib/Progname.qh | 14 ++++ qcsrc/{common/registry.qh => lib/Registry.qh} | 3 +- qcsrc/lib/_all.inc | 5 ++ qcsrc/menu/oo/base.qh | 2 - 17 files changed, 91 insertions(+), 87 deletions(-) create mode 100644 qcsrc/lib/Accumulate.qh create mode 100644 qcsrc/lib/Nil.qh rename qcsrc/{common/oo.qh => lib/OO.qh} (98%) create mode 100644 qcsrc/lib/Progname.qh rename qcsrc/{common/registry.qh => lib/Registry.qh} (97%) diff --git a/qcsrc/common/buffs.qh b/qcsrc/common/buffs.qh index e0bda4c67..f1ef589ee 100644 --- a/qcsrc/common/buffs.qh +++ b/qcsrc/common/buffs.qh @@ -8,8 +8,6 @@ #include "teams.qh" #include "util.qh" -#include "registry.qh" - void RegisterBuffs(); const int BUFFS_MAX = 16; entity BUFFS[BUFFS_MAX], BUFFS_first, BUFFS_last; diff --git a/qcsrc/common/items/all.qh b/qcsrc/common/items/all.qh index e22bcd747..2e33119fb 100644 --- a/qcsrc/common/items/all.qh +++ b/qcsrc/common/items/all.qh @@ -1,5 +1,3 @@ -#include "../registry.qh" - #ifndef ITEMS_ALL_H #define ITEMS_ALL_H diff --git a/qcsrc/common/items/item.qh b/qcsrc/common/items/item.qh index 6e566f6cc..bddf75b04 100644 --- a/qcsrc/common/items/item.qh +++ b/qcsrc/common/items/item.qh @@ -1,6 +1,5 @@ #ifndef GAMEITEM_H #define GAMEITEM_H -#include "../oo.qh" #define ITEM_HANDLE(signal, ...) __Item_Send_##signal(__VA_ARGS__) /** If you register a new item, make sure to add it to all.inc */ CLASS(GameItem, Object) diff --git a/qcsrc/common/monsters/all.qh b/qcsrc/common/monsters/all.qh index 45adf5e59..4158b1537 100644 --- a/qcsrc/common/monsters/all.qh +++ b/qcsrc/common/monsters/all.qh @@ -1,5 +1,3 @@ -#include "../registry.qh" - #ifndef MONSTERS_ALL_H #define MONSTERS_ALL_H diff --git a/qcsrc/common/monsters/monster.qh b/qcsrc/common/monsters/monster.qh index 75eccd95d..79077acc3 100644 --- a/qcsrc/common/monsters/monster.qh +++ b/qcsrc/common/monsters/monster.qh @@ -3,7 +3,6 @@ bool m_null(int) { return false; } -#include "../oo.qh" /** If you register a new monster, make sure to add it to all.inc */ CLASS(Monster, Object) ATTRIB(Monster, monsterid, int, 0) diff --git a/qcsrc/common/mutators/mutator/waypoints/all.qh b/qcsrc/common/mutators/mutator/waypoints/all.qh index 9670a6f38..790d08698 100644 --- a/qcsrc/common/mutators/mutator/waypoints/all.qh +++ b/qcsrc/common/mutators/mutator/waypoints/all.qh @@ -1,5 +1,3 @@ -#include "../../../registry.qh" - #ifndef WAYPOINTS_ALL_H #define WAYPOINTS_ALL_H diff --git a/qcsrc/common/nades.qh b/qcsrc/common/nades.qh index 50f2e57e8..5a9877c4e 100644 --- a/qcsrc/common/nades.qh +++ b/qcsrc/common/nades.qh @@ -1,8 +1,6 @@ #ifndef NADES_H #define NADES_H -#include "oo.qh" -#include "registry.qh" #include "teams.qh" .float healer_lifetime; diff --git a/qcsrc/common/util-post.qh b/qcsrc/common/util-post.qh index 6d1ab21f9..6b43f34bf 100644 --- a/qcsrc/common/util-post.qh +++ b/qcsrc/common/util-post.qh @@ -3,6 +3,4 @@ #define spawn() new(entity) -#include "oo.qh" - #endif diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index 2e41ce76c..995d882f6 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -1,54 +1,6 @@ #ifndef COMMON_UTIL_H #define COMMON_UTIL_H -#ifdef QCC_SUPPORT_ACCUMULATE -# define ACCUMULATE_FUNCTION(func,otherfunc) \ - [[accumulate]] void func() { otherfunc(); } -# define CALL_ACCUMULATED_FUNCTION(func) \ - func() -#else -#ifdef HAVE_YO_DAWG_CPP -// TODO make ascii art pic of xzibit -// YO DAWG! -// I HERD YO LIEK MACROS -// SO I PUT A MACRO DEFINITION IN YO MACRO DEFINITION -// SO YO CAN EXPAND MACROS WHILE YO EXPAND MACROS -# define ACCUMULATE_FUNCTION(func,otherfunc) \ - #ifdef func \ - void __merge__##otherfunc() { func(); otherfunc(); } \ - #undef func \ - #define func __merge__##otherfunc \ - #else \ - #define func otherfunc \ - #endif -# define CALL_ACCUMULATED_FUNCTION(func) \ - func() -#else -# define ACCUMULATE_FUNCTION(func,otherfunc) \ - .float _ACCUMULATE_##func##__##otherfunc -void ACCUMULATE_call(string func) -{ - float i; - float n = numentityfields(); - string funcprefix = strcat("_ACCUMULATE_", func, "__"); - float funcprefixlen = strlen(funcprefix); - for(i = 0; i < n; ++i) - { - string name = entityfieldname(i); - if(substring(name, 0, funcprefixlen) == funcprefix) - callfunction(substring(name, funcprefixlen, -1)); - } -} -# define CALL_ACCUMULATED_FUNCTION(func) \ - ACCUMULATE_call(#func) -#endif -#endif - -// used for simplifying ACCUMULATE_FUNCTIONs -#define SET_FIRST_OR_LAST(input,first,count) if(!input) { input = (first + count); } -#define SET_FIELD_COUNT(field,first,count) if(!field) { field = (first + count); ++count; } -#define CHECK_MAX_COUNT(name,max,count,type) if(count > max) { error(strcat("Maximum ", type, " hit: ", #name, ": ", ftos(count), ".\n")); } - // this returns a tempstring containing a copy of s with additional \n newlines added, it also replaces \n in the text with a real newline // NOTE: s IS allowed to be a tempstring string wordwrap(string s, float l); @@ -232,14 +184,6 @@ void WriteInt72_t(float dest, vector val); #endif #endif -// the NULL function -#ifdef QCC_SUPPORT_NIL -#define func_null nil -#define string_null nil -#else -var void func_null(void); -string string_null; -#endif float float2range11(float f); float float2range01(float f); @@ -408,17 +352,6 @@ vector animfixfps(entity e, vector a, vector b); void dedicated_print(string input); #endif -// todo: better way to do this? -#ifdef MENUQC -#define PROGNAME "MENUQC" -#else -#ifdef SVQC -#define PROGNAME "SVQC" -#else -#define PROGNAME "CSQC" -#endif -#endif - #ifndef MENUQC const float CNT_NORMAL = 1; const float CNT_GAMESTART = 2; diff --git a/qcsrc/lib/Accumulate.qh b/qcsrc/lib/Accumulate.qh new file mode 100644 index 000000000..423f36413 --- /dev/null +++ b/qcsrc/lib/Accumulate.qh @@ -0,0 +1,52 @@ +#ifndef ACCUMULATE_H +#define ACCUMULATE_H + +#ifdef QCC_SUPPORT_ACCUMULATE +# define ACCUMULATE_FUNCTION(func, otherfunc) \ + [[accumulate]] void func() { otherfunc(); } +# define CALL_ACCUMULATED_FUNCTION(func) \ + func() +#else +#ifdef HAVE_YO_DAWG_CPP +// TODO make ascii art pic of xzibit +// YO DAWG! +// I HERD YO LIEK MACROS +// SO I PUT A MACRO DEFINITION IN YO MACRO DEFINITION +// SO YO CAN EXPAND MACROS WHILE YO EXPAND MACROS +# define ACCUMULATE_FUNCTION(func,otherfunc) \ + #ifdef func \ + void __merge__##otherfunc() { func(); otherfunc(); } \ + #undef func \ + #define func __merge__##otherfunc \ + #else \ + #define func otherfunc \ + #endif +# define CALL_ACCUMULATED_FUNCTION(func) \ + func() +#else +# define ACCUMULATE_FUNCTION(func,otherfunc) \ + .float _ACCUMULATE_##func##__##otherfunc +void ACCUMULATE_call(string func) +{ + float i; + float n = numentityfields(); + string funcprefix = strcat("_ACCUMULATE_", func, "__"); + float funcprefixlen = strlen(funcprefix); + for(i = 0; i < n; ++i) + { + string name = entityfieldname(i); + if(substring(name, 0, funcprefixlen) == funcprefix) + callfunction(substring(name, funcprefixlen, -1)); + } +} +# define CALL_ACCUMULATED_FUNCTION(func) \ + ACCUMULATE_call(#func) +#endif +#endif + +// used for simplifying ACCUMULATE_FUNCTIONs +#define SET_FIRST_OR_LAST(input,first,count) if(!input) { input = (first + count); } +#define SET_FIELD_COUNT(field,first,count) if(!field) { field = (first + count); ++count; } +#define CHECK_MAX_COUNT(name,max,count,type) if(count > max) { error(strcat("Maximum ", type, " hit: ", #name, ": ", ftos(count), ".\n")); } + +#endif diff --git a/qcsrc/lib/Lazy.qh b/qcsrc/lib/Lazy.qh index bf29049e7..fcf065189 100644 --- a/qcsrc/lib/Lazy.qh +++ b/qcsrc/lib/Lazy.qh @@ -1,5 +1,8 @@ #ifndef LAZY_H #define LAZY_H + +#include "OO.qh" + CLASS(Lazy, Object) ATTRIB(Lazy, m_get, entity(), func_null); CONSTRUCTOR(Lazy, entity() _compute) { this.m_get = _compute; } diff --git a/qcsrc/lib/Nil.qh b/qcsrc/lib/Nil.qh new file mode 100644 index 000000000..87e3aea5e --- /dev/null +++ b/qcsrc/lib/Nil.qh @@ -0,0 +1,13 @@ +#ifndef NIL_H +#define NIL_H + +#ifdef QCC_SUPPORT_NIL +#define func_null nil +#define string_null nil +#else +// the NULL function +var void func_null(void); +string string_null; +#endif + +#endif diff --git a/qcsrc/common/oo.qh b/qcsrc/lib/OO.qh similarity index 98% rename from qcsrc/common/oo.qh rename to qcsrc/lib/OO.qh index 3c7237ef4..63a70f7da 100644 --- a/qcsrc/common/oo.qh +++ b/qcsrc/lib/OO.qh @@ -1,7 +1,8 @@ #ifndef OO_H #define OO_H -#include "registry.qh" +#include "Nil.qh" +#include "Registry.qh" #ifdef MENUQC #define NULL (null_entity) @@ -125,7 +126,7 @@ CLASS(Object, ); string value = getentityfieldstring(i, this); if (value != "") s = sprintf("%s\n%s = %s", s, entityfieldname(i), value); } - } + } return s; } METHOD(Object, display, void(entity this, void(string name, string icon) returns)) { diff --git a/qcsrc/lib/Progname.qh b/qcsrc/lib/Progname.qh new file mode 100644 index 000000000..ed112a5c2 --- /dev/null +++ b/qcsrc/lib/Progname.qh @@ -0,0 +1,14 @@ +#ifndef PROGNAME_H +#define PROGNAME_H + +#if defined(MENUQC) + #define PROGNAME "MENUQC" +#elif defined(SVQC) + #define PROGNAME "SVQC" +#elif defined(CSQC) + #define PROGNAME "CSQC" +#else + #error "Unable to detect PROGNAME" +#endif + +#endif diff --git a/qcsrc/common/registry.qh b/qcsrc/lib/Registry.qh similarity index 97% rename from qcsrc/common/registry.qh rename to qcsrc/lib/Registry.qh index 6e8557edf..8a93146d5 100644 --- a/qcsrc/common/registry.qh +++ b/qcsrc/lib/Registry.qh @@ -1,8 +1,7 @@ #ifndef REGISTRY_H #define REGISTRY_H -#include "oo.qh" -#include "util.qh" +#include "OO.qh" #define REGISTER_INIT(ns, id) [[accumulate]] void Register_##ns##_##id##_init(entity this) #define REGISTER_INIT_POST(ns, id) [[accumulate]] void Register_##ns##_##id##_init_post(entity this) diff --git a/qcsrc/lib/_all.inc b/qcsrc/lib/_all.inc index 288553278..931bc50b4 100644 --- a/qcsrc/lib/_all.inc +++ b/qcsrc/lib/_all.inc @@ -1,2 +1,7 @@ +#include "Accumulate.qh" #include "Cvar.qh" #include "Lazy.qh" +#include "Nil.qh" +#include "OO.qh" +#include "Progname.qh" +#include "Registry.qh" diff --git a/qcsrc/menu/oo/base.qh b/qcsrc/menu/oo/base.qh index 28b87ab7f..894b4b928 100644 --- a/qcsrc/menu/oo/base.qh +++ b/qcsrc/menu/oo/base.qh @@ -1,8 +1,6 @@ #ifndef BASE_H #define BASE_H -#include "../../common/oo.qh" - #include "../../common/util.qh" #include "../../dpdefs/keycodes.qh" -- 2.39.2