@inglorious/engine 24.15.0 → 24.17.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/package.json +2 -2
- package/src/ai/movement/dynamic/align.js +16 -17
- package/src/ai/movement/dynamic/alignment.js +25 -0
- package/src/ai/movement/dynamic/arrive.js +13 -5
- package/src/ai/movement/dynamic/avoid-walls.js +93 -0
- package/src/ai/movement/dynamic/cohesion.js +23 -0
- package/src/ai/movement/dynamic/evade.js +13 -31
- package/src/ai/movement/dynamic/face.js +10 -7
- package/src/ai/movement/dynamic/flee.js +11 -35
- package/src/ai/movement/dynamic/look-where-youre-going.js +10 -4
- package/src/ai/movement/dynamic/match-velocity.js +17 -33
- package/src/ai/movement/dynamic/pursue.js +20 -9
- package/src/ai/movement/dynamic/seek.js +11 -34
- package/src/ai/movement/dynamic/separation.js +49 -0
- package/src/ai/movement/dynamic/steering.js +151 -0
- package/src/ai/movement/dynamic/wander.js +17 -5
- package/src/behaviors/film.js +269 -0
- package/types/ai/movement/dynamic/align.d.ts +8 -1
- package/types/ai/movement/dynamic/alignment.d.ts +8 -0
- package/types/ai/movement/dynamic/arrive.d.ts +12 -0
- package/types/ai/movement/dynamic/avoid-walls.d.ts +11 -0
- package/types/ai/movement/dynamic/cohesion.d.ts +7 -0
- package/types/ai/movement/dynamic/evade.d.ts +8 -0
- package/types/ai/movement/dynamic/face.d.ts +13 -1
- package/types/ai/movement/dynamic/flee.d.ts +7 -0
- package/types/ai/movement/dynamic/look-where-youre-going.d.ts +7 -1
- package/types/ai/movement/dynamic/match-velocity.d.ts +8 -1
- package/types/ai/movement/dynamic/pursue.d.ts +15 -0
- package/types/ai/movement/dynamic/seek.d.ts +7 -0
- package/types/ai/movement/dynamic/separation.d.ts +11 -0
- package/types/ai/movement/dynamic/steering.d.ts +34 -0
- package/types/ai/movement/dynamic/wander.d.ts +20 -2
- package/types/behaviors/film.d.ts +124 -0
- package/types/index.d.ts +11 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Kinematic, SteeringOutput } from "../../../index"
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_EPSILON: number
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Applies a steering for `dt` seconds: the linear part changes `velocity` (at
|
|
7
|
+
* most `maxSpeed`), `position` and `orientation` (where it goes); the angular
|
|
8
|
+
* part changes `angularSpeed` and `orientation`. `null` returns the entity.
|
|
9
|
+
*/
|
|
10
|
+
export function integrate<TEntity extends Kinematic>(
|
|
11
|
+
entity: TEntity,
|
|
12
|
+
steering: SteeringOutput | null,
|
|
13
|
+
dt: number,
|
|
14
|
+
):
|
|
15
|
+
| TEntity
|
|
16
|
+
| {
|
|
17
|
+
acceleration?: Kinematic["position"]
|
|
18
|
+
velocity?: Kinematic["position"]
|
|
19
|
+
position?: Kinematic["position"]
|
|
20
|
+
orientation?: number
|
|
21
|
+
angularSpeed?: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Adds up `[steering, weight]` pairs, capped at `maxAcceleration` and `maxAngularAcceleration`. `null` if all are. */
|
|
25
|
+
export function blend(
|
|
26
|
+
entity: Pick<Kinematic, "maxAcceleration" | "maxAngularAcceleration">,
|
|
27
|
+
weightedSteerings: [SteeringOutput | null, number][],
|
|
28
|
+
): SteeringOutput | null
|
|
29
|
+
|
|
30
|
+
/** The first steering asking for more than `epsilon`, most urgent first; else the last. */
|
|
31
|
+
export function prioritize(
|
|
32
|
+
steerings: (SteeringOutput | null)[],
|
|
33
|
+
options?: { epsilon?: number },
|
|
34
|
+
): SteeringOutput | null
|
|
@@ -1,11 +1,29 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
DynamicMovement,
|
|
3
|
+
Kinematic,
|
|
4
|
+
Steering,
|
|
5
|
+
SteeringOutput,
|
|
6
|
+
} from "../../../index"
|
|
2
7
|
|
|
3
8
|
export const DEFAULT_WANDER_OFFSET: number
|
|
4
9
|
export const DEFAULT_WANDER_RADIUS: number
|
|
5
10
|
|
|
11
|
+
export interface WanderOptions {
|
|
12
|
+
wanderOffset?: number
|
|
13
|
+
wanderRadius?: number
|
|
14
|
+
/** A seeded generator (`createRng`), to keep a simulation deterministic. */
|
|
15
|
+
rng?: { randomBinomial(): number }
|
|
16
|
+
}
|
|
17
|
+
|
|
6
18
|
/** Seeks a random point on a circle `wanderOffset` ahead. */
|
|
7
19
|
export function wander<TEntity extends Kinematic>(
|
|
8
20
|
entity: TEntity,
|
|
9
21
|
dt: number,
|
|
10
|
-
options?:
|
|
22
|
+
options?: WanderOptions,
|
|
11
23
|
): Steering<TEntity, DynamicMovement>
|
|
24
|
+
|
|
25
|
+
/** The acceleration `wander` applies. */
|
|
26
|
+
export function wanderSteering(
|
|
27
|
+
entity: Kinematic,
|
|
28
|
+
options?: WanderOptions,
|
|
29
|
+
): SteeringOutput | null
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Vector3 } from "@inglorious/utils/vector.js"
|
|
2
|
+
|
|
3
|
+
import type { Entity } from "../index"
|
|
4
|
+
|
|
5
|
+
/** An entity showing one still picture at a time, changing through black. */
|
|
6
|
+
export interface FilmEntity extends Omit<Entity, "size"> {
|
|
7
|
+
position: Vector3
|
|
8
|
+
/** The image id on screen, or `null` for black. */
|
|
9
|
+
shot: string | null
|
|
10
|
+
/** The shot before the last cut. */
|
|
11
|
+
previous: string | null
|
|
12
|
+
/** Seconds the shot has been on screen. */
|
|
13
|
+
shotTime: number
|
|
14
|
+
/** How long the previous shot had been on screen when it was cut. */
|
|
15
|
+
previousTime: number
|
|
16
|
+
/** Seconds since the last cut. */
|
|
17
|
+
cutTime: number
|
|
18
|
+
/** How long a cut lasts, out and in together. */
|
|
19
|
+
cutSeconds: number
|
|
20
|
+
/** How much a shot zooms in: 0.06 is 6%. */
|
|
21
|
+
pushIn: number
|
|
22
|
+
/** Over how long a shot zooms in, then holds. */
|
|
23
|
+
pushSeconds: number
|
|
24
|
+
/** The frame's width and height; the whole game without one. */
|
|
25
|
+
size?: Vector3 | readonly [width: number, height: number]
|
|
26
|
+
/** The point the push-in closes on, as fractions of the frame from its bottom left. */
|
|
27
|
+
focus?: readonly [x: number, y: number]
|
|
28
|
+
layer?: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface FilmOptions {
|
|
32
|
+
/** Defaults to `"film"`. */
|
|
33
|
+
id?: string
|
|
34
|
+
type?: string
|
|
35
|
+
/** Defaults to 0.6. */
|
|
36
|
+
cutSeconds?: number
|
|
37
|
+
/** Defaults to 0.06. */
|
|
38
|
+
pushIn?: number
|
|
39
|
+
/** Defaults to 12. */
|
|
40
|
+
pushSeconds?: number
|
|
41
|
+
size?: Vector3 | readonly [width: number, height: number]
|
|
42
|
+
focus?: readonly [x: number, y: number]
|
|
43
|
+
layer?: number
|
|
44
|
+
[key: string]: unknown
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A film entity showing black. */
|
|
48
|
+
export function createFilm(options?: FilmOptions): FilmEntity
|
|
49
|
+
|
|
50
|
+
/** Keeps time for the shot and the cut; shots change with `cut`. */
|
|
51
|
+
export function film(): {
|
|
52
|
+
update: (entity: FilmEntity, dt: number) => void
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Changes the shot through black, from the film type's own handler. Same shot: nothing. */
|
|
56
|
+
export function cut(entity: FilmEntity, shot: string | null): void
|
|
57
|
+
|
|
58
|
+
/** How black the frame is now, from 0 (the shot fully visible) to 1. */
|
|
59
|
+
export function filmBlack(entity: FilmEntity): number
|
|
60
|
+
|
|
61
|
+
/** The shot to draw now (the outgoing one in the first half of a cut) and its time on screen. */
|
|
62
|
+
export function shownShot(entity: FilmEntity): {
|
|
63
|
+
shot: string | null
|
|
64
|
+
time: number
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** How much a shot on screen for `time` seconds is zoomed: from 1 to `1 + pushIn`. */
|
|
68
|
+
export function pushZoom(entity: FilmEntity, time: number): number
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* An entity showing a title and an optional subtitle for a moment. Its `size` is the
|
|
72
|
+
* title's font size, as for a text entity.
|
|
73
|
+
*/
|
|
74
|
+
export interface TitleCardEntity extends Omit<Entity, "size"> {
|
|
75
|
+
position: Vector3
|
|
76
|
+
title: string | null
|
|
77
|
+
subtitle: string | null
|
|
78
|
+
/** Seconds since the card was shown. */
|
|
79
|
+
cardTime: number
|
|
80
|
+
/** How long a card stays, fades included. */
|
|
81
|
+
cardSeconds: number
|
|
82
|
+
/** The title's font size. */
|
|
83
|
+
size?: number
|
|
84
|
+
font?: string
|
|
85
|
+
weight?: string
|
|
86
|
+
color?: string
|
|
87
|
+
/** The band behind the text; `null` for none. */
|
|
88
|
+
shade?: string | null
|
|
89
|
+
layer?: number
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface TitleCardOptions {
|
|
93
|
+
/** Defaults to `"titleCard"`. */
|
|
94
|
+
id?: string
|
|
95
|
+
type?: string
|
|
96
|
+
/** Defaults to 2. */
|
|
97
|
+
cardSeconds?: number
|
|
98
|
+
position?: Vector3
|
|
99
|
+
size?: number
|
|
100
|
+
font?: string
|
|
101
|
+
weight?: string
|
|
102
|
+
color?: string
|
|
103
|
+
shade?: string | null
|
|
104
|
+
layer?: number
|
|
105
|
+
[key: string]: unknown
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** A title card entity showing nothing. */
|
|
109
|
+
export function createTitleCard(options?: TitleCardOptions): TitleCardEntity
|
|
110
|
+
|
|
111
|
+
/** Keeps time for the card showing. */
|
|
112
|
+
export function titleCard(): {
|
|
113
|
+
update: (entity: TitleCardEntity, dt: number) => void
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Shows a card from now, from the card type's own handler. */
|
|
117
|
+
export function showTitleCard(
|
|
118
|
+
entity: TitleCardEntity,
|
|
119
|
+
title: string,
|
|
120
|
+
subtitle?: string | null,
|
|
121
|
+
): void
|
|
122
|
+
|
|
123
|
+
/** How opaque the card is now: in over 0.25 s, out over the last 0.5 s; 0 when none shows. */
|
|
124
|
+
export function titleCardOpacity(entity: TitleCardEntity): number
|
package/types/index.d.ts
CHANGED
|
@@ -188,3 +188,14 @@ export type KinematicMovement = {
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
export type DynamicMovement = KinematicMovement & { acceleration?: Vector3 }
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* What a dynamic steering behavior asks for, before anything moves: a linear
|
|
194
|
+
* acceleration, an angular one (radians a second²), or both. `null` asks for
|
|
195
|
+
* nothing. Apply it with `integrate`, or combine several first with `blend` and
|
|
196
|
+
* `prioritize` (`@inglorious/engine/ai/movement/dynamic/steering.js`).
|
|
197
|
+
*/
|
|
198
|
+
export interface SteeringOutput {
|
|
199
|
+
linear?: Vector3
|
|
200
|
+
angular?: number
|
|
201
|
+
}
|