From 3769fd3aced1f33188cb61d10a835f1a278a4ea0 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Fri, 16 Aug 2024 19:00:45 +0200 Subject: [PATCH 01/23] begin network --- godot/Scenes/Characters/player.tscn | 9 --- godot/Scenes/Levels/world.tscn | 4 +- godot/Scenes/Menus/mainmenu.tscn | 8 ++- godot/Scenes/Network/networking.tscn | 3 + godot/Scenes/main.tscn | 15 +++++ godot/project.godot | 2 +- src/Lobby.cpp | 96 ++++++++++++++++++++++++++++ src/Lobby.h | 35 ++++++++++ src/Main.cpp | 40 ++++++++++++ src/Main.h | 19 ++++++ src/MainMenu.cpp | 18 ++++-- src/MainMenu.h | 12 ++-- src/Player.cpp | 47 +------------- src/Player.h | 7 -- src/PlayerInfo.h | 11 ++++ src/World.cpp | 28 ++++++++ src/World.h | 20 ++++++ src/register_types.cpp | 8 ++- 18 files changed, 305 insertions(+), 77 deletions(-) create mode 100644 godot/Scenes/Network/networking.tscn create mode 100644 godot/Scenes/main.tscn create mode 100644 src/Lobby.cpp create mode 100644 src/Lobby.h create mode 100644 src/Main.cpp create mode 100644 src/Main.h create mode 100644 src/PlayerInfo.h create mode 100644 src/World.cpp create mode 100644 src/World.h diff --git a/godot/Scenes/Characters/player.tscn b/godot/Scenes/Characters/player.tscn index cc90c2c..3a2f9d3 100644 --- a/godot/Scenes/Characters/player.tscn +++ b/godot/Scenes/Characters/player.tscn @@ -3750,15 +3750,6 @@ skin = SubResource("Skin_l3wpu") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.908729, 0) shape = SubResource("CapsuleShape3D_mm42w") -[node name="SpringArmPivot" type="SpringArmPivot" parent="."] - -[node name="SpringArm3D" type="SpringArm3D" parent="SpringArmPivot"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.31667, 0) -spring_length = 2.0 -margin = 0.2 - -[node name="Camera3D" type="Camera3D" parent="SpringArmPivot/SpringArm3D"] - [node name="AnimationPlayer" type="AnimationPlayer" parent="."] root_node = NodePath("../Mesh") libraries = { diff --git a/godot/Scenes/Levels/world.tscn b/godot/Scenes/Levels/world.tscn index 8413269..013e2b1 100644 --- a/godot/Scenes/Levels/world.tscn +++ b/godot/Scenes/Levels/world.tscn @@ -4,7 +4,7 @@ [ext_resource type="Texture2D" path="res://Assets/Textures/Black.png" id="2_fkwcn"] [ext_resource type="Texture2D" path="res://Assets/Textures/Orange.png" id="3_ux02w"] [ext_resource type="Texture2D" path="res://Assets/Textures/Green.png" id="4_wp15n"] -[ext_resource type="PackedScene" uid="uid://d38w4ae3qj0k4" path="res://Scenes/Characters/first_person_player.tscn" id="5_8ctht"] +[ext_resource type="PackedScene" path="res://Scenes/Characters/first_person_player.tscn" id="5_8ctht"] [sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_6c4vd"] panorama = ExtResource("1_mnexj") @@ -51,7 +51,7 @@ uv1_triplanar = true [sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_rit6o"] data = PackedVector3Array(-12.5, 2.5, 2.5, 2.5, -2.5, 2.5, -2.5, -2.5, 2.5, -12.5, 2.5, -2.5, -2.5, -2.5, -2.5, 2.5, -2.5, -2.5, -12.5, 2.5, 2.5, -12.5, 2.5, -2.5, 2.5, -2.5, 2.5, -12.5, 2.5, -2.5, 2.5, -2.5, -2.5, 2.5, -2.5, 2.5, -12.5, 2.5, -2.5, -12.5, 2.5, 2.5, -2.5, -2.5, -2.5, -12.5, 2.5, 2.5, -2.5, -2.5, 2.5, -2.5, -2.5, -2.5, -2.5, -2.5, 2.5, 2.5, -2.5, 2.5, -2.5, -2.5, -2.5, 2.5, -2.5, 2.5, 2.5, -2.5, -2.5, -2.5, -2.5, -2.5) -[node name="World" type="Node3D"] +[node name="World" type="World"] [node name="WorldEnvironment" type="WorldEnvironment" parent="."] environment = SubResource("Environment_ctwiv") diff --git a/godot/Scenes/Menus/mainmenu.tscn b/godot/Scenes/Menus/mainmenu.tscn index 3b4a107..11d3a9a 100644 --- a/godot/Scenes/Menus/mainmenu.tscn +++ b/godot/Scenes/Menus/mainmenu.tscn @@ -1,6 +1,8 @@ -[gd_scene format=3 uid="uid://bqfqg7xwwlxd8"] +[gd_scene load_steps=2 format=3 uid="uid://bqfqg7xwwlxd8"] -[node name="Main Menu" type="MainMenu"] +[ext_resource type="PackedScene" path="res://Scenes/Network/networking.tscn" id="1_vrong"] + +[node name="MainMenu" type="MainMenu"] anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 @@ -39,3 +41,5 @@ text = "Create Game" layout_mode = 2 theme_override_font_sizes/font_size = 35 text = "Quit" + +[node name="Lobby" parent="." instance=ExtResource("1_vrong")] diff --git a/godot/Scenes/Network/networking.tscn b/godot/Scenes/Network/networking.tscn new file mode 100644 index 0000000..70df01d --- /dev/null +++ b/godot/Scenes/Network/networking.tscn @@ -0,0 +1,3 @@ +[gd_scene format=3 uid="uid://clafls1xhludi"] + +[node name="Lobby" type="Lobby"] diff --git a/godot/Scenes/main.tscn b/godot/Scenes/main.tscn new file mode 100644 index 0000000..0a6779b --- /dev/null +++ b/godot/Scenes/main.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=3 format=3 uid="uid://4jt0v2b2l4rt"] + +[ext_resource type="PackedScene" path="res://Scenes/Network/networking.tscn" id="1_06ibn"] +[ext_resource type="PackedScene" path="res://Scenes/Menus/mainmenu.tscn" id="2_lavg1"] + +[node name="Main" type="Main"] + +[node name="Lobby" parent="." instance=ExtResource("1_06ibn")] + +[node name="MainMenu" parent="." instance=ExtResource("2_lavg1")] + +[connection signal="local_player_connected" from="Lobby" to="MainMenu" method="on_connected"] +[connection signal="change_scene" from="MainMenu" to="." method="change_scene"] +[connection signal="create_game" from="MainMenu" to="Lobby" method="create_game"] +[connection signal="join_game" from="MainMenu" to="Lobby" method="join_game"] diff --git a/godot/project.godot b/godot/project.godot index c562b59..b91f2c6 100644 --- a/godot/project.godot +++ b/godot/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Blitz3" -run/main_scene="res://Scenes/Levels/world.tscn" +run/main_scene="res://Scenes/main.tscn" config/features=PackedStringArray("4.2", "Forward Plus") config/icon="res://icon.svg" diff --git a/src/Lobby.cpp b/src/Lobby.cpp new file mode 100644 index 0000000..44eb2d3 --- /dev/null +++ b/src/Lobby.cpp @@ -0,0 +1,96 @@ +#include "Lobby.h" + +#include +#include + +using namespace godot; + +namespace blitz { + +void Lobby::_bind_methods() { + godot::ClassDB::bind_method(godot::D_METHOD("create_game", "port", "dedicated"), &Lobby::CreateGame); + godot::ClassDB::bind_method(godot::D_METHOD("join_game", "address", "port"), &Lobby::JoinGame); + ADD_SIGNAL(MethodInfo("player_connected", PropertyInfo(Variant::INT, "peer_id"), PropertyInfo(Variant::STRING, "player_name"))); + ADD_SIGNAL(MethodInfo("player_disconnected", PropertyInfo(Variant::INT, "peer_id"))); + ADD_SIGNAL(MethodInfo("server_disconnected")); + ADD_SIGNAL(MethodInfo("local_player_connected")); +} + +Lobby::Lobby() {} + +Lobby::~Lobby() {} + +void Lobby::_ready() { + get_multiplayer()->connect("peer_connected", callable_mp(this, &Lobby::OnPlayerConnected)); + get_multiplayer()->connect("peer_disconnected", callable_mp(this, &Lobby::OnPlayerDisconnected)); + get_multiplayer()->connect("connected_to_server", callable_mp(this, &Lobby::OnConnectOk)); + get_multiplayer()->connect("connection_failed", callable_mp(this, &Lobby::OnConnectFail)); + get_multiplayer()->connect("server_disconnected", callable_mp(this, &Lobby::OnServerDisconnected)); +} + +Error Lobby::JoinGame(const String& a_Address, uint16_t a_Port) { + auto* peer = memnew(ENetMultiplayerPeer); + Error error = peer->create_client(a_Address, a_Port); + if (error) + return error; + + get_multiplayer()->set_multiplayer_peer(peer); + return Error::OK; +} + +Error Lobby::CreateGame(uint16_t a_Port, bool a_Dedicated) { + auto* peer = memnew(ENetMultiplayerPeer); + Error error = peer->create_server(a_Port); + if (error) + return error; + + get_multiplayer()->set_multiplayer_peer(peer); + + if (!a_Dedicated) { + emit_signal("local_player_connected"); + String playerName = "Imtheadmin"; + m_Players.insert({get_multiplayer()->get_unique_id(), {playerName}}); + emit_signal("player_connected", get_multiplayer()->get_unique_id(), playerName); + } + + return Error::OK; +} + +void Lobby::Shutdown() { + get_multiplayer()->set_multiplayer_peer(nullptr); + m_Players.clear(); +} + +void Lobby::OnPlayerConnected(int32_t a_PeerId) { + emit_signal("player_connected", a_PeerId, "anonymous"); + if (get_multiplayer()->is_server()) { + // TODO: broadcast player join + } +} + +void Lobby::OnPlayerDisconnected(int32_t a_PeerId) { + m_Players.erase(a_PeerId); + emit_signal("player_disconnected", a_PeerId); + if (get_multiplayer()->is_server()) { + // TODO: broadcast player leave + } +} + +void Lobby::OnConnectOk() { + int32_t peerId = get_multiplayer()->get_unique_id(); + PlayerInfo localPlayer{"MonPseudo"}; + m_Players.insert({peerId, localPlayer}); + emit_signal("player_connected", peerId, localPlayer.m_Name); + emit_signal("local_player_connected"); +} + +void Lobby::OnConnectFail() { + Shutdown(); +} + +void Lobby::OnServerDisconnected() { + Shutdown(); + emit_signal("server_disconnected"); +} + +} // namespace blitz \ No newline at end of file diff --git a/src/Lobby.h b/src/Lobby.h new file mode 100644 index 0000000..4d97307 --- /dev/null +++ b/src/Lobby.h @@ -0,0 +1,35 @@ +#pragma once + +#include "PlayerInfo.h" +#include +#include + +namespace blitz { + +class Lobby : public godot::Node { + GDCLASS(Lobby, godot::Node) + protected: + static void _bind_methods(); + + public: + Lobby(); + ~Lobby(); + + void _ready() override; + + godot::Error JoinGame(const godot::String& a_Address, uint16_t a_Port); + godot::Error CreateGame(uint16_t a_Port, bool a_Dedicated = false); + + void Shutdown(); + + private: + std::map m_Players; + + void OnPlayerConnected(int32_t a_PeerId); + void OnPlayerDisconnected(int32_t a_PeerId); + void OnConnectOk(); + void OnConnectFail(); + void OnServerDisconnected(); +}; + +} // namespace blitz \ No newline at end of file diff --git a/src/Main.cpp b/src/Main.cpp new file mode 100644 index 0000000..1538425 --- /dev/null +++ b/src/Main.cpp @@ -0,0 +1,40 @@ +#include "Main.h" + +#include +#include +#include +#include +#include +#include + +#include "Lobby.h" +#include "World.h" + +using namespace godot; + +namespace blitz { + +static constexpr char MainScenePath[] = "res://Scenes/Levels/world.tscn"; + +void Main::_bind_methods() { + godot::ClassDB::bind_method(godot::D_METHOD("change_scene"), &Main::ChangeScene); +} + +Main::Main() {} + +Main::~Main() {} + +void Main::ChangeScene() { + Ref sceneData = ResourceLoader::get_singleton()->load(MainScenePath); + World* world = Object::cast_to(sceneData->instantiate()); + get_parent()->add_child(world); + + Lobby* lobby = Object::cast_to(find_child("Lobby")); + DEV_ASSERT(lobby); + + // connect signals + lobby->connect("player_connected", callable_mp(world, &World::AddPlayer)); + lobby->connect("player_disconnected", callable_mp(world, &World::RemovePlayer)); +} + +} // namespace blitz \ No newline at end of file diff --git a/src/Main.h b/src/Main.h new file mode 100644 index 0000000..6e6bfca --- /dev/null +++ b/src/Main.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +namespace blitz { + +class Main : public godot::Node { + GDCLASS(Main, godot::Node) + protected: + static void _bind_methods(); + + public: + Main(); + ~Main(); + + void ChangeScene(); +}; + +} // namespace blitz \ No newline at end of file diff --git a/src/MainMenu.cpp b/src/MainMenu.cpp index 20e7fc5..f1538ad 100644 --- a/src/MainMenu.cpp +++ b/src/MainMenu.cpp @@ -5,11 +5,14 @@ using namespace godot; -static constexpr char MainScenePath[] = "res://Scenes/Levels/world.tscn"; - namespace blitz { -void MainMenu::_bind_methods() {} +void MainMenu::_bind_methods() { + godot::ClassDB::bind_method(godot::D_METHOD("on_connected"), &MainMenu::OnConnected); + ADD_SIGNAL(MethodInfo("create_game", PropertyInfo(Variant::INT, "port"), PropertyInfo(Variant::BOOL, "dedicated"))); + ADD_SIGNAL(MethodInfo("join_game", PropertyInfo(Variant::STRING, "address"), PropertyInfo(Variant::INT, "port"))); + ADD_SIGNAL(MethodInfo("change_scene")); +} MainMenu::MainMenu() {} @@ -32,12 +35,17 @@ void MainMenu::_ready() { m_QuitButton->connect("pressed", callable_mp(this, &MainMenu::OnQuitPressed)); } +void MainMenu::OnConnected() { + emit_signal("change_scene"); + queue_free(); +} + void MainMenu::OnJoinPressed() { - get_tree()->change_scene_to_file(MainScenePath); + emit_signal("join_game", "localhost", 25565); } void MainMenu::OnCreatePressed() { - get_tree()->change_scene_to_file(MainScenePath); + emit_signal("create_game", 25565, false); } void MainMenu::OnQuitPressed() { diff --git a/src/MainMenu.h b/src/MainMenu.h index b6d3961..488861a 100644 --- a/src/MainMenu.h +++ b/src/MainMenu.h @@ -19,12 +19,14 @@ class MainMenu : public godot::Control { private: godot::Button* m_JoinButton; - godot::Button* m_CreateButton; - godot::Button* m_QuitButton; + godot::Button* m_CreateButton; + godot::Button* m_QuitButton; - void OnJoinPressed(); - void OnCreatePressed(); - void OnQuitPressed(); + void OnConnected(); + + void OnJoinPressed(); + void OnCreatePressed(); + void OnQuitPressed(); }; } // namespace blitz \ No newline at end of file diff --git a/src/Player.cpp b/src/Player.cpp index 1d48266..4803b58 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -23,11 +23,9 @@ Player::~Player() {} void Player::_ready() { godot::InputMap::get_singleton()->load_from_project_settings(); - m_PlayerMesh = Object::cast_to(get_child(0)); - m_SpringArmPivot = Object::cast_to(get_child(2)); - m_AnimationTree = Object::cast_to(get_child(4)); + m_PlayerMesh = Object::cast_to(find_child("Mesh")); + m_AnimationTree = Object::cast_to(find_child("AnimationTree")); DEV_ASSERT(m_PlayerMesh); - DEV_ASSERT(m_SpringArmPivot); DEV_ASSERT(m_AnimationTree); apply_floor_snap(); @@ -39,47 +37,6 @@ void Player::_physics_process(float delta) { return; - auto* Input = godot::Input::get_singleton(); - godot::Vector3 move_direction{0, 0, 0}; - move_direction.x = Input->get_action_strength("move_right") - Input->get_action_strength("move_left"); - move_direction.z = Input->get_action_strength("move_backwards") - Input->get_action_strength("move_forwards"); - move_direction = move_direction.rotated({0, 1, 0}, m_SpringArmPivot->get_rotation().y); - - godot::Vector3 newVelocity = get_velocity(); - newVelocity.y -= Gravity * delta; - set_velocity(newVelocity); - - - - if (Input->is_action_pressed("run")) - m_Speed = RunSpeed; - else - m_Speed = WalkSpeed; - - newVelocity = get_velocity(); - newVelocity.x = move_direction.x * m_Speed; - newVelocity.z = move_direction.z * m_Speed; - set_velocity(newVelocity); - - if (move_direction != godot::Vector3{0, 0, 0}) { - godot::Vector3 newRotation = m_PlayerMesh->get_rotation(); - newRotation.y = godot::UtilityFunctions::lerp_angle( - newRotation.y, godot::UtilityFunctions::atan2(get_velocity().x, get_velocity().z), LerpValue); - m_PlayerMesh->set_rotation(newRotation); - } - - bool justLanded = is_on_floor() && m_SnapVector == godot::Vector3{0, 0, 0}; - bool isJumping = is_on_floor() && Input->is_action_just_pressed("jump"); - - if (isJumping) { - newVelocity = get_velocity(); - newVelocity.y = JumpStrength; - set_velocity(newVelocity); - m_SnapVector.zero(); - } else if (justLanded) { - m_SnapVector = {0, -1, 0}; - } - apply_floor_snap(); move_and_slide(); animate(delta); diff --git a/src/Player.h b/src/Player.h index 5fdea94..d01a093 100644 --- a/src/Player.h +++ b/src/Player.h @@ -22,16 +22,9 @@ class Player : public godot::CharacterBody3D { private: godot::Node3D* m_PlayerMesh; - godot::Node3D* m_SpringArmPivot; godot::AnimationTree* m_AnimationTree; godot::Vector3 m_SnapVector; float m_Speed; - /* - @onready var player_mesh : Node3D = $Mesh -@onready var spring_arm_pivot : Node3D = $SpringArmPivot -@onready var animator : AnimationTree = $AnimationTree - - */ }; } // namespace blitz diff --git a/src/PlayerInfo.h b/src/PlayerInfo.h new file mode 100644 index 0000000..19e644f --- /dev/null +++ b/src/PlayerInfo.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +namespace blitz { + +struct PlayerInfo { + godot::String m_Name; +}; + +} // namespace blitz diff --git a/src/World.cpp b/src/World.cpp new file mode 100644 index 0000000..a39d27e --- /dev/null +++ b/src/World.cpp @@ -0,0 +1,28 @@ +#include "World.h" + +#include + +using namespace godot; + +namespace blitz { + +void World::_bind_methods() { + ClassDB::bind_method(D_METHOD("add_player", "id", "name"), &World::AddPlayer); + ClassDB::bind_method(D_METHOD("remove_player", "id"), &World::RemovePlayer); +} + +World::World() {} + +World::~World() {} + +void World::_process(float delta) { + // do update here +} + +void World::AddPlayer(int32_t a_PlayerId, String a_PlayerName) { + UtilityFunctions::print_rich("New player joined ! Id : ", a_PlayerId, ", Name : ", a_PlayerName); +} + +void World::RemovePlayer(int32_t a_PlayerId) {} + +} // namespace blitz \ No newline at end of file diff --git a/src/World.h b/src/World.h new file mode 100644 index 0000000..705d505 --- /dev/null +++ b/src/World.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +namespace blitz { +class World : public godot::Node3D { + GDCLASS(World, godot::Node3D) + protected: + static void _bind_methods(); + + public: + World(); + ~World(); + + void _process(float delta); + + void AddPlayer(int32_t a_PlayerId, godot::String a_PlayerName); + void RemovePlayer(int32_t a_PlayerId); +}; +} // namespace blitz \ No newline at end of file diff --git a/src/register_types.cpp b/src/register_types.cpp index f852032..acb18e6 100644 --- a/src/register_types.cpp +++ b/src/register_types.cpp @@ -1,9 +1,12 @@ #include "register_types.h" #include "FirstPersonPlayer.h" +#include "Lobby.h" +#include "Main.h" +#include "MainMenu.h" #include "Player.h" #include "SpringArmPivot.h" -#include "MainMenu.h" +#include "World.h" #include #include @@ -16,6 +19,9 @@ static void RegisterClasses() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); } void initialize_example_module(ModuleInitializationLevel p_level) { From 9449b125eb426653d75f24043955727bfb9e0c44 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Fri, 16 Aug 2024 19:11:30 +0200 Subject: [PATCH 02/23] add icon --- godot/bin/Blitz3.gdextension | 2 +- godot/icon.png | Bin 0 -> 52765 bytes godot/icon.svg | 1 - godot/project.godot | 2 +- 4 files changed, 2 insertions(+), 3 deletions(-) create mode 100644 godot/icon.png delete mode 100644 godot/icon.svg diff --git a/godot/bin/Blitz3.gdextension b/godot/bin/Blitz3.gdextension index be8f5b5..b0d66f2 100644 --- a/godot/bin/Blitz3.gdextension +++ b/godot/bin/Blitz3.gdextension @@ -1,5 +1,5 @@ [icons] -Blitz3 = "res://icon.svg" +Blitz3 = "res://icon.png" [configuration] diff --git a/godot/icon.png b/godot/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..cfc16f7ead3908d0428e3b8394bfeb561326f87b GIT binary patch literal 52765 zcmeFYWl)^W);3BAGFTu44Fq=^+yV>|+$FdTgS)#VXz<{{g9rEEZowf02p-&m4zB0U z^X$Ffz3Y5cr{1db{o7OxGt>9#)!nOCuU>LZxQdcA7Wzwc1Ox;uS(!I#z4p`({S^FpG~H7UIW53Khz9eiwXg3^*IM`URyZC8WkGsu>ecIi3YmpLX)bZN{?iL3=mE(SlZ2hRXMy@4K5f ziTCJF3DYOS}mupFWM1MZDKS;&^ATV60-E%t0@U<{4Azb9LoSxT>?f{Xp7gJ!A4t znI?v_r!JiDg9Wc$5M0FR1HNg}RfgwcJ_att*}&;K+NHe2thm@p)eaWR|*p|3oCnJs-u<;Dhex8VJa;iMRr9;2{TJ88E2zm-r{l!-h`243COhxe*iK~q;mA0Y^ zg@l8%83i{RHyb;vq^FfTCzS{~g^;tUxuDt`seiBlz6n!Vy1F_Fg25gh9&8?5Y!1#A zU=9HR0Wdo!n3IzgpkQ_JvUi1gvf8^)|6%brk2hv6FlQ@AS1Sj5ia$J|CJt_{!cOQmMFTjcU^O!r z2RCP!nWVd!y({&XV7)yn*Tg!LbD`}5?l<^20ZfbRd|`ybT*T>D?d0F|Pm;2Q^++n?#lz7eMS zGrpjy1I)@)@UM@2JY4){=3J(%Ts%BntlR>;ysS_&b`Dl<4t72sel7t{J|6CWV1bDc(cuh=!iI{Tnv2ycr0kbhR=Vj%CadMfloAC3P!r1>}WeO9N za&WeT0^4b22emK*JK9_P_27@d1;tckg{e5%{wDpaMa35CY7TS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3~~pRq(%X7Z#rMI5rG-mwl9e z!7xsFb^4dRLX^oC=CE&#ld)RyF>Je553ICBeC$@IF*Yt)&XGQe@=f7!Ocx`FvWtBs$-t}DFIrytng6(y=(Ps)j|Hi7%vLU=eh#mI| zn3@L}-QbuTHc)J8?fH8~0!XC`tT<28%}?lvt`@08cvol6LdUTA@wE|;mf)53;ztY(YDC^dgwUFCm$+Lb&f>!h;0zSkkzU zSm|-p!<3E0Q64hn9kCN0!!GFru*CH6?DJ2F@PNIBExYT3yZg;8AbKUl-r^qkfyt;y J7fBiU{~xY7Z2$lO literal 0 HcmV?d00001 diff --git a/godot/icon.svg b/godot/icon.svg deleted file mode 100644 index b370ceb..0000000 --- a/godot/icon.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/godot/project.godot b/godot/project.godot index b91f2c6..a64f2c6 100644 --- a/godot/project.godot +++ b/godot/project.godot @@ -13,7 +13,7 @@ config_version=5 config/name="Blitz3" run/main_scene="res://Scenes/main.tscn" config/features=PackedStringArray("4.2", "Forward Plus") -config/icon="res://icon.svg" +config/icon="res://icon.png" [display] From d261672f516c17641112e12556df53bc992ddf17 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Sat, 17 Aug 2024 14:32:53 +0200 Subject: [PATCH 03/23] change node hierarchy --- godot/Scenes/Menus/mainmenu.tscn | 6 +----- src/MainMenu.cpp | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/godot/Scenes/Menus/mainmenu.tscn b/godot/Scenes/Menus/mainmenu.tscn index 11d3a9a..d097b93 100644 --- a/godot/Scenes/Menus/mainmenu.tscn +++ b/godot/Scenes/Menus/mainmenu.tscn @@ -1,6 +1,4 @@ -[gd_scene load_steps=2 format=3 uid="uid://bqfqg7xwwlxd8"] - -[ext_resource type="PackedScene" path="res://Scenes/Network/networking.tscn" id="1_vrong"] +[gd_scene format=3 uid="uid://bqfqg7xwwlxd8"] [node name="MainMenu" type="MainMenu"] anchors_preset = 8 @@ -41,5 +39,3 @@ text = "Create Game" layout_mode = 2 theme_override_font_sizes/font_size = 35 text = "Quit" - -[node name="Lobby" parent="." instance=ExtResource("1_vrong")] diff --git a/src/MainMenu.cpp b/src/MainMenu.cpp index f1538ad..76b0afa 100644 --- a/src/MainMenu.cpp +++ b/src/MainMenu.cpp @@ -37,7 +37,7 @@ void MainMenu::_ready() { void MainMenu::OnConnected() { emit_signal("change_scene"); - queue_free(); + set_visible(false); } void MainMenu::OnJoinPressed() { From 65808e9deed66505046aea0c621f410cc9073d03 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Sat, 17 Aug 2024 17:18:13 +0200 Subject: [PATCH 04/23] i guess it's working --- .../Characters/first_person_player.tscn | 8 +- godot/Scenes/Characters/player.tscn | 1 - godot/Scenes/Levels/world.tscn | 5 +- godot/Scenes/Network/networking.tscn | 2 + godot/Scenes/Network/server.tscn | 3 + src/FirstPersonPlayer.cpp | 3 +- src/FirstPersonPlayer.h | 11 +-- src/Lobby.cpp | 39 ++++---- src/Lobby.h | 9 +- src/Main.cpp | 19 ++-- src/MainMenu.cpp | 2 +- src/NetworkInterface.cpp | 57 +++++++++++ src/NetworkInterface.h | 22 +++++ src/Player.cpp | 19 +++- src/Player.h | 17 +++- src/Server.cpp | 44 +++++++++ src/Server.h | 31 ++++++ src/World.cpp | 96 +++++++++++++++++-- src/World.h | 14 +++ src/register_types.cpp | 4 + 20 files changed, 338 insertions(+), 68 deletions(-) create mode 100644 godot/Scenes/Network/server.tscn create mode 100644 src/NetworkInterface.cpp create mode 100644 src/NetworkInterface.h create mode 100644 src/Server.cpp create mode 100644 src/Server.h diff --git a/godot/Scenes/Characters/first_person_player.tscn b/godot/Scenes/Characters/first_person_player.tscn index 71fb28c..1449b9f 100644 --- a/godot/Scenes/Characters/first_person_player.tscn +++ b/godot/Scenes/Characters/first_person_player.tscn @@ -3274,25 +3274,25 @@ nodes/output/position = Vector2(860, 160) node_connections = [&"ground_air_transition", 0, &"iwr_blend", &"ground_air_transition", 1, &"Air", &"iwr_blend", 0, &"Idle", &"iwr_blend", 1, &"Walk", &"iwr_blend", 2, &"Run", &"output", 0, &"ground_air_transition"] [node name="FirstPersonPlayer" type="FirstPersonPlayer"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) [node name="MeshInstance3D" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) visible = false layers = 2 mesh = SubResource("CapsuleMesh_ky6st") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] -visible = false +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) shape = SubResource("ConvexPolygonShape3D_qjfxs") [node name="Head" type="Node3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.578545, 0) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.579, 0) [node name="Camera" type="Camera3D" parent="Head"] cull_mask = 1048573 [node name="Mesh" type="Node3D" parent="."] -transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, -1, 0) +transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0) [node name="Armature" type="Node3D" parent="Mesh"] transform = Transform3D(0.01, 0, 0, 0, -3.57628e-09, -0.01, 0, 0.01, -3.57628e-09, 0, 0, 0) diff --git a/godot/Scenes/Characters/player.tscn b/godot/Scenes/Characters/player.tscn index 3a2f9d3..2ebef8c 100644 --- a/godot/Scenes/Characters/player.tscn +++ b/godot/Scenes/Characters/player.tscn @@ -3276,7 +3276,6 @@ node_connections = [&"ground_air_transition", 0, &"iwr_blend", &"ground_air_tran velocity = Vector3(0, -5821.84, 0) [node name="Mesh" type="Node3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0730165, 0) [node name="Armature" type="Node3D" parent="Mesh"] transform = Transform3D(0.01, 0, 0, 0, -3.57628e-09, -0.01, 0, 0.01, -3.57628e-09, 0, 0, 0) diff --git a/godot/Scenes/Levels/world.tscn b/godot/Scenes/Levels/world.tscn index 013e2b1..80d3526 100644 --- a/godot/Scenes/Levels/world.tscn +++ b/godot/Scenes/Levels/world.tscn @@ -1,10 +1,9 @@ -[gd_scene load_steps=18 format=3 uid="uid://coue2qehpn4fr"] +[gd_scene load_steps=17 format=3 uid="uid://coue2qehpn4fr"] [ext_resource type="Texture2D" path="res://Assets/Textures/Sky.png" id="1_mnexj"] [ext_resource type="Texture2D" path="res://Assets/Textures/Black.png" id="2_fkwcn"] [ext_resource type="Texture2D" path="res://Assets/Textures/Orange.png" id="3_ux02w"] [ext_resource type="Texture2D" path="res://Assets/Textures/Green.png" id="4_wp15n"] -[ext_resource type="PackedScene" path="res://Scenes/Characters/first_person_player.tscn" id="5_8ctht"] [sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_6c4vd"] panorama = ExtResource("1_mnexj") @@ -87,4 +86,4 @@ surface_material_override/0 = SubResource("StandardMaterial3D_pfpgv") [node name="CollisionShape3D" type="CollisionShape3D" parent="Slope/StaticBody3D"] shape = SubResource("ConcavePolygonShape3D_rit6o") -[node name="FirstPersonPlayer" parent="." instance=ExtResource("5_8ctht")] +[node name="Players" type="Node" parent="."] diff --git a/godot/Scenes/Network/networking.tscn b/godot/Scenes/Network/networking.tscn index 70df01d..9ad3fb5 100644 --- a/godot/Scenes/Network/networking.tscn +++ b/godot/Scenes/Network/networking.tscn @@ -1,3 +1,5 @@ [gd_scene format=3 uid="uid://clafls1xhludi"] [node name="Lobby" type="Lobby"] + +[node name="NetworkInterface" type="NetworkInterface" parent="."] diff --git a/godot/Scenes/Network/server.tscn b/godot/Scenes/Network/server.tscn new file mode 100644 index 0000000..0bc31e6 --- /dev/null +++ b/godot/Scenes/Network/server.tscn @@ -0,0 +1,3 @@ +[gd_scene format=3 uid="uid://us5sb4a0kq8d"] + +[node name="Server" type="Server"] diff --git a/src/FirstPersonPlayer.cpp b/src/FirstPersonPlayer.cpp index 5114087..f7fe3b6 100644 --- a/src/FirstPersonPlayer.cpp +++ b/src/FirstPersonPlayer.cpp @@ -1,5 +1,6 @@ #include "FirstPersonPlayer.h" +#include #include #include #include @@ -104,7 +105,7 @@ void FirstPersonPlayer::UpdateBobbing(float a_Delta) { void FirstPersonPlayer::UpdateCamera(const InputEventMouseMotion& a_Event) { m_Head->rotate_y(-a_Event.get_relative().x * SENSITIVITY); - m_Mesh->rotate_y(-a_Event.get_relative().x * 0.005); + m_Mesh->rotate_y(-a_Event.get_relative().x * SENSITIVITY); m_Camera->rotate_x(-a_Event.get_relative().y * SENSITIVITY); float rotationX = m_Camera->get_rotation().x; diff --git a/src/FirstPersonPlayer.h b/src/FirstPersonPlayer.h index 3236b30..c1edd84 100644 --- a/src/FirstPersonPlayer.h +++ b/src/FirstPersonPlayer.h @@ -1,14 +1,11 @@ #pragma once -#include -#include -#include +#include "Player.h" #include -#include namespace blitz { -class FirstPersonPlayer : public godot::CharacterBody3D { +class FirstPersonPlayer : public Player { GDCLASS(FirstPersonPlayer, godot::CharacterBody3D) protected: static void _bind_methods(); @@ -20,13 +17,11 @@ class FirstPersonPlayer : public godot::CharacterBody3D { // Godot overrides void _unhandled_input(const godot::Ref&); void _physics_process(float delta); - void _ready(); + void _ready() override; private: - godot::AnimationTree* m_AnimationTree; godot::Camera3D* m_Camera; godot::Node3D* m_Head; - godot::Node3D* m_Mesh; float m_BobTime; float m_Speed; diff --git a/src/Lobby.cpp b/src/Lobby.cpp index 44eb2d3..105c6c9 100644 --- a/src/Lobby.cpp +++ b/src/Lobby.cpp @@ -2,15 +2,21 @@ #include #include +#include +#include +#include +#include using namespace godot; +static const char ServerScenePath[] = "res://Scenes/Network/server.tscn"; + namespace blitz { void Lobby::_bind_methods() { godot::ClassDB::bind_method(godot::D_METHOD("create_game", "port", "dedicated"), &Lobby::CreateGame); godot::ClassDB::bind_method(godot::D_METHOD("join_game", "address", "port"), &Lobby::JoinGame); - ADD_SIGNAL(MethodInfo("player_connected", PropertyInfo(Variant::INT, "peer_id"), PropertyInfo(Variant::STRING, "player_name"))); + ADD_SIGNAL(MethodInfo("player_connected", PropertyInfo(Variant::INT, "peer_id"))); ADD_SIGNAL(MethodInfo("player_disconnected", PropertyInfo(Variant::INT, "peer_id"))); ADD_SIGNAL(MethodInfo("server_disconnected")); ADD_SIGNAL(MethodInfo("local_player_connected")); @@ -46,11 +52,12 @@ Error Lobby::CreateGame(uint16_t a_Port, bool a_Dedicated) { get_multiplayer()->set_multiplayer_peer(peer); + Ref serverScene = ResourceLoader::get_singleton()->load(ServerScenePath); + add_child(serverScene->instantiate()); + if (!a_Dedicated) { emit_signal("local_player_connected"); - String playerName = "Imtheadmin"; - m_Players.insert({get_multiplayer()->get_unique_id(), {playerName}}); - emit_signal("player_connected", get_multiplayer()->get_unique_id(), playerName); + emit_signal("player_connected", get_multiplayer()->get_unique_id()); } return Error::OK; @@ -58,29 +65,25 @@ Error Lobby::CreateGame(uint16_t a_Port, bool a_Dedicated) { void Lobby::Shutdown() { get_multiplayer()->set_multiplayer_peer(nullptr); - m_Players.clear(); -} - -void Lobby::OnPlayerConnected(int32_t a_PeerId) { - emit_signal("player_connected", a_PeerId, "anonymous"); - if (get_multiplayer()->is_server()) { - // TODO: broadcast player join + if (auto* server = find_child("Server")) { + remove_child(server); } } -void Lobby::OnPlayerDisconnected(int32_t a_PeerId) { - m_Players.erase(a_PeerId); - emit_signal("player_disconnected", a_PeerId); +void Lobby::OnPlayerConnected(int64_t a_PeerId) { if (get_multiplayer()->is_server()) { - // TODO: broadcast player leave + emit_signal("player_connected", a_PeerId); + } +} + +void Lobby::OnPlayerDisconnected(int64_t a_PeerId) { + if (get_multiplayer()->is_server()) { + emit_signal("player_disconnected", a_PeerId); } } void Lobby::OnConnectOk() { int32_t peerId = get_multiplayer()->get_unique_id(); - PlayerInfo localPlayer{"MonPseudo"}; - m_Players.insert({peerId, localPlayer}); - emit_signal("player_connected", peerId, localPlayer.m_Name); emit_signal("local_player_connected"); } diff --git a/src/Lobby.h b/src/Lobby.h index 4d97307..ffa49cf 100644 --- a/src/Lobby.h +++ b/src/Lobby.h @@ -1,8 +1,7 @@ #pragma once -#include "PlayerInfo.h" #include -#include +#include "NetworkInterface.h" namespace blitz { @@ -23,10 +22,8 @@ class Lobby : public godot::Node { void Shutdown(); private: - std::map m_Players; - - void OnPlayerConnected(int32_t a_PeerId); - void OnPlayerDisconnected(int32_t a_PeerId); + void OnPlayerConnected(int64_t a_PeerId); + void OnPlayerDisconnected(int64_t a_PeerId); void OnConnectOk(); void OnConnectFail(); void OnServerDisconnected(); diff --git a/src/Main.cpp b/src/Main.cpp index 1538425..2d1f63b 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1,10 +1,10 @@ #include "Main.h" -#include -#include +#include #include #include -#include +#include +#include #include #include "Lobby.h" @@ -17,7 +17,7 @@ namespace blitz { static constexpr char MainScenePath[] = "res://Scenes/Levels/world.tscn"; void Main::_bind_methods() { - godot::ClassDB::bind_method(godot::D_METHOD("change_scene"), &Main::ChangeScene); + godot::ClassDB::bind_method(godot::D_METHOD("change_scene"), &Main::ChangeScene); } Main::Main() {} @@ -25,16 +25,9 @@ Main::Main() {} Main::~Main() {} void Main::ChangeScene() { - Ref sceneData = ResourceLoader::get_singleton()->load(MainScenePath); + Ref sceneData = ResourceLoader::get_singleton()->load(MainScenePath); World* world = Object::cast_to(sceneData->instantiate()); - get_parent()->add_child(world); - - Lobby* lobby = Object::cast_to(find_child("Lobby")); - DEV_ASSERT(lobby); - - // connect signals - lobby->connect("player_connected", callable_mp(world, &World::AddPlayer)); - lobby->connect("player_disconnected", callable_mp(world, &World::RemovePlayer)); + add_child(world); } } // namespace blitz \ No newline at end of file diff --git a/src/MainMenu.cpp b/src/MainMenu.cpp index 76b0afa..0f4d289 100644 --- a/src/MainMenu.cpp +++ b/src/MainMenu.cpp @@ -35,7 +35,7 @@ void MainMenu::_ready() { m_QuitButton->connect("pressed", callable_mp(this, &MainMenu::OnQuitPressed)); } -void MainMenu::OnConnected() { +void MainMenu::OnConnected() { emit_signal("change_scene"); set_visible(false); } diff --git a/src/NetworkInterface.cpp b/src/NetworkInterface.cpp new file mode 100644 index 0000000..b71bc4b --- /dev/null +++ b/src/NetworkInterface.cpp @@ -0,0 +1,57 @@ +#include "NetworkInterface.h" + +#include +#include +#include + +namespace blitz { + +using namespace godot; + +void NetworkInterface::_bind_methods() { + ClassDB::bind_method(D_METHOD("AddPlayer", "a_PlayerId", "a_PlayerName"), &NetworkInterface::AddPlayer); + ClassDB::bind_method(D_METHOD("RemovePlayer", "a_PlayerId"), &NetworkInterface::RemovePlayer); + ClassDB::bind_method(D_METHOD("SetPlayerPositionAndRotation", "a_PlayerId", "a_Position", "a_Rotation"), + &NetworkInterface::SetPlayerPositionAndRotation); + + ADD_SIGNAL(MethodInfo("AddPlayer", PropertyInfo(Variant::INT, "a_PlayerId"), PropertyInfo(Variant::STRING, "a_PlayerName"))); + ADD_SIGNAL(MethodInfo("RemovePlayer", PropertyInfo(Variant::INT, "a_PlayerId"))); + ADD_SIGNAL(MethodInfo("SetPlayerPositionAndRotation", PropertyInfo(Variant::INT, "a_PlayerId"), + PropertyInfo(Variant::VECTOR3, "a_Position"), PropertyInfo(Variant::VECTOR3, "a_Rotation"))); +} + +NetworkInterface::NetworkInterface() {} + +NetworkInterface::~NetworkInterface() {} + +void NetworkInterface::AddPlayer(int64_t a_PlayerId, godot::String a_PlayerName) { + emit_signal("AddPlayer", a_PlayerId, a_PlayerName); +} + +void NetworkInterface::RemovePlayer(int64_t a_PlayerId) { + emit_signal("RemovePlayer", a_PlayerId); +} + +void NetworkInterface::SetPlayerPositionAndRotation(int64_t a_PlayerId, Vector3 a_Position, Vector3 a_Rotation) { + emit_signal("SetPlayerPositionAndRotation", a_PlayerId, a_Position, a_Rotation); +} + +void NetworkInterface::_ready() { + Dictionary config; + config["rpc_mode"] = MultiplayerAPI::RPC_MODE_AUTHORITY; + config["transfer_mode"] = MultiplayerPeer::TRANSFER_MODE_RELIABLE; + config["call_local"] = true; + config["channel"] = 0; + rpc_config("AddPlayer", config); + rpc_config("RemovePlayer", config); + + Dictionary config2; + config["transfer_mode"] = MultiplayerPeer::TRANSFER_MODE_RELIABLE; + config["channel"] = 0; + config2["rpc_mode"] = MultiplayerAPI::RPC_MODE_ANY_PEER; + config2["call_local"] = false; + rpc_config("SetPlayerPositionAndRotation", config2); +} + + +} // namespace blitz \ No newline at end of file diff --git a/src/NetworkInterface.h b/src/NetworkInterface.h new file mode 100644 index 0000000..0b86a1a --- /dev/null +++ b/src/NetworkInterface.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace blitz { +class NetworkInterface : public godot::Node { + GDCLASS(NetworkInterface, godot::Node) + protected: + static void _bind_methods(); + + public: + NetworkInterface(); + ~NetworkInterface(); + + void AddPlayer(int64_t a_PlayerId, godot::String a_PlayerName); + void RemovePlayer(int64_t a_PlayerId); + void SetPlayerPositionAndRotation(int64_t a_PlayerId, godot::Vector3 a_Position, godot::Vector3 a_Rotation); + + void _ready() override; +}; + +} // namespace blitz \ No newline at end of file diff --git a/src/Player.cpp b/src/Player.cpp index 4803b58..4bb3bb1 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -16,16 +16,19 @@ static const float AnimationBlend = 7.0; namespace blitz { +using namespace godot; + void Player::_bind_methods() {} Player::Player() {} + Player::~Player() {} void Player::_ready() { godot::InputMap::get_singleton()->load_from_project_settings(); - m_PlayerMesh = Object::cast_to(find_child("Mesh")); + m_Mesh = Object::cast_to(find_child("Mesh")); m_AnimationTree = Object::cast_to(find_child("AnimationTree")); - DEV_ASSERT(m_PlayerMesh); + DEV_ASSERT(m_Mesh); DEV_ASSERT(m_AnimationTree); apply_floor_snap(); @@ -36,9 +39,6 @@ void Player::_physics_process(float delta) { if (godot::Engine::get_singleton()->is_editor_hint()) return; - - apply_floor_snap(); - move_and_slide(); animate(delta); } @@ -65,4 +65,13 @@ void Player::animate(float delta) { m_AnimationTree->set("parameters/ground_air_transition/transition_request", "air"); } } + +Vector3 Player::GetCameraRotation() const { + return m_Mesh->get_rotation(); +} + +void Player::SetCameraRotation(const Vector3& a_Rotation) { + m_Mesh->set_rotation(a_Rotation); +} + } // namespace blitz diff --git a/src/Player.h b/src/Player.h index d01a093..d69f7f9 100644 --- a/src/Player.h +++ b/src/Player.h @@ -5,6 +5,9 @@ #include namespace blitz { + +class World; + class Player : public godot::CharacterBody3D { GDCLASS(Player, godot::CharacterBody3D); @@ -20,11 +23,21 @@ class Player : public godot::CharacterBody3D { void _physics_process(float delta); void animate(float delta); - private: - godot::Node3D* m_PlayerMesh; + godot::Vector3 GetCameraRotation() const; + void SetCameraRotation(const godot::Vector3& a_Rotation); + + uint64_t GetId() const { + return m_PeerId; + } + + protected: + godot::Node3D* m_Mesh; godot::AnimationTree* m_AnimationTree; godot::Vector3 m_SnapVector; float m_Speed; + uint64_t m_PeerId; + + friend class World; }; } // namespace blitz diff --git a/src/Server.cpp b/src/Server.cpp new file mode 100644 index 0000000..883e9c2 --- /dev/null +++ b/src/Server.cpp @@ -0,0 +1,44 @@ +#include "Server.h" + +#include "Lobby.h" +#include "NetworkInterface.h" +#include + +using namespace godot; + +namespace blitz { + +void Server::_bind_methods() {} + +Server::Server() {} + +Server::~Server() {} + +void Server::_ready() { + if (Engine::get_singleton()->is_editor_hint()) + return; + + + m_Lobby = Object::cast_to(get_parent()); + DEV_ASSERT(m_Lobby); + m_NetworkInterface = Object::cast_to(m_Lobby->find_child("NetworkInterface")); + DEV_ASSERT(m_NetworkInterface); + + m_Lobby->connect("player_connected", callable_mp(this, &Server::OnPlayerConnect)); + m_Lobby->connect("player_disconnected", callable_mp(this, &Server::OnPlayerDisconnect)); +} + +void Server::OnPlayerConnect(uint64_t a_PeerId) { + for (int i = 0; i < m_Peers.size(); i++) { + m_NetworkInterface->rpc_id(a_PeerId, "AddPlayer", m_Peers[i], "Aucuneidee"); + } + m_Peers.push_back(a_PeerId); + m_NetworkInterface->rpc("AddPlayer", a_PeerId, "Aucuneidee"); +} + +void Server::OnPlayerDisconnect(uint64_t a_PeerId) { + m_Peers.erase(a_PeerId); + m_NetworkInterface->rpc("RemovePlayer", a_PeerId); +} + +} // namespace blitz \ No newline at end of file diff --git a/src/Server.h b/src/Server.h new file mode 100644 index 0000000..2f98f08 --- /dev/null +++ b/src/Server.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +namespace blitz { + +class Lobby; +class NetworkInterface; + +class Server : public godot::Node { + GDCLASS(Server, godot::Node) + protected: + static void _bind_methods(); + + public: + Server(); + ~Server(); + + void _ready() override; + + void OnPlayerConnect(uint64_t a_PeerId); + void OnPlayerDisconnect(uint64_t a_PeerId); + + private: + Lobby* m_Lobby; + NetworkInterface* m_NetworkInterface; + + godot::TypedArray m_Peers; +}; + +} // namespace blitz \ No newline at end of file diff --git a/src/World.cpp b/src/World.cpp index a39d27e..4b63e27 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1,28 +1,112 @@ #include "World.h" +#include "FirstPersonPlayer.h" +#include "NetworkInterface.h" +#include "Player.h" +#include +#include +#include +#include #include + using namespace godot; namespace blitz { -void World::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_player", "id", "name"), &World::AddPlayer); - ClassDB::bind_method(D_METHOD("remove_player", "id"), &World::RemovePlayer); +static const char FirstPersonPlayerScenePath[] = "res://Scenes/Characters/first_person_player.tscn"; +static const char PlayerScenePath[] = "res://Scenes/Characters/player.tscn"; + +void World::_bind_methods() {} + +void World::_ready() { + if (Engine::get_singleton()->is_editor_hint()) + return; + + m_Players = find_child("Players"); + DEV_ASSERT(m_Players); + + auto* lobby = get_parent()->find_child("Lobby"); + DEV_ASSERT(lobby); + + m_NetworkInterface = Object::cast_to(lobby->find_child("NetworkInterface")); + DEV_ASSERT(m_NetworkInterface); + + m_NetworkInterface->connect("AddPlayer", callable_mp(this, &World::AddPlayer)); + m_NetworkInterface->connect("RemovePlayer", callable_mp(this, &World::RemovePlayer)); + m_NetworkInterface->connect("SetPlayerPositionAndRotation", callable_mp(this, &World::SetPlayerPositionAndRotation)); } + World::World() {} World::~World() {} void World::_process(float delta) { - // do update here +#if DEBUG_ENABLED + if (Engine::get_singleton()->is_editor_hint()) + return; +#endif + if (get_multiplayer()->is_server()) { + for (int i = 0; i < m_Players->get_child_count(); i++) { + Player* player = Object::cast_to(m_Players->get_child(i)); + DEV_ASSERT(player); + m_NetworkInterface->rpc( + "SetPlayerPositionAndRotation", player->m_PeerId, player->get_position(), player->GetCameraRotation()); + } + } else { + Player* player = GetPlayerById(get_multiplayer()->get_unique_id()); + if (player) + m_NetworkInterface->rpc("SetPlayerPositionAndRotation", get_multiplayer()->get_unique_id(), player->get_position(), + player->GetCameraRotation()); + } +} + +Player* World::GetPlayerById(uint64_t a_PlayerId) { + String stringId = UtilityFunctions::var_to_str(a_PlayerId); + for (int i = 0; i < m_Players->get_child_count(); i++) { + Node* player = m_Players->get_child(i); + if (player->get_name() == stringId) { + return Object::cast_to(player); + } + } + return nullptr; } void World::AddPlayer(int32_t a_PlayerId, String a_PlayerName) { - UtilityFunctions::print_rich("New player joined ! Id : ", a_PlayerId, ", Name : ", a_PlayerName); + UtilityFunctions::print("New Player with id : ", a_PlayerId); + if (a_PlayerId == get_multiplayer()->get_unique_id()) { + Ref serverScene = ResourceLoader::get_singleton()->load(FirstPersonPlayerScenePath); + FirstPersonPlayer* player = Object::cast_to(serverScene->instantiate()); + player->set_name(UtilityFunctions::var_to_str(a_PlayerId)); + player->m_PeerId = a_PlayerId; + m_Players->add_child(player); + } else { + Ref serverScene = ResourceLoader::get_singleton()->load(PlayerScenePath); + Player* player = Object::cast_to(serverScene->instantiate()); + player->set_name(UtilityFunctions::var_to_str(a_PlayerId)); + player->m_PeerId = a_PlayerId; + m_Players->add_child(player); + } } -void World::RemovePlayer(int32_t a_PlayerId) {} +void World::RemovePlayer(int32_t a_PlayerId) { + UtilityFunctions::print("Removing Player with id : ", a_PlayerId); + Player* player = GetPlayerById(a_PlayerId); + if (player) { + player->queue_free(); + } +} + +void World::SetPlayerPositionAndRotation(int64_t a_PlayerId, Vector3 a_Position, Vector3 a_Rotation) { + if (a_PlayerId == get_multiplayer()->get_unique_id()) + return; + + Player* player = GetPlayerById(a_PlayerId); + if (player) { + player->set_position(a_Position); + player->SetCameraRotation(a_Rotation); + } +} } // namespace blitz \ No newline at end of file diff --git a/src/World.h b/src/World.h index 705d505..8618bfd 100644 --- a/src/World.h +++ b/src/World.h @@ -3,6 +3,10 @@ #include namespace blitz { + +class Player; +class NetworkInterface; + class World : public godot::Node3D { GDCLASS(World, godot::Node3D) protected: @@ -14,7 +18,17 @@ class World : public godot::Node3D { void _process(float delta); + void _ready() override; + + Player* GetPlayerById(uint64_t a_PlayerId); + void AddPlayer(int32_t a_PlayerId, godot::String a_PlayerName); void RemovePlayer(int32_t a_PlayerId); + void SetPlayerPositionAndRotation(int64_t a_PlayerId, godot::Vector3 a_Position, godot::Vector3 a_Rotation); + + private: + NetworkInterface* m_NetworkInterface; + godot::Node* m_Players; + float m_PassedTime; }; } // namespace blitz \ No newline at end of file diff --git a/src/register_types.cpp b/src/register_types.cpp index acb18e6..f58997d 100644 --- a/src/register_types.cpp +++ b/src/register_types.cpp @@ -4,7 +4,9 @@ #include "Lobby.h" #include "Main.h" #include "MainMenu.h" +#include "NetworkInterface.h" #include "Player.h" +#include "Server.h" #include "SpringArmPivot.h" #include "World.h" @@ -22,6 +24,8 @@ static void RegisterClasses() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); } void initialize_example_module(ModuleInitializationLevel p_level) { From ccb68705673cc345858294dbef5ccd117b5da7b7 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Mon, 19 Aug 2024 11:00:26 +0200 Subject: [PATCH 05/23] lock godot version --- xmake/godot.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/godot.lua b/xmake/godot.lua index f520ac5..e726c16 100644 --- a/xmake/godot.lua +++ b/xmake/godot.lua @@ -16,7 +16,7 @@ add_rules("mode.debug", "mode.release") set_languages("c++20") -- use latest 4.x version by default -add_requires("godotcpp4") +add_requires("godotcpp4 4.2") includes("tasks.lua") From 665dc4938feed62f53d95e92ff603f212e190302 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Mon, 19 Aug 2024 11:04:37 +0200 Subject: [PATCH 06/23] add blitz files --- include/blitz/common/NonCopyable.h | 25 ++ include/blitz/common/Types.h | 11 + include/blitz/protocol/ByteBuffer.h | 89 +++++++ include/blitz/protocol/PacketData.h | 72 ++++++ include/blitz/protocol/PacketDeclare.h | 49 ++++ include/blitz/protocol/PacketDispatcher.h | 58 +++++ include/blitz/protocol/PacketFactory.h | 21 ++ include/blitz/protocol/PacketHandler.h | 34 +++ include/blitz/protocol/PacketSerializer.h | 20 ++ include/blitz/protocol/PacketVisitor.h | 39 +++ include/blitz/protocol/Packets.h | 112 +++++++++ src/blitz/protocol/ByteBuffer.cpp | 49 ++++ src/blitz/protocol/PacketDispatcher.cpp | 37 +++ src/blitz/protocol/PacketFactory.cpp | 32 +++ src/blitz/protocol/PacketHandler.cpp | 14 ++ src/blitz/protocol/PacketSerializer.cpp | 294 ++++++++++++++++++++++ src/blitz/protocol/PacketVisitor.cpp | 11 + src/blitz/protocol/Packets.cpp | 18 ++ xmake/target.lua | 2 + 19 files changed, 987 insertions(+) create mode 100644 include/blitz/common/NonCopyable.h create mode 100644 include/blitz/common/Types.h create mode 100644 include/blitz/protocol/ByteBuffer.h create mode 100644 include/blitz/protocol/PacketData.h create mode 100644 include/blitz/protocol/PacketDeclare.h create mode 100644 include/blitz/protocol/PacketDispatcher.h create mode 100644 include/blitz/protocol/PacketFactory.h create mode 100644 include/blitz/protocol/PacketHandler.h create mode 100644 include/blitz/protocol/PacketSerializer.h create mode 100644 include/blitz/protocol/PacketVisitor.h create mode 100644 include/blitz/protocol/Packets.h create mode 100644 src/blitz/protocol/ByteBuffer.cpp create mode 100644 src/blitz/protocol/PacketDispatcher.cpp create mode 100644 src/blitz/protocol/PacketFactory.cpp create mode 100644 src/blitz/protocol/PacketHandler.cpp create mode 100644 src/blitz/protocol/PacketSerializer.cpp create mode 100644 src/blitz/protocol/PacketVisitor.cpp create mode 100644 src/blitz/protocol/Packets.cpp diff --git a/include/blitz/common/NonCopyable.h b/include/blitz/common/NonCopyable.h new file mode 100644 index 0000000..308a744 --- /dev/null +++ b/include/blitz/common/NonCopyable.h @@ -0,0 +1,25 @@ +#pragma once + +/** + * \file NonCopyable.h + * \brief File containing the blitz::NonCopyable class + */ + +namespace blitz { + +/** + * \class NonCopyable + * \brief Class used to make a class non copyable + * \note Inherit from this class privately to make a class non copyable + */ +class NonCopyable { + public: + NonCopyable(const NonCopyable&) = delete; + NonCopyable& operator=(const NonCopyable&) = delete; + + protected: + NonCopyable() {} + ~NonCopyable() {} +}; + +} // namespace blitz diff --git a/include/blitz/common/Types.h b/include/blitz/common/Types.h new file mode 100644 index 0000000..1208204 --- /dev/null +++ b/include/blitz/common/Types.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +namespace blitz { + +using EntityID = std::uint64_t; +using PeerID = std::int32_t; +using PlayerID = PeerID; + +} // namespace blitz diff --git a/include/blitz/protocol/ByteBuffer.h b/include/blitz/protocol/ByteBuffer.h new file mode 100644 index 0000000..5540bae --- /dev/null +++ b/include/blitz/protocol/ByteBuffer.h @@ -0,0 +1,89 @@ +#pragma once + +#include +#include +#include + +namespace blitz { +namespace protocol { + +class PlayerInfo; + +#define Operators(Type, GodotType) \ + ByteBuffer& operator>>(Type& a_Data) { \ + a_Data = m_Buffer.decode_##GodotType(m_ReadOffset); \ + m_ReadOffset += sizeof(a_Data); \ + return *this; \ + } \ + \ + ByteBuffer& operator<<(Type a_Data) { \ + m_Buffer.resize(m_Buffer.size() + sizeof(a_Data)); \ + m_Buffer.encode_##GodotType(m_Buffer.size() - sizeof(a_Data), a_Data); \ + return *this; \ + } + +class ByteBuffer { + private: + godot::PackedByteArray m_Buffer; + std::size_t m_ReadOffset; + + public: + ByteBuffer(godot::PackedByteArray&& a_Buffer) : m_Buffer(std::move(a_Buffer)), m_ReadOffset(0) {} + ByteBuffer() : m_ReadOffset(0) { + m_Buffer.resize(0); + } + + const godot::PackedByteArray& GetByteArray() const { + return m_Buffer; + } + + godot::PackedByteArray& GetByteArray() { + return m_Buffer; + } + + // Integers + Operators(int8_t, s8); + Operators(uint8_t, u8); + Operators(int16_t, s16); + Operators(uint16_t, u16); + Operators(int32_t, s32); + Operators(uint32_t, u32); + Operators(int64_t, s64); + Operators(uint64_t, u64); + + // Reals + Operators(float, float); + Operators(double, double); + + ByteBuffer& operator<<(const godot::String& a_Data); + ByteBuffer& operator>>(godot::String& a_Data); + + ByteBuffer& operator<<(const godot::Vector3& a_Data); + ByteBuffer& operator>>(godot::Vector3& a_Data); + + template + ByteBuffer& operator<<(const std::vector& a_Data) { + *this << static_cast(a_Data.size()); + for (const T& data : a_Data) { + *this << data; + } + return *this; + } + + template + ByteBuffer& operator>>(std::vector& a_Data) { + std::uint32_t arraySize; + *this >> arraySize; + a_Data.resize(arraySize); + for (std::uint32_t i = 0; i < arraySize; i++) { + *this >> a_Data[i]; + } + return *this; + } + + ByteBuffer& operator<<(const PlayerInfo& a_Data); + ByteBuffer& operator>>(PlayerInfo& a_Data); +}; + +} // namespace protocol +} // namespace blitz diff --git a/include/blitz/protocol/PacketData.h b/include/blitz/protocol/PacketData.h new file mode 100644 index 0000000..0587af7 --- /dev/null +++ b/include/blitz/protocol/PacketData.h @@ -0,0 +1,72 @@ +#pragma once + +#include +#include +#include +#include + +namespace blitz { +namespace protocol { + +struct PlayerInfo { + PlayerID m_PlayerId; + godot::String m_PlayerName; +}; + +namespace data { + +struct PlayerLogin { + godot::String m_PlayerName; +}; + +struct UpdateHealth { + float m_NewHealth; +}; + +struct LoggingSuccess { + PlayerID m_PlayerId; +}; + +struct PlayerDeath {}; + +struct PlayerJoin { + PlayerInfo m_Player; +}; + +struct PlayerLeave { + PlayerID m_PlayerId; +}; + +struct PlayerStats {}; + +struct PlayerList { + std::vector m_Players; +}; + +struct ServerConfig {}; + +struct ServerTps {}; + +struct UpdateGameState {}; + +struct KeepAlive { + std::uint64_t m_KeepAliveId; +}; + +struct Disconnect {}; + +struct ChatMessage { + godot::String m_Text; +}; + +struct PlayerPositionAndRotation { + PlayerID m_Player; + godot::Vector3 m_Position; + godot::Vector3 m_Rotation; +}; + +struct PlayerShoot {}; + +} // namespace data +} // namespace protocol +} // namespace blitz diff --git a/include/blitz/protocol/PacketDeclare.h b/include/blitz/protocol/PacketDeclare.h new file mode 100644 index 0000000..a4340cb --- /dev/null +++ b/include/blitz/protocol/PacketDeclare.h @@ -0,0 +1,49 @@ +#pragma once + +/** + * \file PacketDeclare.h + * \brief Holds the definitions of the packets (but not their content) + */ + +namespace blitz { +namespace protocol { + +/** + * \enum PacketSender + * \brief Indicate who should send a packet + */ +enum class PacketSender { + /** Sent by clients and server */ + Both, + /** Sent by clients to the server */ + Client, + /** Sent by server to the clients */ + Server, +}; + + +/** + * \def DeclareAllPacket + * \brief Avoids repetitive operations on packets + */ +#define DeclareAllPacket() \ + DeclarePacket(ChatMessage, Reliable, Both) \ + DeclarePacket(Disconnect, Reliable, Both) \ + DeclarePacket(KeepAlive, Reliable, Both) \ + DeclarePacket(LoggingSuccess, Reliable, Server) \ + DeclarePacket(PlayerDeath, Reliable, Server) \ + DeclarePacket(PlayerJoin, Reliable, Server) \ + DeclarePacket(PlayerLeave, Reliable, Server) \ + DeclarePacket(PlayerList, Reliable, Server) \ + DeclarePacket(PlayerLogin, Reliable, Client) \ + DeclarePacket(PlayerPositionAndRotation, Reliable, Both) \ + DeclarePacket(PlayerShoot, Reliable, Both) \ + DeclarePacket(PlayerStats, Reliable, Server) \ + DeclarePacket(ServerConfig, Reliable, Server) \ + DeclarePacket(ServerTps, Reliable, Server) \ + DeclarePacket(UpdateGameState, Reliable, Server) \ + DeclarePacket(UpdateHealth, Reliable, Client) + + +} // namespace protocol +} // namespace blitz \ No newline at end of file diff --git a/include/blitz/protocol/PacketDispatcher.h b/include/blitz/protocol/PacketDispatcher.h new file mode 100644 index 0000000..4e9b32d --- /dev/null +++ b/include/blitz/protocol/PacketDispatcher.h @@ -0,0 +1,58 @@ +#pragma once + +/** + * \file PacketDispatcher.h + * \brief File containing the blitz::protocol::PacketDispatcher class + */ + +#include +#include + +#include + +namespace blitz { +namespace protocol { + +class PacketHandler; + +/** + * \class PacketDispatcher + * \brief Class used to dispatch packets + */ +class PacketDispatcher : private NonCopyable { + private: + std::map> m_Handlers; + + public: + /** + * \brief Constructor + */ + PacketDispatcher() {} + + /** + * \brief Dispatch a packet + * \param packet The packet to dispatch + */ + void Dispatch(const Packet& packet); + + /** + * \brief Register a packet handler + * \param type The packet type + * \param handler The packet handler + */ + void RegisterHandler(PacketType type, PacketHandler& handler); + /** + * \brief Unregister a packet handler + * \param type The packet type + * \param handler The packet handler + */ + void UnregisterHandler(PacketType type, PacketHandler& handler); + /** + * \brief Unregister a packet handler + * \param handler The packet handler + */ + void UnregisterHandler(PacketHandler& handler); +}; + +} // namespace protocol +} // namespace blitz diff --git a/include/blitz/protocol/PacketFactory.h b/include/blitz/protocol/PacketFactory.h new file mode 100644 index 0000000..88ed43f --- /dev/null +++ b/include/blitz/protocol/PacketFactory.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +namespace blitz { +namespace protocol { +namespace PacketFactory { + +template::value>::type> +std::unique_ptr CreatePacket() { + return std::make_unique(); +} + +const std::unique_ptr& CreateReadOnlyPacket(PacketType a_Type); + +void Init(); + +} // namespace PacketFactory +} // namespace protocol +} // namespace blitz diff --git a/include/blitz/protocol/PacketHandler.h b/include/blitz/protocol/PacketHandler.h new file mode 100644 index 0000000..e99b731 --- /dev/null +++ b/include/blitz/protocol/PacketHandler.h @@ -0,0 +1,34 @@ +#pragma once + +/** + * \file PacketHandler.h + * \brief File containing the blitz::protocol::PacketHandler class + */ + +#include +#include + +namespace blitz { +namespace protocol { + +class PacketDispatcher; + +#define DeclarePacket(PacketName, ...) virtual void Visit(const packets::PacketName&); virtual void HandlePacket(const packets::PacketName&) {} + +/** + * \class PacketHandler + * \brief Class used to handle packets + */ +class PacketHandler : public PacketVisitor { + public: + PacketHandler() {} + ~PacketHandler() {} + + DeclareAllPacket() + +}; + +#undef DeclarePacket + +} // namespace protocol +} // namespace blitz \ No newline at end of file diff --git a/include/blitz/protocol/PacketSerializer.h b/include/blitz/protocol/PacketSerializer.h new file mode 100644 index 0000000..f797525 --- /dev/null +++ b/include/blitz/protocol/PacketSerializer.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include + +namespace blitz { +namespace protocol { + +using PacketPtr = std::unique_ptr; + +namespace PacketSerializer { + +godot::PackedByteArray Serialize(const Packet& a_Packet); + +std::unique_ptr Deserialize(godot::PackedByteArray& a_Data); + +} +} // namespace protocol +} // namespace blitz diff --git a/include/blitz/protocol/PacketVisitor.h b/include/blitz/protocol/PacketVisitor.h new file mode 100644 index 0000000..1f41f53 --- /dev/null +++ b/include/blitz/protocol/PacketVisitor.h @@ -0,0 +1,39 @@ +#pragma once + +/** + * \file PacketVisitor.h + * \brief File containing the blitz::protocol::PacketVisitor class + */ + +#include + +namespace blitz { +namespace protocol { + +#define DeclarePacket(PacketName, ...) \ + /** This function is called when the packet processed by PacketVisitor::Check is a PacketName */ \ + virtual void Visit(const packets::PacketName&) {} + +/** + * \class PacketVisitor + * \brief This class uses double-dispatch in order to find the real type of a packet + */ +class PacketVisitor : private NonCopyable { + protected: + PacketVisitor() {} + virtual ~PacketVisitor() {} + + public: + /** + * \brief Calls the right PacketVisitor::Visit method corresponding to the real type of the packet + * \param packet the Packet to visit + */ + void Check(const Packet& packet); + + DeclareAllPacket() +}; + +#undef DeclarePacket + +} // namespace protocol +} // namespace blitz diff --git a/include/blitz/protocol/Packets.h b/include/blitz/protocol/Packets.h new file mode 100644 index 0000000..f0d47f6 --- /dev/null +++ b/include/blitz/protocol/Packets.h @@ -0,0 +1,112 @@ +#pragma once + +/** + * \file Packets.h + * \brief File containing the definitions of the packets + */ + +#include +#include +#include + +namespace blitz { +namespace protocol { + +class PacketVisitor; + +/** A Packet id is 8 bits wide */ +using PacketID = std::uint8_t; + +#define DeclarePacket(PacketName, ...) /** PacketName */ PacketName, + +/** + * \enum PacketType + * \brief Map a Packet to an id + */ +enum class PacketType : PacketID { + + DeclareAllPacket() + + /** The number of packets */ + PACKET_COUNT +}; + + +#undef DeclarePacket + + +class Packet : private NonCopyable { + public: + /** + * \return The real type of the packet + */ + virtual PacketType GetType() const = 0; + + /** + * \brief The network peer who sent the packet + */ + PeerID m_Sender; + + private: + /** Use a PacketVisitor to make double-dispatch possible */ + virtual void Accept(PacketVisitor& a_Visitor) const = 0; + + friend class PacketVisitor; +}; + + + + + +namespace packets { + +/** + * \class ConcretePacket + * \brief A Packet associated with an id and holding data + * \tparam PT The packet type + * \tparam Data The structure holding the data of the packet (in blitz::protocol::data namespace) + */ +template +class ConcretePacket : public Packet { + public: + /** The type of the struct holding the data */ + using PacketDataType = Data; + + /** The structure holding the actual data */ + PacketDataType m_Data; + + /** Construct the packet with data of type PacketDataType */ + ConcretePacket(const PacketDataType& a_Data = {}); + + constexpr PacketType GetType() const override { + return PT; + }; + + private: + void Accept(PacketVisitor& a_Visitor) const override; +}; + + + + + +// define BLITZ_INSTANCIATE_PACKETS +// before including this file +// if you want to instantiate templates +#ifdef BLITZ_INSTANCIATE_PACKETS +#define DeclarePacket(PacketName, ...) \ + using PacketName = ConcretePacket; \ + template class ConcretePacket; +#else +#define DeclarePacket(PacketName, ...) /** Defines the PacketName packet */ \ + using PacketName = ConcretePacket; +#endif + +DeclareAllPacket() + +#undef DeclarePacket + +} // namespace packets + +} // namespace protocol +} // namespace blitz diff --git a/src/blitz/protocol/ByteBuffer.cpp b/src/blitz/protocol/ByteBuffer.cpp new file mode 100644 index 0000000..1916f7e --- /dev/null +++ b/src/blitz/protocol/ByteBuffer.cpp @@ -0,0 +1,49 @@ +#include + +#include + +namespace blitz { +namespace protocol { + +ByteBuffer& ByteBuffer::operator>>(PlayerInfo& a_Data) { + *this >> a_Data.m_PlayerId >> a_Data.m_PlayerName; + return *this; +} + +ByteBuffer& ByteBuffer::operator<<(const PlayerInfo& a_Data) { + *this << a_Data.m_PlayerId << a_Data.m_PlayerName; + return *this; +} + +ByteBuffer& ByteBuffer::operator<<(const godot::Vector3& a_Data) { + *this << a_Data.x << a_Data.y << a_Data.z; + return *this; +} + +ByteBuffer& ByteBuffer::operator>>(godot::Vector3& a_Data) { + *this >> a_Data.x >> a_Data.y >> a_Data.z; + return *this; +} + +ByteBuffer& ByteBuffer::operator>>(godot::String& a_Data) { + int nullPos = m_Buffer.find(0, m_ReadOffset); + // TODO: error handling + if (nullPos < 0) + return *this; + + godot::PackedByteArray stringBuffer = m_Buffer.slice(m_ReadOffset, nullPos); + a_Data = stringBuffer.get_string_from_utf8(); + m_ReadOffset = nullPos + 1; + return *this; +} + +ByteBuffer& ByteBuffer::operator<<(const godot::String& a_Data) { + godot::PackedByteArray stringBuffer = a_Data.to_utf8_buffer(); + m_Buffer.append_array(stringBuffer); + // ends the string + *this << static_cast(0); + return *this; +} + +} // namespace protocol +} // namespace blitz diff --git a/src/blitz/protocol/PacketDispatcher.cpp b/src/blitz/protocol/PacketDispatcher.cpp new file mode 100644 index 0000000..b704fa3 --- /dev/null +++ b/src/blitz/protocol/PacketDispatcher.cpp @@ -0,0 +1,37 @@ +#include + +#include +#include + +namespace blitz { +namespace protocol { + +void PacketDispatcher::RegisterHandler(PacketType type, PacketHandler& handler) { + auto found = std::find(m_Handlers[type].begin(), m_Handlers[type].end(), &handler); + if (found == m_Handlers[type].end()) + m_Handlers[type].push_back(&handler); +} + +void PacketDispatcher::UnregisterHandler(PacketType type, PacketHandler& handler) { + m_Handlers[type].erase(std::remove(m_Handlers[type].begin(), m_Handlers[type].end(), &handler), m_Handlers[type].end()); +} + +void PacketDispatcher::UnregisterHandler(PacketHandler& handler) { + for (auto& pair : m_Handlers) { + if (pair.second.empty()) + continue; + + PacketType type = pair.first; + + m_Handlers[type].erase(std::remove(m_Handlers[type].begin(), m_Handlers[type].end(), &handler), m_Handlers[type].end()); + } +} + +void PacketDispatcher::Dispatch(const Packet& packet) { + PacketType type = packet.GetType(); + for (PacketHandler* handler : m_Handlers[type]) + handler->Check(packet); +} + +} // namespace protocol +} // namespace blitz diff --git a/src/blitz/protocol/PacketFactory.cpp b/src/blitz/protocol/PacketFactory.cpp new file mode 100644 index 0000000..d21743f --- /dev/null +++ b/src/blitz/protocol/PacketFactory.cpp @@ -0,0 +1,32 @@ +#include + +#include +#include +#include + +namespace blitz { +namespace protocol { +namespace PacketFactory { + +using PacketCreator = std::function()>; + +#define DeclarePacket(PacketName, ...) std::make_unique(), + +static std::array, static_cast(PacketType::PACKET_COUNT)> Packets; + +void Init() { + Packets = { + + DeclareAllPacket() + + }; +} + +const std::unique_ptr& CreateReadOnlyPacket(PacketType a_Type) { + assert(a_Type < PacketType::PACKET_COUNT); + return Packets[static_cast(a_Type)]; +} + +} // namespace PacketFactory +} // namespace protocol +} // namespace blitz diff --git a/src/blitz/protocol/PacketHandler.cpp b/src/blitz/protocol/PacketHandler.cpp new file mode 100644 index 0000000..4d68fbc --- /dev/null +++ b/src/blitz/protocol/PacketHandler.cpp @@ -0,0 +1,14 @@ +#include + +namespace blitz { +namespace protocol { + +#define DeclarePacket(PacketName, ...) \ + void PacketHandler::Visit(const packets::PacketName& a_Packet) { \ + HandlePacket(a_Packet); \ + } + +DeclareAllPacket() + +} // namespace protocol +} // namespace blitz diff --git a/src/blitz/protocol/PacketSerializer.cpp b/src/blitz/protocol/PacketSerializer.cpp new file mode 100644 index 0000000..74b7bb1 --- /dev/null +++ b/src/blitz/protocol/PacketSerializer.cpp @@ -0,0 +1,294 @@ +#include + +#include +#include +#include + +#include +#include + +namespace blitz { +namespace protocol { +namespace PacketSerializer { + +#define DeclarePacket(PacketName, ...) \ + void Visit(const packets::PacketName& a_Packet) override { \ + const auto& packetData = a_Packet.m_Data; \ + SerializePacketData(packetData); \ + } \ + \ + void SerializePacketData(const packets::PacketName::PacketDataType& a_Packet); + + + + +class Serializer : public PacketVisitor { + private: + ByteBuffer& m_Buffer; + + public: + Serializer(ByteBuffer& a_Buffer) : m_Buffer(a_Buffer) {} + + void Serialize(const Packet& a_Packet) { + m_Buffer << static_cast(a_Packet.GetType()); + Check(a_Packet); + } + + DeclareAllPacket() +}; + +#undef DeclarePacket + + + + + +#define DeclarePacket(PacketName, ...) \ + void Visit(const packets::PacketName& a_Packet) override { \ + auto packetPtr = PacketFactory::CreatePacket(); \ + auto& packetData = packetPtr->m_Data; \ + \ + DeserializePacketData(packetData); \ + \ + m_Packet = std::move(packetPtr); \ + } \ + \ + void DeserializePacketData(packets::PacketName::PacketDataType& a_Packet); + + + +class Deserializer : public PacketVisitor { + private: + ByteBuffer& m_Buffer; + PacketPtr m_Packet; + + public: + Deserializer(ByteBuffer&& a_Buffer) : m_Buffer(a_Buffer) {} + + bool Deserialize(const PacketPtr& a_Packet) { + try { + Check(*a_Packet.get()); + } catch (std::exception& e) { + return false; + } + return true; + } + + PacketPtr& GetPacket() { + return m_Packet; + } + + DeclareAllPacket() +}; + + + + + +godot::PackedByteArray Serialize(const Packet& a_Packet) { + ByteBuffer stream; + + Serializer serializer(stream); + serializer.Serialize(a_Packet); + + return stream.GetByteArray(); +} + +std::unique_ptr Deserialize(godot::PackedByteArray& a_Data) { + ByteBuffer stream(std::move(a_Data)); + + PacketID packetId; + stream >> packetId; + + if (packetId >= static_cast(PacketType::PACKET_COUNT)) + return nullptr; + + PacketType packetType = PacketType(packetId); + + // for double-dispatch + const PacketPtr& emptyPacket = PacketFactory::CreateReadOnlyPacket(packetType); + + Deserializer deserializer(std::move(stream)); + if (deserializer.Deserialize(emptyPacket)) { + PacketPtr packet = std::move(deserializer.GetPacket()); + return packet; + } + + return nullptr; +} + + + + + +//--------------------------------------------- +// Packet serializer implementation +//---------------------------------------------- + + + + + +void Serializer::SerializePacketData(const data::PlayerLogin& a_Packet) { + m_Buffer << a_Packet.m_PlayerName; +} + +void Deserializer::DeserializePacketData(data::PlayerLogin& a_Packet) { + m_Buffer >> a_Packet.m_PlayerName; +} + + + + +void Serializer::SerializePacketData(const data::UpdateHealth& a_Packet) { + m_Buffer << a_Packet.m_NewHealth; +} + +void Deserializer::DeserializePacketData(data::UpdateHealth& a_Packet) { + m_Buffer >> a_Packet.m_NewHealth; +} + + + + +void Serializer::SerializePacketData(const data::LoggingSuccess& a_Packet) { + m_Buffer << a_Packet.m_PlayerId; +} + +void Deserializer::DeserializePacketData(data::LoggingSuccess& a_Packet) { + m_Buffer >> a_Packet.m_PlayerId; +} + + + + +void Serializer::SerializePacketData(const data::PlayerDeath& a_Packet) {} + +void Deserializer::DeserializePacketData(data::PlayerDeath& a_Packet) {} + + + + +void Serializer::SerializePacketData(const data::PlayerJoin& a_Packet) { + m_Buffer << a_Packet.m_Player; +} + +void Deserializer::DeserializePacketData(data::PlayerJoin& a_Packet) { + m_Buffer >> a_Packet.m_Player; +} + + + + +void Serializer::SerializePacketData(const data::PlayerLeave& a_Packet) { + m_Buffer << a_Packet.m_PlayerId; +} + +void Deserializer::DeserializePacketData(data::PlayerLeave& a_Packet) { + m_Buffer >> a_Packet.m_PlayerId; +} + + + + +void Serializer::SerializePacketData(const data::PlayerList& a_Packet) { + m_Buffer << a_Packet.m_Players; + // m_Buffer << static_cast(a_Packet.m_Players.size()); + // for (auto player : a_Packet.m_Players) { + // m_Buffer << player.m_PlayerId << player.m_PlayerName; + // } +} + +void Deserializer::DeserializePacketData(data::PlayerList& a_Packet) { + m_Buffer >> a_Packet.m_Players; + // std::uint8_t playerCount; + // m_Buffer >> playerCount; + // for (std::uint8_t i = 0; i < playerCount; i++) { + // PlayerInfo player; + // m_Buffer >> player.m_PlayerId >> player.m_PlayerName; + // a_Packet.m_Players.push_back(player); + // } +} + + + + +void Serializer::SerializePacketData(const data::PlayerStats& a_Packet) {} + +void Deserializer::DeserializePacketData(data::PlayerStats& a_Packet) {} + + + + +void Serializer::SerializePacketData(const data::ServerConfig& a_Packet) {} + +void Deserializer::DeserializePacketData(data::ServerConfig& a_Packet) {} + + + + +void Serializer::SerializePacketData(const data::ServerTps& a_Packet) {} + +void Deserializer::DeserializePacketData(data::ServerTps& a_Packet) {} + + + + +void Serializer::SerializePacketData(const data::UpdateGameState& a_Packet) {} + +void Deserializer::DeserializePacketData(data::UpdateGameState& a_Packet) {} + + + + +void Serializer::SerializePacketData(const data::KeepAlive& a_Packet) { + m_Buffer << a_Packet.m_KeepAliveId; +} + +void Deserializer::DeserializePacketData(data::KeepAlive& a_Packet) { + m_Buffer >> a_Packet.m_KeepAliveId; +} + + + + +void Serializer::SerializePacketData(const data::Disconnect& a_Packet) {} + +void Deserializer::DeserializePacketData(data::Disconnect& a_Packet) {} + + + + +void Serializer::SerializePacketData(const data::ChatMessage& a_Packet) { + m_Buffer << a_Packet.m_Text; +} + +void Deserializer::DeserializePacketData(data::ChatMessage& a_Packet) { + m_Buffer >> a_Packet.m_Text; +} + + + + +void Serializer::SerializePacketData(const data::PlayerPositionAndRotation& a_Packet) { + m_Buffer << a_Packet.m_Player << a_Packet.m_Position << a_Packet.m_Rotation; +} + +void Deserializer::DeserializePacketData(data::PlayerPositionAndRotation& a_Packet) { + m_Buffer >> a_Packet.m_Player >> a_Packet.m_Position >> a_Packet.m_Rotation; +} + + + + +void Serializer::SerializePacketData(const data::PlayerShoot& a_Packet) {} + +void Deserializer::DeserializePacketData(data::PlayerShoot& a_Packet) {} + + + + + +} // namespace PacketSerializer +} // namespace protocol +} // namespace blitz diff --git a/src/blitz/protocol/PacketVisitor.cpp b/src/blitz/protocol/PacketVisitor.cpp new file mode 100644 index 0000000..90f1382 --- /dev/null +++ b/src/blitz/protocol/PacketVisitor.cpp @@ -0,0 +1,11 @@ +#include + +namespace blitz { +namespace protocol { + +void PacketVisitor::Check(const Packet& a_Packet) { + a_Packet.Accept(*this); +} + +} // namespace protocol +} // namespace blitz diff --git a/src/blitz/protocol/Packets.cpp b/src/blitz/protocol/Packets.cpp new file mode 100644 index 0000000..84913b0 --- /dev/null +++ b/src/blitz/protocol/Packets.cpp @@ -0,0 +1,18 @@ +#define BLITZ_INSTANCIATE_PACKETS +#include + +#include + +namespace blitz { +namespace protocol { + +template +packets::ConcretePacket::ConcretePacket(const PacketDataType& a_Data) : m_Data(a_Data) {} + +template +void packets::ConcretePacket::Accept(PacketVisitor& a_Visitor) const { + a_Visitor.Visit(*this); +} + +} // namespace protocol +} // namespace blitz diff --git a/xmake/target.lua b/xmake/target.lua index f5d56a4..8ce9c00 100644 --- a/xmake/target.lua +++ b/xmake/target.lua @@ -14,6 +14,8 @@ target(PROJECT_NAME) -- more on https://xmake.io/#/manual/project_target?id=targetadd_files add_files("../src/**.cpp") + add_includedirs("../include") + -- change the output name set_basename(PROJECT_NAME .. ".$(os)_$(mode)_$(arch)") From 15a385a8251b2fa431e5bd9d5b7a9e286e247a8f Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Mon, 19 Aug 2024 11:05:47 +0200 Subject: [PATCH 07/23] better networking --- src/Lobby.cpp | 4 +-- src/Lobby.h | 4 +-- src/NetworkInterface.cpp | 55 +++++++++++++++------------------- src/NetworkInterface.h | 14 +++++---- src/Player.h | 5 ++-- src/Server.cpp | 11 +++---- src/Server.h | 7 +++-- src/World.cpp | 64 +++++++++++++++++++++++++++++----------- src/World.h | 21 ++++++++----- 9 files changed, 111 insertions(+), 74 deletions(-) diff --git a/src/Lobby.cpp b/src/Lobby.cpp index 105c6c9..db517dd 100644 --- a/src/Lobby.cpp +++ b/src/Lobby.cpp @@ -70,13 +70,13 @@ void Lobby::Shutdown() { } } -void Lobby::OnPlayerConnected(int64_t a_PeerId) { +void Lobby::OnPlayerConnected(PeerID a_PeerId) { if (get_multiplayer()->is_server()) { emit_signal("player_connected", a_PeerId); } } -void Lobby::OnPlayerDisconnected(int64_t a_PeerId) { +void Lobby::OnPlayerDisconnected(PeerID a_PeerId) { if (get_multiplayer()->is_server()) { emit_signal("player_disconnected", a_PeerId); } diff --git a/src/Lobby.h b/src/Lobby.h index ffa49cf..58d6a72 100644 --- a/src/Lobby.h +++ b/src/Lobby.h @@ -22,8 +22,8 @@ class Lobby : public godot::Node { void Shutdown(); private: - void OnPlayerConnected(int64_t a_PeerId); - void OnPlayerDisconnected(int64_t a_PeerId); + void OnPlayerConnected(PeerID a_PeerId); + void OnPlayerDisconnected(PeerID a_PeerId); void OnConnectOk(); void OnConnectFail(); void OnServerDisconnected(); diff --git a/src/NetworkInterface.cpp b/src/NetworkInterface.cpp index b71bc4b..f01efa2 100644 --- a/src/NetworkInterface.cpp +++ b/src/NetworkInterface.cpp @@ -1,5 +1,7 @@ #include "NetworkInterface.h" +#include +#include #include #include #include @@ -9,49 +11,40 @@ namespace blitz { using namespace godot; void NetworkInterface::_bind_methods() { - ClassDB::bind_method(D_METHOD("AddPlayer", "a_PlayerId", "a_PlayerName"), &NetworkInterface::AddPlayer); - ClassDB::bind_method(D_METHOD("RemovePlayer", "a_PlayerId"), &NetworkInterface::RemovePlayer); - ClassDB::bind_method(D_METHOD("SetPlayerPositionAndRotation", "a_PlayerId", "a_Position", "a_Rotation"), - &NetworkInterface::SetPlayerPositionAndRotation); - - ADD_SIGNAL(MethodInfo("AddPlayer", PropertyInfo(Variant::INT, "a_PlayerId"), PropertyInfo(Variant::STRING, "a_PlayerName"))); - ADD_SIGNAL(MethodInfo("RemovePlayer", PropertyInfo(Variant::INT, "a_PlayerId"))); - ADD_SIGNAL(MethodInfo("SetPlayerPositionAndRotation", PropertyInfo(Variant::INT, "a_PlayerId"), - PropertyInfo(Variant::VECTOR3, "a_Position"), PropertyInfo(Variant::VECTOR3, "a_Rotation"))); + ClassDB::bind_method(D_METHOD("RecievePacketDataReliable", "a_PacketData"), &NetworkInterface::RecievePacketDataReliable); + protocol::PacketFactory::Init(); } NetworkInterface::NetworkInterface() {} NetworkInterface::~NetworkInterface() {} -void NetworkInterface::AddPlayer(int64_t a_PlayerId, godot::String a_PlayerName) { - emit_signal("AddPlayer", a_PlayerId, a_PlayerName); -} - -void NetworkInterface::RemovePlayer(int64_t a_PlayerId) { - emit_signal("RemovePlayer", a_PlayerId); -} - -void NetworkInterface::SetPlayerPositionAndRotation(int64_t a_PlayerId, Vector3 a_Position, Vector3 a_Rotation) { - emit_signal("SetPlayerPositionAndRotation", a_PlayerId, a_Position, a_Rotation); -} - void NetworkInterface::_ready() { + // TODO: unreliable Dictionary config; - config["rpc_mode"] = MultiplayerAPI::RPC_MODE_AUTHORITY; + config["rpc_mode"] = MultiplayerAPI::RPC_MODE_ANY_PEER; config["transfer_mode"] = MultiplayerPeer::TRANSFER_MODE_RELIABLE; config["call_local"] = true; config["channel"] = 0; - rpc_config("AddPlayer", config); - rpc_config("RemovePlayer", config); - - Dictionary config2; - config["transfer_mode"] = MultiplayerPeer::TRANSFER_MODE_RELIABLE; - config["channel"] = 0; - config2["rpc_mode"] = MultiplayerAPI::RPC_MODE_ANY_PEER; - config2["call_local"] = false; - rpc_config("SetPlayerPositionAndRotation", config2); + rpc_config("RecievePacketDataReliable", config); } +void NetworkInterface::BroadcastPacket(const protocol::Packet& a_Packet) { + PackedByteArray byteArray = protocol::PacketSerializer::Serialize(a_Packet); + rpc("RecievePacketDataReliable", byteArray); +} + +void NetworkInterface::SendPacket(PeerID a_Peer, const protocol::Packet& a_Packet) { + PackedByteArray byteArray = protocol::PacketSerializer::Serialize(a_Packet); + rpc_id(a_Peer, "RecievePacketDataReliable", byteArray); +} + +void NetworkInterface::RecievePacketDataReliable(godot::PackedByteArray a_PacketData) { + auto packet = protocol::PacketSerializer::Deserialize(a_PacketData); + if (packet) { + packet->m_Sender = get_multiplayer()->get_remote_sender_id(); + Dispatch(*packet); + } +} } // namespace blitz \ No newline at end of file diff --git a/src/NetworkInterface.h b/src/NetworkInterface.h index 0b86a1a..6b6510e 100644 --- a/src/NetworkInterface.h +++ b/src/NetworkInterface.h @@ -1,9 +1,11 @@ #pragma once +#include #include +#include namespace blitz { -class NetworkInterface : public godot::Node { +class NetworkInterface : public godot::Node, public protocol::PacketDispatcher { GDCLASS(NetworkInterface, godot::Node) protected: static void _bind_methods(); @@ -12,11 +14,13 @@ class NetworkInterface : public godot::Node { NetworkInterface(); ~NetworkInterface(); - void AddPlayer(int64_t a_PlayerId, godot::String a_PlayerName); - void RemovePlayer(int64_t a_PlayerId); - void SetPlayerPositionAndRotation(int64_t a_PlayerId, godot::Vector3 a_Position, godot::Vector3 a_Rotation); + void BroadcastPacket(const protocol::Packet& a_Packet); + void SendPacket(PeerID a_Peer, const protocol::Packet& a_Packet); - void _ready() override; + void _ready() override; + + private: + void RecievePacketDataReliable(godot::PackedByteArray a_PacketData); }; } // namespace blitz \ No newline at end of file diff --git a/src/Player.h b/src/Player.h index d69f7f9..5f1cc9f 100644 --- a/src/Player.h +++ b/src/Player.h @@ -3,6 +3,7 @@ #include #include #include +#include namespace blitz { @@ -26,7 +27,7 @@ class Player : public godot::CharacterBody3D { godot::Vector3 GetCameraRotation() const; void SetCameraRotation(const godot::Vector3& a_Rotation); - uint64_t GetId() const { + PlayerID GetId() const { return m_PeerId; } @@ -36,7 +37,7 @@ class Player : public godot::CharacterBody3D { godot::Vector3 m_SnapVector; float m_Speed; - uint64_t m_PeerId; + PeerID m_PeerId; friend class World; }; diff --git a/src/Server.cpp b/src/Server.cpp index 883e9c2..b6ee784 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -28,17 +28,18 @@ void Server::_ready() { m_Lobby->connect("player_disconnected", callable_mp(this, &Server::OnPlayerDisconnect)); } -void Server::OnPlayerConnect(uint64_t a_PeerId) { +void Server::OnPlayerConnect(PeerID a_PeerId) { + protocol::PlayerInfo playerInfo{a_PeerId, "whoami"}; for (int i = 0; i < m_Peers.size(); i++) { - m_NetworkInterface->rpc_id(a_PeerId, "AddPlayer", m_Peers[i], "Aucuneidee"); + m_NetworkInterface->SendPacket(a_PeerId, protocol::packets::PlayerJoin({m_Peers[i], "whoami"})); } m_Peers.push_back(a_PeerId); - m_NetworkInterface->rpc("AddPlayer", a_PeerId, "Aucuneidee"); + m_NetworkInterface->BroadcastPacket(protocol::packets::PlayerJoin({playerInfo})); } -void Server::OnPlayerDisconnect(uint64_t a_PeerId) { +void Server::OnPlayerDisconnect(PeerID a_PeerId) { m_Peers.erase(a_PeerId); - m_NetworkInterface->rpc("RemovePlayer", a_PeerId); + m_NetworkInterface->BroadcastPacket(protocol::packets::PlayerLeave({a_PeerId})); } } // namespace blitz \ No newline at end of file diff --git a/src/Server.h b/src/Server.h index 2f98f08..c2debff 100644 --- a/src/Server.h +++ b/src/Server.h @@ -1,6 +1,7 @@ #pragma once #include +#include namespace blitz { @@ -18,14 +19,14 @@ class Server : public godot::Node { void _ready() override; - void OnPlayerConnect(uint64_t a_PeerId); - void OnPlayerDisconnect(uint64_t a_PeerId); + void OnPlayerConnect(PeerID a_PeerId); + void OnPlayerDisconnect(PeerID a_PeerId); private: Lobby* m_Lobby; NetworkInterface* m_NetworkInterface; - godot::TypedArray m_Peers; + godot::TypedArray m_Peers; }; } // namespace blitz \ No newline at end of file diff --git a/src/World.cpp b/src/World.cpp index 4b63e27..f9f4bc7 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -32,37 +32,53 @@ void World::_ready() { m_NetworkInterface = Object::cast_to(lobby->find_child("NetworkInterface")); DEV_ASSERT(m_NetworkInterface); - m_NetworkInterface->connect("AddPlayer", callable_mp(this, &World::AddPlayer)); - m_NetworkInterface->connect("RemovePlayer", callable_mp(this, &World::RemovePlayer)); - m_NetworkInterface->connect("SetPlayerPositionAndRotation", callable_mp(this, &World::SetPlayerPositionAndRotation)); + m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerJoin, *this); + m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerLeave, *this); + m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerPositionAndRotation, *this); } World::World() {} -World::~World() {} +World::~World() { + if (Engine::get_singleton()->is_editor_hint()) + return; + + m_NetworkInterface->UnregisterHandler(*this); +} void World::_process(float delta) { #if DEBUG_ENABLED if (Engine::get_singleton()->is_editor_hint()) return; #endif + m_PassedTime += delta; + if (m_PassedTime < 0.05f) + return; + + // UtilityFunctions::print(m_PassedTime); + + // m_PassedTime -= 0.05f; + // if (m_PassedTime > 0.5f) + // m_PassedTime = 0.0f; + if (get_multiplayer()->is_server()) { for (int i = 0; i < m_Players->get_child_count(); i++) { Player* player = Object::cast_to(m_Players->get_child(i)); DEV_ASSERT(player); - m_NetworkInterface->rpc( - "SetPlayerPositionAndRotation", player->m_PeerId, player->get_position(), player->GetCameraRotation()); + m_NetworkInterface->BroadcastPacket( + protocol::packets::PlayerPositionAndRotation({player->GetId(), player->get_position(), player->GetCameraRotation()})); } } else { Player* player = GetPlayerById(get_multiplayer()->get_unique_id()); - if (player) - m_NetworkInterface->rpc("SetPlayerPositionAndRotation", get_multiplayer()->get_unique_id(), player->get_position(), - player->GetCameraRotation()); + if (player) { + m_NetworkInterface->BroadcastPacket(protocol::packets::PlayerPositionAndRotation( + {get_multiplayer()->get_unique_id(), player->get_position(), player->GetCameraRotation()})); + } } } -Player* World::GetPlayerById(uint64_t a_PlayerId) { +Player* World::GetPlayerById(PlayerID a_PlayerId) { String stringId = UtilityFunctions::var_to_str(a_PlayerId); for (int i = 0; i < m_Players->get_child_count(); i++) { Node* player = m_Players->get_child(i); @@ -73,8 +89,25 @@ Player* World::GetPlayerById(uint64_t a_PlayerId) { return nullptr; } -void World::AddPlayer(int32_t a_PlayerId, String a_PlayerName) { - UtilityFunctions::print("New Player with id : ", a_PlayerId); +void World::HandlePacket(const protocol::packets::PlayerJoin& a_PlayerJoin) { + const protocol::PlayerInfo& playerInfo = a_PlayerJoin.m_Data.m_Player; + AddPlayer(playerInfo.m_PlayerId, playerInfo.m_PlayerName); +} + +void World::HandlePacket(const protocol::packets::PlayerLeave& a_PlayerLeave) { + RemovePlayer(a_PlayerLeave.m_Data.m_PlayerId); +} + +void World::HandlePacket(const protocol::packets::PlayerPositionAndRotation& a_PlayerPos) { + const auto& data = a_PlayerPos.m_Data; + if (data.m_Player == get_multiplayer()->get_unique_id() || data.m_Player != a_PlayerPos.m_Sender) + return; + + SetPlayerPositionAndRotation(data.m_Player, data.m_Position, data.m_Rotation); +} + +void World::AddPlayer(PlayerID a_PlayerId, String a_PlayerName) { + UtilityFunctions::print("New Player with id : ", a_PlayerId, " and name ", a_PlayerName); if (a_PlayerId == get_multiplayer()->get_unique_id()) { Ref serverScene = ResourceLoader::get_singleton()->load(FirstPersonPlayerScenePath); FirstPersonPlayer* player = Object::cast_to(serverScene->instantiate()); @@ -90,7 +123,7 @@ void World::AddPlayer(int32_t a_PlayerId, String a_PlayerName) { } } -void World::RemovePlayer(int32_t a_PlayerId) { +void World::RemovePlayer(PlayerID a_PlayerId) { UtilityFunctions::print("Removing Player with id : ", a_PlayerId); Player* player = GetPlayerById(a_PlayerId); if (player) { @@ -98,10 +131,7 @@ void World::RemovePlayer(int32_t a_PlayerId) { } } -void World::SetPlayerPositionAndRotation(int64_t a_PlayerId, Vector3 a_Position, Vector3 a_Rotation) { - if (a_PlayerId == get_multiplayer()->get_unique_id()) - return; - +void World::SetPlayerPositionAndRotation(PlayerID a_PlayerId, const Vector3& a_Position, const Vector3& a_Rotation) { Player* player = GetPlayerById(a_PlayerId); if (player) { player->set_position(a_Position); diff --git a/src/World.h b/src/World.h index 8618bfd..183221b 100644 --- a/src/World.h +++ b/src/World.h @@ -2,12 +2,14 @@ #include +#include + namespace blitz { class Player; class NetworkInterface; -class World : public godot::Node3D { +class World : public godot::Node3D, public protocol::PacketHandler { GDCLASS(World, godot::Node3D) protected: static void _bind_methods(); @@ -16,19 +18,24 @@ class World : public godot::Node3D { World(); ~World(); + // Godot overrides + void _ready() override; void _process(float delta); - void _ready() override; + Player* GetPlayerById(PlayerID a_PlayerId); - Player* GetPlayerById(uint64_t a_PlayerId); - - void AddPlayer(int32_t a_PlayerId, godot::String a_PlayerName); - void RemovePlayer(int32_t a_PlayerId); - void SetPlayerPositionAndRotation(int64_t a_PlayerId, godot::Vector3 a_Position, godot::Vector3 a_Rotation); + void HandlePacket(const protocol::packets::PlayerJoin&) override; + void HandlePacket(const protocol::packets::PlayerLeave&) override; + void HandlePacket(const protocol::packets::PlayerPositionAndRotation&) override; private: NetworkInterface* m_NetworkInterface; godot::Node* m_Players; float m_PassedTime; + + + void AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName); + void RemovePlayer(PlayerID a_PlayerId); + void SetPlayerPositionAndRotation(PlayerID a_PlayerId, const godot::Vector3& a_Position, const godot::Vector3& a_Rotation); }; } // namespace blitz \ No newline at end of file From 770e0281ef232f0c1799c1f4f4a07c19c3462a9f Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Mon, 19 Aug 2024 11:06:04 +0200 Subject: [PATCH 08/23] use GDREGISTER_CLASS --- src/register_types.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/register_types.cpp b/src/register_types.cpp index f58997d..b710979 100644 --- a/src/register_types.cpp +++ b/src/register_types.cpp @@ -17,15 +17,15 @@ using namespace godot; static void RegisterClasses() { - ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); + GDREGISTER_CLASS(blitz::Player); + GDREGISTER_CLASS(blitz::SpringArmPivot); + GDREGISTER_CLASS(blitz::FirstPersonPlayer); + GDREGISTER_CLASS(blitz::MainMenu); + GDREGISTER_CLASS(blitz::Lobby); + GDREGISTER_CLASS(blitz::World); + GDREGISTER_CLASS(blitz::Main); + GDREGISTER_CLASS(blitz::NetworkInterface); + GDREGISTER_CLASS(blitz::Server); } void initialize_example_module(ModuleInitializationLevel p_level) { From 7948e0ce3ac5d6ffb7f27274204f8dfe4c91e6f0 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Mon, 19 Aug 2024 14:25:29 +0200 Subject: [PATCH 09/23] remove unused springarmpivot --- src/SpringArmPivot.cpp | 65 ------------------------------------------ src/SpringArmPivot.h | 38 ------------------------ src/register_types.cpp | 2 -- 3 files changed, 105 deletions(-) delete mode 100644 src/SpringArmPivot.cpp delete mode 100644 src/SpringArmPivot.h diff --git a/src/SpringArmPivot.cpp b/src/SpringArmPivot.cpp deleted file mode 100644 index 551ee06..0000000 --- a/src/SpringArmPivot.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "SpringArmPivot.h" - -#include "Player.h" -#include -#include -#include -#include -#include -#include -#include - -static const float NormalFov = 75.0; -static const float RunFov = 90.0; -static const float CameraBlend = 0.05; - -namespace blitz { - -void SpringArmPivot::_bind_methods() { - godot::ClassDB::bind_method(godot::D_METHOD("get_dynfov"), &SpringArmPivot::IsFovDynamic); - godot::ClassDB::bind_method(godot::D_METHOD("set_dynfov", "dynamic_fov"), &SpringArmPivot::SetDynamicFov); - ADD_PROPERTY(godot::PropertyInfo(godot::Variant::BOOL, "dynamic_fov"), "set_dynfov", "get_dynfov"); -} - -SpringArmPivot::SpringArmPivot() {} - -SpringArmPivot::~SpringArmPivot() {} - -void SpringArmPivot::_ready() { - m_SpringArm = Object::cast_to(get_child(0)); - m_Camera = Object::cast_to(m_SpringArm->get_child(0)); - DEV_ASSERT(m_SpringArm); - DEV_ASSERT(m_Camera); - if (!godot::Engine::get_singleton()->is_editor_hint()) { - godot::Input::get_singleton()->set_mouse_mode(godot::Input::MOUSE_MODE_CAPTURED); - } -} - -void SpringArmPivot::_unhandled_input(const godot::Ref& p_event) { - auto* event = Object::cast_to(p_event.ptr()); - if (event) { - rotate_y(-event->get_relative().x * 0.005); - m_SpringArm->rotate_x(-event->get_relative().y * 0.005); - - godot::Vector3 rotationClamped = m_SpringArm->get_rotation(); - rotationClamped.x = godot::UtilityFunctions::clamp(rotationClamped.x, -Math_PI / 4, Math_PI / 4); - m_SpringArm->set_rotation(rotationClamped); - } -} - -void SpringArmPivot::_physics_process(float delta) { - if (m_DynamicFOV) { - auto* parent = Object::cast_to(get_owner()); - if (parent->is_on_floor()) { - if (godot::Input::get_singleton()->is_action_pressed("run")) { - m_Camera->set_fov(godot::UtilityFunctions::lerp(m_Camera->get_fov(), RunFov, CameraBlend)); - } else { - m_Camera->set_fov(godot::UtilityFunctions::lerp(m_Camera->get_fov(), NormalFov, CameraBlend)); - } - } else { - m_Camera->set_fov(godot::UtilityFunctions::lerp(m_Camera->get_fov(), NormalFov, CameraBlend)); - } - } -} - -} // namespace blitz diff --git a/src/SpringArmPivot.h b/src/SpringArmPivot.h deleted file mode 100644 index 410b3ce..0000000 --- a/src/SpringArmPivot.h +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace blitz { -class SpringArmPivot : public godot::Node3D { - - GDCLASS(SpringArmPivot, godot::Node3D); - - protected: - static void _bind_methods(); - - public: - SpringArmPivot(); - ~SpringArmPivot(); - - void _ready(); - void _unhandled_input(const godot::Ref& p_event); - void _physics_process(float delta); - - void SetDynamicFov(bool fov) { - m_DynamicFOV = fov; - } - - bool IsFovDynamic() const { - return m_DynamicFOV; - } - - private: - godot::SpringArm3D* m_SpringArm; - godot::Camera3D* m_Camera; - - bool m_DynamicFOV = false; -}; -} // namespace blitz diff --git a/src/register_types.cpp b/src/register_types.cpp index b710979..343ac20 100644 --- a/src/register_types.cpp +++ b/src/register_types.cpp @@ -7,7 +7,6 @@ #include "NetworkInterface.h" #include "Player.h" #include "Server.h" -#include "SpringArmPivot.h" #include "World.h" #include @@ -18,7 +17,6 @@ using namespace godot; static void RegisterClasses() { GDREGISTER_CLASS(blitz::Player); - GDREGISTER_CLASS(blitz::SpringArmPivot); GDREGISTER_CLASS(blitz::FirstPersonPlayer); GDREGISTER_CLASS(blitz::MainMenu); GDREGISTER_CLASS(blitz::Lobby); From 211533d967d804d367cb5d50988400fe40f20d16 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Mon, 19 Aug 2024 14:26:55 +0200 Subject: [PATCH 10/23] remove old PlayerInfo --- src/PlayerInfo.h | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 src/PlayerInfo.h diff --git a/src/PlayerInfo.h b/src/PlayerInfo.h deleted file mode 100644 index 19e644f..0000000 --- a/src/PlayerInfo.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -namespace blitz { - -struct PlayerInfo { - godot::String m_Name; -}; - -} // namespace blitz From 5c1793c1e74cb55763c58b18b104637fed0d4b54 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Mon, 19 Aug 2024 14:37:36 +0200 Subject: [PATCH 11/23] move files into client folder --- {src => include/client}/FirstPersonPlayer.h | 2 +- {src => include/client}/Lobby.h | 2 +- {src => include/client}/Main.h | 0 {src => include/client}/MainMenu.h | 0 {src => include/client}/NetworkInterface.h | 0 {src => include/client}/Player.h | 0 {src => include/client}/Server.h | 0 {src => include/client}/World.h | 0 src/{ => client}/FirstPersonPlayer.cpp | 2 +- src/{ => client}/Lobby.cpp | 2 +- src/{ => client}/Main.cpp | 6 ++--- src/{ => client}/MainMenu.cpp | 2 +- src/{ => client}/NetworkInterface.cpp | 2 +- src/{ => client}/Player.cpp | 2 +- src/{ => client}/Server.cpp | 6 ++--- src/{ => client}/World.cpp | 8 +++---- src/{ => client}/register_types.cpp | 26 ++++++++++----------- src/register_types.h | 11 --------- 18 files changed, 29 insertions(+), 42 deletions(-) rename {src => include/client}/FirstPersonPlayer.h (96%) rename {src => include/client}/Lobby.h (94%) rename {src => include/client}/Main.h (100%) rename {src => include/client}/MainMenu.h (100%) rename {src => include/client}/NetworkInterface.h (100%) rename {src => include/client}/Player.h (100%) rename {src => include/client}/Server.h (100%) rename {src => include/client}/World.h (100%) rename src/{ => client}/FirstPersonPlayer.cpp (99%) rename src/{ => client}/Lobby.cpp (99%) rename src/{ => client}/Main.cpp (90%) rename src/{ => client}/MainMenu.cpp (98%) rename src/{ => client}/NetworkInterface.cpp (97%) rename src/{ => client}/Player.cpp (98%) rename src/{ => client}/Server.cpp (92%) rename src/{ => client}/World.cpp (97%) rename src/{ => client}/register_types.cpp (66%) delete mode 100644 src/register_types.h diff --git a/src/FirstPersonPlayer.h b/include/client/FirstPersonPlayer.h similarity index 96% rename from src/FirstPersonPlayer.h rename to include/client/FirstPersonPlayer.h index c1edd84..f5d2f89 100644 --- a/src/FirstPersonPlayer.h +++ b/include/client/FirstPersonPlayer.h @@ -1,6 +1,6 @@ #pragma once -#include "Player.h" +#include #include namespace blitz { diff --git a/src/Lobby.h b/include/client/Lobby.h similarity index 94% rename from src/Lobby.h rename to include/client/Lobby.h index 58d6a72..f612a6b 100644 --- a/src/Lobby.h +++ b/include/client/Lobby.h @@ -1,7 +1,7 @@ #pragma once #include -#include "NetworkInterface.h" +#include namespace blitz { diff --git a/src/Main.h b/include/client/Main.h similarity index 100% rename from src/Main.h rename to include/client/Main.h diff --git a/src/MainMenu.h b/include/client/MainMenu.h similarity index 100% rename from src/MainMenu.h rename to include/client/MainMenu.h diff --git a/src/NetworkInterface.h b/include/client/NetworkInterface.h similarity index 100% rename from src/NetworkInterface.h rename to include/client/NetworkInterface.h diff --git a/src/Player.h b/include/client/Player.h similarity index 100% rename from src/Player.h rename to include/client/Player.h diff --git a/src/Server.h b/include/client/Server.h similarity index 100% rename from src/Server.h rename to include/client/Server.h diff --git a/src/World.h b/include/client/World.h similarity index 100% rename from src/World.h rename to include/client/World.h diff --git a/src/FirstPersonPlayer.cpp b/src/client/FirstPersonPlayer.cpp similarity index 99% rename from src/FirstPersonPlayer.cpp rename to src/client/FirstPersonPlayer.cpp index f7fe3b6..2d65420 100644 --- a/src/FirstPersonPlayer.cpp +++ b/src/client/FirstPersonPlayer.cpp @@ -1,4 +1,4 @@ -#include "FirstPersonPlayer.h" +#include #include #include diff --git a/src/Lobby.cpp b/src/client/Lobby.cpp similarity index 99% rename from src/Lobby.cpp rename to src/client/Lobby.cpp index db517dd..07f2ccb 100644 --- a/src/Lobby.cpp +++ b/src/client/Lobby.cpp @@ -1,4 +1,4 @@ -#include "Lobby.h" +#include #include #include diff --git a/src/Main.cpp b/src/client/Main.cpp similarity index 90% rename from src/Main.cpp rename to src/client/Main.cpp index 2d1f63b..057fc23 100644 --- a/src/Main.cpp +++ b/src/client/Main.cpp @@ -1,4 +1,4 @@ -#include "Main.h" +#include #include #include @@ -7,8 +7,8 @@ #include #include -#include "Lobby.h" -#include "World.h" +#include +#include using namespace godot; diff --git a/src/MainMenu.cpp b/src/client/MainMenu.cpp similarity index 98% rename from src/MainMenu.cpp rename to src/client/MainMenu.cpp index 0f4d289..f2de218 100644 --- a/src/MainMenu.cpp +++ b/src/client/MainMenu.cpp @@ -1,4 +1,4 @@ -#include "MainMenu.h" +#include #include #include diff --git a/src/NetworkInterface.cpp b/src/client/NetworkInterface.cpp similarity index 97% rename from src/NetworkInterface.cpp rename to src/client/NetworkInterface.cpp index f01efa2..357f17c 100644 --- a/src/NetworkInterface.cpp +++ b/src/client/NetworkInterface.cpp @@ -1,4 +1,4 @@ -#include "NetworkInterface.h" +#include #include #include diff --git a/src/Player.cpp b/src/client/Player.cpp similarity index 98% rename from src/Player.cpp rename to src/client/Player.cpp index 4bb3bb1..b3711d7 100644 --- a/src/Player.cpp +++ b/src/client/Player.cpp @@ -1,4 +1,4 @@ -#include "Player.h" +#include #include #include diff --git a/src/Server.cpp b/src/client/Server.cpp similarity index 92% rename from src/Server.cpp rename to src/client/Server.cpp index b6ee784..cdb395a 100644 --- a/src/Server.cpp +++ b/src/client/Server.cpp @@ -1,7 +1,7 @@ -#include "Server.h" +#include -#include "Lobby.h" -#include "NetworkInterface.h" +#include +#include #include using namespace godot; diff --git a/src/World.cpp b/src/client/World.cpp similarity index 97% rename from src/World.cpp rename to src/client/World.cpp index f9f4bc7..a8d0532 100644 --- a/src/World.cpp +++ b/src/client/World.cpp @@ -1,8 +1,8 @@ -#include "World.h" +#include -#include "FirstPersonPlayer.h" -#include "NetworkInterface.h" -#include "Player.h" +#include +#include +#include #include #include #include diff --git a/src/register_types.cpp b/src/client/register_types.cpp similarity index 66% rename from src/register_types.cpp rename to src/client/register_types.cpp index 343ac20..334ef00 100644 --- a/src/register_types.cpp +++ b/src/client/register_types.cpp @@ -1,13 +1,11 @@ -#include "register_types.h" - -#include "FirstPersonPlayer.h" -#include "Lobby.h" -#include "Main.h" -#include "MainMenu.h" -#include "NetworkInterface.h" -#include "Player.h" -#include "Server.h" -#include "World.h" +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -26,7 +24,7 @@ static void RegisterClasses() { GDREGISTER_CLASS(blitz::Server); } -void initialize_example_module(ModuleInitializationLevel p_level) { +static void initialize_blitz_module(ModuleInitializationLevel p_level) { if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { return; } @@ -34,7 +32,7 @@ void initialize_example_module(ModuleInitializationLevel p_level) { RegisterClasses(); } -void uninitialize_example_module(ModuleInitializationLevel p_level) { +static void uninitialize_blitz_module(ModuleInitializationLevel p_level) { if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { return; } @@ -44,8 +42,8 @@ extern "C" GDExtensionBool GDE_EXPORT library_init(GDExtensionInterfaceGetProcAd const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization* r_initialization) { godot::GDExtensionBinding::InitObject init_obj(p_get_proc, p_library, r_initialization); - init_obj.register_initializer(initialize_example_module); - init_obj.register_terminator(uninitialize_example_module); + init_obj.register_initializer(initialize_blitz_module); + init_obj.register_terminator(uninitialize_blitz_module); init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE); return init_obj.init(); diff --git a/src/register_types.h b/src/register_types.h deleted file mode 100644 index 938f7a1..0000000 --- a/src/register_types.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef GDEXAMPLE_REGISTER_TYPES_H -#define GDEXAMPLE_REGISTER_TYPES_H - -#include - -using namespace godot; - -void initialize_example_module(ModuleInitializationLevel p_level); -void uninitialize_example_module(ModuleInitializationLevel p_level); - -#endif \ No newline at end of file From 27a3581af14abe5b0b353ae31d8c6dd57984804f Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Mon, 19 Aug 2024 15:24:44 +0200 Subject: [PATCH 12/23] moved network interface --- godot/Scenes/Network/networking.tscn | 4 +- godot/Scenes/main.tscn | 5 +- .../godot}/NetworkInterface.h | 16 ++- include/client/Lobby.h | 32 ----- include/client/MainMenu.h | 7 + include/client/Server.h | 12 +- src/blitz/godot/NetworkInterface.cpp | 129 ++++++++++++++++++ src/client/Lobby.cpp | 99 -------------- src/client/Main.cpp | 1 - src/client/MainMenu.cpp | 29 +++- src/client/NetworkInterface.cpp | 50 ------- src/client/Server.cpp | 11 +- src/client/World.cpp | 7 +- src/client/register_types.cpp | 4 +- 14 files changed, 190 insertions(+), 216 deletions(-) rename include/{client => blitz/godot}/NetworkInterface.h (65%) delete mode 100644 include/client/Lobby.h create mode 100644 src/blitz/godot/NetworkInterface.cpp delete mode 100644 src/client/Lobby.cpp delete mode 100644 src/client/NetworkInterface.cpp diff --git a/godot/Scenes/Network/networking.tscn b/godot/Scenes/Network/networking.tscn index 9ad3fb5..edbb3c6 100644 --- a/godot/Scenes/Network/networking.tscn +++ b/godot/Scenes/Network/networking.tscn @@ -1,5 +1,3 @@ [gd_scene format=3 uid="uid://clafls1xhludi"] -[node name="Lobby" type="Lobby"] - -[node name="NetworkInterface" type="NetworkInterface" parent="."] +[node name="NetworkInterface" type="NetworkInterface"] diff --git a/godot/Scenes/main.tscn b/godot/Scenes/main.tscn index 0a6779b..1312a1c 100644 --- a/godot/Scenes/main.tscn +++ b/godot/Scenes/main.tscn @@ -5,11 +5,8 @@ [node name="Main" type="Main"] -[node name="Lobby" parent="." instance=ExtResource("1_06ibn")] +[node name="Network" parent="." instance=ExtResource("1_06ibn")] [node name="MainMenu" parent="." instance=ExtResource("2_lavg1")] -[connection signal="local_player_connected" from="Lobby" to="MainMenu" method="on_connected"] [connection signal="change_scene" from="MainMenu" to="." method="change_scene"] -[connection signal="create_game" from="MainMenu" to="Lobby" method="create_game"] -[connection signal="join_game" from="MainMenu" to="Lobby" method="join_game"] diff --git a/include/client/NetworkInterface.h b/include/blitz/godot/NetworkInterface.h similarity index 65% rename from include/client/NetworkInterface.h rename to include/blitz/godot/NetworkInterface.h index 6b6510e..5f53cb1 100644 --- a/include/client/NetworkInterface.h +++ b/include/blitz/godot/NetworkInterface.h @@ -1,10 +1,11 @@ #pragma once +#include #include #include -#include namespace blitz { + class NetworkInterface : public godot::Node, public protocol::PacketDispatcher { GDCLASS(NetworkInterface, godot::Node) protected: @@ -17,10 +18,21 @@ class NetworkInterface : public godot::Node, public protocol::PacketDispatcher { void BroadcastPacket(const protocol::Packet& a_Packet); void SendPacket(PeerID a_Peer, const protocol::Packet& a_Packet); + godot::Error JoinGame(const godot::String& a_Address, uint16_t a_Port); + godot::Error CreateGame(uint16_t a_Port, bool a_Dedicated = false); + + void ShutdownNetwork(); + void _ready() override; - + private: void RecievePacketDataReliable(godot::PackedByteArray a_PacketData); + + void OnPlayerConnected(PeerID a_PeerId); + void OnPlayerDisconnected(PeerID a_PeerId); + void OnConnectOk(); + void OnConnectFail(); + void OnServerDisconnected(); }; } // namespace blitz \ No newline at end of file diff --git a/include/client/Lobby.h b/include/client/Lobby.h deleted file mode 100644 index f612a6b..0000000 --- a/include/client/Lobby.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include - -namespace blitz { - -class Lobby : public godot::Node { - GDCLASS(Lobby, godot::Node) - protected: - static void _bind_methods(); - - public: - Lobby(); - ~Lobby(); - - void _ready() override; - - godot::Error JoinGame(const godot::String& a_Address, uint16_t a_Port); - godot::Error CreateGame(uint16_t a_Port, bool a_Dedicated = false); - - void Shutdown(); - - private: - void OnPlayerConnected(PeerID a_PeerId); - void OnPlayerDisconnected(PeerID a_PeerId); - void OnConnectOk(); - void OnConnectFail(); - void OnServerDisconnected(); -}; - -} // namespace blitz \ No newline at end of file diff --git a/include/client/MainMenu.h b/include/client/MainMenu.h index 488861a..73157c9 100644 --- a/include/client/MainMenu.h +++ b/include/client/MainMenu.h @@ -2,6 +2,7 @@ #include #include +#include namespace blitz { @@ -22,11 +23,17 @@ class MainMenu : public godot::Control { godot::Button* m_CreateButton; godot::Button* m_QuitButton; + NetworkInterface* m_NetworkInterface; + void OnConnected(); + void OnDisconnected(); void OnJoinPressed(); void OnCreatePressed(); void OnQuitPressed(); + + void DisableButtons(); + void EnableButtons(); }; } // namespace blitz \ No newline at end of file diff --git a/include/client/Server.h b/include/client/Server.h index c2debff..2f6c7ab 100644 --- a/include/client/Server.h +++ b/include/client/Server.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include namespace blitz { @@ -19,14 +19,14 @@ class Server : public godot::Node { void _ready() override; - void OnPlayerConnect(PeerID a_PeerId); - void OnPlayerDisconnect(PeerID a_PeerId); + void OnPlayerConnect(PeerID a_PeerId); + void OnPlayerDisconnect(PeerID a_PeerId); private: - Lobby* m_Lobby; - NetworkInterface* m_NetworkInterface; + Lobby* m_Lobby; + NetworkInterface* m_NetworkInterface; - godot::TypedArray m_Peers; + godot::TypedArray m_Peers; }; } // namespace blitz \ No newline at end of file diff --git a/src/blitz/godot/NetworkInterface.cpp b/src/blitz/godot/NetworkInterface.cpp new file mode 100644 index 0000000..a412d2c --- /dev/null +++ b/src/blitz/godot/NetworkInterface.cpp @@ -0,0 +1,129 @@ +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace blitz { + +static const char ServerScenePath[] = "res://Scenes/Network/server.tscn"; + +using namespace godot; + +void NetworkInterface::_bind_methods() { + ClassDB::bind_method(D_METHOD("RecievePacketDataReliable", "a_PacketData"), &NetworkInterface::RecievePacketDataReliable); + + // server + ADD_SIGNAL(MethodInfo("player_connected", PropertyInfo(Variant::INT, "peer_id"))); + ADD_SIGNAL(MethodInfo("player_disconnected", PropertyInfo(Variant::INT, "peer_id"))); + + // client + ADD_SIGNAL(MethodInfo("server_disconnected")); + ADD_SIGNAL(MethodInfo("local_player_connected")); + + protocol::PacketFactory::Init(); +} + +NetworkInterface::NetworkInterface() {} + +NetworkInterface::~NetworkInterface() {} + +void NetworkInterface::_ready() { + // TODO: unreliable + Dictionary config; + config["rpc_mode"] = MultiplayerAPI::RPC_MODE_ANY_PEER; + config["transfer_mode"] = MultiplayerPeer::TRANSFER_MODE_RELIABLE; + config["call_local"] = true; + config["channel"] = 0; + rpc_config("RecievePacketDataReliable", config); + + get_multiplayer()->connect("peer_connected", callable_mp(this, &NetworkInterface::OnPlayerConnected)); + get_multiplayer()->connect("peer_disconnected", callable_mp(this, &NetworkInterface::OnPlayerDisconnected)); + get_multiplayer()->connect("connected_to_server", callable_mp(this, &NetworkInterface::OnConnectOk)); + get_multiplayer()->connect("connection_failed", callable_mp(this, &NetworkInterface::OnConnectFail)); + get_multiplayer()->connect("server_disconnected", callable_mp(this, &NetworkInterface::OnServerDisconnected)); +} + +void NetworkInterface::BroadcastPacket(const protocol::Packet& a_Packet) { + PackedByteArray byteArray = protocol::PacketSerializer::Serialize(a_Packet); + rpc("RecievePacketDataReliable", byteArray); +} + +void NetworkInterface::SendPacket(PeerID a_Peer, const protocol::Packet& a_Packet) { + PackedByteArray byteArray = protocol::PacketSerializer::Serialize(a_Packet); + rpc_id(a_Peer, "RecievePacketDataReliable", byteArray); +} + +void NetworkInterface::RecievePacketDataReliable(godot::PackedByteArray a_PacketData) { + auto packet = protocol::PacketSerializer::Deserialize(a_PacketData); + if (packet) { + packet->m_Sender = get_multiplayer()->get_remote_sender_id(); + Dispatch(*packet); + } +} + +Error NetworkInterface::JoinGame(const String& a_Address, uint16_t a_Port) { + auto* peer = memnew(ENetMultiplayerPeer); + Error error = peer->create_client(a_Address, a_Port); + if (error) { + OnConnectFail(); + return error; + } + + get_multiplayer()->set_multiplayer_peer(peer); + return Error::OK; +} + +Error NetworkInterface::CreateGame(uint16_t a_Port, bool a_Dedicated) { + auto* peer = memnew(ENetMultiplayerPeer); + Error error = peer->create_server(a_Port); + if (error) + return error; + + get_multiplayer()->set_multiplayer_peer(peer); + + Ref serverScene = ResourceLoader::get_singleton()->load(ServerScenePath); + add_child(serverScene->instantiate()); + + if (!a_Dedicated) { + emit_signal("local_player_connected"); + emit_signal("player_connected", get_multiplayer()->get_unique_id()); + } + + return Error::OK; +} + +void NetworkInterface::OnPlayerConnected(PeerID a_PeerId) { + emit_signal("player_connected", a_PeerId); +} + +void NetworkInterface::OnPlayerDisconnected(PeerID a_PeerId) { + emit_signal("player_disconnected", a_PeerId); +} + +void NetworkInterface::OnConnectOk() { + emit_signal("local_player_connected"); +} + +void NetworkInterface::OnConnectFail() { + ShutdownNetwork(); + emit_signal("server_disconnected"); +} + +void NetworkInterface::OnServerDisconnected() { + ShutdownNetwork(); + emit_signal("server_disconnected"); +} + +void NetworkInterface::ShutdownNetwork() { + get_multiplayer()->set_multiplayer_peer(nullptr); + if (auto* server = find_child("Server")) { + server->queue_free(); + } +} + +} // namespace blitz \ No newline at end of file diff --git a/src/client/Lobby.cpp b/src/client/Lobby.cpp deleted file mode 100644 index 07f2ccb..0000000 --- a/src/client/Lobby.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include - -#include -#include -#include -#include -#include -#include - -using namespace godot; - -static const char ServerScenePath[] = "res://Scenes/Network/server.tscn"; - -namespace blitz { - -void Lobby::_bind_methods() { - godot::ClassDB::bind_method(godot::D_METHOD("create_game", "port", "dedicated"), &Lobby::CreateGame); - godot::ClassDB::bind_method(godot::D_METHOD("join_game", "address", "port"), &Lobby::JoinGame); - ADD_SIGNAL(MethodInfo("player_connected", PropertyInfo(Variant::INT, "peer_id"))); - ADD_SIGNAL(MethodInfo("player_disconnected", PropertyInfo(Variant::INT, "peer_id"))); - ADD_SIGNAL(MethodInfo("server_disconnected")); - ADD_SIGNAL(MethodInfo("local_player_connected")); -} - -Lobby::Lobby() {} - -Lobby::~Lobby() {} - -void Lobby::_ready() { - get_multiplayer()->connect("peer_connected", callable_mp(this, &Lobby::OnPlayerConnected)); - get_multiplayer()->connect("peer_disconnected", callable_mp(this, &Lobby::OnPlayerDisconnected)); - get_multiplayer()->connect("connected_to_server", callable_mp(this, &Lobby::OnConnectOk)); - get_multiplayer()->connect("connection_failed", callable_mp(this, &Lobby::OnConnectFail)); - get_multiplayer()->connect("server_disconnected", callable_mp(this, &Lobby::OnServerDisconnected)); -} - -Error Lobby::JoinGame(const String& a_Address, uint16_t a_Port) { - auto* peer = memnew(ENetMultiplayerPeer); - Error error = peer->create_client(a_Address, a_Port); - if (error) - return error; - - get_multiplayer()->set_multiplayer_peer(peer); - return Error::OK; -} - -Error Lobby::CreateGame(uint16_t a_Port, bool a_Dedicated) { - auto* peer = memnew(ENetMultiplayerPeer); - Error error = peer->create_server(a_Port); - if (error) - return error; - - get_multiplayer()->set_multiplayer_peer(peer); - - Ref serverScene = ResourceLoader::get_singleton()->load(ServerScenePath); - add_child(serverScene->instantiate()); - - if (!a_Dedicated) { - emit_signal("local_player_connected"); - emit_signal("player_connected", get_multiplayer()->get_unique_id()); - } - - return Error::OK; -} - -void Lobby::Shutdown() { - get_multiplayer()->set_multiplayer_peer(nullptr); - if (auto* server = find_child("Server")) { - remove_child(server); - } -} - -void Lobby::OnPlayerConnected(PeerID a_PeerId) { - if (get_multiplayer()->is_server()) { - emit_signal("player_connected", a_PeerId); - } -} - -void Lobby::OnPlayerDisconnected(PeerID a_PeerId) { - if (get_multiplayer()->is_server()) { - emit_signal("player_disconnected", a_PeerId); - } -} - -void Lobby::OnConnectOk() { - int32_t peerId = get_multiplayer()->get_unique_id(); - emit_signal("local_player_connected"); -} - -void Lobby::OnConnectFail() { - Shutdown(); -} - -void Lobby::OnServerDisconnected() { - Shutdown(); - emit_signal("server_disconnected"); -} - -} // namespace blitz \ No newline at end of file diff --git a/src/client/Main.cpp b/src/client/Main.cpp index 057fc23..920e8b2 100644 --- a/src/client/Main.cpp +++ b/src/client/Main.cpp @@ -7,7 +7,6 @@ #include #include -#include #include using namespace godot; diff --git a/src/client/MainMenu.cpp b/src/client/MainMenu.cpp index f2de218..7308ddc 100644 --- a/src/client/MainMenu.cpp +++ b/src/client/MainMenu.cpp @@ -9,8 +9,6 @@ namespace blitz { void MainMenu::_bind_methods() { godot::ClassDB::bind_method(godot::D_METHOD("on_connected"), &MainMenu::OnConnected); - ADD_SIGNAL(MethodInfo("create_game", PropertyInfo(Variant::INT, "port"), PropertyInfo(Variant::BOOL, "dedicated"))); - ADD_SIGNAL(MethodInfo("join_game", PropertyInfo(Variant::STRING, "address"), PropertyInfo(Variant::INT, "port"))); ADD_SIGNAL(MethodInfo("change_scene")); } @@ -30,9 +28,15 @@ void MainMenu::_ready() { DEV_ASSERT(m_CreateButton); DEV_ASSERT(m_QuitButton); + m_NetworkInterface = Object::cast_to(get_parent()->find_child("Network")); + DEV_ASSERT(m_NetworkInterface); + m_JoinButton->connect("pressed", callable_mp(this, &MainMenu::OnJoinPressed)); m_CreateButton->connect("pressed", callable_mp(this, &MainMenu::OnCreatePressed)); m_QuitButton->connect("pressed", callable_mp(this, &MainMenu::OnQuitPressed)); + + m_NetworkInterface->connect("local_player_connected", callable_mp(this, &MainMenu::OnConnected)); + m_NetworkInterface->connect("server_disconnected", callable_mp(this, &MainMenu::OnDisconnected)); } void MainMenu::OnConnected() { @@ -40,16 +44,33 @@ void MainMenu::OnConnected() { set_visible(false); } +void MainMenu::OnDisconnected() { + set_visible(true); + EnableButtons(); +} + void MainMenu::OnJoinPressed() { - emit_signal("join_game", "localhost", 25565); + DisableButtons(); + m_NetworkInterface->JoinGame("localhost", 25565); } void MainMenu::OnCreatePressed() { - emit_signal("create_game", 25565, false); + DisableButtons(); + m_NetworkInterface->CreateGame(25565); } void MainMenu::OnQuitPressed() { get_tree()->quit(); } +void MainMenu::DisableButtons() { + m_JoinButton->set_disabled(true); + m_CreateButton->set_disabled(true); +} + +void MainMenu::EnableButtons() { + m_JoinButton->set_disabled(false); + m_CreateButton->set_disabled(false); +} + } // namespace blitz \ No newline at end of file diff --git a/src/client/NetworkInterface.cpp b/src/client/NetworkInterface.cpp deleted file mode 100644 index 357f17c..0000000 --- a/src/client/NetworkInterface.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include - -#include -#include -#include -#include -#include - -namespace blitz { - -using namespace godot; - -void NetworkInterface::_bind_methods() { - ClassDB::bind_method(D_METHOD("RecievePacketDataReliable", "a_PacketData"), &NetworkInterface::RecievePacketDataReliable); - protocol::PacketFactory::Init(); -} - -NetworkInterface::NetworkInterface() {} - -NetworkInterface::~NetworkInterface() {} - -void NetworkInterface::_ready() { - // TODO: unreliable - Dictionary config; - config["rpc_mode"] = MultiplayerAPI::RPC_MODE_ANY_PEER; - config["transfer_mode"] = MultiplayerPeer::TRANSFER_MODE_RELIABLE; - config["call_local"] = true; - config["channel"] = 0; - rpc_config("RecievePacketDataReliable", config); -} - -void NetworkInterface::BroadcastPacket(const protocol::Packet& a_Packet) { - PackedByteArray byteArray = protocol::PacketSerializer::Serialize(a_Packet); - rpc("RecievePacketDataReliable", byteArray); -} - -void NetworkInterface::SendPacket(PeerID a_Peer, const protocol::Packet& a_Packet) { - PackedByteArray byteArray = protocol::PacketSerializer::Serialize(a_Packet); - rpc_id(a_Peer, "RecievePacketDataReliable", byteArray); -} - -void NetworkInterface::RecievePacketDataReliable(godot::PackedByteArray a_PacketData) { - auto packet = protocol::PacketSerializer::Deserialize(a_PacketData); - if (packet) { - packet->m_Sender = get_multiplayer()->get_remote_sender_id(); - Dispatch(*packet); - } -} - -} // namespace blitz \ No newline at end of file diff --git a/src/client/Server.cpp b/src/client/Server.cpp index cdb395a..9491cb0 100644 --- a/src/client/Server.cpp +++ b/src/client/Server.cpp @@ -1,7 +1,6 @@ #include -#include -#include +#include #include using namespace godot; @@ -19,13 +18,11 @@ void Server::_ready() { return; - m_Lobby = Object::cast_to(get_parent()); - DEV_ASSERT(m_Lobby); - m_NetworkInterface = Object::cast_to(m_Lobby->find_child("NetworkInterface")); + m_NetworkInterface = Object::cast_to(get_parent()); DEV_ASSERT(m_NetworkInterface); - m_Lobby->connect("player_connected", callable_mp(this, &Server::OnPlayerConnect)); - m_Lobby->connect("player_disconnected", callable_mp(this, &Server::OnPlayerDisconnect)); + m_NetworkInterface->connect("player_connected", callable_mp(this, &Server::OnPlayerConnect)); + m_NetworkInterface->connect("player_disconnected", callable_mp(this, &Server::OnPlayerDisconnect)); } void Server::OnPlayerConnect(PeerID a_PeerId) { diff --git a/src/client/World.cpp b/src/client/World.cpp index a8d0532..2d4d598 100644 --- a/src/client/World.cpp +++ b/src/client/World.cpp @@ -1,7 +1,7 @@ #include +#include #include -#include #include #include #include @@ -26,10 +26,7 @@ void World::_ready() { m_Players = find_child("Players"); DEV_ASSERT(m_Players); - auto* lobby = get_parent()->find_child("Lobby"); - DEV_ASSERT(lobby); - - m_NetworkInterface = Object::cast_to(lobby->find_child("NetworkInterface")); + m_NetworkInterface = Object::cast_to(get_parent()->find_child("Network")); DEV_ASSERT(m_NetworkInterface); m_NetworkInterface->RegisterHandler(protocol::PacketType::PlayerJoin, *this); diff --git a/src/client/register_types.cpp b/src/client/register_types.cpp index 334ef00..1e02b45 100644 --- a/src/client/register_types.cpp +++ b/src/client/register_types.cpp @@ -1,8 +1,7 @@ +#include #include -#include #include #include -#include #include #include #include @@ -17,7 +16,6 @@ static void RegisterClasses() { GDREGISTER_CLASS(blitz::Player); GDREGISTER_CLASS(blitz::FirstPersonPlayer); GDREGISTER_CLASS(blitz::MainMenu); - GDREGISTER_CLASS(blitz::Lobby); GDREGISTER_CLASS(blitz::World); GDREGISTER_CLASS(blitz::Main); GDREGISTER_CLASS(blitz::NetworkInterface); From 3cebb702896dbe2a6ef1236a9085be52b9a2ab20 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Mon, 19 Aug 2024 15:26:23 +0200 Subject: [PATCH 13/23] moved server --- include/{client => server}/Server.h | 0 src/client/register_types.cpp | 2 +- src/{client => server}/Server.cpp | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename include/{client => server}/Server.h (100%) rename src/{client => server}/Server.cpp (97%) diff --git a/include/client/Server.h b/include/server/Server.h similarity index 100% rename from include/client/Server.h rename to include/server/Server.h diff --git a/src/client/register_types.cpp b/src/client/register_types.cpp index 1e02b45..1a3e84b 100644 --- a/src/client/register_types.cpp +++ b/src/client/register_types.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/client/Server.cpp b/src/server/Server.cpp similarity index 97% rename from src/client/Server.cpp rename to src/server/Server.cpp index 9491cb0..682abeb 100644 --- a/src/client/Server.cpp +++ b/src/server/Server.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include From a092f6fbc1731e3423127d2d05a3bd62102c1535 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Mon, 19 Aug 2024 16:19:45 +0200 Subject: [PATCH 14/23] make world abstract --- godot/Scenes/Levels/client_world.tscn | 7 +++++ godot/Scenes/Levels/server_world.tscn | 7 +++++ godot/Scenes/Levels/world.tscn | 20 ++++++------- godot/Scenes/main.tscn | 2 -- include/{client => blitz/godot}/World.h | 5 ++-- include/client/ClientWorld.h | 19 ++++++++++++ include/client/Main.h | 4 ++- include/server/ServerWorld.h | 19 ++++++++++++ src/{client => blitz/godot}/World.cpp | 33 +-------------------- src/client/ClientWorld.cpp | 39 +++++++++++++++++++++++++ src/client/Main.cpp | 26 ++++++++++++----- src/client/MainMenu.cpp | 19 +++++++----- src/client/register_types.cpp | 7 +++-- src/server/ServerWorld.cpp | 38 ++++++++++++++++++++++++ 14 files changed, 180 insertions(+), 65 deletions(-) create mode 100644 godot/Scenes/Levels/client_world.tscn create mode 100644 godot/Scenes/Levels/server_world.tscn rename include/{client => blitz/godot}/World.h (96%) create mode 100644 include/client/ClientWorld.h create mode 100644 include/server/ServerWorld.h rename src/{client => blitz/godot}/World.cpp (78%) create mode 100644 src/client/ClientWorld.cpp create mode 100644 src/server/ServerWorld.cpp diff --git a/godot/Scenes/Levels/client_world.tscn b/godot/Scenes/Levels/client_world.tscn new file mode 100644 index 0000000..3035263 --- /dev/null +++ b/godot/Scenes/Levels/client_world.tscn @@ -0,0 +1,7 @@ +[gd_scene load_steps=2 format=3 uid="uid://bqv0m8kbr300b"] + +[ext_resource type="PackedScene" path="res://Scenes/Levels/world.tscn" id="1_ajsqk"] + +[node name="World" type="ClientWorld"] + +[node name="WorldContent" parent="." instance=ExtResource("1_ajsqk")] diff --git a/godot/Scenes/Levels/server_world.tscn b/godot/Scenes/Levels/server_world.tscn new file mode 100644 index 0000000..fa8c865 --- /dev/null +++ b/godot/Scenes/Levels/server_world.tscn @@ -0,0 +1,7 @@ +[gd_scene load_steps=2 format=3 uid="uid://c2p67anlxe3mk"] + +[ext_resource type="PackedScene" path="res://Scenes/Levels/world.tscn" id="1_tecss"] + +[node name="World" type="ServerWorld"] + +[node name="WorldContent" parent="." instance=ExtResource("1_tecss")] diff --git a/godot/Scenes/Levels/world.tscn b/godot/Scenes/Levels/world.tscn index 80d3526..98553bc 100644 --- a/godot/Scenes/Levels/world.tscn +++ b/godot/Scenes/Levels/world.tscn @@ -1,12 +1,12 @@ -[gd_scene load_steps=17 format=3 uid="uid://coue2qehpn4fr"] +[gd_scene load_steps=17 format=3 uid="uid://cl8gww414apoq"] -[ext_resource type="Texture2D" path="res://Assets/Textures/Sky.png" id="1_mnexj"] -[ext_resource type="Texture2D" path="res://Assets/Textures/Black.png" id="2_fkwcn"] -[ext_resource type="Texture2D" path="res://Assets/Textures/Orange.png" id="3_ux02w"] -[ext_resource type="Texture2D" path="res://Assets/Textures/Green.png" id="4_wp15n"] +[ext_resource type="Texture2D" path="res://Assets/Textures/Sky.png" id="1_tcyn8"] +[ext_resource type="Texture2D" path="res://Assets/Textures/Black.png" id="2_j33w8"] +[ext_resource type="Texture2D" path="res://Assets/Textures/Orange.png" id="3_n1lus"] +[ext_resource type="Texture2D" path="res://Assets/Textures/Green.png" id="4_klpsf"] [sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_6c4vd"] -panorama = ExtResource("1_mnexj") +panorama = ExtResource("1_tcyn8") [sub_resource type="Sky" id="Sky_5ngqa"] sky_material = SubResource("PanoramaSkyMaterial_6c4vd") @@ -18,7 +18,7 @@ tonemap_mode = 2 glow_enabled = true [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ajchh"] -albedo_texture = ExtResource("2_fkwcn") +albedo_texture = ExtResource("2_j33w8") uv1_triplanar = true [sub_resource type="PlaneMesh" id="PlaneMesh_mmup0"] @@ -29,7 +29,7 @@ size = Vector2(50, 50) data = PackedVector3Array(25, 0, 25, -25, 0, 25, 25, 0, -25, -25, 0, 25, -25, 0, -25, 25, 0, -25) [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_jkvud"] -albedo_texture = ExtResource("3_ux02w") +albedo_texture = ExtResource("3_n1lus") uv1_triplanar = true [sub_resource type="BoxMesh" id="BoxMesh_plpqy"] @@ -44,13 +44,13 @@ left_to_right = -2.0 size = Vector3(5, 5, 5) [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_pfpgv"] -albedo_texture = ExtResource("4_wp15n") +albedo_texture = ExtResource("4_klpsf") uv1_triplanar = true [sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_rit6o"] data = PackedVector3Array(-12.5, 2.5, 2.5, 2.5, -2.5, 2.5, -2.5, -2.5, 2.5, -12.5, 2.5, -2.5, -2.5, -2.5, -2.5, 2.5, -2.5, -2.5, -12.5, 2.5, 2.5, -12.5, 2.5, -2.5, 2.5, -2.5, 2.5, -12.5, 2.5, -2.5, 2.5, -2.5, -2.5, 2.5, -2.5, 2.5, -12.5, 2.5, -2.5, -12.5, 2.5, 2.5, -2.5, -2.5, -2.5, -12.5, 2.5, 2.5, -2.5, -2.5, 2.5, -2.5, -2.5, -2.5, -2.5, -2.5, 2.5, 2.5, -2.5, 2.5, -2.5, -2.5, -2.5, 2.5, -2.5, 2.5, 2.5, -2.5, -2.5, -2.5, -2.5, -2.5) -[node name="World" type="World"] +[node name="World" type="Node3D"] [node name="WorldEnvironment" type="WorldEnvironment" parent="."] environment = SubResource("Environment_ctwiv") diff --git a/godot/Scenes/main.tscn b/godot/Scenes/main.tscn index 1312a1c..ee40fa4 100644 --- a/godot/Scenes/main.tscn +++ b/godot/Scenes/main.tscn @@ -8,5 +8,3 @@ [node name="Network" parent="." instance=ExtResource("1_06ibn")] [node name="MainMenu" parent="." instance=ExtResource("2_lavg1")] - -[connection signal="change_scene" from="MainMenu" to="." method="change_scene"] diff --git a/include/client/World.h b/include/blitz/godot/World.h similarity index 96% rename from include/client/World.h rename to include/blitz/godot/World.h index 183221b..e699a9e 100644 --- a/include/client/World.h +++ b/include/blitz/godot/World.h @@ -14,13 +14,12 @@ class World : public godot::Node3D, public protocol::PacketHandler { protected: static void _bind_methods(); - public: World(); ~World(); + public: // Godot overrides void _ready() override; - void _process(float delta); Player* GetPlayerById(PlayerID a_PlayerId); @@ -28,7 +27,7 @@ class World : public godot::Node3D, public protocol::PacketHandler { void HandlePacket(const protocol::packets::PlayerLeave&) override; void HandlePacket(const protocol::packets::PlayerPositionAndRotation&) override; - private: + protected: NetworkInterface* m_NetworkInterface; godot::Node* m_Players; float m_PassedTime; diff --git a/include/client/ClientWorld.h b/include/client/ClientWorld.h new file mode 100644 index 0000000..4b8087b --- /dev/null +++ b/include/client/ClientWorld.h @@ -0,0 +1,19 @@ +#include + +namespace blitz { + +class ClientWorld : public World { + GDCLASS(ClientWorld, World) + protected: + static void _bind_methods(); + + public: + ClientWorld(); + ~ClientWorld(); + void _process(float delta); + + private: + void UpdatePlayerPos(); +}; + +} // namespace blitz \ No newline at end of file diff --git a/include/client/Main.h b/include/client/Main.h index 6e6bfca..71bf9b4 100644 --- a/include/client/Main.h +++ b/include/client/Main.h @@ -13,7 +13,9 @@ class Main : public godot::Node { Main(); ~Main(); - void ChangeScene(); + void _ready() override; + + void ChangeScene(bool a_Server); }; } // namespace blitz \ No newline at end of file diff --git a/include/server/ServerWorld.h b/include/server/ServerWorld.h new file mode 100644 index 0000000..2f609f8 --- /dev/null +++ b/include/server/ServerWorld.h @@ -0,0 +1,19 @@ +#include + +namespace blitz { + +class ServerWorld : public World { + GDCLASS(ServerWorld, World) + protected: + static void _bind_methods(); + + public: + ServerWorld(); + ~ServerWorld(); + void _process(float delta); + + private: + void SyncPlayersPos(); +}; + +} // namespace blitz \ No newline at end of file diff --git a/src/client/World.cpp b/src/blitz/godot/World.cpp similarity index 78% rename from src/client/World.cpp rename to src/blitz/godot/World.cpp index 2d4d598..a0b0bb3 100644 --- a/src/client/World.cpp +++ b/src/blitz/godot/World.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -44,37 +44,6 @@ World::~World() { m_NetworkInterface->UnregisterHandler(*this); } -void World::_process(float delta) { -#if DEBUG_ENABLED - if (Engine::get_singleton()->is_editor_hint()) - return; -#endif - m_PassedTime += delta; - if (m_PassedTime < 0.05f) - return; - - // UtilityFunctions::print(m_PassedTime); - - // m_PassedTime -= 0.05f; - // if (m_PassedTime > 0.5f) - // m_PassedTime = 0.0f; - - if (get_multiplayer()->is_server()) { - for (int i = 0; i < m_Players->get_child_count(); i++) { - Player* player = Object::cast_to(m_Players->get_child(i)); - DEV_ASSERT(player); - m_NetworkInterface->BroadcastPacket( - protocol::packets::PlayerPositionAndRotation({player->GetId(), player->get_position(), player->GetCameraRotation()})); - } - } else { - Player* player = GetPlayerById(get_multiplayer()->get_unique_id()); - if (player) { - m_NetworkInterface->BroadcastPacket(protocol::packets::PlayerPositionAndRotation( - {get_multiplayer()->get_unique_id(), player->get_position(), player->GetCameraRotation()})); - } - } -} - Player* World::GetPlayerById(PlayerID a_PlayerId) { String stringId = UtilityFunctions::var_to_str(a_PlayerId); for (int i = 0; i < m_Players->get_child_count(); i++) { diff --git a/src/client/ClientWorld.cpp b/src/client/ClientWorld.cpp new file mode 100644 index 0000000..f140374 --- /dev/null +++ b/src/client/ClientWorld.cpp @@ -0,0 +1,39 @@ +#include + +#include +#include +#include +#include + +namespace blitz { + +using namespace godot; + +void ClientWorld::_bind_methods() {} + +ClientWorld::ClientWorld() {} + +ClientWorld::~ClientWorld() {} + +void ClientWorld::_process(float delta) { +#if DEBUG_ENABLED + if (Engine::get_singleton()->is_editor_hint()) + return; +#endif + m_PassedTime += delta; + if (m_PassedTime < 0.05f) + return; + + + UpdatePlayerPos(); +} + +void ClientWorld::UpdatePlayerPos() { + Player* player = GetPlayerById(get_multiplayer()->get_unique_id()); + if (player) { + m_NetworkInterface->BroadcastPacket(protocol::packets::PlayerPositionAndRotation( + {get_multiplayer()->get_unique_id(), player->get_position(), player->GetCameraRotation()})); + } +} + +} // namespace blitz \ No newline at end of file diff --git a/src/client/Main.cpp b/src/client/Main.cpp index 920e8b2..b38f556 100644 --- a/src/client/Main.cpp +++ b/src/client/Main.cpp @@ -7,26 +7,36 @@ #include #include -#include +#include +#include using namespace godot; namespace blitz { -static constexpr char MainScenePath[] = "res://Scenes/Levels/world.tscn"; +static constexpr char ClientWorldScenePath[] = "res://Scenes/Levels/client_world.tscn"; +static constexpr char ServerWorldScenePath[] = "res://Scenes/Levels/server_world.tscn"; -void Main::_bind_methods() { - godot::ClassDB::bind_method(godot::D_METHOD("change_scene"), &Main::ChangeScene); +void Main::_bind_methods() {} + +void Main::_ready() { + auto* mainMenu = find_child("MainMenu"); + DEV_ASSERT(mainMenu); + mainMenu->connect("change_scene_to_game", callable_mp(this, &Main::ChangeScene)); } Main::Main() {} Main::~Main() {} -void Main::ChangeScene() { - Ref sceneData = ResourceLoader::get_singleton()->load(MainScenePath); - World* world = Object::cast_to(sceneData->instantiate()); - add_child(world); +void Main::ChangeScene(bool a_Server) { + Ref sceneData; + if (a_Server) + sceneData = ResourceLoader::get_singleton()->load(ServerWorldScenePath); + else + sceneData = ResourceLoader::get_singleton()->load(ClientWorldScenePath); + + add_child(sceneData->instantiate()); } } // namespace blitz \ No newline at end of file diff --git a/src/client/MainMenu.cpp b/src/client/MainMenu.cpp index 7308ddc..2a02168 100644 --- a/src/client/MainMenu.cpp +++ b/src/client/MainMenu.cpp @@ -1,5 +1,7 @@ #include +#include +#include #include #include @@ -9,7 +11,7 @@ namespace blitz { void MainMenu::_bind_methods() { godot::ClassDB::bind_method(godot::D_METHOD("on_connected"), &MainMenu::OnConnected); - ADD_SIGNAL(MethodInfo("change_scene")); + ADD_SIGNAL(MethodInfo("change_scene_to_game", PropertyInfo(Variant::BOOL, "server"))); } MainMenu::MainMenu() {} @@ -28,19 +30,22 @@ void MainMenu::_ready() { DEV_ASSERT(m_CreateButton); DEV_ASSERT(m_QuitButton); - m_NetworkInterface = Object::cast_to(get_parent()->find_child("Network")); - DEV_ASSERT(m_NetworkInterface); - m_JoinButton->connect("pressed", callable_mp(this, &MainMenu::OnJoinPressed)); m_CreateButton->connect("pressed", callable_mp(this, &MainMenu::OnCreatePressed)); m_QuitButton->connect("pressed", callable_mp(this, &MainMenu::OnQuitPressed)); - m_NetworkInterface->connect("local_player_connected", callable_mp(this, &MainMenu::OnConnected)); - m_NetworkInterface->connect("server_disconnected", callable_mp(this, &MainMenu::OnDisconnected)); + + if (!Engine::get_singleton()->is_editor_hint()) { + m_NetworkInterface = Object::cast_to(get_parent()->find_child("Network")); + DEV_ASSERT(m_NetworkInterface); + + m_NetworkInterface->connect("local_player_connected", callable_mp(this, &MainMenu::OnConnected)); + m_NetworkInterface->connect("server_disconnected", callable_mp(this, &MainMenu::OnDisconnected)); + } } void MainMenu::OnConnected() { - emit_signal("change_scene"); + emit_signal("change_scene_to_game", get_multiplayer()->is_server()); set_visible(false); } diff --git a/src/client/register_types.cpp b/src/client/register_types.cpp index 1a3e84b..99b775e 100644 --- a/src/client/register_types.cpp +++ b/src/client/register_types.cpp @@ -1,10 +1,11 @@ #include +#include #include #include #include #include #include -#include +#include #include #include @@ -16,10 +17,12 @@ static void RegisterClasses() { GDREGISTER_CLASS(blitz::Player); GDREGISTER_CLASS(blitz::FirstPersonPlayer); GDREGISTER_CLASS(blitz::MainMenu); - GDREGISTER_CLASS(blitz::World); GDREGISTER_CLASS(blitz::Main); GDREGISTER_CLASS(blitz::NetworkInterface); GDREGISTER_CLASS(blitz::Server); + GDREGISTER_ABSTRACT_CLASS(blitz::World); + GDREGISTER_CLASS(blitz::ClientWorld); + GDREGISTER_CLASS(blitz::ServerWorld); } static void initialize_blitz_module(ModuleInitializationLevel p_level) { diff --git a/src/server/ServerWorld.cpp b/src/server/ServerWorld.cpp new file mode 100644 index 0000000..568e4cc --- /dev/null +++ b/src/server/ServerWorld.cpp @@ -0,0 +1,38 @@ +#include + +#include +#include +#include + +namespace blitz { + +using namespace godot; + +void ServerWorld::_bind_methods() {} + +ServerWorld::ServerWorld() {} + +ServerWorld::~ServerWorld() {} + +void ServerWorld::_process(float delta) { +#if DEBUG_ENABLED + if (Engine::get_singleton()->is_editor_hint()) + return; +#endif + m_PassedTime += delta; + if (m_PassedTime < 0.05f) + return; + + SyncPlayersPos(); +} + +void ServerWorld::SyncPlayersPos() { + for (int i = 0; i < m_Players->get_child_count(); i++) { + Player* player = Object::cast_to(m_Players->get_child(i)); + DEV_ASSERT(player); + m_NetworkInterface->BroadcastPacket( + protocol::packets::PlayerPositionAndRotation({player->GetId(), player->get_position(), player->GetCameraRotation()})); + } +} + +} // namespace blitz \ No newline at end of file From f557d0dd2d15f97def9545b7323b730e6d13f047 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Tue, 20 Aug 2024 18:51:01 +0200 Subject: [PATCH 15/23] ByteBuffer: handle read errors --- include/blitz/protocol/ByteBuffer.h | 53 ++++++++++++++----------- src/blitz/protocol/ByteBuffer.cpp | 34 +++++++++++++++- src/blitz/protocol/PacketSerializer.cpp | 4 +- 3 files changed, 64 insertions(+), 27 deletions(-) diff --git a/include/blitz/protocol/ByteBuffer.h b/include/blitz/protocol/ByteBuffer.h index 5540bae..95adeda 100644 --- a/include/blitz/protocol/ByteBuffer.h +++ b/include/blitz/protocol/ByteBuffer.h @@ -2,6 +2,7 @@ #include #include +#include #include namespace blitz { @@ -9,25 +10,17 @@ namespace protocol { class PlayerInfo; -#define Operators(Type, GodotType) \ - ByteBuffer& operator>>(Type& a_Data) { \ - a_Data = m_Buffer.decode_##GodotType(m_ReadOffset); \ - m_ReadOffset += sizeof(a_Data); \ - return *this; \ - } \ - \ - ByteBuffer& operator<<(Type a_Data) { \ - m_Buffer.resize(m_Buffer.size() + sizeof(a_Data)); \ - m_Buffer.encode_##GodotType(m_Buffer.size() - sizeof(a_Data), a_Data); \ - return *this; \ - } - class ByteBuffer { private: godot::PackedByteArray m_Buffer; std::size_t m_ReadOffset; public: + class ReadError : public std::runtime_error { + public: + ReadError(const std::string& msg) : std::runtime_error(msg) {} + }; + ByteBuffer(godot::PackedByteArray&& a_Buffer) : m_Buffer(std::move(a_Buffer)), m_ReadOffset(0) {} ByteBuffer() : m_ReadOffset(0) { m_Buffer.resize(0); @@ -42,18 +35,30 @@ class ByteBuffer { } // Integers - Operators(int8_t, s8); - Operators(uint8_t, u8); - Operators(int16_t, s16); - Operators(uint16_t, u16); - Operators(int32_t, s32); - Operators(uint32_t, u32); - Operators(int64_t, s64); - Operators(uint64_t, u64); + ByteBuffer& operator<<(int8_t a_Data); + ByteBuffer& operator>>(int8_t& a_Data); + ByteBuffer& operator<<(uint8_t a_Data); + ByteBuffer& operator>>(uint8_t& a_Data); - // Reals - Operators(float, float); - Operators(double, double); + ByteBuffer& operator<<(int16_t a_Data); + ByteBuffer& operator>>(int16_t& a_Data); + ByteBuffer& operator<<(uint16_t a_Data); + ByteBuffer& operator>>(uint16_t& a_Data); + + ByteBuffer& operator<<(int32_t a_Data); + ByteBuffer& operator>>(int32_t& a_Data); + ByteBuffer& operator<<(uint32_t a_Data); + ByteBuffer& operator>>(uint32_t& a_Data); + + ByteBuffer& operator<<(int64_t a_Data); + ByteBuffer& operator>>(int64_t& a_Data); + ByteBuffer& operator<<(uint64_t a_Data); + ByteBuffer& operator>>(uint64_t& a_Data); + + ByteBuffer& operator<<(float a_Data); + ByteBuffer& operator>>(float& a_Data); + ByteBuffer& operator<<(double a_Data); + ByteBuffer& operator>>(double& a_Data); ByteBuffer& operator<<(const godot::String& a_Data); ByteBuffer& operator>>(godot::String& a_Data); diff --git a/src/blitz/protocol/ByteBuffer.cpp b/src/blitz/protocol/ByteBuffer.cpp index 1916f7e..f0572fd 100644 --- a/src/blitz/protocol/ByteBuffer.cpp +++ b/src/blitz/protocol/ByteBuffer.cpp @@ -5,6 +5,36 @@ namespace blitz { namespace protocol { +#define Operators(Type, GodotType) \ + ByteBuffer& ByteBuffer::operator>>(Type& a_Data) { \ + if (sizeof(a_Data) + m_ReadOffset > m_Buffer.size()) { \ + throw ReadError("Buffer is too small ! Can't read " #Type); \ + } \ + a_Data = m_Buffer.decode_##GodotType(m_ReadOffset); \ + m_ReadOffset += sizeof(a_Data); \ + return *this; \ + } \ + \ + ByteBuffer& ByteBuffer::operator<<(Type a_Data) { \ + m_Buffer.resize(m_Buffer.size() + sizeof(a_Data)); \ + m_Buffer.encode_##GodotType(m_Buffer.size() - sizeof(a_Data), a_Data); \ + return *this; \ + } + +// Integers +Operators(int8_t, s8); +Operators(uint8_t, u8); +Operators(int16_t, s16); +Operators(uint16_t, u16); +Operators(int32_t, s32); +Operators(uint32_t, u32); +Operators(int64_t, s64); +Operators(uint64_t, u64); + +// Reals +Operators(float, float); +Operators(double, double); + ByteBuffer& ByteBuffer::operator>>(PlayerInfo& a_Data) { *this >> a_Data.m_PlayerId >> a_Data.m_PlayerName; return *this; @@ -27,9 +57,9 @@ ByteBuffer& ByteBuffer::operator>>(godot::Vector3& a_Data) { ByteBuffer& ByteBuffer::operator>>(godot::String& a_Data) { int nullPos = m_Buffer.find(0, m_ReadOffset); - // TODO: error handling if (nullPos < 0) - return *this; + throw ReadError("String does not have an and in buffer !"); + godot::PackedByteArray stringBuffer = m_Buffer.slice(m_ReadOffset, nullPos); a_Data = stringBuffer.get_string_from_utf8(); diff --git a/src/blitz/protocol/PacketSerializer.cpp b/src/blitz/protocol/PacketSerializer.cpp index 74b7bb1..5df73b3 100644 --- a/src/blitz/protocol/PacketSerializer.cpp +++ b/src/blitz/protocol/PacketSerializer.cpp @@ -68,7 +68,8 @@ class Deserializer : public PacketVisitor { bool Deserialize(const PacketPtr& a_Packet) { try { Check(*a_Packet.get()); - } catch (std::exception& e) { + } catch (ByteBuffer::ReadError& e) { + godot::UtilityFunctions::printerr("[PacketSerializer::Deserializer] ", e.what()); return false; } return true; @@ -109,6 +110,7 @@ std::unique_ptr Deserialize(godot::PackedByteArray& a_Data) { const PacketPtr& emptyPacket = PacketFactory::CreateReadOnlyPacket(packetType); Deserializer deserializer(std::move(stream)); + if (deserializer.Deserialize(emptyPacket)) { PacketPtr packet = std::move(deserializer.GetPacket()); return packet; From 03b6e577ea04f9884918946fd4ee7147c5b25d7d Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Tue, 20 Aug 2024 19:27:20 +0200 Subject: [PATCH 16/23] unreliable packets --- include/blitz/godot/NetworkInterface.h | 2 + include/blitz/protocol/PacketDeclare.h | 4 +- include/blitz/protocol/PacketSender.h | 57 ++++++++++++++++++++++++++ src/blitz/godot/NetworkInterface.cpp | 57 ++++++++++++++++++++------ src/blitz/protocol/PacketSender.cpp | 39 ++++++++++++++++++ 5 files changed, 144 insertions(+), 15 deletions(-) create mode 100644 include/blitz/protocol/PacketSender.h create mode 100644 src/blitz/protocol/PacketSender.cpp diff --git a/include/blitz/godot/NetworkInterface.h b/include/blitz/godot/NetworkInterface.h index 5f53cb1..483a190 100644 --- a/include/blitz/godot/NetworkInterface.h +++ b/include/blitz/godot/NetworkInterface.h @@ -27,6 +27,8 @@ class NetworkInterface : public godot::Node, public protocol::PacketDispatcher { private: void RecievePacketDataReliable(godot::PackedByteArray a_PacketData); + void RecievePacketDataUnreliable(godot::PackedByteArray a_PacketData); + void RecievePacketDataUnreliableOrdered(godot::PackedByteArray a_PacketData); void OnPlayerConnected(PeerID a_PeerId); void OnPlayerDisconnected(PeerID a_PeerId); diff --git a/include/blitz/protocol/PacketDeclare.h b/include/blitz/protocol/PacketDeclare.h index a4340cb..101671c 100644 --- a/include/blitz/protocol/PacketDeclare.h +++ b/include/blitz/protocol/PacketDeclare.h @@ -12,7 +12,7 @@ namespace protocol { * \enum PacketSender * \brief Indicate who should send a packet */ -enum class PacketSender { +enum class PacketSenderType { /** Sent by clients and server */ Both, /** Sent by clients to the server */ @@ -36,7 +36,7 @@ enum class PacketSender { DeclarePacket(PlayerLeave, Reliable, Server) \ DeclarePacket(PlayerList, Reliable, Server) \ DeclarePacket(PlayerLogin, Reliable, Client) \ - DeclarePacket(PlayerPositionAndRotation, Reliable, Both) \ + DeclarePacket(PlayerPositionAndRotation, Unreliable, Both) \ DeclarePacket(PlayerShoot, Reliable, Both) \ DeclarePacket(PlayerStats, Reliable, Server) \ DeclarePacket(ServerConfig, Reliable, Server) \ diff --git a/include/blitz/protocol/PacketSender.h b/include/blitz/protocol/PacketSender.h new file mode 100644 index 0000000..e33f9d6 --- /dev/null +++ b/include/blitz/protocol/PacketSender.h @@ -0,0 +1,57 @@ +#pragma once + +#include + +namespace blitz { + +class NetworkInterface; + +namespace protocol { + +/////////////////////// +/* PacketBroadcaster */ +/////////////////////// + +#define DeclarePacket(PacketName, Reliability, ...) void Visit(const protocol::packets::PacketName& a_Packet) override; + +class PacketBroadcaster : public protocol::PacketVisitor { + private: + NetworkInterface& m_NetworkInterface; + + public: + PacketBroadcaster(NetworkInterface& a_NetworkInterface) : m_NetworkInterface(a_NetworkInterface) {} + + void BroadcastPacket(const protocol::Packet& a_Packet) { + Check(a_Packet); + } + + DeclareAllPacket() +}; + + + + + + +////////////////// +/* PacketSender */ +////////////////// +class PacketSender : public protocol::PacketVisitor { + private: + NetworkInterface& m_NetworkInterface; + PeerID m_PeerId; + + public: + PacketSender(PeerID a_PeerId, NetworkInterface& a_NetworkInterface) : m_PeerId(a_PeerId), m_NetworkInterface(a_NetworkInterface) {} + + void SendPacket(const protocol::Packet& a_Packet) { + Check(a_Packet); + } + + DeclareAllPacket() +}; + +#undef DeclarePacket + +} // namespace protocol +} // namespace blitz diff --git a/src/blitz/godot/NetworkInterface.cpp b/src/blitz/godot/NetworkInterface.cpp index a412d2c..d69bfde 100644 --- a/src/blitz/godot/NetworkInterface.cpp +++ b/src/blitz/godot/NetworkInterface.cpp @@ -1,21 +1,37 @@ #include #include +#include #include +#include #include #include #include #include #include + namespace blitz { +#define RPC_CONFIG(functionName, rpc_mode, transfer_mode, call_local, channel) \ + { \ + Dictionary config; \ + config["rpc_mode"] = rpc_mode; \ + config["transfer_mode"] = transfer_mode; \ + config["call_local"] = call_local; \ + config["channel"] = channel; \ + rpc_config(functionName, config); \ + } + static const char ServerScenePath[] = "res://Scenes/Network/server.tscn"; using namespace godot; void NetworkInterface::_bind_methods() { ClassDB::bind_method(D_METHOD("RecievePacketDataReliable", "a_PacketData"), &NetworkInterface::RecievePacketDataReliable); + ClassDB::bind_method(D_METHOD("RecievePacketDataUnreliable", "a_PacketData"), &NetworkInterface::RecievePacketDataUnreliable); + ClassDB::bind_method( + D_METHOD("RecievePacketDataUnreliableOrdered", "a_PacketData"), &NetworkInterface::RecievePacketDataUnreliableOrdered); // server ADD_SIGNAL(MethodInfo("player_connected", PropertyInfo(Variant::INT, "peer_id"))); @@ -33,13 +49,10 @@ NetworkInterface::NetworkInterface() {} NetworkInterface::~NetworkInterface() {} void NetworkInterface::_ready() { - // TODO: unreliable - Dictionary config; - config["rpc_mode"] = MultiplayerAPI::RPC_MODE_ANY_PEER; - config["transfer_mode"] = MultiplayerPeer::TRANSFER_MODE_RELIABLE; - config["call_local"] = true; - config["channel"] = 0; - rpc_config("RecievePacketDataReliable", config); + RPC_CONFIG("RecievePacketDataReliable", MultiplayerAPI::RPC_MODE_ANY_PEER, MultiplayerPeer::TRANSFER_MODE_RELIABLE, true, 0); + RPC_CONFIG("RecievePacketDataUnreliable", MultiplayerAPI::RPC_MODE_ANY_PEER, MultiplayerPeer::TRANSFER_MODE_UNRELIABLE, true, 1); + RPC_CONFIG("RecievePacketDataUnreliableOrdered", MultiplayerAPI::RPC_MODE_ANY_PEER, + MultiplayerPeer::TRANSFER_MODE_UNRELIABLE_ORDERED, true, 2); get_multiplayer()->connect("peer_connected", callable_mp(this, &NetworkInterface::OnPlayerConnected)); get_multiplayer()->connect("peer_disconnected", callable_mp(this, &NetworkInterface::OnPlayerDisconnected)); @@ -49,13 +62,13 @@ void NetworkInterface::_ready() { } void NetworkInterface::BroadcastPacket(const protocol::Packet& a_Packet) { - PackedByteArray byteArray = protocol::PacketSerializer::Serialize(a_Packet); - rpc("RecievePacketDataReliable", byteArray); + protocol::PacketBroadcaster packetBroadcaster(*this); + packetBroadcaster.BroadcastPacket(a_Packet); } void NetworkInterface::SendPacket(PeerID a_Peer, const protocol::Packet& a_Packet) { - PackedByteArray byteArray = protocol::PacketSerializer::Serialize(a_Packet); - rpc_id(a_Peer, "RecievePacketDataReliable", byteArray); + protocol::PacketSender packetSender(a_Peer, *this); + packetSender.SendPacket(a_Packet); } void NetworkInterface::RecievePacketDataReliable(godot::PackedByteArray a_PacketData) { @@ -66,9 +79,27 @@ void NetworkInterface::RecievePacketDataReliable(godot::PackedByteArray a_Packet } } +void NetworkInterface::RecievePacketDataUnreliable(godot::PackedByteArray a_PacketData) { + // we have to copy the function body in order to preserve the remote sender id + auto packet = protocol::PacketSerializer::Deserialize(a_PacketData); + if (packet) { + packet->m_Sender = get_multiplayer()->get_remote_sender_id(); + Dispatch(*packet); + } +} + +void NetworkInterface::RecievePacketDataUnreliableOrdered(godot::PackedByteArray a_PacketData) { + // we have to copy the function body in order to preserve the remote sender id + auto packet = protocol::PacketSerializer::Deserialize(a_PacketData); + if (packet) { + packet->m_Sender = get_multiplayer()->get_remote_sender_id(); + Dispatch(*packet); + } +} + Error NetworkInterface::JoinGame(const String& a_Address, uint16_t a_Port) { auto* peer = memnew(ENetMultiplayerPeer); - Error error = peer->create_client(a_Address, a_Port); + Error error = peer->create_client(a_Address, a_Port, 3); if (error) { OnConnectFail(); return error; @@ -80,7 +111,7 @@ Error NetworkInterface::JoinGame(const String& a_Address, uint16_t a_Port) { Error NetworkInterface::CreateGame(uint16_t a_Port, bool a_Dedicated) { auto* peer = memnew(ENetMultiplayerPeer); - Error error = peer->create_server(a_Port); + Error error = peer->create_server(a_Port, 50, 3); if (error) return error; diff --git a/src/blitz/protocol/PacketSender.cpp b/src/blitz/protocol/PacketSender.cpp new file mode 100644 index 0000000..33eb245 --- /dev/null +++ b/src/blitz/protocol/PacketSender.cpp @@ -0,0 +1,39 @@ +#include + +#include +#include + +namespace blitz { +namespace protocol { + +/////////////////////// +/* PacketBroadcaster */ +/////////////////////// + +#define DeclarePacket(PacketName, Reliability, ...) \ + void PacketBroadcaster::Visit(const protocol::packets::PacketName& a_Packet) { \ + m_NetworkInterface.rpc("RecievePacketData" #Reliability, protocol::PacketSerializer::Serialize(a_Packet)); \ + } + +DeclareAllPacket() + +#undef DeclarePacket + + + + + +////////////////// +/* PacketSender */ +////////////////// +#define DeclarePacket(PacketName, Reliability, ...) \ + void PacketSender::Visit(const protocol::packets::PacketName& a_Packet) { \ + m_NetworkInterface.rpc_id(m_PeerId, "RecievePacketData" #Reliability, protocol::PacketSerializer::Serialize(a_Packet)); \ + } + + DeclareAllPacket() + +#undef DeclarePacket + +} // namespace protocol +} // namespace blitz From d3dddff00539ca86cfd728dc22878e1564a24309 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Wed, 21 Aug 2024 10:22:57 +0200 Subject: [PATCH 17/23] very small refactor --- include/blitz/protocol/PacketSender.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/blitz/protocol/PacketSender.h b/include/blitz/protocol/PacketSender.h index e33f9d6..a3a1afc 100644 --- a/include/blitz/protocol/PacketSender.h +++ b/include/blitz/protocol/PacketSender.h @@ -8,12 +8,15 @@ class NetworkInterface; namespace protocol { +#define DeclarePacket(PacketName, Reliability, ...) void Visit(const protocol::packets::PacketName& a_Packet) override; + + + + + /////////////////////// /* PacketBroadcaster */ /////////////////////// - -#define DeclarePacket(PacketName, Reliability, ...) void Visit(const protocol::packets::PacketName& a_Packet) override; - class PacketBroadcaster : public protocol::PacketVisitor { private: NetworkInterface& m_NetworkInterface; From 6ee87733ca53e4eecb1edc33966c7903b7e3d54b Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Wed, 21 Aug 2024 10:29:42 +0200 Subject: [PATCH 18/23] network: send player velocity --- include/blitz/godot/World.h | 3 ++- include/blitz/protocol/PacketData.h | 1 + src/blitz/godot/World.cpp | 6 ++++-- src/blitz/protocol/PacketSerializer.cpp | 15 ++------------- src/client/ClientWorld.cpp | 2 +- src/server/ServerWorld.cpp | 4 ++-- 6 files changed, 12 insertions(+), 19 deletions(-) diff --git a/include/blitz/godot/World.h b/include/blitz/godot/World.h index e699a9e..272ed84 100644 --- a/include/blitz/godot/World.h +++ b/include/blitz/godot/World.h @@ -35,6 +35,7 @@ class World : public godot::Node3D, public protocol::PacketHandler { void AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName); void RemovePlayer(PlayerID a_PlayerId); - void SetPlayerPositionAndRotation(PlayerID a_PlayerId, const godot::Vector3& a_Position, const godot::Vector3& a_Rotation); + void SetPlayerPositionAndRotation( + PlayerID a_PlayerId, const godot::Vector3& a_Position, const godot::Vector3& a_Rotation, const godot::Vector3& a_Velocity); }; } // namespace blitz \ No newline at end of file diff --git a/include/blitz/protocol/PacketData.h b/include/blitz/protocol/PacketData.h index 0587af7..2c5174c 100644 --- a/include/blitz/protocol/PacketData.h +++ b/include/blitz/protocol/PacketData.h @@ -63,6 +63,7 @@ struct PlayerPositionAndRotation { PlayerID m_Player; godot::Vector3 m_Position; godot::Vector3 m_Rotation; + godot::Vector3 m_Velocity; }; struct PlayerShoot {}; diff --git a/src/blitz/godot/World.cpp b/src/blitz/godot/World.cpp index a0b0bb3..86b547f 100644 --- a/src/blitz/godot/World.cpp +++ b/src/blitz/godot/World.cpp @@ -69,7 +69,7 @@ void World::HandlePacket(const protocol::packets::PlayerPositionAndRotation& a_P if (data.m_Player == get_multiplayer()->get_unique_id() || data.m_Player != a_PlayerPos.m_Sender) return; - SetPlayerPositionAndRotation(data.m_Player, data.m_Position, data.m_Rotation); + SetPlayerPositionAndRotation(data.m_Player, data.m_Position, data.m_Rotation, data.m_Velocity); } void World::AddPlayer(PlayerID a_PlayerId, String a_PlayerName) { @@ -97,11 +97,13 @@ void World::RemovePlayer(PlayerID a_PlayerId) { } } -void World::SetPlayerPositionAndRotation(PlayerID a_PlayerId, const Vector3& a_Position, const Vector3& a_Rotation) { +void World::SetPlayerPositionAndRotation( + PlayerID a_PlayerId, const Vector3& a_Position, const Vector3& a_Rotation, const godot::Vector3& a_Velocity) { Player* player = GetPlayerById(a_PlayerId); if (player) { player->set_position(a_Position); player->SetCameraRotation(a_Rotation); + player->set_velocity(a_Velocity); } } diff --git a/src/blitz/protocol/PacketSerializer.cpp b/src/blitz/protocol/PacketSerializer.cpp index 5df73b3..0be9097 100644 --- a/src/blitz/protocol/PacketSerializer.cpp +++ b/src/blitz/protocol/PacketSerializer.cpp @@ -195,21 +195,10 @@ void Deserializer::DeserializePacketData(data::PlayerLeave& a_Packet) { void Serializer::SerializePacketData(const data::PlayerList& a_Packet) { m_Buffer << a_Packet.m_Players; - // m_Buffer << static_cast(a_Packet.m_Players.size()); - // for (auto player : a_Packet.m_Players) { - // m_Buffer << player.m_PlayerId << player.m_PlayerName; - // } } void Deserializer::DeserializePacketData(data::PlayerList& a_Packet) { m_Buffer >> a_Packet.m_Players; - // std::uint8_t playerCount; - // m_Buffer >> playerCount; - // for (std::uint8_t i = 0; i < playerCount; i++) { - // PlayerInfo player; - // m_Buffer >> player.m_PlayerId >> player.m_PlayerName; - // a_Packet.m_Players.push_back(player); - // } } @@ -273,11 +262,11 @@ void Deserializer::DeserializePacketData(data::ChatMessage& a_Packet) { void Serializer::SerializePacketData(const data::PlayerPositionAndRotation& a_Packet) { - m_Buffer << a_Packet.m_Player << a_Packet.m_Position << a_Packet.m_Rotation; + m_Buffer << a_Packet.m_Player << a_Packet.m_Position << a_Packet.m_Rotation << a_Packet.m_Velocity; } void Deserializer::DeserializePacketData(data::PlayerPositionAndRotation& a_Packet) { - m_Buffer >> a_Packet.m_Player >> a_Packet.m_Position >> a_Packet.m_Rotation; + m_Buffer >> a_Packet.m_Player >> a_Packet.m_Position >> a_Packet.m_Rotation >> a_Packet.m_Velocity; } diff --git a/src/client/ClientWorld.cpp b/src/client/ClientWorld.cpp index f140374..4f30631 100644 --- a/src/client/ClientWorld.cpp +++ b/src/client/ClientWorld.cpp @@ -32,7 +32,7 @@ void ClientWorld::UpdatePlayerPos() { Player* player = GetPlayerById(get_multiplayer()->get_unique_id()); if (player) { m_NetworkInterface->BroadcastPacket(protocol::packets::PlayerPositionAndRotation( - {get_multiplayer()->get_unique_id(), player->get_position(), player->GetCameraRotation()})); + {get_multiplayer()->get_unique_id(), player->get_position(), player->GetCameraRotation(), player->get_velocity()})); } } diff --git a/src/server/ServerWorld.cpp b/src/server/ServerWorld.cpp index 568e4cc..8c86fa7 100644 --- a/src/server/ServerWorld.cpp +++ b/src/server/ServerWorld.cpp @@ -30,8 +30,8 @@ void ServerWorld::SyncPlayersPos() { for (int i = 0; i < m_Players->get_child_count(); i++) { Player* player = Object::cast_to(m_Players->get_child(i)); DEV_ASSERT(player); - m_NetworkInterface->BroadcastPacket( - protocol::packets::PlayerPositionAndRotation({player->GetId(), player->get_position(), player->GetCameraRotation()})); + m_NetworkInterface->BroadcastPacket(protocol::packets::PlayerPositionAndRotation( + {player->GetId(), player->get_position(), player->GetCameraRotation(), player->get_velocity()})); } } From e17387b867194d660652efe7513fa7a01820a5b9 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Wed, 21 Aug 2024 12:28:40 +0200 Subject: [PATCH 19/23] add packet declare syntax check --- include/blitz/protocol/PacketDeclare.h | 8 +++++++- src/blitz/protocol/Packets.cpp | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/blitz/protocol/PacketDeclare.h b/include/blitz/protocol/PacketDeclare.h index 101671c..dd19355 100644 --- a/include/blitz/protocol/PacketDeclare.h +++ b/include/blitz/protocol/PacketDeclare.h @@ -14,13 +14,19 @@ namespace protocol { */ enum class PacketSenderType { /** Sent by clients and server */ - Both, + Both = 1, /** Sent by clients to the server */ Client, /** Sent by server to the clients */ Server, }; +enum class PacketSendType { + Reliable = 1, + Unreliable, + UnreliableOrdered, +}; + /** * \def DeclareAllPacket diff --git a/src/blitz/protocol/Packets.cpp b/src/blitz/protocol/Packets.cpp index 84913b0..38fdeeb 100644 --- a/src/blitz/protocol/Packets.cpp +++ b/src/blitz/protocol/Packets.cpp @@ -14,5 +14,9 @@ void packets::ConcretePacket::Accept(PacketVisitor& a_Visitor) const { a_Visitor.Visit(*this); } +#define DeclarePacket(PacketName, packetSendType, packetSenderType) static_assert(static_cast(PacketSendType::packetSendType) && static_cast(PacketSenderType::packetSenderType)); + +DeclareAllPacket() + } // namespace protocol } // namespace blitz From 1bd053aba3ee94e2381c6ae0ed7d66270d4c22f0 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Wed, 21 Aug 2024 12:52:00 +0200 Subject: [PATCH 20/23] fix position sync issues --- .../Characters/first_person_player.tscn | 5 +- godot/Scenes/Characters/player.tscn | 93 +++++++++---------- include/blitz/godot/World.h | 1 - include/client/ClientWorld.h | 2 + include/client/FirstPersonPlayer.h | 2 +- include/client/Player.h | 3 +- include/server/ServerWorld.h | 3 +- src/blitz/godot/World.cpp | 8 -- src/blitz/protocol/Packets.cpp | 3 +- src/client/ClientWorld.cpp | 18 ++++ src/client/FirstPersonPlayer.cpp | 9 +- src/client/Player.cpp | 15 ++- src/server/ServerWorld.cpp | 9 ++ 13 files changed, 98 insertions(+), 73 deletions(-) diff --git a/godot/Scenes/Characters/first_person_player.tscn b/godot/Scenes/Characters/first_person_player.tscn index 1449b9f..7c4a05a 100644 --- a/godot/Scenes/Characters/first_person_player.tscn +++ b/godot/Scenes/Characters/first_person_player.tscn @@ -2,8 +2,7 @@ [sub_resource type="CapsuleMesh" id="CapsuleMesh_ky6st"] -[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_qjfxs"] -points = PackedVector3Array(-0.125207, -0.532801, -0.480507, 0.0227831, 0.47607, 0.498884, 0.169713, 0.559144, 0.464172, 0.231051, -0.803591, 0.320455, 0.40741, 0.651043, -0.243523, -0.482789, 0.594843, 0.0822132, -0.362868, -0.682312, 0.289697, 0.469044, -0.654529, -0.0662713, -0.127444, 0.842701, -0.338103, -0.393435, -0.683942, -0.244717, 0.438255, 0.623309, 0.200849, 0.0841477, 0.977454, 0.114795, -0.0682023, -0.976458, -0.12927, 0.20055, -0.563129, -0.451454, -0.185527, 0.595453, -0.453475, -0.273363, 0.592268, 0.407754, -0.00693649, -0.476823, 0.49966, 0.375821, -0.588614, 0.316955, 0.111579, 0.563059, -0.481177, -0.41725, 0.527866, -0.270497, -0.484546, -0.596972, -0.0665097, -0.279747, 0.908561, 0.0533361, -0.250197, -0.880712, 0.205319, 0.263647, -0.902771, -0.127394, 0.293368, 0.871526, -0.157196, 0.373412, -0.526319, -0.328246, 0.499663, 0.476641, -0.00688856, 0.0531056, 0.875001, 0.324703, -0.154543, -0.590854, 0.465879, -0.0972799, -0.782358, -0.398188, -0.387649, -0.498171, 0.31565, -0.30068, -0.587995, -0.388901) +[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_snsyg"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_gwsuw"] resource_name = "Beta_Joints_MAT1" @@ -3283,7 +3282,7 @@ mesh = SubResource("CapsuleMesh_ky6st") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) -shape = SubResource("ConvexPolygonShape3D_qjfxs") +shape = SubResource("CapsuleShape3D_snsyg") [node name="Head" type="Node3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.579, 0) diff --git a/godot/Scenes/Characters/player.tscn b/godot/Scenes/Characters/player.tscn index 2ebef8c..a7b4cc0 100644 --- a/godot/Scenes/Characters/player.tscn +++ b/godot/Scenes/Characters/player.tscn @@ -254,9 +254,7 @@ _surfaces = [{ }] blend_shape_mode = 0 -[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_mm42w"] -radius = 0.283343 -height = 1.84319 +[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_p1dvg"] [sub_resource type="Animation" id="Animation_jas7c"] resource_name = "Air-loop" @@ -3273,7 +3271,6 @@ nodes/output/position = Vector2(860, 160) node_connections = [&"ground_air_transition", 0, &"iwr_blend", &"ground_air_transition", 1, &"Air", &"iwr_blend", 0, &"Idle", &"iwr_blend", 1, &"Walk", &"iwr_blend", 2, &"Run", &"output", 0, &"ground_air_transition"] [node name="Player" type="Player"] -velocity = Vector3(0, -5821.84, 0) [node name="Mesh" type="Node3D" parent="."] @@ -3285,43 +3282,43 @@ bones/0/name = "Hips" bones/0/parent = -1 bones/0/rest = Transform3D(1, -5.00981e-07, 6.47142e-09, 0, 0.0129164, 0.999917, -5.01023e-07, -0.999917, 0.0129164, -7.72729e-06, 1.55432, -104.275) bones/0/enabled = true -bones/0/position = Vector3(-0.00545547, 1.5608, -104.173) -bones/0/rotation = Quaternion(-0.673975, -0.26086, 0.257429, 0.641436) +bones/0/position = Vector3(-0.00545729, 1.56079, -104.173) +bones/0/rotation = Quaternion(-0.674952, -0.262938, 0.255891, 0.640175) bones/0/scale = Vector3(1, 1, 1) bones/1/name = "Spine" bones/1/parent = 0 bones/1/rest = Transform3D(1, 4.9454e-07, 3.97682e-08, -4.9454e-07, 0.98715, 0.159796, 3.97681e-08, -0.159796, 0.98715, -4.1641e-10, 10.1824, 4.47034e-08) bones/1/enabled = true bones/1/position = Vector3(-4.1641e-10, 10.1824, 4.47034e-08) -bones/1/rotation = Quaternion(0.0494452, 0.00102938, -0.0281418, 0.99838) +bones/1/rotation = Quaternion(0.0492163, 0.000532408, -0.02752, 0.998409) bones/1/scale = Vector3(1, 1, 1) bones/2/name = "Spine1" bones/2/parent = 1 bones/2/rest = Transform3D(1, 4.13003e-14, -6.10621e-16, -4.13003e-14, 1, 5.96046e-08, 6.10624e-16, -5.96046e-08, 1, -6.45306e-12, 10.0027, 2.63751e-06) bones/2/enabled = true bones/2/position = Vector3(-6.45306e-12, 10.0027, 2.63751e-06) -bones/2/rotation = Quaternion(0.25634, 0.00456356, -0.0680245, 0.964179) +bones/2/rotation = Quaternion(0.255913, 0.00352153, -0.0657837, 0.964453) bones/2/scale = Vector3(1, 1, 1) bones/3/name = "Spine2" bones/3/parent = 2 bones/3/rest = Transform3D(1, 7.40298e-08, -1.9083e-09, -7.40543e-08, 0.999668, -0.0257692, -2.13163e-14, 0.0257692, 0.999668, -6.39488e-13, 9.32208, -1.54972e-06) bones/3/enabled = true bones/3/position = Vector3(-6.39488e-13, 9.32208, -1.54972e-06) -bones/3/rotation = Quaternion(0.268751, 0.00362875, -0.0681548, 0.960789) +bones/3/rotation = Quaternion(0.268319, 0.00267362, -0.0658236, 0.961075) bones/3/scale = Vector3(1, 1, 1) bones/4/name = "Neck" bones/4/parent = 3 bones/4/rest = Transform3D(1, -1.45661e-13, -1.46549e-14, 1.45661e-13, 1, -1.86265e-08, 1.46549e-14, 1.86265e-08, 1, 4.13195e-10, 16.8654, 4.15668e-13) bones/4/enabled = true bones/4/position = Vector3(4.13195e-10, 16.8654, 4.15668e-13) -bones/4/rotation = Quaternion(0.0150258, 0.0423437, -0.0448451, 0.997983) +bones/4/rotation = Quaternion(0.0137645, 0.0488776, -0.0564687, 0.997112) bones/4/scale = Vector3(1, 1, 1) bones/5/name = "Head" bones/5/parent = 4 bones/5/rest = Transform3D(1, 7.74936e-14, 5.77316e-15, -7.74936e-14, 1, 4.47035e-08, -5.77316e-15, -4.47035e-08, 1, -1.07566e-07, 9.3419, 2.84104) bones/5/enabled = true bones/5/position = Vector3(-1.07566e-07, 9.3419, 2.84104) -bones/5/rotation = Quaternion(0.00920543, 0.0563305, 0.022933, 0.998106) +bones/5/rotation = Quaternion(0.011752, 0.0558241, 0.0292939, 0.997942) bones/5/scale = Vector3(1, 1, 1) bones/6/name = "HeadTop_End" bones/6/parent = 5 @@ -3335,42 +3332,42 @@ bones/7/parent = 3 bones/7/rest = Transform3D(-0.205696, -0.977364, 0.0494833, -0.129005, -0.0230424, -0.991376, 0.970076, -0.210305, -0.121346, -4.56997, 11.1959, -0.806634) bones/7/enabled = true bones/7/position = Vector3(-4.56997, 11.1959, -0.806634) -bones/7/rotation = Quaternion(-0.407796, 0.575185, -0.614273, -0.354307) +bones/7/rotation = Quaternion(-0.41009, 0.574024, -0.615595, -0.351234) bones/7/scale = Vector3(1, 1, 1) bones/8/name = "RightArm" bones/8/parent = 7 bones/8/rest = Transform3D(0.978563, 0.205696, 0.0101912, -0.205948, 0.977364, 0.0484225, -2.57045e-07, -0.0494833, 0.998775, -3.57628e-07, 10.8382, -1.46913e-05) bones/8/enabled = true bones/8/position = Vector3(1.96774e-07, 10.8382, -3.20984e-07) -bones/8/rotation = Quaternion(0.203226, 0.203129, -0.0329129, 0.957264) +bones/8/rotation = Quaternion(0.211294, 0.201632, -0.0386556, 0.955618) bones/8/scale = Vector3(1, 1, 1) bones/9/name = "RightForeArm" bones/9/parent = 8 bones/9/rest = Transform3D(1, -5.8991e-08, -1.67444e-07, 5.8991e-08, 1, -9.42509e-15, 1.67444e-07, -4.52622e-16, 1, -1.01963e-05, 27.8415, -1.44409e-05) bones/9/enabled = true bones/9/position = Vector3(-1.00907e-05, 27.8415, -3.06037e-05) -bones/9/rotation = Quaternion(0.016868, -0.0422137, -0.187411, 0.981229) +bones/9/rotation = Quaternion(0.0174234, -0.0442375, -0.187662, 0.981082) bones/9/scale = Vector3(1, 1, 1) bones/10/name = "RightHand" bones/10/parent = 9 bones/10/rest = Transform3D(1, -1.90228e-09, 1.90222e-09, 1.90228e-09, 1, 1.10216e-13, -1.90222e-09, -1.10212e-13, 1, 1.54253e-05, 28.3288, 1.70057e-05) bones/10/enabled = true bones/10/position = Vector3(1.5054e-05, 28.3288, 8.42971e-07) -bones/10/rotation = Quaternion(-0.29465, 0.0869538, -0.124768, 0.943426) +bones/10/rotation = Quaternion(-0.311762, 0.048629, -0.109617, 0.942562) bones/10/scale = Vector3(1, 1, 1) bones/11/name = "RightHandThumb1" bones/11/parent = 10 bones/11/rest = Transform3D(0.888246, 0.459367, 6.78003e-07, -0.396939, 0.767535, -0.503319, -0.231209, 0.447071, 0.864101, 2.68185, 2.46481, 1.57399) bones/11/enabled = true bones/11/position = Vector3(2.68185, 2.46481, 1.57397) -bones/11/rotation = Quaternion(0.2394, 0.160363, -0.215536, 0.933014) +bones/11/rotation = Quaternion(0.248563, 0.146822, -0.244856, 0.925584) bones/11/scale = Vector3(1, 1, 1) bones/12/name = "RightHandThumb2" bones/12/parent = 11 bones/12/rest = Transform3D(0.999824, -0.0185942, -0.0023841, 0.0186051, 0.999816, 0.00460874, 0.00229796, -0.00465229, 0.999986, 3.93391e-06, 4.18899, 7.30372e-06) bones/12/enabled = true bones/12/position = Vector3(-4.17233e-06, 4.18898, -1.18934e-05) -bones/12/rotation = Quaternion(-0.115742, 0.0900667, 0.192157, 0.970344) +bones/12/rotation = Quaternion(-0.107896, 0.082565, 0.177687, 0.974663) bones/12/scale = Vector3(1, 1, 1) bones/13/name = "RightHandThumb3" bones/13/parent = 12 @@ -3391,14 +3388,14 @@ bones/15/parent = 10 bones/15/rest = Transform3D(1, 0.000328245, -7.43808e-08, -0.000328245, 1, 2.44166e-11, 7.43808e-08, -1.4988e-15, 1, 2.25983, 9.10829, 0.517869) bones/15/enabled = true bones/15/position = Vector3(2.25983, 9.10828, 0.517853) -bones/15/rotation = Quaternion(0.11025, 0.00650945, 0.00551306, 0.993867) +bones/15/rotation = Quaternion(0.0830017, 0.00512602, 0.00685563, 0.996513) bones/15/scale = Vector3(1, 1, 1) bones/16/name = "RightHandIndex2" bones/16/parent = 15 bones/16/rest = Transform3D(1, -0.000511482, 3.19887e-07, 0.000511482, 1, 1.0708e-05, -3.25364e-07, -1.07078e-05, 1, -7.49751e-08, 3.69999, 1.65342e-05) bones/16/enabled = true bones/16/position = Vector3(1.82747e-07, 3.7, 7.39788e-07) -bones/16/rotation = Quaternion(0.165573, 0.0101262, 0.00848687, 0.986109) +bones/16/rotation = Quaternion(0.154202, 0.00991445, 0.00963483, 0.987943) bones/16/scale = Vector3(1, 1, 1) bones/17/name = "RightHandIndex3" bones/17/parent = 16 @@ -3419,14 +3416,14 @@ bones/19/parent = 10 bones/19/rest = Transform3D(1, 0.0010033, 8.39909e-08, -0.0010033, 1, 6.61679e-11, -8.39908e-08, -1.50436e-10, 1, -2.58012e-05, 9.53251, 4.75128e-05) bones/19/enabled = true bones/19/position = Vector3(-2.61725e-05, 9.5325, 3.135e-05) -bones/19/rotation = Quaternion(0.1721, 0.00873778, 0.0157109, 0.984915) +bones/19/rotation = Quaternion(0.147732, 0.0111146, 0.0265099, 0.98861) bones/19/scale = Vector3(1, 1, 1) bones/20/name = "RightHandMiddle2" bones/20/parent = 19 bones/20/rest = Transform3D(0.999998, -0.00169976, 6.79326e-08, 0.00169976, 0.999998, 5.1725e-06, -7.67245e-08, -5.17238e-06, 1, 4.37467e-07, 3.70001, 1.65339e-05) bones/20/enabled = true bones/20/position = Vector3(5.8697e-08, 3.70001, -3.01458e-05) -bones/20/rotation = Quaternion(0.29122, 0.00291729, -0.0159203, 0.956519) +bones/20/rotation = Quaternion(0.254491, 0.00271635, -0.01288, 0.966986) bones/20/scale = Vector3(1, 1, 1) bones/21/name = "RightHandMiddle3" bones/21/parent = 20 @@ -3447,14 +3444,14 @@ bones/23/parent = 10 bones/23/rest = Transform3D(1, -0.000311951, 2.28835e-07, 0.000311951, 1, 7.13874e-11, -2.28835e-07, -1.97758e-15, 1, -1.86514, 9.1036, 0.0430626) bones/23/enabled = true bones/23/position = Vector3(-1.86514, 9.1036, 0.0430626) -bones/23/rotation = Quaternion(0.230492, 0.00939941, 0.0756768, 0.970082) +bones/23/rotation = Quaternion(0.181591, 0.0278997, 0.069303, 0.980532) bones/23/scale = Vector3(1, 1, 1) bones/24/name = "RightHandRing2" bones/24/parent = 23 bones/24/rest = Transform3D(1, 0.000442856, 1.18525e-07, -0.000442856, 1, 5.28028e-06, -1.16186e-07, -5.28033e-06, 1, -2.23002e-07, 3.37928, 6.29645e-07) bones/24/enabled = true bones/24/position = Vector3(-2.23002e-07, 3.37928, 6.29645e-07) -bones/24/rotation = Quaternion(0.355641, -0.00404305, -0.0360694, 0.933917) +bones/24/rotation = Quaternion(0.317146, -0.00384532, -0.0329689, 0.947796) bones/24/scale = Vector3(1, 1, 1) bones/25/name = "RightHandRing3" bones/25/parent = 24 @@ -3475,14 +3472,14 @@ bones/27/parent = 10 bones/27/rest = Transform3D(0.999999, -0.00104089, 1.35743e-07, 0.00104089, 0.999999, -8.47695e-06, -1.26919e-07, 8.47709e-06, 1, -3.80628, 8.07669, 0.486713) bones/27/enabled = true bones/27/position = Vector3(-3.80628, 8.07668, 0.486696) -bones/27/rotation = Quaternion(0.293242, 0.0144781, 0.0775827, 0.952775) +bones/27/rotation = Quaternion(0.247856, 0.00925302, 0.0721828, 0.96606) bones/27/scale = Vector3(1, 1, 1) bones/28/name = "RightHandPinky2" bones/28/parent = 27 bones/28/rest = Transform3D(0.999999, -0.00169266, 2.0762e-07, 0.00169266, 0.999999, 1.21108e-06, -2.0967e-07, -1.21073e-06, 1, 1.02501e-06, 3.6, -1.07715e-07) bones/28/enabled = true bones/28/position = Vector3(1.02501e-06, 3.6, -1.07715e-07) -bones/28/rotation = Quaternion(0.398295, -0.018258, -0.0590211, 0.915175) +bones/28/rotation = Quaternion(0.356941, -0.017438, -0.057749, 0.932177) bones/28/scale = Vector3(1, 1, 1) bones/29/name = "RightHandPinky3" bones/29/parent = 28 @@ -3503,42 +3500,42 @@ bones/31/parent = 3 bones/31/rest = Transform3D(-0.205707, 0.977362, -0.0494651, 0.129002, -0.0230232, -0.991377, -0.970074, -0.210314, -0.121346, 4.57045, 11.1957, -0.806628) bones/31/enabled = true bones/31/position = Vector3(4.57045, 11.1957, -0.806628) -bones/31/rotation = Quaternion(0.488057, 0.536105, -0.568538, 0.388789) +bones/31/rotation = Quaternion(0.48725, 0.536206, -0.569594, 0.388114) bones/31/scale = Vector3(1, 1, 1) bones/32/name = "LeftArm" bones/32/parent = 31 bones/32/rest = Transform3D(0.978561, -0.205707, -0.0101878, 0.20596, 0.977363, 0.0484042, 1.67638e-08, -0.0494647, 0.998776, 1.19209e-07, 10.8377, -7.69096e-07) bones/32/enabled = true bones/32/position = Vector3(1.19209e-07, 10.8377, -7.69096e-07) -bones/32/rotation = Quaternion(0.185302, -0.209923, 0.138081, 0.950015) +bones/32/rotation = Quaternion(0.176075, -0.211821, 0.127993, 0.952758) bones/32/scale = Vector3(1, 1, 1) bones/33/name = "LeftForeArm" bones/33/parent = 32 bones/33/rest = Transform3D(1, -7.91888e-10, 1.53855e-09, 7.9189e-10, 1, -1.06455e-06, -1.53855e-09, 1.06455e-06, 1, 6.43076e-07, 27.8415, 7.54874e-06) bones/33/enabled = true bones/33/position = Vector3(6.43076e-07, 27.8415, 7.54874e-06) -bones/33/rotation = Quaternion(0.0734728, -0.0260904, 0.146778, 0.986092) +bones/33/rotation = Quaternion(0.0710945, -0.0137076, 0.17137, 0.982543) bones/33/scale = Vector3(1, 1, 1) bones/34/name = "LeftHand" bones/34/parent = 33 bones/34/rest = Transform3D(1, 1.34242e-08, -1.34244e-08, -1.34242e-08, 1, -2.38631e-07, 1.34244e-08, 2.38631e-07, 1, 6.6208e-06, 28.3288, 7.55342e-06) bones/34/enabled = true bones/34/position = Vector3(6.6208e-06, 28.3288, 7.55342e-06) -bones/34/rotation = Quaternion(-0.269413, 0.00612019, 0.168673, 0.948118) +bones/34/rotation = Quaternion(-0.264837, 0.0075152, 0.176516, 0.94797) bones/34/scale = Vector3(1, 1, 1) bones/35/name = "LeftHandThumb1" bones/35/parent = 34 bones/35/rest = Transform3D(0.8891, -0.457712, -1.3113e-06, 0.395629, 0.768507, -0.502867, 0.230169, 0.447099, 0.864364, -2.68173, 2.46615, 1.57617) bones/35/enabled = true bones/35/position = Vector3(-2.68173, 2.46615, 1.57617) -bones/35/rotation = Quaternion(0.284649, -0.0891071, 0.106222, 0.948553) +bones/35/rotation = Quaternion(0.284339, -0.0840352, 0.103361, 0.949424) bones/35/scale = Vector3(1, 1, 1) bones/36/name = "LeftHandThumb2" bones/36/parent = 35 bones/36/rest = Transform3D(0.999863, 0.0164218, 0.00212004, -0.0164305, 0.999857, 0.00411473, -0.00205216, -0.004149, 0.999989, 3.03984e-06, 4.1871, 3.07148e-06) bones/36/enabled = true bones/36/position = Vector3(2.98023e-07, 4.18709, 1.43951e-05) -bones/36/rotation = Quaternion(-0.012463, -0.00528461, -0.0347495, 0.999304) +bones/36/rotation = Quaternion(-0.0138929, -0.00574121, -0.0316338, 0.999386) bones/36/scale = Vector3(1, 1, 1) bones/37/name = "LeftHandThumb3" bones/37/parent = 36 @@ -3559,14 +3556,14 @@ bones/39/parent = 34 bones/39/rest = Transform3D(1, 8.81505e-05, -2.88796e-08, -8.81505e-05, 1, -2.25531e-06, 2.86808e-08, 2.25531e-06, 1, -2.25986, 9.10932, 0.518009) bones/39/enabled = true bones/39/position = Vector3(-2.25986, 9.10932, 0.518024) -bones/39/rotation = Quaternion(0.0830108, 0.0388407, 0.0514195, 0.994463) +bones/39/rotation = Quaternion(0.0770195, 0.0389847, 0.0515855, 0.994931) bones/39/scale = Vector3(1, 1, 1) bones/40/name = "LeftHandIndex2" bones/40/parent = 39 bones/40/rest = Transform3D(1, -0.000210313, 1.21517e-07, 0.000210313, 1, -1.2441e-06, -1.21255e-07, 1.24412e-06, 1, -7.90296e-08, 3.70001, -2.50717e-05) bones/40/enabled = true bones/40/position = Vector3(-1.00166e-07, 3.69999, 4.91004e-06) -bones/40/rotation = Quaternion(0.162598, -0.00866607, -0.00498977, 0.986642) +bones/40/rotation = Quaternion(0.161606, -0.00865864, -0.0051118, 0.986804) bones/40/scale = Vector3(1, 1, 1) bones/41/name = "LeftHandIndex3" bones/41/parent = 40 @@ -3587,14 +3584,14 @@ bones/43/parent = 34 bones/43/rest = Transform3D(1, 6.33157e-05, -1.5605e-08, -6.33157e-05, 1, 1.85453e-06, 1.57224e-08, -1.85453e-06, 1, -3.57426e-05, 9.5334, -7.29997e-05) bones/43/enabled = true bones/43/position = Vector3(-3.58482e-05, 9.53341, -4.3386e-05) -bones/43/rotation = Quaternion(0.166169, -0.0258238, -0.0800847, 0.982501) +bones/43/rotation = Quaternion(0.160956, -0.0268348, -0.0830034, 0.983099) bones/43/scale = Vector3(1, 1, 1) bones/44/name = "LeftHandMiddle2" bones/44/parent = 43 bones/44/rest = Transform3D(1, -4.26227e-05, 1.84394e-07, 4.26227e-05, 1, -5.17247e-06, -1.84174e-07, 5.17248e-06, 1, 7.8513e-07, 3.70001, 5.89059e-07) bones/44/enabled = true bones/44/position = Vector3(7.8513e-07, 3.70001, 5.89059e-07) -bones/44/rotation = Quaternion(0.199962, 3.23689e-06, 0.0137906, 0.979707) +bones/44/rotation = Quaternion(0.211036, -2.03901e-05, 0.0148582, 0.977365) bones/44/scale = Vector3(1, 1, 1) bones/45/name = "LeftHandMiddle3" bones/45/parent = 44 @@ -3615,14 +3612,14 @@ bones/47/parent = 34 bones/47/rest = Transform3D(1, -1.26778e-05, 1.44174e-07, 1.26778e-05, 1, 1.85554e-06, -1.44198e-07, -1.85554e-06, 1, 1.86508, 9.10454, 0.0429883) bones/47/enabled = true bones/47/position = Vector3(1.86508, 9.10454, 0.0430176) -bones/47/rotation = Quaternion(0.289842, -0.0611307, -0.118318, 0.947763) +bones/47/rotation = Quaternion(0.297001, -0.0708289, -0.113667, 0.945438) bones/47/scale = Vector3(1, 1, 1) bones/48/name = "LeftHandRing2" bones/48/parent = 47 bones/48/rest = Transform3D(1, 7.29823e-08, -5.63593e-08, -7.29826e-08, 1, -5.17351e-06, 5.63589e-08, 5.17351e-06, 1, 7.46404e-07, 3.15002, 2.05661e-06) bones/48/enabled = true bones/48/position = Vector3(7.46404e-07, 3.15002, 2.05661e-06) -bones/48/rotation = Quaternion(0.289539, -0.000320947, 0.024351, 0.956857) +bones/48/rotation = Quaternion(0.299352, -0.000364506, 0.0249265, 0.953817) bones/48/scale = Vector3(1, 1, 1) bones/49/name = "LeftHandRing3" bones/49/parent = 48 @@ -3643,14 +3640,14 @@ bones/51/parent = 34 bones/51/rest = Transform3D(0.999992, -0.00408962, 4.99198e-08, 0.00408962, 0.999992, 1.03318e-05, -9.21724e-08, -1.03315e-05, 1, 3.80626, 8.07779, 0.486838) bones/51/enabled = true bones/51/position = Vector3(3.80626, 8.07779, 0.486867) -bones/51/rotation = Quaternion(0.327025, -0.0820818, -0.129876, 0.932443) +bones/51/rotation = Quaternion(0.327225, -0.0828698, -0.126651, 0.932746) bones/51/scale = Vector3(1, 1, 1) bones/52/name = "LeftHandPinky2" bones/52/parent = 51 bones/52/rest = Transform3D(1, 0.000421534, -2.89811e-07, -0.000421534, 1, 6.05504e-06, 2.92363e-07, -6.05491e-06, 1, 5.8622e-07, 3.59999, 1.86631e-05) bones/52/enabled = true bones/52/position = Vector3(-9.29924e-07, 3.59999, -1.33763e-05) -bones/52/rotation = Quaternion(0.35166, 0.00795197, 0.0407161, 0.935208) +bones/52/rotation = Quaternion(0.360969, 0.00803003, 0.0406202, 0.931658) bones/52/scale = Vector3(1, 1, 1) bones/53/name = "LeftHandPinky3" bones/53/parent = 52 @@ -3671,28 +3668,28 @@ bones/55/parent = 0 bones/55/rest = Transform3D(-1, -5.15831e-07, -6.28369e-08, 5.14419e-07, -0.999785, 0.0207118, -7.35073e-08, 0.0207118, 0.999785, -8.20779, -6.77175, -1.51222) bones/55/enabled = true bones/55/position = Vector3(-8.20779, -6.77175, -1.51222) -bones/55/rotation = Quaternion(-0.171821, 0.578667, 0.782421, 0.153099) +bones/55/rotation = Quaternion(-0.17425, 0.59257, 0.774068, 0.138983) bones/55/scale = Vector3(1, 1, 1) bones/56/name = "RightLeg" bones/56/parent = 55 bones/56/rest = Transform3D(1, -3.11163e-08, -6.95594e-08, 3.63214e-08, 0.997098, 0.0761275, 6.69888e-08, -0.0761275, 0.997098, 7.40101e-07, 44.3715, -4.82482e-08) bones/56/enabled = true bones/56/position = Vector3(7.40101e-07, 44.3715, -4.82482e-08) -bones/56/rotation = Quaternion(-0.914553, -0.0261421, 0.0810702, 0.395396) +bones/56/rotation = Quaternion(-0.923313, -0.0260744, 0.0789081, 0.374948) bones/56/scale = Vector3(1, 1, 1) bones/57/name = "RightFoot" bones/57/parent = 56 bones/57/rest = Transform3D(1, 2.89989e-07, -6.30721e-08, -2.18905e-07, 0.577278, -0.816548, -2.00379e-07, 0.816548, 0.577278, -1.88774e-07, 44.5278, 5.80588e-07) bones/57/enabled = true bones/57/position = Vector3(-1.88774e-07, 44.5278, 5.80588e-07) -bones/57/rotation = Quaternion(0.264136, 0.0252433, 0.0430909, 0.963192) +bones/57/rotation = Quaternion(0.272201, 0.039937, 0.0662076, 0.959129) bones/57/scale = Vector3(1, 1, 1) bones/58/name = "RightToeBase" bones/58/parent = 57 bones/58/rest = Transform3D(1, 1.2381e-07, -1.08868e-07, -1.64751e-07, 0.775226, -0.631684, 6.18842e-09, 0.631684, 0.775226, -5.1651e-07, 13.8169, -1.90205e-06) bones/58/enabled = true bones/58/position = Vector3(-5.1651e-07, 13.8169, -1.90205e-06) -bones/58/rotation = Quaternion(0.317939, -1.00007e-07, -1.98108e-07, 0.948111) +bones/58/rotation = Quaternion(0.316531, -1.75597e-07, 4.4775e-07, 0.948582) bones/58/scale = Vector3(1, 1, 1) bones/59/name = "RightToe_End" bones/59/parent = 58 @@ -3706,21 +3703,21 @@ bones/60/parent = 0 bones/60/rest = Transform3D(-1, -5.37325e-07, -1.73336e-07, 5.33615e-07, -0.999785, 0.0207348, -1.84441e-07, 0.0207348, 0.999785, 8.20779, -6.77179, -1.51221) bones/60/enabled = true bones/60/position = Vector3(8.20779, -6.77179, -1.51221) -bones/60/rotation = Quaternion(0.15404, 0.603026, 0.780016, -0.0648573) +bones/60/rotation = Quaternion(0.147747, 0.598258, 0.783679, -0.0781332) bones/60/scale = Vector3(1, 1, 1) bones/61/name = "LeftLeg" bones/61/parent = 60 bones/61/rest = Transform3D(1, -2.27105e-08, -2.66928e-07, 4.29763e-08, 0.997095, 0.0761695, 2.64423e-07, -0.0761695, 0.997095, 8.49408e-07, 44.3714, 5.43912e-09) bones/61/enabled = true bones/61/position = Vector3(8.49408e-07, 44.3714, 5.43912e-09) -bones/61/rotation = Quaternion(-0.898276, -0.00139739, 0.0107046, 0.439299) +bones/61/rotation = Quaternion(-0.896348, 0.0043123, -0.00358725, 0.443317) bones/61/scale = Vector3(1, 1, 1) bones/62/name = "LeftFoot" bones/62/parent = 61 bones/62/rest = Transform3D(1, 2.78454e-07, -1.41493e-07, -2.76279e-07, 0.577262, -0.816559, -1.45696e-07, 0.816559, 0.577262, 6.62281e-07, 44.5279, 6.18865e-08) bones/62/enabled = true bones/62/position = Vector3(6.62281e-07, 44.5279, 6.18865e-08) -bones/62/rotation = Quaternion(0.40896, -0.0618288, -0.11995, 0.902519) +bones/62/rotation = Quaternion(0.417055, -0.0641341, -0.125439, 0.897896) bones/62/scale = Vector3(1, 1, 1) bones/63/name = "LeftToeBase" bones/63/parent = 62 @@ -3746,8 +3743,8 @@ mesh = SubResource("ArrayMesh_1w418") skin = SubResource("Skin_l3wpu") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.908729, 0) -shape = SubResource("CapsuleShape3D_mm42w") +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) +shape = SubResource("CapsuleShape3D_p1dvg") [node name="AnimationPlayer" type="AnimationPlayer" parent="."] root_node = NodePath("../Mesh") diff --git a/include/blitz/godot/World.h b/include/blitz/godot/World.h index 272ed84..7c0ca39 100644 --- a/include/blitz/godot/World.h +++ b/include/blitz/godot/World.h @@ -25,7 +25,6 @@ class World : public godot::Node3D, public protocol::PacketHandler { void HandlePacket(const protocol::packets::PlayerJoin&) override; void HandlePacket(const protocol::packets::PlayerLeave&) override; - void HandlePacket(const protocol::packets::PlayerPositionAndRotation&) override; protected: NetworkInterface* m_NetworkInterface; diff --git a/include/client/ClientWorld.h b/include/client/ClientWorld.h index 4b8087b..919abca 100644 --- a/include/client/ClientWorld.h +++ b/include/client/ClientWorld.h @@ -12,6 +12,8 @@ class ClientWorld : public World { ~ClientWorld(); void _process(float delta); + void HandlePacket(const protocol::packets::PlayerPositionAndRotation&) override; + private: void UpdatePlayerPos(); }; diff --git a/include/client/FirstPersonPlayer.h b/include/client/FirstPersonPlayer.h index f5d2f89..9e7c2bc 100644 --- a/include/client/FirstPersonPlayer.h +++ b/include/client/FirstPersonPlayer.h @@ -16,7 +16,7 @@ class FirstPersonPlayer : public Player { // Godot overrides void _unhandled_input(const godot::Ref&); - void _physics_process(float delta); + void _physics_process(float delta) override; void _ready() override; private: diff --git a/include/client/Player.h b/include/client/Player.h index 5f1cc9f..6afe037 100644 --- a/include/client/Player.h +++ b/include/client/Player.h @@ -21,7 +21,7 @@ class Player : public godot::CharacterBody3D { ~Player(); void _ready(); - void _physics_process(float delta); + virtual void _physics_process(float delta); void animate(float delta); godot::Vector3 GetCameraRotation() const; @@ -36,7 +36,6 @@ class Player : public godot::CharacterBody3D { godot::AnimationTree* m_AnimationTree; godot::Vector3 m_SnapVector; - float m_Speed; PeerID m_PeerId; friend class World; diff --git a/include/server/ServerWorld.h b/include/server/ServerWorld.h index 2f609f8..9c3270b 100644 --- a/include/server/ServerWorld.h +++ b/include/server/ServerWorld.h @@ -12,7 +12,8 @@ class ServerWorld : public World { ~ServerWorld(); void _process(float delta); - private: + void HandlePacket(const protocol::packets::PlayerPositionAndRotation&) override; + void SyncPlayersPos(); }; diff --git a/src/blitz/godot/World.cpp b/src/blitz/godot/World.cpp index 86b547f..972a16f 100644 --- a/src/blitz/godot/World.cpp +++ b/src/blitz/godot/World.cpp @@ -64,14 +64,6 @@ void World::HandlePacket(const protocol::packets::PlayerLeave& a_PlayerLeave) { RemovePlayer(a_PlayerLeave.m_Data.m_PlayerId); } -void World::HandlePacket(const protocol::packets::PlayerPositionAndRotation& a_PlayerPos) { - const auto& data = a_PlayerPos.m_Data; - if (data.m_Player == get_multiplayer()->get_unique_id() || data.m_Player != a_PlayerPos.m_Sender) - return; - - SetPlayerPositionAndRotation(data.m_Player, data.m_Position, data.m_Rotation, data.m_Velocity); -} - void World::AddPlayer(PlayerID a_PlayerId, String a_PlayerName) { UtilityFunctions::print("New Player with id : ", a_PlayerId, " and name ", a_PlayerName); if (a_PlayerId == get_multiplayer()->get_unique_id()) { diff --git a/src/blitz/protocol/Packets.cpp b/src/blitz/protocol/Packets.cpp index 38fdeeb..e858461 100644 --- a/src/blitz/protocol/Packets.cpp +++ b/src/blitz/protocol/Packets.cpp @@ -14,7 +14,8 @@ void packets::ConcretePacket::Accept(PacketVisitor& a_Visitor) const { a_Visitor.Visit(*this); } -#define DeclarePacket(PacketName, packetSendType, packetSenderType) static_assert(static_cast(PacketSendType::packetSendType) && static_cast(PacketSenderType::packetSenderType)); +#define DeclarePacket(PacketName, packetSendType, packetSenderType) \ + static_assert(static_cast(PacketSendType::packetSendType) && static_cast(PacketSenderType::packetSenderType)); DeclareAllPacket() diff --git a/src/client/ClientWorld.cpp b/src/client/ClientWorld.cpp index 4f30631..85f882d 100644 --- a/src/client/ClientWorld.cpp +++ b/src/client/ClientWorld.cpp @@ -5,6 +5,8 @@ #include #include +#include + namespace blitz { using namespace godot; @@ -20,10 +22,12 @@ void ClientWorld::_process(float delta) { if (Engine::get_singleton()->is_editor_hint()) return; #endif + m_PassedTime += delta; if (m_PassedTime < 0.05f) return; + m_PassedTime = 0.0f; UpdatePlayerPos(); } @@ -36,4 +40,18 @@ void ClientWorld::UpdatePlayerPos() { } } +void ClientWorld::HandlePacket(const protocol::packets::PlayerPositionAndRotation& a_PlayerPos) { + const auto& data = a_PlayerPos.m_Data; + if (data.m_Player == get_multiplayer()->get_unique_id()) { + Player* player = GetPlayerById(get_multiplayer()->get_unique_id()); + if (player && (a_PlayerPos.m_Data.m_Position - player->get_position()).length() > 10) { + SetPlayerPositionAndRotation(data.m_Player, data.m_Position, data.m_Rotation, data.m_Velocity); + godot::UtilityFunctions::print("Teleported to : ", data.m_Position); + } + return; + } + + SetPlayerPositionAndRotation(data.m_Player, data.m_Position, data.m_Rotation, data.m_Velocity); +} + } // namespace blitz \ No newline at end of file diff --git a/src/client/FirstPersonPlayer.cpp b/src/client/FirstPersonPlayer.cpp index 2d65420..0f83999 100644 --- a/src/client/FirstPersonPlayer.cpp +++ b/src/client/FirstPersonPlayer.cpp @@ -39,7 +39,7 @@ static const float AnimationBlend = 7.0; void FirstPersonPlayer::_bind_methods() {} -FirstPersonPlayer::FirstPersonPlayer() : m_BobTime(0) {} +FirstPersonPlayer::FirstPersonPlayer() : Player(), m_BobTime(0) {} FirstPersonPlayer::~FirstPersonPlayer() {} @@ -52,6 +52,9 @@ void FirstPersonPlayer::_ready() { m_Camera = Object::cast_to(m_Head->find_child("Camera")); m_AnimationTree = Object::cast_to(find_child("AnimationTree")); m_Mesh = Object::cast_to(find_child("Mesh")); + + set_position({0, 0, 0}); + set_velocity({0, 0, 0}); } void FirstPersonPlayer::_unhandled_input(const godot::Ref& a_Event) { @@ -89,9 +92,9 @@ void FirstPersonPlayer::_physics_process(float a_Delta) { UpdateFOV(a_Delta); UpdateBobbing(a_Delta); - UpdateAnimation(a_Delta); - move_and_slide(); + + UpdateAnimation(a_Delta); } void FirstPersonPlayer::UpdateBobbing(float a_Delta) { diff --git a/src/client/Player.cpp b/src/client/Player.cpp index b3711d7..487a6e6 100644 --- a/src/client/Player.cpp +++ b/src/client/Player.cpp @@ -7,7 +7,7 @@ #include static const float WalkSpeed = 2.0; -static const float RunSpeed = 5.0; +static const float RunSpeed = 7.0; static const float JumpStrength = 15.0; static const float Gravity = 50.0; @@ -20,7 +20,7 @@ using namespace godot; void Player::_bind_methods() {} -Player::Player() {} +Player::Player() : m_PeerId(0) {} Player::~Player() {} @@ -31,7 +31,9 @@ void Player::_ready() { DEV_ASSERT(m_Mesh); DEV_ASSERT(m_AnimationTree); - apply_floor_snap(); + set_position({0, 0, 0}); + set_velocity({0, 0, 0}); + animate(0); } @@ -39,6 +41,7 @@ void Player::_physics_process(float delta) { if (godot::Engine::get_singleton()->is_editor_hint()) return; + move_and_slide(); animate(delta); } @@ -46,8 +49,10 @@ void Player::animate(float delta) { if (is_on_floor()) { m_AnimationTree->set("parameters/ground_air_transition/transition_request", "grounded"); - if (get_velocity().length() > 0) { - if (m_Speed == RunSpeed) { + float speed = get_velocity().length(); + + if (speed > 0.2f) { + if (speed >= RunSpeed) { m_AnimationTree->set("parameters/iwr_blend/blend_amount", godot::UtilityFunctions::lerp( m_AnimationTree->get("parameters/iwr_blend/blend_amount"), 1.0, delta * AnimationBlend)); diff --git a/src/server/ServerWorld.cpp b/src/server/ServerWorld.cpp index 8c86fa7..a556d1d 100644 --- a/src/server/ServerWorld.cpp +++ b/src/server/ServerWorld.cpp @@ -23,6 +23,7 @@ void ServerWorld::_process(float delta) { if (m_PassedTime < 0.05f) return; + m_PassedTime = 0.0f; SyncPlayersPos(); } @@ -35,4 +36,12 @@ void ServerWorld::SyncPlayersPos() { } } +void ServerWorld::HandlePacket(const protocol::packets::PlayerPositionAndRotation& a_PlayerPos) { + const auto& data = a_PlayerPos.m_Data; + if (data.m_Player != a_PlayerPos.m_Sender) + return; + + SetPlayerPositionAndRotation(data.m_Player, data.m_Position, data.m_Rotation, data.m_Velocity); +} + } // namespace blitz \ No newline at end of file From f7d0103dbf222d830aeb36f08596ee1286f6d607 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Thu, 22 Aug 2024 10:19:28 +0200 Subject: [PATCH 21/23] fix warning --- src/client/FirstPersonPlayer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/FirstPersonPlayer.cpp b/src/client/FirstPersonPlayer.cpp index 0f83999..2ca433b 100644 --- a/src/client/FirstPersonPlayer.cpp +++ b/src/client/FirstPersonPlayer.cpp @@ -152,7 +152,7 @@ void FirstPersonPlayer::UpdatePosition(float delta) { void FirstPersonPlayer::UpdateFOV(float a_Delta) { float velocityClamped = Math::clamp(get_velocity().length(), MIN_FOV_VELOCITY, MAX_FOV_VELOCITY); float targetFOV = BASE_FOV + FOV_CHANGE * velocityClamped; - m_Camera->set_fov(Math::lerp(m_Camera->get_fov(), targetFOV, a_Delta * FOV_TRANSITION)); + m_Camera->set_fov(Math::lerp(static_cast(m_Camera->get_fov()), targetFOV, a_Delta * FOV_TRANSITION)); } void FirstPersonPlayer::UpdateAnimation(float delta) { From d7e80e05de0a4cf09899ed1d5c49b4bd3217468a Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Thu, 22 Aug 2024 10:21:51 +0200 Subject: [PATCH 22/23] add server side speed check --- src/server/ServerWorld.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/server/ServerWorld.cpp b/src/server/ServerWorld.cpp index a556d1d..5d8cebf 100644 --- a/src/server/ServerWorld.cpp +++ b/src/server/ServerWorld.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace blitz { @@ -41,6 +42,16 @@ void ServerWorld::HandlePacket(const protocol::packets::PlayerPositionAndRotatio if (data.m_Player != a_PlayerPos.m_Sender) return; + Player* player = GetPlayerById(data.m_Player); + if (!player) + return; + + if ((data.m_Position - player->get_position()).length() > 10) { + UtilityFunctions::print( + "Player ", data.m_Player, " moved too fast ! (from ", player->get_position(), " to ", data.m_Position, ")"); + return; + } + SetPlayerPositionAndRotation(data.m_Player, data.m_Position, data.m_Rotation, data.m_Velocity); } From eb85b13ac763c950dcb50674b9ba3c72762ed721 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Thu, 22 Aug 2024 10:25:01 +0200 Subject: [PATCH 23/23] fixed client player going crazy on spawn --- include/blitz/godot/World.h | 6 +++--- include/client/Player.h | 2 +- include/server/ServerWorld.h | 3 +++ src/client/Player.cpp | 8 ++++---- src/server/ServerWorld.cpp | 6 ++++++ 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/blitz/godot/World.h b/include/blitz/godot/World.h index 7c0ca39..24476d7 100644 --- a/include/blitz/godot/World.h +++ b/include/blitz/godot/World.h @@ -32,9 +32,9 @@ class World : public godot::Node3D, public protocol::PacketHandler { float m_PassedTime; - void AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName); - void RemovePlayer(PlayerID a_PlayerId); - void SetPlayerPositionAndRotation( + virtual void AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName); + virtual void RemovePlayer(PlayerID a_PlayerId); + virtual void SetPlayerPositionAndRotation( PlayerID a_PlayerId, const godot::Vector3& a_Position, const godot::Vector3& a_Rotation, const godot::Vector3& a_Velocity); }; } // namespace blitz \ No newline at end of file diff --git a/include/client/Player.h b/include/client/Player.h index 6afe037..e65d84b 100644 --- a/include/client/Player.h +++ b/include/client/Player.h @@ -20,7 +20,7 @@ class Player : public godot::CharacterBody3D { Player(); ~Player(); - void _ready(); + void _ready() override; virtual void _physics_process(float delta); void animate(float delta); diff --git a/include/server/ServerWorld.h b/include/server/ServerWorld.h index 9c3270b..fda4380 100644 --- a/include/server/ServerWorld.h +++ b/include/server/ServerWorld.h @@ -15,6 +15,9 @@ class ServerWorld : public World { void HandlePacket(const protocol::packets::PlayerPositionAndRotation&) override; void SyncPlayersPos(); + + protected: + virtual void AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName); }; } // namespace blitz \ No newline at end of file diff --git a/src/client/Player.cpp b/src/client/Player.cpp index 487a6e6..19911b5 100644 --- a/src/client/Player.cpp +++ b/src/client/Player.cpp @@ -20,7 +20,10 @@ using namespace godot; void Player::_bind_methods() {} -Player::Player() : m_PeerId(0) {} +Player::Player() : m_PeerId(0) { + // we set the player to an invalid position + set_position({-99999, -999999, -999999}); +} Player::~Player() {} @@ -31,9 +34,6 @@ void Player::_ready() { DEV_ASSERT(m_Mesh); DEV_ASSERT(m_AnimationTree); - set_position({0, 0, 0}); - set_velocity({0, 0, 0}); - animate(0); } diff --git a/src/server/ServerWorld.cpp b/src/server/ServerWorld.cpp index 5d8cebf..38c121e 100644 --- a/src/server/ServerWorld.cpp +++ b/src/server/ServerWorld.cpp @@ -55,4 +55,10 @@ void ServerWorld::HandlePacket(const protocol::packets::PlayerPositionAndRotatio SetPlayerPositionAndRotation(data.m_Player, data.m_Position, data.m_Rotation, data.m_Velocity); } +void ServerWorld::AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName) { + World::AddPlayer(a_PlayerId, a_PlayerName); + Player* player = GetPlayerById(a_PlayerId); + player->set_position({0, 0, 0}); +} + } // namespace blitz \ No newline at end of file