载入中...
搜索中...
未找到
OceanInteractionCodec.cpp
浏览该文件的文档.
3
4namespace eve::fluids {
5using namespace ocean_codec;
7 return Value::Object{{"resolution", Value(static_cast<std::int64_t>(s.resolution))},
8 {"length", Value(s.length)},
9 {"depth", Value(s.depth)},
10 {"gravity", Value(s.gravity)},
11 {"damping", Value(s.damping)},
12 {"absorptionWidth", Value(s.absorptionWidth)},
13 {"foamDecay", Value(s.foamDecay)},
14 {"center", vector(s.center)}};
15}
17 try {
18 keys(value, {"resolution", "length", "depth", "gravity", "damping", "absorptionWidth", "foamDecay", "center"});
20 const auto& resolution = field(value, "resolution");
21 if (!resolution.isInt64() || resolution.asInt() < 8 || resolution.asInt() > 512)
22 throw std::runtime_error("bounded integer resolution");
23 out.resolution = static_cast<unsigned>(resolution.asInt());
24 out.length = number(field(value, "length"));
25 out.depth = number(field(value, "depth"));
26 out.gravity = number(field(value, "gravity"));
27 out.damping = number(field(value, "damping"));
28 out.absorptionWidth = number(field(value, "absorptionWidth"));
29 out.foamDecay = number(field(value, "foamDecay"));
30 out.center = vector(field(value, "center"));
32 } catch (const std::runtime_error& error) {
34 Diagnostic::error(DiagnosticCode::InvalidArgument, "Invalid ocean wake arguments", error.what()));
35 }
36}
39 for (const auto& c : s.cells)
40 cells.emplace_back(
41 Value::Object{{"center", vector(c.center)}, {"radius", Value(c.radius)}, {"volume", Value(c.volume)}});
42 return Value::Object{{"cells", Value(std::move(cells))},
43 {"waterDensity", Value(s.waterDensity)},
44 {"gravity", Value(s.gravity)},
45 {"drag", vector(s.drag)},
46 {"propeller", vector(s.propeller)},
47 {"thrust", Value(s.thrust)},
48 {"rudderCoefficient", Value(s.rudderCoefficient)}};
49}
51 try {
52 keys(value, {"cells", "waterDensity", "gravity", "drag", "propeller", "thrust", "rudderCoefficient"});
54 out.waterDensity = number(field(value, "waterDensity"));
55 out.gravity = number(field(value, "gravity"));
56 out.drag = vector3(field(value, "drag"));
57 out.propeller = vector3(field(value, "propeller"));
58 out.thrust = number(field(value, "thrust"));
59 out.rudderCoefficient = number(field(value, "rudderCoefficient"));
60 const auto& cells = field(value, "cells");
61 if (!cells.isArray() || cells.arraySize() > 64) throw std::runtime_error("bounded hull cells");
62 for (std::size_t i = 0; i < cells.arraySize(); ++i) {
63 const auto& c = cells.at(i);
64 keys(c, {"center", "radius", "volume"});
65 out.cells.push_back({vector3(field(c, "center")), number(field(c, "radius")), number(field(c, "volume"))});
66 }
67 return Result<OceanHullSettings>::success(std::move(out));
68 } catch (const std::runtime_error& error) {
70 Diagnostic::error(DiagnosticCode::InvalidArgument, "Invalid ocean hull arguments", error.what()));
71 }
72}
73} // namespace eve::fluids
const std::string & s
std::int32_t c
std::string error
Definition Package.cpp:174
std::array< PixelCell, kPixelChunkSize *kPixelChunkSize > cells
Object::Ptr value
double number
ScriptStructure out
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
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
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:27
void keys(const Value &value, std::initializer_list< const char * > names)
glm::dvec3 vector3(const Value &value)
const Value & field(const Value &value, const char *name)
Borrow a required child of value; throws on a missing field.
GLSL compute kernels for the GPU surface-flow solver.
Definition FluidTarget.h:12
Value encodeOceanHullSettings(const OceanHullSettings &s)
Encode owning transient hull arguments; physics links are deliberately absent. @thread Const/reentran...
Result< OceanHullSettings > decodeOceanHullSettings(const Value &value)
Strict structural decode of at most 64 cells; OceanBoat::create validates all physical domains.
Value encodeOceanWakeSettings(const OceanWakeSettings &s)
Encode owning transient wake construction arguments; not a persistent checkpoint. @thread Const/reent...
Result< OceanWakeSettings > decodeOceanWakeSettings(const Value &value)
Strict bounded structural decode; native OceanWake::create owns domain validation.
Hull water response; local +Z forward, +X starboard, +Y up.
Definition OceanBoat.h:20
Local dispersive wave tile, SI units; kept independent of the observing camera.
Definition OceanWake.h:16