FIFE 2008.0
|
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_VIEW_LAYERCACHE_H 00023 #define FIFE_VIEW_LAYERCACHE_H 00024 00025 // Standard C++ library includes 00026 #include <string> 00027 #include <map> 00028 #include <set> 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 "model/structures/location.h" 00037 #include "util/math/matrix.h" 00038 #include "util/structures/rect.h" 00039 #include "util/structures/quadtree.h" 00040 #include "model/metamodel/grids/cellgrid.h" 00041 00042 #include "rendererbase.h" 00043 00044 namespace FIFE { 00045 00046 class Camera; 00047 class CacheLayerChangeListener; 00048 00049 class LayerCache { 00050 public: 00051 typedef QuadTree<std::set<int> > CacheTree; 00052 00053 LayerCache(Camera* camera, ImagePool* image_pool, AnimationPool* animation_pool); 00054 ~LayerCache(); 00055 00056 void setLayer(Layer* layer); 00057 void update(Camera::Transform transform, RenderList& renderlist); 00058 00059 void addInstance(Instance* instance); 00060 void removeInstance(Instance* instance); 00061 00062 void updateInstance(Instance* instance); 00063 00064 00065 private: 00066 void collect(const Rect& viewport, std::vector<int>& indices); 00067 void reset(); 00068 void fullUpdate(); 00069 00070 struct Entry { 00072 CacheTree::Node* node; 00073 00075 unsigned instance_index; 00076 00078 unsigned entry_index; 00080 bool force_update; 00081 }; 00082 00083 ImagePool* m_image_pool; 00084 AnimationPool* m_animation_pool; 00085 Camera* m_camera; 00086 Layer* m_layer; 00087 CacheLayerChangeListener* m_layer_observer; 00088 00089 void updateEntry(Entry& item); 00090 00091 std::map<Instance*,int> m_instance_map; 00092 std::vector<Entry> m_entries; 00093 00094 CacheTree* m_tree; 00095 std::vector<RenderItem> m_instances; 00096 }; 00097 00098 } 00099 #endif