Skip to content

Commit

Permalink
Merge from fix_serverlist_query_allocations -> master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Rich committed Aug 14, 2024
2 parents 62a1ae7 + 7f747b0 commit eec3c05
Show file tree
Hide file tree
Showing 38 changed files with 88 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Facepunch.Steamworks/Generated/Interfaces/ISteamAppList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamAppList : SteamInterface
internal unsafe partial class ISteamAppList : SteamInterface
{

internal ISteamAppList( bool IsGameServer )
Expand Down
2 changes: 1 addition & 1 deletion Facepunch.Steamworks/Generated/Interfaces/ISteamApps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamApps : SteamInterface
internal unsafe partial class ISteamApps : SteamInterface
{

internal ISteamApps( bool IsGameServer )
Expand Down
2 changes: 1 addition & 1 deletion Facepunch.Steamworks/Generated/Interfaces/ISteamClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamClient : SteamInterface
internal unsafe partial class ISteamClient : SteamInterface
{

internal ISteamClient( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamController : SteamInterface
internal unsafe partial class ISteamController : SteamInterface
{

internal ISteamController( bool IsGameServer )
Expand Down
2 changes: 1 addition & 1 deletion Facepunch.Steamworks/Generated/Interfaces/ISteamFriends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamFriends : SteamInterface
internal unsafe partial class ISteamFriends : SteamInterface
{

internal ISteamFriends( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamGameSearch : SteamInterface
internal unsafe partial class ISteamGameSearch : SteamInterface
{

internal ISteamGameSearch( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamGameServer : SteamInterface
internal unsafe partial class ISteamGameServer : SteamInterface
{

internal ISteamGameServer( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamGameServerStats : SteamInterface
internal unsafe partial class ISteamGameServerStats : SteamInterface
{

internal ISteamGameServerStats( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamHTMLSurface : SteamInterface
internal unsafe partial class ISteamHTMLSurface : SteamInterface
{

internal ISteamHTMLSurface( bool IsGameServer )
Expand Down
2 changes: 1 addition & 1 deletion Facepunch.Steamworks/Generated/Interfaces/ISteamHTTP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamHTTP : SteamInterface
internal unsafe partial class ISteamHTTP : SteamInterface
{

internal ISteamHTTP( bool IsGameServer )
Expand Down
2 changes: 1 addition & 1 deletion Facepunch.Steamworks/Generated/Interfaces/ISteamInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamInput : SteamInterface
internal unsafe partial class ISteamInput : SteamInterface
{

internal ISteamInput( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamInventory : SteamInterface
internal unsafe partial class ISteamInventory : SteamInterface
{

internal ISteamInventory( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamMatchmaking : SteamInterface
internal unsafe partial class ISteamMatchmaking : SteamInterface
{

internal ISteamMatchmaking( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamMatchmakingPingResponse : SteamInterface
internal unsafe partial class ISteamMatchmakingPingResponse : SteamInterface
{

internal ISteamMatchmakingPingResponse( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamMatchmakingPlayersResponse : SteamInterface
internal unsafe partial class ISteamMatchmakingPlayersResponse : SteamInterface
{

internal ISteamMatchmakingPlayersResponse( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamMatchmakingRulesResponse : SteamInterface
internal unsafe partial class ISteamMatchmakingRulesResponse : SteamInterface
{

internal ISteamMatchmakingRulesResponse( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamMatchmakingServerListResponse : SteamInterface
internal unsafe partial class ISteamMatchmakingServerListResponse : SteamInterface
{

internal ISteamMatchmakingServerListResponse( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamMatchmakingServers : SteamInterface
internal unsafe partial class ISteamMatchmakingServers : SteamInterface
{

internal ISteamMatchmakingServers( bool IsGameServer )
Expand Down
2 changes: 1 addition & 1 deletion Facepunch.Steamworks/Generated/Interfaces/ISteamMusic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamMusic : SteamInterface
internal unsafe partial class ISteamMusic : SteamInterface
{

internal ISteamMusic( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamMusicRemote : SteamInterface
internal unsafe partial class ISteamMusicRemote : SteamInterface
{

internal ISteamMusicRemote( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamNetworking : SteamInterface
internal unsafe partial class ISteamNetworking : SteamInterface
{

internal ISteamNetworking( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamNetworkingFakeUDPPort : SteamInterface
internal unsafe partial class ISteamNetworkingFakeUDPPort : SteamInterface
{

internal ISteamNetworkingFakeUDPPort( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamNetworkingMessages : SteamInterface
internal unsafe partial class ISteamNetworkingMessages : SteamInterface
{

internal ISteamNetworkingMessages( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamNetworkingSockets : SteamInterface
internal unsafe partial class ISteamNetworkingSockets : SteamInterface
{

internal ISteamNetworkingSockets( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamNetworkingUtils : SteamInterface
internal unsafe partial class ISteamNetworkingUtils : SteamInterface
{

internal ISteamNetworkingUtils( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamParentalSettings : SteamInterface
internal unsafe partial class ISteamParentalSettings : SteamInterface
{

internal ISteamParentalSettings( bool IsGameServer )
Expand Down
2 changes: 1 addition & 1 deletion Facepunch.Steamworks/Generated/Interfaces/ISteamParties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamParties : SteamInterface
internal unsafe partial class ISteamParties : SteamInterface
{

internal ISteamParties( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamRemotePlay : SteamInterface
internal unsafe partial class ISteamRemotePlay : SteamInterface
{

internal ISteamRemotePlay( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamRemoteStorage : SteamInterface
internal unsafe partial class ISteamRemoteStorage : SteamInterface
{

internal ISteamRemoteStorage( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamScreenshots : SteamInterface
internal unsafe partial class ISteamScreenshots : SteamInterface
{

internal ISteamScreenshots( bool IsGameServer )
Expand Down
2 changes: 1 addition & 1 deletion Facepunch.Steamworks/Generated/Interfaces/ISteamUGC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamUGC : SteamInterface
internal unsafe partial class ISteamUGC : SteamInterface
{

internal ISteamUGC( bool IsGameServer )
Expand Down
2 changes: 1 addition & 1 deletion Facepunch.Steamworks/Generated/Interfaces/ISteamUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamUser : SteamInterface
internal unsafe partial class ISteamUser : SteamInterface
{

internal ISteamUser( bool IsGameServer )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamUserStats : SteamInterface
internal unsafe partial class ISteamUserStats : SteamInterface
{

internal ISteamUserStats( bool IsGameServer )
Expand Down
2 changes: 1 addition & 1 deletion Facepunch.Steamworks/Generated/Interfaces/ISteamUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamUtils : SteamInterface
internal unsafe partial class ISteamUtils : SteamInterface
{

internal ISteamUtils( bool IsGameServer )
Expand Down
2 changes: 1 addition & 1 deletion Facepunch.Steamworks/Generated/Interfaces/ISteamVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Steamworks
{
internal unsafe class ISteamVideo : SteamInterface
internal unsafe partial class ISteamVideo : SteamInterface
{

internal ISteamVideo( bool IsGameServer )
Expand Down
42 changes: 42 additions & 0 deletions Facepunch.Steamworks/Interfaces/ISteamMatchmakingServers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Steamworks.Data;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace Steamworks
{
internal partial class ISteamMatchmakingServers
{
// Cached offset of gameserveritem_t.m_bHadSuccessfulResponse
private static int hasSuccessfulResponseOffset;

/// <summary>
/// Read gameserveritem_t.m_bHadSuccessfulResponse without allocating the struct on the heap
/// </summary>
/// <param name="hRequest"></param>
/// <param name="iServer"></param>
/// <returns></returns>
internal bool HasServerResponded( HServerListRequest hRequest, int iServer )
{
IntPtr returnValue = _GetServerDetails( Self, hRequest, iServer );

// Return false if steam returned null
if ( returnValue == IntPtr.Zero ) return false;

// Cache the offset of m_bHadSuccessfulResponse
if ( hasSuccessfulResponseOffset == 0 )
{
hasSuccessfulResponseOffset = Marshal.OffsetOf<gameserveritem_t>( nameof( gameserveritem_t.HadSuccessfulResponse ) ).ToInt32();

if ( hasSuccessfulResponseOffset == 0 )
{
throw new Exception( "Failed to get offset of gameserveritem_t.HadSuccessfulResponse" );
}
}

// Read byte m_bHadSuccessfulResponse
return Marshal.ReadByte( IntPtr.Add( returnValue, hasSuccessfulResponseOffset ) ) == 1;
}
}
}
14 changes: 10 additions & 4 deletions Facepunch.Steamworks/ServerList/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,17 @@ public void UpdateResponsive()
{
watchList.RemoveAll( x =>
{
var info = Internal.GetServerDetails( request, x );
if ( info.HadSuccessfulResponse )
// First check if the server has responded without allocating server info
bool hasResponded = Internal.HasServerResponded( request, x );
if ( hasResponded )
{
OnServer( ServerInfo.From( info ), info.HadSuccessfulResponse );
return true;
// Now get all server info
var info = Internal.GetServerDetails( request, x );
if ( info.HadSuccessfulResponse )
{
OnServer( ServerInfo.From( info ), info.HadSuccessfulResponse );
return true;
}
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion Generator/CodeWriter/Interface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void GenerateInterface( SteamApiDefinition.Interface iface, string folder

StartBlock( $"namespace Steamworks" );
{
StartBlock( $"internal unsafe class {iface.Name} : SteamInterface" );
StartBlock( $"internal unsafe partial class {iface.Name} : SteamInterface" );
{
WriteLine();
StartBlock( $"internal {iface.Name}( bool IsGameServer )" );
Expand Down

0 comments on commit eec3c05

Please sign in to comment.