engine load fix (#5993)

* engine load fix

* renderPipeline config fix

* bug  fix

* event remove
This commit is contained in:
ChiaNing
2019-12-28 16:14:55 +08:00
committed by pandamicro
parent 24e8103051
commit d0cb5a8be3
2 changed files with 62 additions and 67 deletions
+11 -12
View File
@@ -1066,23 +1066,11 @@ export class Director extends EventTarget {
}
private _initOnRendererInitialized () {
this._root = new Root(cc.game._gfxDevice);
const rootInfo = {};
if (!this._root.initialize(rootInfo)) {
return false;
}
return true;
}
private _initOnEngineInitialized () {
this._totalFrames = 0;
this._lastUpdate = performance.now();
this._paused = false;
this._purgeDirectorInNextLoop = false;
cc.loader.init(this);
// Event manager
if (eventManager) {
eventManager.setEnabled(true);
@@ -1094,6 +1082,17 @@ export class Director extends EventTarget {
this.emit(Director.EVENT_INIT);
}
private _initOnEngineInitialized () {
cc.loader.init(this);
this._root = new Root(cc.game._gfxDevice);
const rootInfo = {};
if (!this._root.initialize(rootInfo)) {
return false;
}
return true;
}
}
export declare namespace Director {
+51 -55
View File
@@ -154,6 +154,11 @@ export interface IGameConfig {
* For internal use.
*/
jsList?: string[];
/**
* Render pipeline resources
*/
renderPipeline?: string;
}
/**
@@ -490,23 +495,9 @@ export class Game extends EventTarget {
*/
public run (config: any, onStart: Function | null) {
this._initConfig(config);
this._initRenderer();
// load renderpipeline
cc.loader.load({ uuid: config.renderpipeline }, (err, asset) => {
// failed load renderPipeline
if (err || !(asset instanceof cc.RenderPipeline)) {
console.error(`Failed load renderpipeline: ${config.renderpipeline}`);
console.error(err);
cc.game.setRenderPipeline(null);
} else {
cc.game.setRenderPipeline(asset);
}
this.onStart = onStart;
this.prepare(cc.game.onStart && cc.game.onStart.bind(cc.game));
});
this.onStart = onStart;
this.prepare(cc.game.onStart && cc.game.onStart.bind(cc.game));
}
// @ Persist root node section
@@ -580,41 +571,8 @@ export class Game extends EventTarget {
return;
}
// Load game scripts
const jsList = this.config.jsList;
if (jsList && jsList.length > 0) {
const self = this;
cc.loader.load(jsList, (err: any) => {
if (err) { throw new Error(JSON.stringify(err)); }
self._prepareFinished(cb);
});
}
else {
this._prepareFinished(cb);
}
}
// @Game loading
private _initEngine () {
if (!CC_EDITOR) {
this._initEvents();
}
this.emit(Game.EVENT_ENGINE_INITED);
}
private _prepareFinished (cb: Function | null) {
this._prepared = true;
// Init engine
this._initEngine();
// Log engine version
console.log('Cocos Creator 3D v' + cc.ENGINE_VERSION);
const start = () => {
this._prepared = true;
this._setAnimFrame();
this._runMainLoop();
@@ -623,7 +581,49 @@ export class Game extends EventTarget {
if (cb) { cb(); }
};
start();
// Init engine
this._initEngine(start);
}
// @Game loading
private _initEngine (cb: Function | null) {
this._initRenderer();
if (!CC_EDITOR) {
this._initEvents();
}
// load renderpipeline
let config = this.config;
cc.loader.load({ uuid: config.renderPipeline }, (err, asset) => {
// failed load renderPipeline
if (err || !(asset instanceof cc.RenderPipeline)) {
console.error(`Failed load renderpipeline: ${config.renderPipeline}, engine failed to initialize, all process stoped`);
console.error(err);
this.setRenderPipeline(null);
} else {
this.setRenderPipeline(asset);
}
this._rendererInitialized = true;
this.emit(Game.EVENT_RENDERER_INITED);
if (cc.internal.SplashScreen) {
// Start splash screen
cc.internal.SplashScreen.instance.main(this._gfxDevice);
cc.internal.SplashScreen.instance.setOnFinish(cb);
cc.internal.SplashScreen.instance.loadFinish = true;
}
else {
cb && cb();
}
});
// Log engine version
console.log('Cocos Creator 3D v' + cc.ENGINE_VERSION);
this.emit(Game.EVENT_ENGINE_INITED);
}
// @Methods
@@ -884,10 +884,6 @@ export class Game extends EventTarget {
this.canvas!.oncontextmenu = () => {
if (!cc._isContextMenuEnable) { return false; }
};
this._rendererInitialized = true;
this.emit(Game.EVENT_RENDERER_INITED);
}
private _initEvents () {