refactor(ecs): BigInt
This commit is contained in:
parent
3373cb7135
commit
ba938bc39d
|
@ -131,7 +131,7 @@ export default class FlatComponent extends BaseComponent {
|
|||
`return this.view.get${Schema.viewMethodFromType(type)}(this.cursor + ${offset}, true);`
|
||||
);
|
||||
const set = (type) => [
|
||||
`this.parent.setDirty(Number(this.view.getBigUint64(this.cursor + ${width - 9}, true)));`,
|
||||
`this.parent.setDirty(this.view.getBigUint64(this.cursor + ${width - 9}, true));`,
|
||||
`this.view.set${Schema.viewMethodFromType(type)}(this.cursor + ${offset}, v, true);`,
|
||||
`this.view.setUint8(this.cursor + ${width - 1}, 1, true);`,
|
||||
].join('');
|
||||
|
@ -141,8 +141,8 @@ export default class FlatComponent extends BaseComponent {
|
|||
set: new Function('v', `this.view.setUint8(this.cursor + ${width - 1}, v ? 1 : 0, true);`),
|
||||
};
|
||||
properties.entity = {
|
||||
get: new Function('', `return Number(this.view.getBigUint64(this.cursor + ${width - 9}, true));`),
|
||||
set: new Function('v', `this.view.setBigUint64(this.cursor + ${width - 9}, BigInt(v), true);`),
|
||||
get: new Function('', `return this.view.getBigUint64(this.cursor + ${width - 9}, true);`),
|
||||
set: new Function('v', `this.view.setBigUint64(this.cursor + ${width - 9}, v, true);`),
|
||||
};
|
||||
for (const [i, spec] of this.schema) {
|
||||
const {type} = spec;
|
||||
|
|
|
@ -60,7 +60,7 @@ export default class Ecs {
|
|||
}
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
while (count-- > 0) {
|
||||
const entity = this.$$caret++;
|
||||
const entity = BigInt(this.$$caret++);
|
||||
entities.push(entity);
|
||||
this.$$entities[entity] = componentKeys.slice(0);
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ export default class Ecs {
|
|||
const create = [];
|
||||
const update = [];
|
||||
for (let i = 0; i < count; ++i) {
|
||||
const entity = Number(view.getBigUint64(cursor, true));
|
||||
const entity = view.getBigUint64(cursor, true);
|
||||
cursor += 8;
|
||||
const components = {};
|
||||
const componentCount = view.getUint16(cursor, true);
|
||||
|
@ -149,7 +149,7 @@ export default class Ecs {
|
|||
}
|
||||
|
||||
destroyAll() {
|
||||
this.destroyMany(Object.keys(this.$$entities).map((entity) => parseInt(entity, 10)));
|
||||
this.destroyMany(Object.keys(this.$$entities).map((entity) => BigInt(entity)));
|
||||
}
|
||||
|
||||
destroyMany(entities) {
|
||||
|
@ -199,7 +199,7 @@ export default class Ecs {
|
|||
continue;
|
||||
}
|
||||
entitiesWritten += 1;
|
||||
view.setBigUint64(cursor, BigInt(entity), true);
|
||||
view.setBigUint64(cursor, entity, true);
|
||||
cursor += 8;
|
||||
const components = this.$$entities[entity];
|
||||
view.setUint16(cursor, components.length, true);
|
||||
|
|
|
@ -20,11 +20,11 @@ class B extends Component {
|
|||
}
|
||||
|
||||
const Components = {A: new A(), B: new B()};
|
||||
Components.A.createMany([2, 3]);
|
||||
Components.B.createMany([1, 2]);
|
||||
Components.A.createMany([2n, 3n]);
|
||||
Components.B.createMany([1n, 2n]);
|
||||
function testQuery(parameters, expected) {
|
||||
const query = new Query(parameters, Components);
|
||||
query.reindex([1, 2, 3]);
|
||||
query.reindex([1n, 2n, 3n]);
|
||||
expect(query.count)
|
||||
.to.equal(expected.length);
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
|
@ -37,25 +37,25 @@ function testQuery(parameters, expected) {
|
|||
}
|
||||
|
||||
it('can query all', () => {
|
||||
testQuery([], [1, 2, 3]);
|
||||
testQuery([], [1n, 2n, 3n]);
|
||||
});
|
||||
|
||||
it('can query some', () => {
|
||||
testQuery(['A'], [2, 3]);
|
||||
testQuery(['A', 'B'], [2]);
|
||||
testQuery(['A'], [2n, 3n]);
|
||||
testQuery(['A', 'B'], [2n]);
|
||||
});
|
||||
|
||||
it('can query excluding', () => {
|
||||
testQuery(['!A'], [1]);
|
||||
testQuery(['A', '!B'], [3]);
|
||||
testQuery(['!A'], [1n]);
|
||||
testQuery(['A', '!B'], [3n]);
|
||||
});
|
||||
|
||||
it('can deindex', () => {
|
||||
const query = new Query(['A'], Components);
|
||||
query.reindex([1, 2, 3]);
|
||||
query.reindex([1n, 2n, 3n]);
|
||||
expect(query.count)
|
||||
.to.equal(2);
|
||||
query.deindex([2]);
|
||||
query.deindex([2n]);
|
||||
expect(query.count)
|
||||
.to.equal(1);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user