Initial release: SDL Windows Tetris
This commit is contained in:
51
src/states/State.h
Normal file
51
src/states/State.h
Normal file
@ -0,0 +1,51 @@
|
||||
// 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;
|
||||
|
||||
// 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* backgroundTex = nullptr;
|
||||
SDL_Texture* blocksTex = nullptr;
|
||||
|
||||
// Audio / SFX - forward declared types in main
|
||||
// Pointers to booleans/flags used by multiple states
|
||||
bool* musicEnabled = nullptr;
|
||||
int* startLevelSelection = nullptr;
|
||||
int* hoveredButton = 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;
|
||||
};
|
||||
Reference in New Issue
Block a user