-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cpp
73 lines (58 loc) · 2.13 KB
/
Game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "Game.h"
Game::Game() : m_window("Chapter 12", sf::Vector2u(800, 600)),
m_entityManager(&m_systemManager, &m_textureManager), m_stateManager(&m_context),
m_guiManager(m_window.GetEventManager(), &m_context), m_soundManager(&m_audioManager)
{
m_clock.restart();
srand(time(nullptr));
m_systemManager.SetEntityManager(&m_entityManager);
m_context.m_wind = &m_window;
m_context.m_eventManager = m_window.GetEventManager();
m_context.m_textureManager = &m_textureManager;
m_context.m_fontManager = &m_fontManager;
m_context.m_audioManager = &m_audioManager;
m_context.m_soundManager = &m_soundManager;
m_context.m_systemManager = &m_systemManager;
m_context.m_entityManager = &m_entityManager;
m_context.m_guiManager = &m_guiManager;
m_systemManager.GetSystem<S_Sound>(System::Sound)->SetUp(&m_audioManager, &m_soundManager);
// Debug:
m_systemManager.m_debugOverlay = &m_context.m_debugOverlay;
m_fontManager.RequireResource("Main");
m_stateManager.SwitchTo(StateType::Intro);
}
Game::~Game(){
m_fontManager.ReleaseResource("Main");
}
sf::Time Game::GetElapsed(){ return m_clock.getElapsedTime(); }
void Game::RestartClock(){ m_elapsed = m_clock.restart(); }
Window* Game::GetWindow(){ return &m_window; }
void Game::Update(){
m_window.Update();
m_stateManager.Update(m_elapsed);
m_guiManager.Update(m_elapsed.asSeconds());
m_soundManager.Update(m_elapsed.asSeconds());
GUI_Event guiEvent;
while (m_context.m_guiManager->PollEvent(guiEvent)){
m_window.GetEventManager()->HandleEvent(guiEvent);
}
}
void Game::Render(){
m_window.BeginDraw();
// Render here.
m_stateManager.Draw();
sf::View CurrentView = m_window.GetRenderWindow()->getView();
m_window.GetRenderWindow()->setView(m_window.GetRenderWindow()->getDefaultView());
m_guiManager.Render(m_window.GetRenderWindow());
m_window.GetRenderWindow()->setView(CurrentView);
// Debug.
if(m_context.m_debugOverlay.Debug()){
m_context.m_debugOverlay.Draw(m_window.GetRenderWindow());
}
// End debug.
m_window.EndDraw();
}
void Game::LateUpdate(){
m_stateManager.ProcessRequests();
RestartClock();
}