layer.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_LAYER_H
00023 #define FIFE_LAYER_H
00024 
00025 // Standard C++ library includes
00026 #include <algorithm>
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 "model/metamodel/modelcoords.h"
00038 #include "model/metamodel/object.h"
00039 
00040 #include "instance.h"
00041 
00042 namespace FIFE {
00043 
00044     class Map;
00045     class Selection;
00046     class CellGrid;
00047     class Object;
00048     class InstanceTree;
00049 
00056     enum PathingStrategy {
00057         CELL_EDGES_ONLY,
00058         CELL_EDGES_AND_DIAGONALS,
00059         FREEFORM
00060     };
00061 
00064     class LayerChangeListener {
00065     public:
00066         virtual ~LayerChangeListener() {};
00067 
00073         virtual void onLayerChanged(Layer* layer, std::vector<Instance*>& changedInstances) = 0;
00074 
00079         virtual void onInstanceCreate(Layer* layer, Instance* instance) = 0;
00080 
00086         virtual void onInstanceDelete(Layer* layer, Instance* instance) = 0;
00087     };
00088 
00089 
00092     class Layer : public ResourceClass {
00093         public:
00098             Layer(const std::string& identifier, Map* map, CellGrid* grid);
00099 
00102             ~Layer();
00103 
00106             const std::string& getId() const { return m_id; }
00107 
00110             void setId(const std::string& id) { m_id = id; }
00111 
00114             Map* getMap() const { return m_map; }
00115 
00119             CellGrid* getCellGrid() const { return m_grid; }
00120 
00123             void setCellGrid(CellGrid* grid) { m_grid = grid; }
00124 
00128             InstanceTree* getInstanceTree(void) const { return m_instanceTree; }
00129 
00133             bool hasInstances() const;
00134 
00137             Instance* createInstance(Object* object, const ModelCoordinate& p, const std::string& id="");
00138 
00141             Instance* createInstance(Object* object, const ExactModelCoordinate& p, const std::string& id="");
00142 
00146             bool addInstance(Instance* instance, const ExactModelCoordinate& p);
00147 
00150             void deleteInstance(Instance* object);
00151 
00154             const std::vector<Instance*>& getInstances() const { return m_instances; }
00155 
00158             std::vector<Instance*> getInstances(const std::string& id);
00159 
00164             std::vector<Instance*> getInstancesAt(Location& loc, bool use_exactcoordinates=false);
00165 
00168             Instance* getInstance(const std::string& identifier);
00169 
00172             void setInstancesVisible(bool vis);
00173 
00177             void setLayerTransparency(uint8_t transparency);
00178 
00181             uint8_t getLayerTransparency();
00182 
00188             void getMinMaxCoordinates(ModelCoordinate& min, ModelCoordinate& max, const Layer* layer = 0) const;
00189 
00195             bool cellContainsBlockingInstance(const ModelCoordinate& cellCoordinate);
00196 
00200             void toggleInstancesVisible();
00201 
00205             bool areInstancesVisible() const { return m_instances_visibility; }
00206 
00210             bool update();
00211 
00215             void setPathingStrategy(PathingStrategy strategy) { m_pathingstrategy = strategy; }
00216 
00220             PathingStrategy getPathingStrategy() const { return m_pathingstrategy; }
00221 
00225             void addChangeListener(LayerChangeListener* listener);
00226 
00230             void removeChangeListener(LayerChangeListener* listener);
00231 
00234             bool isChanged() { return m_changed; }
00235 
00239             std::vector<Instance*>& getChangedInstances() { return m_changedinstances; }
00240 
00241         protected:
00242             std::string m_id;
00243 
00244             Map* m_map;
00245 
00246             bool m_instances_visibility;
00247 
00248             uint8_t m_transparency;
00249 
00250             // all the instances on this layer
00251             std::vector<Instance*> m_instances;
00252 
00253             //The instance tree
00254             InstanceTree* m_instanceTree;
00255 
00256             // layer's cellgrid
00257             CellGrid* m_grid;
00258 
00259             // pathing strategy for the layer
00260             PathingStrategy m_pathingstrategy;
00261 
00262             // listeners for layer changes
00263             std::vector<LayerChangeListener*> m_changelisteners;
00264 
00265             // holds changed instances after each update
00266             std::vector<Instance*> m_changedinstances;
00267 
00268             // true if layer (or it's instance) information was changed during previous update round
00269             bool m_changed;
00270     };
00271 
00272 } // FIFE
00273 
00274 #endif
Generated by  doxygen 1.6.2-20100208