BsBuiltinComponentLookup.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. namespace bs
  8. {
  9. /** Begins the definition for the builtin component lookup table. */
  10. #define LOOKUP_BEGIN \
  11. class BuiltinComponents \
  12. { \
  13. private: \
  14. struct META_FirstEntry {}; \
  15. static void META_GetPrevEntries(Vector<BuiltinComponentInfo>& entries, META_FirstEntry id) { } \
  16. \
  17. typedef META_FirstEntry
  18. /** Registers a new entry in the component lookup table. */
  19. #define ADD_ENTRY(ComponentType, ScriptType) \
  20. META_Entry_##ScriptType; \
  21. \
  22. public: \
  23. static ScriptComponentBase* create##ScriptType(const HComponent& component) \
  24. { \
  25. MonoObject* managedInstance = ScriptType::getMetaData()->scriptClass->createInstance(); \
  26. ScriptType* scriptComponent = new (bs_alloc<ScriptType>()) \
  27. ScriptType(managedInstance, static_object_cast<ComponentType>(component)); \
  28. \
  29. return scriptComponent; \
  30. } \
  31. \
  32. struct META_NextEntry_##ScriptType {}; \
  33. static void META_GetPrevEntries(Vector<BuiltinComponentInfo>& entries, META_NextEntry_##ScriptType id) \
  34. { \
  35. META_GetPrevEntries(entries, META_Entry_##ScriptType()); \
  36. \
  37. BuiltinComponentInfo entry; \
  38. entry.metaData = ScriptType::getMetaData(); \
  39. entry.typeId = ComponentType::getRTTIStatic()->getRTTIId(); \
  40. entry.monoClass = nullptr; \
  41. entry.createCallback = &create##ScriptType; \
  42. \
  43. entries.push_back(entry); \
  44. } \
  45. \
  46. typedef META_NextEntry_##ScriptType
  47. /** End the definition for the builtin component lookup table. */
  48. #define LOOKUP_END \
  49. META_LastEntry; \
  50. \
  51. public: \
  52. static Vector<BuiltinComponentInfo> getEntries() \
  53. { \
  54. Vector<BuiltinComponentInfo> entries; \
  55. META_GetPrevEntries(entries, META_LastEntry()); \
  56. return entries; \
  57. } \
  58. };
  59. }