comparison engine/core/view/layercache.h @ 482:16c2b3ee59ce

* Merged the view performance branch back into trunk. fixes[ticket:419]
author helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 29 Apr 2010 13:51:45 +0000
parents
children
comparison
equal deleted inserted replaced
481:1f37adc9a685 482:16c2b3ee59ce
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<int> > CacheTree;
52
53 LayerCache(Camera* camera, ImagePool* image_pool, AnimationPool* animation_pool);
54 ~LayerCache();
55
56 void setLayer(Layer* layer);
57 void update(Camera::Transform transform, RenderList& renderlist);
58
59 void addInstance(Instance* instance);
60 void removeInstance(Instance* instance);
61
62 void updateInstance(Instance* instance);
63
64
65 private:
66 void collect(const Rect& viewport, std::vector<int>& indices);
67 void reset();
68 void fullUpdate();
69
70 struct Entry {
71 /// Node in m_tree;
72 CacheTree::Node* node;
73
74 /// Index in m_instances;
75 unsigned instance_index;
76
77 /// Index in m_entries;
78 unsigned entry_index;
79 /// Force update for entries with animation
80 bool force_update;
81 };
82
83 ImagePool* m_image_pool;
84 AnimationPool* m_animation_pool;
85 Camera* m_camera;
86 Layer* m_layer;
87 CacheLayerChangeListener* m_layer_observer;
88
89 void updateEntry(Entry& item);
90
91 std::map<Instance*,int> m_instance_map;
92 std::vector<Entry> m_entries;
93
94 CacheTree* m_tree;
95 std::vector<RenderItem> m_instances;
96 };
97
98 }
99 #endif