Design question

78 views
Skip to first unread message

Joaquin Bello

unread,
Feb 23, 2014, 7:49:10 PM2/23/14
to ash-fr...@googlegroups.com
Hi I start learning Ash yesterday, I been playing with the Asteroid example, and I decided the best way to learn was to change the example to use Nape as an Collision Engine. So I made a NapeBody component, a NapeBodyNode and a NapeSystem, it was simple and fast, things were colliding using nape in no time. The NapeBodyNode has NapeBody, Position and Motion, NapeSystem sets the velocity and angularVelocity of the nodes, then simulates the system(space.step) and then I update the positions to set the new value of the Bodys. This was awesome!! I didn't had to change the rest of the systems and I had working Input and Render without modifying anything, because I was still using Position and Motion. The problem is that because I still use them, the MovementSystem was still using them. MovementSystem does two things, adds the dxy (velocity) to the position, and wraps objects around the screen. Its not nice, but its not a big problem that MovementSystem creates the node, because I override the value of the position in NapeSystem. I can't and I don't want to modify position because Render system use it and i can't modify motion because Input use it.

What I cant help thinking is what I'm gaining from using the "auto node feed" of the systems vs adding the entities(the nodes) to the systems. The obvious reason is that you don't have to manually link them, but at the same time you have to know all the nodes when programming because if you add some combination of components to an entity you might create a node that will be consumed by a system. If I don't use the "auto feed" I have more freedom to reuse components and mix them to reuse systems . The solution now I think is to create more specific components to avoid node creations, but I don't think that's a good solution because you indirectly create a dependency between components and systems. 

Again I started learning yesterday so I might be horribly wrong about how to use Entity Systems or Ash =P

Thanks
Joaquin

James Wrightson

unread,
Feb 24, 2014, 4:13:57 AM2/24/14
to ash-fr...@googlegroups.com
A good practice with components is to keep them separate from everything else, you could run into issues later if you don't.

When you decided to link an entity to the NapeSystem, you are deciding to apply a different set of movement integration
compared to the standard MotionSystem. I would ensure your space ship uses one or the other, as although your nape system overwrites 
the location, there is still an update that will produce different results ie:

MotionSystem:
new x = 10
new y = 11
...

{some event fires here that accesses the x,y values}
...

NapeSystem:
new x = 15
new y = 11
...

Depending on what is going on, what add/remove events, you could find your self with some nasty motion bugs :)

I would simply not add the MotionSystem to the engine, and let your NapeSystem deal with it instead. That to me
is the most simplistic solution. It is very rare to require multiple motion integrators anyway...

- Hope it helps

Joaquin Bello

unread,
Feb 24, 2014, 12:11:50 PM2/24/14
to ash-fr...@googlegroups.com
Thank you James for your answer. 
What I did was to add another dummy component call SimpleMove and required that to use MovementSystem , because you may still want objects that move but don't collide or you may want to add change by steps(I was still using simple move for bullets). Now the problem of detecting collisions =)

I still think the auto node fetch by the systems its not a good thing, in this test it was easy to spot the error but in a more complex game this could became a nightmare. You can debug a system but is almost impossible to debug the behavior of an entity, to that you add the complexity of not knowing who is processing the components.  

I know that in 99.9% of games you will find a simple solution by adding a specific component to avoid consumption by a system, and I know that the same asteroid game made with gameObjects(OO) would have been a lot more hard to modify.

Again thank you for your quick answer
Reply all
Reply to author
Forward
0 new messages