61 |
* ResourceToBeUpdated() was called |
* ResourceToBeUpdated() was called |
62 |
*/ |
*/ |
63 |
virtual void ResourceUpdated(T_res* pOldResource, T_res* pNewResource, void* pUpdateArg) = 0; |
virtual void ResourceUpdated(T_res* pOldResource, T_res* pNewResource, void* pUpdateArg) = 0; |
64 |
|
|
65 |
|
/** |
66 |
|
* Might be called by the ResourceManager periodically during an |
67 |
|
* update / creation of a resource to inform the consumer about the |
68 |
|
* current progress of that process. This method needs to be |
69 |
|
* implemented by the consumer. |
70 |
|
* |
71 |
|
* @param fProgress - current progress as value between 0.0 and 1.0 |
72 |
|
*/ |
73 |
|
virtual void OnResourceProgress(float fProgress) = 0; |
74 |
}; |
}; |
75 |
|
|
76 |
/** |
/** |
110 |
T_res* Borrow(T_key Key, ResourceConsumer<T_res>* pConsumer) { |
T_res* Borrow(T_key Key, ResourceConsumer<T_res>* pConsumer) { |
111 |
typename ResourceMap::iterator iterEntry = ResourceEntries.find(Key); |
typename ResourceMap::iterator iterEntry = ResourceEntries.find(Key); |
112 |
if (iterEntry == ResourceEntries.end()) { |
if (iterEntry == ResourceEntries.end()) { |
113 |
|
// already create an entry for the resource |
114 |
resource_entry_t entry; |
resource_entry_t entry; |
115 |
entry.key = Key; |
entry.key = Key; |
116 |
entry.resource = Create(Key, pConsumer, entry.arg); |
entry.resource = NULL; |
117 |
entry.consumers.insert(pConsumer); |
entry.consumers.insert(pConsumer); |
|
OnBorrow(entry.resource, pConsumer, entry.arg); |
|
118 |
ResourceEntries[Key] = entry; |
ResourceEntries[Key] = entry; |
119 |
|
// actually create the resource |
120 |
|
entry.resource = Create(Key, pConsumer, entry.arg); |
121 |
|
// now update the entry with the created resource |
122 |
|
ResourceEntries[Key] = entry; |
123 |
|
OnBorrow(entry.resource, pConsumer, entry.arg); |
124 |
return entry.resource; |
return entry.resource; |
125 |
} |
} |
126 |
resource_entry_t& entry = iterEntry->second; |
resource_entry_t& entry = iterEntry->second; |
236 |
* updated by the descendant here |
* updated by the descendant here |
237 |
*/ |
*/ |
238 |
virtual void OnBorrow(T_res* pResource, ResourceConsumer<T_res>* pConsumer, void*& pArg) = 0; |
virtual void OnBorrow(T_res* pResource, ResourceConsumer<T_res>* pConsumer, void*& pArg) = 0; |
239 |
|
|
240 |
|
/** |
241 |
|
* Dispatcher method which should be periodically called by the |
242 |
|
* descendant during update or creation of the resource associated |
243 |
|
* with \a Key. This method will inform all associated consumers |
244 |
|
* of the given resource about the current progress. |
245 |
|
* |
246 |
|
* @param Key - unique identifier of the resource which is |
247 |
|
* currently creating or updating |
248 |
|
* @param fProgress - current progress of that creation / update |
249 |
|
* process as value between 0.0 and 1.0 |
250 |
|
*/ |
251 |
|
void DispatchResourceProgressEvent(T_key Key, float fProgress) { |
252 |
|
typename ResourceMap::iterator iterEntry = ResourceEntries.find(Key); |
253 |
|
if (iterEntry != ResourceEntries.end()) { |
254 |
|
resource_entry_t& entry = iterEntry->second; |
255 |
|
// inform all consumers of that resource about current progress |
256 |
|
typename ConsumerSet::iterator iterCons = entry.consumers.begin(); |
257 |
|
typename ConsumerSet::iterator endCons = entry.consumers.end(); |
258 |
|
for (; iterCons != endCons; iterCons++) { |
259 |
|
(*iterCons)->OnResourceProgress(fProgress); |
260 |
|
} |
261 |
|
} |
262 |
|
} |
263 |
}; |
}; |
264 |
|
|
265 |
#endif // __RESOURCE_MANAGER__ |
#endif // __RESOURCE_MANAGER__ |