Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces uses of doubles with floats #7455

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions Source/controls/touch/gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,40 @@

namespace {

constexpr double Pi = 3.141592653589793;
constexpr float Pi = 3.141592653589793F;

int roundToInt(double value)
int roundToInt(float value)
{
return static_cast<int>(round(value));
}

constexpr bool PointsUp(double angle)
constexpr bool PointsUp(float angle)
{
constexpr double UpAngle = Pi / 2;
constexpr double MinAngle = UpAngle - 3 * Pi / 8;
constexpr double MaxAngle = UpAngle + 3 * Pi / 8;
constexpr float UpAngle = Pi / 2;
constexpr float MinAngle = UpAngle - 3 * Pi / 8;
constexpr float MaxAngle = UpAngle + 3 * Pi / 8;
return MinAngle <= angle && angle <= MaxAngle;
}

constexpr bool PointsDown(double angle)
constexpr bool PointsDown(float angle)
{
constexpr double DownAngle = -Pi / 2;
constexpr double MinAngle = DownAngle - 3 * Pi / 8;
constexpr double MaxAngle = DownAngle + 3 * Pi / 8;
constexpr float DownAngle = -Pi / 2;
constexpr float MinAngle = DownAngle - 3 * Pi / 8;
constexpr float MaxAngle = DownAngle + 3 * Pi / 8;
return MinAngle <= angle && angle <= MaxAngle;
}

constexpr bool PointsLeft(double angle)
constexpr bool PointsLeft(float angle)
{
constexpr double MaxAngle = Pi - 3 * Pi / 8;
constexpr double MinAngle = -Pi + 3 * Pi / 8;
constexpr float MaxAngle = Pi - 3 * Pi / 8;
constexpr float MinAngle = -Pi + 3 * Pi / 8;
return !(MinAngle < angle && angle < MaxAngle);
}

constexpr bool PointsRight(double angle)
constexpr bool PointsRight(float angle)
{
constexpr double MinAngle = -3 * Pi / 8;
constexpr double MaxAngle = 3 * Pi / 8;
constexpr float MinAngle = -3 * Pi / 8;
constexpr float MaxAngle = 3 * Pi / 8;
return MinAngle <= angle && angle <= MaxAngle;
}

Expand All @@ -57,7 +57,7 @@
int inputMargin = screenPixels / 10;
int menuButtonWidth = screenPixels / 10;
int directionPadSize = screenPixels / 4;
int padButtonSize = roundToInt(1.1 * screenPixels / 10);

Check warning on line 60 in Source/controls/touch/gamepad.cpp

View workflow job for this annotation

GitHub Actions / build

'argument': conversion from 'double' to 'float', possible loss of data
int padButtonSpacing = inputMargin / 3;

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

float dpi = std::min(hdpi, vdpi);
inputMargin = roundToInt(0.25 * dpi);

Check warning on line 78 in Source/controls/touch/gamepad.cpp

View workflow job for this annotation

GitHub Actions / build

'argument': conversion from 'double' to 'float', possible loss of data
menuButtonWidth = roundToInt(0.2 * dpi);

Check warning on line 79 in Source/controls/touch/gamepad.cpp

View workflow job for this annotation

GitHub Actions / build

'argument': conversion from 'double' to 'float', possible loss of data
directionPadSize = roundToInt(dpi);
padButtonSize = roundToInt(0.3 * dpi);

Check warning on line 81 in Source/controls/touch/gamepad.cpp

View workflow job for this annotation

GitHub Actions / build

'argument': conversion from 'double' to 'float', possible loss of data
padButtonSpacing = roundToInt(0.1 * dpi);

Check warning on line 82 in Source/controls/touch/gamepad.cpp

View workflow job for this annotation

GitHub Actions / build

'argument': conversion from 'double' to 'float', possible loss of data
}

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

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

Check warning on line 93 in Source/controls/touch/gamepad.cpp

View workflow job for this annotation

GitHub Actions / build

'argument': conversion from 'double' to 'float', possible loss of data

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

int standButtonDiagonalOffset = directionPadArea.radius + padButtonSpacing / 2 + padButtonSize / 2;
int standButtonOffset = roundToInt(standButtonDiagonalOffset / std::sqrt(2));

