BsManagedEditorCommand.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEditorPrerequisites.h"
  5. #include "BsScriptObject.h"
  6. #include "UndoRedo/BsEditorCommand.h"
  7. namespace bs
  8. {
  9. class CmdManaged;
  10. /** @addtogroup ScriptInteropEditor
  11. * @{
  12. */
  13. /** Interop class between C++ & CLR for CmdManaged. */
  14. class BS_SCR_BED_EXPORT ScriptCmdManaged : public ScriptObject <ScriptCmdManaged, PersistentScriptObjectBase>
  15. {
  16. public:
  17. SCRIPT_OBJ(EDITOR_ASSEMBLY, EDITOR_NS, "UndoableCommand")
  18. ~ScriptCmdManaged();
  19. /** Returns the internal command wrapped by this object. */
  20. SPtr<CmdManaged> getInternal() const { return mManagedCommand; }
  21. private:
  22. friend class CmdManaged;
  23. ScriptCmdManaged(MonoObject* instance);
  24. /** Triggers the Commit() method on the managed object instance. */
  25. void triggerCommit();
  26. /** Triggers the Revert() method on the managed object instance. */
  27. void triggerRevert();
  28. /**
  29. * Allocates a GC handle that ensures the object doesn't get GC collected. Must eventually be followed by
  30. * freeGCHandle().
  31. */
  32. void notifyStackAdded();
  33. /** Frees a GC handle previously allocated from allocGCHandle(). */
  34. void notifyStackRemoved();
  35. /** Notifies the script instance that the underlying managed command was destroyed. */
  36. void notifyCommandDestroyed();
  37. /** @copydoc ScriptObjectBase::beginRefresh */
  38. ScriptObjectBackup beginRefresh() override;
  39. /** @copydoc ScriptObjectBase::endRefresh */
  40. void endRefresh(const ScriptObjectBackup& backupData) override;
  41. /** @copydoc ScriptObjectBase::_createManagedInstance */
  42. MonoObject* _createManagedInstance(bool construct) override;
  43. /** @copydoc ScriptObjectBase::_clearManagedInstance */
  44. void _clearManagedInstance() override;
  45. /** @copydoc ScriptObjectBase::_onManagedInstanceDeleted */
  46. void _onManagedInstanceDeleted(bool assemblyRefresh) override;
  47. SPtr<CmdManaged> mManagedCommand;
  48. UINT32 mGCHandle = 0;
  49. bool mInUndoRedoStack = false;
  50. String mType;
  51. String mNamespace;
  52. bool mTypeMissing = false;
  53. SPtr<ManagedSerializableObject> mSerializedObjectData;
  54. /************************************************************************/
  55. /* CLR HOOKS */
  56. /************************************************************************/
  57. static void internal_CreateInstance(MonoObject* instance);
  58. static MonoMethod* sCommitMethod;
  59. static MonoMethod* sRevertMethod;
  60. };
  61. /** @} */
  62. /** @addtogroup EditorScript
  63. * @{
  64. */
  65. /**
  66. * A command used for undo/redo purposes. This particular implementation provides a generic overridable base to be
  67. * implemented by script classes.
  68. */
  69. class BS_SCR_BED_EXPORT CmdManaged : public EditorCommand
  70. {
  71. public:
  72. ~CmdManaged();
  73. /** @copydoc EditorCommand::commit */
  74. void commit() override;
  75. /** @copydoc EditorCommand::revert */
  76. void revert() override;
  77. private:
  78. friend class UndoRedo;
  79. friend class ScriptCmdManaged;
  80. CmdManaged(ScriptCmdManaged* scriptObj);
  81. /** @copydoc EditorCommand::commit */
  82. void onCommandAdded() override;
  83. /** @copydoc EditorCommand::commit */
  84. void onCommandRemoved() override;
  85. /**
  86. * Notifies the command the managed script object instance it is referencing has been destroyed. Normally when this
  87. * happens the command should already be outside of the undo/redo stack, but we clear the instance just in case.
  88. */
  89. void notifyScriptInstanceDestroyed();
  90. ScriptCmdManaged* mScriptObj;
  91. UINT32 mRefCount;
  92. };
  93. /** @} */
  94. }