载入中...
搜索中...
未找到
PixelWorldPhysicsModule.cpp
浏览该文件的文档.
2
4
5#include <simplesquirrel/simplesquirrel.hpp>
6
7#include <functional>
8#include <stdexcept>
9
11
13
17
18void PixelWorldPhysics::expose(ssq::Table& table) {
19 auto module = table.addClass(name, PixelWorldPhysics::create, false);
20 expose(module);
21
22 auto cache = table.addClass<PixelTerrainCollisionCache>(
23 "PixelTerrainCollisionCache",
24 std::function<PixelTerrainCollisionCache*()>([]() -> PixelTerrainCollisionCache* { return nullptr; }), true);
25 cache.addFunc("sync", [](PixelTerrainCollisionCache* self, eve::physics::World* physics,
26 eve::pixelworld::PixelWorld* pixels, int maximumFixtures) {
27 if (!self || !physics || !pixels) throw std::runtime_error("terrain sync requires cache and live worlds");
28 if (maximumFixtures <= 0) throw std::runtime_error("maximumFixtures must be positive");
29 auto result = self->sync(*physics, *pixels, static_cast<std::uint32_t>(maximumFixtures));
30 if (!result) throw std::runtime_error(result.status().describe());
31 return int(result.value().fixturesCreated);
32 });
33 cache.addFunc("clear", [](PixelTerrainCollisionCache* self, eve::physics::World* physics) {
34 if (!self || !physics) throw std::runtime_error("terrain clear requires cache and live physics world");
35 auto result = self->clearPhysics(*physics);
36 if (!result) throw std::runtime_error(result.status().describe());
37 });
38 cache.addFunc("getSourceRevision", [](PixelTerrainCollisionCache* self) {
39 return std::int64_t(self ? self->sourceRevision() : 0);
40 });
41 cache.addFunc("getBodyCount", [](PixelTerrainCollisionCache* self) {
42 return int(self ? self->bodyCount() : 0);
43 });
44}
45
46void PixelWorldPhysics::expose(ssq::Class& cls) {
47 cls.addFunc("newTerrainCache", &PixelWorldPhysics::newTerrainCache);
48}
49
50} // namespace eve::pixelworld_physics
HSQOBJECT cls
Definition ECS.cpp:21
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:26
uint8_t * pixels
Box2D world wrapper (2D physics) with pixel-space coordinates. Handles stepping, gravity,...
Definition World.h:41
Sparse, chunked, deterministic 2D falling-material world.
Definition PixelWorld.h:224
Incremental static collision projection of authoritative PixelWorld chunks.
Script-facing owner for PixelWorld-to-Box2D terrain projection.
PixelTerrainCollisionCache * newTerrainCache()
Create a caller-owned incremental terrain collision cache. @ownership Ownership transfers to the scri...