Add a child timer node

This commit is contained in:
Marek S. Łukasiewicz 2025-01-28 16:43:08 +01:00
parent d2f4e02361
commit 7890c90380
6 changed files with 41 additions and 5 deletions

2
.clangd Normal file
View file

@ -0,0 +1,2 @@
# Cannot suppress driver diagnostics
# https://github.com/clangd/clangd/issues/1142

2
.helix/config.toml Normal file
View file

@ -0,0 +1,2 @@
[keys.normal."space"]
B = ":run-shell-command scons"

5
project/main.tscn Normal file
View file

@ -0,0 +1,5 @@
[gd_scene format=3 uid="uid://cjrkxv8ix1h8s"]
[node name="Node3D" type="Node3D"]
[node name="MarshConnector" type="MarshConnector" parent="."]

View file

@ -11,6 +11,7 @@ config_version=5
[application]
config/name="Visualisation for MARSH"
run/main_scene="uid://cjrkxv8ix1h8s"
config/features=PackedStringArray("4.4", "GL Compatibility")
config/icon="res://icon.svg"

View file

@ -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");
}

View file

@ -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