Skip to content

Commit

Permalink
q3_ui: Replace most macros for better security, easier debugging and …
Browse files Browse the repository at this point in the history
…improved maintainability
  • Loading branch information
LegendaryGuard committed Nov 29, 2024
1 parent a043376 commit 4f9cb18
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 114 deletions.
117 changes: 59 additions & 58 deletions source/q3_ui/ui_bfpoptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,55 +133,56 @@ void BFPAuraOptions_MenuInit( void );
void BFPExplosionsOptions_MenuInit( void );
void BFPViewEffSndsOptions_MenuInit( void );

// A macro to look better the code
#define BFPOPTIONS_MENUITEM( menu_item_curvalue, cvar ) \
menu_item_curvalue = trap_Cvar_VariableValue( cvar ) != 0;
static void BFPOptions_MenuItem( int *menu_item_curvalue, const char *cvar ) {
*menu_item_curvalue = trap_Cvar_VariableValue( cvar ) != 0;
}

static void BFPOptions_SetMenuItems( void ) {
BFPOPTIONS_MENUITEM( s_bfpoptions.fix3person.curvalue, "cg_fixedThirdPerson" )
BFPOPTIONS_MENUITEM( s_bfpoptions.particlesfx.curvalue, "cg_particles" )
BFPOPTIONS_MENUITEM( s_bfpoptions.dynauralight.curvalue, "cg_lightAuras" )
BFPOPTIONS_MENUITEM( s_bfpoptions.dynexplolights.curvalue, "cg_lightExplosions" )
BFPOPTIONS_MENUITEM( s_bfpoptions.bigexplosions.curvalue, "cg_bigExplosions" )
BFPOPTIONS_MENUITEM( s_bfpoptions.explosionshell.curvalue, "cg_explosionShell" )
BFPOPTIONS_MENUITEM( s_bfpoptions.explosionsmoke.curvalue, "cg_explosionSmoke" )
BFPOPTIONS_MENUITEM( s_bfpoptions.explosionring.curvalue, "cg_explosionRing" )
BFPOPTIONS_MENUITEM( s_bfpoptions.transaura.curvalue, "cg_transformationAura" )
BFPOPTIONS_MENUITEM( s_bfpoptions.smallaura.curvalue, "cg_smallOwnAura" )
BFPOPTIONS_MENUITEM( s_bfpoptions.ssjglow.curvalue, "cg_permaglowUltimate" )
BFPOPTIONS_MENUITEM( s_bfpoptions.accucrosshair.curvalue, "cg_stableCrosshair" )
BFPOPTIONS_MENUITEM( s_bfpoptions.simplehud.curvalue, "cg_simpleHUD" )
BFPOPTIONS_MENUITEM( s_bfpoptions.chargealert.curvalue, "cg_chargeupAlert" )
BFPOPTIONS_MENUITEM( s_bfpoptions.q3hitsfx.curvalue, "cg_playHitSound" )
BFPOPTIONS_MENUITEM( s_bfpoptions.flightilt.curvalue, "cg_flytilt" )
BFPOPTIONS_MENUITEM( s_bfpoptions.bigheads.curvalue, "cg_superdeformed" )
BFPOPTIONS_MENUITEM( s_bfpoptions.defaultskins.curvalue, "cg_forceSkin" )
BFPOPTIONS_MENUITEM( s_bfpoptions.stfu.curvalue, "cg_stfu" )
BFPOPTIONS_MENUITEM( s_bfpoptions.lowpolysphere.curvalue, "cg_lowpolysphere" )
BFPOptions_MenuItem( &s_bfpoptions.fix3person.curvalue, "cg_fixedThirdPerson" );
BFPOptions_MenuItem( &s_bfpoptions.particlesfx.curvalue, "cg_particles" );
BFPOptions_MenuItem( &s_bfpoptions.dynauralight.curvalue, "cg_lightAuras" );
BFPOptions_MenuItem( &s_bfpoptions.dynexplolights.curvalue, "cg_lightExplosions" );
BFPOptions_MenuItem( &s_bfpoptions.bigexplosions.curvalue, "cg_bigExplosions" );
BFPOptions_MenuItem( &s_bfpoptions.explosionshell.curvalue, "cg_explosionShell" );
BFPOptions_MenuItem( &s_bfpoptions.explosionsmoke.curvalue, "cg_explosionSmoke" );
BFPOptions_MenuItem( &s_bfpoptions.explosionring.curvalue, "cg_explosionRing" );
BFPOptions_MenuItem( &s_bfpoptions.transaura.curvalue, "cg_transformationAura" );
BFPOptions_MenuItem( &s_bfpoptions.smallaura.curvalue, "cg_smallOwnAura" );
BFPOptions_MenuItem( &s_bfpoptions.ssjglow.curvalue, "cg_permaglowUltimate" );
BFPOptions_MenuItem( &s_bfpoptions.accucrosshair.curvalue, "cg_stableCrosshair" );
BFPOptions_MenuItem( &s_bfpoptions.simplehud.curvalue, "cg_simpleHUD" );
BFPOptions_MenuItem( &s_bfpoptions.chargealert.curvalue, "cg_chargeupAlert" );
BFPOptions_MenuItem( &s_bfpoptions.q3hitsfx.curvalue, "cg_playHitSound" );
BFPOptions_MenuItem( &s_bfpoptions.flightilt.curvalue, "cg_flytilt" );
BFPOptions_MenuItem( &s_bfpoptions.bigheads.curvalue, "cg_superdeformed" );
BFPOptions_MenuItem( &s_bfpoptions.defaultskins.curvalue, "cg_forceSkin" );
BFPOptions_MenuItem( &s_bfpoptions.stfu.curvalue, "cg_stfu" );
BFPOptions_MenuItem( &s_bfpoptions.lowpolysphere.curvalue, "cg_lowpolysphere" );
}

