-
-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Asynchronous initialization of Engine #411
Comments
There are several reasons why the engine must consider asynchronous initialization:
We don't want the engine's future initialization process to happen Here are some initial ideas and designs: WebGLUniversal version: const webCanvas = new WebCanvas(htmlCanvas);
const webGLGraphicDevice = new WebGLGraphicDevice({});
const physXPhysics = new PhysXPhysics(PhysXRuntimeMode.Auto);
const configuration = {
canvas: webCanvas,
graphicDevice: webGLGraphicDevice,
physics: physXPhysics,
ktx2LoaderOptions:<LTX2LoaderOptions>{}
};
const engine = await Engine.create(configuration);
// Destroy physX
physXPhysics.destroy(); Encapsulation version: const physXPhysics = new PhysXPhysics(PhysXRuntimeMode.Auto);
const configuration = {
canvas: htmlCanvas,
physics: physXPhysics,
graphicDeviceOptions: <WebGLGraphcDeviceOptions>{},
ktx2LoaderOptions:<LTX2LoaderOptions>{}
};
const engine = await WebGLEngine.create(configuration);
// Destroy physX
physXPhysics.destroy(); WebGPU with multi canvasUniversal version: const webCanvas1 = new WebGPUCanvas("htmlCanvas1",{...});
const webCanvas2 = new WebGPUCanvas("htmlCanvas2",{...});
const webGPUGraphicDevice = new WebGPUGraphicDevice({...});
const physXPhysics = new PhysXPhysics(PhysXRuntimeMode.Auto);
const configuration = {
graphicDevice:webGPUGraphicDevice,
physics: physXPhysics,
ktx2LoaderOptions:<LTX2LoaderOptions>{}
};
const engine = await Engine.create(configuration);
......
// Set multi renderTaget to different canvas
camera1.renderTaget = webCanvas1);
camera2.renderTaget = webCanvas2;
// Destroy physX
physXPhysics.destroy(); Encapsulation version: const webCanvas1 = new WebGPUCanvas("htmlCanvas1",{});
const webCanvas2 = new WebGPUCanvas("htmlCanvas2",{});
const physXPhysics = new PhysXPhysics(PhysXRuntimeMode.Auto);
const configuration = {
physics: physXPhysics,
graphicDeviceOptions:<WebGPUGraphcDeviceOptions>{}
ktx2LoaderOptions:<LTX2LoaderOptions>{}
};
const engine = await WebGPUEngine.create(configuration);
......
// Set multi renderTaget to different canvas
camera1.renderTaget = webCanvas1);
camera2.renderTaget = webCanvas2;
// Destroy physX
physXPhysics.destroy(); PhysX and KTX2Loader implementation: @resourceLoader(AssetType.Texture2D, ["ktx2"])
class KTX2Loader extends Loader<Texture2D> {
initialize(): Promise<void> {}
load(item: LoadItem, resourceManager: ResourceManager): AssetPromise<Texture2D> {}
}
class PhysXPhysics {
constructor(runtimeMode: PhysXRuntimeMode);
initialize(): Promise<void> {}
destroy(): void {}
} @yangfengzzz @gz65555 Discuss together to see if there are other improvements and potential unmet needs |
How about letting developers handle asynchrony themselves, like PhysXPhysics now.
When they don't use KTX2 or PhysXPhysic, they can still use the engine in a synchronous way. |
@luzhuang Specified configuration can be easily exported by Editor. |
Use {
"ktx2Loader": {
"maxWorker": 4,
"preCreated": true,
}
} How to register a initialized function to be called. @GuoLei1990 |
In the foreseeable future, it can be considered that almost 90% of projects will use asynchronous, even WebGPU is forced asynchronous |
Because WASM loaded is asynchronous,All physical component should be used after WASM binary loaded well.
The initialization of engine and component should be written in the callback function like Laya:
Laya3D.init(0, 0, null, Handler.create(null, () => { xxx }
PR reviewers: @yangfengzzz , @cptbtptpbcptdtptp , @zhuxudong
The text was updated successfully, but these errors were encountered: