修复bitset调整数组大小时错误/componentTypeManager获取修复
This commit is contained in:
3
source/bin/framework.d.ts
vendored
3
source/bin/framework.d.ts
vendored
@@ -584,7 +584,8 @@ declare module es {
|
|||||||
getAllSet(): BitSet;
|
getAllSet(): BitSet;
|
||||||
getExclusionSet(): BitSet;
|
getExclusionSet(): BitSet;
|
||||||
getOneSet(): BitSet;
|
getOneSet(): BitSet;
|
||||||
IsIntersted(e: Entity): boolean;
|
isInterestedEntity(e: Entity): boolean;
|
||||||
|
isInterested(componentBits: BitSet): boolean;
|
||||||
all(...types: any[]): Matcher;
|
all(...types: any[]): Matcher;
|
||||||
exclude(...types: any[]): this;
|
exclude(...types: any[]): this;
|
||||||
one(...types: any[]): this;
|
one(...types: any[]): this;
|
||||||
|
|||||||
@@ -1781,7 +1781,7 @@ var es;
|
|||||||
};
|
};
|
||||||
EntitySystem.prototype.onChanged = function (entity) {
|
EntitySystem.prototype.onChanged = function (entity) {
|
||||||
var contains = this._entities.contains(entity);
|
var contains = this._entities.contains(entity);
|
||||||
var interest = this._matcher.IsIntersted(entity);
|
var interest = this._matcher.isInterestedEntity(entity);
|
||||||
if (interest && !contains)
|
if (interest && !contains)
|
||||||
this.add(entity);
|
this.add(entity);
|
||||||
else if (!interest && contains)
|
else if (!interest && contains)
|
||||||
@@ -1880,10 +1880,11 @@ var es;
|
|||||||
var BitSet = (function () {
|
var BitSet = (function () {
|
||||||
function BitSet(nbits) {
|
function BitSet(nbits) {
|
||||||
if (nbits === void 0) { nbits = 64; }
|
if (nbits === void 0) { nbits = 64; }
|
||||||
var length = nbits >> 6;
|
var length = nbits >> 6 >>> 0;
|
||||||
if ((nbits & BitSet.LONG_MASK) != 0)
|
if ((nbits & BitSet.LONG_MASK) != 0)
|
||||||
length++;
|
length++;
|
||||||
this._bits = new Array(length);
|
this._bits = new Array(length);
|
||||||
|
this._bits.fill(0);
|
||||||
}
|
}
|
||||||
BitSet.prototype.and = function (bs) {
|
BitSet.prototype.and = function (bs) {
|
||||||
var max = Math.min(this._bits.length, bs._bits.length);
|
var max = Math.min(this._bits.length, bs._bits.length);
|
||||||
@@ -1899,7 +1900,7 @@ var es;
|
|||||||
this._bits[i] &= ~bs._bits[i];
|
this._bits[i] &= ~bs._bits[i];
|
||||||
};
|
};
|
||||||
BitSet.prototype.cardinality = function () {
|
BitSet.prototype.cardinality = function () {
|
||||||
var card = 0;
|
var card = 0 >>> 0;
|
||||||
for (var i = this._bits.length - 1; i >= 0; i--) {
|
for (var i = this._bits.length - 1; i >= 0; i--) {
|
||||||
var a = this._bits[i];
|
var a = this._bits[i];
|
||||||
if (a == 0)
|
if (a == 0)
|
||||||
@@ -1910,7 +1911,7 @@ var es;
|
|||||||
}
|
}
|
||||||
a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555);
|
a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555);
|
||||||
a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333);
|
a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333);
|
||||||
var b = ((a >> 32) + a);
|
var b = ((a >> 32) + a) >>> 0;
|
||||||
b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f);
|
b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f);
|
||||||
b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff);
|
b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff);
|
||||||
card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff);
|
card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff);
|
||||||
@@ -1978,9 +1979,9 @@ var es;
|
|||||||
};
|
};
|
||||||
BitSet.prototype.ensure = function (lastElt) {
|
BitSet.prototype.ensure = function (lastElt) {
|
||||||
if (lastElt >= this._bits.length) {
|
if (lastElt >= this._bits.length) {
|
||||||
var nd = new Number[lastElt + 1];
|
var startIndex = this._bits.length;
|
||||||
nd = this._bits.copyWithin(0, 0, this._bits.length);
|
this._bits.length = lastElt + 1;
|
||||||
this._bits = nd;
|
this._bits.fill(0, startIndex, lastElt + 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
BitSet.LONG_MASK = 0x3f;
|
BitSet.LONG_MASK = 0x3f;
|
||||||
@@ -2044,7 +2045,7 @@ var es;
|
|||||||
continue;
|
continue;
|
||||||
if (es.isIUpdatable(component))
|
if (es.isIUpdatable(component))
|
||||||
this._updatableComponents.remove(component);
|
this._updatableComponents.remove(component);
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false);
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]), false);
|
||||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -2053,7 +2054,7 @@ var es;
|
|||||||
var component = this._components.buffer[i];
|
var component = this._components.buffer[i];
|
||||||
if (es.isIUpdatable(component))
|
if (es.isIUpdatable(component))
|
||||||
this._updatableComponents.add(component);
|
this._updatableComponents.add(component);
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -2070,7 +2071,7 @@ var es;
|
|||||||
var component = this._componentsToAdd[i];
|
var component = this._componentsToAdd[i];
|
||||||
if (es.isIUpdatable(component))
|
if (es.isIUpdatable(component))
|
||||||
this._updatableComponents.add(component);
|
this._updatableComponents.add(component);
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
this._components.add(component);
|
this._components.add(component);
|
||||||
this._tempBufferList.push(component);
|
this._tempBufferList.push(component);
|
||||||
@@ -2096,7 +2097,7 @@ var es;
|
|||||||
return;
|
return;
|
||||||
if (es.isIUpdatable(component))
|
if (es.isIUpdatable(component))
|
||||||
this._updatableComponents.remove(component);
|
this._updatableComponents.remove(component);
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false);
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]), false);
|
||||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||||
component.onRemovedFromEntity();
|
component.onRemovedFromEntity();
|
||||||
component.entity = null;
|
component.entity = null;
|
||||||
@@ -2178,6 +2179,9 @@ var es;
|
|||||||
this.add(type);
|
this.add(type);
|
||||||
v = this._componentTypesMask.get(type);
|
v = this._componentTypesMask.get(type);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
v = this._componentTypesMask.get(type);
|
||||||
|
}
|
||||||
return v;
|
return v;
|
||||||
};
|
};
|
||||||
ComponentTypeManager._componentTypesMask = new Map();
|
ComponentTypeManager._componentTypesMask = new Map();
|
||||||
@@ -2824,16 +2828,19 @@ var es;
|
|||||||
Matcher.prototype.getOneSet = function () {
|
Matcher.prototype.getOneSet = function () {
|
||||||
return this.oneSet;
|
return this.oneSet;
|
||||||
};
|
};
|
||||||
Matcher.prototype.IsIntersted = function (e) {
|
Matcher.prototype.isInterestedEntity = function (e) {
|
||||||
|
return this.isInterested(e.componentBits);
|
||||||
|
};
|
||||||
|
Matcher.prototype.isInterested = function (componentBits) {
|
||||||
if (!this.allSet.isEmpty()) {
|
if (!this.allSet.isEmpty()) {
|
||||||
for (var i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) {
|
for (var i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) {
|
||||||
if (!e.componentBits.get(i))
|
if (!componentBits.get(i))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(e.componentBits))
|
if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(componentBits))
|
||||||
return false;
|
return false;
|
||||||
if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits))
|
if (!this.oneSet.isEmpty() && !this.oneSet.intersects(componentBits))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
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
@@ -29,7 +29,7 @@ module es {
|
|||||||
|
|
||||||
public onChanged(entity: Entity) {
|
public onChanged(entity: Entity) {
|
||||||
let contains = this._entities.contains(entity);
|
let contains = this._entities.contains(entity);
|
||||||
let interest = this._matcher.IsIntersted(entity);
|
let interest = this._matcher.isInterestedEntity(entity);
|
||||||
|
|
||||||
if (interest && !contains)
|
if (interest && !contains)
|
||||||
this.add(entity);
|
this.add(entity);
|
||||||
|
|||||||
@@ -9,11 +9,12 @@ module es {
|
|||||||
private _bits: number[];
|
private _bits: number[];
|
||||||
|
|
||||||
constructor(nbits: number = 64) {
|
constructor(nbits: number = 64) {
|
||||||
let length = nbits >> 6;
|
let length = nbits >> 6 >>> 0;
|
||||||
if ((nbits & BitSet.LONG_MASK) != 0)
|
if ((nbits & BitSet.LONG_MASK) != 0)
|
||||||
length++;
|
length++;
|
||||||
|
|
||||||
this._bits = new Array(length);
|
this._bits = new Array(length);
|
||||||
|
this._bits.fill(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public and(bs: BitSet) {
|
public and(bs: BitSet) {
|
||||||
@@ -33,7 +34,7 @@ module es {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public cardinality(): number {
|
public cardinality(): number {
|
||||||
let card = 0;
|
let card = 0 >>> 0;
|
||||||
for (let i = this._bits.length - 1; i >= 0; i--) {
|
for (let i = this._bits.length - 1; i >= 0; i--) {
|
||||||
let a = this._bits[i];
|
let a = this._bits[i];
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ module es {
|
|||||||
|
|
||||||
a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555);
|
a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555);
|
||||||
a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333);
|
a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333);
|
||||||
let b = ((a >> 32) + a);
|
let b = ((a >> 32) + a) >>> 0;
|
||||||
b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f);
|
b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f);
|
||||||
b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff);
|
b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff);
|
||||||
card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff);
|
card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff);
|
||||||
@@ -126,9 +127,9 @@ module es {
|
|||||||
|
|
||||||
private ensure(lastElt: number) {
|
private ensure(lastElt: number) {
|
||||||
if (lastElt >= this._bits.length) {
|
if (lastElt >= this._bits.length) {
|
||||||
let nd = new Number[lastElt + 1];
|
let startIndex = this._bits.length;
|
||||||
nd = this._bits.copyWithin(0, 0, this._bits.length);
|
this._bits.length = lastElt + 1;
|
||||||
this._bits = nd;
|
this._bits.fill(0, startIndex, lastElt + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ module es {
|
|||||||
if (isIUpdatable(component))
|
if (isIUpdatable(component))
|
||||||
this._updatableComponents.remove(component);
|
this._updatableComponents.remove(component);
|
||||||
|
|
||||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false);
|
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]), false);
|
||||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ module es {
|
|||||||
if (isIUpdatable(component))
|
if (isIUpdatable(component))
|
||||||
this._updatableComponents.add(component);
|
this._updatableComponents.add(component);
|
||||||
|
|
||||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component));
|
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ module es {
|
|||||||
if (isIUpdatable(component))
|
if (isIUpdatable(component))
|
||||||
this._updatableComponents.add(component);
|
this._updatableComponents.add(component);
|
||||||
|
|
||||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component));
|
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
|
|
||||||
this._components.add(component);
|
this._components.add(component);
|
||||||
@@ -160,7 +160,7 @@ module es {
|
|||||||
if (isIUpdatable(component))
|
if (isIUpdatable(component))
|
||||||
this._updatableComponents.remove(component);
|
this._updatableComponents.remove(component);
|
||||||
|
|
||||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false);
|
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]), false);
|
||||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||||
|
|
||||||
component.onRemovedFromEntity();
|
component.onRemovedFromEntity();
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ module es {
|
|||||||
if (!this._componentTypesMask.has(type)) {
|
if (!this._componentTypesMask.has(type)) {
|
||||||
this.add(type);
|
this.add(type);
|
||||||
v = this._componentTypesMask.get(type);
|
v = this._componentTypesMask.get(type);
|
||||||
|
} else {
|
||||||
|
v = this._componentTypesMask.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
|
|||||||
@@ -20,18 +20,25 @@ module es {
|
|||||||
return this.oneSet;
|
return this.oneSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IsIntersted(e: Entity) {
|
public isInterestedEntity(e: Entity) {
|
||||||
|
return this.isInterested(e.componentBits);
|
||||||
|
}
|
||||||
|
|
||||||
|
public isInterested(componentBits: BitSet) {
|
||||||
|
// 检查实体是否拥有该方面中定义的所有组件
|
||||||
if (!this.allSet.isEmpty()) {
|
if (!this.allSet.isEmpty()) {
|
||||||
for (let i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) {
|
for (let i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) {
|
||||||
if (!e.componentBits.get(i))
|
if (!componentBits.get(i))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(e.componentBits))
|
// 如果我们仍然感兴趣,检查该实体是否拥有任何一个排除组件,如果有,那么系统就不感兴趣
|
||||||
|
if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(componentBits))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits))
|
// 如果我们仍然感兴趣,检查该实体是否拥有oneSet中的任何一个组件。如果是,系统就会感兴趣
|
||||||
|
if (!this.oneSet.isEmpty() && !this.oneSet.intersects(componentBits))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user