Skip to content

Commit

Permalink
port: fix crosshair aspect and make sights centered 4:3
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsfdsfgs committed Dec 2, 2023
1 parent ef83f23 commit 2b8d5d4
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
86 changes: 84 additions & 2 deletions src/game/sight.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@
#include "lib/snd.h"
#include "data.h"
#include "types.h"
#ifndef PLATFORM_N64
#include <math.h>
#include "video.h"

static inline f32 sightGetScaleX(void)
{
return (videoGetAspect() / (4.f / 3.f));
}

static inline s32 sightGetAdjustedX(const f32 x)
{
const f32 cx = (x - (f32)(SCREEN_WIDTH_LO / 2)) * sightGetScaleX();
return roundf((f32)(SCREEN_WIDTH_LO / 2) + cx);
}

#else

#define sightGetScaleX() 1.f
#define sightGetAdjustedX(x) (x)

#endif

/**
* Return true if the prop is considered friendly (blue sight).
Expand Down Expand Up @@ -440,6 +461,11 @@ Gfx *sightDrawAimer(Gfx *gdl, s32 x, s32 y, s32 radius, s32 cornergap, u32 colou

gdl = textSetPrimColour(gdl, 0x00ff0028);

#ifndef PLATFORM_N64
x = sightGetAdjustedX(x);
gSPSetExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT);
#endif

// Draw the lines that span most of the viewport
if (PLAYERCOUNT() == 1) {
gDPHudRectangle(gdl++, viewleft + 48, y, x - radius + 2, y);
Expand Down Expand Up @@ -472,6 +498,10 @@ Gfx *sightDrawAimer(Gfx *gdl, s32 x, s32 y, s32 radius, s32 cornergap, u32 colou
gDPHudRectangle(gdl++, x - radius, y + radius, x - cornergap, y + radius);
gDPHudRectangle(gdl++, x + cornergap, y + radius, x + radius, y + radius);

#ifndef PLATFORM_N64
gSPClearExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT);
#endif

gdl = text0f153838(gdl);

return gdl;
Expand Down Expand Up @@ -506,6 +536,11 @@ Gfx *sightDrawDelayedAimer(Gfx *gdl, s32 x, s32 y, s32 radius, s32 cornergap, u3
static f32 xspeed = 0;
static f32 yspeed = 0;

#ifndef PLATFORM_N64
x = sightGetAdjustedX(x);
gSPSetExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT);
#endif

for (i = 0; i < g_Vars.lvupdate60; i++) {
dist = x - xpos;

Expand Down Expand Up @@ -613,6 +648,10 @@ Gfx *sightDrawDelayedAimer(Gfx *gdl, s32 x, s32 y, s32 radius, s32 cornergap, u3

gdl = text0f153838(gdl);

#ifndef PLATFORM_N64
gSPClearExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT);
#endif

return gdl;
}

Expand Down Expand Up @@ -817,7 +856,7 @@ Gfx *sightDrawClassic(Gfx *gdl, bool sighton)
struct textureconfig *tconfig = &g_TexGeCrosshairConfigs[0];
f32 spc4[2];
f32 spbc[2];
s32 x = g_Vars.currentplayer->crosspos[0];
s32 x = sightGetAdjustedX(g_Vars.currentplayer->crosspos[0]);
s32 y = g_Vars.currentplayer->crosspos[1];
s32 x1;
s32 x2;
Expand All @@ -828,6 +867,10 @@ Gfx *sightDrawClassic(Gfx *gdl, bool sighton)
return gdl;
}

#ifndef PLATFORM_N64
gSPSetExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT);
#endif

gDPSetColorDither(gdl++, G_CD_DISABLE);
gDPSetTexturePersp(gdl++, G_TP_NONE);
gDPSetAlphaCompare(gdl++, G_AC_NONE);
Expand Down Expand Up @@ -868,6 +911,10 @@ Gfx *sightDrawClassic(Gfx *gdl, bool sighton)
gDPSetTextureConvert(gdl++, G_TC_FILT);
gDPSetTextureLUT(gdl++, G_TT_NONE);

#ifndef PLATFORM_N64
gSPClearExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT);
#endif

return gdl;
}

Expand Down Expand Up @@ -992,6 +1039,11 @@ Gfx *sightDrawSkedar(Gfx *gdl, bool sighton)
g_Vars.currentplayer->sighttimer240 = 0;
}

#ifndef PLATFORM_N64
x = sightGetAdjustedX(x);
gSPSetExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT);
#endif

gdl = func0f0d479c(gdl);

gSPClearGeometryMode(gdl++, G_CULL_BOTH);
Expand Down Expand Up @@ -1144,6 +1196,10 @@ Gfx *sightDrawSkedar(Gfx *gdl, bool sighton)

gdl = func0f0d49c8(gdl);

#ifndef PLATFORM_N64
gSPClearExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT);
#endif

return gdl;
}

Expand Down Expand Up @@ -1240,6 +1296,10 @@ Gfx *sightDrawZoom(Gfx *gdl, bool sighton)
cornerheight = BOXBOTTOM - BOXTOP;
}

#ifndef PLATFORM_N64
gSPSetExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT);
#endif

// Top left
gDPHudRectangle(gdl++, BOXLEFT + 1, BOXTOP, BOXLEFT + cornerwidth - 1, BOXTOP);
gDPHudRectangle(gdl++, BOXLEFT, BOXTOP, BOXLEFT, BOXTOP + cornerheight - 1);
Expand Down Expand Up @@ -1276,6 +1336,11 @@ Gfx *sightDrawZoom(Gfx *gdl, bool sighton)
gDPHudRectangle(gdl++, BOXRIGHT - cornerwidth, BOXBOTTOM, BOXRIGHT, BOXBOTTOM);
gDPHudRectangle(gdl++, BOXRIGHT, BOXBOTTOM - cornerheight, BOXRIGHT, BOXBOTTOM);


#ifndef PLATFORM_N64
gSPClearExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT);
#endif

gdl = text0f153838(gdl);
gdl = text0f153780(gdl);
}
Expand Down Expand Up @@ -1309,6 +1374,11 @@ Gfx *sightDrawMaian(Gfx *gdl, bool sighton)
colour = 0x0000ff60;
}

#ifndef PLATFORM_N64
x = sightGetAdjustedX(x);
gSPSetExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT);
#endif

vertices = gfxAllocateVertices(8);
colours = gfxAllocateColours(2);
gdl = func0f0d479c(gdl);
Expand Down Expand Up @@ -1379,12 +1449,16 @@ Gfx *sightDrawMaian(Gfx *gdl, bool sighton)

gdl = text0f153838(gdl);

#ifndef PLATFORM_N64
gSPClearExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT);
#endif

return gdl;
}

Gfx *sightDrawTarget(Gfx *gdl)
{
s32 x = (s32)g_Vars.currentplayer->crosspos[0] / g_ScaleX;
s32 x = sightGetAdjustedX((s32)g_Vars.currentplayer->crosspos[0] / g_ScaleX);
s32 y = g_Vars.currentplayer->crosspos[1];

static u32 var80070f9c = 0x00ff00ff;
Expand All @@ -1395,6 +1469,10 @@ Gfx *sightDrawTarget(Gfx *gdl)

gdl = textSetPrimColour(gdl, 0x00ff0028);

#ifndef PLATFORM_N64
gSPSetExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT);
#endif

gDPHudRectangle(gdl++, x + 2, y + 0, x + 6, y + 0);
gDPHudRectangle(gdl++, x + 2, y + 0, x + 4, y + 0);
gDPHudRectangle(gdl++, x - 6, y + 0, x - 2, y + 0);
Expand All @@ -1404,6 +1482,10 @@ Gfx *sightDrawTarget(Gfx *gdl)
gDPHudRectangle(gdl++, x + 0, y - 6, x + 0, y - 2);
gDPHudRectangle(gdl++, x + 0, y - 4, x + 0, y - 2);

#ifndef PLATFORM_N64
gSPClearExtraGeometryModeEXT(gdl++, G_ASPECT_CENTER_EXT);
#endif

gdl = text0f153838(gdl);

return gdl;
Expand Down
3 changes: 3 additions & 0 deletions src/include/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include_next <math.h>
#undef M_PI
#undef M_TAU
// HACK: for some reason the #include_next above doesn't really do anything, so
float fabsf(float x);
float roundf(float x);
#endif

// @bug?
Expand Down

0 comments on commit 2b8d5d4

Please sign in to comment.