aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/Framework/Scenes/CollisionSounds.cs90
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs45
2 files changed, 89 insertions, 46 deletions
diff --git a/OpenSim/Region/Framework/Scenes/CollisionSounds.cs b/OpenSim/Region/Framework/Scenes/CollisionSounds.cs
index 724ecb6..1f43843 100644
--- a/OpenSim/Region/Framework/Scenes/CollisionSounds.cs
+++ b/OpenSim/Region/Framework/Scenes/CollisionSounds.cs
@@ -114,12 +114,9 @@ namespace OpenSim.Region.Framework.Scenes
114 snd_StoneRubber, snd_MetalRubber, snd_GlassRubber, snd_WoodRubber, snd_FleshRubber, snd_PlasticRubber, snd_RubberRubber 114 snd_StoneRubber, snd_MetalRubber, snd_GlassRubber, snd_WoodRubber, snd_FleshRubber, snd_PlasticRubber, snd_RubberRubber
115 }; 115 };
116 116
117 public static void PartCollisionSound(SceneObjectPart part,List<uint> Colliders) 117 public static void PartCollisionSound(SceneObjectPart part, List<CollisionForSoundInfo> collidersinfolist)
118 { 118 {
119 // temporary mute sounds 119 if (collidersinfolist.Count == 0 || part == null)
120// return;
121
122 if(Colliders.Count == 0 || part == null)
123 return; 120 return;
124 121
125 if (part.VolumeDetectActive || (part.Flags & PrimFlags.Physics) == 0) 122 if (part.VolumeDetectActive || (part.Flags & PrimFlags.Physics) == 0)
@@ -128,19 +125,20 @@ namespace OpenSim.Region.Framework.Scenes
128 if (part.ParentGroup == null) 125 if (part.ParentGroup == null)
129 return; 126 return;
130 127
131 if (part.CollisionSound == part.invalidCollisionSoundUUID) 128 UUID soundID = part.CollisionSound;
129 if (soundID == part.invalidCollisionSoundUUID)
132 return; 130 return;
133 131
134 UUID soundID; 132 float volume = 0.0f;
135 int otherMaterial; 133 int otherMaterial;
134 bool HaveSound = false;
136 135
137 Vector3 position = part.AbsolutePosition; 136 if (soundID != UUID.Zero)
138
139 if (part.CollisionSound != UUID.Zero)
140 { 137 {
141 if (part.CollisionSoundVolume > 0.0f) 138 volume = part.CollisionSoundVolume;
142 part.SendCollisionSound(part.CollisionSound, part.CollisionSoundVolume, position); 139 if (volume == 0.0f)
143 return; 140 return;
141 HaveSound = true;
144 } 142 }
145 143
146 int thisMaterial = (int) part.Material; 144 int thisMaterial = (int) part.Material;
@@ -152,41 +150,73 @@ namespace OpenSim.Region.Framework.Scenes
152 150
153 bool doneownsound = false; 151 bool doneownsound = false;
154 152
155 foreach (uint Id in Colliders) 153 CollisionForSoundInfo colInfo;
154 uint id;
155
156 for(int i = 0; i< collidersinfolist.Count; i++)
156 { 157 {
157 if (Id == 0) 158 colInfo = collidersinfolist[i];
159
160 if (!HaveSound)
161 {
162 volume = Math.Abs(colInfo.relativeVel);
163 if (volume < 0.2f)
164 continue;
165 }
166
167 id = colInfo.colliderID;
168 if (id == 0)
158 { 169 {
159 if (!doneownsound) 170 if (!doneownsound)
160 { 171 {
161 soundID = m_TerrainPart[thisMaterial]; 172 if (!HaveSound)
162 part.SendCollisionSound(soundID, 1.0, position); 173 {
174 volume *= volume * .0625f; // 4m/s == full volume
175 if (volume > 1.0f)
176 volume = 1.0f;
177 soundID = m_TerrainPart[thisMaterial];
178 }
179 part.SendCollisionSound(soundID, volume, colInfo.position);
163 doneownsound = true; 180 doneownsound = true;
164 } 181 }
165 continue; 182 continue;
166 } 183 }
167 184
168 SceneObjectPart otherPart = part.ParentGroup.Scene.GetSceneObjectPart(Id); 185 SceneObjectPart otherPart = part.ParentGroup.Scene.GetSceneObjectPart(id);
169 if (otherPart != null) 186 if (otherPart != null)
170 { 187 {
171 if (otherPart.CollisionSound == part.invalidCollisionSoundUUID || otherPart.VolumeDetectActive) 188 if (otherPart.CollisionSound == part.invalidCollisionSoundUUID || otherPart.VolumeDetectActive)
172 continue; 189 continue;
173 if (otherPart.CollisionSound != UUID.Zero) 190
174 otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, position); 191 if (!HaveSound)
175 else
176 { 192 {
177 otherMaterial = (int)otherPart.Material; 193 if (otherPart.CollisionSound != UUID.Zero)
178 if (otherMaterial >= MaxMaterials) 194 {
179 otherMaterial = 3; 195 soundID = otherPart.CollisionSound;
180 index = thisMatScaled + otherMaterial; 196 volume = otherPart.CollisionSoundVolume;
181 soundID = m_PartPart[index]; 197 if (volume == 0.0f)
182 if (doneownsound) 198 continue;
183 otherPart.SendCollisionSound(soundID, 1.0, position); 199 }
184 else 200 else
185 { 201 {
186 part.SendCollisionSound(soundID, 1.0, position); 202 volume *= volume * .0625f; // 4m/s == full volume
187 doneownsound = true; 203 if (volume > 1.0f)
204 volume = 1.0f;
205 otherMaterial = (int)otherPart.Material;
206 if (otherMaterial >= MaxMaterials)
207 otherMaterial = 3;
208 index = thisMatScaled + otherMaterial;
209 soundID = m_PartPart[index];
188 } 210 }
189 } 211 }
212
213 if (doneownsound)
214 otherPart.SendCollisionSound(soundID, volume, colInfo.position);
215 else
216 {
217 part.SendCollisionSound(soundID, volume, colInfo.position);
218 doneownsound = true;
219 }
190 } 220 }
191 } 221 }
192 } 222 }
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index b5705b7..467b625 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -333,7 +333,7 @@ namespace OpenSim.Region.Framework.Scenes
333 private UUID m_collisionSound; 333 private UUID m_collisionSound;
334 private float m_collisionSoundVolume; 334 private float m_collisionSoundVolume;
335 335
336 private DateTime LastColSoundSentTime; 336 private int LastColSoundSentTime;
337 337
338 338
339 private SOPVehicle m_vehicle = null; 339 private SOPVehicle m_vehicle = null;
@@ -374,7 +374,7 @@ namespace OpenSim.Region.Framework.Scenes
374 // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from 374 // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from
375 // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log 375 // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log
376 m_inventory = new SceneObjectPartInventory(this); 376 m_inventory = new SceneObjectPartInventory(this);
377 LastColSoundSentTime = DateTime.UtcNow; 377 LastColSoundSentTime = Util.EnvironmentTickCount();
378 } 378 }
379 379
380 /// <summary> 380 /// <summary>
@@ -2632,13 +2632,29 @@ namespace OpenSim.Region.Framework.Scenes
2632 2632
2633 else 2633 else
2634 { 2634 {
2635 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
2636 CollisionForSoundInfo soundinfo;
2637 ContactPoint curcontact;
2638
2635 // calculate things that started colliding this time 2639 // calculate things that started colliding this time
2636 // and build up list of colliders this time 2640 // and build up list of colliders this time
2637 foreach (uint localid in collissionswith.Keys) 2641 foreach (uint id in collissionswith.Keys)
2638 { 2642 {
2639 thisHitColliders.Add(localid); 2643 thisHitColliders.Add(id);
2640 if (!m_lastColliders.Contains(localid)) 2644 if (!m_lastColliders.Contains(id))
2641 startedColliders.Add(localid); 2645 {
2646 startedColliders.Add(id);
2647
2648 curcontact = collissionswith[id];
2649 if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
2650 {
2651 soundinfo = new CollisionForSoundInfo();
2652 soundinfo.colliderID = id;
2653 soundinfo.position = curcontact.Position;
2654 soundinfo.relativeVel = curcontact.RelativeSpeed;
2655 soundinfolist.Add(soundinfo);
2656 }
2657 }
2642 } 2658 }
2643 2659
2644 // calculate things that ended colliding 2660 // calculate things that ended colliding
@@ -2655,17 +2671,14 @@ namespace OpenSim.Region.Framework.Scenes
2655 // remove things that ended colliding from the last colliders list 2671 // remove things that ended colliding from the last colliders list
2656 foreach (uint localID in endedColliders) 2672 foreach (uint localID in endedColliders)
2657 m_lastColliders.Remove(localID); 2673 m_lastColliders.Remove(localID);
2658 }
2659
2660 // play the sound.
2661 2674
2662 bool IsNotVolumeDtc = !VolumeDetectActive; 2675 // play sounds.
2663 2676 if (soundinfolist.Count > 0 && !VolumeDetectActive && CollisionSound != invalidCollisionSoundUUID)
2664 if (IsNotVolumeDtc && startedColliders.Count > 0 && CollisionSound != invalidCollisionSoundUUID) 2677 CollisionSounds.PartCollisionSound(this, soundinfolist);
2665 CollisionSounds.PartCollisionSound(this, startedColliders); 2678 }
2666 2679
2667 SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart); 2680 SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart);
2668 if (IsNotVolumeDtc) 2681 if (!VolumeDetectActive)
2669 SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding); 2682 SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding);
2670 SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd); 2683 SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd);
2671 2684
@@ -3210,8 +3223,8 @@ namespace OpenSim.Region.Framework.Scenes
3210 if (volume < 0) 3223 if (volume < 0)
3211 volume = 0; 3224 volume = 0;
3212 3225
3213 DateTime now = DateTime.UtcNow; 3226 int now = Util.EnvironmentTickCount();
3214 if((now - LastColSoundSentTime).Milliseconds < 200) // reduce rate to 5 per sec per part ?? 3227 if(Util.EnvironmentTickCountSubtract(now,LastColSoundSentTime) <200)
3215 return; 3228 return;
3216 3229
3217 LastColSoundSentTime = now; 3230 LastColSoundSentTime = now;