Skip to content

Commit

Permalink
Update for last Nazara version
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLynix committed Feb 25, 2024
1 parent 6e05106 commit 19ba8b0
Show file tree
Hide file tree
Showing 27 changed files with 161 additions and 166 deletions.
2 changes: 1 addition & 1 deletion include/ClientLib/ClientSession.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace bw

inline bool IsConnected() const;

void HandleIncomingPacket(Nz::NetPacket& packet);
void HandleIncomingPacket(Nz::ByteArray& packet);

inline void QuerySessionInfo(std::function<void(const SessionBridge::SessionInfo& info)> callback) const;

Expand Down
6 changes: 3 additions & 3 deletions include/ClientLib/ClientSession.inl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <ClientLib/ClientSession.hpp>
#include <CoreLib/BurgAppComponent.hpp>
#include <Nazara/Network/NetPacket.hpp>

namespace bw
{
Expand Down Expand Up @@ -48,8 +47,9 @@ namespace bw
if (!IsConnected())
return;

Nz::NetPacket data;
m_commandStore.SerializePacket(data, packet);
Nz::ByteArray data;
Nz::ByteStream byteStream(&data, Nz::OpenMode::Write);
m_commandStore.SerializePacket(byteStream, packet);

const auto& command = m_commandStore.GetOutgoingCommand<T>();
m_bridge->SendPacket(command.channelId, command.flags, std::move(data));
Expand Down
4 changes: 2 additions & 2 deletions include/ClientLib/LocalSessionBridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ namespace bw

void Disconnect() override;

void HandleIncomingPacket(Nz::NetPacket& packet) override;
void HandleIncomingPacket(Nz::ByteArray& packet) override;
inline bool IsServer() const;
bool IsLocal() const override;

void QueryInfo(std::function<void(const SessionInfo& info)> callback) const override;

void SendPacket(Nz::UInt8 channelId, Nz::ENetPacketFlags flags, Nz::NetPacket&& packet) override;
void SendPacket(Nz::UInt8 channelId, Nz::ENetPacketFlags flags, Nz::ByteArray&& packet) override;

private:
std::size_t m_peerId;
Expand Down
6 changes: 3 additions & 3 deletions include/ClientLib/LocalSessionManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ namespace bw

private:
void DisconnectPeer(std::size_t peerId);
void SendPacket(std::size_t peerId, Nz::NetPacket&& packet, bool isServer);
void SendPacket(std::size_t peerId, Nz::ByteArray&& packet, bool isServer);

struct Peer
{
std::shared_ptr<LocalSessionBridge> clientBridge;
std::shared_ptr<LocalSessionBridge> serverBridge;
std::vector<Nz::NetPacket> clientPackets;
std::vector<Nz::NetPacket> serverPackets;
std::vector<Nz::ByteArray> clientPackets;
std::vector<Nz::ByteArray> serverPackets;
MatchClientSession* session;
bool disconnectionRequested = false;
};
Expand Down
2 changes: 1 addition & 1 deletion include/ClientLib/NetworkReactorManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace bw
private:
void HandlePeerConnection(bool outgoing, std::size_t peerId, Nz::UInt32 data);
void HandlePeerDisconnection(std::size_t peerId, Nz::UInt32 data);
void HandlePeerPacket(std::size_t peerId, Nz::NetPacket& packet);
void HandlePeerPacket(std::size_t peerId, Nz::ByteArray& packet);

std::vector<std::unique_ptr<NetworkReactor>> m_reactors;
std::vector<std::shared_ptr<NetworkSessionBridge>> m_connections;
Expand Down
10 changes: 5 additions & 5 deletions include/CoreLib/CommandStore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#ifndef BURGWAR_CORELIB_COMMANDSTORE_HPP
#define BURGWAR_CORELIB_COMMANDSTORE_HPP

#include <Nazara/Core/ByteStream.hpp>
#include <Nazara/Network/ENetPacket.hpp>
#include <Nazara/Network/NetPacket.hpp>
#include <functional>
#include <type_traits>
#include <vector>
Expand All @@ -33,11 +33,11 @@ namespace bw
template<typename T> const OutgoingCommand& GetOutgoingCommand() const;

template<typename T>
void SerializePacket(Nz::NetPacket& packet, const T& data) const;
void SerializePacket(Nz::ByteStream& packet, const T& data) const;

bool UnserializePacket(PeerRef peer, Nz::NetPacket& packet) const;
bool UnserializePacket(PeerRef peer, Nz::ByteStream& packet) const;

using UnserializeFunction = std::function<void(PeerRef peer, Nz::NetPacket& packet)>;
using UnserializeFunction = std::function<void(PeerRef peer, Nz::ByteStream& packet)>;

struct IncomingCommand
{
Expand All @@ -59,7 +59,7 @@ namespace bw
template<typename T> void RegisterOutgoingCommand(const char* name, Nz::ENetPacketFlags flags, Nz::UInt8 channelId);

private:
using HandleFunction = std::function<void(Nz::NetPacket& packet)>;
using HandleFunction = std::function<void(Nz::ByteArray& packet)>;

std::vector<IncomingCommand> m_incomingCommands;
std::vector<OutgoingCommand> m_outgoingCommands;
Expand Down
6 changes: 3 additions & 3 deletions include/CoreLib/CommandStore.inl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace bw

IncomingCommand& newCommand = m_incomingCommands[packetId];
newCommand.enabled = true;
newCommand.unserialize = [this, cb = std::forward<CB>(callback)](PeerRef peer, Nz::NetPacket& packet)
newCommand.unserialize = [this, cb = std::forward<CB>(callback)](PeerRef peer, Nz::ByteStream& packet)
{
T data;
try
Expand Down Expand Up @@ -91,7 +91,7 @@ namespace bw

template<typename Peer>
template<typename T>
void CommandStore<Peer>::SerializePacket(Nz::NetPacket& packet, const T& data) const
void CommandStore<Peer>::SerializePacket(Nz::ByteStream& packet, const T& data) const
{
packet << static_cast<Nz::UInt8>(T::Type);

Expand All @@ -106,7 +106,7 @@ namespace bw
}

template<typename Peer>
bool CommandStore<Peer>::UnserializePacket(PeerRef peer, Nz::NetPacket& packet) const
bool CommandStore<Peer>::UnserializePacket(PeerRef peer, Nz::ByteStream& packet) const
{
Nz::UInt8 opcode;
try
Expand Down
2 changes: 1 addition & 1 deletion include/CoreLib/MatchClientSession.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace bw
inline MatchClientVisibility& GetVisibility();
inline const MatchClientVisibility& GetVisibility() const;

void HandleIncomingPacket(Nz::NetPacket& packet);
void HandleIncomingPacket(Nz::ByteArray& packet);

void OnTick(Nz::Time elapsedTime);

Expand Down
6 changes: 4 additions & 2 deletions include/CoreLib/MatchClientSession.inl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ namespace bw
template<typename T>
void MatchClientSession::SendPacket(const T& packet)
{
Nz::NetPacket data;
m_commandStore.SerializePacket(data, packet);
Nz::ByteArray data;
Nz::ByteStream stream(&data, Nz::OpenMode::Write);
m_commandStore.SerializePacket(stream, packet);
stream.FlushBits();

const auto& command = m_commandStore.GetOutgoingCommand<T>();
m_bridge->SendPacket(command.channelId, command.flags, std::move(data));
Expand Down
6 changes: 3 additions & 3 deletions include/CoreLib/NetworkReactor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace bw

void QueryInfo(std::size_t peerId, PeerInfoCallback callback);

void SendData(std::size_t peerId, Nz::UInt8 channelId, Nz::ENetPacketFlags flags, Nz::NetPacket&& packet);
void SendData(std::size_t peerId, Nz::UInt8 channelId, Nz::ENetPacketFlags flags, Nz::ByteArray&& packet);

NetworkReactor& operator=(const NetworkReactor&) = delete;
NetworkReactor& operator=(NetworkReactor&&) = delete;
Expand Down Expand Up @@ -96,7 +96,7 @@ namespace bw

struct PacketEvent
{
Nz::NetPacket packet;
Nz::ByteArray packet;
};

struct PeerInfoResponse
Expand All @@ -121,7 +121,7 @@ namespace bw
{
Nz::ENetPacketFlags flags;
Nz::UInt8 channelId;
Nz::NetPacket packet;
Nz::ByteArray packet;
};

struct QueryPeerInfo
Expand Down
2 changes: 1 addition & 1 deletion include/CoreLib/NetworkSessionBridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace bw

void QueryInfo(std::function<void(const SessionInfo& info)> callback) const override;

void SendPacket(Nz::UInt8 channelId, Nz::ENetPacketFlags flags, Nz::NetPacket&& packet) override;
void SendPacket(Nz::UInt8 channelId, Nz::ENetPacketFlags flags, Nz::ByteArray&& packet) override;

private:
std::size_t m_peerId;
Expand Down
2 changes: 1 addition & 1 deletion include/CoreLib/NetworkSessionManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace bw
private:
void HandlePeerConnection(bool outgoing, std::size_t peerId, Nz::UInt32 data);
void HandlePeerDisconnection(std::size_t peerId, Nz::UInt32 data);
void HandlePeerPacket(std::size_t peerId, Nz::NetPacket&& packet);
void HandlePeerPacket(std::size_t peerId, Nz::ByteArray&& packet);

std::vector<MatchClientSession*> m_peerIdToSession;
NetworkReactor m_reactor;
Expand Down
1 change: 0 additions & 1 deletion include/CoreLib/Protocol/Packets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Network/NetPacket.hpp>
#include <array>
#include <optional>
#include <variant>
Expand Down
6 changes: 3 additions & 3 deletions include/CoreLib/SessionBridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ namespace bw

virtual void HandleConnection(Nz::UInt32 data);
virtual void HandleDisconnection(Nz::UInt32 data);
virtual void HandleIncomingPacket(Nz::NetPacket& packet);
virtual void HandleIncomingPacket(Nz::ByteArray& packet);

virtual void QueryInfo(std::function<void(const SessionInfo& info)> callback) const = 0;

virtual void SendPacket(Nz::UInt8 channelId, Nz::ENetPacketFlags flags, Nz::NetPacket&& data) = 0;
virtual void SendPacket(Nz::UInt8 channelId, Nz::ENetPacketFlags flags, Nz::ByteArray&& data) = 0;

NazaraSignal(OnConnected, Nz::UInt32 /*data*/);
NazaraSignal(OnDisconnected, Nz::UInt32 /*data*/);
NazaraSignal(OnIncomingPacket, Nz::NetPacket& /*packet*/);
NazaraSignal(OnIncomingPacket, Nz::ByteArray& /*packet*/);

struct SessionInfo
{
Expand Down
20 changes: 10 additions & 10 deletions src/ClientLib/ClientCommandStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ namespace bw
IncomingCommand(ScriptPacket);

// Outgoing commands
OutgoingCommand(Auth, Nz::ENetPacketFlag_Reliable, 0);
OutgoingCommand(DownloadClientFileRequest, Nz::ENetPacketFlag_Reliable, 0);
OutgoingCommand(NetworkStrings, Nz::ENetPacketFlag_Reliable, 0);
OutgoingCommand(PlayerChat, Nz::ENetPacketFlag_Reliable, 1);
OutgoingCommand(PlayerConsoleCommand, Nz::ENetPacketFlag_Reliable, 1);
OutgoingCommand(PlayerSelectWeapon, Nz::ENetPacketFlag_Reliable, 0);
OutgoingCommand(PlayersInput, Nz::ENetPacketFlag_Reliable, 0);
OutgoingCommand(Ready, Nz::ENetPacketFlag_Reliable, 0);
OutgoingCommand(ScriptPacket, Nz::ENetPacketFlag_Reliable, 1);
OutgoingCommand(UpdatePlayerName, Nz::ENetPacketFlag_Reliable, 1);
OutgoingCommand(Auth, Nz::ENetPacketFlag::Reliable, 0);
OutgoingCommand(DownloadClientFileRequest, Nz::ENetPacketFlag::Reliable, 0);
OutgoingCommand(NetworkStrings, Nz::ENetPacketFlag::Reliable, 0);
OutgoingCommand(PlayerChat, Nz::ENetPacketFlag::Reliable, 1);
OutgoingCommand(PlayerConsoleCommand, Nz::ENetPacketFlag::Reliable, 1);
OutgoingCommand(PlayerSelectWeapon, Nz::ENetPacketFlag::Reliable, 0);
OutgoingCommand(PlayersInput, Nz::ENetPacketFlag::Reliable, 0);
OutgoingCommand(Ready, Nz::ENetPacketFlag::Reliable, 0);
OutgoingCommand(ScriptPacket, Nz::ENetPacketFlag::Reliable, 1);
OutgoingCommand(UpdatePlayerName, Nz::ENetPacketFlag::Reliable, 1);

#undef IncomingCommand
#undef OutgoingCommand
Expand Down
117 changes: 55 additions & 62 deletions src/ClientLib/ClientMatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,80 +511,73 @@ namespace bw

if (m_debug)
{
Nz::NetPacket debugPacket;
while (m_debug->socket.ReceivePacket(&debugPacket, nullptr))
Nz::ByteArray debugPacket(0xFFFF);
std::size_t received;
while (m_debug->socket.Receive(debugPacket.GetBuffer(), debugPacket.GetSize(), nullptr, &received) && received > 0)
{
switch (debugPacket.GetNetCode())
debugPacket.Resize(received);
Nz::ByteStream stream(&debugPacket, Nz::OpenMode::Read);

Nz::UInt32 entityCount;
stream >> entityCount;

for (Nz::UInt32 i = 0; i < entityCount; ++i)
{
case 1: //< StatePacket
{
Nz::UInt32 entityCount;
debugPacket >> entityCount;
CompressedUnsigned<Nz::UInt16> layerId;
CompressedUnsigned<Nz::UInt32> entityId;
stream >> layerId;
stream >> entityId;

for (Nz::UInt32 i = 0; i < entityCount; ++i)
{
CompressedUnsigned<Nz::UInt16> layerId;
CompressedUnsigned<Nz::UInt32> entityId;
debugPacket >> layerId;
debugPacket >> entityId;
bool isPhysical;
Nz::Vector2f linearVelocity;
Nz::RadianAnglef angularVelocity;
Nz::Vector2f position;
Nz::RadianAnglef rotation;

bool isPhysical;
Nz::Vector2f linearVelocity;
Nz::RadianAnglef angularVelocity;
Nz::Vector2f position;
Nz::RadianAnglef rotation;
stream >> isPhysical;

debugPacket >> isPhysical;
if (isPhysical)
stream >> linearVelocity >> angularVelocity;

if (isPhysical)
debugPacket >> linearVelocity >> angularVelocity;
stream >> position >> rotation;

debugPacket >> position >> rotation;
auto& layer = m_layers[layerId];
if (layer->IsEnabled())
{
if (auto entityOpt = layer->GetEntityByServerId(entityId))
{
ClientLayerEntity& entity = entityOpt.value();
ClientLayerEntity* ghostEntity = entity.GetGhost();
/*if (isPhysical)
ghostEntity->UpdateState(position, rotation, linearVelocity, angularVelocity);
else*/
ghostEntity->UpdateState(position, rotation);

ghostEntity->SyncVisuals();
}
}

auto& layer = m_layers[layerId];
if (layer->IsEnabled())
/*if (auto it = m_serverEntityIdToClient.find(entityId); it != m_serverEntityIdToClient.end())
{
ServerEntity& serverEntity = it.value();
if (serverEntity.serverGhost)
{
if (isPhysical && serverEntity.serverGhost->HasComponent<Ndk::PhysicsComponent2D>())
{
if (auto entityOpt = layer->GetEntityByServerId(entityId))
{
ClientLayerEntity& entity = entityOpt.value();
ClientLayerEntity* ghostEntity = entity.GetGhost();
/*if (isPhysical)
ghostEntity->UpdateState(position, rotation, linearVelocity, angularVelocity);
else*/
ghostEntity->UpdateState(position, rotation);

ghostEntity->SyncVisuals();
}
auto& ghostPhysics = serverEntity.serverGhost->GetComponent<Ndk::PhysicsComponent2D>();
ghostPhysics.SetPosition(position);
ghostPhysics.SetRotation(rotation);
ghostPhysics.SetAngularVelocity(angularVelocity);
ghostPhysics.SetVelocity(linearVelocity);
}

/*if (auto it = m_serverEntityIdToClient.find(entityId); it != m_serverEntityIdToClient.end())
else
{
ServerEntity& serverEntity = it.value();
if (serverEntity.serverGhost)
{
if (isPhysical && serverEntity.serverGhost->HasComponent<Ndk::PhysicsComponent2D>())
{
auto& ghostPhysics = serverEntity.serverGhost->GetComponent<Ndk::PhysicsComponent2D>();
ghostPhysics.SetPosition(position);
ghostPhysics.SetRotation(rotation);
ghostPhysics.SetAngularVelocity(angularVelocity);
ghostPhysics.SetVelocity(linearVelocity);
}
else
{
auto& ghostNode = serverEntity.serverGhost->GetComponent<Nz::NodeComponent>();
ghostNode.SetPosition(position);
ghostNode.SetRotation(rotation);
}
}
}*/
auto& ghostNode = serverEntity.serverGhost->GetComponent<Nz::NodeComponent>();
ghostNode.SetPosition(position);
ghostNode.SetRotation(rotation);
}
}

break;
}

default:
break;
}*/
}
}
}
Expand Down
Loading

0 comments on commit 19ba8b0

Please sign in to comment.