载入中...
搜索中...
未找到
HexSphereMap.cpp
浏览该文件的文档.
16[[nodiscard]] constexpr std::int32_t clampInt(std::int32_t value, std::int32_t low, std::int32_t high) noexcept {
25[[nodiscard]] float dot3(HexVec3 a, HexVec3 b) noexcept { return a.x * b.x + a.y * b.y + a.z * b.z; }
55 Diagnostic::error(DiagnosticCode::InvalidArgument, "subdivision level is out of range", "hexmap.sphere"));
57 Diagnostic::error(DiagnosticCode::InvalidArgument, "sphere radius must be finite and positive", "hexmap.sphere"));
211 Diagnostic::error(DiagnosticCode::NotFound, "ray misses the hex planet", "hexmap.sphere.pick"));
385 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
386 const std::int32_t clamped = clampInt(value, HexMetrics::kMinElevation, HexMetrics::kMaxElevation);
413 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
425 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
434 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
443 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
452 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
461 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
472 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
481 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
492 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
501 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
511 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
514 Diagnostic::error(DiagnosticCode::InvalidArgument, "river direction is not an edge of the cell", "hexmap.sphere"));
517 Diagnostic::error(DiagnosticCode::InvalidArgument, "river direction has no neighbour", "hexmap.sphere"));
520 Diagnostic::error(DiagnosticCode::InvalidArgument, "river direction has no opposite edge", "hexmap.sphere"));
524 if (data->flags.hasAnyRiverOut() && data->flags.hasRiverOut(out)) return Result<void>::success();
527 Diagnostic::error(DiagnosticCode::InvalidArgument, "a river cannot flow uphill", "hexmap.sphere"));
543 if (previousData) previousData->flags = previousData->flags.withoutRiverIn(static_cast<HexDirection>(previousBack));
570 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
593 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
596 Diagnostic::error(DiagnosticCode::InvalidArgument, "road direction is not an edge of the cell", "hexmap.sphere"));
599 Diagnostic::error(DiagnosticCode::InvalidArgument, "road direction has no neighbour", "hexmap.sphere"));
602 Diagnostic::error(DiagnosticCode::InvalidArgument, "road direction has no opposite edge", "hexmap.sphere"));
613 if (other->values.specialIndex() != 0 || data->values.specialIndex() != 0) return Result<void>::success();
628 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
646Result<void> HexSphereMap::editElevation(HexSphereCell center, std::int32_t radius, std::int32_t delta) {
648 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush centre is outside the hex sphere map", "hexmap.sphere"));
650 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush radius must be non-negative", "hexmap.sphere"));
660Result<void> HexSphereMap::editWaterLevel(HexSphereCell center, std::int32_t radius, std::int32_t delta) {
662 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush centre is outside the hex sphere map", "hexmap.sphere"));
664 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush radius must be non-negative", "hexmap.sphere"));
672Result<void> HexSphereMap::editTerrainType(HexSphereCell center, std::int32_t radius, std::int32_t terrainType) {
674 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush centre is outside the hex sphere map", "hexmap.sphere"));
676 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush radius must be non-negative", "hexmap.sphere"));
684Result<void> HexSphereMap::editFeatureLevel(HexSphereCell center, std::int32_t radius, std::int32_t feature,
687 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush centre is outside the hex sphere map", "hexmap.sphere"));
689 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush radius must be non-negative", "hexmap.sphere"));
Stable, structured diagnostics shared by engine modules.
Editable spherical hex map over an icosahedral hex topology.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:537
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Packed boolean cell state (roads, rivers, walls, exploration).
Definition HexCell.h:123
constexpr bool hasRiverThrough(HexDirection d) const noexcept
Whether a river enters and/or leaves through d.
Definition HexCell.h:172
constexpr HexFlags withoutRiverIn(HexDirection d) const noexcept
Without river in.
Definition HexCell.h:207
constexpr HexFlags withoutRiverOut(HexDirection d) const noexcept
Without river out.
Definition HexCell.h:217
std::int32_t urbanLevel(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:133
std::int32_t waterLevel(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:125
float cellSpacing() const noexcept
Mean centre-to-centre distance between neighbouring cells, in world units.
Definition HexSphereMap.cpp:87
HexVec3 cellGroundPosition(HexSphereCell cell) const noexcept
World-space centre of the cell at radius, ignoring elevation.
Definition HexSphereMap.cpp:99
void setElevationStep(float step) noexcept
Sets the radial world distance of one elevation level.
Definition HexSphereMap.cpp:75
std::int32_t subdivision() const noexcept
The subdivision level this map was built at.
Definition HexSphereMap.h:87
bool hasRiver(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:153
Result< void > editTerrainType(HexSphereCell center, std::int32_t radius, std::int32_t terrainType)
Paints a terrain palette index over a hex brush.
Definition HexSphereMap.cpp:672
Result< void > addRoad(HexSphereCell c, std::int32_t direction)
Adds a road through direction when both cells can carry one.
Definition HexSphereMap.cpp:590
Result< void > editWaterLevel(HexSphereCell center, std::int32_t radius, std::int32_t delta)
Applies additive water-level change over a hex brush.
Definition HexSphereMap.cpp:660
bool hasRiverThrough(HexSphereCell c, std::int32_t direction) const noexcept
Definition HexSphereMap.cpp:161
Result< void > setExplorable(HexSphereCell c, bool explorable)
Sets whether a cell may ever be explored.
Definition HexSphereMap.cpp:489
Result< void > removeRiver(HexSphereCell c)
Removes every river connection of the cell and its neighbours.
Definition HexSphereMap.cpp:567
Result< void > setWaterLevel(HexSphereCell c, std::int32_t waterLevel)
Sets a cell's water level, clamped to [0, kMaxElevation].
Definition HexSphereMap.cpp:410
bool isExplored(HexSphereCell c) const noexcept
Whether a cell has ever been seen by a viewer (the fog-of-war latch).
Definition HexSphereMap.cpp:170
bool hasRoad(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:157
bool isWalled(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:166
bool isExplorable(HexSphereCell c) const noexcept
Whether a cell may ever be revealed by a viewer.
Definition HexSphereMap.cpp:174
std::int32_t elevation(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:121
Result< void > setFarmLevel(HexSphereCell c, std::int32_t level)
Sets a cell's farm level, clamped to [0, 3].
Definition HexSphereMap.cpp:440
void collectBrush(HexSphereCell center, std::int32_t radius, std::vector< HexSphereCell > &out) const
Enumerates the cells within radius steps of center into out.
Definition HexSphereMap.cpp:284
std::int32_t farmLevel(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:137
Result< void > setUrbanLevel(HexSphereCell c, std::int32_t level)
Sets a cell's urban level, clamped to [0, 3].
Definition HexSphereMap.cpp:431
void markCellDirtyAndNeighbors(HexSphereCell cell) noexcept
Marks one cell and its direct neighbours dirty.
Definition HexSphereMap.cpp:319
Result< void > editElevation(HexSphereCell center, std::int32_t radius, std::int32_t delta)
Raises or lowers every cell within radius steps of center.
Definition HexSphereMap.cpp:646
Result< void > setExplored(HexSphereCell c, bool explored)
Sets the explored (fog-of-war) latch of a cell.
Definition HexSphereMap.cpp:478
Result< void > setElevation(HexSphereCell c, std::int32_t elevation)
Sets a cell's elevation, clamped to the editable range, and refreshes dependents.
Definition HexSphereMap.cpp:382
HexFlags flags(HexSphereCell c) const noexcept
Full packed flag record of a cell (zero when out of range).
Definition HexSphereMap.cpp:182
Result< void > removeRoads(HexSphereCell c)
Removes every road of the cell and its neighbours.
Definition HexSphereMap.cpp:625
Result< void > setOutgoingRiver(HexSphereCell c, std::int32_t direction)
Forces a river to leave the cell through direction, mirroring the neighbour.
Definition HexSphereMap.cpp:508
std::int32_t distance(HexSphereCell a, HexSphereCell b) const
Number of edges between two cells, or kNoHexSphereCell when either is invalid.
Definition HexSphereMap.cpp:253
HexValues values(HexSphereCell c) const noexcept
Full packed value record of a cell (zero when out of range).
Definition HexSphereMap.cpp:178
std::int32_t plantLevel(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:141
Result< void > setTerrainType(HexSphereCell c, std::int32_t terrainType)
Sets a cell's terrain palette index, clamped to the palette range.
Definition HexSphereMap.cpp:422
const HexCellData * cellAt(HexSphereCell cell) const noexcept
Cell record by id, or null when out of range. @ownership Borrowed; the map owns the record....
Definition HexSphereMap.cpp:111
float surfaceRadius(HexSphereCell cell) const noexcept
Radius of the cell's surface: sphereRadius + elevation * elevationStep.
Definition HexSphereMap.cpp:82
HexEdgeType edgeTypeTo(HexSphereCell a, HexSphereCell b) const noexcept
Relationship between two adjacent cells; Flat when not adjacent.
Definition HexSphereMap.cpp:103
Result< void > setWalled(HexSphereCell c, bool walled)
Sets whether a cell is walled.
Definition HexSphereMap.cpp:469
std::int32_t terrainType(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:129
std::int32_t neighborCount(HexSphereCell cell) const noexcept
Number of edges of cell (5 or 6), or 0 when out of range.
Definition HexSphereMap.h:138
Result< void > reset(std::int32_t subdivision, float radius, std::uint32_t seed)
Replaces the map with a new sphere of 10 * 4^subdivision + 2 cells.
Definition HexSphereMap.cpp:52
Result< void > setCellState(HexSphereCell c, HexValues values, HexFlags flags)
Writes a complete cell record verbatim.
Definition HexSphereMap.cpp:498
HexVec3 cellPosition(HexSphereCell cell) const noexcept
World-space centre of the cell's surface.
Definition HexSphereMap.cpp:95
Result< void > setPlantLevel(HexSphereCell c, std::int32_t level)
Sets a cell's plant level, clamped to [0, 3].
Definition HexSphereMap.cpp:449
Result< HexSphereCell > pickCell(HexVec3 rayOrigin, HexVec3 rayDirection) const
Finds the cell under a world-space ray.
Definition HexSphereMap.cpp:189
static constexpr float kDefaultElevationRatio
Ratio of the default radial elevation step to the sphere radius.
Definition HexSphereMap.h:61
Result< void > setSpecialIndex(HexSphereCell c, std::int32_t index)
Sets a cell's special-feature index; ignored while the cell carries a river.
Definition HexSphereMap.cpp:458
std::int32_t specialIndex(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:145
Result< void > editFeatureLevel(HexSphereCell center, std::int32_t radius, std::int32_t feature, std::int32_t delta)
Applies additive change to one feature level (0 urban, 1 farm, 2 plant).
Definition HexSphereMap.cpp:684
bool isUnderwater(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:149
bool contains(HexSphereCell cell) const noexcept
Whether cell is a valid id of this map.
Definition HexSphereMap.h:129
std::int32_t neighborCount(HexSphereCell cell) const noexcept
Number of edges of cell (5 or 6), or 0 when out of range.
Definition HexSphereTopology.cpp:294
std::int32_t oppositeDirection(HexSphereCell cell, std::int32_t direction) const noexcept
Edge index of cell's edge towards its neighbour across direction.
Definition HexSphereTopology.cpp:314
std::int32_t cellCount() const noexcept
Number of cells (10 * f^2 + 2).
Definition HexSphereTopology.h:80
HexSphereCell neighbor(HexSphereCell cell, std::int32_t direction) const noexcept
Neighbour of cell across edge direction.
Definition HexSphereTopology.cpp:299
static Result< HexSphereTopology > build(std::int32_t subdivision)
Builds the topology of one subdivision level.
Definition HexSphereTopology.cpp:92
HexSphereCell cellAt(HexVec3 unitDirection) const noexcept
The cell whose centre direction is nearest to unitDirection.
Definition HexSphereTopology.cpp:334
constexpr HexValues withSpecialIndex(std::int32_t value) const noexcept
With special index.
Definition HexCell.h:96
Definition HexCell.h:9
constexpr std::int32_t kHexDirectionCount
Number of hex edges / facing directions.
Definition HexMetrics.h:62
constexpr HexEdgeType edgeType(int elevation1, int elevation2) noexcept
The relationship between two elevations (single-step changes are slopes).
Definition HexMetrics.h:96
constexpr std::int32_t kMaxHexSphereSubdivision
Largest supported subdivision level; 10 * 4^7 + 2 = 163842 cells.
Definition HexSphereTopology.h:22
HexEdgeType
Relationship between two neighbouring cells of different elevation.
Definition HexMetrics.h:93
constexpr HexSphereCell kNoHexSphereCell
Returned by a spherical cell query that has no answer.
Definition HexSphereTopology.h:19
constexpr HexDirection next(HexDirection d) noexcept
The next direction clockwise (NW wraps to NE).
Definition HexMetrics.h:76
std::int32_t HexSphereCell
Dense identifier of one cell of a spherical hex topology.
Definition HexSphereTopology.h:16
constexpr std::int32_t clampTerrainType(std::int32_t index) noexcept
Terrain type index clamped into the supported palette range.
Definition HexCell.h:24
@ InvalidArgument
@ NotFound
One cell of the hex map: packed values plus packed flags.
Definition HexCell.h:244
Minimal 3-component float vector used by the hex mesh builders.
Definition HexMetrics.h:18