BsRuntimeScriptObjects.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "BsRuntimeScriptObjects.h"
  2. using namespace CamelotFramework;
  3. namespace BansheeEngine
  4. {
  5. SerializableObjectInfo::SerializableObjectInfo()
  6. :mMonoClass(nullptr)
  7. {
  8. }
  9. SerializableObjectInfo::~SerializableObjectInfo()
  10. {
  11. for(auto& field : mFields)
  12. {
  13. cm_delete(field.second);
  14. }
  15. }
  16. SerializableFieldInfo::SerializableFieldInfo()
  17. :mMonoField(nullptr), mType(ScriptFieldType::Primitive), mFlags((ScriptFieldFlags)0)
  18. {
  19. }
  20. SerializableFieldInfo::~SerializableFieldInfo()
  21. {
  22. }
  23. RuntimeScriptObjects::~RuntimeScriptObjects()
  24. {
  25. clearScriptObjects();
  26. }
  27. void RuntimeScriptObjects::refreshScriptObjects()
  28. {
  29. clearScriptObjects();
  30. // Scan all loaded assemblies
  31. // - find classes deriving from Component (make sure even non-direct descendants from Component are considered)
  32. // - find classes implementing [Serializable] attribute
  33. // - If multiple copies of the same class are found ignore them
  34. // Create dummy SerializableObjectInfo entries in the map so I can quickly look up serializable objects
  35. // SerializableObjectInfo should know if object is Component or [Serializable]
  36. // Go through all of their fields
  37. // Depending on attributes and visibility, mark them as inspectable and/or serializable
  38. // Ensure to only get fields of that EXACT class, not its base
  39. // Detect field type:
  40. // - Primitive - straightforward just check for primitive types
  41. // - GameObjectHandle - check if object is SceneObject or derives from Component
  42. // - SerializableObject - check if object is SerializableObject
  43. // - ResourceHandle - derives from Resource
  44. // TODO - How will I serialize SerializableObjects?
  45. // - We don't do any instance tracking for SerializableObjects. Each one will be deserialized and serialized
  46. // as its own separate instance.
  47. // TODO - Each class will need an unique ID
  48. // - So will each field within a class
  49. // - Will likely need two maps
  50. // - ns.type -> id
  51. // - id -> SerializableObjectInfo*
  52. // TODO - For each class search its base class (if it has one) and see if it is Component
  53. // or child of COmponent. If it is, set up the parent/child fields in SerializableObjectInfo.
  54. // TODO - SerializableObjectInfo needs to be IReflectable and its referenced children
  55. // should be shared pointers
  56. }
  57. void RuntimeScriptObjects::clearScriptObjects()
  58. {
  59. for(auto& scriptObject : mObjectInfos)
  60. {
  61. cm_delete(scriptObject.second);
  62. }
  63. }
  64. }