UndoMgr.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/UndoMgr.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 4/19/01 11:34a $*
  29. * *
  30. * $Revision:: 4 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __UNDO_MGR_H
  39. #define __UNDO_MGR_H
  40. #include "matrix3d.h"
  41. #include "vector.h"
  42. #include "listtypes.h"
  43. // Forward declarations
  44. class NodeClass;
  45. ////////////////////////////////////////////////////////////////////////////////////
  46. //
  47. // Data types
  48. //
  49. ////////////////////////////////////////////////////////////////////////////////////
  50. typedef enum
  51. {
  52. OPERATION_MOVE,
  53. OPERATION_ROTATE,
  54. OPERATION_DELETE,
  55. OPERATION_RESIZE,
  56. OPERATION_COUNT
  57. } OPERATION_TYPE;
  58. ////////////////////////////////////////////////////////////////////////////////////
  59. //
  60. // Constants
  61. //
  62. ////////////////////////////////////////////////////////////////////////////////////
  63. const int UNDO_LEVELS = 5;
  64. ////////////////////////////////////////////////////////////////////////////////////
  65. //
  66. // UndoBufferClass
  67. //
  68. ////////////////////////////////////////////////////////////////////////////////////
  69. class UndoBufferClass
  70. {
  71. public:
  72. //////////////////////////////////////////////////////////
  73. // Public constructors/destructors
  74. //////////////////////////////////////////////////////////
  75. UndoBufferClass (void)
  76. : m_dwOperationID (0) {}
  77. virtual ~UndoBufferClass (void) {}
  78. //////////////////////////////////////////////////////////
  79. // Public methods
  80. //////////////////////////////////////////////////////////
  81. //
  82. // Inline Accessors
  83. //
  84. OPERATION_TYPE Get_Operation_Type (void) const { return m_Type; }
  85. void Set_Operation_Type (OPERATION_TYPE type) { m_Type = type; }
  86. DWORD Get_ID (void) const { return m_dwOperationID; }
  87. void Set_ID (DWORD id) { m_dwOperationID = id; }
  88. //
  89. // Operation methods
  90. //
  91. void Capture_Position (const NODE_LIST &node_list);
  92. void Capture_Dimensions (const NODE_LIST &node_list);
  93. void Capture_Existence (const NODE_LIST &node_list);
  94. void Restore_State (void);
  95. //
  96. // Information methods
  97. //
  98. LPCTSTR Get_Operation_Name (void);
  99. protected:
  100. //////////////////////////////////////////////////////////
  101. // Protected methods
  102. ////////////////////////////////////////////////////////////
  103. //void Restore_Node_State (NodeClass &node);
  104. private:
  105. //////////////////////////////////////////////////////////
  106. // Private data types
  107. //////////////////////////////////////////////////////////
  108. class NodeStateClass
  109. {
  110. public:
  111. NodeStateClass (void)
  112. : node_ptr (0),
  113. transform (1),
  114. dimensions (0, 0, 0) {}
  115. virtual ~NodeStateClass (void);
  116. bool operator== (const NodeStateClass &src) { return (node_ptr == src.node_ptr); }
  117. bool operator!= (const NodeStateClass &src) { return !((*this) == src); }
  118. const NodeStateClass &operator= (const NodeStateClass &src);
  119. //DWORD node_id;
  120. Matrix3D transform;
  121. Vector3 dimensions;
  122. //NodeClass * deleted_node;
  123. NodeClass * node_ptr;
  124. };
  125. //////////////////////////////////////////////////////////
  126. // Private member data
  127. //////////////////////////////////////////////////////////
  128. DWORD m_dwOperationID;
  129. OPERATION_TYPE m_Type;
  130. DynamicVectorClass<NodeStateClass> m_StateList;
  131. };
  132. ////////////////////////////////////////////////////////////////////////////////////
  133. //
  134. // UndoMgrClass
  135. //
  136. ////////////////////////////////////////////////////////////////////////////////////
  137. class UndoMgrClass
  138. {
  139. public:
  140. //////////////////////////////////////////////////////////
  141. // Public constructors/destructors
  142. //////////////////////////////////////////////////////////
  143. UndoMgrClass (void)
  144. : m_dwNextOperationID (0),
  145. m_iCurrentBuffer (0) {}
  146. virtual ~UndoMgrClass (void) { Free_Buffer_List (); }
  147. //////////////////////////////////////////////////////////
  148. // Public methods
  149. //////////////////////////////////////////////////////////
  150. //
  151. // Operation management
  152. //
  153. void Begin_Operation (OPERATION_TYPE type, const NODE_LIST &nodes_affected);
  154. void End_Operation (void) { }
  155. void Perform_Undo (int ilevels = 1);
  156. void Purge_Buffers (void) { Free_Buffer_List (); }
  157. //
  158. // Information methods
  159. //
  160. int Get_Possible_Undo_Count (void) const { return m_iCurrentBuffer; }
  161. LPCTSTR Get_Next_Undo_Name (void) const;
  162. protected:
  163. //////////////////////////////////////////////////////////
  164. // Protected methods
  165. //////////////////////////////////////////////////////////
  166. void Push_Buffer (UndoBufferClass *pbuffer);
  167. void Free_Buffer_List (void);
  168. private:
  169. //////////////////////////////////////////////////////////
  170. // Private member data
  171. //////////////////////////////////////////////////////////
  172. DWORD m_dwNextOperationID;
  173. int m_iCurrentBuffer;
  174. UndoBufferClass * m_pBuffers[UNDO_LEVELS];
  175. };
  176. #endif //__UNDO_MGR_H