Add a child timer node
This commit is contained in:
parent
d2f4e02361
commit
7890c90380
6 changed files with 41 additions and 5 deletions
2
.clangd
Normal file
2
.clangd
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
# Cannot suppress driver diagnostics
|
||||||
|
# https://github.com/clangd/clangd/issues/1142
|
||||||
2
.helix/config.toml
Normal file
2
.helix/config.toml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
[keys.normal."space"]
|
||||||
|
B = ":run-shell-command scons"
|
||||||
5
project/main.tscn
Normal file
5
project/main.tscn
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
[gd_scene format=3 uid="uid://cjrkxv8ix1h8s"]
|
||||||
|
|
||||||
|
[node name="Node3D" type="Node3D"]
|
||||||
|
|
||||||
|
[node name="MarshConnector" type="MarshConnector" parent="."]
|
||||||
|
|
@ -11,6 +11,7 @@ config_version=5
|
||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Visualisation for MARSH"
|
config/name="Visualisation for MARSH"
|
||||||
|
run/main_scene="uid://cjrkxv8ix1h8s"
|
||||||
config/features=PackedStringArray("4.4", "GL Compatibility")
|
config/features=PackedStringArray("4.4", "GL Compatibility")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,39 @@
|
||||||
#include "marshconnector.h"
|
#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;
|
using namespace godot;
|
||||||
|
|
||||||
void MarshConnector::_bind_methods() {}
|
void MarshConnector::_bind_methods() {
|
||||||
|
ClassDB::bind_method(D_METHOD("send_heartbeat"),
|
||||||
|
&MarshConnector::send_heartbeat);
|
||||||
|
}
|
||||||
|
|
||||||
MarshConnector::MarshConnector() {
|
MarshConnector::MarshConnector() {
|
||||||
// Initialize any variables here.
|
// Initialize member variables
|
||||||
time_passed = 0.0;
|
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() {
|
MarshConnector::~MarshConnector() {
|
||||||
// Add your cleanup here.
|
// Free only manually managed member variables
|
||||||
}
|
}
|
||||||
|
|
||||||
void MarshConnector::_process(double delta) { time_passed += delta; }
|
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
|
#ifndef MARSHCONNECTOR_H
|
||||||
#define 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 {
|
namespace godot {
|
||||||
|
|
||||||
|
|
@ -10,6 +11,7 @@ class MarshConnector : public Node {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double time_passed;
|
double time_passed;
|
||||||
|
Timer *heartbeat_timer;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
@ -19,6 +21,8 @@ public:
|
||||||
~MarshConnector();
|
~MarshConnector();
|
||||||
|
|
||||||
void _process(double delta) override;
|
void _process(double delta) override;
|
||||||
|
|
||||||
|
void send_heartbeat();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace godot
|
} // namespace godot
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue