MCPcopy Create free account
hub / github.com/esengine/esengine / shouldCleanupWorld

Method shouldCleanupWorld

packages/core/src/ECS/WorldManager.ts:398–414  ·  view source on GitHub ↗

* 判断World是否应该被清理 * 清理策略: * 1. World未激活 * 2. 没有Scene或所有Scene都是空的 * 3. 创建时间超过10分钟

(world: World)

Source from the content-addressed store, hash-verified

396 * 3. 创建时间超过10分钟
397 */
398 private shouldCleanupWorld(world: World): boolean {
399 if (world.isActive) {
400 return false;
401 }
402
403 const age = Date.now() - world.createdAt;
404 const isOldEnough = age > 10 * 60 * 1000; // 10分钟
405
406 if (world.sceneCount === 0) {
407 return isOldEnough;
408 }
409
410 // 检查是否所有Scene都是空的
411 const allScenes = world.getAllScenes();
412 const hasEntities = allScenes.some((scene) => scene.entities && scene.entities.count > 0);
413 return !hasEntities && isOldEnough;
414 }
415
416 /**
417 * 获取World总数

Callers 1

cleanupMethod · 0.95

Calls 3

nowMethod · 0.80
getAllScenesMethod · 0.45
someMethod · 0.45

Tested by

no test coverage detected