载入中...
搜索中...
未找到
PointGraphScript.cpp
浏览该文件的文档.
2
6
7#include <simplesquirrel/simplesquirrel.hpp>
8#include <squirrel.h>
9
10#include <functional>
11
12namespace eve::procgen {
13namespace {
14
15SQInteger sqPointGraphConnect(HSQUIRRELVM vm) {
16 const SQInteger n = sq_gettop(vm);
17 if (n < 3 || n > 4) return sq_throwerror(vm, "PointGraph.connect expects (from, to [, inputIndex=0])");
18 PointGraph* self = nullptr;
19 if (SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*>(&self), nullptr)) || !self)
20 return sq_throwerror(vm, "invalid PointGraph");
21 const SQChar* from = nullptr;
22 const SQChar* to = nullptr;
23 SQInteger inputIndex = 0;
24 if (SQ_FAILED(sq_getstring(vm, 2, &from)) || SQ_FAILED(sq_getstring(vm, 3, &to)))
25 return sq_throwerror(vm, "PointGraph.connect expects string node ids");
26 if (n >= 4 && SQ_FAILED(sq_getinteger(vm, 4, &inputIndex)))
27 return sq_throwerror(vm, "PointGraph.connect inputIndex must be an integer");
28 sq_pushbool(vm, self->connect(from ? from : "", to ? to : "", static_cast<int>(inputIndex)) ? SQTrue : SQFalse);
29 return 1;
30}
31
32SQInteger sqPointGraphDisconnect(HSQUIRRELVM vm) {
33 const SQInteger n = sq_gettop(vm);
34 if (n < 2 || n > 3) return sq_throwerror(vm, "PointGraph.disconnect expects (to [, inputIndex=0])");
35 PointGraph* self = nullptr;
36 if (SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*>(&self), nullptr)) || !self)
37 return sq_throwerror(vm, "invalid PointGraph");
38 const SQChar* to = nullptr;
39 SQInteger inputIndex = 0;
40 if (SQ_FAILED(sq_getstring(vm, 2, &to))) return sq_throwerror(vm, "PointGraph.disconnect expects a string node id");
41 if (n >= 3 && SQ_FAILED(sq_getinteger(vm, 3, &inputIndex)))
42 return sq_throwerror(vm, "PointGraph.disconnect inputIndex must be an integer");
43 sq_pushbool(vm, self->disconnect(to ? to : "", static_cast<int>(inputIndex)) ? SQTrue : SQFalse);
44 return 1;
45}
46
47void addOptionalTrailingInt(ssq::Class& cls, const char* name, SQFUNCTION func, SQInteger minParams,
48 const SQChar* typemask) {
49 HSQUIRRELVM vm = cls.getHandle();
50 sq_pushobject(vm, cls.getRaw());
51 sq_pushstring(vm, name, -1);
52 sq_newclosure(vm, func, 0);
53 sq_setparamscheck(vm, -minParams, typemask);
54 sq_newslot(vm, -3, SQFalse);
55 sq_poptop(vm);
56}
57
58} // namespace
59
60void exposePointGraph(ssq::Table& table) {
61 auto graph = table.addClass<PointGraph>(
62 "ProcgenPointGraph", std::function<PointGraph*()>([]() -> PointGraph* { return nullptr; }),
63 true);
64 graph.addFunc("addNode", &PointGraph::addNode);
65 graph.addFunc("removeNode", &PointGraph::removeNode);
66 graph.addFunc("hasNode", &PointGraph::hasNode);
67 graph.addFunc("getNodeCount", &PointGraph::getNodeCount);
68 graph.addFunc("getNodeId", &PointGraph::getNodeId);
69 graph.addFunc("getNodeOperation", &PointGraph::getNodeOperation);
70 addOptionalTrailingInt(graph, "connect", sqPointGraphConnect, 3, _SC("xssi"));
71 addOptionalTrailingInt(graph, "disconnect", sqPointGraphDisconnect, 2, _SC("xsi"));
72 graph.addFunc("getInputNode", &PointGraph::getInputNode);
73 graph.addFunc("setNodePoints", &PointGraph::setNodePoints);
74 graph.addFunc("setNodeSpatial", &PointGraph::setNodeSpatial);
75 graph.addFunc("setNodeBiomeRules", &PointGraph::setNodeBiomeRules);
76 graph.addFunc("setNodeShapeGrammar", &PointGraph::setNodeShapeGrammar);
77 graph.addFunc("setNodeFloat", &PointGraph::setNodeFloat);
78 graph.addFunc("setNodeInt", &PointGraph::setNodeInt);
79 graph.addFunc("setNodeString", &PointGraph::setNodeString);
80 graph.addFunc("exposeParameter", &PointGraph::exposeParameter);
81 graph.addFunc("getParameterCount", &PointGraph::getParameterCount);
82 graph.addFunc("getParameterName", &PointGraph::getParameterName);
83 graph.addFunc("getParameterKind", &PointGraph::getParameterKind);
84 graph.addFunc("hasParameterOverride", &PointGraph::hasParameterOverride);
85 graph.addFunc("setParameterFloat", &PointGraph::setParameterFloat);
86 graph.addFunc("setParameterInt", &PointGraph::setParameterInt);
87 graph.addFunc("setParameterString", &PointGraph::setParameterString);
88 graph.addFunc("getParameterFloat", &PointGraph::getParameterFloat);
89 graph.addFunc("getParameterInt", &PointGraph::getParameterInt);
90 graph.addFunc("getParameterString", &PointGraph::getParameterString);
91 graph.addFunc("clearParameterOverride", &PointGraph::clearParameterOverride);
92 graph.addFunc("setNodeSubgraph", &PointGraph::setNodeSubgraph);
93 graph.addFunc("execute", &PointGraph::execute);
94 graph.addFunc("executeResult", [vm = graph.getHandle()](PointGraph* self, const std::string& output) {
95 auto result = self->executeResult(output);
96 if (!result.ok()) return eve::script::projectStatusResult(vm, result.status());
97 auto instance = eve::script::makeOwnedSquirrelInstance<PointSet>(
98 vm, std::make_unique<PointSet>(std::move(result).takeValue()));
99 if (!instance.ok()) return eve::script::projectStatusResult(vm, instance.status());
100 return eve::script::projectStatusResult(vm, Status::success(), std::move(instance).takeValue());
101 });
102 graph.addFunc("validateResult", [vm = graph.getHandle()](PointGraph* self) {
103 return eve::script::projectResult(vm, self->validateResult());
104 });
105 graph.addFunc("setExecutionNodeBudget", &PointGraph::setExecutionNodeBudget);
106 graph.addFunc("getExecutionNodeBudget", &PointGraph::getExecutionNodeBudget);
107 graph.addFunc("setMaxNodeOutputPoints", &PointGraph::setMaxNodeOutputPoints);
108 graph.addFunc("getMaxNodeOutputPoints", &PointGraph::getMaxNodeOutputPoints);
109 graph.addFunc("setComputePolicy", &PointGraph::setComputePolicy);
110 graph.addFunc("getComputePolicy", &PointGraph::getComputePolicy);
111 graph.addFunc("setComputeMinimumPoints", &PointGraph::setComputeMinimumPoints);
112 graph.addFunc("getComputeMinimumPoints", &PointGraph::getComputeMinimumPoints);
113 graph.addFunc("requestCancel", &PointGraph::requestCancel);
114 graph.addFunc("resetCancellation", &PointGraph::resetCancellation);
115 graph.addFunc("wasCancelled", &PointGraph::wasCancelled);
116 graph.addFunc("validate", &PointGraph::validate);
117 graph.addFunc("getError", &PointGraph::getError);
118 graph.addFunc("clearCache", &PointGraph::clearCache);
119 graph.addFunc("getRevision", &PointGraph::getRevision);
120 graph.addFunc("getExecutionCount", &PointGraph::getExecutionCount);
121 graph.addFunc("getCacheHitCount", &PointGraph::getCacheHitCount);
122 graph.addFunc("getCompiledSegmentCount", &PointGraph::getCompiledSegmentCount);
123 graph.addFunc("getExecutionPlanBuildCount", &PointGraph::getExecutionPlanBuildCount);
124 graph.addFunc("getMetricCount", &PointGraph::getMetricCount);
125 graph.addFunc("getMetricNodeId", &PointGraph::getMetricNodeId);
126 graph.addFunc("getMetricOutputCount", &PointGraph::getMetricOutputCount);
127 graph.addFunc("getMetricMilliseconds", &PointGraph::getMetricMilliseconds);
128 graph.addFunc("isMetricCacheHit", &PointGraph::isMetricCacheHit);
129 graph.addFunc("getMetricBackend", &PointGraph::getMetricBackend);
130 graph.addFunc("getComputeFallbackReason", &PointGraph::getComputeFallbackReason);
131 graph.addFunc("getComputeUploadCount", &PointGraph::getComputeUploadCount);
132 graph.addFunc("getComputeDispatchCount", &PointGraph::getComputeDispatchCount);
133 graph.addFunc("getComputeReadbackCount", &PointGraph::getComputeReadbackCount);
134 graph.addFunc("getComputeBufferReuseCount", &PointGraph::getComputeBufferReuseCount);
135 graph.addFunc("getComputePeakBufferBytes", &PointGraph::getComputePeakBufferBytes);
136 graph.addFunc("getLastFusedTransformCount", &PointGraph::getLastFusedTransformCount);
137 graph.addFunc("getMetricMinX", &PointGraph::getMetricMinX);
138 graph.addFunc("getMetricMinY", &PointGraph::getMetricMinY);
139 graph.addFunc("getMetricMinZ", &PointGraph::getMetricMinZ);
140 graph.addFunc("getMetricMaxX", &PointGraph::getMetricMaxX);
141 graph.addFunc("getMetricMaxY", &PointGraph::getMetricMaxY);
142 graph.addFunc("getMetricMaxZ", &PointGraph::getMetricMaxZ);
143 graph.addFunc("getMetricAverageDensity", &PointGraph::getMetricAverageDensity);
144 graph.addFunc("getNodeOutput", &PointGraph::getNodeOutput);
145 graph.addFunc("debugReport", &PointGraph::debugReport);
146 graph.addFunc("serializeDefinition", &PointGraph::serializeDefinition);
147 graph.addFunc("deserializeDefinition", &PointGraph::deserializeDefinition);
148 graph.addFunc("instantiate", &PointGraph::instantiate);
149 graph.addFunc("getOperationCount", [](PointGraph*) { return PointGraph::getOperationCount(); });
150 graph.addFunc("getOperationId",
151 [](PointGraph*, int index) { return PointGraph::getOperationId(index); });
152 graph.addFunc("getOperationInputCount", [](PointGraph*, const std::string& operation) {
154 });
155 graph.addFunc("getOperationParamCount", [](PointGraph*, const std::string& operation) {
157 });
158 graph.addFunc("getOperationParamKey",
159 [](PointGraph*, const std::string& operation, int index) {
161 });
162 graph.addFunc("getOperationParamKind",
163 [](PointGraph*, const std::string& operation, int index) {
165 });
166 graph.addFunc("getOperationParamDefault",
167 [](PointGraph*, const std::string& operation, int index) {
169 });
170}
171
172} // namespace eve::procgen
ActionParameterOperation operation
std::string output
std::string from
struct SQVM * HSQUIRRELVM
HSQUIRRELVM vm
Definition ECS.cpp:20
HSQOBJECT cls
Definition ECS.cpp:21
glm::vec3 n
Definition Grass.cpp:63
HexCoordinates to
Cell the unit walks towards on this segment.
Definition HexUnits.cpp:64
std::string name
std::map< std::string, std::vector< std::string > > graph
Definition Package.cpp:59
The single Squirrel projection for common Result, Status and Value.
Explicit Value/Owned/Borrowed semantics at the Squirrel boundary.
uint32_t index
EVENGINE_API_DOMAINS public API.
Definition PointGraph.h:66
void resetCancellation()
Resets cancellation.
uint64_t getComputePeakBufferBytes() const
Return peak bytes reserved in each reusable point-compute buffer.
static std::string getOperationParamDefault(const std::string &operation, int index)
Returns the operation param default.
bool setParameterFloat(const std::string &name, float value)
Override an exposed floating-point parameter for this graph instance.
float getMetricMinZ(int index) const
Return the cached minimum output Z coordinate.
uint64_t getComputeBufferReuseCount() const
Return executions that reused allocated point-compute buffers.
bool setNodeFloat(const std::string &id, const std::string &key, float value)
Sets the node float.
bool removeNode(const std::string &id)
Remove a node and every edge that references it.
void setExecutionNodeBudget(int nodes)
Limit uncached nodes evaluated by one execute call; zero disables the limit.
PointGraph * instantiate() const
Create an independent runtime instance without external inputs or overrides.
bool exposeParameter(const std::string &name, const std::string &nodeId, const std::string &key)
Expose one reflected node parameter for per-instance overrides.
float getMetricMilliseconds(int index) const
Returns the metric milliseconds.
void clearCache()
Clears cache.
static int getOperationCount()
Returns the operation count.
bool setNodeString(const std::string &id, const std::string &key, const std::string &value)
Sets the node string.
bool wasCancelled() const
Was cancelled.
float getMetricMaxX(int index) const
Return the cached maximum output X coordinate.
int getMetricCount() const
Returns the metric count.
std::string getInputNode(const std::string &nodeId, int inputIndex) const
Returns the input node.
std::string getNodeOperation(const std::string &id) const
Returns the node operation.
std::string serializeDefinition() const
Serialize graph topology, parameters and nested graphs.
uint64_t getRevision() const
Monotonic topology/parameter revision used by asset and preview caches.
std::string getComputeFallbackReason() const
Return why the latest eligible GPU node used the CPU fallback.
int getComputeMinimumPoints() const
Return the minimum point count for automatic GPU dispatch.
PointSet * getNodeOutput(const std::string &id) const
Copy the cached/debug output of a node after execution.
uint64_t getComputeReadbackCount() const
Return successful point-compute readbacks for this graph executor.
void requestCancel()
Cancel subsequent execution until resetCancellation is called.
int getExecutionCount() const
Returns the execution count.
uint64_t getExecutionPlanBuildCount() const
Return how many execution plans this graph instance has compiled.
int getNodeCount() const
Returns the node count.
bool setComputePolicy(const std::string &policy)
Select auto, gpu, or cpu point execution; GPU failures fall back to CPU.
PointSet * execute(const std::string &outputId)
Compatibility-only projection of executeResult; caller deletes the result, nullptr means failure.
int getLastFusedTransformCount() const
Return logical transforms in the latest successful fused dispatch.
bool isMetricCacheHit(int index) const
True when metric cache hit.
std::string getComputePolicy() const
Return the configured point compute policy.
bool validate()
Compatibility-only bool projection of validateResult; diagnostics are rendered by getError().
static int getOperationParamCount(const std::string &operation)
Returns the operation param count.
int getMaxNodeOutputPoints() const
Return the per-node point output limit; zero means unlimited.
bool deserializeDefinition(const std::string &definition)
Transactionally replace this graph from serializeDefinition output.
static std::string getOperationId(int index)
Returns the operation id.
int getExecutionNodeBudget() const
Returns the execution node budget.
std::string getMetricBackend(int index) const
Return cpu, vulkan, or webgpu for one evaluated node.
float getMetricAverageDensity(int index) const
Return the mean point density of one node output.
bool setNodeSubgraph(const std::string &id, PointGraph *graph, const std::string &inputNode, const std::string &outputNode)
Assign an immutable nested graph.
void setMaxNodeOutputPoints(int points)
Limit points produced by any node; zero disables the limit.
int getParameterCount() const
Return the number of exposed graph parameters.
int getCompiledSegmentCount() const
Return logical CPU/GPU segments in the execution plan compiled for the latest output.
float getMetricMinY(int index) const
Return the cached minimum output Y coordinate.
bool setNodeSpatial(const std::string &id, SpatialData *spatial)
Assign copied spatial data to a spatial sample, filter, projection, or biome node.
float getMetricMaxY(int index) const
Return the cached maximum output Y coordinate.
uint64_t getComputeUploadCount() const
Return successful point-compute uploads for this graph executor.
bool clearParameterOverride(const std::string &name)
Remove an instance override and restore the asset default.
static std::string getOperationParamKind(const std::string &operation, int index)
Returns the operation param kind.
float getParameterFloat(const std::string &name, float fallback) const
Return the effective floating-point parameter value.
std::string getParameterName(int index) const
Return an exposed parameter name by stable insertion index.
std::string getError() const
Render the last compatibility execute/validate or legacy authoring error; canonical Result calls do n...
int getCacheHitCount() const
Returns the cache hit count.
std::string getParameterKind(const std::string &name) const
Return the reflected kind of an exposed parameter.
bool hasParameterOverride(const std::string &name) const
Report whether an instance override is active.
bool setNodeInt(const std::string &id, const std::string &key, int value)
Sets the node int.
float getMetricMaxZ(int index) const
Return the cached maximum output Z coordinate.
std::string getMetricNodeId(int index) const
Returns the metric node id.
std::string getNodeId(int index) const
Returns the node id.
float getMetricMinX(int index) const
Return cached output bounds for editor/debug visualization.
bool setNodeShapeGrammar(const std::string &id, ShapeGrammar *grammar)
Assign a copied shape grammar to a grammar.generate node.
bool setNodePoints(const std::string &id, PointSet *points)
Assign a copied PointSet to an input node.
std::string getParameterString(const std::string &name, const std::string &fallback) const
Return the effective string parameter value.
uint64_t getComputeDispatchCount() const
Return successful point-compute dispatches for this graph executor.
bool setParameterString(const std::string &name, const std::string &value)
Override an exposed string parameter for this graph instance.
int getParameterInt(const std::string &name, int fallback) const
Return the effective integer or Boolean parameter value.
static std::string getOperationParamKey(const std::string &operation, int index)
Returns the operation param key.
bool hasNode(const std::string &id) const
True when node.
int getMetricOutputCount(int index) const
Returns the metric output count.
bool setParameterInt(const std::string &name, int value)
Override an exposed integer or Boolean parameter for this graph instance.
bool addNode(const std::string &id, const std::string &operation)
Add a node using one of the operations returned by operationAt().
bool setNodeBiomeRules(const std::string &id, BiomeRules *rules)
Assign copied biome rules to a biome.generate node.
std::string debugReport() const
Debug report.
void setComputeMinimumPoints(int points)
Set the minimum point count for auto GPU dispatch.
static int getOperationInputCount(const std::string &operation)
Returns the operation input count.
void exposePointGraph(ssq::Table &table)
Register PointGraph script types on the Procgen module table.