00001
00002
00003
00004
00005
00006
00007 #ifdef USE_TILE
00008 #ifndef TILEMCACHE_H
00009 #define TILEMCACHE_H
00010
00011 #include "debug.h"
00012 #include <vector>
00013
00014 struct dolls_data;
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 class tile_draw_info
00025 {
00026 public:
00027 tile_draw_info() : idx(~0), ofs_x(0), ofs_y(0) {}
00028
00029 void set(tileidx_t _idx, int _ofs_x = 0, int _ofs_y = 0)
00030 { idx = _idx; ofs_x = _ofs_x; ofs_y = _ofs_y; }
00031
00032 tileidx_t idx;
00033 int ofs_x;
00034 int ofs_y;
00035 };
00036
00037 class mcache_entry
00038 {
00039 public:
00040 mcache_entry() : m_ref_count(0) {}
00041 virtual ~mcache_entry() {}
00042
00043 void inc_ref() { m_ref_count++; }
00044 void dec_ref() { m_ref_count--; ASSERT(m_ref_count >= 0); }
00045 int ref_count() { return m_ref_count; }
00046
00047 enum
00048 {
00049
00050 MAX_INFO_COUNT = 3
00051 };
00052
00053 virtual int info(tile_draw_info *dinfo) const { return 0; }
00054 virtual const dolls_data *doll() const { return NULL; }
00055
00056 virtual void construct(writer &th);
00057
00058 virtual bool transparent() const { return false; }
00059
00060 protected:
00061 mcache_entry(reader &th);
00062
00063
00064 int m_ref_count;
00065 };
00066
00067 class mcache_manager
00068 {
00069 public:
00070 ~mcache_manager();
00071
00072 unsigned int register_monster(const monster* mon);
00073 mcache_entry *get(tileidx_t idx);
00074
00075 void clear_nonref();
00076 void clear_all();
00077
00078 void read(reader &th);
00079 void construct(writer &th);
00080
00081 protected:
00082 std::vector<mcache_entry*> m_entries;
00083 };
00084
00085
00086 extern mcache_manager mcache;
00087
00088 #endif
00089 #endif