移除Graphics相关
This commit is contained in:
178
source/bin/framework.d.ts
vendored
178
source/bin/framework.d.ts
vendored
@@ -88,7 +88,6 @@ declare module es {
|
|||||||
*/
|
*/
|
||||||
static entitySystemsEnabled: boolean;
|
static entitySystemsEnabled: boolean;
|
||||||
_nextScene: Scene;
|
_nextScene: Scene;
|
||||||
_sceneTransition: SceneTransition;
|
|
||||||
/**
|
/**
|
||||||
* 用于凝聚GraphicsDeviceReset事件
|
* 用于凝聚GraphicsDeviceReset事件
|
||||||
*/
|
*/
|
||||||
@@ -119,11 +118,6 @@ declare module es {
|
|||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
static scene: Scene;
|
static scene: Scene;
|
||||||
/**
|
|
||||||
* 临时运行SceneTransition,允许一个场景过渡到另一个平滑的自定义效果。
|
|
||||||
* @param sceneTransition
|
|
||||||
*/
|
|
||||||
static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T;
|
|
||||||
/**
|
/**
|
||||||
* 添加一个全局管理器对象,它的更新方法将调用场景前的每一帧。
|
* 添加一个全局管理器对象,它的更新方法将调用场景前的每一帧。
|
||||||
* @param manager
|
* @param manager
|
||||||
@@ -148,7 +142,6 @@ declare module es {
|
|||||||
*/
|
*/
|
||||||
static schedule(timeInSeconds: number, repeats: boolean, context: any, onTime: (timer: ITimer) => void): Timer;
|
static schedule(timeInSeconds: number, repeats: boolean, context: any, onTime: (timer: ITimer) => void): Timer;
|
||||||
onOrientationChanged(): void;
|
onOrientationChanged(): void;
|
||||||
draw(): Promise<void>;
|
|
||||||
startDebugDraw(): void;
|
startDebugDraw(): void;
|
||||||
/**
|
/**
|
||||||
* 在一个场景结束后,下一个场景开始之前调用
|
* 在一个场景结束后,下一个场景开始之前调用
|
||||||
@@ -354,16 +347,11 @@ declare module es {
|
|||||||
* 这个场景中的实体列表
|
* 这个场景中的实体列表
|
||||||
*/
|
*/
|
||||||
readonly entities: EntityList;
|
readonly entities: EntityList;
|
||||||
/**
|
|
||||||
* 管理当前在场景实体上的所有可呈现组件的列表
|
|
||||||
*/
|
|
||||||
readonly renderableComponents: RenderableComponentList;
|
|
||||||
/**
|
/**
|
||||||
* 管理所有实体处理器
|
* 管理所有实体处理器
|
||||||
*/
|
*/
|
||||||
readonly entityProcessors: EntityProcessorList;
|
readonly entityProcessors: EntityProcessorList;
|
||||||
readonly _sceneComponents: FastList<SceneComponent>;
|
readonly _sceneComponents: FastList<SceneComponent>;
|
||||||
_renderers: Renderer[];
|
|
||||||
_didSceneBegin: any;
|
_didSceneBegin: any;
|
||||||
constructor();
|
constructor();
|
||||||
/**
|
/**
|
||||||
@@ -384,12 +372,6 @@ declare module es {
|
|||||||
end(): void;
|
end(): void;
|
||||||
updateResolutionScaler(): void;
|
updateResolutionScaler(): void;
|
||||||
update(): void;
|
update(): void;
|
||||||
render(): void;
|
|
||||||
/**
|
|
||||||
* 现在的任何后处理器都要完成它的处理
|
|
||||||
* 只有在SceneTransition请求渲染时,它才会有一个值。
|
|
||||||
*/
|
|
||||||
postRender(): void;
|
|
||||||
/**
|
/**
|
||||||
* 向组件列表添加并返回SceneComponent
|
* 向组件列表添加并返回SceneComponent
|
||||||
* @param component
|
* @param component
|
||||||
@@ -410,21 +392,6 @@ declare module es {
|
|||||||
* @param component
|
* @param component
|
||||||
*/
|
*/
|
||||||
removeSceneComponent(component: SceneComponent): void;
|
removeSceneComponent(component: SceneComponent): void;
|
||||||
/**
|
|
||||||
* 为场景添加一个渲染器
|
|
||||||
* @param renderer
|
|
||||||
*/
|
|
||||||
addRenderer<T extends Renderer>(renderer: T): T;
|
|
||||||
/**
|
|
||||||
* 获取类型为T的第一个渲染器
|
|
||||||
* @param type
|
|
||||||
*/
|
|
||||||
getRenderer<T extends Renderer>(type: any): T;
|
|
||||||
/**
|
|
||||||
* 从场景中移除渲染器
|
|
||||||
* @param renderer
|
|
||||||
*/
|
|
||||||
removeRenderer(renderer: Renderer): void;
|
|
||||||
/**
|
/**
|
||||||
* 将实体添加到此场景,并返回它
|
* 将实体添加到此场景,并返回它
|
||||||
* @param name
|
* @param name
|
||||||
@@ -1389,73 +1356,6 @@ declare module es {
|
|||||||
one(...types: any[]): this;
|
one(...types: any[]): this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
|
||||||
/**
|
|
||||||
* 当该接口应用到组件时,它将注册组件以场景渲染器显示
|
|
||||||
* 该接口请谨慎实现
|
|
||||||
*/
|
|
||||||
interface IRenderable {
|
|
||||||
/**
|
|
||||||
* 对象的AABB用于相机剔除
|
|
||||||
*/
|
|
||||||
bounds: Rectangle;
|
|
||||||
/**
|
|
||||||
* 这个组件是否应该被渲染
|
|
||||||
*/
|
|
||||||
enabled: boolean;
|
|
||||||
/**
|
|
||||||
* 较低的渲染层在前面,较高的在后面
|
|
||||||
*/
|
|
||||||
renderLayer: number;
|
|
||||||
/**
|
|
||||||
* 可渲染的可见性。状态的改变会调用onBecameVisible/onBecameInvisible方法
|
|
||||||
*/
|
|
||||||
isVisible: boolean;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 用于排序IRenderables的比较器
|
|
||||||
*/
|
|
||||||
class RenderableComparer {
|
|
||||||
compare(self: IRenderable, other: IRenderable): number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare module es {
|
|
||||||
class RenderableComponentList {
|
|
||||||
/**
|
|
||||||
* IRenderable列表的全局updatePrder排序
|
|
||||||
*/
|
|
||||||
static compareUpdatableOrder: RenderableComparer;
|
|
||||||
/**
|
|
||||||
* 添加到实体的组件列表
|
|
||||||
*/
|
|
||||||
_components: IRenderable[];
|
|
||||||
/**
|
|
||||||
* 通过渲染层跟踪组件,便于检索
|
|
||||||
*/
|
|
||||||
_componentsByRenderLayer: Map<number, IRenderable[]>;
|
|
||||||
_unsortedRenderLayers: number[];
|
|
||||||
private _componentsNeedSort;
|
|
||||||
componentsNeedSort: boolean;
|
|
||||||
readonly count: number;
|
|
||||||
readonly buffer: IRenderable[];
|
|
||||||
add(component: IRenderable): void;
|
|
||||||
remove(component: IRenderable): void;
|
|
||||||
updateRenderableRenderLayer(component: IRenderable, oldRenderLayer: number, newRenderLayer: number): void;
|
|
||||||
/**
|
|
||||||
* 将渲染层排序标志弄脏,让所有组件重新排序
|
|
||||||
* @param renderLayer
|
|
||||||
*/
|
|
||||||
setRenderLayerNeedsComponentSort(renderLayer: number): void;
|
|
||||||
setNeedsComponentSort(): void;
|
|
||||||
addToRenderLayerList(component: IRenderable, renderLayer: number): void;
|
|
||||||
/**
|
|
||||||
* 使用给定的渲染层获取所有组件。组件列表是预先排序的
|
|
||||||
* @param renderLayer
|
|
||||||
*/
|
|
||||||
componentsWithRenderLayer(renderLayer: number): IRenderable[];
|
|
||||||
updateList(): void;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare class StringUtils {
|
declare class StringUtils {
|
||||||
/**
|
/**
|
||||||
* 特殊符号字符串
|
* 特殊符号字符串
|
||||||
@@ -1646,84 +1546,6 @@ declare class TimeUtils {
|
|||||||
*/
|
*/
|
||||||
static timeToMillisecond(time: string, partition?: string): string;
|
static timeToMillisecond(time: string, partition?: string): string;
|
||||||
}
|
}
|
||||||
declare module es {
|
|
||||||
class Viewport {
|
|
||||||
private _x;
|
|
||||||
private _y;
|
|
||||||
private _minDepth;
|
|
||||||
private _maxDepth;
|
|
||||||
constructor(x: number, y: number, width: number, height: number);
|
|
||||||
private _width;
|
|
||||||
width: number;
|
|
||||||
private _height;
|
|
||||||
height: number;
|
|
||||||
readonly aspectRatio: number;
|
|
||||||
bounds: Rectangle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare module es {
|
|
||||||
/**
|
|
||||||
* 渲染器被添加到场景中并处理所有对RenderableComponent的实际调用
|
|
||||||
*/
|
|
||||||
abstract class Renderer {
|
|
||||||
/**
|
|
||||||
* 指定场景调用渲染器的顺序
|
|
||||||
*/
|
|
||||||
readonly renderOrder: number;
|
|
||||||
/**
|
|
||||||
* 这个渲染器的标志,决定它是否应该调试渲染。
|
|
||||||
* render方法接收一个bool (debugRenderEnabled),让渲染器知道全局调试渲染是否打开/关闭。
|
|
||||||
* 渲染器然后使用本地bool来决定它是否应该调试渲染。
|
|
||||||
*/
|
|
||||||
shouldDebugRender: boolean;
|
|
||||||
protected constructor(renderOrder: number);
|
|
||||||
/**
|
|
||||||
* 当渲染器被添加到场景时调用
|
|
||||||
* @param scene
|
|
||||||
*/
|
|
||||||
onAddedToScene(scene: Scene): void;
|
|
||||||
/**
|
|
||||||
* 当场景结束或渲染器从场景中移除时调用。使用这个进行清理。
|
|
||||||
*/
|
|
||||||
unload(): void;
|
|
||||||
abstract render(scene: Scene): any;
|
|
||||||
/**
|
|
||||||
* 当默认场景渲染目标被调整大小和当场景已经开始添加渲染器时调用
|
|
||||||
* @param newWidth
|
|
||||||
* @param newHeight
|
|
||||||
*/
|
|
||||||
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
|
|
||||||
compareTo(other: Renderer): number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare module es {
|
|
||||||
/**
|
|
||||||
* SceneTransition用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡
|
|
||||||
*/
|
|
||||||
abstract class SceneTransition {
|
|
||||||
/** 是否加载新场景的标志 */
|
|
||||||
loadsNewScene: boolean;
|
|
||||||
/**
|
|
||||||
* 将此用于两个部分的转换。例如,淡出会先淡出到黑色,然后当isNewSceneLoaded为true,它会淡出。
|
|
||||||
* 对于场景过渡,isNewSceneLoaded应该在中点设置为true,这就标识一个新的场景被加载了。
|
|
||||||
*/
|
|
||||||
isNewSceneLoaded: boolean;
|
|
||||||
/** 在loadNextScene执行时调用。这在进行场景间过渡时很有用,这样你就知道什么时候可以更多地使用相机或者重置任何实体 */
|
|
||||||
onScreenObscured: Function;
|
|
||||||
/** 当转换完成执行时调用,以便可以调用其他工作,比如启动另一个转换。 */
|
|
||||||
onTransitionCompleted: Function;
|
|
||||||
/** 返回新加载场景的函数 */
|
|
||||||
protected sceneLoadAction: Function;
|
|
||||||
constructor(sceneLoadAction: Function);
|
|
||||||
private _hasPreviousSceneRender;
|
|
||||||
readonly hasPreviousSceneRender: boolean;
|
|
||||||
preRender(): void;
|
|
||||||
render(): void;
|
|
||||||
onBeginTransition(): Promise<void>;
|
|
||||||
protected transitionComplete(): void;
|
|
||||||
protected loadNextScene(): Promise<void>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare module es {
|
declare module es {
|
||||||
/** 贝塞尔帮助类 */
|
/** 贝塞尔帮助类 */
|
||||||
class Bezier {
|
class Bezier {
|
||||||
|
|||||||
@@ -220,18 +220,6 @@ var es;
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
/**
|
|
||||||
* 临时运行SceneTransition,允许一个场景过渡到另一个平滑的自定义效果。
|
|
||||||
* @param sceneTransition
|
|
||||||
*/
|
|
||||||
Core.startSceneTransition = function (sceneTransition) {
|
|
||||||
if (this._instance._sceneTransition) {
|
|
||||||
console.warn("在前一个场景完成之前,不能开始一个新的场景转换。");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._instance._sceneTransition = sceneTransition;
|
|
||||||
return sceneTransition;
|
|
||||||
};
|
|
||||||
/**
|
/**
|
||||||
* 添加一个全局管理器对象,它的更新方法将调用场景前的每一帧。
|
* 添加一个全局管理器对象,它的更新方法将调用场景前的每一帧。
|
||||||
* @param manager
|
* @param manager
|
||||||
@@ -274,44 +262,6 @@ var es;
|
|||||||
Core.prototype.onOrientationChanged = function () {
|
Core.prototype.onOrientationChanged = function () {
|
||||||
Core.emitter.emit(es.CoreEvents.OrientationChanged);
|
Core.emitter.emit(es.CoreEvents.OrientationChanged);
|
||||||
};
|
};
|
||||||
Core.prototype.draw = function () {
|
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
|
||||||
return __generator(this, function (_a) {
|
|
||||||
switch (_a.label) {
|
|
||||||
case 0:
|
|
||||||
this.startDebugDraw();
|
|
||||||
if (!(this._sceneTransition != null)) return [3 /*break*/, 5];
|
|
||||||
this._sceneTransition.preRender();
|
|
||||||
if (!(this._sceneTransition != null)) return [3 /*break*/, 4];
|
|
||||||
if (!(this._scene != null && !this._sceneTransition.hasPreviousSceneRender)) return [3 /*break*/, 2];
|
|
||||||
this._scene.render();
|
|
||||||
this._scene.postRender();
|
|
||||||
return [4 /*yield*/, this._sceneTransition.onBeginTransition()];
|
|
||||||
case 1:
|
|
||||||
_a.sent();
|
|
||||||
return [3 /*break*/, 3];
|
|
||||||
case 2:
|
|
||||||
if (this._scene != null && this._sceneTransition.isNewSceneLoaded) {
|
|
||||||
this._scene.render();
|
|
||||||
this._scene.postRender();
|
|
||||||
}
|
|
||||||
_a.label = 3;
|
|
||||||
case 3:
|
|
||||||
this._sceneTransition.render();
|
|
||||||
_a.label = 4;
|
|
||||||
case 4: return [3 /*break*/, 6];
|
|
||||||
case 5:
|
|
||||||
if (this._scene) {
|
|
||||||
this._scene.render();
|
|
||||||
// 如如果我们没有一个活动的SceneTransition,就像往常一样渲染
|
|
||||||
this._scene.postRender();
|
|
||||||
}
|
|
||||||
_a.label = 6;
|
|
||||||
case 6: return [2 /*return*/];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Core.prototype.startDebugDraw = function () {
|
Core.prototype.startDebugDraw = function () {
|
||||||
this._frameCounter++;
|
this._frameCounter++;
|
||||||
this._frameCounterElapsedTime += es.Time.deltaTime;
|
this._frameCounterElapsedTime += es.Time.deltaTime;
|
||||||
@@ -354,8 +304,6 @@ var es;
|
|||||||
return __awaiter(this, void 0, void 0, function () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
var i;
|
var i;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
|
||||||
case 0:
|
|
||||||
if (currentTime != null)
|
if (currentTime != null)
|
||||||
es.Time.update(currentTime);
|
es.Time.update(currentTime);
|
||||||
if (this._scene != null) {
|
if (this._scene != null) {
|
||||||
@@ -363,15 +311,7 @@ var es;
|
|||||||
if (this._globalManagers.buffer[i].enabled)
|
if (this._globalManagers.buffer[i].enabled)
|
||||||
this._globalManagers.buffer[i].update();
|
this._globalManagers.buffer[i].update();
|
||||||
}
|
}
|
||||||
// 仔细阅读:
|
|
||||||
// 当场景转换发生时,我们不更新场景
|
|
||||||
// - 除非是不改变场景的SceneTransition(没有理由不更新)
|
|
||||||
// - 或者是一个已经切换到新场景的SceneTransition(新场景需要做它的事情)
|
|
||||||
if (this._sceneTransition == null ||
|
|
||||||
(this._sceneTransition != null &&
|
|
||||||
(!this._sceneTransition.loadsNewScene || this._sceneTransition.isNewSceneLoaded))) {
|
|
||||||
this._scene.update();
|
this._scene.update();
|
||||||
}
|
|
||||||
if (this._nextScene != null) {
|
if (this._nextScene != null) {
|
||||||
this._scene.end();
|
this._scene.end();
|
||||||
this._scene = this._nextScene;
|
this._scene = this._nextScene;
|
||||||
@@ -380,11 +320,8 @@ var es;
|
|||||||
this._scene.begin();
|
this._scene.begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [4 /*yield*/, this.draw()];
|
this.startDebugDraw();
|
||||||
case 1:
|
|
||||||
_a.sent();
|
|
||||||
return [2 /*return*/];
|
return [2 /*return*/];
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -828,9 +765,7 @@ var es;
|
|||||||
var Scene = /** @class */ (function () {
|
var Scene = /** @class */ (function () {
|
||||||
function Scene() {
|
function Scene() {
|
||||||
this._sceneComponents = new es.FastList();
|
this._sceneComponents = new es.FastList();
|
||||||
this._renderers = [];
|
|
||||||
this.entities = new es.EntityList(this);
|
this.entities = new es.EntityList(this);
|
||||||
this.renderableComponents = new es.RenderableComponentList();
|
|
||||||
if (es.Core.entitySystemsEnabled)
|
if (es.Core.entitySystemsEnabled)
|
||||||
this.entityProcessors = new es.EntityProcessorList();
|
this.entityProcessors = new es.EntityProcessorList();
|
||||||
this.initialize();
|
this.initialize();
|
||||||
@@ -869,9 +804,6 @@ var es;
|
|||||||
};
|
};
|
||||||
Scene.prototype.end = function () {
|
Scene.prototype.end = function () {
|
||||||
this._didSceneBegin = false;
|
this._didSceneBegin = false;
|
||||||
for (var i = 0; i < this._renderers.length; i++) {
|
|
||||||
this._renderers[i].unload();
|
|
||||||
}
|
|
||||||
es.Core.emitter.removeObserver(es.CoreEvents.GraphicsDeviceReset, this.updateResolutionScaler);
|
es.Core.emitter.removeObserver(es.CoreEvents.GraphicsDeviceReset, this.updateResolutionScaler);
|
||||||
es.Core.emitter.removeObserver(es.CoreEvents.OrientationChanged, this.updateResolutionScaler);
|
es.Core.emitter.removeObserver(es.CoreEvents.OrientationChanged, this.updateResolutionScaler);
|
||||||
this.entities.removeAllEntities();
|
this.entities.removeAllEntities();
|
||||||
@@ -900,19 +832,6 @@ var es;
|
|||||||
this.entities.update();
|
this.entities.update();
|
||||||
if (this.entityProcessors != null)
|
if (this.entityProcessors != null)
|
||||||
this.entityProcessors.lateUpdate();
|
this.entityProcessors.lateUpdate();
|
||||||
// 我们在entity.update之后更新我们的renderables,以防止任何新的Renderables被添加
|
|
||||||
this.renderableComponents.updateList();
|
|
||||||
};
|
|
||||||
Scene.prototype.render = function () {
|
|
||||||
for (var i = 0; i < this._renderers.length; i++) {
|
|
||||||
this._renderers[i].render(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 现在的任何后处理器都要完成它的处理
|
|
||||||
* 只有在SceneTransition请求渲染时,它才会有一个值。
|
|
||||||
*/
|
|
||||||
Scene.prototype.postRender = function () {
|
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 向组件列表添加并返回SceneComponent
|
* 向组件列表添加并返回SceneComponent
|
||||||
@@ -959,38 +878,6 @@ var es;
|
|||||||
this._sceneComponents.remove(component);
|
this._sceneComponents.remove(component);
|
||||||
component.onRemovedFromScene();
|
component.onRemovedFromScene();
|
||||||
};
|
};
|
||||||
/**
|
|
||||||
* 为场景添加一个渲染器
|
|
||||||
* @param renderer
|
|
||||||
*/
|
|
||||||
Scene.prototype.addRenderer = function (renderer) {
|
|
||||||
this._renderers.push(renderer);
|
|
||||||
this._renderers.sort();
|
|
||||||
renderer.onAddedToScene(this);
|
|
||||||
return renderer;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 获取类型为T的第一个渲染器
|
|
||||||
* @param type
|
|
||||||
*/
|
|
||||||
Scene.prototype.getRenderer = function (type) {
|
|
||||||
for (var i = 0; i < this._renderers.length; i++) {
|
|
||||||
if (this._renderers[i] instanceof type)
|
|
||||||
return this._renderers[i];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 从场景中移除渲染器
|
|
||||||
* @param renderer
|
|
||||||
*/
|
|
||||||
Scene.prototype.removeRenderer = function (renderer) {
|
|
||||||
var rendererList = new linq.List(this._renderers);
|
|
||||||
if (!rendererList.contains(renderer))
|
|
||||||
return;
|
|
||||||
rendererList.remove(renderer);
|
|
||||||
renderer.unload();
|
|
||||||
};
|
|
||||||
/**
|
/**
|
||||||
* 将实体添加到此场景,并返回它
|
* 将实体添加到此场景,并返回它
|
||||||
* @param name
|
* @param name
|
||||||
@@ -3542,136 +3429,6 @@ var es;
|
|||||||
}());
|
}());
|
||||||
es.Matcher = Matcher;
|
es.Matcher = Matcher;
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
|
||||||
(function (es) {
|
|
||||||
/**
|
|
||||||
* 用于排序IRenderables的比较器
|
|
||||||
*/
|
|
||||||
var RenderableComparer = /** @class */ (function () {
|
|
||||||
function RenderableComparer() {
|
|
||||||
}
|
|
||||||
RenderableComparer.prototype.compare = function (self, other) {
|
|
||||||
return other.renderLayer - self.renderLayer;
|
|
||||||
};
|
|
||||||
return RenderableComparer;
|
|
||||||
}());
|
|
||||||
es.RenderableComparer = RenderableComparer;
|
|
||||||
})(es || (es = {}));
|
|
||||||
///<reference path="../../Graphics/Renderers/IRenderable.ts" />
|
|
||||||
var es;
|
|
||||||
///<reference path="../../Graphics/Renderers/IRenderable.ts" />
|
|
||||||
(function (es) {
|
|
||||||
var RenderableComponentList = /** @class */ (function () {
|
|
||||||
function RenderableComponentList() {
|
|
||||||
/**
|
|
||||||
* 添加到实体的组件列表
|
|
||||||
*/
|
|
||||||
this._components = [];
|
|
||||||
/**
|
|
||||||
* 通过渲染层跟踪组件,便于检索
|
|
||||||
*/
|
|
||||||
this._componentsByRenderLayer = new Map();
|
|
||||||
this._unsortedRenderLayers = [];
|
|
||||||
this._componentsNeedSort = true;
|
|
||||||
}
|
|
||||||
Object.defineProperty(RenderableComponentList.prototype, "componentsNeedSort", {
|
|
||||||
get: function () {
|
|
||||||
return this._componentsNeedSort;
|
|
||||||
},
|
|
||||||
set: function (value) {
|
|
||||||
this._componentsNeedSort = value;
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
Object.defineProperty(RenderableComponentList.prototype, "count", {
|
|
||||||
get: function () {
|
|
||||||
return this._components.length;
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
Object.defineProperty(RenderableComponentList.prototype, "buffer", {
|
|
||||||
get: function () {
|
|
||||||
return this._components;
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
RenderableComponentList.prototype.add = function (component) {
|
|
||||||
this._components.push(component);
|
|
||||||
this.addToRenderLayerList(component, component.renderLayer);
|
|
||||||
};
|
|
||||||
RenderableComponentList.prototype.remove = function (component) {
|
|
||||||
new linq.List(this._components).remove(component);
|
|
||||||
new linq.List(this._componentsByRenderLayer.get(component.renderLayer)).remove(component);
|
|
||||||
};
|
|
||||||
RenderableComponentList.prototype.updateRenderableRenderLayer = function (component, oldRenderLayer, newRenderLayer) {
|
|
||||||
// 需要注意的是,如果渲染层在组件update之前发生了改变
|
|
||||||
var oldRenderLayers = new linq.List(this._componentsByRenderLayer.get(oldRenderLayer));
|
|
||||||
if (this._componentsByRenderLayer.has(oldRenderLayer) && oldRenderLayers.contains(component)) {
|
|
||||||
oldRenderLayers.remove(component);
|
|
||||||
this.addToRenderLayerList(component, newRenderLayer);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 将渲染层排序标志弄脏,让所有组件重新排序
|
|
||||||
* @param renderLayer
|
|
||||||
*/
|
|
||||||
RenderableComponentList.prototype.setRenderLayerNeedsComponentSort = function (renderLayer) {
|
|
||||||
var unsortedRenderLayers = new linq.List(this._unsortedRenderLayers);
|
|
||||||
if (!unsortedRenderLayers.contains(renderLayer))
|
|
||||||
unsortedRenderLayers.add(renderLayer);
|
|
||||||
this.componentsNeedSort = true;
|
|
||||||
};
|
|
||||||
RenderableComponentList.prototype.setNeedsComponentSort = function () {
|
|
||||||
this.componentsNeedSort = true;
|
|
||||||
};
|
|
||||||
RenderableComponentList.prototype.addToRenderLayerList = function (component, renderLayer) {
|
|
||||||
var list = new linq.List(this.componentsWithRenderLayer(renderLayer));
|
|
||||||
if (list.contains(component)) {
|
|
||||||
console.warn("组件呈现层列表已经包含此组件");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
list.add(component);
|
|
||||||
var unsortedRenderLayers = new linq.List(this._unsortedRenderLayers);
|
|
||||||
if (!unsortedRenderLayers.contains(renderLayer))
|
|
||||||
unsortedRenderLayers.add(renderLayer);
|
|
||||||
this.componentsNeedSort = true;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 使用给定的渲染层获取所有组件。组件列表是预先排序的
|
|
||||||
* @param renderLayer
|
|
||||||
*/
|
|
||||||
RenderableComponentList.prototype.componentsWithRenderLayer = function (renderLayer) {
|
|
||||||
if (!this._componentsByRenderLayer.get(renderLayer)) {
|
|
||||||
this._componentsByRenderLayer.set(renderLayer, []);
|
|
||||||
}
|
|
||||||
return this._componentsByRenderLayer.get(renderLayer);
|
|
||||||
};
|
|
||||||
RenderableComponentList.prototype.updateList = function () {
|
|
||||||
if (this.componentsNeedSort) {
|
|
||||||
this._components.sort(RenderableComponentList.compareUpdatableOrder.compare);
|
|
||||||
this.componentsNeedSort = false;
|
|
||||||
}
|
|
||||||
if (this._unsortedRenderLayers.length > 0) {
|
|
||||||
for (var i = 0, count = this._unsortedRenderLayers.length; i < count; i++) {
|
|
||||||
var renderLayerComponents = this._componentsByRenderLayer.get(this._unsortedRenderLayers[i]);
|
|
||||||
if (renderLayerComponents) {
|
|
||||||
renderLayerComponents.sort(RenderableComponentList.compareUpdatableOrder.compare);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this._unsortedRenderLayers.length = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* IRenderable列表的全局updatePrder排序
|
|
||||||
*/
|
|
||||||
RenderableComponentList.compareUpdatableOrder = new es.RenderableComparer();
|
|
||||||
return RenderableComponentList;
|
|
||||||
}());
|
|
||||||
es.RenderableComponentList = RenderableComponentList;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var StringUtils = /** @class */ (function () {
|
var StringUtils = /** @class */ (function () {
|
||||||
function StringUtils() {
|
function StringUtils() {
|
||||||
}
|
}
|
||||||
@@ -4145,176 +3902,6 @@ var TimeUtils = /** @class */ (function () {
|
|||||||
return TimeUtils;
|
return TimeUtils;
|
||||||
}());
|
}());
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
|
||||||
var Viewport = /** @class */ (function () {
|
|
||||||
function Viewport(x, y, width, height) {
|
|
||||||
this._x = x;
|
|
||||||
this._y = y;
|
|
||||||
this._width = width;
|
|
||||||
this._height = height;
|
|
||||||
this._minDepth = 0;
|
|
||||||
this._maxDepth = 1;
|
|
||||||
}
|
|
||||||
Object.defineProperty(Viewport.prototype, "width", {
|
|
||||||
get: function () {
|
|
||||||
return this._width;
|
|
||||||
},
|
|
||||||
set: function (value) {
|
|
||||||
this._width = value;
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
Object.defineProperty(Viewport.prototype, "height", {
|
|
||||||
get: function () {
|
|
||||||
return this._height;
|
|
||||||
},
|
|
||||||
set: function (value) {
|
|
||||||
this._height = value;
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
Object.defineProperty(Viewport.prototype, "aspectRatio", {
|
|
||||||
get: function () {
|
|
||||||
if ((this._height != 0) && (this._width != 0))
|
|
||||||
return (this._width / this._height);
|
|
||||||
return 0;
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
Object.defineProperty(Viewport.prototype, "bounds", {
|
|
||||||
get: function () {
|
|
||||||
return new es.Rectangle(this._x, this._y, this._width, this._height);
|
|
||||||
},
|
|
||||||
set: function (value) {
|
|
||||||
this._x = value.x;
|
|
||||||
this._y = value.y;
|
|
||||||
this._width = value.width;
|
|
||||||
this._height = value.height;
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
return Viewport;
|
|
||||||
}());
|
|
||||||
es.Viewport = Viewport;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var es;
|
|
||||||
(function (es) {
|
|
||||||
/**
|
|
||||||
* 渲染器被添加到场景中并处理所有对RenderableComponent的实际调用
|
|
||||||
*/
|
|
||||||
var Renderer = /** @class */ (function () {
|
|
||||||
function Renderer(renderOrder) {
|
|
||||||
/**
|
|
||||||
* 指定场景调用渲染器的顺序
|
|
||||||
*/
|
|
||||||
this.renderOrder = 0;
|
|
||||||
/**
|
|
||||||
* 这个渲染器的标志,决定它是否应该调试渲染。
|
|
||||||
* render方法接收一个bool (debugRenderEnabled),让渲染器知道全局调试渲染是否打开/关闭。
|
|
||||||
* 渲染器然后使用本地bool来决定它是否应该调试渲染。
|
|
||||||
*/
|
|
||||||
this.shouldDebugRender = true;
|
|
||||||
this.renderOrder = renderOrder;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 当渲染器被添加到场景时调用
|
|
||||||
* @param scene
|
|
||||||
*/
|
|
||||||
Renderer.prototype.onAddedToScene = function (scene) {
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 当场景结束或渲染器从场景中移除时调用。使用这个进行清理。
|
|
||||||
*/
|
|
||||||
Renderer.prototype.unload = function () {
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 当默认场景渲染目标被调整大小和当场景已经开始添加渲染器时调用
|
|
||||||
* @param newWidth
|
|
||||||
* @param newHeight
|
|
||||||
*/
|
|
||||||
Renderer.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) {
|
|
||||||
};
|
|
||||||
Renderer.prototype.compareTo = function (other) {
|
|
||||||
return this.renderOrder - other.renderOrder;
|
|
||||||
};
|
|
||||||
return Renderer;
|
|
||||||
}());
|
|
||||||
es.Renderer = Renderer;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var es;
|
|
||||||
(function (es) {
|
|
||||||
/**
|
|
||||||
* SceneTransition用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡
|
|
||||||
*/
|
|
||||||
var SceneTransition = /** @class */ (function () {
|
|
||||||
function SceneTransition(sceneLoadAction) {
|
|
||||||
this.sceneLoadAction = sceneLoadAction;
|
|
||||||
this.loadsNewScene = sceneLoadAction != null;
|
|
||||||
}
|
|
||||||
Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", {
|
|
||||||
get: function () {
|
|
||||||
if (!this._hasPreviousSceneRender) {
|
|
||||||
this._hasPreviousSceneRender = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
SceneTransition.prototype.preRender = function () {
|
|
||||||
};
|
|
||||||
SceneTransition.prototype.render = function () {
|
|
||||||
};
|
|
||||||
SceneTransition.prototype.onBeginTransition = function () {
|
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
|
||||||
return __generator(this, function (_a) {
|
|
||||||
switch (_a.label) {
|
|
||||||
case 0: return [4 /*yield*/, this.loadNextScene()];
|
|
||||||
case 1:
|
|
||||||
_a.sent();
|
|
||||||
this.transitionComplete();
|
|
||||||
return [2 /*return*/];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
SceneTransition.prototype.transitionComplete = function () {
|
|
||||||
es.Core._instance._sceneTransition = null;
|
|
||||||
if (this.onTransitionCompleted) {
|
|
||||||
this.onTransitionCompleted();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
SceneTransition.prototype.loadNextScene = function () {
|
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
|
||||||
var _a;
|
|
||||||
return __generator(this, function (_b) {
|
|
||||||
switch (_b.label) {
|
|
||||||
case 0:
|
|
||||||
if (this.onScreenObscured)
|
|
||||||
this.onScreenObscured();
|
|
||||||
if (!this.loadsNewScene) {
|
|
||||||
this.isNewSceneLoaded = true;
|
|
||||||
}
|
|
||||||
_a = es.Core;
|
|
||||||
return [4 /*yield*/, this.sceneLoadAction()];
|
|
||||||
case 1:
|
|
||||||
_a.scene = _b.sent();
|
|
||||||
this.isNewSceneLoaded = true;
|
|
||||||
return [2 /*return*/];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
return SceneTransition;
|
|
||||||
}());
|
|
||||||
es.SceneTransition = SceneTransition;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var es;
|
|
||||||
(function (es) {
|
(function (es) {
|
||||||
/** 贝塞尔帮助类 */
|
/** 贝塞尔帮助类 */
|
||||||
var Bezier = /** @class */ (function () {
|
var Bezier = /** @class */ (function () {
|
||||||
|
|||||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -25,7 +25,6 @@ module es {
|
|||||||
public static entitySystemsEnabled: boolean;
|
public static entitySystemsEnabled: boolean;
|
||||||
|
|
||||||
public _nextScene: Scene;
|
public _nextScene: Scene;
|
||||||
public _sceneTransition: SceneTransition;
|
|
||||||
/**
|
/**
|
||||||
* 用于凝聚GraphicsDeviceReset事件
|
* 用于凝聚GraphicsDeviceReset事件
|
||||||
*/
|
*/
|
||||||
@@ -94,20 +93,6 @@ module es {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 临时运行SceneTransition,允许一个场景过渡到另一个平滑的自定义效果。
|
|
||||||
* @param sceneTransition
|
|
||||||
*/
|
|
||||||
public static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T {
|
|
||||||
if (this._instance._sceneTransition) {
|
|
||||||
console.warn("在前一个场景完成之前,不能开始一个新的场景转换。");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._instance._sceneTransition = sceneTransition;
|
|
||||||
return sceneTransition;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个全局管理器对象,它的更新方法将调用场景前的每一帧。
|
* 添加一个全局管理器对象,它的更新方法将调用场景前的每一帧。
|
||||||
* @param manager
|
* @param manager
|
||||||
@@ -153,34 +138,6 @@ module es {
|
|||||||
Core.emitter.emit(CoreEvents.OrientationChanged);
|
Core.emitter.emit(CoreEvents.OrientationChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async draw() {
|
|
||||||
this.startDebugDraw();
|
|
||||||
|
|
||||||
if (this._sceneTransition != null) {
|
|
||||||
this._sceneTransition.preRender();
|
|
||||||
|
|
||||||
// 如果有的话,我们会对SceneTransition进行特殊处理。
|
|
||||||
// 我们要么渲染SceneTransition,要么渲染Scene的
|
|
||||||
if (this._sceneTransition != null){
|
|
||||||
if (this._scene != null && !this._sceneTransition.hasPreviousSceneRender) {
|
|
||||||
this._scene.render();
|
|
||||||
this._scene.postRender();
|
|
||||||
await this._sceneTransition.onBeginTransition();
|
|
||||||
} else if (this._scene != null && this._sceneTransition.isNewSceneLoaded) {
|
|
||||||
this._scene.render();
|
|
||||||
this._scene.postRender();
|
|
||||||
}
|
|
||||||
|
|
||||||
this._sceneTransition.render();
|
|
||||||
}
|
|
||||||
} else if (this._scene) {
|
|
||||||
this._scene.render();
|
|
||||||
|
|
||||||
// 如如果我们没有一个活动的SceneTransition,就像往常一样渲染
|
|
||||||
this._scene.postRender();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public startDebugDraw() {
|
public startDebugDraw() {
|
||||||
this._frameCounter ++;
|
this._frameCounter ++;
|
||||||
this._frameCounterElapsedTime += Time.deltaTime;
|
this._frameCounterElapsedTime += Time.deltaTime;
|
||||||
@@ -230,15 +187,7 @@ module es {
|
|||||||
this._globalManagers.buffer[i].update();
|
this._globalManagers.buffer[i].update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 仔细阅读:
|
|
||||||
// 当场景转换发生时,我们不更新场景
|
|
||||||
// - 除非是不改变场景的SceneTransition(没有理由不更新)
|
|
||||||
// - 或者是一个已经切换到新场景的SceneTransition(新场景需要做它的事情)
|
|
||||||
if (this._sceneTransition == null ||
|
|
||||||
(this._sceneTransition != null &&
|
|
||||||
(!this._sceneTransition.loadsNewScene || this._sceneTransition.isNewSceneLoaded))) {
|
|
||||||
this._scene.update();
|
this._scene.update();
|
||||||
}
|
|
||||||
|
|
||||||
if (this._nextScene != null) {
|
if (this._nextScene != null) {
|
||||||
this._scene.end();
|
this._scene.end();
|
||||||
@@ -251,7 +200,7 @@ module es {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.draw();
|
this.startDebugDraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,22 +5,16 @@ module es {
|
|||||||
* 这个场景中的实体列表
|
* 这个场景中的实体列表
|
||||||
*/
|
*/
|
||||||
public readonly entities: EntityList;
|
public readonly entities: EntityList;
|
||||||
/**
|
|
||||||
* 管理当前在场景实体上的所有可呈现组件的列表
|
|
||||||
*/
|
|
||||||
public readonly renderableComponents: RenderableComponentList;
|
|
||||||
/**
|
/**
|
||||||
* 管理所有实体处理器
|
* 管理所有实体处理器
|
||||||
*/
|
*/
|
||||||
public readonly entityProcessors: EntityProcessorList;
|
public readonly entityProcessors: EntityProcessorList;
|
||||||
|
|
||||||
public readonly _sceneComponents: FastList<SceneComponent> = new FastList<SceneComponent>();
|
public readonly _sceneComponents: FastList<SceneComponent> = new FastList<SceneComponent>();
|
||||||
public _renderers: Renderer[] = [];
|
|
||||||
public _didSceneBegin;
|
public _didSceneBegin;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.entities = new EntityList(this);
|
this.entities = new EntityList(this);
|
||||||
this.renderableComponents = new RenderableComponentList();
|
|
||||||
|
|
||||||
if (Core.entitySystemsEnabled)
|
if (Core.entitySystemsEnabled)
|
||||||
this.entityProcessors = new EntityProcessorList();
|
this.entityProcessors = new EntityProcessorList();
|
||||||
@@ -66,10 +60,6 @@ module es {
|
|||||||
public end() {
|
public end() {
|
||||||
this._didSceneBegin = false;
|
this._didSceneBegin = false;
|
||||||
|
|
||||||
for (let i = 0; i < this._renderers.length; i++) {
|
|
||||||
this._renderers[i].unload();
|
|
||||||
}
|
|
||||||
|
|
||||||
Core.emitter.removeObserver(CoreEvents.GraphicsDeviceReset, this.updateResolutionScaler);
|
Core.emitter.removeObserver(CoreEvents.GraphicsDeviceReset, this.updateResolutionScaler);
|
||||||
Core.emitter.removeObserver(CoreEvents.OrientationChanged, this.updateResolutionScaler);
|
Core.emitter.removeObserver(CoreEvents.OrientationChanged, this.updateResolutionScaler);
|
||||||
|
|
||||||
@@ -110,23 +100,6 @@ module es {
|
|||||||
|
|
||||||
if (this.entityProcessors != null)
|
if (this.entityProcessors != null)
|
||||||
this.entityProcessors.lateUpdate();
|
this.entityProcessors.lateUpdate();
|
||||||
|
|
||||||
// 我们在entity.update之后更新我们的renderables,以防止任何新的Renderables被添加
|
|
||||||
this.renderableComponents.updateList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public render() {
|
|
||||||
for (let i = 0; i < this._renderers.length; i++) {
|
|
||||||
this._renderers[i].render(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 现在的任何后处理器都要完成它的处理
|
|
||||||
* 只有在SceneTransition请求渲染时,它才会有一个值。
|
|
||||||
*/
|
|
||||||
public postRender() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -181,44 +154,6 @@ module es {
|
|||||||
component.onRemovedFromScene();
|
component.onRemovedFromScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 为场景添加一个渲染器
|
|
||||||
* @param renderer
|
|
||||||
*/
|
|
||||||
public addRenderer<T extends Renderer>(renderer: T) {
|
|
||||||
this._renderers.push(renderer);
|
|
||||||
this._renderers.sort();
|
|
||||||
|
|
||||||
renderer.onAddedToScene(this);
|
|
||||||
|
|
||||||
return renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取类型为T的第一个渲染器
|
|
||||||
* @param type
|
|
||||||
*/
|
|
||||||
public getRenderer<T extends Renderer>(type): T {
|
|
||||||
for (let i = 0; i < this._renderers.length; i++) {
|
|
||||||
if (this._renderers[i] instanceof type)
|
|
||||||
return this._renderers[i] as T;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从场景中移除渲染器
|
|
||||||
* @param renderer
|
|
||||||
*/
|
|
||||||
public removeRenderer(renderer: Renderer) {
|
|
||||||
let rendererList = new linq.List(this._renderers);
|
|
||||||
if (!rendererList.contains(renderer))
|
|
||||||
return;
|
|
||||||
rendererList.remove(renderer);
|
|
||||||
renderer.unload();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将实体添加到此场景,并返回它
|
* 将实体添加到此场景,并返回它
|
||||||
* @param name
|
* @param name
|
||||||
|
|||||||
@@ -1,110 +0,0 @@
|
|||||||
///<reference path="../../Graphics/Renderers/IRenderable.ts" />
|
|
||||||
module es {
|
|
||||||
export class RenderableComponentList {
|
|
||||||
/**
|
|
||||||
* IRenderable列表的全局updatePrder排序
|
|
||||||
*/
|
|
||||||
public static compareUpdatableOrder = new RenderableComparer();
|
|
||||||
/**
|
|
||||||
* 添加到实体的组件列表
|
|
||||||
*/
|
|
||||||
public _components: IRenderable[] = [];
|
|
||||||
/**
|
|
||||||
* 通过渲染层跟踪组件,便于检索
|
|
||||||
*/
|
|
||||||
public _componentsByRenderLayer: Map<number, IRenderable[]> = new Map<number, IRenderable[]>();
|
|
||||||
public _unsortedRenderLayers: number[] = [];
|
|
||||||
private _componentsNeedSort: boolean = true;
|
|
||||||
public get componentsNeedSort(): boolean {
|
|
||||||
return this._componentsNeedSort;
|
|
||||||
}
|
|
||||||
public set componentsNeedSort(value: boolean) {
|
|
||||||
this._componentsNeedSort = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get count() {
|
|
||||||
return this._components.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get buffer() {
|
|
||||||
return this._components;
|
|
||||||
}
|
|
||||||
|
|
||||||
public add(component: IRenderable) {
|
|
||||||
this._components.push(component);
|
|
||||||
this.addToRenderLayerList(component, component.renderLayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public remove(component: IRenderable) {
|
|
||||||
new linq.List(this._components).remove(component);
|
|
||||||
new linq.List(this._componentsByRenderLayer.get(component.renderLayer)).remove(component);
|
|
||||||
}
|
|
||||||
|
|
||||||
public updateRenderableRenderLayer(component: IRenderable, oldRenderLayer: number, newRenderLayer: number) {
|
|
||||||
// 需要注意的是,如果渲染层在组件update之前发生了改变
|
|
||||||
let oldRenderLayers = new linq.List(this._componentsByRenderLayer.get(oldRenderLayer));
|
|
||||||
if (this._componentsByRenderLayer.has(oldRenderLayer) && oldRenderLayers.contains(component)) {
|
|
||||||
oldRenderLayers.remove(component);
|
|
||||||
this.addToRenderLayerList(component, newRenderLayer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将渲染层排序标志弄脏,让所有组件重新排序
|
|
||||||
* @param renderLayer
|
|
||||||
*/
|
|
||||||
public setRenderLayerNeedsComponentSort(renderLayer: number) {
|
|
||||||
let unsortedRenderLayers = new linq.List(this._unsortedRenderLayers);
|
|
||||||
if (!unsortedRenderLayers.contains(renderLayer))
|
|
||||||
unsortedRenderLayers.add(renderLayer);
|
|
||||||
this.componentsNeedSort = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public setNeedsComponentSort() {
|
|
||||||
this.componentsNeedSort = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public addToRenderLayerList(component: IRenderable, renderLayer: number) {
|
|
||||||
let list = new linq.List(this.componentsWithRenderLayer(renderLayer));
|
|
||||||
if (list.contains(component)) {
|
|
||||||
console.warn("组件呈现层列表已经包含此组件");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
list.add(component);
|
|
||||||
let unsortedRenderLayers = new linq.List(this._unsortedRenderLayers);
|
|
||||||
if (!unsortedRenderLayers.contains(renderLayer))
|
|
||||||
unsortedRenderLayers.add(renderLayer);
|
|
||||||
this.componentsNeedSort = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用给定的渲染层获取所有组件。组件列表是预先排序的
|
|
||||||
* @param renderLayer
|
|
||||||
*/
|
|
||||||
public componentsWithRenderLayer(renderLayer: number): IRenderable[] {
|
|
||||||
if (!this._componentsByRenderLayer.get(renderLayer)) {
|
|
||||||
this._componentsByRenderLayer.set(renderLayer, []);
|
|
||||||
}
|
|
||||||
return this._componentsByRenderLayer.get(renderLayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public updateList() {
|
|
||||||
if (this.componentsNeedSort) {
|
|
||||||
this._components.sort(RenderableComponentList.compareUpdatableOrder.compare);
|
|
||||||
this.componentsNeedSort = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._unsortedRenderLayers.length > 0) {
|
|
||||||
for (let i = 0, count = this._unsortedRenderLayers.length; i < count; i++) {
|
|
||||||
let renderLayerComponents = this._componentsByRenderLayer.get(this._unsortedRenderLayers[i]);
|
|
||||||
if (renderLayerComponents) {
|
|
||||||
renderLayerComponents.sort(RenderableComponentList.compareUpdatableOrder.compare);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this._unsortedRenderLayers.length = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
module es {
|
|
||||||
/**
|
|
||||||
* 当该接口应用到组件时,它将注册组件以场景渲染器显示
|
|
||||||
* 该接口请谨慎实现
|
|
||||||
*/
|
|
||||||
export interface IRenderable {
|
|
||||||
/**
|
|
||||||
* 对象的AABB用于相机剔除
|
|
||||||
*/
|
|
||||||
bounds: Rectangle;
|
|
||||||
/**
|
|
||||||
* 这个组件是否应该被渲染
|
|
||||||
*/
|
|
||||||
enabled: boolean;
|
|
||||||
/**
|
|
||||||
* 较低的渲染层在前面,较高的在后面
|
|
||||||
*/
|
|
||||||
renderLayer: number;
|
|
||||||
/**
|
|
||||||
* 可渲染的可见性。状态的改变会调用onBecameVisible/onBecameInvisible方法
|
|
||||||
*/
|
|
||||||
isVisible: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用于排序IRenderables的比较器
|
|
||||||
*/
|
|
||||||
export class RenderableComparer {
|
|
||||||
public compare(self: IRenderable, other: IRenderable) {
|
|
||||||
return other.renderLayer - self.renderLayer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
module es {
|
|
||||||
/**
|
|
||||||
* 渲染器被添加到场景中并处理所有对RenderableComponent的实际调用
|
|
||||||
*/
|
|
||||||
export abstract class Renderer {
|
|
||||||
/**
|
|
||||||
* 指定场景调用渲染器的顺序
|
|
||||||
*/
|
|
||||||
public readonly renderOrder: number = 0;
|
|
||||||
/**
|
|
||||||
* 这个渲染器的标志,决定它是否应该调试渲染。
|
|
||||||
* render方法接收一个bool (debugRenderEnabled),让渲染器知道全局调试渲染是否打开/关闭。
|
|
||||||
* 渲染器然后使用本地bool来决定它是否应该调试渲染。
|
|
||||||
*/
|
|
||||||
public shouldDebugRender: boolean = true;
|
|
||||||
|
|
||||||
protected constructor(renderOrder: number) {
|
|
||||||
this.renderOrder = renderOrder;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 当渲染器被添加到场景时调用
|
|
||||||
* @param scene
|
|
||||||
*/
|
|
||||||
public onAddedToScene(scene: Scene) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 当场景结束或渲染器从场景中移除时调用。使用这个进行清理。
|
|
||||||
*/
|
|
||||||
public unload() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract render(scene: Scene);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 当默认场景渲染目标被调整大小和当场景已经开始添加渲染器时调用
|
|
||||||
* @param newWidth
|
|
||||||
* @param newHeight
|
|
||||||
*/
|
|
||||||
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public compareTo(other: Renderer): number {
|
|
||||||
return this.renderOrder - other.renderOrder;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
module es {
|
|
||||||
/**
|
|
||||||
* SceneTransition用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡
|
|
||||||
*/
|
|
||||||
export abstract class SceneTransition {
|
|
||||||
/** 是否加载新场景的标志 */
|
|
||||||
public loadsNewScene: boolean;
|
|
||||||
/**
|
|
||||||
* 将此用于两个部分的转换。例如,淡出会先淡出到黑色,然后当isNewSceneLoaded为true,它会淡出。
|
|
||||||
* 对于场景过渡,isNewSceneLoaded应该在中点设置为true,这就标识一个新的场景被加载了。
|
|
||||||
*/
|
|
||||||
public isNewSceneLoaded: boolean;
|
|
||||||
/** 在loadNextScene执行时调用。这在进行场景间过渡时很有用,这样你就知道什么时候可以更多地使用相机或者重置任何实体 */
|
|
||||||
public onScreenObscured: Function;
|
|
||||||
/** 当转换完成执行时调用,以便可以调用其他工作,比如启动另一个转换。 */
|
|
||||||
public onTransitionCompleted: Function;
|
|
||||||
/** 返回新加载场景的函数 */
|
|
||||||
protected sceneLoadAction: Function;
|
|
||||||
|
|
||||||
constructor(sceneLoadAction: Function) {
|
|
||||||
this.sceneLoadAction = sceneLoadAction;
|
|
||||||
this.loadsNewScene = sceneLoadAction != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _hasPreviousSceneRender: boolean;
|
|
||||||
|
|
||||||
public get hasPreviousSceneRender() {
|
|
||||||
if (!this._hasPreviousSceneRender) {
|
|
||||||
this._hasPreviousSceneRender = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public preRender() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public render() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async onBeginTransition() {
|
|
||||||
await this.loadNextScene();
|
|
||||||
this.transitionComplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected transitionComplete() {
|
|
||||||
Core._instance._sceneTransition = null;
|
|
||||||
|
|
||||||
if (this.onTransitionCompleted) {
|
|
||||||
this.onTransitionCompleted();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async loadNextScene() {
|
|
||||||
if (this.onScreenObscured)
|
|
||||||
this.onScreenObscured();
|
|
||||||
|
|
||||||
if (!this.loadsNewScene) {
|
|
||||||
this.isNewSceneLoaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Core.scene = await this.sceneLoadAction();
|
|
||||||
this.isNewSceneLoaded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
module es {
|
|
||||||
export class Viewport {
|
|
||||||
private _x: number;
|
|
||||||
private _y: number;
|
|
||||||
private _minDepth: number;
|
|
||||||
private _maxDepth: number;
|
|
||||||
|
|
||||||
constructor(x: number, y: number, width: number, height: number) {
|
|
||||||
this._x = x;
|
|
||||||
this._y = y;
|
|
||||||
this._width = width;
|
|
||||||
this._height = height;
|
|
||||||
this._minDepth = 0;
|
|
||||||
this._maxDepth = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _width: number;
|
|
||||||
|
|
||||||
public get width() {
|
|
||||||
return this._width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set width(value: number) {
|
|
||||||
this._width = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _height: number;
|
|
||||||
|
|
||||||
public get height() {
|
|
||||||
return this._height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set height(value: number) {
|
|
||||||
this._height = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get aspectRatio() {
|
|
||||||
if ((this._height != 0) && (this._width != 0))
|
|
||||||
return (this._width / this._height);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get bounds() {
|
|
||||||
return new Rectangle(this._x, this._y, this._width, this._height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public set bounds(value: Rectangle) {
|
|
||||||
this._x = value.x;
|
|
||||||
this._y = value.y;
|
|
||||||
this._width = value.width;
|
|
||||||
this._height = value.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user