// 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
#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;
// 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"; \
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; \
} \
} \
} \
-} 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); \
} \
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) \
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"))); \
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"))); \
} \
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;
// 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)
}
// 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);
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; \
} \
break; \
} \
- } while (0)
+ } MACRO_END
X(red, myteam != NUM_TEAM_1);
X(blue, myteam != NUM_TEAM_2);
X(yellow, myteam != NUM_TEAM_3);
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);
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);
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;\
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) { \
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);
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)
{
}
#define CROSSHAIR_DO_BLUR(M,sz,wcross_name,wcross_alpha) \
- do \
- { \
+ MACRO_BEGIN { \
if(wcross_blur > 0) \
{ \
for(i = -2; i <= 2; ++i) \
{ \
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)
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");
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;
#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; \
else if (flood > 0) fake = false; \
else break; \
_GlobalSound(this, NULL, VM, string_null, CH_VOICE, voicetype, fake); \
- } \
- while (0)
+ } MACRO_END
#endif
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);
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"); \
MUTATOR_ONROLLBACK_OR_REMOVE { \
CallbackChain_Remove(HOOK_##cb, CALLBACK_##func); \
} \
-} while (0)
+} MACRO_END
#include "events.qh"
#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
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(
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
// ======================
// 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, \
stringname \
)) \
); \
- } while(0)
+ } MACRO_END
if(GENTLE)
{
// 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]) \
found_choice.nent_floatcount, \
s1, s2, s3, s4, \
f1, f2, f3, f4); \
- } while(0)
+ } MACRO_END
switch(broadcast)
{
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 \
// 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
* @param sf
*/
#define sound8(e, o, chan, samp, vol, atten, speed, sf) \
- do \
+ MACRO_BEGIN \
{ \
entity __e; \
int __chan = chan; \
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)
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)
#include "../dpdefs/keycodes.qh"
#endif
+#include "macro.qh"
+
#include "warpzone/mathlib.qc"
#include "accumulate.qh"
.int al_len;
#define AL_NEW(this, n, default, T) \
- do \
+ MACRO_BEGIN \
{ \
ArrayList _al = this = new(ArrayList); \
make_pure(_al); \
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)
#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) \
const noref _AL_type__##T() it = AL_get##T(_al, i); \
if (cond) { body } \
} \
- } \
- while (0)
+ } MACRO_END
#endif
#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; \
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)
#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); \
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)) \
noref entity it = _it.ll_data; \
if (cond) { body } \
} \
- } \
- while (0)
+ } MACRO_END
#endif
#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__))
noref bool autocvar_prvm_backtraceforwarnings;
#define backtrace(msg) \
- do \
+ MACRO_BEGIN \
{ \
int dev = autocvar_developer; \
bool war = 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
--- /dev/null
+#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
// 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
#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
}
#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
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 \
.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;
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)
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); ) \
{ \
swap(root, child, pass); \
root = child; \
} \
- } \
- while (0)
+ } MACRO_END
heapify(n);
int end = n - 1;
#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;
#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);
#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)
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);
{
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"));