feat: started using _underscore prefixes for functions that (might) have a signal by the same name

main
Sara 2024-11-24 00:28:57 +01:00
parent a61f1efb88
commit 5392fd0540
2 changed files with 12 additions and 9 deletions

View File

@ -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<std::string> destroy_list{};
for(std::pair<std::string const, Node::OwnedPtr> &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<std::string const, Node::OwnedPtr> &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<std::string const, Node::OwnedPtr> &pair : this->children)
pair.second->propagate_draw(render);
}

View File

@ -1,6 +1,7 @@
#ifndef CANVAS_NODE_HPP
#define CANVAS_NODE_HPP
#include "core/signal.hpp"
#include <memory>
#include <map>
#include <optional>
@ -17,14 +18,16 @@ typedef std::map<std::string, Node::OwnedPtr> 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<Node::OwnedPtr> remove_child(Node *child); //!< remove a child, the caller now owns the pointer