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