void GameTable::HandleSDLMouseEvent(SDL_Event& event) { if (state != GameTableState::Running && state != GameTableState::Paused) { ClearBlocks(false); return; } // Clear button state btnAddColumn->highlighted = false; btnPauseGame->highlighted = false; // Mouse position auto mousePos = SDL_Point{ event.button.x, event.button.y }; // Clear highlight state ClearBlocks(false); if (SDL_EnclosePoints(&mousePos, 1, tableDelimiter, nullptr) == SDL_TRUE) { // We are over the table if (state == GameTableState::Running) { ProcessInputOnBlocks(mousePos, event); } } else if (SDL_EnclosePoints(&mousePos, 1, &(btnAddColumn->rect), nullptr) == SDL_TRUE) { // We are over the add new column button btnAddColumn->highlighted = true; // We check if we can add a new column if (event.button.state == SDL_PRESSED && table->size() < colLimit) { // Add the new column AddNewColumn(); // Restart the timer for the new column timer->start(); } } else if (SDL_EnclosePoints(&mousePos, 1, &(btnPauseGame->rect), nullptr) == SDL_TRUE) { // We are over the pause button btnPauseGame->highlighted = true; if (event.button.state == SDL_PRESSED) { // Let's pause the game TogglePause(); } } }
void GameTable::ProcessInputOnBlocks(SDL_Point& mousePos, SDL_Event& event) { bool found = false; bool remove = false; Uint32 linkNR = 0; for (auto& p1 : *table) { auto col = p1.first; auto colRow = p1.second; // For each block in the current column for (auto& p2 : *colRow) { auto row = p2.first; auto block = p2.second; found = block != nullptr && block->IsHover(mousePos); if (found) { if (event.button.state == SDL_PRESSED) { MarkBlocks(block, true, true); linkNR = block->link; remove = true; } else { MarkBlocks(block, true, false); } break; } } if (found) { break; } } if (!found) { ClearBlocks(false); } if (remove && linkNR > 0) { GatherPoints(linkNR); RemoveBlocksAndUpdateTable(linkNR); } }
void GameTable::AddNewColumn() { if (state == GameTableState::Running) { // Clear blocks linked state ClearBlocks(true); // Move blocks to the left MoveColumnsLeft(); // Add the new column table->insert(std::make_pair(colLimit - 1, GenerateColumn(colLimit - 1))); // Recalculate linked state CalcLinkedBlocks(); } }
void GameTable::RemoveBlocksAndUpdateTable(Uint32 linkNr) { // Let's check if we should level up if (experience > expToLevelUp) { LevelUp(); ClearTable(); } else { // Let's stop the timer timer->stop(); for (auto blockPos : blockLinks[linkNr - 1]) { auto col = table->at(blockPos->x); col->erase(blockPos->y); if (col->size() == 0) { table->erase(blockPos->x); delete col; } delete blockPos; } UpdateTable(); ClearBlocks(true); CalcLinkedBlocks(); // Begin destruction animation animTimer->start(); state = GameTableState::InputDisabled; } }
DualErr Volume::Format() { DualErr derr; FatData fat; PGPBoolean allocedBlockBuf, lockedForFormat; PGPUInt8 *blockBuf; PGPUInt64 megsDisk; pgpAssert(Mounted()); pgpAssert(!LockedForReadWrite() || !LockedForFormat()); allocedBlockBuf = lockedForFormat = FALSE; megsDisk = (GetTotalBlocks() * kDefaultBlockSize) / kBytesPerMeg; // Can only format drives with standard block sizes. if (GetBlockSize() != kDefaultBlockSize) derr = DualErr(kPGDMinorError_CantFormatDrive); // Too big for format? if (derr.IsntError()) { if (GetBlockSize() > kMaxBlocksDiskWeFormat) derr = DualErr(kPGDMinorError_DiskTooBigToFormat); } // Get block buffer. if (derr.IsntError()) { derr = GetByteBuffer(kDefaultBlockSize, &blockBuf); allocedBlockBuf = derr.IsntError(); } // Lock the volume for format. if (derr.IsntError()) { derr = LockVolumeForFormat(); lockedForFormat = derr.IsntError(); } if (derr.IsntError()) { // Initialize FAT data. fat.fdFsId = kFS_FAT16; if (megsDisk < 2) { fat.fdFsId = kFS_FAT12; } else if ((megsDisk >= kMinFat32Megs) && IsWin95OSR2CompatibleMachine()) { fat.fdFsId = kFS_FAT32; } InitFatData(&fat, GetBlockSize()); derr = ClearBlocks(0, fat.fdFirstSecData); } // Write out the FAT data structures. if (derr.IsntError()) { BigFatBootFSInfo bfInfo; BootSector12 bb12; BootSector16 bb16; BootSector32 bb32; PGPUInt32 fat16Sig; PGPUInt64 pos; pgpAssert(sizeof(bb12) == kDefaultBlockSize); pgpAssert(sizeof(bb16) == kDefaultBlockSize); pgpAssert(sizeof(bb32) == kDefaultBlockSize); pgpClearMemory(blockBuf, kDefaultBlockSize); pos = 0; switch (fat.fdFsId) { case kFS_FAT12: // Init the boot block. InitFAT12BootBlock(GetBlockSize(), &fat, &bb12); // Write the boot block. derr = Write((PGPUInt8 *) &bb12, pos, 1); // Write the first FAT. if (derr.IsntError()) { pgpCopyMemory((PGPUInt8 *) &kFat12Sig, blockBuf, sizeof(kFat12Sig)); pos += fat.fdReservedSecs; derr = Write(blockBuf, pos, 1); } // Write the second FAT. if (derr.IsntError()) { pos += fat.fdFatSize; derr = Write(blockBuf, pos, 1); } break; case kFS_FAT16: // Init the boot block. InitFAT16BootBlock(GetBlockSize(), &fat, &bb16); // Decide on a FAT signature. fat16Sig = (megsDisk < 16 ? kUnder16MbFat16Sig : kOver16MbFat16Sig); // Write the boot block. derr = Write((PGPUInt8 *) &bb16, pos, 1); // Write the first FAT. if (derr.IsntError()) { pgpCopyMemory((PGPUInt8 *) &fat16Sig, blockBuf, sizeof(fat16Sig)); pos += fat.fdReservedSecs; derr = Write(blockBuf, pos, 1); } // Write the second FAT. if (derr.IsntError()) { pos += fat.fdFatSize; derr = Write(blockBuf, pos, 1); } break; case kFS_FAT32: // Init the boot block. InitFAT32BootBlock(GetBlockSize(), &fat, &bb32, &bfInfo); // Write the boot block. derr = Write((PGPUInt8 *) &bb32, pos, 1); // Write the BigFatBootInfo structure. if (derr.IsntError()) { pgpCopyMemory((PGPUInt8 *) &bfInfo, blockBuf, sizeof(bfInfo)); pos += bb32.bsFsInfoSec; derr = Write(blockBuf, pos, 1); } if (derr.IsntError()) { PGPUInt32 threeClusts[3]; threeClusts[0] = kFat32Clust1; threeClusts[1] = kFat32Clust2; threeClusts[2] = kFat32Clust3; pgpClearMemory(blockBuf, kDefaultBlockSize); pgpCopyMemory((PGPUInt8 *) &threeClusts, blockBuf, sizeof(threeClusts)); // Write the first FAT. pos = fat.fdReservedSecs; derr = Write(blockBuf, pos, 1); // Write the second FAT. if (derr.IsntError()) { pos += fat.fdFatSize; derr = Write(blockBuf, pos, 1); } } break; default: pgpAssert(FALSE); break; } } // Unlock the volume. if (lockedForFormat) { UnlockVolume(); } // Free our block buffer. if (allocedBlockBuf) { FreeByteBuffer(blockBuf); } return derr; }