remove glm dependency

This commit is contained in:
Simon Pribylski
2022-10-13 12:24:15 +02:00
parent bba9ef8219
commit 6e0923ac75
20 changed files with 110 additions and 71 deletions

52
include/Defines.h Normal file
View File

@@ -0,0 +1,52 @@
#pragma once
namespace td {
template<typename T>
struct Vec2 {
union {
T x;
T r;
};
union {
T y;
T g;
};
Vec2(T X = 0, T Y = 0) : x(X), y(Y) {}
friend bool operator==(const Vec2& vec2, const Vec2& other) { return vec2.x == other.x && vec2.y == other.y; }
};
template<typename T>
struct Vec3 {
union {
T x;
T r;
};
union {
T y;
T g;
};
union {
T z;
T b;
};
Vec3(T X = 0, T Y = 0, T Z = 0) : x(X), y(Y), z(Z) {}
};
using Vec2i = Vec2<int>;
using Vec2u = Vec2<unsigned int>;
using Vec2f = Vec2<float>;
using Vec2d = Vec2<double>;
using Vec3i = Vec3<int>;
using Vec3u = Vec3<unsigned int>;
using Vec3f = Vec3<float>;
using Vec3d = Vec3<double>;
} // namespace td

View File

@@ -1,5 +1,6 @@
#pragma once
#include "Defines.h"
#include "Towers.h"
#include "Types.h"
#include "Team.h"
@@ -9,8 +10,6 @@
#include <vector>
#include <memory>
#include <glm/glm.hpp>
namespace td {
namespace game {
@@ -48,13 +47,13 @@ class MobStats {
private:
float m_Damage;
float m_Speed;
glm::vec2 m_Size;
Vec2f m_Size;
std::uint16_t m_MoneyCost;
std::uint16_t m_ExpCost;
std::uint16_t m_MaxLife;
std::uint16_t m_ExpReward;
public:
MobStats(float damage, float speed, glm::vec2 size, std::uint16_t moneyCost,
MobStats(float damage, float speed, Vec2f size, std::uint16_t moneyCost,
std::uint16_t expCost, std::uint16_t expReward,
std::uint16_t maxLife) : m_Damage(damage), m_Speed(speed),
m_Size(size), m_MoneyCost(moneyCost), m_ExpCost(expCost),
@@ -63,7 +62,7 @@ public:
float GetDamage() const { return m_Damage; }
float GetMovementSpeed() const { return m_Speed; }
const glm::vec2& GetSize() const { return m_Size; }
const Vec2f& GetSize() const { return m_Size; }
std::uint16_t GetMoneyCost() const { return m_MoneyCost; }
std::uint16_t GetExpCost() const { return m_ExpCost; }
std::uint16_t GetExpReward() const { return m_ExpReward; }

View File

@@ -4,7 +4,6 @@
#include <vector>
#include <map>
#include <unordered_map>
#include <glm/glm.hpp>
#include <array>
#include "Mobs.h"
@@ -196,10 +195,10 @@ public:
return m_TilePalette.at(index - 1);
}
bool CanPlaceLittleTower(const glm::vec2& worldPos, PlayerID player) const;
bool CanPlaceBigTower(const glm::vec2& worldPos, PlayerID player) const;
bool CanPlaceLittleTower(const Vec2f& worldPos, PlayerID player) const;
bool CanPlaceBigTower(const Vec2f& worldPos, PlayerID player) const;
TowerPtr GetTower(const glm::vec2& position) const; // returns null if no tower is here
TowerPtr GetTower(const Vec2f& position) const; // returns null if no tower is here
const std::unordered_map<ChunkCoord, ChunkPtr>& GetChunks() const { return m_Chunks; }

View File

@@ -44,7 +44,7 @@ public:
void SelectTeam(game::TeamColor team);
void SendMobs(const std::vector<protocol::MobSend>& mobSends);
void PlaceTower(game::TowerType type, const glm::vec2& position);
void PlaceTower(game::TowerType type, const Vec2f& position);
void UpgradeTower(game::TowerID tower, game::TowerLevel level);
void RemoveTower(game::TowerID tower);
private:

View File

@@ -1,6 +1,6 @@
#pragma once
#include <glm/glm.hpp>
#include "Defines.h"
#include <memory>
#include "loader/GLLoader.h"
#include "render/shaders/WorldShader.h"
@@ -15,17 +15,17 @@ public:
struct Model {
GL::VertexArray* vao;
glm::vec2 positon;
Vec2f positon;
};
private:
std::unique_ptr<shader::WorldShader> m_WorldShader;
std::unique_ptr<shader::EntityShader> m_EntityShader;
glm::vec3 m_BackgroundColor;
Vec3f m_BackgroundColor;
bool m_IsometricView = true;
float m_IsometricShade = m_IsometricView;
glm::vec2 m_CamPos{};
Vec2f m_CamPos{};
public:
Renderer();
~Renderer();
@@ -39,13 +39,13 @@ public:
void RenderModel(const Model& model);
void SetZoom(float zoom);
void SetCamMovement(const glm::vec2& mov);
void SetCamPos(const glm::vec2& newPos);
void SetCamMovement(const Vec2f& mov);
void SetCamPos(const Vec2f& newPos);
void SetIsometricView(bool isometric); // false = 2D true = Isometric
void SetBackgroundColor(const glm::vec3& color) { m_BackgroundColor = color; }
void SetBackgroundColor(const Vec3f& color) { m_BackgroundColor = color; }
glm::vec2 GetCursorWorldPos(const glm::vec2& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight);
Vec2f GetCursorWorldPos(const Vec2f& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight);
private:
void UpdateIsometricView();
void UpdateIsometricFade();

View File

@@ -11,8 +11,6 @@
#include "render/gui/imgui/imgui.h"
#include <glm/glm.hpp>
namespace td {
namespace client {
@@ -30,10 +28,10 @@ private:
Renderer* m_Renderer;
game::World* m_World;
std::unique_ptr<GL::VertexArray> m_WorldVao, m_MobVao, m_SelectTileVao;
glm::vec2 m_CamPos;
glm::vec2 m_CursorPos;
glm::vec2 m_HoldCursorPos;
glm::vec2 m_LastClicked;
Vec2f m_CamPos;
Vec2f m_CursorPos;
Vec2f m_HoldCursorPos;
Vec2f m_LastClicked;
float m_Zoom;
float m_CamSensibility = 1;
bool m_PopupOpened = false;
@@ -77,8 +75,8 @@ private:
void DetectCastleHovering() const;
void RenderTooltips() const;
void RemoveTower();
glm::vec2 GetCursorWorldPos() const;
glm::vec2 GetClickWorldPos() const;
Vec2f GetCursorWorldPos() const;
Vec2f GetClickWorldPos() const;
void UpdateCursorPos();
};

View File

@@ -2,20 +2,20 @@
#include "GuiWidget.h"
#include <glm/glm.hpp>
#include "Defines.h"
namespace td {
namespace gui {
class TowerPlacePopup : public GuiWidget {
private:
glm::vec2 m_ClickWorldPos;
Vec2f m_ClickWorldPos;
public:
TowerPlacePopup(client::Client* client);
virtual void Render();
void SetClickPos(const glm::vec2& worldPos);
void SetClickPos(const Vec2f& worldPos);
private:
static constexpr float m_TowerPopupTileWidth = 200.0f;
static constexpr float m_TowerPopupTileHeight = 200.0f;

View File

@@ -19,10 +19,10 @@ public:
EntityShader();
void LoadShader();
void SetCamPos(const glm::vec2& camPos);
void SetCamPos(const Vec2f& camPos);
void SetZoom(float zoom);
void SetAspectRatio(float aspectRatio);
void SetModelPos(const glm::vec2& modelPos);
void SetModelPos(const Vec2f& modelPos);
void SetIsometricView(float isometric);
};

View File

@@ -1,7 +1,7 @@
#pragma once
#include <string>
#include <glm/glm.hpp>
#include "Defines.h"
#include "render/GL.h"
namespace td {
@@ -24,11 +24,9 @@ protected:
void LoadFloat(unsigned int location, float value) const;
void LoadInt(unsigned int location, int value) const;
void LoadVector(unsigned int location, const glm::vec2& vector) const;
void LoadVector(unsigned int location, const glm::vec3& vector) const;
void LoadVector(unsigned int location, const glm::vec4& vector) 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 LoadMatrix(unsigned int location, const glm::mat4& matrix) const;
void CleanUp() const;
private:

View File

@@ -13,7 +13,7 @@ protected:
public:
WorldShader();
void LoadShader();
void SetCamPos(const glm::vec2& camPos);
void SetCamPos(const Vec2f& camPos);
void SetZoom(float zoom);
void SetAspectRatio(float aspectRatio);
void SetIsometricView(float isometric);