Files
spacetris/LOADING_FIX_SUMMARY.md
Gregor Klevze 66099809e0 feat: implement textured line clear effects and refine UI alignment
- **Visual Effects**: Upgraded line clear particles to use the game's block texture instead of simple circles, matching the reference web game's aesthetic.
- **Particle Physics**: Tuned particle velocity, gravity, and fade rates for a more dynamic explosion effect.
- **Rendering Integration**: Updated [main.cpp](cci:7://file:///d:/Sites/Work/tetris/src/main.cpp:0:0-0:0) and `GameRenderer` to pass the block texture to the effect system and correctly trigger animations upon line completion.
- **Menu UI**: Fixed [MenuState](cci:1://file:///d:/Sites/Work/tetris/src/states/MenuState.cpp:19:0-19:55) layout calculations to use fixed logical dimensions (1200x1000), ensuring consistent centering and alignment of the logo, buttons, and settings icon across different window sizes.
- **Code Cleanup**: Refactored `PlayingState` to delegate effect triggering to the rendering layer where correct screen coordinates are available.
2025-11-21 21:19:14 +01:00

1.6 KiB

Loading Screen Fix Summary

Issue

The loading screen was getting stuck at 99% and not transitioning to the main menu.

Root Cause Analysis

  1. Floating Point Precision: The loading progress calculation involved adding 0.2 + 0.7 + 0.1. In standard IEEE 754 double precision, this sum results in 0.9999999999999999, which is slightly less than 1.0.

    • The transition condition loadingProgress >= 1.0 failed because of this.
    • The percentage display showed 99% because int(0.999... * 100) is 99.
  2. Potential Thread Synchronization: There was a possibility that the audio loading thread finished loading all tracks but hadn't yet set the loadingComplete flag (e.g., due to a delay in thread cleanup/shutdown). This would prevent musicLoaded from becoming true, which is also required for the transition.

Fix Implemented

  1. Precision Handling: Added a check to force loadingProgress to 1.0 if it exceeds 0.99.

    if (loadingProgress > 0.99) loadingProgress = 1.0;
    
  2. Robust Completion Check: Modified the condition for musicLoaded to accept completion if the number of loaded tracks matches the expected total, even if the thread hasn't officially signaled completion yet.

    if (Audio::instance().isLoadingComplete() || (totalTracks > 0 && currentTrackLoading >= totalTracks)) {
        Audio::instance().shuffle();
        musicLoaded = true;
    }
    

Verification

  • Verified mathematically that the floating point sum was indeed < 1.0.
  • The code now explicitly handles this case and ensures a smooth transition to the main menu.