Skip to content

Commit

Permalink
Merge branch 'port' into dev/pausing-optional
Browse files Browse the repository at this point in the history
  • Loading branch information
cylonicboom committed Jan 28, 2024
2 parents 7fe34f2 + 33cc89e commit 26d3c39
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 1 deletion.
1 change: 1 addition & 0 deletions port/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,6 @@ PD_CONSTRUCTOR static void gameConfigInit(void)
configRegisterInt(strFmt("Game.Player%d.ExtendedControls", i), &g_PlayerExtCfg[j].extcontrols, 0, 1);
configRegisterUInt(strFmt("Game.Player%d.CrosshairColour", i), &g_PlayerExtCfg[j].crosshaircolour, 0, 0xFFFFFFFF);
configRegisterUInt(strFmt("Game.Player%d.CrosshairSize", i), &g_PlayerExtCfg[j].crosshairsize, 0, 4);
configRegisterInt(strFmt("Game.Player%d.CrosshairHealth", i), &g_PlayerExtCfg[j].crosshairhealth, 0, CROSSHAIR_HEALTH_ON_WHITE);
}
}
32 changes: 32 additions & 0 deletions port/src/optionsmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,30 @@ static MenuItemHandlerResult menuhandlerCrosshairSize(s32 operation, struct menu
return 0;
}

static MenuItemHandlerResult menuhandlerCrosshairHealth(s32 operation, struct menuitem *item, union handlerdata *data)
{
static const char *opts[] = {
"Off",
"On (Green)",
"On (White)"
};

switch (operation) {
case MENUOP_GETOPTIONCOUNT:
data->dropdown.value = ARRAYCOUNT(opts);
break;
case MENUOP_GETOPTIONTEXT:
return (intptr_t)opts[data->dropdown.value];
case MENUOP_SET:
g_PlayerExtCfg[g_ExtMenuPlayer].crosshairhealth = data->dropdown.value;
break;
case MENUOP_GETSELECTEDINDEX:
data->dropdown.value = g_PlayerExtCfg[g_ExtMenuPlayer].crosshairhealth;
}

return 0;
}

struct menuitem g_ExtendedGameCrosshairColourMenuItems[] = {
{
MENUITEMTYPE_SLIDER,
Expand Down Expand Up @@ -1180,6 +1204,14 @@ struct menuitem g_ExtendedGameMenuItems[] = {
0,
(void*)&g_ExtendedGameCrosshairColourMenuDialog,
},
{
MENUITEMTYPE_DROPDOWN,
0,
MENUITEMFLAG_LITERAL_TEXT,
(uintptr_t)"Crosshair Colour by Health",
0,
menuhandlerCrosshairHealth,
},
{
MENUITEMTYPE_SEPARATOR,
0,
Expand Down
1 change: 1 addition & 0 deletions src/game/mplayer/mplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ struct mpweapon g_MpWeapons[NUM_MPWEAPONS] = {
.extcontrols = true, \
.crosshaircolour = 0x00ff0028, \
.crosshairsize = 2, \
.crosshairhealth = CROSSHAIR_HEALTH_OFF, \
}

struct extplayerconfig g_PlayerExtCfg[MAX_PLAYERS] = {
Expand Down
55 changes: 54 additions & 1 deletion src/game/sight.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,55 @@
#include <math.h>
#include "video.h"

#define SIGHT_COLOUR PLAYER_EXTCFG().crosshaircolour
#define SIGHT_COLOUR ((PLAYER_EXTCFG().crosshairhealth >= CROSSHAIR_HEALTH_ON_GREEN) ? sightGetCrosshairHealthColor(g_Vars.currentplayer->bondhealth, g_Vars.currentplayer->prop->chr->cshield * 0.125f) : PLAYER_EXTCFG().crosshaircolour)
#define SIGHT_SCALE PLAYER_EXTCFG().crosshairsize

static u32 sightGetCrosshairHealthColor(float health, float shield)
{
const float ratio = MAX(0.0f, MIN(health + shield, 2.0f));

int red = 0;
int green = 0;
int blue = 0;
if (ratio < 0.2f) {
// Red (critical health level)
red = 255;
green = 0;
blue = 0;
} else if (ratio < 0.6f) {
// Red-yellow
red = 255;
green = 255 * ((ratio - 0.2f) / 0.4f);
blue = 0;
} else if (ratio < 1.0f) {
if (PLAYER_EXTCFG().crosshairhealth == CROSSHAIR_HEALTH_ON_GREEN) {
// Yellow-green
red = 255 * ((ratio - 0.6f) / 0.4f);
green = 255;
blue = 0;
} else {
// Yellow-white
red = 255;
green = 255;
blue = 255 * ((ratio - 0.6f) / 0.4f);
}
} else {
if (PLAYER_EXTCFG().crosshairhealth == CROSSHAIR_HEALTH_ON_GREEN) {
// Green-cyan (overheal via shield)
red = 0;
green = 255;
blue = 255 * (ratio - 1.0f);
} else {
// White-green (overheal via shield)
red = 255 * (2.0f - ratio);
green = 255;
blue = 255 * (2.0f - ratio);
}
}

return (red << 24) + (green << 16) + (blue << 8) + (PLAYER_EXTCFG().crosshaircolour & 0xff);
}

static inline f32 sightGetScaleX(void)
{
return (videoGetAspect() / SCREEN_ASPECT);
Expand Down Expand Up @@ -1536,6 +1582,13 @@ Gfx *sightDraw(Gfx *gdl, bool sighton, s32 sight)
sight = SIGHT_DEFAULT;
}

#ifndef PLATFORM_N64
if (g_Vars.currentplayer->bondhealth <= 0.0f) {
// Hide crosshair during death animation
sight = SIGHT_NONE;
}
#endif

sightTick(sighton);

switch (sight) {
Expand Down
4 changes: 4 additions & 0 deletions src/include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -4718,6 +4718,10 @@ enum weaponnum {
#define CROUCHMODE_TOGGLE 2 // press the crouch buttons to toggle stance
#define CROUCHMODE_TOGGLE_ANALOG (CROUCHMODE_ANALOG | CROUCHMODE_TOGGLE)

#define CROSSHAIR_HEALTH_OFF 0
#define CROSSHAIR_HEALTH_ON_GREEN 1
#define CROSSHAIR_HEALTH_ON_WHITE 2

#endif

#endif
1 change: 1 addition & 0 deletions src/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6144,6 +6144,7 @@ struct extplayerconfig {
s32 extcontrols;
u32 crosshaircolour;
u32 crosshairsize;
s32 crosshairhealth;
};

#endif
Expand Down

0 comments on commit 26d3c39

Please sign in to comment.