More refactor

This commit is contained in:
Garry Newman 2016-10-05 12:44:01 +01:00
parent 778db29a68
commit 220a49e716
16 changed files with 63 additions and 118 deletions

View File

@ -14,7 +14,7 @@ namespace Facepunch.Steamworks.Test
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
Assert.IsTrue( client.Valid );
Assert.IsTrue( client.IsValid );
}
}
@ -25,7 +25,7 @@ namespace Facepunch.Steamworks.Test
{
var username = client.Username;
Console.WriteLine( username );
Assert.IsTrue( client.Valid );
Assert.IsTrue( client.IsValid );
Assert.IsNotNull( username );
}
}
@ -37,7 +37,7 @@ namespace Facepunch.Steamworks.Test
{
var steamid = client.SteamId;
Console.WriteLine( steamid );
Assert.IsTrue( client.Valid );
Assert.IsTrue( client.IsValid );
Assert.AreNotEqual( 0, steamid );
}
}

View File

@ -14,7 +14,7 @@ namespace Facepunch.Steamworks.Test
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
Assert.IsTrue( client.Valid );
Assert.IsTrue( client.IsValid );
client.Friends.Refresh();
@ -32,7 +32,7 @@ namespace Facepunch.Steamworks.Test
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
Assert.IsTrue( client.Valid );
Assert.IsTrue( client.IsValid );
foreach ( var friend in client.Friends.All )
{
@ -46,7 +46,7 @@ namespace Facepunch.Steamworks.Test
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
Assert.IsTrue( client.Valid );
Assert.IsTrue( client.IsValid );
var friend = client.Friends.All.First();

View File

@ -13,7 +13,7 @@ namespace Facepunch.Steamworks.Test
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
Assert.IsTrue( client.Valid );
Assert.IsTrue( client.IsValid );
Assert.IsNull( client.Inventory.SerializedItems );
@ -33,7 +33,7 @@ namespace Facepunch.Steamworks.Test
using ( var server = new Facepunch.Steamworks.Server( 252490, 0, 30002, true, "VersionString" ) )
{
server.LogOnAnonymous();
Assert.IsTrue( server.Valid );
Assert.IsTrue( server.IsValid );
var result = server.Inventory.Deserialize( client.Inventory.SerializedItems );

View File

@ -16,7 +16,7 @@ namespace Facepunch.Steamworks.Test
{
using ( var server = new Facepunch.Steamworks.Server( 252490, 30001, 30002, 30003, false, "VersionString" ) )
{
Assert.IsTrue( server.Valid );
Assert.IsTrue( server.IsValid );
}
}
@ -25,7 +25,7 @@ namespace Facepunch.Steamworks.Test
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
Assert.IsTrue( client.Valid );
Assert.IsTrue( client.IsValid );
var ticket = client.Auth.GetAuthSessionTicket();
var ticketBinary = ticket.Data;
@ -33,7 +33,7 @@ namespace Facepunch.Steamworks.Test
{
server.LogOnAnonymous();
Assert.IsTrue( server.Valid );
Assert.IsTrue( server.IsValid );
var auth = server.Auth;

View File

@ -12,7 +12,7 @@ namespace Facepunch.Steamworks.Test
{
using ( var server = new Facepunch.Steamworks.Server( 252490, 0, 30002, true, "VersionString" ) )
{
Assert.IsTrue( server.Valid );
Assert.IsTrue( server.IsValid );
server.LogOnAnonymous();
ulong MySteamId = 76561197960279927;

View File

@ -22,6 +22,20 @@ namespace Facepunch.Steamworks
}
}
public void SetupCommonInterfaces()
{
Networking = new Steamworks.Networking( this, native.networking );
Inventory = new Steamworks.Inventory( native.inventory, IsGameServer );
}
public bool IsValid
{
get { return native != null; }
}
public Networking Networking { get; internal set; }
public Inventory Inventory { get; internal set; }
internal Interop.NativeInterface native;
internal virtual bool IsGameServer { get { return false; } }
@ -43,5 +57,17 @@ namespace Facepunch.Steamworks
var callback = new Facepunch.Steamworks.Interop.Callback<T>( IsGameServer, id, Callback );
Disposables.Add( callback );
}
public Action OnUpdate;
public virtual void Update()
{
Inventory.Update();
Networking.Update();
if ( OnUpdate != null )
OnUpdate();
}
}
}

View File

