From 1cad9871174728c15abbdb71ee5cbe2cf03ccf0c Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Wed, 7 Nov 2018 08:27:09 -0800 Subject: Cleanup before I dive further --- Source/RandomizerCore.cpp | 139 ---------------------------------------------- 1 file changed, 139 deletions(-) (limited to 'Source/RandomizerCore.cpp') 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 @@ -#include "RandomizerCore.h" -#include "Memory.h" -#include "Random.h" -#include - -void RandomizerCore::Randomize(std::vector& panels, int flags) { - return RandomizeRange(panels, flags, 0, panels.size()); -} - -// Range is [start, end) -void RandomizerCore::RandomizeRange(std::vector &panels, int flags, size_t startIndex, size_t endIndex) { - if (panels.size() == 0) return; - if (startIndex >= endIndex) return; - if (endIndex >= panels.size()) endIndex = panels.size(); - for (size_t i = endIndex-1; i > startIndex; i--) { - const size_t target = Random::RandInt(startIndex, i); - if (i != target) { - // std::cout << "Swapping panels " << std::hex << panels[i] << " and " << std::hex << panels[target] << std::endl; - SwapPanels(panels[i], panels[target], flags); - std::swap(panels[i], panels[target]); // Panel indices in the array - } - } -} - -void RandomizerCore::SwapPanels(int panel1, int panel2, int flags) { - std::map offsets; - - if (flags & SWAP_TARGETS) { - offsets[TARGET] = sizeof(int); - } - if (flags & SWAP_AUDIO_NAMES) { - offsets[AUDIO_LOG_NAME] = sizeof(void*); - } - if (flags & SWAP_LINES) { - offsets[PATH_COLOR] = 16; - offsets[REFLECTION_PATH_COLOR] = 16; - offsets[DOT_COLOR] = 16; - offsets[ACTIVE_COLOR] = 16; - offsets[BACKGROUND_REGION_COLOR] = 12; // Not copying alpha to preserve transparency. - offsets[SUCCESS_COLOR_A] = 16; - offsets[SUCCESS_COLOR_B] = 16; - offsets[STROBE_COLOR_A] = 16; - offsets[STROBE_COLOR_B] = 16; - offsets[ERROR_COLOR] = 16; - offsets[PATTERN_POINT_COLOR] = 16; - offsets[PATTERN_POINT_COLOR_A] = 16; - offsets[PATTERN_POINT_COLOR_B] = 16; - offsets[SYMBOL_A] = 16; - offsets[SYMBOL_B] = 16; - offsets[SYMBOL_C] = 16; - offsets[SYMBOL_D] = 16; - offsets[SYMBOL_E] = 16; - offsets[PUSH_SYMBOL_COLORS] = sizeof(int); - offsets[OUTER_BACKGROUND] = 16; - offsets[OUTER_BACKGROUND_MODE] = sizeof(int); - offsets[TRACED_EDGES] = 16; - offsets[AUDIO_PREFIX] = sizeof(void*); -// offsets[IS_CYLINDER] = sizeof(int); -// offsets[CYLINDER_Z0] = sizeof(float); -// offsets[CYLINDER_Z1] = sizeof(float); -// offsets[CYLINDER_RADIUS] = sizeof(float); - offsets[SPECULAR_ADD] = sizeof(float); - offsets[SPECULAR_POWER] = sizeof(int); - offsets[PATH_WIDTH_SCALE] = sizeof(float); - offsets[STARTPOINT_SCALE] = sizeof(float); - offsets[NUM_DOTS] = sizeof(int); - offsets[NUM_CONNECTIONS] = sizeof(int); - offsets[DOT_POSITIONS] = sizeof(void*); - offsets[DOT_FLAGS] = sizeof(void*); - offsets[DOT_CONNECTION_A] = sizeof(void*); - offsets[DOT_CONNECTION_B] = sizeof(void*); - offsets[DECORATIONS] = sizeof(void*); - offsets[DECORATION_FLAGS] = sizeof(void*); - offsets[DECORATION_COLORS] = sizeof(void*); - offsets[NUM_DECORATIONS] = sizeof(int); - offsets[REFLECTION_DATA] = sizeof(void*); - offsets[GRID_SIZE_X] = sizeof(int); - offsets[GRID_SIZE_Y] = sizeof(int); - offsets[STYLE_FLAGS] = sizeof(int); - offsets[SEQUENCE_LEN] = sizeof(int); - offsets[SEQUENCE] = sizeof(void*); - offsets[DOT_SEQUENCE_LEN] = sizeof(int); - offsets[DOT_SEQUENCE] = sizeof(void*); - offsets[DOT_SEQUENCE_LEN_REFLECTION] = sizeof(int); - offsets[DOT_SEQUENCE_REFLECTION] = sizeof(void*); - offsets[NUM_COLORED_REGIONS] = sizeof(int); - offsets[COLORED_REGIONS] = sizeof(void*); - offsets[PANEL_TARGET] = sizeof(void*); - offsets[SPECULAR_TEXTURE] = sizeof(void*); - } - - for (auto const& [offset, size] : offsets) { - std::vector panel1data = _memory->ReadPanelData(panel1, offset, size); - std::vector panel2data = _memory->ReadPanelData(panel2, offset, size); - _memory->WritePanelData(panel2, offset, panel1data); - _memory->WritePanelData(panel1, offset, panel2data); - } -} - -void RandomizerCore::ReassignTargets(const std::vector& panels, const std::vector& order, std::vector targets) { - if (targets.empty()) { - // This list is offset by 1, so the target of the Nth panel is in position N (aka the N+1th element) - // The first panel may not have a wire to power it, so we use the panel ID itself. - targets = {panels[0] + 1}; - for (const int panel : panels) { - int target = _memory->ReadPanelData(panel, TARGET, 1)[0]; - targets.push_back(target); - } - } - - for (size_t i=0; iWritePanelData(panels[order[i]], TARGET, {panelTarget}); - } -} - -void RandomizerCore::ReassignNames(const std::vector& panels, const std::vector& order) { - std::vector names; - for (const int panel : panels) { - names.push_back(_memory->ReadPanelData(panel, AUDIO_LOG_NAME, 1)[0]); - } - - for (int i=0; iWritePanelData(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); - } -} - -short RandomizerCore::ReadMetadata() { - return _memory->ReadData({GLOBALS + METADATA}, 1)[0]; -} - -void RandomizerCore::WriteMetadata(short metadata) { - return _memory->WriteData({GLOBALS + METADATA}, {metadata}); -} - -int RandomizerCore::GetCurrentFrame() { - return _memory->ReadData({SCRIPT_FRAMES}, 1)[0]; -} -- cgit 1.4.1