int WorldMap::clearSphere(const v3d_t& pos, double radius) { BoundingSphere s(pos, radius); int blocksCleared = 0; v3di_t start = v3di_v(static_cast<int>(pos.x - (radius + 1)), static_cast<int>(pos.y - (radius + 1)), static_cast<int>(pos.z - (radius + 1))); v3di_t stop = v3di_v(static_cast<int>(pos.x + (radius + 1)), static_cast<int>(pos.y + (radius + 1)), static_cast<int>(pos.z + (radius + 1))); v3di_t i; for (i.z = start.z; i.z <= stop.z; i.z++) { for (i.y = start.y; i.y <= stop.y; i.y++) { for (i.x = start.x; i.x <= stop.x; i.x++) { if (s.isPointInside (v3d_v (static_cast<int>(i.x + 0.5), static_cast<int>(i.y + 0.5), static_cast<int>(i.z + 0.5)))) { clearBlock(i); } } } } return blocksCleared; // return 0; }
void WorldMap::fillVolume(v3di_t a, v3di_t b, int blockType) { if (a.x > b.x) { int temp = a.x; a.x = b.x; b.x = temp; } if (a.y > b.y) { int temp = a.y; a.y = b.y; b.y = temp; } if (a.z > b.z) { int temp = a.z; a.z = b.z; b.z = temp; } v3di_t pos; for (pos.z = a.z; pos.z <= b.z; pos.z++) { for (pos.y = a.y; pos.y <= b.y; pos.y++) { for (pos.x = a.x; pos.x <= b.x; pos.x++) { // clear first to ensure we have all the neighbors if (gBlockData.get(blockType)->solidityType != BLOCK_SOLIDITY_TYPE_ROCK || gBlockData.get(blockType)->alpha < 1.0) { clearBlock(pos); } setBlockType(pos, blockType); } } } }
void ScreenData::clearToEndOfScreen(int y) { auto it = it_for_row_ensure_single_line_block(y); while(it != m_screen_blocks.end()) { clearBlock(it); ++it; } }
void TextMgr::clearBlockInsideWindow(int16 windowRow, int16 windowColumn, int16 width, byte color) { int16 row; int16 column; if (!_messageState.window_Active) return; row = _messageState.textPos.row + windowRow; column = _messageState.textPos.column + windowColumn; clearBlock(row, column, row, column + width - 1, color); }
void ScreenData::clearToBeginningOfScreen(int y) { auto it = it_for_row_ensure_single_line_block(y); if (it != m_screen_blocks.end()) (*it)->clear(); while(it != m_screen_blocks.begin()) { --it; clearBlock(it); } }
int Game::destroyElements(list<ElementData*>* toDestroy) { int dstrBlocks = 0; if(toDestroy!=NULL) { for(list<ElementData*>::iterator it = toDestroy->begin(); it!=toDestroy->end(); it++) { clearBlock(*it); dstrBlocks++; } toDestroy->clear(); } return dstrBlocks; }
void WorldMap::clearBlock(const v3di_t& position) { int column = pickColumn(position); if (column == -1) { mOverdrawManager.setBlock(position, BLOCK_TYPE_AIR); return; } // just get out if there's no change block_t *block = mColumns[column].getBlockAtWorldPosition (position); if (block != NULL && block->type == BLOCK_TYPE_AIR) { return; } // FIXME: this will (re)generate rocky outcroppings...no good // but we need to do it to drill into the ground generateChunkContaining(mColumns[column], position); mColumns[column].clearBlockAtWorldPosition(position); // make note of that change... addToChangedList(column); // check if some plant is on top // FIXME: beware! this is recursive v3di_t neighborPosition = position; neighborPosition.y += 1; if (gBlockData.get(mColumns[column].getBlockType(neighborPosition))->solidityType == BLOCK_SOLIDITY_TYPE_PLANT) { clearBlock(neighborPosition); } // now deal with the boundary issues for (int i = 0; i < NUM_BLOCK_SIDES; i++) { neighborPosition = v3di_add(position, gBlockNeighborAddLookup[i]); int neighborColumn = pickColumn(neighborPosition); if (neighborColumn >= 0) { generateChunkContaining(mColumns[neighborColumn], neighborPosition); mColumns[neighborColumn].mNeedShadowVolume = true; addToChangedList(neighborColumn); } } }
void flash25spi::clearSector(unsigned int addr) { if (_sectorSize == 0) { clearBlock(addr); return; } addr &= ~(_sectorSize-1); enableWrite(); _enable->write(0); wait_us(1); _spi->write(0x20); _spi->write(HIGH(addr)); _spi->write(MID(addr)); _spi->write(LOW(addr)); wait_us(1); _enable->write(1); waitForWrite(); }
int Game::askUserToDo(Map & map, int & wait) { unsigned int x,y; do { _printer.printMessage(USER_ASKED_TO_DO,cout); //Prosba o wpisanie danych _user.makeStep(x,y); //uzytkownik wpisuje dane }while(x>map.getWidth()-1 || y>map.getHeight()-1); //Wstawianie bloku int result = putBlock(x,y,map); //reakcja na wstepny test czy w ogole sie da polozyc blok if(result == GAME_BUSY_BLOCK) { _printer.printMessage(GAME_BUSY_BLOCK,cout); wait++; } else if(result == GAME_IN_THE_AIR_BLOCK) //Jesli w powietrzu kamien { _printer.makeBoomConsole(); _printer.printMessage(GAME_IN_THE_AIR_BLOCK, cout); //To prosba, aby nie klasc w powietrzu kamieni bool destroyedBlock = false; for(int i= y; i>=0 && !destroyedBlock; i--) //Sprawdzenie czy spadl kamien na jakis inny { if(map(x,i,DIM_WEIGHT_TAB)!=EMPTY) //Jesli spadl to trzeba o tym poinformowac i usunac kamien { _destroyedBlocks++; _printer.printMessage(GAME_SAY_YOU_DESTROYED, cout); clearBlock(x,i,map); destroyedBlock = true; wait ++; }//Szukanie czy mozna rozbic jakis blok } _usedBlocks++; _destroyedBlocks++; wait++; } if(result == 0) { _usedBlocks++; } return result; }
void main() { int ch; x = 5; /*처음 좌표 */ y = 2; noCursor(); /* 커서 지움 */ printMap(); /* 맵 그리기 */ printBlock(); /* 블록 출력 */ for (; 1;) { //블록 움직임 반복 if (kbhit()) { // 키입력 처리 --------------------------------- clearBlock(); ch = getch(); if (ch == 0xE0) { //방향키를 눌럿을 때× ch = getch(); switch (ch) { case LEFT: x--; break; case RIGHT: x++; break; case DOWN: y++; break; case UP: sh++; if (sh > 3) sh = 0; break; } } printBlock(); } // ------------------- 키입력 처리 종료 Sleep(100); /* 0.1초간 대기 */ } }
void TextMgr::displayCharacter(byte character, bool disabledLook) { TextPos_Struct charCurPos; charPos_Get(&charCurPos); switch (character) { case 0x08: // backspace if (charCurPos.column) { charCurPos.column--; } else if (charCurPos.row > 21) { charCurPos.column = (FONT_COLUMN_CHARACTERS - 1); charCurPos.row--; } clearBlock(charCurPos.row, charCurPos.column, charCurPos.row, charCurPos.column, _textAttrib.background); charPos_Set(&charCurPos); break; case 0x0D: case 0x0A: // CR/LF if (charCurPos.row < (FONT_ROW_CHARACTERS - 1)) charCurPos.row++; charCurPos.column = _reset_Column; charPos_Set(&charCurPos); break; default: // ch_attrib(state.text_comb, conversion); _gfx->drawCharacter(charCurPos.row, charCurPos.column, character, _textAttrib.combinedForeground, _textAttrib.combinedBackground, disabledLook); charCurPos.column++; if (charCurPos.column <= (FONT_COLUMN_CHARACTERS - 1)) { charPos_Set(&charCurPos); } else { displayCharacter(0x0D); // go to next line } } }
void TextMgr::clearLines(int16 row_Upper, int16 row_Lower, byte color) { clearBlock(row_Upper, 0, row_Lower, FONT_COLUMN_CHARACTERS - 1, color); }
//----------------------------------------------------------------- // compress a byte void mgLZWEncode::compressByte( BYTE nByte) { if (m_firstByte) { // need to initialize nWaitingCode m_waitingCode = nByte; m_firstByte = FALSE; return; } // Probe hash table to see if a symbol exists for // waiting_code followed by nByte. HashInt i = ((HashInt) nByte << (MAX_LZW_BITS-8)) + m_waitingCode; HashInt nDisp; // i is less than twice 2**MAX_LZW_BITS, therefore less than twice HSIZE if (i >= HASH_SIZE) i -= HASH_SIZE; mgLZWHash lProbeValue = HASH_ENTRY(m_waitingCode, nByte); // is first probed slot not empty? if (m_hashCode[i] != 0) { if (m_hashValue[i] == lProbeValue) { m_waitingCode = m_hashCode[i]; return; } if (i == 0) // secondary hash (after G. Knott) nDisp = 1; else nDisp = HASH_SIZE - i; for (;;) { i -= nDisp; if (i < 0) i += HASH_SIZE; if (m_hashCode[i] == 0) break; // hit empty slot if (m_hashValue[i] == lProbeValue) { m_waitingCode = m_hashCode[i]; return; } } } // here when hashtable[i] is an empty slot; desired symbol not in table writeCode(m_waitingCode); if (m_freeCode < LZW_TABLE_SIZE) { m_hashCode[i] = m_freeCode++; // add symbol to hashtable m_hashValue[i] = lProbeValue; } else clearBlock(); m_waitingCode = nByte; }
void ufsInput(char *arq_sistema, char *arq_ufs, char *fs_name) { FILE* arq = fopen(arq_sistema, "r"); Filesystem fs = fileToFilesystem (fs_name); FILE* ufs = fopen(fs_name, "r+"); int32_t file_size = 0; //tamanho do file int32_t file_blocks = 0; //# blocos usado pelo file int32_t bsize; //block size int32_t i = 0, j = 0; //contadores int32_t c = 0; datablock dblock; char* full_name; Inode inode; if (arq == NULL) error ("Native FS -> Null file."); if (fs == NULL) error ("Filesystem -> Null file."); c = getFatherfromPathname(arq_ufs, fs, fs->inodes[0]); if(c < 0) error("Invalid pathname!"); if(fs->inodes[c]->number_of_blocks >= MAX_BLOCKS_PER_INODE) error("Diretory is full!"); bsize = fs->superblock->block_size; printAllInodes(fs); printf("\n\nAntes de calcular tamanho arquivo\n\n"); do{ fgetc(arq); if( feof(arq) ) break; else { file_size++; printf("\nLoop!\n"); } }while(true); fseek(arq, -file_size, SEEK_CUR); printf("File Size: %d\n", file_size); if(fs->superblock->number_of_inodes >= 1024) error ("Filesystem is full! (Unavailable Inodes)"); if(file_size == 0) file_blocks = 0; else file_blocks = (file_size + bsize-1) / bsize; if(fs->superblock->number_of_blocks + file_blocks > FILE_SIZE/bsize) error ("Filesystem is full! (Not enough Datablocks)"); fs->inodes[c]->number_of_blocks++; //inode = getFreeInode(fs); inode = createEmptyInode (fs, getFreeInode (fs)); printf("\nPeguei Inode Livre\n"); full_name = getFullNamefromPathname(arq_sistema); j = checkNameValidity(full_name); if(j<0) error("Invalid filename!"); if(j==1){} else strncpy(inode->type, getType(full_name), INODE_TYPE_SIZE); strncpy(inode->name, getName(full_name), INODE_NAME_SIZE); insertBlockInInode(inode->number, fs->inodes[c], fs, ufs); printf("\nInseri bloco no inode\n\n"); dblock.id = findDatablockByInode(c, fs); readBlocktoBlock(&dblock, bsize, ufs); setInodeAtBlock(c, &dblock, fs->inodes[c]); writeBlock(dblock.id, ufs, &dblock, bsize); printf("\nSalvei o novo inode pai!\n"); printAllInodes(fs); return; for (j=0;j<file_blocks;j++){ clearBlock(&dblock); dblock.id=j; if (j != file_blocks-1) readBlocktoBlock(&dblock, bsize, arq); else{ for(i=0;i<bsize;i++) { c = fgetc(arq); if(feof(arq) == EOF) break; dblock.content[i] = (char) c; } } getFreeDatablock(fs, &dblock); inode->number_of_blocks++; if(j < BLOCKS_PER_INODE-1){ inode->blocks[j] = dblock.id; writeBlock (dblock.id, ufs, &dblock, bsize); } //Fazer tratamento de indirecao } //salvar o inode de alguma forma c = findInodePosAtBlock(inode, bsize); if(c < 0) error("Couldn't find InodePosAtBlock"); dblock.id = findInodeBlock(inode, bsize); readBlocktoBlock(&dblock, bsize, ufs); setInodeAtBlock(c, &dblock, inode); writeBlock(dblock.id, ufs, &dblock, bsize); free(inode); free(fs); fclose(arq); fclose(ufs); }
void ScreenData::clear() { for (auto it = m_screen_blocks.begin(); it != m_screen_blocks.end(); ++it) { clearBlock(it); } }
void Game::clearBlock(unsigned int x, unsigned int y, Map & map) //Kasowanie bloku ze zwiekszeniem licznika rozbitych { clearBlock((ElementData*)&map(x,y)); }