1
\$\begingroup\$

In a game engine I'm working on, I'm using scenes similar to what you would find in Unity. The entities, in my game, are composed of reusable components and custom data which is linked to those components. Entities have children, and one parent. This is shown, below:

class Entity {
    ...custom data here...
    let parent : Component
    var children : [Component] = []
    var components : [Component] = []

    ...methods...
}

If the entities did not have custom data, then creating a scene would be described by the following steps:

  1. Loading a file into memory.
  2. Creating a tree of entities.
  3. Adding components to them, with parameters listed in the file.

However, this does not leave room for custom data. My other alternative is to create a scene by creating a scene object, then hard-coding the entities in. It would look something a bit like this:

var opening_scene = Scene()

opening_scene.addEntity(Player()) 
opening_scene.addEntity(Car()) 
opening_scene.addEntity(Terrain())
...

The downside to this is that everything is hard coded. What can I do to create scenes in a game more efficiently?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Game Coding Complete book addressing exactly this problem,where the engine architecture is entity component data driven,so in chapter 6 "Game Actors and Component Architecture" where here "Actor" is the same as entity,the writer says:

"All actors are defined with an XML data file. This data file allows you to def component configuration and any default values for that component. Here’s s sample XML for an actor......Keep in mind that these actor XML files define the template for a type of actor, not specific actor instance. There can be many instances of this actor running around, each with completely different sets of data within their components. The XML file onl defines the definition. You can think of it as defining a class for this type of actor."

then he create a factory method to create all components at runtime , the book is full explanatory for all areas of game engine programming and it contains full engine source , and a game

\$\endgroup\$

You must log in to answer this question.