Entities - lede701/CPlusEngine GitHub Wiki

Entities

The primary object for the game engine is the Entity class. Everything that runs through the game engine is some form of an Entity.

Public Parameters

  • Ptr - Type definition for a unique pointer
  • SPtr - Type definition for a shared pointer
  • Component - Type definition for the interface component class
  • CmpData - Type definition for the map data structure for components

Private Parameters

  • _childen - A vector data structure that stores all the entities parented to this entity. If that isn't confusing then I don't know what is today. Another way of thinking of it is this data structure allows the entities to be group together and act as one entity. For example if you have a car and want to have a body, 4 wheels, and a driver you could create the body and then parent all the tires and driver to the body. When you move the body all the children will move making it easier to manage large groups of entities.
  • _component - Data structure to manage all the components attached to this entity.
  • _id - Entity unique identifier that gets assigned when the entity factory creates any new entities.
  • _layer - Not sure why this was added but will do some research into the parameter and see if it is still needed.
  • _nextComponentId - Used when adding a new component to the entity.
  • _maxComponentId - The last component ID in the current component list.
  • _active - A boolean value that denotes if the object needs to be track in the game engine or is it turned off. This typically will get set because of something happening in the game engine that needs to destroy the entity and moves it to the destruction pile.
  • _parent - The parent entity that is used in calculating the current world position.
  • _transform - Shared pointer to a transformation object. This is where all changes to an entity happen.

Public Methods

  • Entity(uint id, uint layer = 10) - Main constructor of the Entity class. When creating a new class based on the entity class make sure to pass through the entities factory ID.
  • ~Entity() - This is the default destructor method.
  • Id() - Returns the entities current ID.
  • Layer() - Returns the current defined layer the entity resides on. Mostly used for 2D based games to allow adding object to different render layers.
  • Add(Ptr child) - Add children entities to the current entity. For example adding a wheel to the car's body.
  • Add(Component component) - Adds a component to the entity list of components to manage.
  • Remove(Ptr child) - Remove a child from the list of children.
  • Parent() - Returns the current defined parent of the current Entity.
  • Children() - Return a list of all children parented to the current Entity.
  • DebugChildren() - Used in debugging and sending basic information of all the children parented to the current Entity. You will need to have a console open to see the messages.
  • IsActive() - Returns the Boolean value True for active and False for inactive.
  • SetActive(bool active) - Allows the game logic the ability to set objects active and inactive.
  • NextComponentId() - Returns the next available ComponentId. Used when building components for an Entity.
  • Components() - Returns the list of components that is stored in the current entity.
  • Draw(Context context) - Called during the drawing phase of the game engine. The entity is passed the current context object. See the context definition for more information of what is included in the context object.
  • Update(deltaTime) - The update method is called during each step of the game engine simulation.
  • Transform() - Provides access to the transformation object. This object only stores the raw entity transformations and should not be used to move entities around in the game world!
  • Position() - Provides the current object x,y position in the game world in relation to the entities parent.
  • Rotation() - Provides the current objects rotation in the game world based on the parent rotation.
  • Scale() - Provides the current scale of the entity based on the parent scale.

Private Methods

None have been defined for this core class