From aad0c3c60e90536aa5bafcd861fd8d41dcc0552a Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 14 Aug 2022 00:23:16 +0100 Subject: [PATCH] map image service: always try to delete a map tile, before saving a new one; ubode cosmetics that where on disk" --- .../PhysicsModules/ubOde/ODECharacter.cs | 10 +- .../Region/PhysicsModules/ubOde/ODEPrim.cs | 4 +- .../Region/PhysicsModules/ubOde/ODEScene.cs | 154 +++++++++--------- .../MapImageService/MapImageService.cs | 24 +-- 4 files changed, 91 insertions(+), 101 deletions(-) diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs b/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs index f57583dc0e..e6eebab663 100644 --- a/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs +++ b/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs @@ -850,7 +850,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde AvaAvaSizeYsq = 0.5f * sy; AvaAvaSizeYsq *= AvaAvaSizeYsq; - m_parent_scene.waitForSpaceUnlock(m_parent_scene.CharsSpace); + //m_parent_scene.waitForSpaceUnlock(m_parent_scene.CharsSpace); //collider = SafeNativeMethods.SimpleSpaceCreate(m_parent_scene.CharsSpace); //SafeNativeMethods.SpaceSetSublevel(collider, 0); @@ -962,7 +962,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde if (capsule != IntPtr.Zero) { m_parent_scene.actor_name_map.Remove(capsule); - m_parent_scene.waitForSpaceUnlock(collider); + //m_parent_scene.waitForSpaceUnlock(collider); SafeNativeMethods.GeomDestroy(capsule); capsule = IntPtr.Zero; } @@ -976,7 +976,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde if (collider != IntPtr.Zero) { m_parent_scene.actor_name_map.Remove(collider); - m_parent_scene.waitForSpaceUnlock(m_parent_scene.CharsSpace); + //m_parent_scene.waitForSpaceUnlock(m_parent_scene.CharsSpace); SafeNativeMethods.GeomDestroy(collider); collider = IntPtr.Zero; } @@ -992,13 +992,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde x = tx * cos - y * sin; y = tx * sin + y * cos; } - public void RotateXYonZ(ref float x, ref float y, ref float sin, ref float cos) + public void RotateXYonZ(ref float x, ref float y, float sin, float cos) { float tx = x; x = tx * cos - y * sin; y = tx * sin + y * cos; } - public void invRotateXYonZ(ref float x, ref float y, ref float sin, ref float cos) + public void invRotateXYonZ(ref float x, ref float y, float sin, float cos) { float tx = x; x = tx * cos + y * sin; diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs index 75909430cb..95adeec483 100644 --- a/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs +++ b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs @@ -2008,7 +2008,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde if (m_targetSpace != IntPtr.Zero) { - m_parentScene.waitForSpaceUnlock(m_targetSpace); + //m_parentScene.waitForSpaceUnlock(m_targetSpace); if (SafeNativeMethods.SpaceQuery(m_targetSpace, m_prim_geom)) SafeNativeMethods.SpaceRemove(m_targetSpace, m_prim_geom); } @@ -2067,7 +2067,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde { if (prmspace != IntPtr.Zero) { - m_parentScene.waitForSpaceUnlock(prmspace); + //m_parentScene.waitForSpaceUnlock(prmspace); if (SafeNativeMethods.SpaceQuery(prmspace, prmgeom)) SafeNativeMethods.SpaceRemove(prmspace, prmgeom); } diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs index 5a09fa5af4..a65803e2fc 100644 --- a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs +++ b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs @@ -222,7 +222,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde private SafeNativeMethods.NearCallback nearCallback; - private readonly Dictionary _prims = new Dictionary(); + private readonly Dictionary _prims = new Dictionary(); private readonly HashSet _characters = new HashSet(); private readonly HashSet _activeprims = new HashSet(); private readonly HashSet _activegroups = new HashSet(); @@ -290,17 +290,17 @@ namespace OpenSim.Region.PhysicsModule.ubOde public ODEMeshWorker m_meshWorker; /* maybe needed if ode uses tls - private void checkThread() - { + private void checkThread() + { - int th = Thread.CurrentThread.ManagedThreadId; - if(th != threadid) - { - threadid = th; - d.AllocateODEDataForThread(~0U); - } - } - */ + int th = Thread.CurrentThread.ManagedThreadId; + if(th != threadid) + { + threadid = th; + d.AllocateODEDataForThread(~0U); + } + } + */ IConfig physicsconfig = null; @@ -528,16 +528,18 @@ namespace OpenSim.Region.PhysicsModule.ubOde (float)m_frameWorkScene.RegionInfo.RegionSettings.WaterHeight); } + /* internal void waitForSpaceUnlock(IntPtr space) { //if (space != IntPtr.Zero) //while (d.SpaceLockQuery(space)) { } // Wait and do nothing } + */ #region Collision Detection // sets a global contact for a joint for contactgeom , and base contact description) - private IntPtr CreateContacJoint(ref SafeNativeMethods.ContactGeomClass contactGeom,bool smooth) + private IntPtr CreateContacJoint(ref SafeNativeMethods.ContactGeomClass contactGeom, bool smooth) { if (m_global_contactcount >= maxContactsbeforedeath) return IntPtr.Zero; @@ -1088,8 +1090,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde { lock(_collisionEventPrimRemove) { - if (_collisionEventPrim.Contains(obj) && !_collisionEventPrimRemove.Contains(obj)) - _collisionEventPrimRemove.Add(obj); + _collisionEventPrimRemove.Add(obj); } } @@ -1119,12 +1120,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde { lock (_characters) { - if (!_characters.Contains(chr)) - { - _characters.Add(chr); - if (chr.bad) - m_log.DebugFormat("[PHYSICS] Added BAD actor {0} to characters list", chr.LocalID); - } + _characters.Add(chr); + if (chr.bad) + m_log.DebugFormat("[PHYSICS] Added BAD actor {0} to characters list", chr.LocalID); } } @@ -1132,10 +1130,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde { lock (_characters) { - if (_characters.Contains(chr)) - { - _characters.Remove(chr); - } + _characters.Remove(chr); } } @@ -1143,8 +1138,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde { lock (_badCharacter) { - if (!_badCharacter.Contains(chr)) - _badCharacter.Add(chr); + _badCharacter.Add(chr); } } @@ -1161,8 +1155,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde // adds active prim.. lock (_activeprims) { - if (!_activeprims.Contains(activatePrim)) - _activeprims.Add(activatePrim); + _activeprims.Add(activatePrim); } } @@ -1170,8 +1163,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde { lock (_activegroups) { - if (!_activegroups.Contains(activatePrim)) - _activegroups.Add(activatePrim); + _activegroups.Add(activatePrim); } } @@ -1248,8 +1240,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde { lock (_prims) { - if(_prims.ContainsKey(id)) - return _prims[id]; + if(_prims.TryGetValue(id, out OdePrim p)) + return p; else return null; } @@ -1265,8 +1257,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde { lock (_prims) { - if(_prims.ContainsKey(oldID)) - _prims.Remove(oldID); + _prims.Remove(oldID); _prims[prim.LocalID] = prim; } } @@ -1315,7 +1306,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde { if (SafeNativeMethods.GeomIsSpace(currentspace)) { - waitForSpaceUnlock(currentspace); + //waitForSpaceUnlock(currentspace); SafeNativeMethods.SpaceRemove(currentspace, geom); if (SafeNativeMethods.SpaceGetSublevel(currentspace) > 2 && SafeNativeMethods.SpaceGetNumGeoms(currentspace) == 0) @@ -1336,7 +1327,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde { if (SafeNativeMethods.GeomIsSpace(currentspace)) { - waitForSpaceUnlock(currentspace); + //waitForSpaceUnlock(currentspace); SafeNativeMethods.SpaceRemove(currentspace, geom); if (SafeNativeMethods.SpaceGetSublevel(currentspace) > 2 && SafeNativeMethods.SpaceGetNumGeoms(currentspace) == 0) @@ -1348,7 +1339,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde } // put the geom in the newspace - waitForSpaceUnlock(StaticSpace); + //waitForSpaceUnlock(StaticSpace); if(SafeNativeMethods.SpaceQuery(StaticSpace, geom)) m_log.Info("[Physics]: 'MoveGeomToStaticSpace' geom already in static space:" + geom); else @@ -2189,14 +2180,16 @@ namespace OpenSim.Region.PhysicsModule.ubOde } }; - ODERayRequest req = new ODERayRequest(); - req.actor = null; - req.callbackMethod = retMethod; - req.length = length; - req.Normal = direction; - req.Origin = position; - req.Count = Count; - req.filter = RayFilterFlags.AllPrims; + ODERayRequest req = new ODERayRequest + { + actor = null, + callbackMethod = retMethod, + length = length, + Normal = direction, + Origin = position, + Count = Count, + filter = RayFilterFlags.AllPrims + }; lock (SyncObject) { @@ -2276,14 +2269,16 @@ namespace OpenSim.Region.PhysicsModule.ubOde } }; - ODERayRequest req = new ODERayRequest(); - req.actor = actor; - req.callbackMethod = retMethod; - req.length = length; - req.Normal = direction; - req.Origin = position; - req.Count = Count; - req.filter = flags; + ODERayRequest req = new ODERayRequest + { + actor = actor, + callbackMethod = retMethod, + length = length, + Normal = direction, + Origin = position, + Count = Count, + filter = flags + }; lock (SyncObject) { @@ -2311,14 +2306,16 @@ namespace OpenSim.Region.PhysicsModule.ubOde } }; - ODERayRequest req = new ODERayRequest(); - req.actor = null; - req.callbackMethod = retMethod; - req.Normal = size; - req.Origin = position; - req.orientation = orientation; - req.Count = Count; - req.filter = flags; + ODERayRequest req = new ODERayRequest + { + actor = null, + callbackMethod = retMethod, + Normal = size, + Origin = position, + orientation = orientation, + Count = Count, + filter = flags + }; lock (SyncObject) { @@ -2343,14 +2340,15 @@ namespace OpenSim.Region.PhysicsModule.ubOde Monitor.PulseAll(SyncObject); }; - ODERayRequest req = new ODERayRequest(); - req.actor = null; - req.callbackMethod = retMethod; - req.length = radius; - req.Origin = position; - req.Count = Count; - req.filter = flags; - + ODERayRequest req = new ODERayRequest + { + actor = null, + callbackMethod = retMethod, + length = radius, + Origin = position, + Count = Count, + filter = flags + }; lock (SyncObject) { @@ -2385,15 +2383,15 @@ namespace OpenSim.Region.PhysicsModule.ubOde Monitor.PulseAll(SyncObject); }; - ODERayRequest req = new ODERayRequest(); - req.actor = null; - req.callbackMethod = retMethod; - req.length = plane.W; - req.Normal.X = plane.X; - req.Normal.Y = plane.Y; - req.Normal.Z = plane.Z; - req.Count = Count; - req.filter = flags; + ODERayRequest req = new ODERayRequest + { + actor = null, + callbackMethod = retMethod, + length = plane.W, + Normal = new Vector3(plane.X, plane.Y, plane.Z), + Count = Count, + filter = flags + }; lock (SyncObject) { diff --git a/OpenSim/Services/MapImageService/MapImageService.cs b/OpenSim/Services/MapImageService/MapImageService.cs index f7a611754b..bb9fb4b918 100644 --- a/OpenSim/Services/MapImageService/MapImageService.cs +++ b/OpenSim/Services/MapImageService/MapImageService.cs @@ -148,7 +148,6 @@ namespace OpenSim.Services.MapImageService } catch (Exception e) { - m_log.WarnFormat("[MAP IMAGE SERVICE]: Unable to save delete file {0}: {1}", fileName, e); reason = e.Message; return false; @@ -157,7 +156,6 @@ namespace OpenSim.Services.MapImageService return UpdateMultiResolutionFiles(x, y, scopeID, out reason); } - // When large varregions start up, they can send piles of new map tiles. This causes // this multi-resolution routine to be called a zillion times an causes much CPU // time to be spent creating multi-resolution tiles that will be replaced when @@ -361,22 +359,16 @@ namespace OpenSim.Services.MapImageService ntiles++; } - // Write the modified output - if (ntiles == 0) - File.Delete(outputFile); - - else + try { - - try - { + File.Delete(outputFile); + if (ntiles > 0) output.Save(outputFile, ImageFormat.Jpeg); - } - catch (Exception e) - { - m_log.WarnFormat("[MAP IMAGE SERVICE]: Oops on saving {0} {1}", outputFile, e); - } - } // Save also as png? + } + catch (Exception e) + { + m_log.WarnFormat("[MAP IMAGE SERVICE]: Oops on saving {0} {1}", outputFile, e); + } output.Dispose(); return true;