@roost2d/core 0.1.0-rc.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 +201 -0
- package/README.md +17 -0
- package/dist/index.d.ts +176 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +353 -0
- package/dist/index.js.map +1 -0
- package/package.json +13 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @roost2d/core
|
|
2
|
+
|
|
3
|
+
Renderer-neutral deterministic runtime primitives: scenes, fixed updates, events, services, scheduling, object pools, and seeded random.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @roost2d/core
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { GameRuntime } from '@roost2d/core';
|
|
11
|
+
const runtime = new GameRuntime({ stepMs: 1000 / 60, seed: 42 });
|
|
12
|
+
runtime.registerScene('play', () => ({ id: 'play', fixedUpdate() {}, render() {} }));
|
|
13
|
+
await runtime.switchScene('play');
|
|
14
|
+
runtime.start();
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Call `runtime.dispose()` when its application owner is removed. [Complete quick start](https://github.com/Roost2D/roost2d/blob/main/docs/getting-started.md).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
export type Unsubscribe = () => void;
|
|
2
|
+
export interface Vec2 {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
}
|
|
6
|
+
export interface Rect {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
export interface Disposable {
|
|
13
|
+
dispose(): void | Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare class EventBus<Events extends Record<string, unknown>> {
|
|
16
|
+
private readonly listeners;
|
|
17
|
+
on<Key extends keyof Events>(type: Key, listener: (event: Events[Key]) => void): Unsubscribe;
|
|
18
|
+
once<Key extends keyof Events>(type: Key, listener: (event: Events[Key]) => void): Unsubscribe;
|
|
19
|
+
emit<Key extends keyof Events>(type: Key, event: Events[Key]): void;
|
|
20
|
+
clear(type?: keyof Events): void;
|
|
21
|
+
}
|
|
22
|
+
export interface Tick {
|
|
23
|
+
deltaMs: number;
|
|
24
|
+
elapsedMs: number;
|
|
25
|
+
frame: number;
|
|
26
|
+
}
|
|
27
|
+
/** Deterministic fixed-step accumulator. Rendering remains caller-controlled. */
|
|
28
|
+
export declare class FixedStepClock {
|
|
29
|
+
readonly stepMs: number;
|
|
30
|
+
readonly maxCatchUpSteps: number;
|
|
31
|
+
private accumulatorMs;
|
|
32
|
+
private elapsedMs;
|
|
33
|
+
private frame;
|
|
34
|
+
constructor(stepMs?: number, maxCatchUpSteps?: number);
|
|
35
|
+
advance(deltaMs: number, onTick: (tick: Tick) => void): number;
|
|
36
|
+
get alpha(): number;
|
|
37
|
+
get currentFrame(): number;
|
|
38
|
+
get currentTimeMs(): number;
|
|
39
|
+
reset(): void;
|
|
40
|
+
}
|
|
41
|
+
export declare class DisposalScope implements Disposable {
|
|
42
|
+
private disposed;
|
|
43
|
+
private readonly resources;
|
|
44
|
+
add<T extends Disposable>(resource: T): T;
|
|
45
|
+
dispose(): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export declare class ServiceRegistry {
|
|
48
|
+
private readonly values;
|
|
49
|
+
register<T>(key: symbol | string, value: T): T;
|
|
50
|
+
replace<T>(key: symbol | string, value: T): T;
|
|
51
|
+
has(key: symbol | string): boolean;
|
|
52
|
+
get<T>(key: symbol | string): T;
|
|
53
|
+
tryGet<T>(key: symbol | string): T | undefined;
|
|
54
|
+
delete(key: symbol | string): boolean;
|
|
55
|
+
clear(): void;
|
|
56
|
+
}
|
|
57
|
+
export interface RandomSource {
|
|
58
|
+
next(): number;
|
|
59
|
+
integer(minInclusive: number, maxExclusive: number): number;
|
|
60
|
+
pick<T>(items: readonly T[]): T;
|
|
61
|
+
}
|
|
62
|
+
/** Small reproducible PRNG suitable for gameplay decisions, not cryptography. */
|
|
63
|
+
export declare class SeededRandom implements RandomSource {
|
|
64
|
+
private state;
|
|
65
|
+
constructor(seed?: number);
|
|
66
|
+
next(): number;
|
|
67
|
+
integer(minInclusive: number, maxExclusive: number): number;
|
|
68
|
+
pick<T>(items: readonly T[]): T;
|
|
69
|
+
}
|
|
70
|
+
export declare class ObjectPool<T> {
|
|
71
|
+
private readonly create;
|
|
72
|
+
private readonly reset;
|
|
73
|
+
private readonly destroy;
|
|
74
|
+
private readonly maximumRetained;
|
|
75
|
+
private readonly available;
|
|
76
|
+
private readonly active;
|
|
77
|
+
constructor(create: () => T, reset?: (value: T) => void, destroy?: (value: T) => void, maximumRetained?: number);
|
|
78
|
+
acquire(): T;
|
|
79
|
+
release(value: T): boolean;
|
|
80
|
+
releaseAll(): void;
|
|
81
|
+
dispose(): void;
|
|
82
|
+
get activeCount(): number;
|
|
83
|
+
get retainedCount(): number;
|
|
84
|
+
}
|
|
85
|
+
/** Fixed-update scheduler. It advances only when the owning runtime advances. */
|
|
86
|
+
export declare class Scheduler {
|
|
87
|
+
private nextId;
|
|
88
|
+
private readonly tasks;
|
|
89
|
+
after(delayMs: number, callback: () => void): number;
|
|
90
|
+
every(intervalMs: number, callback: () => void): number;
|
|
91
|
+
cancel(id: number): boolean;
|
|
92
|
+
clear(): void;
|
|
93
|
+
update(deltaMs: number): void;
|
|
94
|
+
private add;
|
|
95
|
+
}
|
|
96
|
+
export interface SceneContext {
|
|
97
|
+
readonly services: ServiceRegistry;
|
|
98
|
+
readonly events: EventBus<Record<string, unknown>>;
|
|
99
|
+
readonly scheduler: Scheduler;
|
|
100
|
+
readonly random: RandomSource;
|
|
101
|
+
readonly runtime: GameRuntime;
|
|
102
|
+
}
|
|
103
|
+
export interface Scene {
|
|
104
|
+
readonly id: string;
|
|
105
|
+
load?(context: SceneContext): void | Promise<void>;
|
|
106
|
+
enter?(context: SceneContext): void | Promise<void>;
|
|
107
|
+
fixedUpdate?(tick: Tick, context: SceneContext): void;
|
|
108
|
+
render?(deltaMs: number, alpha: number, context: SceneContext): void;
|
|
109
|
+
exit?(context: SceneContext): void | Promise<void>;
|
|
110
|
+
dispose?(): void | Promise<void>;
|
|
111
|
+
}
|
|
112
|
+
export interface System extends Partial<Disposable> {
|
|
113
|
+
readonly id: string;
|
|
114
|
+
fixedUpdate?(tick: Tick, context: SceneContext): void;
|
|
115
|
+
render?(deltaMs: number, alpha: number, context: SceneContext): void;
|
|
116
|
+
}
|
|
117
|
+
export interface Plugin extends Partial<Disposable> {
|
|
118
|
+
readonly id: string;
|
|
119
|
+
install(context: SceneContext): void | Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
export interface FrameDriver {
|
|
122
|
+
request(callback: (timeMs: number) => void): unknown;
|
|
123
|
+
cancel(handle: unknown): void;
|
|
124
|
+
now(): number;
|
|
125
|
+
}
|
|
126
|
+
export declare const browserFrameDriver: FrameDriver | undefined;
|
|
127
|
+
export interface RuntimeEvents extends Record<string, unknown> {
|
|
128
|
+
'runtime:paused': {
|
|
129
|
+
paused: boolean;
|
|
130
|
+
};
|
|
131
|
+
'scene:changed': {
|
|
132
|
+
previousId?: string;
|
|
133
|
+
currentId: string;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export interface GameRuntimeOptions {
|
|
137
|
+
stepMs?: number;
|
|
138
|
+
maxCatchUpSteps?: number;
|
|
139
|
+
seed?: number;
|
|
140
|
+
services?: ServiceRegistry;
|
|
141
|
+
}
|
|
142
|
+
export declare class GameRuntime implements Disposable {
|
|
143
|
+
readonly clock: FixedStepClock;
|
|
144
|
+
readonly services: ServiceRegistry;
|
|
145
|
+
readonly scheduler: Scheduler;
|
|
146
|
+
readonly random: RandomSource;
|
|
147
|
+
readonly events: EventBus<RuntimeEvents>;
|
|
148
|
+
readonly context: SceneContext;
|
|
149
|
+
private readonly sceneFactories;
|
|
150
|
+
private readonly loadedScenes;
|
|
151
|
+
private readonly systems;
|
|
152
|
+
private readonly plugins;
|
|
153
|
+
private current?;
|
|
154
|
+
private frameHandle?;
|
|
155
|
+
private frameDriver?;
|
|
156
|
+
private lastFrameMs;
|
|
157
|
+
private switching;
|
|
158
|
+
/** Incremented by every `start`/`stop`, so a frame callback can tell whether its loop still owns the runtime. */
|
|
159
|
+
private runGeneration;
|
|
160
|
+
private disposing;
|
|
161
|
+
paused: boolean;
|
|
162
|
+
constructor(options?: GameRuntimeOptions);
|
|
163
|
+
registerScene(id: string, factory: () => Scene | Promise<Scene>): this;
|
|
164
|
+
addSystem(system: System): this;
|
|
165
|
+
addPlugin(plugin: Plugin): Promise<this>;
|
|
166
|
+
switchScene(id: string): Promise<Scene>;
|
|
167
|
+
setPaused(paused: boolean): void;
|
|
168
|
+
pause(): void;
|
|
169
|
+
resume(): void;
|
|
170
|
+
advance(deltaMs: number): number;
|
|
171
|
+
start(driver?: FrameDriver): void;
|
|
172
|
+
stop(): void;
|
|
173
|
+
private render;
|
|
174
|
+
dispose(): Promise<void>;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC,MAAM,WAAW,IAAI;IAAG,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM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AC,QAAQ,CAAC,YAAY,CAA4B;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,OAAO,CAAC,CAAQ;IACxB,OAAO,CAAC,WAAW,CAAC,CAAU;IAC9B,OAAO,CAAC,WAAW,CAAC,CAAc;IAClC,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,SAAS,CAAqB;IACtC,iHAAiH;IACjH,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,SAAS,CAAS;IAC1B,MAAM,UAAS;gBAEH,OAAO,GAAE,kBAAuB;IAO5C,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI;IAKtE,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAKzB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK9C,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAoBvC,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;IAIhC,KAAK,IAAI,IAAI;IACb,MAAM,IAAI,IAAI;IAEd,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAWhC,KAAK,CAAC,MAAM,GAAE,WAAiC,GAAG,IAAI;IAkBtD,IAAI,IAAI,IAAI;IAMZ,OAAO,CAAC,MAAM;IAKR,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAa/B"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
export class EventBus {
|
|
2
|
+
listeners = new Map();
|
|
3
|
+
on(type, listener) {
|
|
4
|
+
const listeners = this.listeners.get(type) ?? new Set();
|
|
5
|
+
listeners.add(listener);
|
|
6
|
+
this.listeners.set(type, listeners);
|
|
7
|
+
return () => listeners.delete(listener);
|
|
8
|
+
}
|
|
9
|
+
once(type, listener) {
|
|
10
|
+
let unsubscribe = () => undefined;
|
|
11
|
+
unsubscribe = this.on(type, (event) => { unsubscribe(); listener(event); });
|
|
12
|
+
return unsubscribe;
|
|
13
|
+
}
|
|
14
|
+
emit(type, event) {
|
|
15
|
+
for (const listener of [...(this.listeners.get(type) ?? [])])
|
|
16
|
+
listener(event);
|
|
17
|
+
}
|
|
18
|
+
clear(type) {
|
|
19
|
+
if (type === undefined)
|
|
20
|
+
this.listeners.clear();
|
|
21
|
+
else
|
|
22
|
+
this.listeners.delete(type);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Deterministic fixed-step accumulator. Rendering remains caller-controlled. */
|
|
26
|
+
export class FixedStepClock {
|
|
27
|
+
stepMs;
|
|
28
|
+
maxCatchUpSteps;
|
|
29
|
+
accumulatorMs = 0;
|
|
30
|
+
elapsedMs = 0;
|
|
31
|
+
frame = 0;
|
|
32
|
+
constructor(stepMs = 1000 / 60, maxCatchUpSteps = 5) {
|
|
33
|
+
this.stepMs = stepMs;
|
|
34
|
+
this.maxCatchUpSteps = maxCatchUpSteps;
|
|
35
|
+
if (!(stepMs > 0))
|
|
36
|
+
throw new Error('stepMs must be positive');
|
|
37
|
+
if (!Number.isInteger(maxCatchUpSteps) || maxCatchUpSteps < 1)
|
|
38
|
+
throw new Error('maxCatchUpSteps must be a positive integer');
|
|
39
|
+
}
|
|
40
|
+
advance(deltaMs, onTick) {
|
|
41
|
+
this.accumulatorMs += Math.max(0, Number.isFinite(deltaMs) ? deltaMs : 0);
|
|
42
|
+
let steps = 0;
|
|
43
|
+
while (this.accumulatorMs >= this.stepMs && steps < this.maxCatchUpSteps) {
|
|
44
|
+
this.accumulatorMs -= this.stepMs;
|
|
45
|
+
this.elapsedMs += this.stepMs;
|
|
46
|
+
this.frame += 1;
|
|
47
|
+
onTick({ deltaMs: this.stepMs, elapsedMs: this.elapsedMs, frame: this.frame });
|
|
48
|
+
steps += 1;
|
|
49
|
+
}
|
|
50
|
+
if (steps === this.maxCatchUpSteps)
|
|
51
|
+
this.accumulatorMs = Math.min(this.accumulatorMs, this.stepMs);
|
|
52
|
+
return steps;
|
|
53
|
+
}
|
|
54
|
+
get alpha() { return this.accumulatorMs / this.stepMs; }
|
|
55
|
+
get currentFrame() { return this.frame; }
|
|
56
|
+
get currentTimeMs() { return this.elapsedMs; }
|
|
57
|
+
reset() { this.accumulatorMs = 0; this.elapsedMs = 0; this.frame = 0; }
|
|
58
|
+
}
|
|
59
|
+
export class DisposalScope {
|
|
60
|
+
disposed = false;
|
|
61
|
+
resources = [];
|
|
62
|
+
add(resource) {
|
|
63
|
+
if (this.disposed) {
|
|
64
|
+
void resource.dispose();
|
|
65
|
+
throw new Error('DisposalScope is already disposed');
|
|
66
|
+
}
|
|
67
|
+
this.resources.push(resource);
|
|
68
|
+
return resource;
|
|
69
|
+
}
|
|
70
|
+
async dispose() {
|
|
71
|
+
if (this.disposed)
|
|
72
|
+
return;
|
|
73
|
+
this.disposed = true;
|
|
74
|
+
const errors = [];
|
|
75
|
+
for (const resource of this.resources.splice(0).reverse()) {
|
|
76
|
+
try {
|
|
77
|
+
await resource.dispose();
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
errors.push(error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (errors.length)
|
|
84
|
+
throw new AggregateError(errors, 'One or more resources failed to dispose');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export class ServiceRegistry {
|
|
88
|
+
values = new Map();
|
|
89
|
+
register(key, value) {
|
|
90
|
+
if (this.values.has(key))
|
|
91
|
+
throw new Error(`Service is already registered: ${String(key)}`);
|
|
92
|
+
this.values.set(key, value);
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
replace(key, value) { this.values.set(key, value); return value; }
|
|
96
|
+
has(key) { return this.values.has(key); }
|
|
97
|
+
get(key) {
|
|
98
|
+
if (!this.values.has(key))
|
|
99
|
+
throw new Error(`Unknown service: ${String(key)}`);
|
|
100
|
+
return this.values.get(key);
|
|
101
|
+
}
|
|
102
|
+
tryGet(key) { return this.values.get(key); }
|
|
103
|
+
delete(key) { return this.values.delete(key); }
|
|
104
|
+
clear() { this.values.clear(); }
|
|
105
|
+
}
|
|
106
|
+
/** Small reproducible PRNG suitable for gameplay decisions, not cryptography. */
|
|
107
|
+
export class SeededRandom {
|
|
108
|
+
state;
|
|
109
|
+
constructor(seed = 0x6d2b79f5) { this.state = seed >>> 0; }
|
|
110
|
+
next() {
|
|
111
|
+
let value = this.state += 0x6d2b79f5;
|
|
112
|
+
value = Math.imul(value ^ value >>> 15, value | 1);
|
|
113
|
+
value ^= value + Math.imul(value ^ value >>> 7, value | 61);
|
|
114
|
+
return ((value ^ value >>> 14) >>> 0) / 4294967296;
|
|
115
|
+
}
|
|
116
|
+
integer(minInclusive, maxExclusive) {
|
|
117
|
+
if (!Number.isInteger(minInclusive) || !Number.isInteger(maxExclusive) || maxExclusive <= minInclusive)
|
|
118
|
+
throw new Error('Invalid integer range');
|
|
119
|
+
return minInclusive + Math.floor(this.next() * (maxExclusive - minInclusive));
|
|
120
|
+
}
|
|
121
|
+
pick(items) {
|
|
122
|
+
if (!items.length)
|
|
123
|
+
throw new Error('Cannot pick from an empty collection');
|
|
124
|
+
return items[this.integer(0, items.length)];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export class ObjectPool {
|
|
128
|
+
create;
|
|
129
|
+
reset;
|
|
130
|
+
destroy;
|
|
131
|
+
maximumRetained;
|
|
132
|
+
available = [];
|
|
133
|
+
active = new Set();
|
|
134
|
+
constructor(create, reset = () => undefined, destroy = () => undefined, maximumRetained = 256) {
|
|
135
|
+
this.create = create;
|
|
136
|
+
this.reset = reset;
|
|
137
|
+
this.destroy = destroy;
|
|
138
|
+
this.maximumRetained = maximumRetained;
|
|
139
|
+
}
|
|
140
|
+
acquire() {
|
|
141
|
+
const value = this.available.pop() ?? this.create();
|
|
142
|
+
this.active.add(value);
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
release(value) {
|
|
146
|
+
if (!this.active.delete(value))
|
|
147
|
+
return false;
|
|
148
|
+
this.reset(value);
|
|
149
|
+
if (this.available.length < this.maximumRetained)
|
|
150
|
+
this.available.push(value);
|
|
151
|
+
else
|
|
152
|
+
this.destroy(value);
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
releaseAll() { for (const value of [...this.active])
|
|
156
|
+
this.release(value); }
|
|
157
|
+
dispose() {
|
|
158
|
+
for (const value of [...this.active, ...this.available])
|
|
159
|
+
this.destroy(value);
|
|
160
|
+
this.active.clear();
|
|
161
|
+
this.available.length = 0;
|
|
162
|
+
}
|
|
163
|
+
get activeCount() { return this.active.size; }
|
|
164
|
+
get retainedCount() { return this.available.length; }
|
|
165
|
+
}
|
|
166
|
+
/** Fixed-update scheduler. It advances only when the owning runtime advances. */
|
|
167
|
+
export class Scheduler {
|
|
168
|
+
nextId = 1;
|
|
169
|
+
tasks = new Map();
|
|
170
|
+
after(delayMs, callback) { return this.add(delayMs, undefined, callback); }
|
|
171
|
+
every(intervalMs, callback) { return this.add(intervalMs, intervalMs, callback); }
|
|
172
|
+
cancel(id) { return this.tasks.delete(id); }
|
|
173
|
+
clear() { this.tasks.clear(); }
|
|
174
|
+
update(deltaMs) {
|
|
175
|
+
for (const task of [...this.tasks.values()]) {
|
|
176
|
+
task.remainingMs -= deltaMs;
|
|
177
|
+
while (task.remainingMs <= 0 && this.tasks.has(task.id)) {
|
|
178
|
+
task.callback();
|
|
179
|
+
if (task.intervalMs === undefined) {
|
|
180
|
+
this.tasks.delete(task.id);
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
task.remainingMs += task.intervalMs;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
add(delayMs, intervalMs, callback) {
|
|
188
|
+
if (!(delayMs >= 0) || (intervalMs !== undefined && !(intervalMs > 0)))
|
|
189
|
+
throw new Error('Invalid schedule duration');
|
|
190
|
+
const id = this.nextId++;
|
|
191
|
+
this.tasks.set(id, { id, remainingMs: delayMs, intervalMs, callback });
|
|
192
|
+
return id;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
export const browserFrameDriver = typeof globalThis.requestAnimationFrame === 'function' ? {
|
|
196
|
+
request: (callback) => globalThis.requestAnimationFrame(callback),
|
|
197
|
+
cancel: (handle) => globalThis.cancelAnimationFrame(handle),
|
|
198
|
+
now: () => globalThis.performance.now()
|
|
199
|
+
} : undefined;
|
|
200
|
+
export class GameRuntime {
|
|
201
|
+
clock;
|
|
202
|
+
services;
|
|
203
|
+
scheduler = new Scheduler();
|
|
204
|
+
random;
|
|
205
|
+
events = new EventBus();
|
|
206
|
+
context;
|
|
207
|
+
sceneFactories = new Map();
|
|
208
|
+
loadedScenes = new Map();
|
|
209
|
+
systems = new Map();
|
|
210
|
+
plugins = new Map();
|
|
211
|
+
current;
|
|
212
|
+
frameHandle;
|
|
213
|
+
frameDriver;
|
|
214
|
+
lastFrameMs = 0;
|
|
215
|
+
switching = Promise.resolve();
|
|
216
|
+
/** Incremented by every `start`/`stop`, so a frame callback can tell whether its loop still owns the runtime. */
|
|
217
|
+
runGeneration = 0;
|
|
218
|
+
disposing = false;
|
|
219
|
+
paused = false;
|
|
220
|
+
constructor(options = {}) {
|
|
221
|
+
this.clock = new FixedStepClock(options.stepMs, options.maxCatchUpSteps);
|
|
222
|
+
this.services = options.services ?? new ServiceRegistry();
|
|
223
|
+
this.random = new SeededRandom(options.seed);
|
|
224
|
+
this.context = { services: this.services, events: this.events, scheduler: this.scheduler, random: this.random, runtime: this };
|
|
225
|
+
}
|
|
226
|
+
registerScene(id, factory) {
|
|
227
|
+
if (!id || this.sceneFactories.has(id))
|
|
228
|
+
throw new Error(`Duplicate or empty scene id: ${id}`);
|
|
229
|
+
this.sceneFactories.set(id, factory);
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
addSystem(system) {
|
|
233
|
+
if (this.systems.has(system.id))
|
|
234
|
+
throw new Error(`Duplicate system: ${system.id}`);
|
|
235
|
+
this.systems.set(system.id, system);
|
|
236
|
+
return this;
|
|
237
|
+
}
|
|
238
|
+
async addPlugin(plugin) {
|
|
239
|
+
if (this.plugins.has(plugin.id))
|
|
240
|
+
throw new Error(`Duplicate plugin: ${plugin.id}`);
|
|
241
|
+
await plugin.install(this.context);
|
|
242
|
+
this.plugins.set(plugin.id, plugin);
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
switchScene(id) {
|
|
246
|
+
const operation = this.switching.then(async () => {
|
|
247
|
+
if (this.disposing)
|
|
248
|
+
throw new Error('GameRuntime is disposed');
|
|
249
|
+
const factory = this.sceneFactories.get(id);
|
|
250
|
+
if (!factory)
|
|
251
|
+
throw new Error(`Unknown scene: ${id}`);
|
|
252
|
+
const previous = this.current;
|
|
253
|
+
if (previous?.id === id)
|
|
254
|
+
return previous;
|
|
255
|
+
const next = this.loadedScenes.get(id) ?? await factory();
|
|
256
|
+
if (next.id !== id)
|
|
257
|
+
throw new Error(`Scene factory for ${id} returned ${next.id}`);
|
|
258
|
+
if (!this.loadedScenes.has(id)) {
|
|
259
|
+
await next.load?.(this.context);
|
|
260
|
+
this.loadedScenes.set(id, next);
|
|
261
|
+
}
|
|
262
|
+
await previous?.exit?.(this.context);
|
|
263
|
+
this.current = next;
|
|
264
|
+
await next.enter?.(this.context);
|
|
265
|
+
this.events.emit('scene:changed', { previousId: previous?.id, currentId: id });
|
|
266
|
+
return next;
|
|
267
|
+
});
|
|
268
|
+
this.switching = operation.then(() => undefined, () => undefined);
|
|
269
|
+
return operation;
|
|
270
|
+
}
|
|
271
|
+
setPaused(paused) {
|
|
272
|
+
if (this.paused === paused)
|
|
273
|
+
return;
|
|
274
|
+
this.paused = paused;
|
|
275
|
+
this.events.emit('runtime:paused', { paused });
|
|
276
|
+
}
|
|
277
|
+
pause() { this.setPaused(true); }
|
|
278
|
+
resume() { this.setPaused(false); }
|
|
279
|
+
advance(deltaMs) {
|
|
280
|
+
if (this.paused) {
|
|
281
|
+
this.render(deltaMs);
|
|
282
|
+
return 0;
|
|
283
|
+
}
|
|
284
|
+
const steps = this.clock.advance(deltaMs, (tick) => {
|
|
285
|
+
this.scheduler.update(tick.deltaMs);
|
|
286
|
+
for (const system of this.systems.values())
|
|
287
|
+
system.fixedUpdate?.(tick, this.context);
|
|
288
|
+
this.current?.fixedUpdate?.(tick, this.context);
|
|
289
|
+
});
|
|
290
|
+
this.render(deltaMs);
|
|
291
|
+
return steps;
|
|
292
|
+
}
|
|
293
|
+
start(driver = browserFrameDriver) {
|
|
294
|
+
if (!driver)
|
|
295
|
+
throw new Error('A frame driver is required outside a browser');
|
|
296
|
+
if (this.disposing)
|
|
297
|
+
throw new Error('GameRuntime is disposed');
|
|
298
|
+
if (this.frameHandle !== undefined)
|
|
299
|
+
return;
|
|
300
|
+
const generation = ++this.runGeneration;
|
|
301
|
+
this.frameDriver = driver;
|
|
302
|
+
this.lastFrameMs = driver.now();
|
|
303
|
+
const frame = (timeMs) => {
|
|
304
|
+
if (generation !== this.runGeneration)
|
|
305
|
+
return;
|
|
306
|
+
const deltaMs = Math.max(0, Math.min(1000, timeMs - this.lastFrameMs));
|
|
307
|
+
this.lastFrameMs = timeMs;
|
|
308
|
+
this.advance(deltaMs);
|
|
309
|
+
// A scene may have called stop() — or stop() then start() — during that advance. Only the
|
|
310
|
+
// loop that still owns the runtime re-arms; a handle check alone would schedule two loops.
|
|
311
|
+
if (generation !== this.runGeneration)
|
|
312
|
+
return;
|
|
313
|
+
this.frameHandle = driver.request(frame);
|
|
314
|
+
};
|
|
315
|
+
this.frameHandle = driver.request(frame);
|
|
316
|
+
}
|
|
317
|
+
stop() {
|
|
318
|
+
this.runGeneration += 1;
|
|
319
|
+
if (this.frameHandle !== undefined)
|
|
320
|
+
this.frameDriver?.cancel(this.frameHandle);
|
|
321
|
+
this.frameHandle = undefined;
|
|
322
|
+
this.frameDriver = undefined;
|
|
323
|
+
}
|
|
324
|
+
render(deltaMs) {
|
|
325
|
+
for (const system of this.systems.values())
|
|
326
|
+
system.render?.(deltaMs, this.clock.alpha, this.context);
|
|
327
|
+
this.current?.render?.(deltaMs, this.clock.alpha, this.context);
|
|
328
|
+
}
|
|
329
|
+
async dispose() {
|
|
330
|
+
if (this.disposing)
|
|
331
|
+
return;
|
|
332
|
+
this.disposing = true;
|
|
333
|
+
this.stop();
|
|
334
|
+
// Settle any in-flight switchScene first, or it repopulates loadedScenes after teardown.
|
|
335
|
+
await this.switching;
|
|
336
|
+
await this.current?.exit?.(this.context);
|
|
337
|
+
for (const scene of [...this.loadedScenes.values()].reverse())
|
|
338
|
+
await scene.dispose?.();
|
|
339
|
+
for (const system of [...this.systems.values()].reverse())
|
|
340
|
+
await system.dispose?.();
|
|
341
|
+
for (const plugin of [...this.plugins.values()].reverse())
|
|
342
|
+
await plugin.dispose?.();
|
|
343
|
+
this.loadedScenes.clear();
|
|
344
|
+
this.systems.clear();
|
|
345
|
+
this.plugins.clear();
|
|
346
|
+
this.sceneFactories.clear();
|
|
347
|
+
this.scheduler.clear();
|
|
348
|
+
this.services.clear();
|
|
349
|
+
this.events.clear();
|
|
350
|
+
this.current = undefined;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,QAAQ;IACF,SAAS,GAAG,IAAI,GAAG,EAA4D,CAAC;IAEjG,EAAE,CAA2B,IAAS,EAAE,QAAsC;QAC5E,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;QACxD,SAAS,CAAC,GAAG,CAAC,QAAiD,CAAC,CAAC;QACjE,IAAI,CAAC,SAAS,CAAC,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AAO,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;YAAE,MAAM,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QACpF,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;QAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAAC,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QACnG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAAC,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;IAC/F,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@roost2d/core",
|
|
3
|
+
"version": "0.1.0-rc.0",
|
|
4
|
+
"description": "Runtime-neutral lifecycle, events, and frame scheduling primitives for Roost2D.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": { "type": "git", "url": "git+https://github.com/Roost2D/roost2d.git", "directory": "packages/core" },
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
10
|
+
"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } },
|
|
11
|
+
"publishConfig": { "access": "public" },
|
|
12
|
+
"scripts": { "build": "tsc -p tsconfig.json", "check": "tsc --noEmit -p tsconfig.json", "test": "node --test test/*.test.mjs" }
|
|
13
|
+
}
|