Add a child timer node
This commit is contained in:
parent
d2f4e02361
commit
7890c90380
6 changed files with 41 additions and 5 deletions
|
|
@ -1,17 +1,39 @@
|
|||
#include "marshconnector.h"
|
||||
#include <godot_cpp/core/class_db.hpp>
|
||||
|
||||
#include "godot_cpp/classes/engine.hpp"
|
||||
#include "godot_cpp/core/memory.hpp"
|
||||
#include "godot_cpp/core/print_string.hpp"
|
||||
|
||||
using namespace godot;
|
||||
|
||||
void MarshConnector::_bind_methods() {}
|
||||
void MarshConnector::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("send_heartbeat"),
|
||||
&MarshConnector::send_heartbeat);
|
||||
}
|
||||
|
||||
MarshConnector::MarshConnector() {
|
||||
// Initialize any variables here.
|
||||
// Initialize member variables
|
||||
time_passed = 0.0;
|
||||
|
||||
heartbeat_timer = memnew(Timer);
|
||||
add_child(heartbeat_timer);
|
||||
heartbeat_timer->set_wait_time(1.0);
|
||||
heartbeat_timer->set_one_shot(false);
|
||||
heartbeat_timer->set_autostart(true);
|
||||
heartbeat_timer->connect("timeout", Callable(this, "send_heartbeat"));
|
||||
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
// Don't run _process() in the editor
|
||||
set_process_mode(Node::ProcessMode::PROCESS_MODE_DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
MarshConnector::~MarshConnector() {
|
||||
// Add your cleanup here.
|
||||
// Free only manually managed member variables
|
||||
}
|
||||
|
||||
void MarshConnector::_process(double delta) { time_passed += delta; }
|
||||
|
||||
void MarshConnector::send_heartbeat() {
|
||||
print_line("Sending HEARTBEAT at ", time_passed, " seconds");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef MARSHCONNECTOR_H
|
||||
#define MARSHCONNECTOR_H
|
||||
|
||||
#include <godot_cpp/classes/node.hpp>
|
||||
#include "godot_cpp/classes/node.hpp"
|
||||
#include "godot_cpp/classes/timer.hpp"
|
||||
|
||||
namespace godot {
|
||||
|
||||
|
|
@ -10,6 +11,7 @@ class MarshConnector : public Node {
|
|||
|
||||
private:
|
||||
double time_passed;
|
||||
Timer *heartbeat_timer;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
|
@ -19,6 +21,8 @@ public:
|
|||
~MarshConnector();
|
||||
|
||||
void _process(double delta) override;
|
||||
|
||||
void send_heartbeat();
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue