Skip to content

Commit

Permalink
cleaning code using clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperFola committed Nov 15, 2023
1 parent d3704d5 commit f01af39
Show file tree
Hide file tree
Showing 38 changed files with 108 additions and 130 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
build/*
build/
cmake-build-*/
tcod/
.idea/
*.a
*.o
*.lib
Expand Down
4 changes: 2 additions & 2 deletions include/Pataro/Animation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace pat
*
* @param source the entity to which the animation should be applied
*/
Animation(Entity* source);
explicit Animation(Entity* source);

/**
* @brief Add a frame, after a given duration, executes once the given operation
Expand Down Expand Up @@ -67,7 +67,7 @@ namespace pat
* @return true
* @return false
*/
bool is_finished() const;
[[nodiscard]] bool is_finished() const;

private:
std::size_t m_current = 0;
Expand Down
4 changes: 2 additions & 2 deletions include/Pataro/Components/AI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ namespace pat::component
*/
virtual std::unique_ptr<Action> update(Entity* owner, Engine* engine) = 0;

inline std::unique_ptr<AI> clone() const { return std::unique_ptr<AI>(clone_impl()); }
[[nodiscard]] inline std::unique_ptr<AI> clone() const { return std::unique_ptr<AI>(clone_impl()); }

protected:
virtual AI* clone_impl() const = 0;
[[nodiscard]] virtual AI* clone_impl() const = 0;
};
}

Expand Down
2 changes: 1 addition & 1 deletion include/Pataro/Components/AI/ConfusedMonster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace pat::component
std::unique_ptr<Action> update(Entity* owner, Engine* engine) override;

protected:
virtual ConfusedMonsterAI* clone_impl() const override;
[[nodiscard]] ConfusedMonsterAI* clone_impl() const override;

private:
int m_nb_turns;
Expand Down
2 changes: 1 addition & 1 deletion include/Pataro/Components/AI/Monster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace pat::component
std::unique_ptr<Action> update(Entity* owner, Engine* engine) override;

protected:
virtual MonsterAI* clone_impl() const override;
[[nodiscard]] MonsterAI* clone_impl() const override;

private:
/**
Expand Down
2 changes: 1 addition & 1 deletion include/Pataro/Components/AI/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace pat::component
*/
std::unique_ptr<pat::Action> handle_action_key(Entity* owner, Engine* engine, int keycode);

virtual PlayerAI* clone_impl() const override;
[[nodiscard]] PlayerAI* clone_impl() const override;
};
}

Expand Down
8 changes: 4 additions & 4 deletions include/Pataro/Components/Attacker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ namespace pat::component
*
* @param power
*/
Attacker(float power);
explicit Attacker(float power);

virtual ~Attacker() = default;

inline float power() const { return m_power; }
[[nodiscard]] inline float power() const { return m_power; }

inline std::unique_ptr<Attacker> clone() const { return std::unique_ptr<Attacker>(clone_impl()); }
[[nodiscard]] inline std::unique_ptr<Attacker> clone() const { return std::unique_ptr<Attacker>(clone_impl()); }

protected:
virtual Attacker* clone_impl() const;
[[nodiscard]] virtual Attacker* clone_impl() const;

private:
float m_power;
Expand Down
14 changes: 7 additions & 7 deletions include/Pataro/Components/Destructible.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace pat::component
* @param defense
* @param corpse_name the name of the Entity once dead
*/
Destructible(float max_hp, float defense, const std::string& corpse_name);
Destructible(float max_hp, float defense, std::string corpse_name);

/**
* @brief Destroy the Destructible object
Expand Down Expand Up @@ -56,15 +56,15 @@ namespace pat::component
*/
float heal(float amount);

inline bool is_dead() { return m_hp <= 0.f; }
inline float max_hp() { return m_max_hp; }
inline float hp() { return m_hp; }
inline float defense() { return m_defense; }
[[nodiscard]] inline bool is_dead() const { return m_hp <= 0.f; }
[[nodiscard]] inline float max_hp() const { return m_max_hp; }
[[nodiscard]] inline float hp() const { return m_hp; }
[[nodiscard]] inline float defense() const { return m_defense; }

inline std::unique_ptr<Destructible> clone() const { return std::unique_ptr<Destructible>(clone_impl()); }
[[nodiscard]] inline std::unique_ptr<Destructible> clone() const { return std::unique_ptr<Destructible>(clone_impl()); }

protected:
virtual Destructible* clone_impl() const;
[[nodiscard]] virtual Destructible* clone_impl() const;

