-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from ethanmoffat/reduce_async
Reduce async calls and disable vsync and fixed timestep. Fixes performance issues transitioning to in-game state.
- Loading branch information
Showing
23 changed files
with
255 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,44 @@ | ||
using System; | ||
using System.Threading; | ||
using AutomaticTypeMapper; | ||
using EOLib.Net.Communication; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace EOLib.Net.Connection | ||
{ | ||
[AutoMappedType] | ||
public class BackgroundReceiveActions : IBackgroundReceiveActions | ||
{ | ||
private readonly INetworkClientProvider _clientProvider; | ||
private readonly IBackgroundReceiveThreadRepository _backgroundReceiveThreadRepository; | ||
private readonly IBackgroundReceiveTaskRepository _backgroundReceiveTaskRepository; | ||
|
||
public BackgroundReceiveActions(INetworkClientProvider clientProvider, | ||
IBackgroundReceiveThreadRepository backgroundReceiveThreadRepository) | ||
IBackgroundReceiveTaskRepository backgroundReceiveThreadRepository) | ||
{ | ||
_clientProvider = clientProvider; | ||
_backgroundReceiveThreadRepository = backgroundReceiveThreadRepository; | ||
_backgroundReceiveThreadRepository.BackgroundThreadObject = new Thread(BackgroundLoop); | ||
_backgroundReceiveTaskRepository = backgroundReceiveThreadRepository; | ||
} | ||
|
||
public void RunBackgroundReceiveLoop() | ||
{ | ||
if (_backgroundReceiveThreadRepository.BackgroundThreadRunning) | ||
if (_backgroundReceiveTaskRepository.Task != null) | ||
return; | ||
|
||
_backgroundReceiveThreadRepository.BackgroundThreadObject.Start(); | ||
_backgroundReceiveThreadRepository.BackgroundThreadRunning = true; | ||
_backgroundReceiveTaskRepository.BackgroundCancellationTokenSource = new CancellationTokenSource(); | ||
_backgroundReceiveTaskRepository.Task = Task.Run(RunLoop, _backgroundReceiveTaskRepository.BackgroundCancellationTokenSource.Token); | ||
} | ||
|
||
public void CancelBackgroundReceiveLoop() | ||
{ | ||
if (!_backgroundReceiveThreadRepository.BackgroundThreadRunning) | ||
return; | ||
_backgroundReceiveTaskRepository.BackgroundCancellationTokenSource?.Cancel(); | ||
_backgroundReceiveTaskRepository.BackgroundCancellationTokenSource?.Dispose(); | ||
_backgroundReceiveTaskRepository.BackgroundCancellationTokenSource = null; | ||
|
||
Client.CancelBackgroundReceiveLoop(); | ||
|
||
if (_backgroundReceiveThreadRepository.BackgroundThreadObject.ThreadState == ThreadState.Running) | ||
_backgroundReceiveThreadRepository.BackgroundThreadObject.Join(); | ||
_backgroundReceiveThreadRepository.BackgroundThreadObject = new Thread(BackgroundLoop); | ||
_backgroundReceiveThreadRepository.BackgroundThreadRunning = false; | ||
_backgroundReceiveTaskRepository.Task = null; | ||
} | ||
|
||
private async void BackgroundLoop() | ||
private Task RunLoop() | ||
{ | ||
await Client.RunReceiveLoopAsync().ConfigureAwait(false); | ||
return _clientProvider.NetworkClient.RunReceiveLoopAsync(_backgroundReceiveTaskRepository.BackgroundCancellationTokenSource.Token); | ||
} | ||
|
||
private INetworkClient Client => _clientProvider.NetworkClient; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using AutomaticTypeMapper; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace EOLib.Net.Connection | ||
{ | ||
public interface IBackgroundReceiveTaskRepository | ||
{ | ||
Task Task { get; set; } | ||
|
||
CancellationTokenSource BackgroundCancellationTokenSource { get; set; } | ||
} | ||
|
||
[AutoMappedType(IsSingleton = true)] | ||
public class BackgroundReceiveThreadRepository : IBackgroundReceiveTaskRepository | ||
{ | ||
public Task Task { get; set; } | ||
|
||
public CancellationTokenSource BackgroundCancellationTokenSource { get; set; } | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
EOLib/Net/Connection/IBackgroundReceiveThreadRepository.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.