aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/ContentManagementSystem/SceneObjectGroupDiff.cs
diff options
context:
space:
mode:
authorSean Dague2008-09-03 18:11:44 +0000
committerSean Dague2008-09-03 18:11:44 +0000
commitaf5c7e52b1163cf65f897e5c7ecf9ef2d9f6e88e (patch)
treefcc52c0f3e20f005873def97e3be5cd9ca16270e /OpenSim/Region/Environment/Modules/ContentManagementSystem/SceneObjectGroupDiff.cs
parentwhite space fixes (diff)
downloadopensim-SC_OLD-af5c7e52b1163cf65f897e5c7ecf9ef2d9f6e88e.zip
opensim-SC_OLD-af5c7e52b1163cf65f897e5c7ecf9ef2d9f6e88e.tar.gz
opensim-SC_OLD-af5c7e52b1163cf65f897e5c7ecf9ef2d9f6e88e.tar.bz2
opensim-SC_OLD-af5c7e52b1163cf65f897e5c7ecf9ef2d9f6e88e.tar.xz
narrange to do basic cleanup of the CMS module
Diffstat (limited to 'OpenSim/Region/Environment/Modules/ContentManagementSystem/SceneObjectGroupDiff.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/ContentManagementSystem/SceneObjectGroupDiff.cs298
1 files changed, 161 insertions, 137 deletions
diff --git a/OpenSim/Region/Environment/Modules/ContentManagementSystem/SceneObjectGroupDiff.cs b/OpenSim/Region/Environment/Modules/ContentManagementSystem/SceneObjectGroupDiff.cs
index c3817ef..6f34d3b 100644
--- a/OpenSim/Region/Environment/Modules/ContentManagementSystem/SceneObjectGroupDiff.cs
+++ b/OpenSim/Region/Environment/Modules/ContentManagementSystem/SceneObjectGroupDiff.cs
@@ -1,87 +1,113 @@
1#region Header
2
1// SceneObjectGroupDiff.cs 3// SceneObjectGroupDiff.cs
2// User: bongiojp 4// User: bongiojp
3 5
6#endregion Header
7
4using System; 8using System;
5using System.Collections.Generic; 9using System.Collections.Generic;
10using System.Diagnostics;
6using System.Drawing; 11using System.Drawing;
12
7using libsecondlife; 13using libsecondlife;
14
8using Nini.Config; 15using Nini.Config;
16
9using OpenSim.Framework; 17using OpenSim.Framework;
10using OpenSim.Region.Environment.Interfaces; 18using OpenSim.Region.Environment.Interfaces;
11using OpenSim.Region.Environment.Scenes; 19using OpenSim.Region.Environment.Scenes;
12using log4net;
13using OpenSim.Region.Physics.Manager; 20using OpenSim.Region.Physics.Manager;
21
22using log4net;
23
14using Axiom.Math; 24using Axiom.Math;
15using System.Diagnostics;
16 25
17namespace OpenSim.Region.Environment.Modules.ContentManagement 26namespace OpenSim.Region.Environment.Modules.ContentManagement
18{ 27{
19 [Flags] 28 #region Enumerations
20 public enum Diff 29
21 { 30 [Flags]
22 NONE = 0, 31 public enum Diff
23 FACECOLOR = 1, 32 {
24 SHAPE = 1<<1, 33 NONE = 0,
25 MATERIAL = 1<<2, 34 FACECOLOR = 1,
26 TEXTURE = 1<<3, 35 SHAPE = 1<<1,
27 SCALE = 1<<4, 36 MATERIAL = 1<<2,
28 POSITION = 1<<5, 37 TEXTURE = 1<<3,
29 OFFSETPOSITION = 1<<6, 38 SCALE = 1<<4,
30 ROTATIONOFFSET = 1<<7, 39 POSITION = 1<<5,
31 ROTATIONALVELOCITY = 1<<8, 40 OFFSETPOSITION = 1<<6,
32 ACCELERATION = 1<<9, 41 ROTATIONOFFSET = 1<<7,
33 ANGULARVELOCITY = 1<<10, 42 ROTATIONALVELOCITY = 1<<8,
34 VELOCITY = 1<<11, 43 ACCELERATION = 1<<9,
35 OBJECTOWNER = 1<<12, 44 ANGULARVELOCITY = 1<<10,
36 PERMISSIONS = 1<<13, 45 VELOCITY = 1<<11,
37 DESCRIPTION = 1<<14, 46 OBJECTOWNER = 1<<12,
38 NAME = 1<<15, 47 PERMISSIONS = 1<<13,
39 SCRIPT = 1<<16, 48 DESCRIPTION = 1<<14,
40 CLICKACTION = 1<<17, 49 NAME = 1<<15,
41 PARTICLESYSTEM = 1<<18, 50 SCRIPT = 1<<16,
42 GLOW = 1<<19, 51 CLICKACTION = 1<<17,
43 SALEPRICE = 1<<20, 52 PARTICLESYSTEM = 1<<18,
44 SITNAME = 1<<21, 53 GLOW = 1<<19,
45 SITTARGETORIENTATION = 1<<22, 54 SALEPRICE = 1<<20,
46 SITTARGETPOSITION = 1<<23, 55 SITNAME = 1<<21,
47 TEXT = 1<<24, 56 SITTARGETORIENTATION = 1<<22,
48 TOUCHNAME = 1<<25 57 SITTARGETPOSITION = 1<<23,
49 }; 58 TEXT = 1<<24,
50 59 TOUCHNAME = 1<<25
51 public static class Difference 60 }
52 { 61
53 static float TimeToDiff = 0; 62 #endregion Enumerations
54 63
55 private static readonly ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 64 public static class Difference
56 65 {
57 private static int TruncateSignificant(float num, int digits) 66 #region Static Fields
58 { 67
59 return (int) Math.Ceiling((Math.Truncate(num * 10 * digits)/10*digits)); 68 static float TimeToDiff = 0;
60 // return (int) ((num * (10*digits))/10*digits); 69 private static readonly ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
61 } 70
62 71 #endregion Static Fields
63 private static bool AreVectorsEquivalent(LLVector3 first, LLVector3 second) 72
64 { 73 #region Private Methods
65 if(TruncateSignificant(first.X, 2) == TruncateSignificant(second.X, 2) 74
66 && TruncateSignificant(first.Y, 2) == TruncateSignificant(second.Y, 2) 75 private static bool AreQuaternionsEquivalent(LLQuaternion first, LLQuaternion second)
67 && TruncateSignificant(first.Z, 2) == TruncateSignificant(second.Z, 2) 76 {
68 ) 77 LLVector3 firstVector = llRot2Euler(first);
69 return true; 78 LLVector3 secondVector = llRot2Euler(second);
70 else 79 return AreVectorsEquivalent(firstVector, secondVector);
71 return false; 80 }
72 } 81
73 82 private static bool AreVectorsEquivalent(LLVector3 first, LLVector3 second)
74 private static bool AreQuaternionsEquivalent(LLQuaternion first, LLQuaternion second) 83 {
75 { 84 if(TruncateSignificant(first.X, 2) == TruncateSignificant(second.X, 2)
76 LLVector3 firstVector = llRot2Euler(first); 85 && TruncateSignificant(first.Y, 2) == TruncateSignificant(second.Y, 2)
77 LLVector3 secondVector = llRot2Euler(second); 86 && TruncateSignificant(first.Z, 2) == TruncateSignificant(second.Z, 2)
78 return AreVectorsEquivalent(firstVector, secondVector); 87 )
79 } 88 return true;
80 89 else
81 // Taken from Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs 90 return false;
82 // Also changed the original function from LSL_Types to LL types 91 }
92
93 // Taken from Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
94 private static double NormalizeAngle(double angle)
95 {
96 angle = angle % (Math.PI * 2);
97 if (angle < 0) angle = angle + Math.PI * 2;
98 return angle;
99 }
100
101 private static int TruncateSignificant(float num, int digits)
102 {
103 return (int) Math.Ceiling((Math.Truncate(num * 10 * digits)/10*digits));
104 // return (int) ((num * (10*digits))/10*digits);
105 }
106
107 // Taken from Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
108 // Also changed the original function from LSL_Types to LL types
83 private static LLVector3 llRot2Euler(LLQuaternion r) 109 private static LLVector3 llRot2Euler(LLQuaternion r)
84 { 110 {
85 LLQuaternion t = new LLQuaternion(r.X * r.X, r.Y * r.Y, r.Z * r.Z, r.W * r.W); 111 LLQuaternion t = new LLQuaternion(r.X * r.X, r.Y * r.Y, r.Z * r.Z, r.W * r.W);
86 double m = (t.X + t.Y + t.Z + t.W); 112 double m = (t.X + t.Y + t.Z + t.W);
87 if (m == 0) return new LLVector3(); 113 if (m == 0) return new LLVector3();
@@ -96,74 +122,72 @@ namespace OpenSim.Region.Environment.Modules.ContentManagement
96 else 122 else
97 return new LLVector3(0.0f, (float)(-Math.PI / 2), (float)NormalizeAngle(Math.Atan2((r.Z * r.W + r.X * r.Y), 0.5 - t.X - t.Z))); 123 return new LLVector3(0.0f, (float)(-Math.PI / 2), (float)NormalizeAngle(Math.Atan2((r.Z * r.W + r.X * r.Y), 0.5 - t.X - t.Z)));
98 } 124 }
99 125
100 // Taken from Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs 126 #endregion Private Methods
101 private static double NormalizeAngle(double angle) 127
102 { 128 #region Public Methods
103 angle = angle % (Math.PI * 2); 129
104 if (angle < 0) angle = angle + Math.PI * 2; 130 /// <summary>
105 return angle; 131 /// Compares the attributes (Vectors, Quaternions, Strings, etc.) between two scene object parts
132 /// and returns a Diff bitmask which details what the differences are.
133 /// </summary>
134 public static Diff FindDifferences(SceneObjectPart first, SceneObjectPart second)
135 {
136 Stopwatch x = new Stopwatch();
137 x.Start();
138
139 Diff result = 0;
140
141 // VECTOR COMPARISONS
142 if(! AreVectorsEquivalent(first.Acceleration, second.Acceleration))
143 result |= Diff.ACCELERATION;
144 if(! AreVectorsEquivalent(first.AbsolutePosition, second.AbsolutePosition))
145 result |= Diff.POSITION;
146 if(! AreVectorsEquivalent(first.AngularVelocity, second.AngularVelocity))
147 result |= Diff.ANGULARVELOCITY;
148 if(! AreVectorsEquivalent(first.OffsetPosition, second.OffsetPosition))
149 result |= Diff.OFFSETPOSITION;
150 if(! AreVectorsEquivalent(first.RotationalVelocity, second.RotationalVelocity))
151 result |= Diff.ROTATIONALVELOCITY;
152 if(! AreVectorsEquivalent(first.Scale, second.Scale))
153 result |= Diff.SCALE;
154 if(! AreVectorsEquivalent(first.Velocity, second.Velocity))
155 result |= Diff.VELOCITY;
156
157
158 // QUATERNION COMPARISONS
159 if(! AreQuaternionsEquivalent(first.RotationOffset, second.RotationOffset))
160 result |= Diff.ROTATIONOFFSET;
161
162
163 // MISC COMPARISONS (LLUUID, Byte)
164 if(first.ClickAction != second.ClickAction)
165 result |= Diff.CLICKACTION;
166 if(first.ObjectOwner != second.ObjectOwner)
167 result |= Diff.OBJECTOWNER;
168
169
170 // STRING COMPARISONS
171 if(first.Description != second.Description)
172 result |= Diff.DESCRIPTION;
173 if(first.Material != second.Material)
174 result |= Diff.MATERIAL;
175 if(first.Name != second.Name)
176 result |= Diff.NAME;
177 if(first.SitName != second.SitName)
178 result |= Diff.SITNAME;
179 if(first.Text != second.Text)
180 result |= Diff.TEXT;
181 if(first.TouchName != second.TouchName)
182 result |= Diff.TOUCHNAME;
183
184 x.Stop();
185 TimeToDiff += x.ElapsedMilliseconds;
186 //m_log.Info("[DIFFERENCES] Time spent diffing objects so far" + TimeToDiff);
187
188 return result;
106 } 189 }
107 190
108 /// <summary> 191 #endregion Public Methods
109 /// Compares the attributes (Vectors, Quaternions, Strings, etc.) between two scene object parts 192 }
110 /// and returns a Diff bitmask which details what the differences are. 193} \ No newline at end of file
111 /// </summary>
112 public static Diff FindDifferences(SceneObjectPart first, SceneObjectPart second)
113 {
114 Stopwatch x = new Stopwatch();
115 x.Start();
116
117 Diff result = 0;
118
119 // VECTOR COMPARISONS
120 if(! AreVectorsEquivalent(first.Acceleration, second.Acceleration))
121 result |= Diff.ACCELERATION;
122 if(! AreVectorsEquivalent(first.AbsolutePosition, second.AbsolutePosition))
123 result |= Diff.POSITION;
124 if(! AreVectorsEquivalent(first.AngularVelocity, second.AngularVelocity))
125 result |= Diff.ANGULARVELOCITY;
126 if(! AreVectorsEquivalent(first.OffsetPosition, second.OffsetPosition))
127 result |= Diff.OFFSETPOSITION;
128 if(! AreVectorsEquivalent(first.RotationalVelocity, second.RotationalVelocity))
129 result |= Diff.ROTATIONALVELOCITY;
130 if(! AreVectorsEquivalent(first.Scale, second.Scale))
131 result |= Diff.SCALE;
132 if(! AreVectorsEquivalent(first.Velocity, second.Velocity))
133 result |= Diff.VELOCITY;
134
135
136 // QUATERNION COMPARISONS
137 if(! AreQuaternionsEquivalent(first.RotationOffset, second.RotationOffset))
138 result |= Diff.ROTATIONOFFSET;
139
140
141 // MISC COMPARISONS (LLUUID, Byte)
142 if(first.ClickAction != second.ClickAction)
143 result |= Diff.CLICKACTION;
144 if(first.ObjectOwner != second.ObjectOwner)
145 result |= Diff.OBJECTOWNER;
146
147
148 // STRING COMPARISONS
149 if(first.Description != second.Description)
150 result |= Diff.DESCRIPTION;
151 if(first.Material != second.Material)
152 result |= Diff.MATERIAL;
153 if(first.Name != second.Name)
154 result |= Diff.NAME;
155 if(first.SitName != second.SitName)
156 result |= Diff.SITNAME;
157 if(first.Text != second.Text)
158 result |= Diff.TEXT;
159 if(first.TouchName != second.TouchName)
160 result |= Diff.TOUCHNAME;
161
162 x.Stop();
163 TimeToDiff += x.ElapsedMilliseconds;
164 //m_log.Info("[DIFFERENCES] Time spent diffing objects so far" + TimeToDiff);
165
166 return result;
167 }
168 }
169}