@codehz/ecs 0.3.1 → 0.3.2
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 +15 -4
- package/package.json +1 -1
- package/query.d.ts +4 -0
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
|
}
|
|
@@ -929,10 +937,10 @@ class World {
|
|
|
929
937
|
if (detailedType.type === "invalid") {
|
|
930
938
|
throw new Error(`Invalid component type: ${componentType}`);
|
|
931
939
|
}
|
|
932
|
-
this.commandBuffer.
|
|
940
|
+
this.commandBuffer.remove(entityId, componentType);
|
|
933
941
|
}
|
|
934
942
|
delete(entityId) {
|
|
935
|
-
this.commandBuffer.
|
|
943
|
+
this.commandBuffer.delete(entityId);
|
|
936
944
|
}
|
|
937
945
|
has(entityId, componentType) {
|
|
938
946
|
const archetype = this.entityToArchetype.get(entityId);
|
|
@@ -1242,6 +1250,9 @@ class World {
|
|
|
1242
1250
|
}
|
|
1243
1251
|
}
|
|
1244
1252
|
}
|
|
1253
|
+
for (const query of this.queries) {
|
|
1254
|
+
query.removeArchetype(archetype);
|
|
1255
|
+
}
|
|
1245
1256
|
}
|
|
1246
1257
|
triggerLifecycleHooks(entityId, addedComponents, removedComponents) {
|
|
1247
1258
|
for (const [componentType, component2] of addedComponents) {
|
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
|
*/
|