]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Macros: optimize
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 10 Dec 2015 08:03:10 +0000 (19:03 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 10 Dec 2015 08:03:10 +0000 (19:03 +1100)
33 files changed:
qcsrc/client/csqcmodel_hooks.qc
qcsrc/client/hud/hud.qh
qcsrc/client/hud/panel/infomessages.qc
qcsrc/client/hud/panel/modicons.qc
qcsrc/client/miscfunctions.qh
qcsrc/client/view.qc
qcsrc/common/effects/effectinfo.qc
qcsrc/common/effects/qc/globalsound.qc
qcsrc/common/effects/qc/globalsound.qh
qcsrc/common/mapinfo.qc
qcsrc/common/mutators/base.qh
qcsrc/common/mutators/mutator/nades/nades.inc
qcsrc/common/net_notice.qc
qcsrc/common/notifications.qc
qcsrc/common/notifications.qh
qcsrc/common/sounds/sound.qh
qcsrc/common/weapons/config.qh
qcsrc/lib/_all.inc
qcsrc/lib/arraylist.qh
qcsrc/lib/iter.qh
qcsrc/lib/linkedlist.qh
qcsrc/lib/log.qh
qcsrc/lib/macro.qh [new file with mode: 0644]
qcsrc/lib/misc.qh
qcsrc/lib/net.qh
qcsrc/lib/oo.qh
qcsrc/lib/registry.qh
qcsrc/lib/sort.qh
qcsrc/lib/stats.qh
qcsrc/lib/test.qh
qcsrc/lib/vector.qh
qcsrc/menu/draw.qh
qcsrc/menu/xonotic/keybinder.qc

index 506d35c6bb6c02a6a4dc934645c34ec66474878e..83c3f448a2ec802378a09d238b62d0afdcf26de1 100644 (file)
@@ -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
index d30a87273514636a87d1fd9b2ca6903c96e0f67d..47126a7389c6c53f4fd73b6e51a546edb4b04ce5 100644 (file)
@@ -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;
index 33f797f3d3201b0a337596a774f709c1c8244ce9..9153b855da45c510d7c88fcb561b8fb205ea0bac 100644 (file)
@@ -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)
index d57a23e1e90f6bc55ade27d6f806ecc94bc155b0..9ea22c92bf55333fe9e508652bb7185d6f6cbbd1 100644 (file)
@@ -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);
index ddac22e8dab42c07f560372bd795ee0e4cf564cf..3066fc6c642c8f7c5530732352911222e61bc18b 100644 (file)
@@ -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);
index c1591497138e138daaf067b0933e00aaf85faf01..8602ef26a24eb179ebf0aee8599393f3e25dff67 100644 (file)
@@ -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)
index f4df3237d4e5ef046bb5909e84652004d2da9f59..400a47b5d5d9b004b2e94ff85f8c700b7d5b5287 100644 (file)
@@ -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");
index 9f530b9ea7478faf858c35257024e80dd18d4e65..83a2440cf8fe08e9f1db7e3423bdcff89a37c2a5 100644 (file)
                                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
                                        float tauntrand = 0;
                                        if (voicetype == VOICETYPE_AUTOTAUNT) tauntrand = random();
                                        #define X() \
