Created
April 14, 2013 15:22
-
-
Save erincandescent/5383092 to your computer and use it in GitHub Desktop.
Resource interface changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** REMOVED **/ | |
OGRE_AUTO_MUTEX | |
Resource objects are no longer thread safe, except for getting their state | |
and reference counting | |
virtual void prepareImpl(void) | |
virtual void unprepareImpl(void) | |
virtual void prepare(bool backgroundThread = false); | |
virtual bool isPrepared(void) const | |
virtual void _firePreparingComplete(bool wasBackgroundLoaded); | |
OgreMain will have no notion of "prepared" | |
virtual void loadImpl(void) = 0; | |
All loading will be done by the ResourceLoader | |
virtual void preUnloadImpl(void) | |
virtual void postUnloadImpl(void) | |
Unload process will be | |
unloadImpl(); // Clean up resident portion | |
mLoader->unloaded(this); // Notify manager so it can release resources as appropriate | |
size_t mSize; | |
virtual size_t calculateSize(void) const = 0; | |
virtual size_t getSize(void) const | |
mSize is going. Can be tracked by the ResourceManager implementation if needed | |
(?) would calculateSize remain valuable? | |
bool mIsManual; | |
virtual bool isReloadable(void) const | |
All resources reloadable | |
Convinience class may be added which "caches" resources which would not | |
be reloadable | |
virtual bool isManuallyLoaded(void) const | |
Removal of distinction of Resource System vs Manually Loaded resources from | |
OgreMain | |
virtual void touch(void); | |
Other methodology | |
String mName; | |
String mGroup; | |
ResourceHandle mHandle; | |
String mOrigin; | |
virtual const String& getName(void) const | |
virtual ResourceHandle getHandle(void) const | |
virtual const String& getGroup(void) const | |
virtual void changeGroupOwnership(const String& newGroup); | |
ResourceManager* mCreator; | |
virtual ResourceManager* getCreator(void) { return mCreator; } | |
virtual const String& getOrigin(void) const { return mOrigin; } | |
virtual void _notifyOrigin(const String& origin) { mOrigin = origin; } | |
No longer a part of OgreMain | |
volatile bool mIsBackgroundLoaded; | |
virtual bool isBackgroundLoaded(void) const | |
virtual void setBackgroundLoaded(bool bl) | |
All resource loading may be async | |
virtual void escalateLoading(); | |
No sync loading | |
virtual size_t getStateCount() const { return mStateCount; } | |
virtual void _dirtyState(); | |
size_t mStateCount; | |
Better handled by resource listener (?) | |
/** CHANGED **/ | |
AtomicScalar<LoadingState> mLoadingState; | |
New loading states, no longer atomic, etc | |
ManualResourceLoader* mLoader; | |
ResourceLoader* mLoader; | |
virtual void unloadImpl(void) = 0; | |
Mostly the same, some notification of loader | |
Resource(), ~Resource() | |
Removal of resource names, etc | |
virtual void load(bool backgroundThread = false); | |
All loading may be done in background (backgroundThread option removed) | |
Mainly triggers notifications to ResourceLoader | |
virtual void reload(void); | |
Will notify ResourceLoader. Asynchronous. | |
virtual void unload(void); | |
Drops internal buffers and notifies resource loader | |
/** ADDED **/ | |
AtomicScalar<unsigned> mRefCount; | |
Intrusive shared pointer to support intelligent management (see | |
ResourceLoader::unused near the end of this document) | |
protected: void loadingComplete(void); | |
Called by ResourceLoader when it is ready to load the resource; **must be | |
invoked on the main thread** | |
this->preLoadImpl() | |
mLoader->makeResident(this) | |
this->postLoadImpl() | |
this->_fireLoadingComplete() | |
/** RETAINED **/ | |
ListenerList mListenerList; | |
OGRE_MUTEX(mListenerListMutex) | |
virtual void addListener(Listener* lis); | |
virtual void removeListener(Listener* lis); | |
virtual void _fireLoadingComplete(bool wasBackgroundLoaded); | |
(Without wasBackgroundLoaded) | |
virtual void _fireUnloadingComplete(void); | |
(Unless compelling reason to remove) | |
virtual void preLoadImpl(void) | |
virtual void postLoadImpl(void) | |
virtual bool isLoaded(void) const | |
virtual bool isLoading() const | |
virtual LoadingState getLoadingState() const | |
But no longer virtual | |
/** ResourceLoader **/ | |
class ResourceLoader { | |
friend class Resource; | |
// Methods invoked by Resource. All invoked on the main thread. | |
/** Invoked when the Resource requests to be loaded. May either | |
* synchronously load the resource, or begin an asynchronous loading | |
* process | |
*/ | |
void load(Resource* r); | |
/** Invoked by Resource when it is ready to make itself resident */ | |
void makeResident(Resource* r); | |
/** Invoked by Resource when it has been unloaded */ | |
void unloaded(Resource* r); | |
/** Invoked when the resource is unused - defined as when the resource's | |
* reference count has dropped to zero | |
* | |
* The loader is then responsible for implementing policy regarding if/when | |
* the resource will be unloaded or the resource object destroyed. | |
* | |
* Because at this point the loader *should* be the only object with a | |
* remaining reference to the resource, it intrinsically knows when the | |
* resource becomes used again. | |
*/ | |
void unused(Resource* r); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment