BsCmdRecordSO.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsEditorCommand.h"
  4. #include "BsUndoRedo.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief A command used for undo/redo purposes. It records a state of the entire
  9. * scene object at a specific point and allows you to restore it to its
  10. * original values as needed.
  11. */
  12. class CmdRecordSO : public EditorCommand
  13. {
  14. /**
  15. * @brief Contains stored information about stored scene object instance data,
  16. * including all of its children and components.
  17. *
  18. * @note When object is serialized it will receive new instance data (as if it was a new
  19. * object). But we want to restore the original object completely (including any references
  20. * other objects might have to it) so we need store the instance data.
  21. */
  22. struct SceneObjProxy
  23. {
  24. GameObjectInstanceDataPtr instanceData;
  25. Vector<GameObjectInstanceDataPtr> componentInstanceData;
  26. Vector<SceneObjProxy> children;
  27. };
  28. public:
  29. ~CmdRecordSO();
  30. /**
  31. * @brief Creates and executes the command on the provided scene object.
  32. * Automatically registers the command with undo/redo system.
  33. *
  34. * @param inputField Input field to modify the value on.
  35. * @param value New value for the field.
  36. */
  37. static void execute(const HSceneObject& sceneObject);
  38. /**
  39. * @copydoc EditorCommand::commit
  40. */
  41. void commit() override;
  42. /**
  43. * @copydoc EditorCommand::revert
  44. */
  45. void revert() override;
  46. private:
  47. friend class UndoRedo;
  48. CmdRecordSO(const HSceneObject& sceneObject);
  49. /**
  50. * @brief Saves the state of the specified object, all of its children
  51. * and components. Make sure to call "clear" when you no longer need
  52. * the data, or wish to call this method again.
  53. */
  54. void recordSO(const HSceneObject& sceneObject);
  55. /**
  56. * @brief Clears all the stored data and frees memory.
  57. */
  58. void clear();
  59. /**
  60. * @brief Parses the scene object hierarchy and components and generates a
  61. * hierarchy of instance data required to restore the object identities.
  62. *
  63. * @see SceneObjProxy
  64. */
  65. SceneObjProxy createProxy(const HSceneObject& sceneObject);
  66. /**
  67. * @brief Restores original object instance data after deserialization.
  68. *
  69. * @see SceneObjProxy
  70. */
  71. void restoreIds(const HSceneObject& restored);
  72. HSceneObject mSceneObject;
  73. SceneObjProxy mSceneObjectProxy;
  74. UINT8* mSerializedObject;
  75. UINT32 mSerializedObjectSize;
  76. UINT64 mSerializedObjectParentId;
  77. };
  78. }