mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-04 11:07:12 +02:00
commit 46881727ce4107bf61e12cbbdbfa702381debb93 Author: Pieter-Jan Briers <pieterjan.briers+git@gmail.com> Date: Fri Jun 5 23:27:02 2020 +0200 Fix playing stream storage. commit 4beef7d66e48c7517ec14f21e0a3ce8db1de57c8 Merge:6138c00e3c32f21beaAuthor: Pieter-Jan Briers <pieterjan.briers+git@gmail.com> Date: Fri Jun 5 22:45:11 2020 +0200 Merge branch 'master' into audio commit6138c00e3cAuthor: FL-OZ <anotherscuffed@gmail.com> Date: Fri Jun 5 14:23:52 2020 -0500 refine audiosystem changes commit21f9c389e8Author: FL-OZ <anotherscuffed@gmail.com> Date: Mon Jun 1 00:50:49 2020 -0500 remove unused variable commitee0cf99edfAuthor: FL-OZ <anotherscuffed@gmail.com> Date: Fri May 29 00:26:41 2020 -0500 I THINK that fixed the crash. Not sure exactly what though. commit4a2e0b3b18Author: FL-OZ <anotherscuffed@gmail.com> Date: Fri May 29 00:22:30 2020 -0500 Remove bloat. commit1cddcac705Author: FL-OZ <anotherscuffed@gmail.com> Date: Thu May 28 15:35:32 2020 -0500 fix everything commitc45dc8fb9dAuthor: FL-OZ <anotherscuffed@gmail.com> Date: Thu May 28 01:36:45 2020 -0500 Add server side sound event stopping.
170 lines
5.8 KiB
C#
170 lines
5.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.GameObjects.Systems;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.Map;
|
|
|
|
namespace Robust.Server.GameObjects.EntitySystems
|
|
{
|
|
public class AudioSystem : EntitySystem
|
|
{
|
|
private uint _streamIndex;
|
|
|
|
public class AudioSourceServer
|
|
{
|
|
private readonly uint _id;
|
|
private readonly AudioSystem _audioSystem;
|
|
|
|
internal AudioSourceServer(AudioSystem parent, uint identifier)
|
|
{
|
|
_audioSystem = parent;
|
|
_id = identifier;
|
|
}
|
|
public void Stop()
|
|
{
|
|
_audioSystem.InternalStop(_id);
|
|
}
|
|
}
|
|
|
|
private void InternalStop(uint id)
|
|
{
|
|
var msg = new StopAudioMessageClient
|
|
{
|
|
Identifier = id
|
|
};
|
|
|
|
RaiseNetworkEvent(msg);
|
|
}
|
|
|
|
private uint CacheIdentifier()
|
|
{
|
|
if (_streamIndex >= uint.MaxValue)
|
|
{
|
|
_streamIndex = 0;
|
|
}
|
|
return _streamIndex++;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Play an audio file globally, without position.
|
|
/// </summary>
|
|
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
|
|
/// <param name="audioParams"></param>
|
|
public AudioSourceServer PlayGlobal(string filename, AudioParams? audioParams = null)
|
|
{
|
|
var id = CacheIdentifier();
|
|
var msg = new PlayAudioGlobalMessage
|
|
{
|
|
FileName = filename,
|
|
AudioParams = audioParams ?? AudioParams.Default,
|
|
Identifier = id
|
|
};
|
|
RaiseNetworkEvent(msg);
|
|
var src = new AudioSourceServer(this, id);
|
|
return src;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Play an audio file following an entity.
|
|
/// </summary>
|
|
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
|
|
/// <param name="entity">The entity "emitting" the audio.</param>
|
|
/// <param name="audioParams"></param>
|
|
public AudioSourceServer PlayFromEntity(string filename, IEntity entity, AudioParams? audioParams = null)
|
|
{
|
|
var id = CacheIdentifier();
|
|
var msg = new PlayAudioEntityMessage
|
|
{
|
|
FileName = filename,
|
|
EntityUid = entity.Uid,
|
|
AudioParams = audioParams ?? AudioParams.Default,
|
|
Identifier = id
|
|
};
|
|
RaiseNetworkEvent(msg);
|
|
var src = new AudioSourceServer(this, id);
|
|
return src;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Play an audio file at a static position.
|
|
/// </summary>
|
|
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
|
|
/// <param name="coordinates">The coordinates at which to play the audio.</param>
|
|
/// <param name="audioParams"></param>
|
|
public AudioSourceServer PlayAtCoords(string filename, GridCoordinates coordinates, AudioParams? audioParams = null)
|
|
{
|
|
var id = CacheIdentifier();
|
|
var msg = new PlayAudioPositionalMessage
|
|
{
|
|
FileName = filename,
|
|
Coordinates = coordinates,
|
|
AudioParams = audioParams ?? AudioParams.Default,
|
|
Identifier = id
|
|
};
|
|
RaiseNetworkEvent(msg);
|
|
var src = new AudioSourceServer(this, id);
|
|
return src;
|
|
}
|
|
|
|
#region DEPRECATED
|
|
/// <summary>
|
|
/// Play an audio file globally, without position.
|
|
/// </summary>
|
|
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
|
|
/// <param name="audioParams"></param>
|
|
[Obsolete("Deprecated. Use PlayGlobal instead.")]
|
|
public void Play(string filename, AudioParams? audioParams = null)
|
|
{
|
|
var msg = new PlayAudioGlobalMessage
|
|
{
|
|
FileName = filename,
|
|
AudioParams = audioParams ?? AudioParams.Default
|
|
};
|
|
RaiseNetworkEvent(msg);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Play an audio file following an entity.
|
|
/// </summary>
|
|
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
|
|
/// <param name="entity">The entity "emitting" the audio.</param>
|
|
/// <param name="audioParams"></param>
|
|
[Obsolete("Deprecated. Use PlayFromEntity instead.")]
|
|
public void Play(string filename, IEntity entity, AudioParams? audioParams = null)
|
|
{
|
|
var msg = new PlayAudioEntityMessage
|
|
{
|
|
FileName = filename,
|
|
EntityUid = entity.Uid,
|
|
AudioParams = audioParams ?? AudioParams.Default
|
|
};
|
|
RaiseNetworkEvent(msg);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Play an audio file at a static position.
|
|
/// </summary>
|
|
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
|
|
/// <param name="coordinates">The coordinates at which to play the audio.</param>
|
|
/// <param name="audioParams"></param>
|
|
[Obsolete("Deprecated. Use PlayAtCoords instead.")]
|
|
public void Play(string filename, GridCoordinates coordinates, AudioParams? audioParams = null)
|
|
{
|
|
var msg = new PlayAudioPositionalMessage
|
|
{
|
|
FileName = filename,
|
|
Coordinates = coordinates,
|
|
AudioParams = audioParams ?? AudioParams.Default
|
|
};
|
|
RaiseNetworkEvent(msg);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|