OgreResource.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef _Resource_H__
#define _Resource_H__
#include "OgrePrerequisites.h"
#include "OgreString.h"
#include "OgreSharedPtr.h"
#include "OgreStringInterface.h"
#include "OgreAtomicScalar.h"
#include "Threading/OgreThreadHeaders.h"
#include "OgreHeaderPrefix.h"
namespace Ogre {
typedef unsigned long long int ResourceHandle;
// Forward declaration
class ManualResourceLoader;
class _OgreExport Resource : public StringInterface, public ResourceAlloc
{
public:
OGRE_AUTO_MUTEX; // public to allow external locking
class Listener
{
public:
Listener() {}
virtual ~Listener() {}
OGRE_DEPRECATED virtual void backgroundLoadingComplete(Resource*) {}
OGRE_DEPRECATED virtual void backgroundPreparingComplete(Resource*) {}
virtual void loadingComplete(Resource*) {}
virtual void preparingComplete(Resource*) {}
virtual void unloadingComplete(Resource*) {}
};
enum LoadingState
{
LOADSTATE_UNLOADED,
LOADSTATE_LOADING,
LOADSTATE_LOADED,
LOADSTATE_UNLOADING,
LOADSTATE_PREPARED,
LOADSTATE_PREPARING
};
protected:
ResourceManager* mCreator;
String mName;
String mGroup;
ResourceHandle mHandle;
AtomicScalar<LoadingState> mLoadingState;
volatile bool mIsBackgroundLoaded;
size_t mSize;
bool mIsManual;
String mOrigin;
ManualResourceLoader* mLoader;
size_t mStateCount;
typedef set<Listener*>::type ListenerList;
ListenerList mListenerList;
OGRE_MUTEX(mListenerListMutex);
Resource()
: mCreator(0), mHandle(0), mLoadingState(LOADSTATE_UNLOADED),
mIsBackgroundLoaded(false), mSize(0), mIsManual(0), mLoader(0)
{
}
virtual void preLoadImpl(void) {}
virtual void postLoadImpl(void) {}
virtual void preUnloadImpl(void) {}
virtual void postUnloadImpl(void) {}
virtual void prepareImpl(void) {}
virtual void unprepareImpl(void) {}
virtual void loadImpl(void) = 0;
virtual void unloadImpl(void) = 0;
public:
Resource(ResourceManager* creator, const String& name, ResourceHandle handle,
const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
virtual ~Resource();
virtual void prepare(bool backgroundThread = false);
virtual void load(bool backgroundThread = false);
virtual void reload(void);
virtual bool isReloadable(void) const
{
return !mIsManual || mLoader;
}
virtual bool isManuallyLoaded(void) const
{
return mIsManual;
}
virtual void unload(void);
virtual size_t getSize(void) const
{
return mSize;
}
virtual void touch(void);
virtual const String& getName(void) const
{
return mName;
}
virtual ResourceHandle getHandle(void) const
{
return mHandle;
}
virtual bool isPrepared(void) const
{
// No lock required to read this state since no modify
return (mLoadingState.get() == LOADSTATE_PREPARED);
}
virtual bool isLoaded(void) const
{
// No lock required to read this state since no modify
return (mLoadingState.get() == LOADSTATE_LOADED);
}
virtual bool isLoading() const
{
return (mLoadingState.get() == LOADSTATE_LOADING);
}
virtual LoadingState getLoadingState() const
{
return mLoadingState.get();
}
virtual bool isBackgroundLoaded(void) const { return mIsBackgroundLoaded; }
virtual void setBackgroundLoaded(bool bl) { mIsBackgroundLoaded = bl; }
virtual void escalateLoading();
virtual void addListener(Listener* lis);
virtual void removeListener(Listener* lis);
virtual const String& getGroup(void) const { return mGroup; }
virtual void changeGroupOwnership(const String& newGroup);
virtual ResourceManager* getCreator(void) { return mCreator; }
virtual const String& getOrigin(void) const { return mOrigin; }
virtual void _notifyOrigin(const String& origin) { mOrigin = origin; }
virtual size_t getStateCount() const { return mStateCount; }
virtual void _dirtyState();
virtual void _fireLoadingComplete(bool wasBackgroundLoaded);
virtual void _firePreparingComplete(bool wasBackgroundLoaded);
virtual void _fireUnloadingComplete(void);
virtual size_t calculateSize(void) const;
};
typedef SharedPtr<Resource> ResourcePtr;
class _OgreExport ManualResourceLoader
{
public:
ManualResourceLoader() {}
virtual ~ManualResourceLoader() {}
virtual void prepareResource(Resource* resource)
{ (void)resource; }
virtual void loadResource(Resource* resource) = 0;
};
}
#include "OgreHeaderSuffix.h"
#endif
Ogre::Resource::mLoadingState
AtomicScalar< LoadingState > mLoadingState
Is the resource currently loaded?
Definition: OgreResource.h:152
Ogre::Resource::Listener::preparingComplete
virtual void preparingComplete(Resource *)
Called whenever the resource finishes preparing (paging into memory).
Definition: OgreResource.h:120
Ogre::Resource::mLoader
ManualResourceLoader * mLoader
Optional manual loader; if provided, data is loaded from here instead of a file.
Definition: OgreResource.h:162
Ogre::Resource::LOADSTATE_LOADING
Loading is in progress.
Definition: OgreResource.h:132
Ogre::Resource::getGroup
virtual const String & getGroup(void) const
Gets the group which this resource is a member of.
Definition: OgreResource.h:399
Ogre::Resource::Listener::Listener
Listener()
Definition: OgreResource.h:86
Ogre::ManualResourceLoader::ManualResourceLoader
ManualResourceLoader()
Definition: OgreResource.h:517
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::Resource::mListenerList
ListenerList mListenerList
Definition: OgreResource.h:167
OgreSharedPtr.h
Ogre::Resource::isBackgroundLoaded
virtual bool isBackgroundLoaded(void) const
Returns whether this Resource has been earmarked for background loading.
Definition: OgreResource.h:365
Ogre::ResourcePtr
SharedPtr< Resource > ResourcePtr
Shared pointer to a Resource.
Definition: OgrePrerequisites.h:317
Ogre::Resource::mStateCount
size_t mStateCount
State count, the number of times this resource has changed state.
Definition: OgreResource.h:164
Ogre::Resource::mHandle
ResourceHandle mHandle
Numeric handle for more efficient look up than name.
Definition: OgreResource.h:150
Ogre::Resource::LOADSTATE_PREPARED
Fully prepared.
Definition: OgreResource.h:138
Ogre::Resource::getOrigin
virtual const String & getOrigin(void) const
Get the origin of this resource, e.g.
Definition: OgreResource.h:418
OGRE_DEPRECATED
#define OGRE_DEPRECATED
Definition: OgrePlatform.h:189
OgreString.h
Ogre::Resource
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:79
Ogre::Resource::Listener::~Listener
virtual ~Listener()
Definition: OgreResource.h:87
OGRE_MUTEX
#define OGRE_MUTEX(name)
Definition: OgreThreadDefinesBoost.h:47
Ogre::Resource::isLoading
virtual bool isLoading() const
Returns whether the resource is currently in the process of background loading.
Definition: OgreResource.h:341
Ogre::AtomicScalar::get
T get(void) const
Definition: OgreAtomicScalar.h:417
Ogre::ManualResourceLoader
Interface describing a manual resource loader.
Definition: OgreResource.h:514
Ogre::ManualResourceLoader::prepareResource
virtual void prepareResource(Resource *resource)
Called when a resource wishes to load.
Definition: OgreResource.h:526
Ogre::Resource::isReloadable
virtual bool isReloadable(void) const
Returns true if the Resource is reloadable, false otherwise.
Definition: OgreResource.h:282
Ogre::ResourceHandle
unsigned long long int ResourceHandle
Definition: OgreResource.h:41
OgreAtomicScalar.h
Ogre::Resource::isLoaded
virtual bool isLoaded(void) const
Returns true if the Resource has been loaded, false otherwise.
Definition: OgreResource.h:332
Ogre::Resource::getName
virtual const String & getName(void) const
Gets resource name.
Definition: OgreResource.h:312
Ogre::Resource::mIsManual
bool mIsManual
Is this file manually loaded?
Definition: OgreResource.h:158
Ogre::Resource::Listener
Definition: OgreResource.h:83
Ogre::Resource::getHandle
virtual ResourceHandle getHandle(void) const
Definition: OgreResource.h:317
Ogre::Resource::mGroup
String mGroup
The name of the resource group.
Definition: OgreResource.h:148
Ogre::Resource::prepareImpl
virtual void prepareImpl(void)
Internal implementation of the meat of the &#39;prepare&#39; action.
Definition: OgreResource.h:205
OgrePrerequisites.h
Ogre::Resource::postLoadImpl
virtual void postLoadImpl(void)
Internal hook to perform actions after the load process, but before the resource has been marked as f...
Definition: OgreResource.h:191
Ogre::Resource::getSize
virtual size_t getSize(void) const
Retrieves info about the size of the resource.
Definition: OgreResource.h:301
Ogre::Resource::mName
String mName
Unique name of the resource.
Definition: OgreResource.h:146
Ogre::Resource::OGRE_AUTO_MUTEX
OGRE_AUTO_MUTEX
Definition: OgreResource.h:82
Ogre::Resource::getLoadingState
virtual LoadingState getLoadingState() const
Returns the current loading state.
Definition: OgreResource.h:348
Ogre::Resource::LOADSTATE_LOADED
Fully loaded.
Definition: OgreResource.h:134
Ogre::Resource::Resource
Resource()
Protected unnamed constructor to prevent default construction.
Definition: OgreResource.h:172
Ogre::Resource::Listener::unloadingComplete
virtual void unloadingComplete(Resource *)
Called whenever the resource has been unloaded.
Definition: OgreResource.h:123
Ogre::StringInterface
Class defining the common interface which classes can use to present a reflection-style, self-defining parameter set to callers.
Definition: OgreStringInterface.h:163
Ogre::Resource::Listener::backgroundLoadingComplete
virtual OGRE_DEPRECATED void backgroundLoadingComplete(Resource *)
Callback to indicate that background loading has completed.
Definition: OgreResource.h:93
Ogre::Resource::mSize
size_t mSize
The size of the resource in bytes.
Definition: OgreResource.h:156
Ogre::ManualResourceLoader::~ManualResourceLoader
virtual ~ManualResourceLoader()
Definition: OgreResource.h:518
Ogre::Resource::setBackgroundLoaded
virtual void setBackgroundLoaded(bool bl)
Tells the resource whether it is background loaded or not.
Definition: OgreResource.h:375
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::Resource::mIsBackgroundLoaded
volatile bool mIsBackgroundLoaded
Is this resource going to be background loaded? Only applicable for multithreaded.
Definition: OgreResource.h:154
Ogre::set
Definition: OgrePrerequisites.h:519
Ogre::Resource::preUnloadImpl
virtual void preUnloadImpl(void)
Internal hook to perform actions before the unload process.
Definition: OgreResource.h:196
Ogre::Resource::Listener::backgroundPreparingComplete
virtual OGRE_DEPRECATED void backgroundPreparingComplete(Resource *)
Callback to indicate that background preparing has completed.
Definition: OgreResource.h:99
OgreHeaderSuffix.h
Ogre::ResourceManager
Defines a generic resource handler.
Definition: OgreResourceManager.h:122
OgreThreadHeaders.h
Ogre::AtomicScalar< LoadingState >
Ogre::Resource::mCreator
ResourceManager * mCreator
Creator.
Definition: OgreResource.h:144
Ogre::Resource::preLoadImpl
virtual void preLoadImpl(void)
Internal hook to perform actions before the load process, but after the resource has been marked as &#39;...
Definition: OgreResource.h:184
Ogre::Resource::LOADSTATE_UNLOADING
Currently unloading.
Definition: OgreResource.h:136
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::Resource::getCreator
virtual ResourceManager * getCreator(void)
Gets the manager which created this resource.
Definition: OgreResource.h:411
Ogre::Resource::unprepareImpl
virtual void unprepareImpl(void)
Internal function for undoing the &#39;prepare&#39; action.
Definition: OgreResource.h:210
Ogre::Resource::LoadingState
LoadingState
Enum identifying the loading state of the resource.
Definition: OgreResource.h:127
Ogre::Resource::mOrigin
String mOrigin
Origin of this resource (e.g. script name) - optional.
Definition: OgreResource.h:160
Ogre::SharedPtr< Resource >
Ogre::Resource::getStateCount
virtual size_t getStateCount() const
Returns the number of times this resource has changed state, which generally means the number of time...
Definition: OgreResource.h:429
OgreHeaderPrefix.h
Ogre::Resource::_notifyOrigin
virtual void _notifyOrigin(const String &origin)
Notify this resource of it&#39;s origin.
Definition: OgreResource.h:420
Ogre::Resource::isPrepared
virtual bool isPrepared(void) const
Returns true if the Resource has been prepared, false otherwise.
Definition: OgreResource.h:324
Ogre::Resource::isManuallyLoaded
virtual bool isManuallyLoaded(void) const
Is this resource manually loaded?
Definition: OgreResource.h:289
Ogre::Resource::postUnloadImpl
virtual void postUnloadImpl(void)
Internal hook to perform actions after the unload process, but before the resource has been marked as...
Definition: OgreResource.h:201
Ogre::Resource::LOADSTATE_UNLOADED
Not loaded.
Definition: OgreResource.h:130
OgreStringInterface.h
Ogre::Resource::ListenerList
set< Listener * >::type ListenerList
Definition: OgreResource.h:166
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::Resource::Listener::loadingComplete
virtual void loadingComplete(Resource *)
Called whenever the resource finishes loading.
Definition: OgreResource.h:109

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.