resourceManager.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _RESOURCEMANAGER_H_
  23. #define _RESOURCEMANAGER_H_
  24. #ifndef __RESOURCE_H__
  25. #include "core/resource.h"
  26. #endif
  27. #ifndef _TDICTIONARY_H_
  28. #include "core/util/tDictionary.h"
  29. #endif
  30. class ResourceManager
  31. {
  32. public:
  33. static ResourceManager &get();
  34. ResourceBase load(const Torque::Path &path);
  35. ResourceBase find(const Torque::Path &path);
  36. ResourceBase startResourceList( ResourceBase::Signature inSignature = U32_MAX );
  37. ResourceBase nextResource();
  38. void reloadResource( const Torque::Path &path, bool showMessage = false );
  39. typedef Signal<void(const Torque::Path &path)> ChangedSignal;
  40. /// Registering with this signal will give an opportunity to handle a change to the
  41. /// resource on disk. For example, if a PNG file is edited by the artist and saved
  42. /// the ResourceManager will signal that the file has changed so the TextureManager
  43. /// may act appropriately - which probably means to re-init the materials using that PNG.
  44. /// The signal passes the Resource's signature so the callee may filter these.
  45. ChangedSignal &getChangedSignal() { return mChangeSignal; }
  46. #ifdef TORQUE_DEBUG
  47. void dumpToConsole();
  48. #endif
  49. ~ResourceManager();
  50. protected:
  51. friend class ResourceBase::Header;
  52. ResourceManager();
  53. bool remove( ResourceBase::Header* header );
  54. void notifiedFileChanged( const Torque::Path &path );
  55. typedef HashTable<String,ResourceBase::Header*> ResourceHeaderMap;
  56. /// The map of resources.
  57. ResourceHeaderMap mResourceHeaderMap;
  58. /// The map of old resources which have been replaced by
  59. /// new resources from a file change notification.
  60. ResourceHeaderMap mPrevResourceHeaderMap;
  61. ResourceHeaderMap::Iterator mIter;
  62. U32 mIterSigFilter;
  63. ChangedSignal mChangeSignal;
  64. };
  65. #endif