Skip to content

Commit adc0005

Browse files
committed
fix create after insert when id == entitySequence
1 parent 5d56d2a commit adc0005

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/ecs.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ describe("behavior", function () {
203203
expect(world.create()).toEqual(201);
204204
});
205205

206+
it("insert does not break sequence when entity == world.entitySequence", function () {
207+
const world = new World;
208+
209+
const a = world.insert(0);
210+
const b = world.create(); // should be 1
211+
212+
expect(a + 1).toEqual(b);
213+
});
214+
206215
it("view doesn't loop infinitely", function () {
207216
const world = new World;
208217
world.create(A);

src/world.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class World {
8282
*/
8383
insert<T extends Component[]>(entity: Entity, ...components: T): Entity {
8484
// ensure this doesn't break our entity sequence
85-
if (entity > this.entitySequence) this.entitySequence = entity + 1;
85+
if (entity >= this.entitySequence) this.entitySequence = entity + 1;
8686
this.entities.add(entity);
8787
for (let i = 0, len = components.length; i < len; ++i) {
8888
this.emplace(entity, components[i]);

0 commit comments

Comments
 (0)