取消wxgame依赖,去除debugRender与camera依赖

This commit is contained in:
yhh
2020-11-23 18:10:45 +08:00
parent 5845128479
commit e67f568069
13 changed files with 4 additions and 4149 deletions

View File

@@ -30,7 +30,6 @@ declare module es {
onAddedToEntity(): void; onAddedToEntity(): void;
onRemovedFromEntity(): void; onRemovedFromEntity(): void;
onEntityTransformChanged(comp: transform.Component): void; onEntityTransformChanged(comp: transform.Component): void;
debugRender(camera: Camera): void;
onEnabled(): void; onEnabled(): void;
onDisabled(): void; onDisabled(): void;
setEnabled(isEnabled: boolean): this; setEnabled(isEnabled: boolean): this;
@@ -116,7 +115,6 @@ declare module es {
onAddedToScene(): void; onAddedToScene(): void;
onRemovedFromScene(): void; onRemovedFromScene(): void;
update(): void; update(): void;
debugRender(camera: Camera): void;
addComponent<T extends Component>(component: T): T; addComponent<T extends Component>(component: T): T;
getComponent<T extends Component>(type: any): T; getComponent<T extends Component>(type: any): T;
hasComponent<T extends Component>(type: any): boolean; hasComponent<T extends Component>(type: any): boolean;
@@ -131,7 +129,6 @@ declare module es {
} }
declare module es { declare module es {
class Scene { class Scene {
camera: Camera;
readonly entities: EntityList; readonly entities: EntityList;
readonly renderableComponents: RenderableComponentList; readonly renderableComponents: RenderableComponentList;
readonly entityProcessors: EntityProcessorList; readonly entityProcessors: EntityProcessorList;
@@ -139,7 +136,6 @@ declare module es {
_renderers: Renderer[]; _renderers: Renderer[];
_didSceneBegin: any; _didSceneBegin: any;
constructor(); constructor();
static createWithDefaultRenderer(): Scene;
initialize(): void; initialize(): void;
onStart(): Promise<void>; onStart(): Promise<void>;
unload(): void; unload(): void;
@@ -345,7 +341,6 @@ declare module es {
setSize(width: number, height: number): this; setSize(width: number, height: number): this;
setWidth(width: number): BoxCollider; setWidth(width: number): BoxCollider;
setHeight(height: number): void; setHeight(height: number): void;
debugRender(camera: Camera): void;
toString(): string; toString(): string;
} }
} }
@@ -354,7 +349,6 @@ declare module es {
constructor(radius: number); constructor(radius: number);
radius: number; radius: number;
setRadius(radius: number): CircleCollider; setRadius(radius: number): CircleCollider;
debugRender(camera: Camera): void;
toString(): string; toString(): string;
} }
} }
@@ -451,7 +445,6 @@ declare module es {
onEntityTransformChanged(comp: transform.Component): void; onEntityTransformChanged(comp: transform.Component): void;
onEntityEnabled(): void; onEntityEnabled(): void;
onEntityDisabled(): void; onEntityDisabled(): void;
debugRender(camera: Camera): void;
} }
} }
declare module es { declare module es {
@@ -602,9 +595,6 @@ declare module es {
enabled: boolean; enabled: boolean;
renderLayer: number; renderLayer: number;
isVisible: boolean; isVisible: boolean;
isVisibleFromCamera(camera: Camera): any;
render(camera: Camera): any;
debugRender(camera: Camera): any;
} }
class RenderableComparer { class RenderableComparer {
compare(self: IRenderable, other: IRenderable): number; compare(self: IRenderable, other: IRenderable): number;
@@ -688,24 +678,14 @@ declare module es {
} }
declare module es { declare module es {
abstract class Renderer { abstract class Renderer {
camera: Camera;
readonly renderOrder: number; readonly renderOrder: number;
shouldDebugRender: boolean; shouldDebugRender: boolean;
protected constructor(renderOrder: number, camera?: Camera); protected constructor(renderOrder: number);
onAddedToScene(scene: Scene): void; onAddedToScene(scene: Scene): void;
unload(): void; unload(): void;
abstract render(scene: Scene): any; abstract render(scene: Scene): any;
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void; onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
compareTo(other: Renderer): number; compareTo(other: Renderer): number;
protected beginRender(cam: Camera): void;
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void;
protected debugRender(scene: Scene, cam: Camera): void;
}
}
declare module es {
class DefaultRenderer extends Renderer {
constructor();
render(scene: Scene): void;
} }
} }
declare module es { declare module es {

View File

@@ -320,8 +320,6 @@ var es;
}; };
Component.prototype.onEntityTransformChanged = function (comp) { Component.prototype.onEntityTransformChanged = function (comp) {
}; };
Component.prototype.debugRender = function (camera) {
};
Component.prototype.onEnabled = function () { Component.prototype.onEnabled = function () {
}; };
Component.prototype.onDisabled = function () { Component.prototype.onDisabled = function () {
@@ -748,9 +746,6 @@ var es;
Entity.prototype.update = function () { Entity.prototype.update = function () {
this.components.update(); this.components.update();
}; };
Entity.prototype.debugRender = function (camera) {
this.components.debugRender(camera);
};
Entity.prototype.addComponent = function (component) { Entity.prototype.addComponent = function (component) {
component.entity = this; component.entity = this;
this.components.add(component); this.components.add(component);
@@ -814,11 +809,6 @@ var es;
this.entityProcessors = new es.EntityProcessorList(); this.entityProcessors = new es.EntityProcessorList();
this.initialize(); this.initialize();
} }
Scene.createWithDefaultRenderer = function () {
var scene = new Scene();
scene.addRenderer(new es.DefaultRenderer());
return scene;
};
Scene.prototype.initialize = function () { Scene.prototype.initialize = function () {
}; };
Scene.prototype.onStart = function () { Scene.prototype.onStart = function () {
@@ -835,10 +825,6 @@ var es;
Scene.prototype.onDeactive = function () { Scene.prototype.onDeactive = function () {
}; };
Scene.prototype.begin = function () { Scene.prototype.begin = function () {
if (this._renderers.length == 0) {
this.addRenderer(new es.DefaultRenderer());
console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染");
}
es.Physics.reset(); es.Physics.reset();
this.updateResolutionScaler(); this.updateResolutionScaler();
if (this.entityProcessors) if (this.entityProcessors)
@@ -860,7 +846,6 @@ var es;
this._sceneComponents[i].onRemovedFromScene(); this._sceneComponents[i].onRemovedFromScene();
} }
this._sceneComponents.length = 0; this._sceneComponents.length = 0;
this.camera = null;
if (this.entityProcessors) if (this.entityProcessors)
this.entityProcessors.end(); this.entityProcessors.end();
this.unload(); this.unload();
@@ -1707,8 +1692,6 @@ var es;
es.Physics.updateCollider(this); es.Physics.updateCollider(this);
} }
}; };
BoxCollider.prototype.debugRender = function (camera) {
};
BoxCollider.prototype.toString = function () { BoxCollider.prototype.toString = function () {
return "[BoxCollider: bounds: " + this.bounds + "]"; return "[BoxCollider: bounds: " + this.bounds + "]";
}; };
@@ -1745,8 +1728,6 @@ var es;
} }
return this; return this;
}; };
CircleCollider.prototype.debugRender = function (camera) {
};
CircleCollider.prototype.toString = function () { CircleCollider.prototype.toString = function () {
return "[CircleCollider: bounds: " + this.bounds + ", radius: " + this.shape.radius + "]"; return "[CircleCollider: bounds: " + this.bounds + ", radius: " + this.shape.radius + "]";
}; };
@@ -2179,12 +2160,6 @@ var es;
for (var i = 0; i < this._components.length; i++) for (var i = 0; i < this._components.length; i++)
this._components.buffer[i].onDisabled(); this._components.buffer[i].onDisabled();
}; };
ComponentList.prototype.debugRender = function (camera) {
for (var i = 0; i < this._components.length; i++) {
if (this._components.buffer[i].enabled)
this._components.buffer[i].debugRender(camera);
}
};
ComponentList.compareUpdatableOrder = new es.IUpdatableComparer(); ComponentList.compareUpdatableOrder = new es.IUpdatableComparer();
return ComponentList; return ComponentList;
}()); }());
@@ -3389,11 +3364,9 @@ var es;
var es; var es;
(function (es) { (function (es) {
var Renderer = (function () { var Renderer = (function () {
function Renderer(renderOrder, camera) { function Renderer(renderOrder) {
if (camera === void 0) { camera = null; }
this.renderOrder = 0; this.renderOrder = 0;
this.shouldDebugRender = true; this.shouldDebugRender = true;
this.camera = camera;
this.renderOrder = renderOrder; this.renderOrder = renderOrder;
} }
Renderer.prototype.onAddedToScene = function (scene) { Renderer.prototype.onAddedToScene = function (scene) {
@@ -3405,43 +3378,11 @@ var es;
Renderer.prototype.compareTo = function (other) { Renderer.prototype.compareTo = function (other) {
return this.renderOrder - other.renderOrder; return this.renderOrder - other.renderOrder;
}; };
Renderer.prototype.beginRender = function (cam) {
};
Renderer.prototype.renderAfterStateCheck = function (renderable, cam) {
renderable.render(cam);
};
Renderer.prototype.debugRender = function (scene, cam) {
for (var i = 0; i < scene.entities.count; i++) {
var entity = scene.entities.buffer[i];
if (entity.enabled)
entity.debugRender(cam);
}
};
return Renderer; return Renderer;
}()); }());
es.Renderer = Renderer; es.Renderer = Renderer;
})(es || (es = {})); })(es || (es = {}));
var es; var es;
(function (es) {
var DefaultRenderer = (function (_super) {
__extends(DefaultRenderer, _super);
function DefaultRenderer() {
return _super.call(this, 0, null) || this;
}
DefaultRenderer.prototype.render = function (scene) {
var cam = this.camera ? this.camera : scene.camera;
this.beginRender(cam);
for (var i = 0; i < scene.renderableComponents.count; i++) {
var renderable = scene.renderableComponents.buffer[i];
if (renderable.enabled && renderable.isVisibleFromCamera(cam))
this.renderAfterStateCheck(renderable, cam);
}
};
return DefaultRenderer;
}(es.Renderer));
es.DefaultRenderer = DefaultRenderer;
})(es || (es = {}));
var es;
(function (es) { (function (es) {
var SceneTransition = (function () { var SceneTransition = (function () {
function SceneTransition(sceneLoadAction) { function SceneTransition(sceneLoadAction) {

File diff suppressed because one or more lines are too long

3945
source/lib/wxgame.d.ts vendored

File diff suppressed because it is too large Load Diff

View File

@@ -78,12 +78,6 @@ module es {
public onEntityTransformChanged(comp: transform.Component) { public onEntityTransformChanged(comp: transform.Component) {
} }
/**
*
*/
public debugRender(camera: Camera) {
}
/** /**
*当父实体或此组件启用时调用 *当父实体或此组件启用时调用
*/ */

View File

@@ -74,9 +74,6 @@ module es {
} }
} }
public debugRender(camera: Camera) {
}
public toString() { public toString() {
return `[BoxCollider: bounds: ${this.bounds}]`; return `[BoxCollider: bounds: ${this.bounds}]`;
} }

View File

@@ -36,10 +36,6 @@ module es {
return this; return this;
} }
public debugRender(camera: Camera) {
}
public toString() { public toString() {
return `[CircleCollider: bounds: ${this.bounds}, radius: ${(this.shape as Circle).radius}]` return `[CircleCollider: bounds: ${this.bounds}, radius: ${(this.shape as Circle).radius}]`
} }

View File

@@ -302,13 +302,6 @@ module es {
this.components.update(); this.components.update();
} }
/**
* 在默认渲染器中如果Core.debugRenderEnabled为true则调用。自定义渲染器可以选择是否调用它。
*/
public debugRender(camera: Camera){
this.components.debugRender(camera);
}
/** /**
* 将组件添加到组件列表中。返回组件。 * 将组件添加到组件列表中。返回组件。
* @param component * @param component

View File

@@ -1,10 +1,6 @@
module es { module es {
/** 场景 */ /** 场景 */
export class Scene { export class Scene {
/**
* 默认场景摄像机
*/
public camera: Camera;
/** /**
* 这个场景中的实体列表 * 这个场景中的实体列表
*/ */
@@ -31,15 +27,6 @@ module es {
this.initialize(); this.initialize();
} }
/**
* 辅助器创建一个场景与DefaultRenderer附加并准备使用
*/
public static createWithDefaultRenderer() {
let scene = new Scene();
scene.addRenderer(new DefaultRenderer());
return scene;
}
/** /**
* 在场景子类中重写这个并在这里进行加载。在场景设置好之后在调用begin之前从构造器中调用。 * 在场景子类中重写这个并在这里进行加载。在场景设置好之后在调用begin之前从构造器中调用。
*/ */
@@ -72,11 +59,6 @@ module es {
} }
public begin() { public begin() {
if (this._renderers.length == 0) {
this.addRenderer(new DefaultRenderer());
console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染");
}
Physics.reset(); Physics.reset();
this.updateResolutionScaler(); this.updateResolutionScaler();
@@ -108,8 +90,6 @@ module es {
} }
this._sceneComponents.length = 0; this._sceneComponents.length = 0;
this.camera = null;
if (this.entityProcessors) if (this.entityProcessors)
this.entityProcessors.end(); this.entityProcessors.end();

View File

@@ -250,12 +250,5 @@ module es {
for (let i = 0; i < this._components.length; i++) for (let i = 0; i < this._components.length; i++)
this._components.buffer[i].onDisabled(); this._components.buffer[i].onDisabled();
} }
public debugRender(camera: Camera){
for (let i = 0; i < this._components.length; i ++){
if (this._components.buffer[i].enabled)
this._components.buffer[i].debugRender(camera);
}
}
} }
} }

View File

@@ -1,19 +0,0 @@
///<reference path="./Renderer.ts" />
module es {
export class DefaultRenderer extends Renderer {
constructor() {
super(0, null);
}
public render(scene: Scene) {
let cam = this.camera ? this.camera : scene.camera;
this.beginRender(cam);
for (let i = 0; i < scene.renderableComponents.count; i++) {
let renderable = scene.renderableComponents.buffer[i];
if (renderable.enabled && renderable.isVisibleFromCamera(cam))
this.renderAfterStateCheck(renderable, cam);
}
}
}
}

View File

@@ -20,25 +20,6 @@ module es {
* 可渲染的可见性。状态的改变会调用onBecameVisible/onBecameInvisible方法 * 可渲染的可见性。状态的改变会调用onBecameVisible/onBecameInvisible方法
*/ */
isVisible: boolean; isVisible: boolean;
/**
* 如果renderableComponent的边界与camera.bounds相交 返回true
* 用于处理isVisible标志的状态开关
* 在渲染方法中使用这个方法来决定是否渲染
* @param camera
*/
isVisibleFromCamera(camera: Camera);
/**
* 由渲染器调用。可以使用摄像机进行剔除
* @param camera
*/
render(camera: Camera);
/**
* 只有在没有碰撞器时才呈现边界。总是在原点上渲染一个正方形。
*/
debugRender(camera: Camera);
} }
/** /**

View File

@@ -3,12 +3,6 @@ module es {
* 渲染器被添加到场景中并处理所有对RenderableComponent的实际调用 * 渲染器被添加到场景中并处理所有对RenderableComponent的实际调用
*/ */
export abstract class Renderer { export abstract class Renderer {
/**
* 渲染器用于渲染的摄像机(实际上是用于剔除的变换矩阵和边界)
* 不是必须的
* Renderer子类可以选择调用beginRender时使用的摄像头
*/
public camera: Camera;
/** /**
* 指定场景调用渲染器的顺序 * 指定场景调用渲染器的顺序
*/ */
@@ -20,8 +14,7 @@ module es {
*/ */
public shouldDebugRender: boolean = true; public shouldDebugRender: boolean = true;
protected constructor(renderOrder: number, camera: Camera = null) { protected constructor(renderOrder: number) {
this.camera = camera;
this.renderOrder = renderOrder; this.renderOrder = renderOrder;
} }
@@ -52,34 +45,5 @@ module es {
public compareTo(other: Renderer): number { public compareTo(other: Renderer): number {
return this.renderOrder - other.renderOrder; return this.renderOrder - other.renderOrder;
} }
/**
*
* @param cam
*/
protected beginRender(cam: Camera) {
}
/**
*
* @param renderable
* @param cam
*/
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera) {
renderable.render(cam);
}
/**
* 默认debugRender方法只循环遍历所有实体并调用entity.debugRender
* @param scene
* @param cam
*/
protected debugRender(scene: Scene, cam: Camera){
for (let i = 0; i < scene.entities.count; i ++){
let entity = scene.entities.buffer[i];
if (entity.enabled)
entity.debugRender(cam);
}
}
} }
} }