add splash image (#5363)

* add splash image

* asynchronous execution & fix circular reference & instance mode

* rename onFinish to setOnFinish
This commit is contained in:
jiaxin.lai
2019-09-12 16:46:50 +08:00
committed by pandamicro
parent 60f89f8b4e
commit f979d8fe6e
5 changed files with 423 additions and 30 deletions
+13 -10
View File
@@ -303,10 +303,21 @@ export class Director extends EventTarget {
self._lastUpdate = performance.now();
});
cc.game.once(Game.EVENT_ENGINE_INITED, this.init, this);
cc.game.once(Game.EVENT_RENDERER_INITED, this.initOnRenererInited, this);
cc.game.once(Game.EVENT_ENGINE_INITED, this.initOnEngineInited, this);
}
public init () {
public initOnRenererInited () {
this._root = new Root(cc.game._gfxDevice);
const rootInfo = {};
if (!this._root.initialize(rootInfo)) {
return false;
}
return true;
}
public initOnEngineInited () {
this._totalFrames = 0;
this._lastUpdate = performance.now();
this._paused = false;
@@ -324,14 +335,6 @@ export class Director extends EventTarget {
this.registerSystem(Scheduler.ID, this._scheduler, 200);
this.emit(Director.EVENT_INIT);
this._root = new Root(cc.game._gfxDevice);
const rootInfo = {};
if (!this._root.initialize(rootInfo)) {
return false;
}
return true;
}
/**
+42 -19
View File
@@ -31,7 +31,7 @@ import { EventTarget } from './event/event-target';
import { WebGLGFXDevice } from './gfx/webgl/webgl-device';
import { WebGL2GFXDevice } from './gfx/webgl2/webgl2-device';
import * as debug from './platform/debug';
import { SplashImage } from './splash-image';
/**
* @en
* The current game configuration, including:<br/>
@@ -202,15 +202,23 @@ export class Game extends EventTarget {
/**
* @en Event triggered after engine inited, at this point you will be able to use all engine classes.<br>
* It was defined as EVENT_RENDERER_INITED in cocos creator v1.x and renamed in v2.0
* It was defined as EVENT_RENDERER_INITED in cocos creator v1.x and renamed in v2.0.
* In cocos creator 3d, EVENT_RENDERER_INITED is a new event, look up define for details.
* @zh 在引擎初始化之后触发的事件,此时您能够使用引擎所有的类。<br>
* 它在 cocos creator v1.x 版本中名字为 EVENT_RENDERER_INITED ,在 v2.0 版本中更名为 EVENT_ENGINE_INITED
* 并在 cocos creator 3d 版本中将 EVENT_RENDERER_INITED 用作为渲染器初始化的事件。
* @property EVENT_ENGINE_INITED
* @constant
*/
public static EVENT_ENGINE_INITED: string = 'engine_inited';
// deprecated
public static EVENT_RENDERER_INITED: string = 'engine_inited';
/**
* @en Event triggered after renderer inited, at this point you will be able to use all gfx renderer feature.<br>
* @zh 在渲染器初始化之后触发的事件,此事件在 EVENT_ENGINE_INITED 之前触发,此时开始可使用 gfx 渲染框架。
* @property EVENT_RENDERER_INITED
* @readonly
*/
public static readonly EVENT_RENDERER_INITED: string = 'renderer_inited';
/**
* @en Web Canvas 2d API as renderer backend.
@@ -278,7 +286,7 @@ export class Game extends EventTarget {
* @zh 当引擎完成启动后的回调函数。
* @method onStart
*/
public onStart: Function|null = null;
public onStart: Function | null = null;
public _persistRootNodes = {};
@@ -291,10 +299,10 @@ export class Game extends EventTarget {
public _gfxDevice: WebGL2GFXDevice | WebGLGFXDevice | null = null;
public _intervalId: number|null = null; // interval target of main
public _intervalId: number | null = null; // interval target of main
public _lastTime: Date|null = null;
public _frameTime: number|null = null;
public _lastTime: Date | null = null;
public _frameTime: number | null = null;
// Scenes list
public _sceneInfos: string[] = [];
@@ -435,7 +443,7 @@ export class Game extends EventTarget {
* @param {Object} [target] - The target (this object) to invoke the callback, can be null
* @return {Function} - Just returns the incoming callback so you can save the anonymous function easier.
*/
public on (type: string, callback: Function, target?: object ): any {
public on (type: string, callback: Function, target?: object): any {
// Make sure EVENT_ENGINE_INITED callbacks to be invoked
if (this._prepared && type === Game.EVENT_ENGINE_INITED) {
callback.call(target);
@@ -481,7 +489,14 @@ export class Game extends EventTarget {
*/
public run (config: any, onStart: Function | null) {
this._initConfig(config);
this._initRenderer();
this.onStart = onStart;
if (!CC_EDITOR && CC_WECHATGAME/* && !CC_PREVIEW*/) {
SplashImage.instance.main(this._gfxDevice as any);
}
this.prepare(cc.game.onStart && cc.game.onStart.bind(cc.game));
}
@@ -573,9 +588,6 @@ export class Game extends EventTarget {
// @Game loading
private _initEngine () {
if (this._rendererInitialized) { return; }
this._initRenderer();
if (!CC_EDITOR) {
this._initEvents();
@@ -593,12 +605,21 @@ export class Game extends EventTarget {
// Log engine version
console.log('Cocos Creator 3D v' + cc.ENGINE_VERSION);
this._setAnimFrame();
this._runMainLoop();
const start = () => {
this._setAnimFrame();
this._runMainLoop();
this.emit(Game.EVENT_GAME_INITED);
this.emit(Game.EVENT_GAME_INITED);
if (cb) { cb(); }
if (cb) { cb(); }
};
if (!CC_EDITOR && CC_WECHATGAME) {
SplashImage.instance.setOnFinish(start);
SplashImage.instance.loadFinish = true;
} else {
start();
}
}
// @Methods
@@ -746,7 +767,7 @@ export class Game extends EventTarget {
// Avoid setup to be called twice.
if (this._rendererInitialized) { return; }
// tslint:disable-next-line: no-shadowed-variable
// tslint:disable-next-line: no-shadowed-variable
function addClass (element: { className: string; }, name: string) {
const hasClass = (' ' + element.className + ' ').indexOf(' ' + name + ' ') > -1;
if (!hasClass) {
@@ -868,6 +889,8 @@ export class Game extends EventTarget {
};
this._rendererInitialized = true;
this.emit(Game.EVENT_RENDERER_INITED);
}
private _initEvents () {
@@ -932,10 +955,10 @@ export class Game extends EventTarget {
}
if (CC_WECHATGAME && cc.sys.browserType !== cc.sys.BROWSER_TYPE_WECHAT_GAME_SUB) {
if ( wx.onShow ){
if (wx.onShow) {
wx.onShow(onShown);
}
if ( wx.onHide ){
if (wx.onHide) {
wx.onHide(onHidden);
}
}
+1
View File
@@ -57,4 +57,5 @@ import './primitive';
export * from './utils/profiler/profiler';
import './splash-image';
import './deprecated';
+1 -1
View File
@@ -2,7 +2,7 @@
* @category pipeline
*/
import {RenderPassStage} from './define';
import { RenderPassStage } from './define';
import './render-view';
cc.RenderPassStage = RenderPassStage;
File diff suppressed because one or more lines are too long