Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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 
00136         Resource() 
00137             : mCreator(0), mHandle(0), mLoadingState(LOADSTATE_UNLOADED), 
00138             mIsBackgroundLoaded(false), mSize(0), mIsManual(0), mLoader(0)
00139         { 
00140         }
00141 
00148         virtual void preLoadImpl(void) {}
00155         virtual void postLoadImpl(void) {}
00156 
00160         virtual void preUnloadImpl(void) {}
00165         virtual void postUnloadImpl(void) {}
00166 
00170         virtual void loadImpl(void) = 0;
00174         virtual void unloadImpl(void) = 0;
00176         virtual size_t calculateSize(void) const = 0;
00177 
00179         virtual void queueFireBackgroundLoadingComplete(void);
00180 
00181     public:
00196         Resource(ResourceManager* creator, const String& name, ResourceHandle handle,
00197             const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
00198 
00204         virtual ~Resource();
00205 
00216         virtual void load(bool backgroundThread = false);
00217 
00223         virtual void reload(void);
00224 
00227         bool isReloadable(void) const
00228         {
00229             return !mIsManual || mLoader;
00230         }
00231 
00234         bool isManuallyLoaded(void) const
00235         {
00236             return mIsManual;
00237         }
00238 
00242         virtual void unload(void);
00243 
00246         size_t getSize(void) const
00247         { 
00248             return mSize; 
00249         }
00250 
00253         virtual void touch(void);
00254 
00257         const String& getName(void) const 
00258         { 
00259             return mName; 
00260         }
00261 
00262         ResourceHandle getHandle(void) const
00263         {
00264             return mHandle;
00265         }
00266 
00269         bool isLoaded(void) const 
00270         { 
00271             // No lock required to read this state since no modify
00272             return (mLoadingState == LOADSTATE_LOADED); 
00273         }
00274 
00278         LoadingState isLoading() const
00279         {
00280             return mLoadingState;
00281         }
00282 
00285         LoadingState getLoadingState() const
00286         {
00287             return mLoadingState;
00288         }
00289 
00290 
00291 
00302         bool isBackgroundLoaded(void) const { return mIsBackgroundLoaded; }
00303 
00312         void setBackgroundLoaded(bool bl) { mIsBackgroundLoaded = bl; }
00313 
00323         void escalateLoading();
00324 
00328         void addListener(Listener* lis);
00329 
00333         void removeListener(Listener* lis);
00334 
00336         const String& getGroup(void) { return mGroup; }
00337 
00345         void changeGroupOwnership(const String& newGroup);
00346 
00348         ResourceManager* getCreator(void) { return mCreator; }
00355         const String& getOrigin(void) const { return mOrigin; }
00357         void _notifyOrigin(const String& origin) { mOrigin = origin; }
00358 
00359     };
00360 
00379     typedef SharedPtr<Resource> ResourcePtr;
00380 
00402     class _OgreExport ManualResourceLoader
00403     {
00404     public:
00405         ManualResourceLoader() {}
00406         virtual ~ManualResourceLoader() {}
00407 
00411         virtual void loadResource(Resource* resource) = 0;
00412     };
00413 }
00414 
00415 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun May 6 10:54:23 2007