Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ViewportManager.h
Go to the documentation of this file.
1#pragma once
2#include <vector>
3#include <unordered_map>
4#include <SDL3/SDL.h>
5
6
7// Simple Viewport manager singleton that computes up to 4 view rectangles
8// according to the number of players. Viewports are laid out as follows:
9// 1 player: full screen
10// 2 players: vertical split (2 columns)
11// 3 players: vertical split (3 columns)
12// 4 players: 2x2 grid
22
24{
25public:
28
30 {
32 return instance;
33 }
34 static ViewportManager& Get() { return GetInstance(); }
35
36 virtual void Render() ; // Render viewports (for debug purposes)
37
38 void Initialize(int w, int h);
39 void Shutdown();
41 bool RemovePlayer(short playerID);
42 void SetSize(int w, int h);
43 int GetPlayerCount() const { return static_cast<int>(m_players.size() == 0 ? 0 : m_players.size()); }
44
45 // Return view rects in the same order as m_players (if no players defined returns single full-screen rect)
46 const std::vector<SDL_FRect>& GetViewRects() const { return m_viewRects; }
47
48
50 const std::vector<short>& GetPlayers() const { return m_players; }
51 void UpdateViewports();
52
53private:
54 int m_width = 400;
55 int m_height = 320;
56 std::vector<SDL_FRect> m_viewRects;
57 std::vector<short> m_players; // ordered list of player ids
58 std::unordered_map<short,int> m_playerIndexMap;
59
61};
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
ViewportLayout
void SetSize(int w, int h)
bool GetViewRectForPlayer(short playerID, SDL_FRect &outRect) const
std::unordered_map< short, int > m_playerIndexMap
void Initialize(int w, int h)
std::vector< SDL_FRect > m_viewRects
ViewportLayout m_currentLayout
static ViewportManager & Get()
bool AddPlayer(short playerID, ViewportLayout viewportLayout)
const std::vector< SDL_FRect > & GetViewRects() const
std::vector< short > m_players
static ViewportManager & GetInstance()
virtual void Render()
int GetPlayerCount() const
const std::vector< short > & GetPlayers() const
bool RemovePlayer(short playerID)