@dcl/ecs 1.0.0-20220506152015.commit-2dd9f0a
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/README.md +18 -0
- package/dist/built-in-types/ArrayType.d.ts +3 -0
- package/dist/built-in-types/ArrayType.d.ts.map +1 -0
- package/dist/built-in-types/ArrayType.js +23 -0
- package/dist/built-in-types/ArrayType.js.map +1 -0
- package/dist/built-in-types/EcsType.d.ts +6 -0
- package/dist/built-in-types/EcsType.d.ts.map +1 -0
- package/dist/built-in-types/EcsType.js +3 -0
- package/dist/built-in-types/EcsType.js.map +1 -0
- package/dist/built-in-types/MapType.d.ts +10 -0
- package/dist/built-in-types/MapType.d.ts.map +1 -0
- package/dist/built-in-types/MapType.js +24 -0
- package/dist/built-in-types/MapType.js.map +1 -0
- package/dist/built-in-types/Optional.d.ts +3 -0
- package/dist/built-in-types/Optional.d.ts.map +1 -0
- package/dist/built-in-types/Optional.js +24 -0
- package/dist/built-in-types/Optional.js.map +1 -0
- package/dist/built-in-types/basic/Boolean.d.ts +3 -0
- package/dist/built-in-types/basic/Boolean.d.ts.map +1 -0
- package/dist/built-in-types/basic/Boolean.js +12 -0
- package/dist/built-in-types/basic/Boolean.js.map +1 -0
- package/dist/built-in-types/basic/Enum.d.ts +3 -0
- package/dist/built-in-types/basic/Enum.d.ts.map +1 -0
- package/dist/built-in-types/basic/Enum.js +15 -0
- package/dist/built-in-types/basic/Enum.js.map +1 -0
- package/dist/built-in-types/basic/Float.d.ts +4 -0
- package/dist/built-in-types/basic/Float.d.ts.map +1 -0
- package/dist/built-in-types/basic/Float.js +20 -0
- package/dist/built-in-types/basic/Float.js.map +1 -0
- package/dist/built-in-types/basic/Integer.d.ts +6 -0
- package/dist/built-in-types/basic/Integer.d.ts.map +1 -0
- package/dist/built-in-types/basic/Integer.js +44 -0
- package/dist/built-in-types/basic/Integer.js.map +1 -0
- package/dist/built-in-types/basic/String.d.ts +4 -0
- package/dist/built-in-types/basic/String.d.ts.map +1 -0
- package/dist/built-in-types/basic/String.js +13 -0
- package/dist/built-in-types/basic/String.js.map +1 -0
- package/dist/built-in-types/index.d.ts +10 -0
- package/dist/built-in-types/index.d.ts.map +1 -0
- package/dist/built-in-types/index.js +26 -0
- package/dist/built-in-types/index.js.map +1 -0
- package/dist/built-in-types/typing.d.ts +17 -0
- package/dist/built-in-types/typing.d.ts.map +1 -0
- package/dist/built-in-types/typing.js +3 -0
- package/dist/built-in-types/typing.js.map +1 -0
- package/dist/components/definitions/BoxShape.proto +13 -0
- package/dist/components/definitions/README.md +0 -0
- package/dist/components/definitions/Transform.md +0 -0
- package/dist/components/generated/BoxShape.d.ts +5 -0
- package/dist/components/generated/BoxShape.d.ts.map +1 -0
- package/dist/components/generated/BoxShape.js +17 -0
- package/dist/components/generated/BoxShape.js.map +1 -0
- package/dist/components/generated/index.d.ts +5 -0
- package/dist/components/generated/index.d.ts.map +1 -0
- package/dist/components/generated/index.js +34 -0
- package/dist/components/generated/index.js.map +1 -0
- package/dist/components/generated/pb/BoxShape.d.ts +13 -0
- package/dist/components/generated/pb/BoxShape.d.ts.map +1 -0
- package/dist/components/generated/pb/BoxShape.js +91 -0
- package/dist/components/generated/pb/BoxShape.js.map +1 -0
- package/dist/components/index.d.ts +11 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +26 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/legacy/Transform.d.ts +10 -0
- package/dist/components/legacy/Transform.d.ts.map +1 -0
- package/dist/components/legacy/Transform.js +29 -0
- package/dist/components/legacy/Transform.js.map +1 -0
- package/dist/components/legacy/index.d.ts +10 -0
- package/dist/components/legacy/index.d.ts.map +1 -0
- package/dist/components/legacy/index.js +14 -0
- package/dist/components/legacy/index.js.map +1 -0
- package/dist/components/legacy/types.d.ts +52 -0
- package/dist/components/legacy/types.d.ts.map +1 -0
- package/dist/components/legacy/types.js +57 -0
- package/dist/components/legacy/types.js.map +1 -0
- package/dist/components/types.d.ts +4 -0
- package/dist/components/types.d.ts.map +1 -0
- package/dist/components/types.js +8 -0
- package/dist/components/types.js.map +1 -0
- package/dist/ecs.api.json +418 -0
- package/dist/engine/component.d.ts +26 -0
- package/dist/engine/component.d.ts.map +1 -0
- package/dist/engine/component.js +103 -0
- package/dist/engine/component.js.map +1 -0
- package/dist/engine/entity-utils.d.ts +8 -0
- package/dist/engine/entity-utils.d.ts.map +1 -0
- package/dist/engine/entity-utils.js +22 -0
- package/dist/engine/entity-utils.js.map +1 -0
- package/dist/engine/entity.d.ts +18 -0
- package/dist/engine/entity.d.ts.map +1 -0
- package/dist/engine/entity.js +80 -0
- package/dist/engine/entity.js.map +1 -0
- package/dist/engine/index.d.ts +46 -0
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/index.js +139 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/types.d.ts +10 -0
- package/dist/engine/types.d.ts.map +1 -0
- package/dist/engine/types.js +3 -0
- package/dist/engine/types.js.map +1 -0
- package/dist/engine/utils.d.ts +4 -0
- package/dist/engine/utils.d.ts.map +1 -0
- package/dist/engine/utils.js +17 -0
- package/dist/engine/utils.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/serialization/ByteBuffer/index.d.ts +120 -0
- package/dist/serialization/ByteBuffer/index.d.ts.map +1 -0
- package/dist/serialization/ByteBuffer/index.js +272 -0
- package/dist/serialization/ByteBuffer/index.js.map +1 -0
- package/dist/serialization/crdt/componentOperation.d.ts +26 -0
- package/dist/serialization/crdt/componentOperation.d.ts.map +1 -0
- package/dist/serialization/crdt/componentOperation.js +46 -0
- package/dist/serialization/crdt/componentOperation.js.map +1 -0
- package/dist/serialization/wireMessage.d.ts +40 -0
- package/dist/serialization/wireMessage.d.ts.map +1 -0
- package/dist/serialization/wireMessage.js +57 -0
- package/dist/serialization/wireMessage.js.map +1 -0
- package/dist/systems/crdt/index.d.ts +12 -0
- package/dist/systems/crdt/index.d.ts.map +1 -0
- package/dist/systems/crdt/index.js +121 -0
- package/dist/systems/crdt/index.js.map +1 -0
- package/dist/systems/crdt/transport.d.ts +2 -0
- package/dist/systems/crdt/transport.d.ts.map +1 -0
- package/dist/systems/crdt/transport.js +8 -0
- package/dist/systems/crdt/transport.js.map +1 -0
- package/dist/systems/crdt/utils.d.ts +14 -0
- package/dist/systems/crdt/utils.d.ts.map +1 -0
- package/dist/systems/crdt/utils.js +54 -0
- package/dist/systems/crdt/utils.js.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/package.json +45 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityContainer = void 0;
|
|
4
|
+
const entity_utils_1 = require("./entity-utils");
|
|
5
|
+
function EntityContainer() {
|
|
6
|
+
const staticEntity = Entity();
|
|
7
|
+
const dynamicEntity = Entity(true);
|
|
8
|
+
return {
|
|
9
|
+
generateEntity(dynamic = false) {
|
|
10
|
+
if (dynamic)
|
|
11
|
+
return dynamicEntity.generateEntity();
|
|
12
|
+
return staticEntity.generateEntity();
|
|
13
|
+
},
|
|
14
|
+
removeEntity(entity) {
|
|
15
|
+
staticEntity.removeEntity(entity);
|
|
16
|
+
dynamicEntity.removeEntity(entity);
|
|
17
|
+
},
|
|
18
|
+
getUnusedEntities() {
|
|
19
|
+
return new Set([
|
|
20
|
+
...staticEntity.getUnusedEntities(),
|
|
21
|
+
...dynamicEntity.getUnusedEntities()
|
|
22
|
+
]);
|
|
23
|
+
},
|
|
24
|
+
getUsedEntities() {
|
|
25
|
+
return new Set([
|
|
26
|
+
...staticEntity.getUsedEntities(),
|
|
27
|
+
...dynamicEntity.getUsedEntities()
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.EntityContainer = EntityContainer;
|
|
33
|
+
function Entity(withOffset = false) {
|
|
34
|
+
function createEntity(entity) {
|
|
35
|
+
return entity;
|
|
36
|
+
}
|
|
37
|
+
// TODO: getoffset from a server?
|
|
38
|
+
const offset = withOffset ? entity_utils_1.EntityUtils.getOffset() : 0;
|
|
39
|
+
const usedEntities = new Set();
|
|
40
|
+
const unusedEntities = new Set();
|
|
41
|
+
function generateEntity() {
|
|
42
|
+
if (!unusedEntities.size && !usedEntities.size) {
|
|
43
|
+
const entity = createEntity(offset);
|
|
44
|
+
usedEntities.add(entity);
|
|
45
|
+
return entity;
|
|
46
|
+
}
|
|
47
|
+
// TODO: what happens if we delete an entity
|
|
48
|
+
// and creates a new one in the same tick
|
|
49
|
+
const iterator = unusedEntities[Symbol.iterator]().next();
|
|
50
|
+
if (iterator.done) {
|
|
51
|
+
const entity = createEntity(Math.max(...usedEntities.values()) + 1);
|
|
52
|
+
if (entity >= entity_utils_1.EntityUtils.MAX_ENTITIES + offset) {
|
|
53
|
+
throw new Error('Entity rate limit exceed');
|
|
54
|
+
}
|
|
55
|
+
usedEntities.add(entity);
|
|
56
|
+
return entity;
|
|
57
|
+
}
|
|
58
|
+
const entity = iterator.value;
|
|
59
|
+
unusedEntities.delete(entity);
|
|
60
|
+
usedEntities.add(entity);
|
|
61
|
+
return entity;
|
|
62
|
+
}
|
|
63
|
+
function removeEntity(entity) {
|
|
64
|
+
if (!usedEntities.has(entity))
|
|
65
|
+
return;
|
|
66
|
+
usedEntities.delete(entity);
|
|
67
|
+
unusedEntities.add(entity);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
getUnusedEntities() {
|
|
71
|
+
return new Set(unusedEntities);
|
|
72
|
+
},
|
|
73
|
+
getUsedEntities() {
|
|
74
|
+
return new Set(usedEntities);
|
|
75
|
+
},
|
|
76
|
+
generateEntity,
|
|
77
|
+
removeEntity
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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+
import { defineSdkComponents } from '../components';
|
|
2
|
+
import { Entity } from './entity';
|
|
3
|
+
import { ComponentDefinition } from './component';
|
|
4
|
+
import { ComponentEcsType, Update, DeepReadonly } from './types';
|
|
5
|
+
import { EcsType } from '../built-in-types';
|
|
6
|
+
/**
|
|
7
|
+
* @alpha
|
|
8
|
+
*/
|
|
9
|
+
declare function preEngine(): {
|
|
10
|
+
entitiesComponent: Map<number, Set<number>>;
|
|
11
|
+
componentsDefinition: Map<number, ComponentDefinition<any>>;
|
|
12
|
+
systems: Set<Update>;
|
|
13
|
+
addEntity: (dynamic?: boolean) => Entity;
|
|
14
|
+
addDynamicEntity: () => Entity;
|
|
15
|
+
removeEntity: (entity: Entity) => void;
|
|
16
|
+
addSystem: (fn: Update) => void;
|
|
17
|
+
defineComponent: <T extends EcsType<any>>(componentId: number, spec: T) => ComponentDefinition<T>;
|
|
18
|
+
mutableGroupOf: <T_1 extends [ComponentDefinition<EcsType<any>>, ...ComponentDefinition<EcsType<any>>[]]>(...components: T_1) => Iterable<[Entity, ...ComponentEcsType<T_1>]>;
|
|
19
|
+
groupOf: <T_2 extends [ComponentDefinition<EcsType<any>>, ...ComponentDefinition<EcsType<any>>[]]>(...components: T_2) => Iterable<[Entity, ...DeepReadonly<ComponentEcsType<T_2>>]>;
|
|
20
|
+
getComponent: <T_3 extends EcsType<any>>(componentId: number) => ComponentDefinition<T_3>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* @alpha
|
|
24
|
+
*/
|
|
25
|
+
export declare type PreEngine = ReturnType<typeof preEngine>;
|
|
26
|
+
/**
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare type Engine = {
|
|
30
|
+
addEntity(dynamic?: boolean): Entity;
|
|
31
|
+
addDynamicEntity(): Entity;
|
|
32
|
+
removeEntity(entity: Entity): void;
|
|
33
|
+
addSystem(system: Update): void;
|
|
34
|
+
defineComponent<T extends EcsType>(componentId: number, spec: T): ComponentDefinition<T>;
|
|
35
|
+
mutableGroupOf<T extends [ComponentDefinition, ...ComponentDefinition[]]>(...components: T): Iterable<[Entity, ...ComponentEcsType<T>]>;
|
|
36
|
+
groupOf<T extends [ComponentDefinition, ...ComponentDefinition[]]>(...components: T): Iterable<[Entity, ...DeepReadonly<ComponentEcsType<T>>]>;
|
|
37
|
+
getComponent<T extends EcsType>(componentId: number): ComponentDefinition<T>;
|
|
38
|
+
update(dt: number): void;
|
|
39
|
+
baseComponents: ReturnType<typeof defineSdkComponents>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare function Engine(): Engine;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/engine/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAEnD,OAAO,EAAE,MAAM,EAAmB,MAAM,UAAU,CAAA;AAClD,OAAO,EACL,mBAAmB,EAEpB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAE3C;;GAEG;AACH,iBAAS,SAAS;;;;0BAkBY,OAAO;;2BAUL,MAAM;oBAjBb,MAAM;2DA6Bd,MAAM;;;0DAYN,MAAM;EAiEtB;AAED;;GAEG;AACH,oBAAY,SAAS,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAA;AAGpD;;GAEG;AACH,oBAAY,MAAM,GAAG;IACnB,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACpC,gBAAgB,IAAI,MAAM,CAAA;IAC1B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAClC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,eAAe,CAAC,CAAC,SAAS,OAAO,EAC/B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,CAAC,GACN,mBAAmB,CAAC,CAAC,CAAC,CAAA;IACzB,cAAc,CAAC,CAAC,SAAS,CAAC,mBAAmB,EAAE,GAAG,mBAAmB,EAAE,CAAC,EACtE,GAAG,UAAU,EAAE,CAAC,GACf,QAAQ,CAAC,CAAC,MAAM,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC7C,OAAO,CAAC,CAAC,SAAS,CAAC,mBAAmB,EAAE,GAAG,mBAAmB,EAAE,CAAC,EAC/D,GAAG,UAAU,EAAE,CAAC,GACf,QAAQ,CAAC,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3D,YAAY,CAAC,CAAC,SAAS,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAA;IAC5E,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,cAAc,EAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAA;CACvD,CAAA;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,MAAM,CA0C/B"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Engine = void 0;
|
|
4
|
+
const components_1 = require("../components");
|
|
5
|
+
const crdt_1 = require("../systems/crdt");
|
|
6
|
+
const entity_1 = require("./entity");
|
|
7
|
+
const component_1 = require("./component");
|
|
8
|
+
/**
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
11
|
+
function preEngine() {
|
|
12
|
+
const entityContainer = (0, entity_1.EntityContainer)();
|
|
13
|
+
const componentsDefinition = new Map();
|
|
14
|
+
// TODO: find a way to make this work.
|
|
15
|
+
// Maybe a proxy/callback to be up-to-date
|
|
16
|
+
const entitiesComponent = new Map();
|
|
17
|
+
const systems = new Set();
|
|
18
|
+
function addSystem(fn) {
|
|
19
|
+
if (systems.has(fn)) {
|
|
20
|
+
throw new Error('System already added');
|
|
21
|
+
}
|
|
22
|
+
systems.add(fn);
|
|
23
|
+
}
|
|
24
|
+
function addEntity(dynamic = false) {
|
|
25
|
+
// entitiesCompnonent.set(entity, new Set())
|
|
26
|
+
const entity = entityContainer.generateEntity(dynamic);
|
|
27
|
+
return entity;
|
|
28
|
+
}
|
|
29
|
+
function addDynamicEntity() {
|
|
30
|
+
return addEntity(true);
|
|
31
|
+
}
|
|
32
|
+
function removeEntity(entity) {
|
|
33
|
+
// TODO: Remove all the components of that entity
|
|
34
|
+
for (const [, component] of componentsDefinition) {
|
|
35
|
+
if (component.has(entity)) {
|
|
36
|
+
component.deleteFrom(entity);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// entitiesComponent.delete(entity)
|
|
40
|
+
return entityContainer.removeEntity(entity);
|
|
41
|
+
}
|
|
42
|
+
function defineComponent(componentId, spec) {
|
|
43
|
+
if (componentsDefinition.get(componentId)) {
|
|
44
|
+
throw new Error(`Component ${componentId} already declared`);
|
|
45
|
+
}
|
|
46
|
+
const newComponent = (0, component_1.defineComponent)(componentId, spec);
|
|
47
|
+
componentsDefinition.set(componentId, newComponent);
|
|
48
|
+
return newComponent;
|
|
49
|
+
}
|
|
50
|
+
function getComponent(componentId) {
|
|
51
|
+
const component = componentsDefinition.get(componentId);
|
|
52
|
+
if (!component) {
|
|
53
|
+
throw new Error('Component not found. You need to declare the components at the beginnig of the engine declaration');
|
|
54
|
+
}
|
|
55
|
+
return component;
|
|
56
|
+
}
|
|
57
|
+
function* mutableGroupOf(...components) {
|
|
58
|
+
for (const [entity, ...groupComp] of getComponentDefGroup(...components)) {
|
|
59
|
+
yield [entity, ...groupComp.map((c) => c.mutable(entity))];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function* groupOf(...components) {
|
|
63
|
+
for (const [entity, ...groupComp] of getComponentDefGroup(...components)) {
|
|
64
|
+
yield [entity, ...groupComp.map((c) => c.getFrom(entity))];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function* getComponentDefGroup(...args) {
|
|
68
|
+
const [firstComponentDef, ...componentDefinitions] = args;
|
|
69
|
+
for (const [entity] of firstComponentDef.iterator()) {
|
|
70
|
+
let matches = true;
|
|
71
|
+
for (const componentDef of componentDefinitions) {
|
|
72
|
+
if (!componentDef.has(entity)) {
|
|
73
|
+
matches = false;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (matches) {
|
|
78
|
+
yield [entity, ...args];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
entitiesComponent,
|
|
84
|
+
componentsDefinition,
|
|
85
|
+
systems,
|
|
86
|
+
addEntity,
|
|
87
|
+
addDynamicEntity,
|
|
88
|
+
removeEntity,
|
|
89
|
+
addSystem,
|
|
90
|
+
defineComponent,
|
|
91
|
+
mutableGroupOf,
|
|
92
|
+
groupOf,
|
|
93
|
+
getComponent
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
function Engine() {
|
|
100
|
+
const engine = preEngine();
|
|
101
|
+
const crdtSystem = (0, crdt_1.crdtSceneSystem)(engine);
|
|
102
|
+
const baseComponents = (0, components_1.defineSdkComponents)(engine);
|
|
103
|
+
function update(dt) {
|
|
104
|
+
crdtSystem.processMessages();
|
|
105
|
+
for (const system of engine.systems) {
|
|
106
|
+
system(dt);
|
|
107
|
+
}
|
|
108
|
+
// TODO: Perf tip
|
|
109
|
+
// Should we add some dirtyIteratorSet at engine level so we dont have
|
|
110
|
+
// to iterate all the component definitions to get the dirty ones ?
|
|
111
|
+
const dirtySet = new Map();
|
|
112
|
+
for (const [componentId, definition] of engine.componentsDefinition) {
|
|
113
|
+
for (const entity of definition.dirtyIterator()) {
|
|
114
|
+
if (!dirtySet.has(entity)) {
|
|
115
|
+
dirtySet.set(entity, new Set());
|
|
116
|
+
}
|
|
117
|
+
dirtySet.get(entity).add(componentId);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
crdtSystem.send(dirtySet);
|
|
121
|
+
for (const [_componentId, definition] of engine.componentsDefinition) {
|
|
122
|
+
definition.clearDirty();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
addEntity: engine.addEntity,
|
|
127
|
+
addDynamicEntity: engine.addDynamicEntity,
|
|
128
|
+
removeEntity: engine.removeEntity,
|
|
129
|
+
addSystem: engine.addSystem,
|
|
130
|
+
defineComponent: engine.defineComponent,
|
|
131
|
+
mutableGroupOf: engine.mutableGroupOf,
|
|
132
|
+
groupOf: engine.groupOf,
|
|
133
|
+
getComponent: engine.getComponent,
|
|
134
|
+
update,
|
|
135
|
+
baseComponents
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
exports.Engine = Engine;
|
|
139
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/engine/index.ts"],"names":[],"mappings":";;;AAAA,8CAAmD;AACnD,0CAAiD;AACjD,qCAAkD;AAClD,2CAGoB;AAIpB;;GAEG;AACH,SAAS,SAAS;IAChB,MAAM,eAAe,GAAG,IAAA,wBAAe,GAAE,CAAA;IACzC,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAoC,CAAA;IACxE,sCAAsC;IACtC,0CAA0C;IAC1C,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAG9B,CAAA;IACH,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;IAEjC,SAAS,SAAS,CAAC,EAAU;QAC3B,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE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C,eAAe;QACvC,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,MAAM;QACN,cAAc;KACf,CAAA;AACH,CAAC;AA1CD,wBA0CC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ComponentDefinition as CompDef } from './component';
|
|
2
|
+
export declare type Unpacked<T> = T extends (infer U)[] ? U : T;
|
|
3
|
+
export declare type Update = (dt: number) => void;
|
|
4
|
+
export declare type ComponentEcsType<T extends [CompDef, ...CompDef[]]> = {
|
|
5
|
+
[K in keyof T]: T[K] extends CompDef ? ReturnType<T[K]['mutable']> : never;
|
|
6
|
+
};
|
|
7
|
+
export declare type DeepReadonly<T> = {
|
|
8
|
+
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/engine/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,IAAI,OAAO,EAAE,MAAM,aAAa,CAAA;AAE5D,oBAAY,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;AACvD,oBAAY,MAAM,GAAG,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;AAEzC,oBAAY,gBAAgB,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC,IAAI;KAC/D,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,KAAK;CAC3E,CAAA;AAED,oBAAY,YAAY,CAAC,CAAC,IAAI;IAC5B,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC5C,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/engine/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/engine/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAItC,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5D,GAAG,EAAE,CAAC,GACL,YAAY,CAAC,CAAC,CAAC,CAMjB;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,GAAG,GAAG,IAAI,CAAC,CAE9D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNotUndefined = exports.deepReadonly = void 0;
|
|
4
|
+
const isProd = () => !!process.env.PRODUCTION || false;
|
|
5
|
+
function deepReadonly(val) {
|
|
6
|
+
// Fail only on development due to perf issues
|
|
7
|
+
if (isProd()) {
|
|
8
|
+
return val;
|
|
9
|
+
}
|
|
10
|
+
return Object.freeze({ ...val });
|
|
11
|
+
}
|
|
12
|
+
exports.deepReadonly = deepReadonly;
|
|
13
|
+
function isNotUndefined(val) {
|
|
14
|
+
return !!val;
|
|
15
|
+
}
|
|
16
|
+
exports.isNotUndefined = isNotUndefined;
|
|
17
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/engine/utils.ts"],"names":[],"mappings":";;;AAEA,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,KAAK,CAAA;AAEtD,SAAgB,YAAY,CAC1B,GAAM;IAEN,8CAA8C;IAC9C,IAAI,MAAM,EAAE,EAAE;QACZ,OAAO,GAAG,CAAA;KACX;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,CAAA;AAClC,CAAC;AARD,oCAQC;AAED,SAAgB,cAAc,CAAI,GAAkB;IAClD,OAAO,CAAC,CAAC,GAAG,CAAA;AACd,CAAC;AAFD,wCAEC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./engine"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param writing - writing option, see object specs.
|
|
3
|
+
* @param reading - reading option, see object specs.
|
|
4
|
+
* @param initialCapacity - Initial capacity of buffer to allocate, ignored if you use writing or reading options
|
|
5
|
+
*/
|
|
6
|
+
export interface CreateByteBufferOptions {
|
|
7
|
+
/**
|
|
8
|
+
* @param buffer - a buffer already allocated to read from there.
|
|
9
|
+
* @param currentOffset - set the cursor where begins to read. Default 0
|
|
10
|
+
* @param length - delimite where the valid data ends. Default: buffer.length
|
|
11
|
+
*/
|
|
12
|
+
reading?: {
|
|
13
|
+
buffer: Uint8Array;
|
|
14
|
+
length?: number;
|
|
15
|
+
currentOffset: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @param buffer - a buffer already allocated to write there.
|
|
19
|
+
* @param currentOffset - set the cursor to not start writing from the begin of it. Default 0
|
|
20
|
+
*/
|
|
21
|
+
writing?: {
|
|
22
|
+
buffer: Uint8Array;
|
|
23
|
+
currentOffset?: number;
|
|
24
|
+
};
|
|
25
|
+
initialCapacity?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* ByteBuffer is a wrapper of DataView which also adds a read and write offset.
|
|
29
|
+
* Also in a write operation it resizes the buffer is being used if it needs.
|
|
30
|
+
*
|
|
31
|
+
* - Use read and write function to generate or consume data.
|
|
32
|
+
* - Use set and get only if you are sure that you're doing.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createByteBuffer(options?: CreateByteBufferOptions): {
|
|
35
|
+
/**
|
|
36
|
+
* @returns The entire current Uint8Array.
|
|
37
|
+
*
|
|
38
|
+
* WARNING: if the buffer grows, the view had changed itself,
|
|
39
|
+
* and the reference will be a invalid one.
|
|
40
|
+
*/
|
|
41
|
+
buffer(): Uint8Array;
|
|
42
|
+
/**
|
|
43
|
+
* @returns The capacity of the current buffer
|
|
44
|
+
*/
|
|
45
|
+
bufferLength(): number;
|
|
46
|
+
/**
|
|
47
|
+
* Reading purpose
|
|
48
|
+
* Returns the previuos offsset size before incrementing
|
|
49
|
+
*/
|
|
50
|
+
incrementReadOffset(amount: number): number;
|
|
51
|
+
/**
|
|
52
|
+
* @returns The current read offset.
|
|
53
|
+
*/
|
|
54
|
+
currentReadOffset(): number;
|
|
55
|
+
/**
|
|
56
|
+
* @returns How many bytes are available to read.
|
|
57
|
+
*/
|
|
58
|
+
remainingBytes(): number;
|
|
59
|
+
readFloat32(): number;
|
|
60
|
+
readFloat64(): number;
|
|
61
|
+
readInt8(): number;
|
|
62
|
+
readInt16(): number;
|
|
63
|
+
readInt32(): number;
|
|
64
|
+
readInt64(): bigint;
|
|
65
|
+
readUint8(): number;
|
|
66
|
+
readUint16(): number;
|
|
67
|
+
readUint32(): number;
|
|
68
|
+
readUint64(): bigint;
|
|
69
|
+
readBuffer(): Uint8Array;
|
|
70
|
+
/**
|
|
71
|
+
* Writing purpose
|
|
72
|
+
*/
|
|
73
|
+
/**
|
|
74
|
+
* Increment offset
|
|
75
|
+
* @param amount - how many bytes
|
|
76
|
+
* @returns The offset when this reserving starts.
|
|
77
|
+
*/
|
|
78
|
+
incrementWriteOffset(amount: number): number;
|
|
79
|
+
/**
|
|
80
|
+
* @returns The total number of bytes writen in the buffer.
|
|
81
|
+
*/
|
|
82
|
+
size(): number;
|
|
83
|
+
/**
|
|
84
|
+
* @returns The subarray from 0 to offset.
|
|
85
|
+
*/
|
|
86
|
+
toBinary(): Uint8Array;
|
|
87
|
+
writeBuffer(value: Uint8Array, writeLength?: boolean): void;
|
|
88
|
+
writeFloat32(value: number): void;
|
|
89
|
+
writeFloat64(value: number): void;
|
|
90
|
+
writeInt8(value: number): void;
|
|
91
|
+
writeInt16(value: number): void;
|
|
92
|
+
writeInt32(value: number): void;
|
|
93
|
+
writeInt64(value: bigint): void;
|
|
94
|
+
writeUint8(value: number): void;
|
|
95
|
+
writeUint16(value: number): void;
|
|
96
|
+
writeUint32(value: number): void;
|
|
97
|
+
writeUint64(value: bigint): void;
|
|
98
|
+
getFloat32(offset: number): number;
|
|
99
|
+
getFloat64(offset: number): number;
|
|
100
|
+
getInt8(offset: number): number;
|
|
101
|
+
getInt16(offset: number): number;
|
|
102
|
+
getInt32(offset: number): number;
|
|
103
|
+
getInt64(offset: number): bigint;
|
|
104
|
+
getUint8(offset: number): number;
|
|
105
|
+
getUint16(offset: number): number;
|
|
106
|
+
getUint32(offset: number): number;
|
|
107
|
+
getUint64(offset: number): bigint;
|
|
108
|
+
setFloat32(offset: number, value: number): void;
|
|
109
|
+
setFloat64(offset: number, value: number): void;
|
|
110
|
+
setInt8(offset: number, value: number): void;
|
|
111
|
+
setInt16(offset: number, value: number): void;
|
|
112
|
+
setInt32(offset: number, value: number): void;
|
|
113
|
+
setInt64(offset: number, value: bigint): void;
|
|
114
|
+
setUint8(offset: number, value: number): void;
|
|
115
|
+
setUint16(offset: number, value: number): void;
|
|
116
|
+
setUint32(offset: number, value: number): void;
|
|
117
|
+
setUint64(offset: number, value: bigint): void;
|
|
118
|
+
};
|
|
119
|
+
export declare type ByteBuffer = ReturnType<typeof createByteBuffer>;
|
|
120
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/serialization/ByteBuffer/index.ts"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,OAAO,CAAC,EAAE;QACR,MAAM,EAAE,UAAU,CAAA;QAClB,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,aAAa,EAAE,MAAM,CAAA;KACtB,CAAA;IAED;;;OAGG;IACH,OAAO,CAAC,EAAE;QACR,MAAM,EAAE,UAAU,CAAA;QAClB,aAAa,CAAC,EAAE,MAAM,CAAA;KACvB,CAAA;IAED,eAAe,CAAC,EA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