duu
This commit is contained in:
parent
88f618cadf
commit
8f9f5b5100
108 changed files with 2139 additions and 1500 deletions
|
|
@ -29,7 +29,7 @@
|
|||
this.terrainDirtyStatsThisFrame = { raw: 0, global: 0, chunk: 0, coalesced: 0, reasons: {} };
|
||||
this.nearbyQueryStatsThisFrame = { obstacleRectHits: 0, obstacleRectMisses: 0, obstacleRectBypass: 0, obstacleRectBuilt: 0 };
|
||||
this.constraintDirtyStatsThisFrame = { marked: 0, coalesced: 0 };
|
||||
this._solidObstacleRectQueryCache = new Map();
|
||||
if (!this._solidObstacleRectQueryCache) this._solidObstacleRectQueryCache = new Map();
|
||||
},
|
||||
|
||||
spendScheduledWork(kind = "ai", urgent = false) {
|
||||
|
|
@ -98,6 +98,7 @@
|
|||
bucketTypes: this.itemTypeBuckets?.size || 0,
|
||||
bucketsDirty: Boolean(this.itemBucketsDirty),
|
||||
idMapSize: this.itemIdMap?.size || 0,
|
||||
ownerBuckets: this.itemOwnerBuckets?.size || 0,
|
||||
bucketRebuildsTotal: this.itemBucketRebuildsTotal || 0,
|
||||
},
|
||||
behavior: {
|
||||
|
|
@ -278,7 +279,7 @@
|
|||
},
|
||||
|
||||
ensureItemBuckets(reason = "read") {
|
||||
if (!this.itemTypeBuckets || !this.itemIdMap || this.itemBucketsDirty) {
|
||||
if (!this.itemTypeBuckets || !this.itemIdMap || !this.itemOwnerBuckets || this.itemBucketsDirty) {
|
||||
this.updateItemCounts(reason);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -312,17 +313,33 @@
|
|||
const bucket = this.itemTypeBuckets?.get?.(type);
|
||||
return bucket || [];
|
||||
},
|
||||
|
||||
ownedItemsFor(ownerId) {
|
||||
if (ownerId == null || ownerId === "") return [];
|
||||
this.ensureItemBuckets?.(`owned-items:${ownerId}`);
|
||||
return this.itemOwnerBuckets?.get?.(ownerId) || [];
|
||||
},
|
||||
updateItemCounts(reason = "manual") {
|
||||
const counts = this.itemCounts;
|
||||
if (!this.itemTypeBuckets) this.itemTypeBuckets = new Map();
|
||||
if (!this.itemIdMap) this.itemIdMap = new Map();
|
||||
if (!this.itemOwnerBuckets) this.itemOwnerBuckets = new Map();
|
||||
for (const key of Object.keys(counts)) counts[key] = 0;
|
||||
this.itemTypeBuckets.clear();
|
||||
this.itemIdMap.clear();
|
||||
this.itemOwnerBuckets.clear();
|
||||
for (const it of this.items) {
|
||||
if (!it || it.dead) continue;
|
||||
counts[it.type] = (counts[it.type] || 0) + 1;
|
||||
if (it.id != null) this.itemIdMap.set(it.id, it);
|
||||
if (it.ownerId) {
|
||||
let ownerBucket = this.itemOwnerBuckets.get(it.ownerId);
|
||||
if (!ownerBucket) {
|
||||
ownerBucket = [];
|
||||
this.itemOwnerBuckets.set(it.ownerId, ownerBucket);
|
||||
}
|
||||
ownerBucket.push(it);
|
||||
}
|
||||
let bucket = this.itemTypeBuckets.get(it.type);
|
||||
if (!bucket) {
|
||||
bucket = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue