BsBuiltinComponentLookup.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "BsScriptRenderable.h"
  8. namespace bs
  9. {
  10. /** Begins the definition for the builtin component lookup table. */
  11. #define LOOKUP_BEGIN \
  12. class BuiltinComponents \
  13. { \
  14. public: \
  15. template<int TID> \
  16. class TLookup { }; \
  17. \
  18. private: \
  19. struct META_FirstEntry {}; \
  20. static void META_GetPrevEntries(Vector<BuiltinComponentInfo>& entries, META_FirstEntry id) { } \
  21. \
  22. typedef META_FirstEntry
  23. /** Registers a new entry in the component lookup table. */
  24. #define ADD_ENTRY(TID, Type) \
  25. META_Entry_##Type; \
  26. \
  27. public: \
  28. template<> \
  29. class TLookup<TID> \
  30. { \
  31. typedef Type ScriptType; \
  32. }; \
  33. \
  34. static ScriptComponentBase* create##Type(const HComponent& component) \
  35. { \
  36. MonoObject* managedInstance = Type::getMetaData()->scriptClass->createInstance(); \
  37. Type* scriptComponent = new (bs_alloc<Type>()) Type(managedInstance, component); \
  38. \
  39. return scriptComponent; \
  40. } \
  41. \
  42. struct META_NextEntry_##Type {}; \
  43. static void META_GetPrevEntries(Vector<BuiltinComponentInfo>& entries, META_NextEntry_##Type id) \
  44. { \
  45. META_GetPrevEntries(entries, META_Entry_##Type()); \
  46. \
  47. BuiltinComponentInfo entry; \
  48. entry.metaData = Type::getMetaData(); \
  49. entry.typeId = TID; \
  50. entry.monoClass = nullptr; \
  51. entry.createCallback = &create##Type; \
  52. \
  53. entries.push_back(entry); \
  54. } \
  55. \
  56. typedef META_NextEntry_##Type
  57. /** End the definition for the builtin component lookup table. */
  58. #define LOOKUP_END \
  59. META_LastEntry; \
  60. \
  61. public: \
  62. static Vector<BuiltinComponentInfo> getEntries() \
  63. { \
  64. Vector<BuiltinComponentInfo> entries; \
  65. META_GetPrevEntries(entries, META_LastEntry()); \
  66. return entries; \
  67. } \
  68. };
  69. LOOKUP_BEGIN
  70. ADD_ENTRY(TID_CRenderable, ScriptRenderable2)
  71. LOOKUP_END
  72. #undef LOOKUP_BEGIN
  73. #undef ADD_ENTRY
  74. #undef LOOKUP_END
  75. }