From d3387e9314d70cd090c1611669ffd42db3deedbe Mon Sep 17 00:00:00 2001 From: TimePath Date: Thu, 10 Sep 2015 11:01:16 +1000 Subject: [PATCH] Improve compatibility with cpp --- qcsrc/client/hud.qh | 2 +- qcsrc/common/deathtypes.qh | 2 +- qcsrc/common/effects.qh | 4 ++-- qcsrc/common/mutators/base.qh | 2 +- qcsrc/common/notifications.qc | 2 +- qcsrc/common/notifications.qh | 16 +++++++-------- qcsrc/common/turrets/turrets.qh | 2 +- qcsrc/common/util-pre.qh | 23 ++++++++++++++++++---- qcsrc/common/weapons/all.qh | 2 +- qcsrc/lib/Cvar.qh | 2 +- qcsrc/lib/OO.qh | 14 ++++++++++++- qcsrc/menu/xonotic/dialog_settings_game.qc | 3 ++- 12 files changed, 51 insertions(+), 23 deletions(-) diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh index d30eea145d..62b5ec6fd3 100644 --- a/qcsrc/client/hud.qh +++ b/qcsrc/client/hud.qh @@ -198,7 +198,7 @@ void HUD_ItemsTime(); hud_panelent.panel_showflags = showflags; \ HUD_PANEL_NUM++; \ } \ - ACCUMULATE_FUNCTION(RegisterHUD_Panels, RegisterHUD_Panel_##NAME); + ACCUMULATE_FUNCTION(RegisterHUD_Panels, RegisterHUD_Panel_##NAME) HUD_PANELS(HUD_PANEL) #undef HUD_PANEL diff --git a/qcsrc/common/deathtypes.qh b/qcsrc/common/deathtypes.qh index b9c215f907..c1e8bd2218 100644 --- a/qcsrc/common/deathtypes.qh +++ b/qcsrc/common/deathtypes.qh @@ -104,7 +104,7 @@ entity deathtypes[DT_MAX]; if (msg_death_by != NO_MSG) \ deathent.death_msgmurder = msg_multi_notifs[msg_death_by - 1]; \ } \ - ACCUMULATE_FUNCTION(RegisterDeathtypes, RegisterDeathtype_##name); + ACCUMULATE_FUNCTION(RegisterDeathtypes, RegisterDeathtype_##name) DEATHTYPES #undef DEATHTYPE diff --git a/qcsrc/common/effects.qh b/qcsrc/common/effects.qh index b0c452ce07..a1102e96a2 100644 --- a/qcsrc/common/effects.qh +++ b/qcsrc/common/effects.qh @@ -53,9 +53,9 @@ void RegisterEffects_Done() } // NOW we actually activate the declarations -ACCUMULATE_FUNCTION(RegisterEffects, RegisterEffects_First); +ACCUMULATE_FUNCTION(RegisterEffects, RegisterEffects_First) EFFECT(0, Null, string_null) #include "effects.inc" -ACCUMULATE_FUNCTION(RegisterEffects, RegisterEffects_Done); +ACCUMULATE_FUNCTION(RegisterEffects, RegisterEffects_Done) #endif diff --git a/qcsrc/common/mutators/base.qh b/qcsrc/common/mutators/base.qh index a8f6c53a9f..6fa77a858a 100644 --- a/qcsrc/common/mutators/base.qh +++ b/qcsrc/common/mutators/base.qh @@ -247,7 +247,7 @@ STATIC_INIT_LATE(Mutators) { [[accumulate]] void RegisterCallbacks() { CALLBACK_##name = NEW(Callback, func); } #define MUTATOR_HOOKFUNCTION(...) \ - OVERLOAD(MUTATOR_HOOKFUNCTION, __VA_ARGS__) + EVAL(OVERLOAD(MUTATOR_HOOKFUNCTION, __VA_ARGS__)) #define MUTATOR_HOOKFUNCTION_1(name) \ _MUTATOR_CALLBACK(name, HOOKFUNCTION_##name) \ diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index 16521a849d..626c42c7d6 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -69,7 +69,7 @@ string Notification_CheckArgs_TypeName(float net_type, float net_name) { // check supplied type and name for errors string checkargs = ""; - #define CHECKARG_TYPENAME(type) case MSG_##type##: \ + #define CHECKARG_TYPENAME(type) case MSG_##type: \ { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \ { checkargs = sprintf("Improper name: %d!", net_name); } break; } switch(net_type) diff --git a/qcsrc/common/notifications.qh b/qcsrc/common/notifications.qh index 2fbc9cdf0e..d44a651567 100644 --- a/qcsrc/common/notifications.qh +++ b/qcsrc/common/notifications.qh @@ -623,7 +623,7 @@ float notif_global_error; NO_MSG, /* optiona */ \ NO_MSG); /* optionb */ \ } \ - ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name); + ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name) #define MSG_INFO_NOTIF(default,name,strnum,flnum,args,hudargs,icon,normal,gentle) \ NOTIF_ADD_AUTOCVAR(name, default) \ @@ -665,7 +665,7 @@ float notif_global_error; NO_MSG, /* optiona */ \ NO_MSG); /* optionb */ \ } \ - ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name); + ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name) .string nent_iconargs; #define MULTIICON_INFO(default,name,strnum,flnum,args,hudargs,iconargs,icon,normal,gentle) \ @@ -709,7 +709,7 @@ float notif_global_error; NO_MSG); /* optionb */ \ msg_info_notifs[name - 1].nent_iconargs = iconargs; \ } \ - ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name); + ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name) #define MSG_CENTER_NOTIF(default,name,strnum,flnum,args,cpid,durcnt,normal,gentle) \ NOTIF_ADD_AUTOCVAR(name, default) \ @@ -751,7 +751,7 @@ float notif_global_error; NO_MSG, /* optiona */ \ NO_MSG); /* optionb */ \ } \ - ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name); + ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name) #define MSG_MULTI_NOTIF(default,name,anncename,infoname,centername) \ NOTIF_ADD_AUTOCVAR(name, default) \ @@ -793,7 +793,7 @@ float notif_global_error; NO_MSG, /* optiona */ \ NO_MSG); /* optionb */ \ } \ - ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name); + ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name) #define ACVNN(name) autocvar_notification_##name @@ -838,7 +838,7 @@ float notif_global_error; optiona, /* optiona */ \ optionb); /* optionb */ \ } \ - ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name); + ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotification_##name) void RegisterNotifications_First() { @@ -882,8 +882,8 @@ void RegisterNotifications_Done() } // NOW we actually activate the declarations -ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotifications_First); +ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotifications_First) #include "notifications.inc" -ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotifications_Done); +ACCUMULATE_FUNCTION(RegisterNotifications, RegisterNotifications_Done) #endif diff --git a/qcsrc/common/turrets/turrets.qh b/qcsrc/common/turrets/turrets.qh index 0c2250bc93..e1bf48c1b2 100644 --- a/qcsrc/common/turrets/turrets.qh +++ b/qcsrc/common/turrets/turrets.qh @@ -183,6 +183,6 @@ float TUR_LAST; #include "all.qh" #undef REGISTER_TURRET -ACCUMULATE_FUNCTION(RegisterTurrets, register_turrets_done); +ACCUMULATE_FUNCTION(RegisterTurrets, register_turrets_done) #endif diff --git a/qcsrc/common/util-pre.qh b/qcsrc/common/util-pre.qh index 22cdfda81d..ad9be12cba 100644 --- a/qcsrc/common/util-pre.qh +++ b/qcsrc/common/util-pre.qh @@ -46,15 +46,30 @@ #define FOREACH(list, cond, body) FOREACH_LIST(list, enemy, cond, body) #ifdef GMQCC - #define OVERLOAD(F, ...) F##_##__VA_COUNT__(__VA_ARGS__) + #define EVAL(...) __VA_ARGS__ + + #define OVERLOAD_(F, ...) F##_##__VA_COUNT__(__VA_ARGS__) + #define OVERLOAD(F, ...) F##_##__VA_COUNT__(__VA_ARGS__) #else - #define OVERLOAD_(F,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1,n,...) F##_##n - #define OVERLOAD(F, ...) OVERLOAD_(F,__VA_ARGS__,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1)(__VA_ARGS__) + #define EMPTY() + #define DEFER(id) id EMPTY() + + #define EVAL(...) EVAL1(EVAL1(EVAL1(__VA_ARGS__))) + #define EVAL1(...) EVAL2(EVAL2(EVAL2(__VA_ARGS__))) + #define EVAL2(...) EVAL3(EVAL3(EVAL3(__VA_ARGS__))) + #define EVAL3(...) EVAL4(EVAL4(EVAL4(__VA_ARGS__))) + #define EVAL4(...) EVAL5(EVAL5(EVAL5(__VA_ARGS__))) + #define EVAL5(...) __VA_ARGS__ + + #define OVERLOAD___(F,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1,n,...) F##_##n + #define OVERLOAD__(F, ...) OVERLOAD___(F,##__VA_ARGS__,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0) + #define OVERLOAD_(...) DEFER(OVERLOAD__(__VA_ARGS__)) + #define OVERLOAD(F, ...) OVERLOAD_(F,##__VA_ARGS__)(__VA_ARGS__) #endif #define LAMBDA(...) { __VA_ARGS__ ; } -#define MAP(f, ...) OVERLOAD(MAP, f, __VA_ARGS__) +#define MAP(f, ...) EVAL(OVERLOAD(MAP, f, __VA_ARGS__)) #define MAP_2(f, it) f(it) #define MAP_3(f, it, ...) f(it)MAP_2(f, __VA_ARGS__) #define MAP_4(f, it, ...) f(it)MAP_3(f, __VA_ARGS__) diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index 081e13a7e5..f965c39988 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -267,5 +267,5 @@ entity dummy_weapon_info; #undef WEP_ADD_CVAR #undef WEP_ADD_PROP void register_weapons_done(); -ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done); +ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done) #endif diff --git a/qcsrc/lib/Cvar.qh b/qcsrc/lib/Cvar.qh index 02016a2517..b2093b13e4 100644 --- a/qcsrc/lib/Cvar.qh +++ b/qcsrc/lib/Cvar.qh @@ -17,7 +17,7 @@ STATIC_INIT_LATE(Cvars) { RegisterCvars(RegisterCvars_Set); } type autocvar_##var #define AUTOCVAR_6(file, archive, var, type, default, desc) \ AUTOCVAR_5(file, archive, var, type, desc) = default -#define _AUTOCVAR(...) OVERLOAD(AUTOCVAR, __FILE__, __VA_ARGS__) +#define _AUTOCVAR(...) EVAL(OVERLOAD(AUTOCVAR, __FILE__, __VA_ARGS__)) #define AUTOCVAR_SAVE(...) _AUTOCVAR(true, __VA_ARGS__) #define AUTOCVAR(...) _AUTOCVAR(false, __VA_ARGS__) diff --git a/qcsrc/lib/OO.qh b/qcsrc/lib/OO.qh index d4efe9a6e3..96978baf7d 100644 --- a/qcsrc/lib/OO.qh +++ b/qcsrc/lib/OO.qh @@ -25,7 +25,7 @@ entity __spawn(string _classname, string _sourceFile, int _sourceLine) { -#define entityclass(...) OVERLOAD(entityclass, __VA_ARGS__) +#define entityclass(...) EVAL(OVERLOAD(entityclass, __VA_ARGS__)) #define entityclass_1(name) entityclass_2(name, Object) #ifndef QCC_SUPPORT_ENTITYCLASS #define entityclass_2(name, base) typedef entity name @@ -41,11 +41,23 @@ entity __spawn(string _classname, string _sourceFile, int _sourceLine) { // The parameter is used across [[accumulate]] functions // Macros to hide this implementation detail: +#ifdef GMQCC #define NEW(cname, ...) \ OVERLOAD(spawn##cname, new(cname), ##__VA_ARGS__) #define CONSTRUCT(cname, ...) \ OVERLOAD(spawn##cname, this, ##__VA_ARGS__) +#else +#define NEW_(cname, ...) \ + OVERLOAD_(spawn##cname, __VA_ARGS__) +#define NEW(cname, ...) \ + NEW_(cname, new(cname), ##__VA_ARGS__)(new(cname), ##__VA_ARGS__) + +#define CONSTRUCT_(cname, ...) \ + OVERLOAD_(spawn##cname, __VA_ARGS__) +#define CONSTRUCT(cname, ...) \ + CONSTRUCT_(cname, this, ##__VA_ARGS__)(this, ##__VA_ARGS__) +#endif #define CONSTRUCTOR(cname, ...) \ cname OVERLOAD(spawn##cname, cname this, __VA_ARGS__) { return = this; } \ diff --git a/qcsrc/menu/xonotic/dialog_settings_game.qc b/qcsrc/menu/xonotic/dialog_settings_game.qc index 497e1e5e77..fc87261a53 100644 --- a/qcsrc/menu/xonotic/dialog_settings_game.qc +++ b/qcsrc/menu/xonotic/dialog_settings_game.qc @@ -84,7 +84,8 @@ CLASS(XonoticGameSettingsTab, XonoticTab) ATTRIB(XonoticGameSettingsTab, intendedWidth, float, 0.9) ATTRIB(XonoticGameSettingsTab, rows, float, 15.5) ATTRIB(XonoticGameSettingsTab, columns, float, 6.5) - ATTRIB(XonoticGameSettingsTab, topicList, entity, NEW(XonoticRegisteredSettingsList, NEW(SettingSource))) + ATTRIB(XonoticGameSettingsTab, source, DataSource, NEW(SettingSource)) + ATTRIB(XonoticGameSettingsTab, topicList, entity, NEW(XonoticRegisteredSettingsList, this.source)) ATTRIB(XonoticGameSettingsTab, currentPanel, entity, NEW(XonoticTab)) ATTRIB(XonoticGameSettingsTab, currentItem, entity, NULL) METHOD(XonoticGameSettingsTab, topicChangeNotify, void(entity, entity this)) -- 2.39.2