载入中...
搜索中...
未找到
LightningBindings.cpp
浏览该文件的文档.
1#include <functional>
2#include <stdexcept>
5#include "graphics/Graphics.h"
6#include "weather/Lightning.h"
7#include "weather/Weather.h"
8namespace eve::weather {
9void exposeLightning(ssq::Table& table, ssq::Class& weather) {
10 const auto vm = table.getHandle();
11 auto settings = table.addClass("LightningSettings", ssq::Class::Ctor<LightningSettings()>());
12 settings.addVar("width", &LightningSettings::width);
13 settings.addVar("displacement", &LightningSettings::displacement);
14 settings.addVar("duration", &LightningSettings::duration);
15 settings.addVar("subdivisions", &LightningSettings::subdivisions);
16 settings.addVar("branches", &LightningSettings::branches);
17 settings.addVar("variants", &LightningSettings::variants);
18 settings.addVar("seed", &LightningSettings::seed);
19 auto cls = table.addClass<Lightning>("Lightning", std::function<Lightning*()>([]() -> Lightning* {
20 throw std::runtime_error("Use weather.prepareLightning(gfx, settings)");
21 }),
22 false);
23 weather.addFunc("prepareLightning", [vm](Weather*, graphics::Graphics* gfx, LightningSettings* s) {
24 if (!gfx || !s)
27 "weather.lightning")));
28 auto prepared = Lightning::prepare(*gfx, *s);
29 if (!prepared) return script::projectStatusResult(vm, prepared.status());
30 auto owned = script::makeOwnedSquirrelInstance(vm, std::move(prepared).takeValue());
31 if (!owned) return script::projectStatusResult(vm, owned.status());
32 return script::projectStatusResult(vm, Status::success(), std::move(owned).takeValue());
33 });
34 cls.addFunc("setEndpoints", [vm](Lightning* s, float ax, float ay, float az, float bx, float by, float bz) {
35 return script::projectResult(vm, s->setEndpoints(ax, ay, az, bx, by, bz));
36 });
37 cls.addFunc("setColor", [vm](Lightning* s, float r, float g, float b) {
38 return script::projectResult(vm, s->setColor(r, g, b));
39 });
40 cls.addFunc("trigger", [vm](Lightning* s) { return script::projectResult(vm, s->trigger()); });
41 cls.addFunc("update", [vm](Lightning* s, float dt) { return script::projectResult(vm, s->update(dt)); });
42 cls.addFunc("stop", &Lightning::stop);
43 cls.addFunc("amplitude", &Lightning::amplitude);
44}
45} // namespace eve::weather
ActiveSource owned
const std::string & s
HSQUIRRELVM vm
Definition ECS.cpp:38
HSQOBJECT cls
Definition ECS.cpp:39
tensor::Graph g
Definition GpuGraph.cpp:7
double r
MeleePoint3 b
Definition MeleeHit.cpp:41
OceanWakeSettings settings
double dt
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={})
Construct an error diagnostic with the standard error severity.
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
static Status failure(StatusCode code, Diagnostic diagnostic)
Construct a failed status with one diagnostic.
Definition Status.cpp:28
Independently owned, pooled visual effect; main/render thread only, no callbacks or gameplay damage....
Definition Lightning.h:44
float amplitude() const
Current visual amplitude; zero after stop or retirement.
void stop()
Hide immediately; safe after provider/entity retirement.
static Result< std::unique_ptr< Lightning > > prepare(graphics::Graphics &graphics, const LightningSettings &settings)
Validate and prepare hidden geometry; Graphics must be live during this call.
Definition Lightning.cpp:55
Weather module — real-time precipitation / lightning / wind system.
Definition Weather.h:36
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.
void exposeLightning(ssq::Table &table, ssq::Class &weather)
Register preparation/settings and owned Lightning methods on Weather.
Copied preparation settings. Width and displacement are world units, independent of endpoint distance...
Definition Lightning.h:16