@ -46,14 +46,17 @@ namespace Facepunch.Steamworks
return;
}
Networking = new Steamworks.Networking( this, native.networking );
//
// Set up warning hook callback
//
SteamAPIWarningMessageHook ptr = InternalOnWarning;
native.client.SetWarningMessageHook( Marshal.GetFunctionPointerForDelegate( ptr ) );
//
// Setup interfaces that client and server both have
//
SetupCommonInterfaces();
//
// Cache common, unchanging info
//
@ -68,17 +71,6 @@ namespace Facepunch.Steamworks
Update();
}
public override void Dispose()
{
if ( native != null)
{
native.Dispose();
native = null;
}
base.Dispose();
}
[UnmanagedFunctionPointer( CallingConvention.Cdecl )]
public delegate void SteamAPIWarningMessageHook( int nSeverity, System.Text.StringBuilder pchDebugText );
@ -90,43 +82,20 @@ namespace Facepunch.Steamworks
}
}
internal event Action OnUpdate;
/// <summary>
/// Should be called at least once every frame
/// </summary>
public void Update()
public override void Update()
{
if ( native == null )
if ( !IsValid )
return;
Valve.Steamworks.SteamAPI.RunCallbacks();
Voice.Update();
Inventory.Update();
Networking.Update();
if ( OnUpdate != null )
OnUpdate();
base.Update();
}
public bool Valid
{
get { return native != null; }
}
internal Action InstallCallback( int type, Delegate action )
{
var del = Marshal.GetFunctionPointerForDelegate( action );
// var ptr = Marshal.GetFunctionPointerForDelegate( action );
// Valve.Steamworks.SteamAPI.RegisterCallback( del, type );
// Valve.Steamworks.SteamAPI.UnregisterCallback( del );
//return () => Valve.Steamworks.SteamAPI.UnregisterCallback( ptr );
return null;
}
public Networking Networking { get; internal set; }
}
}

View File

@ -38,7 +38,7 @@ namespace Facepunch.Steamworks
/// </summary>
public void Cancel()
{
if ( client.Valid && Handle != 0 )
if ( client.IsValid && Handle != 0 )
{
client.native.user.CancelAuthTicket( Handle );
Handle = 0;

View File

@ -182,7 +182,7 @@ namespace Facepunch.Steamworks
//
if ( Id != IntPtr.Zero )
{
if ( client.Valid )
if ( client.IsValid )
client.native.servers.CancelQuery( Id );
Id = IntPtr.Zero;

View File

@ -116,8 +116,8 @@
<Compile Include="BaseSteamworks.cs" />
<Compile Include="Callbacks\Index.cs" />
<Compile Include="Callbacks\User.cs" />
<Compile Include="Client\Inventory.Item.cs" />
<Compile Include="Client\Inventory.Result.cs" />
<Compile Include="Interfaces\Inventory.Item.cs" />
<Compile Include="Interfaces\Inventory.Result.cs" />
<Compile Include="Interfaces\Networking.cs" />
<Compile Include="Client\Overlay.cs" />
<Compile Include="Client\ServerList.cs" />
@ -128,10 +128,10 @@
<Compile Include="Client\App.cs" />
<Compile Include="Client\Friends.cs" />
<Compile Include="Client\Image.cs" />
<Compile Include="Client\Inventory.cs" />
<Compile Include="Interfaces\Inventory.cs" />
<Compile Include="Client\Screenshots.cs" />
<Compile Include="Client\Stats.cs" />
<Compile Include="Client\Inventory.Definition.cs" />
<Compile Include="Interfaces\Inventory.Definition.cs" />
<Compile Include="Client\Voice.cs" />
<Compile Include="Config.cs" />
<Compile Include="Callbacks\Networking.cs" />
@ -142,7 +142,6 @@
<Compile Include="Interop\steam_api_interop.cs" />
<Compile Include="Server.cs" />
<Compile Include="Server\Auth.cs" />
<Compile Include="Server\Inventory.cs" />
<Compile Include="Server\Query.cs" />
<Compile Include="Server\Stats.cs" />
</ItemGroup>

View File

@ -6,22 +6,6 @@ using System.Text;
namespace Facepunch.Steamworks
{
public partial class Client : IDisposable
{
Inventory _inv;
public Inventory Inventory
{
get
{
if ( _inv == null )
_inv = new Inventory( native.inventory, false );
return _inv;
}
}
}
public partial class Inventory
{
/// <summary>
@ -133,7 +117,7 @@ namespace Facepunch.Steamworks
/// </summary>
internal void Update()
{
if ( Definitions == null )
if ( Definitions == null && !IsServer )
FetchItemDefinitions();
UpdateLocalRequest();
@ -222,6 +206,5 @@ namespace Facepunch.Steamworks
return new Result( this, resultHandle );
}
}
}
}

View File

@ -49,6 +49,11 @@ namespace Facepunch.Steamworks
var rr = GCHandle.Alloc( d );
native.utils.SetWarningMessageHook( d );
//
// Setup interfaces that client and server both have
//
SetupCommonInterfaces();
//
// Cache common, unchanging info
//
@ -89,29 +94,17 @@ namespace Facepunch.Steamworks
Console.WriteLine( "STEAM: {0}", text );
}
internal event Action OnUpdate;
/// <summary>
/// Should be called at least once every frame
/// </summary>
public void Update()
public override void Update()
{
if ( native == null )
if ( !IsValid )
return;
Valve.Interop.NativeEntrypoints.Extended.SteamGameServer_RunCallbacks();
Valve.Steamworks.SteamAPI.RunCallbacks();
// Voice.Update();
// Inventory.Update();
// Networking.Update();
if ( OnUpdate != null )
OnUpdate();
}
public bool Valid
{
get { return native != null; }
base.Update();
}
/// <summary>

View File

@ -1,25 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace Facepunch.Steamworks
{
public partial class Server
{
Inventory _inv;
public Inventory Inventory
{
get
{
if ( _inv == null )
_inv = new Inventory( native.inventory, true );
return _inv;
}
}
}
}