载入中...
搜索中...
未找到
ProcgenHandles.cpp
浏览该文件的文档.
2#include "procgen/Procgen.h"
6
7#include "common/Capability.h"
12
13#include "image/ImageData.h"
14
19
20#include <simplesquirrel/simplesquirrel.hpp>
21
22#include <any>
23#include <cstdint>
24#include <functional>
25#include <memory>
26#include <mutex>
27#include <optional>
28#include <unordered_map>
29#include <utility>
30#include <vector>
31
32namespace eve::procgen {
33
35 Procgen* module = Procgen::create();
36 return module->ownership_->params.emplace(std::make_unique<Params>());
37}
38
40 Procgen* module = liveProcgen();
41 if (!module) return {};
42 return module->ownership_->params.resolve(reference);
43}
44
46 Procgen* module = liveProcgen();
47 if (!module)
49 eve::DiagnosticCode::StaleHandle, "Procgen module is no longer loaded", "params", {}, "procgen.squirrel"));
50 return module->ownership_->params.erase(reference);
51}
52
54 if (!reference.isValid()) return false;
55 Procgen* module = liveProcgen();
56 return !module || module->ownership_->params.isStale(reference);
57}
58
60 Procgen* module = Procgen::create();
61 return ownProcgenObject(module->ownership_->outputs, std::make_unique<OutputSpec>());
62}
63
65 Procgen* module = liveProcgen();
66 return module ? module->ownership_->outputs.resolve(reference) : eve::script::Borrowed<OutputSpec>();
67}
68
70 Procgen* module = liveProcgen();
71 if (!module)
73 eve::DiagnosticCode::StaleHandle, "Procgen module is no longer loaded", "output", {}, "procgen.squirrel"));
74 return module->ownership_->outputs.erase(reference);
75}
76
78 return reference.isValid() && ownership_->outputs.isStale(reference);
79}
80
82 if (width <= 0 || height <= 0)
84 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "procedural grid dimensions must be positive",
85 "grid", {}, "procgen.squirrel"));
86 auto grid = std::make_unique<Grid2D>();
87 grid->resize(width, height);
88 Procgen* module = Procgen::create();
89 return module->ownership_->grids.emplace(std::move(grid));
90}
91
93 Procgen* module = liveProcgen();
94 if (!module) return {};
95 return module->ownership_->grids.resolve(reference);
96}
97
99 Procgen* module = liveProcgen();
100 if (!module)
102 eve::DiagnosticCode::StaleHandle, "Procgen module is no longer loaded", "grid", {}, "procgen.squirrel"));
103 return module->ownership_->grids.erase(reference);
104}
105
107 if (!reference.isValid()) return false;
108 Procgen* module = liveProcgen();
109 return !module || module->ownership_->grids.isStale(reference);
110}
111
113 return ownProcgenObject(ownership_->points, std::make_unique<PointSet>());
114}
115
119
123
125 return reference.isValid() && ownership_->points.isStale(reference);
126}
127
128
129} // namespace eve::procgen
AuthorityStoreHandleRef reference
Definition Authority.cpp:24
std::uint32_t height
std::uint32_t width
The single Squirrel projection for common Result, Status and Value.
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 failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Procedural generation module. Phase A: runtime maps (semantic Grid2D → TileLayer)....
Definition Procgen.h:159
static bool isStale(ProcgenParamsHandleRef reference) noexcept
Reports whether a parameter reference is stale.
static eve::script::Borrowed< Params > resolve(ProcgenParamsHandleRef reference) noexcept
Resolves parameters as a non-owning observation.
eve::Result< void > releaseOutput(ProcgenOutputHandleRef reference)
Releases an output specification.
eve::Result< ProcgenOutputHandleRef > newOutputHandle()
Allocates an owning output specification.
eve::script::Borrowed< PointSet > resolvePointSet(ProcgenPointSetHandleRef reference) noexcept
Resolves a point set as a borrowed view.
bool isPointSetStale(ProcgenPointSetHandleRef reference) const noexcept
Reports whether a point-set handle is stale.
eve::Result< void > releasePointSet(ProcgenPointSetHandleRef reference)
Releases a point-set intermediate.
eve::Result< ProcgenPointSetHandleRef > newPointSetHandle()
Allocates a point-set intermediate and returns its owner handle.
static eve::Result< ProcgenParamsHandleRef > newParamsHandle()
Allocates module-owned generation parameters.
static eve::Result< void > release(ProcgenParamsHandleRef reference)
Releases module-owned parameters.
eve::script::Borrowed< OutputSpec > resolveOutput(ProcgenOutputHandleRef reference) noexcept
Resolves an output specification as a borrowed view.
bool isOutputStale(ProcgenOutputHandleRef reference) const noexcept
Reports whether an output specification reference is stale.
static eve::Result< ProcgenGridHandleRef > newGridHandle(int width, int height)
Allocates module-owned grid storage and returns its handle.
Non-owning observation of a registry-owned object.
eve::Result< eve::script::RuntimeHandleRef< Tag > > ownProcgenObject(eve::script::RuntimeObjectRegistry< T, Tag > &registry, eve::script::Owned< T > object)