Create a new entity
| 37 | |
| 38 | // Create a new entity |
| 39 | Entity EntityManager::createEntity() { |
| 40 | |
| 41 | uint32 index; |
| 42 | |
| 43 | // If there are already enough free indices to start using them |
| 44 | if (mFreeIndices.size() > Entity::MINIMUM_FREE_INDICES) { |
| 45 | |
| 46 | // Recycle an index from the free indices |
| 47 | index = mFreeIndices.getFront(); |
| 48 | mFreeIndices.popFront(); |
| 49 | } |
| 50 | else { |
| 51 | |
| 52 | // We start at generation 0 |
| 53 | mGenerations.add(0); |
| 54 | |
| 55 | // Create a new indice |
| 56 | index = static_cast<uint32>(mGenerations.size()) - 1; |
| 57 | |
| 58 | assert(index < (uint32(1) << Entity::ENTITY_INDEX_BITS)); |
| 59 | } |
| 60 | |
| 61 | // Return a new entity |
| 62 | return Entity(index, mGenerations[index]); |
| 63 | } |
| 64 | |
| 65 | // Destroy an entity |
| 66 | void EntityManager::destroyEntity(Entity entity) { |
no test coverage detected