Commit 5c5b9ac2 authored by Anakin's avatar Anakin

don't copy the model list. It can be very big - using pointer now,

garbage is not from the texture or object changes
parent e1e8e165
......@@ -45,7 +45,7 @@ public:
private:
std::vector<Modl*> vModls;
std::vector<Modl*>* vModls;
std::fstream fsMesh;
std::vector<std::string> vTextures;
......@@ -63,7 +63,7 @@ private:
public:
std::vector<Modl*> getModels() const;
std::vector<Modl*>* getModels() const;
std::vector<std::string> getTextureList() const;
};
......@@ -70,7 +70,7 @@ private:
// ========================================
// data
std::vector<Modl*> vModels;
std::vector<Modl*>* vModels = NULL;
std::vector<textureData*> vTextures;
// transformation =========================
......
......@@ -10,6 +10,8 @@
Object::Object(const char* path)
{
vModls = new std::vector<Modl*>;
// open file
fsMesh.open(path, std::ios::in | std::ios::binary);
......@@ -65,9 +67,6 @@ Object::~Object()
{
// clear texture list
vTextures.clear();
// clear Model list (don't delete the elements)
vModls.clear();
}
......@@ -177,7 +176,7 @@ void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
}
// save Model data
vModls.push_back(tempModl);
vModls->push_back(tempModl);
continue;
}
......@@ -593,7 +592,7 @@ void Object::readUV(Segment* dataDestination, std::streampos position)
/////////////////////////////////////////////////////////////////////////
// public getter
std::vector<Modl*> Object::getModels() const
std::vector<Modl*>* Object::getModels() const
{
return vModls;
}
......
......@@ -109,37 +109,42 @@ void OpenGLController::processInit()
void OpenGLController::deleteVectors()
{
while (!vModels.empty())
if (vModels != NULL)
{
Modl* cursor = vModels.back();
vModels.pop_back();
while (!cursor->segmLst.empty())
while (!vModels->empty())
{
Segment* segmCuror = cursor->segmLst.back();
cursor->segmLst.pop_back();
delete segmCuror->uv;
delete segmCuror->vertex;
Modl* cursor = vModels->back();
vModels->pop_back();
while (!segmCuror->meshIndices.empty())
while (!cursor->segmLst.empty())
{
std::vector<std::uint32_t>* meshCursor = segmCuror->meshIndices.back();
meshCursor->clear();
segmCuror->meshIndices.pop_back();
delete meshCursor;
Segment* segmCuror = cursor->segmLst.back();
cursor->segmLst.pop_back();
delete segmCuror->uv;
delete segmCuror->vertex;
while (!segmCuror->meshIndices.empty())
{
std::vector<std::uint32_t>* meshCursor = segmCuror->meshIndices.back();
meshCursor->clear();
segmCuror->meshIndices.pop_back();
delete meshCursor;
}
delete segmCuror;
}
delete segmCuror;
delete cursor;
}
delete cursor;
delete vModels;
}
while (!vTextures.empty())
{
textureData* cursor = vTextures.back();
vTextures.pop_back();
cursor->data->clear();
delete cursor->data;
delete cursor;
}
......@@ -207,16 +212,16 @@ glm::mat4 OpenGLController::getModelMatrix(unsigned int index)
{
glm::mat4 tempParentMatrix = glm::mat4(1.0f);
for (unsigned int loop = 0; loop < vModels.size(); loop++)
for (unsigned int loop = 0; loop < vModels->size(); loop++)
{
if (!strcmp(vModels[index]->parent.c_str(), vModels[loop]->name.c_str()))
if (!strcmp(vModels->at(index)->parent.c_str(), vModels->at(loop)->name.c_str()))
{
tempParentMatrix = getModelMatrix(loop);
break;
}
}
return tempParentMatrix * vModels[index]->m4x4Translation;
return tempParentMatrix * vModels->at(index)->m4x4Translation;
}
glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
......@@ -311,16 +316,16 @@ void OpenGLController::updateScene()
int instanceOffset(0);
for (unsigned int modelIndex = 0; modelIndex < vModels.size(); modelIndex++)
for (unsigned int modelIndex = 0; modelIndex < vModels->size(); modelIndex++)
{
// skip null, bones, shadowMesh, hidden things (don't increase textrue index!!)
if (vModels[modelIndex]->type == null ||
vModels[modelIndex]->type == bone ||
vModels[modelIndex]->type == shadowMesh ||
vModels[modelIndex]->renderFlags == 1)
if (vModels->at(modelIndex)->type == null ||
vModels->at(modelIndex)->type == bone ||
vModels->at(modelIndex)->type == shadowMesh ||
vModels->at(modelIndex)->renderFlags == 1)
continue;
for (auto& segIt : vModels[modelIndex]->segmLst)
for (auto& segIt : vModels->at(modelIndex)->segmLst)
{
// give texture to the shader
std::uint32_t tempTexIndex = segIt->textureIndex >= vTextures.size() ? vTextures.size() - 1 : segIt->textureIndex;
......@@ -382,7 +387,7 @@ void OpenGLController::loadMsh(const char * path)
// collect vertex data of all models
std::vector<Vertex> tempBufferData;
for (auto& modIt : vModels) // for every model chunk
for (auto& modIt : *vModels) // for every model chunk
{
for (auto& segIt : modIt->segmLst) // for every cluster
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment