Resource.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "Types.h"
  25. #include "StringUtils.h"
  26. #include "StringUtils.h"
  27. namespace crown
  28. {
  29. /// Hashed values for supported resource types
  30. #define TEXTURE_EXTENSION "texture"
  31. #define MESH_EXTENSION "mesh"
  32. #define LUA_EXTENSION "lua"
  33. #define TEXT_EXTENSION "text"
  34. #define MATERIAL_EXTENSION "material"
  35. #define SOUND_EXTENSION "sound"
  36. #define SPRITE_EXTENSION "sprite"
  37. #define CONFIG_EXTENSION "config"
  38. #define PACKAGE_EXTENSION "package"
  39. #define UNIT_EXTENSION "unit"
  40. #define PHYSICS_EXTENSION "physics"
  41. #define GUI_EXTENSION "gui"
  42. #define PHYSICS_CONFIG_EXTENSION "physics_config"
  43. #define FONT_EXTENSION "font"
  44. #define LEVEL_EXTENSION "level"
  45. #define TEXTURE_TYPE 0x0DEED4F7
  46. #define MESH_TYPE 0x742FBC9A
  47. #define LUA_TYPE 0xD96E7C37
  48. #define TEXT_TYPE 0x045CC650
  49. #define MATERIAL_TYPE 0x46807A92
  50. #define SOUND_TYPE 0xD196AB6E
  51. #define SPRITE_TYPE 0x5DD272E5
  52. #define CONFIG_TYPE 0x17DEA5E1
  53. #define PACKAGE_TYPE 0xC0A2212C
  54. #define UNIT_TYPE 0x516224CF
  55. #define PHYSICS_TYPE 0xFA32C012
  56. #define GUI_TYPE 0x2C56149A
  57. #define PHYSICS_CONFIG_TYPE 0x514F14A1
  58. #define FONT_TYPE 0x536DC7D4
  59. #define LEVEL_TYPE 0x349657F7
  60. struct ResourceId
  61. {
  62. ResourceId() : id(0) {}
  63. ResourceId(const char* type, const char* name);
  64. ResourceId(const char* name);
  65. bool operator==(const ResourceId& a) const { return id == a.id; }
  66. uint64_t id;
  67. };
  68. class Allocator;
  69. class Bundle;
  70. typedef void* (*ResourceLoadCallback)(Allocator& a, Bundle& b, ResourceId id);
  71. typedef void (*ResourceUnloadCallback)(Allocator& a, void* resource);
  72. typedef void (*ResourceOnlineCallback)(void* resource);
  73. typedef void (*ResourceOfflineCallback)(void* resource);
  74. struct ResourceCallback
  75. {
  76. uint32_t type;
  77. ResourceLoadCallback on_load;
  78. ResourceUnloadCallback on_unload;
  79. ResourceOnlineCallback on_online;
  80. ResourceOfflineCallback on_offline;
  81. };
  82. } // namespace crown