feat: full flow from startup to gameplay & clues sending

This commit is contained in:
Sara Gerretsen 2025-11-02 18:00:35 +01:00
parent c765f7daf9
commit 261694773f
9 changed files with 213 additions and 12 deletions

View file

@ -1,5 +1,6 @@
#include "client_node.h"
#include "core/config/engine.h"
#include "scene/main/node.h"
#include "you_done_it/clue_data.h"
#include "you_done_it/clue_db.h"
#include "you_done_it/ydi_client.h"
@ -54,6 +55,19 @@ void ClientNode::_notification(int what) {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
switch (what) {
default:
return;
case NOTIFICATION_ENTER_TREE:
set_process(true);
return;
case NOTIFICATION_PROCESS:
process();
return;
case NOTIFICATION_EXIT_TREE:
exit_tree();
return;
}
}
ClientNode *ClientNode::get_singleton() {

View file

@ -34,8 +34,6 @@ void handle_ok(zmq::multipart_t const &message) {
}
void handle_message(zmq::multipart_t const &message) {
print_line("Client handle_message:");
print_message_contents(message);
NetworkData::MessageType type{ to_message_type(message[0]) };
switch (type) {
case NetworkData::MSG_OK:
@ -43,11 +41,11 @@ void handle_message(zmq::multipart_t const &message) {
handle_ok(message);
return;
case NetworkData::MSG_HEART:
print_line("Client: Received HEART, sending BEAT");
multipart(NetworkData::MSG_BEAT).send(*connection->socket);
return;
default:
print_line("Client: Message not handled");
print_line("Client: Message not handled:");
print_message_contents(message);
return;
}
}
@ -132,12 +130,18 @@ void disconnect() {
}
NetworkData::ConnectionStatus status() {
return connection ? NetworkData::ConnectionStatus(connection->status) : NetworkData::CONNECTION_DISCONNECTED;
if (!connection) {
return NetworkData::CONNECTION_DISCONNECTED;
} else {
std::scoped_lock lock{ connection->mtx };
return connection->status;
}
}
namespace send {
void reveal_clue(NetworkData::ClueID id) {
if (connection) {
print_line("Sending Clue ", id);
std::scoped_lock lock{ connection->mtx };
multipart(NetworkData::MSG_REVEAL, id).send(*connection->socket);
} else {

View file

@ -35,7 +35,6 @@ void handle_reveal_clue(zmq::multipart_t const &message) {
void handle_authorised_message(std::string_view const &sender, NetworkData::MessageType type, zmq::multipart_t &message) {
switch (type) {
case NetworkData::MSG_BEAT:
print_line("Server: Received beat, storing timestamp");
service->lastBeat = Time::get_singleton()->get_unix_time_from_system();
return;
case NetworkData::MSG_REVEAL:
@ -44,6 +43,7 @@ void handle_authorised_message(std::string_view const &sender, NetworkData::Mess
return;
default:
print_line("Server: Encountered unknown message type, sending NOK_UNKNOWN_MSG response");
print_message_contents(message);
multipart(sender, NetworkData::MSG_NOK, NetworkData::NOK_UNKNOWN_MSG, message).send(*service->socket);
return;
}
@ -60,15 +60,12 @@ void ping_thread_entry() {
while (!service->stop_threads) {
std::this_thread::sleep_for(1s);
std::scoped_lock lock{ service->mtx };
print_line("Server: Send HEART");
multipart(*service->client, NetworkData::MSG_HEART).send(*service->socket);
service->lastHeart = Time::get_singleton()->get_unix_time_from_system();
}
}
void handle_message(zmq::multipart_t &message) {
print_line("Server handle_message:");
print_message_contents(message);
std::string_view const sender{ message.at(0).to_string_view() };
NetworkData::MessageType type{ to_message_type(message.at(1)) };
std::scoped_lock lock{ service->mtx };

View file

@ -0,0 +1,59 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://be2i5t47efh3w"
path="res://.godot/imported/VR Hand Left.blend-48513c82aee08ea7f00c25b20ce57aa0.scn"
[deps]
source_file="res://3D Models/VR Hand Left.blend"
dest_files=["res://.godot/imported/VR Hand Left.blend-48513c82aee08ea7f00c25b20ce57aa0.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/root_script=null
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
nodes/use_name_suffixes=true
nodes/use_node_type_suffixes=true
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
materials/extract=0
materials/extract_format=0
materials/extract_path=""
_subresources={}
blender/nodes/visible=0
blender/nodes/active_collection_only=false
blender/nodes/punctual_lights=true
blender/nodes/cameras=true
blender/nodes/custom_properties=true
blender/nodes/modifiers=1
blender/meshes/colors=false
blender/meshes/uvs=true
blender/meshes/normals=true
blender/meshes/export_geometry_nodes_instances=false
blender/meshes/tangents=true
blender/meshes/skins=2
blender/meshes/export_bones_deforming_mesh_only=false
blender/materials/unpack_enabled=true
blender/materials/export_materials=1
blender/animation/limit_playback=true
blender/animation/always_sample=true
blender/animation/group_tracks=true
gltf/naming_version=2

View file

@ -0,0 +1,59 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://16mdrd1edwtj"
path="res://.godot/imported/VR Hand Right.blend-3a895814cf75bf835ed1651de19f1f91.scn"
[deps]
source_file="res://3D Models/VR Hand Right.blend"
dest_files=["res://.godot/imported/VR Hand Right.blend-3a895814cf75bf835ed1651de19f1f91.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/root_script=null
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
nodes/use_name_suffixes=true
nodes/use_node_type_suffixes=true
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
materials/extract=0
materials/extract_format=0
materials/extract_path=""
_subresources={}
blender/nodes/visible=0
blender/nodes/active_collection_only=false
blender/nodes/punctual_lights=true
blender/nodes/cameras=true
blender/nodes/custom_properties=true
blender/nodes/modifiers=1
blender/meshes/colors=false
blender/meshes/uvs=true
blender/meshes/normals=true
blender/meshes/export_geometry_nodes_instances=false
blender/meshes/tangents=true
blender/meshes/skins=2
blender/meshes/export_bones_deforming_mesh_only=false
blender/materials/unpack_enabled=true
blender/materials/export_materials=1
blender/animation/limit_playback=true
blender/animation/always_sample=true
blender/animation/group_tracks=true
gltf/naming_version=2

View file

@ -11,7 +11,7 @@ config_version=5
[application]
config/name="you_done_it"
run/main_scene="uid://b5m5h30gog3pu"
run/main_scene="uid://cj8weoqksmfm6"
config/features=PackedStringArray("4.5", "Forward Plus")
config/icon="res://icon.svg"

View file

@ -0,0 +1,65 @@
[gd_scene load_steps=4 format=3 uid="uid://cj8weoqksmfm6"]
[ext_resource type="PackedScene" uid="uid://b5m5h30gog3pu" path="res://scenes/game_scene.tscn" id="1_78s5d"]
[sub_resource type="GDScript" id="GDScript_78s5d"]
script/source = "extends Node
@export var game_scene : PackedScene
func _on_client_node_connection_changed(connected: int) -> void:
print(\"CONNECTION CHANGED: \", connected)
if connected == NetworkData.CONNECTION_AUTHENTICATED:
var instance = game_scene.instantiate()
if instance:
$PanelContainer.queue_free()
add_child(instance)
"
[sub_resource type="GDScript" id="GDScript_xkpyy"]
script/source = "extends VBoxContainer
func _on_line_edit_text_submitted(new_text: String) -> void:
%ClientNode.connect_to_server(new_text)
func _on_button_pressed() -> void:
%ClientNode.connect_to_server($LineEdit.text)
"
[node name="GameRoot" type="Node"]
script = SubResource("GDScript_78s5d")
game_scene = ExtResource("1_78s5d")
[node name="ClientNode" type="ClientNode" parent="."]
unique_name_in_owner = true
[node name="PanelContainer" type="PanelContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="CenterContainer" type="CenterContainer" parent="PanelContainer"]
layout_mode = 2
[node name="AspectRatioContainer" type="AspectRatioContainer" parent="PanelContainer/CenterContainer"]
layout_mode = 2
ratio = 4.127
stretch_mode = 1
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/CenterContainer/AspectRatioContainer"]
layout_mode = 2
script = SubResource("GDScript_xkpyy")
[node name="LineEdit" type="LineEdit" parent="PanelContainer/CenterContainer/AspectRatioContainer/VBoxContainer"]
layout_mode = 2
placeholder_text = "IP Address"
[node name="Button" type="Button" parent="PanelContainer/CenterContainer/AspectRatioContainer/VBoxContainer"]
layout_mode = 2
text = "Connect"
[connection signal="connection_changed" from="ClientNode" to="." method="_on_client_node_connection_changed"]
[connection signal="text_submitted" from="PanelContainer/CenterContainer/AspectRatioContainer/VBoxContainer/LineEdit" to="PanelContainer/CenterContainer/AspectRatioContainer/VBoxContainer" method="_on_line_edit_text_submitted"]
[connection signal="pressed" from="PanelContainer/CenterContainer/AspectRatioContainer/VBoxContainer/Button" to="PanelContainer/CenterContainer/AspectRatioContainer/VBoxContainer" method="_on_button_pressed"]

View file

@ -73,8 +73,13 @@ shadow_blur = 1.476
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.27989578, 0, 1.4924412)
[node name="ClueMarker" type="ClueMarker" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.2472578, 0.96516895, 2.9078503)
clue_id = 0
[node name="ClueMarker2" type="ClueMarker" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.1681437, 0.93944424, 2.9801283)
clue_id = 1
[node name="Stapler" parent="." instance=ExtResource("3_ycayy")]
transform = Transform3D(-1.8868132, 0, -1.8585076, 0, 2.6484175, 0, 1.8585076, 0, -1.8868132, -1.2748423, 0.9004388, 2.876501)

View file

@ -9,8 +9,6 @@ height = 0.05
[node name="VROrigin" type="VROrigin"]
[node name="ClientNode" type="ClientNode" parent="."]
[node name="XRCamera3D" type="XRCamera3D" parent="."]
current = true