载入中...
搜索中...
未找到
TerrainAsset.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
6#include "common/Result.h"
7
8#include <cstddef>
9#include <cstdint>
10#include <memory>
11#include <span>
12#include <string>
13#include <vector>
14
15namespace eve::procgen {
16
19public:
21 virtual ~ITerrainArchiveSource() = default;
23 [[nodiscard]] virtual std::uint64_t size() const noexcept = 0;
29 [[nodiscard]] virtual Result<std::vector<std::uint8_t>> read(
30 std::uint64_t offset, std::size_t length) const = 0;
31};
32
35public:
37 explicit MemoryTerrainArchiveSource(std::span<const std::uint8_t> bytes)
39 : bytes_(bytes.begin(), bytes.end()) {}
41 [[nodiscard]] std::uint64_t size() const noexcept override { return bytes_.size(); }
44 std::uint64_t offset, std::size_t length) const override;
45
46private:
47 std::vector<std::uint8_t> bytes_;
48};
49
52 int chunkX = 0, chunkY = 0;
53 int width = 0, height = 0;
55 std::vector<float> flowAccumulation, flowVectorX, flowVectorY;
56 std::vector<float> lakeDepth, temperature, moisture;
57 std::vector<int8_t> flowDirection;
58 std::vector<uint8_t> rivers, streamOrder;
59 std::vector<Biome> biomes;
60};
61
64 int chunkX = 0, chunkY = 0;
65 int width = 0, height = 0;
66 uint64_t offset = 0;
67 uint32_t storedSize = 0, rawSize = 0, checksum = 0;
68 bool compressed = false;
69};
70
82public:
84 static bool bake(const Heightmap &heightmap, const HydrologyMap &hydrology,
85 const ClimateMap &climate, int chunkSize, std::vector<uint8_t> &out,
86 std::string *error = nullptr);
87
89 bool open(const uint8_t *data, size_t size, std::string *error = nullptr);
96 [[nodiscard]] Result<void> openSource(std::shared_ptr<const ITerrainArchiveSource> source);
98 bool loadChunk(int chunkX, int chunkY, TerrainChunkData &out,
99 std::string *error = nullptr) const;
100
102 int getWidth() const { return width_; }
104 int getHeight() const { return height_; }
106 int getChunkSize() const { return chunkSize_; }
108 float getMinHeight() const { return minHeight_; }
110 float getMaxHeight() const { return maxHeight_; }
112 const std::vector<TerrainChunkEntry> &chunks() const { return chunks_; }
114 [[nodiscard]] const TerrainChunkEntry* findChunk(int chunkX, int chunkY) const noexcept;
115
116private:
117 bool openMetadata(const std::uint8_t* data, std::size_t metadataSize,
118 std::uint64_t archiveSize, std::string* error);
119 int width_ = 0, height_ = 0, chunkSize_ = 0;
120 uint16_t version_ = 0;
121 float minHeight_ = 0.f, maxHeight_ = 1.f, maxFlow_ = 1.f;
122 std::shared_ptr<const ITerrainArchiveSource> source_;
123 std::vector<TerrainChunkEntry> chunks_;
124};
125
126} // namespace eve::procgen
#define EVENGINE_API_DOMAINS
Definition Export.h:110
float moisture
std::vector< ClimateData > climate
Current moisture and cloud state per cell.
float temperature
std::uint32_t height
std::uint32_t width
float length
std::function< Numbers(b3JointId)> read
size_t offset
std::uint64_t bytes
std::string error
Definition Package.cpp:174
Move-only, checked operation results for the common layer.
ScriptStructure out
std::string_view source
size_t begin
size_t end
float size
Definition TreeMesh.cpp:158
Move-only operation result carrying either a value or Status.
Definition Result.h:176
In-memory terrain heightmap: a dense float grid (row-major, index = y * width + x) materialized from ...
Definition Heightmap.h:21
Immutable random-access byte source for an EVTR archive.
virtual std::uint64_t size() const noexcept=0
Total stable byte length of the archive. @thread Safe for concurrent reads.
virtual ~ITerrainArchiveSource()=default
Releases ITerrainArchiveSource resources.
Owning in-memory EVTR source used by compatibility callers and tests.
std::uint64_t size() const noexcept override
Returns the size of .
MemoryTerrainArchiveSource(std::span< const std::uint8_t > bytes)
Copy immutable archive bytes into this source.
Versioned, random-access terrain archive.
float getMaxHeight() const
Returns the max height.
float getMinHeight() const
Returns the min height.
int getChunkSize() const
Returns the chunk size.
int getHeight() const
Returns the height.
int getWidth() const
Returns the width.
const std::vector< TerrainChunkEntry > & chunks() const
Chunks.
ClimateMap public API.
HydrologyMap public API.
Decoded terrain chunk containing all baked runtime layers.
std::vector< float > flowAccumulation
std::vector< float > lakeDepth
std::vector< uint8_t > rivers
std::vector< Biome > biomes
std::vector< int8_t > flowDirection
Metadata for one independently compressed chunk in an EVTR archive.