Make preevolutioncache and item script containers concurrent
Build / Build (push) Successful in 10m56s
Build / Build (push) Successful in 10m56s
This commit is contained in:
3 files changed
+10
-10
No files matched your search
@@ -28,7 +28,7 @@ public class ScriptRegistry
|
|||||||
public void RegisterAssemblyScripts(Assembly assembly)
|
public void RegisterAssemblyScripts(Assembly assembly)
|
||||||
{
|
{
|
||||||
var baseType = typeof(Script);
|
var baseType = typeof(Script);
|
||||||
foreach (var type in assembly.GetTypes().Where(t => baseType.IsAssignableFrom(t)))
|
foreach (var type in assembly.GetTypes().Where(baseType.IsAssignableFrom))
|
||||||
{
|
{
|
||||||
var attribute = type.GetCustomAttribute<ScriptAttribute>();
|
var attribute = type.GetCustomAttribute<ScriptAttribute>();
|
||||||
if (attribute == null)
|
if (attribute == null)
|
||||||
@@ -37,7 +37,7 @@ public class ScriptRegistry
|
|||||||
RegisterScriptType(attribute.Category, attribute.Name, type);
|
RegisterScriptType(attribute.Category, attribute.Name, type);
|
||||||
}
|
}
|
||||||
var itemBaseType = typeof(ItemScript);
|
var itemBaseType = typeof(ItemScript);
|
||||||
foreach (var type in assembly.GetTypes().Where(t => itemBaseType.IsAssignableFrom(t)))
|
foreach (var type in assembly.GetTypes().Where(itemBaseType.IsAssignableFrom))
|
||||||
{
|
{
|
||||||
var attribute = type.GetCustomAttribute<ItemScriptAttribute>();
|
var attribute = type.GetCustomAttribute<ItemScriptAttribute>();
|
||||||
if (attribute == null)
|
if (attribute == null)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using PkmnLib.Static;
|
using PkmnLib.Static;
|
||||||
using PkmnLib.Static.Utils;
|
using PkmnLib.Static.Utils;
|
||||||
@@ -9,10 +10,10 @@ namespace PkmnLib.Dynamic.ScriptHandling;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ScriptResolver
|
public class ScriptResolver
|
||||||
{
|
{
|
||||||
private IReadOnlyDictionary<(ScriptCategory, StringKey), Func<Script>> _scriptCtors;
|
private readonly IReadOnlyDictionary<(ScriptCategory, StringKey), Func<Script>> _scriptCtors;
|
||||||
private IReadOnlyDictionary<StringKey, Func<IItem, ItemScript>> _itemScriptCtors;
|
private readonly IReadOnlyDictionary<StringKey, Func<IItem, ItemScript>> _itemScriptCtors;
|
||||||
private readonly Dictionary<IItem, ItemScript> _itemBattleScripts = new();
|
private readonly ConcurrentDictionary<IItem, ItemScript> _itemBattleScripts = new();
|
||||||
private readonly Dictionary<IItem, ItemScript> _itemScripts = new();
|
private readonly ConcurrentDictionary<IItem, ItemScript> _itemScripts = new();
|
||||||
|
|
||||||
/// <inheritdoc cref="ScriptResolver"/>
|
/// <inheritdoc cref="ScriptResolver"/>
|
||||||
public ScriptResolver(IReadOnlyDictionary<(ScriptCategory, StringKey), Func<Script>> scriptCtors,
|
public ScriptResolver(IReadOnlyDictionary<(ScriptCategory, StringKey), Func<Script>> scriptCtors,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using PkmnLib.Static.Species;
|
using PkmnLib.Static.Species;
|
||||||
using PkmnLib.Static.Utils;
|
using PkmnLib.Static.Utils;
|
||||||
@@ -44,14 +45,12 @@ public interface IReadOnlySpeciesLibrary : IEnumerable<ISpecies>
|
|||||||
/// <inheritdoc cref="IReadOnlySpeciesLibrary"/>
|
/// <inheritdoc cref="IReadOnlySpeciesLibrary"/>
|
||||||
public class SpeciesLibrary : DataLibrary<ISpecies>, IReadOnlySpeciesLibrary
|
public class SpeciesLibrary : DataLibrary<ISpecies>, IReadOnlySpeciesLibrary
|
||||||
{
|
{
|
||||||
private Dictionary<ISpecies, ISpecies> _preEvolutionCache = new();
|
private readonly ConcurrentDictionary<ISpecies, ISpecies> _preEvolutionCache = new();
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool TryGetById(int id, [MaybeNullWhen(false)] out ISpecies value)
|
public bool TryGetById(int id, [MaybeNullWhen(false)] out ISpecies value)
|
||||||
{
|
{
|
||||||
return this.FirstOrDefault(s => s.Id == id) is { } species
|
return this.FirstOrDefault(s => s.Id == id) is { } species ? (value = species) != null : (value = null) != null;
|
||||||
? (value = species) != null
|
|
||||||
: (value = default) != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
Reference in new issue
Block a user