network: send player velocity

This commit is contained in:
2024-08-21 10:29:42 +02:00
parent d3dddff005
commit 6ee87733ca
6 changed files with 12 additions and 19 deletions

View File

@@ -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);
}
}

View File

@@ -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<std::uint8_t>(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;
}

View File

@@ -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()}));
}
}

View File

@@ -30,8 +30,8 @@ void ServerWorld::SyncPlayersPos() {
for (int i = 0; i < m_Players->get_child_count(); i++) {
Player* player = Object::cast_to<Player>(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()}));
}
}