* 判断World是否应该被清理 * 清理策略: * 1. World未激活 * 2. 没有Scene或所有Scene都是空的 * 3. 创建时间超过10分钟
(world: World)
| 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总数 |
no test coverage detected