Immediate Code Cleanup
This commit is contained in:
115
src/core/GlobalState.h
Normal file
115
src/core/GlobalState.h
Normal file
@ -0,0 +1,115 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
// Forward declarations
|
||||
class FontAtlas;
|
||||
class Game;
|
||||
class ScoreManager;
|
||||
class Starfield;
|
||||
class Starfield3D;
|
||||
class LineEffect;
|
||||
|
||||
/**
|
||||
* GlobalState - Centralized management of application-wide state
|
||||
*
|
||||
* Replaces global variables scattered throughout main.cpp
|
||||
* Provides controlled access to shared state between systems
|
||||
* Will eventually be replaced by proper dependency injection
|
||||
*/
|
||||
class GlobalState {
|
||||
public:
|
||||
// Singleton access (temporary until dependency injection is implemented)
|
||||
static GlobalState& instance();
|
||||
|
||||
// Initialization and cleanup
|
||||
void initialize();
|
||||
void shutdown();
|
||||
|
||||
// Application state flags
|
||||
bool running = true;
|
||||
bool isFullscreen = false;
|
||||
bool musicEnabled = true;
|
||||
bool musicStarted = false;
|
||||
bool musicLoaded = false;
|
||||
|
||||
// UI state flags
|
||||
bool showSettingsPopup = false;
|
||||
bool showExitConfirmPopup = false;
|
||||
int hoveredButton = -1; // -1 = none, 0 = play, 1 = level, 2 = settings
|
||||
|
||||
// Input state (will be migrated to InputManager)
|
||||
bool leftHeld = false;
|
||||
bool rightHeld = false;
|
||||
double moveTimerMs = 0.0;
|
||||
|
||||
// Loading state
|
||||
double loadingProgress = 0.0;
|
||||
int currentTrackLoading = 0;
|
||||
int totalTracks = 0;
|
||||
int startLevelSelection = 0;
|
||||
|
||||
// Timing
|
||||
Uint64 lastMs = 0;
|
||||
Uint64 loadStart = 0;
|
||||
|
||||
// Animation state
|
||||
double logoAnimCounter = 0.0;
|
||||
|
||||
// Level background caching
|
||||
int cachedLevel = -1;
|
||||
float levelFadeAlpha = 0.0f;
|
||||
float levelFadeElapsed = 0.0f;
|
||||
|
||||
// Viewport and scaling
|
||||
SDL_Rect logicalVP{0, 0, 1200, 1000}; // Will use Config::Logical constants
|
||||
float logicalScale = 1.0f;
|
||||
|
||||
// Fireworks system (for menu animation)
|
||||
struct BlockParticle {
|
||||
float x, y, vx, vy;
|
||||
int type;
|
||||
float life, maxLife;
|
||||
float size;
|
||||
};
|
||||
|
||||
struct TetrisFirework {
|
||||
std::vector<BlockParticle> particles;
|
||||
bool active = false;
|
||||
};
|
||||
|
||||
std::vector<TetrisFirework> fireworks;
|
||||
Uint64 lastFireworkTime = 0;
|
||||
|
||||
// Fireworks management methods
|
||||
void updateFireworks(double frameMs);
|
||||
void createFirework(float x, float y);
|
||||
void drawFireworks(SDL_Renderer* renderer, SDL_Texture* blocksTex);
|
||||
|
||||
// Reset methods for different states
|
||||
void resetGameState();
|
||||
void resetUIState();
|
||||
void resetAnimationState();
|
||||
|
||||
private:
|
||||
GlobalState() = default;
|
||||
~GlobalState() = default;
|
||||
GlobalState(const GlobalState&) = delete;
|
||||
GlobalState& operator=(const GlobalState&) = delete;
|
||||
|
||||
bool m_initialized = false;
|
||||
};
|
||||
|
||||
// Convenience accessors (temporary until proper dependency injection)
|
||||
namespace Globals {
|
||||
inline GlobalState& state() { return GlobalState::instance(); }
|
||||
|
||||
// Quick access to commonly used flags
|
||||
inline bool& running() { return state().running; }
|
||||
inline bool& musicEnabled() { return state().musicEnabled; }
|
||||
inline bool& showSettingsPopup() { return state().showSettingsPopup; }
|
||||
inline int& hoveredButton() { return state().hoveredButton; }
|
||||
inline double& logoAnimCounter() { return state().logoAnimCounter; }
|
||||
}
|
||||
Reference in New Issue
Block a user