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

Use float literals where applicable, fix -Wdouble-promotion #1210

Merged
merged 1 commit into from
Aug 14, 2023
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
4 changes: 2 additions & 2 deletions src/client/animatedtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void AnimatedText::drawText(const Point& dest, const Rect& visibleRect)

if(visibleRect.contains(rect)) {
//TODO: cache into a framebuffer
float t0 = tf / 1.2;
float t0 = tf / 1.2f;
if(t > t0) {
Color color = m_color;
color.setAlpha((float)(1 - (t - t0) / (tf - t0)));
Expand Down Expand Up @@ -92,7 +92,7 @@ bool AnimatedText::merge(const AnimatedTextPtr& other)
if(other->getCachedText().getFont() != m_cachedText.getFont())
return false;

if(m_animationTimer.ticksElapsed() > Otc::ANIMATED_TEXT_DURATION / 2.5)
if(m_animationTimer.ticksElapsed() > Otc::ANIMATED_TEXT_DURATION / 2.5f)
return false;

try {
Expand Down
2 changes: 1 addition & 1 deletion src/client/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos)
if(prevAnimatedText) {
Point offset = prevAnimatedText->getOffset();
float t = prevAnimatedText->getTimer().ticksElapsed();
if(t < Otc::ANIMATED_TEXT_DURATION / 4.0) { // didnt move 12 pixels
if(t < Otc::ANIMATED_TEXT_DURATION / 4.f) { // didnt move 12 pixels
int y = 12 - 48 * t / (float)Otc::ANIMATED_TEXT_DURATION;
offset += Point(0, y);
}
Expand Down
40 changes: 20 additions & 20 deletions src/client/outfit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,38 @@ Color Outfit::getColor(int color)

float loc1 = 0, loc2 = 0, loc3 = 0;
if(color % HSI_H_STEPS != 0) {
loc1 = color % HSI_H_STEPS * 1.0/18.0;
loc1 = color % HSI_H_STEPS * 1.f/18.f;
loc2 = 1;
loc3 = 1;

switch(int(color / HSI_H_STEPS)) {
case 0:
loc2 = 0.25;
loc3 = 1.00;
loc2 = 0.25f;
loc3 = 1.f;
break;
case 1:
loc2 = 0.25;
loc3 = 0.75;
loc2 = 0.25f;
loc3 = 0.75f;
break;
case 2:
loc2 = 0.50;
loc3 = 0.75;
loc2 = 0.5f;
loc3 = 0.75f;
break;
case 3:
loc2 = 0.667;
loc3 = 0.75;
loc2 = 0.667f;
loc3 = 0.75f;
break;
case 4:
loc2 = 1.00;
loc3 = 1.00;
loc2 = 1.f;
loc3 = 1.f;
break;
case 5:
loc2 = 1.00;
loc3 = 0.75;
loc2 = 1.f;
loc3 = 0.75f;
break;
case 6:
loc2 = 1.00;
loc3 = 0.50;
loc2 = 1.f;
loc3 = 0.5f;
break;
}
}
Expand All @@ -88,27 +88,27 @@ Color Outfit::getColor(int color)

float red = 0, green = 0, blue = 0;

if(loc1 < 1.0/6.0) {
if(loc1 < 1.f/6.f) {
red = loc3;
blue = loc3 * (1 - loc2);
green = blue + (loc3 - blue) * 6 * loc1;
}
else if(loc1 < 2.0/6.0) {
else if(loc1 < 2.f/6.f) {
green = loc3;
blue = loc3 * (1 - loc2);
red = green - (loc3 - blue) * (6 * loc1 - 1);
}
else if(loc1 < 3.0/6.0) {
else if(loc1 < 3.f/6.f) {
green = loc3;
red = loc3 * (1 - loc2);
blue = red + (loc3 - red) * (6 * loc1 - 2);
}
else if(loc1 < 4.0/6.0) {
else if(loc1 < 4.f/6.f) {
blue = loc3;
red = loc3 * (1 - loc2);
green = blue - (loc3 - red) * (6 * loc1 - 3);
}
else if(loc1 < 5.0/6.0) {
else if(loc1 < 5.f/6.f) {
blue = loc3;
green = loc3 * (1 - loc2);
red = green + (loc3 - green) * (6 * loc1 - 4);
Expand Down
4 changes: 2 additions & 2 deletions src/client/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class Position
return positions;
}

static double getAngleFromPositions(const Position& fromPos, const Position& toPos) {
static float getAngleFromPositions(const Position& fromPos, const Position& toPos) {
// Returns angle in radians from 0 to 2Pi. -1 means positions are equal.
int dx = toPos.x - fromPos.x;
int dy = toPos.y - fromPos.y;
Expand All @@ -145,7 +145,7 @@ class Position
return angle;
}

double getAngleFromPosition(const Position& position) const {
float getAngleFromPosition(const Position& position) const {
return getAngleFromPositions(*this, position);
}

Expand Down
20 changes: 10 additions & 10 deletions src/client/uiprogressrect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,36 @@ void UIProgressRect::drawSelf(Fw::DrawPane drawPane)

// 0% - 12.5% (12.5)
// triangle from top center, to top right (var x)
if(m_percent < 12.5) {
Point var = Point(std::max<int>(m_percent - 0.0, 0.0) * (drawRect.right() - drawRect.horizontalCenter()) / 12.5, 0);
if(m_percent < 12.5f) {
Point var = Point(std::max<int>(m_percent - 0.f, 0.f) * (drawRect.right() - drawRect.horizontalCenter()) / 12.5f, 0);
g_painter->drawFilledTriangle(drawRect.center(), drawRect.topRight() + Point(1,0), drawRect.topCenter() + var);
}

// 12.5% - 37.5% (25)
// triangle from top right to bottom right (var y)
if(m_percent < 37.5) {
Point var = Point(0, std::max<int>(m_percent - 12.5, 0.0) * (drawRect.bottom() - drawRect.top()) / 25.0);
if(m_percent < 37.5f) {
Point var = Point(0, std::max<int>(m_percent - 12.5f, 0.f) * (drawRect.bottom() - drawRect.top()) / 25.f);
g_painter->drawFilledTriangle(drawRect.center(), drawRect.bottomRight() + Point(1,1), drawRect.topRight() + var + Point(1,0));
}

// 37.5% - 62.5% (25)
// triangle from bottom right to bottom left (var x)
if(m_percent < 62.5) {
Point var = Point(std::max<int>(m_percent - 37.5, 0.0) * (drawRect.right() - drawRect.left()) / 25.0, 0);
if(m_percent < 62.5f) {
Point var = Point(std::max<int>(m_percent - 37.5f, 0.f) * (drawRect.right() - drawRect.left()) / 25.f, 0);
g_painter->drawFilledTriangle(drawRect.center(), drawRect.bottomLeft() + Point(0,1), drawRect.bottomRight() - var + Point(1,1));
}

// 62.5% - 87.5% (25)
// triangle from bottom left to top left
if(m_percent < 87.5) {
Point var = Point(0, std::max<int>(m_percent - 62.5, 0.0) * (drawRect.bottom() - drawRect.top()) / 25.0);
if(m_percent < 87.5f) {
Point var = Point(0, std::max<int>(m_percent - 62.5f, 0.f) * (drawRect.bottom() - drawRect.top()) / 25.f);
g_painter->drawFilledTriangle(drawRect.center(), drawRect.topLeft(), drawRect.bottomLeft() - var + Point(0,1));
}

// 87.5% - 100% (12.5)
// triangle from top left to top center
if(m_percent < 100) {
Point var = Point(std::max<int>(m_percent - 87.5, 0.0) * (drawRect.horizontalCenter() - drawRect.left()) / 12.5, 0);
Point var = Point(std::max<int>(m_percent - 87.5f, 0.f) * (drawRect.horizontalCenter() - drawRect.left()) / 12.5f, 0);
g_painter->drawFilledTriangle(drawRect.center(), drawRect.topCenter(), drawRect.topLeft() + var);
}

Expand All @@ -84,7 +84,7 @@ void UIProgressRect::drawSelf(Fw::DrawPane drawPane)

void UIProgressRect::setPercent(float percent)
{
m_percent = stdext::clamp<float>((double)percent, 0.0, 100.0);
m_percent = stdext::clamp<float>(percent, 0.f, 100.f);
}

void UIProgressRect::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
Expand Down
2 changes: 1 addition & 1 deletion src/framework/ui/uiwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void UIWidget::draw(const Rect& visibleRect, Fw::DrawPane drawPane)

if(m_rotation != 0.0f) {
g_painter->pushTransformMatrix();
g_painter->rotate(m_rect.center(), m_rotation * (Fw::pi / 180.0));
g_painter->rotate(m_rect.center(), m_rotation * (Fw::pi / 180.f));
}

drawSelf(drawPane);
Expand Down
Loading