move files into client folder

This commit is contained in:
2024-08-19 14:37:36 +02:00
parent 472f66d184
commit 99ff2c4ac3
18 changed files with 29 additions and 42 deletions

View File

@@ -0,0 +1,36 @@
#pragma once
#include <client/Player.h>
#include <godot_cpp/classes/input_event_mouse_motion.hpp>
namespace blitz {
class FirstPersonPlayer : public Player {
GDCLASS(FirstPersonPlayer, godot::CharacterBody3D)
protected:
static void _bind_methods();
public:
FirstPersonPlayer();
~FirstPersonPlayer();
// Godot overrides
void _unhandled_input(const godot::Ref<godot::InputEvent>&);
void _physics_process(float delta);
void _ready() override;
private:
godot::Camera3D* m_Camera;
godot::Node3D* m_Head;
float m_BobTime;
float m_Speed;
void UpdateBobbing(float delta);
void UpdateFOV(float delta);
void UpdateCamera(const godot::InputEventMouseMotion&);
void UpdatePosition(float delta);
void UpdateAnimation(float delta);
};
} // namespace blitz

32
include/client/Lobby.h Normal file
View File

@@ -0,0 +1,32 @@
#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

19
include/client/Main.h Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include <godot_cpp/classes/node.hpp>
namespace blitz {
class Main : public godot::Node {
GDCLASS(Main, godot::Node)
protected:
static void _bind_methods();
public:
Main();
~Main();
void ChangeScene();
};
} // namespace blitz

32
include/client/MainMenu.h Normal file
View File

@@ -0,0 +1,32 @@
#pragma once
#include <godot_cpp/classes/button.hpp>
#include <godot_cpp/classes/control.hpp>
namespace blitz {
class MainMenu : public godot::Control {
GDCLASS(MainMenu, godot::Control)
protected:
static void _bind_methods();
public:
MainMenu();
~MainMenu();
// Godot overrides
void _ready() override;
private:
godot::Button* m_JoinButton;
godot::Button* m_CreateButton;
godot::Button* m_QuitButton;
void OnConnected();
void OnJoinPressed();
void OnCreatePressed();
void OnQuitPressed();
};
} // namespace blitz

View File

@@ -0,0 +1,26 @@
#pragma once
#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:
static void _bind_methods();
public:
NetworkInterface();
~NetworkInterface();
void BroadcastPacket(const protocol::Packet& a_Packet);
void SendPacket(PeerID a_Peer, const protocol::Packet& a_Packet);
void _ready() override;
private:
void RecievePacketDataReliable(godot::PackedByteArray a_PacketData);
};
} // namespace blitz

44
include/client/Player.h Normal file
View File

@@ -0,0 +1,44 @@
#pragma once
#include <godot_cpp/classes/animation_tree.hpp>
#include <godot_cpp/classes/character_body3d.hpp>
#include <godot_cpp/classes/node3d.hpp>
#include <blitz/common/Types.h>
namespace blitz {
class World;
class Player : public godot::CharacterBody3D {
GDCLASS(Player, godot::CharacterBody3D);
protected:
static void _bind_methods();
public:
Player();
~Player();
void _ready();
void _physics_process(float delta);
void animate(float delta);
godot::Vector3 GetCameraRotation() const;
void SetCameraRotation(const godot::Vector3& a_Rotation);
PlayerID GetId() const {
return m_PeerId;
}
protected:
godot::Node3D* m_Mesh;
godot::AnimationTree* m_AnimationTree;
godot::Vector3 m_SnapVector;
float m_Speed;
PeerID m_PeerId;
friend class World;
};
} // namespace blitz

32
include/client/Server.h Normal file
View File

@@ -0,0 +1,32 @@
#pragma once
#include <godot_cpp/classes/node.hpp>
#include <blitz/common/Types.h>
namespace blitz {
class Lobby;
class NetworkInterface;
class Server : public godot::Node {
GDCLASS(Server, godot::Node)
protected:
static void _bind_methods();
public:
Server();
~Server();
void _ready() override;
void OnPlayerConnect(PeerID a_PeerId);
void OnPlayerDisconnect(PeerID a_PeerId);
private:
Lobby* m_Lobby;
NetworkInterface* m_NetworkInterface;
godot::TypedArray<PeerID> m_Peers;
};
} // namespace blitz

41
include/client/World.h Normal file
View File

@@ -0,0 +1,41 @@
#pragma once
#include <godot_cpp/classes/node3d.hpp>
#include <blitz/protocol/PacketHandler.h>
namespace blitz {
class Player;
class NetworkInterface;
class World : public godot::Node3D, public protocol::PacketHandler {
GDCLASS(World, godot::Node3D)
protected:
static void _bind_methods();
public:
World();
~World();
// Godot overrides
void _ready() override;
void _process(float delta);
Player* GetPlayerById(PlayerID a_PlayerId);
void HandlePacket(const protocol::packets::PlayerJoin&) override;
void HandlePacket(const protocol::packets::PlayerLeave&) override;
void HandlePacket(const protocol::packets::PlayerPositionAndRotation&) override;
private:
NetworkInterface* m_NetworkInterface;
godot::Node* m_Players;
float m_PassedTime;
void AddPlayer(PlayerID a_PlayerId, godot::String a_PlayerName);
void RemovePlayer(PlayerID a_PlayerId);
void SetPlayerPositionAndRotation(PlayerID a_PlayerId, const godot::Vector3& a_Position, const godot::Vector3& a_Rotation);
};
} // namespace blitz