Entity Component Model Collisions

Started by
4 comments, last by wqking 12 years, 9 months ago
Hello,

When using the Entity Component Model, what is generally accepted to be the best method for collision checks?

Does the Collision Component simply listen for collisions or does it actually check for collisions?
Advertisement
How about,

1, Entity provides the collision data (shape, etc), maybe via a component (collision data component),
2, A sub system, processes all collision data in each frame.
3, If any collision occurs, the sub system just emits an event.
4, Any interesting component subscribes to the events. An AI component of an enemy may want to know when the hero hits the ground, etc.

https://www.kbasm.com -- My personal website

https://github.com/wqking/eventpp  eventpp -- C++ library for event dispatcher and callback list

https://github.com/cpgf/cpgf  cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.

wqking,

Your proposal is similar to the architecture I decided to use last night. After doing some research I found this:

http://www.gamadu.com/artemis/

I really like the idea of every bit of ingame logic being a 'system'. However, I was still having issues figuring out where to generate events.

I guess having a global collision detection system would be the best way. Then, I would have to use a listener structure for collision events, like you sugguested.

An alternative of listener is that, register a component which is to response collision, such like a CollisionSolverComponent.
When collision occurs, the sub system just try to find if there is CollisionSolverComponent in the entity, if there is one, call special function on it.

This method is more coupled, but may (or may not) be more efficient than event dispatch.

Of course CollisionSolverComponent can listen to the events, then no need of the component look up.

https://www.kbasm.com -- My personal website

https://github.com/wqking/eventpp  eventpp -- C++ library for event dispatcher and callback list

https://github.com/cpgf/cpgf  cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.

OK, for the purposes of performance, I don't believe it's efficient to have each object have its own subsystem to check for collisions. This is because the world object list must be accessed multiple times and, due to the limitations of Java, I must create an array version of my list in order to use it and modify the object at the same time. Thus, I think the most elegant solution is probably a CollisionHandlerComponent like you suggested, and stick the CollisionGeneratorComponent into the WorldEntity.
"each object have its own subsystem" ?

I think you misunderstand about sub system.
A sub system is NOT for any single object, it's for the whole sub behavior, which may include a lot of entities or components.

For example, a game may have several sub systems, rendering sub system, resource management SS, physics and collision SS, etc.
If an entity needs to render itself, just provide data to rendering sub system.

So an entity, or an object, doesn't have any sub system. Sub system is in quite global and top level.

https://www.kbasm.com -- My personal website

https://github.com/wqking/eventpp  eventpp -- C++ library for event dispatcher and callback list

https://github.com/cpgf/cpgf  cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.

This topic is closed to new replies.

Advertisement