diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/UndoState.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/UndoState.cs | 176 |
1 files changed, 173 insertions, 3 deletions
diff --git a/OpenSim/Region/Framework/Scenes/UndoState.cs b/OpenSim/Region/Framework/Scenes/UndoState.cs index eb76ca5..668b53b 100644 --- a/OpenSim/Region/Framework/Scenes/UndoState.cs +++ b/OpenSim/Region/Framework/Scenes/UndoState.cs | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Reflection; | 29 | using System.Reflection; |
30 | using System.Collections.Generic; | ||
30 | using log4net; | 31 | using log4net; |
31 | using OpenMetaverse; | 32 | using OpenMetaverse; |
32 | using OpenSim.Region.Framework.Interfaces; | 33 | using OpenSim.Region.Framework.Interfaces; |
@@ -34,6 +35,8 @@ using System; | |||
34 | 35 | ||
35 | namespace OpenSim.Region.Framework.Scenes | 36 | namespace OpenSim.Region.Framework.Scenes |
36 | { | 37 | { |
38 | |||
39 | /* | ||
37 | [Flags] | 40 | [Flags] |
38 | public enum UndoType | 41 | public enum UndoType |
39 | { | 42 | { |
@@ -48,7 +51,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
48 | STATE_ALL = 63 | 51 | STATE_ALL = 63 |
49 | } | 52 | } |
50 | 53 | ||
51 | /* | 54 | |
52 | public class UndoState | 55 | public class UndoState |
53 | { | 56 | { |
54 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 57 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
@@ -194,7 +197,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
194 | */ | 197 | */ |
195 | public class UndoState | 198 | public class UndoState |
196 | { | 199 | { |
200 | const int UNDOEXPIRESECONDS = 300; // undo expire time (nice to have it came from a ini later) | ||
201 | |||
197 | public ObjectChangeData data; | 202 | public ObjectChangeData data; |
203 | public DateTime creationtime; | ||
198 | /// <summary> | 204 | /// <summary> |
199 | /// Constructor. | 205 | /// Constructor. |
200 | /// </summary> | 206 | /// </summary> |
@@ -204,8 +210,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
204 | public UndoState(SceneObjectPart part, ObjectChangeWhat what) | 210 | public UndoState(SceneObjectPart part, ObjectChangeWhat what) |
205 | { | 211 | { |
206 | data = new ObjectChangeData(); | 212 | data = new ObjectChangeData(); |
207 | |||
208 | data.what = what; | 213 | data.what = what; |
214 | creationtime = DateTime.UtcNow; | ||
209 | 215 | ||
210 | if (part.ParentGroup.RootPart == part) | 216 | if (part.ParentGroup.RootPart == part) |
211 | { | 217 | { |
@@ -227,12 +233,25 @@ namespace OpenSim.Region.Framework.Scenes | |||
227 | } | 233 | } |
228 | } | 234 | } |
229 | 235 | ||
236 | public bool checkExpire() | ||
237 | { | ||
238 | TimeSpan t = DateTime.UtcNow - creationtime; | ||
239 | if (t.Seconds > UNDOEXPIRESECONDS) | ||
240 | return true; | ||
241 | return false; | ||
242 | } | ||
243 | |||
244 | public void updateExpire() | ||
245 | { | ||
246 | creationtime = DateTime.UtcNow; | ||
247 | } | ||
248 | |||
230 | /// <summary> | 249 | /// <summary> |
231 | /// Compare the relevant state in the given part to this state. | 250 | /// Compare the relevant state in the given part to this state. |
232 | /// </summary> | 251 | /// </summary> |
233 | /// <param name="part"></param> | 252 | /// <param name="part"></param> |
234 | /// <returns>true if both the part's position, rotation and scale match those in this undo state. False otherwise.</returns> | 253 | /// <returns>true if both the part's position, rotation and scale match those in this undo state. False otherwise.</returns> |
235 | public bool Compare(SceneObjectPart part, ObjectChangeWhat what) | 254 | public bool Compare(SceneObjectPart part, ObjectChangeWhat what) |
236 | { | 255 | { |
237 | if (data.what != what) // if diferent targets, then they are diferent | 256 | if (data.what != what) // if diferent targets, then they are diferent |
238 | return false; | 257 | return false; |
@@ -274,6 +293,157 @@ namespace OpenSim.Region.Framework.Scenes | |||
274 | } | 293 | } |
275 | } | 294 | } |
276 | 295 | ||
296 | public class UndoRedoState | ||
297 | { | ||
298 | int size; | ||
299 | public LinkedList<UndoState> m_redo = new LinkedList<UndoState>(); | ||
300 | public LinkedList<UndoState> m_undo = new LinkedList<UndoState>(); | ||
301 | |||
302 | public UndoRedoState() | ||
303 | { | ||
304 | size = 5; | ||
305 | } | ||
306 | |||
307 | public UndoRedoState(int _size) | ||
308 | { | ||
309 | if (_size < 3) | ||
310 | size = 3; | ||
311 | else | ||
312 | size = _size; | ||
313 | } | ||
314 | |||
315 | public int Count | ||
316 | { | ||
317 | get { return m_undo.Count; } | ||
318 | } | ||
319 | |||
320 | public void Clear() | ||
321 | { | ||
322 | m_undo.Clear(); | ||
323 | m_redo.Clear(); | ||
324 | } | ||
325 | |||
326 | public void StoreUndo(SceneObjectPart part, ObjectChangeWhat what) | ||
327 | { | ||
328 | lock (m_undo) | ||
329 | { | ||
330 | UndoState last; | ||
331 | |||
332 | if (m_redo.Count > 0) // last code seems to clear redo on every new undo | ||
333 | { | ||
334 | m_redo.Clear(); | ||
335 | } | ||
336 | |||
337 | if (m_undo.Count > 0) | ||
338 | { | ||
339 | // check expired entry | ||
340 | last = m_undo.First.Value; | ||
341 | if (last != null && last.checkExpire()) | ||
342 | m_undo.Clear(); | ||
343 | else | ||
344 | { | ||
345 | // see if we actually have a change | ||
346 | if (last != null) | ||
347 | { | ||
348 | if (last.Compare(part, what)) | ||
349 | return; | ||
350 | } | ||
351 | } | ||
352 | } | ||
353 | |||
354 | // limite size | ||
355 | while (m_undo.Count >= size) | ||
356 | m_undo.RemoveLast(); | ||
357 | |||
358 | UndoState nUndo = new UndoState(part, what); | ||
359 | m_undo.AddFirst(nUndo); | ||
360 | } | ||
361 | } | ||
362 | |||
363 | public void Undo(SceneObjectPart part) | ||
364 | { | ||
365 | lock (m_undo) | ||
366 | { | ||
367 | UndoState nUndo; | ||
368 | |||
369 | // expire redo | ||
370 | if (m_redo.Count > 0) | ||
371 | { | ||
372 | nUndo = m_redo.First.Value; | ||
373 | if (nUndo != null && nUndo.checkExpire()) | ||
374 | m_redo.Clear(); | ||
375 | } | ||
376 | |||
377 | if (m_undo.Count > 0) | ||
378 | { | ||
379 | UndoState goback = m_undo.First.Value; | ||
380 | // check expired | ||
381 | if (goback != null && goback.checkExpire()) | ||
382 | { | ||
383 | m_undo.Clear(); | ||
384 | return; | ||
385 | } | ||
386 | |||
387 | if (goback != null) | ||
388 | { | ||
389 | m_undo.RemoveFirst(); | ||
390 | |||
391 | // redo limite size | ||
392 | while (m_redo.Count >= size) | ||
393 | m_redo.RemoveLast(); | ||
394 | |||
395 | nUndo = new UndoState(part, goback.data.what); // new value in part should it be full goback copy? | ||
396 | m_redo.AddFirst(nUndo); | ||
397 | |||
398 | goback.PlayState(part); | ||
399 | } | ||
400 | } | ||
401 | } | ||
402 | } | ||
403 | |||
404 | public void Redo(SceneObjectPart part) | ||
405 | { | ||
406 | lock (m_undo) | ||
407 | { | ||
408 | UndoState nUndo; | ||
409 | |||
410 | // expire undo | ||
411 | if (m_undo.Count > 0) | ||
412 | { | ||
413 | nUndo = m_undo.First.Value; | ||
414 | if (nUndo != null && nUndo.checkExpire()) | ||
415 | m_undo.Clear(); | ||
416 | } | ||
417 | |||
418 | if (m_redo.Count > 0) | ||
419 | { | ||
420 | UndoState gofwd = m_redo.First.Value; | ||
421 | // check expired | ||
422 | if (gofwd != null && gofwd.checkExpire()) | ||
423 | { | ||
424 | m_redo.Clear(); | ||
425 | return; | ||
426 | } | ||
427 | |||
428 | if (gofwd != null) | ||
429 | { | ||
430 | m_redo.RemoveFirst(); | ||
431 | |||
432 | // limite undo size | ||
433 | while (m_undo.Count >= size) | ||
434 | m_undo.RemoveLast(); | ||
435 | |||
436 | nUndo = new UndoState(part, gofwd.data.what); // new value in part should it be full gofwd copy? | ||
437 | m_undo.AddFirst(nUndo); | ||
438 | |||
439 | gofwd.PlayState(part); | ||
440 | } | ||
441 | } | ||
442 | } | ||
443 | } | ||
444 | |||
445 | |||
446 | } | ||
277 | 447 | ||
278 | public class LandUndoState | 448 | public class LandUndoState |
279 | { | 449 | { |