CVars for MIDI instrument limits (#2632)
* CVars for MIDI instruments limits! * Localize this * Cache CVars in instrument systems * better naming Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
committed by
GitHub
parent
6bb1e9fa5d
commit
cec722e19e
@@ -2,12 +2,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Client.GameObjects.EntitySystems;
|
||||
using Content.Shared;
|
||||
using Content.Shared.GameObjects.Components.Instruments;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Client.Audio.Midi;
|
||||
using Robust.Shared.Audio.Midi;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components.Timers;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.Configuration;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -34,6 +38,8 @@ namespace Content.Client.GameObjects.Components.Instruments
|
||||
|
||||
private IMidiRenderer? _renderer;
|
||||
|
||||
private InstrumentSystem _instrumentSystem = default!;
|
||||
|
||||
private byte _instrumentProgram = 1;
|
||||
|
||||
private byte _instrumentBank;
|
||||
@@ -158,6 +164,7 @@ namespace Content.Client.GameObjects.Components.Instruments
|
||||
{
|
||||
base.Initialize();
|
||||
IoCManager.InjectDependencies(this);
|
||||
_instrumentSystem = EntitySystem.Get<InstrumentSystem>();
|
||||
}
|
||||
|
||||
protected virtual void SetupRenderer(bool fromStateChange = false)
|
||||
@@ -422,7 +429,7 @@ namespace Content.Client.GameObjects.Components.Instruments
|
||||
|
||||
if (_midiEventBuffer.Count == 0) return;
|
||||
|
||||
var max = Math.Min(MaxMidiEventsPerBatch, MaxMidiEventsPerSecond - _sentWithinASec);
|
||||
var max = Math.Min(_instrumentSystem.MaxMidiEventsPerBatch, _instrumentSystem.MaxMidiEventsPerSecond - _sentWithinASec);
|
||||
|
||||
if (max <= 0)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Content.Client.GameObjects.Components.Instruments;
|
||||
using Content.Shared;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.Configuration;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
@@ -10,6 +12,28 @@ namespace Content.Client.GameObjects.EntitySystems
|
||||
public class InstrumentSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_cfg.OnValueChanged(CCVars.MaxMidiEventsPerBatch, OnMaxMidiEventsPerBatchChanged, true);
|
||||
_cfg.OnValueChanged(CCVars.MaxMidiEventsPerSecond, OnMaxMidiEventsPerSecondChanged, true);
|
||||
}
|
||||
|
||||
public int MaxMidiEventsPerBatch { get; private set; }
|
||||
public int MaxMidiEventsPerSecond { get; private set; }
|
||||
|
||||
private void OnMaxMidiEventsPerSecondChanged(int obj)
|
||||
{
|
||||
MaxMidiEventsPerSecond = obj;
|
||||
}
|
||||
|
||||
private void OnMaxMidiEventsPerBatchChanged(int obj)
|
||||
{
|
||||
MaxMidiEventsPerBatch = obj;
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user