Epic Quest Land  Enties

An entity is anything (well, any subclass of entity_interface that has position/velocity/acceleration and that can be drawn to a RenderTarget.

  • entity_interface is a completely abstract class that just defines the interface entities must have

  • entity is the normal base class for entities: this implements an entity that saves its position and uses a semi-implicit Euler numerical integration scheme to update it from velocity and acceleration.

  • visual_entity is the base class for visual entities (see below). This replaces the numerical integration with an exact analytical solution, assuming constant acceleration, and also handles killing the entity when it moves off screen.

Note that for all entities, their positions are always in world coordinates. (Even for chunk-attached entities, their positions are relative to the world, and not to the chunk origin.)

Internally, entities are stored in several different places:

  • Spatial entities are those attached to chunks. The chunk manages their lifetime, and they are processed as part of the chunk. Most active "things" that live in the world and need to interact with other entities are spatial, as this allows us to cut down on the amount of processing (by only processing those chunks that are in range, and that have some entities in them). The chunkmap system automatically moves entities from one chunk to another when necessary. Spatial entities participate in the normal physics update cycle.

  • Special entities are attached to the game mode; they are processed and rendered always, regardless of whether they are visible or in-range. These entities must manage their own lifetimes, by setting their dead() flag when they are ready to be deleted. This is typically used for boss creatures and the like, but also for the player. Special entities participate in the normal physics update cycle.

  • Visual entities are those that represent purely visual effects. They are attached to the game mode, and automatically destroyed when the move a certain distance outside the screen. Visual entities have their update step run at a lower precision than non-visual entities, and they are not processed for collision detection or things like that.

For processing entities, we use entity_list and entity_multilists. An entity_list is just a std::list of entity_interface* with a few extra methods to make it easy to process the entities in it. An entity_multilist is a list of entity lists, that can be iterated over as if it was a single large list. We collect all the chunks that should be processed, along with the list of special entities, into a single multilist and then run the various entity events on that.