Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

Resource.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #ifndef BZR_RESOURCE_H
  19. #define BZR_RESOURCE_H
  20. #include "Noncopyable.h"
  21. /*
  22. * 00 GID_TYPE_WEENIE_DEFS (0)
  23. * 01 GID_TYPE_GFXOBJ (15105)
  24. * 02 GID_TYPE_SETUP (5852)
  25. * 03 GID_TYPE_ANIM (2055)
  26. * 04 GID_TYPE_PALETTE (4515)
  27. * 05 GID_TYPE_IMGTEX (7152)
  28. * 06 GID_TYPE_IMGCOLOR (20547)
  29. * 08 GID_TYPE_SURFACE (6080)
  30. * 09 GID_TYPE_MTABLE (427)
  31. * 0a GID_TYPE_WAVE (783)
  32. * 0b GID_TYPE_LAND_BLOCK (0)
  33. * 0c GID_TYPE_LBI (0)
  34. * 0d GID_TYPE_ENVIRONMENT (769)
  35. * 0e GID_TYPE_UNIQUE (14)
  36. * 0f GID_TYPE_PAL_SET (2676)
  37. * 10 GID_TYPE_CLOTHING (1909)
  38. * 11 GID_TYPE_DEGRADEINFO (4126)
  39. * 12 GID_TYPE_SCENE (179)
  40. * 13 GID_TYPE_REGION (1)
  41. * 14 ?? (2)
  42. * 15 ?? (2)
  43. * 16 ?? (1)
  44. * 17 ?? (1)
  45. * 18 ?? (1)
  46. * 20 GID_TYPE_STABLE (189)
  47. * 22 GID_TYPE_ENUM_MAPPER (40)
  48. * 25 GID_TYPE_DID_MAPPER (22)
  49. * 26 ?? (1)
  50. * 27 ?? (5)
  51. * 30 GID_TYPE_COMBAT_TABLE (71)
  52. * 31 GID_TYPE_STRING (28)
  53. * 32 GID_TYPE_PARTICLE_EMITTER (2006)
  54. * 33 GID_TYPE_PHYSICS_SCRIPT (4189)
  55. * 34 GID_TYPE_PHYSICS_SCRIPT_TABLE (160)
  56. * 38 GID_TYPE_MUTATE_FILTER (0)
  57. * 39 ?? (1)
  58. * 40 ?? (49)
  59. * 78 ?? (2)
  60. * ff ?? (1)
  61. */
  62. enum class ResourceType : uint32_t
  63. {
  64. kModel = 0x01000000,
  65. kSetup = 0x02000000,
  66. kAnimation = 0x03000000,
  67. kPalette = 0x04000000,
  68. kImgTex = 0x05000000,
  69. kImgColor = 0x06000000,
  70. kSurface = 0x08000000,
  71. kMotionTable = 0x09000000,
  72. kSound = 0x0A000000,
  73. kEnvironment = 0x0D000000,
  74. kScene = 0x12000000,
  75. kRegion = 0x13000000,
  76. kSoundTable = 0x20000000,
  77. kEnumMapper = 0x22000000,
  78. kParticleEmitter = 0x32000000,
  79. kPhysicsScript = 0x33000000,
  80. kPhysicsScriptTable = 0x34000000
  81. };
  82. class Resource : Noncopyable
  83. {
  84. public:
  85. Resource(uint32_t id) : resourceId_(id)
  86. {}
  87. virtual ~Resource()
  88. {}
  89. template<class T>
  90. T& cast()
  91. {
  92. assert(resourceType() == T::RESOURCE_TYPE);
  93. return (T&)*this;
  94. }
  95. template<class T>
  96. const T& cast() const
  97. {
  98. assert(resourceType() == T::RESOURCE_TYPE);
  99. return (const T&)*this;
  100. }
  101. uint32_t resourceId() const
  102. {
  103. return resourceId_;
  104. }
  105. ResourceType resourceType() const
  106. {
  107. return static_cast<ResourceType>(resourceId_ & 0xFF000000);
  108. }
  109. private:
  110. const uint32_t resourceId_;
  111. };
  112. template<ResourceType RT>
  113. class ResourceImpl : public Resource
  114. {
  115. public:
  116. ResourceImpl(uint32_t id) : Resource(id)
  117. {
  118. assert((id & 0xFF000000) == static_cast<uint32_t>(RT));
  119. }
  120. static const ResourceType RESOURCE_TYPE = RT;
  121. };
  122. typedef shared_ptr<const Resource> ResourcePtr;
  123. #endif