model.h

00001 /***************************************************************************
00002  *   Copyright (C) 2006-2011 by the FIFE team                              *
00003  *   http://www.fifengine.net                                              *
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_MODEL_H
00023 #define FIFE_MODEL_H
00024 
00025 // Standard C++ library includes
00026 #include <list>
00027 #include <map>
00028 #include <vector>
00029 #include <utility>
00030 
00031 // 3rd party library includes
00032 
00033 // FIFE includes
00034 // These includes are split up in two parts, separated by one empty line
00035 // First block: files included from the FIFE root src directory
00036 // Second block: files included from the same folder
00037 #include "util/base/fifeclass.h"
00038 
00039 #include "model/structures/map.h"
00040 #include "model/metamodel/timeprovider.h"
00041 
00042 namespace FIFE {
00043 
00044     class RenderBackend;
00045     class RendererBase;
00046     class MetaModel;
00047     class IPather;
00048     class Object;
00049 
00053     class Model: public FifeClass {
00054     public:
00055 
00059         Model(RenderBackend* renderbackend, const std::vector<RendererBase*>& renderers);
00060 
00064         ~Model();
00065 
00069         Map* createMap(const std::string& identifier);
00070 
00073         void deleteMap(Map*);
00074 
00077         const std::list<Map*>& getMaps() const { return m_maps; }
00078 
00083         Map* getMap(const std::string& identifier) const;
00084 
00087         uint32_t getMapCount() const;
00088 
00091         void deleteMaps();
00092 
00095         std::list<std::string> getNamespaces() const;
00096 
00103         Object* createObject(const std::string& identifier, const std::string& name_space, Object* parent=0);
00104 
00108         bool deleteObject(Object*);
00109 
00113         bool deleteObjects();
00114 
00117         Object* getObject(const std::string& id, const std::string& name_space);
00118 
00121         std::list<Object*> getObjects(const std::string& name_space) const;
00122 
00125         void adoptPather(IPather* pather);
00126 
00129         IPather* getPather(const std::string& pathername);
00130 
00133         void adoptCellGrid(CellGrid* grid);
00134 
00137         CellGrid* getCellGrid(const std::string& gridtype);
00138 
00141         void update();
00142 
00147         void setTimeMultiplier(float multip) { m_timeprovider.setMultiplier(multip); }
00148 
00151         double getTimeMultiplier() const { return m_timeprovider.getMultiplier(); }
00152 
00153     private:
00154 
00155         std::list<Map*> m_maps;
00156 
00157         typedef std::map<std::string,Object*> objectmap_t;
00158         typedef std::pair<std::string,objectmap_t> namespace_t;
00159         std::list<namespace_t> m_namespaces;
00160 
00162         namespace_t* m_last_namespace;
00163 
00165         namespace_t* selectNamespace(const std::string& name_space);
00166 
00168         const namespace_t* selectNamespace(const std::string& name_space) const;
00169 
00170         std::vector<IPather*> m_pathers;
00171         std::vector<CellGrid*> m_created_grids;
00172         std::vector<CellGrid*> m_adopted_grids;
00173         //std::vector<CellGrid*> m_created_grids;
00174         TimeProvider m_timeprovider;
00175 
00176         RenderBackend* m_renderbackend;
00177 
00178         std::vector<RendererBase*> m_renderers;
00179     };
00180 
00181 }; //FIFE
00182 #endif