Mechanism to elegantly cleanup components
See original GitHub issueUse case:
PhysicsComponent
contains a Box2D body. Every time either a component of this class is removed from an entity or the entity itself is removed from the engine, we need to callworld.destroyBody(component.body)
. It would be nice to have a mechanism to catch this event and act accordingly.
Options:
EntityListener
that processes entities in the family of entities with physics component that does the cleanup on entity removed from the family.- Make
ComponentListener
a public class and have something like this:
public interface ComponentListener {
public void componentAdded(Entity e, Component e);
public void componentRemoved(Entity e, Component e);
}
public class Engine {
public void addComponentListener(Class<? implements Component> componentClass, ComponentListener listener)
public void removeComponentListener(Class<? implements Component> componentClass, ComponentListener listener);
}
- Somehow reuse the
Entity
signaling system that already notifies engine of these events. Component
could implementDisposable
and theEngine
would calldispose()
if it implements the interface. Nasty because it adds logic to components.
What do you guys think would be best?
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Introducing cleanup components | Entities | 1.0.0-pre.15
Cleanup components are like regular components, but when you destroy an entity that contains one, Unity removes all non-cleanup components instead.
Read more >Against Cleaning - Debates in the Digital Humanities
In reality, data cleaning is a consequential step in the research process that we often ... However, the menus also express nonscalable elements—historical ......
Read more >Clean Code and the Art of Exception Handling - Toptal
In this article, we will discuss how to manage exceptions elegantly, ... specialized programming language constructs or computer hardware mechanisms.
Read more >3 Ways to Clean Up Components - Michael Thiessen
If you convert parts of your component to use computed props, it magically cleans up your code. Okay, it's not exactly magic. But...
Read more >What is the most innovative component or mechanism ... - Reddit
Watching the game rules and components evolve was a thrilling and ... their values signifying their move speed AND attack value is so...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would go for solution 2 for many reasons :
For now my workaround is to use PooledEngine and implements Poolable interface on my components which works but it doesn’t work with other engine implementation.
@saltares I think this topic should be reopened.
Since nothing really happened on this issue, I’ll just drop my solution here: https://gist.github.com/Desmaster/a05d669208a05f98e8074761af5aad98
Could be way more advanced, but it currently fits my needs.