载入中...
搜索中...
未找到
VegetationScriptBindings.cpp
浏览该文件的文档.
2#include <functional>
3#include <memory>
4#include <simplesquirrel/simplesquirrel.hpp>
7#include "graphics/Graphics.h"
10
11namespace eve::graphics {
12namespace {
13Value vector(glm::vec4 v) { return Value::array({v.x, v.y, v.z, v.w}); }
14} // namespace
15void exposeVegetationScriptBindings(ssq::Table& table, ssq::Class& graphicsClass) {
16 const auto vm = table.getHandle();
17 auto cls = table.addClass<VegetationField>("VegetationField",
18 std::function<VegetationField*()>([] { return nullptr; }), false);
19 graphicsClass.addFunc("newVegetationField", [vm](Graphics*) {
20 auto owned = script::makeOwnedSquirrelInstance(vm, std::make_unique<VegetationField>());
21 if (!owned.ok()) return script::projectStatusResult(vm, owned.status());
22 auto result = script::projectStatusResult(vm, Status::success(), std::move(owned).takeValue());
23 result.set("ownership", std::string("owned"));
24 return result;
25 });
26 cls.addFunc("restore", [vm](VegetationField* self, ssq::Object document) {
28 Diagnostic::error(DiagnosticCode::InvalidArgument, "vegetation field must not be null")));
29 auto input = script::valueFromSquirrel(document);
30 if (!input.ok()) return script::projectResult(vm, Result<void>::failure(input.status()));
31 return script::projectResult(vm, self->restore(input.value()));
32 });
33 cls.addFunc("snapshot", [vm](VegetationField* self) {
35 Diagnostic::error(DiagnosticCode::InvalidArgument, "vegetation field must not be null")));
36 return script::projectResult(vm, self->snapshot(), [](Value value) { return value; });
37 });
38 cls.addFunc("sample", [vm](VegetationField* self, float x, float y, float z, int color, int extras, int motion,
39 int vertex) {
41 Diagnostic::error(DiagnosticCode::InvalidArgument, "vegetation field must not be null")));
42 if (color < 0 || color > 8 || extras < 0 || extras > 8 || motion < 0 || motion > 8 || vertex < 0 || vertex > 8)
44 "layers must be in [0,8]")));
46 vm, self->sample({x, y, z}, {uint8_t(color), uint8_t(extras), uint8_t(motion), uint8_t(vertex)}),
48 return Value::object({{"color", vector(value.color)},
49 {"extras", vector(value.extras)},
50 {"motion", vector(value.motion)},
51 {"vertex", vector(value.vertex)}});
52 });
53 });
54
55 auto detailsClass = table.addClass<VegetationDetailSettings>(
56 "VegetationDetails", std::function<VegetationDetailSettings*()>([] { return nullptr; }), false);
57 graphicsClass.addFunc("newVegetationDetails", [vm](Graphics*) {
58 auto owned = script::makeOwnedSquirrelInstance(vm, std::make_unique<VegetationDetailSettings>());
59 if (!owned.ok()) return script::projectStatusResult(vm, owned.status());
60 auto result = script::projectStatusResult(vm, Status::success(), std::move(owned).takeValue());
61 result.set("ownership", std::string("owned"));
62 return result;
63 });
64 detailsClass.addFunc("restore", [vm](VegetationDetailSettings* self, ssq::Object document) {
66 Diagnostic::error(DiagnosticCode::InvalidArgument, "vegetation details must not be null")));
67 auto input = script::valueFromSquirrel(document);
68 if (!input.ok()) return script::projectResult(vm, Result<void>::failure(input.status()));
69 auto restored = restoreVegetationDetails(input.value());
70 if (!restored.ok()) return script::projectResult(vm, Result<void>::failure(restored.status()));
71 *self = std::move(restored).takeValue();
73 });
74 detailsClass.addFunc("snapshot", [vm](VegetationDetailSettings* self) {
76 Diagnostic::error(DiagnosticCode::InvalidArgument, "vegetation details must not be null")));
77 return script::projectResult(vm, snapshotVegetationDetails(*self), [](Value value) { return value; });
78 });
79}
80} // namespace eve::graphics
double value
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
ActiveSource owned
HSQUIRRELVM vm
Definition ECS.cpp:20
HSQOBJECT cls
Definition ECS.cpp:21
EvpackChunkInput input
Definition Evpack.cpp:170
float v
The single Squirrel projection for common Result, Status and Value.
Explicit Value/Owned/Borrowed semantics at the Squirrel boundary.
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
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
static Value array(Array value)
Compatibility factory for an array value.
Definition Value.h:112
Backend-independent, owning vegetation influence field. Single writer; concurrent const evaluation is...
Result< void > restore(const Value &document)
Decode eve.graphics.vegetation-field version 1; rejects unknown fields/versions. Single-writer,...
Result< VegetationSample > sample(glm::vec3 position, std::array< uint8_t, 4 > layers={}) const
Evaluate four independently selected layers (0..8) at a finite world position.
Result< Value > snapshot() const
Owning versioned snapshot; thread-safe while no mutation occurs. No callbacks.
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:26
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
Result< VegetationDetailSettings > restoreVegetationDetails(const Value &document)
Decode one exact Global Details document transactionally.
Result< Value > snapshotVegetationDetails(const VegetationDetailSettings &settings)
Encode one owning Global Details document using eve.graphics.vegetation-details/1.
void exposeVegetationScriptBindings(ssq::Table &table, ssq::Class &graphicsClass)
Register vegetation field bindings on the VM owner thread. Borrows tables for this call; no script ca...
ssq::Table projectStatusResult(HSQUIRRELVM vm, const Status &status)
Project a checked native status that carries no payload.
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
eve::Result< ssq::Object > makeOwnedSquirrelInstance(HSQUIRRELVM vm, Owned< T > object)
Creates a Squirrel instance that owns a C++ wrapper through a release hook.
Result< Value > valueFromSquirrel(HSQUIRRELVM vm, SQInteger index, const SquirrelValueOptions &options)
Convert one Squirrel value into the canonical owning Value tree.
Owning sampled field channels; no lifetime dependency on the field.
glm::vec4 color