/* Delete a record off the table described via pTable @param Table *pTable @param UUID delete_uuid */ int BufferManager::deleteRec(const Table *pTable, UUID delete_uuid){ FileInf *file; file = getFile(pTable); long last_recOff = file->recordNum - file->recordPerBlock * (file->Block_Num - 1); long last_byteOff = file->recordLen * (last_recOff - 1); if ( delete_uuid != file->recordNum ){ // The record to delete is not the last one /* delete */ int del_blockNum = static_cast<int>(ceil((float)delete_uuid / file->recordPerBlock)); // long del_recordOffset = delete_uuid - file->recordPerBlock * (del_blockNum - 1); long del_byteOffset = file->recordLen * (del_recordOffset - 1); int del_blkIndex = getBlock(file, del_blockNum); // The block to delete /* Cover the deteled record with the last one */ memcpy(&Bufferlist[del_blkIndex].token[del_byteOffset + sizeof(UUID)], &Bufferlist[file->lastBlock].token[last_byteOff + sizeof(UUID)], file->recordLen - sizeof(UUID)); Bufferlist[del_blkIndex].is_Dirty = true; } /* To delete the last block */ memset(&Bufferlist[file->lastBlock].token[last_byteOff], EMPTY, file->recordLen); Bufferlist[file->lastBlock].is_Dirty = true; /* In case of block withdraw i.e. the last tuple unluckily the tuple being the first in its the block */ int CurBlkNum_in_File = static_cast<int>(ceil((float)(file->recordNum - 1) / file->recordPerBlock)); if ( CurBlkNum_in_File < file->Block_Num ){ file->Block_Num--; blockCount--; Bufferlist[file->lastBlock].unlock(); Bufferlist[file->lastBlock].Initialize(); if ( CurBlkNum_in_File == 0 ){ file->firstBlock = file->lastBlock = -1; } else { int block = getBlock(file, CurBlkNum_in_File); if ( block != file->firstBlock ){ // Equals when two-blocks reduce to one int i = file->firstBlock; while ( i >= 0 && i < MAX_BLOCK_NUM && Bufferlist[i].next != file->lastBlock ) i = Bufferlist[i].next; if ( i != -1 ){ Bufferlist[i].next = block; // Link the lastBlock back to the list } } Bufferlist[block].next = -1; Bufferlist[block].lock(); file->lastBlock = block; } } /* Descrease the number in FileInf while pTable is maintained by the CatalogManager */ file->recordNum--; return pTable->recordNum; }
/*! * This method looks to see if there is a list at the current point. If so * fill the dialog with that stuff, otherwise fill the dialog with the uncustomized * values corresponding to m_NewListType. */ void AP_Dialog_Lists::PopulateDialogData(void) { m_isListAtPoint = getBlock()->isListItem(); if(m_isListAtPoint == true) { fillDialogFromBlock(); } else { // m_NewListType = NOT_A_LIST; fillUncustomizedValues(); } if(m_isListAtPoint == true) { const UT_UCSChar * tmp1 = getBlock()->getListLabel(); if(tmp1 != NULL) { UT_sint32 cnt = UT_MIN(UT_UCS4_strlen(tmp1),80); UT_sint32 i; for(i =0; i<=cnt; i++) m_curListLabel[i] = *tmp1++; } m_curListLevel = getBlock()->getLevel(); m_curStartValue = getAutoNum()->getStartValue32(); m_iStartValue = getAutoNum()->getStartValue32(); m_DocListType = getAutoNum()->getType(); } else { m_DocListType = NOT_A_LIST; m_curStartValue = 1; } }
void FreeListAllocator::printDebugInfo( std::ostream& out ) const { void * pend; out << "FreeListAllocator(" << this << "):\n"; out << "\tBlock Start: " << getBlock() << "\n"; out << "\tBlock Size: " << getSize() << " bytes\n"; out << "\tBlock End: " << (pend = (void*)(reinterpret_cast<uintptr_t>(getBlock())+getSize())) << "\n"; out << "\tUsed Memory: " << usedMemory() << " bytes\n"; out << "\tUnused Memory: " << unusedMemory() << " bytes\n"; out << "\tNumber of Allocations: " << numAllocations() << "\n"; out << "\tMax Used Memory: " << maxUsedMemory() << " bytes\n"; out << "\tMax Number of Allocations: " << maxNumAllocations() << "\n"; //out << "\tNumber of deallocLoops: " << deallocLoops << "\n"; if(true) { out << "{\n"; out << "\tfree:\n\t{\n"; std::size_t numFreeBlocks = 0; _FreeBlock * curr_block = _free_blocks; while( curr_block != nullptr && (void*)curr_block >= _block_start && (void*)curr_block < pend) { out << "\t\taddr:" << curr_block << ",size:" << curr_block->size << ",end:" << (void*)(reinterpret_cast<uintptr_t>(curr_block)+curr_block->size) << ",next:" << curr_block->next << "\n"; curr_block = curr_block->next; ++numFreeBlocks; } out << "\t}(freeBlocks:" << numFreeBlocks << ");\n"; out << "};\n"; } }
bool fp_FieldTOCListLabelRun::calculateValue(void) { UT_UCSChar sz_ucs_FieldValue[FPFIELD_MAX_LENGTH + 1]; // // First get owning TOC. // UT_ASSERT(getLength() == 0); fl_TOCLayout * pTOCL = static_cast<fl_TOCLayout *>(getBlock()->myContainingLayout()); UT_ASSERT(pTOCL->getContainerType() == FL_CONTAINER_TOC); UT_String str = pTOCL->getTOCListLabel(getBlock()).utf8_str(); if(str.size() == 0) { sz_ucs_FieldValue[0] = 0; return _setValue(sz_ucs_FieldValue); } UT_sint32 i = 0; bool bStop = false; for(i=0; (i<FPFIELD_MAX_LENGTH) && !bStop; i++) { sz_ucs_FieldValue[i] = static_cast<UT_UCSChar>(str[i]); if(str[i] == 0) { bStop = true; } } return _setValue(sz_ucs_FieldValue); }
string readLine(FILE *infile) { string line, nline; int n, ch, size; n = 0; size = INITIAL_BUFFER_SIZE; line = (string) getBlock(size + 1); while (true) { ch = getc(infile); if (ch == '\n' || ch == EOF) break; if (ch == '\r') { ch = getc(infile); if (ch != '\n') ungetc(ch, infile); break; } if (n == size) { size *= 2; nline = (string) getBlock(size + 1); strncpy(nline, line, n); freeBlock(line); line = nline; } line[n++] = ch; } if (n == 0 && ch == EOF) { freeBlock(line); return NULL; } line[n] = '\0'; nline = (string) getBlock(n + 1); strcpy(nline, line); freeBlock(line); return nline; }
inline extern void deleteDir (char *pattern) { struct dirEntryStruct *entry; entryIndex_t entryIndex = 0; while ((entry = getEntry (entryIndex++))) { /* only process non-deleted dirs */ if (entry->startBlock) { /* only delete dirs that match pattern */ if (filenameMatch (entry->fileName, pattern)) { block_t blockWithEntry = dirBufferBlock; /* only delete dirs */ if (entry->fileType == DIR) { getBlock (entry->startBlock); /* only delete empty dirs */ if (!getUsedEntryInCurrentBlock()) { /* delete directory */ getBlock (blockWithEntry); freeBlock (entry->startBlock); deleteEntry (entry); flushDirBuffer(); flushFreeBlockList(); /* begin counting at 0 because direntries may have been moved */ entryIndex = 0; } } } } } }
VarExprReturnSP LitMatrixExprReturn::convertToVarExprReturn( VarExprReturn &varExprReturn ) { SFC::DT dt = getDT(); // assert( dt == varExprReturn.getDT() ); SFCTypesManager::DimensionVector dimensionVector = SFCTypesManager::getDimensions( dt ); if ( dimensionVector.empty() ) { Exprs exprs = DE( getSequence().front() ); VarExprReturnSP varExprReturnSP = VarExprReturn::create( getBlock(), exprs, ExprsProxyVector(), SFCTypesManager::getSingleton().getBasicType( "double" ) ); varExprReturn.combine( "=", varExprReturnSP )->collapse(); return VarExprReturn::create( varExprReturn ); } SFCTypesManager::DimensionVector countVector( dimensionVector.size(), 0 ); for( Sequence::iterator sqnItr = getSequence().begin() ; sqnItr != getSequence().end() ; ++sqnItr ) { for( unsigned int ix = 0 ; ix < (unsigned int) dimensionVector.size() ; ++ix ) { varExprReturn.getExprsProxyVector()[ ix ].setExprs( IE( countVector[ ix ] ) ); } Exprs exprs = BE( varExprReturn.getExprs(), "=", DE( *sqnItr ) ); exprs.buildUdm( getBlock(), SFC::CompoundStatement::meta_stmnt ); for( int ix = dimensionVector.size() ; --ix >= 0 ;) { if ( ++countVector[ix] < dimensionVector[ix] ) break; countVector[ix] = 0; } } return VarExprReturn::create( varExprReturn ); }
void AP_Dialog_Lists::StartList(void) { UT_ASSERT_HARMLESS(!IS_NONE_LIST_TYPE(m_DocListType)); getBlock()->listUpdate(); const gchar* pStyle = getBlock()->getListStyleString(m_DocListType); UT_return_if_fail (pStyle); getView()->cmdStartList(pStyle); }
Filesys::Filesys(std::string diskName, int numberOfBlocks, int blockSize) : Sdisk(diskName, numberOfBlocks, blockSize) { // Calculate rootSize and fatSize rootSize = blockSize / 12; fatSize = (6 * numberOfBlocks) / blockSize + 1; // If no filesystem exists on disk, build one and synch. If a filesystem // exists, read in to ROOT and FAT and synch. std::string buffer; getBlock(0, buffer); if (buffer[0] == '#') { // No filesystem exists std::cout << "Creating fs..." << '\n'; for (int i = 1; i <= rootSize; i++) { fileName.push_back("xxxxx"); firstBlock.push_back(0); } fat.push_back(fatSize + 1); for (int i = 1; i <= fatSize; i++) { fat.push_back(0); } for (int i = fatSize + 1; i <= numberOfBlocks - 1; i++) { fat.push_back(i + 1); } fat[numberOfBlocks - 1] = 0; // ROOT and FAT created, now write to disk. fssynch(); } else { // Filesys exists, read in ROOT and FAT. std::cout << "Reading fs..." << '\n'; std::string readBuffer, file; int block; getBlock(0, readBuffer); std::istringstream instream; instream.str(readBuffer); for (int i = 0; i < rootSize; i++) { instream >> file >> block; fileName.push_back(file); firstBlock.push_back(block); } // Read in FAT std::string tempBuffer, fatBuffer; for (int i = 1; i <= fatSize; i++) { getBlock(i, tempBuffer); fatBuffer += tempBuffer; } std::istringstream instream2(tempBuffer); int toInt; for (int i = 0; i < numberOfBlocks; i++) { instream2 >> toInt; fat.push_back(toInt); } fssynch(); } }
/** * Allocates a free physical page of memory. * This is chosen using a round robin algorithm, to even out the wear on the physical device. * @return NULL on error, page address on success */ uint32_t* MicroBitFileSystem::getFreePage() { // Walk the file table, starting at the last allocated block, looking for an unused page. int blocksPerPage = (PAGE_SIZE / MBFS_BLOCK_SIZE); // get a handle on the next physical page. uint16_t currentPage = getBlockNumber(getPage(lastBlockAllocated)); uint16_t page = (currentPage + blocksPerPage) % fileSystemSize; uint16_t recyclablePage = 0; // Walk around the file table, looking for a free page. while (page != currentPage) { bool empty = true; bool deleted = false; uint16_t next; for (int i = 0; i < blocksPerPage; i++) { next = getNextFileBlock(page + i); if (next == MBFS_DELETED) deleted = true; else if (next != MBFS_UNUSED) { empty = false; break; } } // See if we found one... if (empty) { lastBlockAllocated = page; return getBlock(page); } // make note of the first unused but un-erased page we find (if any). if (deleted && !recyclablePage) recyclablePage = page; page = (page + blocksPerPage) % fileSystemSize; } // No empty pages are available, but we may be able to recycle one. if (recyclablePage) { uint32_t *address = getBlock(recyclablePage); flash.erase_page(address); return address; } // Nothing available at all. Use the default. flash.erase_page(defaultScratchPage); return defaultScratchPage; }
void NodeConstantArray::checkForSymbol() { //in case of a cloned unknown NodeBlock * currBlock = getBlock(); m_state.pushCurrentBlockAndDontUseMemberBlock(currBlock); Symbol * asymptr = NULL; bool hazyKin = false; if(m_state.alreadyDefinedSymbol(m_token.m_dataindex, asymptr, hazyKin)) { if(asymptr->isConstant()) { m_constSymbol = (SymbolConstantValue *) asymptr; } else { std::ostringstream msg; msg << "(1) <" << m_state.getTokenDataAsString(m_token).c_str(); msg << "> is not a constant, and cannot be used as one with class: "; msg << m_state.getUlamTypeNameBriefByIndex(m_state.getCompileThisIdx()).c_str(); MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), ERR); } } else { std::ostringstream msg; msg << "Named Constant Array <" << m_state.getTokenDataAsString(m_token).c_str(); msg << "> is not defined, or was used before declared in a function"; if(!hazyKin) MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), ERR); else MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), DEBUG); } m_state.popClassContext(); //restore if(m_constSymbol && !m_constSymbol->isDataMember() && !m_constSymbol->isLocalsFilescopeDef() && !m_constSymbol->isClassArgument() && (m_constSymbol->getDeclNodeNo() > getNodeNo())) { NodeBlock * currBlock = getBlock(); currBlock = currBlock->getPreviousBlockPointer(); std::ostringstream msg; msg << "Named constant array '" << getName(); msg << "' was used before declared in a function"; if(currBlock) { MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), WAIT); setBlockNo(currBlock->getNodeNo()); m_constSymbol = NULL; return checkForSymbol(); } else { MSG(getNodeLocationAsString().c_str(), msg.str().c_str(), ERR); m_constSymbol = NULL; } } } //checkForSymbol
void fp_EmbedRun::mapXYToPosition(UT_sint32 x, UT_sint32 /*y*/, PT_DocPosition& pos, bool& bBOL, bool& bEOL, bool & /*isTOC*/) { if (x > getWidth()) pos = getBlock()->getPosition() + getBlockOffset() + getLength(); else pos = getBlock()->getPosition() + getBlockOffset(); bBOL = false; bEOL = false; }
bool fp_FieldTOCNumRun::calculateValue(void) { UT_UCSChar sz_ucs_FieldValue[FPFIELD_MAX_LENGTH + 1]; // // First Find page number. // PL_StruxDocHandle sdh = getBlock()->getStruxDocHandle(); PD_Document * pDoc = getBlock()->getDocument(); PT_DocPosition pos = pDoc->getStruxPosition(sdh)+1; FL_DocLayout * pLayout = getBlock()->getDocLayout(); fl_BlockLayout * pBlockInDoc = pLayout->findBlockAtPosition(pos); if(pBlockInDoc == NULL) { sz_ucs_FieldValue[0] = static_cast<UT_UCSChar>(' '); sz_ucs_FieldValue[1] = 0; return _setValue(sz_ucs_FieldValue); } fp_Line * pLine = static_cast<fp_Line *>(pBlockInDoc->getFirstContainer()); if(pLine == NULL) { sz_ucs_FieldValue[0] = static_cast<UT_UCSChar>(' '); sz_ucs_FieldValue[1] = 0; return _setValue(sz_ucs_FieldValue); } fp_Page * pPage = pLine->getPage(); UT_sint32 iPage = pLayout->findPage(pPage); if( iPage < 0) { sz_ucs_FieldValue[0] = static_cast<UT_UCSChar>(' '); sz_ucs_FieldValue[1] = 0; return _setValue(sz_ucs_FieldValue); } iPage++; // Start from Page 1. UT_String sVal(""); FootnoteType iType = getBlock()->getTOCNumType(); pLayout->getStringFromFootnoteVal(sVal,iPage,iType); const char * psz = sVal.c_str(); bool bStop = false; UT_sint32 i = 0; sz_ucs_FieldValue[0] = static_cast<UT_UCSChar>(' '); for(i=1; (i<FPFIELD_MAX_LENGTH) && !bStop; i++) { sz_ucs_FieldValue[i] = static_cast<UT_UCSChar>(*psz); if(*psz == 0) { bStop = true; } else { psz++; } } return _setValue(sz_ucs_FieldValue); }
void StripedStructure::fillMatrixFromP( gsl_matrix* c, const gsl_vector* p ) { size_t n_row = 0, sum_np = 0; gsl_matrix_view sub_c; for (size_t l = 0; l < getBlocksN(); sum_np += myStripe[l]->getNp(), n_row += getBlock(l)->getN(), l++) { sub_c = gsl_matrix_submatrix(c, n_row, 0, getBlock(l)->getN(), c->size2); gsl_vector_const_view sub_p = gsl_vector_const_subvector(p, sum_np, myStripe[l]->getNp()); myStripe[l]->fillMatrixFromP(&sub_c.matrix, &sub_p.vector); } }
void getBlock(int f, int t, int x){ if(f != t) push(x); if(f == t){ l = tag[x].f; r = tag[x].t; }else{ if(X <= mid) return getBlock(f, mid, ls); getBlock(mid + 1, t, rs); } }
ExprReturnSP LitMatrixExprReturn::collapseLogical() { if ( getDT().type() != SFC::Array::meta ) return create( *this ); Sequence::iterator sqnItr = getSequence().begin(); SFC::LocalVar localVar = SFCManager::createUniqueLocalVar( getBlock(), "test" ); bool value = *sqnItr != 0; while( ++sqnItr != getSequence().end() ) value = value && ( *sqnItr != 0 ); return create( getBlock(), value ); }
VarMatrixExprReturnSP LitMatrixExprReturn::convertToVarMatrixExprReturn( void ) { VarMatrixExprReturn::Sequence sequence; if ( !getSequence().empty() ) { SFC::DT dt = SFCTypesManager::getSingleton().getBaseDT( getDT() ); for( Sequence::iterator sqnItr = getSequence().begin() ; sqnItr != getSequence().end() ; (void)++sqnItr ) { Exprs exprs = DE( *sqnItr ); sequence.push_back( VarExprReturn::create( getBlock(), exprs, ExprsProxyVector(), dt ) ); } } return VarMatrixExprReturn::create( getBlock(), getDT(), sequence ); }
void StripedStructure::multByGtUnweighted( gsl_vector* p, const gsl_matrix *Rt, const gsl_vector *y, double alpha, double beta, bool skipFixedBlocks ){ size_t n_row = 0, sum_np = 0, d = Rt->size2; gsl_vector subp, suby; for (size_t l = 0; l < getBlocksN(); sum_np += myStripe[l]->getNp(), n_row += getBlock(l)->getN() * d, l++) { suby = gsl_vector_const_subvector(y, n_row, getBlock(l)->getN() * d).vector; subp = gsl_vector_subvector(p, sum_np, myStripe[l]->getNp()).vector; myStripe[l]->multByGtUnweighted(&subp, Rt, &suby, alpha, beta, skipFixedBlocks); } }
/*! * This method reads the various elements in the Customize box and loads * the XP member variables with them */ void AP_UnixDialog_Lists::_gatherData(void) { UT_sint32 maxWidth = getBlock()->getDocSectionLayout()->getActualColumnWidth(); if(getBlock()->getFirstContainer()) { if(getBlock()->getFirstContainer()->getContainer()) { maxWidth = getBlock()->getFirstContainer()->getContainer()->getWidth(); } } // // screen resolution is 100 pixels/inch // float fmaxWidthIN = (static_cast<float>(maxWidth)/ 100.) - 0.6; setiLevel(1); float f =gtk_spin_button_get_value(GTK_SPIN_BUTTON(m_wAlignListSpin)); if(f > fmaxWidthIN) { f = fmaxWidthIN; gtk_spin_button_set_value(GTK_SPIN_BUTTON( m_wAlignListSpin), f); } setfAlign(f); float indent = gtk_spin_button_get_value(GTK_SPIN_BUTTON( m_wIndentAlignSpin)); if((indent - f) > fmaxWidthIN ) { indent = fmaxWidthIN + f; gtk_spin_button_set_value(GTK_SPIN_BUTTON( m_wIndentAlignSpin), indent); } setfIndent(indent - getfAlign()); if( (getfIndent() + getfAlign()) < 0.0) { setfIndent(- getfAlign()); gtk_spin_button_set_value(GTK_SPIN_BUTTON( m_wIndentAlignSpin), 0.0); } gint ifont = gtk_combo_box_get_active(m_wFontOptions); if(ifont == 0) { copyCharToFont("NULL"); } else { copyCharToFont(m_glFonts[ifont - 1]); } const gchar * pszDec = gtk_entry_get_text( GTK_ENTRY(m_wDecimalEntry)); copyCharToDecimal( static_cast<const char *>(pszDec)); setiStartValue(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(m_wStartSpin))); const gchar * pszDel = gtk_entry_get_text( GTK_ENTRY(m_wDelimEntry)); copyCharToDelim(static_cast<const char *>(pszDel)); }
bool fp_FieldListLabelRun::calculateValue(void) { UT_UCSChar sz_ucs_FieldValue[FPFIELD_MAX_LENGTH + 1]; UT_uint32 i = 0; UT_UCSChar * listlabel = NULL; if(getBlock()->isContainedByTOC()) { xxx_UT_DEBUGMSG(("!!!!!!------!!!! ListLabel in TOC!!!! \n")); // // First Find the block in the document. // pf_Frag_Strux* sdh = getBlock()->getStruxDocHandle(); PD_Document * pDoc = getBlock()->getDocument(); PT_DocPosition pos = pDoc->getStruxPosition(sdh)+1; FL_DocLayout * pLayout = getBlock()->getDocLayout(); fl_BlockLayout * pBlockInDoc = pLayout->findBlockAtPosition(pos); if(pBlockInDoc == NULL) { sz_ucs_FieldValue[0] = static_cast<UT_UCSChar>(' '); sz_ucs_FieldValue[1] = 0; return _setValue(sz_ucs_FieldValue); } i = 0; listlabel = pBlockInDoc->getListLabel(); } else { i = 0; listlabel = getBlock()->getListLabel(); } if(listlabel == NULL) { sz_ucs_FieldValue[0] = 0; } else { // // This code is here because UT_UCS_copy_char is broken // i = 0; UT_uint32 len = UT_MIN( UT_UCS4_strlen(listlabel),FPFIELD_MAX_LENGTH + 1) ; for(i=0; i<=len;i++) { sz_ucs_FieldValue[i] = *listlabel++; } // sz_ucs_FieldValue[len] = 0; // m_sFieldValue[0] = 0; // Force an update!!! } return _setValue(sz_ucs_FieldValue); }
void deleteEntry (struct dirEntryStruct *entry) { block_t oldBlock = dirBufferBlock; /* if directory has more blocks in chain, move an entry from the last block in chain to this block */ if (dirBuffer.nextBlock) { struct dirEntryStruct *entryToMove; struct dirEntryStruct copyOfEntry; block_t prevBlock = oldBlock; /* find the last block in dir chain */ while (dirBuffer.nextBlock) { prevBlock = dirBufferBlock; getBlock (dirBuffer.nextBlock); } /* if no entries in last dir block, remove the last dir block */ if (!(entryToMove = getUsedEntryInCurrentBlock())) { getBlock (prevBlock); freeBlock (dirBuffer.nextBlock); flushFreeBlockList(); dirBuffer.nextBlock = 0; dirBufferChanged = TRUE; /* get an entry to move */ if (!(entryToMove = getUsedEntryInCurrentBlock())) { /* TODO: error recovery */ } } /* overwrite the entry to be deleted with the one just found */ if (dirBufferBlock != oldBlock) { memcpy (©OfEntry, entryToMove, sizeof (struct dirEntryStruct)); entryToMove->startBlock = 0; dirBufferChanged = TRUE; getBlock (oldBlock); memcpy (entry, ©OfEntry, sizeof (struct dirEntryStruct)); dirBufferChanged = TRUE; } else { /* delete entry */ entry->startBlock = 0;/* a eletet file has del type (0) and is not closed.*/ entry->fileType= DEL; entry->splat =FALSE; dirBufferChanged = TRUE; } } else { /* delete entry */ entry->startBlock = 0; /* a eletet file has del type (0) and is not closed.*/ dirBufferChanged = TRUE; entry->fileType= DEL; entry->splat =FALSE; } }
void freeChunk(Chunk *chunk) { int x, y, z; for (x = 0; x < CHUNK_SIZE; x++) { for (y = 0; y < CHUNK_SIZE; y++) { for (z = 0; z < CHUNK_SIZE; z++) { if (getBlock(chunk, x, y, z)->logic) free(getBlock(chunk, x, y, z)->logic); } } } freeMesh(chunk->mesh); free(chunk->mesh); free(chunk); }
int countChunkSize(Chunk *chunk) { int x, y, z; int count = 0; Block *block; for (x = 0; x < CHUNK_SIZE; x++) { for (y = 0; y < CHUNK_SIZE; y++) { for (z = 0; z < CHUNK_SIZE; z++) { block = getBlock(chunk, x, y, z); if (block->active) { if (block->data) count += countChunkSize(block->data->chunk); // due to some multithreading issues, we may have to over-report else if (block->logic) count += countChunkSize(getLogicModel(block->logic->type, 0)->chunk); else count += 12 * 3 * 3; } } } } return count; }
void addToIteratorList(Iterator iterator, void *dst) { Cell *np, *pp, *ip; void *dp; np = (Cell *) getBlock(sizeof (Cell) + iterator->elementSize); dp = ((char *) np) + sizeof (Cell); memcpy(dp, dst, iterator->elementSize); pp = NULL; if (iterator->tail != NULL) { if (iterator->cmpFn == NULL || iterator->cmpFn == NULL) { pp = iterator->tail; } else { dp = ((char *) iterator->tail) + sizeof (Cell); if (iterator->cmpFn(dst, dp) >= 0) pp = iterator->tail; } } if (pp == NULL) { for (ip = iterator->head; ip != NULL; ip = ip->link) { dp = ((char *) ip) + sizeof (Cell); if (iterator->cmpFn(dst, dp) < 0) break; pp = ip; } } if (pp == NULL) { np->link = iterator->head; if (iterator->head == NULL) iterator->tail = np; iterator->head = np; } else { np->link = pp->link; if (pp->link == NULL) iterator->tail = np; pp->link = np; } }
BlockCacheEntry * BlockCacheLinux::getBlockRead(uval32 b) { BlockCacheEntry *entry = getBlock(b); entry->readData(); return entry; }
int cRecPlayer::getBlock(unsigned char* buffer, uint64_t position, int amount) { // dont let the block be larger than 256 kb if (amount > 256*1024) amount = 256*1024; if ((uint64_t)amount > m_totalLength) amount = m_totalLength; if (position >= m_totalLength) return 0; if ((position + amount) > m_totalLength) amount = m_totalLength - position; // work out what block "position" is in int segmentNumber = -1; for(int i = 0; i < m_segments.Size(); i++) { if ((position >= m_segments[i]->start) && (position < m_segments[i]->end)) { segmentNumber = i; break; } } // segment not found / invalid position if (segmentNumber == -1) return 0; // open file (if not already open) if (!openFile(segmentNumber)) return 0; // work out position in current file uint64_t filePosition = position - m_segments[segmentNumber]->start; // seek to position if(lseek(m_file, filePosition, SEEK_SET) == -1) { ERRORLOG("unable to seek to position: %llu", filePosition); return 0; } // try to read the block int bytes_read = read(m_file, buffer, amount); DEBUGLOG("read %i bytes from file %i at position %llu", bytes_read, segmentNumber, filePosition); if(bytes_read <= 0) { return 0; } #ifndef __FreeBSD__ // Tell linux not to bother keeping the data in the FS cache posix_fadvise(m_file, filePosition, bytes_read, POSIX_FADV_DONTNEED); #endif // divide and conquer if(bytes_read < amount) { bytes_read += getBlock(&buffer[bytes_read], position + bytes_read, amount - bytes_read); } return bytes_read; }
void setBlock(Chunk *chunk, int x, int y, int z, Block block) { Block *current = getBlock(chunk, x, y, z); if (current->logic) freeLogic(current->logic); block.nb_pos_x = current->nb_pos_x; block.nb_neg_x = current->nb_neg_x; block.nb_pos_y = current->nb_pos_y; block.nb_neg_y = current->nb_neg_y; block.nb_pos_z = current->nb_pos_z; block.nb_neg_z = current->nb_neg_z; *getBlock(chunk, x, y, z) = block; renderChunk(chunk); }
unsigned long* FileBlocks::getBlocks(unsigned long beginIndex, unsigned long length) throw( ArrayIndexOutOfBoundsException*, HardDiskNotInitializedException*, InvalidBlockNumberException*, IOException*) { if ((beginIndex+length) > MAX_BLOCKS) { throw new ArrayIndexOutOfBoundsException(beginIndex+length); } unsigned long* addresses = new unsigned long[length]; if (addresses == NULL) { cout << "Not enough memory.\n"; exit(1); } for (unsigned long i = 0; i < length; i++) { addresses[i] = getBlock(beginIndex+i); } return addresses; }
int solidBlockInArea(World *world, int minx, int miny, int minz, int maxx, int maxy, int maxz) { int x, y, z; int bx, by, bz, cx, cy, cz; for (x = minx; x < maxx; x++) { for (y = miny; y < maxy; y++) { for (z = minz; z < maxz; z++) { bx = x & BLOCK_MASK; by = y & BLOCK_MASK; bz = z & BLOCK_MASK; cx = x >> LOG_CHUNK_SIZE; cy = y >> LOG_CHUNK_SIZE; cz = z >> LOG_CHUNK_SIZE; if (bx >= 0 && by >= 0 && bz >= 0 && bx < CHUNK_SIZE && by < CHUNK_SIZE && bz < CHUNK_SIZE && cx >= 0 && cy >= 0 && cz >= 0 && cx < world->size && cy < world->size && cz < world->size && getBlock(getChunk(world, cx, cy, cz), bx, by, bz)->active) return 1; } } } return 0; }
struct dirEntryStruct *getUnusedEntry (void) { while (TRUE) { entryIndex_t i; /* search through current block for an empty entry */ for (i = 0; i < DIR_ENTRIES_IN_BLOCK; i++) { if (!dirBuffer.dirEntry[i].startBlock) { return &dirBuffer.dirEntry[i]; } } /* if no more blocks in directory chain, make a new one */ if (!dirBuffer.nextBlock) { if (!(dirBuffer.nextBlock = allocateBlock())) { return NULL; } dirBufferChanged = TRUE; flushDirBuffer(); dirBufferBlock = dirBuffer.nextBlock; dirBufferBlockNumber = ~0; memset (&dirBuffer, '\0', BLOCKSIZE); dirBufferChanged = TRUE; } else { /* load the next dir block in chain */ getBlock (dirBuffer.nextBlock); } } return NULL; }