载入中...
搜索中...
未找到
OceanBindingInternal.h
浏览该文件的文档.
1#pragma once
2
6
8template <class T>
9ssq::Table ownedPointerResult(HSQUIRRELVM vm, Result<std::unique_ptr<T>> result) {
10 if (!result) return script::projectStatusResult(vm, result.status());
11 auto object = script::makeOwnedSquirrelInstance<T>(vm, std::move(result).takeValue());
12 if (!object) return script::projectStatusResult(vm, object.status());
13 return script::projectStatusResult(vm, Status::success(), std::move(object).takeValue());
14}
15template <class T>
17 if (!result) return script::projectStatusResult(vm, result.status());
19 Result<std::unique_ptr<T>>::success(std::make_unique<T>(std::move(result).takeValue())));
20}
21inline Status invalid(const char* message) {
23}
24struct FixedTime {
25 double time, dt;
26};
28 if (tick < 0 || rate < 30 || rate > 1000 || static_cast<double>(tick) > 1e9 * rate)
30 invalid("Expected nonnegative tick, frequency 30..1000 Hz and time <= 1e9 s"));
31 return Result<FixedTime>::success({static_cast<double>(tick) / rate, 1.0 / rate});
32}
33inline Value vector(glm::dvec3 v) { return Value::Array{Value(v.x), Value(v.y), Value(v.z)}; }
34inline Value sampleValue(const OceanSurfaceSample& sample) {
35 return Value::Object{
36 {"height", Value(sample.height)}, {"normal", vector(sample.normal)}, {"velocity", vector(sample.velocity)}};
37}
38} // namespace eve::fluids::ocean_script
struct SQVM * HSQUIRRELVM
HSQUIRRELVM vm
Definition ECS.cpp:38
std::string message
wgpu::PopErrorScopeStatus status
float v
Poco::JSON::Object::Ptr result
The single Squirrel projection for common Result, Status and Value.
Explicit Value/Owned/Borrowed semantics at the Squirrel boundary.
SimulationTick tick
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
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
Structured status and zero or more diagnostics for an operation.
Definition Status.h:70
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
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::map< std::string, Value > Object
Definition Value.h:34
std::vector< Value > Array
Definition Value.h:33
ssq::Table ownedResult(HSQUIRRELVM vm, Result< T > result)
ssq::Table ownedPointerResult(HSQUIRRELVM vm, Result< std::unique_ptr< T > > result)
Result< FixedTime > fixedTime(SQInteger tick, SQInteger rate)
Status invalid(const char *message)
Value sampleValue(const OceanSurfaceSample &sample)
ssq::Table projectStatusResult(HSQUIRRELVM vm, const Status &status)
Project a checked native status that carries no payload.
Owning sample of the displaced surface at a requested world XZ and time.