feat: added singleton logic to Client-/Server-Node
This commit is contained in:
parent
8086924141
commit
0703b30ed9
4 changed files with 23 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include "client_node.h"
|
||||
#include "ydi_client.h"
|
||||
|
||||
ClientNode *ClientNode::singleton_instance{ nullptr };
|
||||
String const ClientNode::sig_connection_changed{ "connection_changed" };
|
||||
|
||||
void ClientNode::_bind_methods() {
|
||||
|
|
@ -8,6 +9,13 @@ void ClientNode::_bind_methods() {
|
|||
ADD_SIGNAL(MethodInfo(sig_connection_changed, PropertyInfo(Variant::INT, "connected", PROPERTY_HINT_ENUM, "Disconnected,Connected,Authenticated")));
|
||||
}
|
||||
|
||||
void ClientNode::enter_tree() {
|
||||
if (singleton_instance) {
|
||||
print_error("Attempt to create duplicate ClientNode, aborting");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void ClientNode::process() {
|
||||
NetworkData::ConnectionStatus const new_status{ ydi::client::status() };
|
||||
if (new_status != this->state) {
|
||||
|
|
@ -18,6 +26,9 @@ void ClientNode::process() {
|
|||
|
||||
void ClientNode::exit_tree() {
|
||||
ydi::client::disconnect();
|
||||
if (singleton_instance == this) {
|
||||
singleton_instance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void ClientNode::_notification(int what) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue