From 2f078e6565cf7bd5a46f0956480b3537ed293bba Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 20 Apr 2021 01:02:32 -0700 Subject: [PATCH] Minor tweaks Make HP IV set use single array fetch, less memory required add some xmldoc --- PKHeX.Core/Editing/HiddenPower.cs | 38 ++++++++++--------- .../Legality/Moves/Breeding/MoveBreed6.cs | 4 +- PKHeX.Core/Legality/Moves/LearnInfo.cs | 1 - PKHeX.Core/Legality/Structures/IVersion.cs | 6 +++ PKHeX.Core/PKM/PKM.cs | 15 ++++---- PKHeX.Core/PKM/Shared/IGeneration.cs | 6 +++ 6 files changed, 43 insertions(+), 27 deletions(-) diff --git a/PKHeX.Core/Editing/HiddenPower.cs b/PKHeX.Core/Editing/HiddenPower.cs index 3af7c1007..66a340821 100644 --- a/PKHeX.Core/Editing/HiddenPower.cs +++ b/PKHeX.Core/Editing/HiddenPower.cs @@ -157,8 +157,10 @@ public static int[] SetIVs(int type, int[] ivs, int format = PKX.Generation) ivs[2] = (ivs[2] & ~3) | (type & 3); return ivs; } + + var bits = DefaultLowBits[type]; for (int i = 0; i < 6; i++) - ivs[i] = (ivs[i] & 0x1E) + DefaultLowBits[type, i]; + ivs[i] = (ivs[i] & 0x1E) + ((bits >> i) & 1); return ivs; } @@ -170,24 +172,24 @@ public static int[] SetIVs(int type, int[] ivs, int format = PKX.Generation) /// These are just precomputed for fast modification. /// Individual Values (H/A/B/S/C/D) /// - public static readonly byte[,] DefaultLowBits = + public static readonly byte[] DefaultLowBits = { - { 1, 1, 0, 0, 0, 0 }, // Fighting - { 0, 0, 0, 1, 0, 0 }, // Flying - { 1, 1, 0, 1, 0, 0 }, // Poison - { 1, 1, 1, 1, 0, 0 }, // Ground - { 1, 1, 0, 0, 1, 0 }, // Rock - { 1, 0, 0, 1, 1, 0 }, // Bug - { 1, 0, 1, 1, 1, 0 }, // Ghost - { 1, 1, 1, 1, 1, 0 }, // Steel - { 1, 0, 1, 0, 0, 1 }, // Fire - { 1, 0, 0, 1, 0, 1 }, // Water - { 1, 0, 1, 1, 0, 1 }, // Grass - { 1, 1, 1, 1, 0, 1 }, // Electric - { 1, 0, 1, 0, 1, 1 }, // Psychic - { 1, 0, 0, 1, 1, 1 }, // Ice - { 1, 0, 1, 1, 1, 1 }, // Dragon - { 1, 1, 1, 1, 1, 1 }, // Dark + 0b000011, // Fighting + 0b001000, // Flying + 0b001011, // Poison + 0b001111, // Ground + 0b010011, // Rock + 0b011001, // Bug + 0b011101, // Ghost + 0b011111, // Steel + 0b100101, // Fire + 0b101001, // Water + 0b101101, // Grass + 0b101111, // Electric + 0b110101, // Psychic + 0b111001, // Ice + 0b111101, // Dragon + 0b111111, // Dark }; } } diff --git a/PKHeX.Core/Legality/Moves/Breeding/MoveBreed6.cs b/PKHeX.Core/Legality/Moves/Breeding/MoveBreed6.cs index f4f0ad097..10fa9f34a 100644 --- a/PKHeX.Core/Legality/Moves/Breeding/MoveBreed6.cs +++ b/PKHeX.Core/Legality/Moves/Breeding/MoveBreed6.cs @@ -11,6 +11,8 @@ namespace PKHeX.Core /// Refer to for inheritance ordering. public static class MoveBreed6 { + private const int level = 1; + public static EggSource6[] Validate(int generation, int species, int form, GameVersion version, int[] moves, out bool valid) { var count = Array.IndexOf(moves, 0); @@ -28,7 +30,7 @@ public static EggSource6[] Validate(int generation, int species, int form, GameV var learnset = learn[index]; var egg = MoveEgg.GetEggMoves(generation, species, form, version); - var value = new BreedInfo(count, learnset, moves, 1); + var value = new BreedInfo(count, learnset, moves, level); if (moves[count - 1] is (int)Move.VoltTackle) value.Actual[--count] = VoltTackle; diff --git a/PKHeX.Core/Legality/Moves/LearnInfo.cs b/PKHeX.Core/Legality/Moves/LearnInfo.cs index 696ce105e..52b1536f1 100644 --- a/PKHeX.Core/Legality/Moves/LearnInfo.cs +++ b/PKHeX.Core/Legality/Moves/LearnInfo.cs @@ -10,7 +10,6 @@ internal sealed class LearnInfo public List EggMovesLearned { get; } = new(); public List LevelUpEggMoves { get; } = new(); public List EventEggMoves { get; } = new(); - public List IncenseMoves { get; } = new(); public readonly MoveParseSource Source; public readonly bool IsGen2Pkm; diff --git a/PKHeX.Core/Legality/Structures/IVersion.cs b/PKHeX.Core/Legality/Structures/IVersion.cs index 65fe87dc4..03021cb25 100644 --- a/PKHeX.Core/Legality/Structures/IVersion.cs +++ b/PKHeX.Core/Legality/Structures/IVersion.cs @@ -1,7 +1,13 @@ namespace PKHeX.Core { + /// + /// Interface that exposes a to see which version the data originated in. + /// public interface IVersion { + /// + /// The version the data originated in. + /// GameVersion Version { get; } } diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index 57129b2b3..f5e7c9981 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -491,13 +491,14 @@ public virtual int HPType get => 15 * HPBitValType / 63; set { - var dlb = HiddenPower.DefaultLowBits; - IV_HP = (IV_HP & ~1) + dlb[value, 0]; - IV_ATK = (IV_ATK & ~1) + dlb[value, 1]; - IV_DEF = (IV_DEF & ~1) + dlb[value, 2]; - IV_SPE = (IV_SPE & ~1) + dlb[value, 3]; - IV_SPA = (IV_SPA & ~1) + dlb[value, 4]; - IV_SPD = (IV_SPD & ~1) + dlb[value, 5]; + var arr = HiddenPower.DefaultLowBits; + var bits = (uint)value >= arr.Length ? 0 : arr[value]; + IV_HP = (IV_HP & ~1) + ((bits >> 0) & 1); + IV_ATK = (IV_ATK & ~1) + ((bits >> 1) & 1); + IV_DEF = (IV_DEF & ~1) + ((bits >> 2) & 1); + IV_SPE = (IV_SPE & ~1) + ((bits >> 3) & 1); + IV_SPA = (IV_SPA & ~1) + ((bits >> 4) & 1); + IV_SPD = (IV_SPD & ~1) + ((bits >> 5) & 1); } } diff --git a/PKHeX.Core/PKM/Shared/IGeneration.cs b/PKHeX.Core/PKM/Shared/IGeneration.cs index afbc3e003..32c616d17 100644 --- a/PKHeX.Core/PKM/Shared/IGeneration.cs +++ b/PKHeX.Core/PKM/Shared/IGeneration.cs @@ -1,7 +1,13 @@ namespace PKHeX.Core { + /// + /// Interface that exposes a to see which canonical generation the data originated in. + /// public interface IGeneration { + /// + /// The canonical generation the data originated in. + /// int Generation { get; } } }