Skip to content

Commit

Permalink
clang-tidy: Error on readability-redundant-casting
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse committed Jul 16, 2024
1 parent 86a7502 commit cbaa7c5
Show file tree
Hide file tree
Showing 22 changed files with 144 additions and 152 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Checks: '
,-readability-uppercase-literal-suffix,
,-readability-use-anyofallof,
'
WarningsAsErrors: 'hicpp-use-override,modernize-avoid-bind,llvm-namespace-comment,modernize-use-nullptr,modernize-pass-by-value,hicpp-noexcept-move,boost-use-to-string,google-readability-namespace-comments,modernize-use-default-member-init,modernize-loop-convert,hicpp-use-nullptr,google-readability-braces-around-statements,cert-dcl03-c,readability-else-after-return,bugprone-macro-parentheses,readability-redundant-declaration,google-explicit-constructor,readability-avoid-const-params-in-decls'
WarningsAsErrors: 'hicpp-use-override,modernize-avoid-bind,llvm-namespace-comment,modernize-use-nullptr,modernize-pass-by-value,hicpp-noexcept-move,boost-use-to-string,google-readability-namespace-comments,modernize-use-default-member-init,modernize-loop-convert,hicpp-use-nullptr,google-readability-braces-around-statements,cert-dcl03-c,readability-else-after-return,bugprone-macro-parentheses,readability-redundant-declaration,google-explicit-constructor,readability-avoid-const-params-in-decls,readability-redundant-casting'
CheckOptions:
- key: readability-implicit-bool-conversion.AllowPointerConditions
value: '1'
Expand Down
6 changes: 3 additions & 3 deletions src/ImageDataWebP.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2022 Jan Niklas Hasse <jhasse@bixense.com>
// Copyright 2021-2024 Jan Niklas Hasse <jhasse@bixense.com>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
#ifndef NOWEBP
#include "ImageDataWebP.hpp"
Expand Down Expand Up @@ -32,9 +32,9 @@ ImageDataWebP::ImageDataWebP(std::string filename, FILE* file, double scaleFacto
if (scaleFactor + 1e-9 < 1) { // only use WebP's scaler when scaling down, otherwise use OpenGL
config.options.use_scaling = 1;
config.options.scaled_width = scaledWidth =
std::max(1, int(std::lround(imgWidth * scaleFactor)));
std::max(1, static_cast<int>(std::lround(imgWidth * scaleFactor)));
config.options.scaled_height = scaledHeight =
std::max(1, int(std::lround(imgHeight * scaleFactor)));
std::max(1, static_cast<int>(std::lround(imgHeight * scaleFactor)));
}
config.output.colorspace = MODE_RGBA;
#ifndef __EMSCRIPTEN__
Expand Down
6 changes: 2 additions & 4 deletions src/Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
#include "Sound.hpp"

#include "audio.hpp"
#include "audio/Track.hpp"
#include "audio/constants.hpp"
#include "audio/effect/loop.hpp"
#include "audio/effect/pitch.hpp"
#include "audio/effect/volume.hpp"
#include "audio/Track.hpp"
#include "jngl/debug.hpp"

#include <cassert>

Expand All @@ -31,8 +30,7 @@ Sound::Sound(std::vector<float>& bufferData, long frequency)
impl->stream = impl->volumeControl = audio::volume(std::move(stream));
}

Sound::~Sound() {
}
Sound::~Sound() = default;

