map.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2008 by the FIFE team                              *
00003  *   http://www.fifengine.de                                               *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 #ifndef FIFE_MAP_MAP_H
00023 #define FIFE_MAP_MAP_H
00024 
00025 // Standard C++ library includes
00026 #include <list>
00027 #include <string>
00028 #include <vector>
00029 
00030 // 3rd party library includes
00031 
00032 // FIFE includes
00033 // These includes are split up in two parts, separated by one empty line
00034 // First block: files included from the FIFE root src directory
00035 // Second block: files included from the same folder
00036 #include "util/base/resourceclass.h"
00037 #include "util/resource/resource.h"
00038 #include "model/metamodel/timeprovider.h"
00039 
00040 #include "location.h"
00041 
00042 namespace FIFE {
00043 
00044     class RendererBase;
00045     class RenderBackend;
00046     class ImagePool;
00047     class AnimationPool;
00048     class Layer;
00049     class CellGrid;
00050     class Map;
00051     class Camera;
00052     class Rect;
00053 
00056     class MapChangeListener {
00057     public:
00058         virtual ~MapChangeListener() {};
00059         
00067         virtual void onMapChanged(Map* map, std::vector<Layer*>& changedLayers) = 0;
00068         
00073         virtual void onLayerCreate(Map* map, Layer* layer) = 0;
00074         
00080         virtual void onLayerDelete(Map* map, Layer* layer) = 0;
00081     };
00082 
00088     class Map : public ResourceClass {
00089         public:
00090 
00095             Map(const std::string& identifier, RenderBackend* renderbackend, 
00096                 const std::vector<RendererBase*>& renderers, ImagePool* imagepool, 
00097                 AnimationPool* animpool, TimeProvider* tp_master=NULL);
00098 
00101             ~Map();
00102 
00105             const std::string& getId() const { return m_id; }
00106 
00109             void setId(const std::string& id) { m_id = id; }
00110 
00113             Layer* createLayer(const std::string& identifier, CellGrid* grid);
00114 
00117             void deleteLayer(Layer*);
00118 
00121             const std::list<Layer*>& getLayers() const { return m_layers; }
00122 
00125             Layer* getLayer(const std::string& identifier);
00126 
00129             size_t getNumLayers() const;
00130 
00133             void deleteLayers();
00134 
00137             void getMatchingCoordinates(const ModelCoordinate& coord_to_map, const Layer* from_layer, 
00138                 const Layer* to_layer, std::vector<ModelCoordinate>& matching_coords) const;
00139 
00143             bool update();
00144             
00147             void setTimeMultiplier(float multip) { m_timeprovider.setMultiplier(multip); }
00148             
00151             float getTimeMultiplier() const { return m_timeprovider.getMultiplier(); }
00152             
00155             TimeProvider* getTimeProvider() { return &m_timeprovider; }
00156             
00160             void addChangeListener(MapChangeListener* listener);
00161     
00165             void removeChangeListener(MapChangeListener* listener);
00166             
00169             bool isChanged() { return !m_changedlayers.empty(); }
00170 
00173             std::vector<Layer*>& getChangedLayers() { return m_changedlayers; }
00174 
00178             Camera* addCamera(const std::string& id, Layer *layer, 
00179                                 const Rect& viewport, const ExactModelCoordinate& emc);
00180 
00183             void removeCamera(const std::string& id);
00184 
00187             Camera* getCamera(const std::string& id);
00188 
00191             std::vector<Camera*>& getCameras();
00192             
00193         private:
00194             std::string m_id;
00195 
00196             std::list<Layer*> m_layers;
00197             TimeProvider m_timeprovider;
00198 
00199             Map(const Map& map);
00200             Map& operator=(const Map& map);
00201     
00202             // listeners for map changes
00203             std::vector<MapChangeListener*> m_changelisteners;
00204 
00205             // holds changed layers after each update
00206             std::vector<Layer*> m_changedlayers;
00207             
00208             // holds the cameras attached to this map
00209             std::vector<Camera*> m_cameras;
00210 
00211             RenderBackend* m_renderbackend;
00212             ImagePool* m_imagepool;
00213             AnimationPool* m_animpool;
00214 
00215             // holds handles to all created renderers
00216             std::vector<RendererBase*> m_renderers;
00217 
00218             // true, if something was changed on map during previous update (layer change, creation, deletion)
00219             bool m_changed;
00220     };
00221 
00222 } //FIFE
00223 
00224 #endif
00225 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */
Generated by  doxygen 1.6.2-20100208