69 lines
2.2 KiB
C++
69 lines
2.2 KiB
C++
// State.h - base class and shared context for app states
|
|
#pragma once
|
|
#include <SDL3/SDL.h>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
// Forward declarations for frequently used types
|
|
class Game;
|
|
class ScoreManager;
|
|
class Starfield;
|
|
class Starfield3D;
|
|
class FontAtlas;
|
|
class LineEffect;
|
|
|
|
// Forward declare StateManager so StateContext can hold a pointer without
|
|
// including the StateManager header here.
|
|
class StateManager;
|
|
|
|
// Shared context passed to states so they can access common resources
|
|
struct StateContext {
|
|
// Core subsystems (may be null if not available)
|
|
Game* game = nullptr;
|
|
ScoreManager* scores = nullptr;
|
|
Starfield* starfield = nullptr;
|
|
Starfield3D* starfield3D = nullptr;
|
|
FontAtlas* font = nullptr;
|
|
FontAtlas* pixelFont = nullptr;
|
|
LineEffect* lineEffect = nullptr;
|
|
|
|
// Textures
|
|
SDL_Texture* logoTex = nullptr;
|
|
SDL_Texture* logoSmallTex = nullptr;
|
|
int logoSmallW = 0;
|
|
int logoSmallH = 0;
|
|
SDL_Texture* backgroundTex = nullptr;
|
|
// backgroundTex is set once in `main.cpp` and passed to states via this context.
|
|
// Prefer reading this field instead of relying on any `extern SDL_Texture*` globals.
|
|
SDL_Texture* blocksTex = nullptr;
|
|
|
|
// Audio / SFX - forward declared types in main
|
|
// Pointers to booleans/flags used by multiple states
|
|
bool* musicEnabled = nullptr;
|
|
bool* musicStarted = nullptr;
|
|
bool* musicLoaded = nullptr;
|
|
int* startLevelSelection = nullptr;
|
|
int* hoveredButton = nullptr;
|
|
// Menu popups (exposed from main)
|
|
bool* showSettingsPopup = nullptr;
|
|
bool* showExitConfirmPopup = nullptr; // If true, show "Exit game?" confirmation while playing
|
|
int* exitPopupSelectedButton = nullptr; // 0 = YES, 1 = NO (default)
|
|
// Pointer to the application's StateManager so states can request transitions
|
|
StateManager* stateManager = nullptr;
|
|
};
|
|
|
|
class State {
|
|
public:
|
|
explicit State(StateContext& ctx) : ctx(ctx) {}
|
|
virtual ~State() = default;
|
|
|
|
virtual void onEnter() {}
|
|
virtual void onExit() {}
|
|
virtual void handleEvent(const SDL_Event& e) {}
|
|
virtual void update(double frameMs) {}
|
|
virtual void render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logicalVP) {}
|
|
|
|
protected:
|
|
StateContext& ctx;
|
|
};
|