aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-01-24 00:14:58 +0000
committerJustin Clark-Casey (justincc)2014-01-24 00:14:58 +0000
commita2d5d810e0572e7f87808ba35c4b2a21e6f48c40 (patch)
tree64f5c0117081438883f282dd1121769ad333fa86 /OpenSim/Region/CoreModules
parentAdd "generate map" console command to allow manual regeneration and storage o... (diff)
downloadopensim-SC_OLD-a2d5d810e0572e7f87808ba35c4b2a21e6f48c40.zip
opensim-SC_OLD-a2d5d810e0572e7f87808ba35c4b2a21e6f48c40.tar.gz
opensim-SC_OLD-a2d5d810e0572e7f87808ba35c4b2a21e6f48c40.tar.bz2
opensim-SC_OLD-a2d5d810e0572e7f87808ba35c4b2a21e6f48c40.tar.xz
Properly dispose of drawing objects to reduce/stop memory leakage on generating map tiles with the MapImageModule and TexturedMapTileRenderer (the current defaults)
Diffstat (limited to 'OpenSim/Region/CoreModules')
-rw-r--r--OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs533
-rw-r--r--OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs11
-rw-r--r--OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs27
-rw-r--r--OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs91
4 files changed, 343 insertions, 319 deletions
diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs b/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
index 61ba5f3..bc52a43 100644
--- a/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
+++ b/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
@@ -55,7 +55,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
55 public struct DrawStruct 55 public struct DrawStruct
56 { 56 {
57 public DrawRoutine dr; 57 public DrawRoutine dr;
58 public Rectangle rect; 58// public Rectangle rect;
59 public SolidBrush brush; 59 public SolidBrush brush;
60 public face[] trns; 60 public face[] trns;
61 } 61 }
@@ -119,6 +119,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
119 { 119 {
120 mapbmp = FetchTexture(m_scene.RegionInfo.RegionSettings.TerrainImageID); 120 mapbmp = FetchTexture(m_scene.RegionInfo.RegionSettings.TerrainImageID);
121 } 121 }
122
122 return mapbmp; 123 return mapbmp;
123 } 124 }
124 125
@@ -280,321 +281,331 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
280 tc = Environment.TickCount; 281 tc = Environment.TickCount;
281 m_log.Debug("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile"); 282 m_log.Debug("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile");
282 EntityBase[] objs = whichScene.GetEntities(); 283 EntityBase[] objs = whichScene.GetEntities();
283 Dictionary<uint, DrawStruct> z_sort = new Dictionary<uint, DrawStruct>();
284 //SortedList<float, RectangleDrawStruct> z_sort = new SortedList<float, RectangleDrawStruct>();
285 List<float> z_sortheights = new List<float>(); 284 List<float> z_sortheights = new List<float>();
286 List<uint> z_localIDs = new List<uint>(); 285 List<uint> z_localIDs = new List<uint>();
286 Dictionary<uint, DrawStruct> z_sort = new Dictionary<uint, DrawStruct>();
287 287
288 lock (objs) 288 try
289 { 289 {
290 foreach (EntityBase obj in objs) 290 //SortedList<float, RectangleDrawStruct> z_sort = new SortedList<float, RectangleDrawStruct>();
291
292 lock (objs)
291 { 293 {
292 // Only draw the contents of SceneObjectGroup 294 foreach (EntityBase obj in objs)
293 if (obj is SceneObjectGroup)
294 { 295 {
295 SceneObjectGroup mapdot = (SceneObjectGroup)obj; 296 // Only draw the contents of SceneObjectGroup
296 Color mapdotspot = Color.Gray; // Default color when prim color is white 297 if (obj is SceneObjectGroup)
297
298 // Loop over prim in group
299 foreach (SceneObjectPart part in mapdot.Parts)
300 { 298 {
301 if (part == null) 299 SceneObjectGroup mapdot = (SceneObjectGroup)obj;
302 continue; 300 Color mapdotspot = Color.Gray; // Default color when prim color is white
303 301
304 // Draw if the object is at least 1 meter wide in any direction 302 // Loop over prim in group
305 if (part.Scale.X > 1f || part.Scale.Y > 1f || part.Scale.Z > 1f) 303 foreach (SceneObjectPart part in mapdot.Parts)
306 { 304 {
307 // Try to get the RGBA of the default texture entry.. 305 if (part == null)
308 // 306 continue;
309 try 307
308 // Draw if the object is at least 1 meter wide in any direction
309 if (part.Scale.X > 1f || part.Scale.Y > 1f || part.Scale.Z > 1f)
310 { 310 {
311 // get the null checks out of the way 311 // Try to get the RGBA of the default texture entry..
312 // skip the ones that break 312 //
313 if (part == null) 313 try
314 continue; 314 {
315 // get the null checks out of the way
316 // skip the ones that break
317 if (part == null)
318 continue;
315 319
316 if (part.Shape == null) 320 if (part.Shape == null)
317 continue; 321 continue;
318 322
319 if (part.Shape.PCode == (byte)PCode.Tree || part.Shape.PCode == (byte)PCode.NewTree || part.Shape.PCode == (byte)PCode.Grass) 323 if (part.Shape.PCode == (byte)PCode.Tree || part.Shape.PCode == (byte)PCode.NewTree || part.Shape.PCode == (byte)PCode.Grass)
320 continue; // eliminates trees from this since we don't really have a good tree representation 324 continue; // eliminates trees from this since we don't really have a good tree representation
321 // if you want tree blocks on the map comment the above line and uncomment the below line 325 // if you want tree blocks on the map comment the above line and uncomment the below line
322 //mapdotspot = Color.PaleGreen; 326 //mapdotspot = Color.PaleGreen;
323 327
324 Primitive.TextureEntry textureEntry = part.Shape.Textures; 328 Primitive.TextureEntry textureEntry = part.Shape.Textures;
325 329
326 if (textureEntry == null || textureEntry.DefaultTexture == null) 330 if (textureEntry == null || textureEntry.DefaultTexture == null)
327 continue; 331 continue;
328 332
329 Color4 texcolor = textureEntry.DefaultTexture.RGBA; 333 Color4 texcolor = textureEntry.DefaultTexture.RGBA;
330 334
331 // Not sure why some of these are null, oh well. 335 // Not sure why some of these are null, oh well.
332 336
333 int colorr = 255 - (int)(texcolor.R * 255f); 337 int colorr = 255 - (int)(texcolor.R * 255f);
334 int colorg = 255 - (int)(texcolor.G * 255f); 338 int colorg = 255 - (int)(texcolor.G * 255f);
335 int colorb = 255 - (int)(texcolor.B * 255f); 339 int colorb = 255 - (int)(texcolor.B * 255f);
336 340
337 if (!(colorr == 255 && colorg == 255 && colorb == 255)) 341 if (!(colorr == 255 && colorg == 255 && colorb == 255))
338 {
339 //Try to set the map spot color
340 try
341 {
342 // If the color gets goofy somehow, skip it *shakes fist at Color4
343 mapdotspot = Color.FromArgb(colorr, colorg, colorb);
344 }
345 catch (ArgumentException)
346 { 342 {
343 //Try to set the map spot color
344 try
345 {
346 // If the color gets goofy somehow, skip it *shakes fist at Color4
347 mapdotspot = Color.FromArgb(colorr, colorg, colorb);
348 }
349 catch (ArgumentException)
350 {
351 }
347 } 352 }
348 } 353 }
349 } 354 catch (IndexOutOfRangeException)
350 catch (IndexOutOfRangeException) 355 {
351 { 356 // Windows Array
352 // Windows Array 357 }
353 } 358 catch (ArgumentOutOfRangeException)
354 catch (ArgumentOutOfRangeException) 359 {
355 { 360 // Mono Array
356 // Mono Array 361 }
357 }
358
359 Vector3 pos = part.GetWorldPosition();
360
361 // skip prim outside of retion
362 if (pos.X < 0f || pos.X > 256f || pos.Y < 0f || pos.Y > 256f)
363 continue;
364
365 // skip prim in non-finite position
366 if (Single.IsNaN(pos.X) || Single.IsNaN(pos.Y) ||
367 Single.IsInfinity(pos.X) || Single.IsInfinity(pos.Y))
368 continue;
369 362
370 // Figure out if object is under 256m above the height of the terrain 363 Vector3 pos = part.GetWorldPosition();
371 bool isBelow256AboveTerrain = false;
372 364
373 try 365 // skip prim outside of retion
374 { 366 if (pos.X < 0f || pos.X > 256f || pos.Y < 0f || pos.Y > 256f)
375 isBelow256AboveTerrain = (pos.Z < ((float)hm[(int)pos.X, (int)pos.Y] + 256f));
376 }
377 catch (Exception)
378 {
379 }
380
381 if (isBelow256AboveTerrain)
382 {
383 // Translate scale by rotation so scale is represented properly when object is rotated
384 Vector3 lscale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z);
385 Vector3 scale = new Vector3();
386 Vector3 tScale = new Vector3();
387 Vector3 axPos = new Vector3(pos.X,pos.Y,pos.Z);
388
389 Quaternion llrot = part.GetWorldRotation();
390 Quaternion rot = new Quaternion(llrot.W, llrot.X, llrot.Y, llrot.Z);
391 scale = lscale * rot;
392
393 // negative scales don't work in this situation
394 scale.X = Math.Abs(scale.X);
395 scale.Y = Math.Abs(scale.Y);
396 scale.Z = Math.Abs(scale.Z);
397
398 // This scaling isn't very accurate and doesn't take into account the face rotation :P
399 int mapdrawstartX = (int)(pos.X - scale.X);
400 int mapdrawstartY = (int)(pos.Y - scale.Y);
401 int mapdrawendX = (int)(pos.X + scale.X);
402 int mapdrawendY = (int)(pos.Y + scale.Y);
403
404 // If object is beyond the edge of the map, don't draw it to avoid errors
405 if (mapdrawstartX < 0 || mapdrawstartX > ((int)Constants.RegionSize - 1) || mapdrawendX < 0 || mapdrawendX > ((int)Constants.RegionSize - 1)
406 || mapdrawstartY < 0 || mapdrawstartY > ((int)Constants.RegionSize - 1) || mapdrawendY < 0
407 || mapdrawendY > ((int)Constants.RegionSize - 1))
408 continue; 367 continue;
409 368
410#region obb face reconstruction part duex 369 // skip prim in non-finite position
411 Vector3[] vertexes = new Vector3[8]; 370 if (Single.IsNaN(pos.X) || Single.IsNaN(pos.Y) ||
412 371 Single.IsInfinity(pos.X) || Single.IsInfinity(pos.Y))
413 // float[] distance = new float[6]; 372 continue;
414 Vector3[] FaceA = new Vector3[6]; // vertex A for Facei
415 Vector3[] FaceB = new Vector3[6]; // vertex B for Facei
416 Vector3[] FaceC = new Vector3[6]; // vertex C for Facei
417 Vector3[] FaceD = new Vector3[6]; // vertex D for Facei
418
419 tScale = new Vector3(lscale.X, -lscale.Y, lscale.Z);
420 scale = ((tScale * rot));
421 vertexes[0] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
422 // vertexes[0].x = pos.X + vertexes[0].x;
423 //vertexes[0].y = pos.Y + vertexes[0].y;
424 //vertexes[0].z = pos.Z + vertexes[0].z;
425
426 FaceA[0] = vertexes[0];
427 FaceB[3] = vertexes[0];
428 FaceA[4] = vertexes[0];
429
430 tScale = lscale;
431 scale = ((tScale * rot));
432 vertexes[1] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
433
434 // vertexes[1].x = pos.X + vertexes[1].x;
435 // vertexes[1].y = pos.Y + vertexes[1].y;
436 //vertexes[1].z = pos.Z + vertexes[1].z;
437
438 FaceB[0] = vertexes[1];
439 FaceA[1] = vertexes[1];
440 FaceC[4] = vertexes[1];
441
442 tScale = new Vector3(lscale.X, -lscale.Y, -lscale.Z);
443 scale = ((tScale * rot));
444
445 vertexes[2] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
446
447 //vertexes[2].x = pos.X + vertexes[2].x;
448 //vertexes[2].y = pos.Y + vertexes[2].y;
449 //vertexes[2].z = pos.Z + vertexes[2].z;
450
451 FaceC[0] = vertexes[2];
452 FaceD[3] = vertexes[2];
453 FaceC[5] = vertexes[2];
454
455 tScale = new Vector3(lscale.X, lscale.Y, -lscale.Z);
456 scale = ((tScale * rot));
457 vertexes[3] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
458
459 //vertexes[3].x = pos.X + vertexes[3].x;
460 // vertexes[3].y = pos.Y + vertexes[3].y;
461 // vertexes[3].z = pos.Z + vertexes[3].z;
462
463 FaceD[0] = vertexes[3];
464 FaceC[1] = vertexes[3];
465 FaceA[5] = vertexes[3];
466
467 tScale = new Vector3(-lscale.X, lscale.Y, lscale.Z);
468 scale = ((tScale * rot));
469 vertexes[4] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
470
471 // vertexes[4].x = pos.X + vertexes[4].x;
472 // vertexes[4].y = pos.Y + vertexes[4].y;
473 // vertexes[4].z = pos.Z + vertexes[4].z;
474
475 FaceB[1] = vertexes[4];
476 FaceA[2] = vertexes[4];
477 FaceD[4] = vertexes[4];
478
479 tScale = new Vector3(-lscale.X, lscale.Y, -lscale.Z);
480 scale = ((tScale * rot));
481 vertexes[5] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
482
483 // vertexes[5].x = pos.X + vertexes[5].x;
484 // vertexes[5].y = pos.Y + vertexes[5].y;
485 // vertexes[5].z = pos.Z + vertexes[5].z;
486
487 FaceD[1] = vertexes[5];
488 FaceC[2] = vertexes[5];
489 FaceB[5] = vertexes[5];
490 373
491 tScale = new Vector3(-lscale.X, -lscale.Y, lscale.Z); 374 // Figure out if object is under 256m above the height of the terrain
492 scale = ((tScale * rot)); 375 bool isBelow256AboveTerrain = false;
493 vertexes[6] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
494 376
495 // vertexes[6].x = pos.X + vertexes[6].x; 377 try
496 // vertexes[6].y = pos.Y + vertexes[6].y; 378 {
497 // vertexes[6].z = pos.Z + vertexes[6].z; 379 isBelow256AboveTerrain = (pos.Z < ((float)hm[(int)pos.X, (int)pos.Y] + 256f));
380 }
381 catch (Exception)
382 {
383 }
498 384
499 FaceB[2] = vertexes[6]; 385 if (isBelow256AboveTerrain)
500 FaceA[3] = vertexes[6]; 386 {
501 FaceB[4] = vertexes[6]; 387 // Translate scale by rotation so scale is represented properly when object is rotated
388 Vector3 lscale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z);
389 Vector3 scale = new Vector3();
390 Vector3 tScale = new Vector3();
391 Vector3 axPos = new Vector3(pos.X,pos.Y,pos.Z);
392
393 Quaternion llrot = part.GetWorldRotation();
394 Quaternion rot = new Quaternion(llrot.W, llrot.X, llrot.Y, llrot.Z);
395 scale = lscale * rot;
396
397 // negative scales don't work in this situation
398 scale.X = Math.Abs(scale.X);
399 scale.Y = Math.Abs(scale.Y);
400 scale.Z = Math.Abs(scale.Z);
401
402 // This scaling isn't very accurate and doesn't take into account the face rotation :P
403 int mapdrawstartX = (int)(pos.X - scale.X);
404 int mapdrawstartY = (int)(pos.Y - scale.Y);
405 int mapdrawendX = (int)(pos.X + scale.X);
406 int mapdrawendY = (int)(pos.Y + scale.Y);
407
408 // If object is beyond the edge of the map, don't draw it to avoid errors
409 if (mapdrawstartX < 0 || mapdrawstartX > ((int)Constants.RegionSize - 1) || mapdrawendX < 0 || mapdrawendX > ((int)Constants.RegionSize - 1)
410 || mapdrawstartY < 0 || mapdrawstartY > ((int)Constants.RegionSize - 1) || mapdrawendY < 0
411 || mapdrawendY > ((int)Constants.RegionSize - 1))
412 continue;
413
414 #region obb face reconstruction part duex
415 Vector3[] vertexes = new Vector3[8];
416
417 // float[] distance = new float[6];
418 Vector3[] FaceA = new Vector3[6]; // vertex A for Facei
419 Vector3[] FaceB = new Vector3[6]; // vertex B for Facei
420 Vector3[] FaceC = new Vector3[6]; // vertex C for Facei
421 Vector3[] FaceD = new Vector3[6]; // vertex D for Facei
422
423 tScale = new Vector3(lscale.X, -lscale.Y, lscale.Z);
424 scale = ((tScale * rot));
425 vertexes[0] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
426 // vertexes[0].x = pos.X + vertexes[0].x;
427 //vertexes[0].y = pos.Y + vertexes[0].y;
428 //vertexes[0].z = pos.Z + vertexes[0].z;
429
430 FaceA[0] = vertexes[0];
431 FaceB[3] = vertexes[0];
432 FaceA[4] = vertexes[0];
433
434 tScale = lscale;
435 scale = ((tScale * rot));
436 vertexes[1] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
437
438 // vertexes[1].x = pos.X + vertexes[1].x;
439 // vertexes[1].y = pos.Y + vertexes[1].y;
440 //vertexes[1].z = pos.Z + vertexes[1].z;
441
442 FaceB[0] = vertexes[1];
443 FaceA[1] = vertexes[1];
444 FaceC[4] = vertexes[1];
445
446 tScale = new Vector3(lscale.X, -lscale.Y, -lscale.Z);
447 scale = ((tScale * rot));
448
449 vertexes[2] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
450
451 //vertexes[2].x = pos.X + vertexes[2].x;
452 //vertexes[2].y = pos.Y + vertexes[2].y;
453 //vertexes[2].z = pos.Z + vertexes[2].z;
454
455 FaceC[0] = vertexes[2];
456 FaceD[3] = vertexes[2];
457 FaceC[5] = vertexes[2];
458
459 tScale = new Vector3(lscale.X, lscale.Y, -lscale.Z);
460 scale = ((tScale * rot));
461 vertexes[3] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
462
463 //vertexes[3].x = pos.X + vertexes[3].x;
464 // vertexes[3].y = pos.Y + vertexes[3].y;
465 // vertexes[3].z = pos.Z + vertexes[3].z;
466
467 FaceD[0] = vertexes[3];
468 FaceC[1] = vertexes[3];
469 FaceA[5] = vertexes[3];
470
471 tScale = new Vector3(-lscale.X, lscale.Y, lscale.Z);
472 scale = ((tScale * rot));
473 vertexes[4] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
474
475 // vertexes[4].x = pos.X + vertexes[4].x;
476 // vertexes[4].y = pos.Y + vertexes[4].y;
477 // vertexes[4].z = pos.Z + vertexes[4].z;
478
479 FaceB[1] = vertexes[4];
480 FaceA[2] = vertexes[4];
481 FaceD[4] = vertexes[4];
482
483 tScale = new Vector3(-lscale.X, lscale.Y, -lscale.Z);
484 scale = ((tScale * rot));
485 vertexes[5] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
486
487 // vertexes[5].x = pos.X + vertexes[5].x;
488 // vertexes[5].y = pos.Y + vertexes[5].y;
489 // vertexes[5].z = pos.Z + vertexes[5].z;
490
491 FaceD[1] = vertexes[5];
492 FaceC[2] = vertexes[5];
493 FaceB[5] = vertexes[5];
494
495 tScale = new Vector3(-lscale.X, -lscale.Y, lscale.Z);
496 scale = ((tScale * rot));
497 vertexes[6] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
498
499 // vertexes[6].x = pos.X + vertexes[6].x;
500 // vertexes[6].y = pos.Y + vertexes[6].y;
501 // vertexes[6].z = pos.Z + vertexes[6].z;
502
503 FaceB[2] = vertexes[6];
504 FaceA[3] = vertexes[6];
505 FaceB[4] = vertexes[6];
502 506
503 tScale = new Vector3(-lscale.X, -lscale.Y, -lscale.Z); 507 tScale = new Vector3(-lscale.X, -lscale.Y, -lscale.Z);
504 scale = ((tScale * rot)); 508 scale = ((tScale * rot));
505 vertexes[7] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); 509 vertexes[7] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
506 510
507 // vertexes[7].x = pos.X + vertexes[7].x; 511 // vertexes[7].x = pos.X + vertexes[7].x;
508 // vertexes[7].y = pos.Y + vertexes[7].y; 512 // vertexes[7].y = pos.Y + vertexes[7].y;
509 // vertexes[7].z = pos.Z + vertexes[7].z; 513 // vertexes[7].z = pos.Z + vertexes[7].z;
510 514
511 FaceD[2] = vertexes[7]; 515 FaceD[2] = vertexes[7];
512 FaceC[3] = vertexes[7]; 516 FaceC[3] = vertexes[7];
513 FaceD[5] = vertexes[7]; 517 FaceD[5] = vertexes[7];
514#endregion 518 #endregion
515 519
516 //int wy = 0; 520 //int wy = 0;
517 521
518 //bool breakYN = false; // If we run into an error drawing, break out of the 522 //bool breakYN = false; // If we run into an error drawing, break out of the
519 // loop so we don't lag to death on error handling 523 // loop so we don't lag to death on error handling
520 DrawStruct ds = new DrawStruct(); 524 DrawStruct ds = new DrawStruct();
521 ds.brush = new SolidBrush(mapdotspot); 525 ds.brush = new SolidBrush(mapdotspot);
522 //ds.rect = new Rectangle(mapdrawstartX, (255 - mapdrawstartY), mapdrawendX - mapdrawstartX, mapdrawendY - mapdrawstartY); 526 //ds.rect = new Rectangle(mapdrawstartX, (255 - mapdrawstartY), mapdrawendX - mapdrawstartX, mapdrawendY - mapdrawstartY);
523 527
524 ds.trns = new face[FaceA.Length]; 528 ds.trns = new face[FaceA.Length];
525 529
526 for (int i = 0; i < FaceA.Length; i++) 530 for (int i = 0; i < FaceA.Length; i++)
527 { 531 {
528 Point[] working = new Point[5]; 532 Point[] working = new Point[5];
529 working[0] = project(FaceA[i], axPos); 533 working[0] = project(FaceA[i], axPos);
530 working[1] = project(FaceB[i], axPos); 534 working[1] = project(FaceB[i], axPos);
531 working[2] = project(FaceD[i], axPos); 535 working[2] = project(FaceD[i], axPos);
532 working[3] = project(FaceC[i], axPos); 536 working[3] = project(FaceC[i], axPos);
533 working[4] = project(FaceA[i], axPos); 537 working[4] = project(FaceA[i], axPos);
534 538
535 face workingface = new face(); 539 face workingface = new face();
536 workingface.pts = working; 540 workingface.pts = working;
537 541
538 ds.trns[i] = workingface; 542 ds.trns[i] = workingface;
539 } 543 }
540 544
541 z_sort.Add(part.LocalId, ds); 545 z_sort.Add(part.LocalId, ds);
542 z_localIDs.Add(part.LocalId); 546 z_localIDs.Add(part.LocalId);
543 z_sortheights.Add(pos.Z); 547 z_sortheights.Add(pos.Z);
544 548
545 //for (int wx = mapdrawstartX; wx < mapdrawendX; wx++) 549 //for (int wx = mapdrawstartX; wx < mapdrawendX; wx++)
546 //{
547 //for (wy = mapdrawstartY; wy < mapdrawendY; wy++)
548 //{ 550 //{
549 //m_log.InfoFormat("[MAPDEBUG]: {0},{1}({2})", wx, (255 - wy),wy); 551 //for (wy = mapdrawstartY; wy < mapdrawendY; wy++)
550 //try
551 //{
552 // Remember, flip the y!
553 // mapbmp.SetPixel(wx, (255 - wy), mapdotspot);
554 //}
555 //catch (ArgumentException)
556 //{ 552 //{
557 // breakYN = true; 553 //m_log.InfoFormat("[MAPDEBUG]: {0},{1}({2})", wx, (255 - wy),wy);
554 //try
555 //{
556 // Remember, flip the y!
557 // mapbmp.SetPixel(wx, (255 - wy), mapdotspot);
558 //}
559 //catch (ArgumentException)
560 //{
561 // breakYN = true;
562 //}
563
564 //if (breakYN)
565 // break;
558 //} 566 //}
559 567
560 //if (breakYN) 568 //if (breakYN)
561 // break; 569 // break;
562 //} 570 //}
571 } // Object is within 256m Z of terrain
572 } // object is at least a meter wide
573 } // loop over group children
574 } // entitybase is sceneobject group
575 } // foreach loop over entities
563 576
564 //if (breakYN) 577 float[] sortedZHeights = z_sortheights.ToArray();
565 // break; 578 uint[] sortedlocalIds = z_localIDs.ToArray();
566 //}
567 } // Object is within 256m Z of terrain
568 } // object is at least a meter wide
569 } // loop over group children
570 } // entitybase is sceneobject group
571 } // foreach loop over entities
572
573 float[] sortedZHeights = z_sortheights.ToArray();
574 uint[] sortedlocalIds = z_localIDs.ToArray();
575
576 // Sort prim by Z position
577 Array.Sort(sortedZHeights, sortedlocalIds);
578 579
579 Graphics g = Graphics.FromImage(mapbmp); 580 // Sort prim by Z position
581 Array.Sort(sortedZHeights, sortedlocalIds);
580 582
581 for (int s = 0; s < sortedZHeights.Length; s++) 583 using (Graphics g = Graphics.FromImage(mapbmp))
582 {
583 if (z_sort.ContainsKey(sortedlocalIds[s]))
584 { 584 {
585 DrawStruct rectDrawStruct = z_sort[sortedlocalIds[s]]; 585 for (int s = 0; s < sortedZHeights.Length; s++)
586 for (int r = 0; r < rectDrawStruct.trns.Length; r++)
587 { 586 {
588 g.FillPolygon(rectDrawStruct.brush,rectDrawStruct.trns[r].pts); 587 if (z_sort.ContainsKey(sortedlocalIds[s]))
588 {
589 DrawStruct rectDrawStruct = z_sort[sortedlocalIds[s]];
590 for (int r = 0; r < rectDrawStruct.trns.Length; r++)
591 {
592 g.FillPolygon(rectDrawStruct.brush,rectDrawStruct.trns[r].pts);
593 }
594 //g.FillRectangle(rectDrawStruct.brush , rectDrawStruct.rect);
595 }
589 } 596 }
590 //g.FillRectangle(rectDrawStruct.brush , rectDrawStruct.rect);
591 } 597 }
592 } 598 } // lock entities objs
593 599
594 g.Dispose(); 600 }
595 } // lock entities objs 601 finally
602 {
603 foreach (DrawStruct ds in z_sort.Values)
604 ds.brush.Dispose();
605 }
596 606
597 m_log.Debug("[MAPTILE]: Generating Maptile Step 2: Done in " + (Environment.TickCount - tc) + " ms"); 607 m_log.Debug("[MAPTILE]: Generating Maptile Step 2: Done in " + (Environment.TickCount - tc) + " ms");
608
598 return mapbmp; 609 return mapbmp;
599 } 610 }
600 611
diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs b/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs
index 992bff3..cb06fd4 100644
--- a/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs
+++ b/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs
@@ -54,7 +54,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
54 public void TerrainToBitmap(Bitmap mapbmp) 54 public void TerrainToBitmap(Bitmap mapbmp)
55 { 55 {
56 int tc = Environment.TickCount; 56 int tc = Environment.TickCount;
57 m_log.Debug("[MAPTILE]: Generating Maptile Step 1: Terrain"); 57 m_log.Debug("[SHADED MAP TILE RENDERER]: Generating Maptile Step 1: Terrain");
58 58
59 double[,] hm = m_scene.Heightmap.GetDoubles(); 59 double[,] hm = m_scene.Heightmap.GetDoubles();
60 bool ShadowDebugContinue = true; 60 bool ShadowDebugContinue = true;
@@ -199,7 +199,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
199 { 199 {
200 if (!terraincorruptedwarningsaid) 200 if (!terraincorruptedwarningsaid)
201 { 201 {
202 m_log.WarnFormat("[MAPIMAGE]: Your terrain is corrupted in region {0}, it might take a few minutes to generate the map image depending on the corruption level", m_scene.RegionInfo.RegionName); 202 m_log.WarnFormat("[SHADED MAP TILE RENDERER]: Your terrain is corrupted in region {0}, it might take a few minutes to generate the map image depending on the corruption level", m_scene.RegionInfo.RegionName);
203 terraincorruptedwarningsaid = true; 203 terraincorruptedwarningsaid = true;
204 } 204 }
205 color = Color.Black; 205 color = Color.Black;
@@ -229,7 +229,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
229 { 229 {
230 if (!terraincorruptedwarningsaid) 230 if (!terraincorruptedwarningsaid)
231 { 231 {
232 m_log.WarnFormat("[MAPIMAGE]: Your terrain is corrupted in region {0}, it might take a few minutes to generate the map image depending on the corruption level", m_scene.RegionInfo.RegionName); 232 m_log.WarnFormat("[SHADED MAP TILE RENDERER]: Your terrain is corrupted in region {0}, it might take a few minutes to generate the map image depending on the corruption level", m_scene.RegionInfo.RegionName);
233 terraincorruptedwarningsaid = true; 233 terraincorruptedwarningsaid = true;
234 } 234 }
235 Color black = Color.Black; 235 Color black = Color.Black;
@@ -238,7 +238,8 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
238 } 238 }
239 } 239 }
240 } 240 }
241 m_log.Debug("[MAPTILE]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms"); 241
242 m_log.Debug("[SHADED MAP TILE RENDERER]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms");
242 } 243 }
243 } 244 }
244} 245} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs b/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs
index d13c2ef..e895178 100644
--- a/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs
+++ b/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs
@@ -173,7 +173,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
173 private Bitmap fetchTexture(UUID id) 173 private Bitmap fetchTexture(UUID id)
174 { 174 {
175 AssetBase asset = m_scene.AssetService.Get(id.ToString()); 175 AssetBase asset = m_scene.AssetService.Get(id.ToString());
176 m_log.DebugFormat("[TexturedMapTileRenderer]: Fetched texture {0}, found: {1}", id, asset != null); 176 m_log.DebugFormat("[TEXTURED MAP TILE RENDERER]: Fetched texture {0}, found: {1}", id, asset != null);
177 if (asset == null) return null; 177 if (asset == null) return null;
178 178
179 ManagedImage managedImage; 179 ManagedImage managedImage;
@@ -188,17 +188,17 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
188 } 188 }
189 catch (DllNotFoundException) 189 catch (DllNotFoundException)
190 { 190 {
191 m_log.ErrorFormat("[TexturedMapTileRenderer]: OpenJpeg is not installed correctly on this system. Asset Data is empty for {0}", id); 191 m_log.ErrorFormat("[TEXTURED MAP TILE RENDERER]: OpenJpeg is not installed correctly on this system. Asset Data is empty for {0}", id);
192 192
193 } 193 }
194 catch (IndexOutOfRangeException) 194 catch (IndexOutOfRangeException)
195 { 195 {
196 m_log.ErrorFormat("[TexturedMapTileRenderer]: OpenJpeg was unable to encode this. Asset Data is empty for {0}", id); 196 m_log.ErrorFormat("[TEXTURED MAP TILE RENDERER]: OpenJpeg was unable to encode this. Asset Data is empty for {0}", id);
197 197
198 } 198 }
199 catch (Exception) 199 catch (Exception)
200 { 200 {
201 m_log.ErrorFormat("[TexturedMapTileRenderer]: OpenJpeg was unable to encode this. Asset Data is empty for {0}", id); 201 m_log.ErrorFormat("[TEXTURED MAP TILE RENDERER]: OpenJpeg was unable to encode this. Asset Data is empty for {0}", id);
202 202
203 } 203 }
204 return null; 204 return null;
@@ -233,10 +233,14 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
233 if (textureID == UUID.Zero) return defaultColor; // not set 233 if (textureID == UUID.Zero) return defaultColor; // not set
234 if (m_mapping.ContainsKey(textureID)) return m_mapping[textureID]; // one of the predefined textures 234 if (m_mapping.ContainsKey(textureID)) return m_mapping[textureID]; // one of the predefined textures
235 235
236 Bitmap bmp = fetchTexture(textureID); 236 Color color;
237 Color color = bmp == null ? defaultColor : computeAverageColor(bmp); 237
238 // store it for future reference 238 using (Bitmap bmp = fetchTexture(textureID))
239 m_mapping[textureID] = color; 239 {
240 color = bmp == null ? defaultColor : computeAverageColor(bmp);
241 // store it for future reference
242 m_mapping[textureID] = color;
243 }
240 244
241 return color; 245 return color;
242 } 246 }
@@ -278,7 +282,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
278 public void TerrainToBitmap(Bitmap mapbmp) 282 public void TerrainToBitmap(Bitmap mapbmp)
279 { 283 {
280 int tc = Environment.TickCount; 284 int tc = Environment.TickCount;
281 m_log.Debug("[MAPTILE]: Generating Maptile Step 1: Terrain"); 285 m_log.Debug("[TEXTURED MAP TILE RENDERER]: Generating Maptile Step 1: Terrain");
282 286
283 // These textures should be in the AssetCache anyway, as every client conneting to this 287 // These textures should be in the AssetCache anyway, as every client conneting to this
284 // region needs them. Except on start, when the map is recreated (before anyone connected), 288 // region needs them. Except on start, when the map is recreated (before anyone connected),
@@ -412,7 +416,8 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap
412 } 416 }
413 } 417 }
414 } 418 }
415 m_log.Debug("[MAPTILE]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms"); 419
420 m_log.Debug("[TEXTURED MAP TILE RENDERER]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms");
416 } 421 }
417 } 422 }
418} 423} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
index 88761a2..cf2ef29 100644
--- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
+++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs
@@ -1520,62 +1520,69 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
1520 1520
1521 private Byte[] GenerateOverlay() 1521 private Byte[] GenerateOverlay()
1522 { 1522 {
1523 Bitmap overlay = new Bitmap(256, 256); 1523 using (Bitmap overlay = new Bitmap(256, 256))
1524
1525 bool[,] saleBitmap = new bool[64, 64];
1526 for (int x = 0 ; x < 64 ; x++)
1527 { 1524 {
1528 for (int y = 0 ; y < 64 ; y++) 1525 bool[,] saleBitmap = new bool[64, 64];
1529 saleBitmap[x, y] = false; 1526 for (int x = 0 ; x < 64 ; x++)
1530 } 1527 {
1531 1528 for (int y = 0 ; y < 64 ; y++)
1532 bool landForSale = false; 1529 saleBitmap[x, y] = false;
1530 }
1533 1531
1534 List<ILandObject> parcels = m_scene.LandChannel.AllParcels(); 1532 bool landForSale = false;
1535 1533
1536 Color background = Color.FromArgb(0, 0, 0, 0); 1534 List<ILandObject> parcels = m_scene.LandChannel.AllParcels();
1537 SolidBrush transparent = new SolidBrush(background);
1538 Graphics g = Graphics.FromImage(overlay);
1539 g.FillRectangle(transparent, 0, 0, 256, 256);
1540 1535
1541 SolidBrush yellow = new SolidBrush(Color.FromArgb(255, 249, 223, 9)); 1536 Color background = Color.FromArgb(0, 0, 0, 0);
1542 1537
1543 foreach (ILandObject land in parcels) 1538 using (Graphics g = Graphics.FromImage(overlay))
1544 {
1545 // m_log.DebugFormat("[WORLD MAP]: Parcel {0} flags {1}", land.LandData.Name, land.LandData.Flags);
1546 if ((land.LandData.Flags & (uint)ParcelFlags.ForSale) != 0)
1547 { 1539 {
1548 landForSale = true; 1540 using (SolidBrush transparent = new SolidBrush(background))
1541 g.FillRectangle(transparent, 0, 0, 256, 256);
1549 1542
1550 saleBitmap = land.MergeLandBitmaps(saleBitmap, land.GetLandBitmap());
1551 }
1552 }
1553 1543
1554 if (!landForSale) 1544 foreach (ILandObject land in parcels)
1555 { 1545 {
1556 m_log.DebugFormat("[WORLD MAP]: Region {0} has no parcels for sale, not generating overlay", m_scene.RegionInfo.RegionName); 1546 // m_log.DebugFormat("[WORLD MAP]: Parcel {0} flags {1}", land.LandData.Name, land.LandData.Flags);
1557 return null; 1547 if ((land.LandData.Flags & (uint)ParcelFlags.ForSale) != 0)
1558 } 1548 {
1549 landForSale = true;
1559 1550
1560 m_log.DebugFormat("[WORLD MAP]: Region {0} has parcels for sale, generating overlay", m_scene.RegionInfo.RegionName); 1551 saleBitmap = land.MergeLandBitmaps(saleBitmap, land.GetLandBitmap());
1552 }
1553 }
1561 1554
1562 for (int x = 0 ; x < 64 ; x++) 1555 if (!landForSale)
1563 { 1556 {
1564 for (int y = 0 ; y < 64 ; y++) 1557 m_log.DebugFormat("[WORLD MAP]: Region {0} has no parcels for sale, not generating overlay", m_scene.RegionInfo.RegionName);
1558 return null;
1559 }
1560
1561 m_log.DebugFormat("[WORLD MAP]: Region {0} has parcels for sale, generating overlay", m_scene.RegionInfo.RegionName);
1562
1563 using (SolidBrush yellow = new SolidBrush(Color.FromArgb(255, 249, 223, 9)))
1564 {
1565 for (int x = 0 ; x < 64 ; x++)
1566 {
1567 for (int y = 0 ; y < 64 ; y++)
1568 {
1569 if (saleBitmap[x, y])
1570 g.FillRectangle(yellow, x * 4, 252 - (y * 4), 4, 4);
1571 }
1572 }
1573 }
1574 }
1575
1576 try
1577 {
1578 return OpenJPEG.EncodeFromImage(overlay, true);
1579 }
1580 catch (Exception e)
1565 { 1581 {
1566 if (saleBitmap[x, y]) 1582 m_log.DebugFormat("[WORLD MAP]: Error creating parcel overlay: " + e.ToString());
1567 g.FillRectangle(yellow, x * 4, 252 - (y * 4), 4, 4);
1568 } 1583 }
1569 } 1584 }
1570 1585
1571 try
1572 {
1573 return OpenJPEG.EncodeFromImage(overlay, true);
1574 }
1575 catch (Exception e)
1576 {
1577 m_log.DebugFormat("[WORLD MAP]: Error creating parcel overlay: " + e.ToString());
1578 }
1579 return null; 1586 return null;
1580 } 1587 }
1581 } 1588 }