载入中...
搜索中...
未找到
DestructionFx.cpp
浏览该文件的文档.
2
3#include "common/Exception.h"
4#include "graphics/Graphics.h"
7
8#include <simplesquirrel/simplesquirrel.hpp>
9
10#include <functional>
11
12namespace eve::physics {
13
15
22
24 auto created = createRenderer(instance);
25 if (!created.ok()) {
26 const auto* diagnostic = created.status().primaryDiagnostic();
27 throw Exception("DestructionFx.createRenderer: %s",
28 diagnostic ? diagnostic->message().c_str() : "creation failed");
29 }
30 return created.value();
31}
32
33namespace {
34
35void drawScript(GeometryCollectionRenderer* self, graphics::Graphics* graphics) {
36 if (!self) throw Exception("GeometryCollectionRenderer.draw: null");
37 auto result = self->draw(graphics);
38 if (!result.ok()) {
39 const auto* diagnostic = result.status().primaryDiagnostic();
40 throw Exception("GeometryCollectionRenderer.draw: %s",
41 diagnostic ? diagnostic->message().c_str() : "draw failed");
42 }
43}
44
45} // namespace
46
47void DestructionFx::expose(ssq::Table& table) {
48 auto cls = table.addClass(name, DestructionFx::create, false);
49 expose(cls);
50
51 auto renderer = table.addClass<GeometryCollectionRenderer>(
52 "GeometryCollectionRenderer",
53 std::function<GeometryCollectionRenderer*()>([]() -> GeometryCollectionRenderer* { return nullptr; }), true);
54 renderer.addFunc("setInstance", &GeometryCollectionRenderer::setInstance);
55 // Lambda keeps BindingContracts from needing to parse the inline noexcept getter.
56 renderer.addFunc("getInstance",
57 [](GeometryCollectionRenderer* self) -> GeometryCollectionInstance* {
58 return self ? self->getInstance() : nullptr;
59 });
60 renderer.addFunc("setExteriorColor", &GeometryCollectionRenderer::setExteriorColor);
61 renderer.addFunc("setInteriorColor", &GeometryCollectionRenderer::setInteriorColor);
62 renderer.addFunc("setSleepColor", &GeometryCollectionRenderer::setSleepColor);
63 renderer.addFunc("draw", drawScript);
64 renderer.addFunc("lastActiveDrawCount", [](GeometryCollectionRenderer* self) {
65 return self->lastActiveDrawCount();
66 });
67 renderer.addFunc("lastSleepBatchCount", [](GeometryCollectionRenderer* self) {
68 return self->lastSleepBatchCount();
69 });
70}
71
72void DestructionFx::expose(ssq::Class& cls) {
73 cls.addFunc("createRenderer", &DestructionFx::createRendererScript);
74}
75
76} // namespace eve::physics
HSQOBJECT cls
Definition ECS.cpp:21
std::string name
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:26
int created
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
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
const Status & status() const noexcept
Inspect the structured operation status.
Definition Result.h:487
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
const Diagnostic * primaryDiagnostic() const noexcept
First diagnostic, or null when no diagnostic was supplied.
Definition Status.h:135
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 ...
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)
Interior RGBA for Detached bones (broken-face stand-in).
void setExteriorColor(float r, float g, float b, float a)
Exterior RGBA for Attached 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:65