This commit is contained in:
Garry Newman 2016-11-03 13:53:06 +00:00
parent c27df08194
commit 2fef034547
3 changed files with 15 additions and 36 deletions

View File

@ -6,6 +6,9 @@ using Facepunch.Steamworks.Interop;
namespace Facepunch.Steamworks namespace Facepunch.Steamworks
{ {
/// <summary>
/// Implements shared functionality between Steamworks.Client and Steamworks.Server
/// </summary>
public class BaseSteamworks : IDisposable public class BaseSteamworks : IDisposable
{ {
/// <summary> /// <summary>
@ -17,6 +20,12 @@ namespace Facepunch.Steamworks
public Inventory Inventory { get; internal set; } public Inventory Inventory { get; internal set; }
public Workshop Workshop { get; internal set; } public Workshop Workshop { get; internal set; }
internal Action OnUpdate;
internal Interop.NativeInterface native;
private List<SteamNative.CallbackHandle> CallbackHandles = new List<SteamNative.CallbackHandle>();
public virtual void Dispose() public virtual void Dispose()
{ {
foreach ( var h in CallbackHandles ) foreach ( var h in CallbackHandles )
@ -50,42 +59,30 @@ namespace Facepunch.Steamworks
} }
} }
public void SetupCommonInterfaces() protected void SetupCommonInterfaces()
{ {
Networking = new Steamworks.Networking( this, native.networking ); Networking = new Steamworks.Networking( this, native.networking );
Inventory = new Steamworks.Inventory( native.inventory, IsGameServer ); Inventory = new Steamworks.Inventory( native.inventory, IsGameServer );
Workshop = new Steamworks.Workshop( this, native.ugc, native.remoteStorage ); Workshop = new Steamworks.Workshop( this, native.ugc, native.remoteStorage );
} }
/// <summary>
/// Returns true if this instance has initialized properly.
/// If this returns false you should Dispose and throw an error.
/// </summary>
public bool IsValid public bool IsValid
{ {
get { return native != null; } get { return native != null; }
} }
internal Interop.NativeInterface native;
internal virtual bool IsGameServer { get { return false; } } internal virtual bool IsGameServer { get { return false; } }
public enum MessageType : int
{
Message = 0,
Warning = 1
}
/// <summary>
/// Called with a message from Steam
/// </summary>
public Action<MessageType, string> OnMessage;
private List<SteamNative.CallbackHandle> CallbackHandles = new List<SteamNative.CallbackHandle>();
internal void RegisterCallbackHandle( SteamNative.CallbackHandle handle ) internal void RegisterCallbackHandle( SteamNative.CallbackHandle handle )
{ {
CallbackHandles.Add( handle ); CallbackHandles.Add( handle );
} }
public Action OnUpdate;
public virtual void Update() public virtual void Update()
{ {
Inventory.Update(); Inventory.Update();

View File

@ -63,14 +63,6 @@ namespace Facepunch.Steamworks
Update(); Update();
} }
private void InternalOnWarning( int nSeverity, System.Text.StringBuilder text )
{
if ( OnMessage != null )
{
OnMessage( ( MessageType)nSeverity, text.ToString() );
}
}
/// <summary> /// <summary>
/// Should be called at least once every frame /// Should be called at least once every frame
/// </summary> /// </summary>

View File

@ -81,16 +81,6 @@ namespace Facepunch.Steamworks
} }
private void InternalOnWarning( int nSeverity, string text )
{
if ( OnMessage != null )
{
OnMessage( ( MessageType)nSeverity, text.ToString() );
}
Console.WriteLine( "STEAM: {0}", text );
}
/// <summary> /// <summary>
/// Should be called at least once every frame /// Should be called at least once every frame
/// </summary> /// </summary>