private:
float m_max_hp, m_hp;
Expand Down
2 changes: 1 addition & 1 deletion include/Pataro/Components/Destructible/Monster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace pat::component
void die(Entity* owner, Engine* engine) override;

protected:
virtual MonsterDestructible* clone_impl() const override;
[[nodiscard]] MonsterDestructible* clone_impl() const override;
};
}

Expand Down
2 changes: 1 addition & 1 deletion include/Pataro/Components/Destructible/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace pat::component
void die(Entity* owner, Engine* engine) override;

protected:
virtual PlayerDestructible* clone_impl() const override;
[[nodiscard]] PlayerDestructible* clone_impl() const override;
};
}

Expand Down
10 changes: 5 additions & 5 deletions include/Pataro/Components/Inventory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace pat::component
*
* @param size the number of elements in the inventory (0 = unlimited)
*/
Inventory(std::size_t size);
explicit Inventory(std::size_t size);

virtual ~Inventory() = default;

Expand Down Expand Up @@ -60,19 +60,19 @@ namespace pat::component
*
* @return std::size_t
*/
std::size_t size() const;
[[nodiscard]] std::size_t size() const;

/**
* @brief Returns the maximum capacity of the inventory
*
* @return std::size_t
*/
std::size_t capacity() const;
[[nodiscard]] std::size_t capacity() const;

inline std::unique_ptr<Inventory> clone() const { return std::unique_ptr<Inventory>(clone_impl()); }
[[nodiscard]] inline std::unique_ptr<Inventory> clone() const { return std::unique_ptr<Inventory>(clone_impl()); }

protected:
virtual Inventory* clone_impl() const;
[[nodiscard]] virtual Inventory* clone_impl() const;

private:
std::size_t m_max_size;
Expand Down
6 changes: 3 additions & 3 deletions include/Pataro/Components/Use.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ namespace pat::component
* @param owner the owner of the source object we are dropping
* @param engine
*/
void drop(Entity* source, Entity* owner, Engine* engine);
void drop(Entity* source, Entity* owner, Engine* engine) const;

/**
* @brief Remove from inventory
*
*/
void remove_from_inventory(Entity* owner, Entity* source);

inline std::unique_ptr<Use> clone() const { return std::unique_ptr<Use>(clone_impl()); }
[[nodiscard]] inline std::unique_ptr<Use> clone() const { return std::unique_ptr<Use>(clone_impl()); }

protected:
/**
Expand All @@ -57,7 +57,7 @@ namespace pat::component
*/
virtual std::unique_ptr<Action> use(Entity* source, Entity* owner, Engine* engine) = 0;

virtual Use* clone_impl() const = 0;
[[nodiscard]] virtual Use* clone_impl() const = 0;

