From 261694773fda1fc4009cb86ac8bcaa9b93bee207 Mon Sep 17 00:00:00 2001 From: Sara Date: Sun, 2 Nov 2025 18:00:35 +0100 Subject: [PATCH] feat: full flow from startup to gameplay & clues sending --- modules/you_done_it/client_node.cpp | 14 ++++ modules/you_done_it/ydi_client.cpp | 14 ++-- modules/you_done_it/ydi_server.cpp | 5 +- .../3D Models/VR Hand Left.blend.import | 59 +++++++++++++++++ .../3D Models/VR Hand Right.blend.import | 59 +++++++++++++++++ vr-project/project.godot | 2 +- vr-project/scenes/game_root.tscn | 65 +++++++++++++++++++ vr-project/scenes/game_scene.tscn | 5 ++ vr-project/vr_base.tscn | 2 - 9 files changed, 213 insertions(+), 12 deletions(-) create mode 100644 vr-project/3D Models/VR Hand Left.blend.import create mode 100644 vr-project/3D Models/VR Hand Right.blend.import create mode 100644 vr-project/scenes/game_root.tscn diff --git a/modules/you_done_it/client_node.cpp b/modules/you_done_it/client_node.cpp index 4726dbb8..9760abd5 100644 --- a/modules/you_done_it/client_node.cpp +++ b/modules/you_done_it/client_node.cpp @@ -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() { diff --git a/modules/you_done_it/ydi_client.cpp b/modules/you_done_it/ydi_client.cpp index d5b51cfc..b806e528 100644 --- a/modules/you_done_it/ydi_client.cpp +++ b/modules/you_done_it/ydi_client.cpp @@ -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 { diff --git a/modules/you_done_it/ydi_server.cpp b/modules/you_done_it/ydi_server.cpp index cf17e12d..23a5100c 100644 --- a/modules/you_done_it/ydi_server.cpp +++ b/modules/you_done_it/ydi_server.cpp @@ -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 }; diff --git a/vr-project/3D Models/VR Hand Left.blend.import b/vr-project/3D Models/VR Hand Left.blend.import new file mode 100644 index 00000000..19519047 --- /dev/null +++ b/vr-project/3D Models/VR Hand Left.blend.import @@ -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 diff --git a/vr-project/3D Models/VR Hand Right.blend.import b/vr-project/3D Models/VR Hand Right.blend.import new file mode 100644 index 00000000..cc4f1e30 --- /dev/null +++ b/vr-project/3D Models/VR Hand Right.blend.import @@ -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 diff --git a/vr-project/project.godot b/vr-project/project.godot index af7a8f7d..d516fb78 100644 --- a/vr-project/project.godot +++ b/vr-project/project.godot @@ -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" diff --git a/vr-project/scenes/game_root.tscn b/vr-project/scenes/game_root.tscn new file mode 100644 index 00000000..612046e7 --- /dev/null +++ b/vr-project/scenes/game_root.tscn @@ -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"] diff --git a/vr-project/scenes/game_scene.tscn b/vr-project/scenes/game_scene.tscn index 2040562e..90fb80d3 100644 --- a/vr-project/scenes/game_scene.tscn +++ b/vr-project/scenes/game_scene.tscn @@ -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) diff --git a/vr-project/vr_base.tscn b/vr-project/vr_base.tscn index d9b06c8e..70e1c9fd 100644 --- a/vr-project/vr_base.tscn +++ b/vr-project/vr_base.tscn @@ -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