BsBuiltinComponentLookup.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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>()) ScriptType(managedInstance, component); \
  27. \
  28. return scriptComponent; \
  29. } \
  30. \
  31. struct META_NextEntry_##ScriptType {}; \
  32. static void META_GetPrevEntries(Vector<BuiltinComponentInfo>& entries, META_NextEntry_##ScriptType id) \
  33. { \
  34. META_GetPrevEntries(entries, META_Entry_##ScriptType()); \
  35. \
  36. BuiltinComponentInfo entry; \
  37. entry.metaData = ScriptType::getMetaData(); \
  38. entry.typeId = ComponentType::getRTTIStatic()->getRTTIId(); \
  39. entry.monoClass = nullptr; \
  40. entry.createCallback = &create##ScriptType; \
  41. \
  42. entries.push_back(entry); \
  43. } \
  44. \
  45. typedef META_NextEntry_##ScriptType
  46. /** End the definition for the builtin component lookup table. */
  47. #define LOOKUP_END \
  48. META_LastEntry; \
  49. \
  50. public: \
  51. static Vector<BuiltinComponentInfo> getEntries() \
  52. { \
  53. Vector<BuiltinComponentInfo> entries; \
  54. META_GetPrevEntries(entries, META_LastEntry()); \
  55. return entries; \
  56. } \
  57. };
  58. }