bool ComponentManager<T>::RemoveInstance(Instance i)
{
    bool result = false;

    // Keep data array tightly packed by swapping last element
    // with element we want to remove and reducing the number
    // of active instances.
    const int index = i.index;
    const unsigned int lastIndex = GetNumInstances() - 1;

    // Make sure we are trying to delete a valid instance
    if (index < GetNumInstances() && index >= 0)
    {
        // Get the entity at the index to destroy
        Entity entityToDestroy = m_data.entity[index];
        // Get the entity at the end of the array
        Entity lastEntity = m_data.entity[lastIndex];

        // Update the references of the deleted component
        OnAddressChange(index, -1);
        // Update the references of the moved component
        OnAddressChange(lastIndex, index);

        // Move last entity's data
        m_data.entity[index] = m_data.entity[lastIndex];
        m_data.component[index] = m_data.component[lastIndex];

        // Update map entry for the swapped entity
        m_map[lastEntity.id] = index;
        // Remove the map entry for the destroyed entity
        m_map.erase(entityToDestroy.id);

        // Destroy component at end of array
        m_data.entity.pop_back();
        m_data.component.pop_back();

        result = true;
    }

    return result;
}
Example #2
0
void SkpModel::print_all_counts(){
	
	std::cout << "Definitions: " << GetNumDefinitions() << "\n";
	std::cout << "Instances: "   << GetNumInstances()   << "\n";
	std::cout << "Groups: "      << GetNumGroups()      << "\n";
	std::cout << "Faces: "       << GetNumFaces()       << "\n";
	std::cout << "Images: "      << GetNumImages()      << "\n";
	std::cout << "Edges: "       << GetNumEdges()       << "\n";
	std::cout << "Guides: "      << GetNumGuides()      << "\n";
	std::cout << "Curves: "      << GetNumCurves()      << "\n";

}
Entity ComponentManager<T>::GetEntityForInstance(Instance i) const
{
    Entity e;

    const int index = i.index;

    if (index < GetNumInstances() && index >= 0)
    {
        e = m_data.entity[index];
    }

    return e;
}
Example #4
0
 /// \brief
 ///   Removes all instances
 inline void                  RemoveAllInstances()                    { int n=GetNumInstances(); for(int i=0; i<n; ++i) delete m_instances[i]; m_instances.RemoveAll(); }
Example #5
0
 /// \brief
 ///   Creates a new instance and returns a reference to it (same as implicitly adding a new instance)
 ///
 /// \param i
 ///   Instantiable object to create instance for
 ///
 /// \return
 ///   Reference to newly added instance
 inline VGInstance&           CreateInstance(const VGInstantiable& i) { m_instances.Add(new VGInstance(i)); return GetInstance(GetNumInstances()-1); }
void CSysClass::Dump(FILE* stream)
{
	fprintf(stream, "%03d %c %-20s instances: %d\n", m_ID, m_Persistent?'p':' ', m_Name.c_str(), GetNumInstances());
}