// // _parseHeader( void ) // void MadelineTable::_parseHeader( void ){ if(getBlockCount()==2){ char *b; unsigned i; char type; char *headerStart = _lineInfo[ _firstHeaderRow ].getMalleableLine(); const char *headerEnd = _lineInfo[ _lastHeaderRow ].getLineEnd(); for(b=headerStart,i=0;b<headerEnd && i<_dataColumns;i++){ // (re) initialize type: type='\0'; // read the column name: b=_readAndNullTerminateColumnName(b,headerEnd,_columnOffset[i]); // Also read the column type: b=_readColumnType(b,headerEnd,_columnOffset[i]); } // UNFINISHED: WHAT IF DECLARATIONS ARE FEWER THAN COLUMNS ? } // UNFINISHED: WHAT IF ONLY ONE BLOCK? HOW DO WE DEAL WITH COLUMN NAMES? }
void RecordManager::PushCondition(uint table_1, uint attribute_1, Operator condition, uint table_2, uint attribute_2) { AddCurrentTable(table_1); AddCurrentTable(table_2); if(getBlockCount(table_1)<getBlockCount(table_2)){ pyEvaluator.PushCondition(table_2, attribute_2, condition, table_1, attribute_1, isTableAttributeIndexBuilt[table_2]->at(attribute_2)); } else{ pyEvaluator.PushCondition(table_1, attribute_1, condition, table_2, attribute_2, isTableAttributeIndexBuilt[table_1]->at(attribute_1)); } return; }
asagi::Grid::Error grid::NumaLocalStaticGrid::init() { unsigned long blockSize = getTotalBlockSize(); size_t block[3]; unsigned long masterBlockCount = getThreadBlockCount()*m_threadHandle.getThreadCount(); //the first thread allocates the memory. if (m_threadHandle.getThreadRank(pthread_self())==0) { asagi::Grid::Error error; error = m_allocator.allocate(getType().getSize() * blockSize * masterBlockCount, m_data); if (error != asagi::Grid::SUCCESS) return error; // Load the blocks from the file, which we control /* for (unsigned long i = 0; i < getLocalBlockCount(); i++) { if (getGlobalBlock(i) >= getBlockCount()){ // Last process(es) may control less blocks break; } // Get x, y and z coordinates of the block getBlockPos(getGlobalBlock(i), block); // Get x, y and z coordinates of the first value in the block for (unsigned char j = 0; j < 3; j++) block[j] *= getBlockSize(j); getType().load(getInputFile(), block, getBlockSize(), &m_data[getType().getSize() * blockSize * i]); }*/ //m_threadHandle.m_staticPtr[pthread_self()][m_id]=m_data; // std::cout << "Thread: " << pthread_self() << " Pointer: " << &m_data; m_threadHandle.setStaticPtr(pthread_self(), m_data, m_id); } else { //The memory was already allocated by the masterthread. //Simply shift the Pointer in the right space. m_data = m_threadHandle.getStaticPtr(m_threadHandle.getMasterthreadId(), m_id) + (getType().getSize() * blockSize * m_threadHandle.getThreadRank(pthread_self()) * getThreadBlockCount()); // std::cout << "Thread: " << pthread_self() << " Pointer: " << &m_data; m_threadHandle.setStaticPtr(pthread_self(), m_data, m_id); } // Load the blocks from the file, which we control for (unsigned long i = m_threadHandle.getThreadRank(pthread_self())*getThreadBlockCount(); i < (m_threadHandle.getThreadRank(pthread_self())*getThreadBlockCount()+getThreadBlockCount()); i++) { if (getGlobalBlock(i) >= getBlockCount()){ // Last process(es) may control less blocks break; } // Get x, y and z coordinates of the block getBlockPos(getGlobalBlock(i), block); // Get x, y and z coordinates of the first value in the block for (unsigned char j = 0; j < 3; j++) block[j] *= getBlockSize(j); getType().load(m_threadHandle.getInputFile(), block, getBlockSize(), &m_data[getType().getSize() * blockSize * (i-m_threadHandle.getThreadRank(pthread_self())*getThreadBlockCount())]); } return asagi::Grid::SUCCESS; }
int main(int argc, char** argv) { FILE *fp; char *name = new char[IDENT_SIZE]; int size; int blockcount; int FATstarts; int FATblocks; int rootdirstart; int rootdirblocks; int freeblocks; int reservedblocks; int allocatedblocks; if ((fp=fopen(argv[1],"r"))) { printf("Super block information: \n"); //getName(fp,name); //printf("File system identifier: %s\n", name); size = getBlockSize(fp); printf("Block size: %d\n", size); blockcount = getBlockCount(fp); printf("Block count: %d\n", blockcount); FATstarts = getFATstart(fp); printf("FAT starts: %d\n", FATstarts); FATblocks = getFATblocks(fp); printf("FAT blocks: %d\n", FATblocks); rootdirstart = getRootDirStart(fp); printf("Root directory start: %d\n", rootdirstart); rootdirblocks = getRootDirBlocks(fp); printf("Root directory blocks: %d\n", rootdirblocks); printf("\nFAT information: \n"); freeblocks = getFreeBlocks(fp); printf("Free Blocks: %d\n", freeblocks); reservedblocks = getReservedBlocks(fp); printf("Reserved Blocks: %d\n", reservedblocks); allocatedblocks = getAllocatedBlocks(fp); printf("Allocated Blocks: %d\n", allocatedblocks); } else printf("Fail to open the image file.\n"); free(name); fclose(fp); return 0; }
// // _assignRecordTypes: // void MadelineTable::_assignRecordTypes( void ){ unsigned i=0; if(getBlockCount()==2){ // Skip empty lines at top: for(;i< _lines && _lineInfo[i].getType()==LineInformation::EMPTY_LINE;i++); // Store first header row index: _firstHeaderRow = i; // Now mark the non-empty lines as the HEADER block: for(;i< _lines && _lineInfo[i].getType()==LineInformation::DIRTY_LINE;i++){ _lineInfo[i].setType(LineInformation::HEADER_LINE); } // Store last header row index and number of (filled) header rows: _headerRows = i - _firstHeaderRow; _lastHeaderRow = i-1; } // Now at or before the DATA block: // Skip any empty lines: for(;i< _lines && _lineInfo[i].getType()==LineInformation::EMPTY_LINE;i++); // First, store pointer to beginning of DATA block: _data = _lineInfo[i].getLine(); _firstDataRow = i; // Arbitrarily assume lines are of same length in DATA block: use one as standard: _length = _lineInfo[i].getLength(); // Mark the non-empty lines as the DATA block: for(;i< _lines && _lineInfo[i].getType()==LineInformation::DIRTY_LINE;i++){ _lineInfo[i].setType(LineInformation::DATA_LINE); } // Set number of rows in the data table: _dataRows = i - _firstDataRow; _lastDataRow = --i; // DEBUG: // std::cerr << "*** FIRST HEADER ROW : " << _firstHeaderRow << std::endl; // std::cerr << "*** LAST HEADER ROW : " << _lastHeaderRow << std::endl; // std::cerr << "*** NO. OF HEADER ROWS : " << _headerRows << std::endl; // // std::cerr << "*** NUMBER OF DATA ROWS: " << _dataRows << std::endl; // std::cerr << "*** LENGTH OF DATA ROW : " << _length << std::endl; // std::cerr << "*** FIRST DATA ROW : " << _firstDataRow << std::endl; // std::cerr << "*** LAST DATA ROW : " << _lastDataRow << std::endl; }
RETURN_CODE bs_apply(int argc, char** argv) { RETURN_CODE rc = 0; char* pDataFilename = NULL; char* pTargetFilename = NULL; FILE* pDataFile = NULL; FILE* pTargetFile = NULL; void* pBuffer = NULL; BSHeader header; BSFooter footer; TRY if ((rc = parse_args(argc, argv, &pDataFilename, &pTargetFilename)) != 0) { THROW("Invalid arguments", 1); } // Open data file if ((pDataFile = fopen(pDataFilename, "rb")) == NULL) { THROW("Error opening data file", OPEN_ERROR); } if ((rc = readHeaderFooter(pDataFile, &header, &footer)) != NO_ERROR) { THROW("Error reading header and footer", rc); } printHeaderInformation(&header, true); printFooterInformation(&footer); // Open target file if ((pTargetFile = fopen(pTargetFilename, "rb+")) == NULL) { THROW("Error opening target", OPEN_ERROR); } // Check if ((rc = checkHeaders(&header, pTargetFile)) != 0) { THROW("Data file is not compatible with target", rc); } // fseek on checksum files if ((rc = fseekAfterHeader(pDataFile)) != NO_ERROR) { THROW("Cannot set position", rc); } pBuffer = malloc(header.blockSize); printf("Data file contains %"PRIu64" block(s)\n", footer.itemCount); uint64_t blockCount = getBlockCount(&header); uint64_t lastBlockSize = getLastBlockSize(&header); uint64_t blockId; for (uint64_t i = 0; i < footer.itemCount; ++i) { // Read block Id if (fread(&blockId, sizeof(uint64_t), 1, pDataFile) != 1) { THROW("Cannot read from data file", READ_ERROR); } if (fread(pBuffer, header.blockSize, 1, pDataFile) != 1) { THROW("Cannot read from data file", READ_ERROR); } printf("Block %"PRIu64" ... ", blockId); if(fseek(pTargetFile, blockId * header.blockSize, SEEK_SET) != 0) { THROW("Cannot set position on target file from", SEEK_ERROR); } if (fwrite(pBuffer, (blockId == (blockCount - 1)) ? lastBlockSize : header.blockSize, 1, pTargetFile) != 1) { THROW("Error writing block", rc); } printf("OK\n"); } CATCH FINALLY AUTOFREE(pBuffer); AUTOCLOSE(pDataFile); AUTOCLOSE(pTargetFile); return exceptionId; }
RawBlock SwappedBlockchainStorage::getBlockByIndex(uint32_t index) const { assert(index < getBlockCount()); return blocks[index]; }
int getAllocatedBlocks(FILE *fp){ int bc = getBlockCount(fp); int rb = getReservedBlocks(fp); int fb = getFreeBlocks(fp); return bc - rb - fb; }
void Chunk::generatePhysics() { if( mPhysicsBody != NULL ) { auto p = mPhysicsBody; mPhysicsBody = nullptr; CoreSingleton->physicsMutex.lock(); CoreSingleton->getPhysicsWorld() ->removeRigidBody( p ); CoreSingleton->physicsMutex.unlock(); delete mPhysicsState; delete mPhysicsBody; delete mPhysicsShape; delete mPhysicsMesh; } if( mGeometry->vertexCount > 0 && mGeometry->edgeData > 0 ) { if( getBlockCount() < CHUNK_SIZE ) { btTriangleIndexVertexArray* meshInterface = new btTriangleIndexVertexArray; btIndexedMesh part; int vertSize = sizeof( TerrainVertex ); int indexSize = sizeof( GLedge ); part.m_vertexBase = (const unsigned char*)&mGeometry->vertexData[0].x; part.m_vertexStride = vertSize; part.m_numVertices = mGeometry->vertexCount; part.m_vertexType = PHY_FLOAT; part.m_triangleIndexBase = (const unsigned char*)&mGeometry->edgeData[0]; part.m_triangleIndexStride = indexSize * 3; part.m_numTriangles = mGeometry->edgeCount / 3; part.m_indexType = PHY_SHORT; meshInterface->addIndexedMesh( part, PHY_SHORT ); //mPhysicsShape = new btBvhTriangleMeshShape( meshInterface, true );//new btConvexTriangleMeshShape( meshInterface );////new btBoxShape( btVector3(8, 64, 8) ); mPhysicsShape = new btBvhTriangleMeshShape( meshInterface, false ); mPhysicsState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3( getX() * CHUNK_WIDTH, getY() * CHUNK_HEIGHT, getZ() * CHUNK_WIDTH))); btRigidBody::btRigidBodyConstructionInfo ci( 0, mPhysicsState, mPhysicsShape, btVector3(0,0,0) ); mPhysicsBody = new btRigidBody( ci ); mPhysicsBody->setCollisionFlags( mPhysicsBody->getCollisionFlags() | btRigidBody::CF_STATIC_OBJECT ); } else { // Chunk is a solid block. mPhysicsShape = new btBoxShape( btVector3(CHUNK_WIDTH/2, CHUNK_HEIGHT/2, CHUNK_WIDTH/2) ); mPhysicsState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3( getX() * CHUNK_WIDTH, getY() * CHUNK_HEIGHT, getZ() * CHUNK_WIDTH))); btRigidBody::btRigidBodyConstructionInfo ci( 0, mPhysicsState, mPhysicsShape, btVector3(0,0,0) ); mPhysicsBody = new btRigidBody( ci ); mPhysicsBody->setCollisionFlags( mPhysicsBody->getCollisionFlags() | btRigidBody::CF_STATIC_OBJECT ); } CoreSingleton->physicsMutex.lock(); CoreSingleton->getPhysicsWorld() ->addRigidBody( mPhysicsBody ); CoreSingleton->physicsMutex.unlock(); } }
void Chunk::updateVisibility( ) { BaseBlock* b = nullptr; BaseBlock* cb = nullptr; short visFlags = 0; BlockList::iterator it; if( _hasChunkFlag( DataUpdated ) && getBlockCount() > 0 ) { size_t id = 0; mVisibleFaces = 0; ChunkScalar worldX = getX() * CHUNK_WIDTH; ChunkScalar worldY = getY() * CHUNK_HEIGHT; ChunkScalar worldZ = getZ() * CHUNK_WIDTH; ChunkScalar blockX = 0; ChunkScalar blockY = 0; ChunkScalar blockZ = 0; bool fc = getBlockCount() == CHUNK_SIZE; for( long z = 0; z < CHUNK_WIDTH; z++ ) { for( long y = 0; y < CHUNK_HEIGHT; y++ ) { for( long x = 0; x < CHUNK_WIDTH; x++ ) { id = BLOCK_INDEX_2( x, y, z ); b = mBlocks[id]; if( b == nullptr ) { continue; } if( fc && ( x > 0 && x < CHUNK_WIDTH-1 && y > 0 && y < CHUNK_HEIGHT-1 && z > 0 && z < CHUNK_WIDTH-1 ) ) { continue; } blockX = worldX + x; blockY = worldY + y; blockZ = worldZ + z; visFlags = 0; //Check All axes for adjacent blocks. CHECK_FACE( x < CHUNK_WIDTH-1, 1, 0, 0, FACE_RIGHT ); CHECK_FACE( x > 0, -1, 0, 0, FACE_LEFT ); CHECK_FACE( y < CHUNK_HEIGHT-1, 0, 1, 0, FACE_TOP ); CHECK_FACE( y > 0, 0,-1, 0, FACE_BOTTOM ); CHECK_FACE( z < CHUNK_WIDTH-1, 0, 0, 1, FACE_BACK ); CHECK_FACE( z > 0, 0, 0,-1, FACE_FORWARD ); if( b->getVisFlags() != visFlags ) { // Check to see if we need to change the VB data. if( visFlags > 0 && b->getVisFlags() == 0 ) { mVisibleBlocks.insert( BlockList::value_type( id, b ) ); } else if( visFlags == 0 && b->getVisFlags() > 0 ) { it = mVisibleBlocks.find( id ); mVisibleBlocks.erase( it ); } b->updateVisFlags(visFlags); } } } } _raiseChunkFlag( MeshInvalid ); } }