FIFE  2008.0
layercache.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_VIEW_LAYERCACHE_H
23 #define FIFE_VIEW_LAYERCACHE_H
24 
25 // Standard C++ library includes
26 #include <string>
27 #include <map>
28 #include <set>
29 
30 // 3rd party library includes
31 
32 // FIFE includes
33 // These includes are split up in two parts, separated by one empty line
34 // First block: files included from the FIFE root src directory
35 // Second block: files included from the same folder
36 #include "model/structures/location.h"
37 #include "util/math/matrix.h"
38 #include "util/structures/rect.h"
39 #include "util/structures/quadtree.h"
40 #include "model/metamodel/grids/cellgrid.h"
41 
42 #include "rendererbase.h"
43 
44 namespace FIFE {
45 
46  class Camera;
47  class CacheLayerChangeListener;
48 
49  class LayerCache {
50  public:
51  typedef QuadTree<std::set<int32_t> > CacheTree;
52 
53  LayerCache(Camera* camera);
54  ~LayerCache();
55 
56  void setLayer(Layer* layer);
57 
58  bool needUpdate() { return m_needupdate; }
59  void update(Camera::Transform transform, RenderList& renderlist);
60 
61  void addInstance(Instance* instance);
62  void removeInstance(Instance* instance);
63 
64  void updateInstance(Instance* instance);
65 
66 
67  private:
68  void collect(const Rect& viewport, std::vector<int32_t>& indices);
69  void reset();
70  void fullUpdate();
71 
72  struct Entry {
74  CacheTree::Node* node;
75 
77  signed instance_index;
78 
80  signed entry_index;
82  bool force_update;
83  };
84 
85  Camera* m_camera;
86  Layer* m_layer;
87  CacheLayerChangeListener* m_layer_observer;
88 
89  void updateEntry(Entry& item);
90 
91  std::map<Instance*,int32_t> m_instance_map;
92  std::vector<Entry> m_entries;
93 
94  CacheTree* m_tree;
95  std::vector<RenderItem> m_instances;
96 
97  bool m_needupdate;
98  bool m_need_sorting;
99  };
100 
101 }
102 #endif
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...
Definition: soundclip.cpp:39