ReactPhysics3D  v0.10.2
C++ Physics engine library
Loading...
Searching...
No Matches
reactphysics3d::Entity Struct Reference

This class is used to identify an entity in the Entity-Component-System. More...

#include <include/reactphysics3d/engine/Entity.h>

Public Member Functions

 Entity (uint32 index, uint32 generation)
 Constructor.
 
uint32 getIndex () const
 Return the lookup index of the entity in a array.
 
uint32 getGeneration () const
 Return the generation number of the entity.
 
bool operator== (const Entity &entity) const
 Equality operator.
 
bool operator!= (const Entity &entity) const
 Inequality operator.
 

Public Attributes

uint32 id
 Id of the entity.
 

Detailed Description

This class is used to identify an entity in the Entity-Component-System.

Entities are used for bodies in the physics engine. The id of an entity is a 32 bits integer that is separated in two parts. The index and the generation parts. The idea is that the index part directly gives us the index of the entity in a lookup array. However, we want to support deletion of the entities. That's why we have the generation part. This number is used to distinguish the entities created at the same index in the array. If it is the case, we will increase the generation number each time.

We use 24 bits for the index. Therefore, we support 16 millions simultaneous entries. We use 8 bits for the generation. Therefore, we support 256 entries created at the same index. To prevent reaching the 256 entries too fast, we make sure that we do not reuse the same index slot too ofen. To do that, we put recycled indices in a queue and only reuse values from that queue when it contains at least MINIMUM_FREE_INDICES values. It means, an id will reappear until its index has run 256 laps through the queue. It means that we must create and destroy at least 256 * MINIMUM_FREE_INDICES entities until an id can reappear. This seems reasonably safe.

This implementation is based on the following article: http://bitsquid.blogspot.com/2014/08/building-data-oriented-entity-system.html


The documentation for this struct was generated from the following files: