@series-inc/rundot-syncplay 6.0.0-rc.2 → 6.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -0
- package/core/deterministic-math.d.ts +75 -1
- package/core/native/instance_ledger.hpp +1095 -0
- package/core/native/legacy_checkpoint_ids.hpp +107 -0
- package/core/native/physics/abi.cpp +39 -211
- package/core/native/physics/abi.hpp +2 -6
- package/core/native/physics/articulation.cpp +1434 -0
- package/core/native/physics/articulation.hpp +279 -0
- package/core/native/physics/buoyancy.cpp +1588 -0
- package/core/native/physics/buoyancy.hpp +254 -0
- package/core/native/physics/capsule_triangle.cpp +168 -0
- package/core/native/physics/capsule_triangle.hpp +40 -0
- package/core/native/physics/capsule_triangle_native.inc +291 -0
- package/core/native/physics/certified_sum.hpp +218 -0
- package/core/native/physics/character.cpp +638 -0
- package/core/native/physics/character.hpp +169 -0
- package/core/native/physics/checkpoint_schema.hpp +379 -0
- package/core/native/physics/cloth.cpp +1401 -0
- package/core/native/physics/cloth.hpp +357 -0
- package/core/native/physics/constraint_rows.cpp +363 -2
- package/core/native/physics/constraint_rows.hpp +72 -1
- package/core/native/physics/deformable_query.cpp +1630 -0
- package/core/native/physics/deformable_query.hpp +578 -0
- package/core/native/physics/distance.cpp +1166 -0
- package/core/native/physics/distance.hpp +151 -0
- package/core/native/physics/exact/exact-applied.cpp +101 -0
- package/core/native/physics/exact/exact-applied.hpp +112 -0
- package/core/native/physics/exact/exact-dyadic.cpp +691 -0
- package/core/native/physics/exact/exact-dyadic.hpp +58 -0
- package/core/native/physics/exact/exact-operation.hpp +51 -0
- package/core/native/physics/exact/word-core.hpp +262 -0
- package/core/native/physics/extended_abi.cpp +1242 -0
- package/core/native/physics/extended_abi.hpp +355 -0
- package/core/native/physics/extended_abi_characters.cpp +261 -0
- package/core/native/physics/extended_abi_characters.hpp +434 -0
- package/core/native/physics/extended_abi_core_features.cpp +713 -0
- package/core/native/physics/extended_abi_core_features.hpp +226 -0
- package/core/native/physics/extended_abi_deformables.cpp +448 -0
- package/core/native/physics/extended_abi_deformables.hpp +867 -0
- package/core/native/physics/extended_abi_vehicles.cpp +411 -0
- package/core/native/physics/extended_abi_vehicles.hpp +222 -0
- package/core/native/physics/fracture.cpp +1981 -0
- package/core/native/physics/fracture.hpp +460 -0
- package/core/native/physics/gear.cpp +563 -0
- package/core/native/physics/gear.hpp +158 -0
- package/core/native/physics/geometry_memory.hpp +476 -0
- package/core/native/physics/geometry_store.cpp +547 -0
- package/core/native/physics/geometry_store.hpp +134 -0
- package/core/native/physics/lag_compensation.cpp +1626 -0
- package/core/native/physics/lag_compensation.hpp +405 -0
- package/core/native/physics/mass_properties.cpp +449 -0
- package/core/native/physics/mass_properties.hpp +23 -0
- package/core/native/physics/material_pose.hpp +988 -0
- package/core/native/physics/particles.cpp +1065 -0
- package/core/native/physics/particles.hpp +261 -0
- package/core/native/physics/path_joint.cpp +781 -0
- package/core/native/physics/path_joint.hpp +154 -0
- package/core/native/physics/physics.cpp +13043 -1065
- package/core/native/physics/physics.hpp +184 -8
- package/core/native/physics/planar_deformable.cpp +2433 -0
- package/core/native/physics/planar_deformable.hpp +889 -0
- package/core/native/physics/platformer_2d.cpp +1353 -0
- package/core/native/physics/platformer_2d.hpp +340 -0
- package/core/native/physics/powered_ragdoll.cpp +1100 -0
- package/core/native/physics/powered_ragdoll.hpp +279 -0
- package/core/native/physics/powertrain.cpp +586 -0
- package/core/native/physics/powertrain.hpp +180 -0
- package/core/native/physics/pulley.cpp +311 -0
- package/core/native/physics/pulley.hpp +121 -0
- package/core/native/physics/ragdoll.cpp +586 -0
- package/core/native/physics/ragdoll.hpp +221 -0
- package/core/native/physics/rope.cpp +692 -0
- package/core/native/physics/rope.hpp +215 -0
- package/core/native/physics/rounded_convex.cpp +1229 -0
- package/core/native/physics/rounded_convex.hpp +287 -0
- package/core/native/physics/sdf_geometry.cpp +1821 -0
- package/core/native/physics/sdf_geometry.hpp +474 -0
- package/core/native/physics/soft_body.cpp +1449 -0
- package/core/native/physics/soft_body.hpp +328 -0
- package/core/native/physics/soft_collision.cpp +1862 -0
- package/core/native/physics/soft_collision.hpp +561 -0
- package/core/native/physics/surface_velocity.cpp +366 -0
- package/core/native/physics/surface_velocity.hpp +243 -0
- package/core/native/physics/topology.cpp +357 -39
- package/core/native/physics/topology.hpp +97 -6
- package/core/native/physics/tracks.cpp +1179 -0
- package/core/native/physics/tracks.hpp +404 -0
- package/core/native/physics/vehicle.cpp +629 -0
- package/core/native/physics/vehicle.hpp +191 -0
- package/core/native/physics/voxel_cooking.cpp +1929 -0
- package/core/native/physics/voxel_cooking.hpp +395 -0
- package/core/native/physics/world.cpp +5290 -854
- package/core/native/physics/world.hpp +796 -24
- package/core/native/physics/world_abi.cpp +3840 -306
- package/core/native/physics/world_abi.hpp +530 -10
- package/core/native/physics/world_digest_visitor.hpp +277 -0
- package/core/native/physics/world_strong_digest.hpp +557 -0
- package/core/native/physics2d/ccd.cpp +1302 -0
- package/core/native/physics2d/ccd.hpp +141 -0
- package/core/native/physics2d/checkpoint_memory.hpp +349 -0
- package/core/native/physics2d/clock_primitives.hpp +138 -0
- package/core/native/physics2d/commands.cpp +174 -28
- package/core/native/physics2d/commands.hpp +3 -1
- package/core/native/physics2d/compound.cpp +581 -0
- package/core/native/physics2d/compound.hpp +248 -0
- package/core/native/physics2d/contour.cpp +325 -0
- package/core/native/physics2d/contour.hpp +143 -0
- package/core/native/physics2d/frame_scope.hpp +124 -0
- package/core/native/physics2d/joint_phases.hpp +93 -0
- package/core/native/physics2d/joints.cpp +587 -150
- package/core/native/physics2d/joints.hpp +5 -0
- package/core/native/physics2d/memory_private.hpp +125 -0
- package/core/native/physics2d/owned_abi.cpp +1354 -879
- package/core/native/physics2d/owned_abi.hpp +190 -52
- package/core/native/physics2d/phase_test_hooks.hpp +17 -0
- package/core/native/physics2d/physics2d.cpp +2073 -120
- package/core/native/physics2d/physics2d.hpp +154 -2
- package/core/native/physics2d/queries.cpp +1055 -79
- package/core/native/physics2d/queries.hpp +71 -5
- package/core/native/physics2d/world.cpp +1313 -353
- package/core/native/physics2d/world.hpp +124 -13
- package/core/native/sha256/sha256_compress_unsigned.hpp +68 -0
- package/core/native/sha256/sha256_fips_constants.hpp +24 -0
- package/core/native/sha256/sha256_length.hpp +56 -0
- package/core/native/sha256/sha256_memo.hpp +48 -0
- package/core/native/sha256/sha256_sink.hpp +234 -0
- package/core/physics2d-owned.d.ts +466 -126
- package/core/runtime.d.ts +192 -19
- package/core/scripts/build-native.mjs +34 -0
- package/core/scripts/build-wasm-physics.mjs +272 -23
- package/core/scripts/extended-physics-profile.mjs +634 -0
- package/core/scripts/generate-physics2d-vectors.mjs +59 -0
- package/core/src/kinetix-deterministic-math.d.ts +2 -0
- package/core/src/kinetix-deterministic-math.mjs +513 -27
- package/core/src/kinetix-owned-runtime-adapter.mjs +788 -0
- package/core/src/kinetix-runtime-adapter-utils.mjs +54 -6
- package/core/src/kinetix-runtime-contract.mjs +55 -9
- package/core/src/kinetix-runtime-identity.mjs +12 -1
- package/core/src/kinetix-session-config.mjs +7 -2
- package/core/src/kinetix-state-report.mjs +36 -0
- package/core/src/physics/abi-constants.mjs +5 -4
- package/core/src/physics/articulation.d.mts +194 -0
- package/core/src/physics/articulation.mjs +1141 -0
- package/core/src/physics/buoyancy.d.mts +143 -0
- package/core/src/physics/buoyancy.mjs +268 -0
- package/core/src/physics/cloth.d.mts +314 -0
- package/core/src/physics/cloth.mjs +1156 -0
- package/core/src/physics/deformable-query.d.mts +217 -0
- package/core/src/physics/deformable-query.mjs +1412 -0
- package/core/src/physics/distance.d.mts +160 -0
- package/core/src/physics/distance.mjs +175 -0
- package/core/src/physics/extended-wasm-instance.d.mts +5 -0
- package/core/src/physics/extended-wasm-instance.mjs +48 -0
- package/core/src/physics/feature-api.d.mts +74 -0
- package/core/src/physics/feature-api.mjs +98 -0
- package/core/src/physics/fracture.d.mts +133 -0
- package/core/src/physics/fracture.mjs +1324 -0
- package/core/src/physics/gear.d.mts +585 -0
- package/core/src/physics/gear.mjs +955 -0
- package/core/src/physics/lag-compensation.d.mts +101 -0
- package/core/src/physics/lag-compensation.mjs +1100 -0
- package/core/src/physics/mass-properties.d.mts +114 -0
- package/core/src/physics/mass-properties.mjs +137 -468
- package/core/src/physics/particles.d.mts +177 -0
- package/core/src/physics/particles.mjs +758 -0
- package/core/src/physics/path-joint.d.mts +171 -0
- package/core/src/physics/path-joint.mjs +1231 -0
- package/core/src/physics/physics-extended-wasm-module.generated.mjs +13 -0
- package/core/src/physics/physics-profile-wasm-module.generated.mjs +48 -0
- package/core/src/physics/physics-wasm-module.generated.mjs +34 -5
- package/core/src/physics/powered-ragdoll.d.mts +188 -0
- package/core/src/physics/powered-ragdoll.mjs +1043 -0
- package/core/src/physics/powertrain.d.mts +260 -0
- package/core/src/physics/powertrain.mjs +621 -0
- package/core/src/physics/pulley.d.mts +98 -0
- package/core/src/physics/pulley.mjs +686 -0
- package/core/src/physics/ragdoll.d.mts +289 -0
- package/core/src/physics/ragdoll.mjs +1323 -0
- package/core/src/physics/rope.d.mts +241 -0
- package/core/src/physics/rope.mjs +319 -0
- package/core/src/physics/rounded-convex.d.mts +328 -0
- package/core/src/physics/rounded-convex.mjs +1404 -0
- package/core/src/physics/sdf-geometry.d.mts +117 -0
- package/core/src/physics/sdf-geometry.mjs +1204 -0
- package/core/src/physics/soft-body.d.mts +144 -0
- package/core/src/physics/soft-body.mjs +1285 -0
- package/core/src/physics/soft-collision.d.mts +651 -0
- package/core/src/physics/soft-collision.mjs +1883 -0
- package/core/src/physics/surface-velocity.d.mts +156 -0
- package/core/src/physics/surface-velocity.mjs +722 -0
- package/core/src/physics/tracks.d.mts +411 -0
- package/core/src/physics/tracks.mjs +1074 -0
- package/core/src/physics/vehicle.d.mts +3 -0
- package/core/src/physics/vehicle.mjs +172 -0
- package/core/src/physics/voxel-cooking.d.mts +219 -0
- package/core/src/physics/voxel-cooking.mjs +1499 -0
- package/core/src/physics/voxel-swept-quad.mjs +110 -0
- package/core/src/physics/wasm-instance.mjs +160 -23
- package/core/src/physics/world.d.mts +62 -0
- package/core/src/physics/world.mjs +1947 -152
- package/core/src/physics2d/body-state.mjs +218 -15
- package/core/src/physics2d/collision.d.mts +52 -0
- package/core/src/physics2d/collision.mjs +234 -0
- package/core/src/physics2d/compound.mjs +454 -0
- package/core/src/physics2d/contour-state.mjs +771 -0
- package/core/src/physics2d/feature-api.d.mts +211 -0
- package/core/src/physics2d/feature-api.mjs +3 -0
- package/core/src/physics2d/fluid-state.mjs +145 -0
- package/core/src/physics2d/joint-state.mjs +1 -1
- package/core/src/physics2d/owned-queries.mjs +3 -1
- package/core/src/physics2d/owned-transport.mjs +268 -122
- package/core/src/physics2d/owned-world.mjs +353 -230
- package/core/src/physics2d/particle-fluid.d.mts +152 -0
- package/core/src/physics2d/particle-fluid.mjs +233 -0
- package/core/src/physics2d/physics2d-wasm-module.generated.mjs +27 -10
- package/core/src/physics2d/query-codec.mjs +61 -13
- package/core/src/physics2d/submerged-geometry.d.mts +51 -0
- package/core/src/physics2d/submerged-geometry.mjs +186 -0
- package/core/src/runtime.mjs +23 -0
- package/core/src/shared/bytes.d.mts +2 -0
- package/core/src/shared/bytes.mjs +33 -0
- package/core/src/shared/sha256.d.mts +3 -0
- package/core/src/shared/sha256.mjs +72 -22
- package/core/units.d.ts +50 -0
- package/core/world.d.ts +253 -5
- package/dist/authority-room.d.ts +9 -0
- package/dist/authority-room.js +45 -16
- package/dist/browser.d.ts +6 -5
- package/dist/browser.js +4 -3
- package/dist/cadence.d.ts +7 -0
- package/dist/cadence.js +19 -0
- package/dist/canonical.d.ts +1 -0
- package/dist/canonical.js +3 -0
- package/dist/checksum-policy.d.ts +10 -0
- package/dist/checksum-policy.js +14 -0
- package/dist/collider-cooking-hull.d.ts +18 -0
- package/dist/collider-cooking-hull.js +248 -0
- package/dist/collider-cooking.d.ts +140 -0
- package/dist/collider-cooking.js +794 -0
- package/dist/compat/v5.d.ts +121 -0
- package/dist/compat/v5.js +479 -0
- package/dist/creator.d.ts +7 -6
- package/dist/creator.js +4 -3
- package/dist/game-byte-section.d.ts +36 -0
- package/dist/game-byte-section.js +350 -0
- package/dist/index.d.ts +13 -6
- package/dist/index.js +9 -4
- package/dist/instant-replay.d.ts +27 -2
- package/dist/instant-replay.js +91 -16
- package/dist/lag-compensation3d.js +11 -10
- package/dist/match-log.d.ts +21 -4
- package/dist/match-log.js +92 -9
- package/dist/math.d.ts +2 -0
- package/dist/math.js +1 -0
- package/dist/modules/character-3d.d.ts +16 -1
- package/dist/modules/character-3d.js +42 -5
- package/dist/modules/combat.js +6 -5
- package/dist/movement3d-revision1.d.ts +2 -0
- package/dist/movement3d-revision1.js +973 -0
- package/dist/movement3d.d.ts +53 -3
- package/dist/movement3d.js +917 -247
- package/dist/networked-client.d.ts +15 -0
- package/dist/networked-client.js +378 -105
- package/dist/node.d.ts +3 -2
- package/dist/node.js +2 -1
- package/dist/physics/2d.d.ts +38 -4
- package/dist/physics/2d.js +57 -36
- package/dist/physics/3d.d.ts +755 -111
- package/dist/physics/3d.js +2355 -158
- package/dist/physics/edit-result-graph.d.ts +36 -0
- package/dist/physics/edit-result-graph.js +141 -0
- package/dist/physics/game-codec3d.d.ts +41 -0
- package/dist/physics/game-codec3d.js +544 -0
- package/dist/physics/installed-checkpoint3d.d.ts +13 -0
- package/dist/physics/installed-checkpoint3d.js +120 -0
- package/dist/physics/installed-runtime3d.d.ts +51 -0
- package/dist/physics/installed-runtime3d.js +372 -0
- package/dist/physics/installed-state-commitment3d.d.ts +2 -0
- package/dist/physics/installed-state-commitment3d.js +24 -0
- package/dist/physics/units.d.ts +38 -0
- package/dist/physics/units.js +56 -0
- package/dist/physics/vehicle-state3d.d.ts +93 -0
- package/dist/physics/vehicle-state3d.js +1191 -0
- package/dist/physics/voxel-body-state.d.ts +61 -0
- package/dist/physics/voxel-body-state.js +410 -0
- package/dist/r3f-render-adapter.d.ts +59 -1
- package/dist/r3f-render-adapter.js +137 -2
- package/dist/replay.d.ts +13 -0
- package/dist/replay.js +95 -70
- package/dist/run-room-transport.js +5 -1
- package/dist/runner.d.ts +17 -2
- package/dist/runner.js +472 -84
- package/dist/runtime-cleanup.d.ts +54 -0
- package/dist/runtime-cleanup.js +266 -0
- package/dist/runtime-lease.d.ts +11 -1
- package/dist/runtime-lease.js +23 -10
- package/dist/runtime-room-metadata.d.ts +2 -8
- package/dist/runtime-room-metadata.js +11 -14
- package/dist/runtime-session.d.ts +8 -0
- package/dist/runtime-session.js +222 -58
- package/dist/schema-codegen.js +3 -0
- package/dist/schema-dsl-binary.d.ts +10 -4
- package/dist/schema-dsl-binary.js +375 -76
- package/dist/scratch-pool.d.ts +32 -0
- package/dist/scratch-pool.js +60 -0
- package/dist/sdk-session.d.ts +1 -0
- package/dist/sdk-session.js +4 -0
- package/dist/secret-config.js +2 -60
- package/dist/secret-crypto.js +70 -36
- package/dist/session-snapshot.d.ts +15 -4
- package/dist/session-snapshot.js +35 -33
- package/dist/session-wire.js +14 -22
- package/dist/sparse-set.d.ts +1 -0
- package/dist/sparse-set.js +22 -0
- package/dist/spatial/spatial-grid-3d.d.ts +41 -0
- package/dist/spatial/spatial-grid-3d.js +115 -0
- package/dist/synctest.d.ts +9 -0
- package/dist/synctest.js +106 -17
- package/dist/testing-network.d.ts +2 -0
- package/dist/testing-network.js +122 -18
- package/dist/testing.d.ts +27 -6
- package/dist/testing.js +297 -56
- package/dist/tools/index.d.ts +3 -2
- package/dist/tools/index.js +3 -2
- package/dist/tools/module-certification.d.ts +6 -0
- package/dist/tools/module-certification.js +26 -2
- package/package.json +18 -5
- package/core/scripts/run-box3d-benchmark.mjs +0 -350
- package/core/src/physics/index.mjs +0 -3169
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
#include "powertrain.hpp"
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <array>
|
|
5
|
+
#include <cmath>
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
#include <span>
|
|
8
|
+
|
|
9
|
+
namespace rundot::kinetix::physics::powertrain {
|
|
10
|
+
|
|
11
|
+
namespace {
|
|
12
|
+
|
|
13
|
+
constexpr double kPi = 3.14159265358979323846;
|
|
14
|
+
constexpr double kEpsilon = 1e-9;
|
|
15
|
+
|
|
16
|
+
inline double jsRound(double value) {
|
|
17
|
+
const double ceiling = std::ceil(value);
|
|
18
|
+
return ceiling - 0.5 <= value ? ceiling : ceiling - 1.0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
inline double clamp(double v, double minVal, double maxVal) {
|
|
22
|
+
return std::max(minVal, std::min(maxVal, v));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
inline double sgn(double v) {
|
|
26
|
+
if (v > kEpsilon) return 1.0;
|
|
27
|
+
if (v < -kEpsilon) return -1.0;
|
|
28
|
+
return 0.0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
} // namespace
|
|
32
|
+
|
|
33
|
+
double quantizeValue(double value) {
|
|
34
|
+
const double quantized = jsRound(value * 1e6) / 1e6;
|
|
35
|
+
return quantized == 0.0 ? 0.0 : quantized;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
double sampleEngineCurve(const EngineConfig& config, double rpm) {
|
|
39
|
+
if (rpm <= 0.0) return 0.0;
|
|
40
|
+
if (rpm >= config.revLimiterRpm) return 0.0;
|
|
41
|
+
|
|
42
|
+
if (config.curvePointCount > 0) {
|
|
43
|
+
const std::uint32_t count = std::min(config.curvePointCount, kMaxEngineCurvePoints);
|
|
44
|
+
if (rpm <= config.curvePoints[0].rpm) {
|
|
45
|
+
return quantizeValue(config.curvePoints[0].torque);
|
|
46
|
+
}
|
|
47
|
+
if (rpm >= config.curvePoints[count - 1].rpm) {
|
|
48
|
+
return quantizeValue(config.curvePoints[count - 1].torque);
|
|
49
|
+
}
|
|
50
|
+
for (std::uint32_t i = 0; i < count - 1; ++i) {
|
|
51
|
+
const auto& p0 = config.curvePoints[i];
|
|
52
|
+
const auto& p1 = config.curvePoints[i + 1];
|
|
53
|
+
if (rpm >= p0.rpm && rpm <= p1.rpm) {
|
|
54
|
+
const double span = p1.rpm - p0.rpm;
|
|
55
|
+
if (span < kEpsilon) return quantizeValue(p0.torque);
|
|
56
|
+
const double t = (rpm - p0.rpm) / span;
|
|
57
|
+
const double torque = p0.torque + t * (p1.torque - p0.torque);
|
|
58
|
+
return quantizeValue(torque);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return quantizeValue(config.curvePoints[count - 1].torque);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Built-in deterministic 5-point default torque curve
|
|
65
|
+
const std::array<EngineCurvePoint, 5> defaultPoints{{
|
|
66
|
+
{0.0, config.idleTorque * 0.5},
|
|
67
|
+
{config.idleRpm, config.idleTorque},
|
|
68
|
+
{config.peakTorqueRpm, config.peakTorque},
|
|
69
|
+
{config.maxRpm, config.redlineTorque},
|
|
70
|
+
{config.revLimiterRpm, 0.0},
|
|
71
|
+
}};
|
|
72
|
+
|
|
73
|
+
for (std::uint32_t i = 0; i < 4; ++i) {
|
|
74
|
+
const auto& p0 = defaultPoints[i];
|
|
75
|
+
const auto& p1 = defaultPoints[i + 1];
|
|
76
|
+
if (rpm >= p0.rpm && rpm <= p1.rpm) {
|
|
77
|
+
const double span = p1.rpm - p0.rpm;
|
|
78
|
+
if (span < kEpsilon) return quantizeValue(p0.torque);
|
|
79
|
+
const double t = (rpm - p0.rpm) / span;
|
|
80
|
+
const double torque = p0.torque + t * (p1.torque - p0.torque);
|
|
81
|
+
return quantizeValue(torque);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return 0.0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
double getGearRatio(const TransmissionConfig& config, std::int32_t gear) {
|
|
89
|
+
if (gear == 0) {
|
|
90
|
+
return 0.0; // Neutral
|
|
91
|
+
}
|
|
92
|
+
if (gear == -1) {
|
|
93
|
+
return config.reverseRatio * config.finalDriveRatio;
|
|
94
|
+
}
|
|
95
|
+
if (gear > 0 && static_cast<std::uint32_t>(gear) <= config.forwardGearCount &&
|
|
96
|
+
static_cast<std::uint32_t>(gear) <= kMaxForwardGears) {
|
|
97
|
+
return config.forwardRatios[static_cast<std::size_t>(gear - 1)] * config.finalDriveRatio;
|
|
98
|
+
}
|
|
99
|
+
return 0.0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
namespace {
|
|
103
|
+
|
|
104
|
+
void splitAxleTorque(
|
|
105
|
+
DifferentialType diffType,
|
|
106
|
+
double axleTorque,
|
|
107
|
+
double wLeft,
|
|
108
|
+
double wRight,
|
|
109
|
+
double lsdBiasRatio,
|
|
110
|
+
double lsdPreload,
|
|
111
|
+
double lockStiffness,
|
|
112
|
+
double& outTorqueLeft,
|
|
113
|
+
double& outTorqueRight) {
|
|
114
|
+
const double halfAxleTorque = 0.5 * axleTorque;
|
|
115
|
+
|
|
116
|
+
if (diffType == DifferentialType::Open) {
|
|
117
|
+
outTorqueLeft = quantizeValue(halfAxleTorque);
|
|
118
|
+
outTorqueRight = quantizeValue(halfAxleTorque);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const double speedDiff = wLeft - wRight; // Positive if left wheel spins faster
|
|
123
|
+
|
|
124
|
+
if (diffType == DifferentialType::Locked) {
|
|
125
|
+
const double maxBias = std::abs(halfAxleTorque);
|
|
126
|
+
const double bias = clamp(speedDiff * lockStiffness, -maxBias, maxBias);
|
|
127
|
+
outTorqueLeft = quantizeValue(halfAxleTorque - bias);
|
|
128
|
+
outTorqueRight = quantizeValue(halfAxleTorque + bias);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (diffType == DifferentialType::LimitedSlip) {
|
|
133
|
+
const double ratio = std::max(1.0, lsdBiasRatio);
|
|
134
|
+
const double maxBias = std::abs(halfAxleTorque) * ((ratio - 1.0) / (ratio + 1.0));
|
|
135
|
+
double preloadTerm = 0.0;
|
|
136
|
+
if (speedDiff > kEpsilon) {
|
|
137
|
+
preloadTerm = lsdPreload;
|
|
138
|
+
} else if (speedDiff < -kEpsilon) {
|
|
139
|
+
preloadTerm = -lsdPreload;
|
|
140
|
+
}
|
|
141
|
+
const double bias = clamp(speedDiff * lockStiffness + preloadTerm, -maxBias, maxBias);
|
|
142
|
+
outTorqueLeft = quantizeValue(halfAxleTorque - bias);
|
|
143
|
+
outTorqueRight = quantizeValue(halfAxleTorque + bias);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
outTorqueLeft = quantizeValue(halfAxleTorque);
|
|
148
|
+
outTorqueRight = quantizeValue(halfAxleTorque);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
} // namespace
|
|
152
|
+
|
|
153
|
+
PowertrainOutput stepPowertrain(
|
|
154
|
+
const PowertrainConfig& config,
|
|
155
|
+
const PowertrainState& currentState,
|
|
156
|
+
const DriverInput& input,
|
|
157
|
+
std::span<const WheelDynamicState> wheelStates,
|
|
158
|
+
double dt) {
|
|
159
|
+
PowertrainOutput output{};
|
|
160
|
+
output.state = currentState;
|
|
161
|
+
|
|
162
|
+
const std::uint32_t wheelCount = std::min(config.wheelCount, kMaxWheels);
|
|
163
|
+
output.wheelCount = wheelCount;
|
|
164
|
+
|
|
165
|
+
// 1. Transmission state machine and gear shifting
|
|
166
|
+
TransmissionState& trans = output.state.transmission;
|
|
167
|
+
std::int32_t desiredGear = input.targetGear;
|
|
168
|
+
if (desiredGear < -1) desiredGear = -1;
|
|
169
|
+
if (desiredGear > static_cast<std::int32_t>(config.transmission.forwardGearCount)) {
|
|
170
|
+
desiredGear = static_cast<std::int32_t>(config.transmission.forwardGearCount);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (trans.targetGear != desiredGear) {
|
|
174
|
+
trans.targetGear = desiredGear;
|
|
175
|
+
trans.isShifting = true;
|
|
176
|
+
trans.shiftTimer = config.transmission.shiftDelay;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (trans.isShifting) {
|
|
180
|
+
trans.shiftTimer -= dt;
|
|
181
|
+
if (trans.shiftTimer <= 0.0) {
|
|
182
|
+
trans.shiftTimer = 0.0;
|
|
183
|
+
trans.currentGear = trans.targetGear;
|
|
184
|
+
trans.isShifting = false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
trans.effectiveRatio = getGearRatio(config.transmission, trans.currentGear);
|
|
189
|
+
const double baseClutch = clamp(input.clutch, 0.0, 1.0);
|
|
190
|
+
trans.clutchEngagement = trans.isShifting ? 0.0 : baseClutch;
|
|
191
|
+
|
|
192
|
+
// 2. Engine RPM coupling and update
|
|
193
|
+
EngineState& eng = output.state.engine;
|
|
194
|
+
eng.throttle = clamp(input.throttle, 0.0, 1.0);
|
|
195
|
+
|
|
196
|
+
// Compute average angular speed of driven wheels for drivetrain coupling
|
|
197
|
+
double drivenSpeedSum = 0.0;
|
|
198
|
+
double drivenCount = 0.0;
|
|
199
|
+
|
|
200
|
+
for (std::uint32_t i = 0; i < wheelCount; ++i) {
|
|
201
|
+
bool isDriven = false;
|
|
202
|
+
if (config.differential.driveType == DriveType::FWD) {
|
|
203
|
+
isDriven = (i == 0 || i == 1);
|
|
204
|
+
} else if (config.differential.driveType == DriveType::RWD) {
|
|
205
|
+
isDriven = (i == 2 || i == 3);
|
|
206
|
+
} else if (config.differential.driveType == DriveType::AWD) {
|
|
207
|
+
isDriven = (i < 4);
|
|
208
|
+
} else if (config.differential.driveType == DriveType::Custom) {
|
|
209
|
+
isDriven = (config.differential.customDriveDistribution[i] > 0.0);
|
|
210
|
+
}
|
|
211
|
+
if (isDriven && i < wheelStates.size()) {
|
|
212
|
+
drivenSpeedSum += std::abs(wheelStates[i].angularVelocity);
|
|
213
|
+
drivenCount += 1.0;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const double avgDrivenWheelSpeed = (drivenCount > 0.0) ? (drivenSpeedSum / drivenCount) : 0.0;
|
|
218
|
+
const double coupledDrivetrainSpeed = avgDrivenWheelSpeed * std::abs(trans.effectiveRatio);
|
|
219
|
+
const double coupledRpm = coupledDrivetrainSpeed * (30.0 / kPi);
|
|
220
|
+
|
|
221
|
+
if (trans.clutchEngagement > 0.1 && trans.currentGear != 0) {
|
|
222
|
+
eng.rpm = std::max(config.engine.idleRpm, coupledRpm);
|
|
223
|
+
} else {
|
|
224
|
+
// Clutch disengaged or neutral: engine revs freely
|
|
225
|
+
const double angularVel = eng.rpm * (kPi / 30.0);
|
|
226
|
+
const double grossT = sampleEngineCurve(config.engine, eng.rpm) * eng.throttle;
|
|
227
|
+
const double frictionT = config.engine.frictionCoefficient * angularVel;
|
|
228
|
+
const double idleAssist = (eng.rpm < config.engine.idleRpm)
|
|
229
|
+
? ((config.engine.idleRpm - eng.rpm) / config.engine.idleRpm) * config.engine.idleTorque
|
|
230
|
+
: 0.0;
|
|
231
|
+
const double freeNetT = grossT + idleAssist - frictionT;
|
|
232
|
+
const double alpha = freeNetT / std::max(0.01, config.engine.inertia);
|
|
233
|
+
const double newAngularVel = std::max(0.0, angularVel + alpha * dt);
|
|
234
|
+
eng.rpm = clamp(newAngularVel * (30.0 / kPi), config.engine.idleRpm, config.engine.revLimiterRpm);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
eng.angularVelocity = eng.rpm * (kPi / 30.0);
|
|
238
|
+
|
|
239
|
+
// Rev limiter state
|
|
240
|
+
if (eng.rpm >= config.engine.revLimiterRpm) {
|
|
241
|
+
eng.revLimiterActive = true;
|
|
242
|
+
} else if (eng.rpm <= config.engine.revLimiterRecoveryRpm) {
|
|
243
|
+
eng.revLimiterActive = false;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Engine output torque
|
|
247
|
+
if (eng.revLimiterActive) {
|
|
248
|
+
eng.grossTorque = 0.0;
|
|
249
|
+
} else {
|
|
250
|
+
eng.grossTorque = sampleEngineCurve(config.engine, eng.rpm) * eng.throttle;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Idle governor assist
|
|
254
|
+
if (eng.rpm < config.engine.idleRpm) {
|
|
255
|
+
const double governor = clamp((config.engine.idleRpm - eng.rpm) / config.engine.idleRpm, 0.0, 1.0);
|
|
256
|
+
eng.grossTorque += governor * config.engine.idleTorque;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const double engineFriction = config.engine.frictionCoefficient * eng.angularVelocity;
|
|
260
|
+
eng.netTorque = quantizeValue(eng.grossTorque - engineFriction);
|
|
261
|
+
|
|
262
|
+
// 3. Transmission output torque
|
|
263
|
+
const double transmissionOutputTorque = eng.netTorque * trans.effectiveRatio *
|
|
264
|
+
config.transmission.efficiency * trans.clutchEngagement;
|
|
265
|
+
|
|
266
|
+
// 4. Differential torque distribution across wheels
|
|
267
|
+
std::array<double, kMaxWheels> rawDriveTorques{};
|
|
268
|
+
const double frontRearSplit = clamp(config.differential.frontRearSplit, 0.0, 1.0);
|
|
269
|
+
|
|
270
|
+
if (config.differential.driveType == DriveType::FWD) {
|
|
271
|
+
const double wL = (wheelStates.size() > 0) ? wheelStates[0].angularVelocity : 0.0;
|
|
272
|
+
const double wR = (wheelStates.size() > 1) ? wheelStates[1].angularVelocity : 0.0;
|
|
273
|
+
splitAxleTorque(
|
|
274
|
+
config.differential.frontDiff,
|
|
275
|
+
transmissionOutputTorque,
|
|
276
|
+
wL, wR,
|
|
277
|
+
config.differential.lsdBiasRatio,
|
|
278
|
+
config.differential.lsdPreload,
|
|
279
|
+
config.differential.lockStiffness,
|
|
280
|
+
rawDriveTorques[0], rawDriveTorques[1]);
|
|
281
|
+
} else if (config.differential.driveType == DriveType::RWD) {
|
|
282
|
+
const double wL = (wheelStates.size() > 2) ? wheelStates[2].angularVelocity : 0.0;
|
|
283
|
+
const double wR = (wheelStates.size() > 3) ? wheelStates[3].angularVelocity : 0.0;
|
|
284
|
+
splitAxleTorque(
|
|
285
|
+
config.differential.rearDiff,
|
|
286
|
+
transmissionOutputTorque,
|
|
287
|
+
wL, wR,
|
|
288
|
+
config.differential.lsdBiasRatio,
|
|
289
|
+
config.differential.lsdPreload,
|
|
290
|
+
config.differential.lockStiffness,
|
|
291
|
+
rawDriveTorques[2], rawDriveTorques[3]);
|
|
292
|
+
} else if (config.differential.driveType == DriveType::AWD) {
|
|
293
|
+
const double frontAxleTorque = transmissionOutputTorque * frontRearSplit;
|
|
294
|
+
const double rearAxleTorque = transmissionOutputTorque * (1.0 - frontRearSplit);
|
|
295
|
+
|
|
296
|
+
const double wFL = (wheelStates.size() > 0) ? wheelStates[0].angularVelocity : 0.0;
|
|
297
|
+
const double wFR = (wheelStates.size() > 1) ? wheelStates[1].angularVelocity : 0.0;
|
|
298
|
+
splitAxleTorque(
|
|
299
|
+
config.differential.frontDiff,
|
|
300
|
+
frontAxleTorque,
|
|
301
|
+
wFL, wFR,
|
|
302
|
+
config.differential.lsdBiasRatio,
|
|
303
|
+
config.differential.lsdPreload,
|
|
304
|
+
config.differential.lockStiffness,
|
|
305
|
+
rawDriveTorques[0], rawDriveTorques[1]);
|
|
306
|
+
|
|
307
|
+
const double wRL = (wheelStates.size() > 2) ? wheelStates[2].angularVelocity : 0.0;
|
|
308
|
+
const double wRR = (wheelStates.size() > 3) ? wheelStates[3].angularVelocity : 0.0;
|
|
309
|
+
splitAxleTorque(
|
|
310
|
+
config.differential.rearDiff,
|
|
311
|
+
rearAxleTorque,
|
|
312
|
+
wRL, wRR,
|
|
313
|
+
config.differential.lsdBiasRatio,
|
|
314
|
+
config.differential.lsdPreload,
|
|
315
|
+
config.differential.lockStiffness,
|
|
316
|
+
rawDriveTorques[2], rawDriveTorques[3]);
|
|
317
|
+
} else if (config.differential.driveType == DriveType::Custom) {
|
|
318
|
+
for (std::uint32_t i = 0; i < wheelCount; ++i) {
|
|
319
|
+
rawDriveTorques[i] = quantizeValue(transmissionOutputTorque * config.differential.customDriveDistribution[i]);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// 5. Brake torque calculation
|
|
324
|
+
const double serviceBrake = clamp(input.brake, 0.0, 1.0);
|
|
325
|
+
const double handbrake = clamp(input.handbrake, 0.0, 1.0);
|
|
326
|
+
const double frontBias = clamp(config.brakes.frontBrakeBias, 0.0, 1.0);
|
|
327
|
+
const double rearBias = 1.0 - frontBias;
|
|
328
|
+
|
|
329
|
+
std::uint32_t handbrakeWheelCount = 0;
|
|
330
|
+
for (std::uint32_t i = 0; i < wheelCount; ++i) {
|
|
331
|
+
if (config.brakes.handbrakeWheels[i]) {
|
|
332
|
+
handbrakeWheelCount++;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
std::array<double, kMaxWheels> rawBrakeTorques{};
|
|
337
|
+
for (std::uint32_t i = 0; i < wheelCount; ++i) {
|
|
338
|
+
double serviceDemand = 0.0;
|
|
339
|
+
if (i == 0 || i == 1) { // Front axle
|
|
340
|
+
serviceDemand = 0.5 * frontBias * config.brakes.maxServiceBrakeTorque * serviceBrake;
|
|
341
|
+
} else if (i == 2 || i == 3) { // Rear axle
|
|
342
|
+
serviceDemand = 0.5 * rearBias * config.brakes.maxServiceBrakeTorque * serviceBrake;
|
|
343
|
+
} else if (config.brakes.customBrakeDistribution[i] > 0.0) {
|
|
344
|
+
serviceDemand = config.brakes.customBrakeDistribution[i] * config.brakes.maxServiceBrakeTorque * serviceBrake;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
double handbrakeDemand = 0.0;
|
|
348
|
+
if (config.brakes.handbrakeWheels[i] && handbrakeWheelCount > 0) {
|
|
349
|
+
handbrakeDemand = (config.brakes.maxHandbrakeTorque / static_cast<double>(handbrakeWheelCount)) * handbrake;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
rawBrakeTorques[i] = serviceDemand + handbrakeDemand;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// 6. Wheel dynamics integration & longitudinal force generation
|
|
356
|
+
// Determinism rule: Iterate strictly in index order 0 .. wheelCount - 1
|
|
357
|
+
double totalDriveForceAccum = 0.0;
|
|
358
|
+
double totalBrakeTorqueAccum = 0.0;
|
|
359
|
+
double totalOutputTorqueAccum = 0.0;
|
|
360
|
+
|
|
361
|
+
for (std::uint32_t i = 0; i < wheelCount; ++i) {
|
|
362
|
+
WheelOutput& wOut = output.wheels[i];
|
|
363
|
+
const double currentAngularVel = (i < wheelStates.size()) ? wheelStates[i].angularVelocity : 0.0;
|
|
364
|
+
const bool grounded = (i < wheelStates.size()) ? wheelStates[i].grounded : false;
|
|
365
|
+
const double normalForce = (i < wheelStates.size()) ? wheelStates[i].normalForce : 0.0;
|
|
366
|
+
const double tireFriction = (i < wheelStates.size()) ? wheelStates[i].friction : 0.8;
|
|
367
|
+
const double radius = std::max(0.01, config.wheelRadii[i]);
|
|
368
|
+
const double inertia = std::max(0.01, config.wheelInertias[i]);
|
|
369
|
+
|
|
370
|
+
const double driveTorque = rawDriveTorques[i];
|
|
371
|
+
const double brakeDemand = rawBrakeTorques[i];
|
|
372
|
+
|
|
373
|
+
// Dissipative braking: opposing wheel rotation direction
|
|
374
|
+
double appliedBrakeTorque = 0.0;
|
|
375
|
+
bool isLocked = false;
|
|
376
|
+
|
|
377
|
+
if (brakeDemand > kEpsilon) {
|
|
378
|
+
const double maxStopTorque = (std::abs(currentAngularVel) * inertia) / dt;
|
|
379
|
+
if (brakeDemand >= maxStopTorque) {
|
|
380
|
+
appliedBrakeTorque = maxStopTorque;
|
|
381
|
+
isLocked = true;
|
|
382
|
+
} else {
|
|
383
|
+
appliedBrakeTorque = brakeDemand;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
wOut.driveTorque = quantizeValue(driveTorque);
|
|
388
|
+
wOut.brakeTorque = quantizeValue(appliedBrakeTorque);
|
|
389
|
+
wOut.isLocked = isLocked;
|
|
390
|
+
|
|
391
|
+
// Contact force at road
|
|
392
|
+
double longitudinalForce = 0.0;
|
|
393
|
+
if (grounded && normalForce > 0.0) {
|
|
394
|
+
const double rawFx = wOut.driveTorque / radius;
|
|
395
|
+
const double maxFx = tireFriction * normalForce;
|
|
396
|
+
longitudinalForce = clamp(rawFx, -maxFx, maxFx);
|
|
397
|
+
}
|
|
398
|
+
wOut.longitudinalForce = quantizeValue(longitudinalForce);
|
|
399
|
+
|
|
400
|
+
// Dynamic wheel acceleration
|
|
401
|
+
const double reactionTorque = -wOut.longitudinalForce * radius;
|
|
402
|
+
const double brakeDirection = -sgn(currentAngularVel);
|
|
403
|
+
const double netBrakeTorque = wOut.brakeTorque * brakeDirection;
|
|
404
|
+
const double netTorque = wOut.driveTorque + netBrakeTorque + reactionTorque;
|
|
405
|
+
|
|
406
|
+
wOut.netTorque = quantizeValue(netTorque);
|
|
407
|
+
|
|
408
|
+
if (isLocked) {
|
|
409
|
+
wOut.updatedAngularVel = 0.0;
|
|
410
|
+
} else {
|
|
411
|
+
const double alpha = netTorque / inertia;
|
|
412
|
+
wOut.updatedAngularVel = quantizeValue(currentAngularVel + alpha * dt);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Accumulate in fixed index order
|
|
416
|
+
totalDriveForceAccum += wOut.longitudinalForce;
|
|
417
|
+
totalBrakeTorqueAccum += wOut.brakeTorque;
|
|
418
|
+
totalOutputTorqueAccum += wOut.driveTorque;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
output.state.totalDriveForce = quantizeValue(totalDriveForceAccum);
|
|
422
|
+
output.state.totalBrakeTorque = quantizeValue(totalBrakeTorqueAccum);
|
|
423
|
+
output.state.totalOutputTorque = quantizeValue(totalOutputTorqueAccum);
|
|
424
|
+
|
|
425
|
+
return output;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
} // namespace rundot::kinetix::physics::powertrain
|
|
429
|
+
|
|
430
|
+
extern "C" {
|
|
431
|
+
|
|
432
|
+
std::uint32_t rundot_kinetix_powertrain_abi_version() {
|
|
433
|
+
return rundot::kinetix::physics::powertrain::kPowertrainAbiVersion;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
std::uint32_t rundot_kinetix_powertrain_max_wheels() {
|
|
437
|
+
return rundot::kinetix::physics::powertrain::kMaxWheels;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
std::uint32_t rundot_kinetix_powertrain_max_gears() {
|
|
441
|
+
return rundot::kinetix::physics::powertrain::kMaxForwardGears;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
std::int32_t rundot_kinetix_powertrain_sample_engine_curve(
|
|
445
|
+
const double* engineConfigData,
|
|
446
|
+
double rpm,
|
|
447
|
+
double* outTorque) {
|
|
448
|
+
if (engineConfigData == nullptr || outTorque == nullptr) return -1;
|
|
449
|
+
rundot::kinetix::physics::powertrain::EngineConfig config{};
|
|
450
|
+
config.idleRpm = engineConfigData[0];
|
|
451
|
+
config.maxRpm = engineConfigData[1];
|
|
452
|
+
config.revLimiterRpm = engineConfigData[2];
|
|
453
|
+
config.revLimiterRecoveryRpm = engineConfigData[3];
|
|
454
|
+
config.idleTorque = engineConfigData[4];
|
|
455
|
+
config.peakTorque = engineConfigData[5];
|
|
456
|
+
config.peakTorqueRpm = engineConfigData[6];
|
|
457
|
+
config.redlineTorque = engineConfigData[7];
|
|
458
|
+
config.inertia = engineConfigData[8];
|
|
459
|
+
config.frictionCoefficient = engineConfigData[9];
|
|
460
|
+
|
|
461
|
+
*outTorque = rundot::kinetix::physics::powertrain::sampleEngineCurve(config, rpm);
|
|
462
|
+
return 0;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
std::int32_t rundot_kinetix_powertrain_step(
|
|
466
|
+
const double* configData,
|
|
467
|
+
const double* stateData,
|
|
468
|
+
const double* inputData,
|
|
469
|
+
const double* wheelStatesData,
|
|
470
|
+
std::uint32_t wheelCount,
|
|
471
|
+
double dt,
|
|
472
|
+
double* outputData) {
|
|
473
|
+
if (configData == nullptr || stateData == nullptr || inputData == nullptr ||
|
|
474
|
+
wheelStatesData == nullptr || outputData == nullptr) {
|
|
475
|
+
return -1;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
rundot::kinetix::physics::powertrain::PowertrainConfig config{};
|
|
479
|
+
config.engine.idleRpm = configData[0];
|
|
480
|
+
config.engine.maxRpm = configData[1];
|
|
481
|
+
config.engine.revLimiterRpm = configData[2];
|
|
482
|
+
config.engine.revLimiterRecoveryRpm = configData[3];
|
|
483
|
+
config.engine.idleTorque = configData[4];
|
|
484
|
+
config.engine.peakTorque = configData[5];
|
|
485
|
+
config.engine.peakTorqueRpm = configData[6];
|
|
486
|
+
config.engine.redlineTorque = configData[7];
|
|
487
|
+
config.engine.inertia = configData[8];
|
|
488
|
+
config.engine.frictionCoefficient = configData[9];
|
|
489
|
+
|
|
490
|
+
config.transmission.forwardGearCount = static_cast<std::uint32_t>(configData[10]);
|
|
491
|
+
for (std::uint32_t g = 0; g < rundot::kinetix::physics::powertrain::kMaxForwardGears; ++g) {
|
|
492
|
+
config.transmission.forwardRatios[g] = configData[11 + g];
|
|
493
|
+
}
|
|
494
|
+
config.transmission.reverseRatio = configData[19];
|
|
495
|
+
config.transmission.finalDriveRatio = configData[20];
|
|
496
|
+
config.transmission.efficiency = configData[21];
|
|
497
|
+
config.transmission.shiftDelay = configData[22];
|
|
498
|
+
|
|
499
|
+
config.differential.driveType = static_cast<rundot::kinetix::physics::powertrain::DriveType>(configData[23]);
|
|
500
|
+
config.differential.frontDiff = static_cast<rundot::kinetix::physics::powertrain::DifferentialType>(configData[24]);
|
|
501
|
+
config.differential.rearDiff = static_cast<rundot::kinetix::physics::powertrain::DifferentialType>(configData[25]);
|
|
502
|
+
config.differential.frontRearSplit = configData[26];
|
|
503
|
+
config.differential.lsdBiasRatio = configData[27];
|
|
504
|
+
config.differential.lsdPreload = configData[28];
|
|
505
|
+
config.differential.wheelCount = wheelCount;
|
|
506
|
+
|
|
507
|
+
config.brakes.maxServiceBrakeTorque = configData[29];
|
|
508
|
+
config.brakes.frontBrakeBias = configData[30];
|
|
509
|
+
config.brakes.maxHandbrakeTorque = configData[31];
|
|
510
|
+
config.wheelCount = wheelCount;
|
|
511
|
+
|
|
512
|
+
for (std::uint32_t w = 0; w < wheelCount && w < rundot::kinetix::physics::powertrain::kMaxWheels; ++w) {
|
|
513
|
+
config.wheelRadii[w] = configData[32 + w];
|
|
514
|
+
config.wheelInertias[w] = configData[40 + w];
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
rundot::kinetix::physics::powertrain::PowertrainState state{};
|
|
518
|
+
state.engine.rpm = stateData[0];
|
|
519
|
+
state.engine.angularVelocity = stateData[1];
|
|
520
|
+
state.engine.throttle = stateData[2];
|
|
521
|
+
state.engine.grossTorque = stateData[3];
|
|
522
|
+
state.engine.netTorque = stateData[4];
|
|
523
|
+
state.engine.revLimiterActive = (stateData[5] > 0.5);
|
|
524
|
+
state.transmission.currentGear = static_cast<std::int32_t>(stateData[6]);
|
|
525
|
+
state.transmission.targetGear = static_cast<std::int32_t>(stateData[7]);
|
|
526
|
+
state.transmission.shiftTimer = stateData[8];
|
|
527
|
+
state.transmission.isShifting = (stateData[9] > 0.5);
|
|
528
|
+
state.transmission.effectiveRatio = stateData[10];
|
|
529
|
+
state.transmission.clutchEngagement = stateData[11];
|
|
530
|
+
state.totalDriveForce = stateData[12];
|
|
531
|
+
state.totalBrakeTorque = stateData[13];
|
|
532
|
+
state.totalOutputTorque = stateData[14];
|
|
533
|
+
|
|
534
|
+
rundot::kinetix::physics::powertrain::DriverInput input{};
|
|
535
|
+
input.throttle = inputData[0];
|
|
536
|
+
input.brake = inputData[1];
|
|
537
|
+
input.handbrake = inputData[2];
|
|
538
|
+
input.clutch = inputData[3];
|
|
539
|
+
input.targetGear = static_cast<std::int32_t>(inputData[4]);
|
|
540
|
+
|
|
541
|
+
std::array<rundot::kinetix::physics::powertrain::WheelDynamicState, rundot::kinetix::physics::powertrain::kMaxWheels> wheelStatesStorage{};
|
|
542
|
+
for (std::uint32_t w = 0; w < wheelCount && w < rundot::kinetix::physics::powertrain::kMaxWheels; ++w) {
|
|
543
|
+
const std::size_t offset = static_cast<std::size_t>(w * 4);
|
|
544
|
+
wheelStatesStorage[w].angularVelocity = wheelStatesData[offset + 0];
|
|
545
|
+
wheelStatesStorage[w].grounded = (wheelStatesData[offset + 1] > 0.5);
|
|
546
|
+
wheelStatesStorage[w].normalForce = wheelStatesData[offset + 2];
|
|
547
|
+
wheelStatesStorage[w].friction = wheelStatesData[offset + 3];
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
std::span<const rundot::kinetix::physics::powertrain::WheelDynamicState> wheelSpan(
|
|
551
|
+
wheelStatesStorage.data(), std::min(wheelCount, rundot::kinetix::physics::powertrain::kMaxWheels));
|
|
552
|
+
|
|
553
|
+
const auto output = rundot::kinetix::physics::powertrain::stepPowertrain(
|
|
554
|
+
config, state, input, wheelSpan, dt);
|
|
555
|
+
|
|
556
|
+
// Encode output
|
|
557
|
+
outputData[0] = output.state.engine.rpm;
|
|
558
|
+
outputData[1] = output.state.engine.angularVelocity;
|
|
559
|
+
outputData[2] = output.state.engine.throttle;
|
|
560
|
+
outputData[3] = output.state.engine.grossTorque;
|
|
561
|
+
outputData[4] = output.state.engine.netTorque;
|
|
562
|
+
outputData[5] = output.state.engine.revLimiterActive ? 1.0 : 0.0;
|
|
563
|
+
outputData[6] = static_cast<double>(output.state.transmission.currentGear);
|
|
564
|
+
outputData[7] = static_cast<double>(output.state.transmission.targetGear);
|
|
565
|
+
outputData[8] = output.state.transmission.shiftTimer;
|
|
566
|
+
outputData[9] = output.state.transmission.isShifting ? 1.0 : 0.0;
|
|
567
|
+
outputData[10] = output.state.transmission.effectiveRatio;
|
|
568
|
+
outputData[11] = output.state.transmission.clutchEngagement;
|
|
569
|
+
outputData[12] = output.state.totalDriveForce;
|
|
570
|
+
outputData[13] = output.state.totalBrakeTorque;
|
|
571
|
+
outputData[14] = output.state.totalOutputTorque;
|
|
572
|
+
|
|
573
|
+
for (std::uint32_t w = 0; w < wheelCount && w < rundot::kinetix::physics::powertrain::kMaxWheels; ++w) {
|
|
574
|
+
const std::size_t offset = static_cast<std::size_t>(15 + w * 6);
|
|
575
|
+
outputData[offset + 0] = output.wheels[w].driveTorque;
|
|
576
|
+
outputData[offset + 1] = output.wheels[w].brakeTorque;
|
|
577
|
+
outputData[offset + 2] = output.wheels[w].netTorque;
|
|
578
|
+
outputData[offset + 3] = output.wheels[w].updatedAngularVel;
|
|
579
|
+
outputData[offset + 4] = output.wheels[w].longitudinalForce;
|
|
580
|
+
outputData[offset + 5] = output.wheels[w].isLocked ? 1.0 : 0.0;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
return 0;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
} // extern "C"
|