1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef _RESOURCEHANDLER_H
4 #define _RESOURCEHANDLER_H
5 
6 #include <vector>
7 #include <map>
8 #include <boost/noncopyable.hpp>
9 #include "System/creg/creg_cond.h"
10 #include "Resource.h"
11 
12 class CResourceMapAnalyzer;
13 
14 class CResourceHandler : public boost::noncopyable
15 {
16 	CR_DECLARE_STRUCT(CResourceHandler)
17 
18 public:
19 	static CResourceHandler* GetInstance();
20 	static void FreeInstance();
21 
22 	/**
23 	 * @brief	add a resource
24 	 * @param	resource the resource to add
25 	 * @return	the id of the resource just added
26 	 *
27 	 * Adds a CResource to the pool and retun its resourceId.
28 	 */
29 	int AddResource(const CResource& resource);
30 	/**
31 	 * @brief	resource
32 	 * @param	resourceId index to fetch
33 	 * @return	the searched resource
34 	 *
35 	 * Accesses a CResource instance at a given index
36 	 */
37 	const CResource* GetResource(int resourceId) const;
38 	/**
39 	 * @brief	resource by name
40 	 * @param	resourceName name of the resource to fetch
41 	 * @return	the searched resource
42 	 *
43 	 * Accesses a CResource instance by name
44 	 */
45 	const CResource* GetResourceByName(const std::string& resourceName) const;
46 	/**
47 	 * @brief	resource index by name
48 	 * @param	resourceName name of the resource to fetch
49 	 * @return	index of the searched resource
50 	 *
51 	 * Accesses a resource by name
52 	 */
53 	int GetResourceId(const std::string& resourceName) const;
54 
55 	/**
56 	 * @brief	resource map
57 	 * @param	resourceId index of the resource whichs map to fetch
58 	 * @return	the resource values for all the pixels of the map
59 	 *
60 	 * Returns a resource map by index.
61 	 */
62 	const unsigned char* GetResourceMap(int resourceId) const;
63 	/**
64 	 * @brief	resource map size
65 	 * @param	resourceId index of the resource whichs map size to fetch
66 	 * @return	the number of values in the resource map
67 	 *
68 	 * Returns the resource map size by index.
69 	 */
70 	size_t GetResourceMapSize(int resourceId) const;
71 	/**
72 	 * @brief	resource map width
73 	 * @param	resourceId index of the resource whichs map width to fetch
74 	 * @return	width of values in the resource map
75 	 *
76 	 * Returns the resource map width by index.
77 	 */
78 	size_t GetResourceMapWidth(int resourceId) const;
79 	/**
80 	 * @brief	resource map height
81 	 * @param	resourceId index of the resource whichs map height to fetch
82 	 * @return	height of values in the resource map
83 	 *
84 	 * Returns the resource map height by index.
85 	 */
86 	size_t GetResourceMapHeight(int resourceId) const;
87 	/**
88 	 * @brief	resource map analyzer
89 	 * @param	resourceId index of the resource whichs map analyzer to fetch
90 	 * @return	resource map analyzer
91 	 *
92 	 * Returns the resource map analyzer by index.
93 	 */
94 	const CResourceMapAnalyzer* GetResourceMapAnalyzer(int resourceId);
95 
96 	size_t GetNumResources() const;
97 
98 //	bool IsMetal(int resourceId) const;
99 //	bool IsEnergy(int resourceId) const;
100 	int GetMetalId() const;
101 	int GetEnergyId() const;
102 
103 	bool IsValidId(int resourceId) const;
104 
105 private:
106 	static CResourceHandler* instance;
107 
108 	CResourceHandler();
109 	~CResourceHandler();
110 
111 	std::vector<CResource> resources;
112 	std::map<int, CResourceMapAnalyzer*> resourceMapAnalyzers;
113 
114 	int metalResourceId;
115 	int energyResourceId;
116 };
117 
118 #define resourceHandler CResourceHandler::GetInstance()
119 
120 #endif // _RESOURCEHANDLER_H
121