static void BFPOptions_AuraType_Setup( int sprite, int highpoly, int poly, int light, int particle ) {
trap_Cvar_SetValue( "cg_spriteAura", sprite );
trap_Cvar_SetValue( "cg_highPolyAura", highpoly );
trap_Cvar_SetValue( "cg_polygonAura", poly );
trap_Cvar_SetValue( "cg_lightweightAuras", light );
trap_Cvar_SetValue( "cg_particleAura", particle );
}

static void BFPOptions_Viewpoint_Setup( int tp, int ownmodel ) {
trap_Cvar_SetValue( "cg_thirdPerson", tp );
trap_Cvar_SetValue( "cg_drawOwnModel", ownmodel );
}

static void BFPOptions_ExploType_Setup( int expShell, int expSmoke, int particles, int expRing ) {
trap_Cvar_SetValue( "cg_explosionShell", expShell );
trap_Cvar_SetValue( "cg_explosionSmoke", expSmoke );
trap_Cvar_SetValue( "cg_explosionRing", expRing );
trap_Cvar_SetValue( "cg_particles", particles );
s_bfpoptions.explosionshell.curvalue = expShell;
s_bfpoptions.explosionsmoke.curvalue = expSmoke;
s_bfpoptions.explosionring.curvalue = expRing;
s_bfpoptions.particlesfx.curvalue = particles;
}
#undef BFPOPTIONS_MENUITEM

// Macros to look better the code
#define AURATYPE_SETUP(sprite, highpoly, poly, light, particle) \
trap_Cvar_SetValue( "cg_spriteAura", sprite ); \
trap_Cvar_SetValue( "cg_highPolyAura", highpoly ); \
trap_Cvar_SetValue( "cg_polygonAura", poly ); \
trap_Cvar_SetValue( "cg_lightweightAuras", light );\
trap_Cvar_SetValue( "cg_particleAura", particle );

#define VIEWPOINT_SETUP(tp, ownmodel) \
trap_Cvar_SetValue( "cg_thirdPerson", tp ); \
trap_Cvar_SetValue( "cg_drawOwnModel", ownmodel );

#define EXPLOTYPE_SETUP(expShell, expSmoke, particles, expRing ) \
trap_Cvar_SetValue( "cg_explosionShell", expShell ); \
trap_Cvar_SetValue( "cg_explosionSmoke", expSmoke ); \
trap_Cvar_SetValue( "cg_explosionRing", expRing ); \
trap_Cvar_SetValue( "cg_particles", particles ); \
s_bfpoptions.explosionshell.curvalue = expShell; \
s_bfpoptions.explosionsmoke.curvalue = expSmoke; \
s_bfpoptions.explosionring.curvalue = expRing; \
s_bfpoptions.particlesfx.curvalue = particles;

