diff options
Diffstat (limited to 'game')
-rw-r--r-- | game/geoData.cpp | 11 | ||||
-rw-r--r-- | game/geoData.h | 4 | ||||
-rw-r--r-- | game/network/network.h | 4 | ||||
-rw-r--r-- | game/network/rail.cpp | 22 | ||||
-rw-r--r-- | game/network/rail.h | 3 | ||||
-rw-r--r-- | game/terrain.cpp | 4 | ||||
-rw-r--r-- | game/terrain.h | 3 |
7 files changed, 44 insertions, 7 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp index d15a51b..d8caff7 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -66,6 +66,7 @@ GeoData::loadFromAsciiGrid(const std::filesystem::path & input) }); } } + mesh.generation++; mesh.updateAllVertexNormals(); return mesh; @@ -106,6 +107,7 @@ GeoData::createFlat(GlobalPosition2D lower, GlobalPosition2D upper, GlobalDistan } mesh.updateAllVertexNormals(); + mesh.generation++; return mesh; } @@ -589,7 +591,7 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const auto surfaceStripWalk = [this, &getTriangle, &opts](const auto & surfaceStripWalk, const auto & face) -> void { if (!property(surface, face)) { - property(surface, face) = &opts.surface; + property(surface, face) = opts.surface; std::ranges::for_each( ff_range(face), [this, &getTriangle, &surfaceStripWalk](const auto & adjacentFaceHandle) { if (getTriangle(this->triangle<2>(adjacentFaceHandle).centroid())) { @@ -601,6 +603,13 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const surfaceStripWalk(surfaceStripWalk, findPoint(strip.front().centroid())); updateAllVertexNormals(newOrChangedVerts); + generation++; +} + +size_t +GeoData::getGeneration() const +{ + return generation; } void diff --git a/game/geoData.h b/game/geoData.h index 01582a6..92b9b75 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -78,12 +78,13 @@ public: static constexpr auto DEFAULT_NEAR_NODE_TOLERANACE = 500.F; static constexpr auto DEFAULT_MAX_SLOPE = 0.5F; - const Surface & surface; + const Surface * surface = nullptr; RelativeDistance nearNodeTolerance = DEFAULT_NEAR_NODE_TOLERANACE; RelativeDistance maxSlope = DEFAULT_MAX_SLOPE; }; void setHeights(std::span<const GlobalPosition3D> triangleStrip, const SetHeightsOpts &); + [[nodiscard]] size_t getGeneration() const; [[nodiscard]] auto getExtents() const @@ -128,4 +129,5 @@ protected: private: GlobalPosition3D lowerExtent {}, upperExtent {}; + size_t generation {}; }; diff --git a/game/network/network.h b/game/network/network.h index be0900b..f8739b8 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -14,6 +14,7 @@ #include <utility> class SceneShader; +class Surface; template<typename> class Ray; template<size_t... n> using GenDef = std::tuple<glm::vec<n, GlobalDistance>...>; @@ -47,6 +48,9 @@ public: [[nodiscard]] virtual float findNodeDirection(Node::AnyCPtr) const = 0; + [[nodiscard]] virtual const Surface * getBaseSurface() const = 0; + [[nodiscard]] virtual RelativeDistance getBaseWidth() const = 0; + protected: static void joinLinks(const Link::Ptr & l, const Link::Ptr & ol); static GenCurveDef genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & end, float startDir); diff --git a/game/network/rail.cpp b/game/network/rail.cpp index 69422aa..dc62cf3 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -1,4 +1,6 @@ #include "rail.h" +#include "game/gamestate.h" +#include "game/geoData.h" #include "network.h" #include <game/network/network.impl.h> // IWYU pragma: keep #include <gfx/gl/sceneShader.h> @@ -8,7 +10,7 @@ template class NetworkOf<RailLink, RailLinkStraight, RailLinkCurve>; constexpr auto RAIL_CROSSSECTION_VERTICES {5U}; -constexpr Size3D RAIL_HEIGHT {0, 0, 250.F}; +constexpr Size3D RAIL_HEIGHT {0, 0, 50.F}; RailLinks::RailLinks() : NetworkOf<RailLink, RailLinkStraight, RailLinkCurve> {"rails.jpg"} { } @@ -74,11 +76,11 @@ RailLinks::addLinksBetween(GlobalPosition3D start, GlobalPosition3D end) } constexpr const std::array<RelativePosition3D, RAIL_CROSSSECTION_VERTICES> railCrossSection {{ - {-1900.F, 0.F, 0.F}, + {-1900.F, 0.F, -RAIL_HEIGHT.z * 2}, {-608.F, 0.F, RAIL_HEIGHT.z}, - {0, 0.F, RAIL_HEIGHT.z * .7F}, + {0, 0.F, RAIL_HEIGHT.z / 2}, {608.F, 0.F, RAIL_HEIGHT.z}, - {1900.F, 0.F, 0.F}, + {1900.F, 0.F, -RAIL_HEIGHT.z * 2}, }}; constexpr const std::array<float, RAIL_CROSSSECTION_VERTICES> railTexturePos { 0.F, @@ -169,3 +171,15 @@ RailLinks::render(const SceneShader & shader) const glBindVertexArray(0); } } + +const Surface * +RailLinks::getBaseSurface() const +{ + return std::dynamic_pointer_cast<Surface>(gameState->assets.at("terrain.surface.gravel")).get(); +} + +RelativeDistance +RailLinks::getBaseWidth() const +{ + return 5'700; +} diff --git a/game/network/rail.h b/game/network/rail.h index 0aae718..fa64eda 100644 --- a/game/network/rail.h +++ b/game/network/rail.h @@ -77,6 +77,9 @@ public: std::shared_ptr<RailLink> addLinksBetween(GlobalPosition3D start, GlobalPosition3D end); void render(const SceneShader &) const override; + [[nodiscard]] const Surface * getBaseSurface() const override; + [[nodiscard]] RelativeDistance getBaseWidth() const override; + private: void tick(TickDuration elapsed) override; }; diff --git a/game/terrain.cpp b/game/terrain.cpp index bb8e3ce..e7508d0 100644 --- a/game/terrain.cpp +++ b/game/terrain.cpp @@ -66,6 +66,10 @@ Terrain::generateMeshes() void Terrain::tick(TickDuration) { + if (const auto newGeneration = geoData->getGeneration(); newGeneration != geoGeneration) { + generateMeshes(); + geoGeneration = newGeneration; + } } void diff --git a/game/terrain.h b/game/terrain.h index 7d074cf..c9d09fe 100644 --- a/game/terrain.h +++ b/game/terrain.h @@ -27,10 +27,11 @@ public: RGB colourBias; }; +private: void generateMeshes(); -private: std::shared_ptr<GeoData> geoData; Collection<MeshT<Vertex>, false> meshes; Texture::Ptr grass; + size_t geoGeneration {}; }; |