resourceManager.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. using namespace Torque;
  31. class ResourceManager
  32. {
  33. public:
  34. static ResourceManager &get();
  35. ResourceBase load(const Torque::Path &path);
  36. ResourceBase find(const Torque::Path &path);
  37. ResourceBase startResourceList( ResourceBase::Signature inSignature = U32_MAX );
  38. ResourceBase nextResource();
  39. void reloadResource( const Torque::Path &path, bool showMessage = false );
  40. typedef Signal<void(const Torque::Path &path)> ChangedSignal;
  41. /// Registering with this signal will give an opportunity to handle a change to the
  42. /// resource on disk. For example, if a PNG file is edited by the artist and saved
  43. /// the ResourceManager will signal that the file has changed so the TextureManager
  44. /// may act appropriately - which probably means to re-init the materials using that PNG.
  45. /// The signal passes the Resource's signature so the callee may filter these.
  46. ChangedSignal &getChangedSignal() { return mChangeSignal; }
  47. #ifdef TORQUE_DEBUG
  48. void dumpToConsole();
  49. #endif
  50. ~ResourceManager();
  51. protected:
  52. friend class ResourceBase::Header;
  53. ResourceManager();
  54. bool remove( ResourceBase::Header* header );
  55. void notifiedFileChanged( const Torque::Path &path );
  56. typedef HashTable<String,ResourceBase::Header*> ResourceHeaderMap;
  57. /// The map of resources.
  58. ResourceHeaderMap mResourceHeaderMap;
  59. /// The map of old resources which have been replaced by
  60. /// new resources from a file change notification.
  61. ResourceHeaderMap mPrevResourceHeaderMap;
  62. ResourceHeaderMap::Iterator mIter;
  63. U32 mIterSigFilter;
  64. ChangedSignal mChangeSignal;
  65. };
  66. #endif