1 /******************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
14 #include <boost/unordered_map.hpp>
15 #include <libxml/parser.h>
16 #include <libxml/tree.h>
30 This class provides the engine's global resource handling and caching.
35 //! Resourcer Constructor
36 Resourcer(GameWindow
* window
, const std::string
& filename
);
38 //! Resourcer Destructor
41 //! Resourcer Initializer
44 //! Requests an image resource from cache.
45 Gosu::Image
* getImage(const std::string
& name
);
47 //! Requests a bitmap that can be used to construct subimages from cache.
48 void getBitmap(Gosu::Bitmap
& bitmap
, const std::string
& name
);
50 //! Converts a subrectangle of a Bitmap into an Image.
51 Gosu::Image
* bitmapSection(const Gosu::Bitmap
& src
,
52 unsigned x
, unsigned y
, unsigned w
, unsigned h
, bool tileable
);
54 //! Requests an XML resource from cache.
55 xmlDoc
* getXMLDoc(const std::string
& name
);
57 //! Close resource request and drop from cache. IMPORTANT!!!
58 void drop(const std::string
& name
);
60 //! Returns a music stream from disk or cache.
61 Gosu::Sample
* getSample(const std::string
& name
);
64 //! Requests a string resource from cache.
65 std::string
getString(const std::string
& name
);
67 //! Requests a string resource from cache.
68 std::string
getStringFromZip(const std::string
& name
);
70 //! Read a resource from disk into memory. Returns NULL on error.
71 Gosu::Buffer
* read(const std::string
& name
);
74 std::string
path(const std::string
& entry_name
) const;
78 The key is the cached file's name, and the value is a pair of a
79 "tally" and a pointer to the data. The "tally" is increased each
80 time something requests the resource, and decreased each time
81 something is finished with that resource. When the tally reaches
82 zero, nothing is using the resource, and it is dropped after a
83 few minutes. The cache drop timer is in a thread.
85 std::map
<std::string
, std::pair
<int, void*> > cache
;
87 //! Modify the cache tally. Logs a Developer warning on tally underrun.
88 void cacheTally(const std::string
& key
, const int mod
);
92 const std::string zip_filename
;
94 typedef boost::unordered_map
<std::string
, std::string
> strMap
;