Coder Social home page Coder Social logo

co_ecs's People

Contributors

blyschak avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

co_ecs's Issues

Sorting view

I've tried sorting a view by entity id, however that does not work. What would be the correct way to sort entities without copying them?

auto view = registry.view<const ecs::entity&>().each()
std::sort(view.begin(), view.end(), [](std::tuple<const ecs::entity&> a, std::tuple<const ecs::entity&> b){
    return std::get<0>(a).id() < std::get<0>(b).id();
});

Segmentation fault on program close

Describe the bug
The program throws a segmentation fault on default exit.

To Reproduce
Paste the reproduction code snippet below:

#include "co_ecs.hpp"

struct s1 {
    uint32_t i1;
    uint64_t i2;
};

struct s2 {
    float f1;
    int i1;
};

struct s3 {
    char c, e;
};

void test_create(ecs::registry& reg) {
    auto a = reg.create<s1, s3>({1, 2}, {92, 93});
    auto b = reg.create<s1, s3>({7, 3}, {75, 76});
    auto c = reg.create<s2>({});
}

int main() {
    ecs::registry reg;
    test_create(reg);
    return 0;
}

Observed behavior
The segfault is caused by the destructor call inside the destructor of the chunk class. Specifically this line:

block.meta.type->destruct(_buffer + block.offset + i * block.meta.type->size);

Environment

  • OS: MacOS 13.1
  • Arch: arm64

Builder-like API

Is your feature request related to a problem? Please describe.

The following code snippet:

auto entity = registry.create<Foo1, Foo2, Foo3, Foo4, Foo5, Fooo6>({1, 2}, {"hello"}, {1.}, {2, 5, 7}, {"my", 9}, {});
  1. It is suboptimal: We need to create 6 temporaries FooX objects and move into an archetype
  2. It is hard to follow. Looking at Nth argument {1.} it is hard to understand to which component it corresponds to, or requires to be more explicit, making the line even longer: Foo3{1.}
  3. No bulk API

Describe the solution you'd like. Give an example of proposed C++ APIs and their usage

The following:

struct Foo {int a, b};
struct S{};

registry.entity().build(); // creates empty

registry.entity<Foo, S>() // -> Builder<Foo, S>/ an archetype is found based on component set
    .with<Foo>(1, 2)        // -> Intermediate<Builder<Foo, S>, Foo>. Static assert that Foo is in the Builder<Foo, S>
    .with<S>()            // -> Intermediate<Builder<Foo, S>, Foo, S>. Static assert that Sis in the Builder<Foo, S>
    .build();               // Static assert that all components are set. No possibility of leaving some components uninitialized.

// Bulk may look like this ??? :

registry.entities<Foo, S>()
      .entity()
          .with<Foo>(1, 2)
          .with<S>()
          .build()
      .entity()
          .with<Foo>(3, 4)
          .with<S>()
          .build()

Pros:

  1. Safe with static asserts and understandable error messages
  2. Ergonomic
  3. Optimal
  4. May extend to bulk API
  5. Same idea might be used for fluent .set APIs

Cons:

  1. Requires to specify <Foo, S> in advance and then construct them with with<T>(). But I don't find a way to implement it like this:
registry.entity()
    .with<Foo>(1, 2)
    .with<S>()
    .build();

Describe alternatives you've considered
N/A

Additional context
N/A

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.