| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 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 |
| 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 |
void update(Camera::Transform transform, RenderList& renderlist); |
| 59 |
|
| 60 |
void addInstance(Instance* instance); |
| 61 |
void removeInstance(Instance* instance); |
| 62 |
void updateInstance(Instance* instance); |
| 63 |
|
| 64 |
ImagePtr getCacheImage(); |
| 65 |
void setCacheImage(ImagePtr image); |
| 66 |
|
| 67 |
private: |
| 68 |
enum RenderEntryUpdateType { |
| 69 |
EntryNoneUpdate = 0x00, |
| 70 |
EntryVisualUpdate = 0x01, |
| 71 |
EntryPositionUpdate = 0x02, |
| 72 |
EntryFullUpdate = 0x03 |
| 73 |
}; |
| 74 |
typedef uint8_t RenderEntryUpdate; |
| 75 |
|
| 76 |
struct Entry { |
| 77 |
// Node in m_tree; |
| 78 |
CacheTree::Node* node; |
| 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 |
| 84 |
bool forceUpdate; |
| 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); |
| 94 |
void fullCoordinateUpdate(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 |
|
| 101 |
Camera* m_camera; |
| 102 |
Layer* m_layer; |
| 103 |
CacheLayerChangeListener* m_layerObserver; |
| 104 |
CacheTree* m_tree; |
| 105 |
ImagePtr m_cacheImage; |
| 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 |
|
| 113 |
bool m_needSorting; |
| 114 |
double m_zMin; |
| 115 |
double m_zMax; |
| 116 |
|
| 117 |
double m_zoom; |
| 118 |
bool m_zoomed; |
| 119 |
bool m_straightZoom; |
| 120 |
}; |
| 121 |
} |
| 122 |
#endif |