Page 1 of 1

Composition?

Posted: Fri Oct 28, 2011 5:05 am
by GroundUpEngine
So I've changed my entity system in my engine, but it is still inheritance based and I feel it could get bloated in the future. I want to aggregate my inheritance stuff into components, since most of the code does the job ;)

My current method:
  • I want to make a new object type e.g. Plane
    I have to make a plane class which would inherit the entity class
    Then add all the necessary stuff
    Then my scene manager can make a new plane
Structure:
Entity
- Plane

But with composition:
  • I want to make a new object type e.g. Plane
    My scene manager can make a new plane, by adding a new entity
    Then add all the necessary components e.g. render, physics
Structure:
Entity
Component
- Render component
- Physics component
- Script component


Am I going about this the right way?

Re: Composition?

Posted: Fri Oct 28, 2011 7:35 am
by szdarkhack
Pretty much, yes. The general idea is that if you want to make, say, a plane, you just make a new entity, add the components necessary and add it to the scene. Of course there is nothing stopping you from automating the creation, although since the main point of using a component system is flexibility, i would advice against hardcoding it. Perhaps, for example, you can read what components to attach from a file describing your objects, or something similar.

Re: Composition?

Posted: Fri Oct 28, 2011 9:16 am
by Falco Girgis
Yeah, that's exactly right.

There's nothing stopping you from having a factory "assemble" a specific type of entity by automatically attaching components for you. That's essentially how saving/loading works. It lends itself extremely well to serialization/deserialization.

Re: Composition?

Posted: Fri Oct 28, 2011 11:57 am
by GroundUpEngine
szdarkhack wrote:Pretty much, yes. The general idea is that if you want to make, say, a plane, you just make a new entity, add the components necessary and add it to the scene. Of course there is nothing stopping you from automating the creation, although since the main point of using a component system is flexibility, i would advice against hardcoding it. Perhaps, for example, you can read what components to attach from a file describing your objects, or something similar.
Ok, good idea but I quite like the automated approach hehe. But I agree, things would be even more flexible with scripting the types.
GyroVorbis wrote:Yeah, that's exactly right.

There's nothing stopping you from having a factory "assemble" a specific type of entity by automatically attaching components for you. That's essentially how saving/loading works. It lends itself extremely well to serialization/deserialization.
Sweet, I choose that way because my entity types are pretty straight forward and I kept things simple.
Speaking of serialisation, I was considering a PAK file format for all the necessary resources needed. But I wasn't sure how it is done; reading in files and then concenate them into one file, or actually loading them into the engine (e.g. Texture("tex.jpg")) and then serialising the state of the object into a binary file?