# OgreResource.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef _Resource_H__
    00030 #define _Resource_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreString.h"
    00034 #include "OgreSharedPtr.h"
    00035 #include "OgreStringInterface.h"
    00036
    00037 namespace Ogre {
    00038
    00039     typedef unsigned long ResourceHandle;
    00040
    00041
    00042     // Forward declaration
    00043     class ManualResourceLoader;
    00044
    00071     class _OgreExport Resource : public StringInterface
    00072     {
    00073     public:
    00074         OGRE_AUTO_MUTEX // public to allow external locking
    00075         class Listener
    00076         {
    00077         public:
    00078             Listener() {}
    00079             virtual ~Listener() {}
    00080
    00091             virtual void backgroundLoadingComplete(Resource*) {}
    00092
    00093         };
    00094
    00096         enum LoadingState
    00097         {
    00099             LOADSTATE_UNLOADED,
    00101             LOADSTATE_LOADING,
    00103             LOADSTATE_LOADED,
    00105             LOADSTATE_UNLOADING
    00106         };
    00107     protected:
    00109         ResourceManager* mCreator;
    00111         String mName;
    00113         String mGroup;
    00115         ResourceHandle mHandle;
    00117         volatile LoadingState mLoadingState;
    00119         volatile bool mIsBackgroundLoaded;
    00121         OGRE_MUTEX(mLoadingStatusMutex)
    00123         size_t mSize;
    00125         bool mIsManual;
    00127         String mOrigin;
    00129         ManualResourceLoader* mLoader;
    00130
    00131         typedef std::list<Listener*> ListenerList;
    00132         ListenerList mListenerList;
    00133         OGRE_MUTEX(mListenerListMutex)
    00134
    00137         Resource()
    00138             : mCreator(0), mHandle(0), mLoadingState(LOADSTATE_UNLOADED),
    00139             mIsBackgroundLoaded(false), mSize(0), mIsManual(0), mLoader(0)
    00140         {
    00141         }
    00142
    00149         virtual void preLoadImpl(void) {}
    00156         virtual void postLoadImpl(void) {}
    00157
    00161         virtual void preUnloadImpl(void) {}
    00166         virtual void postUnloadImpl(void) {}
    00167
    00171         virtual void loadImpl(void) = 0;
    00175         virtual void unloadImpl(void) = 0;
    00177         virtual size_t calculateSize(void) const = 0;
    00178
    00180         virtual void queueFireBackgroundLoadingComplete(void);
    00181
    00182     public:
    00197         Resource(ResourceManager* creator, const String& name, ResourceHandle handle,
    00198             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
    00199
    00205         virtual ~Resource();
    00206
    00217         virtual void load(bool backgroundThread = false);
    00218
    00224         virtual void reload(void);
    00225
    00228         bool isReloadable(void) const
    00229         {
    00230             return !mIsManual || mLoader;
    00231         }
    00232
    00235         bool isManuallyLoaded(void) const
    00236         {
    00237             return mIsManual;
    00238         }
    00239
    00243         virtual void unload(void);
    00244
    00247         size_t getSize(void) const
    00248         {
    00249             return mSize;
    00250         }
    00251
    00254         virtual void touch(void);
    00255
    00258         const String& getName(void) const
    00259         {
    00260             return mName;
    00261         }
    00262
    00263         ResourceHandle getHandle(void) const
    00264         {
    00265             return mHandle;
    00266         }
    00267
    00270         bool isLoaded(void) const
    00271         {
    00272             // No lock required to read this state since no modify
    00273             return (mLoadingState == LOADSTATE_LOADED);
    00274         }
    00275
    00279         LoadingState isLoading() const
    00280         {
    00281             return mLoadingState;
    00282         }
    00283
    00286         LoadingState getLoadingState() const
    00287         {
    00288             return mLoadingState;
    00289         }
    00290
    00291
    00292
    00303         bool isBackgroundLoaded(void) const { return mIsBackgroundLoaded; }
    00304
    00313         void setBackgroundLoaded(bool bl) { mIsBackgroundLoaded = bl; }
    00314
    00324         void escalateLoading();
    00325
    00329         void addListener(Listener* lis);
    00330
    00334         void removeListener(Listener* lis);
    00335
    00337         const String& getGroup(void) { return mGroup; }
    00338
    00346         void changeGroupOwnership(const String& newGroup);
    00347
    00349         ResourceManager* getCreator(void) { return mCreator; }
    00356         const String& getOrigin(void) const { return mOrigin; }
    00358         void _notifyOrigin(const String& origin) { mOrigin = origin; }
    00359
    00367         virtual void _fireBackgroundLoadingComplete(void);
    00368
    00369     };
    00370
    00389     typedef SharedPtr<Resource> ResourcePtr;
    00390
    00412     class _OgreExport ManualResourceLoader
    00413     {
    00414     public:
    00415         ManualResourceLoader() {}
    00416         virtual ~ManualResourceLoader() {}
    00417
    00421         virtual void loadResource(Resource* resource) = 0;
    00422     };
    00423 }
    00424
    00425 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sat May 10 16:25:02 2008