minor fixes
This commit is contained in:
@ -685,6 +685,13 @@ void TetrisApp::Impl::runLoop()
|
||||
challengeClearFxOrder.push_back(idx);
|
||||
}
|
||||
}
|
||||
// Seed FX RNG deterministically from the game's challenge seed so animations
|
||||
// are reproducible per-run and per-level. Fall back to a random seed if game absent.
|
||||
if (game) {
|
||||
challengeClearFxRng.seed(game->getChallengeSeedBase() + static_cast<uint32_t>(nextLevel));
|
||||
} else {
|
||||
challengeClearFxRng.seed(std::random_device{}());
|
||||
}
|
||||
std::shuffle(challengeClearFxOrder.begin(), challengeClearFxOrder.end(), challengeClearFxRng);
|
||||
|
||||
challengeClearFxElapsedMs = 0.0;
|
||||
|
||||
@ -278,7 +278,7 @@ void Game::placeAsteroidsForLevel(int level) {
|
||||
}
|
||||
AsteroidType type = chooseAsteroidTypeForLevel(level);
|
||||
AsteroidCell cell = makeAsteroidForType(type);
|
||||
board[idx] = ASTEROID_BASE + static_cast<int>(type);
|
||||
board[idx] = asteroidBoardValue(type);
|
||||
asteroidGrid[idx] = cell;
|
||||
++asteroidsRemainingCount;
|
||||
++asteroidsTotalThisLevel;
|
||||
@ -289,6 +289,22 @@ void Game::placeAsteroidsForLevel(int level) {
|
||||
}
|
||||
}
|
||||
|
||||
// Helper implementations for asteroid board encoding
|
||||
bool Game::isAsteroidValue(int boardValue) {
|
||||
return boardValue >= ASTEROID_BASE;
|
||||
}
|
||||
|
||||
AsteroidType Game::asteroidTypeFromValue(int boardValue) {
|
||||
int idx = boardValue - ASTEROID_BASE;
|
||||
if (idx < 0) return AsteroidType::Normal;
|
||||
if (idx > static_cast<int>(AsteroidType::Core)) idx = static_cast<int>(AsteroidType::Core);
|
||||
return static_cast<AsteroidType>(idx);
|
||||
}
|
||||
|
||||
int Game::asteroidBoardValue(AsteroidType t) {
|
||||
return ASTEROID_BASE + static_cast<int>(t);
|
||||
}
|
||||
|
||||
double Game::elapsed() const {
|
||||
if (!_startTime) return 0.0;
|
||||
|
||||
@ -519,11 +535,8 @@ int Game::checkLines() {
|
||||
for (int y : completedLines) {
|
||||
for (int x = 0; x < COLS; ++x) {
|
||||
int idx = y * COLS + x;
|
||||
if (board[idx] >= ASTEROID_BASE) {
|
||||
int typeIdx = board[idx] - ASTEROID_BASE;
|
||||
if (typeIdx >= 0 && typeIdx <= static_cast<int>(AsteroidType::Core)) {
|
||||
foundType = static_cast<AsteroidType>(typeIdx);
|
||||
}
|
||||
if (isAsteroidValue(board[idx])) {
|
||||
foundType = asteroidTypeFromValue(board[idx]);
|
||||
} else if (idx >= 0 && idx < static_cast<int>(asteroidGrid.size()) && asteroidGrid[idx].has_value()) {
|
||||
foundType = asteroidGrid[idx]->type;
|
||||
}
|
||||
@ -643,7 +656,7 @@ void Game::handleAsteroidsOnClearedRows(const std::vector<int>& clearedRows,
|
||||
continue; // off the board after collapse
|
||||
}
|
||||
int destIdx = destY * COLS + x;
|
||||
outBoard[destIdx] = ASTEROID_BASE + static_cast<int>(cell.type);
|
||||
outBoard[destIdx] = asteroidBoardValue(cell.type);
|
||||
outAsteroids[destIdx] = cell;
|
||||
} else {
|
||||
int destY = y + clearedBelow[y];
|
||||
|
||||
@ -185,6 +185,15 @@ private:
|
||||
|
||||
// Recent asteroid explosion positions (grid coords) for renderer FX
|
||||
std::vector<SDL_Point> recentAsteroidExplosions;
|
||||
|
||||
// Expose the internal challenge seed base for deterministic FX/RNG coordination
|
||||
public:
|
||||
uint32_t getChallengeSeedBase() const { return challengeSeedBase; }
|
||||
|
||||
// Helpers for board encoding of asteroids
|
||||
static bool isAsteroidValue(int boardValue);
|
||||
static AsteroidType asteroidTypeFromValue(int boardValue);
|
||||
static int asteroidBoardValue(AsteroidType t);
|
||||
|
||||
// Internal helpers ----------------------------------------------------
|
||||
void refillBag();
|
||||
|
||||
Reference in New Issue
Block a user