The majority of the Undo fix. There is still an issue with Rotation which i'll address next; however position undo and scale undo should be working just fine now. Also removed some residual debug logging.

This commit is contained in:
Tom Grimshaw
2010-07-04 19:28:39 -07:00
parent 7665013ad8
commit 5b68343361
5 changed files with 135 additions and 57 deletions

View File

@@ -27,26 +27,43 @@
using OpenMetaverse;
using OpenSim.Region.Framework.Interfaces;
using System;
namespace OpenSim.Region.Framework.Scenes
{
[Flags]
public enum UndoType
{
STATE_PRIM_POSITION = 1,
STATE_PRIM_ROTATION = 2,
STATE_PRIM_SCALE = 4,
STATE_PRIM_ALL = 7,
STATE_GROUP_POSITION = 8,
STATE_GROUP_ROTATION = 16,
STATE_GROUP_SCALE = 32,
STATE_GROUP_ALL = 56,
STATE_ALL = 63
}
public class UndoState
{
public Vector3 Position = Vector3.Zero;
public Vector3 Scale = Vector3.Zero;
public Quaternion Rotation = Quaternion.Identity;
public bool GroupChange = false;
public Vector3 GroupPosition = Vector3.Zero;
public Quaternion GroupRotation = Quaternion.Identity;
public Vector3 GroupScale = Vector3.Zero;
public DateTime LastUpdated = DateTime.Now;
public UndoType Type;
public UndoState(SceneObjectPart part)
public UndoState(SceneObjectPart part, UndoType type)
{
Type = type;
if (part != null)
{
if (part.ParentID == 0)
{
GroupScale = part.Shape.Scale;
GroupScale = part.ParentGroup.RootPart.Shape.Scale;
//FUBAR WARNING: Do NOT get the group's absoluteposition here
//or you'll experience a loop and/or a stack issue
@@ -55,6 +72,7 @@ namespace OpenSim.Region.Framework.Scenes
Position = part.ParentGroup.RootPart.AbsolutePosition;
Rotation = part.RotationOffset;
Scale = part.Shape.Scale;
LastUpdated = DateTime.Now;
}
else
{
@@ -67,10 +85,54 @@ namespace OpenSim.Region.Framework.Scenes
Position = part.OffsetPosition;
Rotation = part.RotationOffset;
Scale = part.Shape.Scale;
LastUpdated = DateTime.Now;
}
}
}
public void Merge(UndoState last)
{
if ((Type & UndoType.STATE_GROUP_POSITION) == 0 || ((last.Type & UndoType.STATE_GROUP_POSITION) >= (Type & UndoType.STATE_GROUP_POSITION)))
{
GroupPosition = last.GroupPosition;
Position = last.Position;
}
if ((Type & UndoType.STATE_GROUP_SCALE) == 0 || ((last.Type & UndoType.STATE_GROUP_SCALE) >= (Type & UndoType.STATE_GROUP_SCALE)))
{
Console.WriteLine("Setting groupscale to " + last.GroupScale.ToString());
GroupScale = last.GroupScale;
Scale = last.Scale;
}
if ((Type & UndoType.STATE_GROUP_ROTATION) == 0 || ((last.Type & UndoType.STATE_GROUP_ROTATION) >= (Type & UndoType.STATE_GROUP_ROTATION)))
{
GroupRotation = last.GroupRotation;
Rotation = last.Rotation;
}
if ((Type & UndoType.STATE_PRIM_POSITION) == 0 || ((last.Type & UndoType.STATE_PRIM_POSITION) >= (Type & UndoType.STATE_PRIM_POSITION)))
{
Position = last.Position;
}
if ((Type & UndoType.STATE_PRIM_SCALE) == 0 || ((last.Type & UndoType.STATE_PRIM_SCALE) >= (Type & UndoType.STATE_PRIM_SCALE)))
{
Scale = last.Scale;
}
if ((Type & UndoType.STATE_PRIM_ROTATION) == 0 || ((last.Type & UndoType.STATE_PRIM_ROTATION) >= (Type & UndoType.STATE_PRIM_ROTATION)))
{
Rotation = last.Rotation;
}
Type = Type | last.Type;
}
public bool Compare(UndoState undo)
{
if (undo == null || Position == null) return false;
if (undo.Position == Position && undo.Rotation == Rotation && undo.Scale == Scale && undo.GroupPosition == GroupPosition && undo.GroupScale == GroupScale && undo.GroupRotation == GroupRotation)
{
return true;
}
else
{
return false;
}
}
public bool Compare(SceneObjectPart part)
{
if (part != null)
@@ -96,6 +158,14 @@ namespace OpenSim.Region.Framework.Scenes
public void PlaybackState(SceneObjectPart part)
{
bool GroupChange = false;
if ((Type & UndoType.STATE_GROUP_POSITION) != 0
|| (Type & UndoType.STATE_GROUP_ROTATION) != 0
|| (Type & UndoType.STATE_GROUP_SCALE) != 0)
{
GroupChange = true;
}
if (part != null)
{
part.Undoing = true;
@@ -113,6 +183,7 @@ namespace OpenSim.Region.Framework.Scenes
{
if (GroupChange)
{
part.ParentGroup.RootPart.Undoing = true;
if (Position != Vector3.Zero)
{
//Calculate the scale...
@@ -125,6 +196,7 @@ namespace OpenSim.Region.Framework.Scenes
part.ParentGroup.Rotation = GroupRotation;
}
part.ParentGroup.RootPart.Undoing = false;
}
else
{