FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
layercache.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 by the FIFE team *
3  * http://www.fifengine.net *
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
37 #include "util/math/matrix.h"
38 #include "util/structures/rect.h"
41 
42 #include "rendererbase.h"
43 
44 namespace FIFE {
45 
46  class Camera;
47  class CacheLayerChangeListener;
48 
49  class LayerCache {
50  public:
52 
53  LayerCache(Camera* camera);
54  ~LayerCache();
55 
56  void setLayer(Layer* layer);
57 
58  void update(Camera::Transform transform, RenderList& renderlist);
59 
60  void addInstance(Instance* instance);
61  void removeInstance(Instance* instance);
62  void updateInstance(Instance* instance);
63 
65  void setCacheImage(ImagePtr image);
66 
67  private:
73  };
75 
76  struct Entry {
77  // Node in m_tree;
79  // Index in m_renderItems;
80  int32_t instanceIndex;
81  // Index in m_entries;
82  int32_t entryIndex;
83  // Force update for entries with animation
85  // Is visible
86  bool visible;
87  // Update info
89  };
90 
91  void collect(const Rect& viewport, std::vector<int32_t>& indices);
92  void reset();
93  void fullUpdate(Camera::Transform transform);
94  void updateEntries(std::set<int32_t>& removes, RenderList& renderlist);
95  bool updateVisual(Entry* entry);
96  void updatePosition(Entry* entry);
97  void sortRenderList(RenderList& renderlist);
98 
104 
105  std::map<Instance*, int32_t> m_instance_map;
106  std::vector<Entry*> m_entries;
107  std::vector<RenderItem*> m_renderItems;
108  std::set<int32_t> m_entriesToUpdate;
109  std::deque<int32_t> m_freeEntries;
110 
112  double m_zMin;
113  double m_zMax;
114 
115  double m_zoom;
116  bool m_zoomed;
118  };
119 }
120 #endif
bool visible
Definition: layercache.h:86
void fullUpdate(Camera::Transform transform)
Definition: layercache.cpp:440
std::vector< RenderItem * > RenderList
Definition: renderitem.h:82
void updatePosition(Entry *entry)
Definition: layercache.cpp:589
void setLayer(Layer *layer)
Definition: layercache.cpp:208
QuadTree< std::set< int32_t > > CacheTree
Definition: layercache.h:51
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
Definition: camera.h:58
int32_t entryIndex
Definition: layercache.h:82
Camera * m_camera
Definition: layercache.h:99
std::deque< int32_t > m_freeEntries
Definition: layercache.h:109
void sortRenderList(RenderList &renderlist)
Definition: layercache.cpp:655
RenderEntryUpdate updateInfo
Definition: layercache.h:88
unsigned char uint8_t
Definition: core.h:38
Definition: layercache.h:76
std::vector< RenderItem * > m_renderItems
Definition: layercache.h:107
Dynamic QuadTree A space partitioning tree automatically expanding to adjust to any object size put i...
Definition: quadtree.h:150
ImagePtr getCacheImage()
Definition: layercache.cpp:706
A basic layer on a map.
Definition: layer.h:98
CacheLayerChangeListener * m_layerObserver
Definition: layercache.h:101
CacheTree * m_tree
Definition: layercache.h:102
void setCacheImage(ImagePtr image)
Definition: layercache.cpp:710
bool forceUpdate
Definition: layercache.h:84
std::vector< Entry * > m_entries
Definition: layercache.h:106
void collect(const Rect &viewport, std::vector< int32_t > &indices)
Definition: layercache.cpp:359
QuadTree Node.
Definition: quadtree.h:41
int32_t instanceIndex
Definition: layercache.h:80
uint32_t Transform
Definition: camera.h:68
ImagePtr m_cacheImage
Definition: layercache.h:103
uint8_t RenderEntryUpdate
Definition: layercache.h:74
LayerCache(Camera *camera)
Definition: layercache.cpp:177
CacheTree::Node * node
Definition: layercache.h:78
void update(Camera::Transform transform, RenderList &renderlist)
Definition: layercache.cpp:370
void removeInstance(Instance *instance)
Definition: layercache.cpp:282
void updateEntries(std::set< int32_t > &removes, RenderList &renderlist)
Definition: layercache.cpp:453
void addInstance(Instance *instance)
Definition: layercache.cpp:246
bool updateVisual(Entry *entry)
Definition: layercache.cpp:512
std::map< Instance *, int32_t > m_instance_map
Definition: layercache.h:105
std::set< int32_t > m_entriesToUpdate
Definition: layercache.h:108
An Instance is an &quot;instantiation&quot; of an Object at a Location.
Definition: instance.h:97
void updateInstance(Instance *instance)
Definition: layercache.cpp:316