summaryrefslogtreecommitdiff
path: root/game/terrain.h
diff options
context:
space:
mode:
Diffstat (limited to 'game/terrain.h')
-rw-r--r--game/terrain.h45
1 files changed, 33 insertions, 12 deletions
diff --git a/game/terrain.h b/game/terrain.h
index 7d074cf..1a63296 100644
--- a/game/terrain.h
+++ b/game/terrain.h
@@ -1,36 +1,57 @@
#pragma once
#include "chronology.h"
-#include "collection.h"
#include "config/types.h"
#include "game/worldobject.h"
-#include "gfx/models/mesh.h"
+#include "geoData.h"
#include "gfx/models/texture.h"
#include "gfx/renderable.h"
-#include <memory>
class SceneShader;
-class GeoData;
-class Terrain : public WorldObject, public Renderable {
+class Terrain : public GeoData, public WorldObject, public Renderable {
public:
- explicit Terrain(std::shared_ptr<GeoData>);
+ template<typename... P> explicit Terrain(P &&... params) : GeoData {std::forward<P>(params)...}
+ {
+ generateMeshes();
+ }
- void render(const SceneShader & shader) const override;
- void shadows(const ShadowMapper &) const override;
+ void render(const SceneShader & shader, const Frustum &) const override;
+ void shadows(const ShadowMapper &, const Frustum &) const override;
void tick(TickDuration) override;
struct Vertex {
GlobalPosition3D pos;
Normal3D normal;
- RGB colourBias;
};
void generateMeshes();
private:
- std::shared_ptr<GeoData> geoData;
- Collection<MeshT<Vertex>, false> meshes;
- Texture::Ptr grass;
+ void afterChange() override;
+
+ struct SurfaceArrayBuffer {
+ glVertexArray vertexArray;
+ glBuffer indicesBuffer;
+ GLsizei count;
+ AxisAlignedBoundingBox<GlobalDistance> aabb;
+ };
+
+ struct SurfaceKey {
+ const Surface * surface;
+ GlobalPosition2D basePosition;
+ inline bool operator<(const SurfaceKey &) const;
+ };
+
+ using SurfaceIndices = std::map<SurfaceKey, std::vector<GLuint>>;
+ void copyVerticesToBuffer() const;
+ [[nodiscard]] SurfaceIndices mapSurfaceFacesToIndices() const;
+ void copyIndicesToBuffers(const SurfaceIndices &);
+ void pruneOrphanMeshes(const SurfaceIndices &);
+ [[nodiscard]] inline GlobalPosition2D getTile(const FaceHandle &) const;
+
+ glBuffer verticesBuffer;
+ std::map<SurfaceKey, SurfaceArrayBuffer> meshes;
+ Texture::Ptr grass = std::make_shared<Texture>("grass.png");
};