@inglorious/engine 24.12.1 → 24.13.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 +1 -1
- package/src/core/engine.js +16 -1
- package/types/index.d.ts +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inglorious/engine",
|
|
3
|
-
"version": "24.
|
|
3
|
+
"version": "24.13.0",
|
|
4
4
|
"description": "A JavaScript game engine written with global state, immutability, and pure functions in mind. Have fun(ctional programming) with it!",
|
|
5
5
|
"author": "Matteo Antony Mistretta <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
|
|
6
6
|
"license": "MIT",
|
package/src/core/engine.js
CHANGED
|
@@ -20,14 +20,28 @@ import { Loop } from "./loops/index.js"
|
|
|
20
20
|
import { assertTypesAreDeclared } from "./types.js"
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* @type {{loop: {type: LoopType, fps: number}, systems: Array, types: Object, entities: Object}}
|
|
23
|
+
* @type {{loop: {type: LoopType, fps: number}, updateStrategy: UpdateStrategy, systems: Array, types: Object, entities: Object}}
|
|
24
24
|
* `loop.type` is a {@link LoopType} and defaults to "animationFrame"; `loop.fps` is
|
|
25
25
|
* what the loops that have a rate measure themselves against, and is ignored by the
|
|
26
26
|
* ones that do not.
|
|
27
|
+
*
|
|
28
|
+
* `updateStrategy` defaults to "copy-on-dispatch". A game hands `update` to most of
|
|
29
|
+
* its entities every frame, and writes to them, so structural sharing's one saving,
|
|
30
|
+
* leaving untouched entities uncopied, rarely applies; what it costs is a proxy on
|
|
31
|
+
* every object a handler reaches. One entity holding a plain world of 300 organisms
|
|
32
|
+
* (the SWARM hackathon game) took 14 ms a frame through the draft proxy, 0.6 ms
|
|
33
|
+
* copied, against 0.35 ms for the bare tick. Immer, whose drafts Mutative follows,
|
|
34
|
+
* says the same of large drafts: https://immerjs.github.io/immer/performance/.
|
|
35
|
+
* Rejected: an opaque-value escape hatch (a class instance or typed array, which the
|
|
36
|
+
* proxy passes through and the game changes in place) is as fast but leaves past
|
|
37
|
+
* states sharing the live world, so time travel and replays lie. A game can still
|
|
38
|
+
* choose "structural-sharing".
|
|
27
39
|
*/
|
|
28
40
|
const DEFAULT_GAME_CONFIG = {
|
|
29
41
|
loop: { type: "animationFrame", fps: 60 },
|
|
30
42
|
|
|
43
|
+
updateStrategy: "copy-on-dispatch",
|
|
44
|
+
|
|
31
45
|
systems: [],
|
|
32
46
|
|
|
33
47
|
types: {
|
|
@@ -242,4 +256,5 @@ function isBehavior(value) {
|
|
|
242
256
|
* @typedef {Object.<string, Object>} Entity - An object representing an entity.
|
|
243
257
|
* @typedef {Object.<string, Entity>} Entities - A collection of entities indexed by id.
|
|
244
258
|
* @typedef {import("./loops/index.js").LoopType} LoopType - Which loop drives the game.
|
|
259
|
+
* @typedef {import("@inglorious/store/store.js").UpdateStrategy} UpdateStrategy - How the store copies what an event changes.
|
|
245
260
|
*/
|
package/types/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
EntitiesState,
|
|
5
5
|
Stored,
|
|
6
6
|
System,
|
|
7
|
+
UpdateStrategy,
|
|
7
8
|
} from "@inglorious/store"
|
|
8
9
|
import type { MultiplayerMiddlewareConfig } from "@inglorious/store/client/multiplayer-middleware.js"
|
|
9
10
|
import type { Vector3 } from "@inglorious/utils/vector.js"
|
|
@@ -123,6 +124,13 @@ export type EntityConfig = BaseEntity & { [key: string]: unknown }
|
|
|
123
124
|
export interface GameConfig {
|
|
124
125
|
/** Which loop drives the game, and the rate the fixed one keeps. */
|
|
125
126
|
loop?: { type?: LoopType; fps?: number }
|
|
127
|
+
/**
|
|
128
|
+
* How the store copies what an event changes. Defaults to `"copy-on-dispatch"`:
|
|
129
|
+
* each entity is deep-copied before an event changes it, with no proxy, so a big
|
|
130
|
+
* plain world in one entity stays cheap and past states stay real snapshots.
|
|
131
|
+
* `"structural-sharing"` drafts through a proxy and copies only what changed.
|
|
132
|
+
*/
|
|
133
|
+
updateStrategy?: UpdateStrategy
|
|
126
134
|
types?: Record<string, GameTypeDefinition>
|
|
127
135
|
entities?: Record<string, BaseEntity | EntityConfig>
|
|
128
136
|
systems?: (System | GameSystem)[]
|