blyschak / co_ecs Goto Github PK
View Code? Open in Web Editor NEWArchetype based Entity Component System
License: MIT License
Archetype based Entity Component System
License: MIT License
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();
});
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
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 hard to understand to which component it corresponds to, or requires to be more explicit, making the line even longer: Foo3{1.}
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:
Cons:
<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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.