private:
bool m_destroyed = false; ///< When equal to true, can not use it again
Expand Down
6 changes: 3 additions & 3 deletions include/Pataro/Components/Use/OneTime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace pat::component
*
* @param args
*/
OneTimeUse(Args&&... args)
explicit OneTimeUse(Args&&... args)
{
m_function = [args = std::make_tuple(std::forward<Args>(args) ...)](Entity* source, Entity* owner) -> std::unique_ptr<Action> {
return std::apply([source, owner](auto&&... args) {
Expand All @@ -48,8 +48,8 @@ namespace pat::component
}

private:
OneTimeUse(const Callback_t& callback) :
m_function(callback)
explicit OneTimeUse(Callback_t callback) :
m_function(std::move(callback))
{}

Callback_t m_function;
Expand Down
19 changes: 10 additions & 9 deletions include/Pataro/Components/Use/OneTimeSelect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <string>
#include <functional>
#include <memory>
#include <utility>

namespace pat::component
{
Expand Down Expand Up @@ -43,11 +44,11 @@ namespace pat::component
*/
bool pick(Engine* engine);

inline PickMethod get_method() const { return m_method; }
inline int get_x() const { return m_x; }
inline int get_y() const { return m_y; }
inline float get_range() const { return m_range; }
inline Entity* get_entity() const { return m_entity; }
[[nodiscard]] inline PickMethod get_method() const { return m_method; }
[[nodiscard]] inline int get_x() const { return m_x; }
[[nodiscard]] inline int get_y() const { return m_y; }
[[nodiscard]] inline float get_range() const { return m_range; }
[[nodiscard]] inline Entity* get_entity() const { return m_entity; }

protected:
/**
Expand Down Expand Up @@ -88,8 +89,8 @@ namespace pat::component
* @param range the range in which the click can be performed
* @param args
*/
OneTimeSelectUse(const std::string& left_click_text, PickTile picker, Args&&... args) :
m_text(left_click_text), m_picker(picker)
OneTimeSelectUse(std::string left_click_text, PickTile picker, Args&&... args) :
m_text(std::move(left_click_text)), m_picker(picker)
{
m_function = [args = std::make_tuple(std::forward<Args>(args) ...)](Entity* source, Entity* owner, const PickTile& picker) -> std::unique_ptr<Action> {
return std::apply([source, owner, &picker](auto&&... args) {
Expand All @@ -113,8 +114,8 @@ namespace pat::component
}

private:
OneTimeSelectUse(const std::string& text, const PickTile& picker, const Callback_t& callback) :
m_text(text), m_picker(picker), m_function(callback)
OneTimeSelectUse(std::string text, const PickTile& picker, Callback_t callback) :
m_text(std::move(text)), m_picker(picker), m_function(std::move(callback))
{}

std::string m_text;
Expand Down
4 changes: 2 additions & 2 deletions include/Pataro/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace pat
{
struct Tile
{
unsigned char repr;
unsigned char repr {'#'};
tcod::ColorRGB color_visible;
tcod::ColorRGB color_outside_fov;
};
Expand All @@ -35,7 +35,7 @@ namespace pat
};

std::vector<Theme> themes;
unsigned fps_max = 30;
int fps_max = 30;
};
}

Expand Down
10 changes: 5 additions & 5 deletions include/Pataro/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace pat
* @param config engine configuration
* @param show_debug default: false. Show debug gui
*/
Engine(unsigned width, unsigned height, const std::string& title, const Config& config, bool show_debug = false);
Engine(unsigned width, unsigned height, const std::string& title, Config config, bool show_debug = false);

/**
* @brief Initialize the engine
Expand Down Expand Up @@ -74,7 +74,7 @@ namespace pat
* @return true
* @return false
*/
inline bool is_running() const { return m_running; }
[[nodiscard]] inline bool is_running() const { return m_running; }

/**
* @brief Log an event with a given name. Only names/occurences are kept
Expand Down Expand Up @@ -110,14 +110,14 @@ namespace pat

void render_defeat();

inline unsigned width() { return m_width; }
inline unsigned height() { return m_height; }
[[nodiscard]] inline unsigned width() const { return m_width; }
[[nodiscard]] inline unsigned height() const { return m_height; }

inline void change_state(GameState state) { m_state = state; }
inline Entity* get_player() { return m_player.get(); }
inline Map* get_map() { return m_map.get(); }
inline Gui* get_gui() { return m_gui.get(); }
inline const SDL_Keycode& lastkey() { return m_lastkey; }
[[nodiscard]] inline const SDL_Keycode& lastkey() const { return m_lastkey; }
inline const Mouse& mouse() { return m_mouse; }

inline tcod::Console& console() { return m_console; }
Expand Down
2 changes: 1 addition & 1 deletion include/Pataro/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace pat
* @param name the name of the entity
* @param color the color for the entity
*/
Entity(int x, int y, int ch, const std::string& name, const tcod::ColorRGB& color);
Entity(int x, int y, int ch, std::string name, const tcod::ColorRGB& color);

/**
* @brief Construct a new Entity object
Expand Down
8 changes: 4 additions & 4 deletions include/Pataro/Gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace pat
* @param height size of the GUI console
* @param proxy a function to retrieve the value and the max value
*/
Gui(unsigned width, unsigned height, const Proxy_t& proxy);
Gui(unsigned width, unsigned height, Proxy_t proxy);

/**
* @brief Render the GUI on a given TCOD console
Expand Down Expand Up @@ -68,8 +68,8 @@ namespace pat
m_log.erase(m_log.begin());
}

inline unsigned get_width() { return m_width; }
inline unsigned get_height() { return m_height; }
[[nodiscard]] inline unsigned get_width() const { return m_width; }
[[nodiscard]] inline unsigned get_height() const { return m_height; }

private:
/**
Expand All @@ -91,7 +91,7 @@ namespace pat
struct Message {
std::string text;
tcod::ColorRGB color;
Message(const std::string& text, const tcod::ColorRGB& color);
Message(std::string text, const tcod::ColorRGB& color);
};

std::vector<Message> m_log;
Expand Down
Loading

0 comments on commit f01af39

Please sign in to comment.