mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Some warning fixes
This commit is contained in:
@@ -206,8 +206,10 @@ namespace Robust.Client.GameObjects
|
||||
SetEntityContextActive(_inputManager, controlled);
|
||||
}
|
||||
|
||||
void IPostInjectInit.PostInject()
|
||||
protected override void PostInject()
|
||||
{
|
||||
base.PostInject();
|
||||
|
||||
_sawmillInputContext = _logManager.GetSawmill("input.context");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.4.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.0.1" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Robust.Shared.Console
|
||||
/// Basic interface to handle console commands. Any class implementing this will be
|
||||
/// registered with the console system through reflection.
|
||||
/// </summary>
|
||||
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors), Obsolete("New commands should utilize RtShellCommand.")]
|
||||
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors), Obsolete("New commands should utilize ToolshedCommand.")]
|
||||
public interface IConsoleCommand
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -115,7 +115,9 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
public void InitializeComponents(EntityUid uid, MetaDataComponent? metadata = null)
|
||||
{
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
DebugTools.Assert(metadata == null || metadata.Owner == uid);
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
metadata ??= GetComponent<MetaDataComponent>(uid);
|
||||
DebugTools.Assert(metadata.EntityLifeStage == EntityLifeStage.PreInit);
|
||||
metadata.EntityLifeStage = EntityLifeStage.Initializing;
|
||||
@@ -182,7 +184,9 @@ namespace Robust.Shared.GameObjects
|
||||
public Component AddComponent(EntityUid uid, ushort netId)
|
||||
{
|
||||
var newComponent = (Component)_componentFactory.GetComponent(netId);
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
newComponent.Owner = uid;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
AddComponent(uid, newComponent);
|
||||
return newComponent;
|
||||
}
|
||||
@@ -190,7 +194,9 @@ namespace Robust.Shared.GameObjects
|
||||
public T AddComponent<T>(EntityUid uid) where T : Component, new()
|
||||
{
|
||||
var newComponent = _componentFactory.GetComponent<T>();
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
newComponent.Owner = uid;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
AddComponent(uid, newComponent);
|
||||
return newComponent;
|
||||
}
|
||||
@@ -199,19 +205,21 @@ namespace Robust.Shared.GameObjects
|
||||
where T : Component
|
||||
{
|
||||
private readonly IEntityManager _entMan;
|
||||
private readonly EntityUid _owner;
|
||||
public readonly CompIdx CompType;
|
||||
public readonly T Comp;
|
||||
|
||||
public CompInitializeHandle(IEntityManager entityManager, T comp, CompIdx compType)
|
||||
public CompInitializeHandle(IEntityManager entityManager, EntityUid owner, T comp, CompIdx compType)
|
||||
{
|
||||
_entMan = entityManager;
|
||||
_owner = owner;
|
||||
Comp = comp;
|
||||
CompType = compType;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
var metadata = _entMan.GetComponent<MetaDataComponent>(Comp.Owner);
|
||||
var metadata = _entMan.GetComponent<MetaDataComponent>(_owner);
|
||||
|
||||
if (!metadata.EntityInitialized && !metadata.EntityInitializing)
|
||||
return;
|
||||
@@ -234,18 +242,16 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
var reg = _componentFactory.GetRegistration<T>();
|
||||
var newComponent = (T)_componentFactory.GetComponent(reg);
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
newComponent.Owner = uid;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
|
||||
if (!uid.IsValid() || !EntityExists(uid))
|
||||
throw new ArgumentException($"Entity {uid} is not valid.", nameof(uid));
|
||||
|
||||
if (newComponent == null) throw new ArgumentNullException(nameof(newComponent));
|
||||
|
||||
if (newComponent.Owner != uid) throw new InvalidOperationException("Component is not owned by entity.");
|
||||
|
||||
AddComponentInternal(uid, newComponent, false, true);
|
||||
|
||||
return new CompInitializeHandle<T>(this, newComponent, reg.Idx);
|
||||
return new CompInitializeHandle<T>(this, uid, newComponent, reg.Idx);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -256,7 +262,9 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
if (component == null) throw new ArgumentNullException(nameof(component));
|
||||
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
if (component.Owner != uid) throw new InvalidOperationException("Component is not owned by entity.");
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
|
||||
AddComponentInternal(uid, component, overwrite, false);
|
||||
}
|
||||
@@ -1417,7 +1425,9 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
if (component != null)
|
||||
{
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
DebugTools.Assert(uid == component.Owner, "Specified Entity is not the component's Owner!");
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1510,7 +1520,9 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
if (component != null)
|
||||
{
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
DebugTools.Assert(uid == component.Owner, "Specified Entity is not the component's Owner!");
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -203,7 +203,10 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
#endregion
|
||||
|
||||
void IPostInjectInit.PostInject()
|
||||
|
||||
void IPostInjectInit.PostInject() => PostInject();
|
||||
|
||||
protected virtual void PostInject()
|
||||
{
|
||||
Log = LogManager.GetSawmill(SawmillName);
|
||||
|
||||
|
||||
@@ -20,17 +20,20 @@ using Robust.Shared.Exceptions;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
{
|
||||
public sealed class EntitySystemManager : IEntitySystemManager
|
||||
public sealed class EntitySystemManager : IEntitySystemManager, IPostInjectInit
|
||||
{
|
||||
[IoC.Dependency] private readonly IReflectionManager _reflectionManager = default!;
|
||||
[IoC.Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[IoC.Dependency] private readonly ProfManager _profManager = default!;
|
||||
[IoC.Dependency] private readonly IDependencyCollection _dependencyCollection = default!;
|
||||
[IoC.Dependency] private readonly ILogManager _logManager = default!;
|
||||
|
||||
#if EXCEPTION_TOLERANCE
|
||||
[Dependency] private readonly IRuntimeLog _runtimeLog = default!;
|
||||
#endif
|
||||
|
||||
private ISawmill _sawmill = default!;
|
||||
|
||||
internal DependencyCollection SystemDependencyCollection = default!;
|
||||
private readonly List<Type> _systemTypes = new();
|
||||
|
||||
@@ -138,7 +141,7 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
foreach (var type in systems)
|
||||
{
|
||||
Logger.DebugS("go.sys", "Initializing entity system {0}", type);
|
||||
_sawmill.Debug("Initializing entity system {0}", type);
|
||||
|
||||
SystemDependencyCollection.Register(type);
|
||||
_systemTypes.Add(type);
|
||||
@@ -406,6 +409,11 @@ namespace Robust.Shared.GameObjects
|
||||
return System.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
void IPostInjectInit.PostInject()
|
||||
{
|
||||
_sawmill = _logManager.GetSawmill("go.sys");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SystemChangedArgs : EventArgs
|
||||
|
||||
@@ -4,7 +4,14 @@ namespace Robust.Shared.GameObjects
|
||||
{
|
||||
public abstract class SharedInputSystem : EntitySystem
|
||||
{
|
||||
private readonly CommandBindRegistry _bindRegistry = new();
|
||||
private CommandBindRegistry _bindRegistry = default!;
|
||||
|
||||
protected override void PostInject()
|
||||
{
|
||||
base.PostInject();
|
||||
|
||||
_bindRegistry = new CommandBindRegistry(Log);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Holds the keyFunction -> handler bindings for the simulation.
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace Robust.Shared.Input.Binding
|
||||
/// <inheritdoc cref="ICommandBindRegistry"/>
|
||||
public sealed class CommandBindRegistry : ICommandBindRegistry
|
||||
{
|
||||
private readonly ISawmill _sawmill;
|
||||
|
||||
// all registered bindings
|
||||
private List<TypedCommandBind> _bindings = new();
|
||||
// handlers in the order they should be resolved for the given key function.
|
||||
@@ -17,6 +19,11 @@ namespace Robust.Shared.Input.Binding
|
||||
private Dictionary<BoundKeyFunction, List<InputCmdHandler>> _bindingsForKey = new();
|
||||
private bool _graphDirty = false;
|
||||
|
||||
public CommandBindRegistry(ISawmill sawmill)
|
||||
{
|
||||
_sawmill = sawmill;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Register<TOwner>(CommandBinds commandBinds)
|
||||
{
|
||||
@@ -30,11 +37,11 @@ namespace Robust.Shared.Input.Binding
|
||||
{
|
||||
// feel free to delete this if there's an actual need for registering multiple
|
||||
// bindings for a given type in separate calls to Register()
|
||||
Logger.Warning("Command binds already registered for type {0}, but you are trying" +
|
||||
" to register more. This may " +
|
||||
"be a programming error. Did you register these under the wrong type, or " +
|
||||
"did you forget to unregister these bindings when" +
|
||||
" your system / manager is shutdown?", owner.Name);
|
||||
_sawmill.Warning("Command binds already registered for type {0}, but you are trying" +
|
||||
" to register more. This may " +
|
||||
"be a programming error. Did you register these under the wrong type, or " +
|
||||
"did you forget to unregister these bindings when" +
|
||||
" your system / manager is shutdown?", owner.Name);
|
||||
}
|
||||
|
||||
foreach (var binding in commandBinds.Bindings)
|
||||
|
||||
@@ -128,7 +128,11 @@ internal sealed class MapSerializationContext : ISerializationContext, IEntityLo
|
||||
return new ValueDataNode("invalid");
|
||||
}
|
||||
|
||||
Logger.ErrorS("map", "Encountered an invalid entityUid '{0}' while serializing a map.", value);
|
||||
dependencies
|
||||
.Resolve<ILogManager>()
|
||||
.GetSawmill("map")
|
||||
.Error("Encountered an invalid entityUid '{0}' while serializing a map.", value);
|
||||
|
||||
return new ValueDataNode("invalid");
|
||||
}
|
||||
|
||||
@@ -147,7 +151,11 @@ internal sealed class MapSerializationContext : ISerializationContext, IEntityLo
|
||||
if (int.TryParse(node.Value, out var val) && _uidEntityMap.TryGetValue(val, out var entity))
|
||||
return entity;
|
||||
|
||||
Logger.ErrorS("map", "Error in map file: found local entity UID '{0}' which does not exist.", val);
|
||||
dependencies
|
||||
.Resolve<ILogManager>()
|
||||
.GetSawmill("map")
|
||||
.Error("Error in map file: found local entity UID '{0}' which does not exist.", val);
|
||||
|
||||
return EntityUid.Invalid;
|
||||
|
||||
}
|
||||
|
||||
@@ -137,6 +137,10 @@ internal sealed unsafe class PrecisionSleepLinuxNanosleep : PrecisionSleep
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable CS8981 // The type name only contains lower-cased ascii characters. Such names may become reserved for the language.
|
||||
#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value
|
||||
// ReSharper disable IdentifierTypo
|
||||
// ReSharper disable InconsistentNaming
|
||||
[DllImport("libc.so.6", SetLastError=true)]
|
||||
private static extern int nanosleep(timespec* req, timespec* rem);
|
||||
|
||||
@@ -151,4 +155,8 @@ internal sealed unsafe class PrecisionSleepLinuxNanosleep : PrecisionSleep
|
||||
public long tv_sec;
|
||||
public long tv_usec;
|
||||
}
|
||||
// ReSharper restore InconsistentNaming
|
||||
// ReSharper restore IdentifierTypo
|
||||
#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value
|
||||
#pragma warning restore CS8981 // The type name only contains lower-cased ascii characters. Such names may become reserved for the language.
|
||||
}
|
||||
|
||||
74
Robust.UnitTesting/DummySawmill.cs
Normal file
74
Robust.UnitTesting/DummySawmill.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using Robust.Shared.Log;
|
||||
|
||||
namespace Robust.UnitTesting;
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="ISawmill"/> that does absolutely nothing.
|
||||
/// </summary>
|
||||
public sealed class DummySawmill : ISawmill
|
||||
{
|
||||
public string Name => "dummy";
|
||||
|
||||
public LogLevel? Level { get; set; }
|
||||
|
||||
public void AddHandler(ILogHandler handler)
|
||||
{
|
||||
}
|
||||
|
||||
public void RemoveHandler(ILogHandler handler)
|
||||
{
|
||||
}
|
||||
|
||||
public void Log(LogLevel level, string message, params object?[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public void Log(LogLevel level, Exception? exception, string message, params object?[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public void Log(LogLevel level, string message)
|
||||
{
|
||||
}
|
||||
|
||||
public void Debug(string message, params object?[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public void Debug(string message)
|
||||
{
|
||||
}
|
||||
|
||||
public void Info(string message, params object?[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public void Info(string message)
|
||||
{
|
||||
}
|
||||
|
||||
public void Warning(string message, params object?[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public void Warning(string message)
|
||||
{
|
||||
}
|
||||
|
||||
public void Error(string message, params object?[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public void Error(string message)
|
||||
{
|
||||
}
|
||||
|
||||
public void Fatal(string message, params object?[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public void Fatal(string message)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ namespace Robust.UnitTesting.Shared.Input.Binding
|
||||
[TestCase(10,10)]
|
||||
public void ResolvesHandlers_WhenNoDependencies(int handlersPerType, int numFunctions)
|
||||
{
|
||||
var registry = new CommandBindRegistry();
|
||||
var registry = new CommandBindRegistry(new DummySawmill());
|
||||
var allHandlers = new Dictionary<BoundKeyFunction,List<InputCmdHandler>>();
|
||||
for (int i = 0; i < numFunctions; i++)
|
||||
{
|
||||
@@ -105,7 +105,7 @@ namespace Robust.UnitTesting.Shared.Input.Binding
|
||||
[TestCase(true, true)]
|
||||
public void ResolvesHandlers_WithDependency(bool before, bool after)
|
||||
{
|
||||
var registry = new CommandBindRegistry();
|
||||
var registry = new CommandBindRegistry(new DummySawmill());
|
||||
var bkf = new BoundKeyFunction("test");
|
||||
|
||||
var aHandler1 = new TestInputCmdHandler( );
|
||||
@@ -204,7 +204,7 @@ namespace Robust.UnitTesting.Shared.Input.Binding
|
||||
[Test]
|
||||
public void ThrowsError_WhenCircularDependency()
|
||||
{
|
||||
var registry = new CommandBindRegistry();
|
||||
var registry = new CommandBindRegistry(new DummySawmill());
|
||||
var bkf = new BoundKeyFunction("test");
|
||||
|
||||
var aHandler1 = new TestInputCmdHandler();
|
||||
|
||||
Reference in New Issue
Block a user