generated from Persson-dev/Godot-Xmake
network: send player velocity
This commit is contained in:
@@ -35,6 +35,7 @@ class World : public godot::Node3D, public protocol::PacketHandler {
|
|||||||
|
|
||||||
void AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName);
|
void AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName);
|
||||||
void RemovePlayer(PlayerID a_PlayerId);
|
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
|
} // namespace blitz
|
||||||
@@ -63,6 +63,7 @@ struct PlayerPositionAndRotation {
|
|||||||
PlayerID m_Player;
|
PlayerID m_Player;
|
||||||
godot::Vector3 m_Position;
|
godot::Vector3 m_Position;
|
||||||
godot::Vector3 m_Rotation;
|
godot::Vector3 m_Rotation;
|
||||||
|
godot::Vector3 m_Velocity;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlayerShoot {};
|
struct PlayerShoot {};
|
||||||
|
|||||||
@@ -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)
|
if (data.m_Player == get_multiplayer()->get_unique_id() || data.m_Player != a_PlayerPos.m_Sender)
|
||||||
return;
|
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) {
|
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);
|
Player* player = GetPlayerById(a_PlayerId);
|
||||||
if (player) {
|
if (player) {
|
||||||
player->set_position(a_Position);
|
player->set_position(a_Position);
|
||||||
player->SetCameraRotation(a_Rotation);
|
player->SetCameraRotation(a_Rotation);
|
||||||
|
player->set_velocity(a_Velocity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -195,21 +195,10 @@ void Deserializer::DeserializePacketData(data::PlayerLeave& a_Packet) {
|
|||||||
|
|
||||||
void Serializer::SerializePacketData(const data::PlayerList& a_Packet) {
|
void Serializer::SerializePacketData(const data::PlayerList& a_Packet) {
|
||||||
m_Buffer << a_Packet.m_Players;
|
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) {
|
void Deserializer::DeserializePacketData(data::PlayerList& a_Packet) {
|
||||||
m_Buffer >> a_Packet.m_Players;
|
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) {
|
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) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ void ClientWorld::UpdatePlayerPos() {
|
|||||||
Player* player = GetPlayerById(get_multiplayer()->get_unique_id());
|
Player* player = GetPlayerById(get_multiplayer()->get_unique_id());
|
||||||
if (player) {
|
if (player) {
|
||||||
m_NetworkInterface->BroadcastPacket(protocol::packets::PlayerPositionAndRotation(
|
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()}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ void ServerWorld::SyncPlayersPos() {
|
|||||||
for (int i = 0; i < m_Players->get_child_count(); i++) {
|
for (int i = 0; i < m_Players->get_child_count(); i++) {
|
||||||
Player* player = Object::cast_to<Player>(m_Players->get_child(i));
|
Player* player = Object::cast_to<Player>(m_Players->get_child(i));
|
||||||
DEV_ASSERT(player);
|
DEV_ASSERT(player);
|
||||||
m_NetworkInterface->BroadcastPacket(
|
m_NetworkInterface->BroadcastPacket(protocol::packets::PlayerPositionAndRotation(
|
||||||
protocol::packets::PlayerPositionAndRotation({player->GetId(), player->get_position(), player->GetCameraRotation()}));
|
{player->GetId(), player->get_position(), player->GetCameraRotation(), player->get_velocity()}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user