This commit is contained in:
yhh
2021-01-05 09:41:40 +08:00
parent cadaeda3bf
commit 6699c32f73
10 changed files with 100 additions and 85 deletions

View File

@@ -167,7 +167,8 @@ declare module es {
resolutionScale = 8,
resolutionOffset = 9,
createRenderTarget = 10,
createCamera = 11
createCamera = 11,
rendererSizeChanged = 12
}
}
declare module es {
@@ -568,7 +569,8 @@ declare module es {
readonly _sceneComponents: SceneComponent[];
_renderers: IRenderer[];
readonly _afterPostProcessorRenderers: IRenderer[];
_didSceneBegin: boolean;
private _didSceneBegin;
private currentRenderId;
/**
* 设置新场景将使用的默认设计尺寸和分辨率策略,水平/垂直Bleed仅与BestFit相关
* @param width
@@ -713,7 +715,7 @@ declare module es {
clean = 0,
positionDirty = 1,
scaleDirty = 2,
rotationDirty = 3
rotationDirty = 4
}
class Transform {
/** 与此转换关联的实体 */
@@ -1376,18 +1378,19 @@ declare module es {
* 非常重要子类必须覆盖width/height或bounds! 子类必须覆盖width/height或bounds!
*/
abstract class RenderableComponent extends Component implements IRenderable, IComparer<RenderableComponent> {
static renderIdGenerator: number;
/**
* 不重写bounds属性的子类必须实现这个RenderableComponent的宽度。
*/
readonly width: number;
abstract readonly width: any;
/**
* 不重写bounds属性的子类必须实现这个!
*/
readonly height: number;
abstract readonly height: any;
/**
* 包裹此对象的AABB。用来进行相机筛选。
*/
readonly bounds: Rectangle;
abstract readonly bounds: any;
/**
* 标准的Batcher图层深度0为前面1为后面。
* 改变这个值会触发场景中可渲染组件列表的排序。
@@ -1398,6 +1401,10 @@ declare module es {
* 请注意这意味着更高的renderLayers首先被发送到Batcher。
*/
renderLayer: number;
/**
* 渲染时传递给批处理程序的颜色
*/
color: number;
/**
* 由渲染器使用,用于指定该精灵的渲染方式
*/
@@ -1411,6 +1418,7 @@ declare module es {
* 状态的改变最终会调用onBecameVisible/onBecameInvisible方法
*/
isVisible: boolean;
constructor();
debugRenderEnabled: boolean;
protected _localOffset: Vector2;
protected _layerDepth: number;
@@ -1794,6 +1802,7 @@ declare module es {
private _unsortedRenderLayers;
private _componentsNeedSort;
readonly count: number;
readonly buffer: IRenderable[];
get(index: number): IRenderable;
add(component: IRenderable): void;
remove(component: IRenderable): void;
@@ -2003,7 +2012,7 @@ declare module es {
*/
shouldRoundDestinations: boolean;
disposed(): any;
begin(effect: any, transformationMatrix?: Matrix, disableBatching?: boolean): any;
begin(id: Ref<number>, effect: any, transformationMatrix?: Matrix, disableBatching?: boolean): any;
end(): any;
prepRenderState(): any;
/**
@@ -2013,10 +2022,7 @@ declare module es {
drawHollowRect(rect: Rectangle, color: number, thickness?: number): any;
drawHollowBounds(x: number, y: number, width: number, height: number, color: number, thickness: number): any;
drawLine(start: Vector2, end: Vector2, color: number, thickness: any): any;
drawLineAngle(start: Vector2, radians: number, length: number, color: number, thickness: number): any;
draw(texture: any, position: Vector2, color?: number, rotation?: number, origin?: Vector2, scale?: Vector2, effects?: any): any;
flushBatch(): any;
drawPrimitives(texture: any, baseSprite: number, batchSize: number): any;
drawPixel(position: Vector2, color: number, size?: number): any;
drawPolygon(position: Vector2, points: Vector2[], color: number, closePoly?: boolean, thickness?: number): any;
drawCircle(position: Vector2, radius: number, color: number, thickness?: number, resolution?: number): any;

View File

@@ -381,6 +381,7 @@ var es;
CoreEvents[CoreEvents["resolutionOffset"] = 9] = "resolutionOffset";
CoreEvents[CoreEvents["createRenderTarget"] = 10] = "createRenderTarget";
CoreEvents[CoreEvents["createCamera"] = 11] = "createCamera";
CoreEvents[CoreEvents["rendererSizeChanged"] = 12] = "rendererSizeChanged";
})(CoreEvents = es.CoreEvents || (es.CoreEvents = {}));
})(es || (es = {}));
var es;
@@ -1139,6 +1140,7 @@ var es;
this._sceneComponents = [];
this._renderers = [];
this._afterPostProcessorRenderers = [];
this.currentRenderId = new es.Ref(null);
this.entities = new es.EntityList(this);
this.renderableComponents = new es.RenderableComponentList();
this.entityProcessors = new es.EntityProcessorList();
@@ -1385,8 +1387,8 @@ var es;
var currentRenderTarget = es.MathHelper.isEven(enabledCounter) ? this._sceneRenderTarget : this._destinationRenderTarget;
es.Framework.emitter.emit(es.CoreEvents.setRenderTarget, finalRenderTarget);
es.Framework.emitter.emit(es.CoreEvents.clearGraphics);
es.Framework.batcher.begin(null);
es.Framework.batcher.draw(currentRenderTarget, new es.Vector2(this._finalRenderDestinationRect.x, this._finalRenderDestinationRect.y), 0xffffff, 0, es.Vector2.zero, new es.Vector2(this._finalRenderDestinationRect.width, this._finalRenderDestinationRect.height));
es.Framework.batcher.begin(this.currentRenderId, null);
es.Framework.batcher.draw(currentRenderTarget.value, new es.Vector2(this._finalRenderDestinationRect.x, this._finalRenderDestinationRect.y), 0xffffff, 0, es.Vector2.zero, new es.Vector2(this._finalRenderDestinationRect.width, this._finalRenderDestinationRect.height));
es.Framework.batcher.end();
}
};
@@ -1453,6 +1455,8 @@ var es;
});
}
renderer.onAddedToScene(this);
if (this._didSceneBegin)
es.Framework.emitter.emit(es.CoreEvents.rendererSizeChanged, this._sceneRenderTarget.value);
return renderer;
};
/**
@@ -1475,12 +1479,14 @@ var es;
* @param renderer
*/
Scene.prototype.removeRenderer = function (renderer) {
es.Insist.isTrue(new linq.List(this._renderers).contains(renderer) ||
new linq.List(this._afterPostProcessorRenderers).contains(renderer));
var afterProcessLinqList = new linq.List(this._afterPostProcessorRenderers);
var rendererLinqList = new linq.List(this._renderers);
es.Insist.isTrue(rendererLinqList.contains(renderer) ||
afterProcessLinqList.contains(renderer));
if (renderer.wantsToRenderAfterPostProcessors)
new linq.List(this._afterPostProcessorRenderers).remove(renderer);
afterProcessLinqList.remove(renderer);
else
new linq.List(this._renderers).remove(renderer);
rendererLinqList.remove(renderer);
renderer.unload();
};
/**
@@ -1597,7 +1603,7 @@ var es;
DirtyType[DirtyType["clean"] = 0] = "clean";
DirtyType[DirtyType["positionDirty"] = 1] = "positionDirty";
DirtyType[DirtyType["scaleDirty"] = 2] = "scaleDirty";
DirtyType[DirtyType["rotationDirty"] = 3] = "rotationDirty";
DirtyType[DirtyType["rotationDirty"] = 4] = "rotationDirty";
})(DirtyType = es.DirtyType || (es.DirtyType = {}));
var Transform = /** @class */ (function () {
function Transform(entity) {
@@ -3077,45 +3083,17 @@ var es;
var RenderableComponent = /** @class */ (function (_super) {
__extends(RenderableComponent, _super);
function RenderableComponent() {
var _this = _super !== null && _super.apply(this, arguments) || this;
var _this = _super.call(this) || this;
/**
* 渲染时传递给批处理程序的颜色
*/
_this.color = 0xffffff;
_this.debugRenderEnabled = true;
_this._localOffset = es.Vector2.zero;
_this._bounds = es.Rectangle.empty;
_this._areBoundsDirty = true;
return _this;
}
Object.defineProperty(RenderableComponent.prototype, "width", {
/**
* 不重写bounds属性的子类必须实现这个RenderableComponent的宽度。
*/
get: function () {
return this.bounds.width;
},
enumerable: true,
configurable: true
});
Object.defineProperty(RenderableComponent.prototype, "height", {
/**
* 不重写bounds属性的子类必须实现这个!
*/
get: function () {
return this.bounds.height;
},
enumerable: true,
configurable: true
});
Object.defineProperty(RenderableComponent.prototype, "bounds", {
/**
* 包裹此对象的AABB。用来进行相机筛选。
*/
get: function () {
if (this._areBoundsDirty) {
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, es.Vector2.zero, this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
this._areBoundsDirty = false;
}
return this._bounds;
},
enumerable: true,
configurable: true
});
Object.defineProperty(RenderableComponent.prototype, "layerDepth", {
/**
* 标准的Batcher图层深度0为前面1为后面。
@@ -3282,6 +3260,7 @@ var es;
}
}
};
RenderableComponent.renderIdGenerator = 0;
return RenderableComponent;
}(es.Component));
es.RenderableComponent = RenderableComponent;
@@ -3622,6 +3601,8 @@ var es;
var component = _c.value;
if (!component)
continue;
if (component instanceof es.RenderableComponent)
new linq.List(this._entity.scene.renderableComponents.buffer).remove(component);
// 处理IUpdatable
if (es.isIUpdatable(component))
new linq.List(this._updatableComponents).remove(component);
@@ -3642,6 +3623,8 @@ var es;
try {
for (var _b = __values(this._components), _c = _b.next(); !_c.done; _c = _b.next()) {
var component = _c.value;
if (component instanceof es.RenderableComponent)
this._entity.scene.renderableComponents.buffer.push(component);
if (es.isIUpdatable(component))
this._updatableComponents.push(component);
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component)));
@@ -3670,6 +3653,8 @@ var es;
if (this._componentsToAdd.length > 0) {
for (var i = 0, count = this._componentsToAdd.length; i < count; i++) {
var component = this._componentsToAdd[i];
if (component instanceof es.RenderableComponent)
this._entity.scene.renderableComponents.buffer.push(component);
if (es.isIUpdatable(component))
this._updatableComponents.push(component);
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component)));
@@ -3697,8 +3682,8 @@ var es;
}
};
ComponentList.prototype.handleRemove = function (component) {
if (!component)
return;
if (component instanceof es.RenderableComponent)
new linq.List(this._entity.scene.renderableComponents.buffer).remove(component);
if (es.isIUpdatable(component))
new linq.List(this._updatableComponents).remove(component);
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component)), false);
@@ -4357,6 +4342,13 @@ var es;
enumerable: true,
configurable: true
});
Object.defineProperty(RenderableComponentList.prototype, "buffer", {
get: function () {
return this._components;
},
enumerable: true,
configurable: true
});
RenderableComponentList.prototype.get = function (index) {
return this._components[index];
};

File diff suppressed because one or more lines are too long

View File

@@ -4,32 +4,21 @@ module es {
* 非常重要子类必须覆盖width/height或bounds! 子类必须覆盖width/height或bounds!
*/
export abstract class RenderableComponent extends Component implements IRenderable, IComparer<RenderableComponent> {
public static renderIdGenerator: number = 0;
/**
* 不重写bounds属性的子类必须实现这个RenderableComponent的宽度。
*/
public get width() {
return this.bounds.width;
}
public abstract get width();
/**
* 不重写bounds属性的子类必须实现这个!
*/
public get height() {
return this.bounds.height;
}
public abstract get height();
/**
* 包裹此对象的AABB。用来进行相机筛选。
*/
public get bounds(): Rectangle {
if (this._areBoundsDirty) {
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, Vector2.zero,
this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
this._areBoundsDirty = false;
}
return this._bounds;
}
public abstract get bounds();
/**
* 标准的Batcher图层深度0为前面1为后面。
@@ -53,6 +42,11 @@ module es {
this.setRenderLayer(value);
}
/**
* 渲染时传递给批处理程序的颜色
*/
public color: number = 0xffffff;
/**
* 由渲染器使用,用于指定该精灵的渲染方式
*/
@@ -84,12 +78,16 @@ module es {
}
}
constructor() {
super();
}
public debugRenderEnabled: boolean = true;
protected _localOffset: Vector2;
protected _localOffset: Vector2 = Vector2.zero;
protected _layerDepth: number;
protected _renderLayer: number;
protected _bounds: Rectangle;
protected _bounds: Rectangle = Rectangle.empty;
protected _isVisble: boolean;
protected _areBoundsDirty: boolean = true;

View File

@@ -24,5 +24,6 @@ module es {
resolutionOffset,
createRenderTarget,
createCamera,
rendererSizeChanged,
}
}

View File

@@ -80,7 +80,9 @@ module es {
public readonly _sceneComponents: SceneComponent[] = [];
public _renderers: IRenderer[] = [];
public readonly _afterPostProcessorRenderers: IRenderer[] = [];
public _didSceneBegin: boolean;
private _didSceneBegin: boolean;
private currentRenderId: Ref<number> = new Ref(null);
/**
* 设置新场景将使用的默认设计尺寸和分辨率策略,水平/垂直Bleed仅与BestFit相关
@@ -369,8 +371,8 @@ module es {
Framework.emitter.emit(CoreEvents.setRenderTarget, finalRenderTarget);
Framework.emitter.emit(CoreEvents.clearGraphics);
Framework.batcher.begin(null);
Framework.batcher.draw(currentRenderTarget,
Framework.batcher.begin(this.currentRenderId, null);
Framework.batcher.draw(currentRenderTarget.value,
new Vector2(this._finalRenderDestinationRect.x, this._finalRenderDestinationRect.y),
0xffffff,
0,
@@ -451,6 +453,9 @@ module es {
renderer.onAddedToScene(this);
if (this._didSceneBegin)
Framework.emitter.emit(CoreEvents.rendererSizeChanged, this._sceneRenderTarget.value);
return renderer;
}
@@ -477,13 +482,15 @@ module es {
* @param renderer
*/
public removeRenderer(renderer: IRenderer) {
Insist.isTrue(new linq.List(this._renderers).contains(renderer) ||
new linq.List(this._afterPostProcessorRenderers).contains(renderer));
let afterProcessLinqList = new linq.List(this._afterPostProcessorRenderers);
let rendererLinqList = new linq.List(this._renderers);
Insist.isTrue(rendererLinqList.contains(renderer) ||
afterProcessLinqList.contains(renderer));
if (renderer.wantsToRenderAfterPostProcessors)
new linq.List(this._afterPostProcessorRenderers).remove(renderer);
afterProcessLinqList.remove(renderer);
else
new linq.List(this._renderers).remove(renderer);
rendererLinqList.remove(renderer);
renderer.unload();
}

View File

@@ -82,6 +82,9 @@ module es {
for (let component of this._components) {
if (!component) continue;
if (component instanceof RenderableComponent)
new linq.List(this._entity.scene.renderableComponents.buffer).remove(component);
// 处理IUpdatable
if (isIUpdatable(component))
new linq.List(this._updatableComponents).remove(component);
@@ -93,6 +96,9 @@ module es {
public registerAllComponents() {
for (let component of this._components) {
if (component instanceof RenderableComponent)
this._entity.scene.renderableComponents.buffer.push(component);
if (isIUpdatable(component))
this._updatableComponents.push(component);
@@ -118,6 +124,9 @@ module es {
for (let i = 0, count = this._componentsToAdd.length; i < count; i++) {
let component = this._componentsToAdd[i];
if (component instanceof RenderableComponent)
this._entity.scene.renderableComponents.buffer.push(component);
if (isIUpdatable(component))
this._updatableComponents.push(component);
@@ -153,7 +162,8 @@ module es {
}
public handleRemove(component: Component) {
if (!component) return;
if (component instanceof RenderableComponent)
new linq.List(this._entity.scene.renderableComponents.buffer).remove(component);
if (isIUpdatable(component))
new linq.List(this._updatableComponents).remove(component);

View File

@@ -19,6 +19,10 @@ module es {
return this._components.length;
}
public get buffer(){
return this._components;
}
public get(index: number): IRenderable {
return this._components[index];
}

View File

@@ -9,7 +9,7 @@ module es {
*/
shouldRoundDestinations: boolean;
disposed();
begin(effect, transformationMatrix?: Matrix, disableBatching?: boolean);
begin(id: Ref<number>, effect, transformationMatrix?: Matrix, disableBatching?: boolean);
end();
prepRenderState();
/**
@@ -19,10 +19,7 @@ module es {
drawHollowRect(rect: Rectangle, color: number, thickness?: number);
drawHollowBounds(x: number, y: number, width: number, height: number, color: number, thickness: number);
drawLine(start: Vector2, end: Vector2, color: number, thickness);
drawLineAngle(start: Vector2, radians: number, length: number, color: number, thickness: number);
draw(texture, position: Vector2, color?: number, rotation?: number, origin?: Vector2, scale?: Vector2, effects?);
flushBatch();
drawPrimitives(texture, baseSprite: number, batchSize: number);
drawPixel(position: Vector2, color: number, size?: number);
drawPolygon(position: Vector2, points: Vector2[], color: number, closePoly?: boolean, thickness?: number);
drawCircle(position: Vector2, radius: number, color: number, thickness?: number, resolution?: number);