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