Entities List

// Holds and maintains entities in data oriented order. Memory is allocated in blocks. Blocksize and 
// block increment is settable in the scene or overlay. Majority of entities should be contained in 
// a single block while larger outlier entities can be contained across multiple blocks. Increment
// is the number blocks to allocate each time the entity list needs to expand. Increment doubles each 
// expansion. Metrics are output when the engine is closed.
class RVAPI Entities
{
public:
    // Check if entity referenced by [entkey] exists.
    bool Exists(EntKey entKey) const;

    // Get entity using [entKey].
    Entity &operator [] (EntKey entKey) const;

    // Add entity to list and return entity memory. Usage: new (entities.Add<Type>()) Type(). [entity] is entity to
    // add. [type] is caller defined type id. [entKey] receives the the new entity's entity key if non-zero 
    // pointer. [supEnt] is a pointer to a super entity or 0. If provided, this entity will become a sub entity 
    // of the super entity.
    template<typename K>
    void *Add(uint type = 0, EntKey *entKey = 0, Entity *supEnt = 0) { return Add_(sizeof(K), type, entKey, supEnt); }

    // Destroy entity referenced by [entKey].
    void DestroyEntity(EntKey entKey);

    // Internal.
    void *operator () () const { return (void *)wobj; }

    // Constructor.
    Entities(void *wobj) : wobj(wobj) {}

    // Destructor.
    ~Entities() {}

private:
    void *wobj;

    void *Add_(uint size, uint type = 0, EntKey *entKey = 0, Entity *supEnt = 0);
};