Skip to content

Commit

Permalink
refactor: remove circular dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki Shimada committed Sep 15, 2024
1 parent afbfa1f commit 46294fa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
27 changes: 12 additions & 15 deletions src/foundation/core/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import { BufferUseEnum } from '../definitions/BufferUse';
import { ComponentTypeEnum } from '../../foundation/definitions/ComponentType';
import { CompositionTypeEnum } from '../../foundation/definitions/CompositionType';
import { ProcessStage, ProcessStageEnum } from '../definitions/ProcessStage';
import { ProcessApproachEnum } from '../definitions/ProcessApproach';
import { ComponentRepository } from './ComponentRepository';
import { Config } from './Config';
import { WebGLStrategy } from '../../webgl/WebGLStrategy';
import { RenderPass } from '../renderer/RenderPass';
import { RnObject } from './RnObject';
import { EntityUID, ComponentSID, TypedArray, Count, Byte } from '../../types/CommonTypes';
Expand All @@ -32,7 +30,6 @@ type MemberInfo = {
*/
export class Component extends RnObject {
private _component_sid: number;
static readonly invalidComponentSID = -1;
_isAlive = true;
protected __currentProcessStage: ProcessStageEnum = ProcessStage.Load;
private static __bufferViews: Map<Function, Map<BufferUseEnum, BufferView>> = new Map();
Expand Down Expand Up @@ -497,7 +494,7 @@ export class Component extends RnObject {
* @returns the entity which has this component
*/
get entity(): IEntity {
return EntityRepository.getEntity(this.__entityUid);
return this.__entityRepository.getEntity(this.__entityUid);
}

/**
Expand Down Expand Up @@ -570,18 +567,18 @@ export class Component extends RnObject {
* @param memberName the member of component in string
* @returns bytes information
*/
static getDataByteInfoByEntityUID(
componentType: typeof Component,
entityUID: EntityUID,
memberName: string
) {
const component = EntityRepository.getComponentOfEntity(entityUID, componentType);
if (component) {
return Component.getDataByteInfoInner(component, memberName);
}
// static getDataByteInfoByEntityUID(
// componentType: typeof Component,
// entityUID: EntityUID,
// memberName: string
// ) {
// const component = EntityRepository.getComponentOfEntity(entityUID, componentType);
// if (component) {
// return Component.getDataByteInfoInner(component, memberName);
// }

return void 0;
}
// return void 0;
// }

/**
* get the Pixel Location Offset in the Buffer of the Member
Expand Down
5 changes: 3 additions & 2 deletions src/foundation/core/ComponentRepository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from './Component';
import type { Component } from './Component';
import { Is } from '../misc/Is';
import { EntityRepository } from './EntityRepository';
import { Config } from './Config';
Expand All @@ -14,6 +14,7 @@ export class ComponentRepository {
static __componentClasses: Map<ComponentTID, typeof Component> = new Map();
private static __componentTIDs: Array<ComponentTID> = [];
private static __renderingComponentTIDs: Array<ComponentTID> = [];
static readonly invalidComponentSID = -1;
constructor() {}

/**
Expand Down Expand Up @@ -60,7 +61,7 @@ export class ComponentRepository {
let component_sid_count = this.__component_sid_count_map.get(componentTid);
if (Is.not.exist(component_sid_count)) {
this.__component_sid_count_map.set(componentTid, 0);
component_sid_count = Component.invalidComponentSID;
component_sid_count = ComponentRepository.invalidComponentSID;
}

// check __components array whether it has undefined element
Expand Down
7 changes: 7 additions & 0 deletions src/foundation/core/EntityRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ export class EntityRepository {
return this.__entities[entityUid];
}

/**
* Gets the entity corresponding to the entityUID.
* @param entityUid The entityUID of the entity.
*/
public getEntity(entityUid: EntityUID): IEntity {
return EntityRepository.__entities[entityUid];
}
/**
* Gets the specified component from the entity.
* @param entityUid The entity to get the component from.
Expand Down

0 comments on commit 46294fa

Please sign in to comment.