moved network interface

This commit is contained in:
2024-08-19 15:24:44 +02:00
parent 99ff2c4ac3
commit 10f91f4b19
14 changed files with 190 additions and 216 deletions

View File

@@ -1,10 +1,11 @@
#pragma once
#include <blitz/protocol/PacketDispatcher.h>
#include <blitz/protocol/Packets.h>
#include <godot_cpp/classes/node.hpp>
#include <blitz/protocol/PacketDispatcher.h>
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

View File

@@ -1,32 +0,0 @@
#pragma once
#include <godot_cpp/classes/node.hpp>
#include <client/NetworkInterface.h>
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

View File

@@ -2,6 +2,7 @@
#include <godot_cpp/classes/button.hpp>
#include <godot_cpp/classes/control.hpp>
#include <blitz/godot/NetworkInterface.h>
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

View File

@@ -1,7 +1,7 @@
#pragma once
#include <godot_cpp/classes/node.hpp>
#include <blitz/common/Types.h>
#include <godot_cpp/classes/node.hpp>
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<PeerID> m_Peers;
godot::TypedArray<PeerID> m_Peers;
};
} // namespace blitz