Skip to content

Commit 21c2013

Browse files
SunrisepeakSunrisepeak
andauthored
mcpplibs.mwrap.jolt 5.6.0: jolt-m (Jolt Physics, rigid and soft body physics, cross-platform deterministic, as a C++23 module) (#786)
Co-authored-by: Sunrisepeak <speakshen@outlook.com>
1 parent f022b31 commit 21c2013

8 files changed

Lines changed: 235 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Add mcpplibs.mwrap.jolt (jolt-m 5.6.0)
2+
3+
## Form
4+
5+
- Third-party upstream [jrouwe/JoltPhysics](https://github.com/jrouwe/JoltPhysics), release v5.6.0, MIT.
6+
- Form A external mwrap module repository [mcpplibs/jolt-m](https://github.com/mcpplibs/jolt-m), package
7+
`mcpplibs.mwrap.jolt`, version 5.6.0 (the first indexed release of the identity), tag `mwrap-5.6.0`; release asset
8+
`jolt-m-5.6.0.tar.gz` (`ea4b7052…9c49`), CN mirror `gitcode.com/mcpp-res/mwrap-jolt` with identical bytes.
9+
- Implementation ownership: the library has no compat package in this index, so the wrapper vendors `Jolt/` from the
10+
release archive (checksums of every file in `upstream/documents.json`) and builds it as upstream's CMake build does
11+
with `CROSS_PLATFORM_DETERMINISTIC` on (`JPH_CROSS_PLATFORM_DETERMINISTIC`, `-ffp-contract=off`, no fast math),
12+
with `JPH_NO_DEBUG` (the same library and module names in every profile: upstream turns on its asserts and
13+
debug-only members when `NDEBUG` is not defined), and without the parts upstream builds only in its Debug and
14+
Release configurations or as options: no debug renderer, profiler, object stream or GPU compute backend (DX12,
15+
Vulkan, Metal and their CPU emulation are not vendored). The SIMD level is the target's baseline. It deploys
16+
upstream's README and LICENSE with its own LICENSE/NOTICE (`runtime.deploy`). On wasm32 it links with a 1 MiB stack
17+
and growing memory.
18+
19+
## Module
20+
21+
- `mcpplibs.mwrap.jolt`: every name declared at namespace scope in `JPH` and its nested namespaces by the headers under
22+
`<Jolt/…>` (the debug renderer's, the compute shaders' shared C++/HLSL headers and a list of macro invocations
23+
excepted), by `using` in the namespace upstream declares it in — `JPH` (450 types, 127 functions and operators, 6
24+
objects), `ClosestPoint`, `HalfFloatConversion`, `ScaleHelpers`, `StreamUtils`, `literals`.
25+
- Internal-linkage adaptation: 50 `static` or non-`inline` `constexpr` objects (`cMaxPhysicsJobs`,
26+
`cMaxPhysicsBarriers`, `cDefaultConvexRadius`, `JPH_PI`, the half-float layout, the height field's constants …) are
27+
declared again under their names, with their types and values, in `mcpplibs::mwrap::jolt` and its nested namespaces
28+
of the same names; a constant array as a `std::array` of its elements. Two `static` narrow-phase helpers
29+
(`ActiveEdges::FixNormal`, `IsEdgeActive`) are not exported.
30+
- A name declared on some targets only is exported under upstream's own condition: `JPH::FPControlWord` (SSE and Arm,
31+
not wasm32).
32+
- No `.macros` module: Jolt's macros are configuration switches and code generation (`JPH_DECLARE_RTTI_*`,
33+
`JPH_OVERRIDE_NEW_DELETE`, `JPH_ASSERT`).
34+
- The export list is derived by `tools/surface.py` from the headers as clang reads them (its JSON AST), recorded in
35+
`tools/surface.json`, and audited in CI: the module is the record on every row, and on the Linux LLVM row the record
36+
is derived again and compared.
37+
38+
## Verification
39+
40+
- Wrapper CI (Linux x86_64 and arm64 with GCC 16.1 and LLVM 23.1.3, macOS LLVM, Windows LLVM, each in the dev and
41+
release profiles; wasm32-emscripten under node): a stack knocked down by a ball, a ray and a point query, a world
42+
saved and restored running on to the uninterrupted run's bits, a scene's hash after 200 steps pinned and the same
43+
on every row with 0, 1 and 4 workers; the adapted constants; header mixing; the export audit; the default template
44+
from an installed copy with a strict build.
45+
- This index: consumer `tests/mwrap/jolt-world`; the installed-template check with `--deploy` (`STATIC_NOTICES`).

‎.github/workflows/validate.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,11 @@ jobs:
17331733
shell: bash
17341734
run: python3 tests/mwrap/check_installed_template.py --mcpp "$MCPP" --package mcpplibs.mwrap.manifold@3.5.5.1 --deploy
17351735

1736+
- name: Installed jolt wrapper archive, actual default world template and its relocated notices
1737+
if: contains(format(' {0} ', env.MEMBERS), ' jolt-world ') && matrix.toolchain == 'default'
1738+
shell: bash
1739+
run: python3 tests/mwrap/check_installed_template.py --mcpp "$MCPP" --package mcpplibs.mwrap.jolt@5.6.0 --deploy
1740+
17361741
- name: Installed libjpeg-turbo wrapper archive, actual default decoding template and its relocated notices
17371742
if: contains(format(' {0} ', env.MEMBERS), ' libjpeg-turbo-decode ') && matrix.toolchain == 'default'
17381743
shell: bash

‎CHANGELOG.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@
4141

4242
### Added
4343

44+
- **mcpplibs.mwrap.jolt 5.6.0(新包)。** jolt-m:Jolt Physics 5.6.0(刚体与软体物理:形状、约束、查询、角色、载具)的 C++23
45+
模块,以 `export using` 在上游的命名空间里导出 `<Jolt/…>` 下各头文件的全部公开名字(`JPH` 450 个类型、127 个函数与运算符、
46+
6 个对象,及嵌套命名空间 `ClosestPoint`、`HalfFloatConversion`、`ScaleHelpers`、`StreamUtils`、`literals` 的名字);50 个内部链接的
47+
常量(`cMaxPhysicsJobs`、`cDefaultConvexRadius`、`JPH_PI` 等;常量数组为 `std::array`)以原名位于 `mcpplibs::mwrap::jolt`。导出清单
48+
由 clang 读头文件推出并在 CI 中审计;`JPH::FPControlWord` 只在上游声明它的平台(SSE、Arm)导出。封装仓库从上游 5.6.0 发布包取
49+
源码并以跨平台确定模式构建(`JPH_CROSS_PLATFORM_DETERMINISTIC`、`-ffp-contract=off`、不用快速数学,`JPH_NO_DEBUG` 使各配置相同):
50+
同一场景在 Linux x86-64 与 arm64、macOS、Windows、wasm32 上,dev 与 release,0、1、4 个工作线程,哈希相同(钉住)。不含调试
51+
渲染器、性能剖析、对象流与 GPU 计算后端。消费者测试 `tests/mwrap/jolt-world`,安装后模板检查带 `--deploy`。GLOBAL 为 GitHub
52+
发布资产,CN 为 GitCode `mcpp-res/mwrap-jolt` 镜像,sha256 相同。
4453
- **mcpplibs.mwrap.basis_universal 2.50.1(新包)。** basis-universal-m:Basis Universal 2.50 转码器(把 KTX2 与 `.basis` 纹理转成
4554
像素或 GPU 自己的压缩格式)的 C++23 模块,`<transcoder/basisu_transcoder.h>` 在 `basist`、`basisu` 及其内部命名空间声明的
4655
603 个名字(148 个类型、273 个函数、70 个对象、112 个无作用域枚举的枚举项)以原名导出;头文件里 139 个内部链接的标量常量

‎mcpp.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ members = [
3838
"tests/mwrap/meshoptimizer-simplify",
3939
"tests/mwrap/cgltf-inspect",
4040
"tests/mwrap/manifold-boolean",
41+
"tests/mwrap/jolt-world",
4142
"tests/mwrap/basis-universal-transcode",
4243
"tests/mwrap/libjpeg-turbo-decode",
4344
"tests/mwrap/libarchive-bundle",

‎pkgs/mwrap/jolt.lua‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- Immutable upstream-aligned mwrap source release (jolt-m mwrap-5.6.0, the first release of upstream 5.6.0);
2+
-- GLOBAL and CN bytes are identical.
3+
--
4+
-- The wrapper is Apache-2.0; the library it vendors and links statically,
5+
-- Jolt Physics 5.6.0, is MIT: the package deploys its README and LICENSE
6+
-- beside programs (runtime.deploy).
7+
package = {
8+
spec = "1",
9+
namespace = "mcpplibs.mwrap",
10+
name = "jolt",
11+
description = "jolt-m: Jolt Physics 5.6.0 (rigid and soft body physics: shapes, constraints, queries, characters, vehicles), cross-platform deterministic, as a C++23 module",
12+
licenses = { "Apache-2.0" },
13+
repo = "https://github.com/mcpplibs/jolt-m",
14+
type = "package",
15+
extensions = {
16+
autoupdate = {
17+
tag = "mwrap-${version}",
18+
url = "https://github.com/mcpplibs/jolt-m/releases/download/${tag}/jolt-m-${version}.tar.gz",
19+
},
20+
},
21+
xpm = {
22+
linux = {
23+
["5.6.0"] = {
24+
url = {
25+
GLOBAL = "https://github.com/mcpplibs/jolt-m/releases/download/mwrap-5.6.0/jolt-m-5.6.0.tar.gz",
26+
CN = "https://gitcode.com/mcpp-res/mwrap-jolt/releases/download/5.6.0/jolt-m-5.6.0.tar.gz",
27+
},
28+
sha256 = "ea4b7052c13888142594a01966081bda80a2dc8a32e9e093479cfacaba939c49",
29+
},
30+
},
31+
macosx = {
32+
["5.6.0"] = {
33+
url = {
34+
GLOBAL = "https://github.com/mcpplibs/jolt-m/releases/download/mwrap-5.6.0/jolt-m-5.6.0.tar.gz",
35+
CN = "https://gitcode.com/mcpp-res/mwrap-jolt/releases/download/5.6.0/jolt-m-5.6.0.tar.gz",
36+
},
37+
sha256 = "ea4b7052c13888142594a01966081bda80a2dc8a32e9e093479cfacaba939c49",
38+
},
39+
},
40+
windows = {
41+
["5.6.0"] = {
42+
url = {
43+
GLOBAL = "https://github.com/mcpplibs/jolt-m/releases/download/mwrap-5.6.0/jolt-m-5.6.0.tar.gz",
44+
CN = "https://gitcode.com/mcpp-res/mwrap-jolt/releases/download/5.6.0/jolt-m-5.6.0.tar.gz",
45+
},
46+
sha256 = "ea4b7052c13888142594a01966081bda80a2dc8a32e9e093479cfacaba939c49",
47+
},
48+
},
49+
},
50+
}

‎tests/mwrap/check_installed_template.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"mcpplibs.mwrap.meshoptimizer": ("meshoptimizer.cppm", "upstream/meshoptimizer/LICENSE.md", b"MIT License", b"Arseny Kapoulkine"),
2424
"mcpplibs.mwrap.cgltf": ("cgltf.cppm", "upstream/cgltf/LICENSE", b"Permission is hereby granted", b"Kuhlmann"),
2525
"mcpplibs.mwrap.manifold": ("manifold.cppm", "upstream/manifold/LICENSE", b"Apache License", b"The Manifold Authors"),
26+
"mcpplibs.mwrap.jolt": ("jolt.cppm", "upstream/jolt/LICENSE", b"Permission is hereby granted", b"Jolt Physics is Copyright (c) 2021 Jorrit"),
2627
"mcpplibs.mwrap.libjpeg_turbo": ("libjpeg_turbo.cppm", "upstream/libjpeg-turbo/README.ijg", b"Independent JPEG Group", b"libjpeg-turbo Project"),
2728
"mcpplibs.mwrap.basis_universal": ("basis_universal.cppm", "upstream/basis_universal/NOTICE", b"Binomial LLC", b"Basis Universal"),
2829
"mcpplibs.mwrap.libc": ("libc.cppm", None, b"", b"ISO/IEC 9899:2018"),

‎tests/mwrap/jolt-world/mcpp.toml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "jolt-world"
3+
version = "5.6.0"
4+
description = "Consume the immutable Jolt Physics wrapper: a world of bodies stepped, queried, saved and restored to the same bits, with one worker and several"
5+
6+
[indices]
7+
# Use the complete candidate built-in index prepared by tests/run_members.sh.
8+
# An explicit empty table overrides the legacy workspace redirect.
9+
10+
[dependencies]
11+
mcpplibs.mwrap.jolt = "5.6.0"
12+
13+
# Jolt's inline math compiled here too, as the library is built.
14+
[build]
15+
cxxflags = ["-ffp-contract=off"]
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// The installed Jolt Physics wrapper: a floor, a stack of boxes and a ball thrown at it; stepped until the stack
2+
// falls, a ray cast down onto it, the world saved and restored to the uninterrupted run's bits, and the same bits
3+
// with one worker and with three; the adapted constants.
4+
import std;
5+
import mcpplibs.mwrap.jolt;
6+
7+
namespace jolt = mcpplibs::mwrap::jolt;
8+
9+
namespace {
10+
11+
constexpr JPH::ObjectLayer still = 0, moving = 1;
12+
13+
bool map(JPH::BroadPhaseLayerInterfaceTable& broad, JPH::ObjectLayerPairFilterTable& pairs) {
14+
broad.MapObjectToBroadPhaseLayer(still, JPH::BroadPhaseLayer(0));
15+
broad.MapObjectToBroadPhaseLayer(moving, JPH::BroadPhaseLayer(1));
16+
pairs.EnableCollision(moving, still);
17+
pairs.EnableCollision(moving, moving);
18+
return true;
19+
}
20+
struct Layers {
21+
JPH::BroadPhaseLayerInterfaceTable broad{2, 2};
22+
JPH::ObjectLayerPairFilterTable pairs{2};
23+
bool mapped = map(broad, pairs);
24+
JPH::ObjectVsBroadPhaseLayerFilterTable object_vs_broad{broad, 2, pairs, 2};
25+
};
26+
27+
struct Scene {
28+
JPH::TempAllocatorImpl temp{4 * 1024 * 1024};
29+
std::unique_ptr<JPH::JobSystem> jobs;
30+
JPH::PhysicsSystem system;
31+
std::vector<JPH::BodyID> bodies;
32+
};
33+
34+
void make(Scene& scene, const Layers& layers, int workers) {
35+
if (workers == 0) scene.jobs = std::make_unique<JPH::JobSystemSingleThreaded>(jolt::cMaxPhysicsJobs);
36+
else scene.jobs = std::make_unique<JPH::JobSystemThreadPool>(jolt::cMaxPhysicsJobs, jolt::cMaxPhysicsBarriers, workers);
37+
scene.system.Init(256, 0, 256, 256, layers.broad, layers.object_vs_broad, layers.pairs);
38+
JPH::BodyInterface& bodies = scene.system.GetBodyInterface();
39+
scene.bodies.push_back(bodies.CreateAndAddBody(
40+
JPH::BodyCreationSettings(new JPH::BoxShape(JPH::Vec3(20, 1, 20)), JPH::RVec3(0, -1, 0), JPH::Quat::sIdentity(), JPH::EMotionType::Static, still),
41+
JPH::EActivation::DontActivate));
42+
for (int level = 0; level < 5; ++level)
43+
scene.bodies.push_back(bodies.CreateAndAddBody(JPH::BodyCreationSettings(new JPH::BoxShape(JPH::Vec3(0.5f, 0.5f, 0.5f)), JPH::RVec3(0, 0.5f + level * 1.0f, 0),
44+
JPH::Quat::sIdentity(), JPH::EMotionType::Dynamic, moving),
45+
JPH::EActivation::Activate));
46+
JPH::BodyCreationSettings ball(new JPH::SphereShape(0.5f), JPH::RVec3(-8, 2, 0), JPH::Quat::sIdentity(), JPH::EMotionType::Dynamic, moving);
47+
ball.mLinearVelocity = JPH::Vec3(20, 1, 0);
48+
scene.bodies.push_back(bodies.CreateAndAddBody(ball, JPH::EActivation::Activate));
49+
}
50+
51+
void step(Scene& scene, int steps) {
52+
for (int index = 0; index < steps; ++index) scene.system.Update(1.0f / 60.0f, 1, &scene.temp, scene.jobs.get());
53+
}
54+
55+
std::uint64_t bits(const Scene& scene) {
56+
std::uint64_t hash = 0xcbf29ce484222325ull;
57+
const JPH::BodyInterface& bodies = scene.system.GetBodyInterface();
58+
for (const JPH::BodyID body : scene.bodies) {
59+
const JPH::RVec3 at = bodies.GetPosition(body);
60+
const JPH::Quat turn = bodies.GetRotation(body);
61+
for (const float value : {float(at.GetX()), float(at.GetY()), float(at.GetZ()), turn.GetX(), turn.GetY(), turn.GetZ(), turn.GetW()}) {
62+
hash ^= std::bit_cast<std::uint32_t>(value);
63+
hash *= 0x100000001b3ull;
64+
}
65+
}
66+
return hash;
67+
}
68+
69+
} // namespace
70+
71+
int main() {
72+
JPH::RegisterDefaultAllocator();
73+
JPH::Factory::sInstance = new JPH::Factory();
74+
JPH::RegisterTypes();
75+
int failed = 0;
76+
{
77+
const Layers layers;
78+
Scene straight;
79+
make(straight, layers, 0);
80+
JPH::RayCastResult hit;
81+
if (!straight.system.GetNarrowPhaseQuery().CastRay(JPH::RRayCast{JPH::RVec3(0, 20, 0), JPH::Vec3(0, -40, 0)}, hit) || hit.mBodyID != straight.bodies[5]) failed = 1;
82+
step(straight, 180);
83+
const std::uint64_t expected = bits(straight);
84+
if (straight.system.GetBodyInterface().GetPosition(straight.bodies[5]).GetY() > 3.0f && !failed) failed = 2; // the top box fell
85+
86+
Scene rolled;
87+
make(rolled, layers, 0);
88+
step(rolled, 60);
89+
JPH::StateRecorderImpl saved;
90+
rolled.system.SaveState(saved);
91+
step(rolled, 60);
92+
saved.Rewind();
93+
if (!rolled.system.RestoreState(saved) && !failed) failed = 3;
94+
step(rolled, 120);
95+
if (bits(rolled) != expected && !failed) failed = 4;
96+
97+
Scene threaded;
98+
make(threaded, layers, 3);
99+
step(threaded, 180);
100+
if (bits(threaded) != expected && !failed) failed = 5;
101+
if ((jolt::cMaxPhysicsJobs != 2048 || jolt::sAllSubShapeTypes.size() != static_cast<std::size_t>(jolt::NumSubShapeTypes)) && !failed) failed = 6;
102+
std::println("Jolt Physics 5.6.0 through import mcpplibs.mwrap.jolt: the stack knocked down, restored and run again to {:#018x}, the same with 3 workers{}",
103+
expected, failed ? std::format(" — check {} failed", failed) : "");
104+
}
105+
JPH::UnregisterTypes();
106+
delete JPH::Factory::sInstance;
107+
JPH::Factory::sInstance = nullptr;
108+
return failed;
109+
}

0 commit comments

Comments
 (0)