BsManagedEditorCommand.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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>
  15. {
  16. public:
  17. SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "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 allocGCHandle();
  33. /** Frees a GC handle previously allocated from allocGCHandle(). */
  34. void freeGCHandle();
  35. /** Notifies the script instance that the underlying managed command was destroyed. */
  36. void notifyCommandDestroyed();
  37. SPtr<CmdManaged> mManagedCommand;
  38. UINT32 mGCHandle = 0;
  39. /************************************************************************/
  40. /* CLR HOOKS */
  41. /************************************************************************/
  42. static void internal_CreateInstance(MonoObject* instance);
  43. static MonoMethod* sCommitMethod;
  44. static MonoMethod* sRevertMethod;
  45. };
  46. /** @} */
  47. /** @addtogroup SBansheeEditor
  48. * @{
  49. */
  50. /**
  51. * A command used for undo/redo purposes. This particular implementation provides a generic overridable base to be
  52. * implemented by script classes.
  53. */
  54. class BS_SCR_BED_EXPORT CmdManaged : public EditorCommand
  55. {
  56. public:
  57. ~CmdManaged();
  58. /** @copydoc EditorCommand::commit */
  59. void commit() override;
  60. /** @copydoc EditorCommand::revert */
  61. void revert() override;
  62. private:
  63. friend class UndoRedo;
  64. friend class ScriptCmdManaged;
  65. CmdManaged(ScriptCmdManaged* scriptObj);
  66. /** @copydoc EditorCommand::commit */
  67. void onCommandAdded() override;
  68. /** @copydoc EditorCommand::commit */
  69. void onCommandRemoved() override;
  70. /**
  71. * Notifies the command the managed script object instance it is referencing has been destroyed. Normally when this
  72. * happens the command should already be outside of the undo/redo stack, but we clear the instance just in case.
  73. */
  74. void notifyScriptInstanceDestroyed();
  75. ScriptCmdManaged* mScriptObj;
  76. uint32_t mGCHandle;
  77. UINT32 mRefCount;
  78. };
  79. /** @} */
  80. }