summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--enc_temp_folder/39556c61ea71e3139a19e47cd4dbe2/RandomizerCore.cpp119
1 files changed, 0 insertions, 119 deletions
diff --git a/enc_temp_folder/39556c61ea71e3139a19e47cd4dbe2/RandomizerCore.cpp b/enc_temp_folder/39556c61ea71e3139a19e47cd4dbe2/RandomizerCore.cpp deleted file mode 100644 index ef0e6e6..0000000 --- a/enc_temp_folder/39556c61ea71e3139a19e47cd4dbe2/RandomizerCore.cpp +++ /dev/null
@@ -1,119 +0,0 @@
1#include "RandomizerCore.h"
2#include "Memory.h"
3#include <sstream>
4
5void RandomizerCore::Randomize(std::vector<int>& panels, int flags) {
6 return RandomizeRange(panels, flags, 0, panels.size());
7}
8
9// Range is [start, end)
10void RandomizerCore::RandomizeRange(std::vector<int> &panels, int flags, size_t startIndex, size_t endIndex) {
11 if (panels.size() == 0) return;
12 if (startIndex >= endIndex) return;
13 if (endIndex >= panels.size()) endIndex = panels.size();
14 for (size_t i = endIndex-1; i > startIndex; i--) {
15 const size_t target = rand() % (i - startIndex) + startIndex;
16 if (i != target) {
17 // std::cout << "Swapping panels " << std::hex << panels[i] << " and " << std::hex << panels[target] << std::endl;
18 SwapPanels(panels[i], panels[target], flags);
19 std::swap(panels[i], panels[target]); // Panel indices in the array
20 }
21 }
22}
23
24void RandomizerCore::SwapPanels(int panel1, int panel2, int flags) {
25 std::map<int, int> offsets;
26
27 if (flags & SWAP_TARGETS) {
28 offsets[TARGET] = sizeof(int);
29 }
30 if (flags & SWAP_LINES) {
31 offsets[PATH_COLOR] = 16;
32 offsets[REFLECTION_PATH_COLOR] = 16;
33 offsets[DOT_COLOR] = 16;
34 offsets[ACTIVE_COLOR] = 16;
35 offsets[BACKGROUND_REGION_COLOR] = 16;
36 offsets[SUCCESS_COLOR_A] = 16;
37 offsets[SUCCESS_COLOR_B] = 16;
38 offsets[STROBE_COLOR_A] = 16;
39 offsets[STROBE_COLOR_B] = 16;
40 offsets[ERROR_COLOR] = 16;
41 offsets[PATTERN_POINT_COLOR] = 16;
42 offsets[PATTERN_POINT_COLOR_A] = 16;
43 offsets[PATTERN_POINT_COLOR_B] = 16;
44 offsets[SYMBOL_A] = 16;
45 offsets[SYMBOL_B] = 16;
46 offsets[SYMBOL_C] = 16;
47 offsets[SYMBOL_D] = 16;
48 offsets[SYMBOL_E] = 16;
49 offsets[PUSH_SYMBOL_COLORS] = sizeof(int);
50 offsets[OUTER_BACKGROUND] = 16;
51 offsets[OUTER_BACKGROUND_MODE] = sizeof(int);
52 offsets[TRACED_EDGES] = 16;
53 offsets[AUDIO_PREFIX] = sizeof(void*);
54// offsets[IS_CYLINDER] = sizeof(int);
55// offsets[CYLINDER_Z0] = sizeof(float);
56// offsets[CYLINDER_Z1] = sizeof(float);
57// offsets[CYLINDER_RADIUS] = sizeof(float);
58 offsets[SPECULAR_ADD] = sizeof(float);
59 offsets[SPECULAR_POWER] = sizeof(int);
60 offsets[PATH_WIDTH_SCALE] = sizeof(float);
61 offsets[STARTPOINT_SCALE] = sizeof(float);
62 offsets[NUM_DOTS] = sizeof(int);
63 offsets[NUM_CONNECTIONS] = sizeof(int);
64 offsets[DOT_POSITIONS] = sizeof(void*);
65 offsets[DOT_FLAGS] = sizeof(void*);
66 offsets[DOT_CONNECTION_A] = sizeof(void*);
67 offsets[DOT_CONNECTION_B] = sizeof(void*);
68 offsets[DECORATIONS] = sizeof(void*);
69 offsets[DECORATION_FLAGS] = sizeof(void*);
70 offsets[DECORATION_COLORS] = sizeof(void*);
71 offsets[NUM_DECORATIONS] = sizeof(int);
72 offsets[REFLECTION_DATA] = sizeof(void*);
73 offsets[GRID_SIZE_X] = sizeof(int);
74 offsets[GRID_SIZE_Y] = sizeof(int);
75 offsets[STYLE_FLAGS] = sizeof(int);
76 offsets[SEQUENCE_LEN] = sizeof(int);
77 offsets[SEQUENCE] = sizeof(void*);
78 offsets[DOT_SEQUENCE_LEN] = sizeof(int);
79 offsets[DOT_SEQUENCE] = sizeof(void*);
80 offsets[DOT_SEQUENCE_LEN_REFLECTION] = sizeof(int);
81 offsets[DOT_SEQUENCE_REFLECTION] = sizeof(void*);
82 offsets[NUM_COLORED_REGIONS] = sizeof(int);
83 offsets[COLORED_REGIONS] = sizeof(void*);
84 offsets[PANEL_TARGET] = sizeof(void*);
85 offsets[SPECULAR_TEXTURE] = sizeof(void*);
86 }
87
88 for (auto const& [offset, size] : offsets) {
89 std::vector<byte> panel1data = ReadPanelData<byte>(panel1, offset, size);
90 std::vector<byte> panel2data = ReadPanelData<byte>(panel2, offset, size);
91 WritePanelData<byte>(panel2, offset, panel1data);
92 WritePanelData<byte>(panel1, offset, panel2data);
93 }
94}
95
96void RandomizerCore::ReassignTargets(const std::vector<int>& panels, const std::vector<int>& order) {
97 // This list is offset by 1, so the target of the Nth panel is in position N (aka the N+1th element)
98 // The first panel may not have a wire to power it, so we use the panel ID itself.
99 std::vector<int> targetToActivatePanel = {panels[0] + 1};
100 for (const int panel : panels) {
101 int target = ReadPanelData<int>(panel, TARGET, 1)[0];
102 targetToActivatePanel.push_back(target);
103 }
104
105 for (size_t i=0; i<order.size() - 1; i++) {
106 // Set the target of order[i] to order[i+1], using the "real" target as determined above.
107 const int panelTarget = targetToActivatePanel[order[i+1]];
108
109 std::stringstream message;
110 message << "i=" << i;
111 message << " order[i]=" << order[i];
112 message << " order[i+1]=" << order[i+1];
113 message << " panels[order[i]]=0x" << std::hex << panels[order[i]];
114 message << " panels[order[i+1]]=0x" << std::hex << panels[order[i+1]];
115 message << " panelTarget=0x" << std::hex << panelTarget << std::endl;
116 OutputDebugStringA(message.str().c_str());
117 WritePanelData<int>(panels[order[i]], TARGET, {panelTarget});
118 }
119}