public static void PlaySound3D(SoundDefinition sound, BaseVob vob, float range = 3000, float volume = 1.0f) { if (sound == null) { throw new ArgumentNullException("Sound is null!"); } if (vob == null) { throw new ArgumentNullException("Vob is null!"); } if (!CanPlay(sound)) // don't play too many sounds at once { return; } Logger.Log("PlayVobSound: " + sound.Name); var param = zTSound3DParams.Create(); param.Volume = volume; param.Radius = range; param.Reverb = 0.15f; param.IsAmbient = true; int idPtr = Process.Alloc(4).ToInt32(); Process.Write(idPtr, zCSndSys_MSS.PlaySound3D(sound.zSFX, vob.gVob, 0, param)); vobSounds.Add(new ActiveSound(idPtr, param, sound)); }
public static SoundInstance PlaySound(SoundDefinition sound, float volume = 1.0f) { if (sound == null) { throw new ArgumentNullException("Sound is null!"); } return(new SoundInstance(sound, zCSndSys_MSS.PlaySound(sound.zSFX, false, 0, volume, 0))); }
public ActiveSound(int id, zTSound3DParams sndParams, SoundDefinition sfx, zCVob sndVob = null) { this.startTime = GameTime.Ticks; this.idPtr = id; this.sndParams = sndParams; this.sfx = sfx; this.sndVob = sndVob; }
public static SoundInstance PlaySound3D(SoundDefinition sound, Vec3f location, float range = 2500, float volume = 1.0f, bool loop = false) { if (sound == null) { throw new ArgumentNullException("Sound is null!"); } if (!CanPlay(sound)) // don't play too many sounds at once { return(null); } Logger.Log("PlayLocSound: " + sound.Name); var param = zTSound3DParams.Create(); param.Volume = volume; param.Radius = range; param.Reverb = 0.15f; param.LoopType = loop ? 1 : 0; param.IsAmbient = true; zCVob vob; if (sndVobs.Count == 0) { vob = zCVob.Create(); } else { int index = sndVobs.Count - 1; vob = sndVobs[index]; sndVobs.RemoveAt(index); } GothicGlobals.Game.GetWorld().AddVob(vob); vob.TrafoObjToWorld.Position = location.ToArray(); vob.SetPositionWorld(location.X, location.Y, location.Z); int idPtr = Process.Alloc(4).ToInt32(); int id = zCSndSys_MSS.PlaySound3D(sound.zSFX, vob, 0, param); Process.Write(idPtr, id); locSounds.Add(new ActiveSound(idPtr, param, sound, vob)); return(new SoundInstance(sound, id)); }
static bool CanPlay(SoundDefinition sound) { /*for (int i = 0; i < vobSounds.Count; i++) * { * if (vobSounds[i].sfx == sound || vobSounds[i].sfx.zSFX.Address == sound.zSFX.Address) * { * if (GameTime.Ticks - vobSounds[i].startTime < 50 * TimeSpan.TicksPerMillisecond) * return false; * } * } * * for (int i = 0; i < locSounds.Count; i++) * { * if (locSounds[i].sfx == sound || locSounds[i].sfx.zSFX.Address == sound.zSFX.Address) * { * if (GameTime.Ticks - locSounds[i].startTime < 50 * TimeSpan.TicksPerMillisecond) * return false; * } * }*/ return(true); }
internal SoundInstance(SoundDefinition def, int id) { this.id = id; this.def = def; }