diff options
Diffstat (limited to 'Source/RandomizerCore.cpp')
-rw-r--r-- | Source/RandomizerCore.cpp | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/Source/RandomizerCore.cpp b/Source/RandomizerCore.cpp index d4aadef..f00dacd 100644 --- a/Source/RandomizerCore.cpp +++ b/Source/RandomizerCore.cpp | |||
@@ -3,17 +3,6 @@ | |||
3 | #include "Random.h" | 3 | #include "Random.h" |
4 | #include <sstream> | 4 | #include <sstream> |
5 | 5 | ||
6 | static int lastKnownFrame = 1 << 30; | ||
7 | |||
8 | RandomizerCore::RandomizerCore() { | ||
9 | int currentFrame = _memory.ReadData<int>({SCRIPT_FRAMES}, 1)[0]; | ||
10 | if (currentFrame < lastKnownFrame) { | ||
11 | // Time went backwards, indicates new game | ||
12 | WriteMetadata(0); | ||
13 | } | ||
14 | lastKnownFrame = currentFrame; | ||
15 | } | ||
16 | |||
17 | void RandomizerCore::Randomize(std::vector<int>& panels, int flags) { | 6 | void RandomizerCore::Randomize(std::vector<int>& panels, int flags) { |
18 | return RandomizeRange(panels, flags, 0, panels.size()); | 7 | return RandomizeRange(panels, flags, 0, panels.size()); |
19 | } | 8 | } |
@@ -47,7 +36,7 @@ void RandomizerCore::SwapPanels(int panel1, int panel2, int flags) { | |||
47 | offsets[REFLECTION_PATH_COLOR] = 16; | 36 | offsets[REFLECTION_PATH_COLOR] = 16; |
48 | offsets[DOT_COLOR] = 16; | 37 | offsets[DOT_COLOR] = 16; |
49 | offsets[ACTIVE_COLOR] = 16; | 38 | offsets[ACTIVE_COLOR] = 16; |
50 | offsets[BACKGROUND_REGION_COLOR] = 16; | 39 | offsets[BACKGROUND_REGION_COLOR] = 12; // Not copying alpha to preserve transparency. |
51 | offsets[SUCCESS_COLOR_A] = 16; | 40 | offsets[SUCCESS_COLOR_A] = 16; |
52 | offsets[SUCCESS_COLOR_B] = 16; | 41 | offsets[SUCCESS_COLOR_B] = 16; |
53 | offsets[STROBE_COLOR_A] = 16; | 42 | offsets[STROBE_COLOR_A] = 16; |
@@ -101,10 +90,10 @@ void RandomizerCore::SwapPanels(int panel1, int panel2, int flags) { | |||
101 | } | 90 | } |
102 | 91 | ||
103 | for (auto const& [offset, size] : offsets) { | 92 | for (auto const& [offset, size] : offsets) { |
104 | std::vector<byte> panel1data = _memory.ReadPanelData<byte>(panel1, offset, size); | 93 | std::vector<byte> panel1data = _memory->ReadPanelData<byte>(panel1, offset, size); |
105 | std::vector<byte> panel2data = _memory.ReadPanelData<byte>(panel2, offset, size); | 94 | std::vector<byte> panel2data = _memory->ReadPanelData<byte>(panel2, offset, size); |
106 | _memory.WritePanelData<byte>(panel2, offset, panel1data); | 95 | _memory->WritePanelData<byte>(panel2, offset, panel1data); |
107 | _memory.WritePanelData<byte>(panel1, offset, panel2data); | 96 | _memory->WritePanelData<byte>(panel1, offset, panel2data); |
108 | } | 97 | } |
109 | } | 98 | } |
110 | 99 | ||
@@ -114,7 +103,7 @@ void RandomizerCore::ReassignTargets(const std::vector<int>& panels, const std:: | |||
114 | // The first panel may not have a wire to power it, so we use the panel ID itself. | 103 | // The first panel may not have a wire to power it, so we use the panel ID itself. |
115 | targets = {panels[0] + 1}; | 104 | targets = {panels[0] + 1}; |
116 | for (const int panel : panels) { | 105 | for (const int panel : panels) { |
117 | int target = _memory.ReadPanelData<int>(panel, TARGET, 1)[0]; | 106 | int target = _memory->ReadPanelData<int>(panel, TARGET, 1)[0]; |
118 | targets.push_back(target); | 107 | targets.push_back(target); |
119 | } | 108 | } |
120 | } | 109 | } |
@@ -122,25 +111,29 @@ void RandomizerCore::ReassignTargets(const std::vector<int>& panels, const std:: | |||
122 | for (size_t i=0; i<order.size() - 1; i++) { | 111 | for (size_t i=0; i<order.size() - 1; i++) { |
123 | // Set the target of order[i] to order[i+1], using the "real" target as determined above. | 112 | // Set the target of order[i] to order[i+1], using the "real" target as determined above. |
124 | const int panelTarget = targets[order[i+1]]; | 113 | const int panelTarget = targets[order[i+1]]; |
125 | _memory.WritePanelData<int>(panels[order[i]], TARGET, {panelTarget}); | 114 | _memory->WritePanelData<int>(panels[order[i]], TARGET, {panelTarget}); |
126 | } | 115 | } |
127 | } | 116 | } |
128 | 117 | ||
129 | void RandomizerCore::ReassignNames(const std::vector<int>& panels, const std::vector<int>& order) { | 118 | void RandomizerCore::ReassignNames(const std::vector<int>& panels, const std::vector<int>& order) { |
130 | std::vector<int64_t> names; | 119 | std::vector<int64_t> names; |
131 | for (const int panel : panels) { | 120 | for (const int panel : panels) { |
132 | names.push_back(_memory.ReadPanelData<int64_t>(panel, AUDIO_LOG_NAME, 1)[0]); | 121 | names.push_back(_memory->ReadPanelData<int64_t>(panel, AUDIO_LOG_NAME, 1)[0]); |
133 | } | 122 | } |
134 | 123 | ||
135 | for (int i=0; i<panels.size(); i++) { | 124 | for (int i=0; i<panels.size(); i++) { |
136 | _memory.WritePanelData<int64_t>(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); | 125 | _memory->WritePanelData<int64_t>(panels[i], AUDIO_LOG_NAME, {names[order[i]]}); |
137 | } | 126 | } |
138 | } | 127 | } |
139 | 128 | ||
140 | short RandomizerCore::ReadMetadata() { | 129 | short RandomizerCore::ReadMetadata() { |
141 | return _memory.ReadData<short>({GLOBALS + METADATA}, 1)[0]; | 130 | return _memory->ReadData<short>({GLOBALS + METADATA}, 1)[0]; |
142 | } | 131 | } |
143 | 132 | ||
144 | void RandomizerCore::WriteMetadata(short metadata) { | 133 | void RandomizerCore::WriteMetadata(short metadata) { |
145 | return _memory.WriteData<short>({GLOBALS + METADATA}, {metadata}); | 134 | return _memory->WriteData<short>({GLOBALS + METADATA}, {metadata}); |
146 | } \ No newline at end of file | 135 | } |
136 | |||
137 | int RandomizerCore::GetCurrentFrame() { | ||
138 | return _memory->ReadData<int>({SCRIPT_FRAMES}, 1)[0]; | ||
139 | } | ||