mani-game-engine 1.0.0-pre.4 → 1.0.0-pre.40

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 CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 Jan Mankopf
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Jan Mankopf
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,69 +1,69 @@
1
-
2
- #### Use entity component system
3
- ```typescript
4
- import {EntityComponent, GetComponent, GetEntity, Inject, Injector} from 'mani-injector';
5
-
6
- class Service {}
7
-
8
- class FooComponent {}
9
- class BarComponent {}
10
-
11
- class FirstEntity {
12
- @EntityComponent
13
- foo: FooComponent = new FooComponent();
14
- }
15
-
16
- class SecondEntity {
17
- @EntityComponent
18
- foo: FooComponent = new FooComponent();
19
- @EntityComponent
20
- bar: BarComponent = new BarComponent();
21
- }
22
-
23
- // this system is created for every entity that has a FooComponent
24
- class FooSystem {
25
- constructor(
26
- // get a reference to the component when the system is created for a specific entity
27
- @GetComponent readonly foo: FooComponent,
28
- // you can get the entity object
29
- @GetEntity readonly entity:Object
30
- ) {}
31
- }
32
-
33
- // this system is created for every entity that has a BarComponent
34
- class BarSystem {
35
- constructor(
36
- @GetComponent readonly bar: BarComponent,
37
- ) {}
38
- }
39
-
40
- // this system is created for every entity that has a FooComponent and a BarComponent
41
- class FooBarSystem {
42
- constructor(
43
- @GetComponent readonly foo: FooComponent,
44
- @GetComponent readonly bar: BarComponent,
45
- // you can inject everything that is mapped in the injector
46
- @Inject readonly service: Service
47
- ) {}
48
- }
49
-
50
-
51
- const injector = new Injector();
52
-
53
- injector.registerSystem(FooSystem);
54
- injector.registerSystem(BarSystem);
55
- injector.registerSystem(FooBarSystem);
56
- injector.map(Service).toSingleton();
57
-
58
- const entity1 = new FirstEntity();
59
- const entity2 = new SecondEntity();
60
-
61
- // array with one instance of FooSystem with a reference to the component
62
- console.log(injector.createSystems(entity1));
63
-
64
- // array with 3 systems
65
- // one instance of FooSystem
66
- // one instance of BarSystem
67
- // one instance of FooBarSystem
68
- console.log(injector.createSystems(entity2));
69
- ```
1
+
2
+ #### Use entity component system
3
+ ```typescript
4
+ import {EntityComponent, GetComponent, GetEntity, Inject, Injector} from 'mani-injector';
5
+
6
+ class Service {}
7
+
8
+ class FooComponent {}
9
+ class BarComponent {}
10
+
11
+ class FirstEntity {
12
+ @EntityComponent
13
+ foo: FooComponent = new FooComponent();
14
+ }
15
+
16
+ class SecondEntity {
17
+ @EntityComponent
18
+ foo: FooComponent = new FooComponent();
19
+ @EntityComponent
20
+ bar: BarComponent = new BarComponent();
21
+ }
22
+
23
+ // this system is created for every entity that has a FooComponent
24
+ class FooSystem {
25
+ constructor(
26
+ // get a reference to the component when the system is created for a specific entity
27
+ @GetComponent readonly foo: FooComponent,
28
+ // you can get the entity object
29
+ @GetEntity readonly entity:Object
30
+ ) {}
31
+ }
32
+
33
+ // this system is created for every entity that has a BarComponent
34
+ class BarSystem {
35
+ constructor(
36
+ @GetComponent readonly bar: BarComponent,
37
+ ) {}
38
+ }
39
+
40
+ // this system is created for every entity that has a FooComponent and a BarComponent
41
+ class FooBarSystem {
42
+ constructor(
43
+ @GetComponent readonly foo: FooComponent,
44
+ @GetComponent readonly bar: BarComponent,
45
+ // you can inject everything that is mapped in the injector
46
+ @Inject readonly service: Service
47
+ ) {}
48
+ }
49
+
50
+
51
+ const injector = new Injector();
52
+
53
+ injector.registerSystem(FooSystem);
54
+ injector.registerSystem(BarSystem);
55
+ injector.registerSystem(FooBarSystem);
56
+ injector.map(Service).toSingleton();
57
+
58
+ const entity1 = new FirstEntity();
59
+ const entity2 = new SecondEntity();
60
+
61
+ // array with one instance of FooSystem with a reference to the component
62
+ console.log(injector.createSystems(entity1));
63
+
64
+ // array with 3 systems
65
+ // one instance of FooSystem
66
+ // one instance of BarSystem
67
+ // one instance of FooBarSystem
68
+ console.log(injector.createSystems(entity2));
69
+ ```
package/lib/clock.d.ts CHANGED
@@ -1,41 +1,55 @@
1
- import { Signal } from 'mani-signal';
2
- declare type OnEarlyUpdateParams = {
3
- time: number;
4
- deltaTime: number;
5
- };
6
- declare type OnUpdateParams = {
7
- time: number;
8
- deltaTime: number;
9
- alpha: number;
10
- };
11
- declare type OnFixedUpdateParams = {
12
- time: number;
13
- deltaTime: number;
14
- };
15
- declare const defaultOptions: {
16
- autoStart: boolean;
17
- fixedDeltaTime: number;
18
- maxFrameTime: number;
19
- timeScale: number;
20
- };
21
- export declare type GameClockOptions = Partial<typeof defaultOptions>;
22
- export declare class Clock {
23
- private isRunning;
24
- private requestId;
25
- private currentTime;
26
- private accumulator;
27
- private gameTime;
28
- private fixedDeltaTime;
29
- private maxFrameTime;
30
- readonly onPrepare: Signal<any>;
31
- readonly onEarlyUpdate: Signal<OnEarlyUpdateParams>;
32
- readonly onUpdate: Signal<OnUpdateParams>;
33
- readonly onFixedUpdate: Signal<OnFixedUpdateParams>;
34
- constructor(options?: GameClockOptions);
35
- private update;
36
- private _timeScale;
37
- timeScale: number;
38
- start(): this;
39
- stop(): void;
40
- }
41
- export {};
1
+ import { Signal } from 'mani-signal';
2
+ import { OnEarlyUpdateParams, OnFixedUpdateParams, OnUpdateParams } from './types';
3
+ declare const defaultOptions: {
4
+ autoStart: boolean;
5
+ fixedDeltaTime: number;
6
+ maxFrameTime: number;
7
+ timeScale: number;
8
+ };
9
+ export type Timeout = {
10
+ recall?: number;
11
+ callback: Function;
12
+ callTime: number;
13
+ };
14
+ export type GameClockOptions = Partial<typeof defaultOptions>;
15
+ export interface Clock {
16
+ onPrepare: Signal<unknown>;
17
+ onEarlyUpdate: Signal<OnEarlyUpdateParams>;
18
+ onUpdate: Signal<OnUpdateParams>;
19
+ onFixedUpdate: Signal<OnFixedUpdateParams>;
20
+ timeScale: number;
21
+ start(): this;
22
+ stop(): this;
23
+ dispose(): void;
24
+ setTimeout(callback: Function, delay: number): number;
25
+ setInterval(callback: Function, delay: number): number;
26
+ clearTimeout(timeoutId: number): boolean;
27
+ }
28
+ export declare class GameClock implements Clock {
29
+ private nextTimeoutId;
30
+ private timeouts;
31
+ private isRunning;
32
+ private requestId;
33
+ private currentTime;
34
+ private accumulator;
35
+ private gameTime;
36
+ private readonly _fixedDeltaTime;
37
+ private update;
38
+ private readonly maxFrameTime;
39
+ readonly onPrepare: Signal<unknown>;
40
+ readonly onEarlyUpdate: Signal<OnEarlyUpdateParams>;
41
+ readonly onUpdate: Signal<OnUpdateParams>;
42
+ readonly onFixedUpdate: Signal<OnFixedUpdateParams>;
43
+ constructor(options?: GameClockOptions);
44
+ dispose(): void;
45
+ get fixedDeltaTime(): number;
46
+ private _timeScale;
47
+ get timeScale(): number;
48
+ set timeScale(value: number);
49
+ start(): this;
50
+ stop(): this;
51
+ setTimeout(callback: Function, delay: number): number;
52
+ setInterval(callback: Function, delay: number): number;
53
+ clearTimeout(timeoutId: number): boolean;
54
+ }
55
+ export {};
package/lib/clock.js CHANGED
@@ -1,78 +1,118 @@
1
- import { Signal } from 'mani-signal';
2
- const MIN_TIME_SCALE = 0.00001;
3
- const defaultOptions = {
4
- autoStart: true,
5
- fixedDeltaTime: 1 / 60,
6
- maxFrameTime: 0.25,
7
- timeScale: 1,
8
- };
9
- export class Clock {
10
- constructor(options) {
11
- this.isRunning = false;
12
- this.requestId = 0;
13
- this.currentTime = 0;
14
- this.accumulator = 0;
15
- this.gameTime = 0;
16
- this.onPrepare = new Signal();
17
- this.onEarlyUpdate = new Signal();
18
- this.onUpdate = new Signal();
19
- this.onFixedUpdate = new Signal();
20
- this.update = (time) => {
21
- const newTime = time * 0.001;
22
- if (!this.isRunning) {
23
- this.currentTime = newTime;
24
- this.isRunning = true;
25
- }
26
- let frameTime = (newTime - this.currentTime) * this.timeScale;
27
- if (frameTime > this.maxFrameTime) {
28
- frameTime = this.maxFrameTime;
29
- }
30
- this.currentTime = newTime;
31
- this.accumulator += frameTime;
32
- let isMultipleFixedUpdate = false;
33
- this.onPrepare.dispatch();
34
- this.onEarlyUpdate.dispatch({ time: this.gameTime, deltaTime: frameTime });
35
- while (this.accumulator >= this.fixedDeltaTime) {
36
- if (isMultipleFixedUpdate) {
37
- this.onPrepare.dispatch();
38
- }
39
- this.onFixedUpdate.dispatch({ time: this.gameTime, deltaTime: this.fixedDeltaTime });
40
- isMultipleFixedUpdate = true;
41
- this.accumulator -= this.fixedDeltaTime;
42
- this.gameTime += this.fixedDeltaTime;
43
- }
44
- const alpha = this.accumulator / this.fixedDeltaTime;
45
- this.onUpdate.dispatch({ time: this.gameTime + alpha * this.fixedDeltaTime, deltaTime: frameTime, alpha: alpha });
46
- if (this.isRunning) {
47
- this.requestId = requestAnimationFrame(this.update);
48
- }
49
- };
50
- this._timeScale = 1;
51
- const opts = Object.assign({}, defaultOptions, options);
52
- this.fixedDeltaTime = opts.fixedDeltaTime;
53
- this.maxFrameTime = opts.maxFrameTime;
54
- this.timeScale = opts.timeScale;
55
- opts.autoStart && this.start();
56
- }
57
- get timeScale() {
58
- return this._timeScale;
59
- }
60
- set timeScale(value) {
61
- this._timeScale = Math.max(value, MIN_TIME_SCALE);
62
- }
63
- start() {
64
- if (this.isRunning) {
65
- return this;
66
- }
67
- this.requestId = requestAnimationFrame(this.update);
68
- return this;
69
- }
70
- stop() {
71
- if (!this.isRunning) {
72
- return;
73
- }
74
- this.isRunning = false;
75
- cancelAnimationFrame(this.requestId);
76
- }
77
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GameClock = void 0;
4
+ const mani_signal_1 = require("mani-signal");
5
+ const MIN_TIME_SCALE = 0.00001;
6
+ const defaultOptions = {
7
+ autoStart: true,
8
+ fixedDeltaTime: 1 / 60,
9
+ maxFrameTime: 0.25,
10
+ timeScale: 1,
11
+ };
12
+ class GameClock {
13
+ constructor(options) {
14
+ this.nextTimeoutId = 0;
15
+ this.timeouts = new Map();
16
+ this.isRunning = false;
17
+ this.requestId = 0;
18
+ this.currentTime = 0;
19
+ this.accumulator = 0;
20
+ this.gameTime = 0;
21
+ this.update = (time) => {
22
+ const newTime = time * 0.001;
23
+ if (!this.isRunning) {
24
+ this.currentTime = newTime;
25
+ this.isRunning = true;
26
+ }
27
+ let frameTime = (newTime - this.currentTime) * this.timeScale;
28
+ if (frameTime > this.maxFrameTime) {
29
+ frameTime = this.maxFrameTime;
30
+ }
31
+ this.currentTime = newTime;
32
+ this.accumulator += frameTime;
33
+ let isMultipleFixedUpdate = false;
34
+ this.onPrepare.dispatch();
35
+ this.onEarlyUpdate.dispatch({ time: this.gameTime, deltaTime: frameTime });
36
+ for (const [id, timeOut] of this.timeouts) {
37
+ if (this.gameTime >= timeOut.callTime) {
38
+ timeOut.callback();
39
+ if (timeOut.recall) {
40
+ timeOut.callTime += timeOut.recall;
41
+ }
42
+ else {
43
+ this.timeouts.delete(id);
44
+ }
45
+ }
46
+ }
47
+ while (this.accumulator >= this._fixedDeltaTime) {
48
+ if (isMultipleFixedUpdate) {
49
+ this.onPrepare.dispatch();
50
+ }
51
+ this.onFixedUpdate.dispatch({ time: this.gameTime, deltaTime: this._fixedDeltaTime });
52
+ isMultipleFixedUpdate = true;
53
+ this.accumulator -= this._fixedDeltaTime;
54
+ this.gameTime += this._fixedDeltaTime;
55
+ }
56
+ const alpha = this.accumulator / this._fixedDeltaTime;
57
+ this.onUpdate.dispatch({ time: this.gameTime + alpha * this._fixedDeltaTime, deltaTime: frameTime, alpha: alpha });
58
+ if (this.isRunning) {
59
+ this.requestId = requestAnimationFrame(this.update);
60
+ }
61
+ };
62
+ this.onPrepare = new mani_signal_1.Signal();
63
+ this.onEarlyUpdate = new mani_signal_1.Signal();
64
+ this.onUpdate = new mani_signal_1.Signal();
65
+ this.onFixedUpdate = new mani_signal_1.Signal();
66
+ this._timeScale = 1;
67
+ const opts = Object.assign(Object.assign({}, defaultOptions), options);
68
+ this._fixedDeltaTime = opts.fixedDeltaTime;
69
+ this.maxFrameTime = opts.maxFrameTime;
70
+ this.timeScale = opts.timeScale;
71
+ opts.autoStart && this.start();
72
+ }
73
+ dispose() {
74
+ this.onPrepare.detachAll();
75
+ this.onEarlyUpdate.detachAll();
76
+ this.onUpdate.detachAll();
77
+ this.onFixedUpdate.detachAll();
78
+ }
79
+ get fixedDeltaTime() { return this._fixedDeltaTime; }
80
+ get timeScale() {
81
+ return this._timeScale;
82
+ }
83
+ set timeScale(value) {
84
+ this._timeScale = Math.max(value, MIN_TIME_SCALE);
85
+ }
86
+ start() {
87
+ if (this.isRunning) {
88
+ return this;
89
+ }
90
+ this.requestId = requestAnimationFrame(this.update);
91
+ return this;
92
+ }
93
+ stop() {
94
+ if (!this.isRunning) {
95
+ return this;
96
+ }
97
+ this.isRunning = false;
98
+ cancelAnimationFrame(this.requestId);
99
+ return this;
100
+ }
101
+ setTimeout(callback, delay) {
102
+ const timeOut = { callback, callTime: this.gameTime + delay };
103
+ this.nextTimeoutId++;
104
+ this.timeouts.set(this.nextTimeoutId, timeOut);
105
+ return this.nextTimeoutId;
106
+ }
107
+ setInterval(callback, delay) {
108
+ const timeOut = { callback, callTime: this.gameTime + delay, recall: delay };
109
+ this.nextTimeoutId++;
110
+ this.timeouts.set(this.nextTimeoutId, timeOut);
111
+ return this.nextTimeoutId;
112
+ }
113
+ clearTimeout(timeoutId) {
114
+ return this.timeouts.delete(timeoutId);
115
+ }
116
+ }
117
+ exports.GameClock = GameClock;
78
118
  //# sourceMappingURL=clock.js.map
package/lib/clock.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"clock.js","sourceRoot":"","sources":["../src/clock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAEnC,MAAM,cAAc,GAAG,OAAO,CAAC;AAM/B,MAAM,cAAc,GAAG;IACnB,SAAS,EAAE,IAAI;IACf,cAAc,EAAE,CAAC,GAAG,EAAE;IACtB,YAAY,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AC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC3C,CAAC;CACJ;AA9HD,8BA8HC"}
@@ -1,21 +1,46 @@
1
- import { Class, ID, Injector, ResolverFunction } from 'mani-injector';
2
- import { Signal } from 'mani-signal';
3
- declare type SystemResolvers<T extends Class> = [T, ResolverFunction[]];
4
- export declare const entityComponents: Map<Class<any>, Map<Class<any>, string>>;
5
- export declare const GetComponent: (dependantType: Class<any>, _propertyKey: string | symbol, index: number) => any;
6
- export declare const GetEntity: (dependantType: Class<any>, _propertyKey: string | symbol, index: number) => any;
7
- export declare const GetSignal: (id: string | symbol) => (dependantType: Class<any>, _propertyKey: string | symbol, index: number) => any;
8
- export declare const EntityComponent: (target: object, propertyKey: string) => any;
9
- export declare const signalHandlers: Map<Object, [string, string | symbol][]>;
10
- export declare const staticSignalHandlers: Map<Object, [string, string | symbol][]>;
11
- export declare const OnSignal: (id: string | symbol) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
12
- export declare class EcsInjector<SystemClass extends Class = Class> extends Injector {
13
- protected entitySystemMap: Map<Class, SystemClass[]>;
14
- protected entitySystemResolverTuples: Map<Class, SystemResolvers<SystemClass>[]>;
15
- private signalMap;
16
- constructor(parent?: EcsInjector<SystemClass>);
17
- registerSystem<T extends SystemClass>(systemClass: T): void;
18
- createSystems(entity: Object): InstanceType<SystemClass>[];
19
- getSignal<T>(id: ID): Signal<T>;
20
- }
21
- export {};
1
+ import { Signal } from 'mani-signal';
2
+ import { Class, Dependency, ID, Injector, ResolverFunction } from './injector';
3
+ import { SystemContext } from './systemContext';
4
+ import { Entity } from './entity';
5
+ type ComponentClass = Class;
6
+ type EntityClass = Class;
7
+ type ComponentDependency = Dependency & {
8
+ kind: 'component';
9
+ index: number;
10
+ type: Class;
11
+ };
12
+ type DynamicComponentDependency = Dependency & {
13
+ kind: 'dynamic';
14
+ index: number;
15
+ type: Class;
16
+ };
17
+ export declare const GetComponent: (dependantType: Class<any>, _propertyKey: string | symbol, index: number) => any;
18
+ export declare const GetDynamicComponent: (dependantType: Class<any>, _propertyKey: string | symbol, index: number) => any;
19
+ export declare const GetEntity: (dependantType: Class<any>, _propertyKey: string | symbol, index: number) => any;
20
+ export declare const GetContext: (dependantType: Class<any>, _propertyKey: string | symbol, index: number) => any;
21
+ export declare const GetSignal: (id: ID) => (dependantType: Class<any>, _propertyKey: string | symbol, index: number) => any;
22
+ export declare const GetEntitySignal: (id: ID) => (dependantType: Class<any>, _propertyKey: string | symbol, index: number) => any;
23
+ export declare const EntityComponent: (target: object, propertyKey: string) => any;
24
+ export declare const signalHandlers: Map<Object, [string, ID][]>;
25
+ export declare const staticSignalHandlers: Map<Object, [string, ID][]>;
26
+ export declare const OnSignal: (id: ID) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
27
+ export declare class EcsInjector<SystemClass extends Class = Class> extends Injector {
28
+ static warnNoMatchingEntities: boolean;
29
+ static entityComponents: Map<EntityClass, Map<ComponentClass, string>>;
30
+ protected componentDependencyMap: Map<Class<any>, ComponentDependency[]>;
31
+ protected dynamicComponentDependencyMap: Map<Class<any>, DynamicComponentDependency[]>;
32
+ protected entitySystemMap: Map<Class, SystemClass[]>;
33
+ protected dynamicComponentSystemMap: Map<Class, SystemClass[]>;
34
+ protected entitySystemResolverTuples: Map<Class, Map<SystemClass, ResolverFunction[]>>;
35
+ private signalMap;
36
+ constructor(parent?: EcsInjector<SystemClass>);
37
+ newSignalScope(): void;
38
+ registerSystem<T extends SystemClass>(systemClass: T): void;
39
+ createSystemsForDynamicComponents(dynamicComponentClass: Class, entity: Entity): Set<SystemContext<import("./types").System>>;
40
+ createSystemsForEntity(entity: Entity): Set<SystemContext>;
41
+ private createSystems;
42
+ private getSystemResolverTuples;
43
+ getSignal<T>(id: ID): Signal<T>;
44
+ dispose(): void;
45
+ }
46
+ export {};