感谢NEZ库提供的思路
This commit is contained in:
@@ -9,6 +9,9 @@ ecs-framework 的目标是成为功能强大的框架。它为您构建游戏提
|
||||
- 针对核心事件的优化的事件发射器(发射器类),您也可以将其添加到自己的任何类中
|
||||
- 延迟和重复任务的调度程序(核心调度方法)
|
||||
|
||||
## 关于ECS-FRAMEWORK
|
||||
该项目由Nez项目由C#转为Typescript。感谢该项目提供的思路:https://github.com/prime31/Nez
|
||||
|
||||
## 交流群
|
||||
点击链接加入群聊【ecs游戏框架交流】:https://jq.qq.com/?_wv=1027&k=29w1Nud6
|
||||
|
||||
|
||||
19
source/bin/framework.d.ts
vendored
19
source/bin/framework.d.ts
vendored
@@ -227,7 +227,11 @@ declare module es {
|
||||
/**
|
||||
* 每帧更新事件
|
||||
*/
|
||||
frameUpdated = 1
|
||||
frameUpdated = 1,
|
||||
/**
|
||||
* 当渲染发生时触发
|
||||
*/
|
||||
renderChanged = 2
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
@@ -2194,11 +2198,13 @@ declare module es {
|
||||
camera: ICamera;
|
||||
readonly renderOrder: number;
|
||||
shouldDebugRender: boolean;
|
||||
protected renderDirty: boolean;
|
||||
constructor(renderOrder: number, camera: ICamera);
|
||||
onAddedToScene(scene: es.Scene): void;
|
||||
unload(): void;
|
||||
protected beginRender(cam: ICamera): void;
|
||||
protected endRender(): void;
|
||||
protected onRenderChanged(): void;
|
||||
abstract render(scene: Scene): void;
|
||||
protected renderAfterStateCheck(renderable: IRenderable, cam: ICamera): void;
|
||||
protected debugRender(scene: Scene): void;
|
||||
@@ -2571,6 +2577,11 @@ declare module es {
|
||||
* @returns
|
||||
*/
|
||||
static approachAngle(start: number, end: number, shift: number): number;
|
||||
/**
|
||||
* 将此 Vector 投影到另一个 Vector 上
|
||||
* @param other
|
||||
*/
|
||||
static project(self: Vector2, other: Vector2): Vector2;
|
||||
/**
|
||||
* 通过将偏移量(全部以弧度为单位)夹住结果并选择最短路径,起始角度朝向终止角度。
|
||||
* 起始值可以小于或大于终止值。
|
||||
@@ -2694,6 +2705,8 @@ declare module es {
|
||||
* 代表右手4x4浮点矩阵,可以存储平移、比例和旋转信息
|
||||
*/
|
||||
class Matrix {
|
||||
private static identity;
|
||||
static readonly Identity: Matrix;
|
||||
m11: number;
|
||||
m12: number;
|
||||
m13: number;
|
||||
@@ -2710,6 +2723,7 @@ declare module es {
|
||||
m42: number;
|
||||
m43: number;
|
||||
m44: number;
|
||||
constructor(m11?: any, m12?: any, m13?: any, m14?: any, m21?: any, m22?: any, m23?: any, m24?: any, m31?: any, m32?: any, m33?: any, m34?: any, m41?: any, m42?: any, m43?: any, m44?: any);
|
||||
/**
|
||||
* 为自定义的正交视图创建一个新的投影矩阵
|
||||
* @param left
|
||||
@@ -2719,6 +2733,8 @@ declare module es {
|
||||
* @param result
|
||||
*/
|
||||
static createOrthographicOffCenter(left: number, right: number, bottom: number, top: number, zNearPlane: number, zFarPlane: number, result?: Matrix): void;
|
||||
static createTranslation(position: Vector2, result: Matrix): void;
|
||||
static createRotationZ(radians: number, result: Matrix): void;
|
||||
/**
|
||||
* 创建一个新的矩阵,其中包含两个矩阵的乘法。
|
||||
* @param matrix1
|
||||
@@ -3185,6 +3201,7 @@ declare module es {
|
||||
* 在碰撞器中开始的射线/直线是否强制转换检测到那些碰撞器
|
||||
*/
|
||||
static raycastsStartInColliders: boolean;
|
||||
static debugRender: boolean;
|
||||
/**
|
||||
* 我们保留它以避免在每次raycast发生时分配它
|
||||
*/
|
||||
|
||||
@@ -585,6 +585,10 @@ var es;
|
||||
* 每帧更新事件
|
||||
*/
|
||||
CoreEvents[CoreEvents["frameUpdated"] = 1] = "frameUpdated";
|
||||
/**
|
||||
* 当渲染发生时触发
|
||||
*/
|
||||
CoreEvents[CoreEvents["renderChanged"] = 2] = "renderChanged";
|
||||
})(CoreEvents = es.CoreEvents || (es.CoreEvents = {}));
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
@@ -5525,8 +5529,10 @@ var es;
|
||||
function Renderer(renderOrder, camera) {
|
||||
this.renderOrder = 0;
|
||||
this.shouldDebugRender = true;
|
||||
this.renderDirty = true;
|
||||
this.renderOrder = renderOrder;
|
||||
this.camera = camera;
|
||||
es.Core.emitter.addObserver(es.CoreEvents.renderChanged, this.onRenderChanged, this);
|
||||
}
|
||||
Renderer.prototype.onAddedToScene = function (scene) { };
|
||||
Renderer.prototype.unload = function () { };
|
||||
@@ -5540,6 +5546,9 @@ var es;
|
||||
return;
|
||||
es.Graphics.instance.batcher.end();
|
||||
};
|
||||
Renderer.prototype.onRenderChanged = function () {
|
||||
this.renderDirty = true;
|
||||
};
|
||||
Renderer.prototype.renderAfterStateCheck = function (renderable, cam) {
|
||||
if (!es.Graphics.instance)
|
||||
return;
|
||||
@@ -5572,6 +5581,9 @@ var es;
|
||||
return _super.call(this, renderOrder, camera) || this;
|
||||
}
|
||||
DefaultRenderer.prototype.render = function (scene) {
|
||||
if (!this.renderDirty)
|
||||
return;
|
||||
this.renderDirty = false;
|
||||
var cam = this.camera ? this.camera : scene.camera;
|
||||
this.beginRender(cam);
|
||||
for (var i = 0; i < scene.renderableComponents.count; i++) {
|
||||
@@ -6204,6 +6216,15 @@ var es;
|
||||
return end;
|
||||
return this.repeat(this.approach(start, start + deltaAngle, shift), 360);
|
||||
};
|
||||
/**
|
||||
* 将此 Vector 投影到另一个 Vector 上
|
||||
* @param other
|
||||
*/
|
||||
MathHelper.project = function (self, other) {
|
||||
var amt = es.Vector2.dot(self, other) / other.lengthSquared();
|
||||
var vec = new es.Vector2(amt * other.x, amt * other.y);
|
||||
return vec;
|
||||
};
|
||||
/**
|
||||
* 通过将偏移量(全部以弧度为单位)夹住结果并选择最短路径,起始角度朝向终止角度。
|
||||
* 起始值可以小于或大于终止值。
|
||||
@@ -6419,8 +6440,31 @@ var es;
|
||||
* 代表右手4x4浮点矩阵,可以存储平移、比例和旋转信息
|
||||
*/
|
||||
var Matrix = /** @class */ (function () {
|
||||
function Matrix() {
|
||||
function Matrix(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
|
||||
this.m11 = m11;
|
||||
this.m12 = m12;
|
||||
this.m13 = m13;
|
||||
this.m14 = m14;
|
||||
this.m21 = m21;
|
||||
this.m22 = m22;
|
||||
this.m23 = m23;
|
||||
this.m24 = m24;
|
||||
this.m31 = m31;
|
||||
this.m32 = m32;
|
||||
this.m33 = m33;
|
||||
this.m34 = m34;
|
||||
this.m41 = m41;
|
||||
this.m42 = m42;
|
||||
this.m43 = m43;
|
||||
this.m44 = m44;
|
||||
}
|
||||
Object.defineProperty(Matrix, "Identity", {
|
||||
get: function () {
|
||||
return this.identity;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* 为自定义的正交视图创建一个新的投影矩阵
|
||||
* @param left
|
||||
@@ -6448,6 +6492,33 @@ var es;
|
||||
result.m43 = zNearPlane / (zNearPlane - zFarPlane);
|
||||
result.m44 = 1;
|
||||
};
|
||||
Matrix.createTranslation = function (position, result) {
|
||||
result.m11 = 1;
|
||||
result.m12 = 0;
|
||||
result.m13 = 0;
|
||||
result.m14 = 0;
|
||||
result.m21 = 0;
|
||||
result.m22 = 1;
|
||||
result.m23 = 0;
|
||||
result.m24 = 0;
|
||||
result.m31 = 0;
|
||||
result.m32 = 0;
|
||||
result.m33 = 1;
|
||||
result.m34 = 0;
|
||||
result.m41 = position.x;
|
||||
result.m42 = position.y;
|
||||
result.m43 = 0;
|
||||
result.m44 = 1;
|
||||
};
|
||||
Matrix.createRotationZ = function (radians, result) {
|
||||
result = Matrix.Identity;
|
||||
var val1 = Math.cos(radians);
|
||||
var val2 = Math.sin(radians);
|
||||
result.m11 = val1;
|
||||
result.m12 = val2;
|
||||
result.m21 = -val2;
|
||||
result.m22 = val1;
|
||||
};
|
||||
/**
|
||||
* 创建一个新的矩阵,其中包含两个矩阵的乘法。
|
||||
* @param matrix1
|
||||
@@ -6489,6 +6560,7 @@ var es;
|
||||
result.m43 = m43;
|
||||
result.m44 = m44;
|
||||
};
|
||||
Matrix.identity = new Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
return Matrix;
|
||||
}());
|
||||
es.Matrix = Matrix;
|
||||
@@ -7815,6 +7887,7 @@ var es;
|
||||
this._spatialHash.clear();
|
||||
};
|
||||
Physics.debugDraw = function (secondsToDisplay) {
|
||||
if (this.debugRender)
|
||||
this._spatialHash.debugDraw(secondsToDisplay);
|
||||
};
|
||||
/**
|
||||
@@ -7975,6 +8048,7 @@ var es;
|
||||
* 在碰撞器中开始的射线/直线是否强制转换检测到那些碰撞器
|
||||
*/
|
||||
Physics.raycastsStartInColliders = false;
|
||||
Physics.debugRender = false;
|
||||
/**
|
||||
* 我们保留它以避免在每次raycast发生时分配它
|
||||
*/
|
||||
|
||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -8,5 +8,9 @@ module es {
|
||||
* 每帧更新事件
|
||||
*/
|
||||
frameUpdated,
|
||||
/**
|
||||
* 当渲染发生时触发
|
||||
*/
|
||||
renderChanged,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ module es {
|
||||
}
|
||||
|
||||
public render(scene: Scene): void {
|
||||
if (!this.renderDirty)
|
||||
return;
|
||||
|
||||
this.renderDirty = false;
|
||||
let cam = this.camera ? this.camera : scene.camera;
|
||||
this.beginRender(cam);
|
||||
|
||||
|
||||
@@ -3,10 +3,13 @@ module es {
|
||||
public camera: ICamera;
|
||||
public readonly renderOrder: number = 0;
|
||||
public shouldDebugRender: boolean = true;
|
||||
protected renderDirty: boolean = true;
|
||||
|
||||
constructor(renderOrder: number, camera: ICamera) {
|
||||
this.renderOrder = renderOrder;
|
||||
this.camera = camera;
|
||||
|
||||
Core.emitter.addObserver(CoreEvents.renderChanged, this.onRenderChanged, this);
|
||||
}
|
||||
|
||||
public onAddedToScene(scene: es.Scene) { }
|
||||
@@ -27,6 +30,10 @@ module es {
|
||||
Graphics.instance.batcher.end();
|
||||
}
|
||||
|
||||
protected onRenderChanged() {
|
||||
this.renderDirty = true;
|
||||
}
|
||||
|
||||
public abstract render(scene: Scene): void;
|
||||
|
||||
protected renderAfterStateCheck(renderable: IRenderable, cam: ICamera) {
|
||||
|
||||
@@ -381,6 +381,16 @@ module es {
|
||||
return this.repeat(this.approach(start, start + deltaAngle, shift), 360);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Vector 投影到另一个 Vector 上
|
||||
* @param other
|
||||
*/
|
||||
public static project(self: Vector2, other: Vector2) {
|
||||
let amt = Vector2.dot(self, other) / other.lengthSquared();
|
||||
let vec = new Vector2(amt * other.x, amt * other.y);
|
||||
return vec;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过将偏移量(全部以弧度为单位)夹住结果并选择最短路径,起始角度朝向终止角度。
|
||||
* 起始值可以小于或大于终止值。
|
||||
|
||||
@@ -3,6 +3,15 @@ module es {
|
||||
* 代表右手4x4浮点矩阵,可以存储平移、比例和旋转信息
|
||||
*/
|
||||
export class Matrix {
|
||||
private static identity = new Matrix(1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
|
||||
public static get Identity() {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
public m11: number;
|
||||
public m12: number;
|
||||
public m13: number;
|
||||
@@ -20,6 +29,26 @@ module es {
|
||||
public m43: number;
|
||||
public m44: number;
|
||||
|
||||
constructor(m11?, m12?, m13?, m14?, m21?, m22?, m23?, m24?, m31?,
|
||||
m32?, m33?, m34?, m41?, m42?, m43?, m44?) {
|
||||
this.m11 = m11;
|
||||
this.m12 = m12;
|
||||
this.m13 = m13;
|
||||
this.m14 = m14;
|
||||
this.m21 = m21;
|
||||
this.m22 = m22;
|
||||
this.m23 = m23;
|
||||
this.m24 = m24;
|
||||
this.m31 = m31;
|
||||
this.m32 = m32;
|
||||
this.m33 = m33;
|
||||
this.m34 = m34;
|
||||
this.m41 = m41;
|
||||
this.m42 = m42;
|
||||
this.m43 = m43;
|
||||
this.m44 = m44;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为自定义的正交视图创建一个新的投影矩阵
|
||||
* @param left
|
||||
@@ -47,6 +76,39 @@ module es {
|
||||
result.m44 = 1;
|
||||
}
|
||||
|
||||
public static createTranslation(position: Vector2, result: Matrix)
|
||||
{
|
||||
result.m11 = 1;
|
||||
result.m12 = 0;
|
||||
result.m13 = 0;
|
||||
result.m14 = 0;
|
||||
result.m21 = 0;
|
||||
result.m22 = 1;
|
||||
result.m23 = 0;
|
||||
result.m24 = 0;
|
||||
result.m31 = 0;
|
||||
result.m32 = 0;
|
||||
result.m33 = 1;
|
||||
result.m34 = 0;
|
||||
result.m41 = position.x;
|
||||
result.m42 = position.y;
|
||||
result.m43 = 0;
|
||||
result.m44 = 1;
|
||||
}
|
||||
|
||||
public static createRotationZ(radians: number, result: Matrix)
|
||||
{
|
||||
result = Matrix.Identity;
|
||||
|
||||
var val1 = Math.cos(radians);
|
||||
var val2 = Math.sin(radians);
|
||||
|
||||
result.m11 = val1;
|
||||
result.m12 = val2;
|
||||
result.m21 = -val2;
|
||||
result.m22 = val1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个新的矩阵,其中包含两个矩阵的乘法。
|
||||
* @param matrix1
|
||||
|
||||
@@ -16,6 +16,7 @@ module es {
|
||||
* 在碰撞器中开始的射线/直线是否强制转换检测到那些碰撞器
|
||||
*/
|
||||
public static raycastsStartInColliders = false;
|
||||
public static debugRender: boolean = false;
|
||||
/**
|
||||
* 我们保留它以避免在每次raycast发生时分配它
|
||||
*/
|
||||
@@ -43,6 +44,7 @@ module es {
|
||||
}
|
||||
|
||||
public static debugDraw(secondsToDisplay) {
|
||||
if (this.debugRender)
|
||||
this._spatialHash.debugDraw(secondsToDisplay);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user