feat: implemented conclusion_received signal

This commit is contained in:
Sara Gerretsen 2025-11-04 13:30:31 +01:00
parent 40631f5be1
commit 534b527f61
4 changed files with 36 additions and 2 deletions

View file

@ -7,11 +7,16 @@
ClientNode *ClientNode::singleton_instance{ nullptr };
String const ClientNode::sig_connection_changed{ "connection_changed" };
String const ClientNode::sig_conclusion_received{ "conclusion_received" };
void ClientNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("connect_to_server", "server_url"), &self_type::connect_to_server);
ADD_SIGNAL(MethodInfo(sig_connection_changed, PropertyInfo(Variant::INT, "connected", PROPERTY_HINT_ENUM, "Disconnected,Connected,Authenticated")));
ADD_SIGNAL(MethodInfo(sig_conclusion_received,
PropertyInfo(Variant::INT, "method", PROPERTY_HINT_ENUM, NetworkData::ClueID_hint()),
PropertyInfo(Variant::INT, "motive", PROPERTY_HINT_ENUM, NetworkData::ClueID_hint()),
PropertyInfo(Variant::INT, "murderer", PROPERTY_HINT_ENUM, NetworkData::ClueID_hint())));
}
void ClientNode::enter_tree() {
@ -32,6 +37,11 @@ void ClientNode::process() {
reveal_backlog();
}
}
bool const new_has_conclusion{ ydi::client::receive::has_conclusion() };
if (new_has_conclusion != this->conclusion.is_full()) {
this->conclusion = ydi::client::receive::conclusion();
emit_signal(sig_conclusion_received, this->conclusion[0], this->conclusion[1], this->conclusion[2]);
}
}
void ClientNode::exit_tree() {

View file

@ -1,5 +1,6 @@
#pragma once
#include "core/templates/fixed_vector.h"
#include "scene/main/node.h"
#include "you_done_it/ydi_networking.h"
@ -20,8 +21,10 @@ public:
void connect_to_server(String const &url);
private:
FixedVector<NetworkData::ClueID, 3> conclusion;
NetworkData::ConnectionStatus state{ NetworkData::CONNECTION_DISCONNECTED };
public:
static String const sig_connection_changed;
static String const sig_conclusion_received;
};

View file

@ -146,6 +146,25 @@ NetworkData::ConnectionStatus status() {
}
}
namespace receive {
FixedVector<NetworkData::ClueID, 3> &conclusion() {
static FixedVector<NetworkData::ClueID, 3> threadsafe_copy{};
if (connection) {
threadsafe_copy = connection->conclusion;
} else {
threadsafe_copy.clear();
}
return threadsafe_copy;
}
bool has_conclusion() {
if (!connection) {
return false;
}
std::scoped_lock lock{ connection->mtx };
return connection->conclusion.is_full();
}
} //namespace receive
namespace send {
void reveal_clue(NetworkData::ClueID id) {
if (connection) {

View file

@ -1,6 +1,7 @@
#pragma once
#include "core/string/ustring.h"
#include "core/templates/fixed_vector.h"
#include "you_done_it/ydi_networking.h"
namespace ydi::client {
@ -8,8 +9,9 @@ void connect(String const &url);
void disconnect();
NetworkData::ConnectionStatus status();
namespace receive {
Vector<NetworkData::ClueID> &conclusion();
}
FixedVector<NetworkData::ClueID, 3> &conclusion();
bool has_conclusion();
} //namespace receive
namespace send {
void reveal_clue(NetworkData::ClueID id);
} //namespace send