-                                               do \
+                                               MACRO_BEGIN \
                                                { \
                                                        if (voicetype != VOICETYPE_AUTOTAUNT || tauntrand < msg_entity.cvar_cl_autotaunt) \
                                                        { \
                                                                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;
index 12ceee29cb31230e3043dc87308bf45de541b23f..1708f912e67fbd47af8a722b8fa08078efc1c658 100644 (file)
@@ -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
 
index 5ca1c3803da30ea19467f6daaa21074ec4ac2d74..173aa8e42e55a574af0e7be9327d1b13ceb211ee 100644 (file)
@@ -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);
index 54b7b662413e28aff63f1c6795aef7ea11237063..6e06e5590943b0c5a7619b96d46a5fcfa8876181 100644 (file)
@@ -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"
 
index 6d16fd15096b3f39cf8131122a9f6c55b5e5ae56..d2f350c5f2bcaa3a9dcba264a541f84c305ff700 100644 (file)
@@ -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
index c25997b1a3dc75c5a15f3e36e5fce9bc87670472..06f310799423f05c635f263e76e74b35225e8f75 100644 (file)
@@ -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(
index 94a46d94aed1774daf01790a11414ca9509b329e..c8664e7af04743d2fce4886ed2ce463a4c185cb4 100644 (file)
@@ -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)
                {
index f3cd0ba494ea482f77b60441f0d7219cc365a815..10ce481d77efe6cdc43c6b4f4ebc5e2df52c75e3 100644 (file)
@@ -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 \
index 1e02758580b7a7e2c982fd36dbd3019013809a61..7e9ba263240f759de67320a778bbc9137612edea 100644 (file)
@@ -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)
index 05294b355e09dfbe1cbeae1ea5b7efd714dbd779..d88e18194bf7c37af8991483eb4448f7448e8a50 100644 (file)
@@ -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)
index a63b43e22a58c879e8c378e91a037bd7b13b0bf4..2d1c0b9744f912fe3e5121f9a20276508e31b067 100644 (file)
@@ -25,6 +25,8 @@
        #include "../dpdefs/keycodes.qh"
 #endif
 
+#include "macro.qh"
+
 #include "warpzone/mathlib.qc"
 
 #include "accumulate.qh"
index b071805ef4136e0b06d2c4b4452f139c0e9e8968..a560474174c3ef742ebe2b711d7fe2142643e2ef 100644 (file)
@@ -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
index 3c2b650051eeee205ffa0b164e2234a0f2e890ad..d0f77b553cb7bb061ab1096f697fa99e53774a09 100644 (file)
@@ -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;
 .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)
 
index 3f57fdbc7214872dfad24b4de2fb0d10480185a0..192ffd79a7dc1c672c87b3d3208033bdb31b15b7 100644 (file)
@@ -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
index af2bab0f486a94b95a6795110f87a08c5d24fa1e..3ac8ed23864c8d787580be8971dcd6ed29266ea7 100644 (file)
@@ -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)];
 
 #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 (file)
index 0000000..adcbe35
--- /dev/null
@@ -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
index e0ac0a478074b6778ab39b34ecf4e069e8c2d979..9ce52dfb596c3d328d3e53eeb7385da3c7de69cb 100644 (file)
 
 // 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
index 95b3a878a763343b5defeafb1df7470261f23975..af914fc6482a2d0af6094b24e3f5e67313a7e3d6 100644 (file)
 
 #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 \
index 6e393ede7bb0d0fc8c68e6f67e81490f6285d8b5..0a945109709a232ecbb689b5d5f3063ca17e4089 100644 (file)
 .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;
index a2284b19448a10428963439464da0b91940a5b73..7f38afe2a7c65553816dd0d61b7662ba805ac544 100644 (file)
@@ -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)
index 748bd2b2748efe82a071e4583771adbe338de146..32ae28112f16b98805789a1ee85aa9a8b5705f0e 100644 (file)
@@ -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;
index da796b910f5fd69745323de0b3493e7530ea5843..0d445817e9118f58212a04ab6f743d199a26873d 100644 (file)
@@ -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;
index 6cddb12e50b1257ac5fe60a56ff3c298889420bc..2890fcaf92f7012e0d8352eeecef69589a026de4 100644 (file)
@@ -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);
index ec8257e3a672ce72d5007689208111fe2d2ca44d..c5c4d655585d1bf6d8a0b0b3d9dd0b2b8ffaebef 100644 (file)
@@ -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)
index bb12e29c8162efc889bbf84f1c5109c8113e01cf..74bcae3042dfd886529aff28737462144e193272 100644 (file)
@@ -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);
 
index 112a346828ebf098deb74f4985e855414cd79583..4f1c74e8156eba07a6e78ccf7637c185d39b3171 100644 (file)
@@ -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"));