mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 06:20:25 +00:00
3c232505e5
In this pull request I've changed a ton of method signatures to reflect the more-narrow types of Species, Move# and Form; additionally, I've narrowed other large collections that stored lists of species / permitted values, and reworked them to be more performant with the latest API spaghetti that PKHeX provides. Roamer met locations, usually in a range of [max-min]<64, can be quickly checked using a bitflag operation on a UInt64. Other collections (like "Is this from Colosseum or XD") were eliminated -- shadow state is not transferred COLO<->XD, so having a Shadow ID or matching the met location from a gift/wild encounter is a sufficient check for "originated in XD".
40 lines
1.5 KiB
C#
40 lines
1.5 KiB
C#
using System;
|
|
using System.Buffers;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Caches move learn data via <see cref="ReloadMoves"/>
|
|
/// </summary>
|
|
public sealed class LegalMoveInfo
|
|
{
|
|
// Use a bool array instead of a HashSet; we have a limited range of moves.
|
|
// This implementation is faster (no hashcode or bucket search) with lower memory overhead (1 byte per move ID).
|
|
private readonly bool[] AllowedMoves = new bool[(int)Move.MAX_COUNT + 1];
|
|
|
|
/// <summary>
|
|
/// Checks if the requested <see cref="move"/> is legally able to be learned.
|
|
/// </summary>
|
|
/// <param name="move">Move to check if can be learned</param>
|
|
/// <returns>True if can learn the move</returns>
|
|
public bool CanLearn(ushort move) => AllowedMoves[move];
|
|
|
|
/// <summary>
|
|
/// Reloads the legality sources to permit the provided legal info.
|
|
/// </summary>
|
|
/// <param name="la">Details of analysis, moves to allow</param>
|
|
public bool ReloadMoves(LegalityAnalysis la)
|
|
{
|
|
var rent = ArrayPool<bool>.Shared.Rent(AllowedMoves.Length);
|
|
var span = rent.AsSpan(0, AllowedMoves.Length);
|
|
LearnPossible.Get(la.Entity, la.EncounterOriginal, la.Info.EvoChainsAllGens, span);
|
|
|
|
// check prior move-pool to not needlessly refresh the data set
|
|
bool diff = !span.SequenceEqual(AllowedMoves);
|
|
if (diff) // keep
|
|
span.CopyTo(AllowedMoves);
|
|
span.Clear();
|
|
ArrayPool<bool>.Shared.Return(rent);
|
|
return diff;
|
|
}
|
|
}
|