Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Commit

Permalink
- Removed GC (Full Credits to Punfish - Thank you)
Browse files Browse the repository at this point in the history
- Removed obsolete method
  • Loading branch information
TiToMoskito committed Jan 31, 2022
1 parent 31fa5c1 commit 6fc8212
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
5 changes: 4 additions & 1 deletion FishNet/Plugins/FishyFacepunch/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
- Organized folder structure
- Removed ChannelData
1.1.1
- FishNetworking 0.1.5.Nightly.10 Support
- FishNetworking 0.1.5.Nightly.10 Support
1.2.0
- Removed GC (Full Credits to Punfish - Thank you)
- Removed obsolete method
12 changes: 6 additions & 6 deletions FishNet/Plugins/FishyFacepunch/Core/ClientHostSocket.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#if !FishyFacepunch
using FishNet.Transporting;
using FishNet.Utility.Performance;
using FishyFacepunch.Server;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;

namespace FishyFacepunch.Client
{
Expand All @@ -20,7 +20,7 @@ public class ClientHostSocket : CommonSocket
/// <summary>
/// Incomimg data.
/// </summary>
private ConcurrentQueue<LocalPacket> _incoming = new ConcurrentQueue<LocalPacket>();
private Queue<LocalPacket> _incoming = new Queue<LocalPacket>();
#endregion

/// <summary>
Expand All @@ -36,7 +36,6 @@ internal void CheckSetStarted()
}
}


/// <summary>
/// Starts the client connection.
/// </summary>
Expand Down Expand Up @@ -75,7 +74,7 @@ internal bool StopConnection()
if (base.GetLocalConnectionState() == LocalConnectionStates.Stopped || base.GetLocalConnectionState() == LocalConnectionStates.Stopping)
return false;

while (_incoming.TryDequeue(out _)) ;
base.ClearQueue(_incoming);
//Immediately set stopped since no real connection exists.
SetLocalConnectionState(LocalConnectionStates.Stopping, false);
SetLocalConnectionState(LocalConnectionStates.Stopped, false);
Expand All @@ -92,11 +91,12 @@ internal void IterateIncoming()
if (base.GetLocalConnectionState() != LocalConnectionStates.Started)
return;

while (_incoming.TryDequeue(out LocalPacket packet))
while (_incoming.Count > 0)
{
LocalPacket packet = _incoming.Dequeue();
ArraySegment<byte> segment = new ArraySegment<byte>(packet.Data, 0, packet.Length);
base.Transport.HandleClientReceivedDataArgs(new ClientReceivedDataArgs(segment, (Channel)packet.Channel));
ByteArrayPool.Store(packet.Data);
packet.Dispose();
}
}

Expand Down
3 changes: 0 additions & 3 deletions FishNet/Plugins/FishyFacepunch/Core/ClientSocket.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if !FishyFacepunch
using FishNet.Managing;
using FishNet.Managing.Logging;
using FishNet.Transporting;
using Steamworks;
Expand Down Expand Up @@ -217,7 +216,6 @@ internal void SendToServer(byte channelId, ArraySegment<byte> segment)
}
}


/// <summary>
/// Sends queued data to server.
/// </summary>
Expand All @@ -228,7 +226,6 @@ internal void IterateOutgoing()

HostConnection.Flush();
}

}
}
#endif // !DISABLESTEAMWORKS
10 changes: 9 additions & 1 deletion FishNet/Plugins/FishyFacepunch/Core/CommonSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Steamworks;
using Steamworks.Data;
using System;
using System.Collections.Generic;
using System.Net;
using System.Runtime.InteropServices;
using UnityEngine;
Expand Down Expand Up @@ -67,6 +68,14 @@ protected virtual void SetLocalConnectionState(LocalConnectionStates connectionS
protected const int MAX_MESSAGES = 256;
#endregion

internal void ClearQueue(Queue<LocalPacket> lpq)
{
while (lpq.Count > 0)
{
LocalPacket lp = lpq.Dequeue();
lp.Dispose();
}
}
/// <summary>
/// Initializes this for use.
/// </summary>
Expand Down Expand Up @@ -164,6 +173,5 @@ protected Result Send(Connection conn, ArraySegment<byte> segment, byte channelI
return (managedArray, channel);
}
}

}
#endif
6 changes: 6 additions & 0 deletions FishNet/Plugins/FishyFacepunch/Core/LocalPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ public LocalPacket(ArraySegment<byte> data, byte channel)
Buffer.BlockCopy(data.Array, data.Offset, Data, 0, Length);
Channel = channel;
}