Check warning on line 138 in Source/controls/touch/gamepad.cpp

View workflow job for this annotation

GitHub Actions / build

'argument': conversion from 'double' to 'float', possible loss of data
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 +227,14 @@
if (!area.contains(position)) {
int x = diff.deltaX;
int y = diff.deltaY;
double dist = sqrt(x * x + y * y);
float dist = sqrt(x * x + y * y);

Check warning on line 230 in Source/controls/touch/gamepad.cpp

View workflow job for this annotation

GitHub Actions / build

'initializing': conversion from 'double' to 'float', possible loss of data
x = roundToInt(x * area.radius / dist);
y = roundToInt(y * area.radius / dist);
position.x = area.position.x + x;
position.y = area.position.y + y;
}

double angle = atan2(-diff.deltaY, diff.deltaX);
float angle = atan2(-diff.deltaY, diff.deltaX);

Check warning on line 237 in Source/controls/touch/gamepad.cpp

View workflow job for this annotation

GitHub Actions / build

'initializing': conversion from 'double' to 'float', possible loss of data

isUpPressed = PointsUp(angle);
isDownPressed = PointsDown(angle);
Expand Down
8 changes: 4 additions & 4 deletions Source/engine/palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ void palette_update(int first, int ncolor)

void ApplyGamma(std::array<SDL_Color, 256> &dst, const std::array<SDL_Color, 256> &src, int n)
{
double g = *sgOptions.Graphics.gammaCorrection / 100.0;
float g = *sgOptions.Graphics.gammaCorrection / 100.0F;

for (int i = 0; i < n; i++) {
dst[i].r = static_cast<Uint8>(pow(src[i].r / 256.0, g) * 256.0);
dst[i].g = static_cast<Uint8>(pow(src[i].g / 256.0, g) * 256.0);
dst[i].b = static_cast<Uint8>(pow(src[i].b / 256.0, g) * 256.0);
dst[i].r = static_cast<Uint8>(pow(src[i].r / 256.0F, g) * 256.0F);
dst[i].g = static_cast<Uint8>(pow(src[i].g / 256.0F, g) * 256.0F);
dst[i].b = static_cast<Uint8>(pow(src[i].b / 256.0F, g) * 256.0F);
}
RedrawEverything();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ void DiabloDeath(Monster &diablo, bool sendmsg)
dist = 20;
diablo.var3 = ViewPosition.x << 16;
diablo.position.temp.x = ViewPosition.y << 16;
diablo.position.temp.y = (int)((diablo.var3 - (diablo.position.tile.x << 16)) / (double)dist);
diablo.position.temp.y = (int)((diablo.var3 - (diablo.position.tile.x << 16)) / (float)dist);
if (!gbIsMultiplayer) {
Player &myPlayer = *MyPlayer;
myPlayer.pDiabloKillLevel = std::max(myPlayer.pDiabloKillLevel, static_cast<uint8_t>(sgGameInitInfo.nDifficulty + 1));
Expand Down
10 changes: 5 additions & 5 deletions Source/utils/sdl2_to_1_2_backports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@ int SDL_BlitScaled(SDL_Surface *src, SDL_Rect *srcrect,
return SDL_BlitSurface(src, srcrect, dst, dstrect);
}

double src_x0, src_y0, src_x1, src_y1;
double dst_x0, dst_y0, dst_x1, dst_y1;
float src_x0, src_y0, src_x1, src_y1;
float dst_x0, dst_y0, dst_x1, dst_y1;
SDL_Rect final_src, final_dst;
double scaling_w, scaling_h;
float scaling_w, scaling_h;
int src_w, src_h;
int dst_w, dst_h;

Expand Down Expand Up @@ -379,8 +379,8 @@ int SDL_BlitScaled(SDL_Surface *src, SDL_Rect *srcrect,
return SDL_BlitSurface(src, srcrect, dst, dstrect);
}

scaling_w = (double)dst_w / src_w;
scaling_h = (double)dst_h / src_h;
scaling_w = (float)dst_w / src_w;
scaling_h = (float)dst_h / src_h;

if (NULL == dstrect) {
dst_x0 = 0;
Expand Down
Loading