BsBuiltinResourceLookup.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEnginePrerequisites.h"
  5. #include "BsScriptMeta.h"
  6. #include "BsMonoClass.h"
  7. #include "Reflection/BsRTTIType.h"
  8. namespace bs
  9. {
  10. /** Begins the definition for the builtin resource lookup table. */
  11. #define LOOKUP_BEGIN \
  12. class BuiltinResourceTypes \
  13. { \
  14. private: \
  15. struct META_FirstEntry {}; \
  16. static void META_GetPrevEntries(Vector<BuiltinResourceInfo>& entries, META_FirstEntry id) { } \
  17. \
  18. typedef META_FirstEntry
  19. /** Registers a new entry in the resource lookup table. */
  20. #define ADD_ENTRY(ResourceType, ScriptType, ResourceTypeEnum) \
  21. META_Entry_##ScriptType; \
  22. \
  23. public: \
  24. static ScriptResourceBase* create##ScriptType(const HResource& resource, MonoObject* existingInstance) \
  25. { \
  26. MonoObject* managedInstance; \
  27. if(existingInstance != nullptr) \
  28. managedInstance = existingInstance; \
  29. else \
  30. managedInstance = ScriptType::createInstance(); \
  31. \
  32. ResourceHandle<ResourceType> castHandle = static_resource_cast<ResourceType>(resource); \
  33. ScriptType* scriptResource = new (bs_alloc<ScriptType>()) ScriptType(managedInstance, castHandle); \
  34. \
  35. return scriptResource; \
  36. } \
  37. \
  38. struct META_NextEntry_##ScriptType {}; \
  39. static void META_GetPrevEntries(Vector<BuiltinResourceInfo>& entries, META_NextEntry_##ScriptType id) \
  40. { \
  41. META_GetPrevEntries(entries, META_Entry_##ScriptType()); \
  42. \
  43. BuiltinResourceInfo entry; \
  44. entry.metaData = ScriptType::getMetaData(); \
  45. entry.typeId = ResourceType::getRTTIStatic()->getRTTIId(); \
  46. entry.monoClass = nullptr; \
  47. entry.resType = ResourceTypeEnum; \
  48. entry.createCallback = &create##ScriptType; \
  49. \
  50. entries.push_back(entry); \
  51. } \
  52. \
  53. typedef META_NextEntry_##ScriptType
  54. /** End the definition for the builtin resource lookup table. */
  55. #define LOOKUP_END \
  56. META_LastEntry; \
  57. \
  58. public: \
  59. static Vector<BuiltinResourceInfo> getEntries() \
  60. { \
  61. Vector<BuiltinResourceInfo> entries; \
  62. META_GetPrevEntries(entries, META_LastEntry()); \
  63. return entries; \
  64. } \
  65. };
  66. }