OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreResource.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE 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 "OgreAtomicWrappers.h"
36 #include "OgreHeaderPrefix.h"
37 
38 namespace Ogre {
39 
40  typedef unsigned long long int ResourceHandle;
41 
42 
43  // Forward declaration
45 
79  {
80  public:
81  OGRE_AUTO_MUTEX // public to allow external locking
82  class Listener
83  {
84  public:
85  Listener() {}
86  virtual ~Listener() {}
87 
93 
99 
108  virtual void loadingComplete(Resource*) {}
109 
110 
119  virtual void preparingComplete(Resource*) {}
120 
122  virtual void unloadingComplete(Resource*) {}
123  };
124 
127  {
139  LOADSTATE_PREPARING
140  };
141  protected:
153  volatile bool mIsBackgroundLoaded;
155  size_t mSize;
157  bool mIsManual;
163  size_t mStateCount;
164 
167  OGRE_MUTEX(mListenerListMutex)
168 
169 
172  : mCreator(0), mHandle(0), mLoadingState(LOADSTATE_UNLOADED),
173  mIsBackgroundLoaded(false), mSize(0), mIsManual(0), mLoader(0)
174  {
175  }
176 
183  virtual void preLoadImpl(void) {}
190  virtual void postLoadImpl(void) {}
191 
195  virtual void preUnloadImpl(void) {}
200  virtual void postUnloadImpl(void) {}
201 
204  virtual void prepareImpl(void) {}
209  virtual void unprepareImpl(void) {}
213  virtual void loadImpl(void) = 0;
217  virtual void unloadImpl(void) = 0;
219  virtual size_t calculateSize(void) const = 0;
220 
221  public:
236  Resource(ResourceManager* creator, const String& name, ResourceHandle handle,
237  const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
238 
244  virtual ~Resource();
245 
260  virtual void prepare(bool backgroundThread = false);
261 
272  virtual void load(bool backgroundThread = false);
273 
279  virtual void reload(void);
280 
283  virtual bool isReloadable(void) const
284  {
285  return !mIsManual || mLoader;
286  }
287 
290  virtual bool isManuallyLoaded(void) const
291  {
292  return mIsManual;
293  }
294 
298  virtual void unload(void);
299 
302  virtual size_t getSize(void) const
303  {
304  return mSize;
305  }
306 
309  virtual void touch(void);
310 
313  virtual const String& getName(void) const
314  {
315  return mName;
316  }
317 
318  virtual ResourceHandle getHandle(void) const
319  {
320  return mHandle;
321  }
322 
325  virtual bool isPrepared(void) const
326  {
327  // No lock required to read this state since no modify
328  return (mLoadingState.get() == LOADSTATE_PREPARED);
329  }
330 
333  virtual bool isLoaded(void) const
334  {
335  // No lock required to read this state since no modify
336  return (mLoadingState.get() == LOADSTATE_LOADED);
337  }
338 
342  virtual bool isLoading() const
343  {
344  return (mLoadingState.get() == LOADSTATE_LOADING);
345  }
346 
350  {
351  return mLoadingState.get();
352  }
353 
354 
355 
366  virtual bool isBackgroundLoaded(void) const { return mIsBackgroundLoaded; }
367 
376  virtual void setBackgroundLoaded(bool bl) { mIsBackgroundLoaded = bl; }
377 
387  virtual void escalateLoading();
388 
392  virtual void addListener(Listener* lis);
393 
397  virtual void removeListener(Listener* lis);
398 
400  virtual const String& getGroup(void) const { return mGroup; }
401 
409  virtual void changeGroupOwnership(const String& newGroup);
410 
412  virtual ResourceManager* getCreator(void) { return mCreator; }
419  virtual const String& getOrigin(void) const { return mOrigin; }
421  virtual void _notifyOrigin(const String& origin) { mOrigin = origin; }
422 
430  virtual size_t getStateCount() const { return mStateCount; }
431 
437  virtual void _dirtyState();
438 
439 
448  virtual void _fireLoadingComplete(bool wasBackgroundLoaded);
449 
458  virtual void _firePreparingComplete(bool wasBackgroundLoaded);
459 
467  virtual void _fireUnloadingComplete(void);
468 
469 
470  };
471 
491 
514  {
515  public:
518 
525  virtual void prepareResource(Resource* resource)
526  { (void)resource; }
527 
531  virtual void loadResource(Resource* resource) = 0;
532  };
535 }
536 
537 #include "OgreHeaderSuffix.h"
538 
539 #endif
virtual void preparingComplete(Resource *)
called whenever the resource finishes preparing (paging into memory).
Definition: OgreResource.h:119
virtual bool isBackgroundLoaded(void) const
Returns whether this Resource has been earmarked for background loading.
Definition: OgreResource.h:366
#define OGRE_AUTO_MUTEX
virtual void backgroundLoadingComplete(Resource *)
Callback to indicate that background loading has completed.
Definition: OgreResource.h:92
#define _OgreExport
Definition: OgrePlatform.h:233
virtual LoadingState getLoadingState() const
Returns the current loading state.
Definition: OgreResource.h:349
virtual bool isReloadable(void) const
Returns true if the Resource is reloadable, false otherwise.
Definition: OgreResource.h:283
virtual void preLoadImpl(void)
Internal hook to perform actions before the load process, but after the resource has been marked as '...
Definition: OgreResource.h:183
LoadingState
Enum identifying the loading state of the resource.
Definition: OgreResource.h:126
virtual void _notifyOrigin(const String &origin)
Notify this resource of it's origin.
Definition: OgreResource.h:421
AtomicScalar< LoadingState > mLoadingState
Is the resource currently loaded?
Definition: OgreResource.h:151
#define OGRE_MUTEX(name)
Interface describing a manual resource loader.
Definition: OgreResource.h:513
virtual void unloadingComplete(Resource *)
Called whenever the resource has been unloaded.
Definition: OgreResource.h:122
virtual bool isManuallyLoaded(void) const
Is this resource manually loaded?
Definition: OgreResource.h:290
virtual size_t getSize(void) const
Retrieves info about the size of the resource.
Definition: OgreResource.h:302
virtual const String & getName(void) const
Gets resource name.
Definition: OgreResource.h:313
ListenerList mListenerList
Definition: OgreResource.h:166
virtual void preUnloadImpl(void)
Internal hook to perform actions before the unload process.
Definition: OgreResource.h:195
virtual void prepareResource(Resource *resource)
Called when a resource wishes to load.
Definition: OgreResource.h:525
virtual void backgroundPreparingComplete(Resource *)
Callback to indicate that background preparing has completed.
Definition: OgreResource.h:98
Class defining the common interface which classes can use to present a reflection-style, self-defining parameter set to callers.
virtual bool isPrepared(void) const
Returns true if the Resource has been prepared, false otherwise.
Definition: OgreResource.h:325
String mGroup
The name of the resource group.
Definition: OgreResource.h:147
virtual void unprepareImpl(void)
Internal function for undoing the 'prepare' action.
Definition: OgreResource.h:209
size_t mSize
The size of the resource in bytes.
Definition: OgreResource.h:155
ManualResourceLoader * mLoader
Optional manual loader; if provided, data is loaded from here instead of a file.
Definition: OgreResource.h:161
virtual ResourceManager * getCreator(void)
Gets the manager which created this resource.
Definition: OgreResource.h:412
String mOrigin
Origin of this resource (e.g. script name) - optional.
Definition: OgreResource.h:159
SharedPtr< Resource > ResourcePtr
Shared pointer to a Resource.
Definition: OgreResource.h:490
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
virtual const String & getGroup(void) const
Gets the group which this resource is a member of.
Definition: OgreResource.h:400
virtual bool isLoading() const
Returns whether the resource is currently in the process of background loading.
Definition: OgreResource.h:342
virtual bool isLoaded(void) const
Returns true if the Resource has been loaded, false otherwise.
Definition: OgreResource.h:333
virtual const String & getOrigin(void) const
Get the origin of this resource, e.g.
Definition: OgreResource.h:419
bool mIsManual
Is this file manually loaded?
Definition: OgreResource.h:157
String mName
Unique name of the resource.
Definition: OgreResource.h:145
virtual void loadingComplete(Resource *)
Called whenever the resource finishes loading.
Definition: OgreResource.h:108
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:78
unsigned long long int ResourceHandle
Definition: OgreResource.h:40
virtual void prepareImpl(void)
Internal implementation of the meat of the 'prepare' action.
Definition: OgreResource.h:204
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:190
virtual void setBackgroundLoaded(bool bl)
Tells the resource whether it is background loaded or not.
Definition: OgreResource.h:376
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:430
ResourceManager * mCreator
Creator.
Definition: OgreResource.h:143
ResourceHandle mHandle
Numeric handle for more efficient look up than name.
Definition: OgreResource.h:149
Defines a generic resource handler.
_StringBase String
volatile bool mIsBackgroundLoaded
Is this resource going to be background loaded? Only applicable for multithreaded.
Definition: OgreResource.h:153
size_t mStateCount
State count, the number of times this resource has changed state.
Definition: OgreResource.h:163
Loading is in progress.
Definition: OgreResource.h:131
virtual ResourceHandle getHandle(void) const
Definition: OgreResource.h:318
virtual void postUnloadImpl(void)
Internal hook to perform actions after the unload process, but before the resource has been marked as...
Definition: OgreResource.h:200
set< Listener * >::type ListenerList
Definition: OgreResource.h:165