public void Dispose()
{
if (Data != null)
ByteArrayPool.Store(Data);
}
}
}
12 changes: 8 additions & 4 deletions FishNet/Plugins/FishyFacepunch/Core/ServerSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Steamworks;
using Steamworks.Data;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using UnityEngine;

Expand Down Expand Up @@ -59,7 +58,7 @@ internal RemoteConnectionStates GetConnectionState(int connectionId)
/// <summary>
/// Packets received from local client.
/// </summary>
private ConcurrentQueue<LocalPacket> _clientHostIncoming = new ConcurrentQueue<LocalPacket>();
private Queue<LocalPacket> _clientHostIncoming = new Queue<LocalPacket>();
/// <summary>
/// Socket for client host. Will be null if not being used.
/// </summary>
Expand Down Expand Up @@ -262,10 +261,12 @@ internal void IterateIncoming()
return;

//Iterate local client packets first.
while (_clientHostIncoming.TryDequeue(out LocalPacket packet))
while (_clientHostIncoming.Count > 0)
{
LocalPacket packet = _clientHostIncoming.Dequeue();
ArraySegment<byte> segment = new ArraySegment<byte>(packet.Data, 0, packet.Length);
base.Transport.HandleServerReceivedDataArgs(new ServerReceivedDataArgs(segment, (Channel)packet.Channel, FishyFacepunch.CLIENT_HOST_ID));
packet.Dispose();
}

_socket.Receive(MAX_MESSAGES);
Expand Down Expand Up @@ -370,7 +371,7 @@ internal void OnClientHostState(bool started)
//If not started flush incoming from local client.
if (!started)
{
while (_clientHostIncoming.TryDequeue(out _)) ;
base.ClearQueue(_clientHostIncoming);
base.Transport.HandleRemoteConnectionState(new RemoteConnectionStateArgs(RemoteConnectionStates.Stopped, FishyFacepunch.CLIENT_HOST_ID));
}
else
Expand All @@ -386,7 +387,10 @@ internal void OnClientHostState(bool started)
internal void ReceivedFromClientHost(LocalPacket packet)
{
if (!_clientHostStarted)
{
packet.Dispose();
return;
}

_clientHostIncoming.Enqueue(packet);
}
Expand Down
18 changes: 0 additions & 18 deletions FishNet/Plugins/FishyFacepunch/FishyFacepunch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ namespace FishyFacepunch
{
public class FishyFacepunch : Transport
{
#region Public.
/// <summary>
/// The SteamId for the local user after connecting to or starting the server. This is populated automatically.
/// </summary>
[Header("Info")]
//[System.NonSerialized]
public ulong LocalUserSteamID = 0;
#endregion

#region Serialized.
/// <summary>
/// Steam application Id.
Expand Down Expand Up @@ -133,7 +124,6 @@ private void InitializeRelayNetworkAccess()
{
#if !UNITY_SERVER
SteamNetworkingUtils.InitRelayNetworkAccess();
LocalUserSteamID = SteamClient.SteamId;
#endif
}
#endregion
Expand Down Expand Up @@ -498,14 +488,6 @@ private bool StopClient(int connectionId, bool immediately)

#region Channels.
/// <summary>
/// Returns how many channels the transport is using.
/// </summary>
/// <returns></returns>
public override byte GetChannelCount()
{
return (byte)_mtus.Length;
}
/// <summary>
/// Returns which channel to use by default for reliable.
/// </summary>
public override byte GetDefaultReliableChannel()
Expand Down
2 changes: 1 addition & 1 deletion FishNet/Plugins/FishyFacepunch/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.1
1.2.0

0 comments on commit 6fc8212

Please sign in to comment.