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AO,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,GAAG,CAAA;gBAC7B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;gBAC1B,IAAI,CAAC,KAAK,EAAE,CAAA;aACf;SACJ;QACD,4BAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;QACjC,OAAO,GAAG,EAAE,CAAA;QACZ,SAAS,GAAG,EAAE,CAAA;QACd,EAAE,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;IAC5B,CAAC;IAbe,wBAAQ,WAavB,CAAA;AACL,CAAC,EA9HgB,eAAe,GAAf,uBAAe,KAAf,uBAAe,QA8H/B","file":"","sourceRoot":"/","sourcesContent":["import { ResUtils } from \"simba-cc-resutils\";\nimport { delay } from \"simba-utils\";\n\nexport namespace NodePoolFactory {\n let arrPool: { [key: string]: cc.NodePool } = {};\n let arrPrefab: { [key: string]: cc.Prefab } = {};\n let creationTasks: { path: string, count: number, callback: () => void, poolHanderComp?: { prototype: cc.Component } | string }[] = [];\n\n let processingTasks = false;\n async function handleTasks() {\n processingTasks = true;\n while (creationTasks.length) {\n let task = creationTasks.shift()!;\n let prefab = await ResUtils.loadRes<cc.Prefab>(task.path, cc.Prefab);\n if (prefab) {\n let pool = new cc.NodePool(task.poolHanderComp);\n for (let i = 0; i < task.count; i++) {\n let node = cc.instantiate(prefab);\n (node as any)._path = task.path;\n pool.put(node);\n if ((i + 1) % 5 == 0) await delay(0.01);\n }\n arrPrefab[task.path] = prefab;\n arrPool[task.path] = pool;\n } else {\n cc.error(\"prefab path not find: \", task.path);\n }\n task.callback();\n await delay(0.01);\n }\n processingTasks = false;\n }\n\n export async function createPool(path: string, count: number = 1, poolHandlerComp?: { prototype: cc.Component } | string) {\n return new Promise((resolve) => {\n if (arrPool[path]) {\n resolve();\n return;\n }\n creationTasks.push({\n path,\n count,\n poolHanderComp: poolHandlerComp,\n callback: () => resolve()\n });\n if (!processingTasks) {\n handleTasks();\n }\n });\n }\n\n /**\n * 获取对象池\n * @param path 对象池名称\n */\n export function getPool(path: string): cc.NodePool {\n return arrPool[path];\n }\n\n /**\n * 清空对象池\n * @param path 对象池名称\n */\n export function clearPool(...path: string[]) {\n if (path == null || path.length <= 0) return\n for (let i = 0; i < path.length; i++) {\n let one = path[i];\n if (arrPool[one]) {\n arrPool[one].clear()\n delete arrPool[one];\n }\n\n }\n ResUtils.releaseResArray(path);\n cc.sys.garbageCollect();\n }\n\n /**\n * 从对象池中取出一个node对象\n * @param path \n */\n export function getNode(path: string) {\n // cc.log(\"getNode:\",path)\n if (arrPool[path]) {\n if (arrPool[path].size() > 0) {\n return arrPool[path].get()\n } else {\n let node = cc.instantiate(arrPrefab[path]);\n (node as any)._path = path;\n return node;\n }\n } else {\n console.error(\"pool not find:\", path)\n return null\n }\n }\n\n /**\n * 把对象放回对象池\n * @param path \n * @param obj \n */\n export function putNode(obj: cc.Node) {\n let path = (obj as any)._path;\n if (arrPool[path]) {\n arrPool[path].put(obj)\n } else {\n obj.removeFromParent(true);\n console.error(\"pool not find:\", path)\n }\n }\n\n /**\n * 清空所有对象池\n */\n export function clearAll() {\n let pathArr: string[] = []\n for (const key in arrPool) {\n if (arrPool.hasOwnProperty(key)) {\n pathArr[pathArr.length] = key\n const pool = arrPool[key];\n pool.clear()\n }\n }\n ResUtils.releaseResArray(pathArr)\n arrPool = {}\n arrPrefab = {}\n cc.sys.garbageCollect();\n }\n}"]}