Skip to content

Commit

Permalink
src/object: use forward declaration for dt
Browse files Browse the repository at this point in the history
  • Loading branch information
sthalik committed Mar 23, 2024
1 parent 36bdeef commit c5edaad
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/critter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "loader/loader.hpp"
#include "src/world.hpp"
#include "src/object.hpp"
#include "src/nanosecond.hpp"
#include "shaders/shader.hpp"
#include "compat/exception.hpp"
#include <cmath>
Expand Down Expand Up @@ -144,7 +143,7 @@ Vector2 critter::ordinal_offset(Vector2b offset) const
return Vector2(offset);
}

void critter::update(size_t i, Ns dt)
void critter::update(size_t i, const Ns& dt)
{
if (playable)
{
Expand All @@ -164,12 +163,12 @@ void critter::update(size_t i, Ns dt)
update_nonplayable(i, dt);
}

void critter::update_nonplayable(size_t i, Ns dt)
void critter::update_nonplayable(size_t i, const Ns& dt)
{
(void)i; (void)dt; (void)playable;
}

void critter::update_movement(size_t i, Ns dt, rotation new_r)
void critter::update_movement(size_t i, const Ns& dt, rotation new_r)
{
fm_assert(new_r < rotation_COUNT);
fm_assert(is_dynamic());
Expand Down
6 changes: 3 additions & 3 deletions src/critter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ struct critter final : object
object_type type() const noexcept override;
explicit operator critter_proto() const;

void update(size_t i, Ns dt) override;
void update_movement(size_t i, Ns dt, rotation r);
void update_nonplayable(size_t i, Ns dt);
void update(size_t i, const Ns& dt) override;
void update_movement(size_t i, const Ns& dt, rotation r);
void update_nonplayable(size_t i, const Ns& dt);
void set_keys(bool L, bool R, bool U, bool D);
void set_keys_auto();
Vector2 ordinal_offset(Vector2b offset) const override;
Expand Down
2 changes: 1 addition & 1 deletion src/light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ light::operator light_proto() const
}

object_type light::type() const noexcept { return object_type::light; }
void light::update(size_t, Ns) {}
void light::update(size_t, const Ns&) {}
bool light::is_dynamic() const { return true; }
bool light::is_virtual() const { return true; }

Expand Down
2 changes: 1 addition & 1 deletion src/light.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct light final : object
Vector2 ordinal_offset(Vector2b offset) const override;
float depth_offset() const override;
object_type type() const noexcept override;
void update(size_t i, Ns dt) override;
void update(size_t i, const Ns& dt) override;
bool is_dynamic() const override;
bool is_virtual() const override;

Expand Down
6 changes: 3 additions & 3 deletions src/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ bool object::move_to(Magnum::Vector2i delta)
}

template<typename T> requires std::is_unsigned_v<T>
uint32_t object::alloc_frame_time(Ns dt, T& accum, uint32_t hz, float speed)
uint32_t object::alloc_frame_time(const Ns& dt, T& accum, uint32_t hz, float speed)
{
constexpr auto ns_in_sec = Ns((int)1e9);
constexpr auto accum_max = uint64_t{limits<T>::max};
Expand Down Expand Up @@ -320,8 +320,8 @@ uint32_t object::alloc_frame_time(Ns dt, T& accum, uint32_t hz, float speed)
return nframes;
}

template uint32_t object::alloc_frame_time(Ns dt, uint16_t& accum, uint32_t hz, float speed);
template uint32_t object::alloc_frame_time(Ns dt, uint32_t& accum, uint32_t hz, float speed);
template uint32_t object::alloc_frame_time(const Ns& dt, uint16_t& accum, uint32_t hz, float speed);
template uint32_t object::alloc_frame_time(const Ns& dt, uint32_t& accum, uint32_t hz, float speed);

void object::set_bbox_(Vector2b offset_, Vector2b bb_offset_, Vector2ub bb_size_, pass_mode pass_)
{
Expand Down
4 changes: 2 additions & 2 deletions src/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct object
virtual object_type type() const noexcept = 0;
virtual bool can_activate(size_t i) const;
virtual bool activate(size_t i);
virtual void update(size_t i, Ns dt) = 0;
virtual void update(size_t i, const Ns& dt) = 0;
virtual void rotate(size_t i, rotation r);
virtual bool can_rotate(global_coords coord, rotation new_r, rotation old_r, Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size);
virtual bool can_move_to(Vector2i delta, global_coords coord, Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_aize);
Expand All @@ -91,7 +91,7 @@ struct object

template<typename T>
requires std::is_unsigned_v<T>
static uint32_t alloc_frame_time(Ns dt, T& accum, uint32_t hz, float speed);
static uint32_t alloc_frame_time(const Ns& dt, T& accum, uint32_t hz, float speed);

protected:
object(object_id id, class chunk& c, const object_proto& proto);
Expand Down
2 changes: 1 addition & 1 deletion src/scenery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ bool scenery::can_activate(size_t i) const
);
}

void scenery::update(size_t i, Ns dt)
void scenery::update(size_t i, const Ns& dt)
{
return std::visit(
[&]<typename T>(T& sc) { sc.update(*this, i, dt); },
Expand Down
2 changes: 1 addition & 1 deletion src/scenery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct scenery final : object
{
scenery_variants subtype;

void update(size_t i, Ns dt) override;
void update(size_t i, const Ns& dt) override;
Vector2 ordinal_offset(Vector2b offset) const override;
float depth_offset() const override;
bool can_activate(size_t i) const override;
Expand Down

0 comments on commit c5edaad

Please sign in to comment.