1 /******************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
14 #include <boost/scoped_ptr.hpp>
15 #include <boost/shared_ptr.hpp>
16 #include <boost/unordered_map.hpp>
17 #include <libxml/parser.h>
18 #include <libxml/tree.h>
33 // We hand out and manage Gosu resources in these forms:
34 typedef boost::scoped_ptr
<Gosu::Buffer
> BufferPtr
;
35 typedef boost::shared_ptr
<Gosu::Image
> ImageRef
;
36 typedef boost::shared_ptr
<Gosu::Sample
> SampleRef
;
37 typedef std::deque
<ImageRef
> TiledImage
;
39 typedef boost::shared_ptr
<xmlDoc
> XMLDocRef
;
43 This class provides the engine's global resource handling and caching.
48 //! Resourcer Constructor
49 Resourcer(GameWindow
* window
, ClientValues
* conf
);
51 //! Resourcer Destructor
54 //! Resourcer Initializer
57 //! Requests an image resource from cache.
58 ImageRef
getImage(const std::string
& name
);
60 //! Requests an image resource from cache and splits it into a number
61 // of tiles each with with and height w by x. Returns false if the
62 // source image wasn't found.
63 bool getTiledImage(TiledImage
& img
, const std::string
& name
,
64 unsigned w
, unsigned h
, bool tileable
);
66 //! Returns a music stream from disk or cache.
67 SampleRef
getSample(const std::string
& name
);
69 //! Requests an XML resource from cache.
70 XMLDocRef
getXMLDoc(const std::string
& name
,
71 const std::string
& dtdPath
);
74 typedef boost::unordered_map
<std::string
, ImageRef
> ImageRefMap
;
75 typedef boost::unordered_map
<std::string
, SampleRef
> SampleRefMap
;
76 typedef boost::unordered_map
<std::string
, XMLDocRef
> XMLMap
;
77 typedef boost::unordered_map
<std::string
, TiledImage
> TiledImageMap
;
79 //! Requests an XML document from disk.
80 xmlDoc
* readXMLDocFromDisk(const std::string
& name
,
81 const std::string
& dtdPath
);
83 //! Requests a string resource from disk.
84 std::string
readStringFromDisk(const std::string
& name
);
86 //! Read a generic resource from disk.
87 Gosu::Buffer
* read(const std::string
& name
);
90 std::string
path(const std::string
& entry_name
) const;
98 The key is the cached file's name, and the value is a pair of a
99 "tally" and a pointer to the data. The "tally" is increased each
100 time something requests the resource, and decreased each time
101 something is finished with that resource. When the tally reaches
102 zero, nothing is using the resource, and it is dropped after a
103 few minutes. The cache drop timer is in a thread.
106 SampleRefMap samples
;