resource.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 "string_utils.h"
  26. #include "string_utils.h"
  27. namespace crown
  28. {
  29. /// Hashed values for supported resource types
  30. #define CONFIG_EXTENSION "config"
  31. #define FONT_EXTENSION "font"
  32. #define LEVEL_EXTENSION "level"
  33. #define LUA_EXTENSION "lua"
  34. #define MATERIAL_EXTENSION "material"
  35. #define MESH_EXTENSION "mesh"
  36. #define PACKAGE_EXTENSION "package"
  37. #define PHYSICS_CONFIG_EXTENSION "physics_config"
  38. #define PHYSICS_EXTENSION "physics"
  39. #define SHADER_EXTENSION "shader"
  40. #define SOUND_EXTENSION "sound"
  41. #define SPRITE_ANIMATION_EXTENSION "sprite_animation"
  42. #define SPRITE_EXTENSION "sprite"
  43. #define TEXTURE_EXTENSION "texture"
  44. #define UNIT_EXTENSION "unit"
  45. #define CONFIG_TYPE uint64_t(0x82645835e6b73232)
  46. #define FONT_TYPE uint64_t(0x9efe0a916aae7880)
  47. #define LEVEL_TYPE uint64_t(0x2a690fd348fe9ac5)
  48. #define LUA_TYPE uint64_t(0xa14e8dfa2cd117e2)
  49. #define MATERIAL_TYPE uint64_t(0xeac0b497876adedf)
  50. #define MESH_TYPE uint64_t(0x48ff313713a997a1)
  51. #define PACKAGE_TYPE uint64_t(0xad9c6d9ed1e5e77a)
  52. #define PHYSICS_CONFIG_TYPE uint64_t(0x72e3cc03787a11a1)
  53. #define PHYSICS_TYPE uint64_t(0x5f7203c8f280dab8)
  54. #define SHADER_TYPE uint64_t(0xcce8d5b5f5ae333f)
  55. #define SOUND_TYPE uint64_t(0x90641b51c98b7aac)
  56. #define SPRITE_ANIMATION_TYPE uint64_t(0x487e78e3f87f238d)
  57. #define SPRITE_TYPE uint64_t(0x8d5871f9ebdb651c)
  58. #define TEXTURE_TYPE uint64_t(0xcd4238c6a0c69e32)
  59. #define UNIT_TYPE uint64_t(0xe0a48d0be9a7453f)
  60. struct ResourceId
  61. {
  62. ResourceId() : type(0), name(0) {}
  63. ResourceId(const char* type, const char* name);
  64. bool operator==(const ResourceId& a) const { return type == a.type && name == a.name; }
  65. uint64_t type;
  66. uint64_t name;
  67. };
  68. class Allocator;
  69. class Bundle;
  70. class ResourceManager;
  71. typedef void* (*ResourceLoadCallback)(Allocator& a, Bundle& b, ResourceId id);
  72. typedef void (*ResourceOnlineCallback)(StringId64 id, ResourceManager& rm);
  73. typedef void (*ResourceOfflineCallback)(StringId64 id, ResourceManager& rm);
  74. typedef void (*ResourceUnloadCallback)(Allocator& a, void* resource);
  75. struct ResourceCallback
  76. {
  77. uint64_t type;
  78. ResourceLoadCallback on_load;
  79. ResourceUnloadCallback on_unload;
  80. ResourceOnlineCallback on_online;
  81. ResourceOfflineCallback on_offline;
  82. };
  83. } // namespace crown