载入中...
搜索中...
未找到
DestructionFx.cpp
浏览该文件的文档.
2
3#include "common/Exception.h"
6#include "graphics/Graphics.h"
12
13#include <simplesquirrel/simplesquirrel.hpp>
14
15#include <functional>
16
17namespace eve::physics {
18
20
27
33 auto created = createRenderer(instance);
34 if (!created.ok()) {
35 const auto* diagnostic = created.status().primaryDiagnostic();
36 throw Exception("DestructionFx.createRenderer: %s",
37 diagnostic ? diagnostic->message().c_str() : "creation failed");
38 }
39 return created.value();
40}
41
42namespace {
43
44void drawScript(GeometryCollectionRenderer* self, graphics::Graphics* graphics) {
45 if (!self) throw Exception("GeometryCollectionRenderer.draw: null");
46 auto result = self->draw(graphics);
47 if (!result.ok()) {
48 const auto* diagnostic = result.status().primaryDiagnostic();
49 throw Exception("GeometryCollectionRenderer.draw: %s",
50 diagnostic ? diagnostic->message().c_str() : "draw failed");
51 }
52}
53
54} // namespace
55
56void DestructionFx::expose(ssq::Table& table) {
57 auto cls = table.addClass(name, DestructionFx::create, false);
58 expose(cls);
59
60 auto renderer = table.addClass<GeometryCollectionRenderer>(
61 "GeometryCollectionRenderer",
62 std::function<GeometryCollectionRenderer*()>([]() -> GeometryCollectionRenderer* { return nullptr; }), true);
64 renderer.addFunc("clearInstance", [](GeometryCollectionRenderer* self) { self->setInstance(nullptr); });
65 // Lambda keeps BindingContracts from needing to parse the inline noexcept getter.
66 renderer.addFunc("getInstance",
67 [](GeometryCollectionRenderer* self) -> GeometryCollectionInstance* {
68 return self ? self->getInstance() : nullptr;
69 });
70 renderer.addFunc("setExteriorColor", &GeometryCollectionRenderer::setExteriorColor);
71 renderer.addFunc("setInteriorColor", &GeometryCollectionRenderer::setInteriorColor);
72 renderer.addFunc("setGroupExteriorColor", [vm = table.getHandle()](GeometryCollectionRenderer* self, int groupId,
73 float r, float g, float b, float a) {
74 return script::projectResult(vm, self->setGroupExteriorColor(groupId, r, g, b, a));
75 });
76 renderer.addFunc("setSleepColor", &GeometryCollectionRenderer::setSleepColor);
77 renderer.addFunc("draw", drawScript);
78 renderer.addFunc("preparePlayback",
79 [vm = table.getHandle()](GeometryCollectionRenderer* self, const ssq::Object& playbackObject,
80 graphics::Graphics* graphics) {
81 auto player = collapse_detail::scriptValue<CollapsePlayback>(playbackObject);
82 if (!player) return script::projectResult(vm, Result<void>::failure(player.status()));
83 return script::projectResult(vm, self->preparePlayback(player.value().get(), graphics));
84 });
85 renderer.addFunc("submitPlayback",
86 [vm = table.getHandle()](GeometryCollectionRenderer* self, const ssq::Object& playbackObject) {
87 auto player = collapse_detail::scriptValue<CollapsePlayback>(playbackObject);
88 if (!player) return script::projectResult(vm, Result<void>::failure(player.status()));
89 return script::projectResult(vm, self->submitPlayback(player.value().get()));
90 });
91 renderer.addFunc("prepareAnimation", [vm = table.getHandle()](GeometryCollectionRenderer* self,
92 CollapseAnimation* animation,
93 graphics::Graphics* graphics) {
94 if (!animation)
96 DiagnosticCode::InvalidArgument, "animation required", "animation")));
97 return script::projectResult(vm, self->prepareAnimation(*animation, graphics));
98 });
99 renderer.addFunc("prepareInstance",
100 [vm = table.getHandle()](GeometryCollectionRenderer* self, graphics::Graphics* graphics) {
101 return script::projectResult(vm, self->prepareInstance(graphics));
102 });
103 renderer.addFunc("submitAnimation", [vm = table.getHandle()](GeometryCollectionRenderer* self,
104 CollapseAnimation* animation, float seconds, float x,
105 float y, float z) {
106 if (!animation)
108 DiagnosticCode::InvalidArgument, "animation required", "animation")));
109 return script::projectResult(vm, self->submitAnimation(*animation, seconds, x, y, z));
110 });
111 renderer.addFunc("drawAnimation", [vm = table.getHandle()](
112 GeometryCollectionRenderer* self, CollapseAnimation* animation,
113 graphics::Graphics* graphics, float seconds, float x, float y, float z) {
114 if (!animation)
116 DiagnosticCode::InvalidArgument, "animation required", "animation")));
117 return script::projectResult(vm, self->drawAnimation(*animation, graphics, seconds, x, y, z));
118 });
119 renderer.addFunc("lastActiveDrawCount", [](GeometryCollectionRenderer* self) {
120 return self->lastActiveDrawCount();
121 });
122 renderer.addFunc("lastSleepBatchCount", [](GeometryCollectionRenderer* self) {
123 return self->lastSleepBatchCount();
124 });
125}
126
127void DestructionFx::expose(ssq::Class& cls) {
128 cls.addFunc("createRenderer", &DestructionFx::createRendererScript);
129 cls.addFunc("createAnimationRenderer", [vm = cls.getHandle()](DestructionFx* self) {
130 auto created = self->createAnimationRenderer();
131 if (!created) return script::projectStatusResult(vm, created.status());
132 auto instance =
133 script::makeOwnedSquirrelInstance<GeometryCollectionRenderer>(vm, std::move(created).takeValue());
134 if (!instance) return script::projectStatusResult(vm, instance.status());
135 return script::projectStatusResult(vm, Status::success(), std::move(instance).takeValue());
136 });
137}
138
139} // namespace eve::physics
double z
double y
double x
HSQUIRRELVM vm
Definition ECS.cpp:38
HSQOBJECT cls
Definition ECS.cpp:39
std::string name
Definition ECS.cpp:154
tensor::Graph g
Definition GpuGraph.cpp:7
double r
Poco::JSON::Object::Ptr result
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:27
std::shared_ptr< OceanRenderer > renderer
int created
Graphics * graphics
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.
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
const Status & status() const noexcept
Inspect the structured operation status.
Definition Result.h:521
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
const Diagnostic * primaryDiagnostic() const noexcept
First diagnostic, or null when no diagnostic was supplied.
Definition Status.h:141
Optional presentation satellite for geometry-collection destruction.
eve::Result< GeometryCollectionRenderer * > createRenderer(GeometryCollectionInstance *instance)
Create a presentation renderer that borrows an instance.
GeometryCollectionRenderer * createRendererScript(GeometryCollectionInstance *instance)
Script facade that projects creation failure to an exception. @ownership Script VM owns the returned ...
eve::Result< std::unique_ptr< GeometryCollectionRenderer > > createAnimationRenderer()
Create an owning renderer for physics-independent animation playback.
Runtime owner of bone state, connection strain, and PhysicsLink bindings.
Presentation bridge for a borrowed geometry-collection instance.
void setInteriorColor(float r, float g, float b, float a)
Cut-face RGBA; also used for Detached legacy box bones.
void setExteriorColor(float r, float g, float b, float a)
Exterior-face RGBA; also used for Attached legacy box bones.
eve::Result< void > draw(graphics::Graphics *graphics)
Synchronize caches and draw all bones into the current 3D frame.
void setSleepColor(float r, float g, float b, float a)
Sleeping-batch RGBA.
void setInstance(GeometryCollectionInstance *instance)
Replace the borrowed instance; null disables drawing. @ownership Does not take ownership of instance....
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
std::unordered_map< std::string, SkillDefinition > & table()
Definition Skill.cpp:73
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.