新增poolcomponent 对象池组件
This commit is contained in:
Vendored
+13
-3
@@ -343,6 +343,13 @@ declare class CameraInset {
|
|||||||
top: number;
|
top: number;
|
||||||
bottom: number;
|
bottom: number;
|
||||||
}
|
}
|
||||||
|
declare class ComponentPool<T extends PooledComponent> {
|
||||||
|
private _cache;
|
||||||
|
private _type;
|
||||||
|
constructor(typeClass: any);
|
||||||
|
obtain(): T;
|
||||||
|
free(component: T): void;
|
||||||
|
}
|
||||||
declare class FollowCamera extends Component {
|
declare class FollowCamera extends Component {
|
||||||
camera: Camera;
|
camera: Camera;
|
||||||
followLerp: number;
|
followLerp: number;
|
||||||
@@ -386,6 +393,9 @@ declare class VertexPosition {
|
|||||||
declare class PolygonMesh extends Mesh {
|
declare class PolygonMesh extends Mesh {
|
||||||
constructor(points: Vector2[], arePointsCCW?: boolean);
|
constructor(points: Vector2[], arePointsCCW?: boolean);
|
||||||
}
|
}
|
||||||
|
declare abstract class PooledComponent extends Component {
|
||||||
|
abstract reset(): any;
|
||||||
|
}
|
||||||
declare abstract class RenderableComponent extends Component implements IRenderable {
|
declare abstract class RenderableComponent extends Component implements IRenderable {
|
||||||
private _isVisible;
|
private _isVisible;
|
||||||
protected _areBoundsDirty: boolean;
|
protected _areBoundsDirty: boolean;
|
||||||
@@ -711,7 +721,7 @@ declare abstract class SceneTransition {
|
|||||||
constructor(sceneLoadAction: Function);
|
constructor(sceneLoadAction: Function);
|
||||||
preRender(): void;
|
preRender(): void;
|
||||||
render(): void;
|
render(): void;
|
||||||
onBeginTransition(): void;
|
onBeginTransition(): Promise<void>;
|
||||||
protected transitionComplete(): void;
|
protected transitionComplete(): void;
|
||||||
protected loadNextScene(): Promise<void>;
|
protected loadNextScene(): Promise<void>;
|
||||||
tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise<{}>;
|
tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise<{}>;
|
||||||
@@ -724,7 +734,7 @@ declare class FadeTransition extends SceneTransition {
|
|||||||
private _mask;
|
private _mask;
|
||||||
private _alpha;
|
private _alpha;
|
||||||
constructor(sceneLoadAction: Function);
|
constructor(sceneLoadAction: Function);
|
||||||
onBeginTransition(): void;
|
onBeginTransition(): Promise<void>;
|
||||||
render(): void;
|
render(): void;
|
||||||
}
|
}
|
||||||
declare class WindTransition extends SceneTransition {
|
declare class WindTransition extends SceneTransition {
|
||||||
@@ -735,7 +745,7 @@ declare class WindTransition extends SceneTransition {
|
|||||||
size: number;
|
size: number;
|
||||||
easeType: (t: number) => number;
|
easeType: (t: number) => number;
|
||||||
constructor(sceneLoadAction: Function);
|
constructor(sceneLoadAction: Function);
|
||||||
onBeginTransition(): void;
|
onBeginTransition(): Promise<void>;
|
||||||
}
|
}
|
||||||
declare class BaseView extends egret.DisplayObjectContainer {
|
declare class BaseView extends egret.DisplayObjectContainer {
|
||||||
protected _data: any;
|
protected _data: any;
|
||||||
|
|||||||
@@ -1782,6 +1782,25 @@ var CameraInset = (function () {
|
|||||||
}
|
}
|
||||||
return CameraInset;
|
return CameraInset;
|
||||||
}());
|
}());
|
||||||
|
var ComponentPool = (function () {
|
||||||
|
function ComponentPool(typeClass) {
|
||||||
|
this._type = typeClass;
|
||||||
|
this._cache = [];
|
||||||
|
}
|
||||||
|
ComponentPool.prototype.obtain = function () {
|
||||||
|
try {
|
||||||
|
return this._cache.length > 0 ? this._cache.shift() : new this._type();
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
throw new Error(this._type + err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ComponentPool.prototype.free = function (component) {
|
||||||
|
component.reset();
|
||||||
|
this._cache.push(component);
|
||||||
|
};
|
||||||
|
return ComponentPool;
|
||||||
|
}());
|
||||||
var FollowCamera = (function (_super) {
|
var FollowCamera = (function (_super) {
|
||||||
__extends(FollowCamera, _super);
|
__extends(FollowCamera, _super);
|
||||||
function FollowCamera(targetEntity, cameraStyle) {
|
function FollowCamera(targetEntity, cameraStyle) {
|
||||||
@@ -1937,6 +1956,13 @@ var PolygonMesh = (function (_super) {
|
|||||||
}
|
}
|
||||||
return PolygonMesh;
|
return PolygonMesh;
|
||||||
}(Mesh));
|
}(Mesh));
|
||||||
|
var PooledComponent = (function (_super) {
|
||||||
|
__extends(PooledComponent, _super);
|
||||||
|
function PooledComponent() {
|
||||||
|
return _super !== null && _super.apply(this, arguments) || this;
|
||||||
|
}
|
||||||
|
return PooledComponent;
|
||||||
|
}(Component));
|
||||||
var RenderableComponent = (function (_super) {
|
var RenderableComponent = (function (_super) {
|
||||||
__extends(RenderableComponent, _super);
|
__extends(RenderableComponent, _super);
|
||||||
function RenderableComponent() {
|
function RenderableComponent() {
|
||||||
@@ -3236,8 +3262,17 @@ var SceneTransition = (function () {
|
|||||||
SceneTransition.prototype.render = function () {
|
SceneTransition.prototype.render = function () {
|
||||||
};
|
};
|
||||||
SceneTransition.prototype.onBeginTransition = function () {
|
SceneTransition.prototype.onBeginTransition = function () {
|
||||||
this.loadNextScene();
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0: return [4, this.loadNextScene()];
|
||||||
|
case 1:
|
||||||
|
_a.sent();
|
||||||
this.transitionComplete();
|
this.transitionComplete();
|
||||||
|
return [2];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
SceneTransition.prototype.transitionComplete = function () {
|
SceneTransition.prototype.transitionComplete = function () {
|
||||||
SceneManager.sceneTransition = null;
|
SceneManager.sceneTransition = null;
|
||||||
@@ -3291,7 +3326,9 @@ var FadeTransition = (function (_super) {
|
|||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
FadeTransition.prototype.onBeginTransition = function () {
|
FadeTransition.prototype.onBeginTransition = function () {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
this._mask.graphics.beginFill(this.fadeToColor, 1);
|
this._mask.graphics.beginFill(this.fadeToColor, 1);
|
||||||
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
|
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
|
||||||
this._mask.graphics.endFill();
|
this._mask.graphics.endFill();
|
||||||
@@ -3312,6 +3349,9 @@ var FadeTransition = (function (_super) {
|
|||||||
SceneManager.stage.removeChild(_this._mask);
|
SceneManager.stage.removeChild(_this._mask);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
return [2];
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
FadeTransition.prototype.render = function () {
|
FadeTransition.prototype.render = function () {
|
||||||
this._mask.graphics.clear();
|
this._mask.graphics.clear();
|
||||||
@@ -3378,11 +3418,19 @@ var WindTransition = (function (_super) {
|
|||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
WindTransition.prototype.onBeginTransition = function () {
|
WindTransition.prototype.onBeginTransition = function () {
|
||||||
var _this = this;
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
this.loadNextScene();
|
this.loadNextScene();
|
||||||
this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType).then(function () {
|
return [4, this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType)];
|
||||||
_this.transitionComplete();
|
case 1:
|
||||||
SceneManager.stage.removeChild(_this._mask);
|
_a.sent();
|
||||||
|
this.transitionComplete();
|
||||||
|
SceneManager.stage.removeChild(this._mask);
|
||||||
|
return [2];
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return WindTransition;
|
return WindTransition;
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+3
-2
@@ -11,14 +11,15 @@
|
|||||||
"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/game/CoreEmitterType.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/SpawnerComponent.js",
|
"bin-debug/game/SpawnerComponent.js",
|
||||||
"bin-debug/game/SpawnerSystem.js"
|
"bin-debug/game/SpawnerSystem.js"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -23,6 +23,15 @@ class MainScene extends Scene {
|
|||||||
player2.addComponent(new BoxCollider());
|
player2.addComponent(new BoxCollider());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pool = new ComponentPool<SimplePooled>(SimplePooled);
|
||||||
|
let c1 = pool.obtain();
|
||||||
|
let c2 = pool.obtain();
|
||||||
|
pool.free(c1);
|
||||||
|
let c1b = pool.obtain();
|
||||||
|
|
||||||
|
console.log(c1 != c2);
|
||||||
|
console.log(c1 == c1b);
|
||||||
|
|
||||||
let button = new eui.Button();
|
let button = new eui.Button();
|
||||||
button.label = "切换场景";
|
button.label = "切换场景";
|
||||||
this.addChild(button);
|
this.addChild(button);
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class SimplePooled extends PooledComponent {
|
||||||
|
public reset(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+13
-3
@@ -343,6 +343,13 @@ declare class CameraInset {
|
|||||||
top: number;
|
top: number;
|
||||||
bottom: number;
|
bottom: number;
|
||||||
}
|
}
|
||||||
|
declare class ComponentPool<T extends PooledComponent> {
|
||||||
|
private _cache;
|
||||||
|
private _type;
|
||||||
|
constructor(typeClass: any);
|
||||||
|
obtain(): T;
|
||||||
|
free(component: T): void;
|
||||||
|
}
|
||||||
declare class FollowCamera extends Component {
|
declare class FollowCamera extends Component {
|
||||||
camera: Camera;
|
camera: Camera;
|
||||||
followLerp: number;
|
followLerp: number;
|
||||||
@@ -386,6 +393,9 @@ declare class VertexPosition {
|
|||||||
declare class PolygonMesh extends Mesh {
|
declare class PolygonMesh extends Mesh {
|
||||||
constructor(points: Vector2[], arePointsCCW?: boolean);
|
constructor(points: Vector2[], arePointsCCW?: boolean);
|
||||||
}
|
}
|
||||||
|
declare abstract class PooledComponent extends Component {
|
||||||
|
abstract reset(): any;
|
||||||
|
}
|
||||||
declare abstract class RenderableComponent extends Component implements IRenderable {
|
declare abstract class RenderableComponent extends Component implements IRenderable {
|
||||||
private _isVisible;
|
private _isVisible;
|
||||||
protected _areBoundsDirty: boolean;
|
protected _areBoundsDirty: boolean;
|
||||||
@@ -711,7 +721,7 @@ declare abstract class SceneTransition {
|
|||||||
constructor(sceneLoadAction: Function);
|
constructor(sceneLoadAction: Function);
|
||||||
preRender(): void;
|
preRender(): void;
|
||||||
render(): void;
|
render(): void;
|
||||||
onBeginTransition(): void;
|
onBeginTransition(): Promise<void>;
|
||||||
protected transitionComplete(): void;
|
protected transitionComplete(): void;
|
||||||
protected loadNextScene(): Promise<void>;
|
protected loadNextScene(): Promise<void>;
|
||||||
tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise<{}>;
|
tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise<{}>;
|
||||||
@@ -724,7 +734,7 @@ declare class FadeTransition extends SceneTransition {
|
|||||||
private _mask;
|
private _mask;
|
||||||
private _alpha;
|
private _alpha;
|
||||||
constructor(sceneLoadAction: Function);
|
constructor(sceneLoadAction: Function);
|
||||||
onBeginTransition(): void;
|
onBeginTransition(): Promise<void>;
|
||||||
render(): void;
|
render(): void;
|
||||||
}
|
}
|
||||||
declare class WindTransition extends SceneTransition {
|
declare class WindTransition extends SceneTransition {
|
||||||
@@ -735,7 +745,7 @@ declare class WindTransition extends SceneTransition {
|
|||||||
size: number;
|
size: number;
|
||||||
easeType: (t: number) => number;
|
easeType: (t: number) => number;
|
||||||
constructor(sceneLoadAction: Function);
|
constructor(sceneLoadAction: Function);
|
||||||
onBeginTransition(): void;
|
onBeginTransition(): Promise<void>;
|
||||||
}
|
}
|
||||||
declare class BaseView extends egret.DisplayObjectContainer {
|
declare class BaseView extends egret.DisplayObjectContainer {
|
||||||
protected _data: any;
|
protected _data: any;
|
||||||
|
|||||||
+53
-5
@@ -1782,6 +1782,25 @@ var CameraInset = (function () {
|
|||||||
}
|
}
|
||||||
return CameraInset;
|
return CameraInset;
|
||||||
}());
|
}());
|
||||||
|
var ComponentPool = (function () {
|
||||||
|
function ComponentPool(typeClass) {
|
||||||
|
this._type = typeClass;
|
||||||
|
this._cache = [];
|
||||||
|
}
|
||||||
|
ComponentPool.prototype.obtain = function () {
|
||||||
|
try {
|
||||||
|
return this._cache.length > 0 ? this._cache.shift() : new this._type();
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
throw new Error(this._type + err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ComponentPool.prototype.free = function (component) {
|
||||||
|
component.reset();
|
||||||
|
this._cache.push(component);
|
||||||
|
};
|
||||||
|
return ComponentPool;
|
||||||
|
}());
|
||||||
var FollowCamera = (function (_super) {
|
var FollowCamera = (function (_super) {
|
||||||
__extends(FollowCamera, _super);
|
__extends(FollowCamera, _super);
|
||||||
function FollowCamera(targetEntity, cameraStyle) {
|
function FollowCamera(targetEntity, cameraStyle) {
|
||||||
@@ -1937,6 +1956,13 @@ var PolygonMesh = (function (_super) {
|
|||||||
}
|
}
|
||||||
return PolygonMesh;
|
return PolygonMesh;
|
||||||
}(Mesh));
|
}(Mesh));
|
||||||
|
var PooledComponent = (function (_super) {
|
||||||
|
__extends(PooledComponent, _super);
|
||||||
|
function PooledComponent() {
|
||||||
|
return _super !== null && _super.apply(this, arguments) || this;
|
||||||
|
}
|
||||||
|
return PooledComponent;
|
||||||
|
}(Component));
|
||||||
var RenderableComponent = (function (_super) {
|
var RenderableComponent = (function (_super) {
|
||||||
__extends(RenderableComponent, _super);
|
__extends(RenderableComponent, _super);
|
||||||
function RenderableComponent() {
|
function RenderableComponent() {
|
||||||
@@ -3236,8 +3262,17 @@ var SceneTransition = (function () {
|
|||||||
SceneTransition.prototype.render = function () {
|
SceneTransition.prototype.render = function () {
|
||||||
};
|
};
|
||||||
SceneTransition.prototype.onBeginTransition = function () {
|
SceneTransition.prototype.onBeginTransition = function () {
|
||||||
this.loadNextScene();
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0: return [4, this.loadNextScene()];
|
||||||
|
case 1:
|
||||||
|
_a.sent();
|
||||||
this.transitionComplete();
|
this.transitionComplete();
|
||||||
|
return [2];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
SceneTransition.prototype.transitionComplete = function () {
|
SceneTransition.prototype.transitionComplete = function () {
|
||||||
SceneManager.sceneTransition = null;
|
SceneManager.sceneTransition = null;
|
||||||
@@ -3291,7 +3326,9 @@ var FadeTransition = (function (_super) {
|
|||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
FadeTransition.prototype.onBeginTransition = function () {
|
FadeTransition.prototype.onBeginTransition = function () {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
this._mask.graphics.beginFill(this.fadeToColor, 1);
|
this._mask.graphics.beginFill(this.fadeToColor, 1);
|
||||||
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
|
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
|
||||||
this._mask.graphics.endFill();
|
this._mask.graphics.endFill();
|
||||||
@@ -3312,6 +3349,9 @@ var FadeTransition = (function (_super) {
|
|||||||
SceneManager.stage.removeChild(_this._mask);
|
SceneManager.stage.removeChild(_this._mask);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
return [2];
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
FadeTransition.prototype.render = function () {
|
FadeTransition.prototype.render = function () {
|
||||||
this._mask.graphics.clear();
|
this._mask.graphics.clear();
|
||||||
@@ -3378,11 +3418,19 @@ var WindTransition = (function (_super) {
|
|||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
WindTransition.prototype.onBeginTransition = function () {
|
WindTransition.prototype.onBeginTransition = function () {
|
||||||
var _this = this;
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
this.loadNextScene();
|
this.loadNextScene();
|
||||||
this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType).then(function () {
|
return [4, this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType)];
|
||||||
_this.transitionComplete();
|
case 1:
|
||||||
SceneManager.stage.removeChild(_this._mask);
|
_a.sent();
|
||||||
|
this.transitionComplete();
|
||||||
|
SceneManager.stage.removeChild(this._mask);
|
||||||
|
return [2];
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return WindTransition;
|
return WindTransition;
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,22 @@
|
|||||||
|
class ComponentPool<T extends PooledComponent>{
|
||||||
|
private _cache: T[];
|
||||||
|
private _type: any;
|
||||||
|
|
||||||
|
constructor(typeClass: any){
|
||||||
|
this._type = typeClass;
|
||||||
|
this._cache = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public obtain(): T{
|
||||||
|
try {
|
||||||
|
return this._cache.length > 0 ? this._cache.shift() : new this._type();
|
||||||
|
} catch(err){
|
||||||
|
throw new Error(this._type + err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public free(component: T){
|
||||||
|
component.reset();
|
||||||
|
this._cache.push(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
/** 回收实例的组件类型。 */
|
||||||
|
abstract class PooledComponent extends Component {
|
||||||
|
public abstract reset();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user