Compare commits
6 Commits
upgrade
...
alpha-0.3.
| Author | SHA1 | Date | |
|---|---|---|---|
| 8949c37891 | |||
| 019174128c | |||
| 4e8b095e31 | |||
| 0e0368cada | |||
|
|
6e0923ac75 | ||
|
|
bba9ef8219 |
52
include/Defines.h
Normal file
52
include/Defines.h
Normal 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
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Defines.h"
|
||||||
#include "Towers.h"
|
#include "Towers.h"
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
#include "Team.h"
|
#include "Team.h"
|
||||||
@@ -9,8 +10,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
|
|
||||||
@@ -48,13 +47,13 @@ class MobStats {
|
|||||||
private:
|
private:
|
||||||
float m_Damage;
|
float m_Damage;
|
||||||
float m_Speed;
|
float m_Speed;
|
||||||
glm::vec2 m_Size;
|
Vec2f m_Size;
|
||||||
std::uint16_t m_MoneyCost;
|
std::uint16_t m_MoneyCost;
|
||||||
std::uint16_t m_ExpCost;
|
std::uint16_t m_ExpCost;
|
||||||
std::uint16_t m_MaxLife;
|
std::uint16_t m_MaxLife;
|
||||||
std::uint16_t m_ExpReward;
|
std::uint16_t m_ExpReward;
|
||||||
public:
|
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 expCost, std::uint16_t expReward,
|
||||||
std::uint16_t maxLife) : m_Damage(damage), m_Speed(speed),
|
std::uint16_t maxLife) : m_Damage(damage), m_Speed(speed),
|
||||||
m_Size(size), m_MoneyCost(moneyCost), m_ExpCost(expCost),
|
m_Size(size), m_MoneyCost(moneyCost), m_ExpCost(expCost),
|
||||||
@@ -63,7 +62,7 @@ public:
|
|||||||
|
|
||||||
float GetDamage() const { return m_Damage; }
|
float GetDamage() const { return m_Damage; }
|
||||||
float GetMovementSpeed() const { return m_Speed; }
|
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 GetMoneyCost() const { return m_MoneyCost; }
|
||||||
std::uint16_t GetExpCost() const { return m_ExpCost; }
|
std::uint16_t GetExpCost() const { return m_ExpCost; }
|
||||||
std::uint16_t GetExpReward() const { return m_ExpReward; }
|
std::uint16_t GetExpReward() const { return m_ExpReward; }
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#include "Mobs.h"
|
#include "Mobs.h"
|
||||||
@@ -196,10 +195,10 @@ public:
|
|||||||
return m_TilePalette.at(index - 1);
|
return m_TilePalette.at(index - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CanPlaceLittleTower(const glm::vec2& worldPos, PlayerID player) const;
|
bool CanPlaceLittleTower(const Vec2f& worldPos, PlayerID player) const;
|
||||||
bool CanPlaceBigTower(const glm::vec2& 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; }
|
const std::unordered_map<ChunkCoord, ChunkPtr>& GetChunks() const { return m_Chunks; }
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
|
|
||||||
void SelectTeam(game::TeamColor team);
|
void SelectTeam(game::TeamColor team);
|
||||||
void SendMobs(const std::vector<protocol::MobSend>& mobSends);
|
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 UpgradeTower(game::TowerID tower, game::TowerLevel level);
|
||||||
void RemoveTower(game::TowerID tower);
|
void RemoveTower(game::TowerID tower);
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include "Defines.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "loader/GLLoader.h"
|
#include "loader/GLLoader.h"
|
||||||
#include "render/shaders/WorldShader.h"
|
#include "render/shaders/WorldShader.h"
|
||||||
@@ -15,17 +15,17 @@ public:
|
|||||||
|
|
||||||
struct Model {
|
struct Model {
|
||||||
GL::VertexArray* vao;
|
GL::VertexArray* vao;
|
||||||
glm::vec2 positon;
|
Vec2f positon;
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<shader::WorldShader> m_WorldShader;
|
std::unique_ptr<shader::WorldShader> m_WorldShader;
|
||||||
std::unique_ptr<shader::EntityShader> m_EntityShader;
|
std::unique_ptr<shader::EntityShader> m_EntityShader;
|
||||||
|
|
||||||
glm::vec3 m_BackgroundColor;
|
Vec3f m_BackgroundColor;
|
||||||
|
|
||||||
bool m_IsometricView = true;
|
bool m_IsometricView = true;
|
||||||
float m_IsometricShade = m_IsometricView;
|
float m_IsometricShade = m_IsometricView;
|
||||||
glm::vec2 m_CamPos{};
|
Vec2f m_CamPos{};
|
||||||
public:
|
public:
|
||||||
Renderer();
|
Renderer();
|
||||||
~Renderer();
|
~Renderer();
|
||||||
@@ -39,13 +39,13 @@ public:
|
|||||||
void RenderModel(const Model& model);
|
void RenderModel(const Model& model);
|
||||||
|
|
||||||
void SetZoom(float zoom);
|
void SetZoom(float zoom);
|
||||||
void SetCamMovement(const glm::vec2& mov);
|
void SetCamMovement(const Vec2f& mov);
|
||||||
void SetCamPos(const glm::vec2& newPos);
|
void SetCamPos(const Vec2f& newPos);
|
||||||
void SetIsometricView(bool isometric); // false = 2D true = Isometric
|
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:
|
private:
|
||||||
void UpdateIsometricView();
|
void UpdateIsometricView();
|
||||||
void UpdateIsometricFade();
|
void UpdateIsometricFade();
|
||||||
|
|||||||
@@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
#include "render/gui/imgui/imgui.h"
|
#include "render/gui/imgui/imgui.h"
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
namespace client {
|
namespace client {
|
||||||
@@ -30,10 +28,10 @@ private:
|
|||||||
Renderer* m_Renderer;
|
Renderer* m_Renderer;
|
||||||
game::World* m_World;
|
game::World* m_World;
|
||||||
std::unique_ptr<GL::VertexArray> m_WorldVao, m_MobVao, m_SelectTileVao;
|
std::unique_ptr<GL::VertexArray> m_WorldVao, m_MobVao, m_SelectTileVao;
|
||||||
glm::vec2 m_CamPos;
|
Vec2f m_CamPos;
|
||||||
glm::vec2 m_CursorPos;
|
Vec2f m_CursorPos;
|
||||||
glm::vec2 m_HoldCursorPos;
|
Vec2f m_HoldCursorPos;
|
||||||
glm::vec2 m_LastClicked;
|
Vec2f m_LastClicked;
|
||||||
float m_Zoom;
|
float m_Zoom;
|
||||||
float m_CamSensibility = 1;
|
float m_CamSensibility = 1;
|
||||||
bool m_PopupOpened = false;
|
bool m_PopupOpened = false;
|
||||||
@@ -77,8 +75,8 @@ private:
|
|||||||
void DetectCastleHovering() const;
|
void DetectCastleHovering() const;
|
||||||
void RenderTooltips() const;
|
void RenderTooltips() const;
|
||||||
void RemoveTower();
|
void RemoveTower();
|
||||||
glm::vec2 GetCursorWorldPos() const;
|
Vec2f GetCursorWorldPos() const;
|
||||||
glm::vec2 GetClickWorldPos() const;
|
Vec2f GetClickWorldPos() const;
|
||||||
|
|
||||||
void UpdateCursorPos();
|
void UpdateCursorPos();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,20 +2,20 @@
|
|||||||
|
|
||||||
#include "GuiWidget.h"
|
#include "GuiWidget.h"
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include "Defines.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace gui {
|
namespace gui {
|
||||||
|
|
||||||
class TowerPlacePopup : public GuiWidget {
|
class TowerPlacePopup : public GuiWidget {
|
||||||
private:
|
private:
|
||||||
glm::vec2 m_ClickWorldPos;
|
Vec2f m_ClickWorldPos;
|
||||||
public:
|
public:
|
||||||
TowerPlacePopup(client::Client* client);
|
TowerPlacePopup(client::Client* client);
|
||||||
|
|
||||||
virtual void Render();
|
virtual void Render();
|
||||||
|
|
||||||
void SetClickPos(const glm::vec2& worldPos);
|
void SetClickPos(const Vec2f& worldPos);
|
||||||
private:
|
private:
|
||||||
static constexpr float m_TowerPopupTileWidth = 200.0f;
|
static constexpr float m_TowerPopupTileWidth = 200.0f;
|
||||||
static constexpr float m_TowerPopupTileHeight = 200.0f;
|
static constexpr float m_TowerPopupTileHeight = 200.0f;
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ public:
|
|||||||
EntityShader();
|
EntityShader();
|
||||||
|
|
||||||
void LoadShader();
|
void LoadShader();
|
||||||
void SetCamPos(const glm::vec2& camPos);
|
void SetCamPos(const Vec2f& camPos);
|
||||||
void SetZoom(float zoom);
|
void SetZoom(float zoom);
|
||||||
void SetAspectRatio(float aspectRatio);
|
void SetAspectRatio(float aspectRatio);
|
||||||
void SetModelPos(const glm::vec2& modelPos);
|
void SetModelPos(const Vec2f& modelPos);
|
||||||
void SetIsometricView(float isometric);
|
void SetIsometricView(float isometric);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <glm/glm.hpp>
|
#include "Defines.h"
|
||||||
#include "render/GL.h"
|
#include "render/GL.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
@@ -24,11 +24,9 @@ protected:
|
|||||||
|
|
||||||
void LoadFloat(unsigned int location, float value) const;
|
void LoadFloat(unsigned int location, float value) const;
|
||||||
void LoadInt(unsigned int location, int 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 Vec2f& vector) const;
|
||||||
void LoadVector(unsigned int location, const glm::vec3& vector) const;
|
void LoadVector(unsigned int location, const Vec3f& vector) const;
|
||||||
void LoadVector(unsigned int location, const glm::vec4& vector) const;
|
|
||||||
void LoadBoolean(unsigned int location, bool value) const;
|
void LoadBoolean(unsigned int location, bool value) const;
|
||||||
void LoadMatrix(unsigned int location, const glm::mat4& matrix) const;
|
|
||||||
void CleanUp() const;
|
void CleanUp() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ protected:
|
|||||||
public:
|
public:
|
||||||
WorldShader();
|
WorldShader();
|
||||||
void LoadShader();
|
void LoadShader();
|
||||||
void SetCamPos(const glm::vec2& camPos);
|
void SetCamPos(const Vec2f& camPos);
|
||||||
void SetZoom(float zoom);
|
void SetZoom(float zoom);
|
||||||
void SetAspectRatio(float aspectRatio);
|
void SetAspectRatio(float aspectRatio);
|
||||||
void SetIsometricView(float isometric);
|
void SetIsometricView(float isometric);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "misc/DataBuffer.h"
|
#include "misc/DataBuffer.h"
|
||||||
|
|
||||||
#define TD_VERSION "alpha-0.2.0"
|
#define TD_VERSION "alpha-0.3.0"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ const Color* World::GetTileColor(TilePtr tile) const {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::CanPlaceLittleTower(const glm::vec2& worldPos, PlayerID playerID) const {
|
bool World::CanPlaceLittleTower(const Vec2f& worldPos, PlayerID playerID) const {
|
||||||
TilePtr tile = GetTile(worldPos.x, worldPos.y);
|
TilePtr tile = GetTile(worldPos.x, worldPos.y);
|
||||||
const Player& player = m_Game->GetPlayers()[playerID];
|
const Player& player = m_Game->GetPlayers()[playerID];
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ bool World::CanPlaceLittleTower(const glm::vec2& worldPos, PlayerID playerID) co
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::CanPlaceBigTower(const glm::vec2& worldPos, PlayerID playerID) const {
|
bool World::CanPlaceBigTower(const Vec2f& worldPos, PlayerID playerID) const {
|
||||||
if (!CanPlaceLittleTower(worldPos, playerID)) return false;
|
if (!CanPlaceLittleTower(worldPos, playerID)) return false;
|
||||||
|
|
||||||
TilePtr tile = GetTile(worldPos.x, worldPos.y);
|
TilePtr tile = GetTile(worldPos.x, worldPos.y);
|
||||||
@@ -224,7 +224,7 @@ void World::CleanDeadMobs() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TowerPtr World::GetTower(const glm::vec2& position) const {
|
TowerPtr World::GetTower(const Vec2f& position) const {
|
||||||
for (TowerPtr tower : m_Towers) {
|
for (TowerPtr tower : m_Towers) {
|
||||||
if (tower->GetSize() == TowerSize::Big) {
|
if (tower->GetSize() == TowerSize::Big) {
|
||||||
if (tower->GetCenterX() - 2.5f < position.x && tower->GetCenterX() + 2.5f > position.x &&
|
if (tower->GetCenterX() - 2.5f < position.x && tower->GetCenterX() + 2.5f > position.x &&
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ void Client::SendMobs(const std::vector<protocol::MobSend>& mobSends) {
|
|||||||
m_Connexion.SendPacket(&packet);
|
m_Connexion.SendPacket(&packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::PlaceTower(game::TowerType type, const glm::vec2& position) {
|
void Client::PlaceTower(game::TowerType type, const Vec2f& position) {
|
||||||
protocol::PlaceTowerPacket packet(position.x, position.y, type);
|
protocol::PlaceTowerPacket packet(position.x, position.y, type);
|
||||||
m_Connexion.SendPacket(&packet);
|
m_Connexion.SendPacket(&packet);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,11 +151,13 @@ void ServerConnexion::HandlePacket(const protocol::PlaceTowerPacket* packet) {
|
|||||||
const game::TowerInfo& towerInfo = game::GetTowerInfo(towerType);
|
const game::TowerInfo& towerInfo = game::GetTowerInfo(towerType);
|
||||||
server::ServerWorld* world = m_Server->GetGame().GetServerWorld();
|
server::ServerWorld* world = m_Server->GetGame().GetServerWorld();
|
||||||
|
|
||||||
if (!world->CanPlaceLittleTower({ packet->GetTowerX(), packet->GetTowerY() }, m_ID))
|
Vec2f towerPos = { static_cast<float>(packet->GetTowerX()), static_cast<float>(packet->GetTowerY()) };
|
||||||
|
|
||||||
|
if (!world->CanPlaceLittleTower(towerPos, m_ID))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (towerInfo.IsBigTower())
|
if (towerInfo.IsBigTower())
|
||||||
if (!world->CanPlaceBigTower({ packet->GetTowerX(), packet->GetTowerY() }, m_ID))
|
if (!world->CanPlaceBigTower(towerPos, m_ID))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
game::TowerPtr tower = world->PlaceTowerAt(towerType, packet->GetTowerX(), packet->GetTowerY(), m_ID);
|
game::TowerPtr tower = world->PlaceTowerAt(towerType, packet->GetTowerX(), packet->GetTowerY(), m_ID);
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ namespace td {
|
|||||||
namespace utils {
|
namespace utils {
|
||||||
|
|
||||||
std::uint64_t Inflate(const std::string& source, std::string& dest) {
|
std::uint64_t Inflate(const std::string& source, std::string& dest) {
|
||||||
std::size_t size;
|
uLongf size = dest.size();
|
||||||
uncompress(reinterpret_cast<Bytef*>(dest.data()), reinterpret_cast<uLongf*>(&size), reinterpret_cast<const Bytef*>(source.c_str()), source.length());
|
uncompress(reinterpret_cast<Bytef*>(dest.data()), reinterpret_cast<uLongf*>(&size), reinterpret_cast<const Bytef*>(source.c_str()), source.length());
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t Deflate(const std::string& source, std::string& dest) {
|
std::uint64_t Deflate(const std::string& source, std::string& dest) {
|
||||||
std::size_t size;
|
uLongf size = source.length();
|
||||||
dest.resize(source.size()); // Resize for the compressed data to fit into
|
dest.resize(source.size()); // Resize for the compressed data to fit into
|
||||||
compress(reinterpret_cast<Bytef*>(dest.data()), reinterpret_cast<uLongf*>(&size), reinterpret_cast<const Bytef*>(source.c_str()), source.length());
|
compress(reinterpret_cast<Bytef*>(dest.data()), reinterpret_cast<uLongf*>(&size), reinterpret_cast<const Bytef*>(source.c_str()), source.length());
|
||||||
dest.resize(size); // Resize to cut useless data
|
dest.resize(size); // Resize to cut useless data
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ void Renderer::InitShaders() {
|
|||||||
UpdateIsometricView();
|
UpdateIsometricView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO : change loader check
|
||||||
|
|
||||||
bool Renderer::Init() {
|
bool Renderer::Init() {
|
||||||
#if __has_include(<glbinding/glbinding.h>)
|
#if __has_include(<glbinding/glbinding.h>)
|
||||||
glbinding::initialize();
|
glbinding::initialize();
|
||||||
@@ -110,13 +112,13 @@ void Renderer::SetZoom(float zoom) {
|
|||||||
m_EntityShader->SetZoom(zoom);
|
m_EntityShader->SetZoom(zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetCamMovement(const glm::vec2& mov) {
|
void Renderer::SetCamMovement(const Vec2f& mov) {
|
||||||
m_CamPos.x += mov.x * (1 - m_IsometricView) + (0.5 * mov.x - mov.y) * m_IsometricView;
|
m_CamPos.x += mov.x * (1 - m_IsometricView) + (0.5 * mov.x - mov.y) * m_IsometricView;
|
||||||
m_CamPos.y += -mov.y * (1 - m_IsometricView) + (-0.5 * mov.x - mov.y) * m_IsometricView;
|
m_CamPos.y += -mov.y * (1 - m_IsometricView) + (-0.5 * mov.x - mov.y) * m_IsometricView;
|
||||||
SetCamPos(m_CamPos);
|
SetCamPos(m_CamPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetCamPos(const glm::vec2& newPos) {
|
void Renderer::SetCamPos(const Vec2f& newPos) {
|
||||||
m_CamPos = newPos;
|
m_CamPos = newPos;
|
||||||
m_WorldShader->Start();
|
m_WorldShader->Start();
|
||||||
m_WorldShader->SetCamPos(newPos);
|
m_WorldShader->SetCamPos(newPos);
|
||||||
@@ -128,7 +130,7 @@ void Renderer::SetIsometricView(bool isometric) {
|
|||||||
m_IsometricView = isometric;
|
m_IsometricView = isometric;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec2 Renderer::GetCursorWorldPos(const glm::vec2& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight) {
|
Vec2f Renderer::GetCursorWorldPos(const Vec2f& cursorPos, float aspectRatio, float zoom, float windowWidth, float windowHeight) {
|
||||||
float isometricEased = utils::EaseInOutExpo(m_IsometricShade);
|
float isometricEased = utils::EaseInOutExpo(m_IsometricShade);
|
||||||
|
|
||||||
float relativeX = (cursorPos.x / windowWidth * 2) - 1;
|
float relativeX = (cursorPos.x / windowWidth * 2) - 1;
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ void WorldRenderer::Update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WorldRenderer::RemoveTower() {
|
void WorldRenderer::RemoveTower() {
|
||||||
glm::vec2 cursorPos = GetCursorWorldPos();
|
Vec2f cursorPos = GetCursorWorldPos();
|
||||||
|
|
||||||
game::TowerPtr clickedTower = m_World->GetTower(cursorPos);
|
game::TowerPtr clickedTower = m_World->GetTower(cursorPos);
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ void WorldRenderer::RenderTileSelect() const {
|
|||||||
|
|
||||||
Renderer::Model tileSelectModel;
|
Renderer::Model tileSelectModel;
|
||||||
tileSelectModel.vao = m_SelectTileVao.get();
|
tileSelectModel.vao = m_SelectTileVao.get();
|
||||||
tileSelectModel.positon = { (int)m_CursorPos.x, (int)m_CursorPos.y };
|
tileSelectModel.positon = { std::floor(m_CursorPos.x), std::floor(m_CursorPos.y) };
|
||||||
|
|
||||||
m_Renderer->RenderModel(tileSelectModel);
|
m_Renderer->RenderModel(tileSelectModel);
|
||||||
}
|
}
|
||||||
@@ -237,7 +237,7 @@ void WorldRenderer::RenderTowerUpgradePopup() {
|
|||||||
void WorldRenderer::DetectClick() {
|
void WorldRenderer::DetectClick() {
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
if (ImGui::IsMouseReleased(0) && !ImGui::IsAnyItemHovered() && !ImGui::IsAnyItemFocused()) {
|
if (ImGui::IsMouseReleased(0) && !ImGui::IsAnyItemHovered() && !ImGui::IsAnyItemFocused()) {
|
||||||
glm::vec2 cursorPos = { io.MousePos.x, io.MousePos.y };
|
Vec2f cursorPos = { io.MousePos.x, io.MousePos.y };
|
||||||
if (cursorPos == m_HoldCursorPos) {
|
if (cursorPos == m_HoldCursorPos) {
|
||||||
m_LastClicked = m_HoldCursorPos;
|
m_LastClicked = m_HoldCursorPos;
|
||||||
Click();
|
Click();
|
||||||
@@ -260,7 +260,7 @@ void WorldRenderer::RenderCastleTooltip() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WorldRenderer::DetectMobHovering() const {
|
void WorldRenderer::DetectMobHovering() const {
|
||||||
glm::vec2 cursorWorldPos = GetCursorWorldPos();
|
Vec2f cursorWorldPos = GetCursorWorldPos();
|
||||||
for (game::MobPtr mob : m_World->GetMobList()) {
|
for (game::MobPtr mob : m_World->GetMobList()) {
|
||||||
if (mob->CollidesWith({ cursorWorldPos.x, cursorWorldPos.y })) {
|
if (mob->CollidesWith({ cursorWorldPos.x, cursorWorldPos.y })) {
|
||||||
m_MobTooltip->SetMob(mob.get());
|
m_MobTooltip->SetMob(mob.get());
|
||||||
@@ -271,7 +271,7 @@ void WorldRenderer::DetectMobHovering() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WorldRenderer::DetectCastleHovering() const {
|
void WorldRenderer::DetectCastleHovering() const {
|
||||||
glm::vec2 cursorWorldPos = GetCursorWorldPos();
|
Vec2f cursorWorldPos = GetCursorWorldPos();
|
||||||
for (const game::Team& team : m_World->GetTeams()) {
|
for (const game::Team& team : m_World->GetTeams()) {
|
||||||
if (team.GetCastle().CollidesWith({ cursorWorldPos.x, cursorWorldPos.y })) {
|
if (team.GetCastle().CollidesWith({ cursorWorldPos.x, cursorWorldPos.y })) {
|
||||||
m_CastleTooltip->SetCastle(&team.GetCastle());
|
m_CastleTooltip->SetCastle(&team.GetCastle());
|
||||||
@@ -292,12 +292,12 @@ void WorldRenderer::OnTowerRemove(game::TowerPtr tower) {
|
|||||||
m_TowersCache.UpdateVertexArray();
|
m_TowersCache.UpdateVertexArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec2 WorldRenderer::GetCursorWorldPos() const {
|
Vec2f WorldRenderer::GetCursorWorldPos() const {
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
return m_Renderer->GetCursorWorldPos({ io.MousePos.x, io.MousePos.y }, Display::GetAspectRatio(), m_Zoom, Display::GetWindowWidth(), Display::GetWindowHeight());
|
return m_Renderer->GetCursorWorldPos({ io.MousePos.x, io.MousePos.y }, Display::GetAspectRatio(), m_Zoom, Display::GetWindowWidth(), Display::GetWindowHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec2 WorldRenderer::GetClickWorldPos() const {
|
Vec2f WorldRenderer::GetClickWorldPos() const {
|
||||||
return m_Renderer->GetCursorWorldPos(m_LastClicked, Display::GetAspectRatio(), m_Zoom, Display::GetWindowWidth(), Display::GetWindowHeight());
|
return m_Renderer->GetCursorWorldPos(m_LastClicked, Display::GetAspectRatio(), m_Zoom, Display::GetWindowWidth(), Display::GetWindowHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ void TowerPlacePopup::Render() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TowerPlacePopup::SetClickPos(const glm::vec2& worldPos) {
|
void TowerPlacePopup::SetClickPos(const Vec2f& worldPos) {
|
||||||
m_ClickWorldPos = worldPos;
|
m_ClickWorldPos = worldPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ void EntityShader::GetAllUniformLocation() {
|
|||||||
m_LocationViewtype = static_cast<unsigned int>(GetUniformLocation("isometricView"));
|
m_LocationViewtype = static_cast<unsigned int>(GetUniformLocation("isometricView"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityShader::SetCamPos(const glm::vec2& camPos) {
|
void EntityShader::SetCamPos(const Vec2f& camPos) {
|
||||||
LoadVector(m_LocationCam, camPos);
|
LoadVector(m_LocationCam, camPos);
|
||||||
}
|
}
|
||||||
void EntityShader::SetZoom(float zoom) {
|
void EntityShader::SetZoom(float zoom) {
|
||||||
@@ -116,7 +116,7 @@ void EntityShader::SetZoom(float zoom) {
|
|||||||
void EntityShader::SetAspectRatio(float aspectRatio) {
|
void EntityShader::SetAspectRatio(float aspectRatio) {
|
||||||
LoadFloat(m_LocationAspectRatio, aspectRatio);
|
LoadFloat(m_LocationAspectRatio, aspectRatio);
|
||||||
}
|
}
|
||||||
void EntityShader::SetModelPos(const glm::vec2& modelPos) {
|
void EntityShader::SetModelPos(const Vec2f& modelPos) {
|
||||||
LoadVector(m_LocationTranslation, modelPos);
|
LoadVector(m_LocationTranslation, modelPos);
|
||||||
}
|
}
|
||||||
void EntityShader::SetIsometricView(float isometric) {
|
void EntityShader::SetIsometricView(float isometric) {
|
||||||
|
|||||||
@@ -14,8 +14,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -56,28 +54,19 @@ void ShaderProgram::LoadInt(unsigned int location, int value) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ShaderProgram::LoadVector(unsigned int location,
|
void ShaderProgram::LoadVector(unsigned int location,
|
||||||
const glm::vec2& vector) const {
|
const Vec2f& vector) const {
|
||||||
glUniform2f(static_cast<GLint>(location), vector.x, vector.y);
|
glUniform2f(static_cast<GLint>(location), vector.x, vector.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderProgram::LoadVector(unsigned int location,
|
void ShaderProgram::LoadVector(unsigned int location,
|
||||||
const glm::vec3& vector) const {
|
const Vec3f& vector) const {
|
||||||
glUniform3f(static_cast<GLint>(location), vector.x, vector.y, vector.z);
|
glUniform3f(static_cast<GLint>(location), vector.x, vector.y, vector.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderProgram::LoadVector(unsigned int location,
|
|
||||||
const glm::vec4& vector) const {
|
|
||||||
glUniform4f(static_cast<GLint>(location), vector.x, vector.y, vector.z, vector.w);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderProgram::LoadBoolean(unsigned int location, bool value) const {
|
void ShaderProgram::LoadBoolean(unsigned int location, bool value) const {
|
||||||
glUniform1i(static_cast<GLint>(location), value);
|
glUniform1i(static_cast<GLint>(location), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderProgram::LoadMatrix(unsigned int location, const glm::mat4& matrix) const {
|
|
||||||
glUniformMatrix4fv(static_cast<GLint>(location), 1, false, glm::value_ptr(matrix));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShaderProgram::CleanUp() const {
|
void ShaderProgram::CleanUp() const {
|
||||||
Stop();
|
Stop();
|
||||||
glDetachShader(m_ProgramID, m_VertexShaderID);
|
glDetachShader(m_ProgramID, m_VertexShaderID);
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ void WorldShader::GetAllUniformLocation() {
|
|||||||
m_LocationViewtype = static_cast<unsigned int>(GetUniformLocation("isometricView"));
|
m_LocationViewtype = static_cast<unsigned int>(GetUniformLocation("isometricView"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldShader::SetCamPos(const glm::vec2& camPos) {
|
void WorldShader::SetCamPos(const Vec2f& camPos) {
|
||||||
LoadVector(m_LocationCam, camPos);
|
LoadVector(m_LocationCam, camPos);
|
||||||
}
|
}
|
||||||
void WorldShader::SetZoom(float zoom) {
|
void WorldShader::SetZoom(float zoom) {
|
||||||
|
|||||||
11
xmake.lua
11
xmake.lua
@@ -13,7 +13,7 @@ target("TowerDefense")
|
|||||||
|
|
||||||
set_languages("c++17")
|
set_languages("c++17")
|
||||||
|
|
||||||
add_packages("zlib", "libsdl", "glew", "opengl")
|
add_packages("zlib", "libsdl", "glew", "opengl", "glm")
|
||||||
|
|
||||||
if is_os("windows") then
|
if is_os("windows") then
|
||||||
add_links("ws2_32") -- link network stuff
|
add_links("ws2_32") -- link network stuff
|
||||||
@@ -40,3 +40,12 @@ target("TowerDefense")
|
|||||||
add_cxflags("-pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Wno-unused")
|
add_cxflags("-pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Wno-unused")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- run windows program with wine on linux
|
||||||
|
if is_host("linux") and is_os("windows") then
|
||||||
|
on_run(function(target)
|
||||||
|
os.cd("test")
|
||||||
|
os.execv("wine", {target:targetfile()})
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user