@awesome-ecs/abstract 0.0.1 → 0.0.5

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Andrei C
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,99 +1,99 @@
1
- # Awesome ECS (Entity-Component-System)
2
-
3
- ## What is it?
4
-
5
- The Entity-Component-System is a well-known Architecture type used for responsive, complex applications, not only restricted to the Web.
6
- It's mostly associated with Game Engines, because of it's way of segregating Behavior from State, and allowing fine-control of the Runtime.
7
-
8
- ## Building blocks
9
-
10
- ### Entities
11
-
12
- Entities are really just collections of Components.
13
-
14
- In this Awesome ECS Architecture implementation, an Entity is built of:
15
-
16
- - one or more Components
17
- - proxies to other Entities
18
-
19
- Entity changes can triggered from outside systems (e.g. UI events, data from backend, a Redux Store change), or on ran a Schedule (e.g. Engine Loop).
20
-
21
- ### Components
22
-
23
- Components are data-holders. They are instantiated for each Entity, and hold the state for the Entity.
24
- An Entity can have many different types of Components, based on what the Entity State is.
25
-
26
- Components should not contain any behavior, only keep data (e.g. Plain-Objects).
27
-
28
- ### Systems
29
-
30
- Systems are behaviors of the ECS Architecture. They receive an Entity as input, and run Behaviors, altering the data contained in the Entity's Components.
31
- Systems are usually Entity-specific, but they can be shared (e.g. Two Entities having the same Component Type, can in fact, share a System's Behavior).
32
-
33
- ## Awesome ECS Architecture
34
-
35
- ### Pipeline
36
-
37
- The Pipelines are at the heart of the Easy ECS Architecture implementation, and it's a way of declaring which Systems are run as part of the Runtime Loop.
38
-
39
- ### Middleware
40
-
41
- The Middleware is the Unit-of-Work implementation of a System, and allows for a System to achieve Single-Responsibility (part of SOLID principles.).
42
-
43
- A Middleware has 3 methods:
44
- - `shouldRun: boolean` -> specifies whether the current System should run it's `action` method, to introduce State changes on the Entity's Components
45
- - `action: void` -> the System implementation that allows for altering Entity Component state, can use Entity Proxies, or Schedule updates for itself or other Entities
46
- - `cleanup: void` -> the System implementation method that gets called when the Entity Model Change Type is Removed. It handles the disposal of any internal objects the System might have instantiated
47
-
48
- Each Middleware method will receive a `context: SystemPipelineContext<TEntity>`, which contains the current Entity state, as well as the Entity Model Change, and any Entity changes Scheduled for Dispatch at the end of the current Tick
49
-
50
- ## Entity Changes
51
-
52
- Each Entity has a mandatory Identity Component. This Identity Component will hold the current Entity Model, and it's Entity Unique Identifier.
53
- Model changes will prompt an Entity to introduce itself on a Entity Change Queue, to be processed on the next Tick by the Runtime.
54
-
55
- ### The Runtime
56
-
57
- The Awesome ECS Architecture implementation Runtime is structured in Loops of Ticks.
58
-
59
- Each Tick has an allocated time for running, and will process Entity Changes during that Tick.
60
- If there is more time left in the current Loop, and the Entity Change Queue is not empty, the next Entity Change in the Entity Change Queue, will be processed.
61
-
62
- ### The Ticks
63
-
64
- Each Tick will receive as an input an Entity Model Change, which will contain: the Current Model, the Previous Model (if available), and the Change Type (Added, Updated or Removed).
65
-
66
- Based on the Change Type and Model, the Entity Identifier is being searched.
67
- Based on the found Entity Identifier and Change Type, The Runtime instantiates the System Pipeline associated with that change.
68
-
69
- ## Runtime Stages
70
-
71
- The Runtime has a few Stages, that will run in this order:
72
-
73
- - Initializer Systems
74
- - Updater Systems
75
- - Renderer Systems
76
- - (Dispatcher) Systems
77
-
78
- Each Stage is a System Pipeline, which will run it's associated System Middlewares, in the order they were registered in.
79
-
80
- ### Generator Systems
81
-
82
- The Generator Systems will be ran once per Entity, when the Model Change Type is Added.
83
- All the Middlewares registered for this stage will contribute to enrich the Entity Components with bootstrap data.
84
-
85
- ### Updater Systems
86
-
87
- The Updater Systems will be ran on each Model Change, and it's the main way of altering the Entity's Components state.
88
-
89
- ### Render Systems
90
-
91
- The Render Systems will make sure to update the underlying Render system with the Entity's `RenderingComponent` state. It's useful as an abstraction layer to lower-lever Rendering (e.g. a Game Engine, WebGL, Canvas)
92
-
93
- The Render Systems can be skipped from the Runtime, if needed. That can be useful to simulate the same Runtime in a non-rendered system, like the Backend.
94
-
95
- ### (Dispatch) Systems
96
-
97
- The Dispatch Systems are built-in Systems in the Awesome ECS, and will take care of Dispatching Actions, Scheduling Entity updates, or synchronizing the Entity Repository with the latest Entity State in the current Context.
98
-
99
- The Dispatch Systems, as well as any other Runtime Stage, can be extended as needed by registering more System Middlewares in the Stage Pipeline.
1
+ # Awesome ECS (Entity-Component-System)
2
+
3
+ ## What is it?
4
+
5
+ The Entity-Component-System is a well-known Architecture type used for responsive, complex applications, not only restricted to the Web.
6
+ It's mostly associated with Game Engines, because of it's way of segregating Behavior from State, and allowing fine-control of the Runtime.
7
+
8
+ ## Building blocks
9
+
10
+ ### Entities
11
+
12
+ Entities are really just collections of Components.
13
+
14
+ In this Awesome ECS Architecture implementation, an Entity is built of:
15
+
16
+ - one or more Components
17
+ - proxies to other Entities
18
+
19
+ Entity changes can triggered from outside systems (e.g. UI events, data from backend, a Redux Store change), or on ran a Schedule (e.g. Engine Loop).
20
+
21
+ ### Components
22
+
23
+ Components are data-holders. They are instantiated for each Entity, and hold the state for the Entity.
24
+ An Entity can have many different types of Components, based on what the Entity State is.
25
+
26
+ Components should not contain any behavior, only keep data (e.g. Plain-Objects).
27
+
28
+ ### Systems
29
+
30
+ Systems are behaviors of the ECS Architecture. They receive an Entity as input, and run Behaviors, altering the data contained in the Entity's Components.
31
+ Systems are usually Entity-specific, but they can be shared (e.g. Two Entities having the same Component Type, can in fact, share a System's Behavior).
32
+
33
+ ## Awesome ECS Architecture
34
+
35
+ ### Pipeline
36
+
37
+ The Pipelines are at the heart of the Easy ECS Architecture implementation, and it's a way of declaring which Systems are run as part of the Runtime Loop.
38
+
39
+ ### Middleware
40
+
41
+ The Middleware is the Unit-of-Work implementation of a System, and allows for a System to achieve Single-Responsibility (part of SOLID principles.).
42
+
43
+ A Middleware has 3 methods:
44
+ - `shouldRun: boolean` -> specifies whether the current System should run it's `action` method, to introduce State changes on the Entity's Components
45
+ - `action: void` -> the System implementation that allows for altering Entity Component state, can use Entity Proxies, or Schedule updates for itself or other Entities
46
+ - `cleanup: void` -> the System implementation method that gets called when the Entity Model Change Type is Removed. It handles the disposal of any internal objects the System might have instantiated
47
+
48
+ Each Middleware method will receive a `context: SystemPipelineContext<TEntity>`, which contains the current Entity state, as well as the Entity Model Change, and any Entity changes Scheduled for Dispatch at the end of the current Tick
49
+
50
+ ## Entity Changes
51
+
52
+ Each Entity has a mandatory Identity Component. This Identity Component will hold the current Entity Model, and it's Entity Unique Identifier.
53
+ Model changes will prompt an Entity to introduce itself on a Entity Change Queue, to be processed on the next Tick by the Runtime.
54
+
55
+ ### The Runtime
56
+
57
+ The Awesome ECS Architecture implementation Runtime is structured in Loops of Ticks.
58
+
59
+ Each Tick has an allocated time for running, and will process Entity Changes during that Tick.
60
+ If there is more time left in the current Loop, and the Entity Change Queue is not empty, the next Entity Change in the Entity Change Queue, will be processed.
61
+
62
+ ### The Ticks
63
+
64
+ Each Tick will receive as an input an Entity Model Change, which will contain: the Current Model, the Previous Model (if available), and the Change Type (Added, Updated or Removed).
65
+
66
+ Based on the Change Type and Model, the Entity Identifier is being searched.
67
+ Based on the found Entity Identifier and Change Type, The Runtime instantiates the System Pipeline associated with that change.
68
+
69
+ ## Runtime Stages
70
+
71
+ The Runtime has a few Stages, that will run in this order:
72
+
73
+ - Initializer Systems
74
+ - Updater Systems
75
+ - Renderer Systems
76
+ - (Dispatcher) Systems
77
+
78
+ Each Stage is a System Pipeline, which will run it's associated System Middlewares, in the order they were registered in.
79
+
80
+ ### Generator Systems
81
+
82
+ The Generator Systems will be ran once per Entity, when the Model Change Type is Added.
83
+ All the Middlewares registered for this stage will contribute to enrich the Entity Components with bootstrap data.
84
+
85
+ ### Updater Systems
86
+
87
+ The Updater Systems will be ran on each Model Change, and it's the main way of altering the Entity's Components state.
88
+
89
+ ### Render Systems
90
+
91
+ The Render Systems will make sure to update the underlying Render system with the Entity's `RenderingComponent` state. It's useful as an abstraction layer to lower-lever Rendering (e.g. a Game Engine, WebGL, Canvas)
92
+
93
+ The Render Systems can be skipped from the Runtime, if needed. That can be useful to simulate the same Runtime in a non-rendered system, like the Backend.
94
+
95
+ ### (Dispatch) Systems
96
+
97
+ The Dispatch Systems are built-in Systems in the Awesome ECS, and will take care of Dispatching Actions, Scheduling Entity updates, or synchronizing the Entity Repository with the latest Entity State in the current Context.
98
+
99
+ The Dispatch Systems, as well as any other Runtime Stage, can be extended as needed by registering more System Middlewares in the Stage Pipeline.
@@ -1,6 +1,9 @@
1
1
  import { IComponent } from "./component";
2
2
  import { IEntityModel } from "../entities/entity-model";
3
3
  import { EntityTypeUid } from "../entities/entity";
4
+ export declare enum BasicComponentType {
5
+ identity = "identity"
6
+ }
4
7
  export interface IdentityComponent<TModel extends IEntityModel> extends IComponent {
5
8
  entityType: EntityTypeUid;
6
9
  model: TModel;
@@ -1,2 +1,5 @@
1
- export {};
1
+ export var BasicComponentType;
2
+ (function (BasicComponentType) {
3
+ BasicComponentType["identity"] = "identity";
4
+ })(BasicComponentType || (BasicComponentType = {}));
2
5
  //# sourceMappingURL=identity-component.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"identity-component.js","sourceRoot":"","sources":["../../src/components/identity-component.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"identity-component.js","sourceRoot":"","sources":["../../src/components/identity-component.ts"],"names":[],"mappings":"AAIA,MAAM,CAAN,IAAY,kBAEX;AAFD,WAAY,kBAAkB;IAC5B,2CAAqB,CAAA;AACvB,CAAC,EAFW,kBAAkB,KAAlB,kBAAkB,QAE7B"}
@@ -7,4 +7,6 @@ export interface IEntityRepository {
7
7
  set(entity: IEntity): void;
8
8
  delete(entity: IEntity): void;
9
9
  clear(entityType: EntityTypeUid): void;
10
+ onEntitySetCallback?: (entity: IEntity) => void;
11
+ onEntityDeletedCallback?: (entity: IEntity) => void;
10
12
  }
@@ -0,0 +1,5 @@
1
+ import { IEntityProxy } from "./entity-proxy";
2
+ export interface IEntityScheduler {
3
+ schedule(entityProxy: IEntityProxy, intervalMs?: number): void;
4
+ remove(entityProxy: IEntityProxy): void;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=entity-scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-scheduler.js","sourceRoot":"","sources":["../../src/entities/entity-scheduler.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from './entities/entity';
4
4
  export * from './entities/entity-model';
5
5
  export * from './entities/entity-proxy';
6
6
  export * from './entities/entity-repository';
7
+ export * from './entities/entity-scheduler';
7
8
  export * from './pipelines/middleware';
8
9
  export * from './pipelines/pipeline';
9
10
  export * from './systems/system-middleware';
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ export * from './entities/entity';
4
4
  export * from './entities/entity-model';
5
5
  export * from './entities/entity-proxy';
6
6
  export * from './entities/entity-repository';
7
+ export * from './entities/entity-scheduler';
7
8
  export * from './pipelines/middleware';
8
9
  export * from './pipelines/pipeline';
9
10
  export * from './systems/system-middleware';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,iCAAiC,CAAC;AAEhD,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAE7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AAErC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,iCAAiC,CAAA;AAE/C,cAAc,mBAAmB,CAAA;AACjC,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,6BAA6B,CAAA;AAE3C,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AAEpC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA;AACzC,cAAc,mCAAmC,CAAA;AACjD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,0BAA0B,CAAA;AAExC,cAAc,2BAA2B,CAAA"}
@@ -2,5 +2,6 @@ export declare enum SystemPipelineType {
2
2
  initialize = "initialize",
3
3
  update = "update",
4
4
  render = "render",
5
+ sync = "sync",
5
6
  dispatch = "dispatch"
6
7
  }
@@ -3,6 +3,7 @@ export var SystemPipelineType;
3
3
  SystemPipelineType["initialize"] = "initialize";
4
4
  SystemPipelineType["update"] = "update";
5
5
  SystemPipelineType["render"] = "render";
6
+ SystemPipelineType["sync"] = "sync";
6
7
  SystemPipelineType["dispatch"] = "dispatch";
7
8
  })(SystemPipelineType || (SystemPipelineType = {}));
8
9
  //# sourceMappingURL=system-pipeline-type.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"system-pipeline-type.js","sourceRoot":"","sources":["../../src/systems/system-pipeline-type.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,+CAAyB,CAAA;IACzB,uCAAiB,CAAA;IACjB,uCAAiB,CAAA;IACjB,2CAAqB,CAAA;AACvB,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B"}
1
+ {"version":3,"file":"system-pipeline-type.js","sourceRoot":"","sources":["../../src/systems/system-pipeline-type.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,+CAAyB,CAAA;IACzB,uCAAiB,CAAA;IACjB,uCAAiB,CAAA;IACjB,mCAAa,CAAA;IACb,2CAAqB,CAAA;AACvB,CAAC,EANW,kBAAkB,KAAlB,kBAAkB,QAM7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesome-ecs/abstract",
3
- "version": "0.0.1",
3
+ "version": "0.0.5",
4
4
  "description": "A comprehensive Entity-Component-System (ECS) Architecture implementation. Abstract components.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -31,5 +31,6 @@
31
31
  "bugs": {
32
32
  "url": "https://github.com/andreicojocaru/awesome-ecs/issues"
33
33
  },
34
- "homepage": "https://github.com/andreicojocaru/awesome-ecs#readme"
34
+ "homepage": "https://github.com/andreicojocaru/awesome-ecs#readme",
35
+ "gitHead": "34ab2cd27bc77e3b1269314b588ea458b1f78f23"
35
36
  }
@@ -1,2 +0,0 @@
1
- export * from './component';
2
- export * from './identity-component';
@@ -1,3 +0,0 @@
1
- export * from './component';
2
- export * from './identity-component';
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,sBAAsB,CAAA"}