新增hash

This commit is contained in:
yhh
2020-12-28 16:59:16 +08:00
parent ebc1ab649e
commit f934890fac
11 changed files with 122 additions and 38 deletions

View File

@@ -945,6 +945,7 @@ declare module es {
* 存储这个允许我们始终能够安全地从物理系统中移除对撞机,即使它在试图移除它之前已经被移动了。
*/
registeredPhysicsBounds: Rectangle;
protected _colliderRequiresAutoSizing: boolean;
_localOffsetLength: number;
_isPositionDirty: boolean;
_isRotationDirty: boolean;
@@ -1768,6 +1769,18 @@ declare module es {
* @param length
*/
static incrementWithWrap(t: number, length: number): number;
/**
* 以roundToNearest为步长将值舍入到最接近的数字。例如在125中找到127到最近的5个结果
* @param value
* @param roundToNearest
*/
static roundToNearest(value: number, roundToNearest: number): number;
/**
* 检查传递的值是否在某个阈值之下。对于小规模、精确的比较很有用
* @param value
* @param ep
*/
static withinEpsilon(value: number, ep?: number): boolean;
/**
* 由上移量向上移。start可以小于或大于end。例如:开始是2结束是10移位是4结果是6
* @param start
@@ -3066,6 +3079,15 @@ declare module es {
update(): void;
}
}
declare module es {
class Hash {
/**
* 从一个字节数组中计算一个哈希值
* @param data
*/
static computeHash(...data: number[]): number;
}
}
declare module es {
interface IComparer<T> {
compare(x: T, y: T): number;
@@ -3976,12 +3998,6 @@ declare module es {
static round(vec: Vector2): Vector2;
}
}
declare class WebGLUtils {
/**
* 获取webgl context
*/
static getContext(): CanvasRenderingContext2D;
}
declare module linq {
class Enumerable {
/**

View File

@@ -2241,7 +2241,7 @@ var es;
* 封装变换。如果碰撞器没和实体一起旋转 则返回transform.rotation
*/
get: function () {
if (this.shouldColliderScaleAndRotateWithTransform && this.entity)
if (this.shouldColliderScaleAndRotateWithTransform && this.entity != null)
return this.entity.transform.rotation;
return 0;
},
@@ -2284,7 +2284,7 @@ var es;
* @param offset
*/
Collider.prototype.setLocalOffset = function (offset) {
if (this._localOffset != offset) {
if (!this._localOffset.equals(offset)) {
this.unregisterColliderWithPhysicsSystem();
this._localOffset = offset;
this._localOffsetLength = this._localOffset.length();
@@ -2303,6 +2303,9 @@ var es;
return this;
};
Collider.prototype.onAddedToEntity = function () {
if (this._colliderRequiresAutoSizing) {
es.Insist.isTrue(this instanceof es.BoxCollider || this instanceof es.CircleCollider, "只有框和圆的碰撞器可以自动创建");
}
this._isParentEntityAddedToScene = true;
this.registerColliderWithPhysicsSystem();
};
@@ -4448,6 +4451,23 @@ var es;
return 0;
return t;
};
/**
* 以roundToNearest为步长将值舍入到最接近的数字。例如在125中找到127到最近的5个结果
* @param value
* @param roundToNearest
*/
MathHelper.roundToNearest = function (value, roundToNearest) {
return Math.round(value / roundToNearest) * roundToNearest;
};
/**
* 检查传递的值是否在某个阈值之下。对于小规模、精确的比较很有用
* @param value
* @param ep
*/
MathHelper.withinEpsilon = function (value, ep) {
if (ep === void 0) { ep = this.Epsilon; }
return Math.abs(value) < ep;
};
/**
* 由上移量向上移。start可以小于或大于end。例如:开始是2结束是10移位是4结果是6
* @param start
@@ -7830,6 +7850,35 @@ var es;
es.GlobalManager = GlobalManager;
})(es || (es = {}));
var es;
(function (es) {
var Hash = /** @class */ (function () {
function Hash() {
}
/**
* 从一个字节数组中计算一个哈希值
* @param data
*/
Hash.computeHash = function () {
var data = [];
for (var _i = 0; _i < arguments.length; _i++) {
data[_i] = arguments[_i];
}
var p = 16777619;
var hash = 2166136261;
for (var i = 0; i < data.length; i++)
hash = (hash ^ data[i]) * p;
hash += hash << 13;
hash ^= hash >> 7;
hash += hash << 3;
hash ^= hash >> 17;
hash += hash << 5;
return hash;
};
return Hash;
}());
es.Hash = Hash;
})(es || (es = {}));
var es;
(function (es) {
/**
* 使得number/string/boolean类型作为对象引用来进行传递
@@ -10175,18 +10224,6 @@ var es;
}());
es.Vector2Ext = Vector2Ext;
})(es || (es = {}));
var WebGLUtils = /** @class */ (function () {
function WebGLUtils() {
}
/**
* 获取webgl context
*/
WebGLUtils.getContext = function () {
var canvas = document.getElementsByTagName('canvas')[0];
return canvas.getContext('2d');
};
return WebGLUtils;
}());
var linq;
(function (linq) {
var Enumerable = /** @class */ (function () {

File diff suppressed because one or more lines are too long

View File

@@ -88,7 +88,7 @@ module es {
return Math.atan2(to.y - from.y, to.x - from.x);
}
public static angleToVector(angleRadians: number, length: number){
public static angleToVector(angleRadians: number, length: number) {
return new Vector2(Math.cos(angleRadians) * length, Math.sin(angleRadians) * length);
}
@@ -97,14 +97,32 @@ module es {
* @param t
* @param length
*/
public static incrementWithWrap(t: number, length: number){
t ++;
public static incrementWithWrap(t: number, length: number) {
t++;
if (t == length)
return 0;
return t;
}
/**
* 以roundToNearest为步长将值舍入到最接近的数字。例如在125中找到127到最近的5个结果
* @param value
* @param roundToNearest
*/
public static roundToNearest(value: number, roundToNearest: number) {
return Math.round(value / roundToNearest) * roundToNearest;
}
/**
* 检查传递的值是否在某个阈值之下。对于小规模、精确的比较很有用
* @param value
* @param ep
*/
public static withinEpsilon(value: number, ep: number = this.Epsilon) {
return Math.abs(value) < ep;
}
/**
* 由上移量向上移。start可以小于或大于end。例如:开始是2结束是10移位是4结果是6
* @param start

View File

@@ -1,9 +0,0 @@
class WebGLUtils {
/**
* 获取webgl context
*/
public static getContext() {
const canvas = document.getElementsByTagName('canvas')[0];
return canvas.getContext('2d');
}
}

22
source/src/Utils/Hash.ts Normal file
View File

@@ -0,0 +1,22 @@
module es {
export class Hash {
/**
* 从一个字节数组中计算一个哈希值
* @param data
*/
public static computeHash(...data: number[]) {
const p: number = 16777619;
let hash = 2166136261;
for (let i = 0; i < data.length; i++)
hash = (hash ^ data[i]) * p;
hash += hash << 13;
hash ^= hash >> 7;
hash += hash << 3;
hash ^= hash >> 17;
hash += hash << 5;
return hash;
}
}
}