1 /******************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
14 #include <Gosu/Gosu.hpp>
15 #include <libxml/parser.h>
16 #include <libxml/tree.h>
19 // Time to live for empty cache members. Defaults to 5 minutes.
20 #define CACHE_EMPTY_TTL "300"
26 This class provides the engine's global resource handling and caching.
31 //! Resourcer Constructor
32 Resourcer(GameWindow
* window
, const std::string
& filename
);
34 //! Resourcer Destructor
37 //! Resourcer Initializer
40 //! Requests an image resource from cache.
41 Gosu::Image
* getImage(const std::string
& name
);
43 //! Requests a bitmap that can be used to construct subimages from cache.
44 Gosu::Bitmap
getBitmap(const std::string
& name
);
46 //! Converts a subrectangle of a Bitmap into an Image.
47 Gosu::Image
* bitmapSection(const Gosu::Bitmap
& src
,
48 unsigned x
, unsigned y
, unsigned w
, unsigned h
, bool tileable
);
50 //! Requests a string resource from cache.
51 std::string
getString(const std::string
& name
);
53 //! Requests an XML resource from cache.
54 xmlDoc
* getXMLDoc(const std::string
& name
);
56 //! Close resource request and drop from cache. IMPORTANT!!!
57 void drop(const std::string
& name
);
59 //! Returns a music stream from disk or cache.
60 Gosu::Sample
* getSample(const std::string
& name
);
63 //! Read a resource from disk into memory. Returns NULL on error.
64 Gosu::Buffer
* read(const std::string
& name
);
67 std::string
path(const std::string
& entry_name
) const;
71 const std::string zip_filename
;
75 The key is the cached file's name, and the value is a pair of a
76 "tally" and a pointer to the data. The "tally" is increased each
77 time something requests the resource, and decreased each time
78 something is finished with that resource. When the tally reaches
79 zero, nothing is using the resource, and it is dropped after a
80 few minutes. The cache drop timer is in a thread.
82 std::map
<std::string
, std::pair
<int, void*> > cache
;
84 //! Modify the cache tally. Logs a Developer warning on tally underrun.
85 void cacheTally(const std::string
& key
, const int mod
);