feat: added singleton logic to Client-/Server-Node

This commit is contained in:
Sara Gerretsen 2025-10-12 23:01:04 +02:00
parent 8086924141
commit 0703b30ed9
4 changed files with 23 additions and 0 deletions

View file

@ -2,6 +2,7 @@
#include "ydi_server.h"
#include <core/config/engine.h>
ServerNode *ServerNode::singleton_instance{ nullptr };
String const ServerNode::sig_clue_revealed{ "clue_revealed" };
String const ServerNode::sig_connection_established{ "connection_established" };
String const ServerNode::sig_connection_lost{ "connection_lost" };
@ -13,6 +14,11 @@ void ServerNode::_bind_methods() {
}
void ServerNode::enter_tree() {
if (singleton_instance) {
print_error("Attempt to create duplicate ServerNode, aborting");
abort();
}
singleton_instance = this;
ydi::server::open();
}
@ -32,6 +38,9 @@ void ServerNode::process(double delta) {
void ServerNode::exit_tree() {
ydi::server::close();
if (singleton_instance == this) {
singleton_instance = nullptr;
}
}
void ServerNode::_notification(int what) {