载入中...
搜索中...
未找到
ActionScriptBindings.cpp
浏览该文件的文档.
2
8
9#include <simplesquirrel/simplesquirrel.hpp>
10
11#include <cstdint>
12#include <functional>
13#include <memory>
14#include <string>
15#include <utility>
16
17namespace eve::action {
18namespace {
19
20constexpr const char* kSource = "action.squirrel";
21
22ssq::Table projectValue(HSQUIRRELVM vm, Result<Value>&& result) {
23 return script::projectResult(vm, std::move(result), [](Value value) { return value; });
24}
25
26template <class MemFn, class... Args>
27ssq::Table invoke(const script::BindContext& bind, ScriptActionRuntime* self, MemFn method, Args&&... args) {
28 if (!self) return bind.failInvalid("action runtime must not be null", "runtime");
29 return projectValue(bind.vm(), (self->*method)(std::forward<Args>(args)...));
30}
31
32ssq::Table newRuntime(const script::BindContext& bind) {
33 auto object =
34 script::makeOwnedSquirrelInstance<ScriptActionRuntime>(bind.vm(), std::make_unique<ScriptActionRuntime>());
35 if (!object) return script::projectStatusResult(bind.vm(), object.status());
37 result.set("value", std::move(object).takeValue());
38 result.set("ownership", std::string("owned"));
39 return result;
40}
41
42} // namespace
43
44void exposeActionScriptBindings(ssq::Table& table) {
45 const script::BindContext bind{table.getHandle(), kSource};
46 auto runtime = table.addClass<ScriptActionRuntime>(
47 "ActionRuntime", std::function<ScriptActionRuntime*()>([] { return nullptr; }), true);
48
49 script::bindMethod(runtime, "ownership", [](ScriptActionRuntime*) { return std::string("owned"); });
50 script::bindMethod(runtime, "registerAbilityJson", [bind](ScriptActionRuntime* self, std::string json) {
51 return invoke(bind, self, &ScriptActionRuntime::registerAbilityJson, json);
52 });
53 script::bindMethod(runtime, "replaceAbilityJson", [bind](ScriptActionRuntime* self, std::string json) {
54 return invoke(bind, self, &ScriptActionRuntime::replaceAbilityJson, json);
55 });
57 runtime, "registerTimelineAbility",
58 [bind](ScriptActionRuntime* self, std::string definitionId, std::string timelineJson, float cooldownSeconds,
59 std::string instancing, std::string activationGroup, std::string triggerTag) {
60 return invoke(bind, self, &ScriptActionRuntime::registerTimelineAbility, definitionId, timelineJson,
61 cooldownSeconds, instancing, activationGroup, triggerTag);
62 });
64 runtime, "replaceTimelineAbility",
65 [bind](ScriptActionRuntime* self, std::string definitionId, std::string timelineJson, float cooldownSeconds,
66 std::string instancing, std::string activationGroup, std::string triggerTag) {
67 return invoke(bind, self, &ScriptActionRuntime::replaceTimelineAbility, definitionId, timelineJson,
68 cooldownSeconds, instancing, activationGroup, triggerTag);
69 });
70 script::bindMethod(runtime, "grantAbility",
71 [bind](ScriptActionRuntime* self, std::string owner, std::string definitionId) {
72 return invoke(bind, self, &ScriptActionRuntime::grantAbility, owner, definitionId);
73 });
74 script::bindMethod(runtime, "revokeAbility", [bind](ScriptActionRuntime* self, std::int64_t grantId) {
75 return invoke(bind, self, &ScriptActionRuntime::revokeAbility, grantId);
76 });
77 script::bindMethod(runtime, "activateAbility",
78 [bind](ScriptActionRuntime* self, std::int64_t grantId, std::int64_t tick) {
79 return invoke(bind, self, &ScriptActionRuntime::activateAbility, grantId, tick);
80 });
81 script::bindMethod(runtime, "advanceAbilities",
82 [bind](ScriptActionRuntime* self, std::int64_t tick, float seconds) {
83 return invoke(bind, self, &ScriptActionRuntime::advanceAbilities, tick, seconds);
84 });
85 script::bindMethod(runtime, "cancelAbility",
86 [bind](ScriptActionRuntime* self, std::int64_t activationId, std::int64_t tick) {
87 return invoke(bind, self, &ScriptActionRuntime::cancelAbility, activationId, tick);
88 });
89 script::bindMethod(runtime, "abilityGrant", [bind](ScriptActionRuntime* self, std::int64_t grantId) {
90 return invoke(bind, self, &ScriptActionRuntime::abilityGrant, grantId);
91 });
92 script::bindMethod(runtime, "matchingAbilities",
93 [bind](ScriptActionRuntime* self, std::string owner, std::string eventTag) {
94 return invoke(bind, self, &ScriptActionRuntime::matchingAbilities, owner, eventTag);
95 });
96 script::bindMethod(runtime, "submitAction",
97 [bind](ScriptActionRuntime* self, std::string actionId, std::int64_t windupNs,
98 std::int64_t activeNs, std::int64_t recoverNs, std::int64_t tick) {
99 return invoke(bind, self, &ScriptActionRuntime::submitAction, actionId, windupNs, activeNs,
100 recoverNs, tick);
101 });
102 script::bindMethod(runtime, "advanceAction",
103 [bind](ScriptActionRuntime* self, std::int64_t executionId, std::int64_t tick, float seconds) {
104 return invoke(bind, self, &ScriptActionRuntime::advanceAction, executionId, tick, seconds);
105 });
106 script::bindMethod(runtime, "cancelAction",
107 [bind](ScriptActionRuntime* self, std::int64_t executionId, std::int64_t tick) {
108 return invoke(bind, self, &ScriptActionRuntime::cancelAction, executionId, tick);
109 });
110 script::bindMethod(runtime, "findAction", [bind](ScriptActionRuntime* self, std::int64_t executionId) {
111 return invoke(bind, self, &ScriptActionRuntime::findAction, executionId);
112 });
113 script::bindNullSafe<ScriptActionRuntime>(
114 runtime, "executionCount", [](ScriptActionRuntime& self) { return self.executionCount(); }, std::int64_t{0});
115
116 auto module = table.addClass(Action::name, Action::create, false);
117 script::bindMethod(module, "getName", &Action::getName);
118 script::bindMethod(module, "newRuntime", [bind](Action*) { return newRuntime(bind); });
119}
120
122 const script::BindContext bind{cls.getHandle(), kSource};
124 script::bindMethod(cls, "newRuntime", [bind](Action*) { return newRuntime(bind); });
125}
126
127} // namespace eve::action
Script-facing factory module for action/ability runtimes.
Squirrel bindings for eve.Action / ActionRuntime.
eve::action::ActionExecutionId executionId
struct SQVM * HSQUIRRELVM
HSQUIRRELVM vm
Definition ECS.cpp:38
HSQOBJECT cls
Definition ECS.cpp:39
std::uint16_t method
Poco::JSON::Object::Ptr result
std::shared_ptr< OceanGpuSpectrum > owner
Object::Ptr value
Script-owned projection over ActionRuntime + AbilityRuntime.
Per-translation-unit VM + diagnostic-source helper for Squirrel bindings.
The single Squirrel projection for common Result, Status and Value.
Explicit Value/Owned/Borrowed semantics at the Squirrel boundary.
AbilityInstancingPolicy instancing
SimulationTick tick
virtual std::string getName() const =0
Returns the name.
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
Factory module for script-owned action/ability protocol runtimes.
Owner-thread script façade. Domain rules live on ActionRuntime / AbilityRuntime / AbilityAsset.
Result< Value > replaceTimelineAbility(const std::string &definitionText, const std::string &timelineJson, float cooldownSeconds, const std::string &instancingText, const std::string &groupText, const std::string &triggerTag)
Result< Value > registerTimelineAbility(const std::string &definitionText, const std::string &timelineJson, float cooldownSeconds, const std::string &instancingText, const std::string &groupText, const std::string &triggerTag)
Result< Value > submitAction(const std::string &actionIdText, std::int64_t windupNs, std::int64_t activeNs, std::int64_t recoverNs, std::int64_t tickValue)
Result< Value > revokeAbility(std::int64_t grantValue)
Result< Value > grantAbility(const std::string &ownerId, const std::string &definitionText)
Result< Value > activateAbility(std::int64_t grantValue, std::int64_t tickValue)
Result< Value > cancelAction(std::int64_t executionValue, std::int64_t tickValue)
Result< Value > registerAbilityJson(const std::string &abilityJson)
Result< Value > replaceAbilityJson(const std::string &abilityJson)
Result< Value > advanceAbilities(std::int64_t tickValue, float seconds)
Result< Value > cancelAbility(std::int64_t activationValue, std::int64_t tickValue)
Result< Value > advanceAction(std::int64_t executionValue, std::int64_t tickValue, float seconds)
Result< Value > abilityGrant(std::int64_t grantValue) const
Result< Value > findAction(std::int64_t executionValue) const
Result< Value > matchingAbilities(const std::string &ownerId, const std::string &eventTag) const
Pins the active VM and a stable diagnostic source for one expose() TU.
void exposeActionScriptBindings(ssq::Table &table)
Register eve.Action and the script-owned ActionRuntime class.
ssq::Table projectStatusResult(HSQUIRRELVM vm, const Status &status)
Project a checked native status that carries no payload.
void bindMethod(ssq::Class &cls, const char *name, F &&fn)
Register one script method while keeping a literal name for Binding Contracts.
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.