Mercurial > fife-parpg
comparison engine/core/view/view.cpp @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 90005975cdbb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2008 by the FIFE team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program is distributed in the hope that it will be useful, * | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 // Standard C++ library includes | |
23 #include <iostream> | |
24 #include <algorithm> | |
25 #include <set> | |
26 | |
27 // 3rd party library includes | |
28 | |
29 // FIFE includes | |
30 // These includes are split up in two parts, separated by one empty line | |
31 // First block: files included from the FIFE root src directory | |
32 // Second block: files included from the same folder | |
33 #include "video/renderbackend.h" | |
34 #include "video/imagepool.h" | |
35 #include "video/animationpool.h" | |
36 | |
37 #include "util/log/logger.h" | |
38 #include "model/structures/location.h" | |
39 | |
40 #include "camera.h" | |
41 #include "view.h" | |
42 | |
43 namespace FIFE { | |
44 static Logger _log(LM_VIEWVIEW); | |
45 | |
46 View::View(RenderBackend* renderbackend, ImagePool* ipool, AnimationPool* apool): | |
47 m_cameras(), | |
48 m_renderbackend(renderbackend), | |
49 m_ipool(ipool), | |
50 m_apool(apool), | |
51 m_renderers() { | |
52 } | |
53 | |
54 View::~View() { | |
55 clearCameras(); | |
56 std::map<std::string, RendererBase*>::iterator r_it = m_renderers.begin(); | |
57 for(; r_it != m_renderers.end(); ++r_it) { | |
58 delete r_it->second; | |
59 } | |
60 m_renderers.clear(); | |
61 } | |
62 | |
63 void View::clearCameras() { | |
64 std::vector<Camera*>::iterator cam_it = m_cameras.begin(); | |
65 for(; cam_it != m_cameras.end(); ++cam_it) { | |
66 delete *cam_it; | |
67 } | |
68 m_cameras.clear(); | |
69 } | |
70 | |
71 | |
72 Camera* View::addCamera(const std::string& id, Layer *layer, Rect viewport, ExactModelCoordinate emc) { | |
73 if (getCamera(id)) { | |
74 throw NameClash("Duplicate camera id registered."); | |
75 } | |
76 Camera* cam = new Camera(id, layer, viewport, emc, m_renderbackend, m_ipool, m_apool); | |
77 m_cameras.push_back(cam); | |
78 | |
79 std::map<std::string, RendererBase*>::iterator r_it = m_renderers.begin(); | |
80 for(; r_it != m_renderers.end(); ++r_it) { | |
81 cam->addRenderer(r_it->second->clone()); | |
82 } | |
83 return cam; | |
84 } | |
85 | |
86 Camera* View::getCamera(const std::string& id) { | |
87 std::vector<Camera*>::iterator it = m_cameras.begin(); | |
88 for (; it != m_cameras.end(); ++it) { | |
89 if ((*it)->getId() == id) | |
90 return *it; | |
91 } | |
92 return NULL; | |
93 } | |
94 | |
95 void View::removeCamera(Camera* camera) { | |
96 std::vector<Camera*>::iterator it = std::find(m_cameras.begin(), m_cameras.end(), camera); | |
97 if (it != m_cameras.end()) { | |
98 m_cameras.erase(it); | |
99 } | |
100 } | |
101 | |
102 void View::resetRenderers() { | |
103 std::vector<Camera*>::iterator it = m_cameras.begin(); | |
104 while (it != m_cameras.end()) { | |
105 (*it)->resetRenderers(); | |
106 ++it; | |
107 } | |
108 } | |
109 | |
110 void View::update() { | |
111 FL_DBG(_log, "In View::update"); | |
112 | |
113 // update each camera | |
114 std::vector<Camera*>::iterator cam_it = m_cameras.begin(); | |
115 for (; cam_it != m_cameras.end(); ++cam_it) { | |
116 Camera* cam = *cam_it; | |
117 if (!cam->isEnabled()) { | |
118 continue; | |
119 } | |
120 cam->update(); | |
121 cam->render(); | |
122 } | |
123 } | |
124 | |
125 void View::addRenderer(RendererBase* renderer) { | |
126 m_renderers[renderer->getName()] = renderer; | |
127 } | |
128 } | |
129 |