From: TimePath Date: Thu, 10 Dec 2015 08:03:10 +0000 (+1100) Subject: Macros: optimize X-Git-Tag: xonotic-v0.8.2~1522 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=87b1a8def06bcf477cb8dbd1b5e069c29ce0ab91;p=xonotic%2Fxonotic-data.pk3dir.git Macros: optimize --- diff --git a/qcsrc/client/csqcmodel_hooks.qc b/qcsrc/client/csqcmodel_hooks.qc index 506d35c6b..83c3f448a 100644 --- a/qcsrc/client/csqcmodel_hooks.qc +++ b/qcsrc/client/csqcmodel_hooks.qc @@ -333,10 +333,10 @@ void CSQCPlayer_FallbackFrame_PostUpdate(bool isnew) // player "pops in" if(isnew) { -#define FIX_FRAMETIME(f,ft) do { \ +#define FIX_FRAMETIME(f,ft) MACRO_BEGIN { \ if(IS_DEAD_FRAME(self.f) && self.ft != 0 && self.death_time != 0) \ self.ft = self.death_time; \ -} while(0) +} MACRO_END FIX_FRAMETIME(frame, frame1time); FIX_FRAMETIME(frame2, frame2time); #ifdef CSQCMODEL_HAVE_TWO_FRAMES diff --git a/qcsrc/client/hud/hud.qh b/qcsrc/client/hud/hud.qh index d30a87273..47126a738 100644 --- a/qcsrc/client/hud/hud.qh +++ b/qcsrc/client/hud/hud.qh @@ -24,10 +24,10 @@ REGISTER_REGISTRY(hud_panels) #define HUD_PANEL(NAME) HUD_PANEL_##NAME // draw the background/borders -#define HUD_Panel_DrawBg(theAlpha) do { \ +#define HUD_Panel_DrawBg(theAlpha) MACRO_BEGIN { \ if(panel.current_panel_bg != "0" && panel.current_panel_bg != "") \ draw_BorderPicture(panel_pos - '1 1 0' * panel_bg_border, panel.current_panel_bg, panel_size + '1 1 0' * 2 * panel_bg_border, panel_bg_color, panel_bg_alpha * theAlpha, '1 1 0' * (panel_bg_border/BORDER_MULTIPLIER));\ -} while(0) +} MACRO_END int panel_order[hud_panels_MAX]; string hud_panelorder_prev; @@ -213,7 +213,7 @@ REGISTER_HUD_PANEL(QUICKMENU, HUD_QuickMenu, quickmenu, PANEL_CO // Get value for panel.current_panel_bg: if "" fetch default, else use panel_bg_str // comment on last line of macro: // we probably want to see a background in config mode at all times... -#define HUD_Panel_GetBg() do { \ +#define HUD_Panel_GetBg() MACRO_BEGIN { \ string panel_bg; \ if (!autocvar__hud_configure && panel_bg_str == "0") { \ panel_bg = "0"; \ @@ -238,10 +238,10 @@ REGISTER_HUD_PANEL(QUICKMENU, HUD_QuickMenu, quickmenu, PANEL_CO if (panel.current_panel_bg) \ strunzone(panel.current_panel_bg); \ panel.current_panel_bg = strzone(panel_bg); \ -} while(0) +} MACRO_END // Get value for panel_bg_color: if "" fetch default, else use panel_bg_color. Convert pants, shirt or teamcolor into a vector. -#define HUD_Panel_GetColor() do { \ +#define HUD_Panel_GetColor() MACRO_BEGIN { \ if ((teamplay) && panel_bg_color_team) { \ if (autocvar__hud_configure && myteam == NUM_SPECTATOR) \ panel_bg_color = '1 0 0' * panel_bg_color_team; \ @@ -262,20 +262,20 @@ REGISTER_HUD_PANEL(QUICKMENU, HUD_QuickMenu, quickmenu, PANEL_CO } \ } \ } \ -} while(0) +} MACRO_END // Get value for panel_bg_color_team: if "" fetch default, else use panel_bg_color_team_str -#define HUD_Panel_GetColorTeam() do { \ +#define HUD_Panel_GetColorTeam() MACRO_BEGIN { \ if (panel_bg_color_team_str == "") { \ panel_bg_color_team = autocvar_hud_panel_bg_color_team; \ } else { \ panel_bg_color_team = stof(panel_bg_color_team_str); \ } \ -} while(0) +} MACRO_END // Get value for panel_bg_alpha: if "" fetch default, else use panel_bg_alpha. Also do various menu dialog fadeout/in checks, and minalpha checks // comment on line 3 of macro: // do not set a minalpha cap when showing the config dialog for this panel -#define HUD_Panel_GetBgAlpha() do { \ +#define HUD_Panel_GetBgAlpha() MACRO_BEGIN { \ if (panel_bg_alpha_str == "") { \ panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha); \ } \ @@ -288,39 +288,39 @@ REGISTER_HUD_PANEL(QUICKMENU, HUD_QuickMenu, quickmenu, PANEL_CO else \ panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha); \ } \ -} while(0) +} MACRO_END // Get value for panel_fg_alpha. Also do various minalpha checks // comment on line 2 of macro: // ALWAYS show disabled panels at 0.25 alpha when in config mode -#define HUD_Panel_GetFgAlpha() do { \ +#define HUD_Panel_GetFgAlpha() MACRO_BEGIN { \ panel_fg_alpha = autocvar_hud_panel_fg_alpha; \ if (autocvar__hud_configure && !panel_enabled) \ panel_fg_alpha = 0.25; \ -} while(0) +} MACRO_END // Get border. See comments above, it's similar. -#define HUD_Panel_GetBorder() do { \ +#define HUD_Panel_GetBorder() MACRO_BEGIN { \ if (panel_bg_border_str == "") { \ panel_bg_border = autocvar_hud_panel_bg_border; \ } else { \ panel_bg_border = stof(panel_bg_border_str); \ } \ -} while(0) +} MACRO_END // Get padding. See comments above, it's similar. // last line is a port of the old function, basically always make sure the panel contents are at least 5 pixels tall/wide, to disallow extreme padding values -#define HUD_Panel_GetPadding() do { \ +#define HUD_Panel_GetPadding() MACRO_BEGIN { \ if (panel_bg_padding_str == "") { \ panel_bg_padding = autocvar_hud_panel_bg_padding; \ } else { \ panel_bg_padding = stof(panel_bg_padding_str); \ } \ panel_bg_padding = min(min(panel_size.x, panel_size.y)/2 - 5, panel_bg_padding); \ -} while(0) +} MACRO_END // return smoothly faded pos and size of given panel when a dialog is active // don't center too wide panels, it doesn't work with different resolutions -#define HUD_Panel_UpdatePosSize_ForMenu() do { \ +#define HUD_Panel_UpdatePosSize_ForMenu() MACRO_BEGIN { \ vector menu_enable_size = panel_size; \ float max_panel_width = 0.52 * vid_conwidth; \ if(panel_size.x > max_panel_width) \ @@ -331,16 +331,16 @@ REGISTER_HUD_PANEL(QUICKMENU, HUD_QuickMenu, quickmenu, PANEL_CO vector menu_enable_pos = eX * (panel_bg_border + 0.5 * max_panel_width) + eY * 0.5 * vid_conheight - 0.5 * menu_enable_size; \ panel_pos = (1 - autocvar__menu_alpha) * panel_pos + (autocvar__menu_alpha) * menu_enable_pos; \ panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size; \ -} while(0) +} MACRO_END // Scale the pos and size vectors to absolute coordinates -#define HUD_Panel_ScalePosSize() do { \ +#define HUD_Panel_ScalePosSize() MACRO_BEGIN { \ panel_pos.x *= vid_conwidth; panel_pos.y *= vid_conheight; \ panel_size.x *= vid_conwidth; panel_size.y *= vid_conheight; \ -} while(0) +} MACRO_END // NOTE: in hud_configure mode cvars must be reloaded every frame -#define HUD_Panel_UpdateCvars() do { \ +#define HUD_Panel_UpdateCvars() MACRO_BEGIN { \ if (panel.update_time <= time) { \ if (autocvar__hud_configure) panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \ panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \ @@ -386,9 +386,9 @@ REGISTER_HUD_PANEL(QUICKMENU, HUD_QuickMenu, quickmenu, PANEL_CO panel_bg_padding = panel.current_panel_bg_padding; \ panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha; \ } \ -} while(0) +} MACRO_END -#define HUD_Panel_UpdatePosSize() do { \ +#define HUD_Panel_UpdatePosSize() MACRO_BEGIN { \ panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \ panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \ panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \ @@ -398,7 +398,7 @@ REGISTER_HUD_PANEL(QUICKMENU, HUD_QuickMenu, quickmenu, PANEL_CO } \ panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \ HUD_Panel_GetBorder(); \ -} while(0) +} MACRO_END const int NOTIFY_MAX_ENTRIES = 10; const float NOTIFY_ICON_MARGIN = 0.02; diff --git a/qcsrc/client/hud/panel/infomessages.qc b/qcsrc/client/hud/panel/infomessages.qc index 33f797f3d..9153b855d 100644 --- a/qcsrc/client/hud/panel/infomessages.qc +++ b/qcsrc/client/hud/panel/infomessages.qc @@ -1,11 +1,11 @@ // Info messages panel (#14) -#define drawInfoMessage(s) do { \ +#define drawInfoMessage(s) MACRO_BEGIN { \ if(autocvar_hud_panel_infomessages_flip) \ o.x = pos.x + mySize.x - stringwidth(s, true, fontsize); \ drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL); \ o.y += fontsize.y; \ -} while(0) +} MACRO_END void HUD_InfoMessages() { if(!autocvar__hud_configure) diff --git a/qcsrc/client/hud/panel/modicons.qc b/qcsrc/client/hud/panel/modicons.qc index d57a23e1e..9ea22c92b 100644 --- a/qcsrc/client/hud/panel/modicons.qc +++ b/qcsrc/client/hud/panel/modicons.qc @@ -135,14 +135,14 @@ void HUD_Mod_CTF(vector pos, vector mySize) } // when status CHANGES, set old status into prevstatus and current status into status - #define X(team) do { \ + #define X(team) MACRO_BEGIN { \ if (team##flag != team##flag_prevframe) { \ team##flag_statuschange_time = time; \ team##flag_prevstatus = team##flag_prevframe; \ team##flag_prevframe = team##flag; \ } \ team##flag_statuschange_elapsedtime = time - team##flag_statuschange_time; \ - } while (0) + } MACRO_END X(red); X(blue); X(yellow); @@ -163,7 +163,7 @@ void HUD_Mod_CTF(vector pos, vector mySize) string team##_icon, team##_icon_prevstatus; \ int team##_alpha, team##_alpha_prevstatus; \ team##_alpha = team##_alpha_prevstatus = 1; \ - do { \ + MACRO_BEGIN { \ switch (team##flag) { \ case 1: team##_icon = "flag_" #team "_taken"; break; \ case 2: team##_icon = "flag_" #team "_lost"; break; \ @@ -190,7 +190,7 @@ void HUD_Mod_CTF(vector pos, vector mySize) } \ break; \ } \ - } while (0) + } MACRO_END X(red, myteam != NUM_TEAM_1); X(blue, myteam != NUM_TEAM_2); X(yellow, myteam != NUM_TEAM_3); @@ -255,13 +255,13 @@ void HUD_Mod_CTF(vector pos, vector mySize) neutralflag_pos = pos; flag_size = e1 * fs * size1 + e2 * size2; - #define X(team) do { \ + #define X(team) MACRO_BEGIN { \ f = bound(0, team##flag_statuschange_elapsedtime * 2, 1); \ if (team##_icon_prevstatus && f < 1) \ drawpic_aspect_skin_expanding(team##flag_pos, team##_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * team##_alpha_prevstatus, DRAWFLAG_NORMAL, f); \ if (team##_icon) \ drawpic_aspect_skin(team##flag_pos, team##_icon, flag_size, '1 1 1', panel_fg_alpha * team##_alpha * f, DRAWFLAG_NORMAL); \ - } while (0) + } MACRO_END X(red); X(blue); X(yellow); diff --git a/qcsrc/client/miscfunctions.qh b/qcsrc/client/miscfunctions.qh index ddac22e8d..3066fc6c6 100644 --- a/qcsrc/client/miscfunctions.qh +++ b/qcsrc/client/miscfunctions.qh @@ -42,8 +42,8 @@ float cvar_or(string cv, float v); vector project_3d_to_2d(vector vec); -#define draw_beginBoldFont() do { drawfont = FONT_USER + 2; } while (0) -#define draw_endBoldFont() do { drawfont = FONT_USER + 1; } while (0) +#define draw_beginBoldFont() MACRO_BEGIN { drawfont = FONT_USER + 2; } MACRO_END +#define draw_endBoldFont() MACRO_BEGIN { drawfont = FONT_USER + 1; } MACRO_END float expandingbox_sizefactor_from_fadelerp(float fadelerp); @@ -60,7 +60,7 @@ vector _drawpic_sz; float _drawpic_oldsz; string _drawpic_picpath; #define drawpic_aspect(pos,pic,mySize,color,theAlpha,drawflag)\ - do {\ + MACRO_BEGIN {\ _drawpic_imgsize = draw_getimagesize(pic);\ if(_drawpic_imgsize != '0 0 0') {\ _drawpic_imgaspect = _drawpic_imgsize.x/_drawpic_imgsize.y;\ @@ -77,35 +77,35 @@ string _drawpic_picpath; drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz.y) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\ }\ }\ - } while(0) + } MACRO_END // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga #define drawpic_aspect_skin(pos,pic,sz,color,theAlpha,drawflag)\ - do{\ + MACRO_BEGIN {\ _drawpic_picpath = strcat(hud_skin_path, "/", pic);\ if(precache_pic(_drawpic_picpath) == "") {\ _drawpic_picpath = strcat("gfx/hud/default/", pic);\ }\ drawpic_aspect(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\ _drawpic_picpath = string_null;\ - } while(0) + } MACRO_END // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga #define drawpic_skin(pos,pic,sz,color,theAlpha,drawflag)\ - do{\ + MACRO_BEGIN {\ _drawpic_picpath = strcat(hud_skin_path, "/", pic);\ if(precache_pic(_drawpic_picpath) == "") {\ _drawpic_picpath = strcat("gfx/hud/default/", pic);\ }\ drawpic(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\ _drawpic_picpath = string_null;\ - } while(0) + } MACRO_END void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp); void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp); -#define SET_POS_AND_SZ_Y_ASPECT(allow_colors) do { \ +#define SET_POS_AND_SZ_Y_ASPECT(allow_colors) MACRO_BEGIN { \ float textaspect, oldsz; \ textaspect = stringwidth(text, allow_colors, '1 1 1' * sz.y) / sz.y; \ if(sz.x/sz.y > textaspect) { \ @@ -117,7 +117,7 @@ void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theSc sz.y = sz.x / textaspect; \ pos.y += (oldsz - sz.y) * 0.5; \ } \ -} while(0) +} MACRO_END // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag); diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index c15914971..8602ef26a 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -63,50 +63,50 @@ float autocvar_cl_leanmodel_up_highpass1; float autocvar_cl_leanmodel_up_lowpass; float autocvar_cl_leanmodel_up_limit; -#define lowpass(value, frac, ref_store, ret) do \ +#define lowpass(value, frac, ref_store, ret) MACRO_BEGIN \ { \ float __frac = bound(0, frac, 1); \ ret = ref_store = ref_store * (1 - __frac) + (value) * __frac; \ -} while (0) +} MACRO_END -#define lowpass_limited(value, frac, limit, ref_store, ret) do \ +#define lowpass_limited(value, frac, limit, ref_store, ret) MACRO_BEGIN \ { \ float __ignore; lowpass(value, frac, ref_store, __ignore); \ ret = ref_store = bound((value) - (limit), ref_store, (value) + (limit)); \ -} while (0) +} MACRO_END -#define highpass(value, frac, ref_store, ret) do \ +#define highpass(value, frac, ref_store, ret) MACRO_BEGIN \ { \ float __f; lowpass(value, frac, ref_store, __f); \ ret = (value) - __f; \ -} while (0) +} MACRO_END -#define highpass_limited(value, frac, limit, ref_store, ret) do \ +#define highpass_limited(value, frac, limit, ref_store, ret) MACRO_BEGIN \ { \ float __f; lowpass_limited(value, frac, limit, ref_store, __f); \ ret = (value) - __f; \ -} while (0) +} MACRO_END -#define lowpass3(value, fracx, fracy, fracz, ref_store, ref_out) do \ +#define lowpass3(value, fracx, fracy, fracz, ref_store, ref_out) MACRO_BEGIN \ { \ lowpass(value.x, fracx, ref_store.x, ref_out.x); \ lowpass(value.y, fracy, ref_store.y, ref_out.y); \ lowpass(value.z, fracz, ref_store.z, ref_out.z); \ -} while (0) +} MACRO_END -#define highpass3(value, fracx, fracy, fracz, ref_store, ref_out) do \ +#define highpass3(value, fracx, fracy, fracz, ref_store, ref_out) MACRO_BEGIN \ { \ highpass(value.x, fracx, ref_store.x, ref_out.x); \ highpass(value.y, fracy, ref_store.y, ref_out.y); \ highpass(value.z, fracz, ref_store.z, ref_out.z); \ -} while (0) +} MACRO_END -#define highpass3_limited(value, fracx, limitx, fracy, limity, fracz, limitz, ref_store, ref_out) do \ +#define highpass3_limited(value, fracx, limitx, fracy, limity, fracz, limitz, ref_store, ref_out) MACRO_BEGIN \ { \ highpass_limited(value.x, fracx, limitx, ref_store.x, ref_out.x); \ highpass_limited(value.y, fracy, limity, ref_store.y, ref_out.y); \ highpass_limited(value.z, fracz, limitz, ref_store.z, ref_out.z); \ -} while (0) +} MACRO_END void viewmodel_animate(entity this) { @@ -1242,8 +1242,7 @@ void HUD_Crosshair() } #define CROSSHAIR_DO_BLUR(M,sz,wcross_name,wcross_alpha) \ - do \ - { \ + MACRO_BEGIN { \ if(wcross_blur > 0) \ { \ for(i = -2; i <= 2; ++i) \ @@ -1254,8 +1253,7 @@ void HUD_Crosshair() { \ M(0,0,sz,wcross_name,wcross_alpha); \ } \ - } \ - while(0) + } MACRO_END #define CROSSHAIR_DRAW_SINGLE(i,j,sz,wcross_name,wcross_alpha) \ drawpic(wcross_origin - ('0.5 0 0' * (sz * wcross_size.x + i * wcross_blur) + '0 0.5 0' * (sz * wcross_size.y + j * wcross_blur)), wcross_name, sz * wcross_size, wcross_color, wcross_alpha, DRAWFLAG_NORMAL) diff --git a/qcsrc/common/effects/effectinfo.qc b/qcsrc/common/effects/effectinfo.qc index f4df3237d..400a47b5d 100644 --- a/qcsrc/common/effects/effectinfo.qc +++ b/qcsrc/common/effects/effectinfo.qc @@ -259,10 +259,10 @@ void effectinfo_read() void effectinfo_dump(int fh, bool alsoprint) { - #define WRITE(s) do { \ + #define WRITE(s) MACRO_BEGIN { \ fputs(fh, s); \ if (alsoprint) LOG_INFO(s); \ - } while (0) + } MACRO_END WRITE("// ********************************************** //\n"); WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n"); WRITE("// ** ** //\n"); diff --git a/qcsrc/common/effects/qc/globalsound.qc b/qcsrc/common/effects/qc/globalsound.qc index 9f530b9ea..83a2440cf 100644 --- a/qcsrc/common/effects/qc/globalsound.qc +++ b/qcsrc/common/effects/qc/globalsound.qc @@ -331,14 +331,13 @@ case VOICETYPE_TEAMRADIO: { #define X() \ - do \ + MACRO_BEGIN \ { \ float atten = (msg_entity.cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; \ if (gs) globalsound(MSG_ONE, this, gs, r, chan, VOL_BASEVOICE, atten); \ else if (ps) playersound(MSG_ONE, this, ps, r, chan, VOL_BASEVOICE, atten); \ else soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten); \ - } \ - while (0) + } MACRO_END if (fake) { msg_entity = this; X(); } else @@ -362,7 +361,7 @@ float tauntrand = 0; if (voicetype == VOICETYPE_AUTOTAUNT) tauntrand = random(); #define X() \ - do \ + MACRO_BEGIN \ { \ if (voicetype != VOICETYPE_AUTOTAUNT || tauntrand < msg_entity.cvar_cl_autotaunt) \ { \ @@ -374,8 +373,7 @@ else if (ps) playersound(MSG_ONE, this, ps, r, chan, VOL_BASEVOICE, atten); \ else soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten); \ } \ - } \ - while (0) + } MACRO_END if (fake) { msg_entity = this; diff --git a/qcsrc/common/effects/qc/globalsound.qh b/qcsrc/common/effects/qc/globalsound.qh index 12ceee29c..1708f912e 100644 --- a/qcsrc/common/effects/qc/globalsound.qh +++ b/qcsrc/common/effects/qc/globalsound.qh @@ -126,7 +126,7 @@ void PrecachePlayerSounds(string f); #define GlobalSound_string(this, def, chan, voicetype) _GlobalSound(this, NULL, NULL, def, chan, voicetype, false) #define PlayerSound(this, def, chan, voicetype) _GlobalSound(this, NULL, def, string_null, chan, voicetype, false) #define VoiceMessage(this, def, msg) \ - do \ + MACRO_BEGIN \ { \ entity VM = def; \ int voicetype = VM.m_playersoundvt; \ @@ -137,8 +137,7 @@ void PrecachePlayerSounds(string f); else if (flood > 0) fake = false; \ else break; \ _GlobalSound(this, NULL, VM, string_null, CH_VOICE, voicetype, fake); \ - } \ - while (0) + } MACRO_END #endif diff --git a/qcsrc/common/mapinfo.qc b/qcsrc/common/mapinfo.qc index 5ca1c3803..173aa8e42 100644 --- a/qcsrc/common/mapinfo.qc +++ b/qcsrc/common/mapinfo.qc @@ -691,13 +691,13 @@ Gametype MapInfo_Type(int t) int MapInfo_Type_FromString(string t) { -#define deprecate(from, to) do { \ +#define deprecate(from, to) MACRO_BEGIN { \ if (t == #from) { \ string replacement = #to; \ LOG_WARNINGF("MapInfo_Type_FromString (probably %s): using deprecated name '%s'. Should use '%s'.\n", MapInfo_Map_bspname, t, replacement); \ t = replacement; \ } \ -} while (0) +} MACRO_END deprecate(nexball, nb); deprecate(freezetag, ft); deprecate(keepaway, ka); diff --git a/qcsrc/common/mutators/base.qh b/qcsrc/common/mutators/base.qh index 54b7b6624..6e06e5590 100644 --- a/qcsrc/common/mutators/base.qh +++ b/qcsrc/common/mutators/base.qh @@ -300,7 +300,7 @@ STATIC_INIT_LATE(Mutators) { bool mut##_##cb() { return = false; } \ [[accumulate]] bool mut##_##cb() -#define MUTATOR_HOOK(cb, func, order) do { \ +#define MUTATOR_HOOK(cb, func, order) MACRO_BEGIN { \ MUTATOR_ONADD { \ if (!CallbackChain_Add(HOOK_##cb, CALLBACK_##func, order)) { \ LOG_INFO("HOOK FAILED: ", #cb, ":", #func, "\n"); \ @@ -310,7 +310,7 @@ STATIC_INIT_LATE(Mutators) { MUTATOR_ONROLLBACK_OR_REMOVE { \ CallbackChain_Remove(HOOK_##cb, CALLBACK_##func); \ } \ -} while (0) +} MACRO_END #include "events.qh" diff --git a/qcsrc/common/mutators/mutator/nades/nades.inc b/qcsrc/common/mutators/mutator/nades/nades.inc index 6d16fd150..d2f350c5f 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.inc +++ b/qcsrc/common/mutators/mutator/nades/nades.inc @@ -1,8 +1,8 @@ #ifndef MENUQC -#define NADE_PROJECTILE(i, projectile, trail) do { \ +#define NADE_PROJECTILE(i, projectile, trail) MACRO_BEGIN { \ this.m_projectile[i] = projectile; \ this.m_trail[i] = trail; \ -} while (0) +} MACRO_END #else #define NADE_PROJECTILE(i, projectile, trail) #endif diff --git a/qcsrc/common/net_notice.qc b/qcsrc/common/net_notice.qc index c25997b1a..06f310799 100644 --- a/qcsrc/common/net_notice.qc +++ b/qcsrc/common/net_notice.qc @@ -79,7 +79,7 @@ void cl_notice_run() drawfill(v1, v2, '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL); vector v3 = v1 + '10 10 0'; - #define OUT(s, z) do { drawcolorcodedstring(v3, s, '1 1 0' * z, 1, DRAWFLAG_NORMAL); v3.y += z + 4; } while (0) + #define OUT(s, z) MACRO_BEGIN { drawcolorcodedstring(v3, s, '1 1 0' * z, 1, DRAWFLAG_NORMAL); v3.y += z + 4; } MACRO_END OUT(_("^1Server notices:"), 32); LL_EACH(cl_notices, it.alpha > time, LAMBDA( diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index 94a46d94a..c8664e7af 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -239,14 +239,14 @@ void Destroy_All_Notifications() entity notif; int i; - #define DESTROY_LOOP(type,count) do { \ + #define DESTROY_LOOP(type,count) MACRO_BEGIN { \ for(i = 1; i <= count; ++i) \ { \ notif = Get_Notif_Ent(type, i); \ if (!notif) { backtrace("Destroy_All_Notifications(): Missing notification entity!\n"); return; } \ Destroy_Notification_Entity(notif); \ } \ - } while(0) + } MACRO_END // kill all networked notifications and centerprints #ifdef SVQC @@ -737,7 +737,7 @@ void Create_Notification_Entity( // ====================== // Process Notif String // ====================== - #define SET_NOTIF_STRING(string,stringname) do { \ + #define SET_NOTIF_STRING(string,stringname) MACRO_BEGIN { \ notif.nent_string = strzone(CCR( \ Process_Notif_Line( \ typeId, \ @@ -748,7 +748,7 @@ void Create_Notification_Entity( stringname \ )) \ ); \ - } while(0) + } MACRO_END if(GENTLE) { @@ -2049,7 +2049,7 @@ void Send_Notification( // 2. Manually handling each separate call on per-usage basis (See old CTF usage of verbose) entity found_choice; - #define RECURSE_FROM_CHOICE(ent,action) do { \ + #define RECURSE_FROM_CHOICE(ent,action) MACRO_BEGIN { \ if(notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) \ { \ switch(ent.msg_choice_choices[net_name - 1]) \ @@ -2069,7 +2069,7 @@ void Send_Notification( found_choice.nent_floatcount, \ s1, s2, s3, s4, \ f1, f2, f3, f4); \ - } while(0) + } MACRO_END switch(broadcast) { diff --git a/qcsrc/common/notifications.qh b/qcsrc/common/notifications.qh index f3cd0ba49..10ce481d7 100644 --- a/qcsrc/common/notifications.qh +++ b/qcsrc/common/notifications.qh @@ -328,9 +328,9 @@ string BUFF_NAME(int i); ARG_CASE(ARG_CS_SV_HA, "minigame1_name",find(world,netname,s1).descriptor.message) \ ARG_CASE(ARG_CS_SV_HA, "minigame1_d", find(world,netname,s1).descriptor.netname) -#define NOTIF_HIT_MAX(count,funcname) do { \ +#define NOTIF_HIT_MAX(count,funcname) MACRO_BEGIN { \ if(sel_num == count) { backtrace(sprintf("%s: Hit maximum arguments!\n", funcname)); break; } \ -} while(0) +} MACRO_END #define NOTIF_HIT_UNKNOWN(token,funcname) { backtrace(sprintf("%s: Hit unknown token in selected string! '%s'\n", funcname, selected)); break; } #define KILL_SPREE_LIST \ diff --git a/qcsrc/common/sounds/sound.qh b/qcsrc/common/sounds/sound.qh index 1e0275858..7e9ba2632 100644 --- a/qcsrc/common/sounds/sound.qh +++ b/qcsrc/common/sounds/sound.qh @@ -40,13 +40,12 @@ const float VOL_BASEVOICE = 1.0; // Otherwise, channels 8 to 15 would be blocked for a weird QW feature. #ifdef SVQC #define _sound(e, c, s, v, a) \ - do \ + MACRO_BEGIN \ { \ entity __e = e; \ - if (!sound_allowed(MSG_BROADCAST, __e)) break; \ - sound7(__e, c, s, v, a, 0, 0); \ - } \ - while (0) + if (sound_allowed(MSG_BROADCAST, __e)) \ + sound7(__e, c, s, v, a, 0, 0); \ + } MACRO_END #else #define _sound(e, c, s, v, a) sound7(e, c, s, v, a, 0, 0) #endif @@ -65,7 +64,7 @@ const float VOL_BASEVOICE = 1.0; * @param sf */ #define sound8(e, o, chan, samp, vol, atten, speed, sf) \ - do \ + MACRO_BEGIN \ { \ entity __e; \ int __chan = chan; \ @@ -87,11 +86,12 @@ const float VOL_BASEVOICE = 1.0; setorigin(__e, o); \ setsize(__e, '0 0 0', '0 0 0'); \ sound7(__e, __chan, __samp, vol, atten, speed, sf); \ - if (auto) break; \ - setorigin(__e, old_origin); \ - setsize(__e, old_mins, old_maxs); \ - } \ - while (0) + if (!auto) \ + { \ + setorigin(__e, old_origin); \ + setsize(__e, old_mins, old_maxs); \ + } \ + } MACRO_END CLASS(Sound, Object) ATTRIB(Sound, m_id, int, 0) diff --git a/qcsrc/common/weapons/config.qh b/qcsrc/common/weapons/config.qh index 05294b355..d88e18194 100644 --- a/qcsrc/common/weapons/config.qh +++ b/qcsrc/common/weapons/config.qh @@ -18,10 +18,10 @@ string wep_config_queue[MAX_WEP_CONFIG]; wep_config_queue[WEP_CONFIG_COUNT] = a; \ ++WEP_CONFIG_COUNT; } -#define WEP_CONFIG_WRITETOFILE(a) do { \ +#define WEP_CONFIG_WRITETOFILE(a) MACRO_BEGIN { \ fputs(wep_config_file, a); \ if(wep_config_alsoprint) { LOG_INFO(a); } \ -} while(0) +} MACRO_END #define WEP_CONFIG_WRITE_CVARS(wepname, name, T) WEP_CONFIG_WRITE_PROPS_##T(wepname, name) diff --git a/qcsrc/lib/_all.inc b/qcsrc/lib/_all.inc index a63b43e22..2d1c0b974 100644 --- a/qcsrc/lib/_all.inc +++ b/qcsrc/lib/_all.inc @@ -25,6 +25,8 @@ #include "../dpdefs/keycodes.qh" #endif +#include "macro.qh" + #include "warpzone/mathlib.qc" #include "accumulate.qh" diff --git a/qcsrc/lib/arraylist.qh b/qcsrc/lib/arraylist.qh index b071805ef..a56047417 100644 --- a/qcsrc/lib/arraylist.qh +++ b/qcsrc/lib/arraylist.qh @@ -6,7 +6,7 @@ typedef entity ArrayList; .int al_len; #define AL_NEW(this, n, default, T) \ - do \ + MACRO_BEGIN \ { \ ArrayList _al = this = new(ArrayList); \ make_pure(_al); \ @@ -16,17 +16,15 @@ typedef entity ArrayList; const _AL_type__##T() it = default; \ AL_set##T(this, i, it); \ } \ - } \ - while (0) + } MACRO_END #define AL_DELETE(this) \ - do \ + MACRO_BEGIN \ { \ buf_del(this.al_buf); \ remove(this); \ this = NULL; \ - } \ - while (0) + } MACRO_END #define _AL_type__s() string #define AL_gets(this, idx) bufstr_get(this.al_buf, idx) @@ -41,7 +39,7 @@ typedef entity ArrayList; #define AL_sete(this, idx, val) AL_setf(this, idx, etof(val)) #define AL_EACH(this, T, cond, body) \ - do \ + MACRO_BEGIN \ { \ const noref ArrayList _al = this; \ for (int i = 0, n = _al.al_len; i < n; ++i) \ @@ -49,7 +47,6 @@ typedef entity ArrayList; const noref _AL_type__##T() it = AL_get##T(_al, i); \ if (cond) { body } \ } \ - } \ - while (0) + } MACRO_END #endif diff --git a/qcsrc/lib/iter.qh b/qcsrc/lib/iter.qh index 3c2b65005..d0f77b553 100644 --- a/qcsrc/lib/iter.qh +++ b/qcsrc/lib/iter.qh @@ -2,29 +2,27 @@ #define ITER_H #define FOREACH_ARRAY(arr, start, end, cond, body) \ - do \ + MACRO_BEGIN \ { \ for (int i = start; i < end; ++i) \ { \ const noref entity it = arr[i]; \ if (cond) { body } \ } \ - } \ - while (0) + } MACRO_END #define FOREACH_LIST(list, next, cond, body) \ - do \ + MACRO_BEGIN \ { \ int i = 0; \ for (entity it = list##_first; it; (it = it.next, ++i)) \ { \ if (cond) { body } \ } \ - } \ - while (0) + } MACRO_END #define FOREACH_WORD(words, cond, body) \ - do \ + MACRO_BEGIN \ { \ string _words = words; \ int i = 0; \ @@ -33,8 +31,7 @@ const noref string it = _it; \ if (cond) { body } \ } \ - } \ - while (0) + } MACRO_END #if defined(CSQC) entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #402; @@ -54,44 +51,40 @@ .entity _FOREACH_ENTITY_next; #define FOREACH_ENTITY_UNORDERED(cond, body) \ - do { \ + MACRO_BEGIN { \ int i = 0; \ for (entity it = findchainentity_tofield(_FOREACH_ENTITY_fld, NULL, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \ { \ if (cond) { body } \ } \ - } \ - while (0) + } MACRO_END #define FOREACH_ENTITY_ORDERED(cond, body) \ - do { \ + MACRO_BEGIN { \ int i = 0; \ for (entity it = NULL; (it = nextent(it)); ++i) \ { \ if (cond) { body } \ } \ - } \ - while (0) + } MACRO_END #define FOREACH_ENTITY_FLAGS(fld, flags, body) \ - do { \ + MACRO_BEGIN { \ int i = 0; \ for (entity it = _findchainflags_tofield(fld, flags, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \ { \ body \ } \ - } \ - while (0) + } MACRO_END #define FOREACH_ENTITY_CLASS(class, cond, body) \ - do { \ + MACRO_BEGIN { \ int i = 0; \ for (entity it = _findchainstring_tofield(classname, class, _FOREACH_ENTITY_next); it; (it = it._FOREACH_ENTITY_next, ++i)) \ { \ if (cond) { body } \ } \ - } \ - while (0) + } MACRO_END #define FOREACH_ENTITY(cond, body) FOREACH_ENTITY_UNORDERED(cond, body) diff --git a/qcsrc/lib/linkedlist.qh b/qcsrc/lib/linkedlist.qh index 3f57fdbc7..192ffd79a 100644 --- a/qcsrc/lib/linkedlist.qh +++ b/qcsrc/lib/linkedlist.qh @@ -48,7 +48,7 @@ entity LL_POP(LinkedList this) #define LL_CLEAR(...) EVAL(OVERLOAD(LL_CLEAR, __VA_ARGS__)) #define LL_CLEAR_1(this) LL_CLEAR_2(this, LAMBDA()) #define LL_CLEAR_2(this, dtor) \ - do \ + MACRO_BEGIN \ { \ LinkedList _ll = this; \ assert(_ll); \ @@ -59,22 +59,20 @@ entity LL_POP(LinkedList this) dtor \ remove(it); \ } \ - } \ - while (0) + } MACRO_END #define LL_DELETE(...) EVAL(OVERLOAD(LL_DELETE, __VA_ARGS__)) #define LL_DELETE_1(this) LL_DELETE_2(this, LAMBDA()) #define LL_DELETE_2(this, dtor) \ - do \ + MACRO_BEGIN \ { \ LL_CLEAR(this, dtor); \ remove(this); \ this = NULL; \ - } \ - while (0) + } MACRO_END #define LL_EACH(list, cond, body) \ - do \ + MACRO_BEGIN \ { \ noref int i = 0; \ for (entity _it = list.ll_head; _it; (_it = _it.ll_next, ++i)) \ @@ -82,7 +80,6 @@ entity LL_POP(LinkedList this) noref entity it = _it.ll_data; \ if (cond) { body } \ } \ - } \ - while (0) + } MACRO_END #endif diff --git a/qcsrc/lib/log.qh b/qcsrc/lib/log.qh index af2bab0f4..3ac8ed238 100644 --- a/qcsrc/lib/log.qh +++ b/qcsrc/lib/log.qh @@ -6,24 +6,22 @@ #define printf(...) print(sprintf(__VA_ARGS__)) #define dprintf(...) dprint(sprintf(__VA_ARGS__)) #define _dprintf2(...) \ - do \ + MACRO_BEGIN \ { \ if (autocvar_developer > 1) dprintf(__VA_ARGS__); \ - } \ - while (0) + } MACRO_END #define assert(expr, ...) _assert(LOG_SEVERE, expr, __VA_ARGS__) #define ASSERT(expr, ...) _assert(LOG_FATAL, expr, __VA_ARGS__) #define _assert(f, expr, then) \ - do \ + MACRO_BEGIN \ { \ if (!(expr)) \ { \ f("assertion failed: `" #expr "`\n"); \ then; \ } \ - } \ - while (0) + } MACRO_END #define ASSERT_LESS(name, var, const) noref int name[(const - var + 1)]; @@ -42,19 +40,17 @@ #define _LOG_WARNING(s) _LOG(printf, "WARNING", s) #define LOG_INFO(...) \ - do \ + MACRO_BEGIN \ { \ if (autocvar_developer) _LOG_INFO(strcat("", __VA_ARGS__)); \ else print(__VA_ARGS__); \ - } \ - while (0) + } MACRO_END #define LOG_INFOF(...) \ - do \ + MACRO_BEGIN \ { \ if (autocvar_developer) _LOG_INFO(sprintf(__VA_ARGS__)); \ else printf(__VA_ARGS__); \ - } \ - while (0) + } MACRO_END #define _LOG_INFO(s) _LOG(printf, "INFO", s) #define LOG_TRACE(...) _LOG_TRACE(strcat("", __VA_ARGS__)) @@ -78,7 +74,7 @@ noref int autocvar_developer; noref bool autocvar_prvm_backtraceforwarnings; #define backtrace(msg) \ - do \ + MACRO_BEGIN \ { \ int dev = autocvar_developer; \ bool war = autocvar_prvm_backtraceforwarnings; \ @@ -89,7 +85,6 @@ noref bool autocvar_prvm_backtraceforwarnings; print("\n--- CUT UNTIL HERE ---\n"); \ cvar_set("developer", ftos(dev)); \ cvar_set("prvm_backtraceforwarnings", ftos(war)); \ - } \ - while (0) + } MACRO_END #endif diff --git a/qcsrc/lib/macro.qh b/qcsrc/lib/macro.qh new file mode 100644 index 000000000..adcbe3553 --- /dev/null +++ b/qcsrc/lib/macro.qh @@ -0,0 +1,13 @@ +#ifndef MACRO_H +#define MACRO_H + +#if 1 + void voidfunc() { error("voidfunc"); } + #define MACRO_BEGIN if (1) { + #define MACRO_END } else voidfunc() +#else + #define MACRO_BEGIN do { + #define MACRO_END } while (0) +#endif + +#endif diff --git a/qcsrc/lib/misc.qh b/qcsrc/lib/misc.qh index e0ac0a478..9ce52dfb5 100644 --- a/qcsrc/lib/misc.qh +++ b/qcsrc/lib/misc.qh @@ -44,13 +44,12 @@ // With block may not contain continue or break #define WITH(type, name, value, block) \ - do \ + MACRO_BEGIN \ { \ type __with_save = (name); \ name = (value); \ LAMBDA(block) \ name = __with_save; \ - } \ - while (0) + } MACRO_END #endif diff --git a/qcsrc/lib/net.qh b/qcsrc/lib/net.qh index 95b3a878a..af914fc64 100644 --- a/qcsrc/lib/net.qh +++ b/qcsrc/lib/net.qh @@ -67,27 +67,24 @@ #ifdef CSQC #define Net_Accept(classname) \ - do \ + MACRO_BEGIN \ { \ if (!this) this = new(classname); \ - } \ - while (0) + } MACRO_END #define Net_Reject() \ - do \ + MACRO_BEGIN \ { \ if (this) remove(this); \ - } \ - while (0) + } MACRO_END #define NET_HANDLE(id, param) \ bool Net_Handle_##id(entity this, param) #else #define WriteHeader(to, id) \ - do \ + MACRO_BEGIN \ { \ if (NET_##id##_istemp) WriteByte(to, SVC_TEMPENTITY); \ WriteByte(to, NET_##id.m_id); \ - } \ - while (0) + } MACRO_END #endif #ifdef CSQC @@ -243,8 +240,8 @@ STATIC_INIT(RegisterTempEntities_renumber) } #define WriteFloat(to, f) WriteCoord(to, f) - #define WriteVector(to, v) do { WriteFloat(to, v.x); WriteFloat(to, v.y); WriteFloat(to, v.z); } while (0) - #define WriteVector2D(to, v) do { WriteFloat(to, v.x); WriteFloat(to, v.y); } while (0) + #define WriteVector(to, v) MACRO_BEGIN { WriteFloat(to, v.x); WriteFloat(to, v.y); WriteFloat(to, v.z); } MACRO_END + #define WriteVector2D(to, v) MACRO_BEGIN { WriteFloat(to, v.x); WriteFloat(to, v.y); } MACRO_END // this will use the value: // 128 @@ -275,11 +272,10 @@ STATIC_INIT(RegisterTempEntities_renumber) if (msg_entity == varname || (msg_entity.classname == STR_SPECTATOR && msg_entity.enemy == varname)) \ statement msg_entity = varname #define WRITESPECTATABLE_MSG_ONE(statement) \ - do \ + MACRO_BEGIN \ { \ WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement); \ - } \ - while (0) + } MACRO_END #define WRITESPECTATABLE(msg, statement) \ if (msg == MSG_ONE) WRITESPECTATABLE_MSG_ONE(statement); \ else \ diff --git a/qcsrc/lib/oo.qh b/qcsrc/lib/oo.qh index 6e393ede7..0a9451097 100644 --- a/qcsrc/lib/oo.qh +++ b/qcsrc/lib/oo.qh @@ -14,17 +14,15 @@ .vector origin; .bool pure_data; #define make_pure(e) \ - do \ + MACRO_BEGIN \ { \ (e).pure_data = true; \ - } \ - while (0) + } MACRO_END #define make_impure(e) \ - do \ + MACRO_BEGIN \ { \ (e).pure_data = false; \ - } \ - while (0) + } MACRO_END #define is_pure(e) ((e).pure_data) .string classname; diff --git a/qcsrc/lib/registry.qh b/qcsrc/lib/registry.qh index a2284b194..7f38afe2a 100644 --- a/qcsrc/lib/registry.qh +++ b/qcsrc/lib/registry.qh @@ -71,21 +71,21 @@ REGISTRY(Registries, BITS(8)) ACCUMULATE_FUNCTION(Register##registry, Register_##id) \ REGISTER_INIT(id) -#define REGISTRY_PUSH(registry, fld, it) do { \ +#define REGISTRY_PUSH(registry, fld, it) MACRO_BEGIN { \ it.fld = registry##_COUNT; \ _R_SET(_##registry, registry##_COUNT, it); \ ++registry##_COUNT; \ if (!registry##_first) registry##_first = it; \ if (registry##_last) registry##_last.REGISTRY_NEXT = it; \ registry##_last = it; \ -} while (0) +} MACRO_END -#define REGISTRY_RESERVE(registry, fld, id, suffix) do { \ +#define REGISTRY_RESERVE(registry, fld, id, suffix) MACRO_BEGIN { \ entity e = new(registry_reserved); \ make_pure(e); \ e.registered_id = #id "/" #suffix; \ REGISTRY_PUSH(registry, fld, e); \ -} while (0) +} MACRO_END #define REGISTER_INIT(id) [[accumulate]] void Register_##id##_init(entity this) #define REGISTER_INIT_POST(id) [[accumulate]] void Register_##id##_init_post(entity this) diff --git a/qcsrc/lib/sort.qh b/qcsrc/lib/sort.qh index 748bd2b27..32ae28112 100644 --- a/qcsrc/lib/sort.qh +++ b/qcsrc/lib/sort.qh @@ -9,17 +9,16 @@ typedef int (int i1, int i2, entity pass) comparefunc_t; void heapsort(int n, swapfunc_t swap, comparefunc_t cmp, entity pass) { #define heapify(_count) \ - do \ + MACRO_BEGIN \ { \ for (int start = floor(((_count) - 2) / 2); start >= 0; --start) \ { \ siftdown(start, (_count) - 1); \ } \ - } \ - while (0) + } MACRO_END #define siftdown(_start, _end) \ - do \ + MACRO_BEGIN \ { \ for (int root = (_start); root * 2 + 1 <= (_end); ) \ { \ @@ -29,8 +28,7 @@ void heapsort(int n, swapfunc_t swap, comparefunc_t cmp, entity pass) swap(root, child, pass); \ root = child; \ } \ - } \ - while (0) + } MACRO_END heapify(n); int end = n - 1; diff --git a/qcsrc/lib/stats.qh b/qcsrc/lib/stats.qh index da796b910..0d445817e 100644 --- a/qcsrc/lib/stats.qh +++ b/qcsrc/lib/stats.qh @@ -47,16 +47,16 @@ typedef vector vectori; #define addstat_int(id, fld) addstat(id, AS_INT, fld) #define addstat_bool(id, fld) addstat(id, AS_INT, fld) #define addstat_float(id, fld) addstat(id, AS_FLOAT, fld) - #define addstat_vector(id, fld) do { \ + #define addstat_vector(id, fld) MACRO_BEGIN { \ addstat_float(id + 0, fld##_x); \ addstat_float(id + 1, fld##_y); \ addstat_float(id + 2, fld##_z); \ - } while (0) - #define addstat_vectori(id, fld) do { \ + } MACRO_END + #define addstat_vectori(id, fld) MACRO_BEGIN { \ addstat_int(id + 0, fld##_x); \ addstat_int(id + 1, fld##_y); \ addstat_int(id + 2, fld##_z); \ - } while (0) + } MACRO_END const int AS_STRING = 1; const int AS_INT = 2; const int AS_FLOAT = 8; diff --git a/qcsrc/lib/test.qh b/qcsrc/lib/test.qh index 6cddb12e5..2890fcaf9 100644 --- a/qcsrc/lib/test.qh +++ b/qcsrc/lib/test.qh @@ -2,11 +2,10 @@ #define TEST_H #define TEST_Check(cond) \ - do \ + MACRO_BEGIN \ { \ if (!(cond)) TEST_Fail( #cond); \ - } \ - while (0) + } MACRO_END void TEST_OK(); void TEST_Fail(string cond); diff --git a/qcsrc/lib/vector.qh b/qcsrc/lib/vector.qh index ec8257e3a..c5c4d6555 100644 --- a/qcsrc/lib/vector.qh +++ b/qcsrc/lib/vector.qh @@ -71,12 +71,12 @@ float boxinsidebox(vector smins, vector smaxs, vector bmins, vector bmaxs) { ret #define YAW(v) ((v).y) #define ROLL(v) ((v).z) -#define MAKEVECTORS(f, angles, forward, right, up) do { \ +#define MAKEVECTORS(f, angles, forward, right, up) MACRO_BEGIN { \ f(angles); \ forward = v_forward; \ right = v_right; \ up = v_up; \ -} while (0) +} MACRO_END noref vector _vec2; #define vec2(v) (_vec2 = (v), _vec2.z = 0, _vec2) diff --git a/qcsrc/menu/draw.qh b/qcsrc/menu/draw.qh index bb12e29c8..74bcae304 100644 --- a/qcsrc/menu/draw.qh +++ b/qcsrc/menu/draw.qh @@ -10,8 +10,8 @@ vector draw_scale; float draw_alpha; void draw_reset(float cw, float ch, float ox, float oy); -#define draw_beginBoldFont() do { drawfont = FONT_USER + 3; } while (0) -#define draw_endBoldFont() do { drawfont = FONT_USER + 0; } while (0) +#define draw_beginBoldFont() MACRO_BEGIN { drawfont = FONT_USER + 3; } MACRO_END +#define draw_endBoldFont() MACRO_BEGIN { drawfont = FONT_USER + 0; } MACRO_END void draw_setMousePointer(string pic, vector theSize, vector theOffset); void draw_drawMousePointer(vector where); diff --git a/qcsrc/menu/xonotic/keybinder.qc b/qcsrc/menu/xonotic/keybinder.qc index 112a34682..4f1c74e81 100644 --- a/qcsrc/menu/xonotic/keybinder.qc +++ b/qcsrc/menu/xonotic/keybinder.qc @@ -47,13 +47,13 @@ void Xonotic_KeyBinds_Read() { Xonotic_KeyBinds_Count = 0; - #define KEYBIND_DEF(func, desc) do { \ + #define KEYBIND_DEF(func, desc) MACRO_BEGIN { \ if((Xonotic_KeyBinds_Count < MAX_KEYBINDS)) { \ Xonotic_KeyBinds_Functions[Xonotic_KeyBinds_Count] = strzone(func); \ Xonotic_KeyBinds_Descriptions[Xonotic_KeyBinds_Count] = strzone(desc); \ ++Xonotic_KeyBinds_Count; \ } \ - } while(0) + } MACRO_END KEYBIND_DEF("" , _("Moving")); KEYBIND_DEF("+forward" , _("forward"));