Replies: 2 comments
-
Why you can't make struct rigid_body {
rigid_body(b2Body *);
rigid_body(rigid_body &&) = default;
rigid_body &operator=(rigid_body &&) = default;
// ...
private:
std::unique_ptr<b2Body, void (*)(void *)> body;
};
struct physics_component {
physics_component(b2Body * /*, other args */);
physics_component(physics_component &&) = default;
physics_component &operator=(physics_component &&) = default;
// ...
rigid_body body;
// ...
}; Then I have something like this in the cpp file: namespace internal {
static void b2body_deleter(void *ptr) noexcept {
b2Body *body = static_cast<b2Body *>(ptr);
b2World *world = body->GetWorld();
world->DestroyBody(body);
}
} // namespace internal
// ...
rigid_body::rigid_body(b2Body *elem)
: body{elem, &internal::b2body_deleter} {}
physics_component::physics_component(b2Body *elem /*, other args */)
: body{elem}
/* , other members */ {}
// ... Otherwise you can listen on the desctruction of the my_registry.on_destroy<BodyComponent>().connect<&my_cleanup_function>(); You can find more details in the documentation for this stuff. I prefer the first method but both work at the end of the day. |
Beta Was this translation helpful? Give feedback.
-
Oh, I had a lambda where I used |
Beta Was this translation helpful? Give feedback.
-
I have the following component:
Now whenever that component is removed I want to execute the following code:
body->GetWorld()->DestroyBody(body);
How would I do that given that I can't make
BodyComponent
move-only and do it in the destructor? Am I thinking about ECS completely wrong?Beta Was this translation helpful? Give feedback.
All reactions