mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Add method to clear networked resources. (#4096)
This commit is contained in:
@@ -19,7 +19,8 @@ public interface IReplayLoadManager
|
||||
public MappingDataNode? LoadYamlMetadata(IWritableDirProvider dir, ResPath path);
|
||||
|
||||
/// <summary>
|
||||
/// Async task that loads up a replay for playback.
|
||||
/// Async task that loads up a replay for playback. Note that this will have some side effects, such as loading
|
||||
/// networked resources and prototypes. These resources are not tracked or automatically unloaded.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This task is intended to be used with a <see cref="Job{T}"/> so that the loading can happen over several frame
|
||||
@@ -34,7 +35,9 @@ public interface IReplayLoadManager
|
||||
Task<ReplayData> LoadReplayAsync(IWritableDirProvider dir, ResPath path, LoadReplayCallback callback);
|
||||
|
||||
/// <summary>
|
||||
/// Async task that loads the initial state of a replay, including spawning & initializing all entities.
|
||||
/// Async task that loads the initial state of a replay, including spawning & initializing all entities. Note that
|
||||
/// this will have some side effects, such as loading networked resources and prototypes. These resources are not
|
||||
/// tracked or automatically unloaded.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This task is intended to be used with a <see cref="Job{T}"/> so that the loading can happen over several frame
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Upload;
|
||||
|
||||
namespace Robust.Client.Upload;
|
||||
|
||||
public sealed class NetworkResourceManager : SharedNetworkResourceManager
|
||||
{
|
||||
[Dependency] private readonly IBaseClient _client = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_client.RunLevelChanged += OnLevelChanged;
|
||||
}
|
||||
|
||||
private void OnLevelChanged(object? sender, RunLevelChangedEventArgs e)
|
||||
{
|
||||
// Clear networked resources when disconnecting from a multiplayer game.
|
||||
if (e.OldLevel == ClientRunLevel.InGame)
|
||||
ClearResources();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback for when the server sends a new resource.
|
||||
/// </summary>
|
||||
@@ -12,4 +28,12 @@ public sealed class NetworkResourceManager : SharedNetworkResourceManager
|
||||
{
|
||||
ContentRoot.AddOrUpdateFile(msg.RelativePath, msg.Data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all the networked resources. If used while connected to a server, this will probably cause issues.
|
||||
/// </summary>
|
||||
public void ClearResources()
|
||||
{
|
||||
ContentRoot.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,22 @@ public sealed class MemoryContentRoot : IContentRoot, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes ALL files from this content root.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
_lock.EnterWriteLock();
|
||||
try
|
||||
{
|
||||
_files.Clear();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lock.ExitWriteLock();
|
||||
}
|
||||
}
|
||||
|
||||
public bool FileExists(ResPath relPath)
|
||||
{
|
||||
_lock.EnterReadLock();
|
||||
|
||||
Reference in New Issue
Block a user