Exemple #1
0
    const NameCollection CoordModelMapping::getFilenamesForCoordinate(unsigned int pMapId, int xPos, int yPos)
    {
        NameCollection result;
        Array<std::string> rawNames;

        CMappingEntry *entry = getCMappingEntry(CMappingEntry::getKeyString(pMapId, xPos, yPos));
        if(entry != 0)
        {
            rawNames = entry->getFilenames();

            int pos = 0;
            while(pos < rawNames.size())
            {
                char namebuffer[500];
                int noVerc;
                int startName = findPosChar(rawNames[pos].c_str(), ' ', 1) + 1;
                int endName = (int) rawNames[pos].length();
                sscanf(rawNames[pos].c_str(), "%d", &noVerc);
                memcpy(namebuffer, &rawNames[pos].c_str()[startName], endName-startName);
                namebuffer[endName-startName]  = 0;
                sscanf(rawNames[pos].c_str(), "%d", &noVerc);
                std::string modelPosFileName = std::string(namebuffer);
                if(noVerc > MIN_VERTICES_FOR_OWN_CONTAINER_FILE)
                {
                    result.appendToSingle(modelPosFileName);
                }
                else
                {
                    result.appendToMain(modelPosFileName);
                }
                ++pos;
            }
        }
        return result;
    }
NameCollection::NameCollection(const NameCollection& other)
{
   reserve( other.size() );
   for( const_iterator it = other.begin();
        it != other.end();
        ++it ) {
      push_back( new Name(**it) );
   }
}
void 
MapModuleNoticeContainer::loadMapSupCoverage( DataBuffer* db ){
   MC2_ASSERT(db != NULL);

   // Read number of elements
   uint32 nbrElements = db->readNextLong();
   
   for (uint32 i=0; i<nbrElements; i++){

      // Read bounding box
      uint32 maxLat = db->readNextLong();
      uint32 minLat = db->readNextLong();
      uint32 maxLon = db->readNextLong();
      uint32 minLon = db->readNextLong();
      MC2BoundingBox bBox;
      bBox.setMaxLat(maxLat);
      bBox.setMinLat(minLat);
      bBox.setMaxLon(maxLon);
      bBox.setMinLon(minLon);

      // Read supplier name.
      MapGenEnums::mapSupplier mapSupplier = 
         static_cast<MapGenEnums::mapSupplier>(db->readNextLong());
      m_mapSupCoverage.push_back(make_pair(bBox, mapSupplier));
   }
   mc2dbg << "[MMNC]: Loaded " << m_mapSupCoverage.size() 
          << " map supplier coverage bounding boxes." << endl;


   // Read coverage tree.
   nbrElements = db->readNextLong();

   m_mapSupCoverageTree.reserve(nbrElements);   
   for (uint32 i=0; i<nbrElements; i++){   
      uint32 parent =  db->readNextLong();
      uint32 child =  db->readNextLong();

      m_mapSupCoverageTree.push_back(make_pair(parent, child));
   }
   MC2_ASSERT(m_mapSupCoverageTree.size() == nbrElements);

   // Load map supplier names.
   uint32 nbrToRead = db->readNextLong();
   for (uint32 i=0; i<nbrToRead; i++){
      NameCollection tmpNames;
      MapGenEnums::mapSupplier mapSup = 
         static_cast<MapGenEnums::mapSupplier>(db->readNextLong());
      tmpNames.load(db);
      m_mapSupNamesByMapSup.insert(make_pair(mapSup, tmpNames));
   }
   mc2dbg << "[MMNC]: Loaded " << m_mapSupNamesByMapSup.size() 
          << " map supplier names." << endl;

} // MapModuleNoticeContainer::loadMapSupCoverage
Exemple #4
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);
				}
bool
XMLIndata::parseName( const DOMNode* name,
                      NameCollection& names ) 
{
   if ( XMLString::equals( name->getNodeName(), "name" ) ) {
      
      // Get attributes
      DOMNamedNodeMap* attributes = name->getAttributes();

      LangTypes::language_t lang;
      ItemTypes::name_t nameType;
      
      // Note that language attribute is #REQUIRED.
      DOMNode* attribute = 
         attributes->getNamedItem( X( "language" ) );
      MC2_ASSERT( attribute != NULL );
      MC2String langStr = 
         XMLUtility::transcodefromucs(attribute->getNodeValue() );
      // Replace any occurance of '_' with space.
      for (MC2String::iterator strIt = langStr.begin();
           strIt != langStr.end(); ++strIt){
         if ( *strIt == '_' ){
            *strIt = ' ';
         }
      }

      lang = LangTypes::getStringAsLanguage( langStr.c_str(), true );
      if ( lang == LangTypes::invalidLanguage ){
         mc2log << error << "Could not interpret language code of string"
                << endl;
         MC2_ASSERT(false);
      }

      // Note that type attribute is always present.
      attribute = 
         attributes->getNamedItem( X( "type" ) );
      MC2_ASSERT( attribute != NULL );
      const char* tmpStr = XMLUtility::transcodefromucs(
            attribute->getNodeValue() );
      nameType = ItemTypes::getStringAsNameType( tmpStr );
      delete [] tmpStr;

      // Get the name.
      tmpStr = XMLUtility::getChildTextValue( name );
      
      // Add name
      Name* tmpName = new Name( tmpStr, lang, nameType );
      names.addName( tmpName );
      mc2dbg << "Added name: " << (*tmpName) << endl;
      mc2dbg8 << "All names: " << names << endl;
      delete tmpStr;

      return true;
   } else {
      // Not a name node.
      mc2log << warn 
             << "XMLIndata::parseName:"
             << " not a name node."
             << name->getNodeName() << endl;
      return false;
   }
}