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

Mark simple getters and setters as inline #3108

Merged
merged 3 commits into from
Nov 26, 2024
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
2 changes: 1 addition & 1 deletion CODINGSTYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ with polymorphism in mind.

Mark all functions that override a virtual function in a base class with `override`.

Write simple getters/setters inside a header file on a single line.
Write simple getters/setters inside a header file on a single line. Mark them as `inline`.

Properly separate data members and member functions. Do not mix them in the same
`public`/`protected`/`private` section.
Expand Down
37 changes: 0 additions & 37 deletions src/addon/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,30 +232,6 @@ Addon::get_filename() const
return get_id() + ".zip";
}

const std::string&
Addon::get_install_filename() const
{
return m_install_filename;
}

bool
Addon::is_installed() const
{
return !m_install_filename.empty();
}

bool
Addon::is_enabled() const
{
return m_enabled;
}

bool
Addon::is_visible() const
{
return true;
}

bool
Addon::is_levelset() const
{
Expand All @@ -277,17 +253,4 @@ Addon::requires_restart() const
return m_type == LANGUAGEPACK || m_type == RESOURCEPACK;
}

void
Addon::set_install_filename(const std::string& absolute_filename, const std::string& md5)
{
m_install_filename = absolute_filename;
m_md5 = md5;
}

void
Addon::set_enabled(bool v)
{
m_enabled = v;
}

/* EOF */
40 changes: 22 additions & 18 deletions src/addon/addon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,34 +62,38 @@ class Addon final
Addon();

public:
const std::string& get_id() const { return m_id; }
int get_version() const { return m_version; }
int get_format() const { return m_format; }
inline const std::string& get_id() const { return m_id; }
inline int get_version() const { return m_version; }
inline int get_format() const { return m_format; }

Type get_type() const { return m_type; }
const std::string& get_title() const { return m_title; }
const std::string& get_author() const { return m_author; }
const std::string& get_license() const { return m_license; }
inline Type get_type() const { return m_type; }
inline const std::string& get_title() const { return m_title; }
inline const std::string& get_author() const { return m_author; }
inline const std::string& get_license() const { return m_license; }

const std::string& get_description() const { return m_description; }
const std::string& get_url() const { return m_url; }
const std::string& get_md5() const { return m_md5; }
const std::vector<std::string>& get_screenshots() const { return m_screenshots; }
const std::vector<std::string>& get_dependencies() const { return m_dependencies; }
inline const std::string& get_description() const { return m_description; }
inline const std::string& get_url() const { return m_url; }
inline const std::string& get_md5() const { return m_md5; }
inline const std::vector<std::string>& get_screenshots() const { return m_screenshots; }
inline const std::vector<std::string>& get_dependencies() const { return m_dependencies; }

std::string get_filename() const;
const std::string& get_install_filename() const;
inline const std::string& get_install_filename() const { return m_install_filename; }

bool is_installed() const;
bool is_enabled() const;
bool is_visible() const;
inline bool is_installed() const { return !m_install_filename.empty(); }
inline bool is_enabled() const { return m_enabled; }
inline bool is_visible() const { return true; }

bool is_levelset() const;
bool overrides_data() const;
bool requires_restart() const;

void set_install_filename(const std::string& absolute_filename, const std::string& md5);
void set_enabled(bool v);
inline void set_install_filename(const std::string& absolute_filename, const std::string& md5)
{
m_install_filename = absolute_filename;
m_md5 = md5;
}
inline void set_enabled(bool v) { m_enabled = v; }

private:
Addon(const Addon&) = delete;
Expand Down
12 changes: 0 additions & 12 deletions src/addon/addon_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,6 @@ AddonManager::get_installed_addons() const
return get_addons(m_installed_addons);
}

bool
AddonManager::has_online_support() const
{
return true;
}

bool
AddonManager::has_been_updated() const
{
return m_has_been_updated;
}

