Skip to content

Commit

Permalink
Replaces uses of doubles with floats
Browse files Browse the repository at this point in the history
Looks like the KallistiOS Dreamcast SDK disables double support
by default: https://github.com/KallistiOS/KallistiOS/blob/495e77fd60d5b09a1ad52a26cd4a7e73cd0d9d51/environ_dreamcast.sh#L16

We don't really need doubles in this code.

The one place where we might have needed them is the SMK video
decoder, handled in a separate PR.
  • Loading branch information
glebm committed Oct 3, 2024
1 parent 1078598 commit a8faa7c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
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 @@ VirtualGamepad VirtualGamepadState;

namespace {

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

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

View workflow job for this annotation

GitHub Actions / build

'initializing': truncation from 'double' to 'const float'

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 Down Expand Up @@ -227,14 +227,14 @@ void VirtualDirectionPad::UpdatePosition(Point touchCoordinates)
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

0 comments on commit a8faa7c

Please sign in to comment.