FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
layercache.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 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
88  RenderEntryUpdate updateInfo;
89  };
90 
91  void collect(const Rect& viewport, std::vector<int32_t>& indices);
92  void reset();
93  void fullUpdate(Camera::Transform transform);
95  void updateEntries(std::set<int32_t>& removes, RenderList& renderlist);
96  bool updateVisual(Entry* entry);
97  void updatePosition(Entry* entry);
98  void updateScreenCoordinate(RenderItem* item, bool changedZoom = true);
99  void sortRenderList(RenderList& renderlist);
100 
104  CacheTree* m_tree;
106 
107  std::map<Instance*, int32_t> m_instance_map;
108  std::vector<Entry*> m_entries;
109  std::vector<RenderItem*> m_renderItems;
110  std::set<int32_t> m_entriesToUpdate;
111  std::deque<int32_t> m_freeEntries;
112 
114  double m_zMin;
115  double m_zMax;
116 
117  double m_zoom;
118  bool m_zoomed;
120  };
121 }
122 #endif
bool visible
Definition: layercache.h:86
void fullUpdate(Camera::Transform transform)
Definition: layercache.cpp:460
std::vector< RenderItem * > RenderList
Definition: renderitem.h:130
void updatePosition(Entry *entry)
Definition: layercache.cpp:695
void setLayer(Layer *layer)
Definition: layercache.cpp:206
QuadTree< std::set< int32_t > > CacheTree
Definition: layercache.h:51
void fullCoordinateUpdate(Camera::Transform transform)
Definition: layercache.cpp:483
void updateScreenCoordinate(RenderItem *item, bool changedZoom=true)
Definition: layercache.cpp:731
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
Definition: camera.h:59
int32_t entryIndex
Definition: layercache.h:82
Camera * m_camera
Definition: layercache.h:101
std::deque< int32_t > m_freeEntries
Definition: layercache.h:111
void sortRenderList(RenderList &renderlist)
Definition: layercache.cpp:752
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:109
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:806
A basic layer on a map.
Definition: layer.h:99
CacheLayerChangeListener * m_layerObserver
Definition: layercache.h:103
CacheTree * m_tree
Definition: layercache.h:104
void setCacheImage(ImagePtr image)
Definition: layercache.cpp:810
bool forceUpdate
Definition: layercache.h:84
std::vector< Entry * > m_entries
Definition: layercache.h:108
void collect(const Rect &viewport, std::vector< int32_t > &indices)
Definition: layercache.cpp:358
QuadTree Node.
Definition: quadtree.h:41
int32_t instanceIndex
Definition: layercache.h:80
uint32_t Transform
Definition: camera.h:69
ImagePtr m_cacheImage
Definition: layercache.h:105
uint8_t RenderEntryUpdate
Definition: layercache.h:74
LayerCache(Camera *camera)
Definition: layercache.cpp:174
CacheTree::Node * node
Definition: layercache.h:78
void update(Camera::Transform transform, RenderList &renderlist)
Definition: layercache.cpp:369
void removeInstance(Instance *instance)
Definition: layercache.cpp:280
void updateEntries(std::set< int32_t > &removes, RenderList &renderlist)
Definition: layercache.cpp:503
void addInstance(Instance *instance)
Definition: layercache.cpp:244
bool updateVisual(Entry *entry)
Definition: layercache.cpp:562
std::map< Instance *, int32_t > m_instance_map
Definition: layercache.h:107
std::set< int32_t > m_entriesToUpdate
Definition: layercache.h:110
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:101
void updateInstance(Instance *instance)
Definition: layercache.cpp:314