@vworlds/box2d3-wasm 0.0.0-stage → 6.0.1
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/LICENSE +21 -0
- package/README.md +301 -2
- package/THIRD_PARTY_NOTICES.md +65 -0
- package/dist/compat/Box2D.compat.d.ts +1388 -0
- package/dist/compat/Box2D.compat.mjs +2886 -0
- package/dist/compat/Box2D.compat.wasm +0 -0
- package/dist/deluxe/Box2D.deluxe.d.ts +1388 -0
- package/dist/deluxe/Box2D.deluxe.mjs +2886 -0
- package/dist/deluxe/Box2D.deluxe.wasm +0 -0
- package/dist/entry.d.ts +4 -0
- package/dist/entry.mjs +32 -0
- package/dist/fastpath.d.ts +192 -0
- package/dist/fastpath.mjs +143 -0
- package/dist/fastpath_body.gen.d.ts +91 -0
- package/package.json +48 -4
|
Binary file
|
package/dist/entry.d.ts
ADDED
package/dist/entry.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { MainModule, ModuleOptions } from './deluxe/Box2D.deluxe'
|
|
3
|
+
* @param {ModuleOptions} options
|
|
4
|
+
* @return {Promise<MainModule>}
|
|
5
|
+
*/
|
|
6
|
+
export default async (options, ...args) => {
|
|
7
|
+
/**
|
|
8
|
+
* This validation expression comes from wasm-feature-detect:
|
|
9
|
+
* https://github.com/GoogleChromeLabs/wasm-feature-detect
|
|
10
|
+
*
|
|
11
|
+
* Copyright 2019 Google Inc. All Rights Reserved.
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const hasSIMD = WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]));
|
|
23
|
+
/** @type {{ 'default': (options?: unknown) => MainModule) }} */
|
|
24
|
+
const Box2DModule = await (
|
|
25
|
+
hasSIMD
|
|
26
|
+
? import('./deluxe/Box2D.deluxe.mjs')
|
|
27
|
+
: import('./compat/Box2D.compat.mjs')
|
|
28
|
+
);
|
|
29
|
+
const { 'default': Box2DFactory } = Box2DModule;
|
|
30
|
+
// awaiting gives us a better stack trace (at the cost of an extra microtask)
|
|
31
|
+
return await Box2DFactory(options, ...args);
|
|
32
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// Types for box2d3-wasm/fastpath: the b2x_ fast path (plain wasm exports, no embind).
|
|
2
|
+
// Reference: docs/fastpath.md in the vworlds/box2d3-wasm repository.
|
|
3
|
+
import type { MainModule } from "./deluxe/Box2D.deluxe.js";
|
|
4
|
+
import type { FastPathBodyExports } from "./fastpath_body.gen.js";
|
|
5
|
+
|
|
6
|
+
export type { FastPathBodyExports } from "./fastpath_body.gen.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The hand-written b2x_ exports (src/fastpath.cpp), typed by parameter name. All arguments and
|
|
10
|
+
* results are plain numbers: ids are packed (see {@link FastPath.world} and {@link FastPath.rev}),
|
|
11
|
+
* pointers are byte addresses in wasm memory, floats cross as f32.
|
|
12
|
+
*/
|
|
13
|
+
export interface FastPathCoreExports {
|
|
14
|
+
/** JSON layout of every exposed struct (sizes and byte offsets from sizeof/offsetof); a C
|
|
15
|
+
* string at the returned address. Read it through {@link FastPath.layout}. */
|
|
16
|
+
_b2x_GetLayout(): number;
|
|
17
|
+
/** Fast-path API version (layout.constants.version). */
|
|
18
|
+
_b2x_GetVersion(): number;
|
|
19
|
+
/** Box2D's profile timers on (1, default) or off (0). Off: b2World_GetProfile reads zeros,
|
|
20
|
+
* results are unaffected, each step makes no JavaScript clock calls. Global to the module. */
|
|
21
|
+
_b2x_SetProfileTimers(enabled: number): void;
|
|
22
|
+
_b2x_GetProfileTimers(): number;
|
|
23
|
+
/** b2World_Step(world, timeStep, subStepCount). May grow memory. */
|
|
24
|
+
_b2x_World_Step(world: number, timeStep: number, subStepCount: number): void;
|
|
25
|
+
/** Move-event count of the last step. */
|
|
26
|
+
_b2x_World_GetMoveCount(world: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* Write one b2xMove record (layout.move) per move event of the last step, in Box2D's event
|
|
29
|
+
* order, to `outPtr` (at most `capacity`). Returns the number of records the export produced;
|
|
30
|
+
* if it exceeds `capacity` only `capacity` were written: grow and call again (the events stay
|
|
31
|
+
* valid until the next step). `flags`: layout.constants.exportVelocity | exportDynamicOnly.
|
|
32
|
+
* Never grows memory.
|
|
33
|
+
*/
|
|
34
|
+
_b2x_World_ExportMoves(world: number, outPtr: number, capacity: number, flags: number): number;
|
|
35
|
+
/** b2x_World_Step then b2x_World_ExportMoves in one crossing. */
|
|
36
|
+
_b2x_World_StepAndExportMoves(
|
|
37
|
+
world: number,
|
|
38
|
+
timeStep: number,
|
|
39
|
+
subStepCount: number,
|
|
40
|
+
outPtr: number,
|
|
41
|
+
capacity: number,
|
|
42
|
+
flags: number
|
|
43
|
+
): number;
|
|
44
|
+
/** Write {ptr, count} (layout.span) of Box2D's own b2BodyMoveEvent array (layout.moveEvent). */
|
|
45
|
+
_b2x_World_GetMoveEventSpan(world: number, outPtr: number): void;
|
|
46
|
+
/** Write the begin/end/hit spans (layout.contactSpans) of Box2D's contact event arrays
|
|
47
|
+
* (layouts contactBegin, contactEnd, contactHit). Valid until the next step or world change. */
|
|
48
|
+
_b2x_World_GetContactSpans(world: number, outPtr: number): void;
|
|
49
|
+
/** Write the begin/end spans (layout.sensorSpans) of Box2D's sensor event arrays
|
|
50
|
+
* (layouts sensorBegin, sensorEnd). Valid until the next step or world change. */
|
|
51
|
+
_b2x_World_GetSensorSpans(world: number, outPtr: number): void;
|
|
52
|
+
/** Store an unsigned 32-bit integer in the body's user data; move records carry it. */
|
|
53
|
+
_b2x_Body_SetUserData(index1: number, rev: number, value: number): void;
|
|
54
|
+
_b2x_Body_GetUserData(index1: number, rev: number): number;
|
|
55
|
+
_b2x_Shape_SetUserData(index1: number, rev: number, value: number): void;
|
|
56
|
+
_b2x_Shape_GetUserData(index1: number, rev: number): number;
|
|
57
|
+
/** b2Body_SetTransform(id, {x, y}, b2Body_GetRotation(id)). */
|
|
58
|
+
_b2x_Body_SetPosition(index1: number, rev: number, x: number, y: number): void;
|
|
59
|
+
/** b2Body_SetTransform(id, b2Body_GetPosition(id), b2MakeRot(angle)). */
|
|
60
|
+
_b2x_Body_SetAngle(index1: number, rev: number, angle: number): void;
|
|
61
|
+
/** Write position, rotation and b2Rot_GetAngle (layout.pose) to `outPtr`. */
|
|
62
|
+
_b2x_Body_GetPose(index1: number, rev: number, outPtr: number): void;
|
|
63
|
+
/** Write awake, velocities, damping, local center, mass, gravity scale (layout.motion). */
|
|
64
|
+
_b2x_Body_GetMotion(index1: number, rev: number, outPtr: number): void;
|
|
65
|
+
_malloc(bytes: number): number;
|
|
66
|
+
_free(ptr: number): void;
|
|
67
|
+
wasmMemory: WebAssembly.Memory;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The module with every b2x_ export typed by parameter name, on top of the embind API. */
|
|
71
|
+
export type FastPathModule = MainModule & FastPathCoreExports & FastPathBodyExports;
|
|
72
|
+
|
|
73
|
+
/** A struct layout: `size` and field offsets, all in bytes, generated in C with sizeof/offsetof. */
|
|
74
|
+
export type StructLayout<F extends string> = { size: number } & Record<F, number>;
|
|
75
|
+
|
|
76
|
+
export interface FastPathLayout {
|
|
77
|
+
constants: {
|
|
78
|
+
version: number;
|
|
79
|
+
/** Export flag: fill vx/vy/w from b2Body_GetLinearVelocity / b2Body_GetAngularVelocity. */
|
|
80
|
+
exportVelocity: number;
|
|
81
|
+
/** Export flag: skip bodies that are not dynamic. */
|
|
82
|
+
exportDynamicOnly: number;
|
|
83
|
+
/** b2xMove.flags bit: the move event's fellAsleep. */
|
|
84
|
+
moveFellAsleep: number;
|
|
85
|
+
/** b2xMove.flags: (flags >> moveTypeShift) & 3 is the b2BodyType (0 static, 1 kinematic, 2 dynamic). */
|
|
86
|
+
moveTypeShift: number;
|
|
87
|
+
/** b2xMove.flags bit: the body id was valid at export (velocities are only read then). */
|
|
88
|
+
moveValid: number;
|
|
89
|
+
};
|
|
90
|
+
/** b2x_World_ExportMoves record. All fields 4-byte aligned. */
|
|
91
|
+
move: StructLayout<
|
|
92
|
+
"bodyIndex" | "rev" | "userData" | "flags" | "x" | "y" | "c" | "s" | "angle" | "vx" | "vy" | "w"
|
|
93
|
+
>;
|
|
94
|
+
/** b2x_Body_GetPose output. */
|
|
95
|
+
pose: StructLayout<"x" | "y" | "c" | "s" | "angle">;
|
|
96
|
+
/** b2x_Body_GetMotion output (`awake` is an int32 1/0). */
|
|
97
|
+
motion: StructLayout<
|
|
98
|
+
| "awake"
|
|
99
|
+
| "vx"
|
|
100
|
+
| "vy"
|
|
101
|
+
| "w"
|
|
102
|
+
| "linearDamping"
|
|
103
|
+
| "angularDamping"
|
|
104
|
+
| "localCenterX"
|
|
105
|
+
| "localCenterY"
|
|
106
|
+
| "mass"
|
|
107
|
+
| "gravityScale"
|
|
108
|
+
>;
|
|
109
|
+
span: StructLayout<"ptr" | "count">;
|
|
110
|
+
contactSpans: StructLayout<"beginPtr" | "beginCount" | "endPtr" | "endCount" | "hitPtr" | "hitCount">;
|
|
111
|
+
sensorSpans: StructLayout<"beginPtr" | "beginCount" | "endPtr" | "endCount">;
|
|
112
|
+
/** Box2D's b2BodyMoveEvent. `bodyWorld0`/`bodyGeneration` are uint16, `fellAsleep` a byte. */
|
|
113
|
+
moveEvent: StructLayout<
|
|
114
|
+
"userData" | "x" | "y" | "c" | "s" | "body" | "bodyWorld0" | "bodyGeneration" | "fellAsleep"
|
|
115
|
+
>;
|
|
116
|
+
contactBegin: StructLayout<ShapePairFields | "contact">;
|
|
117
|
+
contactEnd: StructLayout<ShapePairFields | "contact">;
|
|
118
|
+
contactHit: StructLayout<
|
|
119
|
+
ShapePairFields | "pointX" | "pointY" | "normalX" | "normalY" | "approachSpeed"
|
|
120
|
+
>;
|
|
121
|
+
sensorBegin: StructLayout<SensorPairFields>;
|
|
122
|
+
sensorEnd: StructLayout<SensorPairFields>;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
type ShapePairFields =
|
|
126
|
+
| "shapeA"
|
|
127
|
+
| "shapeAWorld0"
|
|
128
|
+
| "shapeAGeneration"
|
|
129
|
+
| "shapeB"
|
|
130
|
+
| "shapeBWorld0"
|
|
131
|
+
| "shapeBGeneration";
|
|
132
|
+
type SensorPairFields =
|
|
133
|
+
| "sensorShape"
|
|
134
|
+
| "sensorShapeWorld0"
|
|
135
|
+
| "sensorShapeGeneration"
|
|
136
|
+
| "visitorShape"
|
|
137
|
+
| "visitorShapeWorld0"
|
|
138
|
+
| "visitorShapeGeneration";
|
|
139
|
+
|
|
140
|
+
export interface FastPath {
|
|
141
|
+
readonly module: FastPathModule;
|
|
142
|
+
readonly memory: WebAssembly.Memory;
|
|
143
|
+
readonly layout: FastPathLayout;
|
|
144
|
+
/**
|
|
145
|
+
* Whole-memory views. Memory can grow during any call that allocates in wasm (creating
|
|
146
|
+
* worlds/bodies/shapes/joints, stepping, embind calls returning by value, malloc). Call
|
|
147
|
+
* {@link sync} after such a call and before reading; re-read these properties after a sync.
|
|
148
|
+
*/
|
|
149
|
+
readonly buffer: ArrayBufferLike;
|
|
150
|
+
readonly u8: Uint8Array;
|
|
151
|
+
readonly u16: Uint16Array;
|
|
152
|
+
readonly i32: Int32Array;
|
|
153
|
+
readonly u32: Uint32Array;
|
|
154
|
+
readonly f32: Float32Array;
|
|
155
|
+
/** Rebuild the views if memory grew since the last sync. Returns true when it rebuilt them. */
|
|
156
|
+
sync(): boolean;
|
|
157
|
+
/** Packed world id: index1 | generation << 16. */
|
|
158
|
+
world(worldId: { index1: number; generation: number }): number;
|
|
159
|
+
/** `rev` half of a packed body/shape/chain/joint id: world0 | generation << 16. */
|
|
160
|
+
rev(id: { world0: number; generation: number }): number;
|
|
161
|
+
/** malloc + sync. Throws on failure. */
|
|
162
|
+
alloc(bytes: number): number;
|
|
163
|
+
free(ptr: number): void;
|
|
164
|
+
createMoveExporter(initialCapacity?: number): MoveExporter;
|
|
165
|
+
/**
|
|
166
|
+
* Turn Box2D's profile timers on or off (b2World_GetProfile reads 0 while off). They never
|
|
167
|
+
* affect simulation results; off removes a JS clock call per timed section of every step.
|
|
168
|
+
*/
|
|
169
|
+
setProfileTimers(enabled: boolean): void;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface MoveExporter {
|
|
173
|
+
/** Byte address of record 0. */
|
|
174
|
+
readonly ptr: number;
|
|
175
|
+
/** Word index of record 0 in the i32/u32/f32 views. */
|
|
176
|
+
readonly base: number;
|
|
177
|
+
/** Words per record. */
|
|
178
|
+
readonly stride: number;
|
|
179
|
+
readonly capacity: number;
|
|
180
|
+
/** Records written by the last export. */
|
|
181
|
+
readonly count: number;
|
|
182
|
+
/**
|
|
183
|
+
* Export the world's move events (one record each, Box2D's event order) and sync the views.
|
|
184
|
+
* `flags`: layout.constants.exportVelocity | exportDynamicOnly.
|
|
185
|
+
*/
|
|
186
|
+
exportMoves(world: number, flags: number): number;
|
|
187
|
+
/** Step the world, then export, in one crossing. */
|
|
188
|
+
stepAndExportMoves(world: number, timeStep: number, subStepCount: number, flags: number): number;
|
|
189
|
+
dispose(): void;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function createFastPath(module: MainModule): FastPath;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// box2d3-wasm/fastpath: helpers for the b2x_ fast path (see fastpath.d.ts and docs/fastpath.md).
|
|
2
|
+
//
|
|
3
|
+
// The fast path is a set of plain wasm exports on the module (module._b2x_*). This helper parses
|
|
4
|
+
// their struct layout (generated in C from sizeof/offsetof), keeps whole-memory typed views that
|
|
5
|
+
// survive memory growth, packs embind ids into integers and manages export buffers. None of its
|
|
6
|
+
// per-step methods allocate.
|
|
7
|
+
|
|
8
|
+
export function createFastPath(module) {
|
|
9
|
+
const memory = module.wasmMemory;
|
|
10
|
+
if (!memory || typeof module._b2x_GetLayout !== "function") {
|
|
11
|
+
throw new Error("box2d3-wasm build without the b2x_ fast path");
|
|
12
|
+
}
|
|
13
|
+
const fp = {
|
|
14
|
+
module,
|
|
15
|
+
memory,
|
|
16
|
+
layout: undefined,
|
|
17
|
+
buffer: undefined,
|
|
18
|
+
u8: undefined,
|
|
19
|
+
u16: undefined,
|
|
20
|
+
i32: undefined,
|
|
21
|
+
u32: undefined,
|
|
22
|
+
f32: undefined,
|
|
23
|
+
sync() {
|
|
24
|
+
const buffer = memory.buffer;
|
|
25
|
+
if (buffer === fp.buffer) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
fp.buffer = buffer;
|
|
29
|
+
fp.u8 = new Uint8Array(buffer);
|
|
30
|
+
fp.u16 = new Uint16Array(buffer);
|
|
31
|
+
fp.i32 = new Int32Array(buffer);
|
|
32
|
+
fp.u32 = new Uint32Array(buffer);
|
|
33
|
+
fp.f32 = new Float32Array(buffer);
|
|
34
|
+
return true;
|
|
35
|
+
},
|
|
36
|
+
world(worldId) {
|
|
37
|
+
return worldId.index1 | (worldId.generation << 16);
|
|
38
|
+
},
|
|
39
|
+
rev(id) {
|
|
40
|
+
return id.world0 | (id.generation << 16);
|
|
41
|
+
},
|
|
42
|
+
alloc(bytes) {
|
|
43
|
+
const ptr = module._malloc(bytes);
|
|
44
|
+
if (ptr === 0) {
|
|
45
|
+
throw new Error(`b2x: out of memory allocating ${bytes} bytes`);
|
|
46
|
+
}
|
|
47
|
+
fp.sync();
|
|
48
|
+
return ptr;
|
|
49
|
+
},
|
|
50
|
+
free(ptr) {
|
|
51
|
+
module._free(ptr);
|
|
52
|
+
},
|
|
53
|
+
createMoveExporter(initialCapacity = 64) {
|
|
54
|
+
return new MoveExporter(fp, initialCapacity);
|
|
55
|
+
},
|
|
56
|
+
setProfileTimers(enabled) {
|
|
57
|
+
if (typeof module._b2x_SetProfileTimers === "function") {
|
|
58
|
+
module._b2x_SetProfileTimers(enabled ? 1 : 0);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
fp.sync();
|
|
63
|
+
fp.layout = readLayout(fp, module._b2x_GetLayout());
|
|
64
|
+
if (fp.layout.constants.version !== module._b2x_GetVersion()) {
|
|
65
|
+
throw new Error("b2x layout version mismatch");
|
|
66
|
+
}
|
|
67
|
+
return fp;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function readLayout(fp, ptr) {
|
|
71
|
+
const u8 = fp.u8;
|
|
72
|
+
let end = ptr;
|
|
73
|
+
while (u8[end] !== 0) {
|
|
74
|
+
end++;
|
|
75
|
+
}
|
|
76
|
+
// slice() copies into a non-shared buffer, which TextDecoder accepts.
|
|
77
|
+
return JSON.parse(new TextDecoder().decode(u8.slice(ptr, end)));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Owns a growable wasm buffer of b2xMove records and fills it with one crossing per call. */
|
|
81
|
+
class MoveExporter {
|
|
82
|
+
constructor(fp, initialCapacity) {
|
|
83
|
+
this.fp = fp;
|
|
84
|
+
this.capacity = Math.max(1, initialCapacity | 0);
|
|
85
|
+
this.ptr = fp.alloc(this.capacity * fp.layout.move.size);
|
|
86
|
+
/** Word index of record 0 in fp.i32 / fp.u32 / fp.f32. */
|
|
87
|
+
this.base = this.ptr >> 2;
|
|
88
|
+
/** Words per record. */
|
|
89
|
+
this.stride = fp.layout.move.size >> 2;
|
|
90
|
+
this.count = 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Export the moves of `world` (packed id). Returns the record count; views are synced. */
|
|
94
|
+
exportMoves(world, flags) {
|
|
95
|
+
const fp = this.fp;
|
|
96
|
+
let count = fp.module._b2x_World_ExportMoves(world, this.ptr, this.capacity, flags);
|
|
97
|
+
if (count > this.capacity) {
|
|
98
|
+
this.grow(count);
|
|
99
|
+
count = fp.module._b2x_World_ExportMoves(world, this.ptr, this.capacity, flags);
|
|
100
|
+
}
|
|
101
|
+
fp.sync();
|
|
102
|
+
this.count = count;
|
|
103
|
+
return count;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Step `world`, then export its moves, in one crossing. */
|
|
107
|
+
stepAndExportMoves(world, timeStep, subStepCount, flags) {
|
|
108
|
+
const fp = this.fp;
|
|
109
|
+
let count = fp.module._b2x_World_StepAndExportMoves(
|
|
110
|
+
world,
|
|
111
|
+
timeStep,
|
|
112
|
+
subStepCount,
|
|
113
|
+
this.ptr,
|
|
114
|
+
this.capacity,
|
|
115
|
+
flags
|
|
116
|
+
);
|
|
117
|
+
if (count > this.capacity) {
|
|
118
|
+
this.grow(count);
|
|
119
|
+
count = fp.module._b2x_World_ExportMoves(world, this.ptr, this.capacity, flags);
|
|
120
|
+
}
|
|
121
|
+
fp.sync();
|
|
122
|
+
this.count = count;
|
|
123
|
+
return count;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
grow(minCapacity) {
|
|
127
|
+
const fp = this.fp;
|
|
128
|
+
let capacity = this.capacity;
|
|
129
|
+
while (capacity < minCapacity) {
|
|
130
|
+
capacity *= 2;
|
|
131
|
+
}
|
|
132
|
+
fp.free(this.ptr);
|
|
133
|
+
this.capacity = capacity;
|
|
134
|
+
this.ptr = fp.alloc(capacity * fp.layout.move.size);
|
|
135
|
+
this.base = this.ptr >> 2;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
dispose() {
|
|
139
|
+
this.fp.free(this.ptr);
|
|
140
|
+
this.ptr = 0;
|
|
141
|
+
this.capacity = 0;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// GENERATED by scripts/gen_fastpath.py from box2d/include/box2d/box2d.h. Do not edit.
|
|
2
|
+
/** Raw b2x_Body_* exports on the module: body id as (index1, rev). Struct results go to `out`. */
|
|
3
|
+
export interface FastPathBodyExports {
|
|
4
|
+
/** 1 or 0 */
|
|
5
|
+
_b2x_Body_IsValid(index1: number, rev: number): number;
|
|
6
|
+
/** b2BodyType value */
|
|
7
|
+
_b2x_Body_GetType(index1: number, rev: number): number;
|
|
8
|
+
_b2x_Body_SetType(index1: number, rev: number, type: number): void;
|
|
9
|
+
/** out: x, y */
|
|
10
|
+
_b2x_Body_GetPosition(index1: number, rev: number, outPtr: number): void;
|
|
11
|
+
/** out: c, s */
|
|
12
|
+
_b2x_Body_GetRotation(index1: number, rev: number, outPtr: number): void;
|
|
13
|
+
/** out: px, py, qc, qs */
|
|
14
|
+
_b2x_Body_GetTransform(index1: number, rev: number, outPtr: number): void;
|
|
15
|
+
_b2x_Body_SetTransform(index1: number, rev: number, positionX: number, positionY: number, rotationC: number, rotationS: number): void;
|
|
16
|
+
/** out: x, y */
|
|
17
|
+
_b2x_Body_GetLocalPoint(index1: number, rev: number, worldPointX: number, worldPointY: number, outPtr: number): void;
|
|
18
|
+
/** out: x, y */
|
|
19
|
+
_b2x_Body_GetWorldPoint(index1: number, rev: number, localPointX: number, localPointY: number, outPtr: number): void;
|
|
20
|
+
/** out: x, y */
|
|
21
|
+
_b2x_Body_GetLocalVector(index1: number, rev: number, worldVectorX: number, worldVectorY: number, outPtr: number): void;
|
|
22
|
+
/** out: x, y */
|
|
23
|
+
_b2x_Body_GetWorldVector(index1: number, rev: number, localVectorX: number, localVectorY: number, outPtr: number): void;
|
|
24
|
+
/** out: x, y */
|
|
25
|
+
_b2x_Body_GetLinearVelocity(index1: number, rev: number, outPtr: number): void;
|
|
26
|
+
_b2x_Body_GetAngularVelocity(index1: number, rev: number): number;
|
|
27
|
+
_b2x_Body_SetLinearVelocity(index1: number, rev: number, linearVelocityX: number, linearVelocityY: number): void;
|
|
28
|
+
_b2x_Body_SetAngularVelocity(index1: number, rev: number, angularVelocity: number): void;
|
|
29
|
+
_b2x_Body_SetTargetTransform(index1: number, rev: number, targetPx: number, targetPy: number, targetQc: number, targetQs: number, timeStep: number): void;
|
|
30
|
+
/** out: x, y */
|
|
31
|
+
_b2x_Body_GetLocalPointVelocity(index1: number, rev: number, localPointX: number, localPointY: number, outPtr: number): void;
|
|
32
|
+
/** out: x, y */
|
|
33
|
+
_b2x_Body_GetWorldPointVelocity(index1: number, rev: number, worldPointX: number, worldPointY: number, outPtr: number): void;
|
|
34
|
+
_b2x_Body_ApplyForce(index1: number, rev: number, forceX: number, forceY: number, pointX: number, pointY: number, wake: number): void;
|
|
35
|
+
_b2x_Body_ApplyForceToCenter(index1: number, rev: number, forceX: number, forceY: number, wake: number): void;
|
|
36
|
+
_b2x_Body_ApplyTorque(index1: number, rev: number, torque: number, wake: number): void;
|
|
37
|
+
_b2x_Body_ApplyLinearImpulse(index1: number, rev: number, impulseX: number, impulseY: number, pointX: number, pointY: number, wake: number): void;
|
|
38
|
+
_b2x_Body_ApplyLinearImpulseToCenter(index1: number, rev: number, impulseX: number, impulseY: number, wake: number): void;
|
|
39
|
+
_b2x_Body_ApplyAngularImpulse(index1: number, rev: number, impulse: number, wake: number): void;
|
|
40
|
+
_b2x_Body_GetMass(index1: number, rev: number): number;
|
|
41
|
+
_b2x_Body_GetRotationalInertia(index1: number, rev: number): number;
|
|
42
|
+
/** out: x, y */
|
|
43
|
+
_b2x_Body_GetLocalCenterOfMass(index1: number, rev: number, outPtr: number): void;
|
|
44
|
+
/** out: x, y */
|
|
45
|
+
_b2x_Body_GetWorldCenterOfMass(index1: number, rev: number, outPtr: number): void;
|
|
46
|
+
_b2x_Body_SetMassData(index1: number, rev: number, massDataMass: number, massDataCenterX: number, massDataCenterY: number, massDataRotationalInertia: number): void;
|
|
47
|
+
/** out: mass, centerX, centerY, rotationalInertia */
|
|
48
|
+
_b2x_Body_GetMassData(index1: number, rev: number, outPtr: number): void;
|
|
49
|
+
_b2x_Body_ApplyMassFromShapes(index1: number, rev: number): void;
|
|
50
|
+
_b2x_Body_SetLinearDamping(index1: number, rev: number, linearDamping: number): void;
|
|
51
|
+
_b2x_Body_GetLinearDamping(index1: number, rev: number): number;
|
|
52
|
+
_b2x_Body_SetAngularDamping(index1: number, rev: number, angularDamping: number): void;
|
|
53
|
+
_b2x_Body_GetAngularDamping(index1: number, rev: number): number;
|
|
54
|
+
_b2x_Body_SetGravityScale(index1: number, rev: number, gravityScale: number): void;
|
|
55
|
+
_b2x_Body_GetGravityScale(index1: number, rev: number): number;
|
|
56
|
+
/** 1 or 0 */
|
|
57
|
+
_b2x_Body_IsAwake(index1: number, rev: number): number;
|
|
58
|
+
_b2x_Body_SetAwake(index1: number, rev: number, awake: number): void;
|
|
59
|
+
_b2x_Body_WakeTouching(index1: number, rev: number): void;
|
|
60
|
+
_b2x_Body_EnableSleep(index1: number, rev: number, enableSleep: number): void;
|
|
61
|
+
/** 1 or 0 */
|
|
62
|
+
_b2x_Body_IsSleepEnabled(index1: number, rev: number): number;
|
|
63
|
+
_b2x_Body_SetSleepThreshold(index1: number, rev: number, sleepThreshold: number): void;
|
|
64
|
+
_b2x_Body_GetSleepThreshold(index1: number, rev: number): number;
|
|
65
|
+
/** 1 or 0 */
|
|
66
|
+
_b2x_Body_IsEnabled(index1: number, rev: number): number;
|
|
67
|
+
_b2x_Body_Disable(index1: number, rev: number): void;
|
|
68
|
+
_b2x_Body_Enable(index1: number, rev: number): void;
|
|
69
|
+
_b2x_Body_SetMotionLocks(index1: number, rev: number, locks: number): void;
|
|
70
|
+
/** bits: 1 linearX, 2 linearY, 4 angularZ */
|
|
71
|
+
_b2x_Body_GetMotionLocks(index1: number, rev: number): number;
|
|
72
|
+
_b2x_Body_SetBullet(index1: number, rev: number, flag: number): void;
|
|
73
|
+
/** 1 or 0 */
|
|
74
|
+
_b2x_Body_IsBullet(index1: number, rev: number): number;
|
|
75
|
+
_b2x_Body_EnableContactEvents(index1: number, rev: number, flag: number): void;
|
|
76
|
+
_b2x_Body_EnableHitEvents(index1: number, rev: number, flag: number): void;
|
|
77
|
+
/** packed world id */
|
|
78
|
+
_b2x_Body_GetWorld(index1: number, rev: number): number;
|
|
79
|
+
_b2x_Body_GetShapeCount(index1: number, rev: number): number;
|
|
80
|
+
/** writes up to capacity (index1, rev) pairs to shapeArrayPtr; returns the count */
|
|
81
|
+
_b2x_Body_GetShapes(index1: number, rev: number, shapeArrayPtr: number, capacity: number): number;
|
|
82
|
+
_b2x_Body_GetJointCount(index1: number, rev: number): number;
|
|
83
|
+
/** writes up to capacity (index1, rev) pairs to jointArrayPtr; returns the count */
|
|
84
|
+
_b2x_Body_GetJoints(index1: number, rev: number, jointArrayPtr: number, capacity: number): number;
|
|
85
|
+
_b2x_Body_GetContactCapacity(index1: number, rev: number): number;
|
|
86
|
+
/** out: lowerX, lowerY, upperX, upperY */
|
|
87
|
+
_b2x_Body_ComputeAABB(index1: number, rev: number, outPtr: number): void;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Box2D b2Body_* functions without a generated wrapper: GetContactData, GetName, GetUserData, SetName, SetUserData. */
|
|
91
|
+
export type FastPathBodySkipped = "GetContactData" | "GetName" | "GetUserData" | "SetName" | "SetUserData";
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vworlds/box2d3-wasm",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "6.0.1",
|
|
4
|
+
"description": "Box2D v3 for the web and Node as WebAssembly: a flat C-style embind API plus a zero-allocation fast path.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/entry.mjs",
|
|
7
|
+
"module": "./dist/entry.mjs",
|
|
8
|
+
"types": "./dist/entry.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/entry.d.ts",
|
|
12
|
+
"default": "./dist/entry.mjs"
|
|
13
|
+
},
|
|
14
|
+
"./fastpath": {
|
|
15
|
+
"types": "./dist/fastpath.d.ts",
|
|
16
|
+
"default": "./dist/fastpath.mjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"THIRD_PARTY_NOTICES.md",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "bash scripts/build.sh",
|
|
27
|
+
"build:docker": "bash scripts/build-in-docker.sh",
|
|
28
|
+
"test": "node tests/fastpath-differential.mjs deluxe && node tests/fastpath-differential.mjs compat && node tests/bindings.mjs deluxe && node tests/bindings.mjs compat && node tests/integration.mjs",
|
|
29
|
+
"test:stock": "node tests/stock-differential/run.mjs",
|
|
30
|
+
"gen": "python3 scripts/gen_fastpath.py",
|
|
31
|
+
"gen:check": "python3 scripts/gen_fastpath.py --check",
|
|
32
|
+
"check:bindings": "python3 scripts/check_bindings.py",
|
|
33
|
+
"demo:dev": "npm --prefix demo run dev",
|
|
34
|
+
"demo:build": "npm --prefix demo run build",
|
|
35
|
+
"check:pack": "node scripts/check-pack.mjs",
|
|
36
|
+
"test:release": "node --test scripts/release-version.test.mjs"
|
|
37
|
+
},
|
|
38
|
+
"author": "Alex Birch & Erik Sombroek",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/vworlds/box2d3-wasm.git"
|
|
42
|
+
},
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"box2d3-wasm": "5.2.0"
|
|
49
|
+
}
|
|
50
|
+
}
|