Skip to content

Commit

Permalink
Reverting the getters (#191)
Browse files Browse the repository at this point in the history
* Revert "Update CHANGELOG.md"

This reverts commit 2fe66fa.

* Revert "cgame optimizations: CG_GetCurrentHoldable(), CG_GetCurrentRune() and CG_GetCurrentWeapons() (#190)"

This reverts commit 83ba9ba.

* Revert "cgame: New getters for health and armor. (#189)"

This reverts commit 3f3e916.
  • Loading branch information
NeonKnightOA authored Mar 13, 2024
1 parent 2fe66fa commit 04c54dc
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 95 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
* Tons of other bug fixes.

### Extended version
* New cgame functions: CG_GetHealth(), CG_GetArmor(), CG_GetCurrentWeapons(), CG_GetCurrentHoldable() and CG_GetCurrentRune(). All of these functions replace direct calls and allowed optimizations to take place.
* New cvar: bot_developer, for bot-based debugging.
* Missionpack/UI3 backend refactors.
* "You Have Been Mined" message outright displays the counter instead of delaying it.
Expand Down
26 changes: 16 additions & 10 deletions code/cgame/cg_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ static void CG_DrawStatusBar(void) {

// stretch the health up when taking damage
CG_DrawField(185, 432, 3, value);
CG_GetColorForHealth( CG_GetHealth(), CG_GetArmor(), hcolor );
CG_ColorForHealth(hcolor);
trap_R_SetColor(hcolor);


Expand Down Expand Up @@ -1979,7 +1979,7 @@ static int CG_DrawPickupItem(int y) {
int value;
float *fadeColor;

if (CG_GetHealth() <= 0) {
if (cg.snap->ps.stats[STAT_HEALTH] <= 0) {
return y;
}

Expand Down Expand Up @@ -2108,9 +2108,12 @@ CG_DrawHoldableItem
#ifndef MISSIONPACK

static void CG_DrawHoldableItem(void) {
if (CG_GetCurrentHoldable()) {
CG_RegisterItemVisuals(CG_GetCurrentHoldable());
CG_DrawPic(640 - ICON_SIZE, (SCREEN_HEIGHT - ICON_SIZE) / 2, ICON_SIZE, ICON_SIZE, cg_items[CG_GetCurrentHoldable()].icon);
int value;

value = cg.snap->ps.stats[STAT_HOLDABLE_ITEM];
if (value) {
CG_RegisterItemVisuals(value);
CG_DrawPic(640 - ICON_SIZE, (SCREEN_HEIGHT - ICON_SIZE) / 2, ICON_SIZE, ICON_SIZE, cg_items[ value ].icon);
}

}
Expand All @@ -2125,9 +2128,12 @@ CG_DrawPersistantPowerup
#if 1 // sos001208 - DEAD // sago - ALIVE

static void CG_DrawPersistantPowerup(void) {
if (CG_GetCurrentRune()) {
CG_RegisterItemVisuals(CG_GetCurrentRune());
CG_DrawPic(640 - ICON_SIZE, (SCREEN_HEIGHT - ICON_SIZE) / 2 - ICON_SIZE, ICON_SIZE, ICON_SIZE, cg_items[CG_GetCurrentRune()].icon);
int value;

value = cg.snap->ps.stats[STAT_PERSISTANT_POWERUP];
if (value) {
CG_RegisterItemVisuals(value);
CG_DrawPic(640 - ICON_SIZE, (SCREEN_HEIGHT - ICON_SIZE) / 2 - ICON_SIZE, ICON_SIZE, ICON_SIZE, cg_items[ value ].icon);
}
}
#endif
Expand Down Expand Up @@ -2710,7 +2716,7 @@ static void CG_DrawCrosshair(void) {
if (cg_crosshairHealth.integer) {
vec4_t hcolor;

CG_GetColorForHealth( CG_GetHealth(), CG_GetArmor(), hcolor );
CG_ColorForHealth(hcolor);
trap_R_SetColor(hcolor);
} else {
vec4_t color;
Expand Down Expand Up @@ -3499,7 +3505,7 @@ static void CG_Draw2D(stereoFrame_t stereoFrame) {
CG_DrawCrosshairNames();
} else {
// don't draw any status if dead or the scoreboard is being explicitly shown
if (!cg.showScores && CG_GetHealth() > 0) {
if (!cg.showScores && cg.snap->ps.stats[STAT_HEALTH] > 0) {

#ifdef MISSIONPACK
if (cg_drawStatus.integer) {
Expand Down
14 changes: 14 additions & 0 deletions code/cgame/cg_drawtools.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,20 @@ void CG_GetColorForHealth( int health, int armor, vec4_t hcolor ) {
}
}

/*
=================
CG_ColorForHealth
=================
*/
void CG_ColorForHealth( vec4_t hcolor ) {

CG_GetColorForHealth( cg.snap->ps.stats[STAT_HEALTH],
cg.snap->ps.stats[STAT_ARMOR], hcolor );
}




// bk001205 - code below duplicated in q3_ui/ui-atoms.c
// bk001205 - FIXME: does this belong in ui_shared.c?
/*
Expand Down
4 changes: 2 additions & 2 deletions code/cgame/cg_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ static void CG_ItemPickup(int itemNum) {
cg.weaponSelect = bg_itemlist[itemNum].giTag;
}
/* if new */
if (cg_autoswitch.integer == 2 && 0 == (CG_GetCurrentWeapons() & (1 << bg_itemlist[itemNum].giTag))) {
if (cg_autoswitch.integer == 2 && 0 == (cg.snap->ps.stats[ STAT_WEAPONS ] & (1 << bg_itemlist[itemNum].giTag))) {
cg.weaponSelectTime = cg.time;
cg.weaponSelect = bg_itemlist[itemNum].giTag;
}
Expand All @@ -573,7 +573,7 @@ static void CG_ItemPickup(int itemNum) {
cg.weaponSelect = bg_itemlist[itemNum].giTag;
}
/* if new and better */
if (cg_autoswitch.integer == 4 && 0 == (CG_GetCurrentWeapons() & (1 << bg_itemlist[itemNum].giTag))
if (cg_autoswitch.integer == 4 && 0 == (cg.snap->ps.stats[ STAT_WEAPONS ] & (1 << bg_itemlist[itemNum].giTag))
&& CG_WeaponHigher(cg.weaponSelect, bg_itemlist[itemNum].giTag)) {
cg.weaponSelectTime = cg.time;
cg.weaponSelect = bg_itemlist[itemNum].giTag;
Expand Down
7 changes: 1 addition & 6 deletions code/cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,7 @@ int CG_DrawStrlen( const char *str );
float *CG_FadeColor( int startMsec, int totalMsec );
float *CG_TeamColor( int team );
void CG_TileClear( void );
void CG_ColorForHealth( vec4_t hcolor );
void CG_GetColorForHealth( int health, int armor, vec4_t hcolor );

void UI_DrawProportionalString( int x, int y, const char* str, int style, vec4_t color );
Expand Down Expand Up @@ -2042,10 +2043,4 @@ qboolean CG_IsATeamGametype(int check); /* Whether the gametype is team-based or
qboolean CG_UsesTeamFlags(int check); /* Whether the gametype uses the red and blue flags. */
qboolean CG_UsesTheWhiteFlag(int check); /* Whether the gametype uses the neutral flag. */
qboolean CG_IsARoundBasedGametype(int check); /* Whether the gametype uses the neutral flag. */

int CG_GetHealth(void); /* Returns the current health amount. */
int CG_GetArmor(void); /* Returns the current armor amount. */
int CG_GetCurrentHoldable(void); /* Returns the current holdable. */
int CG_GetCurrentRune(void); /* Returns the current rune. */
int CG_GetCurrentWeapons(void); /* Returns the current weapons bitflag. */
/* /Neon_Knight */
50 changes: 0 additions & 50 deletions code/cgame/cg_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2746,54 +2746,4 @@ Checks if the gametype has a round-based system.
qboolean CG_IsARoundBasedGametype(int check) {
return GAMETYPE_IS_ROUND_BASED(check);
}
/*
===================
CG_GetHealth
Returns the current health amount.
===================
*/
int CG_GetHealth(void) {
return cg.snap->ps.stats[STAT_HEALTH];
}
/*
===================
CG_GetArmor
Returns the current armor amount.
===================
*/
int CG_GetArmor(void) {
return cg.snap->ps.stats[STAT_ARMOR];
}
/*
===================
CG_GetCurrentHoldable
Returns the current holdable.
===================
*/
int CG_GetCurrentHoldable(void) {
return cg.snap->ps.stats[STAT_HOLDABLE_ITEM];
}
/*
===================
CG_GetCurrentRune
Returns the current holdable.
===================
*/
int CG_GetCurrentRune(void) {
return cg.snap->ps.stats[STAT_PERSISTANT_POWERUP];
}
/*
===================
CG_GetCurrentWeapons
Returns the current weapon.
===================
*/
int CG_GetCurrentWeapons(void) {
return cg.snap->ps.stats[STAT_WEAPONS];
}
/* /Neon_Knight */
25 changes: 15 additions & 10 deletions code/cgame/cg_newdraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,22 +516,24 @@ static void CG_DrawPlayerScore( rectDef_t *rect, float scale, vec4_t color, qhan

static void CG_DrawPlayerItem( rectDef_t *rect, float scale, qboolean draw2D)
{
int value;
vec3_t origin, angles;

if (CG_GetCurrentHoldable()) {
CG_RegisterItemVisuals(CG_GetCurrentHoldable());
value = cg.snap->ps.stats[STAT_HOLDABLE_ITEM];
if ( value ) {
CG_RegisterItemVisuals( value );

if (qtrue) {
CG_RegisterItemVisuals(CG_GetCurrentHoldable());
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cg_items[CG_GetCurrentHoldable()].icon );
CG_RegisterItemVisuals( value );
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cg_items[ value ].icon );
}
else {
VectorClear( angles );
origin[0] = 90;
origin[1] = 0;
origin[2] = -10;
angles[YAW] = ( cg.time & 2047 ) * 360 / 2048.0;
CG_Draw3DModel(rect->x, rect->y, rect->w, rect->h, cg_items[CG_GetCurrentHoldable()].models[0], 0, origin, angles );
CG_Draw3DModel(rect->x, rect->y, rect->w, rect->h, cg_items[ value ].models[0], 0, origin, angles );
}
}

Expand Down Expand Up @@ -868,12 +870,15 @@ static void CG_OneFlagStatus(rectDef_t *rect)

static void CG_DrawCTFPowerUp(rectDef_t *rect)
{
int value;

if (!CG_IsATeamGametype(cgs.gametype)) {
return;
}
if (CG_GetCurrentRune()) {
CG_RegisterItemVisuals(CG_GetCurrentRune());
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cg_items[CG_GetCurrentRune()].icon );
value = cg.snap->ps.stats[STAT_PERSISTANT_POWERUP];
if ( value ) {
CG_RegisterItemVisuals( value );
CG_DrawPic( rect->x, rect->y, rect->w, rect->h, cg_items[ value ].icon );
}
}

Expand Down Expand Up @@ -1154,13 +1159,13 @@ qboolean CG_OwnerDrawVisible(int flags)
}

if (flags & CG_SHOW_HEALTHCRITICAL) {
if (CG_GetHealth() < 25) {
if (cg.snap->ps.stats[STAT_HEALTH] < 25) {
return qtrue;
}
}

if (flags & CG_SHOW_HEALTHOK) {
if (CG_GetHealth() >= 25) {
if (cg.snap->ps.stats[STAT_HEALTH] >= 25) {
return qtrue;
}
}
Expand Down
10 changes: 7 additions & 3 deletions code/cgame/cg_playerstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ void CG_CheckAmmo( void ) {
int i;
int total;
int previous;
int weapons;

// see about how many seconds of ammo we have remaining
weapons = cg.snap->ps.stats[ STAT_WEAPONS ];
total = 0;
for ( i = WP_MACHINEGUN ; i < WP_NUM_WEAPONS ; i++ ) {
if ( ! ( CG_GetCurrentWeapons() & ( 1 << i ) ) || i == WP_GRAPPLING_HOOK ) {
if ( ! ( weapons & ( 1 << i ) ) || i == WP_GRAPPLING_HOOK ) {
continue;
}
switch ( i ) {
Expand Down Expand Up @@ -85,6 +87,7 @@ CG_DamageFeedback
void CG_DamageFeedback( int yawByte, int pitchByte, int damage ) {
float left, front, up;
float kick;
int health;
float scale;
vec3_t dir;
vec3_t angles;
Expand All @@ -95,10 +98,11 @@ void CG_DamageFeedback( int yawByte, int pitchByte, int damage ) {
cg.attackerTime = cg.time;

// the lower on health you are, the greater the view kick will be
if ( CG_GetHealth() < 40 ) {
health = cg.snap->ps.stats[STAT_HEALTH];
if ( health < 40 ) {
scale = 1;
} else {
scale = 40.0 / CG_GetHealth();
scale = 40.0 / health;
}
kick = damage * scale;

Expand Down
4 changes: 2 additions & 2 deletions code/cgame/cg_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ static void CG_OffsetFirstPersonView( void ) {
angles = cg.refdefViewAngles;

// if dead, fix the angle and don't add any kick
if ( CG_GetHealth() <= 0 ) {
if ( cg.snap->ps.stats[STAT_HEALTH] <= 0 ) {
angles[ROLL] = 40;
angles[PITCH] = -15;
angles[YAW] = cg.snap->ps.stats[STAT_DEAD_YAW];
Expand Down Expand Up @@ -982,7 +982,7 @@ void CG_DrawActiveFrame( int serverTime, stereoFrame_t stereoView, qboolean demo
}
else {
cg.renderingThirdPerson = cg.snap->ps.persistant[PERS_TEAM] != TEAM_SPECTATOR
&& (cg_thirdPerson.integer || (CG_GetHealth() <= 0));
&& (cg_thirdPerson.integer || (cg.snap->ps.stats[STAT_HEALTH] <= 0));
}

// build cg.refdef
Expand Down
24 changes: 13 additions & 11 deletions code/cgame/cg_weapons.c
Original file line number Diff line number Diff line change
Expand Up @@ -2259,6 +2259,7 @@ CG_DrawWeaponSelect
void CG_DrawWeaponSelect( void )
{
int i;
int bits;
int count;
float *color;
vec4_t realColor;
Expand Down Expand Up @@ -2290,9 +2291,10 @@ void CG_DrawWeaponSelect( void )
cg.itemPickupTime = 0;

// count the number of weapons owned
bits = cg.snap->ps.stats[ STAT_WEAPONS ];
count = 0;
for ( i = 1 ; i < MAX_WEAPONS ; i++ ) {
if ( CG_GetCurrentWeapons() & ( 1 << i ) ) {
if ( bits & ( 1 << i ) ) {
count++;
}
}
Expand All @@ -2301,28 +2303,28 @@ void CG_DrawWeaponSelect( void )
case -1: // Don't display the weapon bar.
break;
case 1:
CG_DrawWeaponBar1(count,CG_GetCurrentWeapons());
CG_DrawWeaponBar1(count,bits);
break;
case 2:
CG_DrawWeaponBar2(count,CG_GetCurrentWeapons(),color);
CG_DrawWeaponBar2(count,bits, color);
break;
case 3:
CG_DrawWeaponBar3(count,CG_GetCurrentWeapons(),color);
CG_DrawWeaponBar3(count,bits, color);
break;
case 4:
CG_DrawWeaponBar4(count,CG_GetCurrentWeapons(),color);
CG_DrawWeaponBar4(count,bits, color);
break;
case 5:
CG_DrawWeaponBar5(count,CG_GetCurrentWeapons(),color);
CG_DrawWeaponBar5(count,bits, color);
break;
case 6:
CG_DrawWeaponBar6(count,CG_GetCurrentWeapons(),color);
CG_DrawWeaponBar6(count,bits, color);
break;
case 7:
CG_DrawWeaponBar7(count,CG_GetCurrentWeapons(),color);
CG_DrawWeaponBar7(count,bits, color);
break;
default: // Default weapon bar (0)
CG_DrawWeaponBar0(count,CG_GetCurrentWeapons());
CG_DrawWeaponBar0(count,bits);
break;
}
trap_R_SetColor(NULL);
Expand Down Expand Up @@ -3194,7 +3196,7 @@ static qboolean CG_WeaponSelectable( int i )
if ( !cg.snap->ps.ammo[i] ) {
return qfalse;
}
if ( ! (CG_GetCurrentWeapons() & ( 1 << i ) ) ) {
if ( ! (cg.snap->ps.stats[ STAT_WEAPONS ] & ( 1 << i ) ) ) {
return qfalse;
}

Expand Down Expand Up @@ -3348,7 +3350,7 @@ void CG_Weapon_f( void )

cg.weaponSelectTime = cg.time;

if ( ! ( CG_GetCurrentWeapons() & ( 1 << num ) ) ) {
if ( ! ( cg.snap->ps.stats[STAT_WEAPONS] & ( 1 << num ) ) ) {
return; // don't have the weapon
}

Expand Down

0 comments on commit 04c54dc

Please sign in to comment.