feat: add basic towers rendering
This commit is contained in:
34
include/render/VertexCache.h
Normal file
34
include/render/VertexCache.h
Normal 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
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user