aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics
diff options
context:
space:
mode:
authorJeff Ames2007-12-19 08:44:25 +0000
committerJeff Ames2007-12-19 08:44:25 +0000
commit6702b0373371fd2a546a580ad82f5cc175fa29e0 (patch)
treef2750d5be494d2a976cb583476c4f32ef3d895d7 /OpenSim/Region/Physics
parent*Added Ban Lines around parcels for banned avatars, but there is no actual bl... (diff)
downloadopensim-SC-6702b0373371fd2a546a580ad82f5cc175fa29e0.zip
opensim-SC-6702b0373371fd2a546a580ad82f5cc175fa29e0.tar.gz
opensim-SC-6702b0373371fd2a546a580ad82f5cc175fa29e0.tar.bz2
opensim-SC-6702b0373371fd2a546a580ad82f5cc175fa29e0.tar.xz
Misc. cleanup:
* added Util.Clip(value, min, max) * modified asset cache's numPackets calculation to use max packet size (600) instead of 1000 * removed a few magic numbers
Diffstat (limited to 'OpenSim/Region/Physics')
-rw-r--r--OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs13
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs88
-rw-r--r--OpenSim/Region/Physics/POSPlugin/POSPlugin.cs7
3 files changed, 53 insertions, 55 deletions
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs
index df3ebb9..545f461 100644
--- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs
+++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs
@@ -125,8 +125,9 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
125 { 125 {
126 BasicActor actor = _actors[i]; 126 BasicActor actor = _actors[i];
127 127
128 actor.Position.X = actor.Position.X + (actor.Velocity.X*timeStep); 128 actor.Position.X += actor.Velocity.X * timeStep;
129 actor.Position.Y = actor.Position.Y + (actor.Velocity.Y*timeStep); 129 actor.Position.Y += actor.Velocity.Y * timeStep;
130
130 if (actor.Position.Y < 0) 131 if (actor.Position.Y < 0)
131 { 132 {
132 actor.Position.Y = 0.1F; 133 actor.Position.Y = 0.1F;
@@ -145,18 +146,18 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
145 actor.Position.X = 255.9F; 146 actor.Position.X = 255.9F;
146 } 147 }
147 148
148 float height = _heightMap[(int) actor.Position.Y*256 + (int) actor.Position.X] + 1.0f; 149 float height = _heightMap[(int) actor.Position.Y * 256 + (int) actor.Position.X] + 1.0f;
149 if (actor.Flying) 150 if (actor.Flying)
150 { 151 {
151 if (actor.Position.Z + (actor.Velocity.Z*timeStep) < 152 if (actor.Position.Z + (actor.Velocity.Z * timeStep) <
152 _heightMap[(int) actor.Position.Y*256 + (int) actor.Position.X] + 2) 153 _heightMap[(int) actor.Position.Y * 256 + (int) actor.Position.X] + 2)
153 { 154 {
154 actor.Position.Z = height; 155 actor.Position.Z = height;
155 actor.Velocity.Z = 0; 156 actor.Velocity.Z = 0;
156 } 157 }
157 else 158 else
158 { 159 {
159 actor.Position.Z = actor.Position.Z + (actor.Velocity.Z*timeStep); 160 actor.Position.Z += actor.Velocity.Z * timeStep;
160 } 161 }
161 } 162 }
162 else 163 else
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 0cbd4d6..305a930 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -75,6 +75,10 @@ namespace OpenSim.Region.Physics.OdePlugin
75 75
76 public class OdeScene : PhysicsScene 76 public class OdeScene : PhysicsScene
77 { 77 {
78 // TODO: this should be hard-coded in some common place
79 private const uint m_regionWidth = 256;
80 private const uint m_regionHeight = 256;
81
78 private static float ODE_STEPSIZE = 0.004f; 82 private static float ODE_STEPSIZE = 0.004f;
79 private static bool RENDER_FLAG = false; 83 private static bool RENDER_FLAG = false;
80 private static float metersInSpace = 29.9f; 84 private static float metersInSpace = 29.9f;
@@ -167,12 +171,9 @@ namespace OpenSim.Region.Physics.OdePlugin
167 171
168 } 172 }
169 173
170
171
172 public override void Initialise(IMesher meshmerizer) 174 public override void Initialise(IMesher meshmerizer)
173 { 175 {
174 mesher = meshmerizer; 176 mesher = meshmerizer;
175
176 } 177 }
177 178
178 public string whichspaceamIin(PhysicsVector pos) 179 public string whichspaceamIin(PhysicsVector pos)
@@ -196,7 +197,6 @@ namespace OpenSim.Region.Physics.OdePlugin
196 //Collide all geoms in each space.. 197 //Collide all geoms in each space..
197 //if (d.GeomIsSpace(g1)) d.SpaceCollide(g1, IntPtr.Zero, nearCallback); 198 //if (d.GeomIsSpace(g1)) d.SpaceCollide(g1, IntPtr.Zero, nearCallback);
198 //if (d.GeomIsSpace(g2)) d.SpaceCollide(g2, IntPtr.Zero, nearCallback); 199 //if (d.GeomIsSpace(g2)) d.SpaceCollide(g2, IntPtr.Zero, nearCallback);
199
200 } 200 }
201 else 201 else
202 { 202 {
@@ -206,14 +206,12 @@ namespace OpenSim.Region.Physics.OdePlugin
206 IntPtr b1 = d.GeomGetBody(g1); 206 IntPtr b1 = d.GeomGetBody(g1);
207 IntPtr b2 = d.GeomGetBody(g2); 207 IntPtr b2 = d.GeomGetBody(g2);
208 208
209
210 if (g1 == g2) 209 if (g1 == g2)
211 return; // Can't collide with yourself 210 return; // Can't collide with yourself
212 211
213 if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact)) 212 if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
214 return; 213 return;
215 214
216
217 d.GeomClassID id = d.GeomGetClass(g1); 215 d.GeomClassID id = d.GeomGetClass(g1);
218 216
219 String name1 = null; 217 String name1 = null;
@@ -230,8 +228,6 @@ namespace OpenSim.Region.Physics.OdePlugin
230 228
231 if (id == d.GeomClassID.TriMeshClass) 229 if (id == d.GeomClassID.TriMeshClass)
232 { 230 {
233
234
235 // MainLog.Instance.Verbose("near: A collision was detected between {1} and {2}", 0, name1, name2); 231 // MainLog.Instance.Verbose("near: A collision was detected between {1} and {2}", 0, name1, name2);
236 //System.Console.WriteLine("near: A collision was detected between {1} and {2}", 0, name1, name2); 232 //System.Console.WriteLine("near: A collision was detected between {1} and {2}", 0, name1, name2);
237 } 233 }
@@ -297,8 +293,6 @@ namespace OpenSim.Region.Physics.OdePlugin
297 TerrainContact.geom = contacts[i]; 293 TerrainContact.geom = contacts[i];
298 joint = d.JointCreateContact(world, contactgroup, ref TerrainContact); 294 joint = d.JointCreateContact(world, contactgroup, ref TerrainContact);
299 } 295 }
300
301
302 } 296 }
303 else 297 else
304 { 298 {
@@ -311,9 +305,7 @@ namespace OpenSim.Region.Physics.OdePlugin
311 { 305 {
312 contact.geom = contacts[i]; 306 contact.geom = contacts[i];
313 joint = d.JointCreateContact(world, contactgroup, ref contact); 307 joint = d.JointCreateContact(world, contactgroup, ref contact);
314
315 } 308 }
316
317 } 309 }
318 310
319 311
@@ -333,17 +325,12 @@ namespace OpenSim.Region.Physics.OdePlugin
333 325
334 private void collision_optimized(float timeStep) 326 private void collision_optimized(float timeStep)
335 { 327 {
336
337 foreach (OdeCharacter chr in _characters) 328 foreach (OdeCharacter chr in _characters)
338 { 329 {
339
340
341 chr.IsColliding = false; 330 chr.IsColliding = false;
342 chr.CollidingGround = false; 331 chr.CollidingGround = false;
343 chr.CollidingObj = false; 332 chr.CollidingObj = false;
344 d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); 333 d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback);
345
346
347 } 334 }
348 // If the sim is running slow this frame, 335 // If the sim is running slow this frame,
349 // don't process collision for prim! 336 // don't process collision for prim!
@@ -422,11 +409,11 @@ namespace OpenSim.Region.Physics.OdePlugin
422 } 409 }
423 } 410 }
424 } 411 }
412
425 public void RemovePrimThreadLocked(OdePrim prim) 413 public void RemovePrimThreadLocked(OdePrim prim)
426 { 414 {
427 lock (OdeLock) 415 lock (OdeLock)
428 { 416 {
429
430 if (prim.IsPhysical) 417 if (prim.IsPhysical)
431 { 418 {
432 prim.disableBody(); 419 prim.disableBody();
@@ -479,6 +466,7 @@ namespace OpenSim.Region.Physics.OdePlugin
479 } 466 }
480 467
481 } 468 }
469
482 public void resetSpaceArrayItemToZero(IntPtr space) 470 public void resetSpaceArrayItemToZero(IntPtr space)
483 { 471 {
484 for (int x = 0; x < staticPrimspace.GetLength(0); x++) 472 for (int x = 0; x < staticPrimspace.GetLength(0); x++)
@@ -490,6 +478,7 @@ namespace OpenSim.Region.Physics.OdePlugin
490 } 478 }
491 } 479 }
492 } 480 }
481
493 public void resetSpaceArrayItemToZero(int arrayitemX,int arrayitemY) 482 public void resetSpaceArrayItemToZero(int arrayitemX,int arrayitemY)
494 { 483 {
495 staticPrimspace[arrayitemX, arrayitemY] = IntPtr.Zero; 484 staticPrimspace[arrayitemX, arrayitemY] = IntPtr.Zero;
@@ -524,6 +513,7 @@ namespace OpenSim.Region.Physics.OdePlugin
524 if (!(sGeomIsIn.Equals(null))) 513 if (!(sGeomIsIn.Equals(null)))
525 { 514 {
526 if (sGeomIsIn != (IntPtr)0) 515 if (sGeomIsIn != (IntPtr)0)
516 {
527 if (d.GeomIsSpace(currentspace)) 517 if (d.GeomIsSpace(currentspace))
528 { 518 {
529 d.SpaceRemove(sGeomIsIn, geom); 519 d.SpaceRemove(sGeomIsIn, geom);
@@ -532,6 +522,7 @@ namespace OpenSim.Region.Physics.OdePlugin
532 { 522 {
533 MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + sGeomIsIn.ToString() + " Geom:" + geom.ToString()); 523 MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + sGeomIsIn.ToString() + " Geom:" + geom.ToString());
534 } 524 }
525 }
535 } 526 }
536 } 527 }
537 528
@@ -586,7 +577,6 @@ namespace OpenSim.Region.Physics.OdePlugin
586 else 577 else
587 { 578 {
588 MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + sGeomIsIn.ToString() + " Geom:" + geom.ToString()); 579 MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + sGeomIsIn.ToString() + " Geom:" + geom.ToString());
589
590 } 580 }
591 } 581 }
592 } 582 }
@@ -625,6 +615,7 @@ namespace OpenSim.Region.Physics.OdePlugin
625 //locationbasedspace = space; 615 //locationbasedspace = space;
626 return locationbasedspace; 616 return locationbasedspace;
627 } 617 }
618
628 public int[] calculateSpaceArrayItemFromPos(PhysicsVector pos) 619 public int[] calculateSpaceArrayItemFromPos(PhysicsVector pos)
629 { 620 {
630 int[] returnint = new int[2]; 621 int[] returnint = new int[2];
@@ -682,7 +673,7 @@ namespace OpenSim.Region.Physics.OdePlugin
682 } 673 }
683 674
684 public void addActivePrim(OdePrim activatePrim) 675 public void addActivePrim(OdePrim activatePrim)
685 { 676 {
686 // adds active prim.. (ones that should be iterated over in collisions_optimized 677 // adds active prim.. (ones that should be iterated over in collisions_optimized
687 678
688 _activeprims.Add(activatePrim); 679 _activeprims.Add(activatePrim);
@@ -902,17 +893,18 @@ namespace OpenSim.Region.Physics.OdePlugin
902 get { return (false); // for now we won't be multithreaded 893 get { return (false); // for now we won't be multithreaded
903 } 894 }
904 } 895 }
896
905 public float[] ResizeTerrain512(float[] heightMap) 897 public float[] ResizeTerrain512(float[] heightMap)
906 { 898 {
907 float[] returnarr = new float[262144]; 899 float[] returnarr = new float[262144];
908 float[,] resultarr = new float[256, 256]; 900 float[,] resultarr = new float[m_regionWidth, m_regionHeight];
909 901
910 // Filling out the array into it's multi-dimentional components 902 // Filling out the array into it's multi-dimentional components
911 for (int y = 0; y < 256; y++) 903 for (int y = 0; y < m_regionHeight; y++)
912 { 904 {
913 for (int x = 0; x < 256; x++) 905 for (int x = 0; x < m_regionWidth; x++)
914 { 906 {
915 resultarr[y,x] = heightMap[y * 256 + x]; 907 resultarr[y,x] = heightMap[y * m_regionWidth + x];
916 } 908 }
917 } 909 }
918 910
@@ -976,17 +968,17 @@ namespace OpenSim.Region.Physics.OdePlugin
976 // on single loop. 968 // on single loop.
977 969
978 float[,] resultarr2 = new float[512, 512]; 970 float[,] resultarr2 = new float[512, 512];
979 for (int y = 0; y < 256; y++) 971 for (int y = 0; y < m_regionHeight; y++)
980 { 972 {
981 for (int x = 0; x < 256; x++) 973 for (int x = 0; x < m_regionWidth; x++)
982 { 974 {
983 resultarr2[y*2,x*2] = resultarr[y,x]; 975 resultarr2[y*2,x*2] = resultarr[y,x];
984 976
985 if (y < 256) 977 if (y < m_regionHeight)
986 { 978 {
987 if (y + 1 < 256) 979 if (y + 1 < m_regionHeight)
988 { 980 {
989 if (x + 1 < 256) 981 if (x + 1 < m_regionWidth)
990 { 982 {
991 resultarr2[(y * 2) + 1, x * 2] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x+1] + resultarr[y+1, x+1])/4); 983 resultarr2[(y * 2) + 1, x * 2] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x+1] + resultarr[y+1, x+1])/4);
992 } 984 }
@@ -1000,11 +992,11 @@ namespace OpenSim.Region.Physics.OdePlugin
1000 resultarr2[(y * 2) + 1, x * 2] = resultarr[y, x]; 992 resultarr2[(y * 2) + 1, x * 2] = resultarr[y, x];
1001 } 993 }
1002 } 994 }
1003 if (x < 256) 995 if (x < m_regionWidth)
1004 { 996 {
1005 if (x + 1 < 256) 997 if (x + 1 < m_regionWidth)
1006 { 998 {
1007 if (y + 1 < 256) 999 if (y + 1 < m_regionHeight)
1008 { 1000 {
1009 resultarr2[y * 2, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1]) / 4); 1001 resultarr2[y * 2, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1]) / 4);
1010 } 1002 }
@@ -1018,9 +1010,9 @@ namespace OpenSim.Region.Physics.OdePlugin
1018 resultarr2[y * 2, (x * 2) + 1] = resultarr[y, x]; 1010 resultarr2[y * 2, (x * 2) + 1] = resultarr[y, x];
1019 } 1011 }
1020 } 1012 }
1021 if (x < 256 && y < 256) 1013 if (x < m_regionWidth && y < m_regionHeight)
1022 { 1014 {
1023 if ((x + 1 < 256) && (y + 1 < 256)) 1015 if ((x + 1 < m_regionWidth) && (y + 1 < m_regionHeight))
1024 { 1016 {
1025 resultarr2[(y * 2) + 1, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1]) / 4); 1017 resultarr2[(y * 2) + 1, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1]) / 4);
1026 } 1018 }
@@ -1052,21 +1044,26 @@ namespace OpenSim.Region.Physics.OdePlugin
1052 // dbm (danx0r) -- heightmap x,y must be swapped for Ode (should fix ODE, but for now...) 1044 // dbm (danx0r) -- heightmap x,y must be swapped for Ode (should fix ODE, but for now...)
1053 // also, creating a buffer zone of one extra sample all around 1045 // also, creating a buffer zone of one extra sample all around
1054 1046
1047 const uint heightmapWidth = m_regionWidth + 2;
1048 const uint heightmapHeight = m_regionHeight + 2;
1049 const uint heightmapWidthSamples = 2 * m_regionWidth + 2;
1050 const uint heightmapHeightSamples = 2 * m_regionHeight + 2;
1051 const float scale = 1.0f;
1052 const float offset = 0.0f;
1053 const float thickness = 2.0f;
1054 const int wrap = 0;
1055
1055 //Double resolution 1056 //Double resolution
1056 heightMap = ResizeTerrain512(heightMap); 1057 heightMap = ResizeTerrain512(heightMap);
1057 for (int x = 0; x < 514; x++) 1058 for (int x = 0; x < heightmapWidthSamples; x++)
1058 { 1059 {
1059 for (int y = 0; y < 514; y++) 1060 for (int y = 0; y < heightmapHeightSamples; y++)
1060 { 1061 {
1061 int xx = x - 1; 1062 int xx = Util.Clip(x - 1, 0, 511);
1062 if (xx < 0) xx = 0; 1063 int yy = Util.Clip(y - 1, 0, 511);
1063 if (xx > 511) xx = 511;
1064 int yy = y - 1;
1065 if (yy < 0) yy = 0;
1066 if (yy > 511) yy = 511;
1067 1064
1068 double val = (double) heightMap[yy*512 + xx]; 1065 double val = (double) heightMap[yy*512 + xx];
1069 _heightmap[x*514 + y] = val; 1066 _heightmap[x*heightmapHeightSamples + y] = val;
1070 } 1067 }
1071 } 1068 }
1072 1069
@@ -1077,8 +1074,9 @@ namespace OpenSim.Region.Physics.OdePlugin
1077 d.SpaceRemove(space, LandGeom); 1074 d.SpaceRemove(space, LandGeom);
1078 } 1075 }
1079 IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); 1076 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
1080 d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 258, 258, 514, 514, 1.0f, 0.0f, 2.0f, 0); 1077 d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, heightmapWidth, heightmapHeight,
1081 d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256); 1078 (int) heightmapWidthSamples, (int) heightmapHeightSamples, scale, offset, thickness, wrap);
1079 d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight);
1082 LandGeom = d.CreateHeightfield(space, HeightmapData, 1); 1080 LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
1083 geom_name_map[LandGeom] = "Terrain"; 1081 geom_name_map[LandGeom] = "Terrain";
1084 1082
diff --git a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs
index efc30fe..a565598 100644
--- a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs
+++ b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs
@@ -166,7 +166,6 @@ namespace OpenSim.Region.Physics.POSPlugin
166 166
167 public override void AddPhysicsActorTaint(PhysicsActor prim) 167 public override void AddPhysicsActorTaint(PhysicsActor prim)
168 { 168 {
169
170 } 169 }
171 170
172 public override float Simulate(float timeStep) 171 public override float Simulate(float timeStep)
@@ -187,8 +186,8 @@ namespace OpenSim.Region.Physics.POSPlugin
187 } 186 }
188 187
189 bool forcedZ = false; 188 bool forcedZ = false;
190 character.Position.X = character.Position.X + (character._target_velocity.X * timeStep); 189 character.Position.X += character._target_velocity.X * timeStep;
191 character.Position.Y = character.Position.Y + (character._target_velocity.Y * timeStep); 190 character.Position.Y += character._target_velocity.Y * timeStep;
192 191
193 if (character.Position.Y < 0) 192 if (character.Position.Y < 0)
194 { 193 {
@@ -216,7 +215,7 @@ namespace OpenSim.Region.Physics.POSPlugin
216 } 215 }
217 else 216 else
218 { 217 {
219 character.Position.Z = character.Position.Z + (character._target_velocity.Z * timeStep); 218 character.Position.Z += character._target_velocity.Z * timeStep;
220 } 219 }
221 220
222 /// this is it -- the magic you've all been waiting for! Ladies and gentlemen -- 221 /// this is it -- the magic you've all been waiting for! Ladies and gentlemen --