FIFE  2008.0
model.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_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 ImagePool;
00047     class AnimationPool;
00048     class MetaModel;
00049     class AbstractPather;
00050     class Object;
00051 
00055     class Model: public FifeClass {
00056     public:
00057 
00061         Model(RenderBackend* renderbackend, const std::vector<RendererBase*>& renderers,
00062                 ImagePool* imagepool, AnimationPool* animpool);
00063 
00067         ~Model();
00068 
00072         Map* createMap(const std::string& identifier);
00073 
00076         void deleteMap(Map*);
00077 
00080         const std::list<Map*>& getMaps() const { return m_maps; }
00081 
00086         Map* getMap(const std::string& identifier) const;
00087 
00090         uint32_t getNumMaps() const;
00091 
00094         void deleteMaps();
00095 
00098         std::list<std::string> getNamespaces() const;
00099 
00106         Object* createObject(const std::string& identifier, const std::string& name_space, Object* parent=0);
00107 
00111         bool deleteObject(Object*);
00112 
00116         bool deleteObjects();
00117 
00120         Object* getObject(const std::string& id, const std::string& name_space);
00121 
00124         std::list<Object*> getObjects(const std::string& name_space) const;
00125 
00128         void adoptPather(AbstractPather* pather);
00129 
00132         AbstractPather* getPather(const std::string& pathername);
00133 
00136         void adoptCellGrid(CellGrid* grid);
00137 
00140         CellGrid* getCellGrid(const std::string& gridtype);
00141 
00144         void update();
00145 
00150         void setTimeMultiplier(float multip) { m_timeprovider.setMultiplier(multip); }
00151 
00154         double getTimeMultiplier() const { return m_timeprovider.getMultiplier(); }
00155 
00156     private:
00157 
00158         std::list<Map*> m_maps;
00159 
00160         typedef std::map<std::string,Object*> objectmap_t;
00161         typedef std::pair<std::string,objectmap_t> namespace_t;
00162         std::list<namespace_t> m_namespaces;
00163 
00165         namespace_t* m_last_namespace;
00166 
00168         namespace_t* selectNamespace(const std::string& name_space);
00169 
00171         const namespace_t* selectNamespace(const std::string& name_space) const;
00172 
00173         std::vector<AbstractPather*> m_pathers;
00174         std::vector<CellGrid*> m_adopted_grids;
00175         std::vector<CellGrid*> m_created_grids;
00176         TimeProvider m_timeprovider;
00177 
00178         RenderBackend* m_renderbackend;
00179         ImagePool* m_imagepool;
00180         AnimationPool* m_animpool;
00181 
00182         std::vector<RendererBase*> m_renderers;
00183     };
00184 
00185 }; //FIFE
00186 #endif