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 "OgreAtomicScalar.h"
37 #include "OgreHeaderPrefix.h"
38 
39 namespace 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
83  class Listener
84  {
85  public:
86  Listener() {}
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 
128  {
140  LOADSTATE_PREPARING
141  };
142  protected:
154  volatile bool mIsBackgroundLoaded;
156  size_t mSize;
158  bool mIsManual;
164  size_t mStateCount;
165 
168  OGRE_MUTEX(mListenerListMutex);
169 
173  : mCreator(0), mHandle(0), mLoadingState(LOADSTATE_UNLOADED),
174  mIsBackgroundLoaded(false), mSize(0), mIsManual(0), mLoader(0)
175  {
176  }
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 
491  typedef SharedPtr<Resource> ResourcePtr;
492 
515  {
516  public:
519 
526  virtual void prepareResource(Resource* resource)
527  { (void)resource; }
528 
532  virtual void loadResource(Resource* resource) = 0;
533  };
536 }
537 
538 #include "OgreHeaderSuffix.h"
539 
540 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Oct 23 2013 06:57:25