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