载入中...
搜索中...
未找到
PcgFrameRateManager.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <array>
4#include <cmath>
5#include <limits>
6#include <optional>
7#include <simplesquirrel/simplesquirrel.hpp>
8#include <unordered_map>
9#include <utility>
12#include "procgen/PcgMeshLod.h"
15
16// PcgFrameRateManager.cpp
17namespace eve::procgen {
18namespace {
19constexpr std::array<PcgTerrainQualityPreset, 6> k{{{250, 30, 5, 5, 40, .1f, 20, 1, 100},
20 {500, 50, 10, 10, 50, .25f, 10, 1, 250},
21 {650, 75, 25, 20, 60, .4f, 8, 0, 500},
22 {800, 100, 40, 30, 80, .7f, 5, 0, 800},
23 {1000, 150, 50, 50, 120, 1, 5, 0, 1000},
24 {2000, 200, 50, 100, 150, 1, 5, 0, 1000}}};
25}
27 if (target <= 0 || !std::isfinite(interval) || interval <= 0 || minimum < 0 || maximum >= int(k.size()) ||
28 minimum > maximum || current < minimum || current > maximum)
30 "invalid frame-rate manager configuration",
31 "procgen.frameRate.configure"));
32 target_ = target;
33 interval_ = interval;
34 min_ = minimum;
35 max_ = maximum;
36 quality_ = current;
37 left_ = interval;
38 fpsLeft_ = .5f;
39 accum_ = fps_ = 0;
40 frames_ = 0;
41 changed_ = false;
42 return Result<void>::success();
43}
45 if (!std::isfinite(dt) || dt <= 0 || !std::isfinite(scale) || scale < 0)
47 "dt must be positive and timeScale non-negative",
48 "procgen.frameRate.update"));
49 changed_ = false;
50 fpsLeft_ -= dt;
51 accum_ += scale / dt;
52 ++frames_;
53 if (fpsLeft_ <= 0) {
54 fps_ = accum_ / float(frames_);
55 fpsLeft_ = .5f;
56 accum_ = 0;
57 frames_ = 0;
58 }
59 if (automatic_) {
60 left_ -= dt;
61 if (left_ < 0) {
62 int old = quality_;
63 if (fps_ + 10 >= target_ && quality_ < max_)
64 ++quality_;
65 else if (fps_ - 10 <= target_ && quality_ > min_)
66 --quality_;
67 changed_ = old != quality_;
68 left_ = interval_;
69 }
70 }
71 return Result<int>::success(quality_);
72}
74 if (q < min_ || q > max_)
76 DiagnosticCode::InvalidArgument, "quality is outside configured range", "procgen.frameRate.quality"));
77 changed_ = q != quality_;
78 quality_ = q;
79 automatic_ = false;
80 return Result<void>::success();
81}
82PcgTerrainQualityPreset PcgFrameRateManager::getPreset() const { return k[size_t(quality_)]; }
84 auto p = t.addClass("PcgTerrainQualityPreset", ssq::Class::Ctor<PcgTerrainQualityPreset()>());
85 p.addVar("treeDistance", &PcgTerrainQualityPreset::treeDistance);
86 p.addVar("treeBillboardDistance", &PcgTerrainQualityPreset::treeBillboardDistance);
87 p.addVar("treeCrossFadeLength", &PcgTerrainQualityPreset::treeCrossFadeLength);
88 p.addVar("treeMaximumFullLodCount", &PcgTerrainQualityPreset::treeMaximumFullLodCount);
89 p.addVar("detailObjectDistance", &PcgTerrainQualityPreset::detailObjectDistance);
90 p.addVar("detailObjectDensity", &PcgTerrainQualityPreset::detailObjectDensity);
91 p.addVar("heightmapPixelError", &PcgTerrainQualityPreset::heightmapPixelError);
92 p.addVar("heightmapMaximumLod", &PcgTerrainQualityPreset::heightmapMaximumLod);
93 p.addVar("basemapDistance", &PcgTerrainQualityPreset::basemapDistance);
94 auto m = t.addClass("PcgFrameRateManager", ssq::Class::Ctor<PcgFrameRateManager()>());
95 auto vm = t.getHandle();
96 m.addFunc("configure", [vm](PcgFrameRateManager* s, int a, float b, int c, int d, int e) {
97 return eve::script::projectResult(vm, s->configure(a, b, c, d, e));
98 });
99 m.addFunc("update", [vm](PcgFrameRateManager* s, float d, float scale) {
100 return eve::script::projectResult(vm, s->update(d, scale), [](int q) { return eve::Value(q); });
101 });
102 m.addFunc("setAutomatic", [](PcgFrameRateManager* s, bool v) { s->setAutomatic(v); });
103 m.addFunc("getAutomatic", [](const PcgFrameRateManager* s) { return s->getAutomatic(); });
104 m.addFunc("selectManualQuality", [vm](PcgFrameRateManager* s, int q) {
105 return eve::script::projectResult(vm, s->selectManualQuality(q));
106 });
107 m.addFunc("getQuality", [](const PcgFrameRateManager* s) { return s->getQuality(); });
108 m.addFunc("getFps", [](const PcgFrameRateManager* s) { return s->getFps(); });
109 m.addFunc("getQualityChanged", [](const PcgFrameRateManager* s) { return s->getQualityChanged(); });
110 m.addFunc("getPreset", &PcgFrameRateManager::getPreset);
111}
112} // namespace eve::procgen
113
114// PcgMeshLod.cpp
115namespace eve::procgen {
116namespace {}
117
118PcgMeshTransform::PcgMeshTransform() noexcept { matrix_[0] = matrix_[5] = matrix_[10] = matrix_[15] = 1.F; }
120 if (row < 0 || row >= 4 || column < 0 || column >= 4 || !std::isfinite(value))
122 "Pcg mesh transform element is invalid", "procgen.pcgMeshLod"));
123 matrix_[static_cast<std::size_t>(row * 4 + column)] = value;
124 return Result<void>::success();
125}
126float PcgMeshTransform::getElement(int row, int column) const noexcept {
127 return row >= 0 && row < 4 && column >= 0 && column < 4 ? matrix_[static_cast<std::size_t>(row * 4 + column)] : 0.F;
128}
129
131 const std::string& defaultMaterialId) {
132 if (mesh.empty() || sources_.size() >= 4096 || defaultMaterialId.empty())
134 DiagnosticCode::InvalidArgument, "Pcg mesh combine source, material identity or source budget is invalid",
135 "procgen.pcgMeshLod"));
136 const int vertices = mesh.getVertexCount(), indices = mesh.getIndexCount();
137 if (vertices <= 0 || indices <= 0 || indices % 3 != 0 ||
138 mesh.positions().size() != static_cast<std::size_t>(vertices) * 3U ||
139 mesh.normals().size() != static_cast<std::size_t>(vertices) * 3U ||
140 mesh.uvs().size() != static_cast<std::size_t>(vertices) * 2U ||
141 (mesh.hasVertexColors() && mesh.colors().size() != static_cast<std::size_t>(vertices) * 4U))
143 DiagnosticCode::InvalidArgument, "Pcg mesh combine source streams are invalid", "procgen.pcgMeshLod"));
144 for (float value : transform.matrix_)
145 if (!std::isfinite(value))
147 DiagnosticCode::InvalidArgument, "Pcg mesh combine transform is non-finite", "procgen.pcgMeshLod"));
148 for (std::uint32_t index : mesh.indices())
149 if (index >= static_cast<std::uint32_t>(vertices))
151 "Pcg mesh combine source index is out of range",
152 "procgen.pcgMeshLod"));
153 sources_.push_back(Source{mesh, transform, defaultMaterialId});
154 return Result<void>::success();
155}
156void PcgMeshCombinePlan::clear() noexcept { sources_.clear(); }
157int PcgMeshCombinePlan::getSourceCount() const noexcept { return static_cast<int>(sources_.size()); }
158
160 if (plan.sources_.empty())
162 "Pcg static mesh combine plan is empty", "procgen.pcgMeshLod"));
163 std::uint64_t vertexCount = 0, indexCount = 0;
164 bool anyColors = false;
165 for (const auto& source : plan.sources_) {
166 vertexCount += static_cast<std::uint64_t>(source.mesh.getVertexCount());
167 indexCount += static_cast<std::uint64_t>(source.mesh.getIndexCount());
168 anyColors = anyColors || source.mesh.hasVertexColors();
169 }
170 if (vertexCount > 8U * 1024U * 1024U || indexCount > 48U * 1024U * 1024U ||
171 vertexCount > static_cast<std::uint64_t>(std::numeric_limits<int>::max()) ||
172 indexCount > static_cast<std::uint64_t>(std::numeric_limits<int>::max()))
174 "Pcg static mesh combine output exceeds native mesh budgets",
175 "procgen.pcgMeshLod"));
176 MeshBuild candidate;
177 candidate.reserve(static_cast<int>(vertexCount), static_cast<int>(indexCount));
178 std::vector<float> colors;
179 if (anyColors) colors.reserve(static_cast<std::size_t>(vertexCount) * 4U);
180 struct Bucket {
181 std::string material;
182 std::vector<std::uint32_t> indices;
183 };
184 std::vector<Bucket> buckets;
185 std::unordered_map<std::string, std::size_t> materialMap;
186 std::uint32_t vertexOffset = 0;
187 for (const auto& source : plan.sources_) {
188 const auto& mesh = source.mesh;
189 const auto& m = source.transform.matrix_;
190 for (int vertex = 0; vertex < mesh.getVertexCount(); ++vertex) {
191 const float x = mesh.getPositionX(vertex), y = mesh.getPositionY(vertex), z = mesh.getPositionZ(vertex);
192 const float nx = mesh.getNormalX(vertex), ny = mesh.getNormalY(vertex), nz = mesh.getNormalZ(vertex);
193 const float px = m[0] * x + m[1] * y + m[2] * z + m[3], py = m[4] * x + m[5] * y + m[6] * z + m[7];
194 const float pz = m[8] * x + m[9] * y + m[10] * z + m[11];
195 const float tx = m[0] * nx + m[1] * ny + m[2] * nz, ty = m[4] * nx + m[5] * ny + m[6] * nz;
196 const float tz = m[8] * nx + m[9] * ny + m[10] * nz;
197 if (!std::isfinite(px) || !std::isfinite(py) || !std::isfinite(pz) || !std::isfinite(tx) ||
198 !std::isfinite(ty) || !std::isfinite(tz))
200 DiagnosticCode::InvalidArgument, "Pcg static mesh transform overflowed", "procgen.pcgMeshLod"));
201 candidate.addVertex(px, py, pz, tx, ty, tz, mesh.getUvU(vertex), mesh.getUvV(vertex));
202 if (anyColors)
203 for (int component = 0; component < 4; ++component)
204 colors.push_back(mesh.hasVertexColors() ? mesh.getColor(vertex, component) : 1.F);
205 }
206 for (int triangle = 0; triangle < mesh.getIndexCount() / 3; ++triangle) {
207 const int group = mesh.getTriangleGroup(triangle);
208 std::string material = group >= 0 ? mesh.getGroupName(group) : source.defaultMaterialId;
209 if (material.empty())
211 "Pcg static mesh triangle has no material identity",
212 "procgen.pcgMeshLod"));
213 auto [found, inserted] = materialMap.emplace(material, buckets.size());
214 if (inserted) buckets.push_back(Bucket{material, {}});
215 auto& indices = buckets[found->second].indices;
216 for (int corner = 0; corner < 3; ++corner)
217 indices.push_back(vertexOffset + static_cast<std::uint32_t>(mesh.getIndex(triangle * 3 + corner)));
218 }
219 vertexOffset += static_cast<std::uint32_t>(mesh.getVertexCount());
220 }
221 for (auto& bucket : buckets) {
222 candidate.setActiveGroup(bucket.material);
223 for (std::size_t i = 0; i < bucket.indices.size(); i += 3)
224 candidate.addTriangle(bucket.indices[i], bucket.indices[i + 1], bucket.indices[i + 2]);
225 }
226 if (anyColors) {
227 auto set = candidate.setVertexColors(std::move(colors));
228 if (!set.ok()) return Result<int>::failure(set.status());
229 }
230 candidate.setMeta("kind", "pcg.mesh.combined");
231 candidate.setMeta("sourceCount", std::to_string(plan.sources_.size()));
232 output = std::move(candidate);
233 return Result<int>::success(static_cast<int>(indexCount / 3U));
234}
235Result<void> PcgMeshLodProfile::appendLevel(float transition, float fade, float quality, bool combineMeshes,
236 bool combineSubMeshes) {
237 if (levels_.size() >= 4 || !std::isfinite(transition) || transition < 0.F || transition > 1.F ||
238 !std::isfinite(fade) || fade < 0.F || fade > 1.F || !std::isfinite(quality) || quality < 0.F || quality > 1.F ||
239 (combineSubMeshes && !combineMeshes))
241 "Pcg mesh LOD level values are invalid", "procgen.pcgMeshLod"));
242 if (!levels_.empty() && transition >= levels_.back().screenRelativeTransitionHeight)
244 "Pcg mesh LOD transition heights must be strictly descending",
245 "procgen.pcgMeshLod"));
248 level.fadeTransitionWidth = fade;
249 level.quality = quality;
250 level.combineMeshes = combineMeshes;
251 level.combineSubMeshes = combineSubMeshes;
252 level.simplification.preserveBorderEdges = false;
253 level.simplification.vertexLinkDistance = std::numeric_limits<double>::denorm_min();
254 levels_.push_back(level);
255 return Result<void>::success();
256}
257
258Result<void> PcgMeshLodProfile::setLevelRendererState(int index, int skinQuality, int shadowCastingMode,
259 bool receiveShadows, int motionVectorMode,
260 bool skinnedMotionVectors, int lightProbeUsage,
261 int reflectionProbeUsage) {
262 const bool validSkinQuality = skinQuality == 0 || skinQuality == 1 || skinQuality == 2 || skinQuality == 4;
263 const bool validLightProbe =
265 if (index < 0 || index >= static_cast<int>(levels_.size()) || !validSkinQuality || shadowCastingMode < 0 ||
266 shadowCastingMode > 3 || motionVectorMode < 0 || motionVectorMode > 2 || !validLightProbe ||
267 reflectionProbeUsage < 0 || reflectionProbeUsage > 2)
269 "Pcg mesh LOD renderer state is invalid", "procgen.pcgMeshLod"));
271 state.skinQuality = skinQuality;
272 state.shadowCastingMode = shadowCastingMode;
273 state.receiveShadows = receiveShadows;
274 state.motionVectorMode = motionVectorMode;
275 state.skinnedMotionVectors = skinnedMotionVectors;
276 state.lightProbeUsage = lightProbeUsage;
277 state.reflectionProbeUsage = reflectionProbeUsage;
278 levels_[static_cast<std::size_t>(index)].renderer = state;
279 return Result<void>::success();
280}
281
282int PcgMeshLodProfile::getLevelRendererState(int index, int field) const noexcept {
283 const auto* level = levelAt(index);
284 if (!level || field < 0 || field > 6) return -1;
285 const auto& state = level->renderer;
286 switch (field) {
287 case 0: return state.skinQuality;
288 case 1: return state.shadowCastingMode;
289 case 2: return state.receiveShadows ? 1 : 0;
290 case 3: return state.motionVectorMode;
291 case 4: return state.skinnedMotionVectors ? 1 : 0;
292 case 5: return state.lightProbeUsage;
293 case 6: return state.reflectionProbeUsage;
294 default: return -1;
295 }
296}
297
298Result<void> PcgMeshLodProfile::setFadePolicy(int fadeMode, bool animateCrossFading, float animationDuration) {
299 if ((fadeMode < 0 || fadeMode > 2) || !std::isfinite(animationDuration) || animationDuration <= 0.F ||
300 (animateCrossFading && fadeMode == 0))
302 "Pcg mesh LOD fade policy is invalid", "procgen.pcgMeshLod"));
303 fadeMode_ = fadeMode;
304 animateCrossFading_ = animateCrossFading;
305 crossFadeAnimationDuration_ = animationDuration;
306 return Result<void>::success();
307}
308
310 return index >= 0 && index < static_cast<int>(levels_.size()) ? &levels_[static_cast<std::size_t>(index)] : nullptr;
311}
312
313float PcgMeshLodSet::getTransitionHeight(int index) const noexcept {
314 return index >= 0 && index < static_cast<int>(levels_.size())
315 ? levels_[static_cast<std::size_t>(index)].screenRelativeTransitionHeight
316 : -1.F;
317}
318float PcgMeshLodSet::getFadeWidth(int index) const noexcept {
319 return index >= 0 && index < static_cast<int>(levels_.size())
320 ? levels_[static_cast<std::size_t>(index)].fadeTransitionWidth
321 : -1.F;
322}
323float PcgMeshLodSet::getQuality(int index) const noexcept {
324 return index >= 0 && index < static_cast<int>(levels_.size()) ? levels_[static_cast<std::size_t>(index)].quality
325 : -1.F;
326}
327const MeshBuild* PcgMeshLodSet::meshAt(int index) const noexcept {
328 return index >= 0 && index < static_cast<int>(meshes_.size()) ? &meshes_[static_cast<std::size_t>(index)] : nullptr;
329}
331 return index >= 0 && index < static_cast<int>(levels_.size()) ? &levels_[static_cast<std::size_t>(index)].renderer
332 : nullptr;
333}
334int PcgMeshLodSet::selectLevel(float relativeHeight) const noexcept {
335 if (!std::isfinite(relativeHeight) || relativeHeight < 0.F || levels_.empty()) return -2;
336 for (int i = 0; i < static_cast<int>(levels_.size()); ++i)
337 if (relativeHeight >= levels_[static_cast<std::size_t>(i)].screenRelativeTransitionHeight) return i;
338 return -1;
339}
340float PcgMeshLodSet::getSwitchDistance(int level, float diameter, float fov) const noexcept {
341 if (level < 0 || level >= static_cast<int>(levels_.size()) || !std::isfinite(diameter) || diameter <= 0.F ||
342 !std::isfinite(fov) || fov <= 0.F || fov >= 180.F)
343 return -1.F;
344 constexpr float radians = 0.01745329251994329577F;
345 const float threshold = levels_[static_cast<std::size_t>(level)].screenRelativeTransitionHeight;
346 if (threshold <= 0.F) return -1.F;
347 return diameter / (2.F * std::tan(fov * 0.5F * radians) * threshold);
348}
349
351 const auto& levels = profile.levels();
352 if (source.empty() || levels.empty() || levels.size() > 4)
354 DiagnosticCode::InvalidArgument, "Pcg mesh LOD requires a non-empty mesh and one through four levels",
355 "procgen.pcgMeshLod"));
356 PcgMeshLodSet candidate;
357 candidate.levels_ = levels;
358 candidate.fadeMode_ = profile.getFadeMode();
359 candidate.animateCrossFading_ = profile.getAnimateCrossFading();
360 candidate.crossFadeAnimationDuration_ = profile.getCrossFadeAnimationDuration();
361 candidate.meshes_.reserve(levels.size());
362 for (const PcgMeshLodLevel& level : levels) {
364 auto simplified = simplifyGtsMesh(mesh, source, level.quality, level.simplification);
365 if (!simplified.ok()) return Result<void>::failure(simplified.status());
366 candidate.meshes_.push_back(std::move(mesh));
367 }
368 output = std::move(candidate);
369 return Result<void>::success();
370}
371
373 const PcgMeshLodProfile& profile) {
374 if (profile.levels().empty())
376 "Pcg combined mesh LOD requires at least one level",
377 "procgen.pcgMeshLod"));
378 for (const PcgMeshLodLevel& level : profile.levels())
379 if (!level.combineMeshes)
381 DiagnosticCode::InvalidArgument, "Every Pcg combined mesh LOD level must enable mesh combination",
382 "procgen.pcgMeshLod"));
383 MeshBuild combined;
384 auto combinedResult = combinePcgStaticMeshesInto(combined, plan);
385 if (!combinedResult.ok()) return Result<void>::failure(combinedResult.status());
386 return buildPcgMeshLodsInto(output, combined, profile);
387}
388
389} // namespace eve::procgen
390
391// PcgMeshLodBackup.cpp
392namespace eve::procgen {
393
395 std::optional<graphics::Renderable3D::MeshRenderer> renderer;
396 std::uint32_t entityId = 0;
397 std::uint32_t entityGeneration = 0;
398};
399
400PcgMeshLodBackup::PcgMeshLodBackup() : impl_(std::make_unique<Impl>()) {}
403PcgMeshLodBackup& PcgMeshLodBackup::operator=(PcgMeshLodBackup&&) noexcept = default;
404
405Result<void> PcgMeshLodBackup::capture(graphics::Renderable3D& renderable) {
406 Impl candidate;
407 candidate.renderer = *renderable.meshRenderer();
408 candidate.entityId = renderable.getEntityId();
409 candidate.entityGeneration = renderable.getEntityGeneration();
410 *impl_ = std::move(candidate);
411 return Result<void>::success();
412}
413
415 if (!impl_->renderer)
417 Diagnostic::error(DiagnosticCode::NotFound, "Pcg mesh LOD backup is empty", "procgen.pcgMeshLodBackup"));
418 if (renderable.getEntityId() != impl_->entityId || renderable.getEntityGeneration() != impl_->entityGeneration)
420 "Pcg mesh LOD backup belongs to another entity generation",
421 "procgen.pcgMeshLodBackup"));
422 auto restored = *impl_->renderer;
423 *renderable.meshRenderer() = std::move(restored);
424 discard();
425 return Result<void>::success();
426}
427
429 impl_->renderer.reset();
430 impl_->entityId = 0;
431 impl_->entityGeneration = 0;
432}
433
434bool PcgMeshLodBackup::isCaptured() const noexcept { return impl_->renderer.has_value(); }
435std::uint32_t PcgMeshLodBackup::getEntityId() const noexcept { return impl_->entityId; }
436std::uint32_t PcgMeshLodBackup::getEntityGeneration() const noexcept { return impl_->entityGeneration; }
437
438} // namespace eve::procgen
439
440// PcgTaskQueue.cpp
441namespace eve::procgen {
442namespace {}
444 if (!std::isfinite(wait) || wait < 0)
446 "task wait time must be finite and non-negative", {},
447 {}, "procgen.taskQueue"));
448 const auto id = nextId_++;
449 tasks_.push_back({id, wait, wait});
452}
454 if (!std::isfinite(dt) || dt < 0)
456 "delta time must be finite and non-negative", {},
457 {}, "procgen.taskQueue"));
458 if (status_ == PcgTaskQueueStatus::Ready)
460 "ready task must be resolved before ticking", {},
461 {}, "procgen.taskQueue"));
462 if (tasks_.empty()) {
463 status_ = PcgTaskQueueStatus::Idle;
465 }
466 cursor_ %= tasks_.size();
467 auto& task = tasks_[cursor_];
468 task.remaining -= dt;
469 if (task.remaining <= 1e-12) {
470 readyId_ = task.id;
472 } else
475}
477 if (status_ != PcgTaskQueueStatus::Ready || tasks_.empty())
479 Diagnostic::error(DiagnosticCode::InvalidArgument, "no task is ready", {}, {}, "procgen.taskQueue"));
480 if (finished)
481 tasks_.erase(tasks_.begin() + static_cast<std::ptrdiff_t>(cursor_));
482 else {
483 tasks_[cursor_].remaining = tasks_[cursor_].wait;
484 ++cursor_;
485 }
486 readyId_ = 0;
487 if (tasks_.empty()) {
488 cursor_ = 0;
489 status_ = PcgTaskQueueStatus::Idle;
490 } else {
491 cursor_ %= tasks_.size();
493 }
495}
497 tasks_.clear();
498 cursor_ = 0;
499 readyId_ = 0;
500 return status_ = PcgTaskQueueStatus::Idle;
501}
502void exposePcgTaskQueueBindings(ssq::Table& table) {
503 auto cls = table.addClass("PcgTaskQueue", ssq::Class::Ctor<PcgTaskQueue()>());
504 cls.addFunc("add", [vm = table.getHandle()](PcgTaskQueue* q, float wait) {
505 return eve::script::projectResult(vm, q->add(wait),
506 [](std::uint64_t id) { return eve::Value(static_cast<int64_t>(id)); });
507 });
508 cls.addFunc("tick", [vm = table.getHandle()](PcgTaskQueue* q, float dt) {
509 return eve::script::projectResult(vm, q->tick(dt),
510 [](PcgTaskQueueStatus s) { return eve::Value(static_cast<int>(s)); });
511 });
512 cls.addFunc("resolveReady", [vm = table.getHandle()](PcgTaskQueue* q, bool done) {
513 return eve::script::projectResult(vm, q->resolveReady(done),
514 [](PcgTaskQueueStatus s) { return eve::Value(static_cast<int>(s)); });
515 });
516 cls.addFunc("cancelAll", [](PcgTaskQueue* q) { return static_cast<int>(q->cancelAll()); });
517 cls.addFunc("getReadyTaskId", [](const PcgTaskQueue* q) { return static_cast<int64_t>(q->readyTaskId()); });
518 cls.addFunc("getQueueSize", [](const PcgTaskQueue* q) { return q->queueSize(); });
519 cls.addFunc("getStatus", [](const PcgTaskQueue* q) { return static_cast<int>(q->status()); });
520}
521} // namespace eve::procgen
double z
double y
double m[16]
double x
LogicalId target
std::string output
const std::string & s
glm::vec4 p[6]
HSQUIRRELVM vm
Definition ECS.cpp:38
HSQOBJECT cls
Definition ECS.cpp:39
int triangle
Definition FluidSdf.cpp:554
std::uint32_t vertexCount
float maximum[3]
float minimum[3]
std::uint32_t indexCount
std::array< double, 10 > q
std::vector< std::uint32_t > indices
float v
std::int32_t c
std::vector< Colorf > px
std::array< float, 3 > scale
std::string id
bool done
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
int level
ScriptMotionSinkStore< ScriptMotionSink< MotionColorTraits > > colors
OceanMeshSettings mesh
std::shared_ptr< OceanRenderer > renderer
double dt
std::array< uint32_t, 16 > material
Object::Ptr value
float d
float t
int lightProbeUsage
bool found
std::string_view source
unsigned column
double current
The single Squirrel projection for common Result, Status and Value.
AbilityActivationGroup group
std::array< double, 2 > vertices[3]
uint32_t index
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
EVENGINE_API_BACKENDS public API.
uint32_t getEntityId() const
Return the table-local entity id used with getEntityGeneration().
uint32_t getEntityGeneration() const
Return the generation required to reject stale entity ids.
CPU triangle mesh from procedural mesh recipes (e.g. marching cubes). Positions/normals are xyz-packe...
Definition MeshBuild.h:20
void addVertex(float px, float py, float pz, float nx, float ny, float nz, float u, float v)
Adds vertex.
Definition MeshBuild.cpp:35
void addTriangle(uint32_t i0, uint32_t i1, uint32_t i2)
Adds triangle.
Definition MeshBuild.cpp:48
void reserve(int vertexCount, int indexCount)
Reserve.
Definition MeshBuild.cpp:22
void setMeta(const std::string &key, const std::string &value)
Sets the meta.
int setActiveGroup(const std::string &name)
Select/create the named group assigned to subsequently added triangles.
Definition MeshBuild.cpp:55
eve::Result< void > setVertexColors(std::vector< float > colors)
Atomically replace the optional packed RGBA stream; empty removes it.
Caller-owned deterministic Pcg frame-rate sampling and quality policy.
PcgTerrainQualityPreset getPreset() const
Copy the current Pcg terrain preset.
Result< int > update(float dt, float timeScale)
Add one rendered frame from caller-provided timing and return the selected level.
Result< void > configure(int target, float interval, int minimum, int maximum, int current)
Configure target, check interval, inclusive quality range, and initial level atomically.
Result< void > selectManualQuality(int q)
Select a level and disable automatic changes.
Owned ordered input plan for Pcg static MeshCombiner.
Definition PcgMeshLod.h:64
void clear() noexcept
Remove every owned source.
int getSourceCount() const noexcept
Return the ordered source count.
Result< void > appendSource(const MeshBuild &mesh, const PcgMeshTransform &transform, const std::string &defaultMaterialId)
Copy one readable mesh and root-relative affine transform into the plan.
Caller-owned transactional backup of one Renderable3D renderer before Pcg LOD replacement.
void discard() noexcept
Forget the snapshot without changing its entity.
~PcgMeshLodBackup()
Pcg mesh lod backup.
Result< void > restore(graphics::Renderable3D &renderable)
Restore and consume the backup after exact entity-generation validation.
bool isCaptured() const noexcept
Return whether a restorable snapshot is present.
std::uint32_t getEntityGeneration() const noexcept
Return the captured ECS generation, or zero when empty.
std::uint32_t getEntityId() const noexcept
Return the captured table-local entity id, or zero when empty.
Mutable value profile for at most four native renderer LOD levels.
Definition PcgMeshLod.h:97
const std::vector< PcgMeshLodLevel > & levels() const noexcept
Borrow all levels for synchronous native compilation. @ownership The profile retains ownership....
Definition PcgMeshLod.h:129
bool getAnimateCrossFading() const noexcept
Return whether transitions advance from injected dt.
Definition PcgMeshLod.h:115
int getLevelRendererState(int index, int field) const noexcept
Return one renderer state field (0..6), or -1 for invalid input.
const PcgMeshLodLevel * levelAt(int index) const noexcept
Return an immutable level, or null for an invalid index. @ownership The profile retains ownership....
float getCrossFadeAnimationDuration() const noexcept
Return time-driven transition duration in seconds.
Definition PcgMeshLod.h:117
Result< void > setLevelRendererState(int index, int skinQuality, int shadowCastingMode, bool receiveShadows, int motionVectorMode, bool skinnedMotionVectors, int lightProbeUsage, int reflectionProbeUsage)
Replace one level's renderer policy after validating every Pcg enum value.
Result< void > appendLevel(float transitionHeight, float fadeWidth, float quality, bool combineMeshes=false, bool combineSubMeshes=false)
Append one level after validating its scalar ranges.
Result< void > setFadePolicy(int fadeMode, bool animateCrossFading, float animationDuration=0.5F)
Configure Unity LODFadeMode (0 None, 1 SpeedTree, 2 CrossFade) and optional time animation.
int getFadeMode() const noexcept
Return configured Unity LODFadeMode.
Definition PcgMeshLod.h:113
Owned generic mesh LOD output generated with Pcg's independent-per-level policy.
Definition PcgMeshLod.h:144
float getQuality(int index) const noexcept
Return one level's quality, or -1 for an invalid index.
int selectLevel(float relativeHeight) const noexcept
Select a level from projected relative height; -1 means culled and -2 invalid input.
const PcgMeshLodRendererState * rendererStateAt(int index) const noexcept
Borrow one generated level's immutable renderer state, or null.
float getTransitionHeight(int index) const noexcept
Return one level's transition height, or -1 for an invalid index.
const MeshBuild * meshAt(int index) const noexcept
Borrow a generated mesh, or null for an invalid index. @ownership The set retains ownership....
float getSwitchDistance(int level, float worldDiameter, float verticalFovDegrees) const noexcept
Convert one level threshold to camera distance, or -1 for invalid input.
float getFadeWidth(int index) const noexcept
Return one level's fade width, or -1 for an invalid index.
Row-major affine matrix used by Pcg's root-relative static mesh combination.
Definition PcgMeshLod.h:43
PcgMeshTransform() noexcept
Construct an identity transform.
float getElement(int row, int column) const noexcept
Return one element, or zero for an invalid coordinate.
Result< void > setElement(int row, int column, float value)
Set one finite row/column element in the 4x4 matrix.
Deterministic, callback-free port of PcgTask's delayed task queue.
Result< std::uint64_t > add(double waitSeconds=0.25)
Append a task with Pcg's default 0.25-second delay unless overridden.
Result< PcgTaskQueueStatus > resolveReady(bool finished)
Resolve the ready task; finished tasks are removed, unfinished tasks await their next pass.
Result< PcgTaskQueueStatus > tick(double deltaSeconds)
Advance injected time and publish at most one due task.
PcgTaskQueueStatus cancelAll() noexcept
Cancel every queued task and return Idle.
void exposePcgFrameRateManagerBindings(ssq::Table &t)
Register Pcg frame-rate manager bindings.
PcgTaskQueueStatus
Observable state of Pcg's delayed task processor.
Result< int > simplifyGtsMesh(MeshBuild &output, const MeshBuild &source, float quality, const GtsMeshSimplificationOptions &o)
Simplify a mesh with deterministic quadric edge collapse.
void exposePcgTaskQueueBindings(ssq::Table &table)
Register PcgTaskQueue Squirrel bindings.
Result< int > combinePcgStaticMeshesInto(MeshBuild &output, const PcgMeshCombinePlan &plan)
Combine static meshes with Pcg material deduplication and root-relative transforms.
Result< void > buildPcgCombinedMeshLodsInto(PcgMeshLodSet &output, const PcgMeshCombinePlan &plan, const PcgMeshLodProfile &profile)
Combine an ordered static-renderer plan and generate every combined LOD atomically.
Result< void > buildPcgMeshLodsInto(PcgMeshLodSet &output, const MeshBuild &source, const PcgMeshLodProfile &profile)
Generate a complete generic Pcg LOD chain and publish it atomically.
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
std::optional< graphics::Renderable3D::MeshRenderer > renderer
One UnityMeshSimplifierPcg LOD level translated to native mesh settings.
Definition PcgMeshLod.h:80
Pcg/Unity renderer policies retained per generated mesh LOD.
Definition PcgMeshLod.h:32
Terrain quality values selected by Pcg's six-level frame-rate manager.
uint32_t bucket