Coder Social home page Coder Social logo

Comments (5)

sschmid avatar sschmid commented on May 1, 2024

True. Atm it's intended, because this code is being generated and we can save a method call. If we start using it in more places, we can extract it to a method.

from entitas.

npruehs avatar npruehs commented on May 1, 2024

Yeah, I had to copy it for my own implementation of IComponentCodeGenerator. Not a big deal, but other people might easily miss the pooling part by just calling the component constructor instead. Your decision :)

from entitas.

sschmid avatar sschmid commented on May 1, 2024

In general extracting such a method would be nice. Not sure if it makes sense in this case. It's in a generated extension a should not be used from a different generated extension. Offering a generic method componentPool.GetComponent<Position>() would work but since it's in a generated file I'd rather go for the better performance by writing new PositionComponent()

from entitas.

sschmid avatar sschmid commented on May 1, 2024

Hi, a quick follow-up:
Just added entity.CreateComponent() which does all the pooling logic now. It's also used by the code generator now.
e641cf1

public Entity AddPerson(int newAge, string newName) {
    var component = CreateComponent<PersonComponent>(ComponentIds.Person);
    component.age = newAge;
    component.name = newName;
    return AddComponent(ComponentIds.Person, component);
}

public Entity ReplacePerson(int newAge, string newName) {
    var component = CreateComponent<PersonComponent>(ComponentIds.Person);
    component.age = newAge;
    component.name = newName;
    ReplaceComponent(ComponentIds.Person, component);
    return this;
}

from entitas.

npruehs avatar npruehs commented on May 1, 2024

Excellent :)

from entitas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.