新增numberdictionary的散列键

This commit is contained in:
yhh
2020-06-16 20:22:22 +08:00
parent 447ea4efe4
commit 9e6e5eccc8
8 changed files with 49 additions and 8 deletions

View File

@@ -411,6 +411,7 @@ declare abstract class Collider extends Component {
overlaps(other: Collider): any;
collidesWith(collider: Collider, motion: Vector2): CollisionResult;
onAddedToEntity(): void;
onRemovedFromEntity(): void;
onEntityTransformChanged(comp: ComponentTransform): void;
onEnabled(): void;
onDisabled(): void;
@@ -777,6 +778,7 @@ declare class RaycastResultParser {
declare class NumberDictionary {
private _store;
private getKey;
private intToUint;
add(x: number, y: number, list: Collider[]): void;
remove(obj: Collider): void;
tryGetValue(x: number, y: number): Collider[];

View File

@@ -1911,7 +1911,7 @@ var Collider = (function (_super) {
console.error("Only box and circle colliders can be created automatically");
}
var renderable = this.entity.getComponent(RenderableComponent);
if (!renderable) {
if (renderable) {
var renderbaleBounds = renderable.bounds;
var width = renderbaleBounds.width / this.entity.transform.scale.x;
var height = renderbaleBounds.height / this.entity.transform.scale.y;
@@ -1926,6 +1926,10 @@ var Collider = (function (_super) {
this._isParentEntityAddedToScene = true;
this.registerColliderWithPhysicsSystem();
};
Collider.prototype.onRemovedFromEntity = function () {
this.unregisterColliderWithPhysicsSystem();
this._isParentEntityAddedToScene = false;
};
Collider.prototype.onEntityTransformChanged = function (comp) {
switch (comp) {
case ComponentTransform.position:
@@ -3844,7 +3848,13 @@ var NumberDictionary = (function () {
this._store = new Map();
}
NumberDictionary.prototype.getKey = function (x, y) {
return x << 32 | y;
return x << 32 | this.intToUint(y);
};
NumberDictionary.prototype.intToUint = function (i) {
if (i >= 0)
return i;
else
return 4294967296 + i;
};
NumberDictionary.prototype.add = function (x, y, list) {
this._store.set(this.getKey(x, y), list);

File diff suppressed because one or more lines are too long