修复运行时未初始化

This commit is contained in:
yhh
2020-07-23 19:28:01 +08:00
parent 79c5d6990c
commit d4c244daf5
18 changed files with 283 additions and 303 deletions
+3 -3
View File
@@ -248,7 +248,6 @@ declare module es {
} }
declare module es { declare module es {
class Core extends egret.DisplayObjectContainer { class Core extends egret.DisplayObjectContainer {
static activeSceneChanged: Function;
static emitter: Emitter<CoreEvents>; static emitter: Emitter<CoreEvents>;
static graphicsDevice: GraphicsDevice; static graphicsDevice: GraphicsDevice;
static content: ContentManager; static content: ContentManager;
@@ -260,6 +259,7 @@ declare module es {
_globalManagers: GlobalManager[]; _globalManagers: GlobalManager[];
static scene: Scene; static scene: Scene;
constructor(); constructor();
private onAddToStage;
onOrientationChanged(): void; onOrientationChanged(): void;
protected onGraphicsDeviceReset(): void; protected onGraphicsDeviceReset(): void;
protected initialize(): void; protected initialize(): void;
@@ -269,7 +269,6 @@ declare module es {
endDebugUpdate(): void; endDebugUpdate(): void;
onSceneChanged(): void; onSceneChanged(): void;
static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T; static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T;
static registerActiveSceneChanged(current: Scene, next: Scene): void;
static registerGlobalManager(manager: es.GlobalManager): void; static registerGlobalManager(manager: es.GlobalManager): void;
static unregisterGlobalManager(manager: es.GlobalManager): void; static unregisterGlobalManager(manager: es.GlobalManager): void;
static getGlobalManager<T extends es.GlobalManager>(type: any): T; static getGlobalManager<T extends es.GlobalManager>(type: any): T;
@@ -1679,7 +1678,8 @@ declare module es {
static readonly logSnapDuration: number; static readonly logSnapDuration: number;
static readonly barPadding: number; static readonly barPadding: number;
static readonly autoAdjustDelay: number; static readonly autoAdjustDelay: number;
static Instance: TimeRuler; private static _instance;
static readonly Instance: TimeRuler;
private _frameKey; private _frameKey;
private _logKey; private _logKey;
private _logs; private _logs;
+22 -12
View File
@@ -1105,13 +1105,8 @@ var es;
_this._globalManagers = []; _this._globalManagers = [];
Core._instance = _this; Core._instance = _this;
Core.emitter = new es.Emitter(); Core.emitter = new es.Emitter();
Core.graphicsDevice = new es.GraphicsDevice();
Core.content = new es.ContentManager(); Core.content = new es.ContentManager();
_this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.initialize, _this); _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this);
_this.addEventListener(egret.Event.RESIZE, _this.onGraphicsDeviceReset, _this);
_this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, _this.onOrientationChanged, _this);
_this.addEventListener(egret.Event.ENTER_FRAME, _this.update, _this);
_this.addEventListener(egret.Event.RENDER, _this.draw, _this);
return _this; return _this;
} }
Object.defineProperty(Core, "Instance", { Object.defineProperty(Core, "Instance", {
@@ -1123,6 +1118,8 @@ var es;
}); });
Object.defineProperty(Core, "scene", { Object.defineProperty(Core, "scene", {
get: function () { get: function () {
if (!this._instance)
return null;
return this._instance._scene; return this._instance._scene;
}, },
set: function (value) { set: function (value) {
@@ -1138,11 +1135,18 @@ var es;
else { else {
this._instance._nextScene = value; this._instance._nextScene = value;
} }
this.registerActiveSceneChanged(this._instance._scene, this._instance._nextScene);
}, },
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
Core.prototype.onAddToStage = function () {
Core.graphicsDevice = new es.GraphicsDevice();
this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this);
this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this);
this.addEventListener(egret.Event.ENTER_FRAME, this.update, this);
this.addEventListener(egret.Event.RENDER, this.draw, this);
this.initialize();
};
Core.prototype.onOrientationChanged = function () { Core.prototype.onOrientationChanged = function () {
Core.emitter.emit(es.CoreEvents.OrientationChanged); Core.emitter.emit(es.CoreEvents.OrientationChanged);
}; };
@@ -1228,10 +1232,6 @@ var es;
this._instance._sceneTransition = sceneTransition; this._instance._sceneTransition = sceneTransition;
return sceneTransition; return sceneTransition;
}; };
Core.registerActiveSceneChanged = function (current, next) {
if (this.activeSceneChanged)
this.activeSceneChanged(current, next);
};
Core.registerGlobalManager = function (manager) { Core.registerGlobalManager = function (manager) {
this._instance._globalManagers.push(manager); this._instance._globalManagers.push(manager);
manager.enabled = true; manager.enabled = true;
@@ -4308,6 +4308,8 @@ var es;
this.platformInitialize(device); this.platformInitialize(device);
}; };
GraphicsCapabilities.prototype.platformInitialize = function (device) { GraphicsCapabilities.prototype.platformInitialize = function (device) {
if (GraphicsCapabilities.runtimeType != egret.RuntimeType.WXGAME)
return;
var capabilities = this; var capabilities = this;
capabilities["isMobile"] = true; capabilities["isMobile"] = true;
var systemInfo = wx.getSystemInfoSync(); var systemInfo = wx.getSystemInfoSync();
@@ -7570,7 +7572,6 @@ var es;
this.stopwacth = new stopwatch.Stopwatch(); this.stopwacth = new stopwatch.Stopwatch();
this._markerNameToIdMap = new Map(); this._markerNameToIdMap = new Map();
this.showLog = false; this.showLog = false;
TimeRuler.Instance = this;
this._logs = new Array(2); this._logs = new Array(2);
for (var i = 0; i < this._logs.length; ++i) for (var i = 0; i < this._logs.length; ++i)
this._logs[i] = new FrameLog(); this._logs[i] = new FrameLog();
@@ -7579,6 +7580,15 @@ var es;
es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this); es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this);
this.onGraphicsDeviceReset(); this.onGraphicsDeviceReset();
} }
Object.defineProperty(TimeRuler, "Instance", {
get: function () {
if (!this._instance)
this._instance = new TimeRuler();
return this._instance;
},
enumerable: true,
configurable: true
});
TimeRuler.prototype.onGraphicsDeviceReset = function () { TimeRuler.prototype.onGraphicsDeviceReset = function () {
var layout = new es.Layout(); var layout = new es.Layout();
this._position = layout.place(new es.Vector2(this.width, TimeRuler.barHeight), 0, 0.01, es.Alignment.bottomCenter).location; this._position = layout.place(new es.Vector2(this.width, TimeRuler.barHeight), 0, 0.01, es.Alignment.bottomCenter).location;
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -2
View File
@@ -11,12 +11,11 @@
"libs/long/long.js" "libs/long/long.js"
], ],
"game": [ "game": [
"bin-debug/game/CoreEmitterType.js",
"bin-debug/AssetAdapter.js", "bin-debug/AssetAdapter.js",
"bin-debug/LoadingUI.js",
"bin-debug/Main.js", "bin-debug/Main.js",
"bin-debug/Platform.js", "bin-debug/Platform.js",
"bin-debug/ThemeAdapter.js", "bin-debug/ThemeAdapter.js",
"bin-debug/LoadingUI.js",
"bin-debug/game/MainScene.js", "bin-debug/game/MainScene.js",
"bin-debug/game/PlayerController.js", "bin-debug/game/PlayerController.js",
"bin-debug/game/SimplePooled.js", "bin-debug/game/SimplePooled.js",
+5 -55
View File
@@ -27,43 +27,9 @@
// //
////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////
class Main extends es.Core {
import SceneManager = es.SceneManager; protected async initialize() {
import Emitter = es.Emitter; await this.runGame();
class Main extends SceneManager {
public static emitter: Emitter<CoreEmitterType>;
public static manager: SceneManager;
protected createChildren(): void {
super.createChildren();
egret.lifecycle.addLifecycleListener((context) => {
// custom lifecycle plugin
})
egret.lifecycle.onPause = () => {
egret.ticker.pause();
}
egret.lifecycle.onResume = () => {
egret.ticker.resume();
}
//inject the custom material parser
//注入自定义的素材解析器
let assetAdapter = new AssetAdapter();
egret.registerImplementation("eui.IAssetAdapter", assetAdapter);
egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());
Main.manager = new SceneManager(this.stage);
Main.emitter = new Emitter<CoreEmitterType>();
this.addEventListener(egret.Event.ENTER_FRAME, this.updateFrame, this);
this.runGame();
}
private updateFrame(evt: egret.Event){
Main.emitter.emit(CoreEmitterType.Update, evt);
} }
private async runGame() { private async runGame() {
@@ -71,12 +37,12 @@ class Main extends SceneManager {
this.createGameScene(); this.createGameScene();
} }
private async loadResource() { private async loadResource() {
try { try {
const loadingView = new LoadingUI(); const loadingView = new LoadingUI();
this.stage.addChild(loadingView); this.stage.addChild(loadingView);
await RES.loadConfig("resource/default.res.json", "resource/"); await RES.loadConfig("resource/default.res.json", "resource/");
await this.loadTheme();
await RES.loadGroup("preload", 0, loadingView); await RES.loadGroup("preload", 0, loadingView);
this.stage.removeChild(loadingView); this.stage.removeChild(loadingView);
} }
@@ -85,27 +51,11 @@ class Main extends SceneManager {
} }
} }
private loadTheme() {
return new Promise((resolve, reject) => {
// load skin theme configuration file, you can manually modify the file. And replace the default skin.
//加载皮肤主题配置文件,可以手动修改这个文件。替换默认皮肤。
let theme = new eui.Theme("resource/default.thm.json", this.stage);
theme.addEventListener(eui.UIEvent.COMPLETE, () => {
resolve();
}, this);
})
}
/** /**
* *
* Create scene interface * Create scene interface
*/ */
protected createGameScene(): void { protected createGameScene(): void {
SceneManager.scene = new MainScene(); es.Core.scene = new scene.MainScene();
// Main.emitter.addObserver(CoreEmitterType.Update, ()=>{
// console.log("update emitter");
// });
} }
} }
-3
View File
@@ -1,3 +0,0 @@
enum CoreEmitterType {
Update,
}
+82 -87
View File
@@ -1,95 +1,90 @@
class MainScene extends Scene { module scene {
constructor() { export class MainScene extends es.Scene {
super(); constructor() {
super();
// this.addEntityProcessor(new SpawnerSystem(new Matcher())); // this.addEntityProcessor(new SpawnerSystem(new Matcher()));
this.astarTest(); this.astarTest();
this.dijkstraTest(); this.dijkstraTest();
this.breadthfirstTest(); this.breadthfirstTest();
}
public async onStart() {
let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png"));
let bg = this.createEntity("bg");
bg.addComponent(new SpriteRenderer()).setSprite(sprite).setColor(0xff0000);
bg.addComponent(new PlayerController());
bg.addComponent(new Mover());
bg.addComponent(new ScrollingSpriteRenderer(sprite));
bg.addComponent(new BoxCollider());
bg.position = new Vector2(Math.random() * 200, Math.random() * 200);
for (let i = 0; i < 1; i++) {
let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png"));
let player2 = this.createEntity("player2");
player2.addComponent(new SpriteRenderer()).setSprite(sprite);
player2.position = new Vector2(Math.random() * 100, Math.random() * 100);
player2.addComponent(new BoxCollider());
} }
this.camera.follow(bg, CameraStyle.lockOn); public async onStart() {
let sprite = new es.Sprite(RES.getRes("checkbox_select_disabled_png"));
let bg = this.createEntity("bg");
bg.addComponent(new es.SpriteRenderer()).setSprite(sprite).setColor(0xff0000);
bg.addComponent(new component.PlayerController());
bg.addComponent(new es.Mover());
bg.addComponent(new es.ScrollingSpriteRenderer(sprite));
bg.addComponent(new es.BoxCollider());
bg.position = new es.Vector2(Math.random() * 200, Math.random() * 200);
let pool = new ComponentPool<SimplePooled>(SimplePooled); for (let i = 0; i < 1; i++) {
let c1 = pool.obtain(); let sprite = new es.Sprite(RES.getRes("checkbox_select_disabled_png"));
let c2 = pool.obtain(); let player2 = this.createEntity("player2");
pool.free(c1); player2.addComponent(new es.SpriteRenderer()).setSprite(sprite);
let c1b = pool.obtain(); player2.position = new es.Vector2(Math.random() * 100, Math.random() * 100);
player2.addComponent(new es.BoxCollider());
}
console.log(c1 != c2); this.camera.follow(bg, es.CameraStyle.lockOn);
console.log(c1 == c1b);
let button = new eui.Button(); let pool = new es.ComponentPool<component.SimplePooled>(component.SimplePooled);
button.label = "切换场景"; let c1 = pool.obtain();
this.addChild(button); let c2 = pool.obtain();
button.addEventListener(egret.TouchEvent.TOUCH_TAP, () => { pool.free(c1);
SceneManager.startSceneTransition(new FadeTransition(() => { let c1b = pool.obtain();
return new MainScene();
}));
}, this);
Main.emitter.addObserver(CoreEmitterType.Update, this.handleFuncTest, this); console.log(c1 != c2);
console.log(c1 == c1b);
let button = new eui.Button();
button.label = "切换场景";
this.addChild(button);
button.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
es.Core.startSceneTransition(new es.FadeTransition(() => {
return new MainScene();
}));
}, this);
}
public breadthfirstTest() {
let graph = new es.UnweightedGraph<string>();
graph.addEdgesForNode("a", ["b"]); // a->b
graph.addEdgesForNode("b", ["a", "c", "d"]); // b->a b->c b->d
graph.addEdgesForNode("c", ["a"]); // c->a
graph.addEdgesForNode("d", ["e", "a"]); // d->e d->a
graph.addEdgesForNode("e", ["b"]); // e->b
// 计算从c到e的路径
let path = es.BreadthFirstPathfinder.search(graph, "c", "e");
console.log(path);
}
public dijkstraTest() {
let graph = new es.WeightedGridGraph(20, 20);
graph.weightedNodes.push(new es.Vector2(3, 3));
graph.weightedNodes.push(new es.Vector2(3, 4));
graph.weightedNodes.push(new es.Vector2(4, 3));
graph.weightedNodes.push(new es.Vector2(4, 4));
let path = graph.search(new es.Vector2(3, 4), new es.Vector2(15, 17));
console.log(path);
}
public astarTest() {
let graph = new es.AstarGridGraph(30, 30);
// graph.weightedNodes.push(new Vector2(3, 3));
// graph.weightedNodes.push(new Vector2(3, 4));
// graph.weightedNodes.push(new Vector2(4, 3));
// graph.weightedNodes.push(new Vector2(4, 4));
let startTime = egret.getTimer();
let path = graph.search(new es.Vector2(1, 1), new es.Vector2(29, 29));
console.log(egret.getTimer() - startTime);
}
} }
}
/** 测试Emitter */
private handleFuncTest(){
Main.emitter.removeObserver(CoreEmitterType.Update, this.handleFuncTest);
}
public breadthfirstTest() {
let graph = new UnweightedGraph<string>();
graph.addEdgesForNode("a", ["b"]); // a->b
graph.addEdgesForNode("b", ["a", "c", "d"]); // b->a b->c b->d
graph.addEdgesForNode("c", ["a"]); // c->a
graph.addEdgesForNode("d", ["e", "a"]); // d->e d->a
graph.addEdgesForNode("e", ["b"]); // e->b
// 计算从c到e的路径
let path = BreadthFirstPathfinder.search(graph, "c", "e");
console.log(path);
}
public dijkstraTest() {
let graph = new WeightedGridGraph(20, 20);
graph.weightedNodes.push(new Vector2(3, 3));
graph.weightedNodes.push(new Vector2(3, 4));
graph.weightedNodes.push(new Vector2(4, 3));
graph.weightedNodes.push(new Vector2(4, 4));
let path = graph.search(new Vector2(3, 4), new Vector2(15, 17));
console.log(path);
}
public astarTest() {
let graph = new AstarGridGraph(30, 30);
// graph.weightedNodes.push(new Vector2(3, 3));
// graph.weightedNodes.push(new Vector2(3, 4));
// graph.weightedNodes.push(new Vector2(4, 3));
// graph.weightedNodes.push(new Vector2(4, 4));
let startTime = egret.getTimer();
let path = graph.search(new Vector2(1, 1), new Vector2(29, 29));
console.log(egret.getTimer() - startTime);
}
}
+53 -45
View File
@@ -1,56 +1,64 @@
class PlayerController extends Component { module component {
private down: boolean = false; import Component = es.Component;
private touchPoint: Vector2 = Vector2.zero; import Vector2 = es.Vector2;
private mover: Mover; import Mover = es.Mover;
private spriteRenderer: SpriteRenderer; import SpriteRenderer = es.SpriteRenderer;
import Time = es.Time;
import Input = es.Input;
public onAddedToEntity(){ export class PlayerController extends Component {
this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); private down: boolean = false;
this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchBegin, this); private touchPoint: Vector2 = Vector2.zero;
this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); private mover: Mover;
} private spriteRenderer: SpriteRenderer;
private touchBegin(evt: egret.TouchEvent){ public onAddedToEntity(){
this.down = true; this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this);
this.touchPoint = new Vector2(evt.stageX, evt.stageY); this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchBegin, this);
} this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this);
}
private touchEnd(evt: egret.TouchEvent){ private touchBegin(evt: egret.TouchEvent){
this.down = false; this.down = true;
this.touchPoint = new Vector2(evt.stageX, evt.stageY); this.touchPoint = new Vector2(evt.stageX, evt.stageY);
} }
public update(){ private touchEnd(evt: egret.TouchEvent){
if (!this.mover) this.down = false;
this.mover = this.entity.getComponent<Mover>(Mover); this.touchPoint = new Vector2(evt.stageX, evt.stageY);
}
if (!this.spriteRenderer) public update(){
this.spriteRenderer = this.entity.getComponent<SpriteRenderer>(SpriteRenderer); if (!this.mover)
this.mover = this.entity.getComponent<Mover>(Mover);
if (!this.mover) if (!this.spriteRenderer)
return; this.spriteRenderer = this.entity.getComponent<SpriteRenderer>(SpriteRenderer);
if (!SpriteRenderer) if (!this.mover)
return; return;
if (this.down){ if (!SpriteRenderer)
let camera = SceneManager.scene.camera; return;
let moveLeft: number = 0;
let moveRight: number = 0; if (this.down){
let speed = 100; let moveLeft: number = 0;
let worldPos = Input.touchPosition; let moveRight: number = 0;
if (worldPos.x < this.spriteRenderer.localPosition.x){ let speed = 100;
moveLeft = -1; let worldPos = Input.touchPosition;
} else if(worldPos.x > this.spriteRenderer.localPosition.x){ if (worldPos.x < this.spriteRenderer.transform.position.x){
moveLeft = 1; moveLeft = -1;
} else if(worldPos.x > this.spriteRenderer.transform.position.x){
moveLeft = 1;
}
if (worldPos.y < this.spriteRenderer.transform.position.y){
moveRight = -1;
} else if(worldPos.y > this.spriteRenderer.transform.position.y){
moveRight = 1;
}
this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime));
} }
if (worldPos.y < this.spriteRenderer.localPosition.y){
moveRight = -1;
} else if(worldPos.y > this.spriteRenderer.localPosition.y){
moveRight = 1;
}
this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime));
} }
} }
} }
+8 -4
View File
@@ -1,5 +1,9 @@
class SimplePooled extends PooledComponent { module component {
public reset(){ import PooledComponent = es.PooledComponent;
export class SimplePooled extends PooledComponent {
public reset(){
}
} }
} }
+32 -30
View File
@@ -1,35 +1,37 @@
class SpawnComponent extends Component implements ITriggerListener { module component {
public cooldown = -1; export class SpawnComponent extends es.Component implements es.ITriggerListener {
public minInterval = 2; public cooldown = -1;
public maxInterval = 60; public minInterval = 2;
public enemyType = EnemyType.worm; public maxInterval = 60;
public numSpawned = 0; public enemyType = EnemyType.worm;
public numAlive = 0; public numSpawned = 0;
public numAlive = 0;
constructor(enemyType: EnemyType) { constructor(enemyType: EnemyType) {
super(); super();
this.enemyType = enemyType; this.enemyType = enemyType;
}
public initialize() {
// console.log("initialize");
}
public update() {
// console.log("update");
}
public onTriggerEnter(other: es.Collider, local: es.Collider){
if (other == local)
console.log("repeat collider");
console.log("enter collider");
}
public onTriggerExit(other: es.Collider, local: es.Collider){
console.log("exit collider");
}
} }
public initialize() { export enum EnemyType {
// console.log("initialize"); worm
}
public update() {
// console.log("update");
}
public onTriggerEnter(other: Collider, local: Collider){
if (other == local)
console.log("repeat collider")
console.log("enter collider");
}
public onTriggerExit(other: Collider, local: Collider){
console.log("exit collider");
} }
} }
enum EnemyType {
worm
}
+31 -29
View File
@@ -1,34 +1,36 @@
class SpawnerSystem extends EntityProcessingSystem { module system {
constructor(matcher: Matcher){ export class SpawnerSystem extends es.EntityProcessingSystem {
super(matcher); constructor(matcher: es.Matcher){
} super(matcher);
public processEntity(entity: Entity){
let spawner = entity.getComponent<SpawnComponent>(SpawnComponent);
if (!spawner)
return;
if (spawner.numAlive <= 0)
spawner.enabled = true;
if (!spawner.enabled)
return;
console.log("cooldown", spawner.cooldown);
if (spawner.cooldown == -1){
spawner.cooldown = Math.random() * 60;
spawner.cooldown /= 4;
} }
spawner.cooldown -= Time.deltaTime; public processEntity(entity: es.Entity){
if (spawner.cooldown <= 0){ let spawner = entity.getComponent<component.SpawnComponent>(component.SpawnComponent);
spawner.cooldown = Math.random() * 60; if (!spawner)
// CreateEnemy return;
spawner.numSpawned ++;
spawner.numAlive ++;
if (spawner.numAlive > 0) if (spawner.numAlive <= 0)
spawner.enabled = false; spawner.enabled = true;
if (!spawner.enabled)
return;
console.log("cooldown", spawner.cooldown);
if (spawner.cooldown == -1){
spawner.cooldown = Math.random() * 60;
spawner.cooldown /= 4;
}
spawner.cooldown -= es.Time.deltaTime;
if (spawner.cooldown <= 0){
spawner.cooldown = Math.random() * 60;
// CreateEnemy
spawner.numSpawned ++;
spawner.numAlive ++;
if (spawner.numAlive > 0)
spawner.enabled = false;
}
} }
} }
} }
+3 -3
View File
@@ -248,7 +248,6 @@ declare module es {
} }
declare module es { declare module es {
class Core extends egret.DisplayObjectContainer { class Core extends egret.DisplayObjectContainer {
static activeSceneChanged: Function;
static emitter: Emitter<CoreEvents>; static emitter: Emitter<CoreEvents>;
static graphicsDevice: GraphicsDevice; static graphicsDevice: GraphicsDevice;
static content: ContentManager; static content: ContentManager;
@@ -260,6 +259,7 @@ declare module es {
_globalManagers: GlobalManager[]; _globalManagers: GlobalManager[];
static scene: Scene; static scene: Scene;
constructor(); constructor();
private onAddToStage;
onOrientationChanged(): void; onOrientationChanged(): void;
protected onGraphicsDeviceReset(): void; protected onGraphicsDeviceReset(): void;
protected initialize(): void; protected initialize(): void;
@@ -269,7 +269,6 @@ declare module es {
endDebugUpdate(): void; endDebugUpdate(): void;
onSceneChanged(): void; onSceneChanged(): void;
static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T; static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T;
static registerActiveSceneChanged(current: Scene, next: Scene): void;
static registerGlobalManager(manager: es.GlobalManager): void; static registerGlobalManager(manager: es.GlobalManager): void;
static unregisterGlobalManager(manager: es.GlobalManager): void; static unregisterGlobalManager(manager: es.GlobalManager): void;
static getGlobalManager<T extends es.GlobalManager>(type: any): T; static getGlobalManager<T extends es.GlobalManager>(type: any): T;
@@ -1679,7 +1678,8 @@ declare module es {
static readonly logSnapDuration: number; static readonly logSnapDuration: number;
static readonly barPadding: number; static readonly barPadding: number;
static readonly autoAdjustDelay: number; static readonly autoAdjustDelay: number;
static Instance: TimeRuler; private static _instance;
static readonly Instance: TimeRuler;
private _frameKey; private _frameKey;
private _logKey; private _logKey;
private _logs; private _logs;
+22 -12
View File
@@ -1105,13 +1105,8 @@ var es;
_this._globalManagers = []; _this._globalManagers = [];
Core._instance = _this; Core._instance = _this;
Core.emitter = new es.Emitter(); Core.emitter = new es.Emitter();
Core.graphicsDevice = new es.GraphicsDevice();
Core.content = new es.ContentManager(); Core.content = new es.ContentManager();
_this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.initialize, _this); _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this);
_this.addEventListener(egret.Event.RESIZE, _this.onGraphicsDeviceReset, _this);
_this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, _this.onOrientationChanged, _this);
_this.addEventListener(egret.Event.ENTER_FRAME, _this.update, _this);
_this.addEventListener(egret.Event.RENDER, _this.draw, _this);
return _this; return _this;
} }
Object.defineProperty(Core, "Instance", { Object.defineProperty(Core, "Instance", {
@@ -1123,6 +1118,8 @@ var es;
}); });
Object.defineProperty(Core, "scene", { Object.defineProperty(Core, "scene", {
get: function () { get: function () {
if (!this._instance)
return null;
return this._instance._scene; return this._instance._scene;
}, },
set: function (value) { set: function (value) {
@@ -1138,11 +1135,18 @@ var es;
else { else {
this._instance._nextScene = value; this._instance._nextScene = value;
} }
this.registerActiveSceneChanged(this._instance._scene, this._instance._nextScene);
}, },
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
Core.prototype.onAddToStage = function () {
Core.graphicsDevice = new es.GraphicsDevice();
this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this);
this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this);
this.addEventListener(egret.Event.ENTER_FRAME, this.update, this);
this.addEventListener(egret.Event.RENDER, this.draw, this);
this.initialize();
};
Core.prototype.onOrientationChanged = function () { Core.prototype.onOrientationChanged = function () {
Core.emitter.emit(es.CoreEvents.OrientationChanged); Core.emitter.emit(es.CoreEvents.OrientationChanged);
}; };
@@ -1228,10 +1232,6 @@ var es;
this._instance._sceneTransition = sceneTransition; this._instance._sceneTransition = sceneTransition;
return sceneTransition; return sceneTransition;
}; };
Core.registerActiveSceneChanged = function (current, next) {
if (this.activeSceneChanged)
this.activeSceneChanged(current, next);
};
Core.registerGlobalManager = function (manager) { Core.registerGlobalManager = function (manager) {
this._instance._globalManagers.push(manager); this._instance._globalManagers.push(manager);
manager.enabled = true; manager.enabled = true;
@@ -4308,6 +4308,8 @@ var es;
this.platformInitialize(device); this.platformInitialize(device);
}; };
GraphicsCapabilities.prototype.platformInitialize = function (device) { GraphicsCapabilities.prototype.platformInitialize = function (device) {
if (GraphicsCapabilities.runtimeType != egret.RuntimeType.WXGAME)
return;
var capabilities = this; var capabilities = this;
capabilities["isMobile"] = true; capabilities["isMobile"] = true;
var systemInfo = wx.getSystemInfoSync(); var systemInfo = wx.getSystemInfoSync();
@@ -7570,7 +7572,6 @@ var es;
this.stopwacth = new stopwatch.Stopwatch(); this.stopwacth = new stopwatch.Stopwatch();
this._markerNameToIdMap = new Map(); this._markerNameToIdMap = new Map();
this.showLog = false; this.showLog = false;
TimeRuler.Instance = this;
this._logs = new Array(2); this._logs = new Array(2);
for (var i = 0; i < this._logs.length; ++i) for (var i = 0; i < this._logs.length; ++i)
this._logs[i] = new FrameLog(); this._logs[i] = new FrameLog();
@@ -7579,6 +7580,15 @@ var es;
es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this); es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this);
this.onGraphicsDeviceReset(); this.onGraphicsDeviceReset();
} }
Object.defineProperty(TimeRuler, "Instance", {
get: function () {
if (!this._instance)
this._instance = new TimeRuler();
return this._instance;
},
enumerable: true,
configurable: true
});
TimeRuler.prototype.onGraphicsDeviceReset = function () { TimeRuler.prototype.onGraphicsDeviceReset = function () {
var layout = new es.Layout(); var layout = new es.Layout();
this._position = layout.place(new es.Vector2(this.width, TimeRuler.barHeight), 0, 0.01, es.Alignment.bottomCenter).location; this._position = layout.place(new es.Vector2(this.width, TimeRuler.barHeight), 0, 0.01, es.Alignment.bottomCenter).location;
+1 -1
View File
File diff suppressed because one or more lines are too long
+10 -13
View File
@@ -3,10 +3,6 @@ module es {
* *
*/ */
export class Core extends egret.DisplayObjectContainer { export class Core extends egret.DisplayObjectContainer {
/**
*
*/
public static activeSceneChanged: Function;
/** /**
* *
*/ */
@@ -44,6 +40,8 @@ module es {
* *
*/ */
public static get scene() { public static get scene() {
if (!this._instance)
return null;
return this._instance._scene; return this._instance._scene;
} }
@@ -64,8 +62,6 @@ module es {
} else { } else {
this._instance._nextScene = value; this._instance._nextScene = value;
} }
this.registerActiveSceneChanged(this._instance._scene, this._instance._nextScene);
} }
constructor() { constructor() {
@@ -73,14 +69,20 @@ module es {
Core._instance = this; Core._instance = this;
Core.emitter = new Emitter<CoreEvents>(); Core.emitter = new Emitter<CoreEvents>();
Core.graphicsDevice = new GraphicsDevice();
Core.content = new ContentManager(); Core.content = new ContentManager();
this.addEventListener(egret.Event.ADDED_TO_STAGE, this.initialize, this); this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
}
private onAddToStage(){
Core.graphicsDevice = new GraphicsDevice();
this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this); this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this);
this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this); this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this);
this.addEventListener(egret.Event.ENTER_FRAME, this.update, this); this.addEventListener(egret.Event.ENTER_FRAME, this.update, this);
this.addEventListener(egret.Event.RENDER, this.draw, this); this.addEventListener(egret.Event.RENDER, this.draw, this);
this.initialize();
} }
public onOrientationChanged(){ public onOrientationChanged(){
@@ -190,11 +192,6 @@ module es {
return sceneTransition; return sceneTransition;
} }
public static registerActiveSceneChanged(current: Scene, next: Scene){
if (this.activeSceneChanged)
this.activeSceneChanged(current, next);
}
/** /**
* *
* @param manager * @param manager
@@ -6,6 +6,8 @@ module es {
} }
private platformInitialize(device: GraphicsDevice){ private platformInitialize(device: GraphicsDevice){
if (GraphicsCapabilities.runtimeType != egret.RuntimeType.WXGAME)
return;
let capabilities = this; let capabilities = this;
capabilities["isMobile"] = true; capabilities["isMobile"] = true;
+6 -2
View File
@@ -17,7 +17,12 @@ module es {
public static readonly logSnapDuration = 120; public static readonly logSnapDuration = 120;
public static readonly barPadding = 2; public static readonly barPadding = 2;
public static readonly autoAdjustDelay = 30; public static readonly autoAdjustDelay = 30;
public static Instance: TimeRuler; private static _instance;
public static get Instance(): TimeRuler{
if (!this._instance)
this._instance = new TimeRuler();
return this._instance;
}
private _frameKey = 'frame'; private _frameKey = 'frame';
private _logKey = 'log'; private _logKey = 'log';
@@ -56,7 +61,6 @@ module es {
private _frameAdjust: number; private _frameAdjust: number;
constructor() { constructor() {
TimeRuler.Instance = this;
this._logs = new Array<FrameLog>(2); this._logs = new Array<FrameLog>(2);
for (let i = 0; i < this._logs.length; ++i) for (let i = 0; i < this._logs.length; ++i)
this._logs[i] = new FrameLog(); this._logs[i] = new FrameLog();