feat: add basic towers rendering

This commit is contained in:
2021-09-26 18:19:00 +02:00
parent 2ece5bc9b5
commit fe7cfdec72
22 changed files with 230 additions and 58 deletions

View File

@@ -0,0 +1,34 @@
#include <unordered_map>
#include <cstdint>
#include <memory>
#include "render/loader/GLLoader.h"
namespace td {
namespace render {
class VertexCache {
typedef std::vector<float> Vector;
typedef std::pair<Vector::iterator, Vector::iterator> ElementsIndex;
typedef std::pair<ElementsIndex, ElementsIndex> DataIndex;
private:
Vector m_Positions;
Vector m_Colors;
std::unordered_map<std::uint64_t, DataIndex> m_Indexes;
std::unique_ptr<GL::VertexArray> m_VertexArray;
public:
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

View File

@@ -1,8 +1,8 @@
#pragma once
#include "game/World.h"
#include "render/loader/GLLoader.h"
#include "render/Renderer.h"
#include "render/VertexCache.h"
#include <glm/glm.hpp>
@@ -29,12 +29,16 @@ private:
float m_Zoom = 1;
float m_CamSensibility = 1;
bool m_TowerPlacePopupOpened = false;
VertexCache m_TowersCache;
public:
WorldRenderer(game::World* world, client::ClientGame* client);
~WorldRenderer();
void loadModels();
void addTower(game::TowerPtr tower);
void removeTower(game::TowerPtr tower);
void update();
void render();

View File

@@ -8,9 +8,15 @@ 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