Minor performance tweaks

This commit is contained in:
Asriel Camora
2023-07-14 22:54:53 +04:00
parent 86daf038ce
commit 79377b5e89
3 changed files with 19 additions and 2 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ public sealed partial class SimulatorWindow : Window, IDisposable
SolverInitialActionCount = Actions.Count;
SolverTaskToken = new();
Func<SolverConfig, SimulationState, Action<ActionType>?, CancellationToken, (List<ActionType> Actions, SimulationState State)> solverMethod = Configuration.SolverAlgorithm switch
Func<SolverConfig, SimulationState, Action<ActionType>?, CancellationToken, SolverSolution> solverMethod = Configuration.SolverAlgorithm switch
{
SolverAlgorithm.Oneshot => Solver.Crafty.Solver.SearchOneshot,
SolverAlgorithm.OneshotForked => Solver.Crafty.Solver.SearchOneshotForked,
+1 -1
View File
@@ -86,7 +86,7 @@ public struct Effects
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly byte GetStrength(EffectType effect) =>
effect == EffectType.InnerQuiet ? InnerQuiet :
(byte)(GetDuration(effect) != 0 ? 1 : 0);
(byte)(HasEffect(effect) ? 1 : 0);
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
+17
View File
@@ -1,4 +1,6 @@
using Craftimizer.Simulator.Actions;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace Craftimizer.Simulator;
@@ -62,6 +64,7 @@ public class Simulator
return ActionResponse.UsedAction;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ExecuteForced(ActionType action, BaseAction baseAction)
{
baseAction.Use(this);
@@ -71,9 +74,13 @@ public class Simulator
ActiveEffects.DecrementDuration();
}
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int GetEffectStrength(EffectType effect) =>
ActiveEffects.GetStrength(effect);
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int GetEffectDuration(EffectType effect) =>
ActiveEffects.GetDuration(effect);
@@ -88,12 +95,16 @@ public class Simulator
ActiveEffects.SetDuration(effect, (byte)duration);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void StrengthenEffect(EffectType effect) =>
ActiveEffects.Strengthen(effect);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void RemoveEffect(EffectType effect) =>
ActiveEffects.SetDuration(effect, 0);
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool HasEffect(EffectType effect) =>
ActiveEffects.HasEffect(effect);
@@ -235,9 +246,11 @@ public class Simulator
return qualityGain;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ReduceDurabilityRaw(int amount) =>
Durability -= amount;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ReduceCPRaw(int amount) =>
CP -= amount;
@@ -260,15 +273,19 @@ public class Simulator
StrengthenEffect(EffectType.InnerQuiet);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ReduceDurability(int amount) =>
ReduceDurabilityRaw(CalculateDurabilityCost(amount));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ReduceCP(int amount) =>
ReduceCPRaw(CalculateCPCost(amount));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void IncreaseProgress(float efficiency) =>
IncreaseProgressRaw(CalculateProgressGain(efficiency, false));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void IncreaseQuality(float efficiency) =>
IncreaseQualityRaw(CalculateQualityGain(efficiency, false));