static void BFPOptions_ExplosionsTypeCheck( void ) {
int particles = s_bfpoptions.particlesfx.curvalue;
Expand Down Expand Up @@ -236,27 +237,27 @@ static void BFPOptions_Event( void* ptr, int notification ) {
case ID_AURATYPE:
switch ( s_bfpoptions.auratype.curvalue ) {
case SPRITE_AURA:
AURATYPE_SETUP( 1, 0, 0, 0, 0 )
BFPOptions_AuraType_Setup( 1, 0, 0, 0, 0 );
break;

case LIGHTWEIGHT_AURA:
AURATYPE_SETUP( 0, 0, 0, 1, 0 )
BFPOptions_AuraType_Setup( 0, 0, 0, 1, 0 );
break;

case POLYGON_AURA:
AURATYPE_SETUP( 0, 0, 1, 0, 0 )
BFPOptions_AuraType_Setup( 0, 0, 1, 0, 0 );
break;

case HIGHPOLYCOUNT_AURA:
AURATYPE_SETUP( 0, 1, 1, 0, 0 )
BFPOptions_AuraType_Setup( 0, 1, 1, 0, 0 );
break;

case PARTICLE_AURA:
AURATYPE_SETUP( 0, 0, 0, 0, 1 )
BFPOptions_AuraType_Setup( 0, 0, 0, 0, 1 );
break;

case SHADER_AURA:
AURATYPE_SETUP( 0, 0, 0, 0, 0 )
BFPOptions_AuraType_Setup( 0, 0, 0, 0, 0 );
break;
}
break;
Expand All @@ -270,11 +271,11 @@ static void BFPOptions_Event( void* ptr, int notification ) {
break;

case 1: // First Person
VIEWPOINT_SETUP( 0, 0 )
BFPOptions_Viewpoint_Setup( 0, 0 );
break;

case 2: // First Person Vis
VIEWPOINT_SETUP( 0, 1 )
BFPOptions_Viewpoint_Setup( 0, 1 );
break;
}
break;
Expand All @@ -284,19 +285,19 @@ static void BFPOptions_Event( void* ptr, int notification ) {
case ID_EXPLOTYPE:
switch ( s_bfpoptions.explotype.curvalue ) {
case WIMPY_EXPLO: // Wimpy
EXPLOTYPE_SETUP( 0, 0, 0, 0 )
BFPOptions_ExploType_Setup( 0, 0, 0, 0 );
break;

case WEAK_EXPLO: // Weak
EXPLOTYPE_SETUP( 1, 0, 0, 1 )
BFPOptions_ExploType_Setup( 1, 0, 0, 1 );
break;

case SO_SO_EXPLO: // So-So
EXPLOTYPE_SETUP( 1, 0, 1, 1 )
BFPOptions_ExploType_Setup( 1, 0, 1, 1 );
break;

case HARDCORE_EXPLO: // Hardcore
EXPLOTYPE_SETUP( 1, 1, 1, 1 )
BFPOptions_ExploType_Setup( 1, 1, 1, 1 );
break;
}
break;
Expand Down
106 changes: 50 additions & 56 deletions source/q3_ui/ui_controls2.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,72 +270,66 @@ static controls_t s_controls;

static vec4_t controls_binding_color = {0.90f, 0.90f, 1.00f, 1.00f}; // BFP - Changed to light blue gray (before orange: {1.00f, 0.43f, 0.00f, 1.00f})

// BFP - A macro to shorten the number of parameters of key bindings
#define G_BINDING_KEY(command, label, id, anim, keybind) {command, label, id, anim, keybind, -1, -1, -1},
static bind_t g_bindings[] =
{
G_BINDING_KEY( "+scores", "show scores", ID_SHOWSCORES, ANIM_IDLE, K_TAB )
G_BINDING_KEY( "+button2", "use item", ID_USEITEM, ANIM_IDLE, K_ENTER )
G_BINDING_KEY( "+speed", "run / walk", ID_SPEED, ANIM_RUN, K_SHIFT )
G_BINDING_KEY( "+forward", "walk forward", ID_FORWARD, ANIM_WALK, K_UPARROW )
G_BINDING_KEY( "+back", "backpedal", ID_BACKPEDAL, ANIM_BACK, K_DOWNARROW )
G_BINDING_KEY( "+moveleft", "step left", ID_MOVELEFT, ANIM_STEPLEFT, ',' )
G_BINDING_KEY( "+moveright", "step right", ID_MOVERIGHT, ANIM_STEPRIGHT, '.' )
G_BINDING_KEY( "+moveup", "up / jump", ID_MOVEUP, ANIM_JUMP, K_SPACE )
G_BINDING_KEY( "+movedown", "down / crouch", ID_MOVEDOWN, ANIM_CROUCH, 'c' )
G_BINDING_KEY( "+left", "turn left", ID_LEFT, ANIM_TURNLEFT, K_LEFTARROW )
G_BINDING_KEY( "+right", "turn right", ID_RIGHT, ANIM_TURNRIGHT, K_RIGHTARROW )
G_BINDING_KEY( "+strafe", "sidestep / turn", ID_STRAFE, ANIM_IDLE, K_ALT )
G_BINDING_KEY( "+button12", "fly", ID_ENABLEFLIGHT,ANIM_FLY, 'f' ) // BFP - flight control "fly" bind
G_BINDING_KEY( "+lookup", "look up", ID_LOOKUP, ANIM_LOOKUP, K_PGDN )
G_BINDING_KEY( "+lookdown", "look down", ID_LOOKDOWN, ANIM_LOOKDOWN, K_DEL )
G_BINDING_KEY( "+mlook", "mouse look", ID_MOUSELOOK, ANIM_IDLE, '/' )
G_BINDING_KEY( "centerview", "center view", ID_CENTERVIEW, ANIM_IDLE, K_END )
G_BINDING_KEY( "+zoom", "zoom view", ID_ZOOMVIEW, ANIM_IDLE, -1 )
G_BINDING_KEY( "weapon 1", "ki attack 1", ID_KIATTACK1, ANIM_KIATTACK1, '1' ) // BFP - ki attack 1 (before gauntlet)
G_BINDING_KEY( "weapon 2", "ki attack 2", ID_KIATTACK2, ANIM_KIATTACK2, '2' ) // BFP - ki attack 2 (before machinegun)
G_BINDING_KEY( "weapon 3", "ki attack 3", ID_KIATTACK3, ANIM_KIATTACK3, '3' ) // BFP - ki attack 3 (before shotgun)
G_BINDING_KEY( "weapon 4", "ki attack 4", ID_KIATTACK4, ANIM_KIATTACK4, '4' ) // BFP - ki attack 4 (before grenade launcher)
G_BINDING_KEY( "weapon 5", "ki attack 5", ID_KIATTACK5, ANIM_KIATTACK5, '5' ) // BFP - ki attack 5 (before rocket launcher)
{ "+scores", "show scores", ID_SHOWSCORES, ANIM_IDLE, K_TAB, -1, -1, -1 },
{ "+button2", "use item", ID_USEITEM, ANIM_IDLE, K_ENTER, -1, -1, -1 },
{ "+speed", "run / walk", ID_SPEED, ANIM_RUN, K_SHIFT, -1, -1, -1 },
{ "+forward", "walk forward", ID_FORWARD, ANIM_WALK, K_UPARROW, -1, -1, -1 },
{ "+back", "backpedal", ID_BACKPEDAL, ANIM_BACK, K_DOWNARROW, -1, -1, -1 },
{ "+moveleft", "step left", ID_MOVELEFT, ANIM_STEPLEFT, ',', -1, -1, -1 },
{ "+moveright", "step right", ID_MOVERIGHT, ANIM_STEPRIGHT, '.', -1, -1, -1 },
{ "+moveup", "up / jump", ID_MOVEUP, ANIM_JUMP, K_SPACE, -1, -1, -1 },
{ "+movedown", "down / crouch", ID_MOVEDOWN, ANIM_CROUCH, 'c', -1, -1, -1 },
{ "+left", "turn left", ID_LEFT, ANIM_TURNLEFT, K_LEFTARROW, -1, -1, -1 },
{ "+right", "turn right", ID_RIGHT, ANIM_TURNRIGHT, K_RIGHTARROW, -1, -1, -1 },
{ "+strafe", "sidestep / turn", ID_STRAFE, ANIM_IDLE, K_ALT, -1, -1, -1 },
{ "+button12", "fly", ID_ENABLEFLIGHT,ANIM_FLY, 'f', -1, -1, -1 }, // BFP - flight control "fly" bind
{ "+lookup", "look up", ID_LOOKUP, ANIM_LOOKUP, K_PGDN, -1, -1, -1 },
{ "+lookdown", "look down", ID_LOOKDOWN, ANIM_LOOKDOWN, K_DEL, -1, -1, -1 },
{ "+mlook", "mouse look", ID_MOUSELOOK, ANIM_IDLE, '/', -1, -1, -1 },
{ "centerview", "center view", ID_CENTERVIEW, ANIM_IDLE, K_END, -1, -1, -1 },
{ "+zoom", "zoom view", ID_ZOOMVIEW, ANIM_IDLE, -1, -1, -1, -1 },
{ "weapon 1", "ki attack 1", ID_KIATTACK1, ANIM_KIATTACK1, '1', -1, -1, -1 }, // BFP - ki attack 1 (before gauntlet)
{ "weapon 2", "ki attack 2", ID_KIATTACK2, ANIM_KIATTACK2, '2', -1, -1, -1 }, // BFP - ki attack 2 (before machinegun)
{ "weapon 3", "ki attack 3", ID_KIATTACK3, ANIM_KIATTACK3, '3', -1, -1, -1 }, // BFP - ki attack 3 (before shotgun)
{ "weapon 4", "ki attack 4", ID_KIATTACK4, ANIM_KIATTACK4, '4', -1, -1, -1 }, // BFP - ki attack 4 (before grenade launcher)
{ "weapon 5", "ki attack 5", ID_KIATTACK5, ANIM_KIATTACK5, '5', -1, -1, -1 }, // BFP - ki attack 5 (before rocket launcher)
// BFP - unused
#if 0
G_BINDING_KEY( "weapon 6", "lightning", ID_WEAPON6, ANIM_WEAPON6, '6' )
G_BINDING_KEY( "weapon 7", "railgun", ID_WEAPON7, ANIM_WEAPON7, '7' )
G_BINDING_KEY( "weapon 8", "plasma gun", ID_WEAPON8, ANIM_WEAPON8, '8' )
G_BINDING_KEY( "weapon 9", "BFG", ID_WEAPON9, ANIM_WEAPON9, '9' )
{ "weapon 6", "lightning", ID_WEAPON6, ANIM_WEAPON6, '6', -1, -1, -1 },
{ "weapon 7", "railgun", ID_WEAPON7, ANIM_WEAPON7, '7', -1, -1, -1 },
{ "weapon 8", "plasma gun", ID_WEAPON8, ANIM_WEAPON8, '8', -1, -1, -1 },
{ "weapon 9", "BFG", ID_WEAPON9, ANIM_WEAPON9, '9', -1, -1, -1 },
#endif
G_BINDING_KEY( "+attack", "attack", ID_ATTACK, ANIM_ATTACK, K_CTRL )
G_BINDING_KEY( "+button7", "Melee Combat", ID_MELEE, ANIM_MELEE, K_ALT ) // BFP - melee
G_BINDING_KEY( "+button10", "Block", ID_BLOCK, ANIM_BLOCK, K_CTRL ) // BFP - block
G_BINDING_KEY( "weapprev", "prev weapon", ID_WEAPPREV, ANIM_IDLE, '[' )
G_BINDING_KEY( "weapnext", "next weapon", ID_WEAPNEXT, ANIM_IDLE, ']' )
G_BINDING_KEY( "+button3", "gesture", ID_GESTURE, ANIM_GESTURE, K_MOUSE3 )
G_BINDING_KEY( "messagemode", "chat", ID_CHAT, ANIM_CHAT, 't' )
G_BINDING_KEY( "messagemode2", "chat - team", ID_CHAT2, ANIM_CHAT, -1 )
G_BINDING_KEY( "messagemode3", "chat - target", ID_CHAT3, ANIM_CHAT, -1 )
G_BINDING_KEY( "messagemode4", "chat - attacker", ID_CHAT4, ANIM_CHAT, -1 )
G_BINDING_KEY( "+button9", "Charge Ki", ID_KICHARGE, ANIM_KICHARGE, K_MOUSE2 ) // BFP - charge ki control
G_BINDING_KEY( "kiusetoggle", "Use Ki (toggle)", ID_KIUSETOGGLE, ANIM_IDLE, 'e' ) // BFP - use ki toggle control
G_BINDING_KEY( "+button8", "Use Ki", ID_KIUSE, ANIM_IDLE, K_SHIFT ) // BFP - use ki control
G_BINDING_KEY( (char*)NULL, (char*)NULL, 0, 0, -1 )
{ "+attack", "attack", ID_ATTACK, ANIM_ATTACK, K_CTRL, -1, -1, -1 },
{ "+button7", "Melee Combat", ID_MELEE, ANIM_MELEE, K_ALT, -1, -1, -1 }, // BFP - melee
{ "+button10", "Block", ID_BLOCK, ANIM_BLOCK, K_CTRL, -1, -1, -1 }, // BFP - block
{ "weapprev", "prev weapon", ID_WEAPPREV, ANIM_IDLE, '[', -1, -1, -1 },
{ "weapnext", "next weapon", ID_WEAPNEXT, ANIM_IDLE, ']', -1, -1, -1 },
{ "+button3", "gesture", ID_GESTURE, ANIM_GESTURE, K_MOUSE3, -1, -1, -1 },
{ "messagemode", "chat", ID_CHAT, ANIM_CHAT, 't', -1, -1, -1 },
{ "messagemode2", "chat - team", ID_CHAT2, ANIM_CHAT, -1, -1, -1, -1 },
{ "messagemode3", "chat - target", ID_CHAT3, ANIM_CHAT, -1, -1, -1, -1 },
{ "messagemode4", "chat - attacker", ID_CHAT4, ANIM_CHAT, -1, -1, -1, -1 },
{ "+button9", "Charge Ki", ID_KICHARGE, ANIM_KICHARGE, K_MOUSE2, -1, -1, -1 }, // BFP - charge ki control
{ "kiusetoggle", "Use Ki (toggle)", ID_KIUSETOGGLE, ANIM_IDLE, 'e', -1, -1, -1 }, // BFP - use ki toggle control
{ "+button8", "Use Ki", ID_KIUSE, ANIM_IDLE, K_SHIFT, -1, -1, -1 }, // BFP - use ki control
{ (char*)NULL, (char*)NULL, 0, 0, -1, -1, -1, -1 },
};
#undef G_BINDING_KEY

// BFP - A macro to shorten the number of parameters of configcvars
#define G_CONFIGCVAR(cvarname) {cvarname, 0, 0},
static configcvar_t g_configcvars[] =
{
G_CONFIGCVAR( "cl_run" )
G_CONFIGCVAR( "m_pitch" )
G_CONFIGCVAR( "cg_autoswitch" )
G_CONFIGCVAR( "sensitivity" )
G_CONFIGCVAR( "in_joystick" )
G_CONFIGCVAR( "joy_threshold" )
G_CONFIGCVAR( "m_filter" )
G_CONFIGCVAR( "cl_freelook" )
G_CONFIGCVAR( NULL )
{ "cl_run", 0, 0 },
{ "m_pitch", 0, 0 },
{ "cg_autoswitch", 0, 0 },
{ "sensitivity", 0, 0 },
{ "in_joystick", 0, 0 },
{ "joy_threshold", 0, 0 },
{ "m_filter", 0, 0 },
{ "cl_freelook", 0, 0 },
{ NULL, 0, 0 }
};
#undef G_CONFIGCVAR

static menucommon_s *g_movement_controls[] =
{
Expand Down

0 comments on commit 4f9cb18

Please sign in to comment.