Skip to content

Commit

Permalink
Manual fixes to reduce warnings to zero
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jun 23, 2023
1 parent 75ed421 commit 3064650
Show file tree
Hide file tree
Showing 36 changed files with 42 additions and 96 deletions.
2 changes: 1 addition & 1 deletion osu.Framework.Benchmarks/BenchmarkTextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private class TestStore : ITexturedGlyphLookupStore
new CharacterGlyph(character, character, character, character, character, null),
new DummyRenderer().CreateTexture(1, 1));

public Task<ITexturedCharacterGlyph> GetAsync(string fontName, char character) => Task.Run(() => Get(fontName, character));
public Task<ITexturedCharacterGlyph?> GetAsync(string fontName, char character) => Task.Run<ITexturedCharacterGlyph?>(() => Get(fontName, character));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ private float restitution
{
restitutionBacking = value;

if (sim == null)
return;

foreach (var d in sim.Children)
d.Restitution = value;
sim.Restitution = value;
Expand All @@ -43,9 +40,6 @@ private float friction
{
frictionBacking = value;

if (sim == null)
return;

foreach (var d in sim.Children)
d.FrictionCoefficient = value;
sim.FrictionCoefficient = value;
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Bindables/BindableDouble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public BindableDouble(double defaultValue = 0)
{
}

public override string ToString(string format, IFormatProvider formatProvider) => base.ToString(format ?? "0.0###", formatProvider);
public override string ToString(string? format, IFormatProvider formatProvider) => base.ToString(format ?? "0.0###", formatProvider);

protected override Bindable<double> CreateInstance() => new BindableDouble();
}
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Bindables/BindableFloat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public BindableFloat(float defaultValue = 0)
{
}

public override string ToString(string format, IFormatProvider formatProvider) => base.ToString(format ?? "0.0###", formatProvider);
public override string ToString(string? format, IFormatProvider formatProvider) => base.ToString(format ?? "0.0###", formatProvider);

protected override Bindable<float> CreateInstance() => new BindableFloat();
}
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Development/DebugUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static class DebugUtils
public static bool LogPerformanceIssues { get; internal set; }

// https://stackoverflow.com/a/2186634
private static bool isDebugAssembly(Assembly assembly) => assembly?.GetCustomAttributes(false).OfType<DebuggableAttribute>().Any(da => da.IsJITTrackingEnabled) ?? false;
private static bool isDebugAssembly(Assembly? assembly) => assembly?.GetCustomAttributes(false).OfType<DebuggableAttribute>().Any(da => da.IsJITTrackingEnabled) ?? false;

/// <summary>
/// Gets the entry assembly, or calling assembly otherwise.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics.Performance;

namespace osu.Framework.Graphics.Containers
Expand Down Expand Up @@ -136,7 +137,7 @@ private void drawableLifetimeChanged(Drawable drawable)

public void Dispose()
{
if (Drawable != null)
if (Drawable.IsNotNull())
Drawable.LifetimeChanged -= drawableLifetimeChanged;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public SpriteText CreateSpriteText()
var text = parentTextComponent.CreateSpriteText();
text.Colour = new Color4(255, 0, 0, 255);
text.Font = text.Font.With(size: 21);
text.Text = markdownObject?.GetType() + " Not implemented.";
text.Text = markdownObject.GetType() + " Not implemented.";
return text;
}
}
Expand Down
5 changes: 2 additions & 3 deletions osu.Framework/Graphics/TransformSequenceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using osu.Framework.Graphics.Transforms;
using osu.Framework.Threading;
using System;
using JetBrains.Annotations;
using osu.Framework.Bindables;

