From 5392fd0540b27a59f58fdf3b64c967a0269fb40c Mon Sep 17 00:00:00 2001 From: Sara Date: Sun, 24 Nov 2024 00:28:57 +0100 Subject: [PATCH] feat: started using _underscore prefixes for functions that (might) have a signal by the same name --- src/core/node.cpp | 8 ++++---- src/core/node.hpp | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/core/node.cpp b/src/core/node.cpp index 9381efe..9ebe141 100644 --- a/src/core/node.cpp +++ b/src/core/node.cpp @@ -53,9 +53,9 @@ bool Node::requests_deletion() const { void Node::propagate_tick(double const &delta_time) { if(!this->has_ticked) { this->has_ticked = true; - this->first_tick(); + this->_first_tick(); } - this->tick(delta_time); + this->_tick(delta_time); std::vector destroy_list{}; for(std::pair &pair : this->children) pair.second->propagate_tick(delta_time); @@ -75,11 +75,11 @@ void Node::propagate_post_tick() { void Node::propagate_removed() { for(std::pair &pair : this->children) pair.second->propagate_removed(); - this->removed(); + this->_removed(); } void Node::propagate_draw(SDL_Renderer *render) { - this->draw(render); + this->_draw(render); for(std::pair &pair : this->children) pair.second->propagate_draw(render); } diff --git a/src/core/node.hpp b/src/core/node.hpp index 762f854..87d2c06 100644 --- a/src/core/node.hpp +++ b/src/core/node.hpp @@ -1,6 +1,7 @@ #ifndef CANVAS_NODE_HPP #define CANVAS_NODE_HPP +#include "core/signal.hpp" #include #include #include @@ -17,14 +18,16 @@ typedef std::map ChildrenMap; std::string name{}; ChildrenMap children{}; Node *parent{nullptr}; +public: + Signal<> removed{}; public: Node() = default; virtual ~Node() = default; - virtual void added(Node *parent [[maybe_unused]]) {} //!< 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 tick(double const &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 draw(SDL_Renderer *render [[maybe_unused]]) {} + virtual void _added(Node *parent [[maybe_unused]]) {} //!< 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 _tick(double const &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 _draw(SDL_Renderer *render [[maybe_unused]]) {} void add_child(Node::OwnedPtr &child); //!< add a child, the caller must own the pointer std::optional remove_child(Node *child); //!< remove a child, the caller now owns the pointer