Skip to content

Commit d576a95

Browse files
committed
fix wx
1 parent 99eca54 commit d576a95

File tree

6 files changed

+82
-9
lines changed

6 files changed

+82
-9
lines changed

source/bin/framework.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,16 @@ declare module es {
17711771
onEntityDisabled(): void;
17721772
}
17731773
}
1774+
declare module es {
1775+
class ComponentTypeFactory {
1776+
private componentTypes_;
1777+
private componentTypeCount_;
1778+
types: Bag<ComponentType>;
1779+
constructor();
1780+
getTypeFor(c: any): ComponentType;
1781+
getIndexFor(c: any): number;
1782+
}
1783+
}
17741784
declare module es {
17751785
class ComponentTypeManager {
17761786
private static _componentTypesMask;

source/bin/framework.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,7 +3134,7 @@ var es;
31343134
EntitySystem.prototype.initialize = function () {
31353135
};
31363136
EntitySystem.prototype.onChanged = function (entity) {
3137-
var contains = entity.getSystemBits().get(this.systemIndex_);
3137+
var contains = new es.List(this._entities).contains(entity);
31383138
var interest = this._matcher.isInterestedEntity(entity);
31393139
if (interest && !contains)
31403140
this.add(entity);
@@ -3143,13 +3143,11 @@ var es;
31433143
};
31443144
EntitySystem.prototype.add = function (entity) {
31453145
this._entities.push(entity);
3146-
entity.getSystemBits().set(this.systemIndex_);
31473146
this.onAdded(entity);
31483147
};
31493148
EntitySystem.prototype.onAdded = function (entity) { };
31503149
EntitySystem.prototype.remove = function (entity) {
31513150
new es.List(this._entities).remove(entity);
3152-
entity.getSystemBits().clear(this.systemIndex_);
31533151
this.onRemoved(entity);
31543152
};
31553153
EntitySystem.prototype.onRemoved = function (entity) { };
@@ -4255,6 +4253,34 @@ var es;
42554253
es.ComponentList = ComponentList;
42564254
})(es || (es = {}));
42574255
var es;
4256+
(function (es) {
4257+
var ComponentTypeFactory = /** @class */ (function () {
4258+
function ComponentTypeFactory() {
4259+
this.componentTypeCount_ = 0;
4260+
this.componentTypes_ = {};
4261+
this.types = new es.Bag();
4262+
}
4263+
ComponentTypeFactory.prototype.getTypeFor = function (c) {
4264+
if ("number" === typeof c) {
4265+
return this.types.get(c);
4266+
}
4267+
var type = this.componentTypes_[es.getClassName(c)];
4268+
if (type == null) {
4269+
var index = this.componentTypeCount_++;
4270+
type = new es.ComponentType(c, index);
4271+
this.componentTypes_[es.getClassName(c)] = type;
4272+
this.types.set(index, type);
4273+
}
4274+
return type;
4275+
};
4276+
ComponentTypeFactory.prototype.getIndexFor = function (c) {
4277+
return this.getTypeFor(c).getIndex();
4278+
};
4279+
return ComponentTypeFactory;
4280+
}());
4281+
es.ComponentTypeFactory = ComponentTypeFactory;
4282+
})(es || (es = {}));
4283+
var es;
42584284
(function (es) {
42594285
var ComponentTypeManager = /** @class */ (function () {
42604286
function ComponentTypeManager() {
@@ -11602,7 +11628,7 @@ var es;
1160211628
function TypeUtils() {
1160311629
}
1160411630
TypeUtils.getType = function (obj) {
11605-
return obj["__proto__"]["constructor"];
11631+
return obj.constructor;
1160611632
};
1160711633
return TypeUtils;
1160811634
}());

source/bin/framework.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/src/ECS/Systems/EntitySystem.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module es {
6060
}
6161

6262
public onChanged(entity: Entity) {
63-
let contains = entity.getSystemBits().get(this.systemIndex_);
63+
let contains = new es.List(this._entities).contains(entity);
6464
let interest = this._matcher.isInterestedEntity(entity);
6565

6666
if (interest && !contains)
@@ -71,15 +71,13 @@ module es {
7171

7272
public add(entity: Entity) {
7373
this._entities.push(entity);
74-
entity.getSystemBits().set(this.systemIndex_);
7574
this.onAdded(entity);
7675
}
7776

7877
public onAdded(entity: Entity) { }
7978

8079
public remove(entity: Entity) {
8180
new es.List(this._entities).remove(entity);
82-
entity.getSystemBits().clear(this.systemIndex_);
8381
this.onRemoved(entity);
8482
}
8583

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module es {
2+
interface IdentityHashMap {
3+
[key: string]: ComponentType;
4+
}
5+
6+
export class ComponentTypeFactory {
7+
private componentTypes_: IdentityHashMap;
8+
9+
private componentTypeCount_ = 0;
10+
11+
public types: Bag<ComponentType>;
12+
13+
constructor() {
14+
this.componentTypes_ = {};
15+
this.types = new Bag<ComponentType>();
16+
}
17+
18+
public getTypeFor(c): ComponentType {
19+
if ("number" === typeof c) {
20+
return this.types.get(c);
21+
}
22+
23+
let type: ComponentType = this.componentTypes_[getClassName(c)];
24+
25+
if (type == null) {
26+
const index: number = this.componentTypeCount_++;
27+
type = new ComponentType(c, index);
28+
this.componentTypes_[getClassName(c)] = type;
29+
this.types.set(index, type);
30+
}
31+
32+
return type;
33+
}
34+
35+
public getIndexFor(c): number {
36+
return this.getTypeFor(c).getIndex();
37+
}
38+
}
39+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module es {
22
export class TypeUtils {
33
public static getType(obj: any){
4-
return obj["__proto__"]["constructor"];
4+
return obj.constructor;
55
}
66
}
77
}

0 commit comments

Comments
 (0)