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

Method checkIn

packages/core/src/ECS/Utils/IdentifierPool.ts:147–176  ·  view source on GitHub ↗

* 回收一个ID * * 验证ID的有效性后,将其加入延迟回收队列。 * ID不会立即可重用,而是在延迟时间后才真正回收。 * * @param id 要回收的实体ID * @returns 是否成功回收(ID是否有效且未被重复回收)

(id: number)

Source from the content-addressed store, hash-verified

145 * @returns 是否成功回收(ID是否有效且未被重复回收)
146 */
147 public checkIn(id: number): boolean {
148 const index = this._unpackIndex(id);
149 const generation = this._unpackGeneration(id);
150
151 // 验证ID有效性
152 if (!this._isValidId(index, generation)) {
153 return false;
154 }
155
156 // 检查是否已经在待回收队列中
157 const alreadyPending = this._pendingRecycle.some(
158 (item) => item.index === index && item.generation === generation
159 );
160
161 if (alreadyPending) {
162 return false; // 已经在回收队列中,拒绝重复回收
163 }
164
165 // 加入延迟回收队列
166 this._pendingRecycle.push({
167 index,
168 generation,
169 timestamp: Date.now()
170 });
171
172 this._stats.currentActive--;
173 this._stats.totalRecycled++;
174
175 return true;
176 }
177
178 /**
179 * 验证ID是否有效

Callers 3

removeImmediateMethod · 0.45
removeAllEntitiesMethod · 0.45

Calls 6

_unpackIndexMethod · 0.95
_unpackGenerationMethod · 0.95
_isValidIdMethod · 0.95
nowMethod · 0.80
pushMethod · 0.65
someMethod · 0.45

Tested by

no test coverage detected