@codehz/ecs 0.3.1 → 0.3.3
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/command-buffer.d.ts +2 -2
- package/index.js +21 -12
- package/package.json +1 -1
- package/query.d.ts +4 -0
- package/world.d.ts +0 -1
package/command-buffer.d.ts
CHANGED
|
@@ -26,11 +26,11 @@ export declare class CommandBuffer {
|
|
|
26
26
|
/**
|
|
27
27
|
* Remove a component from an entity (deferred)
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
remove<T>(entityId: EntityId, componentType: EntityId<T>): void;
|
|
30
30
|
/**
|
|
31
31
|
* Destroy an entity (deferred)
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
delete(entityId: EntityId): void;
|
|
34
34
|
/**
|
|
35
35
|
* Execute all commands and clear the buffer
|
|
36
36
|
*/
|
package/index.js
CHANGED
|
@@ -558,10 +558,10 @@ class CommandBuffer {
|
|
|
558
558
|
set(entityId, componentType, component2) {
|
|
559
559
|
this.commands.push({ type: "set", entityId, componentType, component: component2 });
|
|
560
560
|
}
|
|
561
|
-
|
|
561
|
+
remove(entityId, componentType) {
|
|
562
562
|
this.commands.push({ type: "delete", entityId, componentType });
|
|
563
563
|
}
|
|
564
|
-
|
|
564
|
+
delete(entityId) {
|
|
565
565
|
this.commands.push({ type: "destroy", entityId });
|
|
566
566
|
}
|
|
567
567
|
execute() {
|
|
@@ -698,6 +698,14 @@ class Query {
|
|
|
698
698
|
this.cachedArchetypes.push(archetype);
|
|
699
699
|
}
|
|
700
700
|
}
|
|
701
|
+
removeArchetype(archetype) {
|
|
702
|
+
if (this.isDisposed)
|
|
703
|
+
return;
|
|
704
|
+
const index = this.cachedArchetypes.indexOf(archetype);
|
|
705
|
+
if (index !== -1) {
|
|
706
|
+
this.cachedArchetypes.splice(index, 1);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
701
709
|
dispose() {
|
|
702
710
|
this.world.releaseQuery(this);
|
|
703
711
|
}
|
|
@@ -801,11 +809,6 @@ class World {
|
|
|
801
809
|
if (snapshot.entityManager) {
|
|
802
810
|
this.entityIdManager.deserializeState(snapshot.entityManager);
|
|
803
811
|
}
|
|
804
|
-
if (Array.isArray(snapshot.exclusiveComponents)) {
|
|
805
|
-
for (const id of snapshot.exclusiveComponents) {
|
|
806
|
-
this.exclusiveComponents.add(id);
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
812
|
if (Array.isArray(snapshot.entities)) {
|
|
810
813
|
for (const entry of snapshot.entities) {
|
|
811
814
|
const entityId = entry.id;
|
|
@@ -929,10 +932,10 @@ class World {
|
|
|
929
932
|
if (detailedType.type === "invalid") {
|
|
930
933
|
throw new Error(`Invalid component type: ${componentType}`);
|
|
931
934
|
}
|
|
932
|
-
this.commandBuffer.
|
|
935
|
+
this.commandBuffer.remove(entityId, componentType);
|
|
933
936
|
}
|
|
934
937
|
delete(entityId) {
|
|
935
|
-
this.commandBuffer.
|
|
938
|
+
this.commandBuffer.delete(entityId);
|
|
936
939
|
}
|
|
937
940
|
has(entityId, componentType) {
|
|
938
941
|
const archetype = this.entityToArchetype.get(entityId);
|
|
@@ -1075,8 +1078,12 @@ class World {
|
|
|
1075
1078
|
matchingArchetypes = [...this.archetypes];
|
|
1076
1079
|
}
|
|
1077
1080
|
for (const wildcard of wildcardRelations) {
|
|
1078
|
-
|
|
1079
|
-
|
|
1081
|
+
matchingArchetypes = matchingArchetypes.filter((archetype) => archetype.componentTypes.some((archetypeType) => {
|
|
1082
|
+
if (!isRelationId(archetypeType))
|
|
1083
|
+
return false;
|
|
1084
|
+
const decoded = decodeRelationId(archetypeType);
|
|
1085
|
+
return decoded.componentId === wildcard.componentId;
|
|
1086
|
+
}));
|
|
1080
1087
|
}
|
|
1081
1088
|
return matchingArchetypes;
|
|
1082
1089
|
}
|
|
@@ -1242,6 +1249,9 @@ class World {
|
|
|
1242
1249
|
}
|
|
1243
1250
|
}
|
|
1244
1251
|
}
|
|
1252
|
+
for (const query of this.queries) {
|
|
1253
|
+
query.removeArchetype(archetype);
|
|
1254
|
+
}
|
|
1245
1255
|
}
|
|
1246
1256
|
triggerLifecycleHooks(entityId, addedComponents, removedComponents) {
|
|
1247
1257
|
for (const [componentType, component2] of addedComponents) {
|
|
@@ -1320,7 +1330,6 @@ class World {
|
|
|
1320
1330
|
return {
|
|
1321
1331
|
version: 1,
|
|
1322
1332
|
entityManager: this.entityIdManager.serializeState(),
|
|
1323
|
-
exclusiveComponents: Array.from(this.exclusiveComponents),
|
|
1324
1333
|
entities
|
|
1325
1334
|
};
|
|
1326
1335
|
}
|
package/package.json
CHANGED
package/query.d.ts
CHANGED
|
@@ -47,6 +47,10 @@ export declare class Query {
|
|
|
47
47
|
* Check if a new archetype matches this query and add to cache if it does
|
|
48
48
|
*/
|
|
49
49
|
checkNewArchetype(archetype: Archetype): void;
|
|
50
|
+
/**
|
|
51
|
+
* Remove an archetype from the cached archetypes
|
|
52
|
+
*/
|
|
53
|
+
removeArchetype(archetype: Archetype): void;
|
|
50
54
|
/**
|
|
51
55
|
* Dispose the query and disconnect from world
|
|
52
56
|
*/
|
package/world.d.ts
CHANGED
|
@@ -197,7 +197,6 @@ export declare class World<UpdateParams extends any[] = []> {
|
|
|
197
197
|
export type SerializedWorld = {
|
|
198
198
|
version: number;
|
|
199
199
|
entityManager: any;
|
|
200
|
-
exclusiveComponents: EntityId[];
|
|
201
200
|
entities: SerializedEntity[];
|
|
202
201
|
};
|
|
203
202
|
export type SerializedEntity = {
|