Skip to content

Commit

Permalink
fix(ComponentCollect): break component dependency for engine3D (#161)
Browse files Browse the repository at this point in the history
fix break component dependency for engine3D
  • Loading branch information
ZenderJK committed May 18, 2023
1 parent 8c0adf9 commit 5c69be1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
2 changes: 0 additions & 2 deletions src/Engine3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ export class Engine3D {

await webGPUContext.init(descriptor.canvasConfig);

ComponentCollect.init();

ShaderLib.init();

ShaderUtil.init();
Expand Down
3 changes: 2 additions & 1 deletion src/components/Transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Scene3D } from "../core/Scene3D";
import { View3D } from "../core/View3D";
import { Object3D } from "../core/entities/Object3D";
import { CEvent } from "../event/CEvent";
import { ComponentCollect } from "../gfx/renderJob/collect/ComponentCollect";
import { MathUtil } from "../math/MathUtil";
import { Matrix4, makeMatrix44, append } from "../math/Matrix4";
import { Orientation3D } from "../math/Orientation3D";
Expand Down Expand Up @@ -120,7 +121,7 @@ export class Transform extends ComponentBase {
} else {
this._scene3d = hasRoot;
this.object3D.components.forEach((c) => {
this.object3D[`appendLateStart`](c);
ComponentCollect.appendWaitStart(this.object3D, c);
});
}

Expand Down
14 changes: 2 additions & 12 deletions src/core/entities/Object3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,13 @@ export class Object3D extends Entity {
instance.object3D = this;
instance[`__init`](param);
this.components.set(className, instance);
this.appendLateStart(instance);
ComponentCollect.appendWaitStart(this, instance);
return instance;
}
return null;
}

private appendLateStart(component: IComponent) {
let arr = ComponentCollect.waitStartComponent.get(this);
if (!arr) {
ComponentCollect.waitStartComponent.set(this, [component]);
} else {
let index = arr.indexOf(component);
if (index == -1) {
arr.push(component);
}
}
}


/**
*
Expand Down
43 changes: 35 additions & 8 deletions src/gfx/renderJob/collect/ComponentCollect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,22 @@ export class ComponentCollect {
*/
public static waitStartComponent: Map<Object3D, IComponent[]>;

public static init() {
ComponentCollect.componentsUpdateList = new Map<View3D, Map<IComponent, Function>>();
ComponentCollect.componentsLateUpdateList = new Map<View3D, Map<IComponent, Function>>();
ComponentCollect.componentsBeforeUpdateList = new Map<View3D, Map<IComponent, Function>>();
ComponentCollect.componentsComputeList = new Map<View3D, Map<IComponent, Function>>();
ComponentCollect.graphicComponent = new Map<View3D, Map<IComponent, Function>>();
ComponentCollect.waitStartComponent = new Map<Object3D, IComponent[]>();
private static _init: boolean = false;

private static init() {
if (!this._init) {
this._init = true;
ComponentCollect.componentsUpdateList = new Map<View3D, Map<IComponent, Function>>();
ComponentCollect.componentsLateUpdateList = new Map<View3D, Map<IComponent, Function>>();
ComponentCollect.componentsBeforeUpdateList = new Map<View3D, Map<IComponent, Function>>();
ComponentCollect.componentsComputeList = new Map<View3D, Map<IComponent, Function>>();
ComponentCollect.graphicComponent = new Map<View3D, Map<IComponent, Function>>();
ComponentCollect.waitStartComponent = new Map<Object3D, IComponent[]>();
}
}

public static bindUpdate(view: View3D, component: IComponent, call: Function) {
this.init();
let list = ComponentCollect.componentsUpdateList.get(view);
if (!list) {
list = new Map<IComponent, Function>();
Expand All @@ -53,13 +59,15 @@ export class ComponentCollect {
}

public static unBindUpdate(view: View3D, component: IComponent) {
this.init();
let list = ComponentCollect.componentsUpdateList.get(view);
if (list) {
list.delete(component);
}
}

public static bindLateUpdate(view: View3D, component: IComponent, call: Function) {
this.init();
let list = ComponentCollect.componentsLateUpdateList.get(view);
if (!list) {
list = new Map<IComponent, Function>();
Expand All @@ -69,13 +77,15 @@ export class ComponentCollect {
}

public static unBindLateUpdate(view: View3D, component: IComponent) {
this.init();
let list = ComponentCollect.componentsLateUpdateList.get(view);
if (list) {
list.delete(component);
}
}

public static bindBeforeUpdate(view: View3D, component: IComponent, call: Function) {
this.init();
let list = ComponentCollect.componentsBeforeUpdateList.get(view);
if (!list) {
list = new Map<IComponent, Function>();
Expand All @@ -85,13 +95,15 @@ export class ComponentCollect {
}

public static unBindBeforeUpdate(view: View3D, component: IComponent) {
this.init();
let list = ComponentCollect.componentsBeforeUpdateList.get(view);
if (list) {
list.delete(component);
}
}

public static bindCompute(view: View3D, component: IComponent, call: Function) {
this.init();
let list = ComponentCollect.componentsComputeList.get(view);
if (!list) {
list = new Map<IComponent, Function>();
Expand All @@ -101,14 +113,15 @@ export class ComponentCollect {
}

public static unBindCompute(view: View3D, component: IComponent) {
this.init();
let list = ComponentCollect.componentsComputeList.get(view);
if (list) {
list.delete(component);
}
}


public static bindGraphic(view: View3D, component: IComponent, call: Function) {
this.init();
let list = ComponentCollect.graphicComponent.get(view);
if (!list) {
list = new Map<IComponent, Function>();
Expand All @@ -118,9 +131,23 @@ export class ComponentCollect {
}

public static unBindGraphic(view: View3D, component: IComponent) {
this.init();
let list = ComponentCollect.graphicComponent.get(view);
if (list) {
list.delete(component);
}
}

public static appendWaitStart(obj: Object3D, component: IComponent) {
this.init();
let arr = ComponentCollect.waitStartComponent.get(obj);
if (!arr) {
ComponentCollect.waitStartComponent.set(obj, [component]);
} else {
let index = arr.indexOf(component);
if (index == -1) {
arr.push(component);
}
}
}
}
1 change: 0 additions & 1 deletion src/gfx/renderJob/collect/ShadowLightsCollect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export class ShadowLightsCollect {

this.shadowBuffer = new Map<Scene3D, StorageGPUBuffer>;
this.shadowLights = new Map<Scene3D, Uint32Array>;
// this.shadowBuffer.visibility = GPUShaderStage.FRAGMENT;
}

public static createBuffer(scene: Scene3D) {
Expand Down

0 comments on commit 5c69be1

Please sign in to comment.