4. Entities and components

The Bento game engine uses a component-based model (not the Entity-Component-System (ECS) model). Entities hold a number of components that are managed by a scene graph.

Inheritance vs composition

If you're used to inheritance and OOP, it may take a while to get used to component based programming. There's plenty of articles that go deeper into the inheritance vs composition model. Here is one interesting one about games: http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/

In Bento, entities are essentially nodes in a scene graph. The scene graph is not just for graphical purposes. Entities have an update and draw function. The Entity update and draw functions are not meant to be overwritten (as you would overwrite a virtual function in OOP), since Entity update and draw will call the children's update and draw. Instead, you are encouraged to attach a component that has an update and/or draw functions, if you want to write specific behaviors for the entity.

In summary, an Entity/components scene graph looks like this:

Illustration of the entity scene graph. An entity contains many components, but can also attach other entities.

The Bento modules are written as functions for simpler Entity initialization like this. But all Bento modules eventually call entity.attach(), which is the way to attach a child object to the entity. You may attach your own components, either as a Bento style module, or simply attach it right away: