From ac83733b590f3c0750bea1de3556ceb24fa0a4b1 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Mon, 25 Nov 2019 21:10:50 -0800 Subject: Using PCH to clean up includes --- App/App.vcxproj | 12 ++++++++---- App/Main.cpp | 7 +------ Source/ChallengeRandomizer.cpp | 3 ++- Source/ChallengeRandomizer.h | 2 -- Source/Memory.cpp | 4 +--- Source/Memory.h | 9 ++------- Source/MemoryException.h | 3 --- Source/Panels.h | 1 - Source/Puzzle.cpp | 2 +- Source/Puzzle.h | 4 ---- Source/PuzzleSerializer.cpp | 16 +--------------- Source/PuzzleSerializer.h | 5 ----- Source/Random.cpp | 2 +- Source/Random.h | 1 - Source/Randomizer.cpp | 8 +++----- Source/Randomizer.h | 2 -- Source/Randomizer2.cpp | 30 +++++++++++++++++++++++++----- Source/Randomizer2.h | 1 - Source/Randomizer2Core.cpp | 20 ++++++++++---------- Source/Randomizer2Core.h | 4 ---- Source/Solver.cpp | 1 + Source/Source.vcxproj | 13 +++++++++---- Source/Validator.cpp | 3 ++- Source/pch.h | 26 ++++++++++++++++++++++++++ Test/RandomTests.cpp | 1 + Test/Temp.cpp | 1 + Test/Test.vcxproj | 8 ++++---- 27 files changed, 99 insertions(+), 90 deletions(-) create mode 100644 Source/pch.h diff --git a/App/App.vcxproj b/App/App.vcxproj index 25ec076..e2e75a8 100644 --- a/App/App.vcxproj +++ b/App/App.vcxproj @@ -89,7 +89,7 @@ - NotUsing + Create Level3 Disabled true @@ -98,6 +98,7 @@ ..\Source;%(AdditionalIncludeDirectories) stdcpp17 true + pch.h Windows @@ -106,7 +107,7 @@ - NotUsing + Create Level3 Disabled true @@ -116,6 +117,7 @@ ..\Source;%(AdditionalIncludeDirectories) MultiThreadedDebug true + pch.h Windows @@ -124,7 +126,7 @@ - NotUsing + Create Level3 MaxSpeed true @@ -135,6 +137,7 @@ stdcpp17 ..\Source;%(AdditionalIncludeDirectories) true + pch.h Windows @@ -146,7 +149,7 @@ - NotUsing + Create Level3 MaxSpeed true @@ -158,6 +161,7 @@ ..\Source;%(AdditionalIncludeDirectories) true MultiThreaded + pch.h Windows diff --git a/App/Main.cpp b/App/Main.cpp index 9e2757e..4bd009a 100644 --- a/App/Main.cpp +++ b/App/Main.cpp @@ -1,12 +1,7 @@ -#include "Windows.h" +#include "pch.h" #include "Richedit.h" #include "Version.h" -#include -#include -#include -#include - #include "Memory.h" #include "Random.h" #include "Randomizer.h" diff --git a/Source/ChallengeRandomizer.cpp b/Source/ChallengeRandomizer.cpp index e91e9ac..b497564 100644 --- a/Source/ChallengeRandomizer.cpp +++ b/Source/ChallengeRandomizer.cpp @@ -1,5 +1,6 @@ +#include "pch.h" #include "ChallengeRandomizer.h" -#include +#include "Memory.h" // Modify an opcode to use RNG2 instead of main RNG void ChallengeRandomizer::AdjustRng(int offset) { diff --git a/Source/ChallengeRandomizer.h b/Source/ChallengeRandomizer.h index fb0338a..b06be81 100644 --- a/Source/ChallengeRandomizer.h +++ b/Source/ChallengeRandomizer.h @@ -1,6 +1,4 @@ #pragma once -#include "Memory.h" -#include class ChallengeRandomizer { public: diff --git a/Source/Memory.cpp b/Source/Memory.cpp index 80cd103..3121d20 100644 --- a/Source/Memory.cpp +++ b/Source/Memory.cpp @@ -1,9 +1,7 @@ +#include "pch.h" #include "Memory.h" #include #include -#include -#include -#include #undef PROCESSENTRY32 #undef Process32Next diff --git a/Source/Memory.h b/Source/Memory.h index d497123..82d1293 100644 --- a/Source/Memory.h +++ b/Source/Memory.h @@ -1,11 +1,4 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include "MemoryException.h" #define GLOBALS 0x5B28C0 // #define GLOBALS 0x62D0A0 @@ -16,6 +9,8 @@ enum class ProcStatus { NewGame }; +using byte = unsigned char; + // https://github.com/erayarslan/WriteProcessMemory-Example // http://stackoverflow.com/q/32798185 // http://stackoverflow.com/q/36018838 diff --git a/Source/MemoryException.h b/Source/MemoryException.h index ad2824d..48753cd 100644 --- a/Source/MemoryException.h +++ b/Source/MemoryException.h @@ -1,7 +1,4 @@ #pragma once -#include -#include -#include #define MEMORY_CATCH(expr) \ try { \ diff --git a/Source/Panels.h b/Source/Panels.h index 2c7c075..4a850ee 100644 --- a/Source/Panels.h +++ b/Source/Panels.h @@ -1,5 +1,4 @@ #pragma once -#include // Some of these (the puzzle ones) are duplicated elsewhere std::vector lasers = { diff --git a/Source/Puzzle.cpp b/Source/Puzzle.cpp index 2f399a7..15352ed 100644 --- a/Source/Puzzle.cpp +++ b/Source/Puzzle.cpp @@ -1,6 +1,6 @@ +#include "pch.h" #include "Puzzle.h" #include "Memory.h" -#include Cell Puzzle::GetCell(int x, int y) const { x = Mod(x); diff --git a/Source/Puzzle.h b/Source/Puzzle.h index b7dedd5..c2a8fce 100644 --- a/Source/Puzzle.h +++ b/Source/Puzzle.h @@ -1,8 +1,4 @@ #pragma once -#include -#include - -class Memory; enum Type { Stone = 0x100, diff --git a/Source/PuzzleSerializer.cpp b/Source/PuzzleSerializer.cpp index 7461f7b..33f6da6 100644 --- a/Source/PuzzleSerializer.cpp +++ b/Source/PuzzleSerializer.cpp @@ -1,6 +1,6 @@ +#include "pch.h" #include "PuzzleSerializer.h" #include "Memory.h" -#include #pragma warning (disable:26451) #pragma warning (disable:26812) @@ -65,16 +65,6 @@ void PuzzleSerializer::WritePuzzle(const Puzzle& p, int id) { WriteSequence(p, id); WriteSymmetry(p, id); -#ifndef NDEBUG - int maxDots = _memory->ReadEntityData(id, NUM_DOTS, 1)[0]; - assert(_intersectionFlags.size() <= maxDots); - assert(_intersectionLocations.size() <= maxDots*2); - - int maxConnections = _memory->ReadEntityData(id, NUM_CONNECTIONS, 1)[0]; - assert(_connectionsA.size() <= maxConnections); - assert(_connectionsB.size() <= maxConnections); -#endif - _memory->WriteEntityData(id, GRID_SIZE_X, {(p.width + 1)/2}); _memory->WriteEntityData(id, GRID_SIZE_Y, {(p.height + 1)/2}); _memory->WriteEntityData(id, NUM_DOTS, {static_cast(_intersectionFlags.size())}); @@ -455,10 +445,6 @@ void PuzzleSerializer::WriteDecorations(const Puzzle& p, int id) { } } -#ifndef NDEBUG - int maxDecorations = _memory->ReadEntityData(id, NUM_DECORATIONS, 1)[0]; - assert(decorations.size() < maxDecorations); -#endif _memory->WriteEntityData(id, NUM_DECORATIONS, {static_cast(decorations.size())}); _memory->WriteArray(id, DECORATIONS, decorations); } diff --git a/Source/PuzzleSerializer.h b/Source/PuzzleSerializer.h index 4ccd383..e1ee3e8 100644 --- a/Source/PuzzleSerializer.h +++ b/Source/PuzzleSerializer.h @@ -1,11 +1,6 @@ #pragma once -#include -#include - #include "Puzzle.h" -class Memory; - class PuzzleSerializer { public: PuzzleSerializer(const std::shared_ptr& memory); diff --git a/Source/Random.cpp b/Source/Random.cpp index d9fe678..aee4d1a 100644 --- a/Source/Random.cpp +++ b/Source/Random.cpp @@ -1,4 +1,4 @@ -#include +#include "pch.h" #include "Random.h" uint32_t Random::s_seed = static_cast(time(nullptr)); // Seed from the time in milliseconds diff --git a/Source/Random.h b/Source/Random.h index a2ad706..e809c1e 100644 --- a/Source/Random.h +++ b/Source/Random.h @@ -1,5 +1,4 @@ #pragma once -#include class Random { diff --git a/Source/Randomizer.cpp b/Source/Randomizer.cpp index 1427f4d..e70cf44 100644 --- a/Source/Randomizer.cpp +++ b/Source/Randomizer.cpp @@ -91,14 +91,12 @@ Things to do for V2: * 20 challenges with 20 consecutive seeds * Random *rotation* of desert laser redirect? */ +#include "pch.h" #include "Memory.h" #include "Randomizer.h" #include "ChallengeRandomizer.h" #include "Panels.h" #include "Random.h" -#include -#include -#include template int find(const std::vector &data, T search, size_t startIndex = 0) { @@ -250,8 +248,8 @@ void Randomizer::RandomizeTown() { // Ensure that we open the gate before the final puzzle (by swapping) int panel3Index = find(randomOrder, 3); int panel4Index = find(randomOrder, 4); - randomOrder[min(panel3Index, panel4Index)] = 3; - randomOrder[max(panel3Index, panel4Index)] = 4; + randomOrder[std::min(panel3Index, panel4Index)] = 3; + randomOrder[std::max(panel3Index, panel4Index)] = 4; ReassignTargets(orchard, randomOrder); } diff --git a/Source/Randomizer.h b/Source/Randomizer.h index 673468c..bd8895b 100644 --- a/Source/Randomizer.h +++ b/Source/Randomizer.h @@ -1,6 +1,4 @@ #pragma once -#include "Memory.h" -#include class Randomizer { public: diff --git a/Source/Randomizer2.cpp b/Source/Randomizer2.cpp index f93e4fd..4f0bad0 100644 --- a/Source/Randomizer2.cpp +++ b/Source/Randomizer2.cpp @@ -1,14 +1,11 @@ +#include "pch.h" #include "Randomizer2.h" #include "PuzzleSerializer.h" #include "Randomizer2Core.h" #include "Puzzle.h" #include "Random.h" #include "Solver.h" - -#include -#include - -#pragma warning (disable: 26451) +#include "Windows.h" Randomizer2::Randomizer2(const PuzzleSerializer& serializer) : _serializer(serializer) {} @@ -229,6 +226,7 @@ void Randomizer2::RandomizeSymmetry() { _serializer.WritePuzzle(p, 0x62); } + // TODO: Positioning is off, slightly -- which means you can start from the bottom left, if you peek around. { // Back wall 5 Puzzle p; p.NewGrid(11, 8); @@ -259,6 +257,28 @@ void Randomizer2::RandomizeSymmetry() { _serializer.WritePuzzle(p, 0x5C); } + + { // Rotational 1 + Puzzle p; + p.NewGrid(3, 3); + p.symmetry = Puzzle::Symmetry::XY; + p.grid[6][0].start = true; + p.grid[0][6].start = true; + p.grid[4][0].end = Cell::Dir::UP; + p.grid[2][6].end = Cell::Dir::DOWN; + + p.grid[5][0].gap = Cell::Gap::BREAK; + p.grid[1][6].gap = Cell::Gap::BREAK; + + for (Pos pos : Randomizer2Core::CutSymmetricalEdgePairs(p, 1)) { + std::string text = std::to_string(pos.x) + " " + std::to_string(pos.y); + OutputDebugStringA(text.c_str()); + p.grid[pos.x][pos.y].gap = Cell::Gap::BREAK; + Pos sym = p.GetSymmetricalPos(pos.x, pos.y); + p.grid[sym.x][sym.y].gap = Cell::Gap::BREAK; + } + _serializer.WritePuzzle(p, 0x8D); + } } void Randomizer2::RandomizeKeep() { diff --git a/Source/Randomizer2.h b/Source/Randomizer2.h index c8c3db5..34c89f5 100644 --- a/Source/Randomizer2.h +++ b/Source/Randomizer2.h @@ -1,7 +1,6 @@ #pragma once #include "PuzzleSerializer.h" -class Puzzle; class Randomizer2 { public: Randomizer2(const PuzzleSerializer& serializer); diff --git a/Source/Randomizer2Core.cpp b/Source/Randomizer2Core.cpp index eaefa9a..89294ef 100644 --- a/Source/Randomizer2Core.cpp +++ b/Source/Randomizer2Core.cpp @@ -1,11 +1,8 @@ +#include "pch.h" #include "Randomizer2Core.h" #include "Puzzle.h" #include "Random.h" -#include -#include -#include - std::vector Randomizer2Core::CutEdges(const Puzzle& p, size_t numEdges) { return CutEdgesInternal(p, 0, p.width, 0, p.height, numEdges); } @@ -16,17 +13,20 @@ std::vector Randomizer2Core::CutInsideEdges(const Puzzle& p, size_t numEdge std::vector Randomizer2Core::CutSymmetricalEdgePairs(const Puzzle& p, size_t numEdges) { Puzzle copy = p; - assert(p.symmetry != Puzzle::Symmetry::NONE); + // Prevent cuts from landing on the midline if (p.symmetry == Puzzle::Symmetry::X) { - // Prevent cuts from landing on the midline for (int y=0; y Randomizer2Core::CutEdgesInternal(const Puzzle& p, int xMin, int xMax, int yMin, int yMax, size_t numEdges) { diff --git a/Source/Randomizer2Core.h b/Source/Randomizer2Core.h index 674e4ea..df98de8 100644 --- a/Source/Randomizer2Core.h +++ b/Source/Randomizer2Core.h @@ -1,8 +1,4 @@ #pragma once -#include - -struct Pos; -class Puzzle; class Randomizer2Core { public: diff --git a/Source/Solver.cpp b/Source/Solver.cpp index c0b35ef..e09cba2 100644 --- a/Source/Solver.cpp +++ b/Source/Solver.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "Solver.h" #include "Puzzle.h" #include "Validator.h" diff --git a/Source/Source.vcxproj b/Source/Source.vcxproj index 5aaa0b0..c63c664 100644 --- a/Source/Source.vcxproj +++ b/Source/Source.vcxproj @@ -84,7 +84,7 @@ - NotUsing + Create Level3 Disabled true @@ -92,6 +92,7 @@ true stdcpp17 true + pch.h Windows @@ -100,7 +101,7 @@ - NotUsing + Create Level3 Disabled true @@ -109,6 +110,7 @@ stdcpp17 MultiThreadedDebug true + pch.h Windows @@ -117,7 +119,7 @@ - NotUsing + Create Level3 MaxSpeed true @@ -127,6 +129,7 @@ true stdcpp17 true + pch.h Windows @@ -137,7 +140,7 @@ - NotUsing + Create Level3 MaxSpeed true @@ -148,6 +151,7 @@ stdcpp17 true MultiThreaded + pch.h Windows @@ -160,6 +164,7 @@ + diff --git a/Source/Validator.cpp b/Source/Validator.cpp index e71dc34..cb0ffa8 100644 --- a/Source/Validator.cpp +++ b/Source/Validator.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "Validator.h" #include "Puzzle.h" @@ -10,7 +11,7 @@ void Validator::Validate(Puzzle& p) { bool puzzleHasSymbols = false; bool puzzleHasStart = false; bool puzzleHasEnd = false; - // Validate gap failures as an early exit. + // Validate gap failures as an early exit. for (int x = 0; x < p.width; x++) { for (int y = 0; y < p.height; y++) { Cell cell = p.grid[x][y]; diff --git a/Source/pch.h b/Source/pch.h new file mode 100644 index 0000000..d431d61 --- /dev/null +++ b/Source/pch.h @@ -0,0 +1,26 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN 1 +#define VC_EXTRALEAN 1 +#include +#undef min +#undef max + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#pragma warning (disable: 26451) // Potential arithmetic overflow + +#include "MemoryException.h" +#include "Memory.h" +#include "Puzzle.h" diff --git a/Test/RandomTests.cpp b/Test/RandomTests.cpp index 20a86e5..7730a4f 100644 --- a/Test/RandomTests.cpp +++ b/Test/RandomTests.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "gtest/gtest.h" #include "Random.h" diff --git a/Test/Temp.cpp b/Test/Temp.cpp index 3b31539..bf6a09a 100644 --- a/Test/Temp.cpp +++ b/Test/Temp.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "gtest/gtest.h" #include "Randomizer.h" #include diff --git a/Test/Test.vcxproj b/Test/Test.vcxproj index 857cdd4..4d00c77 100644 --- a/Test/Test.vcxproj +++ b/Test/Test.vcxproj @@ -51,7 +51,7 @@ - NotUsing + Create pch.h Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) @@ -72,7 +72,7 @@ - NotUsing + Create pch.h Disabled X64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) @@ -93,7 +93,7 @@ - NotUsing + Create pch.h WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) MultiThreaded @@ -114,7 +114,7 @@ - NotUsing + Create pch.h X64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) MultiThreaded -- cgit 1.4.1