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/fifeclass.h"
00037 #include "util/resource/resource.h"
00038 #include "model/metamodel/timeprovider.h"
00039 #include "util/structures/rect.h"
00040 
00041 #include "location.h"
00042 
00043 namespace FIFE {
00044 
00045     class RendererBase;
00046     class RenderBackend;
00047     class Layer;
00048     class CellGrid;
00049     class Map;
00050     class Camera;
00051 
00054     class MapChangeListener {
00055     public:
00056         virtual ~MapChangeListener() {};
00057 
00065         virtual void onMapChanged(Map* map, std::vector<Layer*>& changedLayers) = 0;
00066 
00071         virtual void onLayerCreate(Map* map, Layer* layer) = 0;
00072 
00078         virtual void onLayerDelete(Map* map, Layer* layer) = 0;
00079     };
00080 
00086     class Map : public FifeClass {
00087         public:
00088 
00093             Map(const std::string& identifier, RenderBackend* renderbackend,
00094                 const std::vector<RendererBase*>& renderers, TimeProvider* tp_master=NULL);
00095 
00098             ~Map();
00099 
00102             const std::string& getId() const { return m_id; }
00103 
00106             void setId(const std::string& id) { m_id = id; }
00107 
00110             Layer* createLayer(const std::string& identifier, CellGrid* grid);
00111 
00114             void deleteLayer(Layer*);
00115 
00118             const std::list<Layer*>& getLayers() const { return m_layers; }
00119 
00122             Layer* getLayer(const std::string& identifier);
00123 
00126             uint32_t getLayerCount() const;
00127 
00130             void deleteLayers();
00131 
00134             void getMatchingCoordinates(const ModelCoordinate& coord_to_map, const Layer* from_layer,
00135                 const Layer* to_layer, std::vector<ModelCoordinate>& matching_coords) const;
00136 
00141             void getMinMaxCoordinates(ExactModelCoordinate& min, ExactModelCoordinate& max);
00142 
00146             bool update();
00147 
00150             void setTimeMultiplier(float multip) { m_timeprovider.setMultiplier(multip); }
00151 
00154             float getTimeMultiplier() const { return m_timeprovider.getMultiplier(); }
00155 
00158             TimeProvider* getTimeProvider() { return &m_timeprovider; }
00159 
00163             void addChangeListener(MapChangeListener* listener);
00164 
00168             void removeChangeListener(MapChangeListener* listener);
00169 
00172             bool isChanged() { return !m_changedlayers.empty(); }
00173 
00176             std::vector<Layer*>& getChangedLayers() { return m_changedlayers; }
00177 
00181             Camera* addCamera(const std::string& id, Layer *layer, const Rect& viewport);
00182 
00185             void removeCamera(const std::string& id);
00186 
00189             Camera* getCamera(const std::string& id);
00190 
00193             const std::vector<Camera*>& getCameras() const;
00194 
00195             void setFilename(const std::string& file) { m_filename = file; }
00196             const std::string& getFilename() const { return m_filename; }
00197 
00198         private:
00199             std::string m_id;
00200             std::string m_filename;
00201 
00202             std::list<Layer*> m_layers;
00203             TimeProvider m_timeprovider;
00204 
00205             Map(const Map& map);
00206             Map& operator=(const Map& map);
00207 
00208             // listeners for map changes
00209             std::vector<MapChangeListener*> m_changelisteners;
00210 
00211             // holds changed layers after each update
00212             std::vector<Layer*> m_changedlayers;
00213 
00214             // holds the cameras attached to this map
00215             std::vector<Camera*> m_cameras;
00216 
00217             RenderBackend* m_renderbackend;
00218 
00219             // holds handles to all created renderers
00220             std::vector<RendererBase*> m_renderers;
00221 
00222             // true, if something was changed on map during previous update (layer change, creation, deletion)
00223             bool m_changed;
00224     };
00225 
00226 } //FIFE
00227 
00228 #endif
00229 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */