Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when removing a component #35

Closed
ooflorent opened this issue Feb 2, 2021 · 2 comments
Closed

TypeError when removing a component #35

ooflorent opened this issue Feb 2, 2021 · 2 comments

Comments

@ooflorent
Copy link

When benchmark the mutations I faced a TypeError when removing a component:

TypeError: Cannot mix BigInt and other types, use explicit conversions
    at subtractBit (file:///Users/fcailhol/Development/_lost/_noctjs/ecs-benchmark/node_modules/geotic/build/index.js:509:21)
    at removeComponent (file:///Users/fcailhol/Development/_lost/_noctjs/ecs-benchmark/node_modules/geotic/build/index.js:555:19)
    at Entity.remove (file:///Users/fcailhol/Development/_lost/_noctjs/ecs-benchmark/node_modules/geotic/build/index.js:654:7)

Reproduction:

import { Component, Engine } from "geotic";

class Position extends Component {
  static properties = {
    x: 0,
    y: 0,
  };
}

class Velocity extends Component {
  static properties = {
    dx: 0,
    dy: 0,
  };
}

class Animation extends Component {
  static properties = {
    frame: 0,
    size: 1,
  };
}

function setup() {
  const engine = new Engine();

  engine.registerComponent(Position);
  engine.registerComponent(Velocity);
  engine.registerComponent(Animation);

  return engine.createWorld();
}

export function bench_mutate(count) {
  let world = setup();

  for (let i = 0; i < count; i++) {
    let e1 = world.createEntity();
    let e2 = world.createEntity();
    e1.add(Position);
    e1.add(Animation);
    e2.add(Position);
    e2.add(Velocity);
  }

  let all = world.createQuery({
    all: [Position],
  });

  let anims = world.createQuery({
    all: [Animation],
  });

  let vels = world.createQuery({
    all: [Velocity],
  });

  return () => {
    for (let entity of all.get()) {
      if (entity.has(Animation)) {
        entity.remove(Animation);
        entity.add(Velocity);
      } else if (entity.has(Velocity)) {
        entity.remove(Velocity);
        entity.add(Animation);
      }
    }

    for (let entity of anims.get()) {
      if (!entity) throw new Error();
    }

    for (let entity of vels.get()) {
      if (!entity) throw new Error();
    }
  };
}
@ddmills
Copy link
Owner

ddmills commented Feb 2, 2021

current you cannot remove component by type, you have to specify the component instance:

entity.remove(entity.animation);
entity.remove(entity.velocity);

@ddmills
Copy link
Owner

ddmills commented Feb 14, 2021

#36

@ddmills ddmills closed this as completed Feb 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants