This commit is contained in:
33333-33333 2026-07-01 14:41:05 +09:00
commit 4d3fc2cd47
84 changed files with 3429 additions and 3480 deletions

View file

@ -13,29 +13,30 @@
return global.TarinaiItemRuntime.updateScheduled(worldRef, dt);
}
function trackSpatialEntityMoved(entity, thresholdSq) {
if (!entity || entity.dead) return false;
const x = Number.isFinite(entity.x) ? entity.x : 0;
const y = Number.isFinite(entity.y) ? entity.y : 0;
const oldX = entity._spatialTrackX;
const oldY = entity._spatialTrackY;
if (!Number.isFinite(oldX) || !Number.isFinite(oldY)) {
entity._spatialTrackX = x;
entity._spatialTrackY = y;
return true;
}
const dx = x - oldX;
const dy = y - oldY;
if (dx * dx + dy * dy <= thresholdSq) return false;
entity._spatialTrackX = x;
entity._spatialTrackY = y;
return true;
}
function markSpatialDirtyIfMoved(worldRef, list, reason = "moved", threshold = 0.35) {
if (!worldRef || !Array.isArray(list) || !list.length) return false;
const thresholdSq = threshold * threshold;
let moved = false;
for (const entity of list) {
if (!entity || entity.dead) continue;
const x = Number.isFinite(entity.x) ? entity.x : 0;
const y = Number.isFinite(entity.y) ? entity.y : 0;
const oldX = entity._spatialTrackX;
const oldY = entity._spatialTrackY;
if (!Number.isFinite(oldX) || !Number.isFinite(oldY)) {
entity._spatialTrackX = x;
entity._spatialTrackY = y;
moved = true;
continue;
}
const dx = x - oldX;
const dy = y - oldY;
if (dx * dx + dy * dy <= thresholdSq) continue;
entity._spatialTrackX = x;
entity._spatialTrackY = y;
moved = true;
}
for (const entity of list) moved = trackSpatialEntityMoved(entity, thresholdSq) || moved;
if (moved) worldRef.markSpatialDirty?.(reason);
return moved;
}
@ -46,29 +47,9 @@
let moved = false;
const tracked = global.TarinaiItemRuntime.trackedDynamicItems(worldRef);
const source = tracked && tracked.length ? tracked : null;
const visit = (entity) => {
const x = Number.isFinite(entity.x) ? entity.x : 0;
const y = Number.isFinite(entity.y) ? entity.y : 0;
const oldX = entity._spatialTrackX;
const oldY = entity._spatialTrackY;
if (!Number.isFinite(oldX) || !Number.isFinite(oldY)) {
entity._spatialTrackX = x;
entity._spatialTrackY = y;
moved = true;
return;
}
const dx = x - oldX;
const dy = y - oldY;
if (dx * dx + dy * dy <= thresholdSq) return;
entity._spatialTrackX = x;
entity._spatialTrackY = y;
moved = true;
};
if (source) {
for (const entity of source) if (entity && !entity.dead) visit(entity);
} else {
forScheduledItems(worldRef, visit);
}
const visit = (entity) => { moved = trackSpatialEntityMoved(entity, thresholdSq) || moved; };
if (source) for (const entity of source) visit(entity);
else forScheduledItems(worldRef, visit);
if (moved) worldRef.markSpatialDirty?.(reason);
return moved;
}
@ -90,6 +71,7 @@
updateItemsScheduled,
markSpatialDirtyIfMoved,
markScheduledItemsMoved,
trackSpatialEntityMoved,
updateVisibleWorldRect,
pointInRect,
});