namespace osu.Framework.Graphics
Expand Down Expand Up @@ -249,7 +248,7 @@ public static TransformSequence<T> TransformSpacingTo<T>(this TransformSequence<
/// Smoothly adjusts the value of a <see cref="Bindable{TValue}"/> over time.
/// </summary>
/// <returns>A <see cref="TransformSequence{T}"/> to which further transforms can be added.</returns>
public static TransformSequence<T> TransformBindableTo<T, TValue>(this TransformSequence<T> t, [NotNull] Bindable<TValue> bindable, TValue newValue, double duration = 0,
public static TransformSequence<T> TransformBindableTo<T, TValue>(this TransformSequence<T> t, Bindable<TValue> bindable, TValue newValue, double duration = 0,
Easing easing = Easing.None)
where T : class, ITransformable
=> t.TransformBindableTo(bindable, newValue, duration, new DefaultEasingFunction(easing));
Expand Down Expand Up @@ -487,7 +486,7 @@ public static TransformSequence<T> TransformSpacingTo<T, TEasing>(this Transform
/// Smoothly adjusts the value of a <see cref="Bindable{TValue}"/> over time.
/// </summary>
/// <returns>A <see cref="TransformSequence{T}"/> to which further transforms can be added.</returns>
public static TransformSequence<T> TransformBindableTo<T, TValue, TEasing>(this TransformSequence<T> t, [NotNull] Bindable<TValue> bindable, TValue newValue, double duration, TEasing easing)
public static TransformSequence<T> TransformBindableTo<T, TValue, TEasing>(this TransformSequence<T> t, Bindable<TValue> bindable, TValue newValue, double duration, TEasing easing)
where T : class, ITransformable
where TEasing : IEasingFunction
=> t.Append(o => o.TransformBindableTo(bindable, newValue, duration, easing));
Expand Down
8 changes: 2 additions & 6 deletions osu.Framework/Graphics/UserInterface/BasicButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ public partial class BasicButton : Button
{
public LocalisableString Text
{
get => SpriteText?.Text ?? default;
set
{
if (SpriteText != null)
SpriteText.Text = value;
}
get => SpriteText.Text;
set => SpriteText.Text = value;
}

public Color4 BackgroundColour
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Graphics/UserInterface/MenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MenuItem
/// <summary>
/// The <see cref="Action"/> that is performed when this <see cref="MenuItem"/> is clicked.
/// </summary>
public readonly Bindable<Action> Action = new Bindable<Action>();
public readonly Bindable<Action?> Action = new Bindable<Action?>();

/// <summary>
/// A list of items which are to be displayed in a sub-menu originating from this <see cref="MenuItem"/>.
Expand Down Expand Up @@ -48,7 +48,7 @@ protected MenuItem(Action action)
/// </summary>
/// <param name="text">The text to display.</param>
/// <param name="action">The <see cref="Action"/> to perform when clicked.</param>
public MenuItem(LocalisableString text, Action action)
public MenuItem(LocalisableString text, Action? action)
: this(text)
{
Action.Value = action;
Expand Down
8 changes: 3 additions & 5 deletions osu.Framework/IO/Stores/FontStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

#nullable disable

using osu.Framework.Graphics.Textures;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
using osu.Framework.Logging;
using System.Collections.Concurrent;
using JetBrains.Annotations;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Textures;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Framework.Text;

Expand Down Expand Up @@ -131,7 +130,6 @@ public override void RemoveStore(ITextureStore store)
base.RemoveStore(store);
}

[CanBeNull]
public ITexturedCharacterGlyph Get(string fontName, char character)
{
var key = (fontName, character);
Expand Down
3 changes: 1 addition & 2 deletions osu.Framework/IO/Stores/GlyphStore.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable
Expand Down Expand Up @@ -118,7 +118,6 @@ protected string GetFilenameForPage(int page)
return $@"{AssetName}_{page.ToString().PadLeft((Font.Pages.Count - 1).ToString().Length, '0')}.png";
}

[CanBeNull]
public CharacterGlyph Get(char character)
{
if (Font == null)
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/IO/Stores/IGlyphStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface IGlyphStore : IResourceStore<CharacterGlyph>
/// </summary>
/// <param name="character">The character to retrieve the <see cref="CharacterGlyph"/> for.</param>
/// <returns>The <see cref="CharacterGlyph"/> containing associated spacing information for <paramref name="character"/>.</returns>
CharacterGlyph Get(char character);
CharacterGlyph? Get(char character);

/// <summary>
/// Retrieves the kerning for a pair of characters.
Expand Down
4 changes: 1 addition & 3 deletions osu.Framework/Input/Events/FocusEvent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using JetBrains.Annotations;
using osu.Framework.Graphics;
using osu.Framework.Input.States;

Expand All @@ -15,8 +14,7 @@ public class FocusEvent : UIEvent
/// <summary>
/// The <see cref="Drawable"/> that has lost focus, or <c>null</c> if nothing was previously focused.
/// </summary>
[CanBeNull]
public readonly Drawable PreviouslyFocused;
public readonly Drawable? PreviouslyFocused;

public FocusEvent(InputState state, Drawable previouslyFocused)
: base(state)
Expand Down
4 changes: 1 addition & 3 deletions osu.Framework/Input/Events/FocusLostEvent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using JetBrains.Annotations;
using osu.Framework.Graphics;
using osu.Framework.Input.States;

Expand All @@ -15,8 +14,7 @@ public class FocusLostEvent : UIEvent
/// <summary>
/// The <see cref="Drawable"/> that will gain focus, or <c>null</c> if nothing will gain focus.
/// </summary>
[CanBeNull]
public readonly Drawable NextFocused;
public readonly Drawable? NextFocused;

public FocusLostEvent(InputState state, Drawable nextFocused)
: base(state)
Expand Down
3 changes: 1 addition & 2 deletions osu.Framework/Input/Events/JoystickAxisMoveEvent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using JetBrains.Annotations;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Input.States;

Expand All @@ -27,7 +26,7 @@ public class JoystickAxisMoveEvent : JoystickEvent
/// </summary>
public float Delta => Axis.Value - LastValue;

public JoystickAxisMoveEvent([NotNull] InputState state, JoystickAxis axis, float lastValue)
public JoystickAxisMoveEvent(InputState state, JoystickAxis axis, float lastValue)
: base(state)
{
LastValue = lastValue;
Expand Down
3 changes: 1 addition & 2 deletions osu.Framework/Input/Events/JoystickEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Input.States;

namespace osu.Framework.Input.Events
{
public abstract class JoystickEvent : UIEvent
{
protected JoystickEvent([NotNull] InputState state)
protected JoystickEvent(InputState state)
: base(state)
{
}
Expand Down
3 changes: 1 addition & 2 deletions osu.Framework/Input/Events/MidiDownEvent.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using JetBrains.Annotations;
using osu.Framework.Input.States;

namespace osu.Framework.Input.Events
{
public class MidiDownEvent : MidiEvent
{
public MidiDownEvent([NotNull] InputState state, MidiKey key, byte velocity)
public MidiDownEvent(InputState state, MidiKey key, byte velocity)
: base(state, key, velocity)
{
}
Expand Down
3 changes: 1 addition & 2 deletions osu.Framework/Input/Events/MidiEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using JetBrains.Annotations;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Input.States;

Expand All @@ -28,7 +27,7 @@ public abstract class MidiEvent : UIEvent
/// </summary>
public IEnumerable<MidiKey> PressedKeys => CurrentState.Midi.Keys;

protected MidiEvent([NotNull] InputState state, MidiKey key, byte velocity)
protected MidiEvent(InputState state, MidiKey key, byte velocity)
: base(state)
{
Key = key;
Expand Down
3 changes: 1 addition & 2 deletions osu.Framework/Input/Events/MidiUpEvent.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using JetBrains.Annotations;
using osu.Framework.Input.States;

namespace osu.Framework.Input.Events
{
public class MidiUpEvent : MidiEvent
{
public MidiUpEvent([NotNull] InputState state, MidiKey key)
public MidiUpEvent(InputState state, MidiKey key)
: base(state, key, 0)
{
}
Expand Down
3 changes: 1 addition & 2 deletions osu.Framework/Input/Events/TabletEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using JetBrains.Annotations;
using osu.Framework.Input.States;

namespace osu.Framework.Input.Events
{
public abstract class TabletEvent : UIEvent
{
protected TabletEvent([NotNull] InputState state)
protected TabletEvent(InputState state)
: base(state)
{
}
Expand Down
7 changes: 1 addition & 6 deletions osu.Framework/Input/JoystickButtonEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ public JoystickButtonEventManager(JoystickButton button)

protected override Drawable HandleButtonDown(InputState state, List<Drawable> targets) => PropagateButtonEvent(targets, new JoystickPressEvent(state, Button));

protected override void HandleButtonUp(InputState state, List<Drawable> targets)
{
if (targets == null)
return;

protected override void HandleButtonUp(InputState state, List<Drawable> targets) =>
PropagateButtonEvent(targets, new JoystickReleaseEvent(state, Button));
}
}
}
7 changes: 1 addition & 6 deletions osu.Framework/Input/KeyEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ public void HandleRepeat(InputState state)

protected override Drawable HandleButtonDown(InputState state, List<Drawable> targets) => PropagateButtonEvent(targets, new KeyDownEvent(state, Button));

protected override void HandleButtonUp(InputState state, List<Drawable> targets)
{
if (targets == null)
return;

protected override void HandleButtonUp(InputState state, List<Drawable> targets) =>
PropagateButtonEvent(targets, new KeyUpEvent(state, Button));
}
}
}
7 changes: 1 addition & 6 deletions osu.Framework/Input/MidiKeyEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ public MidiKeyEventManager(MidiKey button)

protected override Drawable HandleButtonDown(InputState state, List<Drawable> targets) => PropagateButtonEvent(targets, new MidiDownEvent(state, Button, state.Midi.Velocities[Button]));

protected override void HandleButtonUp(InputState state, List<Drawable> targets)
{
if (targets == null)
return;

protected override void HandleButtonUp(InputState state, List<Drawable> targets) =>
PropagateButtonEvent(targets, new MidiUpEvent(state, Button));
}
}
}
2 changes: 1 addition & 1 deletion osu.Framework/Input/SDL2WindowTextInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private void handleTextInput(string text)
}
}

private void handleTextEditing(string text, int selectionStart, int selectionLength)
private void handleTextEditing(string? text, int selectionStart, int selectionLength)
{
if (text == null) return;

Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Input/StateChanges/ButtonInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected ButtonInput(TButton button, bool isPressed)
/// </remarks>
/// <param name="current">The newer <see cref="ButtonStates{TButton}"/>.</param>
/// <param name="previous">The older <see cref="ButtonStates{TButton}"/>.</param>
protected ButtonInput(ButtonStates<TButton> current, ButtonStates<TButton> previous)
protected ButtonInput(ButtonStates<TButton>? current, ButtonStates<TButton>? previous)
{
var difference = (current ?? new ButtonStates<TButton>()).EnumerateDifference(previous ?? new ButtonStates<TButton>());

Expand Down
Loading

0 comments on commit 3064650

Please sign in to comment.