载入中...
搜索中...
未找到
RuntimeGeneration.cpp
浏览该文件的文档.
62bool RuntimeGeneration::isOwnerThread() const noexcept { return std::this_thread::get_id() == ownerThread_; }
80int RuntimeGeneration::addLevel(float cellSize, float generationRadius, float cleanupMultiplier) {
107void RuntimeGeneration::setMaxPointsPerCell(int count) { maxPointsPerCell_ = std::max(0, count); }
172uint64_t RuntimeGeneration::getCommittedRefreshRevision() const { return committedRefreshRevision_; }
312 distance > 0.f && hasDirection ? (dx * source.directionX + dz * source.directionZ) / distance : 1.f;
313 if (plan.frustumCulling && hasDirection && distance > plan.frustumBehindRadius && forward < plan.coneCosine)
316 const float priority = distance / std::max(generationRadius, 0.0001f) - plan.directionWeight * forward;
332 transitionCellState(existing->second, existing->second.revision > 0 ? State::Active : State::Pending);
334 cleanupQueue_.erase(std::remove(cleanupQueue_.begin(), cleanupQueue_.end(), key), cleanupQueue_.end());
440 if (maxActiveCells_ > 0 && getActiveCellCount() + getGeneratingCount() >= maxActiveCells_) return std::nullopt;
462 DiagnosticCode::Conflict, "runtime-generation scheduler called from a non-owner thread", "thread"));
466Result<std::reference_wrapper<RuntimeGeneration::Cell>> RuntimeGeneration::validateGenerationJob(
470 DiagnosticCode::Conflict, "runtime-generation scheduler called from a non-owner thread", "thread"));
473 DiagnosticCode::Conflict, "runtime-generation job belongs to another scheduler", "job.scheduler"));
476 if (found == cells_.end() || found->second.state != State::Generating || job.seed_ != cellSeed(key) ||
479 Diagnostic::error(DiagnosticCode::Conflict, "runtime-generation job ticket is stale", "job.ticket"));
483Result<uint64_t> RuntimeGeneration::completeGenerationJob(ProcgenGenerationCompletion completion) {
494 DiagnosticCode::InvalidArgument, "runtime-generation completion exceeds point budget", "output"));
530 DiagnosticCode::Conflict, "runtime-generation scheduler called from a non-owner thread", "thread"));
589Result<uint64_t> RuntimeGeneration::completeCleanupsAtomic(const std::vector<const ProcgenCellRequest*>& requests) {
592 DiagnosticCode::Conflict, "runtime-generation scheduler called from a non-owner thread", "thread"));
599Result<void> RuntimeGeneration::validateCleanups(const std::vector<const ProcgenCellRequest*>& requests) const {
602 DiagnosticCode::InvalidArgument, "cleanup transaction requires at least one request", "requests"));
615 if (request->schedulerId_ != schedulerId_ || found == cells_.end() || found->second.state != State::Cleanup ||
623void RuntimeGeneration::eraseValidatedCleanups(const std::vector<const ProcgenCellRequest*>& requests) {
644Result<uint64_t> RuntimeGeneration::applyCellUpdate(int level, int x, int z, uint64_t expectedRevision,
649 Diagnostic::error(DiagnosticCode::NotFound, "active runtime-generation cell was not found", "cell"));
652 Diagnostic::error(DiagnosticCode::Conflict, "runtime-generation cell revision is stale", "revision"));
660 const std::int64_t projectedResident = std::int64_t(getResidentPointCount()) - found->second.output.getCount() +
677Result<uint64_t> RuntimeGeneration::migrateCellPointIds(int level, int x, int z, uint64_t expectedRevision) {
682 Diagnostic::error(DiagnosticCode::NotFound, "active runtime-generation cell was not found", "cell"));
685 Diagnostic::error(DiagnosticCode::Conflict, "runtime-generation cell revision is stale", "revision"));
707 out << "levels=" << levels_.size() << " cells=" << cells_.size() << " pending=" << generateQueue_.size()
709 << " cleanup=" << cleanupQueue_.size() << " failed=" << getFailedCellCount() << " maxActive=" << maxActiveCells_
712 << " cancelledGeneration=" << cancelledGenerationCount_ << " refreshPending=" << (refreshPlan_ ? 1 : 0)
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
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Result< void > assignPointIds(std::uint64_t namespaceId)
Fill zero identities deterministically and reject pre-existing duplicates.
Definition PointSet.cpp:310
One immutable runtime-generation cell request returned to script.
Definition RuntimeGeneration.h:17
uint64_t getTicket() const
Unique scheduler ticket used to reject stale asynchronous completions.
Definition RuntimeGeneration.cpp:38
Owning worker result returned to a RuntimeGeneration scheduler.
Definition RuntimeGeneration.h:88
ProcgenGenerationCompletion(ProcgenGenerationJob job, PointSet output)
Package a job and generated points without touching scheduler state.
Definition RuntimeGeneration.cpp:54
Copyable generation input issued by one RuntimeGeneration scheduler.
Definition RuntimeGeneration.h:55
float getMaxZ() const
Return the captured upper world-space Z bound.
Definition RuntimeGeneration.cpp:52
float getMaxX() const
Return the captured upper world-space X bound.
Definition RuntimeGeneration.cpp:51
uint32_t getSeed() const
Return the deterministic seed derived from world seed, level and coordinates.
Definition RuntimeGeneration.cpp:47
float getMinX() const
Return the captured lower world-space X bound.
Definition RuntimeGeneration.cpp:49
float getMinZ() const
Return the captured lower world-space Z bound.
Definition RuntimeGeneration.cpp:50
uint64_t getTicket() const
Return the ticket; valid only together with this job's private scheduler identity.
Definition RuntimeGeneration.cpp:48
int getZ() const
Return the cell Z coordinate captured at issue time.
Definition RuntimeGeneration.cpp:46
int getX() const
Return the cell X coordinate captured at issue time.
Definition RuntimeGeneration.cpp:45
int getLevel() const
Return the hierarchical grid level captured at issue time.
Definition RuntimeGeneration.cpp:44
void setMaxPointsPerCell(int count)
Set the maximum points allowed in one generated cell; zero disables the limit.
Definition RuntimeGeneration.cpp:107
bool completeGeneration(ProcgenCellRequest *request, PointSet *output)
Compatibility-only bool projection of completeGenerationJob; request and output are borrowed.
Definition RuntimeGeneration.cpp:555
bool isFrustumCullingEnabled() const
True when frustum culling enabled.
Definition RuntimeGeneration.cpp:228
Result< std::optional< ProcgenCellRequest > > nextCleanupRequest()
Claim an owning cleanup ticket, or an empty optional when no cleanup is pending.
Definition RuntimeGeneration.cpp:527
float getFrustumBehindRadius() const
Returns the frustum behind radius.
Definition RuntimeGeneration.cpp:230
int getPendingGenerateCount() const
Returns the pending generate count.
Definition RuntimeGeneration.cpp:397
int trimToResidentPoints(int target)
Schedule lowest-priority active cells for cleanup until at most target points remain.
Definition RuntimeGeneration.cpp:120
bool isRequestCurrent(const ProcgenCellRequest *request) const
Test whether an issued generation or cleanup request still owns its scheduler ticket.
Definition RuntimeGeneration.cpp:546
void beginFrame()
Start a new budget window before consuming generation requests.
Definition RuntimeGeneration.cpp:160
float getLevelCellSize(int level) const
Returns the level cell size.
Definition RuntimeGeneration.cpp:87
int addLevel(float cellSize, float generationRadius, float cleanupMultiplier)
Add a hierarchical grid level.
Definition RuntimeGeneration.cpp:80
int getCancelledGenerationCount() const
Return issued generation requests invalidated before completion.
Definition RuntimeGeneration.cpp:401
Result< uint64_t > migrateCellPointIds(int level, int x, int z, uint64_t expectedRevision)
Assign deterministic identities to a legacy active cell atomically.
Definition RuntimeGeneration.cpp:677
float getLevelCleanupRadius(int level) const
Returns the level cleanup radius.
Definition RuntimeGeneration.cpp:95
bool hasCell(int level, int x, int z) const
Definition RuntimeGeneration.cpp:627
int getPendingCleanupCount() const
Returns the pending cleanup count.
Definition RuntimeGeneration.cpp:400
void setFrustumCulling(bool enabled, float halfAngleDegrees, float behindRadius)
Enable view-cone scheduling.
Definition RuntimeGeneration.cpp:221
int getMaxGenerationRetries() const
Return retries allowed after the initial generation attempt.
Definition RuntimeGeneration.cpp:155
uint64_t getCommittedRefreshRevision() const
Return the latest source revision atomically published into generation and cleanup queues.
Definition RuntimeGeneration.cpp:172
bool isRefreshPending() const
Return whether a staged source snapshot still needs planning work.
Definition RuntimeGeneration.cpp:171
uint64_t getCellRevision(int level, int x, int z) const
Returns the cell revision.
Definition RuntimeGeneration.cpp:639
void setFrameTimeBudget(float milliseconds)
CPU issue budget in milliseconds for one frame; zero disables the limit.
Definition RuntimeGeneration.cpp:156
bool failGeneration(ProcgenCellRequest *request)
Compatibility-only bool projection of failGenerationJob; request is borrowed.
Definition RuntimeGeneration.cpp:569
Result< uint64_t > applyCellUpdate(int level, int x, int z, uint64_t expectedRevision, const PointSet &output)
Atomically replace an active cell through an identity-based delta.
Definition RuntimeGeneration.cpp:644
int getRefreshWorkBudget() const
Return the per-call source-refresh candidate budget, or zero when synchronous.
Definition RuntimeGeneration.cpp:170
Result< void > failGenerationJob(const ProcgenGenerationJob &job)
Report an issued job failure and apply the bounded retry policy.
Definition RuntimeGeneration.cpp:504
ProcgenCellRequest * nextGenerate()
Compatibility facade returning a heap request; prefer nextGenerationJob().
Definition RuntimeGeneration.cpp:422
int getMaxResidentPoints() const
Return the total resident-point limit, or zero when unlimited.
Definition RuntimeGeneration.cpp:112
bool removeGenerationSource(const std::string &id)
Removes generation source.
Definition RuntimeGeneration.cpp:201
int getGenerationSourceCount() const
Returns the generation source count.
Definition RuntimeGeneration.cpp:215
PointSet * getCellOutput(int level, int x, int z) const
Returns the cell output.
Definition RuntimeGeneration.cpp:632
float getLevelGenerationRadius(int level) const
Returns the level generation radius.
Definition RuntimeGeneration.cpp:90
int getFailedCellCount() const
Return cells stopped after exhausting the generation retry policy.
Definition RuntimeGeneration.cpp:402
int retryFailedCells()
Reset and requeue all terminally failed cells still tracked by the scheduler.
Definition RuntimeGeneration.cpp:408
Result< uint64_t > completeCleanupsAtomic(const std::vector< const ProcgenCellRequest * > &requests)
Atomically acknowledge several cleanup tickets owned by this scheduler.
Definition RuntimeGeneration.cpp:589
float getFrustumHalfAngle() const
Returns the frustum half angle.
Definition RuntimeGeneration.cpp:229
PointDelta * getCellDelta(int level, int x, int z) const
Return a caller-owned copy of the latest committed delta, or null when unavailable....
Definition RuntimeGeneration.cpp:698
bool setGenerationSource(const std::string &id, float x, float z, float directionX, float directionZ, float radiusScale=1.f)
Add or update a named generation source, then rebuild desired cells.
Definition RuntimeGeneration.cpp:184
Result< uint64_t > completeCleanupRequest(const ProcgenCellRequest &request)
Commit one cleanup ticket after consumers have removed its generated content.
Definition RuntimeGeneration.cpp:542
void updateSource(float x, float z, float directionX, float directionZ)
Recompute desired cells for a generation source.
Definition RuntimeGeneration.cpp:180
std::string getGenerationSourceId(int index) const
Returns the generation source id.
Definition RuntimeGeneration.cpp:216
Result< uint64_t > continueGenerationRefresh()
Advance a budgeted source refresh without changing the requested sources.
Definition RuntimeGeneration.cpp:173
bool completeCleanup(ProcgenCellRequest *request)
Compatibility-only bool projection of completeCleanupsAtomic; request is borrowed.
Definition RuntimeGeneration.cpp:583
void setMaxGenerating(int count)
Maximum simultaneously issued generation requests.
Definition RuntimeGeneration.cpp:103
void setMaxActiveCells(int count)
Maximum active plus in-flight cells; zero disables the resident-cell limit.
Definition RuntimeGeneration.cpp:105
bool isOwnerThread() const noexcept
Return whether the caller is the thread that constructed this scheduler.
Definition RuntimeGeneration.cpp:62
void setMaxGenerationRetries(int count)
Set retries after the initial generation attempt; zero fails immediately.
Definition RuntimeGeneration.cpp:152
Result< std::optional< ProcgenGenerationJob > > nextGenerationJob()
Issue one owning worker job, or an empty optional when no work is currently admissible.
Definition RuntimeGeneration.cpp:459
int getMaxPointsPerCell() const
Return the per-cell point limit, or zero when unlimited.
Definition RuntimeGeneration.cpp:108
int getRejectedOutputCount() const
Return generation or restore outputs rejected by point budgets.
Definition RuntimeGeneration.cpp:119
void setDirectionWeight(float weight)
Weight favoring cells in front of the source, clamped to [0,1].
Definition RuntimeGeneration.cpp:99
int getResidentPointCount() const
Return points retained by active or not-yet-acknowledged cleanup cells.
Definition RuntimeGeneration.cpp:113
ProcgenCellRequest * nextCleanup()
Compatibility-only heap projection of nextCleanupRequest; caller owns the returned request.
Definition RuntimeGeneration.cpp:520
void setRefreshWorkBudget(int candidateCells)
Limit source-refresh planning work performed by one call.
Definition RuntimeGeneration.cpp:166
Result< uint64_t > completeGenerationJob(ProcgenGenerationCompletion completion)
Atomically publish an owning worker completion.
Definition RuntimeGeneration.cpp:483
void refreshGenerationSources()
Re-evaluate generation/cleanup queues from every registered source.
Definition RuntimeGeneration.cpp:232
int getMaxActiveCells() const
Return the resident-cell limit, or zero when unlimited.
Definition RuntimeGeneration.cpp:106
RuntimeGeneration(uint32_t worldSeed=1)
Create a scheduler with a stable world seed.
Definition RuntimeGeneration.cpp:57
void clear()
Remove levels, cells, queues and outputs while retaining the world seed.
Definition RuntimeGeneration.cpp:64
void setMaxResidentPoints(int count)
Set the total point limit across active cell outputs; zero disables the limit.
Definition RuntimeGeneration.cpp:109
std::vector< double > forward(const Policy &p, const Observation &o)
Forward.
Definition Learning.h:65
constexpr HexDirection next(HexDirection d) noexcept
The next direction clockwise (NW wraps to NE).
Definition HexMetrics.h:76
Definition EvpackPointGraphLoader.h:12
std::uint64_t derivePointId(std::uint64_t namespaceId, std::uint64_t ordinal)
Deterministically derive a non-zero stable point identity.
Definition PointSet.cpp:469
Result< PointSet > applyPointDelta(const PointSet &base, const PointDelta &delta)
Apply a delta atomically, rejecting stale or internally inconsistent input.
Definition PointDelta.cpp:212
uint32_t deriveSeed(uint32_t parent, const std::string &scope)
Stable label-based seed derivation; independent pipeline branches do not perturb each other.
Definition PointSet.cpp:459
Result< PointDelta > diffPointSets(const PointSet &before, const PointSet &after)
Compute an identity-based delta without mutating either snapshot.
Definition PointDelta.cpp:179
@ InvalidArgument
@ NotFound
@ PreconditionViolation
@ Conflict
@ Pending
Definition Container.h:602
Transactional identity-based change set between two point snapshots.
Definition PointDelta.h:16