新增子模块与文件迁移

This commit is contained in:
yhh
2020-12-10 16:15:19 +08:00
parent c0450f21b6
commit 59c8d456cb
30 changed files with 3028 additions and 2726 deletions

6
.gitmodules vendored Normal file
View File

@@ -0,0 +1,6 @@
[submodule "demo/egret_demo"]
path = demo/egret_demo
url = https://github.com/esengine/ecs-egret-demo
[submodule "demo/laya_demo"]
path = demo/laya_demo
url = https://github.com/esengine/ecs-laya-demo.git

1
demo/egret_demo Submodule

Submodule demo/egret_demo added at b478905960

1
demo/laya_demo Submodule

Submodule demo/laya_demo added at ef025467dc

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -3,7 +3,7 @@ const gulp = require("gulp");
const minify = require('gulp-minify');
const inject = require("gulp-inject-string");
const ts = require('gulp-typescript');
const compile = require("gulp-typescript");
const merge = require('merge2');
const tsProject = ts.createProject('tsconfig.json');
gulp.task('buildJs', () => {
@@ -23,7 +23,16 @@ gulp.task("buildDts", ["buildJs"], () => {
.pipe(gulp.dest('./bin'));
});
gulp.task("build", ["buildDts"], () => {
gulp.task("copy", ["buildDts"], () => {
return gulp.src('bin/**/*')
// .pipe(gulp.dest('../demo_egret/libs/framework/'))
.pipe(gulp.dest('../demo/egret_demo/libs/framework/'))
});
gulp.task('build', ['copy'], ()=>{
return merge([
gulp.src('bin/*.js')
.pipe(gulp.dest('../demo/laya_demo/bin/libs/')),
gulp.src('bin/*.ts')
.pipe(gulp.dest('../demo/laya_demo/libs/'))
])
});

View File

@@ -4096,6 +4096,12 @@
"readable-stream": "^2.0.1"
}
},
"merge2": {
"version": "1.4.1",
"resolved": "https://registry.npm.taobao.org/merge2/download/merge2-1.4.1.tgz",
"integrity": "sha1-Q2iJL4hekHRVpv19xVwMnUBJkK4=",
"dev": true
},
"micromatch": {
"version": "3.1.10",
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.10.tgz",

View File

@@ -28,7 +28,8 @@
"typedoc": "^0.19.2",
"typescript": "^2.2.2",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.9.0"
"watchify": "^3.9.0",
"merge2": "^1.4.1"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com/359807859@qq.com"

View File

@@ -86,8 +86,8 @@ module es {
if (this._instance._scene == null) {
this._instance._scene = value;
this._instance.onSceneChanged();
this._instance._scene.begin();
Core.Instance.onSceneChanged();
} else {
this._instance._nextScene = value;
}

View File

@@ -398,7 +398,7 @@ module es {
* 对精灵坐标进行四舍五入
*/
public roundPosition() {
this.position = this._position.round();
this.position = Vector2Ext.round(this._position);
}
public updateTransform() {

View File

@@ -116,7 +116,7 @@ module es {
* @param polygon
* @param result
*/
public static circleToPolygon(circle: Circle, polygon: Polygon, result: CollisionResult): boolean {
public static circleToPolygon(circle: Circle, polygon: Polygon, result: CollisionResult = new CollisionResult()): boolean {
// 圆圈在多边形中的位置坐标
let poly2Circle = Vector2.subtract(circle.position, polygon.position);
@@ -141,7 +141,7 @@ module es {
mtv = new Vector2(result.normal.x * circle.radius, result.normal.y * circle.radius);
} else {
let distance = Math.sqrt(distanceSquared.value);
mtv = new Vector2(-poly2Circle.x + closestPoint.x, -poly2Circle.y + closestPoint.y)
mtv = Vector2.subtract(new Vector2(-1), Vector2.subtract(poly2Circle, closestPoint))
.multiply(new Vector2((circle.radius - distance) / distance));
}
}
@@ -153,19 +153,19 @@ module es {
}
/**
* 适用于心在框内以及只与方框外心重的圆。
* 适用于心在框内的圆,也适用于与框外心重的圆。
* @param circle
* @param box
* @param result
*/
public static circleToBox(circle: Circle, box: Box, result: CollisionResult): boolean {
public static circleToBox(circle: Circle, box: Box, result: CollisionResult = new CollisionResult()): boolean {
let closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position, result.normal);
// 处理那些中心在盒子里的圆,因为比较好操作
// 处理中心在盒子里的圆,如果我们是包含的, 它的成本更低
if (box.containsPoint(circle.position)) {
result.point = closestPointOnBounds;
result.point = closestPointOnBounds.clone();
// 计算mtv。找安全的,没有碰撞的位置,然后从那里得到mtv
// 计算MTV。找安全的、非碰撞的位置,并从中得到MTV
let safePlace = Vector2.add(closestPointOnBounds, Vector2.multiply(result.normal, new Vector2(circle.radius)));
result.minimumTranslationVector = Vector2.subtract(circle.position, safePlace);
@@ -173,7 +173,8 @@ module es {
}
let sqrDistance = Vector2.distanceSquared(closestPointOnBounds, circle.position);
// 看盒子上的点与圆的距离是否小于半径
// 看框上的点距圆的半径是否小于圆的半径
if (sqrDistance == 0) {
result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(circle.radius));
} else if (sqrDistance <= circle.radius * circle.radius) {
@@ -236,7 +237,7 @@ module es {
let t = Vector2.dot(w, v) / Vector2.dot(v, v);
t = MathHelper.clamp(t, 0, 1);
return Vector2.add(lineA, Vector2.multiply(v, new Vector2(t, t)));
return Vector2.add(lineA, Vector2.multiply(v, new Vector2(t)));
}
/**
@@ -265,7 +266,7 @@ module es {
* @param second
* @param result
*/
public static circleToCircle(first: Circle, second: Circle, result: CollisionResult): boolean {
public static circleToCircle(first: Circle, second: Circle, result: CollisionResult = new CollisionResult()): boolean {
let distanceSquared = Vector2.distanceSquared(first.position, second.position);
let sumOfRadii = first.radius + second.radius;
let collided = distanceSquared < sumOfRadii * sumOfRadii;
@@ -275,6 +276,11 @@ module es {
result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth), result.normal);
result.point = Vector2.add(second.position, Vector2.multiply(result.normal, new Vector2(second.radius)));
// 这可以得到实际的碰撞点,可能有用也可能没用,所以我们暂时把它留在这里
// let collisionPointX = ((first.position.x * second.radius) + (second.position.x * first.radius)) / sumOfRadii;
// let collisionPointY = ((first.position.y * second.radius) + (second.position.y * first.radius)) / sumOfRadii;
// result.point = new Vector2(collisionPointX, collisionPointY);
return true;
}
@@ -315,7 +321,7 @@ module es {
return new Rectangle(topLeft.x, topLeft.y, fullSize.x, fullSize.y)
}
public static lineToPoly(start: Vector2, end: Vector2, polygon: Polygon, hit: RaycastHit): boolean {
public static lineToPoly(start: Vector2, end: Vector2, polygon: Polygon, hit: RaycastHit = new RaycastHit()): boolean {
let normal = Vector2.zero;
let intersectionPoint = Vector2.zero;
let fraction = Number.MAX_VALUE;

View File

@@ -0,0 +1,220 @@
module es {
export class RectangleExt {
/**
* 获取指定边的位置
* @param rect
* @param edge
*/
public static getSide(rect: Rectangle, edge: Edge) {
switch (edge) {
case Edge.top:
return rect.top;
case Edge.bottom:
return rect.bottom;
case es.Edge.left:
return rect.left;
case Edge.right:
return rect.right;
}
}
/**
* 计算两个矩形的并集。结果将是一个包含其他两个的矩形。
* @param first
* @param point
*/
public static union(first: Rectangle, point: Vector2) {
let rect = new Rectangle(point.x, point.y, 0, 0);
let result = new Rectangle();
result.x = Math.min(first.x, rect.x);
result.y = Math.min(first.y, rect.y);
result.width = Math.max(first.right, rect.right) - result.x;
result.height = Math.max(first.bottom, rect.bottom) - result.y;
return result;
}
public static getHalfRect(rect: Rectangle, edge: Edge) {
switch (edge) {
case Edge.top:
return new Rectangle(rect.x, rect.y, rect.width, rect.height / 2);
case Edge.bottom:
return new Rectangle(rect.x, rect.y + rect.height / 2, rect.width, rect.height / 2);
case Edge.left:
return new Rectangle(rect.x, rect.y, rect.width / 2, rect.height);
case Edge.right:
return new Rectangle(rect.x + rect.width / 2, rect.y, rect.width / 2, rect.height);
}
}
/**
* 获取矩形的一部分,其宽度/高度的大小位于矩形的边缘,但仍然包含在其中。
* @param rect
* @param edge
* @param size
*/
public static getRectEdgePortion(rect: Rectangle, edge: Edge, size: number = 1) {
switch (edge) {
case es.Edge.top:
return new Rectangle(rect.x, rect.y, rect.width, size);
case Edge.bottom:
return new Rectangle(rect.x, rect.y + rect.height - size, rect.width, size);
case Edge.left:
return new Rectangle(rect.x, rect.y, size, rect.height);
case Edge.right:
return new Rectangle(rect.x + rect.width - size, rect.y, size, rect.height);
}
}
public static expandSide(rect: Rectangle, edge: Edge, amount: number) {
amount = Math.abs(amount);
switch (edge) {
case Edge.top:
rect.y -= amount;
rect.height += amount;
break;
case es.Edge.bottom:
rect.height += amount;
break;
case Edge.left:
rect.x -= amount;
rect.width += amount;
break;
case Edge.right:
rect.width += amount;
break;
}
}
public static contract(rect: Rectangle, horizontalAmount, verticalAmount) {
rect.x += horizontalAmount;
rect.y += verticalAmount;
rect.width -= horizontalAmount * 2;
rect.height -= verticalAmount * 2;
}
/**
* 给定多边形的点,计算其边界
* @param points
*/
public static boundsFromPolygonVector(points: Vector2[]) {
// 我们需要找到最小/最大的x/y值。
let minX = Number.POSITIVE_INFINITY;
let minY = Number.POSITIVE_INFINITY;
let maxX = Number.NEGATIVE_INFINITY;
let maxY = Number.NEGATIVE_INFINITY;
for (let i = 0; i < points.length; i ++) {
let pt = points[i];
if (pt.x < minX)
minX = pt.x;
if (pt.x > maxX)
maxX = pt.x;
if (pt.y < minY)
minY = pt.y;
if (pt.y > maxY)
maxY = pt.y;
}
return this.fromMinMaxVector(new Vector2(minX, minY), new Vector2(maxX, maxY));
}
/**
* 创建一个给定最小/最大点(左上角,右下角)的矩形
* @param min
* @param max
*/
public static fromMinMaxVector(min: Vector2, max: Vector2) {
return new Rectangle(min.x, min.y, max.x - min.x, max.y - min.y);
}
/**
* 返回一个跨越当前边界和提供的delta位置的Bounds
* @param rect
* @param deltaX
* @param deltaY
*/
public static getSweptBroadphaseBounds(rect: Rectangle, deltaX: number, deltaY: number){
let broadphasebox = Rectangle.empty;
broadphasebox.x = deltaX > 0 ? rect.x : rect.x + deltaX;
broadphasebox.y = deltaY > 0 ? rect.y : rect.y + deltaY;
broadphasebox.width = deltaX > 0 ? deltaX + rect.width : rect.width - deltaX;
broadphasebox.height = deltaY > 0 ? deltaY + rect.height : rect.height - deltaY;
return broadphasebox;
}
/**
* 如果矩形发生碰撞返回true
* moveX和moveY将返回b1为避免碰撞而必须移动的移动量
* @param rect
* @param other
* @param moveX
* @param moveY
*/
public collisionCheck(rect: Rectangle, other: Rectangle, moveX: Ref<number>, moveY: Ref<number>) {
moveX.value = moveY.value = 0;
let l = other.x - (rect.x + rect.width);
let r = (other.x + other.width) - rect.x;
let t = other.y - (rect.y + rect.height);
let b = (other.y + other.height) - rect.y;
// 检验是否有碰撞
if (l > 0 || r < 0 || t > 0 || b < 0)
return false;
// 求两边的偏移量
moveX.value = Math.abs(l) < r ? l : r;
moveY.value = Math.abs(t) < b ? t : b;
// 只使用最小的偏移量
if (Math.abs(moveX.value) < Math.abs(moveY.value))
moveY.value = 0;
else
moveX.value = 0;
return true;
}
/**
* 计算两个矩形之间有符号的交点深度
* @param rectA
* @param rectB
* @returns 两个相交的矩形之间的重叠量。
* 这些深度值可以是负值,取决于矩形相交的边。
* 这允许调用者确定正确的推送对象的方向,以解决碰撞问题。
* 如果矩形不相交则返回Vector2.zero。
*/
public static getIntersectionDepth(rectA: Rectangle, rectB: Rectangle) {
// 计算半尺寸
let halfWidthA = rectA.width / 2;
let halfHeightA = rectA.height / 2;
let halfWidthB = rectB.width / 2;
let halfHeightB = rectB.height / 2;
// 计算中心
let centerA = new Vector2(rectA.left + halfWidthA, rectA.top + halfHeightA);
let centerB = new Vector2(rectB.left + halfWidthB, rectB.top + halfHeightB);
// 计算当前中心间的距离和最小非相交距离
let distanceX = centerA.x - centerB.x;
let distanceY = centerA.y - centerB.y;
let minDistanceX = halfWidthA + halfWidthB;
let minDistanceY = halfHeightA + halfHeightB;
// 如果我们根本不相交,则返回(00)
if (Math.abs(distanceX) >= minDistanceX || Math.abs(distanceY) >= minDistanceY)
return Vector2.zero;
// 计算并返回交叉点深度
let depthX = distanceX > 0 ? minDistanceX - distanceX : -minDistanceX - distanceX;
let depthY = distanceY > 0 ? minDistanceY - distanceY : -minDistanceY - distanceY;
return new Vector2(depthX, depthY);
}
}
}

View File

@@ -1,4 +1,4 @@
///<reference path="../LinkList.ts" />
///<reference path="../Collections/LinkList.ts" />
module es {
/**
* 类,它可以计算出一个网格,表示从给定的一组遮挡物的原点可以看到哪些区域。使用方法如下。

View File

@@ -1,96 +0,0 @@
module es {
export class RectangleExt {
/**
* 获取指定边的位置
* @param rect
* @param edge
*/
public static getSide(rect: Rectangle, edge: Edge) {
switch (edge) {
case Edge.top:
return rect.top;
case Edge.bottom:
return rect.bottom;
case es.Edge.left:
return rect.left;
case Edge.right:
return rect.right;
}
}
/**
* 计算两个矩形的并集。结果将是一个包含其他两个的矩形。
* @param first
* @param point
*/
public static union(first: Rectangle, point: Vector2) {
let rect = new Rectangle(point.x, point.y, 0, 0);
let result = new Rectangle();
result.x = Math.min(first.x, rect.x);
result.y = Math.min(first.y, rect.y);
result.width = Math.max(first.right, rect.right) - result.x;
result.height = Math.max(first.bottom, rect.bottom) - result.y;
return result;
}
public static getHalfRect(rect: Rectangle, edge: Edge) {
switch (edge) {
case Edge.top:
return new Rectangle(rect.x, rect.y, rect.width, rect.height / 2);
case Edge.bottom:
return new Rectangle(rect.x, rect.y + rect.height / 2, rect.width, rect.height / 2);
case Edge.left:
return new Rectangle(rect.x, rect.y, rect.width / 2, rect.height);
case Edge.right:
return new Rectangle(rect.x + rect.width / 2, rect.y, rect.width / 2, rect.height);
}
}
/**
* 获取矩形的一部分,其宽度/高度的大小位于矩形的边缘,但仍然包含在其中。
* @param rect
* @param edge
* @param size
*/
public static getRectEdgePortion(rect: Rectangle, edge: Edge, size: number = 1) {
switch (edge) {
case es.Edge.top:
return new Rectangle(rect.x, rect.y, rect.width, size);
case Edge.bottom:
return new Rectangle(rect.x, rect.y + rect.height - size, rect.width, size);
case Edge.left:
return new Rectangle(rect.x, rect.y, size, rect.height);
case Edge.right:
return new Rectangle(rect.x + rect.width - size, rect.y, size, rect.height);
}
}
public static expandSide(rect: Rectangle, edge: Edge, amount: number) {
amount = Math.abs(amount);
switch (edge) {
case Edge.top:
rect.y -= amount;
rect.height += amount;
break;
case es.Edge.bottom:
rect.height += amount;
break;
case Edge.left:
rect.x -= amount;
rect.width += amount;
break;
case Edge.right:
rect.width += amount;
break;
}
}
public static contract(rect: Rectangle, horizontalAmount, verticalAmount) {
rect.x += horizontalAmount;
rect.y += verticalAmount;
rect.width -= horizontalAmount * 2;
rect.height -= verticalAmount * 2;
}
}
}