This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
# Blender 3.6.4
|
||||
# www.blender.org
|
||||
mtllib untitled.mtl
|
||||
o Cube
|
||||
v 1.000000 3.829521 -1.000000
|
||||
v 1.000000 -1.000000 -1.000000
|
||||
v 1.000000 3.829521 1.000000
|
||||
v 1.000000 -1.000000 1.000000
|
||||
v -1.000000 3.829521 -1.000000
|
||||
v -1.000000 -1.000000 -1.000000
|
||||
v -1.000000 3.829521 1.000000
|
||||
v -1.000000 -1.000000 1.000000
|
||||
vn -0.0000 1.0000 -0.0000
|
||||
vn -0.0000 -0.0000 1.0000
|
||||
vn -1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -1.0000 -0.0000
|
||||
vn 1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -0.0000 -1.0000
|
||||
vt 0.625000 0.500000
|
||||
vt 0.875000 0.500000
|
||||
vt 0.875000 0.750000
|
||||
vt 0.625000 0.750000
|
||||
vt 0.375000 0.750000
|
||||
vt 0.625000 1.000000
|
||||
vt 0.375000 1.000000
|
||||
vt 0.375000 0.000000
|
||||
vt 0.625000 0.000000
|
||||
vt 0.625000 0.250000
|
||||
vt 0.375000 0.250000
|
||||
vt 0.125000 0.500000
|
||||
vt 0.375000 0.500000
|
||||
vt 0.125000 0.750000
|
||||
s 0
|
||||
usemtl Material
|
||||
f 1/1/1 5/2/1 7/3/1 3/4/1
|
||||
f 4/5/2 3/4/2 7/6/2 8/7/2
|
||||
f 8/8/3 7/9/3 5/10/3 6/11/3
|
||||
f 6/12/4 2/13/4 4/5/4 8/14/4
|
||||
f 2/13/5 1/1/5 3/4/5 4/5/5
|
||||
f 6/11/6 5/10/6 1/1/6 2/13/6
|
||||
@@ -1,37 +0,0 @@
|
||||
# Blender 3.6.4
|
||||
# www.blender.org
|
||||
mtllib void_map.mtl
|
||||
o Plane
|
||||
v -30.0 0.000000 30.0
|
||||
v 30.0 0.000000 30.0
|
||||
v -30.0 0.000000 -30.0
|
||||
v 30.0 0.000000 -30.0
|
||||
v -30.0 0.000000 30.0
|
||||
v -30.0 0.000000 -30.0
|
||||
v -30.0 0.000000 30.0
|
||||
v -30.0 0.000000 -30.0
|
||||
v -30.0 15.0 30.0
|
||||
v -30.0 15.0 -30.0
|
||||
v -30.0 15.0 -30.0
|
||||
v 30.0 15.0 -30.0
|
||||
v 30.0 15.0 30.0
|
||||
v 30.0 15.0 -30.0
|
||||
v -30.0 15.0 30.0
|
||||
v 30.0 15.0 30.0
|
||||
vn -0.0000 1.0000 -0.0000
|
||||
vn 1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -0.0000 1.0000
|
||||
vn -1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -0.0000 -1.0000
|
||||
vt 0.000000 0.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 1.000000 1.000000
|
||||
vt 0.000000 1.000000
|
||||
s 0
|
||||
f 1/1/1 2/2/1 4/3/1 3/4/1
|
||||
f 1/1/1 3/4/1 6/4/1 5/1/1
|
||||
f 5/1/1 6/4/1 8/4/1 7/1/1
|
||||
f 7/1/2 8/4/2 10/4/2 9/1/2
|
||||
f 3/4/3 4/3/3 12/3/3 11/4/3
|
||||
f 4/3/4 2/2/4 13/2/4 14/3/4
|
||||
f 2/2/5 1/1/5 15/1/5 16/2/5
|
||||
@@ -1,38 +0,0 @@
|
||||
# Blender 3.6.4
|
||||
# www.blender.org
|
||||
mtllib void_map2.mtl
|
||||
o Plane
|
||||
v -31.562399 0.000000 31.562399
|
||||
v 31.562399 0.000000 31.562399
|
||||
v -31.562399 0.000000 -31.562399
|
||||
v 31.562399 0.000000 -31.562399
|
||||
v -31.562399 0.000000 31.562399
|
||||
v -31.562399 0.000000 -31.562399
|
||||
v -31.562399 0.000000 31.562399
|
||||
v -31.562399 0.000000 -31.562399
|
||||
v -31.562399 12.947957 31.562399
|
||||
v -31.562399 12.947957 -31.562399
|
||||
v -31.562399 12.885334 -31.562399
|
||||
v 31.562399 12.885334 -31.562399
|
||||
v 31.562399 12.806857 31.562399
|
||||
v 31.562399 12.806857 -31.562399
|
||||
v -31.562399 12.847334 31.562399
|
||||
v 31.562399 12.847334 31.562399
|
||||
vn -0.0000 1.0000 -0.0000
|
||||
vn 1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -0.0000 1.0000
|
||||
vn -1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -0.0000 -1.0000
|
||||
vt 0.000000 0.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 1.000000 1.000000
|
||||
vt 0.000000 1.000000
|
||||
s 0
|
||||
usemtl carrelage
|
||||
f 1/1/1 2/2/1 4/3/1 3/4/1
|
||||
f 1/1/1 3/4/1 6/4/1 5/1/1
|
||||
f 5/1/1 6/4/1 8/4/1 7/1/1
|
||||
f 7/1/2 8/4/2 10/4/2 9/1/2
|
||||
f 3/4/3 4/3/3 12/3/3 11/4/3
|
||||
f 4/3/4 2/2/4 13/2/4 14/3/4
|
||||
f 2/2/5 1/1/5 15/1/5 16/2/5
|
||||
@@ -17,11 +17,17 @@ enum GameState : std::uint8_t {
|
||||
gsEnd,
|
||||
};
|
||||
|
||||
struct GameConfig {
|
||||
float Gravity;
|
||||
int FiringRate;
|
||||
};
|
||||
|
||||
class Game {
|
||||
protected:
|
||||
PlayerMap m_Players;
|
||||
GameState m_GameState;
|
||||
utils::Timer m_GameTimer;
|
||||
GameConfig m_Config;
|
||||
|
||||
public:
|
||||
Game() : m_GameState(gsNone) {}
|
||||
@@ -43,6 +49,14 @@ class Game {
|
||||
return m_GameState;
|
||||
}
|
||||
|
||||
void LoadConfig(const GameConfig& config) {
|
||||
m_Config = config;
|
||||
}
|
||||
|
||||
const game::GameConfig& GetGameConfig() const {
|
||||
return m_Config;
|
||||
}
|
||||
|
||||
virtual void AddPlayer(PlayerID player, const std::string& name);
|
||||
virtual void RemovePlayer(PlayerID player);
|
||||
|
||||
|
||||
25
include/blitz/game/LeaderBoard.h
Normal file
25
include/blitz/game/LeaderBoard.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "blitz/game/Player.h"
|
||||
#include <vector>
|
||||
|
||||
namespace blitz {
|
||||
namespace game {
|
||||
|
||||
class LeaderBoard {
|
||||
private:
|
||||
std::vector<Player*> m_Players;
|
||||
|
||||
public:
|
||||
void AddPlayer(Player* player);
|
||||
void RemovePlayer(PlayerID player);
|
||||
|
||||
void Update();
|
||||
|
||||
const std::vector<Player*>& GetPlayers() const {
|
||||
return m_Players;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace game
|
||||
} // namespace blitz
|
||||
@@ -1,8 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "blitz/common/Defines.h"
|
||||
#include "blitz/maths/Vector.h"
|
||||
#include <vector>
|
||||
|
||||
namespace blitz {
|
||||
|
||||
namespace protocol {
|
||||
|
||||
struct ColoredPart;
|
||||
typedef std::vector<ColoredPart> ColoredText;
|
||||
|
||||
} // namespace protocol
|
||||
|
||||
|
||||
namespace game {
|
||||
|
||||
class PlayerInputListener {
|
||||
@@ -11,5 +22,13 @@ class PlayerInputListener {
|
||||
virtual void OnLocalPlayerShoot(const Vec3f& position, float yaw, float pitch) {}
|
||||
};
|
||||
|
||||
class ClientListener {
|
||||
public:
|
||||
virtual void OnTextChatReceived(const protocol::ColoredText& text) {}
|
||||
virtual void OnSpectatorChange(game::PlayerID player) {}
|
||||
virtual void OnPlayerShoot(PlayerID player, const Vec3f& position, float yaw, float pitch) {}
|
||||
virtual void OnGameConfigUpdate() {}
|
||||
};
|
||||
|
||||
} // namespace game
|
||||
} // namespace blitz
|
||||
|
||||
@@ -102,6 +102,10 @@ class Player {
|
||||
m_IsBot = true;
|
||||
}
|
||||
|
||||
const PlayerStats& GetStats() const {
|
||||
return m_Stats;
|
||||
}
|
||||
|
||||
PlayerStats& GetStats() {
|
||||
return m_Stats;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
|
||||
@@ -41,28 +41,28 @@ class Connexion : public protocol::PacketHandler, private NonCopyable {
|
||||
|
||||
/**
|
||||
* \brief Default destructor
|
||||
*/
|
||||
*/
|
||||
virtual ~Connexion();
|
||||
|
||||
/**
|
||||
* \brief Reads socket and process a Packet, if any
|
||||
*/
|
||||
* \brief Reads socket and process a Packet, if any
|
||||
*/
|
||||
virtual bool UpdateSocket();
|
||||
|
||||
|
||||
/**
|
||||
* \brief Closes the connexion
|
||||
*/
|
||||
*/
|
||||
void CloseConnection();
|
||||
|
||||
/**
|
||||
* \brief Tries to connect the socket at the specified address and port
|
||||
* \return Wether this action was succesfull
|
||||
*/
|
||||
virtual bool Connect(const std::string& address, std::uint16_t port);
|
||||
*/
|
||||
bool Connect(const std::string& address, std::uint16_t port);
|
||||
|
||||
/**
|
||||
* \brief Returns the TCPSocket::Status of the internal socket
|
||||
*/
|
||||
*/
|
||||
TCPSocket::Status GetSocketStatus() const {
|
||||
return m_Socket.GetStatus();
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class Connexion : public protocol::PacketHandler, private NonCopyable {
|
||||
/**
|
||||
* \brief Sends the protocol::Packet over the network to the remote
|
||||
* \param packet The protocol::Packet to send
|
||||
*/
|
||||
*/
|
||||
void SendPacket(const protocol::Packet* packet);
|
||||
};
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ class PacketHandler {
|
||||
virtual void HandlePacket(const PlayerPositionAndRotationPacket* packet) {}
|
||||
virtual void HandlePacket(const PlayerShootPacket* packet) {}
|
||||
virtual void HandlePacket(const PlayerStatsPacket* packet) {}
|
||||
virtual void HandlePacket(const ServerConfigPacket* packet) {}
|
||||
virtual void HandlePacket(const ServerTpsPacket* packet) {}
|
||||
virtual void HandlePacket(const UpdateGameStatePacket* packet) {}
|
||||
virtual void HandlePacket(const UpdateHealthPacket* packet) {}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "packets/PlayerPositionAndRotationPacket.h"
|
||||
#include "packets/PlayerShootPacket.h"
|
||||
#include "packets/PlayerStatsPacket.h"
|
||||
#include "packets/ServerConfigPacket.h"
|
||||
#include "packets/ServerTpsPacket.h"
|
||||
#include "packets/UpdateGameStatePacket.h"
|
||||
#include "packets/UpdateHealthPacket.h"
|
||||
|
||||
@@ -14,6 +14,7 @@ class PlayerLoginPacket;
|
||||
class PlayerPositionAndRotationPacket;
|
||||
class PlayerShootPacket;
|
||||
class PlayerStatsPacket;
|
||||
class ServerConfigPacket;
|
||||
class ServerTpsPacket;
|
||||
class UpdateGameStatePacket;
|
||||
class UpdateHealthPacket;
|
||||
|
||||
@@ -29,6 +29,7 @@ enum class PacketType : std::uint8_t {
|
||||
PlayerLeave, /**< Corresponds to PlayerLeavePacket */
|
||||
PlayerList, /**< Corresponds to PlayerListPacket */
|
||||
PlayerStats, /**< Corresponds to PlayerStatsPacket */
|
||||
ServerConfig, /**< Corresponds to ServerConfigPacket*/
|
||||
ServerTps, /**< Corresponds to ServerTpsPacket */
|
||||
UpdateGameState, /**< Corresponds to UpdateGameStatePacket */
|
||||
|
||||
|
||||
32
include/blitz/protocol/packets/ServerConfigPacket.h
Normal file
32
include/blitz/protocol/packets/ServerConfigPacket.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "blitz/game/Game.h"
|
||||
#include "blitz/protocol/Protocol.h"
|
||||
|
||||
namespace blitz {
|
||||
namespace protocol {
|
||||
|
||||
class ServerConfigPacket : public Packet {
|
||||
private:
|
||||
game::GameConfig m_GameConfig;
|
||||
|
||||
public:
|
||||
ServerConfigPacket() {}
|
||||
ServerConfigPacket(const game::GameConfig& GameConfig) : m_GameConfig(GameConfig) {}
|
||||
virtual ~ServerConfigPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
game::GameConfig GetGameConfig() const {
|
||||
return m_GameConfig;
|
||||
}
|
||||
|
||||
virtual PacketType GetType() const {
|
||||
return PacketType::ServerConfig;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace blitz
|
||||
@@ -23,15 +23,10 @@ namespace server {
|
||||
class Server;
|
||||
} // namespace server
|
||||
|
||||
class GuiListener {
|
||||
public:
|
||||
virtual void OnTextChatReceived(const protocol::ColoredText& text) {}
|
||||
virtual void OnSpectatorChange(game::PlayerID player) {}
|
||||
virtual void OnPlayerShoot(game::PlayerID player, const Vec3f& position, float yaw, float pitch) {}
|
||||
};
|
||||
|
||||
|
||||
// Singleton
|
||||
class Client : public utils::ObjectNotifier<GuiListener>, public game::PlayerInputListener {
|
||||
class Client : public utils::ObjectNotifier<game::ClientListener>, public game::PlayerInputListener {
|
||||
private:
|
||||
std::unique_ptr<server::Server> m_Server;
|
||||
std::unique_ptr<client::ClientConnexion> m_Connexion;
|
||||
@@ -75,6 +70,8 @@ class Client : public utils::ObjectNotifier<GuiListener>, public game::PlayerInp
|
||||
return m_Server.get();
|
||||
}
|
||||
|
||||
void UpdateServerConfig();
|
||||
|
||||
private:
|
||||
void Reset();
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class ClientConnexion : public network::Connexion {
|
||||
virtual void HandlePacket(const protocol::ChatPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet) override;
|
||||
|
||||
virtual bool Connect(const std::string& pseudo, const std::string& address, std::uint16_t port);
|
||||
bool Connect(const std::string& pseudo, const std::string& address, std::uint16_t port);
|
||||
|
||||
game::PlayerID GetPlayerID() const {
|
||||
return m_PlayerID;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "blitz/game/Game.h"
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
@@ -19,11 +20,11 @@ typedef std::array<int, kaMax> Keybinds;
|
||||
class BlitzConfig {
|
||||
private:
|
||||
std::array<char, 256> m_Pseudo;
|
||||
game::GameConfig m_ServerConfig;
|
||||
bool m_VSync;
|
||||
bool m_DisplayFps;
|
||||
KeyAction m_CurrentAction;
|
||||
Keybinds m_Keybinds{};
|
||||
|
||||
float m_MouseSpeed;
|
||||
|
||||
public:
|
||||
BlitzConfig();
|
||||
@@ -53,6 +54,18 @@ class BlitzConfig {
|
||||
return m_Keybinds;
|
||||
}
|
||||
|
||||
float GetMouseSpeed() const {
|
||||
return m_MouseSpeed;
|
||||
}
|
||||
|
||||
void SetMouseSpeed(float MouseSpeed) {
|
||||
m_MouseSpeed = MouseSpeed;
|
||||
}
|
||||
|
||||
game::GameConfig& GetServerConfig() {
|
||||
return m_ServerConfig;
|
||||
}
|
||||
|
||||
private:
|
||||
void LoadConfig();
|
||||
void LoadDefaultConfig();
|
||||
|
||||
@@ -17,27 +17,17 @@ class Player;
|
||||
|
||||
namespace input {
|
||||
|
||||
class PlayerController : public utils::ObjectNotifier<game::PlayerInputListener> {
|
||||
class PlayerController : public utils::ObjectNotifier<game::PlayerInputListener>, game::ClientListener {
|
||||
private:
|
||||
game::Player* m_Player;
|
||||
Client* m_Client;
|
||||
utils::CooldownTimer<float> m_ShootTimer{1.0f};
|
||||
EMASmoother m_DxSmoother;
|
||||
EMASmoother m_DySmoother;
|
||||
/// current (target) x-axis velocity
|
||||
float m_Dx;
|
||||
/// current (target) y-axis velocity
|
||||
float m_Dy;
|
||||
/// current z-axis velocity
|
||||
float m_Dz;
|
||||
// current (target) velocity
|
||||
Vec3f m_Velocity;
|
||||
/// maximum x-axis velocity
|
||||
float m_MaxDx;
|
||||
/// maximum (target) y-axis velocity
|
||||
float m_MaxDy;
|
||||
/// maximum z-axis velocity (velocity at initial keypress)
|
||||
float m_MaxDz;
|
||||
/// individual gravitational force
|
||||
float m_G;
|
||||
Vec3f m_MaxVelocity;
|
||||
/// this is reset when the player touches the ground
|
||||
bool m_OnGround;
|
||||
|
||||
@@ -46,6 +36,8 @@ class PlayerController : public utils::ObjectNotifier<game::PlayerInputListener>
|
||||
|
||||
void Update(float delta);
|
||||
|
||||
virtual void OnGameConfigUpdate() override;
|
||||
|
||||
void SetAttachedPlayer(game::Player* a_Player) {
|
||||
m_Player = a_Player;
|
||||
}
|
||||
@@ -55,6 +47,7 @@ class PlayerController : public utils::ObjectNotifier<game::PlayerInputListener>
|
||||
}
|
||||
|
||||
private:
|
||||
void UpdateShootTimer(int bpm);
|
||||
void MouseMotionEvent(int, int);
|
||||
void UpdatePosition(float delta);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "blitz/game/Game.h"
|
||||
#include "blitz/game/LeaderBoard.h"
|
||||
#include "blitz/protocol/PacketHandler.h"
|
||||
#include <vector>
|
||||
|
||||
namespace blitz {
|
||||
|
||||
@@ -12,6 +14,7 @@ namespace client {
|
||||
class ClientGame : public game::Game, public protocol::PacketHandler {
|
||||
private:
|
||||
Client* m_Client;
|
||||
game::LeaderBoard m_LeaderBoard;
|
||||
|
||||
public:
|
||||
ClientGame(Client* client, protocol::PacketDispatcher* dispatcher);
|
||||
@@ -27,6 +30,14 @@ class ClientGame : public game::Game, public protocol::PacketHandler {
|
||||
virtual void HandlePacket(const protocol::UpdateHealthPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::PlayerStatsPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::UpdateGameStatePacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::ServerConfigPacket* packet) override;
|
||||
|
||||
virtual void AddPlayer(game::PlayerID player, const std::string& name) override;
|
||||
virtual void RemovePlayer(game::PlayerID player) override;
|
||||
|
||||
const game::LeaderBoard& GetLeaderBoard() const {
|
||||
return m_LeaderBoard;
|
||||
}
|
||||
|
||||
private:
|
||||
void RegisterHandlers();
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace blitz {
|
||||
|
||||
namespace gui {
|
||||
|
||||
class GameChatGui : public GuiWidget, GuiListener {
|
||||
class GameChatGui : public GuiWidget, game::ClientListener {
|
||||
private:
|
||||
char InputBuf[256];
|
||||
std::vector<protocol::ColoredText> m_Lines;
|
||||
@@ -26,7 +26,8 @@ class GameChatGui : public GuiWidget, GuiListener {
|
||||
|
||||
public:
|
||||
GameChatGui(GuiWidget* parent, Client* client);
|
||||
virtual void OnTextChatReceived(const protocol::ColoredText& text);
|
||||
|
||||
virtual void OnTextChatReceived(const protocol::ColoredText& text) override;
|
||||
|
||||
virtual void Render() override;
|
||||
};
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
namespace blitz {
|
||||
|
||||
namespace gui {
|
||||
class LeaderBoard : public GuiWidget {
|
||||
class LeaderBoardGui : public GuiWidget {
|
||||
private:
|
||||
void Draw(const char* title, bool* p_open);
|
||||
utils::DelayTimer<float> m_Timer{5.0f};
|
||||
|
||||
public:
|
||||
LeaderBoard(GuiWidget* parent, Client* client);
|
||||
~LeaderBoard();
|
||||
LeaderBoardGui(GuiWidget* parent, Client* client);
|
||||
~LeaderBoardGui();
|
||||
|
||||
virtual void Render() override;
|
||||
};
|
||||
@@ -28,14 +28,13 @@ class BulletRenderer {
|
||||
std::vector<Trail> m_Trails;
|
||||
ModelLoader::Model m_BulletModel;
|
||||
std::unique_ptr<shader::BulletShader> m_Shader;
|
||||
unsigned int m_Vbo;
|
||||
const Camera& m_Camera;
|
||||
|
||||
public:
|
||||
BulletRenderer(const Camera& cam);
|
||||
~BulletRenderer();
|
||||
|
||||
void AddBullet(const Vec3f& origin, float yaw, float pitch);
|
||||
void AddBullet(const Vec3f& origin, float yaw, float pitch, bool firstPersson);
|
||||
void Update(float delta);
|
||||
void Render();
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ class GunShader;
|
||||
|
||||
namespace render {
|
||||
|
||||
class MainRenderer : public GuiListener, public game::PlayerInputListener {
|
||||
class MainRenderer : public game::ClientListener, public game::PlayerInputListener {
|
||||
private:
|
||||
Client* m_Client;
|
||||
ModelLoader::Model m_PlayerModel;
|
||||
@@ -43,6 +43,8 @@ class MainRenderer : public GuiListener, public game::PlayerInputListener {
|
||||
virtual void OnPlayerShoot(game::PlayerID player, const Vec3f& position, float yaw, float pitch) override;
|
||||
virtual void OnLocalPlayerShoot(const Vec3f& position, float yaw, float pitch) override;
|
||||
|
||||
virtual void OnGameConfigUpdate() override;
|
||||
|
||||
void Update();
|
||||
void Render();
|
||||
void RenderEntity(const GL::VertexArray& vao, const Vec3f& position, float yaw);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef BLITZ_GL_LOADER_GLBNIDING
|
||||
#ifdef BLITZ_GL_LOADER_GLEW
|
||||
#include <GL/glew.h>
|
||||
#else
|
||||
#include <glbinding/gl/gl.h>
|
||||
|
||||
@@ -48,7 +48,7 @@ class ServerConnexion : public network::Connexion {
|
||||
return m_ID;
|
||||
}
|
||||
|
||||
virtual bool UpdateSocket();
|
||||
virtual bool UpdateSocket() override;
|
||||
|
||||
private:
|
||||
void RegisterHandlers();
|
||||
@@ -58,6 +58,7 @@ class ServerConnexion : public network::Connexion {
|
||||
void InitPlayerChatColor();
|
||||
void SendPlayers();
|
||||
void SendGameState();
|
||||
void SendServerConfig();
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
|
||||
@@ -36,6 +36,8 @@ class ServerGame : public game::Game {
|
||||
return m_ServerDuration;
|
||||
}
|
||||
|
||||
void SendServerConfig();
|
||||
|
||||
private:
|
||||
void SendPlayerPositions();
|
||||
void DamagePlayer(game::Player& player, game::Player& shooter);
|
||||
|
||||
29
src/blitz/game/LeaderBoard.cpp
Normal file
29
src/blitz/game/LeaderBoard.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "blitz/game/LeaderBoard.h"
|
||||
|
||||
namespace blitz {
|
||||
namespace game {
|
||||
|
||||
void LeaderBoard::AddPlayer(Player* player) {
|
||||
m_Players.push_back(player);
|
||||
Update();
|
||||
}
|
||||
|
||||
void LeaderBoard::RemovePlayer(PlayerID player) {
|
||||
auto it = std::find_if(m_Players.begin(), m_Players.end(), [player](game::Player* p) { return p->GetID() == player; });
|
||||
if (it != m_Players.end())
|
||||
m_Players.erase(it);
|
||||
}
|
||||
|
||||
void LeaderBoard::Update() {
|
||||
std::sort(m_Players.begin(), m_Players.end(), [](Player* a, Player* b) {
|
||||
std::uint16_t killsA = a->GetStats().m_Kills;
|
||||
std::uint16_t killsB = b->GetStats().m_Kills;
|
||||
if (killsA == killsB) {
|
||||
return a->GetStats().m_Deaths < b->GetStats().m_Deaths;
|
||||
}
|
||||
return killsA > killsB;
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
} // namespace blitz
|
||||
@@ -89,6 +89,8 @@ bool TCPSocket::Connect(const std::string& host, unsigned short port) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SetBlocking(m_Blocking);
|
||||
|
||||
struct addrinfo* ptr = nullptr;
|
||||
for (ptr = result; ptr != nullptr; ptr = ptr->ai_next) {
|
||||
struct sockaddr* sockaddr = ptr->ai_addr;
|
||||
@@ -125,6 +127,7 @@ size_t TCPSocket::Send(const unsigned char* data, size_t size) {
|
||||
if (cur <= 0) {
|
||||
m_Status = Status::Error;
|
||||
Disconnect();
|
||||
m_Status = Status::Error;
|
||||
return 0;
|
||||
}
|
||||
sent += static_cast<std::size_t>(cur);
|
||||
@@ -150,6 +153,7 @@ std::size_t TCPSocket::Receive(DataBuffer& buffer, std::size_t amount) {
|
||||
|
||||
Disconnect();
|
||||
buffer.Clear();
|
||||
m_Status = Status::Error;
|
||||
return 0;
|
||||
}
|
||||
buffer.Resize(static_cast<std::size_t>(recvAmount));
|
||||
|
||||
@@ -20,6 +20,7 @@ static std::array<PacketPtr, static_cast<std::size_t>(PacketType::PACKET_COUNT)>
|
||||
std::make_unique<PlayerLeavePacket>(),
|
||||
std::make_unique<PlayerListPacket>(),
|
||||
std::make_unique<PlayerStatsPacket>(),
|
||||
std::make_unique<ServerConfigPacket>(),
|
||||
std::make_unique<ServerTpsPacket>(),
|
||||
std::make_unique<UpdateGameStatePacket>(),
|
||||
std::make_unique<KeepAlivePacket>(),
|
||||
|
||||
@@ -28,6 +28,7 @@ REGISTER_DISPATCH_CLASS(PlayerShootPacket);
|
||||
REGISTER_DISPATCH_CLASS(UpdateHealthPacket);
|
||||
REGISTER_DISPATCH_CLASS(PlayerStatsPacket);
|
||||
REGISTER_DISPATCH_CLASS(UpdateGameStatePacket);
|
||||
REGISTER_DISPATCH_CLASS(ServerConfigPacket);
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace blitz
|
||||
|
||||
19
src/blitz/protocol/packets/ServerConfigPacket.cpp
Normal file
19
src/blitz/protocol/packets/ServerConfigPacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "blitz/protocol/packets/ServerConfigPacket.h"
|
||||
|
||||
namespace blitz {
|
||||
namespace protocol {
|
||||
|
||||
DataBuffer ServerConfigPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_GameConfig;
|
||||
return data;
|
||||
}
|
||||
|
||||
void ServerConfigPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_GameConfig;
|
||||
}
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace blitz
|
||||
@@ -36,6 +36,12 @@ bool Client::JoinGame(const std::string& pseudo, const std::string& address, std
|
||||
return m_Connexion->Connect(pseudo, address, port);
|
||||
}
|
||||
|
||||
void Client::UpdateServerConfig() {
|
||||
m_Server->GetGame().LoadConfig(m_Config.GetServerConfig());
|
||||
|
||||
m_Server->GetGame().SendServerConfig();
|
||||
}
|
||||
|
||||
bool Client::CreateGame(std::uint16_t port, const std::string& pseudo) {
|
||||
if (!m_Server->Start(port, false))
|
||||
return false;
|
||||
@@ -45,6 +51,8 @@ bool Client::CreateGame(std::uint16_t port, const std::string& pseudo) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UpdateServerConfig();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -71,7 +79,7 @@ void Client::SendChatText(const std::string& text) {
|
||||
}
|
||||
|
||||
void Client::ChatTextReceived(const protocol::ColoredText& text) {
|
||||
NotifyListeners(&GuiListener::OnTextChatReceived, text);
|
||||
NotifyListeners(&game::ClientListener::OnTextChatReceived, text);
|
||||
}
|
||||
|
||||
void Client::SendPlayerPosAndLook(const Vec3f& position, float yaw, float pitch) {
|
||||
|
||||
@@ -37,6 +37,9 @@ void BlitzConfig::LoadConfig() {
|
||||
std::memcpy(m_Pseudo.data(), pseudo.data(), pseudo.size() + 1);
|
||||
jsonInput.at("vsync").get_to<bool>(m_VSync);
|
||||
jsonInput.at("fps").get_to<bool>(m_DisplayFps);
|
||||
jsonInput.at("sensitivity").get_to<float>(m_MouseSpeed);
|
||||
jsonInput.at("gravity").get_to<float>(m_ServerConfig.Gravity);
|
||||
jsonInput.at("firingrate").get_to<int>(m_ServerConfig.FiringRate);
|
||||
jsonInput.at("keys").get_to<Keybinds>(m_Keybinds);
|
||||
|
||||
utils::LOG("[BlitzConfig] Restored config !");
|
||||
@@ -50,6 +53,9 @@ void BlitzConfig::LoadDefaultConfig() {
|
||||
m_VSync = true;
|
||||
const char defaultPseudo[] = "Pseudo";
|
||||
std::memcpy(m_Pseudo.data(), defaultPseudo, sizeof(defaultPseudo));
|
||||
m_MouseSpeed = 0.0025f;
|
||||
m_ServerConfig.Gravity = 20.0f;
|
||||
m_ServerConfig.FiringRate = 60;
|
||||
m_Keybinds = {ImGuiKey_Z, ImGuiKey_S, ImGuiKey_D, ImGuiKey_Q, ImGuiKey_P};
|
||||
}
|
||||
|
||||
@@ -64,6 +70,9 @@ void BlitzConfig::SaveConfig() {
|
||||
{"pseudo", GetPseudo().data()},
|
||||
{"vsync", IsVSyncEnabled()},
|
||||
{"fps", IsFPSDisplayEnabled()},
|
||||
{"sensitivity", GetMouseSpeed()},
|
||||
{"gravity", GetServerConfig().Gravity},
|
||||
{"firingrate", GetServerConfig().FiringRate},
|
||||
{"keys", GetKeys()},
|
||||
};
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
#include "client/gui/BlitzGui.h"
|
||||
|
||||
#ifndef BLITZ_GL_LOADER_GLBNIDING
|
||||
#ifdef BLITZ_GL_LOADER_GLEW
|
||||
#include <GL/glew.h>
|
||||
#else
|
||||
#include <glbinding/glbinding.h>
|
||||
@@ -97,7 +97,7 @@ bool Display::Create() {
|
||||
SDL_GL_MakeCurrent(m_Window, m_GL_Context);
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
|
||||
#ifndef BLITZ_GL_LOADER_GLBNIDING
|
||||
#ifdef BLITZ_GL_LOADER_GLEW
|
||||
GLenum error = glewInit();
|
||||
if (error != GLEW_OK) {
|
||||
utils::LOGE(utils::Format("[Display] Failed to initialise glew : %s", glewGetErrorString(error)));
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
#include "blitz/game/Player.h"
|
||||
#include "blitz/maths/Maths.h"
|
||||
#include "blitz/misc/Log.h"
|
||||
#include "blitz/maths/Maths.h"
|
||||
#include "client/Client.h"
|
||||
#include "client/config/BlitzConfig.h"
|
||||
#include "client/display/InputManager.h"
|
||||
#include "client/game/ClientGame.h"
|
||||
#include "imgui.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
@@ -14,7 +15,6 @@ namespace blitz {
|
||||
namespace input {
|
||||
|
||||
static constexpr float DEFAULT_JUMP_VEL = 7.5;
|
||||
static constexpr float DEFAULT_GRAVITY = 20.0;
|
||||
static constexpr float DEFAULT_MAX_LR_SPEED = 10.;
|
||||
static constexpr float DEFAULT_MAX_FB_SPEED = 10.;
|
||||
static constexpr float DEFAULT_LR_SPEED_SMOOTHING_TIME = 1.0;
|
||||
@@ -23,13 +23,8 @@ static constexpr float DEFAULT_FB_SPEED_SMOOTHING_TIME = 1.0;
|
||||
PlayerController::PlayerController(Client* client) :
|
||||
m_Player(nullptr),
|
||||
m_Client(client),
|
||||
m_Dx(0.0),
|
||||
m_Dy(0.0),
|
||||
m_Dz(0.0),
|
||||
m_MaxDx(DEFAULT_MAX_LR_SPEED),
|
||||
m_MaxDy(DEFAULT_MAX_FB_SPEED),
|
||||
m_MaxDz(DEFAULT_JUMP_VEL),
|
||||
m_G(DEFAULT_GRAVITY),
|
||||
m_Velocity({}),
|
||||
m_MaxVelocity(DEFAULT_MAX_LR_SPEED, DEFAULT_MAX_FB_SPEED, DEFAULT_JUMP_VEL),
|
||||
m_OnGround(true) {
|
||||
m_DxSmoother.Current = 0.0f;
|
||||
m_DySmoother.Current = 0.0f;
|
||||
@@ -37,13 +32,23 @@ PlayerController::PlayerController(Client* client) :
|
||||
m_DySmoother.SetSmoothingTime(DEFAULT_FB_SPEED_SMOOTHING_TIME);
|
||||
InputManager::BindMouseMoveCallback(
|
||||
std::bind(&PlayerController::MouseMotionEvent, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->BindListener(this);
|
||||
}
|
||||
|
||||
void PlayerController::OnGameConfigUpdate() {
|
||||
UpdateShootTimer(m_Client->GetGame()->GetGameConfig().FiringRate);
|
||||
}
|
||||
|
||||
void PlayerController::UpdateShootTimer(int bpm) {
|
||||
m_ShootTimer.SetCooldown(60.0f / static_cast<float>(bpm));
|
||||
m_ShootTimer.Reset();
|
||||
}
|
||||
|
||||
void PlayerController::MouseMotionEvent(int deltaX, int deltaY) {
|
||||
if (!m_Player || !InputManager::MouseGrabbed())
|
||||
return;
|
||||
|
||||
static const float MouseSpeed = 0.0025f;
|
||||
float MouseSpeed = m_Client->GetConfig()->GetMouseSpeed();
|
||||
|
||||
m_Player->AddYaw(deltaX * MouseSpeed);
|
||||
m_Player->AddPitch(deltaY * -MouseSpeed);
|
||||
@@ -64,20 +69,22 @@ void PlayerController::Update(float delta) {
|
||||
// scale values in such a way that clamps ||(lr, fb)|| to 1.0
|
||||
float scale = 1.0f / std::max(sqrt(lr * lr + fb * fb), 1.0f);
|
||||
|
||||
m_Dx = lr * m_MaxDx * scale;
|
||||
m_Dy = fb * m_MaxDy * scale;
|
||||
m_Velocity.x = lr * m_MaxVelocity.x * scale;
|
||||
m_Velocity.y = fb * m_MaxVelocity.y * scale;
|
||||
|
||||
if (ImGui::IsKeyDown(ImGuiKey::ImGuiKey_Space) && m_OnGround) {
|
||||
m_Dz = m_MaxDz;
|
||||
m_Velocity.z = m_MaxVelocity.z;
|
||||
NotifyListeners(&game::PlayerInputListener::OnLocalPlayerJump);
|
||||
}
|
||||
|
||||
bool canShoot = m_ShootTimer.Update(delta);
|
||||
bool canShoot = m_ShootTimer.Update(ImGui::GetIO().DeltaTime);
|
||||
if (ImGui::IsMouseDown(ImGuiMouseButton_Left) && canShoot) {
|
||||
NotifyListeners(
|
||||
&game::PlayerInputListener::OnLocalPlayerShoot, m_Player->GetPosition(), m_Player->GetYaw(), m_Player->GetPitch());
|
||||
m_ShootTimer.ApplyCooldown();
|
||||
}
|
||||
} else {
|
||||
m_Velocity.x = m_Velocity.y = 0.0f;
|
||||
}
|
||||
|
||||
UpdatePosition(delta);
|
||||
@@ -89,8 +96,8 @@ void PlayerController::UpdatePosition(const float delta) {
|
||||
float sine = std::sin(yaw);
|
||||
float cosine = std::cos(yaw);
|
||||
|
||||
m_DxSmoother.Tick(m_Dx, delta);
|
||||
m_DySmoother.Tick(m_Dy, delta);
|
||||
m_DxSmoother.Tick(m_Velocity.x, delta);
|
||||
m_DySmoother.Tick(m_Velocity.y, delta);
|
||||
|
||||
float dx_smooth = m_DxSmoother.Current;
|
||||
float dy_smooth = m_DySmoother.Current;
|
||||
@@ -98,7 +105,7 @@ void PlayerController::UpdatePosition(const float delta) {
|
||||
float dx = (dx_smooth * cosine + dy_smooth * sine) * delta;
|
||||
float dy = (dx_smooth * sine - dy_smooth * cosine) * delta;
|
||||
|
||||
float dz = m_Dz * delta;
|
||||
float dz = m_Velocity.z * delta;
|
||||
|
||||
// the floor here is y-level zero, once downwards collision lands it will be dynmicallly calculated
|
||||
// assumed to be a negative number
|
||||
@@ -106,9 +113,9 @@ void PlayerController::UpdatePosition(const float delta) {
|
||||
|
||||
if ((m_OnGround = (dz <= floor_dist))) {
|
||||
dz = floor_dist;
|
||||
m_Dz = 0.0f;
|
||||
m_Velocity.z = 0.0f;
|
||||
} else {
|
||||
m_Dz -= m_G * delta;
|
||||
m_Velocity.z -= m_Client->GetGame()->GetGameConfig().Gravity * 1.0f * delta;
|
||||
}
|
||||
|
||||
m_Player->AddPosition({dx, dz, dy});
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "blitz/protocol/packets/PlayerPositionAndRotationPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerShootPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerStatsPacket.h"
|
||||
#include "blitz/protocol/packets/ServerConfigPacket.h"
|
||||
#include "blitz/protocol/packets/UpdateGameStatePacket.h"
|
||||
#include "blitz/protocol/packets/UpdateHealthPacket.h"
|
||||
#include "client/Client.h"
|
||||
@@ -25,6 +26,15 @@ ClientGame::~ClientGame() {
|
||||
GetDispatcher()->UnregisterHandler(this);
|
||||
}
|
||||
|
||||
void ClientGame::AddPlayer(game::PlayerID player, const std::string& name) {
|
||||
Game::AddPlayer(player, name);
|
||||
m_LeaderBoard.AddPlayer(GetPlayerById(player));
|
||||
}
|
||||
void ClientGame::RemovePlayer(game::PlayerID player) {
|
||||
Game::RemovePlayer(player);
|
||||
m_LeaderBoard.RemovePlayer(player);
|
||||
}
|
||||
|
||||
void ClientGame::RegisterHandlers() {
|
||||
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerJoin, this);
|
||||
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerLeave, this);
|
||||
@@ -34,6 +44,7 @@ void ClientGame::RegisterHandlers() {
|
||||
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerStats, this);
|
||||
GetDispatcher()->RegisterHandler(protocol::PacketType::UpdateGameState, this);
|
||||
GetDispatcher()->RegisterHandler(protocol::PacketType::UpdateHealth, this);
|
||||
GetDispatcher()->RegisterHandler(protocol::PacketType::ServerConfig, this);
|
||||
}
|
||||
|
||||
void ClientGame::HandlePacket(const protocol::PlayerJoinPacket* packet) {
|
||||
@@ -41,7 +52,7 @@ void ClientGame::HandlePacket(const protocol::PlayerJoinPacket* packet) {
|
||||
|
||||
// Initialize camera
|
||||
if (packet->GetPlayerID() == m_Client->GetPlayerID()) {
|
||||
m_Client->NotifyListeners(&GuiListener::OnSpectatorChange, packet->GetPlayerID());
|
||||
m_Client->NotifyListeners(&game::ClientListener::OnSpectatorChange, packet->GetPlayerID());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +71,8 @@ void ClientGame::HandlePacket(const protocol::PlayerStatsPacket* packet) {
|
||||
if (!player)
|
||||
return;
|
||||
player->SetStats(packet->GetPlayerStats());
|
||||
|
||||
m_LeaderBoard.Update();
|
||||
}
|
||||
|
||||
void ClientGame::HandlePacket(const protocol::UpdateHealthPacket* packet) {
|
||||
@@ -78,9 +91,14 @@ void ClientGame::HandlePacket(const protocol::UpdateGameStatePacket* packet) {
|
||||
m_GameTimer.Reset();
|
||||
}
|
||||
|
||||
void ClientGame::HandlePacket(const protocol::ServerConfigPacket* packet) {
|
||||
m_Config = packet->GetGameConfig();
|
||||
m_Client->NotifyListeners(&game::ClientListener::OnGameConfigUpdate);
|
||||
}
|
||||
|
||||
void ClientGame::HandlePacket(const protocol::PlayerShootPacket* packet) {
|
||||
m_Client->NotifyListeners(
|
||||
&GuiListener::OnPlayerShoot, packet->GetPlayer(), packet->GetPosition(), packet->GetYaw(), packet->GetPitch());
|
||||
&game::ClientListener::OnPlayerShoot, packet->GetPlayer(), packet->GetPosition(), packet->GetYaw(), packet->GetPitch());
|
||||
}
|
||||
|
||||
void ClientGame::HandlePacket(const protocol::PlayerPositionAndRotationPacket* packet) {
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include "client/gui/Crosshair.h"
|
||||
#include "client/gui/GameChatGui.h"
|
||||
#include "client/gui/Hud.h"
|
||||
#include "client/gui/LeaderBoardGui.h"
|
||||
#include "client/gui/MainMenu.h"
|
||||
#include "client/gui/LeaderBoard.h"
|
||||
#include "client/gui/ServerGui.h"
|
||||
#include <imgui.h>
|
||||
|
||||
@@ -17,7 +17,7 @@ BlitzGui::BlitzGui(Client* client) : GuiWidget(nullptr, client) {
|
||||
AddWidget(std::make_unique<MainMenu>(client));
|
||||
AddWidget(std::make_unique<CrossHair>(client));
|
||||
AddWidget(std::make_unique<Hud>(this, client));
|
||||
AddWidget(std::make_unique<LeaderBoard>(this, client));
|
||||
AddWidget(std::make_unique<LeaderBoardGui>(this, client));
|
||||
AddWidget(std::make_unique<ServerGui>(this, client));
|
||||
SetCustomTheme();
|
||||
}
|
||||
|
||||
@@ -161,12 +161,13 @@ void Hud::Render() {
|
||||
static game::Player* winner = nullptr;
|
||||
|
||||
switch (m_Client->GetGame()->GetGameState()) {
|
||||
case game::GameState::gsEnd:
|
||||
case game::GameState::gsEnd: {
|
||||
if (!winner) {
|
||||
winner = GetWinner();
|
||||
}
|
||||
DrawFinishScreen(winner->GetID() == m_Client->GetPlayerID());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Draw("Hud Blitz", nullptr);
|
||||
winner = nullptr;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "client/gui/LeaderBoard.h"
|
||||
#include "client/gui/LeaderBoardGui.h"
|
||||
|
||||
#include "blitz/misc/Format.h"
|
||||
#include "blitz/misc/Log.h"
|
||||
@@ -10,11 +10,11 @@
|
||||
namespace blitz {
|
||||
namespace gui {
|
||||
|
||||
LeaderBoard::LeaderBoard(GuiWidget* parent, Client* client) : GuiWidget(parent, client) {}
|
||||
LeaderBoardGui::LeaderBoardGui(GuiWidget* parent, Client* client) : GuiWidget(parent, client) {}
|
||||
|
||||
LeaderBoard::~LeaderBoard() {}
|
||||
LeaderBoardGui::~LeaderBoardGui() {}
|
||||
|
||||
void LeaderBoard::Draw(const char* title, bool* p_open) {
|
||||
void LeaderBoardGui::Draw(const char* title, bool* p_open) {
|
||||
static float leaderboard_width = 640.0f;
|
||||
static float leaderboard_height = 450.0f;
|
||||
|
||||
@@ -31,20 +31,21 @@ void LeaderBoard::Draw(const char* title, bool* p_open) {
|
||||
std::string deathsLeaderBoard = "Deaths";
|
||||
std::string kdLeaderBoard = "K/D";
|
||||
std::string precisionLeaderBoard = "Accuracy";
|
||||
for (auto [id, player] : m_Client->GetGame()->GetPlayers()) {
|
||||
playerLeaderBoard += utils::Format("\n%s", player.GetName().c_str());
|
||||
killsLeaderBoard += utils::Format("\n%i", player.GetStats().m_Kills);
|
||||
deathsLeaderBoard += utils::Format("\n%i", player.GetStats().m_Deaths);
|
||||
for (game::Player* player : m_Client->GetGame()->GetLeaderBoard().GetPlayers()) {
|
||||
playerLeaderBoard += utils::Format("\n%s", player->GetName().c_str());
|
||||
killsLeaderBoard += utils::Format("\n%i", player->GetStats().m_Kills);
|
||||
deathsLeaderBoard += utils::Format("\n%i", player->GetStats().m_Deaths);
|
||||
|
||||
// Check if the denominator is zero before calculating K/D ratio
|
||||
float kdRatio =
|
||||
(player.GetStats().m_Deaths != 0) ? static_cast<float>(player.GetStats().m_Kills) / player.GetStats().m_Deaths : 0.0f;
|
||||
float kdRatio = (player->GetStats().m_Deaths != 0)
|
||||
? static_cast<float>(player->GetStats().m_Kills) / player->GetStats().m_Deaths
|
||||
: 0.0f;
|
||||
kdLeaderBoard += utils::Format("\n%.2f", kdRatio);
|
||||
|
||||
// Check if the denominator is zero before calculating precision percentage
|
||||
float precisionPercentage =
|
||||
(player.GetStats().m_ShootCount != 0)
|
||||
? static_cast<float>(player.GetStats().m_ShootSuccessCount) / player.GetStats().m_ShootCount * 100.0f
|
||||
(player->GetStats().m_ShootCount != 0)
|
||||
? static_cast<float>(player->GetStats().m_ShootSuccessCount) / player->GetStats().m_ShootCount * 100.0f
|
||||
: 0.0f;
|
||||
precisionLeaderBoard += utils::Format("\n%.2f%%", precisionPercentage);
|
||||
}
|
||||
@@ -61,7 +62,7 @@ void LeaderBoard::Draw(const char* title, bool* p_open) {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void LeaderBoard::Render() {
|
||||
void LeaderBoardGui::Render() {
|
||||
if (!m_Client->IsConnected())
|
||||
return;
|
||||
|
||||
@@ -164,12 +164,14 @@ void OptionsMenu::Render() {
|
||||
ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_None;
|
||||
if (ImGui::BeginTabBar("OPTIONS", tab_bar_flags)) {
|
||||
if (ImGui::BeginTabItem("CONTROLES")) {
|
||||
// Always center this window when appearing
|
||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||
|
||||
HotkeyBindingButton();
|
||||
HotkeyBindingPopUp();
|
||||
float sensitivity = m_Client->GetConfig()->GetMouseSpeed() * 200.0f;
|
||||
ImGui::SetNextItemWidth(300.0f);
|
||||
if (ImGui::DragFloat("Sensibilite", &sensitivity, 0.005f, 0.001f, 10.0f, "%.3f")) {
|
||||
sensitivity = std::clamp(sensitivity, 0.001f, 10.0f);
|
||||
m_Client->GetConfig()->SetMouseSpeed(sensitivity / 200.0f);
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("GRAPHISMES")) {
|
||||
|
||||
@@ -24,7 +24,7 @@ void ServerGui::Render() {
|
||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar;
|
||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||
static float servergui_width = 640.0f;
|
||||
static float servergui_height = 450.0f;
|
||||
static float servergui_height = 640.0f;
|
||||
|
||||
const static ImVec2 buttonSize = {300, 60};
|
||||
|
||||
@@ -40,6 +40,43 @@ void ServerGui::Render() {
|
||||
if (ImGui::Button("Ajouter Bot", buttonSize)) {
|
||||
m_Client->GetServer()->AddBot();
|
||||
}
|
||||
|
||||
ImGui::NewLine();
|
||||
ImGui::Text("GRAVITE");
|
||||
float gravity[] = {20.0f, 7.0f, 40.0f};
|
||||
const char* planetes[] = {"Terrestre", "Lunaire", "Solaire"};
|
||||
static int item_current_idx;
|
||||
float currentGravity = m_Client->GetConfig()->GetServerConfig().Gravity;
|
||||
for (int n = 0; n < IM_ARRAYSIZE(planetes); n++) {
|
||||
if (gravity[n] == currentGravity) {
|
||||
item_current_idx = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ImGui::BeginListBox("##Gravity", ImVec2(300.0f, 100.0f))) {
|
||||
for (int n = 0; n < IM_ARRAYSIZE(planetes); n++) {
|
||||
const bool is_selected = (item_current_idx == n);
|
||||
if (ImGui::Selectable(planetes[n], is_selected)) {
|
||||
item_current_idx = n;
|
||||
m_Client->GetConfig()->GetServerConfig().Gravity = gravity[n];
|
||||
m_Client->UpdateServerConfig();
|
||||
}
|
||||
|
||||
if (is_selected)
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
ImGui::EndListBox();
|
||||
}
|
||||
|
||||
ImGui::NewLine();
|
||||
int& firingrate = m_Client->GetConfig()->GetServerConfig().FiringRate;
|
||||
ImGui::SetNextItemWidth(300.0f);
|
||||
if (ImGui::DragInt("##CADENCE TIR", &firingrate, 1, 1, 1000)) {
|
||||
firingrate = std::clamp(firingrate, 1, 1000);
|
||||
m_Client->UpdateServerConfig();
|
||||
}
|
||||
ImGui::Text("Cpm/Rpm %i", firingrate);
|
||||
|
||||
ImGui::SetCursorPosY(servergui_height - 2.0f * buttonSize.y);
|
||||
if (ImGui::Button("Retour", buttonSize)) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
@@ -66,7 +103,7 @@ void ServerGui::Render() {
|
||||
ImGui::Text("%s", min.c_str());
|
||||
ImGui::SameLine();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, 40);
|
||||
if (ImGui::VSliderInt("##int1", ImVec2(40, 160), &gameDurMin, 1, 10)) {
|
||||
if (ImGui::VSliderInt("##Min", ImVec2(40, 160), &gameDurMin, 1, 10)) {
|
||||
m_Client->GetServer()->GetGame().GetServerDuration().m_GameDuration = (gameDurMin * 60 + gameDurSec) * 1000;
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
@@ -75,7 +112,7 @@ void ServerGui::Render() {
|
||||
ImGui::Text("%s", sec.c_str());
|
||||
ImGui::SameLine();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, 40);
|
||||
if (ImGui::VSliderInt("##int2", ImVec2(40, 160), &gameDurSec, 0, 59)) {
|
||||
if (ImGui::VSliderInt("##Sec", ImVec2(40, 160), &gameDurSec, 0, 59)) {
|
||||
m_Client->GetServer()->GetGame().GetServerDuration().m_GameDuration = (gameDurMin * 60 + gameDurSec) * 1000;
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
@@ -23,7 +23,7 @@ BulletRenderer::BulletRenderer(const Camera& camera) : m_Camera(camera) {
|
||||
|
||||
BulletRenderer::~BulletRenderer() {}
|
||||
|
||||
void BulletRenderer::AddBullet(const Vec3f& origin, float yaw, float pitch) {
|
||||
void BulletRenderer::AddBullet(const Vec3f& origin, float yaw, float pitch, bool firstPersson) {
|
||||
static const float TRAIL_LENGHT = 50;
|
||||
|
||||
Vec3f direction = {
|
||||
@@ -34,8 +34,17 @@ void BulletRenderer::AddBullet(const Vec3f& origin, float yaw, float pitch) {
|
||||
|
||||
Vec3f middle = origin + direction * (TRAIL_LENGHT / 2.0f);
|
||||
|
||||
Mat4f rotate = maths::Dot(maths::RotateX(-pitch), maths::RotateY(yaw + maths::PI / 2));
|
||||
Mat4f scale = maths::Scale({0.01, 0.01, TRAIL_LENGHT / 2.0f - 0.2f});
|
||||
static const float RotateXClient = 0.0008f;
|
||||
static const float RotateYClient = 0.0025f;
|
||||
static const float TrailCutClient = 0.4f;
|
||||
|
||||
float rotateX = firstPersson ? RotateXClient : 0.0f;
|
||||
float rotateY = firstPersson ? RotateYClient : 0.0f;
|
||||
float trailCut = firstPersson ? TrailCutClient : 0.2f;
|
||||
|
||||
|
||||
Mat4f rotate = maths::Dot(maths::RotateX(-pitch - rotateX), maths::RotateY(yaw + maths::PI / 2 - rotateY));
|
||||
Mat4f scale = maths::Scale({0.01f, 0.01f, TRAIL_LENGHT / 2.0f - trailCut});
|
||||
Mat4f translate = maths::Translate(middle);
|
||||
|
||||
Mat4f transform = maths::Dot(scale, maths::Dot(rotate, translate));
|
||||
|
||||
@@ -106,12 +106,18 @@ void MainRenderer::RenderPlayers() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainRenderer::OnGameConfigUpdate() {
|
||||
// we need to do that in order to prevent the animation from glitching
|
||||
m_ShootTime = 0.0f;
|
||||
}
|
||||
|
||||
void MainRenderer::OnLocalPlayerShoot(const Vec3f& position, float yaw, float pitch) {
|
||||
m_ShootTime = 1.0f;
|
||||
m_ShootTime = 60.0f / static_cast<float>(m_Client->GetGame()->GetGameConfig().FiringRate);
|
||||
}
|
||||
|
||||
void MainRenderer::OnPlayerShoot(game::PlayerID player, const Vec3f& position, float yaw, float pitch) {
|
||||
m_BulletRenderer.AddBullet(position + Vec3f{0.0f, Camera::GetPlayerEyeHeight(), 0.0f}, yaw, pitch);
|
||||
m_BulletRenderer.AddBullet(
|
||||
position + Vec3f{0.0f, Camera::GetPlayerEyeHeight(), 0.0f}, yaw, pitch, player == m_Client->GetPlayerID());
|
||||
}
|
||||
|
||||
void MainRenderer::RenderGun() {
|
||||
@@ -120,7 +126,7 @@ void MainRenderer::RenderGun() {
|
||||
|
||||
m_GunShader->Start();
|
||||
|
||||
float progression = 1.0f - m_ShootTime;
|
||||
float progression = 1.0f - (m_ShootTime / static_cast<float>(60.0f / m_Client->GetGame()->GetGameConfig().FiringRate));
|
||||
|
||||
float angle = progression * progression * progression * 7 - progression * progression * 11 + progression * 4;
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ void Server::Accept() {
|
||||
if (m_Listener.Accept(newSocket)) {
|
||||
game::PlayerID newPlayerID = GetNewPlayerID();
|
||||
auto con = std::make_unique<ServerConnexion>(this, newSocket, newPlayerID);
|
||||
m_Connections.insert(std::move(ConnexionMap::value_type{newPlayerID, std::move(con)}));
|
||||
m_Connections.insert(ConnexionMap::value_type{newPlayerID, std::move(con)});
|
||||
m_Connections[newPlayerID]->Start();
|
||||
newPlayerID++;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "blitz/protocol/packets/PlayerLoginPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerPositionAndRotationPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerShootPacket.h"
|
||||
#include "blitz/protocol/packets/ServerConfigPacket.h"
|
||||
#include "blitz/protocol/packets/UpdateGameStatePacket.h"
|
||||
#include "client/gui/ColorFulText.h"
|
||||
#include "server/Server.h"
|
||||
@@ -96,6 +97,7 @@ void ServerConnexion::HandlePacket(const protocol::PlayerLoginPacket* packet) {
|
||||
|
||||
SendPlayers();
|
||||
SendGameState();
|
||||
SendServerConfig();
|
||||
|
||||
m_Server->GetGame().AddPlayer(m_ID, packet->GetPlayerName());
|
||||
|
||||
@@ -161,6 +163,11 @@ void ServerConnexion::SendPlayers() {
|
||||
SendPacket(&packet);
|
||||
}
|
||||
|
||||
void ServerConnexion::SendServerConfig() {
|
||||
protocol::ServerConfigPacket packet(m_Server->GetGame().GetGameConfig());
|
||||
SendPacket(&packet);
|
||||
}
|
||||
|
||||
void ServerConnexion::InitConnection() {
|
||||
protocol::ConnexionInfoPacket conPacket(m_ID);
|
||||
SendPacket(&conPacket);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "blitz/protocol/packets/PlayerJoinPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerPositionAndRotationPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerStatsPacket.h"
|
||||
#include "blitz/protocol/packets/ServerConfigPacket.h"
|
||||
#include "blitz/protocol/packets/UpdateGameStatePacket.h"
|
||||
#include "blitz/protocol/packets/UpdateHealthPacket.h"
|
||||
#include "server/Server.h"
|
||||
@@ -176,5 +177,11 @@ void ServerGame::SetGameState(game::GameState gameState, std::uint64_t duration)
|
||||
m_Server->BroadcastPacket(&packet);
|
||||
}
|
||||
|
||||
void ServerGame::SendServerConfig() {
|
||||
protocol::ServerConfigPacket packet(m_Config);
|
||||
m_Server->BroadcastPacket(&packet);
|
||||
}
|
||||
|
||||
|
||||
} // namespace server
|
||||
} // namespace blitz
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
includes("Blitz.lua")
|
||||
|
||||
-- This should be temporary
|
||||
opengl = "glbinding"
|
||||
if is_plat("linux") and is_arch("arm64-v8a") then
|
||||
opengl = "glew"
|
||||
add_defines("BLITZ_GL_LOADER_GLEW")
|
||||
end
|
||||
|
||||
add_requires("libsdl 2.28.3", {configs = {sdlmain = false}})
|
||||
add_requires("glew", "assimp", "nlohmann_json")
|
||||
add_requires(opengl, "assimp 5.3.1", "nlohmann_json")
|
||||
|
||||
|
||||
-- Client binary (default)
|
||||
target("BlitzClient")
|
||||
@@ -18,7 +26,7 @@ target("BlitzClient")
|
||||
|
||||
-- Libraries
|
||||
add_deps("Blitz")
|
||||
add_packages("libsdl", "glew", "assimp", "nlohmann_json")
|
||||
add_packages("libsdl", opengl, "assimp", "nlohmann_json")
|
||||
|
||||
add_includedirs("../libs", "../libs/imgui")
|
||||
add_files("../libs/imgui/**.cpp")
|
||||
|
||||
Reference in New Issue
Block a user