-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAbstractGame.cpp
100 lines (81 loc) · 2.54 KB
/
AbstractGame.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright © 2013 Tom Tondeur
//
// This file is part of tt::Engine.
//
// tt::Engine is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// tt::Engine is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with tt::Engine. If not, see <http://www.gnu.org/licenses/>.
// __ __ ______ _
// / /_/ /__ _ / ____/___ ____ _(_)___ ___
// / __/ __(_|_) __/ / __ \/ __ `/ / __ \/ _ \
// / /_/ /__ _ / /___/ / / / /_/ / / / / / __/
// \__/\__(_|_)_____/_/ /_/\__, /_/_/ /_/\___/
// /____/
//
// AbstractGame.cpp : Copyright © 2013 Tom Tondeur
//
//------------
// Includes
//------------
#include "Helpers/stdafx.h"
#include "AbstractGame.h"
#include "Scenegraph/GameScene.h"
#include "Services/ServiceLocator.h"
//------------
// Defines
//------------
using namespace std;
//---------------------------------
// AbstractGame Implementation
//---------------------------------
AbstractGame::AbstractGame(void):m_pActiveScene(nullptr) // Default constructor
{
}
AbstractGame::~AbstractGame(void) // Destructor
{
for(auto pScene : m_GameScenes)
delete pScene.second;
}
void AbstractGame::InitializeGame(void)
{
auto pPhys = MyServiceLocator::GetInstance()->GetService<IPhysicsService>();
auto prevPhysScene = pPhys->GetActiveScene();
pPhys->SetActiveScene(pPhys->CreateScene() );
m_pActiveScene->Initialize();
m_pActiveScene->InitializeScene();
pPhys->SetActiveScene(prevPhysScene);
}
void AbstractGame::UpdateGame(const tt::GameContext& context)
{
m_pActiveScene->Update(context);
m_pActiveScene->UpdateScene(context);
}
void AbstractGame::DrawGame(const tt::GameContext& context)
{
m_pActiveScene->Draw(context);
m_pActiveScene->DrawScene(context);
}
void AbstractGame::SetActiveScene(const std::tstring& name)
{
auto it = m_GameScenes.find(name);
if(it == m_GameScenes.end())
throw exception();
m_pActiveScene = it->second;
}
void AbstractGame::AddGameScene(const std::tstring& sceneName, GameScene* pScene)
{
m_GameScenes.insert( make_pair(sceneName, pScene) );
}
GameScene* AbstractGame::GetActiveScene(void) const
{
return m_pActiveScene;
}