diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/UndoStack.cs | 40 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 16 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs | 2 |
3 files changed, 55 insertions, 3 deletions
diff --git a/OpenSim/Framework/UndoStack.cs b/OpenSim/Framework/UndoStack.cs index fde63b1..8f8849d 100644 --- a/OpenSim/Framework/UndoStack.cs +++ b/OpenSim/Framework/UndoStack.cs | |||
@@ -45,59 +45,96 @@ namespace OpenSim.Framework | |||
45 | m_Undos = new T[capacity + 1]; | 45 | m_Undos = new T[capacity + 1]; |
46 | } | 46 | } |
47 | 47 | ||
48 | /// <summary> | ||
49 | /// Is the stack full? | ||
50 | /// </summary> | ||
48 | public bool IsFull | 51 | public bool IsFull |
49 | { | 52 | { |
50 | get { return m_new == m_old; } | 53 | get |
54 | { | ||
55 | // If the old and new pointers are in the same place then all stack slots are occupied. | ||
56 | return m_new == m_old; | ||
57 | } | ||
51 | } | 58 | } |
52 | 59 | ||
60 | /// <summary> | ||
61 | /// Capacity of the stack. | ||
62 | /// </summary> | ||
53 | public int Capacity | 63 | public int Capacity |
54 | { | 64 | { |
55 | get { return m_Undos.Length - 1; } | 65 | get { return m_Undos.Length - 1; } |
56 | } | 66 | } |
57 | 67 | ||
68 | /// <summary> | ||
69 | /// Return the number of undos on the stack. | ||
70 | /// </summary> | ||
58 | public int Count | 71 | public int Count |
59 | { | 72 | { |
60 | get | 73 | get |
61 | { | 74 | { |
62 | int count = m_new - m_old - 1; | 75 | int count = m_new - m_old - 1; |
76 | |||
63 | if (count < 0) | 77 | if (count < 0) |
64 | count += m_Undos.Length; | 78 | count += m_Undos.Length; |
79 | |||
65 | return count; | 80 | return count; |
66 | } | 81 | } |
67 | } | 82 | } |
68 | 83 | ||
84 | /// <summary> | ||
85 | /// Push a new undo onto the stack. | ||
86 | /// </summary> | ||
87 | /// <param name="item"></param> | ||
69 | public void Push(T item) | 88 | public void Push(T item) |
70 | { | 89 | { |
71 | if (IsFull) | 90 | if (IsFull) |
72 | { | 91 | { |
73 | m_old++; | 92 | m_old++; |
93 | |||
74 | if (m_old >= m_Undos.Length) | 94 | if (m_old >= m_Undos.Length) |
75 | m_old -= m_Undos.Length; | 95 | m_old -= m_Undos.Length; |
76 | } | 96 | } |
97 | |||
77 | if (++m_new >= m_Undos.Length) | 98 | if (++m_new >= m_Undos.Length) |
78 | m_new -= m_Undos.Length; | 99 | m_new -= m_Undos.Length; |
100 | |||
79 | m_Undos[m_new] = item; | 101 | m_Undos[m_new] = item; |
80 | } | 102 | } |
81 | 103 | ||
104 | /// <summary> | ||
105 | /// Pop and item from the top of the undo stack. | ||
106 | /// </summary> | ||
107 | /// <returns></returns> | ||
82 | public T Pop() | 108 | public T Pop() |
83 | { | 109 | { |
84 | if (Count > 0) | 110 | if (Count > 0) |
85 | { | 111 | { |
86 | T deleted = m_Undos[m_new]; | 112 | T deleted = m_Undos[m_new]; |
87 | m_Undos[m_new--] = default(T); | 113 | m_Undos[m_new--] = default(T); |
114 | |||
88 | if (m_new < 0) | 115 | if (m_new < 0) |
89 | m_new += m_Undos.Length; | 116 | m_new += m_Undos.Length; |
117 | |||
90 | return deleted; | 118 | return deleted; |
91 | } | 119 | } |
92 | else | 120 | else |
121 | { | ||
93 | throw new InvalidOperationException("Cannot pop from empty stack"); | 122 | throw new InvalidOperationException("Cannot pop from empty stack"); |
123 | } | ||
94 | } | 124 | } |
95 | 125 | ||
126 | /// <summary> | ||
127 | /// Peek at the undo on the top of the stack. | ||
128 | /// </summary> | ||
129 | /// <returns></returns> | ||
96 | public T Peek() | 130 | public T Peek() |
97 | { | 131 | { |
98 | return m_Undos[m_new]; | 132 | return m_Undos[m_new]; |
99 | } | 133 | } |
100 | 134 | ||
135 | /// <summary> | ||
136 | /// Clear the stack. | ||
137 | /// </summary> | ||
101 | public void Clear() | 138 | public void Clear() |
102 | { | 139 | { |
103 | if (Count > 0) | 140 | if (Count > 0) |
@@ -106,6 +143,7 @@ namespace OpenSim.Framework | |||
106 | { | 143 | { |
107 | m_Undos[i] = default(T); | 144 | m_Undos[i] = default(T); |
108 | } | 145 | } |
146 | |||
109 | m_new = 1; | 147 | m_new = 1; |
110 | m_old = 0; | 148 | m_old = 0; |
111 | } | 149 | } |
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 253326e..a1200ee 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | |||
@@ -287,8 +287,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
287 | private string m_sitAnimation = "SIT"; | 287 | private string m_sitAnimation = "SIT"; |
288 | private string m_text = String.Empty; | 288 | private string m_text = String.Empty; |
289 | private string m_touchName = String.Empty; | 289 | private string m_touchName = String.Empty; |
290 | private readonly UndoStack<UndoState> m_undo = new UndoStack<UndoState>(5); | 290 | private readonly Stack<UndoState> m_undo = new Stack<UndoState>(5); |
291 | private readonly UndoStack<UndoState> m_redo = new UndoStack<UndoState>(5); | 291 | private readonly Stack<UndoState> m_redo = new Stack<UndoState>(5); |
292 | private UUID _creatorID; | 292 | private UUID _creatorID; |
293 | 293 | ||
294 | private bool m_passTouches; | 294 | private bool m_passTouches; |
@@ -3707,6 +3707,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
3707 | // } | 3707 | // } |
3708 | } | 3708 | } |
3709 | 3709 | ||
3710 | /// <summary> | ||
3711 | /// Return number of undos on the stack. Here temporarily pending a refactor. | ||
3712 | /// </summary> | ||
3713 | public int UndoCount | ||
3714 | { | ||
3715 | get | ||
3716 | { | ||
3717 | lock (m_undo) | ||
3718 | return m_undo.Count; | ||
3719 | } | ||
3720 | } | ||
3721 | |||
3710 | public void Undo() | 3722 | public void Undo() |
3711 | { | 3723 | { |
3712 | // m_log.DebugFormat("[SCENE OBJECT PART]: Handling undo request for {0} {1}", Name, LocalId); | 3724 | // m_log.DebugFormat("[SCENE OBJECT PART]: Handling undo request for {0} {1}", Name, LocalId); |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs index 7ec36b8..6dbac3c 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectResizeTests.cs | |||
@@ -62,6 +62,8 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
62 | Assert.That(g1Post.RootPart.Scale.X, Is.EqualTo(2)); | 62 | Assert.That(g1Post.RootPart.Scale.X, Is.EqualTo(2)); |
63 | Assert.That(g1Post.RootPart.Scale.Y, Is.EqualTo(3)); | 63 | Assert.That(g1Post.RootPart.Scale.Y, Is.EqualTo(3)); |
64 | Assert.That(g1Post.RootPart.Scale.Z, Is.EqualTo(4)); | 64 | Assert.That(g1Post.RootPart.Scale.Z, Is.EqualTo(4)); |
65 | |||
66 | Assert.That(g1Post.RootPart.UndoCount, Is.EqualTo(1)); | ||
65 | } | 67 | } |
66 | 68 | ||
67 | /// <summary> | 69 | /// <summary> |