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:
- Loading a file into memory.
- Creating a tree of entities.
- 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?