bool MapModuleNoticeContainer::oldLoad( int fd, uint32 totalLength, uint32 nbrMaps) { mc2dbg << "[MMNC]: Using old type of index.db!" << endl; vector<MapModuleNotice*> notices; { errno = 0; DataBuffer dataBuffer(totalLength); if (! Utility::read( fd, dataBuffer.getBufferAddress(), totalLength) ) { mc2log << error << "[MMNC]::oldLoad - error reading index : " << strerror(errno) << ", totalLength = " << totalLength << endl; return false; } else { for (uint32 i=0; i<nbrMaps; i++) { MapModuleNotice *tmpMN = new MapModuleNotice(&dataBuffer); mc2dbg4 << "MapNotice for map with ID=" << tmpMN->getMapID() << ", country=" << StringTable::getString( StringTable::getCountryStringCode( tmpMN->getCountryCode()), StringTable::SWEDISH) << endl; mc2dbg4 << "MapModuleNotice with mapID = " << tmpMN->getMapID() << " loaded." << endl; notices.push_back(tmpMN); #if 0 if ( MapBits::isCountryMap(tmpMN->getMapID()) ) { notices.push_back(new MapModuleNotice( MapBits::countryToOverview(tmpMN->getMapID()))); } #endif } } } // Remove contents of container. deleteAllObjs(); // Fake regions. initUsingCC( notices ); return true; }
ServerWorldModel::~ServerWorldModel() { deleteAllObjs(); }
bool MapModuleNoticeContainer::load( DataBuffer& dataBuf, uint32 mapSet ) { dataBuf.readNextLong(); // old totalLength dataBuf.readNextLong(); // nbrMaps mc2dbg << "[MMNC]: Using new kind of index.db" << endl; // Format on disk begins with two 32-bit words with zeroes. // They should already have been read by load. // We should really implement version 0 here as well so that // we can remove the MapModuleObjVector. // Then comes length and version uint32 totalLength = dataBuf.readNextLong(); // length uint32 version = dataBuf.readNextLong(); uint32 nbrItems = dataBuf.readNextLong(); if (dataBuf.getNbrBytesLeft() == 0) { // we must have some bytes left // TODO: check if nbr bytes left is at least // = length * something... return false; } // Reset the internal structs. deleteAllObjs(); // Version should only be 1 now. for ( uint32 i = 0; i < nbrItems; ++i ) { MapModuleNotice* notice = new MapModuleNotice( &dataBuf, version, mapSet ); // Add the notice to the appropriate vectors and maps. addNotice( notice ); mc2dbg << "[MMNC]: Added MapModuleNotice for " << notice->getMapName() << endl; } // Read the map hierarchy m_mapTree.load( &dataBuf, mapSet ); // Read the regions int nbrRegions = dataBuf.readNextLong(); m_regions.clear(); mc2dbg << "[MMNC]: Number of top regions:" << nbrRegions << endl; for ( int i = 0; i < nbrRegions; ++i ) { MapTopRegion* region = new MapTopRegion(); region->load( &dataBuf, mapSet ); m_regions[ region->getID() ] = region; const char* name = region->getName( LangTypes::english ); if ( name == NULL ) { name = "NULL"; } mc2dbg << "[MMNC]: Added Top Region ID:" << region->getID() << " name: " << name << endl; } // Read the region hierarchy m_regionTree.load( &dataBuf ); // Read map supplier coverage data. mc2dbg8 << "Curr offset: " << dataBuf.getCurrentOffset() << " total length " << totalLength << endl; if (dataBuf.getCurrentOffset() < totalLength+12 ){ mc2dbg << "[MMNC]: Loading map supplier coverage." << endl; loadMapSupCoverage( &dataBuf ); mc2dbg << "[MMNC]: Done loading map supplier coverage." << endl; } else { mc2dbg << "[MMNC]: Not loading map supplier coverage." << endl; } #ifdef DEBUG_LEVEL_1 // // debug // for(uint32 i = 0; i < m_allNotices.size(); ++i ) { mc2dbg << "Overview maps for " << m_allNotices[i]->getMapID() << endl; vector<uint32> overviewIDs; m_mapTree.getOverviewMapsFor(m_allNotices[i]->getMapID(), overviewIDs); for(uint32 j = 0; j < overviewIDs.size(); ++j ) { mc2dbg << " " << j << "=" << overviewIDs[j] << endl; } } { // Print stuff mc2dbg << "MAP_HIERARCHY" << endl; set<uint32> mapIDs; m_mapTree.getTopLevelMapIDs(mapIDs); for(set<uint32>::const_iterator it = mapIDs.begin(); it != mapIDs.end(); ++it) { mc2dbg << "TopLevelMap :" << hex << *it << dec << " contains " << endl; set<IDPair_t> items; m_mapTree.getContents(*it, items); for( set<IDPair_t>::iterator it = items.begin(); it != items.end(); ++it ) { mc2dbg << " " << it->getMapID() << ":" << hex << it->getItemID() << dec << endl; } } } // Print stuff mc2dbg << "REGION_HIERARCHY" << endl; set<uint32> mapIDs; m_regionTree.getTopLevelRegionIDs(mapIDs); for(set<uint32>::const_iterator it = mapIDs.begin(); it != mapIDs.end(); ++it) { mc2dbg << "TopLevelRegion : " << getRegion( *it )->getNames() ->getBestName( LangTypes::swedish )->getName() << " " << *it << endl; const ItemIDTree& idTree = getRegion( *it )->getItemIDTree(); set<uint32> mapIDs; mc2dbg << " consists of the following items:" << endl; idTree.getTopLevelMapIDs( mapIDs ); for ( set<uint32>::const_iterator jt = mapIDs.begin(); jt != mapIDs.end(); ++jt ) { mc2dbg << " map id = " << *jt << endl; set<IDPair_t> items; idTree.getContents( *jt, items ); for ( set<IDPair_t>::const_iterator kt = items.begin(); kt != items.end(); ++kt ) { mc2dbg << " [" << kt->first << ", " << kt->second << "]" << endl; } } mc2dbg << " contains the following other regions: " << endl; set<uint32> items; m_regionTree.getContents(*it, items); for( set<uint32>::iterator jt = items.begin(); jt != items.end(); ++jt ) { mc2dbg << " " << *jt << endl; } } // // end debug // #endif // DEBUG_LEVEL_1 return true; }
MapModuleNoticeContainer::~MapModuleNoticeContainer() { deleteAllObjs(); }