feat: delta time is no longer const &

main
Sara 2025-01-27 00:42:02 +01:00
parent 502fc20fb0
commit 8b233db1b6
11 changed files with 23 additions and 11 deletions

View File

@ -15,7 +15,7 @@ void Level::deinstantiate() {
this->root.reset(); this->root.reset();
} }
void Level::propagate_tick(double const &delta_time) { void Level::propagate_tick(double delta_time) {
this->root->propagate_tick(delta_time); this->root->propagate_tick(delta_time);
this->root->propagate_post_tick(); this->root->propagate_post_tick();
} }

View File

@ -17,7 +17,7 @@ public:
void instantiate(); void instantiate();
virtual Node::OwnedPtr construct() = 0; virtual Node::OwnedPtr construct() = 0;
void deinstantiate(); void deinstantiate();
void propagate_tick(double const &delta_time); void propagate_tick(double delta_time);
void propagate_draw(SDL_Renderer *render); void propagate_draw(SDL_Renderer *render);
Node *get_root(); Node *get_root();

View File

@ -125,7 +125,7 @@ std::optional<Node::OwnedPtr> Node::remove_child(Node *node) {
} }
} }
void Node::propagate_tick(double const &delta_time) { void Node::propagate_tick(double delta_time) {
if(this->tick) { if(this->tick) {
if(!this->has_ticked) { if(!this->has_ticked) {
this->has_ticked = true; this->has_ticked = true;
@ -171,6 +171,15 @@ void Node::propagate_draw(SDL_Renderer *render, ce::Transform const &view_transf
} }
} }
void Node::propagate_draw_ui(SDL_Renderer *render, ce::Transform const &ui_transform) {
this->_draw_ui(render, ui_transform);
if(this->visible) {
this->_draw_ui(render, ui_transform);
for(ChildrenVector::value_type &pair : this->children)
pair.second->propagate_draw_ui(render, ui_transform);
}
}
bool Node::rename_child(std::string const &old_name, std::string const &new_name) { bool Node::rename_child(std::string const &old_name, std::string const &new_name) {
// extract ownership of node and erase old name // extract ownership of node and erase old name
for(ChildrenVector::iterator itr{this->children.begin()}; itr != this->children.end(); ++itr) { for(ChildrenVector::iterator itr{this->children.begin()}; itr != this->children.end(); ++itr) {

View File

@ -37,9 +37,10 @@ public:
public: public:
virtual void _added() {} //!< called the moment after the object is added as a child to another node virtual void _added() {} //!< called the moment after the object is added as a child to another node
virtual void _first_tick() {} //!< called the first frame this object is active virtual void _first_tick() {} //!< called the first frame this object is active
virtual void _tick(double const &delta_time [[maybe_unused]]) {} //!< called every frame virtual void _tick(double delta_time [[maybe_unused]]) {} //!< called every frame
virtual void _removed() {} //!< called the moment before the object is removed as a child to another node virtual void _removed() {} //!< called the moment before the object is removed as a child to another node
virtual void _draw(SDL_Renderer *render [[maybe_unused]], ce::Transform const &view_transform [[maybe_unused]]) {} virtual void _draw(SDL_Renderer *render [[maybe_unused]], ce::Transform const &view_transform [[maybe_unused]]) {}
virtual void _draw_ui(SDL_Renderer *render [[maybe_unused]], ce::Transform const &ui_transform [[maybe_unused]]) {}
virtual void _update_transform() {} virtual void _update_transform() {}
public: public:
template <class TNode> TNode *get_child(std::string const &name); //!< get a non-owning pointer to a child template <class TNode> TNode *get_child(std::string const &name); //!< get a non-owning pointer to a child
@ -62,11 +63,12 @@ private:
void set_level(ce::Level *level); void set_level(ce::Level *level);
void set_is_inside_tree(bool value); void set_is_inside_tree(bool value);
std::optional<Node::OwnedPtr> remove_child(Node *child); //!< remove a child, the caller now owns the pointer std::optional<Node::OwnedPtr> remove_child(Node *child); //!< remove a child, the caller now owns the pointer
void propagate_tick(double const &delta_time); void propagate_tick(double delta_time);
void propagate_post_tick(); void propagate_post_tick();
void propagate_added(); void propagate_added();
void propagate_removed(); void propagate_removed();
void propagate_draw(SDL_Renderer *render, ce::Transform const &view_transform); void propagate_draw(SDL_Renderer *render, ce::Transform const &view_transform);
void propagate_draw_ui(SDL_Renderer *renderer, ce::Transform const &ui_transform);
bool rename_child(std::string const &old_name, std::string const &new_name); bool rename_child(std::string const &old_name, std::string const &new_name);
}; };

View File

@ -51,6 +51,7 @@ void Player::_tick(double const &delta) {
ACCELERATION * delta ACCELERATION * delta
); );
ce::Transform trans{this->get_global_transform().translated(this->velocity * delta)}; ce::Transform trans{this->get_global_transform().translated(this->velocity * delta)};
void Player::_tick(double delta) {
trans.position.x = std::clamp(trans.position.x, -LIMITS.x, LIMITS.x); trans.position.x = std::clamp(trans.position.x, -LIMITS.x, LIMITS.x);
trans.position.y = std::clamp(trans.position.y, -LIMITS.y, LIMITS.y); trans.position.y = std::clamp(trans.position.y, -LIMITS.y, LIMITS.y);
this->set_global_transform(trans); this->set_global_transform(trans);

View File

@ -23,7 +23,7 @@ class Player : public ce::CollidableNode {
float invincibility{0.f}; float invincibility{0.f};
public: public:
Player(); Player();
virtual void _tick(double const &delta) override; virtual void _tick(double delta) override;
void _input_horizontal_movement(ce::InputValue value); void _input_horizontal_movement(ce::InputValue value);
void _input_vertical_movement(ce::InputValue value); void _input_vertical_movement(ce::InputValue value);
void _on_overlap_enter(ce::CollisionShape *, ce::CollidableNode *node, ce::CollisionShape*); void _on_overlap_enter(ce::CollisionShape *, ce::CollidableNode *node, ce::CollisionShape*);

View File

@ -20,7 +20,7 @@ ScrollingGround::ScrollingGround()
); );
} }
void ScrollingGround::_tick(double const &delta) { void ScrollingGround::_tick(double delta) {
ce::Transform trans; ce::Transform trans;
for(size_t i{0u}; i < NUM_SPRITES; ++i) { for(size_t i{0u}; i < NUM_SPRITES; ++i) {
trans = this->sprites[i]->get_global_transform() trans = this->sprites[i]->get_global_transform()

View File

@ -11,7 +11,7 @@ class ScrollingGround : public ce::Node2D {
ce::Sprite *sprites[2]{nullptr, nullptr}; ce::Sprite *sprites[2]{nullptr, nullptr};
public: public:
ScrollingGround(); ScrollingGround();
virtual void _tick(double const &delta) override; virtual void _tick(double delta) override;
}; };
#endif // !SCROLLING_GROUND_HPP #endif // !SCROLLING_GROUND_HPP

View File

@ -15,7 +15,7 @@ void TestNode::_first_tick() {
this->sprite->set_global_transform(st); this->sprite->set_global_transform(st);
} }
void TestNode::_tick(double const &delta) { void TestNode::_tick(double delta) {
ce::Node2D::_tick(delta); ce::Node2D::_tick(delta);
ce::Transform trans{this->get_transform()}; ce::Transform trans{this->get_transform()};
trans.position.x = 500 + std::sin(SDL_GetTicks64() * 0.001) * 100.f; trans.position.x = 500 + std::sin(SDL_GetTicks64() * 0.001) * 100.f;

View File

@ -12,7 +12,7 @@ private:
public: public:
TestNode(); TestNode();
virtual void _first_tick() override; virtual void _first_tick() override;
virtual void _tick(double const &delta) override; virtual void _tick(double delta) override;
virtual void _draw(SDL_Renderer *render, ce::Transform const &view_transform) override; virtual void _draw(SDL_Renderer *render, ce::Transform const &view_transform) override;
}; };

View File

@ -15,7 +15,6 @@ Truck::Truck(bool left)
})); }));
} }
void Truck::_tick(double const &delta) {
wave_time += delta * FREQUENCY; wave_time += delta * FREQUENCY;
ce::Transform const transform{this->get_global_transform() ce::Transform const transform{this->get_global_transform()
.translated(ce::Vecf{ .translated(ce::Vecf{
@ -24,6 +23,7 @@ void Truck::_tick(double const &delta) {
} * float(delta)) } * float(delta))
}; };
this->set_global_transform(transform); this->set_global_transform(transform);
void Truck::_tick(double delta) {
if(transform.position.y > 4.5f) if(transform.position.y > 4.5f)
this->flag_for_deletion(); this->flag_for_deletion();
} }