layercache.h
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<int> > CacheTree;
00052
00053 LayerCache(Camera* camera, ImagePool* image_pool, AnimationPool* animation_pool);
00054 ~LayerCache();
00055
00056 void setLayer(Layer* layer);
00057 void update(Camera::Transform transform, RenderList& renderlist);
00058
00059 void addInstance(Instance* instance);
00060 void removeInstance(Instance* instance);
00061
00062 void updateInstance(Instance* instance);
00063
00064
00065 private:
00066 void collect(const Rect& viewport, std::vector<int>& indices);
00067 void reset();
00068 void fullUpdate();
00069
00070 struct Entry {
00072 CacheTree::Node* node;
00073
00075 unsigned instance_index;
00076
00078 unsigned entry_index;
00080 bool force_update;
00081 };
00082
00083 ImagePool* m_image_pool;
00084 AnimationPool* m_animation_pool;
00085 Camera* m_camera;
00086 Layer* m_layer;
00087 CacheLayerChangeListener* m_layer_observer;
00088
00089 void updateEntry(Entry& item);
00090
00091 std::map<Instance*,int> m_instance_map;
00092 std::vector<Entry> m_entries;
00093
00094 CacheTree* m_tree;
00095 std::vector<RenderItem> m_instances;
00096 };
00097
00098 }
00099 #endif