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

Method createProxyView

packages/core/src/ECS/Core/SoAStorage.ts:396–530  ·  view source on GitHub ↗

* 创建组件的 Proxy 视图 * 读写操作直接映射到底层 TypedArray,无数据复制

(entityId: number, index: number)

Source from the content-addressed store, hash-verified

394 * 读写操作直接映射到底层 TypedArray,无数据复制
395 */
396 private createProxyView(entityId: number, index: number): T {
397 // eslint-disable-next-line @typescript-eslint/no-this-alias
398 const self = this;
399
400 // Proxy handler 类型定义
401 const handler: ProxyHandler<Record<string, unknown>> = {
402 get(_, prop: string | symbol) {
403 const propStr = String(prop);
404
405 // TypedArray 字段
406 const array = self.fields.get(propStr);
407 if (array) {
408 const fieldType = self.getFieldType(propStr);
409 if (fieldType === 'boolean') {
410 return array[index] === 1;
411 }
412 return array[index];
413 }
414
415 // 字符串字段
416 const stringArray = self.stringFields.get(propStr);
417 if (stringArray) {
418 return stringArray[index];
419 }
420
421 // 序列化字段
422 const serializedArray = self.serializedFields.get(propStr);
423 if (serializedArray) {
424 const serialized = serializedArray[index];
425 if (serialized) {
426 return SoASerializer.deserialize(serialized, propStr, {
427 isMap: self.serializeMapFields.has(propStr),
428 isSet: self.serializeSetFields.has(propStr),
429 isArray: self.serializeArrayFields.has(propStr)
430 });
431 }
432 return undefined;
433 }
434
435 // 复杂字段
436 const complexFieldMap = self.complexFields.get(entityId);
437 if (complexFieldMap?.has(propStr)) {
438 return complexFieldMap.get(propStr);
439 }
440
441 return undefined;
442 },
443
444 set(_, prop: string | symbol, value) {
445 const propStr = String(prop);
446
447 // entityId 是只读的
448 if (propStr === 'entityId') {
449 return false;
450 }
451
452 // TypedArray 字段
453 const array = self.fields.get(propStr);

Callers 1

getComponentMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected