@zaisma/physics 0.0.0-stage → 2.4.0
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.txt +93 -0
- package/README.md +146 -2
- package/characters.js +189 -0
- package/data.js +85 -0
- package/declare.js +495 -0
- package/engine.js +48 -0
- package/index.d.ts +743 -0
- package/index.js +27 -0
- package/level-characters.js +139 -0
- package/package.json +54 -4
- package/piece.json +136 -0
- package/piece.json.js +137 -0
- package/rapier/LICENSE.txt +201 -0
- package/rapier/rapier.d.ts +903 -0
- package/rapier/rapier.js +12674 -0
- package/rapier/rapier.wasm +0 -0
- package/server.d.ts +34 -0
- package/server.js +17 -0
- package/simulation.js +1136 -0
- package/sync.js +1035 -0
- package/world.d.ts +4 -0
- package/world.js +5 -0
|
Binary file
|
package/server.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zaisma/physics on the game server: the same world the players' games step, run here as the word everyone
|
|
3
|
+
* follows. Nobody's tab holds the world up, and nobody's game can cheat it. `zaisma pieces add` puts this file in
|
|
4
|
+
* zaisma-server/pieces/@zaisma/physics/, with the engine beside it: importing it starts the engine, in Zaisma's
|
|
5
|
+
* rooms and on the Node runner on a developer's own machine alike.
|
|
6
|
+
*
|
|
7
|
+
* What it costs is the game server's time, which Zaisma meters: the world steps only while something moves, a room
|
|
8
|
+
* at rest takes none, and a furniture-moving room of four takes a small part of what each player-hour includes.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // zaisma-server/index.js. world.js is the game's own world file, copied here as it is.
|
|
12
|
+
* import { defineNetServer } from "./pieces/@zaisma/net/server.js";
|
|
13
|
+
* import { physicsKind } from "./pieces/@zaisma/physics/server.js";
|
|
14
|
+
* import { livingRoom } from "./world.js";
|
|
15
|
+
*
|
|
16
|
+
* const physics = physicsKind(livingRoom, {
|
|
17
|
+
* hooks: { beforePutBack: (positionM, { id }) => (id === "ball" ? { x: 0, y: 2, z: 0 } : positionM) },
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* export default defineNetServer({
|
|
21
|
+
* kinds: [physics],
|
|
22
|
+
* ticksPerSec: 30,
|
|
23
|
+
* onTick(state, tickDurationSec, room) {
|
|
24
|
+
* const world = physics.onServer(state, room);
|
|
25
|
+
* if (world.bodyState("sofa").positionM.x > 20) room.broadcast({ type: "sofa_delivered" });
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // In the game: the same code as on the relay, with one word changed.
|
|
30
|
+
* const net = createNet(room, { authorityKind: "server" });
|
|
31
|
+
* const physics = net.use(physicsKind(livingRoom));
|
|
32
|
+
*/
|
|
33
|
+
export { PieceError, defineCharacterKind, definePhysicsWorld, levelCharactersKind, physicsEngine, physicsKind, stickVehicleControls, walkStep, walkingCharacters, wishOf } from "./index.js";
|
|
34
|
+
export type * from "./index.js";
|
package/server.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @zaisma/physics on the game server: the same world the players' games step, run here as the word everyone follows.
|
|
2
|
+
// Importing the engine's WebAssembly gives it compiled, in Zaisma's rooms and on the Node runner on a developer's
|
|
3
|
+
// own machine alike, so it's started as this file loads. The reference is server.d.ts. MIT licensed.
|
|
4
|
+
import engineModule from "./rapier/rapier.wasm";
|
|
5
|
+
import { charactersKind, worldKind } from "../net/server.js";
|
|
6
|
+
import { levelCharactersKindFrom } from "./level-characters.js";
|
|
7
|
+
import { startPhysicsEngine } from "./engine.js";
|
|
8
|
+
import { physicsKindFrom } from "./sync.js";
|
|
9
|
+
|
|
10
|
+
startPhysicsEngine(engineModule);
|
|
11
|
+
|
|
12
|
+
export const physicsKind = physicsKindFrom(worldKind);
|
|
13
|
+
export const levelCharactersKind = levelCharactersKindFrom(charactersKind);
|
|
14
|
+
export { definePhysicsWorld } from "./declare.js";
|
|
15
|
+
export { defineCharacterKind, stickVehicleControls, walkStep, walkingCharacters, wishOf } from "./characters.js";
|
|
16
|
+
export { physicsEngine } from "./engine.js";
|
|
17
|
+
export { PieceError } from "../piece/index.js";
|