Some code quality stuff

This commit is contained in:
Garry Newman 2020-02-24 14:11:27 +00:00
parent b52a63bc8b
commit d990b537a3
25 changed files with 39 additions and 51 deletions

View File

@ -43,11 +43,6 @@ namespace Steamworks
}
static void OnNewUrlLaunchParameters()
{
// Wow!
}
[TestMethod]
public void GameLangauge()
{

View File

@ -195,8 +195,8 @@ namespace Steamworks
{
await SteamInventory.WaitForDefinitions();
byte[] data = null;
int itemCount = 0;
byte[] data;
int itemCount;
// Serialize
{

View File

@ -130,7 +130,7 @@ namespace Steamworks
[TestMethod]
public async Task CreateAndThenEditFile()
{
PublishedFileId fileid = default;
PublishedFileId fileid;
//
// Make a file

View File

@ -168,9 +168,7 @@ namespace Steamworks
appid = SteamClient.AppId;
var depots = new DepotId_t[32];
uint count = 0;
count = Internal.GetInstalledDepots( appid.Value, depots, (uint) depots.Length );
uint count = Internal.GetInstalledDepots( appid.Value, depots, (uint) depots.Length );
for ( int i = 0; i < count; i++ )
{
@ -220,7 +218,7 @@ namespace Steamworks
ulong punBytesTotal = 0;
if ( !Internal.GetDlcDownloadProgress( appid.Value, ref punBytesDownloaded, ref punBytesTotal ) )
return default( DownloadProgress );
return default;
return new DownloadProgress { BytesDownloaded = punBytesDownloaded, BytesTotal = punBytesTotal, Active = true };
}
@ -263,7 +261,7 @@ namespace Steamworks
{
get
{
var len = Internal.GetLaunchCommandLine( out var strVal );
Internal.GetLaunchCommandLine( out var strVal );
return strVal;
}
}

View File

@ -74,7 +74,7 @@ namespace Steamworks
openInterfaces.Add( t );
}
static List<SteamClass> openInterfaces = new List<SteamClass>();
static readonly List<SteamClass> openInterfaces = new List<SteamClass>();
internal static void ShutdownInterfaces()
{

View File

@ -25,7 +25,7 @@ namespace Steamworks
Internal.RunFrame();
}
static InputHandle_t[] queryArray = new InputHandle_t[STEAM_CONTROLLER_MAX_COUNT];
static readonly InputHandle_t[] queryArray = new InputHandle_t[STEAM_CONTROLLER_MAX_COUNT];
/// <summary>
/// Return a list of connected controllers.

View File

@ -103,7 +103,7 @@ namespace Steamworks
public static T CreateNormalSocket<T>( NetAddress address ) where T : SocketInterface, new()
{
var t = new T();
var options = new NetKeyValue[0];
var options = Array.Empty<NetKeyValue>();
t.Socket = Internal.CreateListenSocketIP( ref address, options.Length, options );
t.Initialize();
@ -117,7 +117,7 @@ namespace Steamworks
public static T ConnectNormal<T>( NetAddress address ) where T : ConnectionInterface, new()
{
var t = new T();
var options = new NetKeyValue[0];
var options = Array.Empty<NetKeyValue>();
t.Connection = Internal.ConnectByIPAddress( ref address, options.Length, options );
SetConnectionInterface( t.Connection.Id, t );
return t;
@ -129,7 +129,7 @@ namespace Steamworks
public static T CreateRelaySocket<T>( int virtualport = 0 ) where T : SocketInterface, new()
{
var t = new T();
var options = new NetKeyValue[0];
var options = Array.Empty<NetKeyValue>();
t.Socket = Internal.CreateListenSocketP2P( virtualport, options.Length, options );
SetSocketInterface( t.Socket.Id, t );
return t;
@ -142,7 +142,7 @@ namespace Steamworks
{
var t = new T();
NetIdentity identity = serverId;
var options = new NetKeyValue[0];
var options = Array.Empty<NetKeyValue>();
t.Connection = Internal.ConnectP2P( ref identity, virtualport, options.Length, options );
SetConnectionInterface( t.Connection.Id, t );
return t;

View File

@ -109,7 +109,7 @@ namespace Steamworks
/// </summary>
public static async Task WaitForPingDataAsync( float maxAgeInSeconds = 60 * 5 )
{
if ( Internal.CheckPingDataUpToDate( 120.0f ) )
if ( Internal.CheckPingDataUpToDate( maxAgeInSeconds ) )
return;
SteamRelayNetworkStatus_t status = default;

View File

@ -131,7 +131,7 @@ namespace Steamworks
openInterfaces.Add( t );
}
static List<SteamClass> openInterfaces = new List<SteamClass>();
static readonly List<SteamClass> openInterfaces = new List<SteamClass>();
internal static void ShutdownInterfaces()
{

View File

@ -58,7 +58,7 @@ namespace Steamworks
/// <param name="ct">Allows you to send a message to cancel the download anywhere during the process</param>
/// <param name="milisecondsUpdateDelay">How often to call the progress function</param>
/// <returns>true if downloaded and installed correctly</returns>
public static async Task<bool> DownloadAsync( PublishedFileId fileId, Action<float> progress = null, CancellationToken ct = default, int milisecondsUpdateDelay = 60 )
public static async Task<bool> DownloadAsync( PublishedFileId fileId, Action<float> progress = null, int milisecondsUpdateDelay = 60, CancellationToken ct = default )
{
var item = new Steamworks.Ugc.Item( fileId );

View File

@ -318,11 +318,11 @@ namespace Steamworks
AuthTicket ticket = null;
var stopwatch = Stopwatch.StartNew();
Action<GetAuthSessionTicketResponse_t> f = ( t ) =>
void f( GetAuthSessionTicketResponse_t t )
{
if ( t.AuthTicket != ticket.Handle ) return;
result = t.Result;
};
}
OnGetAuthSessionTicketResponse += f;

View File

@ -75,12 +75,12 @@ namespace Steamworks.Data
var ident = Identifier;
bool gotCallback = false;
Action<string, int> f = ( x, icon ) =>
void f( string x, int icon )
{
if ( x != ident ) return;
i = icon;
gotCallback = true;
};
}
try
{

View File

@ -51,7 +51,7 @@ namespace Steamworks
/// Sometimes we don't know the user's name. This will wait until we have
/// downloaded the information on this user.
/// </summary>
public async Task RequestInfoAsync( int timeout = 5000 )
public async Task RequestInfoAsync()
{
await SteamFriends.CacheUserInformationAsync( Id, true );
}
@ -99,7 +99,7 @@ namespace Steamworks
{
get
{
FriendGameInfo_t gameInfo = default( FriendGameInfo_t );
FriendGameInfo_t gameInfo = default;
if ( !SteamFriends.Internal.GetFriendGamePlayed( Id, ref gameInfo ) )
return null;

View File

@ -135,7 +135,7 @@ namespace Steamworks
string val = GetProperty( name );
if ( string.IsNullOrEmpty( val ) )
return default( T );
return default;
try
{
@ -143,7 +143,7 @@ namespace Steamworks
}
catch ( System.Exception )
{
return default( T );
return default;
}
}

View File

@ -20,7 +20,7 @@ namespace Steamworks.Data
public int EntryCount => SteamUserStats.Internal.GetLeaderboardEntryCount(Id);
static int[] detailsBuffer = new int[64];
static int[] noDetails = new int[0];
static int[] noDetails = Array.Empty<int>();
/// <summary>
/// Submit your score and replace your old score even if it was better
@ -122,7 +122,7 @@ namespace Steamworks.Data
return output;
}
internal async Task WaitForUserNames( LeaderboardEntry[] entries)
internal static async Task WaitForUserNames( LeaderboardEntry[] entries)
{
bool gotAll = false;
while ( !gotAll )

View File

@ -123,7 +123,7 @@ namespace Steamworks.Data
/// <summary>
/// Sets per-user metadata (for the local user implicitly)
/// </summary>
public void SetMemberData( Friend member, string key, string value )
public void SetMemberData( string key, string value )
{
SteamMatchmaking.Internal.SetLobbyMemberData( Id, key, value );
}

View File

@ -18,7 +18,7 @@ namespace Steamworks
{
var owner = default( SteamId );
var location = default( SteamPartyBeaconLocation_t );
Internal.GetBeaconDetails( Id, ref owner, ref location, out var strVal );
Internal.GetBeaconDetails( Id, ref owner, ref location, out _ );
return owner;
}
}
@ -32,7 +32,7 @@ namespace Steamworks
{
var owner = default( SteamId );
var location = default( SteamPartyBeaconLocation_t );
Internal.GetBeaconDetails( Id, ref owner, ref location, out var strVal );
_ = Internal.GetBeaconDetails( Id, ref owner, ref location, out var strVal );
return strVal;
}
}

View File

@ -9,8 +9,6 @@ namespace Steamworks.Data
{
public struct ServerInfo : IEquatable<ServerInfo>
{
static ISteamMatchmakingServers Internal => Steamworks.ServerList.Base.Internal;
public string Name { get; set; }
public int Ping { get; set; }
public string GameDir { get; set; }

View File

@ -183,8 +183,7 @@ namespace Steamworks.Ugc
ulong size = 0;
uint ts = 0;
if ( !SteamUGC.Internal.GetItemInstallInfo( Id, ref size, out var strVal, ref ts ) )
if ( !SteamUGC.Internal.GetItemInstallInfo( Id, ref size, out _, ref ts ) )
return 0;
return (long) size;
@ -262,9 +261,9 @@ namespace Steamworks.Ugc
/// If CancellationToken is default then there is 60 seconds timeout
/// Progress will be set to 0-1
/// </summary>
public async Task<bool> DownloadAsync( Action<float> progress = null, CancellationToken ct = default, int milisecondsUpdateDelay = 60 )
public async Task<bool> DownloadAsync( Action<float> progress = null, int milisecondsUpdateDelay = 60, CancellationToken ct = default )
{
return await SteamUGC.DownloadAsync( Id, progress, ct, milisecondsUpdateDelay );
return await SteamUGC.DownloadAsync( Id, progress, milisecondsUpdateDelay, ct );
}
/// <summary>

View File

@ -13,7 +13,7 @@ namespace Steamworks
{
private static readonly byte[] A2S_SERVERQUERY_GETCHALLENGE = { 0x55, 0xFF, 0xFF, 0xFF, 0xFF };
// private static readonly byte A2S_PLAYER = 0x55;
private static readonly byte A2S_RULES = 0x56;
private const byte A2S_RULES = 0x56;
private static readonly Dictionary<IPEndPoint, Task<Dictionary<string, string>>> PendingQueries =
new Dictionary<IPEndPoint, Task<Dictionary<string, string>>>();
@ -27,7 +27,7 @@ namespace Steamworks
if (PendingQueries.TryGetValue(endpoint, out var pending))
return pending;
var task = GetRulesImpl(endpoint, server)
var task = GetRulesImpl( endpoint )
.ContinueWith(t =>
{
lock (PendingQueries)
@ -44,7 +44,7 @@ namespace Steamworks
}
}
private static async Task<Dictionary<string, string>> GetRulesImpl( IPEndPoint endpoint, ServerInfo server )
private static async Task<Dictionary<string, string>> GetRulesImpl( IPEndPoint endpoint )
{
try
{

View File

@ -61,7 +61,7 @@ namespace Steamworks
public class SteamSharedClass<T> : SteamClass
{
internal static SteamInterface Interface => InterfaceClient != null ? InterfaceClient : InterfaceServer;
internal static SteamInterface Interface => InterfaceClient ?? InterfaceServer;
internal static SteamInterface InterfaceClient;
internal static SteamInterface InterfaceServer;

View File

@ -89,7 +89,7 @@ namespace Steamworks
}
}
static byte[] readBuffer = new byte[1024 * 8];
static readonly byte[] readBuffer = new byte[1024 * 8];
public static string ReadNullTerminatedUTF8String( this BinaryReader br )
{

View File

@ -100,7 +100,7 @@ namespace Generator
{
if ( args[i + 1] is IntType || args[i + 1] is UIntType || args[i + 1] is UIntPtrType )
{
if ( args[i + 1].Ref == string.Empty )
if ( string.IsNullOrEmpty( args[i + 1].Ref ) )
{
args[i + 1] = new LiteralType( args[i + 1], "(1024 * 32)" );
}

View File

@ -15,7 +15,7 @@ namespace Generator
public string ManagedType;
}
private Dictionary<string, TypeDef> TypeDefs = new Dictionary<string, TypeDef>();
private readonly Dictionary<string, TypeDef> TypeDefs = new Dictionary<string, TypeDef>();
void Structs()
{
@ -29,8 +29,6 @@ namespace Generator
if ( name.Contains( "::" ) )
continue;
int defaultPack = c.IsPack4OnWindows ? 4 : 8;
var partial = "";
if ( c.Methods != null ) partial = " partial";

View File

@ -46,7 +46,7 @@ namespace Generator
{
if ( args[i + 1] is IntType || args[i + 1] is UIntType || args[i + 1] is UIntPtrType )
{
if ( args[i + 1].Ref == string.Empty )
if ( string.IsNullOrEmpty( args[i + 1].Ref ) )
{
args[i + 1] = new LiteralType( args[i + 1], "(1024 * 32)" );
}