@adatechnology/game-player 0.10.5 → 0.11.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/README.md +9 -0
- package/dist/index.d.ts +58 -2
- package/dist/index.global.js +117 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +117 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -113,3 +113,12 @@ palm). The pose algebra they use is exported too (`composePose`, `poseHolding`,
|
|
|
113
113
|
`createPhysicsController(world, { position, collider })` (over `PhysicsWorld.createCharacter` of `@adatechnology/game-physics`) goes in `PlayerWorld.controller`
|
|
114
114
|
(`move`, `read`, `teleport`): the player's `x`, `y`, `z` are then the controller's feet, steps up to 18 cm, climbs 30 degrees, pushes a 30 kg crate and is pushed, and `blocked`
|
|
115
115
|
is not asked. Call `player.update(h, input)` in the loop's `beforeStep` (the `actors` phase) with the fixed step, not the frame's `dt`. Without a controller the grid walk is unchanged.
|
|
116
|
+
|
|
117
|
+
## Walker in the physics loop (spec 008, TS.9f)
|
|
118
|
+
|
|
119
|
+
`createWalker(services, { position, collider, shadow?, ... })` (`services` is `PhysicsServices`, or anything with `loop` and `world`) makes the player's body a character of the world and walks it in the
|
|
120
|
+
loop's `actors` phase: `setIntent(vx, vz)` when the key changes (kept until changed), `jump()` (3.99 m/s under 9.81: 0.81 m, only with the feet on something), `setStance('standing' | 'crouched' | 'prone')`
|
|
121
|
+
(1.80 / 1.20 / 0.60 m for a 1.80 m person; false and the stance stays when the new capsule would penetrate), `push(impulse)`. The feet of the last two fixed steps are kept: `drawn(alpha, out)` is the point
|
|
122
|
+
between them at the scheduler's `alpha` (not `loop.frame.alpha`, which `stepFixed` zeroes). `park()` takes the body out of the world (seat, aircraft, vehicle); `unpark(candidates)` puts it back at the first
|
|
123
|
+
candidate (the door, the far side, the roof) where the capsule overlaps nothing solid, false and still parked when none fits. `dispose()` leaves the loop and the world. No allocation per frame.
|
|
124
|
+
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as PlayerCollider, b as PlayerController, c as PlayerMessageId, K as KnownDeathCause } from './player-B-CNsXV5.js';
|
|
2
2
|
export { A as AttributeId, d as Attributes, D as DeathCause, e as Derived, f as DerivedFormulas, g as DerivedId, I as InfectionRule, L as LinearFormula, M as MeleeItem, h as PLAYER_DEFAULTS, P as Player, i as PlayerAction, j as PlayerCrowd, k as PlayerEvent, l as PlayerEventMap, m as PlayerEventName, n as PlayerInput, o as PlayerNumbers, p as PlayerOptions, q as PlayerSave, r as PlayerSoundId, s as PlayerState, t as PlayerWorld, W as WoundRule, u as WoundTable, v as createPlayer, w as deriveVitals, x as drawWound } from './player-B-CNsXV5.js';
|
|
3
|
-
import { Vec3, CharacterId, PhysicsWorld } from '@adatechnology/game-physics';
|
|
3
|
+
import { Vec3, CharacterId, PhysicsWorld, Layer, PhysicsServices } from '@adatechnology/game-physics';
|
|
4
4
|
import { SurfaceId } from '@adatechnology/game-contracts';
|
|
5
5
|
export { PlayerTestModule, PlayerTestModuleOptions, createPlayerTestModule } from './testing.js';
|
|
6
6
|
|
|
@@ -31,6 +31,62 @@ declare const PLAYER_PUSH_STRENGTH_NEWTONS = 400;
|
|
|
31
31
|
*/
|
|
32
32
|
declare const createPhysicsController: (world: PlayerPhysicsWorld, options: PhysicsControllerOptions) => PhysicsPlayerController;
|
|
33
33
|
|
|
34
|
+
/** The vertical speed (m/s) of a jump under the world's 9.81: it rises 0.81 m, as high as the walker's own jump always did. */
|
|
35
|
+
declare const WALKER_JUMP_SPEED = 3.99;
|
|
36
|
+
type WalkerStance = 'standing' | 'crouched' | 'prone';
|
|
37
|
+
type WalkerOptions = {
|
|
38
|
+
/** Where the feet are. */
|
|
39
|
+
readonly position: Vec3;
|
|
40
|
+
/** The standing body: `player.collider()` while standing. */
|
|
41
|
+
readonly collider: PlayerCollider;
|
|
42
|
+
/** Kilograms, default 75. */
|
|
43
|
+
readonly mass?: number;
|
|
44
|
+
/** Most force (N) it pushes a prop with, default 400. */
|
|
45
|
+
readonly strength?: number;
|
|
46
|
+
/** Default 0.4 m. */
|
|
47
|
+
readonly stepHeight?: number;
|
|
48
|
+
readonly maxSlopeDegrees?: number;
|
|
49
|
+
/** Default 9.81. */
|
|
50
|
+
readonly gravity?: number;
|
|
51
|
+
/** The layer of the body the world sees of the walker (`agent`: a vehicle does not stop on it). */
|
|
52
|
+
readonly shadow?: Layer;
|
|
53
|
+
/** The shadow's `user`. */
|
|
54
|
+
readonly user?: number;
|
|
55
|
+
/** What `unpark` may not stand in (default static, debris, prop, vehicle and character). */
|
|
56
|
+
readonly solidLayers?: readonly Layer[];
|
|
57
|
+
};
|
|
58
|
+
type Walker = {
|
|
59
|
+
/** The character in the world: another one after `unpark`. */
|
|
60
|
+
readonly id: CharacterId;
|
|
61
|
+
readonly stance: WalkerStance;
|
|
62
|
+
readonly parked: boolean;
|
|
63
|
+
/** The wanted horizontal velocity (m/s, world x and z), kept until it is changed: the key of the frame, not of the step. */
|
|
64
|
+
setIntent(velocityX: number, velocityZ: number): void;
|
|
65
|
+
/** A jump when the feet stand on something; false in the air or parked. */
|
|
66
|
+
jump(): boolean;
|
|
67
|
+
/** Changes the stance; false (the stance stays) when the new capsule would penetrate something. */
|
|
68
|
+
setStance(stance: WalkerStance): boolean;
|
|
69
|
+
/** Shoves the body: `impulse` in N s. */
|
|
70
|
+
push(impulse: Vec3): void;
|
|
71
|
+
supported(): boolean;
|
|
72
|
+
/** The feet of the last fixed step into `out` (x, y, z). */
|
|
73
|
+
read(out: Float32Array | Float64Array): void;
|
|
74
|
+
/** The feet between the last two fixed steps, `alpha` (0 to 1) of the way: the scheduler's alpha, not the loop's (`stepFixed` zeroes that one). */
|
|
75
|
+
drawn(alpha: number, out: Float32Array | Float64Array): void;
|
|
76
|
+
/** Takes the body out of the world (a seat, an aircraft, a vehicle): it no longer moves or blocks. */
|
|
77
|
+
park(): void;
|
|
78
|
+
/** Puts the body back at the first of `candidates` (feet) where the capsule overlaps nothing solid, in this order (the door, the far side, the roof); false, still parked, when none fits. */
|
|
79
|
+
unpark(candidates: readonly Vec3[]): boolean;
|
|
80
|
+
/** Leaves the loop and the world. */
|
|
81
|
+
dispose(): void;
|
|
82
|
+
};
|
|
83
|
+
type WalkerServices = Pick<PhysicsServices, 'loop' | 'world'>;
|
|
84
|
+
/**
|
|
85
|
+
* The player's body in the physics world, walking in the loop's `actors` phase: the intent is set when the key changes, every fixed step walks it with the step's
|
|
86
|
+
* `h`, and the feet of the last two steps are kept for drawing between them. No allocation after the first call.
|
|
87
|
+
*/
|
|
88
|
+
declare const createWalker: (services: WalkerServices, options: WalkerOptions) => Walker;
|
|
89
|
+
|
|
34
90
|
/** Deterministic mulberry32 generator; returns floats in [0, 1). */
|
|
35
91
|
declare function createRng(seed: number): () => number;
|
|
36
92
|
|
|
@@ -439,4 +495,4 @@ declare const STEP_POSE_DEFAULTS: {
|
|
|
439
495
|
};
|
|
440
496
|
declare function createStepPose(start: StepPosition, options?: StepPoseOptions): StepPose;
|
|
441
497
|
|
|
442
|
-
export { type BodyHand, DOOR_ARM_REACH, DOOR_SHOULDER_HEIGHT, DOOR_USE_DEFAULTS, type DoorUse, type DoorUseBlock, type DoorUseHand, type DoorUsePhase, type DoorUseRules, type DoorUseStep, type DoorUseTarget, type DragMark, FURNITURE_PUSH_DEFAULTS, type FurniturePush, type FurniturePushBlock, type FurniturePushInput, type FurniturePushLoad, type FurniturePushPhase, type FurniturePushRules, type FurniturePushStep, type FurniturePushTarget, HANDS_DEFAULTS, HANDS_TIMING, type HandWeapon, type HandsMove, type HandsMoveKind, type HandsPlan, type HandsRules, type HandsTiming, ITEM_GRIP, type ItemGrip, KnownDeathCause, PLAYER_MASS_KG, PLAYER_PUSH_STRENGTH_NEWTONS, PLAYER_TEXT, type PhysicsControllerOptions, type PhysicsPlayerController, type PlanHandsParams, PlayerCollider, PlayerController, PlayerMessageId, type PlayerPhysicsWorld, type PlayerText, type Pose, type QuatTuple, SLING_SLOT, SLOT_FALLBACKS, STEP_POSE_DEFAULTS, type StepPose, type StepPoseOptions, type StepPosition, type TakeProgress, type TakeSequence, type TakeStep, type TakeStepKind, type TakeTimeline, type Vec3Tuple, blendPoses, canPush, composePose, conjugateQuaternion, createDoorUse, createFurniturePush, createPhysicsController, createRng, createStepPose, createTakeTimeline, dragMarkFor, drawBackOf, easeInOut, frictionFor, gripOfItem, gripSecondsFor, handPoseOnItem, interactionHandsFor, itemPoseInHand, multiplyQuaternions, planDrawSequence, planHands, planTakeSequence, playerTextOf, poseHolding, pushAccelerationFor, pushSpeedFor, quaternionOfBasis, rotateVector, slipsOnTop, swingSecondsFor };
|
|
498
|
+
export { type BodyHand, DOOR_ARM_REACH, DOOR_SHOULDER_HEIGHT, DOOR_USE_DEFAULTS, type DoorUse, type DoorUseBlock, type DoorUseHand, type DoorUsePhase, type DoorUseRules, type DoorUseStep, type DoorUseTarget, type DragMark, FURNITURE_PUSH_DEFAULTS, type FurniturePush, type FurniturePushBlock, type FurniturePushInput, type FurniturePushLoad, type FurniturePushPhase, type FurniturePushRules, type FurniturePushStep, type FurniturePushTarget, HANDS_DEFAULTS, HANDS_TIMING, type HandWeapon, type HandsMove, type HandsMoveKind, type HandsPlan, type HandsRules, type HandsTiming, ITEM_GRIP, type ItemGrip, KnownDeathCause, PLAYER_MASS_KG, PLAYER_PUSH_STRENGTH_NEWTONS, PLAYER_TEXT, type PhysicsControllerOptions, type PhysicsPlayerController, type PlanHandsParams, PlayerCollider, PlayerController, PlayerMessageId, type PlayerPhysicsWorld, type PlayerText, type Pose, type QuatTuple, SLING_SLOT, SLOT_FALLBACKS, STEP_POSE_DEFAULTS, type StepPose, type StepPoseOptions, type StepPosition, type TakeProgress, type TakeSequence, type TakeStep, type TakeStepKind, type TakeTimeline, type Vec3Tuple, WALKER_JUMP_SPEED, type Walker, type WalkerOptions, type WalkerServices, type WalkerStance, blendPoses, canPush, composePose, conjugateQuaternion, createDoorUse, createFurniturePush, createPhysicsController, createRng, createStepPose, createTakeTimeline, createWalker, dragMarkFor, drawBackOf, easeInOut, frictionFor, gripOfItem, gripSecondsFor, handPoseOnItem, interactionHandsFor, itemPoseInHand, multiplyQuaternions, planDrawSequence, planHands, planTakeSequence, playerTextOf, poseHolding, pushAccelerationFor, pushSpeedFor, quaternionOfBasis, rotateVector, slipsOnTop, swingSecondsFor };
|
package/dist/index.global.js
CHANGED
|
@@ -35,6 +35,7 @@ var GamePlayer = (() => {
|
|
|
35
35
|
SLING_SLOT: () => SLING_SLOT,
|
|
36
36
|
SLOT_FALLBACKS: () => SLOT_FALLBACKS,
|
|
37
37
|
STEP_POSE_DEFAULTS: () => STEP_POSE_DEFAULTS,
|
|
38
|
+
WALKER_JUMP_SPEED: () => WALKER_JUMP_SPEED,
|
|
38
39
|
blendPoses: () => blendPoses,
|
|
39
40
|
canPush: () => canPush,
|
|
40
41
|
composePose: () => composePose,
|
|
@@ -47,6 +48,7 @@ var GamePlayer = (() => {
|
|
|
47
48
|
createRng: () => createRng,
|
|
48
49
|
createStepPose: () => createStepPose,
|
|
49
50
|
createTakeTimeline: () => createTakeTimeline,
|
|
51
|
+
createWalker: () => createWalker,
|
|
50
52
|
deriveVitals: () => deriveVitals,
|
|
51
53
|
dragMarkFor: () => dragMarkFor,
|
|
52
54
|
drawBackOf: () => drawBackOf,
|
|
@@ -903,6 +905,121 @@ var GamePlayer = (() => {
|
|
|
903
905
|
};
|
|
904
906
|
};
|
|
905
907
|
|
|
908
|
+
// src/walker.ts
|
|
909
|
+
var WALKER_JUMP_SPEED = 3.99;
|
|
910
|
+
var STANCE_HEIGHT_RATIO = { standing: 1, crouched: 2 / 3, prone: 1 / 3 };
|
|
911
|
+
var NO_ROTATION = [0, 0, 0, 1];
|
|
912
|
+
var PROBE_LIFT = 0.03;
|
|
913
|
+
var SOLID_LAYERS = ["static", "debris", "prop", "vehicle", "character"];
|
|
914
|
+
var shapeOf = (collider, stance) => {
|
|
915
|
+
const height = collider.heightMetres * STANCE_HEIGHT_RATIO[stance];
|
|
916
|
+
const radius = Math.min(collider.radiusMetres, height / 3);
|
|
917
|
+
return { radius, halfHeight: (height - 2 * radius) / 2 };
|
|
918
|
+
};
|
|
919
|
+
var createWalker = (services, options) => {
|
|
920
|
+
const { loop, world } = services;
|
|
921
|
+
const mass = options.mass ?? PLAYER_MASS_KG;
|
|
922
|
+
const shapes = { standing: shapeOf(options.collider, "standing"), crouched: shapeOf(options.collider, "crouched"), prone: shapeOf(options.collider, "prone") };
|
|
923
|
+
const solid = options.solidLayers ?? SOLID_LAYERS;
|
|
924
|
+
const found = [];
|
|
925
|
+
const previous = new Float64Array(3);
|
|
926
|
+
const current = new Float64Array(3);
|
|
927
|
+
let intentX = 0;
|
|
928
|
+
let intentZ = 0;
|
|
929
|
+
let stance = "standing";
|
|
930
|
+
let parked = false;
|
|
931
|
+
const create = (feet) => world.createCharacter({
|
|
932
|
+
position: feet,
|
|
933
|
+
radius: shapes[stance].radius,
|
|
934
|
+
halfHeight: shapes[stance].halfHeight,
|
|
935
|
+
mass,
|
|
936
|
+
strength: options.strength ?? PLAYER_PUSH_STRENGTH_NEWTONS,
|
|
937
|
+
...options.stepHeight !== void 0 ? { stepHeight: options.stepHeight } : {},
|
|
938
|
+
...options.maxSlopeDegrees !== void 0 ? { maxSlopeDegrees: options.maxSlopeDegrees } : {},
|
|
939
|
+
...options.gravity !== void 0 ? { gravity: options.gravity } : {},
|
|
940
|
+
...options.shadow !== void 0 ? { shadow: options.shadow } : {},
|
|
941
|
+
...options.user !== void 0 ? { user: options.user } : {}
|
|
942
|
+
});
|
|
943
|
+
let id = create(options.position);
|
|
944
|
+
world.readCharacter(id, current, 0);
|
|
945
|
+
previous.set(current);
|
|
946
|
+
const stopLoop = loop.add(
|
|
947
|
+
{
|
|
948
|
+
beforeStep: (h) => {
|
|
949
|
+
if (parked) return;
|
|
950
|
+
previous.set(current);
|
|
951
|
+
world.moveCharacter(id, intentX, intentZ, h);
|
|
952
|
+
world.readCharacter(id, current, 0);
|
|
953
|
+
}
|
|
954
|
+
},
|
|
955
|
+
"actors"
|
|
956
|
+
);
|
|
957
|
+
const fitsAt = (feet) => {
|
|
958
|
+
const shape = shapes[stance];
|
|
959
|
+
const centre = [feet[0], feet[1] + PROBE_LIFT + shape.halfHeight + shape.radius, feet[2]];
|
|
960
|
+
return world.overlapShape({ kind: "capsule", halfHeight: shape.halfHeight, radius: shape.radius }, centre, NO_ROTATION, found, { layers: solid }) === 0;
|
|
961
|
+
};
|
|
962
|
+
return {
|
|
963
|
+
get id() {
|
|
964
|
+
return id;
|
|
965
|
+
},
|
|
966
|
+
get stance() {
|
|
967
|
+
return stance;
|
|
968
|
+
},
|
|
969
|
+
get parked() {
|
|
970
|
+
return parked;
|
|
971
|
+
},
|
|
972
|
+
setIntent: (velocityX, velocityZ) => {
|
|
973
|
+
intentX = velocityX;
|
|
974
|
+
intentZ = velocityZ;
|
|
975
|
+
},
|
|
976
|
+
jump: () => {
|
|
977
|
+
if (parked || !world.characterSupported(id)) return false;
|
|
978
|
+
world.pushCharacter(id, [0, mass * WALKER_JUMP_SPEED, 0]);
|
|
979
|
+
return true;
|
|
980
|
+
},
|
|
981
|
+
setStance: (next) => {
|
|
982
|
+
if (parked) return false;
|
|
983
|
+
if (!world.setCharacterShape(id, shapes[next])) return false;
|
|
984
|
+
stance = next;
|
|
985
|
+
return true;
|
|
986
|
+
},
|
|
987
|
+
push: (impulse) => world.pushCharacter(id, impulse),
|
|
988
|
+
supported: () => world.characterSupported(id),
|
|
989
|
+
read: (out) => {
|
|
990
|
+
out[0] = current[0];
|
|
991
|
+
out[1] = current[1];
|
|
992
|
+
out[2] = current[2];
|
|
993
|
+
},
|
|
994
|
+
drawn: (alpha, out) => {
|
|
995
|
+
const t = alpha < 0 ? 0 : alpha > 1 ? 1 : alpha;
|
|
996
|
+
for (let axis = 0; axis < 3; axis++) out[axis] = previous[axis] + (current[axis] - previous[axis]) * t;
|
|
997
|
+
},
|
|
998
|
+
park: () => {
|
|
999
|
+
if (parked) return;
|
|
1000
|
+
parked = true;
|
|
1001
|
+
world.removeCharacter(id);
|
|
1002
|
+
},
|
|
1003
|
+
unpark: (candidates) => {
|
|
1004
|
+
if (!parked) return true;
|
|
1005
|
+
for (const feet of candidates) {
|
|
1006
|
+
if (!fitsAt(feet)) continue;
|
|
1007
|
+
id = create(feet);
|
|
1008
|
+
parked = false;
|
|
1009
|
+
world.readCharacter(id, current, 0);
|
|
1010
|
+
previous.set(current);
|
|
1011
|
+
return true;
|
|
1012
|
+
}
|
|
1013
|
+
return false;
|
|
1014
|
+
},
|
|
1015
|
+
dispose: () => {
|
|
1016
|
+
stopLoop();
|
|
1017
|
+
if (!parked) world.removeCharacter(id);
|
|
1018
|
+
parked = true;
|
|
1019
|
+
}
|
|
1020
|
+
};
|
|
1021
|
+
};
|
|
1022
|
+
|
|
906
1023
|
// src/furniture-push.ts
|
|
907
1024
|
var FURNITURE_PUSH_DEFAULTS = {
|
|
908
1025
|
forceN: 500,
|