- **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.
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
-
Floating Point Precision: The loading progress calculation involved adding
0.2 + 0.7 + 0.1. In standard IEEE 754 double precision, this sum results in0.9999999999999999, which is slightly less than1.0.- The transition condition
loadingProgress >= 1.0failed because of this. - The percentage display showed
99%becauseint(0.999... * 100)is99.
- The transition condition
-
Potential Thread Synchronization: There was a possibility that the audio loading thread finished loading all tracks but hadn't yet set the
loadingCompleteflag (e.g., due to a delay in thread cleanup/shutdown). This would preventmusicLoadedfrom becoming true, which is also required for the transition.
Fix Implemented
-
Precision Handling: Added a check to force
loadingProgressto1.0if it exceeds0.99.if (loadingProgress > 0.99) loadingProgress = 1.0; -
Robust Completion Check: Modified the condition for
musicLoadedto 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.