restructure project
This commit is contained in:
56
include/client/Client.h
Normal file
56
include/client/Client.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "client/ClientConnexion.h"
|
||||
#include "client/game/ClientGame.h"
|
||||
|
||||
#include "td/game/Team.h"
|
||||
#include "td/game/Player.h"
|
||||
|
||||
#include "td/protocol/Protocol.h"
|
||||
#include "td/protocol/packets/SendMobsPacket.h"
|
||||
|
||||
#include "client/render/Renderer.h"
|
||||
|
||||
#include "td/network/Network.h"
|
||||
|
||||
namespace td {
|
||||
namespace client {
|
||||
|
||||
class Client {
|
||||
private:
|
||||
render::Renderer* m_Renderer;
|
||||
ClientConnexion m_Connexion;
|
||||
std::unique_ptr<ClientGame> m_Game;
|
||||
bool m_Connected;
|
||||
public:
|
||||
Client(render::Renderer* renderer) : m_Renderer(renderer), m_Game(std::make_unique<ClientGame>(this)), m_Connected(false) {}
|
||||
|
||||
const ClientGame& GetGame() const { return *m_Game; }
|
||||
const ClientConnexion& GetConnexion() const { return m_Connexion; }
|
||||
render::Renderer* GetRenderer() const { return m_Renderer; }
|
||||
|
||||
ClientGame& GetGame() { return *m_Game; }
|
||||
ClientConnexion& GetConnexion() { return m_Connexion; }
|
||||
|
||||
const game::Player* GetPlayer() { return m_Game->GetPlayer(); }
|
||||
|
||||
void Tick(std::uint64_t delta);
|
||||
|
||||
void Render();
|
||||
|
||||
bool Connect(const network::IPAddresses& addresses, std::uint16_t port);
|
||||
void CloseConnection();
|
||||
|
||||
bool IsConnected() const { return m_Connexion.GetSocketStatus() == network::Socket::Connected; }
|
||||
|
||||
void SelectTeam(game::TeamColor team);
|
||||
void SendMobs(const std::vector<protocol::MobSend>& mobSends);
|
||||
void PlaceTower(game::TowerType type, const Vec2f& position);
|
||||
void UpgradeTower(game::TowerID tower, game::TowerLevel level);
|
||||
void RemoveTower(game::TowerID tower);
|
||||
private:
|
||||
void Reset();
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
} // namespace td
|
||||
39
include/client/ClientConnexion.h
Normal file
39
include/client/ClientConnexion.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "td/protocol/PacketHandler.h"
|
||||
#include "td/network/TCPSocket.h"
|
||||
#include "td/network/Connexion.h"
|
||||
|
||||
namespace td {
|
||||
namespace client {
|
||||
|
||||
class ClientConnexion : public protocol::Connexion {
|
||||
private:
|
||||
std::uint8_t m_ConnectionID;
|
||||
std::string m_DisconnectReason;
|
||||
float m_ServerTPS;
|
||||
float m_ServerMSPT;
|
||||
int m_Ping = 0;
|
||||
public:
|
||||
ClientConnexion();
|
||||
|
||||
virtual bool UpdateSocket();
|
||||
|
||||
virtual void HandlePacket(const protocol::KeepAlivePacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::DisconnectPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::ServerTpsPacket* packet) override;
|
||||
|
||||
const std::string& GetDisconnectReason() const { return m_DisconnectReason; }
|
||||
float GetServerTPS() const { return m_ServerTPS; }
|
||||
float GetServerMSPT() const { return m_ServerMSPT; }
|
||||
int GetServerPing() const { return m_Ping; }
|
||||
|
||||
REMOVE_COPY(ClientConnexion);
|
||||
private:
|
||||
void RegisterHandlers();
|
||||
void Login();
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
} // namespace td
|
||||
57
include/client/game/ClientGame.h
Normal file
57
include/client/game/ClientGame.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "td/game/BaseGame.h"
|
||||
|
||||
#include "td/protocol/PacketHandler.h"
|
||||
|
||||
#include "WorldClient.h"
|
||||
|
||||
#include "client/render/WorldRenderer.h"
|
||||
#include "client/render/Renderer.h"
|
||||
|
||||
namespace td {
|
||||
namespace client {
|
||||
|
||||
class Client;
|
||||
|
||||
class ClientGame : public protocol::PacketHandler, public game::Game {
|
||||
private:
|
||||
Client* m_Client;
|
||||
std::uint8_t m_ConnexionID;
|
||||
std::uint32_t m_LobbyTime = 0;
|
||||
game::Player* m_Player = nullptr;
|
||||
render::Renderer* m_Renderer;
|
||||
client::WorldClient m_WorldClient;
|
||||
render::WorldRenderer m_WorldRenderer;
|
||||
public:
|
||||
ClientGame(Client* client);
|
||||
virtual ~ClientGame();
|
||||
|
||||
virtual void Tick(std::uint64_t delta);
|
||||
|
||||
void RenderWorld();
|
||||
|
||||
std::uint32_t GetLobbyTime() const { return m_LobbyTime; }
|
||||
const game::Player* GetPlayer() const { return m_Player; }
|
||||
const WorldClient& GetWorld() const { return m_WorldClient; }
|
||||
Client* GetClient() const { return m_Client; }
|
||||
|
||||
render::Renderer* GetRenderer() const { return m_Renderer; }
|
||||
WorldClient& GetWorldClient() { return m_WorldClient; }
|
||||
|
||||
virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::PlayerJoinPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::PlayerLeavePacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::PlayerListPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::UpdatePlayerTeamPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::UpdateGameStatePacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::UpdateLobbyTimePacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::UpdateMoneyPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::UpdateExpPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::DisconnectPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::WorldDataPacket* packet) override;
|
||||
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
} // namespace td
|
||||
29
include/client/game/WorldClient.h
Normal file
29
include/client/game/WorldClient.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "td/game/World.h"
|
||||
#include "td/protocol/PacketHandler.h"
|
||||
|
||||
namespace td {
|
||||
namespace client {
|
||||
|
||||
class ClientGame;
|
||||
|
||||
class WorldClient : public game::World, public protocol::PacketHandler {
|
||||
private:
|
||||
ClientGame* m_Game;
|
||||
public:
|
||||
WorldClient(ClientGame* game);
|
||||
|
||||
virtual void HandlePacket(const protocol::WorldBeginDataPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::WorldDataPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::SpawnMobPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::UpgradeTowerPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::WorldAddTowerPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::RemoveTowerPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::UpdateMobStatesPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::UpdateCastleLifePacket* packet) override;
|
||||
|
||||
};
|
||||
|
||||
} // namespace client
|
||||
} // namespace td
|
||||
62
include/client/render/GL.h
Normal file
62
include/client/render/GL.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#if !defined(TD_IMPL_OPENGL_ES2) \
|
||||
&& !defined(TD_IMPL_OPENGL_ES3) \
|
||||
&& !defined(TD_IMPL_OPENGL_LOADER_GL3W) \
|
||||
&& !defined(TD_IMPL_OPENGL_LOADER_GLEW) \
|
||||
&& !defined(TD_IMPL_OPENGL_LOADER_GLAD) \
|
||||
&& !defined(TD_IMPL_OPENGL_LOADER_GLBINDING2) \
|
||||
&& !defined(TD_IMPL_OPENGL_LOADER_GLBINDING3) \
|
||||
&& !defined(TD_IMPL_OPENGL_LOADER_CUSTOM) \
|
||||
&& !defined(__ANDROID__)
|
||||
|
||||
#if defined(__has_include)
|
||||
|
||||
#if __has_include(<GL/glew.h>)
|
||||
#define TD_IMPL_OPENGL_LOADER_GLEW
|
||||
#elif __has_include(<glad/glad.h>)
|
||||
#define TD_IMPL_OPENGL_LOADER_GLAD
|
||||
#elif __has_include(<GL/gl3w.h>)
|
||||
#define TD_IMPL_OPENGL_LOADER_GL3W
|
||||
#elif __has_include(<glbinding/glbinding.h>)
|
||||
#define TD_IMPL_OPENGL_LOADER_GLBINDING3
|
||||
#elif __has_include(<glbinding/Binding.h>)
|
||||
#define TD_IMPL_OPENGL_LOADER_GLBINDING2
|
||||
#else
|
||||
#error "Cannot detect OpenGL loader!"
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "Cannot detect loader with include detection !"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// Include correct files
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include <GLES3/gl3.h>
|
||||
#elif defined(TD_IMPL_OPENGL_LOADER_GL3W)
|
||||
#include <GL/gl3w.h> // Needs to be initialized with gl3wInit() in user's code
|
||||
#elif defined(TD_IMPL_OPENGL_LOADER_GLEW)
|
||||
#include <GL/glew.h> // Needs to be initialized with glewInit() in user's code.
|
||||
#elif defined(TD_IMPL_OPENGL_LOADER_GLAD)
|
||||
#include <glad/glad.h> // Needs to be initialized with gladLoadGL() in user's code.
|
||||
#elif defined(TD_IMPL_OPENGL_LOADER_GLBINDING2)
|
||||
#ifndef GLFW_INCLUDE_NONE
|
||||
#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors.
|
||||
#endif
|
||||
#include <glbinding/Binding.h> // Needs to be initialized with glbinding::Binding::initialize() in user's code.
|
||||
#include <glbinding/gl/gl.h>
|
||||
using namespace gl;
|
||||
#elif defined(TD_IMPL_OPENGL_LOADER_GLBINDING3)
|
||||
#ifndef GLFW_INCLUDE_NONE
|
||||
#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors.
|
||||
#endif
|
||||
#include <glbinding/glbinding.h>// Needs to be initialized with glbinding::initialize() in user's code.
|
||||
#include <glbinding/gl/gl.h>
|
||||
using namespace gl;
|
||||
#else
|
||||
#include TD_IMPL_OPENGL_LOADER_CUSTOM
|
||||
#endif
|
||||
71
include/client/render/Renderer.h
Normal file
71
include/client/render/Renderer.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
#include "td/Defines.h"
|
||||
#include <memory>
|
||||
#include "loader/GLLoader.h"
|
||||
#include "client/render/shaders/WorldShader.h"
|
||||
#include "client/render/shaders/EntityShader.h"
|
||||
|
||||
namespace td {
|
||||
namespace render {
|
||||
|
||||
struct Camera {
|
||||
Mat4f viewMatrix;
|
||||
Mat4f projectionMatrix;
|
||||
Mat4f InvViewMatrix;
|
||||
Mat4f InvProjectionMatrix;
|
||||
|
||||
float CamDistance = 25.0f;
|
||||
Vec3f CamPos {0, CamDistance, 0};
|
||||
Vec2f CamLook {};
|
||||
|
||||
float m_Yaw = -PI / 2.0f;
|
||||
float m_Pitch = -PI / 2.0f + 0.0000001f;
|
||||
};
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
static constexpr float m_AnimationSpeed = 2.0f;
|
||||
static constexpr float m_MouseSensitivity = 200.0f;
|
||||
|
||||
struct Model {
|
||||
GL::VertexArray* vao;
|
||||
Vec3f positon;
|
||||
Vec3f color = { 1, 1, 1 };
|
||||
};
|
||||
private:
|
||||
std::unique_ptr<shader::WorldShader> m_WorldShader;
|
||||
std::unique_ptr<shader::EntityShader> m_EntityShader;
|
||||
|
||||
Vec2i m_WindowSize;
|
||||
|
||||
Vec3f m_BackgroundColor;
|
||||
|
||||
Camera m_Camera {};
|
||||
public:
|
||||
Renderer();
|
||||
~Renderer();
|
||||
|
||||
bool Init();
|
||||
|
||||
void Prepare();
|
||||
void Resize(const int width, const int height);
|
||||
|
||||
void RenderVAO(const GL::VertexArray& vao);
|
||||
void RenderModel(const Model& model);
|
||||
|
||||
void AddZoom(float zoom);
|
||||
void SetCamAngularMovement(const Vec2f& mov);
|
||||
void SetCamMovement(const Vec2f& lastCursorPos, const Vec2f& currentCursorPos);
|
||||
void SetCamLook(const Vec2f& worldPos);
|
||||
|
||||
void SetBackgroundColor(const Vec3f& color) { m_BackgroundColor = color; }
|
||||
|
||||
Vec2f GetCursorWorldPos(const Vec2f& cursorPos, float windowWidth, float windowHeight);
|
||||
private:
|
||||
void InitShaders();
|
||||
void SetCamPos(const Vec3f& newPos);
|
||||
};
|
||||
|
||||
} // namespace render
|
||||
} // namespace td
|
||||
38
include/client/render/VertexCache.h
Normal file
38
include/client/render/VertexCache.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <unordered_map>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include "client/render/loader/GLLoader.h"
|
||||
|
||||
|
||||
namespace td {
|
||||
namespace render {
|
||||
|
||||
|
||||
class VertexCache {
|
||||
|
||||
typedef std::vector<float> Vector;
|
||||
|
||||
struct DataIndex {
|
||||
Vector position;
|
||||
Vector color;
|
||||
};
|
||||
|
||||
private:
|
||||
std::size_t m_VertexCount;
|
||||
std::unordered_map<std::uint64_t, DataIndex> m_Indexes;
|
||||
std::unique_ptr<GL::VertexArray> m_VertexArray;
|
||||
public:
|
||||
VertexCache() : m_VertexCount(0) {}
|
||||
|
||||
void AddData(std::uint64_t index, std::vector<float> positions, std::vector<float> colors);
|
||||
void RemoveData(std::uint64_t index);
|
||||
void Clear();
|
||||
void UpdateVertexArray();
|
||||
|
||||
const GL::VertexArray& GetVertexArray() const { return *m_VertexArray; }
|
||||
bool IsEmpty() const { return m_VertexArray == nullptr; }
|
||||
};
|
||||
|
||||
} // namespace render
|
||||
} // namespace td
|
||||
81
include/client/render/WorldRenderer.h
Normal file
81
include/client/render/WorldRenderer.h
Normal file
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
|
||||
#include "td/game/World.h"
|
||||
|
||||
#include "client/render/Renderer.h"
|
||||
#include "client/render/VertexCache.h"
|
||||
|
||||
#include "client/render/gui/TowerPlacePopup.h"
|
||||
#include "client/render/gui/TowerUpgradePopup.h"
|
||||
#include "client/render/gui/MobTooltip.h"
|
||||
#include "client/render/gui/CastleTooltip.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
namespace client {
|
||||
|
||||
class ClientGame;
|
||||
|
||||
} // namespace client
|
||||
|
||||
namespace render {
|
||||
|
||||
class WorldRenderer : public game::WorldListener {
|
||||
private:
|
||||
client::ClientGame* m_Client;
|
||||
Renderer* m_Renderer;
|
||||
game::World* m_World;
|
||||
std::unique_ptr<GL::VertexArray> m_WorldVao, m_MobVao, m_SelectTileVao;
|
||||
Vec2f m_CamPos;
|
||||
Vec2f m_CursorPos;
|
||||
Vec2f m_HoldCursorPos;
|
||||
Vec2f m_LastClicked;
|
||||
float m_Zoom;
|
||||
float m_CamSensibility = 1;
|
||||
bool m_PopupOpened = false;
|
||||
VertexCache m_TowersCache;
|
||||
|
||||
std::unique_ptr<gui::TowerPlacePopup> m_TowerPlacePopup;
|
||||
std::unique_ptr<gui::TowerUpgradePopup> m_TowerUpgradePopup;
|
||||
std::unique_ptr<gui::MobTooltip> m_MobTooltip;
|
||||
std::unique_ptr<gui::CastleTooltip> m_CastleTooltip;
|
||||
public:
|
||||
WorldRenderer(game::World* world, client::ClientGame* client);
|
||||
~WorldRenderer();
|
||||
|
||||
void LoadModels();
|
||||
|
||||
void Update();
|
||||
void Render();
|
||||
|
||||
void SetCamPos(float camX, float camY);
|
||||
|
||||
void MoveCam(float relativeX, float relativeY);
|
||||
void ChangeZoom(float zoom);
|
||||
|
||||
// WorldListener
|
||||
|
||||
virtual void OnTowerAdd(game::TowerPtr tower);
|
||||
virtual void OnTowerRemove(game::TowerPtr tower);
|
||||
private:
|
||||
void Click();
|
||||
void RenderWorld() const;
|
||||
void RenderTowers() const;
|
||||
void RenderMobs() const;
|
||||
void RenderTileSelect() const;
|
||||
void RenderPopups();
|
||||
void RenderMobTooltip() const;
|
||||
void RenderCastleTooltip() const;
|
||||
void DetectClick();
|
||||
void DetectMobHovering() const;
|
||||
void DetectCastleHovering() const;
|
||||
void RenderTooltips() const;
|
||||
void RemoveTower();
|
||||
Vec2f GetCursorWorldPos() const;
|
||||
Vec2f GetClickWorldPos() const;
|
||||
|
||||
void UpdateCursorPos();
|
||||
};
|
||||
|
||||
} // namespace render
|
||||
} // namespace td
|
||||
28
include/client/render/gui/CastleTooltip.h
Normal file
28
include/client/render/gui/CastleTooltip.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "GuiWidget.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
namespace game {
|
||||
|
||||
class TeamCastle;
|
||||
|
||||
} // namespace game
|
||||
|
||||
namespace gui {
|
||||
|
||||
class CastleTooltip : public GuiWidget {
|
||||
private:
|
||||
const game::TeamCastle* m_Castle;
|
||||
public:
|
||||
CastleTooltip(client::Client* client);
|
||||
|
||||
virtual void Render();
|
||||
|
||||
void SetCastle(const game::TeamCastle* castle) { m_Castle = castle; }
|
||||
bool IsShown() { return m_Castle != nullptr; }
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
20
include/client/render/gui/FrameMenu.h
Normal file
20
include/client/render/gui/FrameMenu.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "GuiWidget.h"
|
||||
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
class FrameMenu : public GuiWidget {
|
||||
private:
|
||||
bool m_VSync;
|
||||
bool m_IsometricView;
|
||||
bool m_ShowDemoWindow;
|
||||
public:
|
||||
FrameMenu(client::Client* client);
|
||||
|
||||
virtual void Render();
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
24
include/client/render/gui/GameMenu.h
Normal file
24
include/client/render/gui/GameMenu.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "SummonMenu.h"
|
||||
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
class GameMenu : public GuiWidget {
|
||||
private:
|
||||
std::unique_ptr<SummonMenu> m_SummonMenu;
|
||||
public:
|
||||
GameMenu(client::Client* client);
|
||||
|
||||
virtual void Render();
|
||||
private:
|
||||
void ShowTPS();
|
||||
void ShowStats();
|
||||
void ShowPlayers();
|
||||
void ShowLobbyProgress();
|
||||
void ShowTeamSelection();
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
29
include/client/render/gui/GuiManager.h
Normal file
29
include/client/render/gui/GuiManager.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "GuiWidget.h"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
class GuiManager {
|
||||
private:
|
||||
std::vector<std::unique_ptr<GuiWidget>> m_Widgets;
|
||||
public:
|
||||
GuiManager() {}
|
||||
|
||||
void RenderWidgets() {
|
||||
for (auto& widget : m_Widgets) {
|
||||
widget->Render();
|
||||
}
|
||||
}
|
||||
|
||||
void AddWidget(std::unique_ptr<GuiWidget>&& widget) {
|
||||
m_Widgets.push_back(std::move(widget));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
23
include/client/render/gui/GuiWidget.h
Normal file
23
include/client/render/gui/GuiWidget.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
namespace td {
|
||||
|
||||
namespace client {
|
||||
class Client;
|
||||
} // namespace client
|
||||
|
||||
namespace gui {
|
||||
|
||||
class GuiWidget {
|
||||
protected:
|
||||
client::Client* m_Client;
|
||||
public:
|
||||
GuiWidget(client::Client* client) : m_Client(client) {}
|
||||
|
||||
client::Client* GetClient() { return m_Client; }
|
||||
|
||||
virtual void Render() = 0;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
13
include/client/render/gui/ImGuiTeamColor.h
Normal file
13
include/client/render/gui/ImGuiTeamColor.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "client/render/gui/imgui/imgui.h"
|
||||
#include "td/game/Team.h"
|
||||
|
||||
namespace td {
|
||||
namespace render {
|
||||
|
||||
ImVec4 GetImGuiTeamColor(game::TeamColor color);
|
||||
|
||||
} // namespace render
|
||||
} // namespace td
|
||||
|
||||
9
include/client/render/gui/LifeProgress.h
Normal file
9
include/client/render/gui/LifeProgress.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
extern void RenderLifeProgress(float progress);
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
37
include/client/render/gui/MainMenu.h
Normal file
37
include/client/render/gui/MainMenu.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "GuiWidget.h"
|
||||
|
||||
#include "imgui/imgui_filebrowser.h"
|
||||
|
||||
#include "server/Server.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
class MainMenu : public GuiWidget {
|
||||
private:
|
||||
bool m_TriedToConnect = false;
|
||||
bool m_TriedToCreate = false;
|
||||
std::string m_ConnectAddress;
|
||||
int m_ConnectPort;
|
||||
int m_ServerPort = 25565;
|
||||
std::string m_WorldFilePath;
|
||||
imgui_addons::ImGuiFileBrowser m_FileDialog;
|
||||
|
||||
std::unique_ptr<server::Server> m_Server;
|
||||
public:
|
||||
MainMenu(client::Client* client);
|
||||
~MainMenu();
|
||||
|
||||
virtual void Render();
|
||||
|
||||
const server::Server* GetServer() const { return m_Server.get(); }
|
||||
private:
|
||||
bool StartServer();
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
28
include/client/render/gui/MobTooltip.h
Normal file
28
include/client/render/gui/MobTooltip.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "GuiWidget.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
namespace game {
|
||||
|
||||
class Mob;
|
||||
|
||||
} // namespace game
|
||||
|
||||
namespace gui {
|
||||
|
||||
class MobTooltip : public GuiWidget {
|
||||
private:
|
||||
const game::Mob* m_Mob;
|
||||
public:
|
||||
MobTooltip(client::Client* client);
|
||||
|
||||
virtual void Render();
|
||||
|
||||
void SetMob(const game::Mob* mob) { m_Mob = mob; }
|
||||
bool IsShown() { return m_Mob != nullptr; }
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
30
include/client/render/gui/SummonMenu.h
Normal file
30
include/client/render/gui/SummonMenu.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "GuiWidget.h"
|
||||
|
||||
#include <array>
|
||||
#include "td/game/Mobs.h"
|
||||
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
class SummonMenu : public GuiWidget {
|
||||
private:
|
||||
bool m_MenuOpened;
|
||||
int m_ImageWidth = 100;
|
||||
float m_Cooldown;
|
||||
float m_LastCooldown;
|
||||
static constexpr int m_MobTypeCount = static_cast<std::size_t>(td::game::MobType::MOB_COUNT);
|
||||
std::array<int, static_cast<std::size_t>(m_MobTypeCount)> m_Values;
|
||||
public:
|
||||
SummonMenu(client::Client* client);
|
||||
|
||||
void SetCooldown(float cooldown);
|
||||
|
||||
virtual void Render();
|
||||
private:
|
||||
void SetSummonMax(int valueIndex);
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
49
include/client/render/gui/TowerGui.h
Normal file
49
include/client/render/gui/TowerGui.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* TowerGUI.h
|
||||
*
|
||||
* Created on: 5 nov. 2020
|
||||
* Author: Persson-dev
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "client/render/gui/GuiManager.h"
|
||||
|
||||
struct SDL_Window;
|
||||
typedef void* SDL_GLContext;
|
||||
|
||||
namespace td {
|
||||
|
||||
namespace client {
|
||||
|
||||
class Client;
|
||||
|
||||
} // namespace client
|
||||
|
||||
namespace render {
|
||||
|
||||
class Renderer;
|
||||
|
||||
class TowerGui {
|
||||
private:
|
||||
SDL_Window* m_Window;
|
||||
SDL_GLContext m_GlContext;
|
||||
td::render::Renderer* m_Renderer;
|
||||
td::gui::GuiManager m_GuiManager;
|
||||
std::unique_ptr<td::client::Client> m_Client;
|
||||
public:
|
||||
TowerGui(SDL_Window* wndow, SDL_GLContext glContext, td::render::Renderer* renderer);
|
||||
~TowerGui();
|
||||
|
||||
void Render();
|
||||
private:
|
||||
void InitWidgets();
|
||||
void Tick();
|
||||
void BeginFrame();
|
||||
void EndFrame();
|
||||
};
|
||||
|
||||
} // namespace render
|
||||
} // namespace td
|
||||
28
include/client/render/gui/TowerPlacePopup.h
Normal file
28
include/client/render/gui/TowerPlacePopup.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "GuiWidget.h"
|
||||
|
||||
#include "td/Defines.h"
|
||||
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
class TowerPlacePopup : public GuiWidget {
|
||||
private:
|
||||
Vec2f m_ClickWorldPos;
|
||||
public:
|
||||
TowerPlacePopup(client::Client* client);
|
||||
|
||||
virtual void Render();
|
||||
|
||||
void SetClickPos(const Vec2f& worldPos);
|
||||
private:
|
||||
static constexpr float m_TowerPopupTileWidth = 200.0f;
|
||||
static constexpr float m_TowerPopupTileHeight = 200.0f;
|
||||
|
||||
static constexpr float m_PlaceTowerButtonWidth = 150.0f;
|
||||
static constexpr float m_PlaceTowerButtonHeight = 35.0f;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
32
include/client/render/gui/TowerUpgradePopup.h
Normal file
32
include/client/render/gui/TowerUpgradePopup.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "GuiWidget.h"
|
||||
|
||||
#include "td/Defines.h"
|
||||
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
class TowerUpgradePopup : public GuiWidget {
|
||||
private:
|
||||
Vec2f m_ClickWorldPos;
|
||||
bool m_ShouldBeClosed;
|
||||
bool m_Opened;
|
||||
public:
|
||||
TowerUpgradePopup(client::Client* client);
|
||||
|
||||
virtual void Render();
|
||||
|
||||
void SetClickPos(const Vec2f& worldPos);
|
||||
|
||||
bool IsPopupOpened();
|
||||
private:
|
||||
static constexpr float m_TowerPopupTileWidth = 200.0f;
|
||||
static constexpr float m_TowerPopupTileHeight = 200.0f;
|
||||
|
||||
static constexpr float m_PlaceTowerButtonWidth = 150.0f;
|
||||
static constexpr float m_PlaceTowerButtonHeight = 35.0f;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
36
include/client/render/gui/UpdateMenu.h
Normal file
36
include/client/render/gui/UpdateMenu.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "GuiWidget.h"
|
||||
|
||||
#include <future>
|
||||
#include <memory>
|
||||
|
||||
namespace td {
|
||||
|
||||
namespace utils {
|
||||
|
||||
class Updater;
|
||||
|
||||
} // namespace utils
|
||||
|
||||
namespace gui {
|
||||
|
||||
class UpdateMenu : public GuiWidget {
|
||||
private:
|
||||
bool m_Opened;
|
||||
std::string m_Error;
|
||||
std::unique_ptr<utils::Updater> m_Updater;
|
||||
std::shared_future<bool> m_UpdateAvailable;
|
||||
public:
|
||||
UpdateMenu(client::Client* client);
|
||||
virtual ~UpdateMenu();
|
||||
|
||||
virtual void Render();
|
||||
private:
|
||||
void CheckUpdates();
|
||||
bool IsUpdateChecked();
|
||||
void RenderErrorPopup();
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
126
include/client/render/gui/imgui/imconfig.h
Executable file
126
include/client/render/gui/imgui/imconfig.h
Executable file
@@ -0,0 +1,126 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// COMPILE-TIME OPTIONS FOR DEAR IMGUI
|
||||
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
|
||||
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
|
||||
//-----------------------------------------------------------------------------
|
||||
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/branch with your modifications to imconfig.h)
|
||||
// B) or add configuration directives in your own file and compile with #define IMGUI_USER_CONFIG "myfilename.h"
|
||||
// If you do so you need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include
|
||||
// the imgui*.cpp files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
|
||||
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
|
||||
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
//---- Define assertion handler. Defaults to calling assert().
|
||||
// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
|
||||
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
|
||||
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
|
||||
|
||||
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
|
||||
// Using dear imgui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
|
||||
//#define IMGUI_API __declspec( dllexport )
|
||||
//#define IMGUI_API __declspec( dllimport )
|
||||
|
||||
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
|
||||
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
|
||||
//---- Disable all of Dear ImGui or don't implement standard windows.
|
||||
// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp.
|
||||
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
|
||||
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended.
|
||||
//#define IMGUI_DISABLE_METRICS_WINDOW // Disable debug/metrics window: ShowMetricsWindow() will be empty.
|
||||
|
||||
//---- Don't implement some functions to reduce linkage requirements.
|
||||
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc.
|
||||
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow.
|
||||
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
|
||||
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
|
||||
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
|
||||
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
|
||||
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
|
||||
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
|
||||
|
||||
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
||||
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
||||
|
||||
//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
|
||||
//#define IMGUI_USE_BGRA_PACKED_COLOR
|
||||
|
||||
//---- Use 32-bit for ImWchar (default is 16-bit) to support full unicode code points.
|
||||
//#define IMGUI_USE_WCHAR32
|
||||
|
||||
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
|
||||
// By default the embedded implementations are declared static and not available outside of imgui cpp files.
|
||||
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
|
||||
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
|
||||
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
||||
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
|
||||
|
||||
//---- Unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined, use the much faster STB sprintf library implementation of vsnprintf instead of the one from the default C library.
|
||||
// Note that stb_sprintf.h is meant to be provided by the user and available in the include path at compile time. Also, the compatibility checks of the arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf.
|
||||
// #define IMGUI_USE_STB_SPRINTF
|
||||
|
||||
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
|
||||
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
|
||||
/*
|
||||
#define IM_VEC2_CLASS_EXTRA \
|
||||
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
|
||||
operator MyVec2() const { return MyVec2(x,y); }
|
||||
|
||||
#define IM_VEC4_CLASS_EXTRA \
|
||||
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
|
||||
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
||||
*/
|
||||
|
||||
//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
|
||||
// Your renderer back-end will need to support it (most example renderer back-ends support both 16/32-bit indices).
|
||||
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
|
||||
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
|
||||
//#define ImDrawIdx unsigned int
|
||||
|
||||
//---- Override ImDrawCallback signature (will need to modify renderer back-ends accordingly)
|
||||
//struct ImDrawList;
|
||||
//struct ImDrawCmd;
|
||||
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
|
||||
//#define ImDrawCallback MyImDrawCallback
|
||||
|
||||
//---- Debug Tools: Macro to break in Debugger
|
||||
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
|
||||
//#define IM_DEBUG_BREAK IM_ASSERT(0)
|
||||
//#define IM_DEBUG_BREAK __debugbreak()
|
||||
|
||||
//---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(),
|
||||
// (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.)
|
||||
// This adds a small runtime cost which is why it is not enabled by default.
|
||||
//#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
|
||||
|
||||
//---- Debug Tools: Enable slower asserts
|
||||
//#define IMGUI_DEBUG_PARANOID
|
||||
|
||||
//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
|
||||
/*
|
||||
namespace ImGui
|
||||
{
|
||||
void MyFunction(const char* name, const MyMatrix44& v);
|
||||
}
|
||||
*/
|
||||
|
||||
#include "client/render/GL.h"
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#define IMGUI_IMPL_OPENGL_LOADER_ES3
|
||||
#elif defined(TD_IMPL_OPENGL_LOADER_GL3W)
|
||||
#define IMGUI_IMPL_OPENGL_LOADER_GL3W
|
||||
#elif defined(TD_IMPL_OPENGL_LOADER_GLEW)
|
||||
#define IMGUI_IMPL_OPENGL_LOADER_GLEW
|
||||
#elif defined(TD_IMPL_OPENGL_LOADER_GLAD)
|
||||
#define IMGUI_IMPL_OPENGL_LOADER_GLAD
|
||||
#elif defined(TD_IMPL_OPENGL_LOADER_GLBINDING2)
|
||||
#define IMGUI_IMPL_OPENGL_LOADER_GLBINDING2
|
||||
#elif defined(TD_IMPL_OPENGL_LOADER_GLBINDING3)
|
||||
#define IMGUI_IMPL_OPENGL_LOADER_GLBINDING3
|
||||
#else
|
||||
#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM
|
||||
#endif
|
||||
2911
include/client/render/gui/imgui/imgui.h
Normal file
2911
include/client/render/gui/imgui/imgui.h
Normal file
File diff suppressed because it is too large
Load Diff
123
include/client/render/gui/imgui/imgui_filebrowser.h
Normal file
123
include/client/render/gui/imgui/imgui_filebrowser.h
Normal file
@@ -0,0 +1,123 @@
|
||||
#ifndef IMGUIFILEBROWSER_H
|
||||
#define IMGUIFILEBROWSER_H
|
||||
|
||||
#include "client/render/gui/imgui/imgui.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace imgui_addons
|
||||
{
|
||||
class ImGuiFileBrowser
|
||||
{
|
||||
public:
|
||||
ImGuiFileBrowser();
|
||||
~ImGuiFileBrowser();
|
||||
|
||||
enum class DialogMode
|
||||
{
|
||||
SELECT, //Select Directory Mode
|
||||
OPEN, //Open File mode
|
||||
SAVE //Save File mode.
|
||||
};
|
||||
|
||||
/* Use this to show an open file dialog. The function takes label for the window,
|
||||
* the size, a DialogMode enum value defining in which mode the dialog should operate and optionally the extensions that are valid for opening.
|
||||
* Note that the select directory mode doesn't need any extensions.
|
||||
*/
|
||||
bool showFileDialog(const std::string& label, const DialogMode mode, const ImVec2& sz_xy = ImVec2(0,0), const std::string& valid_types = "*.*");
|
||||
|
||||
/* Store the opened/saved file name or dir name (incase of selectDirectoryDialog) and the absolute path to the selection
|
||||
* Should only be accessed when above functions return true else may contain garbage.
|
||||
*/
|
||||
std::string selected_fn;
|
||||
std::string selected_path;
|
||||
std::string ext; // Store the saved file extension
|
||||
|
||||
|
||||
private:
|
||||
struct Info
|
||||
{
|
||||
Info(std::string name, bool is_hidden) : name(name), is_hidden(is_hidden)
|
||||
{
|
||||
}
|
||||
std::string name;
|
||||
bool is_hidden;
|
||||
};
|
||||
|
||||
//Enum used as bit flags.
|
||||
enum FilterMode
|
||||
{
|
||||
FilterMode_Files = 0x01,
|
||||
FilterMode_Dirs = 0x02
|
||||
};
|
||||
|
||||
//Helper Functions
|
||||
static std::string wStringToString(const wchar_t* wchar_arr);
|
||||
static bool alphaSortComparator(const Info& a, const Info& b);
|
||||
ImVec2 getButtonSize(std::string button_text);
|
||||
|
||||
/* Helper Functions that render secondary modals
|
||||
* and help in validating file extensions and for filtering, parsing top navigation bar.
|
||||
*/
|
||||
void setValidExtTypes(const std::string& valid_types_string);
|
||||
bool validateFile();
|
||||
void showErrorModal();
|
||||
void showInvalidFileModal();
|
||||
bool showReplaceFileModal();
|
||||
void showHelpMarker(std::string desc);
|
||||
void parsePathTabs(std::string str);
|
||||
void filterFiles(int filter_mode);
|
||||
|
||||
/* Core Functions that render the 4 different regions making up
|
||||
* a simple file dialog
|
||||
*/
|
||||
bool renderNavAndSearchBarRegion();
|
||||
bool renderFileListRegion();
|
||||
bool renderInputTextAndExtRegion();
|
||||
bool renderButtonsAndCheckboxRegion();
|
||||
bool renderInputComboBox();
|
||||
void renderExtBox();
|
||||
|
||||
/* Core Functions that handle navigation and
|
||||
* reading directories/files
|
||||
*/
|
||||
bool readDIR(std::string path);
|
||||
bool onNavigationButtonClick(int idx);
|
||||
bool onDirClick(int idx);
|
||||
|
||||
// Functions that reset state and/or clear file list when reading new directory
|
||||
void clearFileList();
|
||||
void closeDialog();
|
||||
|
||||
#if defined (WIN32) || defined (_WIN32) || defined (__WIN32)
|
||||
bool loadWindowsDrives(); // Helper Function for Windows to load Drive Letters.
|
||||
#endif
|
||||
|
||||
#if defined(unix) || defined(__unix__) || defined(__unix) || defined(__APPLE__)
|
||||
void initCurrentPath(); // Helper function for UNIX based system to load Absolute path using realpath
|
||||
#endif
|
||||
|
||||
ImVec2 min_size, max_size, input_combobox_pos, input_combobox_sz;
|
||||
DialogMode dialog_mode;
|
||||
std::size_t filter_mode, col_items_limit, selected_ext_idx;
|
||||
int selected_idx;
|
||||
float col_width, ext_box_width;
|
||||
bool show_hidden, show_inputbar_combobox, is_dir, is_appearing, filter_dirty, validate_file;
|
||||
char input_fn[256];
|
||||
|
||||
std::vector<std::string> valid_exts;
|
||||
std::vector<std::string> current_dirlist;
|
||||
std::vector<Info> subdirs;
|
||||
std::vector<Info> subfiles;
|
||||
std::string current_path, error_msg, error_title, invfile_modal_id, repfile_modal_id;
|
||||
|
||||
ImGuiTextFilter filter;
|
||||
std::string valid_types;
|
||||
std::vector<const Info*> filtered_dirs; // Note: We don't need to call delete. It's just for storing filtered items from subdirs and subfiles so we don't use PassFilter every frame.
|
||||
std::vector<const Info*> filtered_files;
|
||||
std::vector< std::reference_wrapper<std::string> > inputcb_filter_files;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // IMGUIFILEBROWSER_H
|
||||
74
include/client/render/loader/GLLoader.h
Normal file
74
include/client/render/loader/GLLoader.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* GLLoader.h
|
||||
*
|
||||
* Created on: 4 nov. 2020
|
||||
* Author: simon
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#define REMOVE_COPY(className) \
|
||||
className(const className &) = delete;\
|
||||
className& operator=(const className &) = delete
|
||||
|
||||
|
||||
namespace GL {
|
||||
|
||||
struct VertexAttribPointer {
|
||||
unsigned int m_Index;
|
||||
unsigned int m_Size;
|
||||
unsigned int m_Offset;
|
||||
};
|
||||
|
||||
class VertexBuffer {
|
||||
private:
|
||||
unsigned int m_ID, m_DataStride;
|
||||
std::vector<VertexAttribPointer> m_VertexAttribs;
|
||||
public:
|
||||
REMOVE_COPY(VertexBuffer);
|
||||
|
||||
VertexBuffer(VertexBuffer&& other) {
|
||||
m_VertexAttribs = std::move(other.m_VertexAttribs);
|
||||
m_ID = other.m_ID;
|
||||
m_DataStride = other.m_DataStride;
|
||||
other.m_ID = 0;
|
||||
other.m_DataStride = 0;
|
||||
}
|
||||
|
||||
VertexBuffer(const std::vector<float>& data, unsigned int stride);
|
||||
~VertexBuffer();
|
||||
|
||||
void Bind() const;
|
||||
void Unbind() const;
|
||||
void AddVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset);
|
||||
void BindVertexAttribs() const;
|
||||
};
|
||||
|
||||
class VertexArray {
|
||||
private:
|
||||
unsigned int m_ID, m_VertexCount;
|
||||
std::vector<VertexBuffer> m_VertexBuffers; //use to destroy vbos when become unused
|
||||
public:
|
||||
REMOVE_COPY(VertexArray);
|
||||
|
||||
VertexArray(VertexArray&& other) {
|
||||
m_ID = other.m_ID;
|
||||
m_VertexCount = other.m_VertexCount;
|
||||
m_VertexBuffers = std::move(other.m_VertexBuffers);
|
||||
other.m_VertexCount = 0;
|
||||
other.m_ID = 0;
|
||||
}
|
||||
|
||||
VertexArray(unsigned int vertexCount);
|
||||
~VertexArray();
|
||||
|
||||
unsigned int GetVertexCount() const { return m_VertexCount; }
|
||||
void BindVertexBuffer(VertexBuffer& vbo);
|
||||
void Bind() const;
|
||||
void Unbind() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
18
include/client/render/loader/TextureLoader.h
Normal file
18
include/client/render/loader/TextureLoader.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* TextureLoader.h
|
||||
*
|
||||
* Created on: 15 nov. 2020
|
||||
* Author: simon
|
||||
*/
|
||||
|
||||
#ifndef RENDER_LOADER_TEXTURELOADER_H_
|
||||
#define RENDER_LOADER_TEXTURELOADER_H_
|
||||
|
||||
namespace TextureLoader {
|
||||
|
||||
unsigned int LoadGLTexture(const char* fileName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif /* RENDER_LOADER_TEXTURELOADER_H_ */
|
||||
25
include/client/render/loader/WorldLoader.h
Normal file
25
include/client/render/loader/WorldLoader.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "td/game/World.h"
|
||||
#include "GLLoader.h"
|
||||
|
||||
namespace td {
|
||||
namespace render {
|
||||
|
||||
namespace WorldLoader {
|
||||
|
||||
struct RenderData {
|
||||
std::vector<float> positions;
|
||||
std::vector<float> colors;
|
||||
};
|
||||
|
||||
GL::VertexArray LoadMobModel();
|
||||
GL::VertexArray LoadWorldModel(const td::game::World* world);
|
||||
GL::VertexArray LoadTileSelectModel();
|
||||
RenderData LoadTowerModel(game::TowerPtr tower);
|
||||
|
||||
} // namespace WorldLoader
|
||||
|
||||
|
||||
} // namespace render
|
||||
} // namespace td
|
||||
7559
include/client/render/loader/stb_image.h
Executable file
7559
include/client/render/loader/stb_image.h
Executable file
File diff suppressed because it is too large
Load Diff
28
include/client/render/shaders/EntityShader.h
Normal file
28
include/client/render/shaders/EntityShader.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "ShaderProgram.h"
|
||||
|
||||
namespace td {
|
||||
namespace shader {
|
||||
|
||||
class EntityShader : public ShaderProgram {
|
||||
private:
|
||||
unsigned int m_LocationProjectionMatrix = 0;
|
||||
unsigned int m_LocationViewMatrix = 0;
|
||||
unsigned int m_LocationPosition = 0;
|
||||
unsigned int m_LocationColorEffect = 0;
|
||||
protected:
|
||||
virtual void GetAllUniformLocation();
|
||||
public:
|
||||
EntityShader();
|
||||
|
||||
void LoadShader();
|
||||
|
||||
void SetColorEffect(const Vec3f& color);
|
||||
void SetProjectionMatrix(const Mat4f& proj) const;
|
||||
void SetViewMatrix(const Mat4f& view) const;
|
||||
void SetModelPos(const Vec3f& pos) const;
|
||||
};
|
||||
|
||||
} // namespace shader
|
||||
} // namespace td
|
||||
43
include/client/render/shaders/ShaderProgram.h
Executable file
43
include/client/render/shaders/ShaderProgram.h
Executable file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "td/Defines.h"
|
||||
#include "client/render/GL.h"
|
||||
|
||||
namespace td {
|
||||
namespace shader {
|
||||
|
||||
class ShaderProgram {
|
||||
public:
|
||||
ShaderProgram();
|
||||
virtual ~ShaderProgram();
|
||||
|
||||
void Start() const;
|
||||
void Stop() const;
|
||||
|
||||
void LoadProgramFile(const std::string& vertexFile, const std::string& fragmentFile);
|
||||
void LoadProgram(const std::string& vertexSource, const std::string& fragmentSource);
|
||||
|
||||
protected:
|
||||
virtual void GetAllUniformLocation() = 0;
|
||||
int GetUniformLocation(const std::string& uniformName) const;
|
||||
|
||||
void LoadFloat(unsigned int location, float value) const;
|
||||
void LoadInt(unsigned int location, int value) const;
|
||||
void LoadVector(unsigned int location, const Vec2f& vector) const;
|
||||
void LoadVector(unsigned int location, const Vec3f& vector) const;
|
||||
void LoadBoolean(unsigned int location, bool value) const;
|
||||
void LoadMat4(unsigned int location, const Mat4f& mat) const;
|
||||
void CleanUp() const;
|
||||
|
||||
private:
|
||||
unsigned int m_ProgramID;
|
||||
unsigned int m_VertexShaderID;
|
||||
unsigned int m_FragmentShaderID;
|
||||
|
||||
unsigned int LoadShaderFromFile(const std::string& file, GLenum type);
|
||||
unsigned int LoadShader(const std::string& source, GLenum type);
|
||||
};
|
||||
|
||||
} // namespace shader
|
||||
} // namespace td
|
||||
22
include/client/render/shaders/WorldShader.h
Normal file
22
include/client/render/shaders/WorldShader.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "ShaderProgram.h"
|
||||
|
||||
namespace td {
|
||||
namespace shader {
|
||||
|
||||
class WorldShader : public ShaderProgram {
|
||||
private:
|
||||
unsigned int m_LocationProjection = 0, m_LocationView = 0;
|
||||
protected:
|
||||
void GetAllUniformLocation();
|
||||
public:
|
||||
WorldShader();
|
||||
void LoadShader();
|
||||
|
||||
void SetProjectionMatrix(const Mat4f& proj) const;
|
||||
void SetViewMatrix(const Mat4f& view) const;
|
||||
};
|
||||
|
||||
} // namespace shader
|
||||
} // namespace td
|
||||
44
include/client/updater/Updater.h
Normal file
44
include/client/updater/Updater.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "td/misc/DataBuffer.h"
|
||||
|
||||
#define TD_VERSION "alpha-0.3.0"
|
||||
|
||||
namespace td {
|
||||
namespace utils {
|
||||
|
||||
class Updater {
|
||||
private:
|
||||
float m_Progress;
|
||||
bool m_DownloadComplete;
|
||||
bool m_FileWrited;
|
||||
bool m_CancelDownload;
|
||||
DataBuffer m_FileBuffer;
|
||||
std::string m_LastVersion;
|
||||
public:
|
||||
Updater() : m_Progress(0), m_DownloadComplete(false), m_FileWrited(false), m_CancelDownload(false) {}
|
||||
|
||||
bool CheckUpdate();
|
||||
void DownloadUpdate();
|
||||
void CancelDownload() { m_CancelDownload = true; m_Progress = 0.0f; m_DownloadComplete = false; }
|
||||
bool WriteFile();
|
||||
|
||||
void ClearCache() { m_FileBuffer.Clear(); }
|
||||
|
||||
float GetDownloadProgress() { return m_Progress; }
|
||||
bool IsDownloadComplete() { return m_DownloadComplete; }
|
||||
bool IsFileWrited() { return m_FileWrited; }
|
||||
|
||||
static std::string GetLocalFilePath();
|
||||
static void RemoveOldFile();
|
||||
|
||||
static std::string GetCurrentVersion() { return TD_VERSION; }
|
||||
std::string GetLastVersion() { return m_LastVersion; }
|
||||
|
||||
bool CanUpdate();
|
||||
private:
|
||||
std::string GetDownloadFileURL();
|
||||
};
|
||||
|
||||
} // namespace utils
|
||||
} // namespace td
|
||||
31
include/client/window/Display.h
Normal file
31
include/client/window/Display.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Display.h
|
||||
*
|
||||
* Created on: 4 nov. 2020
|
||||
* Author: simon
|
||||
*/
|
||||
|
||||
#ifndef WINDOW_DISPLAY_H_
|
||||
#define WINDOW_DISPLAY_H_
|
||||
|
||||
|
||||
namespace Display {
|
||||
|
||||
bool Create();
|
||||
void Render();
|
||||
void Update();
|
||||
void Destroy();
|
||||
void PollEvents();
|
||||
|
||||
bool IsCloseRequested();
|
||||
|
||||
bool IsMouseDown(int button);
|
||||
|
||||
float GetAspectRatio();
|
||||
int GetWindowWidth();
|
||||
int GetWindowHeight();
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif /* WINDOW_DISPLAY_H_ */
|
||||
Reference in New Issue
Block a user