fixed statistics

This commit is contained in:
2025-12-07 17:30:18 +01:00
parent 24779755a5
commit 2b4b07ae6a
10 changed files with 424 additions and 125 deletions

View File

@ -9,6 +9,10 @@
#include "../core/Config.h"
#include <SDL3/SDL.h>
// File-scope transport/spawn detection state
static uint64_t s_lastPieceSequence = 0;
static bool s_pendingTransport = false;
PlayingState::PlayingState(StateContext& ctx) : State(ctx) {}
void PlayingState::onEnter() {
@ -18,6 +22,12 @@ void PlayingState::onEnter() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[PLAYING] Resetting game with level %d", *ctx.startLevelSelection);
ctx.game->reset(*ctx.startLevelSelection);
}
if (ctx.game) {
s_lastPieceSequence = ctx.game->getCurrentPieceSequence();
s_pendingTransport = false;
}
// (transport state is tracked at file scope)
}
void PlayingState::onExit() {
@ -28,6 +38,10 @@ void PlayingState::onExit() {
}
void PlayingState::handleEvent(const SDL_Event& e) {
// If a transport animation is active, ignore gameplay input entirely.
if (GameRenderer::isTransportActive()) {
return;
}
// We keep short-circuited input here; main still owns mouse UI
if (e.type == SDL_EVENT_KEY_DOWN && !e.key.repeat) {
if (!ctx.game) return;
@ -130,10 +144,21 @@ void PlayingState::update(double frameMs) {
if (!ctx.game) return;
ctx.game->updateVisualEffects(frameMs);
// If a transport animation is active, pause gameplay updates and ignore inputs
if (GameRenderer::isTransportActive()) {
// Keep visual effects updating but skip gravity/timers while transport runs
return;
}
// forward per-frame gameplay updates (gravity, line effects)
if (!ctx.game->isPaused()) {
ctx.game->tickGravity(frameMs);
// Detect spawn event (sequence increment) and request transport effect
uint64_t seq = ctx.game->getCurrentPieceSequence();
if (seq != s_lastPieceSequence) {
s_lastPieceSequence = seq;
s_pendingTransport = true;
}
ctx.game->updateElapsedTime();
if (ctx.lineEffect && ctx.lineEffect->isActive()) {
@ -183,12 +208,20 @@ void PlayingState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect l
SDL_SetRenderScale(renderer, logicalScale, logicalScale);
// Render game content (no overlays)
// If a transport effect was requested due to a recent spawn, start it here so
// the renderer has the correct layout and renderer context to compute coords.
if (s_pendingTransport) {
GameRenderer::startTransportEffectForGame(ctx.game, ctx.blocksTex, 1200.0f, 1000.0f, logicalScale, (float)winW, (float)winH, 0.4f);
s_pendingTransport = false;
}
GameRenderer::renderPlayingState(
renderer,
ctx.game,
ctx.pixelFont,
ctx.lineEffect,
ctx.blocksTex,
ctx.statisticsPanelTex,
ctx.scorePanelTex,
1200.0f, // LOGICAL_W
1000.0f, // LOGICAL_H
@ -264,12 +297,17 @@ void PlayingState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect l
} else {
// Render normally directly to screen
if (s_pendingTransport) {
GameRenderer::startTransportEffectForGame(ctx.game, ctx.blocksTex, 1200.0f, 1000.0f, logicalScale, (float)winW, (float)winH, 0.4f);
s_pendingTransport = false;
}
GameRenderer::renderPlayingState(
renderer,
ctx.game,
ctx.pixelFont,
ctx.lineEffect,
ctx.blocksTex,
ctx.statisticsPanelTex,
ctx.scorePanelTex,
1200.0f,
1000.0f,