From 2c863730f50af9b02290020d9b6d7ef1bf88caeb Mon Sep 17 00:00:00 2001 From: human-0 Date: Thu, 16 Apr 2020 14:56:40 +1000 Subject: [PATCH] Removed unnecessary state changes to RNG after last next() call --- generator.cpp | 14 +++++++++----- generator.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/generator.cpp b/generator.cpp index ea29969..735493b 100644 --- a/generator.cpp +++ b/generator.cpp @@ -50,14 +50,18 @@ void generator::ChunkGenerator::ignoreLeafPattern(random_math::JavaRand& random) bool generator::ChunkGenerator::leafPatternNot0And4(random_math::JavaRand& random) { - bool _0 = random.nextIntPow2Unchecked(2) != 0; + if (random.nextIntPow2Unchecked(2) != 0) { + return false; + } + random.advance(advance_3); - bool _4 = random.nextIntPow2Unchecked(2) != 0; - random.advance(advance_11); - + if (random.nextIntPow2Unchecked(2)) { + random.advance(advance_11); + return true; + } - return !_0 && _4; + return false; } int32_t generator::ChunkGenerator::checkTrees(random_math::JavaRand& random, int32_t maxTreeCount, int waterfallX) diff --git a/generator.h b/generator.h index 6f4ab31..d98d933 100644 --- a/generator.h +++ b/generator.h @@ -13,6 +13,7 @@ namespace generator static bool isValidTreeSpot(int treeX, int treeZ, bool firstTreeFound, bool secondTreeFound, int waterfallX); static void generateLeafPattern(random_math::JavaRand& random, bool *out); static void ignoreLeafPattern(random_math::JavaRand& random); + /* When false is returned, the RNG will be in an invalid state */ static bool leafPatternNot0And4(random_math::JavaRand& random); static int32_t checkTrees(random_math::JavaRand& random, int32_t maxTreeCount, int waterfallX); public: