载入中...
搜索中...
未找到
HexSphereMap.cpp
浏览该文件的文档.
17[[nodiscard]] constexpr std::int32_t clampInt(std::int32_t value, std::int32_t low, std::int32_t high) noexcept {
26[[nodiscard]] float dot3(HexVec3 a, HexVec3 b) noexcept { return a.x * b.x + a.y * b.y + a.z * b.z; }
56 Diagnostic::error(DiagnosticCode::InvalidArgument, "subdivision level is out of range", "hexmap.sphere"));
58 Diagnostic::error(DiagnosticCode::InvalidArgument, "sphere radius must be finite and positive", "hexmap.sphere"));
214 Diagnostic::error(DiagnosticCode::NotFound, "ray misses the hex planet", "hexmap.sphere.pick"));
388 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
389 const std::int32_t clamped = clampInt(value, HexMetrics::kMinElevation, HexMetrics::kMaxElevation);
416 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
428 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
437 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
446 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
455 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
464 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
475 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
484 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
495 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
504 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
514 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
517 Diagnostic::error(DiagnosticCode::InvalidArgument, "river direction is not an edge of the cell", "hexmap.sphere"));
520 Diagnostic::error(DiagnosticCode::InvalidArgument, "river direction has no neighbour", "hexmap.sphere"));
523 Diagnostic::error(DiagnosticCode::InvalidArgument, "river direction has no opposite edge", "hexmap.sphere"));
527 if (data->flags.hasAnyRiverOut() && data->flags.hasRiverOut(out)) return Result<void>::success();
530 Diagnostic::error(DiagnosticCode::InvalidArgument, "a river cannot flow uphill", "hexmap.sphere"));
546 if (previousData) previousData->flags = previousData->flags.withoutRiverIn(static_cast<HexDirection>(previousBack));
573 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
596 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
599 Diagnostic::error(DiagnosticCode::InvalidArgument, "road direction is not an edge of the cell", "hexmap.sphere"));
602 Diagnostic::error(DiagnosticCode::InvalidArgument, "road direction has no neighbour", "hexmap.sphere"));
605 Diagnostic::error(DiagnosticCode::InvalidArgument, "road direction has no opposite edge", "hexmap.sphere"));
616 if (other->values.specialIndex() != 0 || data->values.specialIndex() != 0) return Result<void>::success();
631 Diagnostic::error(DiagnosticCode::InvalidArgument, "cell is outside the hex sphere map", "hexmap.sphere"));
649Result<void> HexSphereMap::editElevation(HexSphereCell center, std::int32_t radius, std::int32_t delta) {
651 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush centre is outside the hex sphere map", "hexmap.sphere"));
653 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush radius must be non-negative", "hexmap.sphere"));
663Result<void> HexSphereMap::editWaterLevel(HexSphereCell center, std::int32_t radius, std::int32_t delta) {
665 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush centre is outside the hex sphere map", "hexmap.sphere"));
667 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush radius must be non-negative", "hexmap.sphere"));
675Result<void> HexSphereMap::editTerrainType(HexSphereCell center, std::int32_t radius, std::int32_t terrainType) {
677 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush centre is outside the hex sphere map", "hexmap.sphere"));
679 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush radius must be non-negative", "hexmap.sphere"));
687Result<void> HexSphereMap::editFeatureLevel(HexSphereCell center, std::int32_t radius, std::int32_t feature,
690 Diagnostic::error(DiagnosticCode::InvalidArgument, "brush centre is outside the hex sphere map", "hexmap.sphere"));
692 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={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:571
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
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:136
std::int32_t waterLevel(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:128
float cellSpacing() const noexcept
Mean centre-to-centre distance between neighbouring cells, in world units.
Definition HexSphereMap.cpp:90
HexVec3 cellGroundPosition(HexSphereCell cell) const noexcept
World-space centre of the cell at radius, ignoring elevation.
Definition HexSphereMap.cpp:102
void setElevationStep(float step) noexcept
Sets the radial world distance of one elevation level.
Definition HexSphereMap.cpp:78
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:156
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:675
Result< void > addRoad(HexSphereCell c, std::int32_t direction)
Adds a road through direction when both cells can carry one.
Definition HexSphereMap.cpp:593
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:663
bool hasRiverThrough(HexSphereCell c, std::int32_t direction) const noexcept
Definition HexSphereMap.cpp:164
Result< void > setExplorable(HexSphereCell c, bool explorable)
Sets whether a cell may ever be explored.
Definition HexSphereMap.cpp:492
Result< void > removeRiver(HexSphereCell c)
Removes every river connection of the cell and its neighbours.
Definition HexSphereMap.cpp:570
Result< void > setWaterLevel(HexSphereCell c, std::int32_t waterLevel)
Sets a cell's water level, clamped to [0, kMaxElevation].
Definition HexSphereMap.cpp:413
bool isExplored(HexSphereCell c) const noexcept
Whether a cell has ever been seen by a viewer (the fog-of-war latch).
Definition HexSphereMap.cpp:173
bool hasRoad(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:160
bool isWalled(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:169
bool isExplorable(HexSphereCell c) const noexcept
Whether a cell may ever be revealed by a viewer.
Definition HexSphereMap.cpp:177
std::int32_t elevation(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:124
Result< void > setFarmLevel(HexSphereCell c, std::int32_t level)
Sets a cell's farm level, clamped to [0, 3].
Definition HexSphereMap.cpp:443
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:287
std::int32_t farmLevel(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:140
Result< void > setUrbanLevel(HexSphereCell c, std::int32_t level)
Sets a cell's urban level, clamped to [0, 3].
Definition HexSphereMap.cpp:434
void markCellDirtyAndNeighbors(HexSphereCell cell) noexcept
Marks one cell and its direct neighbours dirty.
Definition HexSphereMap.cpp:322
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:649
Result< void > setExplored(HexSphereCell c, bool explored)
Sets the explored (fog-of-war) latch of a cell.
Definition HexSphereMap.cpp:481
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:385
HexFlags flags(HexSphereCell c) const noexcept
Full packed flag record of a cell (zero when out of range).
Definition HexSphereMap.cpp:185
Result< void > removeRoads(HexSphereCell c)
Removes every road of the cell and its neighbours.
Definition HexSphereMap.cpp:628
Result< void > setOutgoingRiver(HexSphereCell c, std::int32_t direction)
Forces a river to leave the cell through direction, mirroring the neighbour.
Definition HexSphereMap.cpp:511
std::int32_t distance(HexSphereCell a, HexSphereCell b) const
Number of edges between two cells, or kNoHexSphereCell when either is invalid.
Definition HexSphereMap.cpp:256
HexValues values(HexSphereCell c) const noexcept
Full packed value record of a cell (zero when out of range).
Definition HexSphereMap.cpp:181
std::int32_t plantLevel(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:144
Result< void > setTerrainType(HexSphereCell c, std::int32_t terrainType)
Sets a cell's terrain palette index, clamped to the palette range.
Definition HexSphereMap.cpp:425
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:114
float surfaceRadius(HexSphereCell cell) const noexcept
Radius of the cell's surface: sphereRadius + elevation * elevationStep.
Definition HexSphereMap.cpp:85
HexEdgeType edgeTypeTo(HexSphereCell a, HexSphereCell b) const noexcept
Relationship between two adjacent cells; Flat when not adjacent.
Definition HexSphereMap.cpp:106
Result< void > setWalled(HexSphereCell c, bool walled)
Sets whether a cell is walled.
Definition HexSphereMap.cpp:472
std::int32_t terrainType(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:132
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:53
Result< void > setCellState(HexSphereCell c, HexValues values, HexFlags flags)
Writes a complete cell record verbatim.
Definition HexSphereMap.cpp:501
HexVec3 cellPosition(HexSphereCell cell) const noexcept
World-space centre of the cell's surface.
Definition HexSphereMap.cpp:98
Result< void > setPlantLevel(HexSphereCell c, std::int32_t level)
Sets a cell's plant level, clamped to [0, 3].
Definition HexSphereMap.cpp:452
Result< HexSphereCell > pickCell(HexVec3 rayOrigin, HexVec3 rayDirection) const
Finds the cell under a world-space ray.
Definition HexSphereMap.cpp:192
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:461
std::int32_t specialIndex(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:148
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:687
bool isUnderwater(HexSphereCell c) const noexcept
Definition HexSphereMap.cpp:152
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:306
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:326
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:311
static Result< HexSphereTopology > build(std::int32_t subdivision)
Builds the topology of one subdivision level.
Definition HexSphereTopology.cpp:100
HexSphereCell cellAt(HexVec3 unitDirection) const noexcept
The cell whose centre direction is nearest to unitDirection.
Definition HexSphereTopology.cpp:347
constexpr HexValues withSpecialIndex(std::int32_t value) const noexcept
With special index.
Definition HexCell.h:96
constexpr HexValues withElevation(std::int32_t value) const noexcept
Definition HexCell.h:76
constexpr HexValues withWaterLevel(std::int32_t value) const noexcept
With water level.
Definition HexCell.h:80
float length3(float x, float y, float z)
Definition PlacementGeometry.cpp:57
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