bool Sound::isPlaying() const {
return impl->stream->isPlaying();
Expand Down
4 changes: 2 additions & 2 deletions src/audio/duration.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright 2023 Jan Niklas Hasse <jhasse@bixense.com>
// Copyright 2023-2024 Jan Niklas Hasse <jhasse@bixense.com>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
// Based on the audio implementation of the psemek engine, see
// https://lisyarus.github.io/blog/programming/2022/10/15/audio-mixing.html
#pragma once

#include "constants.hpp"

#include <cstdint>
#include <cmath>
#include <cstdint>

namespace jngl::audio {

Expand Down
4 changes: 2 additions & 2 deletions src/audio/effect/pause.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Jan Niklas Hasse <jhasse@bixense.com>
// Copyright 2023-2024 Jan Niklas Hasse <jhasse@bixense.com>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
// Based on the audio implementation of the psemek engine, see
// https://lisyarus.github.io/blog/programming/2022/10/15/audio-mixing.html
Expand Down Expand Up @@ -59,7 +59,7 @@ struct pause_control_impl : pause_control {
}

void rewind() override {
return stream_->rewind();
stream_->rewind();
}

bool isPlaying() const override {
Expand Down
4 changes: 2 additions & 2 deletions src/audio/effect/volume.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Jan Niklas Hasse <jhasse@bixense.com>
// Copyright 2023-2024 Jan Niklas Hasse <jhasse@bixense.com>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
// Based on the audio implementation of the psemek engine, see
// https://lisyarus.github.io/blog/programming/2022/10/15/audio-mixing.html
Expand Down Expand Up @@ -30,7 +30,7 @@ struct volume_control_impl : volume_control {
}

void rewind() override {
return stream_->rewind();
stream_->rewind();
}

bool isPlaying() const override {
Expand Down
11 changes: 7 additions & 4 deletions src/audio/smooth.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Jan Niklas Hasse <jhasse@bixense.com>
// Copyright 2023-2024 Jan Niklas Hasse <jhasse@bixense.com>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
// Based on the audio implementation of the psemek engine, see
// https://lisyarus.github.io/blog/programming/2022/10/15/audio-mixing.html
Expand All @@ -11,13 +11,16 @@
namespace jngl::audio {

inline float smoothness_to_multiplier(float smoothness) {
if (smoothness == 0.f) return 1.f;
if (smoothness == 0.f) {
return 1.f;
}
return -std::expm1(-inv_frequency / smoothness);
}

inline float multiplier_to_smoothness(float multiplier) {
if (multiplier == 1.f) return 0.f;

if (multiplier == 1.f) {
return 0.f;
}
return -inv_frequency / std::log1p(-multiplier);
}

Expand Down
166 changes: 83 additions & 83 deletions src/jngl/Channel.cpp
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
// Copyright 2024 Jan Niklas Hasse <jhasse@bixense.com>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
#include "Channel.hpp"

#include "../audio/effect/pause.hpp"
#include "../audio/effect/volume.hpp"
#include "../audio/mixer.hpp"
#include "../audio.hpp"
#include "SoundFile.hpp"

namespace jngl {

struct Channel::Impl {
Mixer* mixer = nullptr;
audio::volume_control* volumeControl = nullptr;
std::shared_ptr<audio::pause_control> pauseControl;
std::shared_ptr<uint8_t> pauseCount = std::make_shared<uint8_t>(0);
};

Channel::Channel() : impl(std::make_unique<Impl>()) {
auto mixer = std::make_shared<Mixer>();
impl->mixer = mixer.get();
auto volumeControl = audio::volume(mixer);
impl->volumeControl = volumeControl.get();
impl->pauseControl = audio::pause(std::move(volumeControl));
Audio::handle().registerChannel(impl->pauseControl);
}

Channel::~Channel() {
if (auto audio = Audio::handleIfAlive()) {
audio->unregisterChannel(*impl->pauseControl);
}
}

// defined in SoundFile.cpp
std::shared_ptr<SoundFile> getSoundFile(const std::string& filename, std::launch policy);

void Channel::play(const std::string& filename) {
getSoundFile(filename, std::launch::deferred)->play(*this);
}

std::shared_ptr<SoundFile> Channel::loop(const std::string& filename) {
auto tmp = getSoundFile(filename, std::launch::deferred);
tmp->loop(*this);
return tmp;
}

void Channel::stop(const std::string& filename) {
getSoundFile(filename, std::launch::async)->stop(*this);
}

Finally Channel::pause() {
if (*impl->pauseCount == 0) {
impl->pauseControl->pause();
}
++(*impl->pauseCount);
return Finally{ [this, weak = std::weak_ptr(impl->pauseCount)]() {
if (auto count = weak.lock()) {
--(*count);
if (*count == 0) {
impl->pauseControl->resume();
}
}
} };
}

void Channel::setVolume(float volume) {
impl->volumeControl->gain(volume);
}

Channel& Channel::main() {
return Audio::handle().getMainChannel();
}

void Channel::add(std::shared_ptr<Stream> stream) {
impl->mixer->add(std::move(stream));
}

void Channel::remove(const Stream* stream) {
impl->mixer->remove(stream);
}

} // namespace jngl
// Copyright 2024 Jan Niklas Hasse <jhasse@bixense.com>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
#include "Channel.hpp"

#include "../audio.hpp"
#include "../audio/effect/pause.hpp"
#include "../audio/effect/volume.hpp"
#include "../audio/mixer.hpp"
#include "SoundFile.hpp"

namespace jngl {

struct Channel::Impl {
Mixer* mixer = nullptr;
audio::volume_control* volumeControl = nullptr;
std::shared_ptr<audio::pause_control> pauseControl;
std::shared_ptr<uint8_t> pauseCount = std::make_shared<uint8_t>(0);
};

Channel::Channel() : impl(std::make_unique<Impl>()) {
auto mixer = std::make_shared<Mixer>();
impl->mixer = mixer.get();
auto volumeControl = audio::volume(mixer);
impl->volumeControl = volumeControl.get();
impl->pauseControl = audio::pause(std::move(volumeControl));
Audio::handle().registerChannel(impl->pauseControl);
}

Channel::~Channel() {
if (auto audio = Audio::handleIfAlive()) {
audio->unregisterChannel(*impl->pauseControl);
}
}

// defined in SoundFile.cpp
std::shared_ptr<SoundFile> getSoundFile(const std::string& filename, std::launch policy);

void Channel::play(const std::string& filename) {
getSoundFile(filename, std::launch::deferred)->play(*this);
}

std::shared_ptr<SoundFile> Channel::loop(const std::string& filename) {
auto tmp = getSoundFile(filename, std::launch::deferred);
tmp->loop(*this);
return tmp;
}

void Channel::stop(const std::string& filename) {
getSoundFile(filename, std::launch::async)->stop(*this);
}

Finally Channel::pause() {
if (*impl->pauseCount == 0) {
impl->pauseControl->pause();
}
++(*impl->pauseCount);
return Finally{ [this, weak = std::weak_ptr(impl->pauseCount)]() {
if (auto count = weak.lock()) {
--(*count);
if (*count == 0) {
impl->pauseControl->resume();
}
}
} };
}

void Channel::setVolume(float volume) {
impl->volumeControl->gain(volume);
}

Channel& Channel::main() {
return Audio::handle().getMainChannel();
}

void Channel::add(std::shared_ptr<Stream> stream) {
impl->mixer->add(std::move(stream));
}

void Channel::remove(const Stream* stream) {
impl->mixer->remove(stream);
}

} // namespace jngl
4 changes: 2 additions & 2 deletions src/jngl/Controller.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2021 Jan Niklas Hasse <jhasse@bixense.com>
// Copyright 2017-2024 Jan Niklas Hasse <jhasse@bixense.com>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
/// Contains jngl::Controller class
/// @file
Expand Down Expand Up @@ -36,7 +36,7 @@ class Controller : public std::enable_shared_from_this<Controller> {
private:
virtual float stateImpl(controller::Button) const = 0;

enum class ButtonState {
enum class ButtonState : uint8_t {
UNKNOWN,
PRESSED,
NOT_PRESSED,
Expand Down
2 changes: 1 addition & 1 deletion src/jngl/FrameBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ FrameBuffer::FrameBuffer(std::array<Pixels, 2> size) : FrameBuffer(size[0], size
FrameBuffer::~FrameBuffer() = default;

void FrameBuffer::draw(const double x, const double y) const {
return draw(Vec2{ x, y });
draw(Vec2{ x, y });
}

void FrameBuffer::draw(const Vec2 position, const ShaderProgram* const shaderProgram) const {
Expand Down
8 changes: 2 additions & 6 deletions src/jngl/Rgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ void Rgb::setBlue(const float blue) {
}

Rgb interpolate(Rgb a, Rgb b, float t) {
return { static_cast<float>(static_cast<float>(a.getRed()) * (1.f - t) +
static_cast<float>(b.getRed()) * t),
static_cast<float>(static_cast<float>(a.getGreen()) * (1.f - t) +
static_cast<float>(b.getGreen()) * t),
static_cast<float>(static_cast<float>(a.getBlue()) * (1.f - t) +
static_cast<float>(b.getBlue()) * t) };
return { a.getRed() * (1.f - t) + b.getRed() * t, a.getGreen() * (1.f - t) + b.getGreen() * t,
a.getBlue() * (1.f - t) + b.getBlue() * t };
}

} // namespace jngl
11 changes: 3 additions & 8 deletions src/jngl/Rgba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,9 @@ Rgba::operator Rgb() const {
}

Rgba interpolate(Rgba a, Rgba b, float t) {
return { static_cast<float>(static_cast<float>(a.getRed()) * (1.f - t) +
static_cast<float>(b.getRed()) * t),
static_cast<float>(static_cast<float>(a.getGreen()) * (1.f - t) +
static_cast<float>(b.getGreen()) * t),
static_cast<float>(static_cast<float>(a.getBlue()) * (1.f - t) +
static_cast<float>(b.getBlue()) * t),
static_cast<float>(static_cast<float>(a.getAlpha()) * (1.f - t) +
static_cast<float>(b.getAlpha()) * t) };
return { a.getRed() * (1.f - t) + b.getRed() * t, a.getGreen() * (1.f - t) + b.getGreen() * t,
a.getBlue() * (1.f - t) + b.getBlue() * t,
a.getAlpha() * (1.f - t) + b.getAlpha() * t };
}

} // namespace jngl
Expand Down
2 changes: 1 addition & 1 deletion src/jngl/Widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Widget {

virtual ~Widget();

enum class Action {
enum class Action : uint8_t {
NONE,
REMOVE,
REQUEST_FOCUS,
Expand Down
4 changes: 2 additions & 2 deletions src/jngl/effects.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2021 Jan Niklas Hasse <jhasse@bixense.com>
// Copyright 2020-2024 Jan Niklas Hasse <jhasse@bixense.com>
// For conditions of distribution and use, see copyright notice in LICENSE.txt

#include "effects.hpp"
Expand All @@ -24,7 +24,7 @@ void Zoom::endDraw() const {
}

Zoom::Action Zoom::step() {
time += 1.f / float(getStepsPerSecond());
time += 1.f / static_cast<float>(getStepsPerSecond());
return Action::NONE;
}

Expand Down
2 changes: 1 addition & 1 deletion src/jngl/job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace jngl {
Job::~Job() = default;

void addJob(std::shared_ptr<Job> job) {
return pWindow->addJob(std::move(job));
pWindow->addJob(std::move(job));
}

void removeJob(Job* job) {
Expand Down
2 changes: 1 addition & 1 deletion src/jngl/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ Finally Sprite::LoadBMP(const std::string& filename, FILE* const fp, const bool
}
width = static_cast<float>(header.width * getScaleFactor());
height = static_cast<float>(header.height * getScaleFactor());
loadTexture(header.width, header.height, filename, halfLoad, GL_BGR, &buf[0]);
loadTexture(header.width, header.height, filename, halfLoad, GL_BGR, buf.data());
return Finally(nullptr);
}
#ifndef NOWEBP
Expand Down
2 changes: 1 addition & 1 deletion src/jngl/sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class Sprite : public Drawable {
/// vertexes.emplace_back(30, 10, 0.5, 1);
/// vertexes.emplace_back(30, 0, 0.5, 0);
/// mySprite.drawMesh(vertexes);
/// \endcode
/// \endcode
///
/// \param shaderProgram Passing `nullptr` uses the default.
void drawMesh(Mat3 modelview, const std::vector<Vertex>& vertexes,
Expand Down
Loading

0 comments on commit cbaa7c5

Please sign in to comment.