载入中...
搜索中...
未找到
WorldSphereSweepScript.cpp
浏览该文件的文档.
3#include "common/ValueRead.h"
4#include "physics/World3D.h"
5
6namespace eve::physics {
7namespace {
8// Script boundary accepts the owning event envelope and ignores unrelated event fields.
9eve::Result<void> applySweepImpulse(World3D& world, const ssq::Object& event, PhysicsVector3D impulse,
10 PhysicsVector3D point) {
11 auto decoded = eve::script::valueFromSquirrel(event);
12 if (!decoded) return eve::Result<void>::failure(decoded.status());
13 const auto* object = decoded.value().getIf<eve::Value::Object>();
14 if (!object)
16 "Expected a physical contact event", "contact"));
17 const char* fields[] = {"worldIndex", "worldGeneration", "bodyIndex", "bodyGeneration", "bodyId"};
18 std::uint32_t parts[5]{};
19 for (std::size_t i = 0; i < 5; ++i) {
20 const auto found = object->find(fields[i]);
21 if (found == object->end())
23 "Missing physical contact identity", fields[i]));
24 auto part = eve::readUInt32Value(found->second);
25 if (!part) return eve::Result<void>::failure(part.status());
26 parts[i] = part.value();
27 }
28 const auto epochField = object->find("worldEpoch");
29 if (epochField == object->end() || parts[4] > static_cast<std::uint32_t>(INT32_MAX))
31 eve::DiagnosticCode::InvalidArgument, "Missing world revision or invalid body ID", "contact"));
32 auto epoch = eve::readInt64Value(epochField->second);
33 if (!epoch) return eve::Result<void>::failure(epoch.status());
34 if (epoch.value() <= 0)
36 "World revision must be positive", "worldEpoch"));
38 contact.identity = {(static_cast<std::uint64_t>(parts[1]) << 32) | parts[0],
39 (static_cast<std::uint64_t>(parts[3]) << 32) | parts[2]};
40 contact.bodyId = static_cast<int>(parts[4]);
41 contact.worldEpoch = static_cast<std::uint64_t>(epoch.value());
42 return world.applySweepContactImpulse(contact, impulse, point);
43}
44} // namespace
45
46ssq::Table projectSweepContactImpulse(World3D* world, const ssq::Object& event, PhysicsVector3D impulse,
48 const auto vm = event.getHandle();
49 if (!world)
52 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "World3D must not be null", "world")));
53 return eve::script::projectResult(vm, applySweepImpulse(*world, event, impulse, point));
54}
55} // namespace eve::physics
std::vector< eve::artifact::PartView > parts
HSQUIRRELVM vm
Definition ECS.cpp:38
std::vector< std::string > fields
Definition ECS.cpp:42
uint64_t epoch
Definition OnnxGpgpu.cpp:28
bool found
The single Squirrel projection for common Result, Status and Value.
Json object
Contact contact
std::array< double, 3 > impulse
glm::vec3 point
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 failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
std::map< std::string, Value > Object
Definition Value.h:34
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:47
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
ssq::Table projectSweepContactImpulse(World3D *world, const ssq::Object &event, PhysicsVector3D impulse, PhysicsVector3D point)
Project an explicit contact impulse through the canonical script Result boundary.
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
Result< Value > valueFromSquirrel(HSQUIRRELVM vm, SQInteger index, const SquirrelValueOptions &options)
Convert one Squirrel value into the canonical owning Value tree.
Result< std::int64_t > readInt64Value(const Value &value)
Read an Int64 without narrowing or numeric coercion.
Definition Value.cpp:57
Result< std::uint32_t > readUInt32Value(const Value &value)
Read an Int64 as a range-checked UInt32 without numeric coercion.
Definition Value.cpp:65
Owning sphere sweep contact; position is the moving sphere center, not the obstacle surface.
WorldSweepIdentity identity
Allocation-free owning three-dimensional physics value.
Definition RigidTypes3D.h:4