Mercurial > fife-parpg
comparison engine/core/model/structures/map.cpp @ 422:9d94f4676d17
Moved the management of cameras into the Map class. The View class no longer exists since it now serves no purpose. The engine class itself holds the renderers and these get passed to each map that is loaded and then passed to each camera on each map. This change makes it possible for multiple maps to be loaded at the same time with the same camera id without a name clash. fixes[t:342]
author | vtchill@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 12 Feb 2010 06:34:50 +0000 |
parents | 90005975cdbb |
children | c9113e23b004 |
comparison
equal
deleted
inserted
replaced
421:293e812316c0 | 422:9d94f4676d17 |
---|---|
29 // These includes are split up in two parts, separated by one empty line | 29 // These includes are split up in two parts, separated by one empty line |
30 // First block: files included from the FIFE root src directory | 30 // First block: files included from the FIFE root src directory |
31 // Second block: files included from the same folder | 31 // Second block: files included from the same folder |
32 #include "util/base/exception.h" | 32 #include "util/base/exception.h" |
33 #include "util/structures/purge.h" | 33 #include "util/structures/purge.h" |
34 #include "util/structures/rect.h" | |
35 #include "view/camera.h" | |
36 #include "view/rendererbase.h" | |
37 #include "video/renderbackend.h" | |
38 #include "video/imagepool.h" | |
39 #include "video/animationpool.h" | |
34 | 40 |
35 #include "map.h" | 41 #include "map.h" |
36 #include "layer.h" | 42 #include "layer.h" |
37 | 43 |
38 namespace FIFE { | 44 namespace FIFE { |
39 | 45 |
40 Map::Map(const std::string& identifier, TimeProvider* tp_master): | 46 Map::Map(const std::string& identifier, RenderBackend* renderBackend, |
47 const std::vector<RendererBase*>& renderers, ImagePool* imagePool, | |
48 AnimationPool* animPool, TimeProvider* tp_master): | |
41 m_id(identifier), | 49 m_id(identifier), |
42 m_timeprovider(tp_master), | 50 m_timeprovider(tp_master), |
43 m_changelisteners(), | 51 m_changelisteners(), |
44 m_changedlayers(), | 52 m_changedlayers(), |
45 m_changed(false) { | 53 m_changed(false), |
54 m_renderbackend(renderBackend), | |
55 m_imagepool(imagePool), | |
56 m_animpool(animPool), | |
57 m_renderers(renderers) { | |
58 | |
46 } | 59 } |
47 | 60 |
48 Map::~Map() { | 61 Map::~Map() { |
49 deleteLayers(); | 62 deleteLayers(); |
50 } | 63 } |
125 while (i != m_changelisteners.end()) { | 138 while (i != m_changelisteners.end()) { |
126 (*i)->onMapChanged(this, m_changedlayers); | 139 (*i)->onMapChanged(this, m_changedlayers); |
127 ++i; | 140 ++i; |
128 } | 141 } |
129 } | 142 } |
143 | |
144 // loop over cameras and update if enabled | |
145 std::vector<Camera*>::iterator camIter = m_cameras.begin(); | |
146 for ( ; camIter != m_cameras.end(); ++camIter) { | |
147 if ((*camIter)->isEnabled()) { | |
148 (*camIter)->update(); | |
149 (*camIter)->render(); | |
150 } | |
151 } | |
152 | |
130 bool retval = m_changed; | 153 bool retval = m_changed; |
131 m_changed = false; | 154 m_changed = false; |
132 return retval; | 155 return retval; |
133 } | 156 } |
134 | 157 |
145 } | 168 } |
146 ++i; | 169 ++i; |
147 } | 170 } |
148 } | 171 } |
149 | 172 |
173 Camera* Map::addCamera(const std::string &id, Layer *layer, | |
174 const Rect& viewport, const ExactModelCoordinate& emc) { | |
175 if (layer == NULL) { | |
176 throw NotSupported("Must have valid layer for camera"); | |
177 } | |
178 | |
179 if (getCamera(id)) { | |
180 std::string errorStr = "Camera: " + id + " already exists"; | |
181 throw NameClash(errorStr); | |
182 } | |
183 | |
184 // create new camera and add to list of cameras | |
185 Camera* camera = new Camera(id, layer, viewport, emc, m_renderbackend, m_imagepool, m_animpool); | |
186 m_cameras.push_back(camera); | |
187 | |
188 std::vector<RendererBase*>::iterator iter = m_renderers.begin(); | |
189 for ( ; iter != m_renderers.end(); ++iter) { | |
190 camera->addRenderer((*iter)->clone()); | |
191 } | |
192 | |
193 return camera; | |
194 } | |
195 | |
196 void Map::removeCamera(const std::string &id) { | |
197 std::vector<Camera*>::iterator iter = m_cameras.begin(); | |
198 for ( ; iter != m_cameras.end(); ++iter) { | |
199 if ((*iter)->getId() == id) { | |
200 // camera has been found delete it | |
201 delete *iter; | |
202 | |
203 // now remove it from the vector | |
204 // note this invalidates iterators, but we do not need | |
205 // to worry about it in this case since we are done | |
206 m_cameras.erase(iter); | |
207 | |
208 break; | |
209 } | |
210 } | |
211 } | |
212 | |
213 Camera* Map::getCamera(const std::string &id) { | |
214 std::vector<Camera*>::iterator iter = m_cameras.begin(); | |
215 for ( ; iter != m_cameras.end(); ++iter) { | |
216 if ((*iter)->getId() == id) { | |
217 return *iter; | |
218 } | |
219 } | |
220 | |
221 return NULL; | |
222 } | |
223 | |
224 std::vector<Camera*>& Map::getCameras() { | |
225 return m_cameras; | |
226 } | |
227 | |
150 } //FIFE | 228 } //FIFE |
151 | 229 |