NameCollection::NameCollection(const NameCollection& other)
{
   reserve( other.size() );
   for( const_iterator it = other.begin();
        it != other.end();
        ++it ) {
      push_back( new Name(**it) );
   }
}
Beispiel #2
0
	//=================================================================
	bool TileAssembler::convertWorld()
	{
		#ifdef _ASSEMBLER_DEBUG
		#   ifdef _DEBUG
		::g_df = fopen("../TileAssembler_debug.txt", "wb");
		#   else
		::g_df = fopen("../TileAssembler_release.txt", "wb");
		#   endif
		#endif

		bool result = true;
		printf("Reading coordinate mappings...\n");
		std::string fname = iSrcDir;
		fname.append("/");
		fname.append("dir");
		iCoordModelMapping->setModelNameFilterMethod(iFilterMethod);
		iCoordModelMapping->readCoordinateMapping(fname);

		Array<unsigned int> mapIds = iCoordModelMapping->getMaps();
		if(mapIds.size() == 0)
		{
			result = false;
		}
		for(int i=0; i<mapIds.size() && result; ++i)
		{
			unsigned int mapId = mapIds[i];
			printf("Converting map %lu...\n", mapId);

			#ifdef _ASSEMBLER_DEBUG
			if(mapId == 0)								  // "Azeroth" just for debug
			{
				for(int x=28; x<29 && result; ++x)		  //debug
				{
					for(int y=28; y<29 && result; ++y)
					{
						#else
						// ignore DeeprunTram (369) it is too large for short vector and not important
						// ignore test (13), Test (29) , development (451)
						if(mapId != 369 && mapId != 13 && mapId != 29 && mapId != 451)
						{
							for(int x=0; x<66 && result; ++x)
							{
								for(int y=0; y<66 && result; ++y)
								{
									#endif
									printf("Converting cell [%lu][%lu] on map %lu...\n", x, y, mapId);
									Array<ModelContainer*> mc;
									std::string dirname;
									char buffer[100];
									if(iCoordModelMapping->isWorldAreaMap(mapId) && x<65 && y<65)
									{
										sprintf(buffer, "%03u_%d_%d",mapId,x,y); // Let's flip x and y here
										dirname = std::string(buffer);
									}
									else
									{
										sprintf(buffer, "%03u",mapId);
										dirname = std::string(buffer);
									}
									result = fillModelContainerArray(dirname, mapId, x, y, mc);
									emptyArray(mc);
								}
							}
						}
					}
					#ifdef _ASSEMBLER_DEBUG
					if(::g_df) fclose(::g_df);
					#endif

					return result;
				}

				//=================================================================

				bool TileAssembler::fillModelContainerArray(const std::string& pDirFileName, unsigned int pMapId, int pXPos, int pYPos, Array<ModelContainer*>& pMC)
				{
					bool result = true;
					ModelContainer* modelContainer;

					NameCollection nameCollection = iCoordModelMapping->getFilenamesForCoordinate(pMapId, pXPos, pYPos);
					if(nameCollection.size() > 0)
					{
						result = false;
						char dirfilename[500];
						sprintf(dirfilename,"%s/%s.vmdir",iDestDir.c_str(),pDirFileName.c_str());
						FILE *dirfile = fopen(dirfilename, "ab");
						if(dirfile)
						{
							result = true;
							char destnamebuffer[500];
							char fullnamedestnamebuffer[500];
							if(nameCollection.iMainFiles.size() >0)
							{
								sprintf(destnamebuffer,"%03u_%i_%i.vmap",pMapId, pXPos, pYPos); // flip it here too
								std::string checkDoubleStr = std::string(dirfilename);
								checkDoubleStr.append("##");
								checkDoubleStr.append(std::string(destnamebuffer));
								// Check, if same file already is in the same dir file
								if(!iCoordModelMapping->isAlreadyProcessedSingleFile(checkDoubleStr))
								{
									iCoordModelMapping->addAlreadyProcessedSingleFile(checkDoubleStr);
									fprintf(dirfile, "%s\n",destnamebuffer);
									sprintf(fullnamedestnamebuffer,"%s/%s",iDestDir.c_str(),destnamebuffer);
									modelContainer = processNames(nameCollection.iMainFiles, fullnamedestnamebuffer);
									if(modelContainer)
									{
										pMC.append(modelContainer);
									}
									else
									{
										result = false;
									}
								}
							}
							// process the large singe files
							int pos = 0;
							while(result && (pos < nameCollection.iSingeFiles.size()))
							{
								std::string destFileName = iDestDir;
								destFileName.append("/");
								std::string dirEntryName = getDirEntryNameFromModName(pMapId,nameCollection.iSingeFiles[pos]);
								std::string checkDoubleStr = std::string(dirfilename);
								checkDoubleStr.append("##");
								checkDoubleStr.append(nameCollection.iSingeFiles[pos]);
								// Check, if same file already is in the same dir file
								if(!iCoordModelMapping->isAlreadyProcessedSingleFile(checkDoubleStr))
								{
									iCoordModelMapping->addAlreadyProcessedSingleFile(checkDoubleStr);
									fprintf(dirfile, "%s\n",dirEntryName.c_str());
									destFileName.append(dirEntryName);

									Array<std::string> positionarray;
									positionarray.append(nameCollection.iSingeFiles[pos]);

									if(!iCoordModelMapping->isAlreadyProcessedSingleFile(nameCollection.iSingeFiles[pos]))
									{
										modelContainer = processNames(positionarray, destFileName.c_str());
										iCoordModelMapping->addAlreadyProcessedSingleFile(nameCollection.iSingeFiles[pos]);
										if(modelContainer)
										{
											pMC.append(modelContainer);
										}
										else
										{
											result = false;
										}
									}
								}
								++pos;
							}
							fclose(dirfile);
						}
					}
					return(result);
				}

				//=================================================================

				void removeEntriesFromTree(AABSPTree<SubModel *>* pTree)
				{
					Array<SubModel *> submodelArray;
					pTree->getMembers(submodelArray);
					int no = submodelArray.size();
					while(no > 0)
					{
						--no;
						delete submodelArray[no];
					}
				}

				//=================================================================

				ModelContainer* TileAssembler::processNames(const Array<std::string>& pPositions, const char* pDestFileName)
				{
					ModelContainer *modelContainer = 0;

					Vector3 basepos = Vector3(0,0,0);
					AABSPTree<SubModel *>* mainTree = new AABSPTree<SubModel *>();

					int pos = 0;

					bool result = true;
					while(result && (pos < pPositions.size()))
					{
						std::string modelPosString = pPositions[pos];
						std::string modelFileName = getModNameFromModPosName(modelPosString);

						if(!fillModelIntoTree(mainTree, basepos, modelPosString, modelFileName))
						{
							result = false;
							break;
						}
						++pos;
					}
					if(result && mainTree->size() > 0)
					{
						mainTree->balance();
						modelContainer = new ModelContainer(mainTree);
						modelContainer->writeFile(pDestFileName);
					}
					removeEntriesFromTree(mainTree);

					delete mainTree;

					return(modelContainer);
				}