Beispiel #1
0
    int VMapManager::loadMap(const char* pBasePath, unsigned int pMapId, int x, int y)
    {
		bool result = false;
		std::string dirFileName;
		if( pMapId >= MAX_MAPS )
			return false;

		if( IsTileMap( pMapId ) )
			dirFileName = getDirFileName( pMapId, x, y );
		else
			dirFileName = getDirFileName( pMapId );

		MapTree* instanceTree = m_maps[pMapId];
		if( instanceTree == NULL )
		{
			instanceTree = new MapTree( pBasePath );
			m_maps[pMapId] = instanceTree;
		}

		unsigned int mapTileIdent = MAP_TILE_IDENT(x,y);
		result = instanceTree->loadMap(dirFileName, mapTileIdent);
		if(!result)                                         // remove on fail
		{
			if(instanceTree->size() == 0)
			{
				m_maps[pMapId] = NULL;
				delete instanceTree;
			}
		}
		return(result);
    }
Beispiel #2
0
    bool VMapManager::_loadMap(const char* pBasePath, unsigned int pMapId, int x, int y, bool pForceTileLoad)
    {
        bool result = false;
        std::string dirFileName;
        if(pForceTileLoad || iMapsSplitIntoTiles.containsKey(pMapId))
        {
            dirFileName = getDirFileName(pMapId,x,y);
        }
        else
        {
            dirFileName = getDirFileName(pMapId);
        }
        MapTree* instanceTree;
        if(!iInstanceMapTrees.containsKey(pMapId))
        {
            instanceTree = new MapTree(pBasePath);
            iInstanceMapTrees.set(pMapId, instanceTree);
        }
        else
            instanceTree = iInstanceMapTrees.get(pMapId);

        unsigned int mapTileIdent = MAP_TILE_IDENT(x,y);
        result = instanceTree->loadMap(dirFileName, mapTileIdent);
        if(!result)                                         // remove on fail
        {
            if(instanceTree->size() == 0)
            {
                iInstanceMapTrees.remove(pMapId);
                delete instanceTree;
            }
        }
        return(result);
    }
Beispiel #3
0
 bool VMapManager::_existsMap(const std::string& pBasePath, unsigned int pMapId, int x, int y, bool pForceTileLoad)
 {
     bool result = false;
     std::string dirFileName;
     if(pForceTileLoad || iMapsSplitIntoTiles.containsKey(pMapId))
     {
         dirFileName = getDirFileName(pMapId,x,y);
     }
     else
     {
         dirFileName = getDirFileName(pMapId);
     }
     size_t len = pBasePath.length() + dirFileName.length();
     char *filenameBuffer = new char[len+1];
     sprintf(filenameBuffer, "%s%s", pBasePath.c_str(), dirFileName.c_str());
     FILE* df = fopen(filenameBuffer, "rb");
     if(df)
     {
         char lineBuffer[FILENAMEBUFFER_SIZE];
         if (fgets(lineBuffer, FILENAMEBUFFER_SIZE-1, df) != 0)
         {
             std::string name = std::string(lineBuffer);
             chomp(name);
             if(name.length() >1)
             {
                 sprintf(filenameBuffer, "%s%s", pBasePath.c_str(), name.c_str());
                 FILE* df2 = fopen(filenameBuffer, "rb");
                 if(df2)
                 {
                     char magic[8];
                     fread(magic,1,8,df2);
                     if(!strncmp(VMAP_MAGIC,magic,8))
                         result = true;
                     fclose(df2);
                 }
             }
         }
         fclose(df);
     }
     delete[] filenameBuffer;
     return result;
 }
Beispiel #4
0
    void VMapManager::unloadMap(unsigned int pMapId, int x, int y)
    {
		if( m_maps[pMapId] != NULL )
		{
			MapTree * instanceTree = m_maps[pMapId];
			std::string dirFileName;

			if( IsTileMap( pMapId ) )
				dirFileName = getDirFileName( pMapId, x, y );
			else
				dirFileName = getDirFileName( pMapId );

			unsigned int mapTileIdent = MAP_TILE_IDENT(x,y);
			instanceTree->unloadMap(dirFileName, mapTileIdent);
			if(instanceTree->size() == 0)
			{
				m_maps[ pMapId ] = NULL;
				delete instanceTree;
			}
		}
    }
Beispiel #5
0
 void VMapManager::_unloadMap(unsigned int  pMapId, int x, int y)
 {
     if(iInstanceMapTrees.containsKey(pMapId))
     {
         MapTree* instanceTree = iInstanceMapTrees.get(pMapId);
         std::string dirFileName;
         if(iMapsSplitIntoTiles.containsKey(pMapId))
         {
             dirFileName = getDirFileName(pMapId,x,y);
         }
         else
         {
             dirFileName = getDirFileName(pMapId);
         }
         unsigned int mapTileIdent = MAP_TILE_IDENT(x,y);
         instanceTree->unloadMap(dirFileName, mapTileIdent);
         if(instanceTree->size() == 0)
         {
             iInstanceMapTrees.remove(pMapId);
             delete instanceTree;
         }
     }
 }
Beispiel #6
0
    void VMapManager::unloadMap(unsigned int pMapId)
    {
		if( m_maps[pMapId] != NULL )
        {
            MapTree* instanceTree = m_maps[ pMapId ];
            std::string dirFileName = getDirFileName(pMapId);
            instanceTree->unloadMap(dirFileName, 0);
            if(instanceTree->size() == 0)
            {
				m_maps[pMapId]=NULL;
                delete instanceTree;
            }
        }
    }
Beispiel #7
0
 bool VMapManager::_existsMap(const std::string& pBasePath, unsigned int pMapId, int x, int y, bool pForceTileLoad)
 {
     bool result = false;
     std::string dirFileName;
     if(pForceTileLoad || iMapsSplitIntoTiles.containsKey(pMapId))
     {
         dirFileName = getDirFileName(pMapId,x,y);
     }
     else
     {
         dirFileName = getDirFileName(pMapId);
     }
     size_t len = pBasePath.length() + dirFileName.length();
     char *filenameBuffer = new char[len+1];
     sprintf(filenameBuffer, "%s%s", pBasePath.c_str(), dirFileName.c_str());
     FILE* df = fopen(filenameBuffer, "rb");
     if(df)
     {
         fclose(df);
         result = true;
     }
     delete[] filenameBuffer;
     return result;
 }
Beispiel #8
0
 void VMapManager::unloadMap(unsigned int pMapId)
 {
     if(iInstanceMapTrees.containsKey(pMapId))
     {
         MapTree* instanceTree = iInstanceMapTrees.get(pMapId);
         std::string dirFileName = getDirFileName(pMapId);
         instanceTree->unloadMap(dirFileName, 0, true);
         if(instanceTree->size() == 0)
         {
             iInstanceMapTrees.remove(pMapId);
             delete instanceTree;
         }
         Command c = Command();
         c.fillUnloadTileCmd(pMapId);
         iCommandLogger.appendCmd(c);
     }
 }