TransferStatusPtr
AddonManager::request_check_online()
{
Expand Down
4 changes: 2 additions & 2 deletions src/addon/addon_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class AddonManager final : public Currenton<AddonManager>

void empty_cache_directory();

bool has_online_support() const;
bool has_been_updated() const;
inline bool has_online_support() const { return true; }
inline bool has_been_updated() const { return m_has_been_updated; }
void check_online();
TransferStatusPtr request_check_online();

Expand Down
2 changes: 1 addition & 1 deletion src/addon/downloader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class TransferStatusList final

int get_download_now() const;
int get_download_total() const;
const std::string& get_error() const { return m_error_msg; }
inline const std::string& get_error() const { return m_error_msg; }

bool is_active() const;

Expand Down
8 changes: 4 additions & 4 deletions src/audio/sound_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ class SoundManager final : public Currenton<SoundManager>
void stop_sounds();
void set_sound_volume(int volume);

bool is_music_enabled() const { return m_music_enabled; }
bool is_sound_enabled() const { return m_sound_enabled; }
inline bool is_music_enabled() const { return m_music_enabled; }
inline bool is_sound_enabled() const { return m_sound_enabled; }

bool is_audio_enabled() const { return m_device != nullptr && m_context != nullptr; }
const std::string& get_current_music() const { return m_current_music; }
inline bool is_audio_enabled() const { return m_device != nullptr && m_context != nullptr; }
inline const std::string& get_current_music() const { return m_current_music; }
void update();

/** Tell soundmanager to call update() for stream_sound_source. */
Expand Down
4 changes: 2 additions & 2 deletions src/audio/stream_sound_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class StreamSoundSource final : public OpenALSoundSource
void set_sound_file(std::unique_ptr<SoundFile> newfile);

void set_fading(FadeState state, float fadetime);
FadeState get_fade_state() const { return m_fade_state; }
bool get_looping() const { return m_looping; }
inline FadeState get_fade_state() const { return m_fade_state; }
inline bool get_looping() const { return m_looping; }

private:
bool fillBufferAndQueue(ALuint buffer);
Expand Down
8 changes: 4 additions & 4 deletions src/badguy/badguy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ class BadGuy : public MovingSprite,
current form. */
virtual bool can_break() const { return false; }

Vector get_start_position() const { return m_start_position; }
void set_start_position(const Vector& vec) { m_start_position = vec; }
inline Vector get_start_position() const { return m_start_position; }
inline void set_start_position(const Vector& vec) { m_start_position = vec; }

virtual void grab(MovingObject& object, const Vector& pos, Direction dir) override;
virtual void ungrab(MovingObject& object, Direction dir) override;
Expand Down Expand Up @@ -157,7 +157,7 @@ class BadGuy : public MovingSprite,
/** Adds velocity from wind */
virtual void add_wind_velocity(const Vector& velocity, const Vector& end_speed);

Physic& get_physic() { return m_physic; }
inline Physic& get_physic() { return m_physic; }

protected:
enum State {
Expand Down Expand Up @@ -216,7 +216,7 @@ class BadGuy : public MovingSprite,
void kill_squished(GameObject& object);

void set_state(State state);
State get_state() const { return m_state; }
inline State get_state() const { return m_state; }

bool check_state_timer() {
return m_state_timer.check();
Expand Down
10 changes: 5 additions & 5 deletions src/badguy/crusher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Crusher final : public MovingSprite
virtual void draw(DrawingContext& context) override;

virtual void after_editor_set() override;
virtual bool is_sideways() const { return m_sideways; }
inline bool is_sideways() const { return m_sideways; }

static std::string class_name() { return "crusher"; }
virtual std::string get_class_name() const override { return class_name(); }
Expand All @@ -78,9 +78,9 @@ class Crusher final : public MovingSprite

virtual void on_flip(float height) override;

Physic& get_physic() { return m_physic; }
bool is_big() const { return m_ic_size == LARGE; }
CrusherState get_state() const { return m_state; }
inline Physic& get_physic() { return m_physic; }
inline bool is_big() const { return m_ic_size == LARGE; }
inline CrusherState get_state() const { return m_state; }

private:
void spawn_roots(Direction direction);
Expand Down Expand Up @@ -123,7 +123,7 @@ class CrusherRoot : public MovingSprite

private:
void start_animation();
bool delay_gone() const { return m_delay_remaining <= 0.f; }
inline bool delay_gone() const { return m_delay_remaining <= 0.f; }

private:
Vector m_original_pos;
Expand Down
6 changes: 0 additions & 6 deletions src/badguy/dart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,6 @@ Dart::play_looping_sounds()
}
}

void
Dart::set_flip(Flip flip)
{
m_flip = flip;
}

std::vector<Direction>
Dart::get_allowed_directions() const
{
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/dart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Dart final : public BadGuy

virtual void on_flip(float height) override;

void set_flip(Flip flip);
inline void set_flip(Flip flip) { m_flip = flip; }

protected:
virtual std::vector<Direction> get_allowed_directions() const override;
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/granito.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Granito : public WalkingBadguy
* @scripting
* @description Gets the current Granito state. Value is any of the ""GRANITO_STATE"" enumerators.
*/
int get_state() const { return static_cast<int>(m_state); }
inline int get_state() const { return static_cast<int>(m_state); }

/**
* @scripting
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/granito_big.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class GranitoBig final : public Granito
virtual GameObjectTypes get_types() const override;

void carry(Granito* granito);
Granito* get_carrying() const { return m_carrying; }
inline Granito* get_carrying() const { return m_carrying; }

/**
* @scripting
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/mrbomb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MrBomb : public WalkingBadguy
virtual void freeze() override;
virtual bool is_freezable() const override;

bool is_ticking() const { return m_state == MB_STATE_TICKING; }
inline bool is_ticking() const { return m_state == MB_STATE_TICKING; }
virtual void trigger(Player* player);
virtual void explode();

Expand Down
6 changes: 0 additions & 6 deletions src/badguy/treewillowisp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,6 @@ TreeWillOWisp::set_color(const Color& color_)
m_sprite->set_color(color_);
}

Color
TreeWillOWisp::get_color() const
{
return color;
}

void TreeWillOWisp::stop_looping_sounds()
{
if (sound_source) {
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/treewillowisp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TreeWillOWisp final : public BadGuy
void start_sucking(const Vector& suck_target);

void set_color(const Color& color);
Color get_color() const;
inline Color get_color() const { return color; }

protected:
virtual bool collides(GameObject& other, const CollisionHit& hit) const override;
Expand Down
6 changes: 0 additions & 6 deletions src/badguy/walking_badguy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,4 @@ WalkingBadguy::unfreeze(bool melt)
WalkingBadguy::initialize();
}

void
WalkingBadguy::set_velocity_y(float vy)
{
m_physic.set_velocity_y(vy);
}

/* EOF */
11 changes: 6 additions & 5 deletions src/badguy/walking_badguy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ class WalkingBadguy : public BadGuy
/** used by objects that should make badguys not turn around when they are walking on them */
void override_stay_on_platform() { m_stay_on_platform_overridden = true; }

float get_velocity_x() const { return m_physic.get_velocity_x(); }
float get_velocity_y() const { return m_physic.get_velocity_y(); }
void set_velocity_y(float vy);
inline float get_velocity_x() const { return m_physic.get_velocity_x(); }
inline float get_velocity_y() const { return m_physic.get_velocity_y(); }
inline void set_velocity_x(float vx) { m_physic.set_velocity_x(vx); }
inline void set_velocity_y(float vy) { m_physic.set_velocity_y(vy); }

/** Adds velocity to the badguy (be careful when using this) */
void add_velocity(const Vector& velocity);

float get_walk_speed() const { return walk_speed; }
inline float get_walk_speed() const { return walk_speed; }
void set_walk_speed (float);
bool is_active() const { return BadGuy::is_active(); }
inline bool is_active() const { return BadGuy::is_active(); }

/** Set max_drop_height depending on the given behavior */
void set_ledge_behavior(LedgeBehavior behavior);
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/willowisp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class WillOWisp final : public BadGuy,
/** make WillOWisp vanish */
void vanish();

Color get_color() const { return m_color; }
inline Color get_color() const { return m_color; }

protected:
virtual std::vector<Direction> get_allowed_directions() const override;
Expand Down
8 changes: 4 additions & 4 deletions src/collision/collision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ class Constraints final
float get_position_left () const { return position_left; }
float get_position_right () const { return position_right; }
float get_position_top () const { return position_top; }
float get_position_bottom () const { return position_bottom; }
inline float get_position_bottom () const { return position_bottom; }

float get_height () const { return (position_bottom - position_top); }
float get_width () const { return (position_right - position_left); }
inline float get_height () const { return (position_bottom - position_top); }
inline float get_width () const { return (position_right - position_left); }

float get_x_midpoint () const { return (.5f * (position_left + position_right)); }
inline float get_x_midpoint () const { return (.5f * (position_left + position_right)); }

CollisionHit hit;

Expand Down
Loading