BsBuiltinComponentLookup.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. private: \
  15. struct META_FirstEntry {}; \
  16. static void META_GetPrevEntries(Vector<BuiltinComponentInfo>& entries, META_FirstEntry id) { } \
  17. \
  18. typedef META_FirstEntry
  19. /** Registers a new entry in the component lookup table. */
  20. #define ADD_ENTRY(ComponentType, ScriptType) \
  21. META_Entry_##ScriptType; \
  22. \
  23. public: \
  24. static ScriptComponentBase* create##ScriptType(const HComponent& component) \
  25. { \
  26. MonoObject* managedInstance = ScriptType::getMetaData()->scriptClass->createInstance(); \
  27. ScriptType* scriptComponent = new (bs_alloc<ScriptType>()) ScriptType(managedInstance, 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. }