void fileManager::writeDistBlock (const unsigned int blockID1, const unsigned int blockID2, const std::vector<std::vector<float> >& dBlock) const { if( dBlock.empty()){ std::cerr<< "ERROR @ fileManager::writeDistBlock(): block is empty, no file was written"<<std::endl; return; } std::string blockFilename = getBlockFilename( blockID1, blockID2 ); writeMatrix( blockFilename, VTFloat32, dBlock, m_zipFlag ); return; }// end fileManager::writeDistBlock() -----------------------------------------------------------------
void fileManager::readDistBlock (const unsigned int blockID1, const unsigned int blockID2, std::vector<std::vector<float> >* dBlockPointer ) const { std::string blockFilename = getBlockFilename(blockID1, blockID2); ValueType blockRepnType = readMatrix(blockFilename,dBlockPointer); if (blockRepnType==VTError) { throw std::runtime_error( "ERROR @ fileManager::readDistBlock(): there was an error when reading the distance block" ); } if (blockRepnType!=VTFloat32) { throw std::runtime_error( "ERROR @ fileManager::readDistBlock(): there was an error when reading the distance block" ); } return; }// end fileManager::readDistBlock() -----------------------------------------------------------------
void Database_SQLite3::saveBlock(MapBlock *block) { DSTACK(__FUNCTION_NAME); /* Dummy blocks are not written */ if(block->isDummy()) { /*v3s16 p = block->getPos(); infostream<<"Database_SQLite3::saveBlock(): WARNING: Not writing dummy block " <<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"<<std::endl;*/ return; } // Format used for writing u8 version = SER_FMT_VER_HIGHEST; // Get destination v3s16 p3d = block->getPos(); #if 0 v2s16 p2d(p3d.X, p3d.Z); std::string sectordir = getSectorDir(p2d); createDirs(sectordir); std::string fullpath = sectordir+DIR_DELIM+getBlockFilename(p3d); std::ofstream o(fullpath.c_str(), std::ios_base::binary); if(o.good() == false) throw FileNotGoodException("Cannot open block data"); #endif /* [0] u8 serialization version [1] data */ verifyDatabase(); std::ostringstream o(std::ios_base::binary); o.write((char*)&version, 1); // Write basic data block->serialize(o, version, true); // Write block to database std::string tmp = o.str(); const char *bytes = tmp.c_str(); if(sqlite3_bind_int64(m_database_write, 1, getBlockAsInteger(p3d)) != SQLITE_OK) infostream<<"WARNING: Block position failed to bind: "<<sqlite3_errmsg(m_database)<<std::endl; if(sqlite3_bind_blob(m_database_write, 2, (void *)bytes, o.tellp(), NULL) != SQLITE_OK) // TODO this mught not be the right length infostream<<"WARNING: Block data failed to bind: "<<sqlite3_errmsg(m_database)<<std::endl; int written = sqlite3_step(m_database_write); if(written != SQLITE_DONE) infostream<<"WARNING: Block failed to save ("<<p3d.X<<", "<<p3d.Y<<", "<<p3d.Z<<") " <<sqlite3_errmsg(m_database)<<std::endl; // Make ready for later reuse sqlite3_reset(m_database_write); // We just wrote it to the disk so clear modified flag block->resetModified(); }