OGRE  1.9.0
OgreResource.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef _Resource_H__
29#define _Resource_H__
30
31#include "OgrePrerequisites.h"
32#include "OgreString.h"
33#include "OgreSharedPtr.h"
34#include "OgreStringInterface.h"
35#include "OgreAtomicScalar.h"
37#include "OgreHeaderPrefix.h"
38
39namespace Ogre {
40
41 typedef unsigned long long int ResourceHandle;
42
43
44 // Forward declaration
46
80 {
81 public:
82 OGRE_AUTO_MUTEX; // public to allow external locking
84 {
85 public:
87 virtual ~Listener() {}
88
94
100
109 virtual void loadingComplete(Resource*) {}
110
111
120 virtual void preparingComplete(Resource*) {}
121
123 virtual void unloadingComplete(Resource*) {}
124 };
125
142 protected:
154 volatile bool mIsBackgroundLoaded;
156 size_t mSize;
165
168 OGRE_MUTEX(mListenerListMutex);
169
177
184 virtual void preLoadImpl(void) {}
191 virtual void postLoadImpl(void) {}
192
196 virtual void preUnloadImpl(void) {}
201 virtual void postUnloadImpl(void) {}
202
205 virtual void prepareImpl(void) {}
210 virtual void unprepareImpl(void) {}
214 virtual void loadImpl(void) = 0;
218 virtual void unloadImpl(void) = 0;
219
220 public:
235 Resource(ResourceManager* creator, const String& name, ResourceHandle handle,
236 const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
237
243 virtual ~Resource();
244
259 virtual void prepare(bool backgroundThread = false);
260
271 virtual void load(bool backgroundThread = false);
272
278 virtual void reload(void);
279
282 virtual bool isReloadable(void) const
283 {
284 return !mIsManual || mLoader;
285 }
286
289 virtual bool isManuallyLoaded(void) const
290 {
291 return mIsManual;
292 }
293
297 virtual void unload(void);
298
301 virtual size_t getSize(void) const
302 {
303 return mSize;
304 }
305
308 virtual void touch(void);
309
312 virtual const String& getName(void) const
313 {
314 return mName;
315 }
316
317 virtual ResourceHandle getHandle(void) const
318 {
319 return mHandle;
320 }
321
324 virtual bool isPrepared(void) const
325 {
326 // No lock required to read this state since no modify
327 return (mLoadingState.get() == LOADSTATE_PREPARED);
328 }
329
332 virtual bool isLoaded(void) const
333 {
334 // No lock required to read this state since no modify
335 return (mLoadingState.get() == LOADSTATE_LOADED);
336 }
337
341 virtual bool isLoading() const
342 {
343 return (mLoadingState.get() == LOADSTATE_LOADING);
344 }
345
349 {
350 return mLoadingState.get();
351 }
352
353
354
365 virtual bool isBackgroundLoaded(void) const { return mIsBackgroundLoaded; }
366
375 virtual void setBackgroundLoaded(bool bl) { mIsBackgroundLoaded = bl; }
376
386 virtual void escalateLoading();
387
391 virtual void addListener(Listener* lis);
392
396 virtual void removeListener(Listener* lis);
397
399 virtual const String& getGroup(void) const { return mGroup; }
400
408 virtual void changeGroupOwnership(const String& newGroup);
409
411 virtual ResourceManager* getCreator(void) { return mCreator; }
418 virtual const String& getOrigin(void) const { return mOrigin; }
420 virtual void _notifyOrigin(const String& origin) { mOrigin = origin; }
421
429 virtual size_t getStateCount() const { return mStateCount; }
430
436 virtual void _dirtyState();
437
438
447 virtual void _fireLoadingComplete(bool wasBackgroundLoaded);
448
457 virtual void _firePreparingComplete(bool wasBackgroundLoaded);
458
466 virtual void _fireUnloadingComplete(void);
467
469 virtual size_t calculateSize(void) const;
470
471 };
472
492
515 {
516 public:
519
526 virtual void prepareResource(Resource* resource)
527 { (void)resource; }
528
532 virtual void loadResource(Resource* resource) = 0;
533 };
534
536}
537
538#include "OgreHeaderSuffix.h"
539
540#endif
#define _OgreExport
#define OGRE_DEPRECATED
Interface describing a manual resource loader.
virtual void prepareResource(Resource *resource)
Called when a resource wishes to load.
virtual void loadResource(Resource *resource)=0
Called when a resource wishes to prepare.
Defines a generic resource handler.
virtual OGRE_DEPRECATED void backgroundPreparingComplete(Resource *)
Callback to indicate that background preparing has completed.
virtual void preparingComplete(Resource *)
Called whenever the resource finishes preparing (paging into memory).
virtual void unloadingComplete(Resource *)
Called whenever the resource has been unloaded.
virtual void loadingComplete(Resource *)
Called whenever the resource finishes loading.
virtual OGRE_DEPRECATED void backgroundLoadingComplete(Resource *)
Callback to indicate that background loading has completed.
Abstract class representing a loadable resource (e.g.
Resource(ResourceManager *creator, const String &name, ResourceHandle handle, const String &group, bool isManual=false, ManualResourceLoader *loader=0)
Standard constructor.
virtual size_t getSize(void) const
Retrieves info about the size of the resource.
virtual bool isPrepared(void) const
Returns true if the Resource has been prepared, false otherwise.
LoadingState
Enum identifying the loading state of the resource.
@ LOADSTATE_PREPARED
Fully prepared.
@ LOADSTATE_UNLOADED
Not loaded.
@ LOADSTATE_UNLOADING
Currently unloading.
@ LOADSTATE_LOADED
Fully loaded.
@ LOADSTATE_PREPARING
Preparing is in progress.
@ LOADSTATE_LOADING
Loading is in progress.
virtual ~Resource()
Virtual destructor.
virtual void postLoadImpl(void)
Internal hook to perform actions after the load process, but before the resource has been marked as f...
ManualResourceLoader * mLoader
Optional manual loader; if provided, data is loaded from here instead of a file.
bool mIsManual
Is this file manually loaded?
virtual ResourceManager * getCreator(void)
Gets the manager which created this resource.
String mName
Unique name of the resource.
virtual LoadingState getLoadingState() const
Returns the current loading state.
virtual ResourceHandle getHandle(void) const
OGRE_MUTEX(mListenerListMutex)
ResourceHandle mHandle
Numeric handle for more efficient look up than name.
virtual void preUnloadImpl(void)
Internal hook to perform actions before the unload process.
String mOrigin
Origin of this resource (e.g. script name) - optional.
virtual void prepare(bool backgroundThread=false)
Prepares the resource for load, if it is not already.
virtual void escalateLoading()
Escalates the loading of a background loaded resource.
size_t mStateCount
State count, the number of times this resource has changed state.
virtual bool isLoading() const
Returns whether the resource is currently in the process of background loading.
virtual void removeListener(Listener *lis)
Remove a listener on this resource.
virtual void _notifyOrigin(const String &origin)
Notify this resource of it's origin.
String mGroup
The name of the resource group.
virtual void _fireUnloadingComplete(void)
Firing of unloading complete event.
virtual size_t calculateSize(void) const
Calculate the size of a resource; this will only be called after 'load'.
virtual void addListener(Listener *lis)
Register a listener on this resource.
virtual const String & getName(void) const
Gets resource name.
virtual void prepareImpl(void)
Internal implementation of the meat of the 'prepare' action.
virtual bool isBackgroundLoaded(void) const
Returns whether this Resource has been earmarked for background loading.
virtual void load(bool backgroundThread=false)
Loads the resource, if it is not already.
volatile bool mIsBackgroundLoaded
Is this resource going to be background loaded? Only applicable for multithreaded.
virtual const String & getGroup(void) const
Gets the group which this resource is a member of.
set< Listener * >::type ListenerList
virtual bool isLoaded(void) const
Returns true if the Resource has been loaded, false otherwise.
virtual void _firePreparingComplete(bool wasBackgroundLoaded)
Firing of preparing complete event.
ResourceManager * mCreator
Creator.
virtual void _fireLoadingComplete(bool wasBackgroundLoaded)
Firing of loading complete event.
virtual const String & getOrigin(void) const
Get the origin of this resource, e.g.
virtual bool isReloadable(void) const
Returns true if the Resource is reloadable, false otherwise.
virtual bool isManuallyLoaded(void) const
Is this resource manually loaded?
virtual void unloadImpl(void)=0
Internal implementation of the 'unload' action; called regardless of whether this resource is being l...
ListenerList mListenerList
AtomicScalar< LoadingState > mLoadingState
Is the resource currently loaded?
virtual void unload(void)
Unloads the resource; this is not permanent, the resource can be reloaded later if required.
virtual void unprepareImpl(void)
Internal function for undoing the 'prepare' action.
virtual void changeGroupOwnership(const String &newGroup)
Change the resource group ownership of a Resource.
virtual void postUnloadImpl(void)
Internal hook to perform actions after the unload process, but before the resource has been marked as...
virtual void reload(void)
Reloads the resource, if it is already loaded.
virtual void preLoadImpl(void)
Internal hook to perform actions before the load process, but after the resource has been marked as '...
virtual size_t getStateCount() const
Returns the number of times this resource has changed state, which generally means the number of time...
virtual void setBackgroundLoaded(bool bl)
Tells the resource whether it is background loaded or not.
virtual void touch(void)
'Touches' the resource to indicate it has been used.
virtual void loadImpl(void)=0
Internal implementation of the meat of the 'load' action, only called if this resource is not being l...
Resource()
Protected unnamed constructor to prevent default construction.
virtual void _dirtyState()
Manually mark the state of this resource as having been changed.
size_t mSize
The size of the resource in bytes.
Reference-counted shared pointer, used for objects where implicit destruction is required.
SharedPtr< Resource > ResourcePtr
Shared pointer to a Resource.
ResourceAllocatedObject ResourceAlloc
unsigned long long int ResourceHandle
_StringBase String
std::set< T, P, A > type