void Map::SetWall(int i, int j, int id) { if (GetWall(i, j) == id || !ValidateBlock(i, j)) return; walls[i][j].Id = id; if (id == 0) { if (blocks[i][j].Id == 0) blocks[i][j].lightSource = MAX_LIGHT; } UpdateBlock(i, j); UpdateNearBlocks(i, j); lightDirty = true; }
TBool CSuspendTest::ValidateAllBlocks( TUint32 aFillWord ) // // Checks that all blocks contain aFillWord // { test.Printf( _L("Validating all blocks\n") ); TBool failed = EFalse; for( TInt i = 0; (i < iBlockCount) && (!failed); i++ ) { failed = !ValidateBlock( i, aFillWord ); } return !failed; }
void StaticServer::Validate() const { wallclock_t start = wallclock(); cout << "Validating statics files: "; for( unsigned short y = 0; y < _descriptor.height; y += STATICBLOCK_CHUNK ) { for( unsigned short x = 0; x < _descriptor.width; x += STATICBLOCK_CHUNK ) { ValidateBlock( x, y ); } } wallclock_t end = wallclock(); long ms = wallclock_diff_ms( start, end ); cout << "Completed in " << ms << " ms." << endl; }
void Map::SetBlock(int i, int j, int id) { if (GetBlock(i, j) == id || !ValidateBlock(i, j)) return; if (id == 0) { blocks[i][j].Id = 0; if (walls[i][j].Id == 0) blocks[i][j].lightSource = MAX_LIGHT; } else { Block* block = Block::GetBlockById(id); blocks[i][j].Id = (char) id; blocks[i][j].lightSource = block->GetLightEmit(); blocks[i][j].hardness = block->GetHardness(); UpdateBlock(i, j); } UpdateNearBlocks(i, j); lightDirty = true; }
void Map::UpdateLight(int i, int j, float level, int previ, int prevj, bool recalculate) { if (level <= 1 || !ValidateBlock(i, j)) return; if (blocks[i][j].lightValue < level || (recalculate && blocks[i][j].lightValue == level)) blocks[i][j].lightValue = level; else return; lightUpdated++; if (blocks[i][j].Id > 0) --level; if (previ != i - 1 || prevj != j) UpdateLight(i - 1, j, level - 1, i, j); if (previ != i + 1 || prevj != j) UpdateLight(i + 1, j, level - 1, i, j); if (previ != i || prevj != j - 1) UpdateLight(i, j - 1, level - 1, i, j); if (previ != i || prevj != j + 1) UpdateLight(i, j + 1, level - 1, i, j); }
int Map::GetWall(int i, int j) { if (!ValidateBlock(i, j)) return 0; return walls[i][j].Id; }
bool Map::IsSolid(int i, int j) { if (!ValidateBlock(i, j)) return false; return Block::GetBlockById(blocks[i][j].Id)->IsSolid(); }
int Map::GetBlock(int i, int j) { if (!ValidateBlock(i, j)) return 0; return blocks[i][j].Id; }
void CSuspendTest::DoRandomWriteSoak() // // For each block issues an erase and then // starts issuing write requests. The intervals // between write requests are derived from the // pseudo-random number generator. // Each block is checked after is has been erased // // The same data is written each time. This data is // also generated from the random number generator. After // each erase the data is read back to check that it is // correct. // { test.Next( _L("Erase suspend soak test using random writes") ); TRandomGenerator random; random.SetSeed( 0x13E00103 ); test.Printf( _L("Preparing buffer") ); TBuf8<20> writeBuf; writeBuf.SetLength( writeBuf.MaxLength() ); for( TInt i = writeBuf.Length(); i > 0;) { --i; writeBuf[i] = static_cast<TUint8>( random.Next() ); } test.Printf( _L("Starting test") ); random.SetSeed( MAKE_TINT64( 0xA05BE111,0x00101111 ) ); iStartTime.HomeTime(); // // We repeat the test for each block, erasing block n and reading from // block (n+1) modulo iBlockCount // // // Writes are always done to the block that we just erased. This // TBool prevents us starting writes until we have erased a block. // TBool firstErase = ETrue; for(;;) { TimeSinceStart(); for( TInt eraseBlock = 0; eraseBlock < iBlockCount; eraseBlock++ ) { TUint32 writeBlock = eraseBlock - 1; if( 0 == eraseBlock ) { writeBlock = iBlockCount - 1; } TUint32 erasePos = eraseBlock * iBlockSize; TInt writePos = writeBlock * iBlockSize; test.Printf( _L("Erasing block %d, writing to block %d"), eraseBlock, writeBlock ); // // Zero the block we are about to erase // test( KErrNone == ZeroFillBlock( eraseBlock ) ); test( ValidateBlock( eraseBlock, 0 ) ); // // Start the erase // _LIT( KEraseNotify, "Main thread starting erase\n" ); test.Printf( KEraseNotify ); iEraser->EraseBlock( erasePos, iBlockSize ); // // Now we loop, waiting for random intervals, issuing // writes, until the erase completes // TBool didWrite = EFalse; while( !iEraser->CheckDone() ) { // // Get a pseudo-random interval between 0 and 524.288 milliseconds // TInt delayInMicroseconds = random.Next() % 0x80000; User::After( delayInMicroseconds ); if( !firstErase ) { test( KErrNone == iDrive.Write( writePos, writeBuf ) ); _LIT( KWriteNotify, "Done write" ); test.Printf( KWriteNotify ); didWrite = ETrue; } } // // Now check that the block was erased // test( ValidateBlock( eraseBlock, 0xFFFFFFFF ) ); firstErase = EFalse; // // Also check that the data written to the Flash is correct. // if( didWrite ) { TBuf8<20> readBuf; test( KErrNone == iDrive.Read( writePos, writeBuf.Length(), readBuf ) ); test( readBuf == writeBuf ); test.Printf( _L("Write data is ok") ); } } } }
void grid::check_block(int row, int col) { int score = 0; // Is the block even valid? if(validate_block(row, col) == BLOCK_TYPE_NOGOOD) { return; } block_type type = grid[row][col]->block_type(); int connected_above = 0; int connected_below = 0; //bool pointsAboveOrBelow = false; // Check above block for (int i = row - 1; i >= 0; --i) { if (validate_block(i, col) == type) { ++connected_above; } else { break; } } // Check below block for (int i = row + 1; i < GRID_MAX_ROWS; ++i) { if(ValidateBlock(i, col) == type) { ++connected_below; } else { break; } } if(connecteda_bove + connected_below >= 2) { //pointsAboveOrBelow = true; score += connected_above + connected_below; for (int i = row + connectedbelow; i >= row - connectedabove; --i) { grid[i][col]->kill(); } for (int i = row - connectedabove - 1; i >= 0; --i) { if (validate_block(i, col) != BLOCK_TYPE_NOGOOD) { grid[i][col]->Fall(); } else { break; } } } int connected_left = 0; int connected_right = 0; // Check left of block for (int i = col - 1; i >= 0; --i) { if(validate_block(row, i) == type) { ++connectedleft; } else { break; } } // Check right of block for (int i = col + 1; i < GRID_MAX_COLUMNS; ++i) { if (ValidateBlock(row, i) == blocktype) { ++connected_right; } else { break; } } // We need at least three connected blocks if (connected_left + connected_right >= 2) { // Add to score score += connectedleft + connectedright; for (int i = col - connectedleft; i <= col + connectedright; ++i) { // Run through blocks again and kill them grid[row][i]->kill(); } for (int i = col - connectedleft; i <= col + connectedright; ++i) { // Run through blocks than now need to fall //if(pointsAboveOrBelow && i == col) // Points scored in vertical direction, don't make // continue; for (int j = row - 1; j >= 1; --j) { if (validate_block(j, i) != BLOCK_TYPE_NOGOOD) { grid[j][i]->fall(); } else { break; } } } } if (score > 0) { // If the player scored any points // For the block we're checking score += 1; grid[row][col]->kill(); if (game::game_settings.cf_mode_unlocked) { audio_manager::get()->play_sound("yes!", 0); } if(score > 3) { // More than three blocks connected counts as a combo ++combos; score *= POINTS_PER_BLOCK; score += COMBO_POINTS * (score - 3); } else { score *= POINTS_PER_BLOCK; } this->score += score; //audio_manager::get()->play_sound("explosion", 0); } else { grid[row][col]->dont_check(); // If no points were scored, don't check this block anymore } }