优化transform结构
新增实体列表排序
This commit is contained in:
Vendored
+63
-15
@@ -263,7 +263,7 @@ declare module es {
|
|||||||
onOrientationChanged(): void;
|
onOrientationChanged(): void;
|
||||||
protected onGraphicsDeviceReset(): void;
|
protected onGraphicsDeviceReset(): void;
|
||||||
protected initialize(): void;
|
protected initialize(): void;
|
||||||
protected update(): void;
|
protected update(): Promise<void>;
|
||||||
draw(): Promise<void>;
|
draw(): Promise<void>;
|
||||||
startDebugUpdate(): void;
|
startDebugUpdate(): void;
|
||||||
endDebugUpdate(): void;
|
endDebugUpdate(): void;
|
||||||
@@ -302,8 +302,16 @@ declare module es {
|
|||||||
parent: Transform;
|
parent: Transform;
|
||||||
readonly childCount: number;
|
readonly childCount: number;
|
||||||
position: Vector2;
|
position: Vector2;
|
||||||
|
localPosition: Vector2;
|
||||||
rotation: number;
|
rotation: number;
|
||||||
|
rotationDegrees: number;
|
||||||
|
localRotation: number;
|
||||||
|
localRotationDegrees: number;
|
||||||
scale: Vector2;
|
scale: Vector2;
|
||||||
|
localScale: Vector2;
|
||||||
|
readonly worldInverseTransform: Matrix2D;
|
||||||
|
readonly localToWorldTransform: Matrix2D;
|
||||||
|
readonly worldToLocalTransform: Matrix2D;
|
||||||
constructor(name: string);
|
constructor(name: string);
|
||||||
onTransformChanged(comp: transform.Component): void;
|
onTransformChanged(comp: transform.Component): void;
|
||||||
setTag(tag: number): Entity;
|
setTag(tag: number): Entity;
|
||||||
@@ -325,6 +333,7 @@ declare module es {
|
|||||||
removeComponent(component: Component): void;
|
removeComponent(component: Component): void;
|
||||||
removeComponentForType<T extends Component>(type: any): boolean;
|
removeComponentForType<T extends Component>(type: any): boolean;
|
||||||
removeAllComponents(): void;
|
removeAllComponents(): void;
|
||||||
|
compareTo(other: Entity): number;
|
||||||
toString(): string;
|
toString(): string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -389,21 +398,56 @@ declare module es {
|
|||||||
parent: Transform;
|
parent: Transform;
|
||||||
readonly childCount: number;
|
readonly childCount: number;
|
||||||
position: Vector2;
|
position: Vector2;
|
||||||
|
localPosition: Vector2;
|
||||||
rotation: number;
|
rotation: number;
|
||||||
|
rotationDegrees: number;
|
||||||
|
localRotation: number;
|
||||||
|
localRotationDegrees: number;
|
||||||
scale: Vector2;
|
scale: Vector2;
|
||||||
|
localScale: Vector2;
|
||||||
|
readonly worldInverseTransform: Matrix2D;
|
||||||
|
readonly localToWorldTransform: Matrix2D;
|
||||||
|
readonly worldToLocalTransform: Matrix2D;
|
||||||
_parent: Transform;
|
_parent: Transform;
|
||||||
hierarchyDirty: DirtyType;
|
hierarchyDirty: DirtyType;
|
||||||
|
_localDirty: boolean;
|
||||||
|
_localPositionDirty: boolean;
|
||||||
|
_localScaleDirty: boolean;
|
||||||
|
_localRotationDirty: boolean;
|
||||||
|
_positionDirty: boolean;
|
||||||
|
_worldToLocalDirty: boolean;
|
||||||
|
_worldInverseDirty: boolean;
|
||||||
|
_localTransform: Matrix2D;
|
||||||
|
_worldTransform: Matrix2D;
|
||||||
|
_worldToLocalTransform: Matrix2D;
|
||||||
|
_worldInverseTransform: Matrix2D;
|
||||||
|
_rotationMatrix: Matrix2D;
|
||||||
|
_translationMatrix: Matrix2D;
|
||||||
|
_scaleMatrix: Matrix2D;
|
||||||
|
_position: Vector2;
|
||||||
|
_scale: Vector2;
|
||||||
|
_rotation: number;
|
||||||
|
_localPosition: Vector2;
|
||||||
|
_localScale: Vector2;
|
||||||
|
_localRotation: number;
|
||||||
_children: Transform[];
|
_children: Transform[];
|
||||||
constructor(entity: Entity);
|
constructor(entity: Entity);
|
||||||
getChild(index: number): Transform;
|
getChild(index: number): Transform;
|
||||||
setParent(parent: Transform): Transform;
|
setParent(parent: Transform): Transform;
|
||||||
setPosition(x: number, y: number): Transform;
|
setPosition(x: number, y: number): Transform;
|
||||||
setRotation(degrees: number): Transform;
|
setLocalPosition(localPosition: Vector2): Transform;
|
||||||
setScale(scale: Vector2): Transform;
|
setRotation(radians: number): Transform;
|
||||||
|
setRotationDegrees(degrees: number): Transform;
|
||||||
lookAt(pos: Vector2): void;
|
lookAt(pos: Vector2): void;
|
||||||
|
setLocalRotation(radians: number): this;
|
||||||
|
setLocalRotationDegrees(degrees: number): Transform;
|
||||||
|
setScale(scale: Vector2): Transform;
|
||||||
|
setLocalScale(scale: Vector2): Transform;
|
||||||
roundPosition(): void;
|
roundPosition(): void;
|
||||||
|
updateTransform(): void;
|
||||||
setDirty(dirtyFlagType: DirtyType): void;
|
setDirty(dirtyFlagType: DirtyType): void;
|
||||||
copyFrom(transform: Transform): void;
|
copyFrom(transform: Transform): void;
|
||||||
|
toString(): string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -796,28 +840,32 @@ declare module es {
|
|||||||
declare module es {
|
declare module es {
|
||||||
class EntityList {
|
class EntityList {
|
||||||
scene: Scene;
|
scene: Scene;
|
||||||
private _entitiesToRemove;
|
_entities: Entity[];
|
||||||
private _entitiesToAdded;
|
_entitiesToAdded: Entity[];
|
||||||
private _tempEntityList;
|
_entitiesToRemove: Entity[];
|
||||||
private _entities;
|
_isEntityListUnsorted: boolean;
|
||||||
private _entityDict;
|
_entityDict: Map<number, Entity[]>;
|
||||||
private _unsortedTags;
|
_unsortedTags: number[];
|
||||||
|
_tempEntityList: Entity[];
|
||||||
constructor(scene: Scene);
|
constructor(scene: Scene);
|
||||||
readonly count: number;
|
readonly count: number;
|
||||||
readonly buffer: Entity[];
|
readonly buffer: Entity[];
|
||||||
|
markEntityListUnsorted(): void;
|
||||||
|
markTagUnsorted(tag: number): void;
|
||||||
add(entity: Entity): void;
|
add(entity: Entity): void;
|
||||||
remove(entity: Entity): void;
|
remove(entity: Entity): void;
|
||||||
|
removeAllEntities(): void;
|
||||||
|
contains(entity: Entity): boolean;
|
||||||
|
getTagList(tag: number): Entity[];
|
||||||
|
addToTagList(entity: Entity): void;
|
||||||
|
removeFromTagList(entity: Entity): void;
|
||||||
|
update(): void;
|
||||||
|
updateLists(): void;
|
||||||
findEntity(name: string): Entity;
|
findEntity(name: string): Entity;
|
||||||
entitiesWithTag(tag: number): Entity[];
|
entitiesWithTag(tag: number): Entity[];
|
||||||
entitiesOfType<T extends Entity>(type: any): T[];
|
entitiesOfType<T extends Entity>(type: any): T[];
|
||||||
findComponentOfType<T extends Component>(type: any): T;
|
findComponentOfType<T extends Component>(type: any): T;
|
||||||
findComponentsOfType<T extends Component>(type: any): T[];
|
findComponentsOfType<T extends Component>(type: any): T[];
|
||||||
getTagList(tag: number): Entity[];
|
|
||||||
addToTagList(entity: Entity): void;
|
|
||||||
removeFromTagList(entity: Entity): void;
|
|
||||||
update(): void;
|
|
||||||
removeAllEntities(): void;
|
|
||||||
updateLists(): void;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
|
|||||||
@@ -1156,10 +1156,15 @@ var es;
|
|||||||
Core.prototype.initialize = function () {
|
Core.prototype.initialize = function () {
|
||||||
};
|
};
|
||||||
Core.prototype.update = function () {
|
Core.prototype.update = function () {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var i;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
this.startDebugUpdate();
|
this.startDebugUpdate();
|
||||||
es.Time.update(egret.getTimer());
|
es.Time.update(egret.getTimer());
|
||||||
if (this._scene) {
|
if (!this._scene) return [3, 2];
|
||||||
for (var i = this._globalManagers.length - 1; i >= 0; i--) {
|
for (i = this._globalManagers.length - 1; i >= 0; i--) {
|
||||||
if (this._globalManagers[i].enabled)
|
if (this._globalManagers[i].enabled)
|
||||||
this._globalManagers[i].update();
|
this._globalManagers[i].update();
|
||||||
}
|
}
|
||||||
@@ -1167,15 +1172,21 @@ var es;
|
|||||||
(this._sceneTransition && (!this._sceneTransition.loadsNewScene || this._sceneTransition.isNewSceneLoaded))) {
|
(this._sceneTransition && (!this._sceneTransition.loadsNewScene || this._sceneTransition.isNewSceneLoaded))) {
|
||||||
this._scene.update();
|
this._scene.update();
|
||||||
}
|
}
|
||||||
if (this._nextScene) {
|
if (!this._nextScene) return [3, 2];
|
||||||
this._scene.end();
|
this._scene.end();
|
||||||
this._scene = this._nextScene;
|
this._scene = this._nextScene;
|
||||||
this._nextScene = null;
|
this._nextScene = null;
|
||||||
this.onSceneChanged();
|
this.onSceneChanged();
|
||||||
this._scene.begin();
|
return [4, this._scene.begin()];
|
||||||
}
|
case 1:
|
||||||
}
|
_a.sent();
|
||||||
|
_a.label = 2;
|
||||||
|
case 2:
|
||||||
this.endDebugUpdate();
|
this.endDebugUpdate();
|
||||||
|
return [2];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
Core.prototype.draw = function () {
|
Core.prototype.draw = function () {
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
@@ -1338,6 +1349,16 @@ var es;
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "localPosition", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.localPosition;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.transform.setLocalPosition(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
Object.defineProperty(Entity.prototype, "rotation", {
|
Object.defineProperty(Entity.prototype, "rotation", {
|
||||||
get: function () {
|
get: function () {
|
||||||
return this.transform.rotation;
|
return this.transform.rotation;
|
||||||
@@ -1348,6 +1369,36 @@ var es;
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "rotationDegrees", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.rotationDegrees;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.transform.setRotationDegrees(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "localRotation", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.localRotation;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.transform.setLocalRotation(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "localRotationDegrees", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.localRotationDegrees;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.transform.setLocalRotationDegrees(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
Object.defineProperty(Entity.prototype, "scale", {
|
Object.defineProperty(Entity.prototype, "scale", {
|
||||||
get: function () {
|
get: function () {
|
||||||
return this.transform.scale;
|
return this.transform.scale;
|
||||||
@@ -1358,6 +1409,37 @@ var es;
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "localScale", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.localScale;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.transform.setLocalScale(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "worldInverseTransform", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.worldInverseTransform;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "localToWorldTransform", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.localToWorldTransform;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "worldToLocalTransform", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.worldToLocalTransform;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
Entity.prototype.onTransformChanged = function (comp) {
|
Entity.prototype.onTransformChanged = function (comp) {
|
||||||
this.components.onEntityTransformChanged(comp);
|
this.components.onEntityTransformChanged(comp);
|
||||||
};
|
};
|
||||||
@@ -1385,6 +1467,8 @@ var es;
|
|||||||
if (this._updateOrder != updateOrder) {
|
if (this._updateOrder != updateOrder) {
|
||||||
this._updateOrder = updateOrder;
|
this._updateOrder = updateOrder;
|
||||||
if (this.scene) {
|
if (this.scene) {
|
||||||
|
this.scene.entities.markEntityListUnsorted();
|
||||||
|
this.scene.entities.markTagUnsorted(this.tag);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -1484,6 +1568,12 @@ var es;
|
|||||||
this.removeComponent(this.components.buffer[i]);
|
this.removeComponent(this.components.buffer[i]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Entity.prototype.compareTo = function (other) {
|
||||||
|
var compare = this._updateOrder - other._updateOrder;
|
||||||
|
if (compare == 0)
|
||||||
|
compare = this.id - other.id;
|
||||||
|
return compare;
|
||||||
|
};
|
||||||
Entity.prototype.toString = function () {
|
Entity.prototype.toString = function () {
|
||||||
return "[Entity: name: " + this.name + ", tag: " + this.tag + ", enabled: " + this.enabled + ", depth: " + this.updateOrder + "]";
|
return "[Entity: name: " + this.name + ", tag: " + this.tag + ", enabled: " + this.enabled + ", depth: " + this.updateOrder + "]";
|
||||||
};
|
};
|
||||||
@@ -1697,6 +1787,9 @@ var es;
|
|||||||
})(DirtyType = es.DirtyType || (es.DirtyType = {}));
|
})(DirtyType = es.DirtyType || (es.DirtyType = {}));
|
||||||
var Transform = (function () {
|
var Transform = (function () {
|
||||||
function Transform(entity) {
|
function Transform(entity) {
|
||||||
|
this._worldTransform = es.Matrix2D.create().identity();
|
||||||
|
this._worldToLocalTransform = es.Matrix2D.create().identity();
|
||||||
|
this._worldInverseTransform = es.Matrix2D.create().identity();
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.scale = es.Vector2.one;
|
this.scale = es.Vector2.one;
|
||||||
this._children = [];
|
this._children = [];
|
||||||
@@ -1718,6 +1811,139 @@ var es;
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "position", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
if (this._positionDirty) {
|
||||||
|
if (!this.parent) {
|
||||||
|
this._position = this._localPosition;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.parent.updateTransform();
|
||||||
|
this._position = es.Vector2Ext.transformR(this._localPosition, this.parent._worldTransform);
|
||||||
|
}
|
||||||
|
this._positionDirty = false;
|
||||||
|
}
|
||||||
|
return this._position;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setPosition(value.x, value.y);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "localPosition", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._localPosition;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setLocalPosition(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "rotation", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._rotation;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setRotation(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "rotationDegrees", {
|
||||||
|
get: function () {
|
||||||
|
return es.MathHelper.toDegrees(this._rotation);
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setRotation(es.MathHelper.toRadians(value));
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "localRotation", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._localRotation;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setLocalRotation(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "localRotationDegrees", {
|
||||||
|
get: function () {
|
||||||
|
return es.MathHelper.toDegrees(this._localRotation);
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.localRotation = es.MathHelper.toRadians(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "scale", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._scale;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setScale(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "localScale", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._localScale;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setLocalScale(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "worldInverseTransform", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
if (this._worldInverseDirty) {
|
||||||
|
this._worldInverseTransform = this._worldTransform.invert();
|
||||||
|
this._worldInverseDirty = false;
|
||||||
|
}
|
||||||
|
return this._worldInverseTransform;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "localToWorldTransform", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._worldTransform;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "worldToLocalTransform", {
|
||||||
|
get: function () {
|
||||||
|
if (this._worldToLocalDirty) {
|
||||||
|
if (!this.parent) {
|
||||||
|
this._worldToLocalTransform = es.Matrix2D.create().identity();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.parent.updateTransform();
|
||||||
|
this._worldToLocalTransform = this.parent._worldTransform.invert();
|
||||||
|
}
|
||||||
|
this._worldToLocalDirty = false;
|
||||||
|
}
|
||||||
|
return this._worldToLocalTransform;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
Transform.prototype.getChild = function (index) {
|
Transform.prototype.getChild = function (index) {
|
||||||
return this._children[index];
|
return this._children[index];
|
||||||
};
|
};
|
||||||
@@ -1733,27 +1959,110 @@ var es;
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Transform.prototype.setPosition = function (x, y) {
|
Transform.prototype.setPosition = function (x, y) {
|
||||||
this.position = new es.Vector2(x, y);
|
var position = new es.Vector2(x, y);
|
||||||
|
if (position == this._position)
|
||||||
|
return this;
|
||||||
|
this._position = position;
|
||||||
|
if (this.parent) {
|
||||||
|
this.localPosition = es.Vector2Ext.transformR(this._position, this._worldToLocalTransform);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.localPosition = position;
|
||||||
|
}
|
||||||
|
this._positionDirty = false;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
Transform.prototype.setLocalPosition = function (localPosition) {
|
||||||
|
if (localPosition == this._localPosition)
|
||||||
|
return this;
|
||||||
|
this._localPosition = localPosition;
|
||||||
|
this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true;
|
||||||
this.setDirty(DirtyType.positionDirty);
|
this.setDirty(DirtyType.positionDirty);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Transform.prototype.setRotation = function (degrees) {
|
Transform.prototype.setRotation = function (radians) {
|
||||||
this.rotation = degrees;
|
this._rotation = radians;
|
||||||
this.setDirty(DirtyType.rotationDirty);
|
if (this.parent) {
|
||||||
|
this.localRotation = this.parent.rotation + radians;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.localRotation = radians;
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Transform.prototype.setScale = function (scale) {
|
Transform.prototype.setRotationDegrees = function (degrees) {
|
||||||
this.scale = scale;
|
return this.setRotation(es.MathHelper.toRadians(degrees));
|
||||||
this.setDirty(DirtyType.scaleDirty);
|
|
||||||
return this;
|
|
||||||
};
|
};
|
||||||
Transform.prototype.lookAt = function (pos) {
|
Transform.prototype.lookAt = function (pos) {
|
||||||
var sign = this.position.x > pos.x ? -1 : 1;
|
var sign = this.position.x > pos.x ? -1 : 1;
|
||||||
var vectorToAlignTo = es.Vector2.normalize(es.Vector2.subtract(this.position, pos));
|
var vectorToAlignTo = es.Vector2.normalize(es.Vector2.subtract(this.position, pos));
|
||||||
this.rotation = sign * Math.acos(es.Vector2.dot(vectorToAlignTo, es.Vector2.unitY));
|
this.rotation = sign * Math.acos(es.Vector2.dot(vectorToAlignTo, es.Vector2.unitY));
|
||||||
};
|
};
|
||||||
|
Transform.prototype.setLocalRotation = function (radians) {
|
||||||
|
this._localRotation = radians;
|
||||||
|
this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true;
|
||||||
|
this.setDirty(DirtyType.rotationDirty);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
Transform.prototype.setLocalRotationDegrees = function (degrees) {
|
||||||
|
return this.setLocalRotation(es.MathHelper.toRadians(degrees));
|
||||||
|
};
|
||||||
|
Transform.prototype.setScale = function (scale) {
|
||||||
|
this._scale = scale;
|
||||||
|
if (this.parent) {
|
||||||
|
this.localScale = es.Vector2.divide(scale, this.parent._scale);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.localScale = scale;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
Transform.prototype.setLocalScale = function (scale) {
|
||||||
|
this._localScale = scale;
|
||||||
|
this._localDirty = this._positionDirty = this._localScaleDirty = true;
|
||||||
|
this.setDirty(DirtyType.scaleDirty);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
Transform.prototype.roundPosition = function () {
|
Transform.prototype.roundPosition = function () {
|
||||||
this.position = this.position.round();
|
this.position = this._position.round();
|
||||||
|
};
|
||||||
|
Transform.prototype.updateTransform = function () {
|
||||||
|
if (this.hierarchyDirty != DirtyType.clean) {
|
||||||
|
if (this.parent)
|
||||||
|
this.parent.updateTransform();
|
||||||
|
if (this._localDirty) {
|
||||||
|
if (this._localPositionDirty) {
|
||||||
|
this._translationMatrix = es.Matrix2D.create().translate(this._localPosition.x, this._localPosition.y);
|
||||||
|
this._localPositionDirty = false;
|
||||||
|
}
|
||||||
|
if (this._localRotationDirty) {
|
||||||
|
this._rotationMatrix = es.Matrix2D.create().rotate(this._localRotation);
|
||||||
|
this._localRotationDirty = false;
|
||||||
|
}
|
||||||
|
if (this._localScaleDirty) {
|
||||||
|
this._scaleMatrix = es.Matrix2D.create().scale(this._localScale.x, this._localScale.y);
|
||||||
|
this._localScaleDirty = false;
|
||||||
|
}
|
||||||
|
this._localTransform = this._scaleMatrix.multiply(this._rotationMatrix);
|
||||||
|
this._localTransform = this._localTransform.multiply(this._translationMatrix);
|
||||||
|
if (!this.parent) {
|
||||||
|
this._worldTransform = this._localTransform;
|
||||||
|
this._rotation = this._localRotation;
|
||||||
|
this._scale = this._localScale;
|
||||||
|
this._worldInverseDirty = true;
|
||||||
|
}
|
||||||
|
this._localDirty = false;
|
||||||
|
}
|
||||||
|
if (this.parent) {
|
||||||
|
this._worldTransform = this._localTransform.multiply(this.parent._worldTransform);
|
||||||
|
this._rotation = this._localRotation + this.parent._rotation;
|
||||||
|
this._scale = es.Vector2.multiply(this.parent._scale, this._localScale);
|
||||||
|
this._worldInverseDirty = true;
|
||||||
|
}
|
||||||
|
this._worldToLocalDirty = true;
|
||||||
|
this._positionDirty = true;
|
||||||
|
this.hierarchyDirty = DirtyType.clean;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Transform.prototype.setDirty = function (dirtyFlagType) {
|
Transform.prototype.setDirty = function (dirtyFlagType) {
|
||||||
if ((this.hierarchyDirty & dirtyFlagType) == 0) {
|
if ((this.hierarchyDirty & dirtyFlagType) == 0) {
|
||||||
@@ -1776,13 +2085,19 @@ var es;
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Transform.prototype.copyFrom = function (transform) {
|
Transform.prototype.copyFrom = function (transform) {
|
||||||
this.position = transform.position;
|
this._position = transform.position;
|
||||||
this.rotation = transform.rotation;
|
this._localPosition = transform._localPosition;
|
||||||
this.scale = transform.scale;
|
this._rotation = transform._rotation;
|
||||||
|
this._localRotation = transform._localRotation;
|
||||||
|
this._scale = transform._scale;
|
||||||
|
this._localScale = transform._localScale;
|
||||||
this.setDirty(DirtyType.positionDirty);
|
this.setDirty(DirtyType.positionDirty);
|
||||||
this.setDirty(DirtyType.rotationDirty);
|
this.setDirty(DirtyType.rotationDirty);
|
||||||
this.setDirty(DirtyType.scaleDirty);
|
this.setDirty(DirtyType.scaleDirty);
|
||||||
};
|
};
|
||||||
|
Transform.prototype.toString = function () {
|
||||||
|
return "[Transform: parent: " + this.parent + ", position: " + this.position + ", rotation: " + this.rotation + ",\n scale: " + this.scale + ", localPosition: " + this._localPosition + ", localRotation: " + this._localRotation + ",\n localScale: " + this._localScale + "]";
|
||||||
|
};
|
||||||
return Transform;
|
return Transform;
|
||||||
}());
|
}());
|
||||||
es.Transform = Transform;
|
es.Transform = Transform;
|
||||||
@@ -3432,12 +3747,12 @@ var es;
|
|||||||
(function (es) {
|
(function (es) {
|
||||||
var EntityList = (function () {
|
var EntityList = (function () {
|
||||||
function EntityList(scene) {
|
function EntityList(scene) {
|
||||||
this._entitiesToRemove = [];
|
|
||||||
this._entitiesToAdded = [];
|
|
||||||
this._tempEntityList = [];
|
|
||||||
this._entities = [];
|
this._entities = [];
|
||||||
|
this._entitiesToAdded = [];
|
||||||
|
this._entitiesToRemove = [];
|
||||||
this._entityDict = new Map();
|
this._entityDict = new Map();
|
||||||
this._unsortedTags = [];
|
this._unsortedTags = [];
|
||||||
|
this._tempEntityList = [];
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
}
|
}
|
||||||
Object.defineProperty(EntityList.prototype, "count", {
|
Object.defineProperty(EntityList.prototype, "count", {
|
||||||
@@ -3454,11 +3769,21 @@ var es;
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
EntityList.prototype.markEntityListUnsorted = function () {
|
||||||
|
this._isEntityListUnsorted = true;
|
||||||
|
};
|
||||||
|
EntityList.prototype.markTagUnsorted = function (tag) {
|
||||||
|
this._unsortedTags.push(tag);
|
||||||
|
};
|
||||||
EntityList.prototype.add = function (entity) {
|
EntityList.prototype.add = function (entity) {
|
||||||
if (this._entitiesToAdded.indexOf(entity) == -1)
|
if (this._entitiesToAdded.indexOf(entity) == -1)
|
||||||
this._entitiesToAdded.push(entity);
|
this._entitiesToAdded.push(entity);
|
||||||
};
|
};
|
||||||
EntityList.prototype.remove = function (entity) {
|
EntityList.prototype.remove = function (entity) {
|
||||||
|
if (!this._entitiesToRemove.contains(entity)) {
|
||||||
|
console.warn("You are trying to remove an entity (" + entity.name + ") that you already removed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this._entitiesToAdded.contains(entity)) {
|
if (this._entitiesToAdded.contains(entity)) {
|
||||||
this._entitiesToAdded.remove(entity);
|
this._entitiesToAdded.remove(entity);
|
||||||
return;
|
return;
|
||||||
@@ -3466,6 +3791,92 @@ var es;
|
|||||||
if (!this._entitiesToRemove.contains(entity))
|
if (!this._entitiesToRemove.contains(entity))
|
||||||
this._entitiesToRemove.push(entity);
|
this._entitiesToRemove.push(entity);
|
||||||
};
|
};
|
||||||
|
EntityList.prototype.removeAllEntities = function () {
|
||||||
|
this._unsortedTags.length = 0;
|
||||||
|
this._entitiesToAdded.length = 0;
|
||||||
|
this._isEntityListUnsorted = false;
|
||||||
|
this.updateLists();
|
||||||
|
for (var i = 0; i < this._entities.length; i++) {
|
||||||
|
this._entities[i]._isDestroyed = true;
|
||||||
|
this._entities[i].onRemovedFromScene();
|
||||||
|
this._entities[i].scene = null;
|
||||||
|
}
|
||||||
|
this._entities.length = 0;
|
||||||
|
this._entityDict.clear();
|
||||||
|
};
|
||||||
|
EntityList.prototype.contains = function (entity) {
|
||||||
|
return this._entities.contains(entity) || this._entitiesToAdded.contains(entity);
|
||||||
|
};
|
||||||
|
EntityList.prototype.getTagList = function (tag) {
|
||||||
|
var list = this._entityDict.get(tag);
|
||||||
|
if (!list) {
|
||||||
|
list = [];
|
||||||
|
this._entityDict.set(tag, list);
|
||||||
|
}
|
||||||
|
return this._entityDict.get(tag);
|
||||||
|
};
|
||||||
|
EntityList.prototype.addToTagList = function (entity) {
|
||||||
|
var list = this.getTagList(entity.tag);
|
||||||
|
if (!list.contains(entity)) {
|
||||||
|
list.push(entity);
|
||||||
|
this._unsortedTags.push(entity.tag);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
EntityList.prototype.removeFromTagList = function (entity) {
|
||||||
|
var list = this._entityDict.get(entity.tag);
|
||||||
|
if (list) {
|
||||||
|
list.remove(entity);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
EntityList.prototype.update = function () {
|
||||||
|
for (var i = 0; i < this._entities.length; i++) {
|
||||||
|
var entity = this._entities[i];
|
||||||
|
if (entity.enabled && (entity.updateInterval == 1 || es.Time.frameCount % entity.updateInterval == 0))
|
||||||
|
entity.update();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
EntityList.prototype.updateLists = function () {
|
||||||
|
var _this = this;
|
||||||
|
if (this._entitiesToRemove.length > 0) {
|
||||||
|
var temp = this._entitiesToRemove;
|
||||||
|
this._entitiesToRemove = this._tempEntityList;
|
||||||
|
this._tempEntityList = temp;
|
||||||
|
this._tempEntityList.forEach(function (entity) {
|
||||||
|
_this.removeFromTagList(entity);
|
||||||
|
_this._entities.remove(entity);
|
||||||
|
entity.onRemovedFromScene();
|
||||||
|
entity.scene = null;
|
||||||
|
_this.scene.entityProcessors.onEntityRemoved(entity);
|
||||||
|
});
|
||||||
|
this._tempEntityList.length = 0;
|
||||||
|
}
|
||||||
|
if (this._entitiesToAdded.length > 0) {
|
||||||
|
var temp = this._entitiesToAdded;
|
||||||
|
this._entitiesToAdded = this._tempEntityList;
|
||||||
|
this._tempEntityList = temp;
|
||||||
|
this._tempEntityList.forEach(function (entity) {
|
||||||
|
if (!_this._entities.contains(entity)) {
|
||||||
|
_this._entities.push(entity);
|
||||||
|
entity.scene = _this.scene;
|
||||||
|
_this.addToTagList(entity);
|
||||||
|
_this.scene.entityProcessors.onEntityAdded(entity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); });
|
||||||
|
this._tempEntityList.length = 0;
|
||||||
|
this._isEntityListUnsorted = true;
|
||||||
|
}
|
||||||
|
if (this._isEntityListUnsorted) {
|
||||||
|
this._entities.sort();
|
||||||
|
this._isEntityListUnsorted = false;
|
||||||
|
}
|
||||||
|
if (this._unsortedTags.length > 0) {
|
||||||
|
this._unsortedTags.forEach(function (tag) {
|
||||||
|
_this._entityDict.get(tag).sort();
|
||||||
|
});
|
||||||
|
this._unsortedTags.length = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
EntityList.prototype.findEntity = function (name) {
|
EntityList.prototype.findEntity = function (name) {
|
||||||
for (var i = 0; i < this._entities.length; i++) {
|
for (var i = 0; i < this._entities.length; i++) {
|
||||||
if (this._entities[i].name == name)
|
if (this._entities[i].name == name)
|
||||||
@@ -3523,79 +3934,6 @@ var es;
|
|||||||
}
|
}
|
||||||
return comps;
|
return comps;
|
||||||
};
|
};
|
||||||
EntityList.prototype.getTagList = function (tag) {
|
|
||||||
var list = this._entityDict.get(tag);
|
|
||||||
if (!list) {
|
|
||||||
list = [];
|
|
||||||
this._entityDict.set(tag, list);
|
|
||||||
}
|
|
||||||
return this._entityDict.get(tag);
|
|
||||||
};
|
|
||||||
EntityList.prototype.addToTagList = function (entity) {
|
|
||||||
var list = this.getTagList(entity.tag);
|
|
||||||
if (!list.contains(entity)) {
|
|
||||||
list.push(entity);
|
|
||||||
this._unsortedTags.push(entity.tag);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
EntityList.prototype.removeFromTagList = function (entity) {
|
|
||||||
var list = this._entityDict.get(entity.tag);
|
|
||||||
if (list) {
|
|
||||||
list.remove(entity);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
EntityList.prototype.update = function () {
|
|
||||||
for (var i = 0; i < this._entities.length; i++) {
|
|
||||||
var entity = this._entities[i];
|
|
||||||
if (entity.enabled)
|
|
||||||
entity.update();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
EntityList.prototype.removeAllEntities = function () {
|
|
||||||
this._entitiesToAdded.length = 0;
|
|
||||||
this.updateLists();
|
|
||||||
for (var i = 0; i < this._entities.length; i++) {
|
|
||||||
this._entities[i]._isDestroyed = true;
|
|
||||||
this._entities[i].onRemovedFromScene();
|
|
||||||
this._entities[i].scene = null;
|
|
||||||
}
|
|
||||||
this._entities.length = 0;
|
|
||||||
this._entityDict.clear();
|
|
||||||
};
|
|
||||||
EntityList.prototype.updateLists = function () {
|
|
||||||
var _this = this;
|
|
||||||
if (this._entitiesToRemove.length > 0) {
|
|
||||||
var temp = this._entitiesToRemove;
|
|
||||||
this._entitiesToRemove = this._tempEntityList;
|
|
||||||
this._tempEntityList = temp;
|
|
||||||
this._tempEntityList.forEach(function (entity) {
|
|
||||||
_this._entities.remove(entity);
|
|
||||||
entity.scene = null;
|
|
||||||
_this.scene.entityProcessors.onEntityRemoved(entity);
|
|
||||||
});
|
|
||||||
this._tempEntityList.length = 0;
|
|
||||||
}
|
|
||||||
if (this._entitiesToAdded.length > 0) {
|
|
||||||
var temp = this._entitiesToAdded;
|
|
||||||
this._entitiesToAdded = this._tempEntityList;
|
|
||||||
this._tempEntityList = temp;
|
|
||||||
this._tempEntityList.forEach(function (entity) {
|
|
||||||
if (!_this._entities.contains(entity)) {
|
|
||||||
_this._entities.push(entity);
|
|
||||||
entity.scene = _this.scene;
|
|
||||||
_this.scene.entityProcessors.onEntityAdded(entity);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); });
|
|
||||||
this._tempEntityList.length = 0;
|
|
||||||
}
|
|
||||||
if (this._unsortedTags.length > 0) {
|
|
||||||
this._unsortedTags.forEach(function (tag) {
|
|
||||||
_this._entityDict.get(tag).sort();
|
|
||||||
});
|
|
||||||
this._unsortedTags.length = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return EntityList;
|
return EntityList;
|
||||||
}());
|
}());
|
||||||
es.EntityList = EntityList;
|
es.EntityList = EntityList;
|
||||||
@@ -5650,8 +5988,7 @@ var es;
|
|||||||
distanceSquared = tempDistanceSquared;
|
distanceSquared = tempDistanceSquared;
|
||||||
closestPoint = closest;
|
closestPoint = closest;
|
||||||
var line = es.Vector2.subtract(points[j], points[i]);
|
var line = es.Vector2.subtract(points[j], points[i]);
|
||||||
edgeNormal.x = -line.y;
|
edgeNormal = new es.Vector2(-line.y, line.x);
|
||||||
edgeNormal.y = line.x;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
edgeNormal = es.Vector2.normalize(edgeNormal);
|
edgeNormal = es.Vector2.normalize(edgeNormal);
|
||||||
@@ -5672,7 +6009,7 @@ var es;
|
|||||||
if (collider.entity.transform.rotation != 0) {
|
if (collider.entity.transform.rotation != 0) {
|
||||||
tempMat = es.Matrix2D.create().rotate(collider.entity.transform.rotation);
|
tempMat = es.Matrix2D.create().rotate(collider.entity.transform.rotation);
|
||||||
combinedMatrix = combinedMatrix.multiply(tempMat);
|
combinedMatrix = combinedMatrix.multiply(tempMat);
|
||||||
var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x);
|
var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * es.MathHelper.Rad2Deg;
|
||||||
var offsetLength = hasUnitScale ? collider._localOffsetLength :
|
var offsetLength = hasUnitScale ? collider._localOffsetLength :
|
||||||
es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length();
|
es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length();
|
||||||
this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle);
|
this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle);
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+63
-15
@@ -263,7 +263,7 @@ declare module es {
|
|||||||
onOrientationChanged(): void;
|
onOrientationChanged(): void;
|
||||||
protected onGraphicsDeviceReset(): void;
|
protected onGraphicsDeviceReset(): void;
|
||||||
protected initialize(): void;
|
protected initialize(): void;
|
||||||
protected update(): void;
|
protected update(): Promise<void>;
|
||||||
draw(): Promise<void>;
|
draw(): Promise<void>;
|
||||||
startDebugUpdate(): void;
|
startDebugUpdate(): void;
|
||||||
endDebugUpdate(): void;
|
endDebugUpdate(): void;
|
||||||
@@ -302,8 +302,16 @@ declare module es {
|
|||||||
parent: Transform;
|
parent: Transform;
|
||||||
readonly childCount: number;
|
readonly childCount: number;
|
||||||
position: Vector2;
|
position: Vector2;
|
||||||
|
localPosition: Vector2;
|
||||||
rotation: number;
|
rotation: number;
|
||||||
|
rotationDegrees: number;
|
||||||
|
localRotation: number;
|
||||||
|
localRotationDegrees: number;
|
||||||
scale: Vector2;
|
scale: Vector2;
|
||||||
|
localScale: Vector2;
|
||||||
|
readonly worldInverseTransform: Matrix2D;
|
||||||
|
readonly localToWorldTransform: Matrix2D;
|
||||||
|
readonly worldToLocalTransform: Matrix2D;
|
||||||
constructor(name: string);
|
constructor(name: string);
|
||||||
onTransformChanged(comp: transform.Component): void;
|
onTransformChanged(comp: transform.Component): void;
|
||||||
setTag(tag: number): Entity;
|
setTag(tag: number): Entity;
|
||||||
@@ -325,6 +333,7 @@ declare module es {
|
|||||||
removeComponent(component: Component): void;
|
removeComponent(component: Component): void;
|
||||||
removeComponentForType<T extends Component>(type: any): boolean;
|
removeComponentForType<T extends Component>(type: any): boolean;
|
||||||
removeAllComponents(): void;
|
removeAllComponents(): void;
|
||||||
|
compareTo(other: Entity): number;
|
||||||
toString(): string;
|
toString(): string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -389,21 +398,56 @@ declare module es {
|
|||||||
parent: Transform;
|
parent: Transform;
|
||||||
readonly childCount: number;
|
readonly childCount: number;
|
||||||
position: Vector2;
|
position: Vector2;
|
||||||
|
localPosition: Vector2;
|
||||||
rotation: number;
|
rotation: number;
|
||||||
|
rotationDegrees: number;
|
||||||
|
localRotation: number;
|
||||||
|
localRotationDegrees: number;
|
||||||
scale: Vector2;
|
scale: Vector2;
|
||||||
|
localScale: Vector2;
|
||||||
|
readonly worldInverseTransform: Matrix2D;
|
||||||
|
readonly localToWorldTransform: Matrix2D;
|
||||||
|
readonly worldToLocalTransform: Matrix2D;
|
||||||
_parent: Transform;
|
_parent: Transform;
|
||||||
hierarchyDirty: DirtyType;
|
hierarchyDirty: DirtyType;
|
||||||
|
_localDirty: boolean;
|
||||||
|
_localPositionDirty: boolean;
|
||||||
|
_localScaleDirty: boolean;
|
||||||
|
_localRotationDirty: boolean;
|
||||||
|
_positionDirty: boolean;
|
||||||
|
_worldToLocalDirty: boolean;
|
||||||
|
_worldInverseDirty: boolean;
|
||||||
|
_localTransform: Matrix2D;
|
||||||
|
_worldTransform: Matrix2D;
|
||||||
|
_worldToLocalTransform: Matrix2D;
|
||||||
|
_worldInverseTransform: Matrix2D;
|
||||||
|
_rotationMatrix: Matrix2D;
|
||||||
|
_translationMatrix: Matrix2D;
|
||||||
|
_scaleMatrix: Matrix2D;
|
||||||
|
_position: Vector2;
|
||||||
|
_scale: Vector2;
|
||||||
|
_rotation: number;
|
||||||
|
_localPosition: Vector2;
|
||||||
|
_localScale: Vector2;
|
||||||
|
_localRotation: number;
|
||||||
_children: Transform[];
|
_children: Transform[];
|
||||||
constructor(entity: Entity);
|
constructor(entity: Entity);
|
||||||
getChild(index: number): Transform;
|
getChild(index: number): Transform;
|
||||||
setParent(parent: Transform): Transform;
|
setParent(parent: Transform): Transform;
|
||||||
setPosition(x: number, y: number): Transform;
|
setPosition(x: number, y: number): Transform;
|
||||||
setRotation(degrees: number): Transform;
|
setLocalPosition(localPosition: Vector2): Transform;
|
||||||
setScale(scale: Vector2): Transform;
|
setRotation(radians: number): Transform;
|
||||||
|
setRotationDegrees(degrees: number): Transform;
|
||||||
lookAt(pos: Vector2): void;
|
lookAt(pos: Vector2): void;
|
||||||
|
setLocalRotation(radians: number): this;
|
||||||
|
setLocalRotationDegrees(degrees: number): Transform;
|
||||||
|
setScale(scale: Vector2): Transform;
|
||||||
|
setLocalScale(scale: Vector2): Transform;
|
||||||
roundPosition(): void;
|
roundPosition(): void;
|
||||||
|
updateTransform(): void;
|
||||||
setDirty(dirtyFlagType: DirtyType): void;
|
setDirty(dirtyFlagType: DirtyType): void;
|
||||||
copyFrom(transform: Transform): void;
|
copyFrom(transform: Transform): void;
|
||||||
|
toString(): string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -796,28 +840,32 @@ declare module es {
|
|||||||
declare module es {
|
declare module es {
|
||||||
class EntityList {
|
class EntityList {
|
||||||
scene: Scene;
|
scene: Scene;
|
||||||
private _entitiesToRemove;
|
_entities: Entity[];
|
||||||
private _entitiesToAdded;
|
_entitiesToAdded: Entity[];
|
||||||
private _tempEntityList;
|
_entitiesToRemove: Entity[];
|
||||||
private _entities;
|
_isEntityListUnsorted: boolean;
|
||||||
private _entityDict;
|
_entityDict: Map<number, Entity[]>;
|
||||||
private _unsortedTags;
|
_unsortedTags: number[];
|
||||||
|
_tempEntityList: Entity[];
|
||||||
constructor(scene: Scene);
|
constructor(scene: Scene);
|
||||||
readonly count: number;
|
readonly count: number;
|
||||||
readonly buffer: Entity[];
|
readonly buffer: Entity[];
|
||||||
|
markEntityListUnsorted(): void;
|
||||||
|
markTagUnsorted(tag: number): void;
|
||||||
add(entity: Entity): void;
|
add(entity: Entity): void;
|
||||||
remove(entity: Entity): void;
|
remove(entity: Entity): void;
|
||||||
|
removeAllEntities(): void;
|
||||||
|
contains(entity: Entity): boolean;
|
||||||
|
getTagList(tag: number): Entity[];
|
||||||
|
addToTagList(entity: Entity): void;
|
||||||
|
removeFromTagList(entity: Entity): void;
|
||||||
|
update(): void;
|
||||||
|
updateLists(): void;
|
||||||
findEntity(name: string): Entity;
|
findEntity(name: string): Entity;
|
||||||
entitiesWithTag(tag: number): Entity[];
|
entitiesWithTag(tag: number): Entity[];
|
||||||
entitiesOfType<T extends Entity>(type: any): T[];
|
entitiesOfType<T extends Entity>(type: any): T[];
|
||||||
findComponentOfType<T extends Component>(type: any): T;
|
findComponentOfType<T extends Component>(type: any): T;
|
||||||
findComponentsOfType<T extends Component>(type: any): T[];
|
findComponentsOfType<T extends Component>(type: any): T[];
|
||||||
getTagList(tag: number): Entity[];
|
|
||||||
addToTagList(entity: Entity): void;
|
|
||||||
removeFromTagList(entity: Entity): void;
|
|
||||||
update(): void;
|
|
||||||
removeAllEntities(): void;
|
|
||||||
updateLists(): void;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
|
|||||||
+434
-97
@@ -1156,10 +1156,15 @@ var es;
|
|||||||
Core.prototype.initialize = function () {
|
Core.prototype.initialize = function () {
|
||||||
};
|
};
|
||||||
Core.prototype.update = function () {
|
Core.prototype.update = function () {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var i;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
this.startDebugUpdate();
|
this.startDebugUpdate();
|
||||||
es.Time.update(egret.getTimer());
|
es.Time.update(egret.getTimer());
|
||||||
if (this._scene) {
|
if (!this._scene) return [3, 2];
|
||||||
for (var i = this._globalManagers.length - 1; i >= 0; i--) {
|
for (i = this._globalManagers.length - 1; i >= 0; i--) {
|
||||||
if (this._globalManagers[i].enabled)
|
if (this._globalManagers[i].enabled)
|
||||||
this._globalManagers[i].update();
|
this._globalManagers[i].update();
|
||||||
}
|
}
|
||||||
@@ -1167,15 +1172,21 @@ var es;
|
|||||||
(this._sceneTransition && (!this._sceneTransition.loadsNewScene || this._sceneTransition.isNewSceneLoaded))) {
|
(this._sceneTransition && (!this._sceneTransition.loadsNewScene || this._sceneTransition.isNewSceneLoaded))) {
|
||||||
this._scene.update();
|
this._scene.update();
|
||||||
}
|
}
|
||||||
if (this._nextScene) {
|
if (!this._nextScene) return [3, 2];
|
||||||
this._scene.end();
|
this._scene.end();
|
||||||
this._scene = this._nextScene;
|
this._scene = this._nextScene;
|
||||||
this._nextScene = null;
|
this._nextScene = null;
|
||||||
this.onSceneChanged();
|
this.onSceneChanged();
|
||||||
this._scene.begin();
|
return [4, this._scene.begin()];
|
||||||
}
|
case 1:
|
||||||
}
|
_a.sent();
|
||||||
|
_a.label = 2;
|
||||||
|
case 2:
|
||||||
this.endDebugUpdate();
|
this.endDebugUpdate();
|
||||||
|
return [2];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
Core.prototype.draw = function () {
|
Core.prototype.draw = function () {
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
@@ -1338,6 +1349,16 @@ var es;
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "localPosition", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.localPosition;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.transform.setLocalPosition(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
Object.defineProperty(Entity.prototype, "rotation", {
|
Object.defineProperty(Entity.prototype, "rotation", {
|
||||||
get: function () {
|
get: function () {
|
||||||
return this.transform.rotation;
|
return this.transform.rotation;
|
||||||
@@ -1348,6 +1369,36 @@ var es;
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "rotationDegrees", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.rotationDegrees;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.transform.setRotationDegrees(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "localRotation", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.localRotation;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.transform.setLocalRotation(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "localRotationDegrees", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.localRotationDegrees;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.transform.setLocalRotationDegrees(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
Object.defineProperty(Entity.prototype, "scale", {
|
Object.defineProperty(Entity.prototype, "scale", {
|
||||||
get: function () {
|
get: function () {
|
||||||
return this.transform.scale;
|
return this.transform.scale;
|
||||||
@@ -1358,6 +1409,37 @@ var es;
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "localScale", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.localScale;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.transform.setLocalScale(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "worldInverseTransform", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.worldInverseTransform;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "localToWorldTransform", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.localToWorldTransform;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Entity.prototype, "worldToLocalTransform", {
|
||||||
|
get: function () {
|
||||||
|
return this.transform.worldToLocalTransform;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
Entity.prototype.onTransformChanged = function (comp) {
|
Entity.prototype.onTransformChanged = function (comp) {
|
||||||
this.components.onEntityTransformChanged(comp);
|
this.components.onEntityTransformChanged(comp);
|
||||||
};
|
};
|
||||||
@@ -1385,6 +1467,8 @@ var es;
|
|||||||
if (this._updateOrder != updateOrder) {
|
if (this._updateOrder != updateOrder) {
|
||||||
this._updateOrder = updateOrder;
|
this._updateOrder = updateOrder;
|
||||||
if (this.scene) {
|
if (this.scene) {
|
||||||
|
this.scene.entities.markEntityListUnsorted();
|
||||||
|
this.scene.entities.markTagUnsorted(this.tag);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -1484,6 +1568,12 @@ var es;
|
|||||||
this.removeComponent(this.components.buffer[i]);
|
this.removeComponent(this.components.buffer[i]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Entity.prototype.compareTo = function (other) {
|
||||||
|
var compare = this._updateOrder - other._updateOrder;
|
||||||
|
if (compare == 0)
|
||||||
|
compare = this.id - other.id;
|
||||||
|
return compare;
|
||||||
|
};
|
||||||
Entity.prototype.toString = function () {
|
Entity.prototype.toString = function () {
|
||||||
return "[Entity: name: " + this.name + ", tag: " + this.tag + ", enabled: " + this.enabled + ", depth: " + this.updateOrder + "]";
|
return "[Entity: name: " + this.name + ", tag: " + this.tag + ", enabled: " + this.enabled + ", depth: " + this.updateOrder + "]";
|
||||||
};
|
};
|
||||||
@@ -1697,6 +1787,9 @@ var es;
|
|||||||
})(DirtyType = es.DirtyType || (es.DirtyType = {}));
|
})(DirtyType = es.DirtyType || (es.DirtyType = {}));
|
||||||
var Transform = (function () {
|
var Transform = (function () {
|
||||||
function Transform(entity) {
|
function Transform(entity) {
|
||||||
|
this._worldTransform = es.Matrix2D.create().identity();
|
||||||
|
this._worldToLocalTransform = es.Matrix2D.create().identity();
|
||||||
|
this._worldInverseTransform = es.Matrix2D.create().identity();
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.scale = es.Vector2.one;
|
this.scale = es.Vector2.one;
|
||||||
this._children = [];
|
this._children = [];
|
||||||
@@ -1718,6 +1811,139 @@ var es;
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "position", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
if (this._positionDirty) {
|
||||||
|
if (!this.parent) {
|
||||||
|
this._position = this._localPosition;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.parent.updateTransform();
|
||||||
|
this._position = es.Vector2Ext.transformR(this._localPosition, this.parent._worldTransform);
|
||||||
|
}
|
||||||
|
this._positionDirty = false;
|
||||||
|
}
|
||||||
|
return this._position;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setPosition(value.x, value.y);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "localPosition", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._localPosition;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setLocalPosition(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "rotation", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._rotation;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setRotation(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "rotationDegrees", {
|
||||||
|
get: function () {
|
||||||
|
return es.MathHelper.toDegrees(this._rotation);
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setRotation(es.MathHelper.toRadians(value));
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "localRotation", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._localRotation;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setLocalRotation(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "localRotationDegrees", {
|
||||||
|
get: function () {
|
||||||
|
return es.MathHelper.toDegrees(this._localRotation);
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.localRotation = es.MathHelper.toRadians(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "scale", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._scale;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setScale(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "localScale", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._localScale;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setLocalScale(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "worldInverseTransform", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
if (this._worldInverseDirty) {
|
||||||
|
this._worldInverseTransform = this._worldTransform.invert();
|
||||||
|
this._worldInverseDirty = false;
|
||||||
|
}
|
||||||
|
return this._worldInverseTransform;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "localToWorldTransform", {
|
||||||
|
get: function () {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._worldTransform;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Transform.prototype, "worldToLocalTransform", {
|
||||||
|
get: function () {
|
||||||
|
if (this._worldToLocalDirty) {
|
||||||
|
if (!this.parent) {
|
||||||
|
this._worldToLocalTransform = es.Matrix2D.create().identity();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.parent.updateTransform();
|
||||||
|
this._worldToLocalTransform = this.parent._worldTransform.invert();
|
||||||
|
}
|
||||||
|
this._worldToLocalDirty = false;
|
||||||
|
}
|
||||||
|
return this._worldToLocalTransform;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
Transform.prototype.getChild = function (index) {
|
Transform.prototype.getChild = function (index) {
|
||||||
return this._children[index];
|
return this._children[index];
|
||||||
};
|
};
|
||||||
@@ -1733,27 +1959,110 @@ var es;
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Transform.prototype.setPosition = function (x, y) {
|
Transform.prototype.setPosition = function (x, y) {
|
||||||
this.position = new es.Vector2(x, y);
|
var position = new es.Vector2(x, y);
|
||||||
|
if (position == this._position)
|
||||||
|
return this;
|
||||||
|
this._position = position;
|
||||||
|
if (this.parent) {
|
||||||
|
this.localPosition = es.Vector2Ext.transformR(this._position, this._worldToLocalTransform);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.localPosition = position;
|
||||||
|
}
|
||||||
|
this._positionDirty = false;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
Transform.prototype.setLocalPosition = function (localPosition) {
|
||||||
|
if (localPosition == this._localPosition)
|
||||||
|
return this;
|
||||||
|
this._localPosition = localPosition;
|
||||||
|
this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true;
|
||||||
this.setDirty(DirtyType.positionDirty);
|
this.setDirty(DirtyType.positionDirty);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Transform.prototype.setRotation = function (degrees) {
|
Transform.prototype.setRotation = function (radians) {
|
||||||
this.rotation = degrees;
|
this._rotation = radians;
|
||||||
this.setDirty(DirtyType.rotationDirty);
|
if (this.parent) {
|
||||||
|
this.localRotation = this.parent.rotation + radians;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.localRotation = radians;
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Transform.prototype.setScale = function (scale) {
|
Transform.prototype.setRotationDegrees = function (degrees) {
|
||||||
this.scale = scale;
|
return this.setRotation(es.MathHelper.toRadians(degrees));
|
||||||
this.setDirty(DirtyType.scaleDirty);
|
|
||||||
return this;
|
|
||||||
};
|
};
|
||||||
Transform.prototype.lookAt = function (pos) {
|
Transform.prototype.lookAt = function (pos) {
|
||||||
var sign = this.position.x > pos.x ? -1 : 1;
|
var sign = this.position.x > pos.x ? -1 : 1;
|
||||||
var vectorToAlignTo = es.Vector2.normalize(es.Vector2.subtract(this.position, pos));
|
var vectorToAlignTo = es.Vector2.normalize(es.Vector2.subtract(this.position, pos));
|
||||||
this.rotation = sign * Math.acos(es.Vector2.dot(vectorToAlignTo, es.Vector2.unitY));
|
this.rotation = sign * Math.acos(es.Vector2.dot(vectorToAlignTo, es.Vector2.unitY));
|
||||||
};
|
};
|
||||||
|
Transform.prototype.setLocalRotation = function (radians) {
|
||||||
|
this._localRotation = radians;
|
||||||
|
this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true;
|
||||||
|
this.setDirty(DirtyType.rotationDirty);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
Transform.prototype.setLocalRotationDegrees = function (degrees) {
|
||||||
|
return this.setLocalRotation(es.MathHelper.toRadians(degrees));
|
||||||
|
};
|
||||||
|
Transform.prototype.setScale = function (scale) {
|
||||||
|
this._scale = scale;
|
||||||
|
if (this.parent) {
|
||||||
|
this.localScale = es.Vector2.divide(scale, this.parent._scale);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.localScale = scale;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
Transform.prototype.setLocalScale = function (scale) {
|
||||||
|
this._localScale = scale;
|
||||||
|
this._localDirty = this._positionDirty = this._localScaleDirty = true;
|
||||||
|
this.setDirty(DirtyType.scaleDirty);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
Transform.prototype.roundPosition = function () {
|
Transform.prototype.roundPosition = function () {
|
||||||
this.position = this.position.round();
|
this.position = this._position.round();
|
||||||
|
};
|
||||||
|
Transform.prototype.updateTransform = function () {
|
||||||
|
if (this.hierarchyDirty != DirtyType.clean) {
|
||||||
|
if (this.parent)
|
||||||
|
this.parent.updateTransform();
|
||||||
|
if (this._localDirty) {
|
||||||
|
if (this._localPositionDirty) {
|
||||||
|
this._translationMatrix = es.Matrix2D.create().translate(this._localPosition.x, this._localPosition.y);
|
||||||
|
this._localPositionDirty = false;
|
||||||
|
}
|
||||||
|
if (this._localRotationDirty) {
|
||||||
|
this._rotationMatrix = es.Matrix2D.create().rotate(this._localRotation);
|
||||||
|
this._localRotationDirty = false;
|
||||||
|
}
|
||||||
|
if (this._localScaleDirty) {
|
||||||
|
this._scaleMatrix = es.Matrix2D.create().scale(this._localScale.x, this._localScale.y);
|
||||||
|
this._localScaleDirty = false;
|
||||||
|
}
|
||||||
|
this._localTransform = this._scaleMatrix.multiply(this._rotationMatrix);
|
||||||
|
this._localTransform = this._localTransform.multiply(this._translationMatrix);
|
||||||
|
if (!this.parent) {
|
||||||
|
this._worldTransform = this._localTransform;
|
||||||
|
this._rotation = this._localRotation;
|
||||||
|
this._scale = this._localScale;
|
||||||
|
this._worldInverseDirty = true;
|
||||||
|
}
|
||||||
|
this._localDirty = false;
|
||||||
|
}
|
||||||
|
if (this.parent) {
|
||||||
|
this._worldTransform = this._localTransform.multiply(this.parent._worldTransform);
|
||||||
|
this._rotation = this._localRotation + this.parent._rotation;
|
||||||
|
this._scale = es.Vector2.multiply(this.parent._scale, this._localScale);
|
||||||
|
this._worldInverseDirty = true;
|
||||||
|
}
|
||||||
|
this._worldToLocalDirty = true;
|
||||||
|
this._positionDirty = true;
|
||||||
|
this.hierarchyDirty = DirtyType.clean;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Transform.prototype.setDirty = function (dirtyFlagType) {
|
Transform.prototype.setDirty = function (dirtyFlagType) {
|
||||||
if ((this.hierarchyDirty & dirtyFlagType) == 0) {
|
if ((this.hierarchyDirty & dirtyFlagType) == 0) {
|
||||||
@@ -1776,13 +2085,19 @@ var es;
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Transform.prototype.copyFrom = function (transform) {
|
Transform.prototype.copyFrom = function (transform) {
|
||||||
this.position = transform.position;
|
this._position = transform.position;
|
||||||
this.rotation = transform.rotation;
|
this._localPosition = transform._localPosition;
|
||||||
this.scale = transform.scale;
|
this._rotation = transform._rotation;
|
||||||
|
this._localRotation = transform._localRotation;
|
||||||
|
this._scale = transform._scale;
|
||||||
|
this._localScale = transform._localScale;
|
||||||
this.setDirty(DirtyType.positionDirty);
|
this.setDirty(DirtyType.positionDirty);
|
||||||
this.setDirty(DirtyType.rotationDirty);
|
this.setDirty(DirtyType.rotationDirty);
|
||||||
this.setDirty(DirtyType.scaleDirty);
|
this.setDirty(DirtyType.scaleDirty);
|
||||||
};
|
};
|
||||||
|
Transform.prototype.toString = function () {
|
||||||
|
return "[Transform: parent: " + this.parent + ", position: " + this.position + ", rotation: " + this.rotation + ",\n scale: " + this.scale + ", localPosition: " + this._localPosition + ", localRotation: " + this._localRotation + ",\n localScale: " + this._localScale + "]";
|
||||||
|
};
|
||||||
return Transform;
|
return Transform;
|
||||||
}());
|
}());
|
||||||
es.Transform = Transform;
|
es.Transform = Transform;
|
||||||
@@ -3432,12 +3747,12 @@ var es;
|
|||||||
(function (es) {
|
(function (es) {
|
||||||
var EntityList = (function () {
|
var EntityList = (function () {
|
||||||
function EntityList(scene) {
|
function EntityList(scene) {
|
||||||
this._entitiesToRemove = [];
|
|
||||||
this._entitiesToAdded = [];
|
|
||||||
this._tempEntityList = [];
|
|
||||||
this._entities = [];
|
this._entities = [];
|
||||||
|
this._entitiesToAdded = [];
|
||||||
|
this._entitiesToRemove = [];
|
||||||
this._entityDict = new Map();
|
this._entityDict = new Map();
|
||||||
this._unsortedTags = [];
|
this._unsortedTags = [];
|
||||||
|
this._tempEntityList = [];
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
}
|
}
|
||||||
Object.defineProperty(EntityList.prototype, "count", {
|
Object.defineProperty(EntityList.prototype, "count", {
|
||||||
@@ -3454,11 +3769,21 @@ var es;
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
EntityList.prototype.markEntityListUnsorted = function () {
|
||||||
|
this._isEntityListUnsorted = true;
|
||||||
|
};
|
||||||
|
EntityList.prototype.markTagUnsorted = function (tag) {
|
||||||
|
this._unsortedTags.push(tag);
|
||||||
|
};
|
||||||
EntityList.prototype.add = function (entity) {
|
EntityList.prototype.add = function (entity) {
|
||||||
if (this._entitiesToAdded.indexOf(entity) == -1)
|
if (this._entitiesToAdded.indexOf(entity) == -1)
|
||||||
this._entitiesToAdded.push(entity);
|
this._entitiesToAdded.push(entity);
|
||||||
};
|
};
|
||||||
EntityList.prototype.remove = function (entity) {
|
EntityList.prototype.remove = function (entity) {
|
||||||
|
if (!this._entitiesToRemove.contains(entity)) {
|
||||||
|
console.warn("You are trying to remove an entity (" + entity.name + ") that you already removed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this._entitiesToAdded.contains(entity)) {
|
if (this._entitiesToAdded.contains(entity)) {
|
||||||
this._entitiesToAdded.remove(entity);
|
this._entitiesToAdded.remove(entity);
|
||||||
return;
|
return;
|
||||||
@@ -3466,6 +3791,92 @@ var es;
|
|||||||
if (!this._entitiesToRemove.contains(entity))
|
if (!this._entitiesToRemove.contains(entity))
|
||||||
this._entitiesToRemove.push(entity);
|
this._entitiesToRemove.push(entity);
|
||||||
};
|
};
|
||||||
|
EntityList.prototype.removeAllEntities = function () {
|
||||||
|
this._unsortedTags.length = 0;
|
||||||
|
this._entitiesToAdded.length = 0;
|
||||||
|
this._isEntityListUnsorted = false;
|
||||||
|
this.updateLists();
|
||||||
|
for (var i = 0; i < this._entities.length; i++) {
|
||||||
|
this._entities[i]._isDestroyed = true;
|
||||||
|
this._entities[i].onRemovedFromScene();
|
||||||
|
this._entities[i].scene = null;
|
||||||
|
}
|
||||||
|
this._entities.length = 0;
|
||||||
|
this._entityDict.clear();
|
||||||
|
};
|
||||||
|
EntityList.prototype.contains = function (entity) {
|
||||||
|
return this._entities.contains(entity) || this._entitiesToAdded.contains(entity);
|
||||||
|
};
|
||||||
|
EntityList.prototype.getTagList = function (tag) {
|
||||||
|
var list = this._entityDict.get(tag);
|
||||||
|
if (!list) {
|
||||||
|
list = [];
|
||||||
|
this._entityDict.set(tag, list);
|
||||||
|
}
|
||||||
|
return this._entityDict.get(tag);
|
||||||
|
};
|
||||||
|
EntityList.prototype.addToTagList = function (entity) {
|
||||||
|
var list = this.getTagList(entity.tag);
|
||||||
|
if (!list.contains(entity)) {
|
||||||
|
list.push(entity);
|
||||||
|
this._unsortedTags.push(entity.tag);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
EntityList.prototype.removeFromTagList = function (entity) {
|
||||||
|
var list = this._entityDict.get(entity.tag);
|
||||||
|
if (list) {
|
||||||
|
list.remove(entity);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
EntityList.prototype.update = function () {
|
||||||
|
for (var i = 0; i < this._entities.length; i++) {
|
||||||
|
var entity = this._entities[i];
|
||||||
|
if (entity.enabled && (entity.updateInterval == 1 || es.Time.frameCount % entity.updateInterval == 0))
|
||||||
|
entity.update();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
EntityList.prototype.updateLists = function () {
|
||||||
|
var _this = this;
|
||||||
|
if (this._entitiesToRemove.length > 0) {
|
||||||
|
var temp = this._entitiesToRemove;
|
||||||
|
this._entitiesToRemove = this._tempEntityList;
|
||||||
|
this._tempEntityList = temp;
|
||||||
|
this._tempEntityList.forEach(function (entity) {
|
||||||
|
_this.removeFromTagList(entity);
|
||||||
|
_this._entities.remove(entity);
|
||||||
|
entity.onRemovedFromScene();
|
||||||
|
entity.scene = null;
|
||||||
|
_this.scene.entityProcessors.onEntityRemoved(entity);
|
||||||
|
});
|
||||||
|
this._tempEntityList.length = 0;
|
||||||
|
}
|
||||||
|
if (this._entitiesToAdded.length > 0) {
|
||||||
|
var temp = this._entitiesToAdded;
|
||||||
|
this._entitiesToAdded = this._tempEntityList;
|
||||||
|
this._tempEntityList = temp;
|
||||||
|
this._tempEntityList.forEach(function (entity) {
|
||||||
|
if (!_this._entities.contains(entity)) {
|
||||||
|
_this._entities.push(entity);
|
||||||
|
entity.scene = _this.scene;
|
||||||
|
_this.addToTagList(entity);
|
||||||
|
_this.scene.entityProcessors.onEntityAdded(entity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); });
|
||||||
|
this._tempEntityList.length = 0;
|
||||||
|
this._isEntityListUnsorted = true;
|
||||||
|
}
|
||||||
|
if (this._isEntityListUnsorted) {
|
||||||
|
this._entities.sort();
|
||||||
|
this._isEntityListUnsorted = false;
|
||||||
|
}
|
||||||
|
if (this._unsortedTags.length > 0) {
|
||||||
|
this._unsortedTags.forEach(function (tag) {
|
||||||
|
_this._entityDict.get(tag).sort();
|
||||||
|
});
|
||||||
|
this._unsortedTags.length = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
EntityList.prototype.findEntity = function (name) {
|
EntityList.prototype.findEntity = function (name) {
|
||||||
for (var i = 0; i < this._entities.length; i++) {
|
for (var i = 0; i < this._entities.length; i++) {
|
||||||
if (this._entities[i].name == name)
|
if (this._entities[i].name == name)
|
||||||
@@ -3523,79 +3934,6 @@ var es;
|
|||||||
}
|
}
|
||||||
return comps;
|
return comps;
|
||||||
};
|
};
|
||||||
EntityList.prototype.getTagList = function (tag) {
|
|
||||||
var list = this._entityDict.get(tag);
|
|
||||||
if (!list) {
|
|
||||||
list = [];
|
|
||||||
this._entityDict.set(tag, list);
|
|
||||||
}
|
|
||||||
return this._entityDict.get(tag);
|
|
||||||
};
|
|
||||||
EntityList.prototype.addToTagList = function (entity) {
|
|
||||||
var list = this.getTagList(entity.tag);
|
|
||||||
if (!list.contains(entity)) {
|
|
||||||
list.push(entity);
|
|
||||||
this._unsortedTags.push(entity.tag);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
EntityList.prototype.removeFromTagList = function (entity) {
|
|
||||||
var list = this._entityDict.get(entity.tag);
|
|
||||||
if (list) {
|
|
||||||
list.remove(entity);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
EntityList.prototype.update = function () {
|
|
||||||
for (var i = 0; i < this._entities.length; i++) {
|
|
||||||
var entity = this._entities[i];
|
|
||||||
if (entity.enabled)
|
|
||||||
entity.update();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
EntityList.prototype.removeAllEntities = function () {
|
|
||||||
this._entitiesToAdded.length = 0;
|
|
||||||
this.updateLists();
|
|
||||||
for (var i = 0; i < this._entities.length; i++) {
|
|
||||||
this._entities[i]._isDestroyed = true;
|
|
||||||
this._entities[i].onRemovedFromScene();
|
|
||||||
this._entities[i].scene = null;
|
|
||||||
}
|
|
||||||
this._entities.length = 0;
|
|
||||||
this._entityDict.clear();
|
|
||||||
};
|
|
||||||
EntityList.prototype.updateLists = function () {
|
|
||||||
var _this = this;
|
|
||||||
if (this._entitiesToRemove.length > 0) {
|
|
||||||
var temp = this._entitiesToRemove;
|
|
||||||
this._entitiesToRemove = this._tempEntityList;
|
|
||||||
this._tempEntityList = temp;
|
|
||||||
this._tempEntityList.forEach(function (entity) {
|
|
||||||
_this._entities.remove(entity);
|
|
||||||
entity.scene = null;
|
|
||||||
_this.scene.entityProcessors.onEntityRemoved(entity);
|
|
||||||
});
|
|
||||||
this._tempEntityList.length = 0;
|
|
||||||
}
|
|
||||||
if (this._entitiesToAdded.length > 0) {
|
|
||||||
var temp = this._entitiesToAdded;
|
|
||||||
this._entitiesToAdded = this._tempEntityList;
|
|
||||||
this._tempEntityList = temp;
|
|
||||||
this._tempEntityList.forEach(function (entity) {
|
|
||||||
if (!_this._entities.contains(entity)) {
|
|
||||||
_this._entities.push(entity);
|
|
||||||
entity.scene = _this.scene;
|
|
||||||
_this.scene.entityProcessors.onEntityAdded(entity);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); });
|
|
||||||
this._tempEntityList.length = 0;
|
|
||||||
}
|
|
||||||
if (this._unsortedTags.length > 0) {
|
|
||||||
this._unsortedTags.forEach(function (tag) {
|
|
||||||
_this._entityDict.get(tag).sort();
|
|
||||||
});
|
|
||||||
this._unsortedTags.length = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return EntityList;
|
return EntityList;
|
||||||
}());
|
}());
|
||||||
es.EntityList = EntityList;
|
es.EntityList = EntityList;
|
||||||
@@ -5650,8 +5988,7 @@ var es;
|
|||||||
distanceSquared = tempDistanceSquared;
|
distanceSquared = tempDistanceSquared;
|
||||||
closestPoint = closest;
|
closestPoint = closest;
|
||||||
var line = es.Vector2.subtract(points[j], points[i]);
|
var line = es.Vector2.subtract(points[j], points[i]);
|
||||||
edgeNormal.x = -line.y;
|
edgeNormal = new es.Vector2(-line.y, line.x);
|
||||||
edgeNormal.y = line.x;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
edgeNormal = es.Vector2.normalize(edgeNormal);
|
edgeNormal = es.Vector2.normalize(edgeNormal);
|
||||||
@@ -5672,7 +6009,7 @@ var es;
|
|||||||
if (collider.entity.transform.rotation != 0) {
|
if (collider.entity.transform.rotation != 0) {
|
||||||
tempMat = es.Matrix2D.create().rotate(collider.entity.transform.rotation);
|
tempMat = es.Matrix2D.create().rotate(collider.entity.transform.rotation);
|
||||||
combinedMatrix = combinedMatrix.multiply(tempMat);
|
combinedMatrix = combinedMatrix.multiply(tempMat);
|
||||||
var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x);
|
var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * es.MathHelper.Rad2Deg;
|
||||||
var offsetLength = hasUnitScale ? collider._localOffsetLength :
|
var offsetLength = hasUnitScale ? collider._localOffsetLength :
|
||||||
es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length();
|
es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length();
|
||||||
this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle);
|
this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle);
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -99,7 +99,7 @@ module es {
|
|||||||
protected initialize(){
|
protected initialize(){
|
||||||
}
|
}
|
||||||
|
|
||||||
protected update() {
|
protected async update() {
|
||||||
this.startDebugUpdate();
|
this.startDebugUpdate();
|
||||||
|
|
||||||
// 更新我们所有的系统管理器
|
// 更新我们所有的系统管理器
|
||||||
@@ -127,7 +127,7 @@ module es {
|
|||||||
this._nextScene = null;
|
this._nextScene = null;
|
||||||
this.onSceneChanged();
|
this.onSceneChanged();
|
||||||
|
|
||||||
this._scene.begin();
|
await this._scene.begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,14 @@ module es {
|
|||||||
this.transform.setPosition(value.x, value.y);
|
this.transform.setPosition(value.x, value.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get localPosition(): Vector2 {
|
||||||
|
return this.transform.localPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set localPosition(value: Vector2){
|
||||||
|
this.transform.setLocalPosition(value);
|
||||||
|
}
|
||||||
|
|
||||||
public get rotation(): number {
|
public get rotation(): number {
|
||||||
return this.transform.rotation;
|
return this.transform.rotation;
|
||||||
}
|
}
|
||||||
@@ -115,6 +123,29 @@ module es {
|
|||||||
this.transform.setRotation(value);
|
this.transform.setRotation(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get rotationDegrees(): number {
|
||||||
|
return this.transform.rotationDegrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set rotationDegrees(value: number){
|
||||||
|
this.transform.setRotationDegrees(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get localRotation(): number {
|
||||||
|
return this.transform.localRotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set localRotation(value: number){
|
||||||
|
this.transform.setLocalRotation(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get localRotationDegrees(): number {
|
||||||
|
return this.transform.localRotationDegrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set localRotationDegrees(value: number){
|
||||||
|
this.transform.setLocalRotationDegrees(value);
|
||||||
|
}
|
||||||
|
|
||||||
public get scale(): Vector2 {
|
public get scale(): Vector2 {
|
||||||
return this.transform.scale;
|
return this.transform.scale;
|
||||||
@@ -124,6 +155,26 @@ module es {
|
|||||||
this.transform.setScale(value);
|
this.transform.setScale(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get localScale(): Vector2 {
|
||||||
|
return this.transform.localScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set localScale(value: Vector2){
|
||||||
|
this.transform.setLocalScale(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get worldInverseTransform(): Matrix2D {
|
||||||
|
return this.transform.worldInverseTransform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get localToWorldTransform(): Matrix2D {
|
||||||
|
return this.transform.localToWorldTransform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get worldToLocalTransform(): Matrix2D {
|
||||||
|
return this.transform.worldToLocalTransform;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(name: string) {
|
constructor(name: string) {
|
||||||
this.components = new ComponentList(this);
|
this.components = new ComponentList(this);
|
||||||
this.transform = new Transform(this);
|
this.transform = new Transform(this);
|
||||||
@@ -180,8 +231,8 @@ module es {
|
|||||||
if (this._updateOrder != updateOrder) {
|
if (this._updateOrder != updateOrder) {
|
||||||
this._updateOrder = updateOrder;
|
this._updateOrder = updateOrder;
|
||||||
if (this.scene) {
|
if (this.scene) {
|
||||||
// TODO: markEntityListSorted
|
this.scene.entities.markEntityListUnsorted();
|
||||||
// markTagUnsorted
|
this.scene.entities.markTagUnsorted(this.tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@@ -370,6 +421,13 @@ module es {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public compareTo(other: Entity): number {
|
||||||
|
let compare = this._updateOrder - other._updateOrder;
|
||||||
|
if (compare == 0)
|
||||||
|
compare = this.id - other.id;
|
||||||
|
return compare;
|
||||||
|
}
|
||||||
|
|
||||||
public toString(): string {
|
public toString(): string {
|
||||||
return `[Entity: name: ${this.name}, tag: ${this.tag}, enabled: ${this.enabled}, depth: ${this.updateOrder}]`;
|
return `[Entity: name: ${this.name}, tag: ${this.tag}, enabled: ${this.enabled}, depth: ${this.updateOrder}]`;
|
||||||
}
|
}
|
||||||
|
|||||||
+340
-22
@@ -42,18 +42,204 @@ module es {
|
|||||||
/**
|
/**
|
||||||
* 变换在世界空间中的位置
|
* 变换在世界空间中的位置
|
||||||
*/
|
*/
|
||||||
public position: Vector2;
|
public get position(): Vector2 {
|
||||||
|
this.updateTransform();
|
||||||
|
if (this._positionDirty){
|
||||||
|
if (!this.parent){
|
||||||
|
this._position = this._localPosition;
|
||||||
|
}else{
|
||||||
|
this.parent.updateTransform();
|
||||||
|
this._position = Vector2Ext.transformR(this._localPosition, this.parent._worldTransform);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._positionDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._position;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变换在世界空间中的位置
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public set position(value: Vector2){
|
||||||
|
this.setPosition(value.x, value.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换相对于父转换的位置。如果转换没有父元素,则与transform.position相同
|
||||||
|
*/
|
||||||
|
public get localPosition(): Vector2 {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._localPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换相对于父转换的位置。如果转换没有父元素,则与transform.position相同
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public set localPosition(value: Vector2){
|
||||||
|
this.setLocalPosition(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在世界空间中以弧度旋转的变换
|
||||||
|
*/
|
||||||
|
public get rotation(): number {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._rotation;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 变换在世界空间的旋转度
|
* 变换在世界空间的旋转度
|
||||||
*/
|
*/
|
||||||
public rotation: number;
|
public get rotationDegrees(): number {
|
||||||
|
return MathHelper.toDegrees(this._rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变换在世界空间的旋转度
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public set rotationDegrees(value: number){
|
||||||
|
this.setRotation(MathHelper.toRadians(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变换在世界空间的旋转度
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public set rotation(value: number){
|
||||||
|
this.setRotation(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 相对于父变换的旋转,变换的旋转。如果转换没有父元素,则与transform.rotation相同
|
||||||
|
*/
|
||||||
|
public get localRotation(): number {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._localRotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 相对于父变换的旋转,变换的旋转。如果转换没有父元素,则与transform.rotation相同
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public set localRotation(value: number){
|
||||||
|
this.setLocalRotation(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 旋转相对于父变换旋转的角度
|
||||||
|
*/
|
||||||
|
public get localRotationDegrees(): number {
|
||||||
|
return MathHelper.toDegrees(this._localRotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 旋转相对于父变换旋转的角度
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public set localRotationDegrees(value: number){
|
||||||
|
this.localRotation = MathHelper.toRadians(value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 变换在世界空间的缩放
|
* 变换在世界空间的缩放
|
||||||
*/
|
*/
|
||||||
public scale: Vector2;
|
public get scale(): Vector2{
|
||||||
|
this.updateTransform();
|
||||||
|
return this._scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变换在世界空间的缩放
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public set scale(value: Vector2){
|
||||||
|
this.setScale(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换相对于父元素的比例。如果转换没有父元素,则与transform.scale相同
|
||||||
|
*/
|
||||||
|
public get localScale(): Vector2 {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._localScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换相对于父元素的比例。如果转换没有父元素,则与transform.scale相同
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public set localScale(value: Vector2){
|
||||||
|
this.setLocalScale(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get worldInverseTransform(): Matrix2D {
|
||||||
|
this.updateTransform();
|
||||||
|
if (this._worldInverseDirty){
|
||||||
|
this._worldInverseTransform = this._worldTransform.invert();
|
||||||
|
this._worldInverseDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._worldInverseTransform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get localToWorldTransform(): Matrix2D {
|
||||||
|
this.updateTransform();
|
||||||
|
return this._worldTransform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get worldToLocalTransform(): Matrix2D {
|
||||||
|
if (this._worldToLocalDirty){
|
||||||
|
if (!this.parent){
|
||||||
|
this._worldToLocalTransform = Matrix2D.create().identity();
|
||||||
|
}else{
|
||||||
|
this.parent.updateTransform();
|
||||||
|
this._worldToLocalTransform = this.parent._worldTransform.invert();
|
||||||
|
}
|
||||||
|
|
||||||
|
this._worldToLocalDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._worldToLocalTransform;
|
||||||
|
}
|
||||||
|
|
||||||
public _parent: Transform;
|
public _parent: Transform;
|
||||||
public hierarchyDirty: DirtyType;
|
public hierarchyDirty: DirtyType;
|
||||||
|
|
||||||
|
public _localDirty: boolean;
|
||||||
|
public _localPositionDirty: boolean;
|
||||||
|
public _localScaleDirty: boolean;
|
||||||
|
public _localRotationDirty: boolean;
|
||||||
|
public _positionDirty: boolean;
|
||||||
|
public _worldToLocalDirty: boolean;
|
||||||
|
public _worldInverseDirty: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 值会根据位置、旋转和比例自动重新计算
|
||||||
|
*/
|
||||||
|
public _localTransform: Matrix2D;
|
||||||
|
/**
|
||||||
|
* 值将自动从本地和父矩阵重新计算。
|
||||||
|
*/
|
||||||
|
public _worldTransform = Matrix2D.create().identity();
|
||||||
|
public _worldToLocalTransform = Matrix2D.create().identity();
|
||||||
|
public _worldInverseTransform = Matrix2D.create().identity();
|
||||||
|
|
||||||
|
public _rotationMatrix: Matrix2D;
|
||||||
|
public _translationMatrix: Matrix2D;
|
||||||
|
public _scaleMatrix: Matrix2D;
|
||||||
|
|
||||||
|
public _position: Vector2;
|
||||||
|
public _scale: Vector2;
|
||||||
|
public _rotation: number;
|
||||||
|
|
||||||
|
public _localPosition: Vector2;
|
||||||
|
public _localScale: Vector2;
|
||||||
|
public _localRotation: number;
|
||||||
|
|
||||||
public _children: Transform[];
|
public _children: Transform[];
|
||||||
|
|
||||||
constructor(entity: Entity) {
|
constructor(entity: Entity) {
|
||||||
@@ -95,8 +281,49 @@ module es {
|
|||||||
* @param y
|
* @param y
|
||||||
*/
|
*/
|
||||||
public setPosition(x: number, y: number): Transform {
|
public setPosition(x: number, y: number): Transform {
|
||||||
this.position = new Vector2(x, y);
|
let position = new Vector2(x, y);
|
||||||
|
if (position == this._position)
|
||||||
|
return this;
|
||||||
|
|
||||||
|
this._position = position;
|
||||||
|
if (this.parent){
|
||||||
|
this.localPosition = Vector2Ext.transformR(this._position, this._worldToLocalTransform);
|
||||||
|
} else {
|
||||||
|
this.localPosition = position;
|
||||||
|
}
|
||||||
|
this._positionDirty = false;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置转换相对于父转换的位置。如果转换没有父元素,则与transform.position相同
|
||||||
|
* @param localPosition
|
||||||
|
*/
|
||||||
|
public setLocalPosition(localPosition: Vector2): Transform {
|
||||||
|
if (localPosition == this._localPosition)
|
||||||
|
return this;
|
||||||
|
|
||||||
|
this._localPosition = localPosition;
|
||||||
|
this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true;
|
||||||
this.setDirty(DirtyType.positionDirty);
|
this.setDirty(DirtyType.positionDirty);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置变换在世界空间的旋转度
|
||||||
|
* @param radians
|
||||||
|
*/
|
||||||
|
public setRotation(radians: number): Transform {
|
||||||
|
this._rotation = radians;
|
||||||
|
if (this.parent){
|
||||||
|
this.localRotation = this.parent.rotation + radians;
|
||||||
|
} else {
|
||||||
|
this.localRotation = radians;
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,20 +331,8 @@ module es {
|
|||||||
* 设置变换在世界空间的旋转度
|
* 设置变换在世界空间的旋转度
|
||||||
* @param degrees
|
* @param degrees
|
||||||
*/
|
*/
|
||||||
public setRotation(degrees: number): Transform {
|
public setRotationDegrees(degrees: number): Transform {
|
||||||
this.rotation = degrees;
|
return this.setRotation(MathHelper.toRadians(degrees));
|
||||||
this.setDirty(DirtyType.rotationDirty);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置变换在世界空间中的缩放
|
|
||||||
* @param scale
|
|
||||||
*/
|
|
||||||
public setScale(scale: Vector2): Transform {
|
|
||||||
this.scale = scale;
|
|
||||||
this.setDirty(DirtyType.scaleDirty);
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -130,11 +345,105 @@ module es {
|
|||||||
this.rotation = sign * Math.acos(Vector2.dot(vectorToAlignTo, Vector2.unitY));
|
this.rotation = sign * Math.acos(Vector2.dot(vectorToAlignTo, Vector2.unitY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 相对于父变换的旋转设置变换的旋转。如果转换没有父元素,则与transform.rotation相同
|
||||||
|
* @param radians
|
||||||
|
*/
|
||||||
|
public setLocalRotation(radians: number){
|
||||||
|
this._localRotation = radians;
|
||||||
|
this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true;
|
||||||
|
this.setDirty(DirtyType.rotationDirty);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 相对于父变换的旋转设置变换的旋转。如果转换没有父元素,则与transform.rotation相同
|
||||||
|
* @param degrees
|
||||||
|
*/
|
||||||
|
public setLocalRotationDegrees(degrees: number): Transform {
|
||||||
|
return this.setLocalRotation(MathHelper.toRadians(degrees));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置变换在世界空间中的缩放
|
||||||
|
* @param scale
|
||||||
|
*/
|
||||||
|
public setScale(scale: Vector2): Transform {
|
||||||
|
this._scale = scale;
|
||||||
|
if (this.parent){
|
||||||
|
this.localScale = Vector2.divide(scale, this.parent._scale);
|
||||||
|
}else{
|
||||||
|
this.localScale = scale;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置转换相对于父对象的比例。如果转换没有父元素,则与transform.scale相同
|
||||||
|
* @param scale
|
||||||
|
*/
|
||||||
|
public setLocalScale(scale: Vector2): Transform {
|
||||||
|
this._localScale = scale;
|
||||||
|
this._localDirty = this._positionDirty = this._localScaleDirty = true;
|
||||||
|
this.setDirty(DirtyType.scaleDirty);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对精灵坐标进行四舍五入
|
* 对精灵坐标进行四舍五入
|
||||||
*/
|
*/
|
||||||
public roundPosition() {
|
public roundPosition() {
|
||||||
this.position = this.position.round();
|
this.position = this._position.round();
|
||||||
|
}
|
||||||
|
|
||||||
|
public updateTransform(){
|
||||||
|
if (this.hierarchyDirty != DirtyType.clean){
|
||||||
|
if (this.parent)
|
||||||
|
this.parent.updateTransform();
|
||||||
|
|
||||||
|
if (this._localDirty){
|
||||||
|
if (this._localPositionDirty){
|
||||||
|
this._translationMatrix = Matrix2D.create().translate(this._localPosition.x, this._localPosition.y);
|
||||||
|
this._localPositionDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._localRotationDirty){
|
||||||
|
this._rotationMatrix = Matrix2D.create().rotate(this._localRotation);
|
||||||
|
this._localRotationDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._localScaleDirty){
|
||||||
|
this._scaleMatrix = Matrix2D.create().scale(this._localScale.x, this._localScale.y);
|
||||||
|
this._localScaleDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._localTransform = this._scaleMatrix.multiply(this._rotationMatrix);
|
||||||
|
this._localTransform = this._localTransform.multiply(this._translationMatrix);
|
||||||
|
|
||||||
|
if (!this.parent){
|
||||||
|
this._worldTransform = this._localTransform;
|
||||||
|
this._rotation = this._localRotation;
|
||||||
|
this._scale = this._localScale;
|
||||||
|
this._worldInverseDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._localDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.parent){
|
||||||
|
this._worldTransform = this._localTransform.multiply(this.parent._worldTransform);
|
||||||
|
|
||||||
|
this._rotation = this._localRotation + this.parent._rotation;
|
||||||
|
this._scale = Vector2.multiply(this.parent._scale, this._localScale);
|
||||||
|
this._worldInverseDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._worldToLocalDirty = true;
|
||||||
|
this._positionDirty = true;
|
||||||
|
this.hierarchyDirty = DirtyType.clean;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public setDirty(dirtyFlagType: DirtyType){
|
public setDirty(dirtyFlagType: DirtyType){
|
||||||
@@ -167,13 +476,22 @@ module es {
|
|||||||
* @param transform
|
* @param transform
|
||||||
*/
|
*/
|
||||||
public copyFrom(transform: Transform) {
|
public copyFrom(transform: Transform) {
|
||||||
this.position = transform.position;
|
this._position = transform.position;
|
||||||
this.rotation = transform.rotation;
|
this._localPosition = transform._localPosition;
|
||||||
this.scale = transform.scale;
|
this._rotation = transform._rotation;
|
||||||
|
this._localRotation = transform._localRotation;
|
||||||
|
this._scale = transform._scale;
|
||||||
|
this._localScale = transform._localScale;
|
||||||
|
|
||||||
this.setDirty(DirtyType.positionDirty);
|
this.setDirty(DirtyType.positionDirty);
|
||||||
this.setDirty(DirtyType.rotationDirty);
|
this.setDirty(DirtyType.rotationDirty);
|
||||||
this.setDirty(DirtyType.scaleDirty);
|
this.setDirty(DirtyType.scaleDirty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public toString(): string{
|
||||||
|
return `[Transform: parent: ${this.parent}, position: ${this.position}, rotation: ${this.rotation},
|
||||||
|
scale: ${this.scale}, localPosition: ${this._localPosition}, localRotation: ${this._localRotation},
|
||||||
|
localScale: ${this._localScale}]`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,31 @@
|
|||||||
module es {
|
module es {
|
||||||
export class EntityList{
|
export class EntityList{
|
||||||
public scene: Scene;
|
public scene: Scene;
|
||||||
private _entitiesToRemove: Entity[] = [];
|
/**
|
||||||
private _entitiesToAdded: Entity[] = [];
|
* 添加到场景中的实体列表
|
||||||
private _tempEntityList: Entity[] = [];
|
*/
|
||||||
private _entities: Entity[] = [];
|
public _entities: Entity[] = [];
|
||||||
private _entityDict: Map<number, Entity[]> = new Map<number, Entity[]>();
|
/**
|
||||||
private _unsortedTags: number[] = [];
|
* 添加到此框架的实体列表。用于对实体进行分组,以便我们可以同时处理它们
|
||||||
|
*/
|
||||||
|
public _entitiesToAdded: Entity[] = [];
|
||||||
|
/**
|
||||||
|
* 标记要删除此框架的实体列表。用于对实体进行分组,以便我们可以同时处理它们
|
||||||
|
*/
|
||||||
|
public _entitiesToRemove: Entity[] = [];
|
||||||
|
/**
|
||||||
|
* 用于确定是否需要在此框架中对实体进行排序的标志
|
||||||
|
*/
|
||||||
|
public _isEntityListUnsorted: boolean;
|
||||||
|
/**
|
||||||
|
* 通过标签跟踪实体,便于检索
|
||||||
|
*/
|
||||||
|
public _entityDict: Map<number, Entity[]> = new Map<number, Entity[]>();
|
||||||
|
public _unsortedTags: number[] = [];
|
||||||
|
/**
|
||||||
|
* 在updateLists中用于双缓冲区,以便可以在其他地方修改原始列表
|
||||||
|
*/
|
||||||
|
public _tempEntityList: Entity[] = [];
|
||||||
|
|
||||||
constructor(scene: Scene){
|
constructor(scene: Scene){
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
@@ -20,12 +39,34 @@ module es {
|
|||||||
return this._entities;
|
return this._entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public markEntityListUnsorted(){
|
||||||
|
this._isEntityListUnsorted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public markTagUnsorted(tag: number){
|
||||||
|
this._unsortedTags.push(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将实体添加到列表中。所有生命周期方法将在下一帧中被调用。
|
||||||
|
* @param entity
|
||||||
|
*/
|
||||||
public add(entity: Entity){
|
public add(entity: Entity){
|
||||||
if (this._entitiesToAdded.indexOf(entity) == -1)
|
if (this._entitiesToAdded.indexOf(entity) == -1)
|
||||||
this._entitiesToAdded.push(entity);
|
this._entitiesToAdded.push(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从列表中删除一个实体。所有生命周期方法将在下一帧中被调用。
|
||||||
|
* @param entity
|
||||||
|
*/
|
||||||
public remove(entity: Entity){
|
public remove(entity: Entity){
|
||||||
|
if (!this._entitiesToRemove.contains(entity)){
|
||||||
|
console.warn(`You are trying to remove an entity (${entity.name}) that you already removed`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 防止在同一帧中添加或删除实体
|
||||||
if (this._entitiesToAdded.contains(entity)){
|
if (this._entitiesToAdded.contains(entity)){
|
||||||
this._entitiesToAdded.remove(entity);
|
this._entitiesToAdded.remove(entity);
|
||||||
return;
|
return;
|
||||||
@@ -35,6 +76,126 @@ module es {
|
|||||||
this._entitiesToRemove.push(entity);
|
this._entitiesToRemove.push(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从实体列表中删除所有实体
|
||||||
|
*/
|
||||||
|
public removeAllEntities(){
|
||||||
|
this._unsortedTags.length = 0;
|
||||||
|
this._entitiesToAdded.length = 0;
|
||||||
|
this._isEntityListUnsorted = false;
|
||||||
|
|
||||||
|
// 为什么我们要在这里更新列表?主要用于处理场景切换前分离的实体。
|
||||||
|
// 它们仍然在_entitiesToRemove列表中,该列表将由更新列表处理。
|
||||||
|
this.updateLists();
|
||||||
|
|
||||||
|
for (let i = 0; i < this._entities.length; i ++){
|
||||||
|
this._entities[i]._isDestroyed = true;
|
||||||
|
this._entities[i].onRemovedFromScene();
|
||||||
|
this._entities[i].scene = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._entities.length = 0;
|
||||||
|
this._entityDict.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查该实体当前是否由此EntityList管理
|
||||||
|
* @param entity
|
||||||
|
*/
|
||||||
|
public contains(entity: Entity): boolean {
|
||||||
|
return this._entities.contains(entity) || this._entitiesToAdded.contains(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getTagList(tag: number){
|
||||||
|
let list = this._entityDict.get(tag);
|
||||||
|
if (!list){
|
||||||
|
list = [];
|
||||||
|
this._entityDict.set(tag, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._entityDict.get(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public addToTagList(entity: Entity){
|
||||||
|
let list = this.getTagList(entity.tag);
|
||||||
|
if (!list.contains(entity)){
|
||||||
|
list.push(entity);
|
||||||
|
this._unsortedTags.push(entity.tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public removeFromTagList(entity: Entity){
|
||||||
|
let list = this._entityDict.get(entity.tag);
|
||||||
|
if (list){
|
||||||
|
list.remove(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public update(){
|
||||||
|
for (let i = 0; i < this._entities.length; i++){
|
||||||
|
let entity = this._entities[i];
|
||||||
|
if (entity.enabled && (entity.updateInterval == 1 || Time.frameCount % entity.updateInterval == 0))
|
||||||
|
entity.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public updateLists(){
|
||||||
|
if (this._entitiesToRemove.length > 0){
|
||||||
|
let temp = this._entitiesToRemove;
|
||||||
|
this._entitiesToRemove = this._tempEntityList;
|
||||||
|
this._tempEntityList = temp;
|
||||||
|
this._tempEntityList.forEach(entity => {
|
||||||
|
this.removeFromTagList(entity);
|
||||||
|
|
||||||
|
this._entities.remove(entity);
|
||||||
|
entity.onRemovedFromScene();
|
||||||
|
entity.scene = null;
|
||||||
|
|
||||||
|
this.scene.entityProcessors.onEntityRemoved(entity);
|
||||||
|
});
|
||||||
|
|
||||||
|
this._tempEntityList.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._entitiesToAdded.length > 0){
|
||||||
|
let temp = this._entitiesToAdded;
|
||||||
|
this._entitiesToAdded = this._tempEntityList;
|
||||||
|
this._tempEntityList = temp;
|
||||||
|
this._tempEntityList.forEach(entity => {
|
||||||
|
if (!this._entities.contains(entity)){
|
||||||
|
this._entities.push(entity);
|
||||||
|
entity.scene = this.scene;
|
||||||
|
|
||||||
|
this.addToTagList(entity);
|
||||||
|
|
||||||
|
this.scene.entityProcessors.onEntityAdded(entity)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 现在所有实体都被添加到场景中,我们再次循环并调用onAddedToScene
|
||||||
|
this._tempEntityList.forEach(entity => entity.onAddedToScene());
|
||||||
|
this._tempEntityList.length = 0;
|
||||||
|
this._isEntityListUnsorted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._isEntityListUnsorted){
|
||||||
|
this._entities.sort();
|
||||||
|
this._isEntityListUnsorted = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._unsortedTags.length > 0){
|
||||||
|
this._unsortedTags.forEach(tag => {
|
||||||
|
this._entityDict.get(tag).sort();
|
||||||
|
});
|
||||||
|
|
||||||
|
this._unsortedTags.length = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回找到的第一个实体的名称。如果没有找到,则返回null。
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
public findEntity(name: string){
|
public findEntity(name: string){
|
||||||
for (let i = 0; i < this._entities.length; i ++){
|
for (let i = 0; i < this._entities.length; i ++){
|
||||||
if (this._entities[i].name == name)
|
if (this._entities[i].name == name)
|
||||||
@@ -120,94 +281,5 @@ module es {
|
|||||||
|
|
||||||
return comps;
|
return comps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTagList(tag: number){
|
|
||||||
let list = this._entityDict.get(tag);
|
|
||||||
if (!list){
|
|
||||||
list = [];
|
|
||||||
this._entityDict.set(tag, list);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this._entityDict.get(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
public addToTagList(entity: Entity){
|
|
||||||
let list = this.getTagList(entity.tag);
|
|
||||||
if (!list.contains(entity)){
|
|
||||||
list.push(entity);
|
|
||||||
this._unsortedTags.push(entity.tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public removeFromTagList(entity: Entity){
|
|
||||||
let list = this._entityDict.get(entity.tag);
|
|
||||||
if (list){
|
|
||||||
list.remove(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public update(){
|
|
||||||
for (let i = 0; i < this._entities.length; i++){
|
|
||||||
let entity = this._entities[i];
|
|
||||||
if (entity.enabled)
|
|
||||||
entity.update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public removeAllEntities(){
|
|
||||||
this._entitiesToAdded.length = 0;
|
|
||||||
|
|
||||||
this.updateLists();
|
|
||||||
|
|
||||||
for (let i = 0; i < this._entities.length; i ++){
|
|
||||||
this._entities[i]._isDestroyed = true;
|
|
||||||
this._entities[i].onRemovedFromScene();
|
|
||||||
this._entities[i].scene = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._entities.length = 0;
|
|
||||||
this._entityDict.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public updateLists(){
|
|
||||||
if (this._entitiesToRemove.length > 0){
|
|
||||||
let temp = this._entitiesToRemove;
|
|
||||||
this._entitiesToRemove = this._tempEntityList;
|
|
||||||
this._tempEntityList = temp;
|
|
||||||
this._tempEntityList.forEach(entity => {
|
|
||||||
this._entities.remove(entity);
|
|
||||||
entity.scene = null;
|
|
||||||
|
|
||||||
this.scene.entityProcessors.onEntityRemoved(entity);
|
|
||||||
});
|
|
||||||
|
|
||||||
this._tempEntityList.length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._entitiesToAdded.length > 0){
|
|
||||||
let temp = this._entitiesToAdded;
|
|
||||||
this._entitiesToAdded = this._tempEntityList;
|
|
||||||
this._tempEntityList = temp;
|
|
||||||
this._tempEntityList.forEach(entity => {
|
|
||||||
if (!this._entities.contains(entity)){
|
|
||||||
this._entities.push(entity);
|
|
||||||
entity.scene = this.scene;
|
|
||||||
|
|
||||||
this.scene.entityProcessors.onEntityAdded(entity)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this._tempEntityList.forEach(entity => entity.onAddedToScene());
|
|
||||||
this._tempEntityList.length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._unsortedTags.length > 0){
|
|
||||||
this._unsortedTags.forEach(tag => {
|
|
||||||
this._entityDict.get(tag).sort();
|
|
||||||
});
|
|
||||||
|
|
||||||
this._unsortedTags.length = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,8 +162,7 @@ module es {
|
|||||||
|
|
||||||
// 求直线的法线
|
// 求直线的法线
|
||||||
let line = Vector2.subtract(points[j], points[i]);
|
let line = Vector2.subtract(points[j], points[i]);
|
||||||
edgeNormal.x = -line.y;
|
edgeNormal = new Vector2(-line.y, line.x);
|
||||||
edgeNormal.y = line.x;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +195,7 @@ module es {
|
|||||||
|
|
||||||
// 为了处理偏移原点的旋转我们只需要将圆心在(0,0)附近移动
|
// 为了处理偏移原点的旋转我们只需要将圆心在(0,0)附近移动
|
||||||
// 我们的偏移使角度为0我们还需要处理这里的比例所以我们先对偏移进行缩放以得到合适的长度。
|
// 我们的偏移使角度为0我们还需要处理这里的比例所以我们先对偏移进行缩放以得到合适的长度。
|
||||||
let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x);
|
let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg;
|
||||||
let offsetLength = hasUnitScale ? collider._localOffsetLength :
|
let offsetLength = hasUnitScale ? collider._localOffsetLength :
|
||||||
Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length();
|
Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length();
|
||||||
this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength,
|
this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength,
|
||||||
|
|||||||
Reference in New Issue
Block a user