From 384249c31afd14b7ab83bd846180b65a0240611d Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Tue, 14 Jul 2015 18:20:31 +0200 Subject: [PATCH] Unify float literals to use f suffix and avoid double promotions I might have missed some. --- src/al-util.h | 2 +- src/alstream.cpp | 8 ++++---- src/audio.cpp | 6 +++--- src/audiostream.cpp | 22 +++++++++++----------- src/bitmap.cpp | 24 ++++++++++++------------ src/etc-internal.h | 6 +++--- src/font.cpp | 2 +- src/graphics.cpp | 12 ++++++------ src/midisource.cpp | 6 +++--- src/plane.cpp | 4 ++-- src/settingsmenu.cpp | 6 +++--- src/sharedmidistate.h | 2 +- src/soundemitter.cpp | 4 ++-- src/sprite.cpp | 8 ++++---- src/tileatlasvx.cpp | 16 ++++++++-------- src/tilemap.cpp | 2 +- src/transform.h | 2 +- src/window.cpp | 4 ++-- src/windowvx.cpp | 6 +++--- 19 files changed, 71 insertions(+), 71 deletions(-) diff --git a/src/al-util.h b/src/al-util.h index 78ae615..51801e7 100644 --- a/src/al-util.h +++ b/src/al-util.h @@ -238,6 +238,6 @@ inline ALenum chooseALFormat(int sampleSize, int channelCount) #define AUDIO_SLEEP 10 #define STREAM_BUF_SIZE 32768 -#define GLOBAL_VOLUME 0.8 +#define GLOBAL_VOLUME 0.8f #endif // ALUTIL_H diff --git a/src/alstream.cpp b/src/alstream.cpp index 2f1e39f..487f09f 100644 --- a/src/alstream.cpp +++ b/src/alstream.cpp @@ -42,12 +42,12 @@ ALStream::ALStream(LoopMode loopMode, source(0), thread(0), preemptPause(false), - pitch(1.0) + pitch(1.0f) { alSrc = AL::Source::gen(); - AL::Source::setVolume(alSrc, 1.0); - AL::Source::setPitch(alSrc, 1.0); + AL::Source::setVolume(alSrc, 1.0f); + AL::Source::setPitch(alSrc, 1.0f); AL::Source::detachBuffer(alSrc); for (int i = 0; i < STREAM_BUFS; ++i) @@ -172,7 +172,7 @@ void ALStream::setPitch(float value) /* If the source supports setting pitch natively, * we don't have to do it via OpenAL */ if (source && source->setPitch(value)) - AL::Source::setPitch(alSrc, 1.0); + AL::Source::setPitch(alSrc, 1.0f); else AL::Source::setPitch(alSrc, value); } diff --git a/src/audio.cpp b/src/audio.cpp index 945aed0..d536c70 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -170,7 +170,7 @@ struct AudioPrivate else { /* BGM is stopped. -> MeNotPlaying */ - bgm.setVolume(AudioStream::External, 1.0); + bgm.setVolume(AudioStream::External, 1.0f); if (!bgm.noResumeStop) bgm.stream.play(); @@ -193,7 +193,7 @@ struct AudioPrivate if (bgm.stream.queryState() == ALStream::Stopped) { /* BGM stopped midway fade in. -> MeNotPlaying */ - bgm.setVolume(AudioStream::External, 1.0); + bgm.setVolume(AudioStream::External, 1.0f); meWatch.state = MeNotPlaying; bgm.unlockStream(); @@ -219,7 +219,7 @@ struct AudioPrivate if (vol >= 1) { /* BGM fully faded in. -> MeNotPlaying */ - vol = 1.0; + vol = 1.0f; meWatch.state = MeNotPlaying; } diff --git a/src/audiostream.cpp b/src/audiostream.cpp index ae572ef..1d96553 100644 --- a/src/audiostream.cpp +++ b/src/audiostream.cpp @@ -34,11 +34,11 @@ AudioStream::AudioStream(ALStream::LoopMode loopMode, noResumeStop(false), stream(loopMode, threadId) { - current.volume = 1.0; - current.pitch = 1.0; + current.volume = 1.0f; + current.pitch = 1.0f; for (size_t i = 0; i < VolumeTypeCount; ++i) - volumes[i] = 1.0; + volumes[i] = 1.0f; fade.thread = 0; fade.threadName = std::string("audio_fadeout (") + threadId + ")"; @@ -82,8 +82,8 @@ void AudioStream::play(const std::string &filename, lockStream(); - float _volume = clamp(volume, 0, 100) / 100.f; - float _pitch = clamp(pitch, 50, 150) / 100.f; + float _volume = clamp(volume, 0, 100) / 100.0f; + float _pitch = clamp(pitch, 50, 150) / 100.0f; ALStream::State sState = stream.queryState(); @@ -211,7 +211,7 @@ void AudioStream::fadeOut(int duration) } fade.active.set(); - fade.msStep = (1.0) / duration; + fade.msStep = 1.0f / duration; fade.reqFini.clear(); fade.reqTerm.clear(); fade.startTicks = SDL_GetTicks(); @@ -302,7 +302,7 @@ void AudioStream::fadeOutThread() lockStream(); uint32_t curDur = SDL_GetTicks() - fade.startTicks; - float resVol = 1.0 - (curDur*fade.msStep); + float resVol = 1.0f - (curDur*fade.msStep); ALStream::State state = stream.queryState(); @@ -313,7 +313,7 @@ void AudioStream::fadeOutThread() if (state != ALStream::Paused) stream.stop(); - setVolume(FadeOut, 1.0); + setVolume(FadeOut, 1.0f); unlockStream(); break; @@ -340,15 +340,15 @@ void AudioStream::fadeInThread() /* Fade in duration is always 1 second */ uint32_t cur = SDL_GetTicks() - fadeIn.startTicks; - float prog = cur / 1000.0; + float prog = cur / 1000.0f; ALStream::State state = stream.queryState(); if (state != ALStream::Playing - || prog >= 1.0 + || prog >= 1.0f || fadeIn.rqFini) { - setVolume(FadeIn, 1.0); + setVolume(FadeIn, 1.0f); unlockStream(); break; diff --git a/src/bitmap.cpp b/src/bitmap.cpp index 37b1af1..24fb70f 100644 --- a/src/bitmap.cpp +++ b/src/bitmap.cpp @@ -890,9 +890,9 @@ static void applyShadow(SDL_Surface *&in, const SDL_PixelFormat &fm, const SDL_C SDL_Surface *out = SDL_CreateRGBSurface (0, in->w+1, in->h+1, fm.BitsPerPixel, fm.Rmask, fm.Gmask, fm.Bmask, fm.Amask); - float fr = c.r / 255.0; - float fg = c.g / 255.0; - float fb = c.b / 255.0; + float fr = c.r / 255.0f; + float fg = c.g / 255.0f; + float fb = c.b / 255.0f; /* We allocate an output surface one pixel wider and higher than the input, * (implicitly) blit a copy of the input with RGB values set to black into @@ -946,11 +946,11 @@ static void applyShadow(SDL_Surface *&in, const SDL_PixelFormat &fm, const SDL_C continue; } - float fSrcA = srcA / 255.0; - float fShdA = shdA / 255.0; + float fSrcA = srcA / 255.0f; + float fShdA = shdA / 255.0f; /* Because opacity == 1, co1 == fSrcA */ - float co2 = fShdA * (1.0 - fSrcA); + float co2 = fShdA * (1.0f - fSrcA); /* Result alpha */ float fa = fSrcA + co2; /* Temp value to simplify arithmetic below */ @@ -959,10 +959,10 @@ static void applyShadow(SDL_Surface *&in, const SDL_PixelFormat &fm, const SDL_C /* Result colors */ uint8_t r, g, b, a; - r = clamp(fr * co3, 0, 1) * 255; - g = clamp(fg * co3, 0, 1) * 255; - b = clamp(fb * co3, 0, 1) * 255; - a = clamp(fa, 0, 1) * 255; + r = clamp(fr * co3, 0, 1) * 255.0f; + g = clamp(fg * co3, 0, 1) * 255.0f; + b = clamp(fb * co3, 0, 1) * 255.0f; + a = clamp(fa, 0, 1) * 255.0f; *outP = SDL_MapRGBA(&fm, r, g, b, a); } @@ -1067,11 +1067,11 @@ void Bitmap::drawText(const IntRect &rect, const char *str, int align) Vec2i gpTexSize; shState->ensureTexSize(txtSurf->w, txtSurf->h, gpTexSize); - bool fastBlit = !p->touchesTaintedArea(posRect) && txtAlpha == 1.0; + bool fastBlit = !p->touchesTaintedArea(posRect) && txtAlpha == 1.0f; if (fastBlit) { - if (squeeze == 1.0 && !shState->config().subImageFix) + if (squeeze == 1.0f && !shState->config().subImageFix) { /* Even faster: upload directly to bitmap texture. * We have to make sure the posRect lies within the texture diff --git a/src/etc-internal.h b/src/etc-internal.h index 6c66239..6b010b3 100644 --- a/src/etc-internal.h +++ b/src/etc-internal.h @@ -63,7 +63,7 @@ struct Vec4 bool xyzNotNull() const { - return (x != 0.0 || y != 0.0 || z != 0.0); + return (x != 0.0f || y != 0.0f || z != 0.0f); } }; @@ -269,13 +269,13 @@ struct NormValue NormValue(int unNorm) : unNorm(unNorm), - norm(unNorm / 255.0) + norm(unNorm / 255.0f) {} void operator =(int value) { unNorm = clamp(value, 0, 255); - norm = unNorm / 255.0; + norm = unNorm / 255.0f; } bool operator ==(int value) const diff --git a/src/font.cpp b/src/font.cpp index 058dd21..560010c 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -174,7 +174,7 @@ _TTF_Font *SharedFontState::getFont(std::string family, // FIXME 0.9 is guesswork at this point // float gamma = (96.0/45.0)*(5.0/14.0)*(size-5); // font = TTF_OpenFontRW(ops, 1, gamma /** .90*/); - font = TTF_OpenFontRW(ops, 1, size* .90); + font = TTF_OpenFontRW(ops, 1, size* 0.90f); if (!font) throw Exception(Exception::SDLError, "%s", SDL_GetError()); diff --git a/src/graphics.cpp b/src/graphics.cpp index 74e97a3..956c4d9 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -281,9 +281,9 @@ public: void setBrightness(float norm) { - brightnessQuad.setColor(Vec4(0, 0, 0, 1.0 - norm)); + brightnessQuad.setColor(Vec4(0, 0, 0, 1.0f - norm)); - brightEffect = norm < 1.0; + brightEffect = norm < 1.0f; } void updateReso(int width, int height) @@ -736,7 +736,7 @@ void Graphics::transition(int duration, shader.setFrozenScene(p->frozenScene.tex); shader.setCurrentScene(p->currentScene.tex); shader.setTransMap(transMap->getGLTypes().tex); - shader.setVague(vague / 256.0); + shader.setVague(vague / 256.0f); shader.setTexSize(p->scRes); } else @@ -774,7 +774,7 @@ void Graphics::transition(int duration, p->checkSyncLock(); - const float prog = i * (1.0 / duration); + const float prog = i * (1.0f / duration); if (transMap) { @@ -852,7 +852,7 @@ void Graphics::fadeout(int duration) FBO::unbind(); float curr = p->brightness; - float diff = 255.0 - curr; + float diff = 255.0f - curr; for (int i = duration-1; i > -1; --i) { @@ -882,7 +882,7 @@ void Graphics::fadein(int duration) FBO::unbind(); float curr = p->brightness; - float diff = 255.0 - curr; + float diff = 255.0f - curr; for (int i = 1; i <= duration; ++i) { diff --git a/src/midisource.cpp b/src/midisource.cpp index 9cd3a44..3d569a7 100644 --- a/src/midisource.cpp +++ b/src/midisource.cpp @@ -320,7 +320,7 @@ readEvent(MidiReadHandler *handler, MemChunk &chunk, | (data[2] << 0x00); e.type = Tempo; - e.e.tempo.bpm = 60000000.0 / mpqn; + e.e.tempo.bpm = 60000000 / mpqn; } else if (metaType == 0x2F) { @@ -699,7 +699,7 @@ struct MidiSource : ALDataSource, MidiReadHandler void updatePlaybackSpeed(uint32_t bpm) { - float deltaLength = 60.0 / (dpb * bpm); + float deltaLength = 60.0f / (dpb * bpm); playbackSpeed = TICK_FRAMES / (deltaLength * freq); } @@ -910,7 +910,7 @@ struct MidiSource : ALDataSource, MidiReadHandler bool setPitch(float value) { // not completely correct, but close - pitchShift = round((value > 1.0 ? 14 : 24) * (value - 1.0)); + pitchShift = round((value > 1.0f ? 14 : 24) * (value - 1.0f)); return true; } diff --git a/src/plane.cpp b/src/plane.cpp index f275e85..e3de3a0 100644 --- a/src/plane.cpp +++ b/src/plane.cpp @@ -105,8 +105,8 @@ struct PlanePrivate return; /* Scaled (zoomed) bitmap dimensions */ - double sw = bitmap->width() * zoomX; - double sh = bitmap->height() * zoomY; + float sw = bitmap->width() * zoomX; + float sh = bitmap->height() * zoomY; /* Plane offset wrapped by scaled bitmap dims */ float wox = fwrap(ox, sw); diff --git a/src/settingsmenu.cpp b/src/settingsmenu.cpp index a14b488..6518d7f 100644 --- a/src/settingsmenu.cpp +++ b/src/settingsmenu.cpp @@ -764,13 +764,13 @@ void Widget::click(int x, int y, uint8_t button) } /* Ratio of cell area to total widget width */ -#define BW_CELL_R 0.75 +#define BW_CELL_R 0.75f void BindingWidget::drawHandler(SDL_Surface *surf) { const int cellW = (rect.w*BW_CELL_R) / 2; const int cellH = rect.h / 2; - const int cellOffX = (1.0-BW_CELL_R) * rect.w; + const int cellOffX = (1.0f-BW_CELL_R) * rect.w; const int cellOff[] = { @@ -860,7 +860,7 @@ int BindingWidget::cellIndex(int x, int y) const { const int cellW = (rect.w*BW_CELL_R) / 2; const int cellH = rect.h / 2; - const int cellOff = (1.0-BW_CELL_R) * rect.w; + const int cellOff = (1.0f-BW_CELL_R) * rect.w; if (x < cellOff) return -1; diff --git a/src/sharedmidistate.h b/src/sharedmidistate.h index 00de6dc..1692848 100644 --- a/src/sharedmidistate.h +++ b/src/sharedmidistate.h @@ -80,7 +80,7 @@ struct SharedMidiState return; flSettings = fluid.new_settings(); - fluid.settings_setnum(flSettings, "synth.gain", 1.0); + fluid.settings_setnum(flSettings, "synth.gain", 1.0f); fluid.settings_setnum(flSettings, "synth.sample-rate", SYNTH_SAMPLERATE); fluid.settings_setstr(flSettings, "synth.chorus.active", conf.midi.chorus ? "yes" : "no"); fluid.settings_setstr(flSettings, "synth.reverb.active", conf.midi.reverb ? "yes" : "no"); diff --git a/src/soundemitter.cpp b/src/soundemitter.cpp index b064fd1..74eaf03 100644 --- a/src/soundemitter.cpp +++ b/src/soundemitter.cpp @@ -123,8 +123,8 @@ void SoundEmitter::play(const std::string &filename, int volume, int pitch) { - float _volume = clamp(volume, 0, 100) / 100.f; - float _pitch = clamp(pitch, 50, 150) / 100.f; + float _volume = clamp(volume, 0, 100) / 100.0f; + float _pitch = clamp(pitch, 50, 150) / 100.0f; SoundBuffer *buffer = allocateBuffer(filename); diff --git a/src/sprite.cpp b/src/sprite.cpp index 0313444..760bb0b 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp @@ -109,7 +109,7 @@ struct SpritePrivate wave.amp = 0; wave.length = 180; wave.speed = 360; - wave.phase = 0.0; + wave.phase = 0.0f; wave.dirty = false; } @@ -129,7 +129,7 @@ struct SpritePrivate (srcRect->y + srcRect->height) + bitmap->height(); - efBushDepth = 1.0 - texBushDepth / bitmap->height(); + efBushDepth = 1.0f - texBushDepth / bitmap->height(); } void onSrcRectChange() @@ -194,7 +194,7 @@ struct SpritePrivate void emitWaveChunk(SVertex *&vert, float phase, int width, float zoomY, int chunkY, int chunkLength) { - float wavePos = phase + (chunkY / (float) wave.length) * M_PI * 2; + float wavePos = phase + (chunkY / (float) wave.length) * (float) (M_PI * 2); float chunkX = sin(wavePos) * wave.amp; FloatRect tex(0, chunkY / zoomY, width, chunkLength / zoomY); @@ -261,7 +261,7 @@ struct SpritePrivate wave.qArray.resize(!!firstLength + chunks + !!lastLength); SVertex *vert = &wave.qArray.vertices[0]; - float phase = (wave.phase * M_PI) / 180.f; + float phase = (wave.phase * (float) M_PI) / 180.0f; if (firstLength > 0) emitWaveChunk(vert, phase, width, zoomY, 0, firstLength); diff --git a/src/tileatlasvx.cpp b/src/tileatlasvx.cpp index 8f3ec47..2e1c176 100644 --- a/src/tileatlasvx.cpp +++ b/src/tileatlasvx.cpp @@ -51,14 +51,14 @@ extern const int autotileVXRectsBN; /* Waterfall (C) autotile patterns */ static const StaticRect autotileVXRectsC[] = { - { 32.5, 0.5, 15, 31 }, - { 16.5, 0.5, 15, 31 }, - { 0.0, 0.5, 15, 31 }, - { 16.5, 0.5, 15, 31 }, - { 32.5, 0.5, 15, 31 }, - { 48.5, 0.5, 15, 31 }, - { 0.0, 0.5, 15, 31 }, - { 48.5, 0.5, 15, 31 } + { 32.5f, 0.5f, 15.0f, 31.0f }, + { 16.5f, 0.5f, 15.0f, 31.0f }, + { 0.0f, 0.5f, 15.0f, 31.0f }, + { 16.5f, 0.5f, 15.0f, 31.0f }, + { 32.5f, 0.5f, 15.0f, 31.0f }, + { 48.5f, 0.5f, 15.0f, 31.0f }, + { 0.0f, 0.5f, 15.0f, 31.0f }, + { 48.5f, 0.5f, 15.0f, 31.0f } }; static elementsN(autotileVXRectsC); diff --git a/src/tilemap.cpp b/src/tilemap.cpp index d3cf437..f721e03 100644 --- a/src/tilemap.cpp +++ b/src/tilemap.cpp @@ -698,7 +698,7 @@ struct TilemapPrivate int tileY = tsInd / 8; Vec2i texPos = TileAtlas::tileToAtlasCoor(tileX, tileY, atlas.efTilesetH, atlas.size.y); - FloatRect texRect((float) texPos.x+.5, (float) texPos.y+.5, 31, 31); + FloatRect texRect((float) texPos.x+0.5f, (float) texPos.y+0.5f, 31, 31); FloatRect posRect(x*32, y*32, 32, 32); SVertex v[4]; diff --git a/src/transform.h b/src/transform.h index cefd09f..7a129f9 100644 --- a/src/transform.h +++ b/src/transform.h @@ -130,7 +130,7 @@ private: if (rotation < 0) rotation += 360; - float angle = rotation * 3.141592654f / 180.f; + float angle = rotation * 3.141592654f / 180.0f; float cosine = (float) cos(angle); float sine = (float) sin(angle); float sxc = scale.x * cosine; diff --git a/src/window.cpp b/src/window.cpp index a32481d..71a8cc9 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -642,7 +642,7 @@ struct WindowPrivate if (active && cursorVert.vert) { - float alpha = cursorAniAlpha[cursorAniAlphaIdx] / 255.0; + float alpha = cursorAniAlpha[cursorAniAlphaIdx] / 255.0f; cursorVert.setAlpha(alpha); @@ -651,7 +651,7 @@ struct WindowPrivate if (pause && pauseAniVert.vert) { - float alpha = pauseAniAlpha[pauseAniAlphaIdx] / 255.0; + float alpha = pauseAniAlpha[pauseAniAlphaIdx] / 255.0f; FloatRect frameRect = pauseAniSrc[pauseAniQuad[pauseAniQuadIdx]]; pauseAniVert.setAlpha(alpha); diff --git a/src/windowvx.cpp b/src/windowvx.cpp index 0bafb5b..02a70d9 100644 --- a/src/windowvx.cpp +++ b/src/windowvx.cpp @@ -482,7 +482,7 @@ struct WindowVXPrivate void updateBaseQuad() { const FloatRect tex(0, 0, geo.w, geo.h); - const FloatRect pos(0, (geo.h / 2.0) * (1 - openness.norm), + const FloatRect pos(0, (geo.h / 2.0f) * (1.0f - openness.norm), geo.w, geo.h * openness.norm); base.quad.setTexPosRect(tex, pos); @@ -633,7 +633,7 @@ struct WindowVXPrivate Quad::setTexRect(pauseVert, pauseSrc[pauseQuad[pauseQuadIdx]]); /* Set opacity */ - Quad::setColor(pauseVert, Vec4(1, 1, 1, pauseAlpha[pauseAlphaIdx] / 255.0)); + Quad::setColor(pauseVert, Vec4(1, 1, 1, pauseAlpha[pauseAlphaIdx] / 255.0f)); ctrlVertArrayDirty = true; } @@ -643,7 +643,7 @@ struct WindowVXPrivate if (cursorVert.count() == 0) return; - Vec4 color(1, 1, 1, cursorAlpha[cursorAlphaIdx] / 255.0); + Vec4 color(1, 1, 1, cursorAlpha[cursorAlphaIdx] / 255.0f); for (size_t i = 0; i < cursorVert.count(); ++i) Quad::setColor(&cursorVert.vertices[i*4], color);