Drop midi batch if it exceeds event limit.
This commit is contained in:
@@ -11,6 +11,8 @@ using Robust.Shared.Interfaces.Network;
|
|||||||
using Robust.Shared.Players;
|
using Robust.Shared.Players;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
|
using Logger = Robust.Shared.Log.Logger;
|
||||||
|
using MidiEvent = Robust.Shared.Audio.Midi.MidiEvent;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.Components.Instruments
|
namespace Content.Server.GameObjects.Components.Instruments
|
||||||
{
|
{
|
||||||
@@ -19,7 +21,10 @@ namespace Content.Server.GameObjects.Components.Instruments
|
|||||||
public class InstrumentComponent : SharedInstrumentComponent,
|
public class InstrumentComponent : SharedInstrumentComponent,
|
||||||
IDropped, IHandSelected, IHandDeselected, IActivate, IUse, IThrown
|
IDropped, IHandSelected, IHandDeselected, IActivate, IUse, IThrown
|
||||||
{
|
{
|
||||||
|
// These 2 values are quite high for now, and this could be easily abused. Change this if people are abusing it.
|
||||||
public const int MaxMidiEventsPerSecond = 20;
|
public const int MaxMidiEventsPerSecond = 20;
|
||||||
|
public const int MaxMidiEventsPerBatch = 50;
|
||||||
|
public const int MaxMidiBatchDropped = 20;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The client channel currently playing the instrument, or null if there's none.
|
/// The client channel currently playing the instrument, or null if there's none.
|
||||||
@@ -35,7 +40,10 @@ namespace Content.Server.GameObjects.Components.Instruments
|
|||||||
private float _timer = 0f;
|
private float _timer = 0f;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public uint _lastSequencerTick = 0;
|
private int _batchesDropped = 0;
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
private uint _lastSequencerTick = 0;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private int _midiEventCount = 0;
|
private int _midiEventCount = 0;
|
||||||
@@ -92,16 +100,22 @@ namespace Content.Server.GameObjects.Components.Instruments
|
|||||||
case InstrumentMidiEventMessage midiEventMsg:
|
case InstrumentMidiEventMessage midiEventMsg:
|
||||||
if (!Playing)
|
if (!Playing)
|
||||||
return;
|
return;
|
||||||
if(++_midiEventCount <= MaxMidiEventsPerSecond)
|
|
||||||
|
if (++_midiEventCount <= MaxMidiEventsPerSecond &&
|
||||||
|
midiEventMsg.MidiEvent.Length < MaxMidiEventsPerBatch)
|
||||||
SendNetworkMessage(midiEventMsg);
|
SendNetworkMessage(midiEventMsg);
|
||||||
|
else
|
||||||
|
_batchesDropped++; // Batch dropped!
|
||||||
|
|
||||||
_lastSequencerTick = midiEventMsg.MidiEvent[^1].Timestamp;
|
_lastSequencerTick = midiEventMsg.MidiEvent[^1].Timestamp;
|
||||||
break;
|
break;
|
||||||
case InstrumentStartMidiMessage startMidi:
|
case InstrumentStartMidiMessage startMidi:
|
||||||
Playing = true;
|
Playing = true;
|
||||||
|
_batchesDropped = 0;
|
||||||
break;
|
break;
|
||||||
case InstrumentStopMidiMessage stopMidi:
|
case InstrumentStopMidiMessage stopMidi:
|
||||||
Playing = false;
|
Playing = false;
|
||||||
|
_lastSequencerTick = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,6 +193,11 @@ namespace Content.Server.GameObjects.Components.Instruments
|
|||||||
{
|
{
|
||||||
base.Update(delta);
|
base.Update(delta);
|
||||||
|
|
||||||
|
if (_batchesDropped > MaxMidiBatchDropped && _instrumentPlayer != null)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
_timer += delta;
|
_timer += delta;
|
||||||
if (_timer < 1) return;
|
if (_timer < 1) return;
|
||||||
_timer = 0f;
|
_timer = 0f;
|
||||||
|
|||||||
Reference in New Issue
Block a user