RioEngine  0.1
My first attempt to create a 3D WYSIWYG Game Engine
cdirector.cpp
Go to the documentation of this file.
1 //--------------------------------------------------------------- @License begins
2 // RioEngine: The late night Coke -without whores- debugging sessions
3 // 2012-2015 Leopoldo Lomas Flores. Torreon, Coahuila. MEXICO
4 // leopoldolomas [at] gmail
5 // www.rioengine.com
6 // www.leopoldolomas.info
7 // "You have a problem, you face it like a man."
8 //
9 // This is free and unencumbered software released into the public domain.
10 //
11 // Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
12 // software, either in source code form or as a compiled binary, for any purpose,
13 // commercial or non-commercial, and by any means.
14 //
15 // In jurisdictions that recognize copyright laws, the author or authors of this
16 // software dedicate any and all copyright interest in the software to the public
17 // domain. We make this dedication for the benefit of the public at large and to
18 // the detriment of our heirs and successors. We intend this dedication to be
19 // an overt act of relinquishment in perpetuity of all present and future
20 // rights to this software under copyright law.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS
24 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
26 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //--------------------------------------------------------------- @License ends
29 
30 #include <string>
31 #include "constants.h"
32 #include "misc/genericshelper.hpp"
34 #include "cengine/cgamescene.h"
35 #include "cengine/cactionmanager.h"
36 #include "cengine/ccamera.h"
37 #include "cengine/time_.h"
38 #include "cengine/cdirector.h"
39 
40 //-----------------------------------------------------------------------------
41 
43  m_cameras = new std::map<std::string, CCamera*>();
45 
47 }
48 
49 //-----------------------------------------------------------------------------
50 
52  return m_actionManager;
53 }
54 
55 //-----------------------------------------------------------------------------
56 
58  return m_gameState;
59 }
60 
61 //-----------------------------------------------------------------------------
62 
64  m_gameState = game_state;
65 }
66 
67 //-----------------------------------------------------------------------------
68 
70  return m_gameScene;
71 }
72 
73 //-----------------------------------------------------------------------------
74 
76  createCamera(k_CDirector_DefaultCameraId);
77  setActiveCameraHavingId(k_CDirector_DefaultCameraId);
78 }
79 
80 //-----------------------------------------------------------------------------
81 
83  std::map<std::string, CCamera*>::iterator it;
84  for(it = m_cameras->begin(); it != m_cameras->end(); ++it) {
85  SAFE_RELEASE(it->second);
86  }
87 }
88 
89 //-----------------------------------------------------------------------------
90 
91 CCamera* CDirector::createCamera(const std::string& camera_id) {
92  if (existsCameraWithId(camera_id)) {
93  return NULL; // TODO return the existing camera?
94  }
95 
96  // if the camera does not exist yet...
97  CCamera* new_camera = new CCamera();
98  m_cameras->insert(std::pair<std::string, CCamera*>(camera_id, new_camera));
99 
100  return new_camera;
101 }
102 
103 //-----------------------------------------------------------------------------
104 
105 CCamera* CDirector::getCameraWithId(const std::string& camera_id) const {
106  if (!existsCameraWithId(camera_id)) { // if the camera does not exist yet
107  return getCameraWithId(k_CDirector_DefaultCameraId); // return the default camera
108  }
109 
110  return m_cameras->at(camera_id);
111 }
112 
113 //-----------------------------------------------------------------------------
114 
115 const std::string& CDirector::getActiveCameraId() const {
116  return m_activeCameraId;
117 }
118 
119 //-----------------------------------------------------------------------------
120 
121 bool CDirector::isActiveCameraWithId(const std::string& camera_id) const {
122  return getActiveCameraId() == camera_id;
123 }
124 
125 //-----------------------------------------------------------------------------
126 
127 bool CDirector::existsCameraWithId(const std::string& camera_id) const {
128  return m_cameras->count(camera_id) > 0;
129 }
130 
131 //-----------------------------------------------------------------------------
132 
135 }
136 
137 //-----------------------------------------------------------------------------
138 
139 CCamera* CDirector::setActiveCameraHavingId(const std::string& camera_id) {
140  m_activeCameraId = (existsCameraWithId(camera_id) ? camera_id : k_CDirector_DefaultCameraId);
141 
142  return getActiveCamera();
143 }
144 
145 //-----------------------------------------------------------------------------
146 
148  std::map<std::string, CCamera*>::iterator it;
149  for(it = m_cameras->begin(); it != m_cameras->end(); ++it) {
150  it->second->reset();
151  }
152 }
153 
154 //-----------------------------------------------------------------------------
155 
157  RE_ASSERT(game_scene);
158  SAFE_RETAIN(game_scene);
159  m_gameScene = game_scene;
160  emit onRunScene(m_gameScene);
161 }
162 
163 //-----------------------------------------------------------------------------
164 
165 void CDirector::pushScene(CGameScene* game_scene) {
166  // TODO
167 }
168 
169 //-----------------------------------------------------------------------------
170 
172  // TODO
173 }
174 
175 //-----------------------------------------------------------------------------
176 
178  // TODO
179 }
180 
181 //-----------------------------------------------------------------------------
182 
186 }
187 
188 //-----------------------------------------------------------------------------
189 
193 }
194 
195 //-----------------------------------------------------------------------------
196 
198  INPUTMANAGER->update();
199  if (gameState() == RUNNING) {
203  }
204 }
205 
206 //-----------------------------------------------------------------------------
207 
212 }
virtual void replaceScene()
Definition: cdirector.cpp:177
CGameScene * currentGameScene() const
Definition: cdirector.cpp:69
static void deleteMap(std::map< TKey, TVal * > *map)
CCamera * setActiveCameraHavingId(const std::string &camera_id)
Definition: cdirector.cpp:139
void releaseCameras()
Definition: cdirector.cpp:82
virtual void onRunScene(CGameScene *game_scene)
virtual void popScene()
Definition: cdirector.cpp:171
bool existsCameraWithId(const std::string &camera_id) const
Definition: cdirector.cpp:127
virtual void resume()
Definition: cdirector.cpp:183
CActionManager * actionManager() const
Definition: cdirector.cpp:51
virtual void pause()
Definition: cdirector.cpp:190
CCamera * getActiveCamera() const
Definition: cdirector.cpp:133
CCamera * createCamera(const std::string &camera_id)
Definition: cdirector.cpp:91
virtual void onResumeScene(CGameScene *game_scene)
virtual void update()
Definition: cgamescene.cpp:170
virtual void onPauseScene(CGameScene *game_scene)
std::map< std::string, CCamera * > * m_cameras
Definition: cdirector.h:106
virtual void runWithScene(CGameScene *game_scene)
Definition: cdirector.cpp:156
#define SAFE_RELEASE(x)
Definition: cobject.h:36
void resetCameras()
Definition: cdirector.cpp:147
virtual void setGameState(GameState game_state)
Definition: cdirector.cpp:63
virtual void pushScene(CGameScene *game_scene)
Definition: cdirector.cpp:165
void update(double dt)
#define SAFE_RETAIN(x)
Definition: cobject.h:35
void createDefaultCamera()
Definition: cdirector.cpp:75
bool isActiveCameraWithId(const std::string &camera_id) const
Definition: cdirector.cpp:121
#define RE_ASSERT
Definition: macro.h:57
const std::string & getActiveCameraId() const
Definition: cdirector.cpp:115
virtual void preUpdate()
Definition: cgamescene.cpp:159
CGameScene * m_gameScene
Definition: cdirector.h:103
static float getDeltaTime()
Definition: time_.h:46
virtual void step()
Definition: cdirector.cpp:197
GameState gameState() const
Definition: cdirector.cpp:57
std::string m_activeCameraId
Definition: cdirector.h:105
CActionManager * m_actionManager
Definition: cdirector.h:104
CCamera * getCameraWithId(const std::string &camera_id) const
Definition: cdirector.cpp:105
#define INPUTMANAGER
Definition: inputmanager.h:39
GameState m_gameState
Definition: cdirector.h:102