bool CProject::_loadTerrain(const string& filename) { CTextFile file; if (!file.Load(filename)) return false; string tok, tok2; int brace = 1, j, k; file.SetMark(); int i = file.GetInt(); tok = file.Token(); int frameCount = file.GetInt(); int imageCount = 0, idCount = 0; if (brace == 1 && frameCount) { if (m_waterListCount) { for (k = 0; k < m_waterListCount; k++) { DeleteArray(m_waterLists[k].textures); DeleteArray(m_waterLists[k].textureIDs); } DeleteArray(m_waterLists); } m_waterListCount = frameCount; m_waterLists = new WaterList[frameCount]; for (j = 0; j < frameCount; j++) { m_waterLists[j].frame = 0.0f; m_waterLists[j].textureCount = 0; m_waterLists[j].textureIDs = 0; m_waterLists[j].textures = 0; } imageCount = 0; } CFolderElement* folders[32]; CTerrainElement* terrain; folders[1] = m_terrainFolder; while (brace) { if (file.TokenType() == ETokenType::EndBlock || file.TokenType() == ETokenType::End) { brace--; if (brace > 0) { file.SetMark(); i = file.GetInt(); tok = file.Token(); frameCount = file.GetInt(); idCount = 0; if (frameCount) { if (brace == 1) { if (m_waterListCount) { for (k = 0; k < m_waterListCount; k++) { DeleteArray(m_waterLists[k].textures); DeleteArray(m_waterLists[k].textureIDs); } DeleteArray(m_waterLists); } m_waterListCount = frameCount; m_waterLists = new WaterList[frameCount]; for (j = 0; j < frameCount; j++) { m_waterLists[j].frame = 0.0f; m_waterLists[j].textureCount = 0; m_waterLists[j].textureIDs = 0; m_waterLists[j].textures = 0; } imageCount = 0; } else if (brace == 2) { m_waterLists[imageCount].name = tok; DeleteArray(m_waterLists[imageCount].textures); DeleteArray(m_waterLists[imageCount].textureIDs); m_waterLists[imageCount].textureCount = frameCount; m_waterLists[imageCount].textures = new CTexture*[frameCount]; m_waterLists[imageCount].textureIDs = new int[frameCount]; memset(m_waterLists[imageCount].textures, 0, sizeof(CTexture*) * frameCount); memset(m_waterLists[imageCount].textureIDs, 0, sizeof(int) * frameCount); imageCount++; } } } continue; } file.NextToken(); if (file.TokenType() == ETokenType::StartBlock) { brace++; file.SetMark(); i = file.GetInt(); tok2 = file.Token(); frameCount = file.GetInt(); if (i == 0 && brace == 2 && frameCount) { m_waterLists[imageCount].name = tok2; DeleteArray(m_waterLists[imageCount].textures); DeleteArray(m_waterLists[imageCount].textureIDs); m_waterLists[imageCount].textureCount = frameCount; m_waterLists[imageCount].textures = new CTexture*[frameCount]; m_waterLists[imageCount].textureIDs = new int[frameCount]; memset(m_waterLists[imageCount].textures, 0, sizeof(CTexture*) * frameCount); memset(m_waterLists[imageCount].textureIDs, 0, sizeof(int) * frameCount); imageCount++; } folders[brace] = new CFolderElement(); folders[brace]->setSelectable(false); folders[brace]->setIcon(m_icons[2]); if (brace == 3) folders[brace]->setText(m_waterLists[imageCount - 1].name); else folders[brace]->setText(tok); folders[brace - 1]->appendRow(folders[brace]); continue; } else { file.GoMark(); i = file.GetInt(); frameCount = file.GetInt(); if (brace == 3) { m_waterLists[imageCount - 1].textureIDs[idCount] = i; idCount++; } } m_terrains[i] = file.GetString(); file.NextToken(); file.NextToken(); terrain = new CTerrainElement(); terrain->setIcon(m_icons[4]); terrain->setText(m_terrains[i]); terrain->SetTerrain(i); folders[brace]->appendRow(terrain); file.SetMark(); i = file.GetInt(); } file.Close(); return true; }
bool CProject::_loadModel(const string& filename) { CTextFile file; if (!file.Load(filename)) return false; CFolderElement* folders[32]; CModelElement* model; ModelProp prop; byte type; int max, motion; string motionStr; file.NextToken(); while (file.TokenType() != ETokenType::End) { folders[1] = new CFolderElement(); folders[1]->setIcon(m_icons[1]); folders[1]->setText(file.Token()); m_objFolder->appendRow(folders[1]); type = (byte)file.GetInt(); file.NextToken(); // { file.NextToken(); // nom d'un objet ou } int brace = 1; while (brace) { if (file.TokenType() == ETokenType::EndBlock) { brace--; if (brace > 0) { file.NextToken(); // nom d'un objet ou } continue; } if (brace == 0) continue; } prop.filename = file.Token(); file.SetMark(); file.NextToken(); if (file.TokenType() == ETokenType::StartBlock) { brace++; folders[brace] = new CFolderElement(); folders[brace]->setIcon(m_icons[1]); folders[brace]->setText(prop.filename); folders[brace - 1]->appendRow(folders[brace]); file.NextToken(); // nom d'un objet ou } prop.filename = file.Token(); continue; } else file.GoMark(); prop.ID = file.GetInt(); prop.type = type; prop.modelType = (byte)file.GetInt(); prop.part = file.GetString(); prop.fly = file.GetBool(); prop.distant = (byte)file.GetInt(); prop.pick = file.GetBool(); prop.scale = file.GetFloat(); prop.trans = file.GetBool(); prop.shadow = file.GetBool(); prop.textureEx = (byte)file.GetInt(); prop.renderFlag = file.GetBool(); file.NextToken(); if (file.TokenType() == ETokenType::StartBlock) { file.SetMark(); file.NextToken(); max = 0; while (file.TokenType() != ETokenType::EndBlock) { motion = file.GetInt(); if (motion > max) max = motion; file.NextToken(); // nom d'une animation ou } } max++; prop.motionCount = max; file.GoMark(); file.NextToken(); // nom d'une animation ou } prop.motions = new char[max * 32]; memset(prop.motions, 0, max * 32); while (file.TokenType() != ETokenType::EndBlock) { motionStr = file.Token(); motion = file.GetInt(); file.NextToken(); // nom d'une animation ou } strcpy(prop.GetMotion(motion), motionStr.toLocal8Bit().constData()); } file.NextToken(); // nom d'un objet ou } } else { prop.motionCount = 0; prop.motions = null; } m_models[type][prop.ID] = prop; model = new CModelElement(); model->setIcon(m_icons[3]); if (type == OT_MOVER) { auto it = m_moverProps.constFind(prop.ID); if (it != m_moverProps.constEnd() && !(*it).name.isEmpty()) model->setText((*it).name); else model->setText(prop.filename); } else if (type == OT_ITEM) { auto it = m_itemProps.constFind(prop.ID); if (it != m_itemProps.constEnd() && !(*it).name.isEmpty()) model->setText((*it).name); else model->setText(prop.filename); } else model->setText(prop.filename); model->SetModel(&m_models[type][prop.ID]); folders[brace]->appendRow(model); } file.NextToken(); // type d'objet ou } } file.Close(); return true; }