mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-09 16:21:51 +00:00
Use Set for entities access during belt recompute
Create a method to return all entities with the specified component as a set (without array indirection), and use the method for belt recomputations.
This commit is contained in:
parent
9cbb797ef6
commit
69fb06e817
@ -149,12 +149,19 @@ export class EntityManager extends BasicSerializableObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all entities having the given component
|
* Returns all entities having the given component
|
||||||
|
* @deprecated use {@link getEntitiesWithComponent} instead
|
||||||
*/
|
*/
|
||||||
getAllWithComponent(componentHandle: typeof Component): Entity[] {
|
getAllWithComponent(componentHandle: typeof Component): Entity[] {
|
||||||
// TODO: Convert usages to set as well
|
|
||||||
return [...(this.componentToEntity[componentHandle.getId()] ?? new Set())];
|
return [...(this.componentToEntity[componentHandle.getId()] ?? new Set())];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A version of {@link getAllWithComponent} that returns a Set
|
||||||
|
*/
|
||||||
|
getEntitiesWithComponent(componentHandle: typeof Component): Set<Entity> {
|
||||||
|
return new Set(this.componentToEntity[componentHandle.getId()] ?? []);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters all components of an entity from the component to entity mapping
|
* Unregisters all components of an entity from the component to entity mapping
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -7,12 +7,11 @@ import { AtlasSprite } from "../../core/sprites";
|
|||||||
import { fastArrayDeleteValue } from "../../core/utils";
|
import { fastArrayDeleteValue } from "../../core/utils";
|
||||||
import { enumDirection, enumDirectionToVector, enumInvertedDirections, Vector } from "../../core/vector";
|
import { enumDirection, enumDirectionToVector, enumInvertedDirections, Vector } from "../../core/vector";
|
||||||
import { BeltPath } from "../belt_path";
|
import { BeltPath } from "../belt_path";
|
||||||
import { arrayBeltVariantToRotation, MetaBeltBuilding } from "../buildings/belt";
|
|
||||||
import { getCodeFromBuildingData } from "../building_codes";
|
import { getCodeFromBuildingData } from "../building_codes";
|
||||||
|
import { arrayBeltVariantToRotation, MetaBeltBuilding } from "../buildings/belt";
|
||||||
import { BeltComponent } from "../components/belt";
|
import { BeltComponent } from "../components/belt";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
import { GameSystem } from "../game_system";
|
import { GameSystem } from "../game_system";
|
||||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
|
||||||
import { MapChunkView } from "../map_chunk_view";
|
import { MapChunkView } from "../map_chunk_view";
|
||||||
import { defaultBuildingVariant } from "../meta_building";
|
import { defaultBuildingVariant } from "../meta_building";
|
||||||
|
|
||||||
@ -424,10 +423,9 @@ export class BeltSystem extends GameSystem {
|
|||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
|
|
||||||
const beltEntities = this.root.entityMgr.getAllWithComponent(BeltComponent);
|
const beltEntities = this.root.entityMgr.getEntitiesWithComponent(BeltComponent);
|
||||||
|
|
||||||
for (let i = 0; i < beltEntities.length; ++i) {
|
for (const entity of beltEntities) {
|
||||||
const entity = beltEntities[i];
|
|
||||||
if (visitedUids.has(entity.uid)) {
|
if (visitedUids.has(entity.uid)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user