Mercurial > fife-parpg
changeset 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]
line wrap: on
line diff
--- a/demos/rio_de_hola/maps/shrine.xml Thu Feb 11 04:18:42 2010 +0000 +++ b/demos/rio_de_hola/maps/shrine.xml Fri Feb 12 06:34:50 2010 +0000 @@ -6110,8 +6110,8 @@ <i x="-19.0" o="beach_bar" z="0.0" y="2.0" r="180"></i> </instances> </layer> - <camera ref_cell_width="64" zoom="1.0" tilt="-42.0" id="shrine_main" ref_layer_id="TechdemoMapGroundObjectLayer" ref_cell_height="48" rotation="45.0"> + <camera ref_cell_width="64" zoom="1.0" tilt="-42.0" id="main" ref_layer_id="TechdemoMapGroundObjectLayer" ref_cell_height="48" rotation="45.0"> </camera> - <camera ref_cell_width="128" zoom="1.0" tilt="-42.0" viewport="10,10,400,250" id="shrine_small" ref_layer_id="TechdemoMapTileLayer" ref_cell_height="96" rotation="45.0"> + <camera ref_cell_width="128" zoom="1.0" tilt="-42.0" viewport="10,10,400,250" id="small" ref_layer_id="TechdemoMapTileLayer" ref_cell_height="96" rotation="45.0"> </camera> </map>
--- a/demos/rio_de_hola/maps/tourist_beach.xml Thu Feb 11 04:18:42 2010 +0000 +++ b/demos/rio_de_hola/maps/tourist_beach.xml Fri Feb 12 06:34:50 2010 +0000 @@ -4792,8 +4792,8 @@ <instances> </instances> </layer> - <camera ref_cell_width="128" zoom="0.822702474792" tilt="-42.0" viewport="0,0,1280,960" id="tourist_beach_main" ref_layer_id="TileLayer" ref_cell_height="96" rotation="45.0"> + <camera ref_cell_width="128" zoom="0.822702474792" tilt="-42.0" viewport="0,0,1280,960" id="main" ref_layer_id="TileLayer" ref_cell_height="96" rotation="45.0"> </camera> - <camera ref_cell_width="128" zoom="1.0" tilt="-42.0" viewport="10,10,400,250" id="tourist_beach_small" ref_layer_id="TileLayer" ref_cell_height="96" rotation="45.0"> + <camera ref_cell_width="128" zoom="1.0" tilt="-42.0" viewport="10,10,400,250" id="small" ref_layer_id="TileLayer" ref_cell_height="96" rotation="45.0"> </camera> </map>
--- a/demos/rio_de_hola/scripts/world.py Thu Feb 11 04:18:42 2010 +0000 +++ b/demos/rio_de_hola/scripts/world.py Fri Feb 12 06:34:50 2010 +0000 @@ -75,7 +75,6 @@ self.engine = engine self.eventmanager = engine.getEventManager() self.model = engine.getModel() - self.view = self.engine.getView() self.filename = '' self.pump_ctr = 0 # for testing purposis self.ctrldown = False @@ -199,13 +198,13 @@ camera_prefix = camera_prefix.rpartition('/')[2] # Remove path camera_prefix += '_' - for cam in self.view.getCameras(): + for cam in self.map.getCameras(): camera_id = cam.getId().replace(camera_prefix, '') self.cameras[camera_id] = cam + cam.resetRenderers() self.cameras['main'].attach(self.hero.agent) - self.view.resetRenderers() # Floating text renderers currntly only support one font. # ... so we set that up. # You'll se that for our demo we use a image font, so we have to specify the font glyphs @@ -274,7 +273,6 @@ c.setEnabled(not c.isEnabled()) elif keystr == 'r': self.model.deleteMaps() - self.view.clearCameras() self.load(self.filename) elif keystr == 'o': self.target_rotation = (self.target_rotation + 90) % 360
--- a/engine/core/controller/engine.cpp Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/core/controller/engine.cpp Fri Feb 12 06:34:50 2010 +0000 @@ -63,7 +63,6 @@ #include "pathfinder/routepather/routepather.h" #include "model/metamodel/grids/hexgrid.h" #include "model/metamodel/grids/squaregrid.h" -#include "view/view.h" #include "view/renderers/camerazonerenderer.h" #include "view/renderers/quadtreerenderer.h" #include "view/renderers/gridrenderer.h" @@ -101,7 +100,6 @@ m_vfs(0), m_model(0), m_gui_graphics(0), - m_view(0), m_logmanager(0), m_cursor(0), m_settings() { @@ -231,27 +229,25 @@ m_soundmanager = new SoundManager(m_soundclippool); m_soundmanager->setVolume(static_cast<float>(m_settings.getInitialVolume()) / 10); + FL_LOG(_log, "Creating renderers"); + m_renderers.push_back(new CameraZoneRenderer(m_renderbackend, 0, m_imagepool)); + m_renderers.push_back(new InstanceRenderer(m_renderbackend, 10, m_imagepool, m_animpool)); + m_renderers.push_back(new GridRenderer(m_renderbackend, 20)); + m_renderers.push_back(new CellSelectionRenderer(m_renderbackend, 30)); + m_renderers.push_back(new BlockingInfoRenderer(m_renderbackend, 40)); + m_renderers.push_back(new FloatingTextRenderer(m_renderbackend, 50, dynamic_cast<AbstractFont*>(m_defaultfont))); + m_renderers.push_back(new QuadTreeRenderer(m_renderbackend, 60)); + m_renderers.push_back(new CoordinateRenderer(m_renderbackend, 70, dynamic_cast<AbstractFont*>(m_defaultfont))); + m_renderers.push_back(new GenericRenderer(m_renderbackend, 80, m_imagepool, m_animpool)); + FL_LOG(_log, "Creating model"); - m_model = new Model(); + m_model = new Model(m_renderbackend, m_renderers, m_imagepool, m_animpool); FL_LOG(_log, "Adding pathers to model"); -// m_model->adoptPather(new LinearPather()); m_model->adoptPather(new RoutePather()); FL_LOG(_log, "Adding grid prototypes to model"); m_model->adoptCellGrid(new SquareGrid()); m_model->adoptCellGrid(new HexGrid()); - FL_LOG(_log, "Creating view"); - m_view = new View(m_renderbackend, m_imagepool, m_animpool); - FL_LOG(_log, "Creating renderers to view"); - m_view->addRenderer(new CameraZoneRenderer(m_renderbackend, 0, m_imagepool)); - m_view->addRenderer(new InstanceRenderer(m_renderbackend, 10, m_imagepool, m_animpool)); - m_view->addRenderer(new GridRenderer(m_renderbackend, 20)); - m_view->addRenderer(new CellSelectionRenderer(m_renderbackend, 30)); - m_view->addRenderer(new BlockingInfoRenderer(m_renderbackend, 40)); - m_view->addRenderer(new FloatingTextRenderer(m_renderbackend, 50, dynamic_cast<AbstractFont*>(m_defaultfont))); - m_view->addRenderer(new QuadTreeRenderer(m_renderbackend, 60)); - m_view->addRenderer(new CoordinateRenderer(m_renderbackend, 70, dynamic_cast<AbstractFont*>(m_defaultfont))); - m_view->addRenderer(new GenericRenderer(m_renderbackend, 80, m_imagepool, m_animpool)); m_cursor = new Cursor(m_imagepool, m_animpool, m_renderbackend); FL_LOG(_log, "Engine intialized"); } @@ -265,7 +261,6 @@ void Engine::destroy() { FL_LOG(_log, "Destructing engine"); delete m_cursor; - delete m_view; delete m_model; delete m_soundmanager; delete m_guimanager; @@ -278,6 +273,14 @@ delete m_imagepool; delete m_eventmanager; + // properly remove all the renderers created during init + std::vector<RendererBase*>::iterator rendererIter = m_renderers.begin(); + for ( ; rendererIter != m_renderers.end(); ++rendererIter) + { + delete *rendererIter; + } + m_renderers.clear(); + m_renderbackend->deinit(); delete m_renderbackend; @@ -303,7 +306,6 @@ m_renderbackend->startFrame(); m_timemanager->update(); m_model->update(); - m_view->update(); m_guimanager->turn(); m_cursor->draw(); m_renderbackend->endFrame();
--- a/engine/core/controller/engine.h Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/core/controller/engine.h Fri Feb 12 06:34:50 2010 +0000 @@ -56,12 +56,12 @@ class TimeManager; class ImagePool; class AnimationPool; - class View; class Model; class LogManager; class GuiFont; class Cursor; class SoundClipPool; + class RendererBase; /** Engine acts as a controller to the whole system @@ -143,10 +143,6 @@ */ Model* getModel() const { return m_model; } - /** Provides access point to the View - */ - View* getView() const { return m_view; } - /** Provides access point to the LogManager */ LogManager* getLogManager() const { return m_logmanager; } @@ -177,7 +173,6 @@ VFS* m_vfs; Model* m_model; gcn::Graphics* m_gui_graphics; - View* m_view; LogManager* m_logmanager; GuiFont* m_defaultfont; Cursor* m_cursor; @@ -185,6 +180,8 @@ EngineSettings m_settings; + std::vector<RendererBase*> m_renderers; + #ifdef USE_COCOA objc_object *m_autoreleasePool; #endif
--- a/engine/core/controller/engine.i Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/core/controller/engine.i Fri Feb 12 06:34:50 2010 +0000 @@ -33,12 +33,12 @@ class AnimationPool; class SoundClipPool; class RenderBackend; - class View; class Model; class LogManager; class GuiFont; class VFS; class Cursor; + class RendererBase; class EngineSettings { public: @@ -99,7 +99,6 @@ AnimationPool* getAnimationPool(); SoundClipPool* getSoundClipPool(); RenderBackend* getRenderBackend(); - View* getView(); Model* getModel(); LogManager* getLogManager(); GuiFont* getDefaultFont();
--- a/engine/core/model/model.cpp Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/core/model/model.cpp Fri Feb 12 06:34:50 2010 +0000 @@ -35,16 +35,26 @@ #include "structures/layer.h" #include "structures/instance.h" #include "util/base/exception.h" +#include "view/rendererbase.h" +#include "video/renderbackend.h" +#include "video/imagepool.h" +#include "video/animationpool.h" #include "model.h" namespace FIFE { - Model::Model(): + Model::Model(RenderBackend* renderbackend, const std::vector<RendererBase*>& renderers, + ImagePool* imagepool, AnimationPool* animpool): FifeClass(), m_last_namespace(NULL), + m_renderbackend(renderbackend), + m_renderers(renderers), + m_imagepool(imagepool), + m_animpool(animpool), m_timeprovider(NULL) { - } + + } Model::~Model() { purge(m_maps); @@ -58,11 +68,12 @@ Map* Model::createMap(const std::string& identifier) { std::list<Map*>::const_iterator it = m_maps.begin(); for(; it != m_maps.end(); ++it) { - if(identifier == (*it)->getId()) + if(identifier == (*it)->getId()) { throw NameClash(identifier); + } } - Map* map = new Map(identifier, &m_timeprovider); + Map* map = new Map(identifier, m_renderbackend, m_renderers, m_imagepool, m_animpool, &m_timeprovider); m_maps.push_back(map); return map; } @@ -105,7 +116,7 @@ return *it; } - throw NotFound(std::string("Tried to get non-existant map: ") + identifier + "."); + throw NotFound(std::string("Tried to get non-existent map: ") + identifier + "."); } void Model::deleteMap(Map* map) {
--- a/engine/core/model/model.h Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/core/model/model.h Fri Feb 12 06:34:50 2010 +0000 @@ -41,6 +41,10 @@ namespace FIFE { + class RenderBackend; + class RendererBase; + class ImagePool; + class AnimationPool; class MetaModel; class AbstractPather; class Object; @@ -54,7 +58,8 @@ /** Constructor * */ - Model(); + Model(RenderBackend* renderbackend, const std::vector<RendererBase*>& renderers, + ImagePool* imagepool, AnimationPool* animpool); /** Destructor * @@ -169,6 +174,12 @@ std::vector<CellGrid*> m_adopted_grids; std::vector<CellGrid*> m_created_grids; TimeProvider m_timeprovider; + + RenderBackend* m_renderbackend; + ImagePool* m_imagepool; + AnimationPool* m_animpool; + + std::vector<RendererBase*> m_renderers; }; }; //FIFE
--- a/engine/core/model/model.i Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/core/model/model.i Fri Feb 12 06:34:50 2010 +0000 @@ -40,7 +40,7 @@ class Model: public FifeClass { public: - Model(); + Model(RenderBackend* renderbackend, const std::vector<RendererBase*>& renderers, ImagePool* imagepool, AnimationPool* animpool); ~Model(); Map* createMap(const std::string& identifier);
--- a/engine/core/model/structures/map.cpp Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/core/model/structures/map.cpp Fri Feb 12 06:34:50 2010 +0000 @@ -31,18 +31,31 @@ // Second block: files included from the same folder #include "util/base/exception.h" #include "util/structures/purge.h" +#include "util/structures/rect.h" +#include "view/camera.h" +#include "view/rendererbase.h" +#include "video/renderbackend.h" +#include "video/imagepool.h" +#include "video/animationpool.h" #include "map.h" #include "layer.h" namespace FIFE { - Map::Map(const std::string& identifier, TimeProvider* tp_master): + Map::Map(const std::string& identifier, RenderBackend* renderBackend, + const std::vector<RendererBase*>& renderers, ImagePool* imagePool, + AnimationPool* animPool, TimeProvider* tp_master): m_id(identifier), m_timeprovider(tp_master), m_changelisteners(), m_changedlayers(), - m_changed(false) { + m_changed(false), + m_renderbackend(renderBackend), + m_imagepool(imagePool), + m_animpool(animPool), + m_renderers(renderers) { + } Map::~Map() { @@ -127,6 +140,16 @@ ++i; } } + + // loop over cameras and update if enabled + std::vector<Camera*>::iterator camIter = m_cameras.begin(); + for ( ; camIter != m_cameras.end(); ++camIter) { + if ((*camIter)->isEnabled()) { + (*camIter)->update(); + (*camIter)->render(); + } + } + bool retval = m_changed; m_changed = false; return retval; @@ -147,5 +170,60 @@ } } + Camera* Map::addCamera(const std::string &id, Layer *layer, + const Rect& viewport, const ExactModelCoordinate& emc) { + if (layer == NULL) { + throw NotSupported("Must have valid layer for camera"); + } + + if (getCamera(id)) { + std::string errorStr = "Camera: " + id + " already exists"; + throw NameClash(errorStr); + } + + // create new camera and add to list of cameras + Camera* camera = new Camera(id, layer, viewport, emc, m_renderbackend, m_imagepool, m_animpool); + m_cameras.push_back(camera); + + std::vector<RendererBase*>::iterator iter = m_renderers.begin(); + for ( ; iter != m_renderers.end(); ++iter) { + camera->addRenderer((*iter)->clone()); + } + + return camera; + } + + void Map::removeCamera(const std::string &id) { + std::vector<Camera*>::iterator iter = m_cameras.begin(); + for ( ; iter != m_cameras.end(); ++iter) { + if ((*iter)->getId() == id) { + // camera has been found delete it + delete *iter; + + // now remove it from the vector + // note this invalidates iterators, but we do not need + // to worry about it in this case since we are done + m_cameras.erase(iter); + + break; + } + } + } + + Camera* Map::getCamera(const std::string &id) { + std::vector<Camera*>::iterator iter = m_cameras.begin(); + for ( ; iter != m_cameras.end(); ++iter) { + if ((*iter)->getId() == id) { + return *iter; + } + } + + return NULL; + } + + std::vector<Camera*>& Map::getCameras() { + return m_cameras; + } + } //FIFE
--- a/engine/core/model/structures/map.h Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/core/model/structures/map.h Fri Feb 12 06:34:50 2010 +0000 @@ -41,9 +41,15 @@ namespace FIFE { + class RendererBase; + class RenderBackend; + class ImagePool; + class AnimationPool; class Layer; class CellGrid; class Map; + class Camera; + class Rect; /** Listener interface for changes happening on map */ @@ -86,7 +92,9 @@ * To add map to model, one should call Model::addMap (otherwise * map is not registered with the engine properly) */ - Map(const std::string& identifier, TimeProvider* tp_master=NULL); + Map(const std::string& identifier, RenderBackend* renderbackend, + const std::vector<RendererBase*>& renderers, ImagePool* imagepool, + AnimationPool* animpool, TimeProvider* tp_master=NULL); /** Destructor */ @@ -164,6 +172,24 @@ */ std::vector<Layer*>& getChangedLayers() { return m_changedlayers; } + /** Adds camera to the map. The Map takes ownership of the camera + so don't delete it. + */ + Camera* addCamera(const std::string& id, Layer *layer, + const Rect& viewport, const ExactModelCoordinate& emc); + + /** Removes a camera from the map + */ + void removeCamera(const std::string& id); + + /** Get a camera by its identifier. + */ + Camera* getCamera(const std::string& id); + + /** Get a list containing all cameras. + */ + std::vector<Camera*>& getCameras(); + private: std::string m_id; @@ -179,6 +205,16 @@ // holds changed layers after each update std::vector<Layer*> m_changedlayers; + // holds the cameras attached to this map + std::vector<Camera*> m_cameras; + + RenderBackend* m_renderbackend; + ImagePool* m_imagepool; + AnimationPool* m_animpool; + + // holds handles to all created renderers + std::vector<RendererBase*> m_renderers; + // true, if something was changed on map during previous update (layer change, creation, deletion) bool m_changed; };
--- a/engine/core/model/structures/map.i Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/core/model/structures/map.i Fri Feb 12 06:34:50 2010 +0000 @@ -28,16 +28,19 @@ namespace FIFE { class Layer; + class Camera; } namespace std { %template(LayerList) list<FIFE::Layer*>; + %template(CameraVector) std::vector<FIFE::Camera*>; } namespace FIFE { class Layer; class Map; + class Rect; %feature("director") MapChangeListener; class MapChangeListener { @@ -51,7 +54,7 @@ class Map : public ResourceClass { public: - Map(const std::string& identifier, TimeProvider* tp_master=NULL); + Map(const std::string& identifier, RenderBackend* renderbackend, const std::vector<RendererBase*>& renderers, ImagePool* imagepool, AnimationPool* animpool, TimeProvider* tp_master=NULL); ~Map(); const std::string& getId() const; @@ -73,5 +76,9 @@ void removeChangeListener(MapChangeListener* listener); bool isChanged(); std::vector<Layer*>& getChangedLayers(); + Camera* addCamera(const std::string& id, Layer *layer, const Rect& viewport, const ExactModelCoordinate& emc); + void removeCamera(const std::string& id); + Camera* getCamera(const std::string& id); + std::vector<Camera*>& getCameras(); }; }
--- a/engine/core/view/camera.cpp Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/core/view/camera.cpp Fri Feb 12 06:34:50 2010 +0000 @@ -56,8 +56,8 @@ Camera::Camera(const std::string& id, Layer *layer, - Rect viewport, - ExactModelCoordinate emc, + const Rect& viewport, + const ExactModelCoordinate& emc, RenderBackend* renderbackend, ImagePool* ipool, AnimationPool* apool):
--- a/engine/core/view/camera.h Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/core/view/camera.h Fri Feb 12 06:34:50 2010 +0000 @@ -33,8 +33,8 @@ // First block: files included from the FIFE root src directory // Second block: files included from the same folder #include "model/structures/location.h" +#include "util/structures/rect.h" #include "util/math/matrix.h" -#include "util/structures/rect.h" #include "rendererbase.h" @@ -42,6 +42,7 @@ typedef Point3D ScreenPoint; class Layer; + class Rect; class Instance; class ImagePool; class AnimationPool; @@ -58,9 +59,9 @@ /** Constructor * Camera needs to be added to the view. If not done so, it is not rendered. * @param id identifier for the camera - * @param layer layer where camera is bind. Camera is bind to a layer for two reasons: + * @param layer layer where camera is bound. Camera is bound to a layer for two reasons: * * camera's scaling is done based on cell image dimensions. Cell image is layer based (@see setCellImageDimensions) - * * camera could be bind to a pather, which operates on layer + * * camera could be bound to a pather, which operates on layer * @param viewport used viewport for the camera. Viewport is measured in pixels in relation to game main screen * @param emc coordinate, where camera is focused on given layer * @param renderbackend to use with rendering @@ -69,8 +70,8 @@ */ Camera(const std::string& id, Layer* layer, - Rect viewport, - ExactModelCoordinate emc, + const Rect& viewport, + const ExactModelCoordinate& emc, RenderBackend* renderbackend, ImagePool* ipool, AnimationPool* apool);
--- a/engine/core/view/renderers/blockinginforenderer.cpp Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/core/view/renderers/blockinginforenderer.cpp Fri Feb 12 06:34:50 2010 +0000 @@ -36,7 +36,6 @@ #include "model/structures/location.h" #include "view/camera.h" -#include "view/view.h" #include "blockinginforenderer.h"
--- a/engine/core/view/renderers/blockinginforenderer.h Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/core/view/renderers/blockinginforenderer.h Fri Feb 12 06:34:50 2010 +0000 @@ -34,7 +34,6 @@ namespace FIFE { class RenderBackend; - class View; class BlockingInfoRenderer: public RendererBase { public:
--- a/engine/core/view/renderers/genericrenderer.i Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/core/view/renderers/genericrenderer.i Fri Feb 12 06:34:50 2010 +0000 @@ -138,7 +138,7 @@ class GenericRenderer: public RendererBase { public: GenericRenderer(RenderBackend* renderbackend, int position, ImagePool* imagepool, AnimationPool* animpool); - ~GeometricRenderer(); + ~GenericRenderer(); std::string getName(); static GenericRenderer* getInstance(IRendererContainer* cnt); void addLine(const std::string &group, GenericRendererNode n1, GenericRendererNode n2, uint8_t r, uint8_t g, uint8_t b);
--- a/engine/core/view/view.cpp Thu Feb 11 04:18:42 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-2008 by the FIFE team * - * http://www.fifengine.de * - * This file is part of FIFE. * - * * - * FIFE is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2.1 of the License, or (at your option) any later version. * - * * - * This library 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 * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this library; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -// Standard C++ library includes -#include <iostream> -#include <algorithm> -#include <set> - -// 3rd party library includes - -// FIFE includes -// These includes are split up in two parts, separated by one empty line -// First block: files included from the FIFE root src directory -// Second block: files included from the same folder -#include "video/renderbackend.h" -#include "video/imagepool.h" -#include "video/animationpool.h" - -#include "util/log/logger.h" -#include "model/structures/location.h" - -#include "camera.h" -#include "view.h" - -namespace FIFE { - static Logger _log(LM_VIEWVIEW); - - View::View(RenderBackend* renderbackend, ImagePool* ipool, AnimationPool* apool): - m_cameras(), - m_renderbackend(renderbackend), - m_ipool(ipool), - m_apool(apool), - m_renderers() { - } - - View::~View() { - clearCameras(); - std::map<std::string, RendererBase*>::iterator r_it = m_renderers.begin(); - for(; r_it != m_renderers.end(); ++r_it) { - delete r_it->second; - } - m_renderers.clear(); - } - - void View::clearCameras() { - std::vector<Camera*>::iterator cam_it = m_cameras.begin(); - for(; cam_it != m_cameras.end(); ++cam_it) { - delete *cam_it; - } - m_cameras.clear(); - } - - - Camera* View::addCamera(const std::string& id, Layer *layer, Rect viewport, ExactModelCoordinate emc) { - if (getCamera(id)) { - throw NameClash("Duplicate camera id registered."); - } - Camera* cam = new Camera(id, layer, viewport, emc, m_renderbackend, m_ipool, m_apool); - m_cameras.push_back(cam); - - std::map<std::string, RendererBase*>::iterator r_it = m_renderers.begin(); - for(; r_it != m_renderers.end(); ++r_it) { - cam->addRenderer(r_it->second->clone()); - } - return cam; - } - - Camera* View::getCamera(const std::string& id) { - std::vector<Camera*>::iterator it = m_cameras.begin(); - for (; it != m_cameras.end(); ++it) { - if ((*it)->getId() == id) - return *it; - } - return NULL; - } - - void View::removeCamera(Camera* camera) { - std::vector<Camera*>::iterator it = std::find(m_cameras.begin(), m_cameras.end(), camera); - if (it != m_cameras.end()) { - m_cameras.erase(it); - } - } - - void View::resetRenderers() { - std::vector<Camera*>::iterator it = m_cameras.begin(); - while (it != m_cameras.end()) { - (*it)->resetRenderers(); - ++it; - } - } - - void View::update() { - FL_DBG(_log, "In View::update"); - - // update each camera - std::vector<Camera*>::iterator cam_it = m_cameras.begin(); - for (; cam_it != m_cameras.end(); ++cam_it) { - Camera* cam = *cam_it; - if (!cam->isEnabled()) { - continue; - } - cam->update(); - cam->render(); - } - } - - void View::addRenderer(RendererBase* renderer) { - m_renderers[renderer->getName()] = renderer; - } -} -
--- a/engine/core/view/view.h Thu Feb 11 04:18:42 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-2008 by the FIFE team * - * http://www.fifengine.de * - * This file is part of FIFE. * - * * - * FIFE is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2.1 of the License, or (at your option) any later version. * - * * - * This library 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 * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this library; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef FIFE_VIEW_VIEW_H -#define FIFE_VIEW_VIEW_H - -// Standard C++ library includes -#include <list> - -// 3rd party library includes -#include <SDL.h> - -// FIFE includes -// These includes are split up in two parts, separated by one empty line -// First block: files included from the FIFE root src directory -// Second block: files included from the same folder - -namespace FIFE { - class Camera; - class RenderBackend; - class ImagePool; - class AnimationPool; - class RendererBase; - - class View { - public: - /** Constructor - * - */ - View(RenderBackend* renderbackend, ImagePool* ipool, AnimationPool* apool); - - /** Destructor - */ - ~View(); - - /** Adds new camera on view. - * After creation, camera gets rendered by the added renderers - */ - Camera* addCamera(const std::string& id, Layer *layer, Rect viewport, ExactModelCoordinate emc); - - /** Get a camera by its identifier. - */ - Camera* getCamera(const std::string& id); - - /** Get a list containing all cameras. - * @return std::list<Camera*>& Cameralist - */ - std::vector<Camera*>& getCameras() { return m_cameras; } - - /** Removes given camera from the view. - */ - void removeCamera(Camera* camera); - - /** Clears all cameras from view - */ - void clearCameras(); - - /** resets active layer information on all renderers. - */ - void resetRenderers(); - - /** Causes view to render all cameras - */ - void update(); - - /** Adds new renderer on the view. Ownership is transferred to the view. - */ - void addRenderer(RendererBase* renderer); - - private: - // list of cameras managed by the view - std::vector<Camera*> m_cameras; - RenderBackend* m_renderbackend; - ImagePool* m_ipool; - AnimationPool* m_apool; - std::map<std::string, RendererBase*> m_renderers; - }; - -} -#endif
--- a/engine/core/view/view.i Thu Feb 11 04:18:42 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-2008 by the FIFE team * - * http://www.fifengine.de * - * This file is part of FIFE. * - * * - * FIFE is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2.1 of the License, or (at your option) any later version. * - * * - * This library 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 * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU Lesser General Public * - * License along with this library; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -%module fife -%{ -#include "view/view.h" -%} - -namespace std { - %template(CameraVector) std::vector<FIFE::Camera*>; -} - -namespace FIFE { - class RendererBase; - class View { - public: - ~View(); - Camera* addCamera(const std::string& id, Layer* layr,Rect viewport, ExactModelCoordinate emc); - Camera* getCamera(const std::string& id); - std::vector<Camera*>& getCameras(); - void removeCamera(Camera* camera); - void clearCameras(); - void resetRenderers(); - private: - View(RenderBackend* renderbackend); - }; -}
--- a/engine/python/fife/extensions/savers.py Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/python/fife/extensions/savers.py Fri Feb 12 06:34:50 2010 +0000 @@ -218,7 +218,7 @@ # Save the linked camera of a map. def write_camera( self, map ): - cameralist = self.engine.getView().getCameras() + cameralist = map.getCameras() for cam in cameralist: if cam.getLocationRef().getMap().getId() == map.getId():
--- a/engine/python/fife/extensions/serializers/xmlmap.py Thu Feb 11 04:18:42 2010 +0000 +++ b/engine/python/fife/extensions/serializers/xmlmap.py Fri Feb 12 06:34:50 2010 +0000 @@ -318,10 +318,11 @@ try: if viewport: - cam = self.engine.getView().addCamera(str(id), map.getLayer(str(ref_layer_id)),fife.Rect(*[int(c) for c in viewport.split(',')]),fife.ExactModelCoordinate(0,0,0)) + cam = map.addCamera(str(id), map.getLayer(str(ref_layer_id)),fife.Rect(*[int(c) for c in viewport.split(',')]),fife.ExactModelCoordinate(0,0,0)) + else: screen = self.engine.getRenderBackend() - cam = self.engine.getView().addCamera(str(id), map.getLayer(str(ref_layer_id)),fife.Rect(0,0,screen.getScreenWidth(),screen.getScreenHeight()),fife.ExactModelCoordinate(0,0,0)) + cam = map.addCamera(str(id), map.getLayer(str(ref_layer_id)),fife.Rect(0,0,screen.getScreenWidth(),screen.getScreenHeight()),fife.ExactModelCoordinate(0,0,0)) cam.setCellImageDimensions(int(ref_cell_width), int(ref_cell_height)) cam.setRotation(float(rotation))
--- a/tools/editor/plugins/LayerTool.py Thu Feb 11 04:18:42 2010 +0000 +++ b/tools/editor/plugins/LayerTool.py Fri Feb 12 06:34:50 2010 +0000 @@ -286,7 +286,7 @@ # FIFE will crash if we try to delete the layer which is in use by a camera # so we will set the camera to another layer instead - for cam in self._editor.getEngine().getView().getCameras(): + for cam in map.getCameras: if cam.getLocationRef().getMap().getId() != map.getId(): continue
--- a/tools/editor/scripts/editor.py Thu Feb 11 04:18:42 2010 +0000 +++ b/tools/editor/scripts/editor.py Fri Feb 12 06:34:50 2010 +0000 @@ -319,6 +319,13 @@ """ Switches to mapview. """ if mapview is None or mapview == self._mapview: return + + if self._mapview != None and mapview != self._mapview: + # need to disable the cameras from the previous map + # if it exists before switching + if self._mapview.getMap() != None: + for cam in self._mapview.getMap().getCameras(): + cam.setEnabled(False) events.preMapShown.send(sender=self, mapview=mapview) self._mapview = mapview @@ -354,6 +361,10 @@ def _mapRemoved(self, mapview): index = self._mapviewlist.index(mapview)-1 + + for cam in mapview.getMap().getCameras(): + cam.setEnabled(False) + self._mapviewlist.remove(mapview) # Remove tab @@ -369,7 +380,6 @@ self._change_map = index else: self._mapview = None - self.getEngine().getView().clearCameras() def openFile(self, path): """ Opens a file """
--- a/tools/editor/scripts/gui/cameradialog.py Thu Feb 11 04:18:42 2010 +0000 +++ b/tools/editor/scripts/gui/cameradialog.py Fri Feb 12 06:34:50 2010 +0000 @@ -100,7 +100,7 @@ print 'Please enter positive integer values for rotation and tilt.' return - cam = self.engine.getView().addCamera(str(id), layer, viewport, fife.ExactModelCoordinate(0,0,0)) + cam = map.addCamera(str(id), layer, viewport, fife.ExactModelCoordinate(0,0,0)) cam.setCellImageDimensions(refw, refh) cam.setRotation(rot) cam.setTilt(tilt)
--- a/tools/editor/scripts/gui/layerdialog.py Thu Feb 11 04:18:42 2010 +0000 +++ b/tools/editor/scripts/gui/layerdialog.py Fri Feb 12 06:34:50 2010 +0000 @@ -163,7 +163,8 @@ layer.setPathingStrategy(pathing) layer.setLayerTransparency(transparency) - self.engine.getView().resetRenderers() + for cam in self.map.getCameras(): + cam.resetRenderers() # Hide dialog and call back self._widget.hide()
--- a/tools/editor/scripts/mapcontroller.py Thu Feb 11 04:18:42 2010 +0000 +++ b/tools/editor/scripts/mapcontroller.py Fri Feb 12 06:34:50 2010 +0000 @@ -82,13 +82,16 @@ if not self._map.getLayers(): raise AttributeError('Editor error: map ' + self._map.getId() + ' has no layers. Cannot edit.') - for cam in self._engine.getView().getCameras(): + for cam in self._map.getCameras(): if cam.getLocationRef().getMap().getId() == self._map.getId(): self._camera = cam break self._layer = self._map.getLayers()[0] + def getMap(self): + return self._map + def selectLayer(self, layerid): """ Select layer to be edited """ self.deselectSelection()
--- a/tools/editor/scripts/mapview.py Thu Feb 11 04:18:42 2010 +0000 +++ b/tools/editor/scripts/mapview.py Fri Feb 12 06:34:50 2010 +0000 @@ -79,12 +79,12 @@ _camera = None engine = self._editor.getEngine() - engine.getView().resetRenderers() - for cam in engine.getView().getCameras(): + for cam in self._map.getCameras(): + cam.resetRenderers() cam.setEnabled(False) - for cam in engine.getView().getCameras(): + for cam in self._map.getCameras(): if cam.getLocationRef().getMap().getId() == self._map.getId(): rb = engine.getRenderBackend() cam.setViewPort(fife.Rect(0, 0, rb.getScreenWidth(), rb.getScreenHeight())) @@ -144,15 +144,9 @@ events.preMapClosed.send(sender=self, mapview=self) self._controller.cleanUp() - - # Remove cameras - view = self._editor.getEngine().getView() - for cam in list(view.getCameras()): - if cam.getLocationRef().getMap().getId() == self._map.getId(): - cam.setEnabled(False) - view.removeCamera(cam) - view.resetRenderers() + for cam in self._map.getCameras(): + cam.resetRenderers() # Unload the map from FIFE self._editor.getEngine().getModel().deleteMap(self._map)