diff --git a/src/extras/weaponwheel.cpp b/src/extras/weaponwheel.cpp index b90307d9..5862501c 100644 --- a/src/extras/weaponwheel.cpp +++ b/src/extras/weaponwheel.cpp @@ -75,19 +75,30 @@ enum WHEEL_MAX_RADIO = 12 }; -// Radii as a fraction of screen height so the wheel stays circular and matches -// the 1080p art (wedge outer ~305px, inner ~169px, icons ~246px from centre). -#define WHEEL_OUTER_RADIUS 0.285f -#define WHEEL_INNER_RADIUS 0.155f -#define WHEEL_ICON_RADIUS 0.228f +// Radii as a fraction of screen height, measured from the supplied 1080p art +// (mean alpha-bbox radius of icon0..icon11 = 277.82px; ww0..ww11 inner/outer +// extents = 208.17/340.83px) so procedural fallbacks and the art coincide. +#define WHEEL_OUTER_RADIUS 0.3156f // 340.83 / 1080 +#define WHEEL_INNER_RADIUS 0.1928f // 208.17 / 1080 +#define WHEEL_ICON_RADIUS 0.2572f // 277.82 / 1080 #define WHEEL_ICON_SIZE 0.100f -#define WHEEL_RADIO_TEXT_R 0.220f -#define WHEEL_WEAPON_LABEL_R 0.335f +#define WHEEL_RADIO_TEXT_R 0.2450f +#define WHEEL_WEAPON_LABEL_R 0.355f + +// The supplied art's wheel is not exactly at the 1920x1080 frame centre: the +// mean of the 12 icon alpha-bbox centres is (945.75, 570.67), i.e. this offset +// from (960, 540) in units of art height. Subtracted when placing crops so the +// art wheel centre lands on the screen centre used by the procedural ring. +#define WHEEL_ART_CENTRE_X (-14.25f / 1080.0f) +#define WHEEL_ART_CENTRE_Y ( 30.67f / 1080.0f) #define WHEEL_STICK_DEADZONE 0.35f #define WHEEL_MOUSE_DEADZONE 0.35f #define WHEEL_KEY_DEADZONE 0.50f -#define WHEEL_MOUSE_SENS 0.015f +// Virtual-cursor gain per mouse pixel. Nudge between 0.004 and 0.006. +#define WHEEL_MOUSE_SENSITIVITY 0.005f +// First-order smoothing of the displayed cursor toward the accumulated target. +#define WHEEL_MOUSE_SMOOTHING 0.30f #define WHEEL_CURSOR_CLAMP 1.0f #define WHEEL_ART_WW_PATH "weapon_wheel/ww%d.png" @@ -121,7 +132,8 @@ static int32 ms_nSegments; static int32 ms_nHovered; // -1 means "nothing pointed at" static int32 ms_nCurrentSegment; // segment of the currently equipped entry static bool ms_bSelectionMoved; // radio wheel: player actually cycled -static float ms_fCursorX, ms_fCursorY; +static float ms_fCursorX, ms_fCursorY; // smoothed virtual cursor +static float ms_fMouseTargetX, ms_fMouseTargetY; // accumulated mouse target static bool ms_bCameraWasDisabled; // bit was already set when a weapon wheel opened static bool ms_bOwnCameraBit; // this wheel set PLAYERCONTROL_CAMERA #ifdef IMPROVED_WEAPON_WHEEL_SLOWMO @@ -224,6 +236,23 @@ Wheel_LoadArt(const char *path, float *pOffX, float *pOffY, float *pW, float *pH for (int32 y = 0; y < ch; y++) memcpy(dst + y * dstStride, pixels + (minY + y) * stride + minX * 4, cw * 4); + // Premultiply alpha. The art is straight-alpha RGBA; filtering it as such + // darkens anti-aliased edges (black fringe/jaggies). With premultiplied + // data Wheel_DrawArt blends with ONE/INVSRCALPHA, which is the correct + // filter result for soft edges. + for (int32 y = 0; y < ch; y++) { + uint8 *row = dst + y * dstStride; + for (int32 x = 0; x < cw; x++) { + uint8 *p = row + x * 4; + uint32 a = p[3]; + if (a == 255) + continue; + p[0] = (uint8)((p[0] * a + 127) / 255); + p[1] = (uint8)((p[1] * a + 127) / 255); + p[2] = (uint8)((p[2] * a + 127) / 255); + } + } + // Normalised placement, relative to the art frame's centre. *pOffX = ((minX + cw * 0.5f) - iw * 0.5f) / (float)ih; *pOffY = ((minY + ch * 0.5f) - ih * 0.5f) / (float)ih; @@ -248,6 +277,7 @@ Wheel_LoadArt(const char *path, float *pOffX, float *pOffY, float *pW, float *pH return nil; } RwTextureSetFilterMode(texture, rwFILTERLINEAR); + RwTextureSetAddressing(texture, rwTEXTUREADDRESSCLAMP); CSprite2d *sprite = new CSprite2d; sprite->m_pTexture = texture; @@ -273,6 +303,10 @@ Wheel_LoadArtOnce(void) // The art was authored for 1920x1080, so positions scale with screen height and // are centred on the screen; the wheel therefore stays circular at any aspect. +// The measured wheel-centre offset is subtracted so hand-placed art lands on the +// procedural ring's centre. The textures are alpha-premultiplied by Wheel_LoadArt, +// so draw them with ONE/INVSRCALPHA (correct filtering for soft edges) and put +// the ordinary straight-alpha HUD state back afterwards. static void Wheel_DrawArt(CSprite2d *sprite, float offX, float offY, float w, float h, const CRGBA &color) { @@ -280,12 +314,25 @@ Wheel_DrawArt(CSprite2d *sprite, float offX, float offY, float w, float h, const return; float scale = SCREEN_HEIGHT; - float x = SCREEN_WIDTH * 0.5f + offX * scale; - float y = SCREEN_HEIGHT * 0.5f + offY * scale; + float x = SCREEN_WIDTH * 0.5f + (offX - WHEEL_ART_CENTRE_X) * scale; + float y = SCREEN_HEIGHT * 0.5f + (offY - WHEEL_ART_CENTRE_Y) * scale; float dw = w * scale; float dh = h * scale; + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); + RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void*)rwTEXTUREADDRESSCLAMP); + sprite->Draw(CRect(x - dw * 0.5f, y - dh * 0.5f, x + dw * 0.5f, y + dh * 0.5f), color); + + // Back to the straight-alpha state the rest of the 2D pass expects. + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void*)rwTEXTUREADDRESSWRAP); } // --------------------------------------------------------------------------- @@ -549,6 +596,8 @@ Wheel_Open(bool radio) ms_bSelectionMoved = false; ms_fCursorX = 0.0f; ms_fCursorY = 0.0f; + ms_fMouseTargetX = 0.0f; + ms_fMouseTargetY = 0.0f; if (radio) { Wheel_BuildRadioList(); @@ -702,14 +751,18 @@ Wheel_UpdateInput(void) bestMag = mag; } - // Mouse: only deltas are available, so integrate them into a virtual - // direction while the wheel is held. - ms_fCursorX += pad->GetMouseX() * WHEEL_MOUSE_SENS; - ms_fCursorY += pad->GetMouseY() * WHEEL_MOUSE_SENS; - if (ms_fCursorX < -WHEEL_CURSOR_CLAMP) ms_fCursorX = -WHEEL_CURSOR_CLAMP; - if (ms_fCursorX > WHEEL_CURSOR_CLAMP) ms_fCursorX = WHEEL_CURSOR_CLAMP; - if (ms_fCursorY < -WHEEL_CURSOR_CLAMP) ms_fCursorY = -WHEEL_CURSOR_CLAMP; - if (ms_fCursorY > WHEEL_CURSOR_CLAMP) ms_fCursorY = WHEEL_CURSOR_CLAMP; + // Mouse: only deltas are available. Accumulate a virtual cursor target at a + // low gain, then lerp the displayed cursor toward it so pointing is smooth + // rather than twitchy (playtest issue #31). + ms_fMouseTargetX += pad->GetMouseX() * WHEEL_MOUSE_SENSITIVITY; + ms_fMouseTargetY += pad->GetMouseY() * WHEEL_MOUSE_SENSITIVITY; + if (ms_fMouseTargetX < -WHEEL_CURSOR_CLAMP) ms_fMouseTargetX = -WHEEL_CURSOR_CLAMP; + if (ms_fMouseTargetX > WHEEL_CURSOR_CLAMP) ms_fMouseTargetX = WHEEL_CURSOR_CLAMP; + if (ms_fMouseTargetY < -WHEEL_CURSOR_CLAMP) ms_fMouseTargetY = -WHEEL_CURSOR_CLAMP; + if (ms_fMouseTargetY > WHEEL_CURSOR_CLAMP) ms_fMouseTargetY = WHEEL_CURSOR_CLAMP; + + ms_fCursorX += (ms_fMouseTargetX - ms_fCursorX) * WHEEL_MOUSE_SMOOTHING; + ms_fCursorY += (ms_fMouseTargetY - ms_fCursorY) * WHEEL_MOUSE_SMOOTHING; mag = Sqrt(ms_fCursorX * ms_fCursorX + ms_fCursorY * ms_fCursorY); if (mag > bestMag && mag >= WHEEL_MOUSE_DEADZONE) { @@ -794,14 +847,54 @@ Wheel_Process(void) Wheel_UpdateInput(); } +static void +Wheel_DrawRingQuad(float a0, float a1, float r0, float r1, const CRGBA &color) +{ + float cx = SCREEN_WIDTH * 0.5f; + float cy = SCREEN_HEIGHT * 0.5f; + + CSprite2d::Draw2DPolygon( + cx + r0 * Cos(a0), cy - r0 * Sin(a0), + cx + r1 * Cos(a0), cy - r1 * Sin(a0), + cx + r1 * Cos(a1), cy - r1 * Sin(a1), + cx + r0 * Cos(a1), cy - r0 * Sin(a1), + color); +} + +static void +Wheel_DrawRingOutline(int32 segment) +{ + if (ms_nSegments <= 0 || segment < 0 || segment >= ms_nSegments) + return; + + float outer = SCREEN_HEIGHT * WHEEL_OUTER_RADIUS; + float inner = SCREEN_HEIGHT * WHEEL_INNER_RADIUS; + float step = TWOPI / ms_nSegments; + float center = HALFPI - segment * step; + float half = step * 0.5f; + float band = SCREEN_HEIGHT * 0.004f; // ~4px at 1080p + float edge = step * 0.035f; // thin radial border, ~1 degree + CRGBA color(255, 245, 210, 245); + + // Inner/outer rim of the selected sector. + for (int32 k = 0; k < WHEEL_ARC_STEPS; k++) { + float aa = center + half + (-2.0f * half) * (k / (float)WHEEL_ARC_STEPS); + float ab = center + half + (-2.0f * half) * ((k + 1) / (float)WHEEL_ARC_STEPS); + Wheel_DrawRingQuad(aa, ab, outer - band, outer, color); + Wheel_DrawRingQuad(aa, ab, inner, inner + band, color); + } + + // Radial borders. + Wheel_DrawRingQuad(center + half - edge, center + half + edge, inner, outer, color); + Wheel_DrawRingQuad(center - half - edge, center - half + edge, inner, outer, color); +} + static void Wheel_DrawRing(void) { if (ms_nSegments <= 0) return; - float cx = SCREEN_WIDTH * 0.5f; - float cy = SCREEN_HEIGHT * 0.5f; float outer = SCREEN_HEIGHT * WHEEL_OUTER_RADIUS; float inner = SCREEN_HEIGHT * WHEEL_INNER_RADIUS; float step = TWOPI / ms_nSegments; @@ -815,9 +908,9 @@ Wheel_DrawRing(void) CRGBA color; if (!available) - color = CRGBA(10, 10, 10, 80); + color = CRGBA(10, 10, 10, 70); else if (i == highlight) - color = CRGBA(90, 90, 90, 200); + color = CRGBA(235, 200, 120, 225); else color = CRGBA(18, 18, 18, 150); @@ -828,13 +921,7 @@ Wheel_DrawRing(void) for (int32 k = 0; k < WHEEL_ARC_STEPS; k++) { float aa = a0 + (a1 - a0) * (k / (float)WHEEL_ARC_STEPS); float ab = a0 + (a1 - a0) * ((k + 1) / (float)WHEEL_ARC_STEPS); - - CSprite2d::Draw2DPolygon( - cx + inner * Cos(aa), cy - inner * Sin(aa), - cx + outer * Cos(aa), cy - outer * Sin(aa), - cx + outer * Cos(ab), cy - outer * Sin(ab), - cx + inner * Cos(ab), cy - inner * Sin(ab), - color); + Wheel_DrawRingQuad(aa, ab, inner, outer, color); } } } @@ -893,23 +980,28 @@ Wheel_DrawWeaponIcons(void) for (int32 i = 0; i < ms_nSegments; i++) { int32 weapon = player != nil ? Wheel_SelectedWeapon(player, i) : -1; bool available = weapon >= 0; - uint8 alpha = available ? 255 : 60; + bool selected = (i == ms_nHovered); + float iconScale = selected ? 1.18f : 1.0f; + uint8 alpha = available ? (selected ? 255 : 150) : 40; // Prefer the art glyph; fall back to the game's HUD weapon sprite. if (ms_apIconArt[i] != nil) { Wheel_DrawArt(ms_apIconArt[i], ms_aIconOffX[i], ms_aIconOffY[i], - ms_aIconW[i], ms_aIconH[i], CRGBA(255, 255, 255, alpha)); + ms_aIconW[i] * iconScale, ms_aIconH[i] * iconScale, + CRGBA(255, 255, 255, alpha)); } else { float angle = HALFPI - i * step; float x = cx + radius * Cos(angle); float y = cy - radius * Sin(angle); + float s = size * iconScale; CHud::Sprites[i].Draw( - CRect(x - size * 0.5f, y - size * 0.5f, x + size * 0.5f, y + size * 0.5f), + CRect(x - s * 0.5f, y - s * 0.5f, x + s * 0.5f, y + s * 0.5f), CRGBA(255, 255, 255, alpha)); // In procedural mode the sprite alone is not always legible, so // label each segment. Art mode carries readable glyphs already. - Wheel_DrawSegmentLabel(i, ms_aWeaponShort[i], WHEEL_WEAPON_LABEL_R, CRGBA(200, 200, 200, alpha)); + Wheel_DrawSegmentLabel(i, ms_aWeaponShort[i], WHEEL_WEAPON_LABEL_R, + CRGBA(200, 200, 200, selected ? 255 : 170)); } } } @@ -948,6 +1040,7 @@ Wheel_Draw(void) // Dim the game/HUD underneath, then the shared ring. CSprite2d::DrawRect(CRect(0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT), CRGBA(0, 0, 0, 140)); Wheel_DrawRing(); + Wheel_DrawRingOutline(highlight); // Draw2DPolygon restores depth states to ON; the 2D pass wants them off. RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE);