00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIFE_VIEW_LAYERCACHE_H
00023 #define FIFE_VIEW_LAYERCACHE_H
00024
00025
00026 #include <string>
00027 #include <map>
00028 #include <set>
00029
00030
00031
00032
00033
00034
00035
00036 #include "model/structures/location.h"
00037 #include "util/math/matrix.h"
00038 #include "util/structures/rect.h"
00039 #include "util/structures/quadtree.h"
00040 #include "model/metamodel/grids/cellgrid.h"
00041
00042 #include "rendererbase.h"
00043
00044 namespace FIFE {
00045
00046 class Camera;
00047 class CacheLayerChangeListener;
00048
00049 class LayerCache {
00050 public:
00051 typedef QuadTree<std::set<int32_t> > CacheTree;
00052
00053 LayerCache(Camera* camera);
00054 ~LayerCache();
00055
00056 void setLayer(Layer* layer);
00057
00058 bool needUpdate() { return m_needupdate; }
00059 void update(Camera::Transform transform, RenderList& renderlist);
00060
00061 void addInstance(Instance* instance);
00062 void removeInstance(Instance* instance);
00063
00064 void updateInstance(Instance* instance);
00065
00066
00067 private:
00068 void collect(const Rect& viewport, std::vector<int32_t>& indices);
00069 void reset();
00070 void fullUpdate();
00071
00072 struct Entry {
00074 CacheTree::Node* node;
00075
00077 signed instance_index;
00078
00080 signed entry_index;
00082 bool force_update;
00083 };
00084
00085 Camera* m_camera;
00086 Layer* m_layer;
00087 CacheLayerChangeListener* m_layer_observer;
00088
00089 void updateEntry(Entry& item);
00090
00091 std::map<Instance*,int32_t> m_instance_map;
00092 std::vector<Entry> m_entries;
00093
00094 CacheTree* m_tree;
00095 std::vector<RenderItem> m_instances;
00096
00097 bool m_needupdate;
00098 bool m_need_sorting;
00099 };
00100
00101 }
00102 #endif