Skip to content

Commit

Permalink
Fix double to float conversion warnings in virtual gamepad logic
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenCWills committed Oct 11, 2024
1 parent 1812479 commit 0398145
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Source/controls/touch/gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ constexpr bool PointsRight(float angle)

void InitializeVirtualGamepad()
{
const float sqrt2 = std::sqrtf(2);

int screenPixels = std::min(gnScreenWidth, gnScreenHeight);
int inputMargin = screenPixels / 10;
int menuButtonWidth = screenPixels / 10;
int directionPadSize = screenPixels / 4;
int padButtonSize = roundToInt(1.1 * screenPixels / 10);
int padButtonSize = roundToInt(1.1f * screenPixels / 10);
int padButtonSpacing = inputMargin / 3;

float hdpi;
Expand All @@ -75,11 +77,11 @@ void InitializeVirtualGamepad()
vdpi *= static_cast<float>(gnScreenHeight) / clientHeight;

float dpi = std::min(hdpi, vdpi);
inputMargin = roundToInt(0.25 * dpi);
menuButtonWidth = roundToInt(0.2 * dpi);
inputMargin = roundToInt(0.25f * dpi);
menuButtonWidth = roundToInt(0.2f * dpi);
directionPadSize = roundToInt(dpi);
padButtonSize = roundToInt(0.3 * dpi);
padButtonSpacing = roundToInt(0.1 * dpi);
padButtonSize = roundToInt(0.3f * dpi);
padButtonSpacing = roundToInt(0.1f * dpi);
}

int menuPanelTopMargin = 30;
Expand All @@ -90,7 +92,7 @@ void InitializeVirtualGamepad()
int rightMarginMenuButton2 = rightMarginMenuButton3 + menuPanelButtonSpacing + menuPanelButtonSize.width;
int rightMarginMenuButton1 = rightMarginMenuButton2 + menuPanelButtonSpacing + menuPanelButtonSize.width;

int padButtonAreaWidth = roundToInt(std::sqrt(2) * (padButtonSize + padButtonSpacing));
int padButtonAreaWidth = roundToInt(sqrt2 * (padButtonSize + padButtonSpacing));

int padButtonRight = gnScreenWidth - inputMargin - padButtonSize / 2;
int padButtonLeft = padButtonRight - padButtonAreaWidth;
Expand Down Expand Up @@ -135,7 +137,7 @@ void InitializeVirtualGamepad()
directionPad.position = directionPadArea.position;

int standButtonDiagonalOffset = directionPadArea.radius + padButtonSpacing / 2 + padButtonSize / 2;
int standButtonOffset = roundToInt(standButtonDiagonalOffset / std::sqrt(2));
int standButtonOffset = roundToInt(standButtonDiagonalOffset / sqrt2);
Circle &standButtonArea = VirtualGamepadState.standButton.area;
standButtonArea.position.x = directionPadArea.position.x - standButtonOffset;
standButtonArea.position.y = directionPadArea.position.y + standButtonOffset;
Expand Down Expand Up @@ -227,14 +229,14 @@ void VirtualDirectionPad::UpdatePosition(Point touchCoordinates)
if (!area.contains(position)) {
int x = diff.deltaX;
int y = diff.deltaY;
float dist = sqrt(x * x + y * y);
float dist = std::sqrtf(static_cast<float>(x * x + y * y));
x = roundToInt(x * area.radius / dist);
y = roundToInt(y * area.radius / dist);
position.x = area.position.x + x;
position.y = area.position.y + y;
}

float angle = atan2(-diff.deltaY, diff.deltaX);
float angle = std::atan2f(static_cast<float>(-diff.deltaY), static_cast<float>(diff.deltaX));

isUpPressed = PointsUp(angle);
isDownPressed = PointsDown(angle);
Expand Down

0 comments on commit 0398145

Please sign in to comment.