Skip to content

Commit d3caaa5

Browse files
committed
remove redundant comments
1 parent 992186c commit d3caaa5

2 files changed

Lines changed: 10 additions & 112 deletions

File tree

SerialPrograms/Source/Pokemon/Pokemon_BdspRng.cpp

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,12 @@ namespace PokemonAutomation{
1515
namespace Pokemon{
1616

1717

18-
// Big enough that a generation can never read past the values the window holds.
19-
// The size has no effect on results; it is purely a cache.
18+
2019
const size_t STATIC_SEARCH_WINDOW = 64;
2120

22-
// How often a long search checks whether the user has stopped the program.
2321
const uint64_t CANCEL_CHECK_INTERVAL = 65536;
2422

2523

26-
27-
//
28-
// Xoroshiro128+, BDSP flavor
29-
//
30-
3124
uint64_t bdsp_splitmix64(uint64_t seed){
3225
seed = 0xBF58476D1CE4E5B9 * (seed ^ (seed >> 30));
3326
seed = 0x94D049BB133111EB * (seed ^ (seed >> 27));
@@ -154,21 +147,15 @@ bool bdsp_is_shiny(uint32_t pid, uint16_t tsv){
154147

155148

156149

157-
//
158-
// Generation
159-
//
160150

161151
namespace{
162152

163-
// Reads straight off a generator. Used for one-off generation.
164153
struct DirectSource{
165154
Xorshift128& rng;
166155
uint32_t next(){ return bdsp_gen_transform(rng.next()); }
167156
uint32_t next(uint32_t modulo){ return next() % modulo; }
168157
};
169158

170-
// Reads off a sliding window. Used when searching a range of advances, where
171-
// consecutive advances re-read almost all of the same values.
172159
struct WindowSource{
173160
Xorshift128List<STATIC_SEARCH_WINDOW>& list;
174161
uint32_t next(){ return list.next_gen(); }
@@ -178,14 +165,12 @@ struct WindowSource{
178165
}
179166

180167

181-
// Force the PID to be non-shiny against the player's own TSV.
182168
static void force_not_shiny(uint32_t& pid, uint16_t tsv){
183169
if (bdsp_is_shiny(pid, tsv)){
184170
pid ^= 0x10000000;
185171
}
186172
}
187-
// Rebuild the PID so that it is shiny against the player's own TSV, in the same
188-
// way (star vs. square) that it was shiny against the rolled TSV.
173+
189174
static void force_shiny(uint32_t& pid, uint16_t tsv, BdspShiny shiny){
190175
if (bdsp_get_shiny(pid, tsv) == shiny){
191176
return;
@@ -194,9 +179,6 @@ static void force_shiny(uint32_t& pid, uint16_t tsv, BdspShiny shiny){
194179
pid = ((uint32_t)high << 16) | (pid & 0xffff);
195180
}
196181

197-
// The encounter rolls its own TSV, decides shininess against that, and only then
198-
// is the PID reshaped to produce the same outcome against the player's real TSV.
199-
// This is why a shiny frame stays shiny no matter whose save file is used.
200182
static BdspShiny resolve_shiny(uint32_t& pid, uint32_t sidtid, uint16_t tsv, bool shiny_locked){
201183
if (shiny_locked){
202184
force_not_shiny(pid, tsv);
@@ -227,8 +209,6 @@ static BdspPokemonResult generate_static_impl(
227209

228210
result.shiny = resolve_shiny(result.pid, sidtid, tsv, tmpl.shiny_locked);
229211

230-
// Guaranteed perfect IVs first. The roll picks a slot and is rerolled if that
231-
// slot is already taken, so the number of calls here is not fixed.
232212
const uint8_t UNSET = 255;
233213
BdspIVs ivs;
234214
for (size_t c = 0; c < 6; c++){
@@ -280,8 +260,7 @@ static BdspPokemonResult generate_static_impl(
280260
break;
281261
}
282262

283-
// A Synchronize lead skips the nature roll entirely rather than overriding
284-
// its result, so it shifts everything after it.
263+
// A Synchronize lead skips the nature roll, so it shifts everything after it
285264
result.nature = synchronize_nature != BDSP_NO_SYNCHRONIZE
286265
? synchronize_nature
287266
: (uint8_t)source.next(25);
@@ -309,16 +288,13 @@ BdspPokemonResult bdsp_generate_roamer(
309288
BdspPokemonResult result;
310289
result.level = tmpl.level;
311290

312-
// A roamer takes exactly one value from the main RNG. Everything else comes
313-
// from a Xoroshiro seeded with it, which is why roamers cost one advance
314-
// regardless of how much they generate.
291+
// roamers cost one advance regardless of how much they generate.
315292
result.ec = bdsp_gen_transform(rng.next());
316293
XoroshiroBDSP roamer(result.ec);
317294

318295
uint32_t sidtid = roamer.next_uint(0xffffffff);
319296
result.pid = roamer.next_uint(0xffffffff);
320297

321-
// Both roamers (Cresselia, Mesprit) are shiny-capable.
322298
result.shiny = resolve_shiny(result.pid, sidtid, tsv, false);
323299

324300
const uint8_t UNSET = 255;
@@ -340,8 +316,7 @@ BdspPokemonResult bdsp_generate_roamer(
340316
}
341317
result.ivs = ivs;
342318

343-
// Neither roamer can have a hidden ability, so this path has no equivalent of
344-
// the ability_kind switch above.
319+
// Neither roamer can have a hidden ability
345320
result.ability = (uint8_t)roamer.next_uint(2);
346321

347322
result.nature = synchronize_nature != BDSP_NO_SYNCHRONIZE
@@ -353,7 +328,7 @@ BdspPokemonResult bdsp_generate_roamer(
353328
result.weight = (uint8_t)roamer.next_uint(129);
354329
result.weight += (uint8_t)roamer.next_uint(128);
355330

356-
// Roamer gender is fixed per species and is never rolled.
331+
// Roamer gender is never rolled
357332
result.gender = tmpl.gender_ratio == 254
358333
? BdspGender::Female
359334
: BdspGender::Genderless;
@@ -385,10 +360,6 @@ BdspIdResult bdsp_generate_id(Xorshift128 rng){
385360

386361

387362

388-
//
389-
// Filtering and searching
390-
//
391-
392363
static bool iv_in_range(const IvRange& range, uint8_t iv){
393364
if (range.low >= 0 && iv < (uint8_t)range.low){
394365
return false;
@@ -433,8 +404,7 @@ std::vector<BdspRngHit> BdspStaticSearcher::scan(
433404
Xorshift128 rng(m_base_state);
434405
rng.advance(min_advances);
435406

436-
// A roamer reseeds a Xoroshiro on every advance, so there is nothing to
437-
// cache and the sliding window would only get in the way.
407+
// A roamer reseeds a Xoroshiro on every advance
438408
if (m_template.roamer){
439409
for (uint64_t advances = min_advances; advances <= max_advances; advances++){
440410
if (cancellable != nullptr && (advances % CANCEL_CHECK_INTERVAL) == 0){

SerialPrograms/Source/Pokemon/Pokemon_BdspRng.h

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
/* BDSP RNG
22
*
33
* From: https://github.com/PokemonAutomation/
4-
*
5-
* Pokemon generation for Brilliant Diamond / Shining Pearl, ported from
6-
* PokeFinder's Gen 8 generators.
7-
*
8-
* The main game RNG is xorshift128 (see Pokemon_Xorshift128.h). Most values are
9-
* read through bdsp_gen_transform(). Some encounters then seed a separate
10-
* Xoroshiro128+ from a single xorshift128 output and generate everything else
11-
* from that.
12-
*
13-
* Only the static/roamer and trainer-ID paths are implemented. Wild and egg
14-
* generation additionally need per-species data and encounter tables, which
15-
* this project does not have for BDSP yet.
16-
*
4+
*
175
*/
186

197
#ifndef PokemonAutomation_Pokemon_BdspRng_H
@@ -34,21 +22,13 @@ namespace PokemonAutomation{
3422
namespace Pokemon{
3523

3624

37-
//
38-
// Xoroshiro128+, BDSP flavor
39-
//
40-
4125
uint64_t bdsp_splitmix64(uint64_t seed);
4226

43-
// Sign-extend a 32-bit RNG output to 64 bits. Egg generation does this before
44-
// seeding; roamer generation does not.
27+
4528
inline uint64_t bdsp_sign_extend_seed(uint32_t seed){
4629
return (uint64_t)(int64_t)(int32_t)seed;
4730
}
4831

49-
// Same core as Xoroshiro128Plus, but seeded through splitmix and bounded
50-
// differently. Do not substitute Xoroshiro128Plus::nextInt() here: it uses
51-
// power-of-two rejection sampling, which is what Sword/Shield does, not BDSP.
5232
class XoroshiroBDSP{
5333
public:
5434
explicit XoroshiroBDSP(uint64_t seed);
@@ -61,11 +41,6 @@ class XoroshiroBDSP{
6141
};
6242

6343

64-
65-
//
66-
// Results
67-
//
68-
6944
enum class BdspShiny : uint8_t{
7045
None = 0,
7146
Star = 1,
@@ -81,9 +56,6 @@ enum class BdspGender : uint8_t{
8156
const char* bdsp_gender_name(BdspGender gender);
8257

8358
struct BdspIVs{
84-
// BDSP's order, which is also PokeFinder's: HP, Atk, Def, SpA, SpD, Spe.
85-
// This is NOT the Gen 3 order used by AdvIVs in Pokemon_AdvRng.h, which puts
86-
// Speed at index 3. Do not unify them.
8759
uint8_t hp = 0;
8860
uint8_t attack = 0;
8961
uint8_t defense = 0;
@@ -116,59 +88,33 @@ struct BdspIdResult{
11688
uint32_t sidtid = 0;
11789
uint16_t tid = 0;
11890
uint16_t sid = 0;
119-
// The 6-digit number the trainer card shows under "ID No.". Derived from the
120-
// whole 32-bit draw, so it is neither the TID nor the SID.
12191
uint32_t display_tid = 0;
12292

12393
uint16_t tsv() const{ return (uint16_t)(tid ^ sid); }
12494
std::string to_string() const;
12595
};
12696

12797

128-
// Natures are indexed in the game's own order (0 = Hardy), which is not the
129-
// order of NatureCheckerValue. Convert before comparing against anything from
130-
// the UI or from an IV/nature reader.
13198
const char* bdsp_nature_name(uint8_t nature);
13299
NatureCheckerValue bdsp_nature_to_checker_value(uint8_t nature);
133100

134-
// psv == tsv is a square shiny; a difference under 16 is a star.
101+
// psv == tsv is a square shiny; a difference under 16 is a star
135102
BdspShiny bdsp_get_shiny(uint32_t pid, uint16_t tsv);
136103
bool bdsp_is_shiny(uint32_t pid, uint16_t tsv);
137104

138105

139-
140-
//
141-
// Generation
142-
//
143-
144-
// Passed as "synchronize_nature" when no Synchronize lead is active.
145106
const uint8_t BDSP_NO_SYNCHRONIZE = 0xff;
146107

147108
struct BdspStaticTemplate{
148109
std::string species;
149110
uint8_t level = 1;
150-
151-
// How many IVs are forced to 31 before the rest are rolled.
152111
uint8_t guaranteed_ivs = 0;
153-
154-
// 0 or 1 forces that ability slot. 2 is the hidden ability, which still
155-
// burns one roll. 3 rolls between the two normal abilities.
156112
uint8_t ability_kind = 3;
157-
158-
// 255 = genderless, 254 = always female, 0 = always male. Otherwise a roll
159-
// must come in under this value to be female.
160113
uint8_t gender_ratio = 255;
161-
162-
// Shiny-locked encounters still roll a PID, then force it non-shiny.
163114
bool shiny_locked = false;
164-
165-
// Roamers (Cresselia, Mesprit) take one value from the main RNG as the EC,
166-
// then generate everything else from a Xoroshiro seeded with it.
167115
bool roamer = false;
168116
};
169117

170-
// Each of these takes the generator positioned at the target advance. The copy
171-
// is deliberate: callers keep their own position.
172118
BdspPokemonResult bdsp_generate_static(
173119
Xorshift128 rng, const BdspStaticTemplate& tmpl,
174120
uint16_t tsv, uint8_t synchronize_nature = BDSP_NO_SYNCHRONIZE
@@ -177,7 +123,6 @@ BdspPokemonResult bdsp_generate_roamer(
177123
Xorshift128 rng, const BdspStaticTemplate& tmpl,
178124
uint16_t tsv, uint8_t synchronize_nature = BDSP_NO_SYNCHRONIZE
179125
);
180-
// Dispatches on tmpl.roamer.
181126
BdspPokemonResult bdsp_generate(
182127
Xorshift128 rng, const BdspStaticTemplate& tmpl,
183128
uint16_t tsv, uint8_t synchronize_nature = BDSP_NO_SYNCHRONIZE
@@ -186,11 +131,6 @@ BdspPokemonResult bdsp_generate(
186131
BdspIdResult bdsp_generate_id(Xorshift128 rng);
187132

188133

189-
190-
//
191-
// Filtering and searching
192-
//
193-
194134
struct BdspRngHit{
195135
uint64_t advances = 0;
196136
Xorshift128State state;
@@ -209,20 +149,8 @@ class BdspStaticSearcher{
209149

210150
const BdspStaticTemplate& pokemon_template() const{ return m_template; }
211151

212-
// The Pokemon produced "advances" steps after the base state.
213-
//
214-
// This jumps from the base state on every call, which is the right thing for one
215-
// advance and the wrong thing for a range: use scan() to sweep one, or the cost
216-
// is a fresh jump per advance rather than a single step.
217152
BdspPokemonResult generate(uint64_t advances) const;
218153

219-
// Every advance in [min_advances, max_advances] that "accept" accepts, earliest
220-
// first, or just the first of them if "stop_at_first".
221-
//
222-
// Walks forward one advance at a time through a sliding window, so sweeping a
223-
// whole search window costs about what a single generate() does. The predicate
224-
// is the caller's because programs filter through the shared UI tables, and a
225-
// second filter type here would only be those tables written out twice.
226154
std::vector<BdspRngHit> scan(
227155
uint64_t min_advances, uint64_t max_advances,
228156
const std::function<bool(const BdspPokemonResult&)>& accept,

0 commit comments

Comments
 (0)