diff options
Diffstat (limited to 'Source/RandomizerCore.cpp')
| -rw-r--r-- | Source/RandomizerCore.cpp | 139 |
1 files changed, 0 insertions, 139 deletions
| diff --git a/Source/RandomizerCore.cpp b/Source/RandomizerCore.cpp index f00dacd..e69de29 100644 --- a/Source/RandomizerCore.cpp +++ b/Source/RandomizerCore.cpp | |||
| @@ -1,139 +0,0 @@ | |||
| 1 | #include "RandomizerCore.h" | ||
| 2 | #include "Memory.h" | ||
| 3 | #include "Random.h" | ||
| 4 | #include <sstream> | ||
| 5 | |||
| 6 | void RandomizerCore::Randomize(std::vector<int>& panels, int flags) { | ||
| 7 | return RandomizeRange(panels, flags, 0, panels.size()); | ||
| 8 | } | ||
| 9 | |||
| 10 | // Range is [start, end) | ||
| 11 | void RandomizerCore::RandomizeRange(std::vector<int> &panels, int flags, size_t startIndex, size_t endIndex) { | ||
| 12 | if (panels.size() == 0) return; | ||
| 13 | if (startIndex >= endIndex) return; | ||
| 14 | if (endIndex >= panels.size()) endIndex = panels.size(); | ||
| 15 | for (size_t i = endIndex-1; i > startIndex; i--) { | ||
| 16 | const size_t target = Random::RandInt(startIndex, i); | ||
| 17 | if (i != target) { | ||
| 18 | // std::cout << "Swapping panels " << std::hex << panels[i] << " and " << std::hex << panels[target] << std::endl; | ||
| 19 | SwapPanels(panels[i], panels[target], flags); | ||
| 20 | std::swap(panels[i], panels[target]); // Panel indices in the array | ||
| 21 | } | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | void RandomizerCore::SwapPanels(int panel1, int panel2, int flags) { | ||
| 26 | std::map<int, int> offsets; | ||
| 27 | |||
| 28 | if (flags & SWAP_TARGETS) { | ||
| 29 | offsets[TARGET] = sizeof(int); | ||
| 30 | } | ||
| 31 | if (flags & SWAP_AUDIO_NAMES) { | ||
| 32 | offsets[AUDIO_LOG_NAME] = sizeof(void*); | ||
| 33 | } | ||
| 34 | if (flags & SWAP_LINES) { | ||
| 35 | offsets[PATH_COLOR] = 16; | ||
| 36 | offsets[REFLECTION_PATH_COLOR] = 16; | ||
| 37 | offsets[DOT_COLOR] = 16; | ||
| 38 | offsets[ACTIVE_COLOR] = 16; | ||
| 39 | offsets[BACKGROUND_REGION_COLOR] = 12; // Not copying alpha to preserve transparency. | ||
| 40 | offsets[SUCCESS_COLOR_A] = 16; | ||
| 41 | offsets[SUCCESS_COLOR_B] = 16; | ||
| 42 | offsets[STROBE_COLOR_A] = 16; | ||
| 43 | offsets[STROBE_COLOR_B] = 16; | ||
| 44 | offsets[ERROR_COLOR] = 16; | ||
| 45 | offsets[PATTERN_POINT_COLOR] = 16; | ||
| 46 | offsets[PATTERN_POINT_COLOR_A] = 16; | ||
| 47 | offsets[PATTERN_POINT_COLOR_B] = 16; | ||
| 48 | offsets[SYMBOL_A] = 16; | ||
| 49 | offsets[SYMBOL_B] = 16; | ||
| 50 | offsets[SYMBOL_C] = 16; | ||
| 51 | offsets[SYMBOL_D] = 16; | ||
| 52 | offsets[SYMBOL_E] = 16; | ||
| 53 | offsets[PUSH_SYMBOL_COLORS] = sizeof(int); | ||
| 54 | offsets[OUTER_BACKGROUND] = 16; | ||
| 55 | offsets[OUTER_BACKGROUND_MODE] = sizeof(int); | ||
| 56 | offsets[TRACED_EDGES] = 16; | ||
| 57 | offsets[AUDIO_PREFIX] = sizeof(void*); | ||
| 58 | // offsets[IS_CYLINDER] = sizeof(int); | ||
| 59 | // offsets[CYLINDER_Z0] = sizeof(float); | ||
| 60 | // offsets[CYLINDER_Z1] = sizeof(float); | ||
| 61 | // offsets[CYLINDER_RADIUS] = sizeof(float); | ||
| 62 | offsets[SPECULAR_ADD] = sizeof(float); | ||
| 63 | offsets[SPECULAR_POWER] = sizeof(int); | ||
| 64 | offsets[PATH_WIDTH_SCALE] = sizeof(float); | ||
| 65 | offsets[STARTPOINT_SCALE] = sizeof(float); | ||
| 66 | offsets[NUM_DOTS] = sizeof(int); | ||
| 67 | offsets[NUM_CONNECTIONS] = sizeof(int); | ||
| 68 | offsets[DOT_POSITIONS] = sizeof(void*); | ||
| 69 | offsets[DOT_FLAGS] = sizeof(void*); | ||
| 70 | offsets[DOT_CONNECTION_A] = sizeof(void*); | ||
| 71 | offsets[DOT_CONNECTION_B] = sizeof(void*); | ||
| 72 | offsets[DECORATIONS] = sizeof(void*); | ||
| 73 | offsets[DECORATION_FLAGS] = sizeof(void*); | ||
| 74 | offsets[DECORATION_COLORS] = sizeof(void*); | ||
| 75 | offsets[NUM_DECORATIONS] = sizeof(int); | ||
| 76 | offsets[REFLECTION_DATA] = sizeof(void*); | ||
| 77 | offsets[GRID_SIZE_X] = sizeof(int); | ||
| 78 | offsets[GRID_SIZE_Y] = sizeof(int); | ||
| 79 | offsets[STYLE_FLAGS] = sizeof(int); | ||
| 80 | offsets[SEQUENCE_LEN] = sizeof(int); | ||
| 81 | offsets[SEQUENCE] = sizeof(void*); | ||
| 82 | offsets[DOT_SEQUENCE_LEN] = sizeof(int); | ||
| 83 | offsets[DOT_SEQUENCE] = sizeof(void*); | ||
| 84 | offsets[DOT_SEQUENCE_LEN_REFLECTION] = sizeof(int); | ||
| 85 | offsets[DOT_SEQUENCE_REFLECTION] = sizeof(void*); | ||
| 86 | offsets[NUM_COLORED_REGIONS] = sizeof(int); | ||
| 87 | offsets[COLORED_REGIONS] = sizeof(void*); | ||
| 88 | offsets[PANEL_TARGET] = sizeof(void*); | ||
| 89 | offsets[SPECULAR_TEXTURE] = sizeof(void*); | ||
| 90 | } | ||
| 91 | |||
| 92 | for (auto const& [offset, size] : offsets) { | ||
| 93 | std::vector<byte> panel1data = _memory->ReadPanelData<byte>(panel1, offset, size); | ||
| 94 | std::vector<byte> panel2data = _memory->ReadPanelData<byte>(panel2, offset, size); | ||
| 95 | _memory->WritePanelData<byte>(panel2, offset, panel1data); | ||
| 96 | _memory->WritePanelData<byte>(panel1, offset, panel2data); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | void RandomizerCore::ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order, std::vector<int> targets) { | ||
| 101 | if (targets.empty()) { | ||
| 102 | // This list is offset by 1, so the target of the Nth panel is in position N (aka the N+1th element) | ||
| 103 | // The first panel may not have a wire to power it, so we use the panel ID itself. | ||
| 104 | targets = {panels[0] + 1}; | ||
| 105 | for (const int panel : panels) { | ||
| 106 | int target = _memory->ReadPanelData<int>(panel, TARGET, 1)[0]; | ||
| 107 | targets.push_back(target); | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | for (size_t i=0; i<order.size() - 1; i++) { | ||
| 112 | // Set the target of order[i] to order[i+1], using the "real" target as determined above. | ||
| 113 | const int panelTarget = targets[order[i+1]]; | ||
| 114 | _memory->WritePanelData<int>(panels[order[i]], TARGET, {panelTarget}); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | void RandomizerCore::ReassignNames(const std::vector<int>& panels, const std::vector<int>& order) { | ||
| 119 | std::vector<int64_t> names; | ||
| 120 | for (const int panel : panels) { | ||
| 121 | names.push_back(_memory->ReadPanelData<int64_t>(panel, AUDIO_LOG_NAME, 1)[0]); | ||
| 122 | } | ||
| 123 | |||
| 124 | for (int i=0; i<panels.size(); i++) { | ||
| 125 | _memory->WritePanelData<int64_t>(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | short RandomizerCore::ReadMetadata() { | ||
| 130 | return _memory->ReadData<short>({GLOBALS + METADATA}, 1)[0]; | ||
| 131 | } | ||
| 132 | |||
| 133 | void RandomizerCore::WriteMetadata(short metadata) { | ||
| 134 | return _memory->WriteData<short>({GLOBALS + METADATA}, {metadata}); | ||
| 135 | } | ||
| 136 | |||
| 137 | int RandomizerCore::GetCurrentFrame() { | ||
| 138 | return _memory->ReadData<int>({SCRIPT_FRAMES}, 1)[0]; | ||
| 139 | } | ||
