diff options
-rw-r--r-- | Source/PuzzlerSerializer.cpp | 25 | ||||
-rw-r--r-- | Source/PuzzlerSerializer.h | 3 |
2 files changed, 19 insertions, 9 deletions
diff --git a/Source/PuzzlerSerializer.cpp b/Source/PuzzlerSerializer.cpp index 86f59e7..cf013ca 100644 --- a/Source/PuzzlerSerializer.cpp +++ b/Source/PuzzlerSerializer.cpp | |||
@@ -234,8 +234,8 @@ void PuzzleSerializer::WriteEndpoints(const Puzzle& p) { | |||
234 | for (int x=0; x<p.width; x++) { | 234 | for (int x=0; x<p.width; x++) { |
235 | for (int y=0; y<p.height; y++) { | 235 | for (int y=0; y<p.height; y++) { |
236 | if (p.grid[x][y].end == Cell::Dir::NONE) continue; | 236 | if (p.grid[x][y].end == Cell::Dir::NONE) continue; |
237 | _connectionsA.push_back(xy_to_loc(p, x, y)); // Target to connect to | 237 | _connectionsA.push_back(xy_to_loc(p, x, y)); |
238 | _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); // This endpoint | 238 | _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); |
239 | 239 | ||
240 | auto [xPos, yPos] = xy_to_pos(p, x, y); | 240 | auto [xPos, yPos] = xy_to_pos(p, x, y); |
241 | switch (p.grid[x][y].end) { | 241 | switch (p.grid[x][y].end) { |
@@ -252,6 +252,7 @@ void PuzzleSerializer::WriteEndpoints(const Puzzle& p) { | |||
252 | yPos -= .05f; | 252 | yPos -= .05f; |
253 | break; | 253 | break; |
254 | } | 254 | } |
255 | _endpointLocations.emplace_back(x, y, static_cast<int>(_intersectionFlags.size())); | ||
255 | _intersectionLocations.push_back(xPos); | 256 | _intersectionLocations.push_back(xPos); |
256 | _intersectionLocations.push_back(yPos); | 257 | _intersectionLocations.push_back(yPos); |
257 | _intersectionFlags.push_back(Flags::IS_ENDPOINT); | 258 | _intersectionFlags.push_back(Flags::IS_ENDPOINT); |
@@ -273,10 +274,10 @@ void PuzzleSerializer::WriteDots(const Puzzle& p) { | |||
273 | if ((x1+1 == x && x2-1 == x && y1 == y && y2 == y) || | 274 | if ((x1+1 == x && x2-1 == x && y1 == y && y2 == y) || |
274 | (y1+1 == y && y2-1 == y && x1 == x && x2 == x)) { | 275 | (y1+1 == y && y2-1 == y && x1 == x && x2 == x)) { |
275 | int other_connection = _connectionsB[i]; | 276 | int other_connection = _connectionsB[i]; |
276 | _connectionsB[i] = static_cast<int>(_intersectionFlags.size()); // This endpoint | 277 | _connectionsB[i] = static_cast<int>(_intersectionFlags.size()); |
277 | 278 | ||
278 | _connectionsA.push_back(other_connection); | 279 | _connectionsA.push_back(other_connection); |
279 | _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); // This endpoint | 280 | _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); |
280 | break; | 281 | break; |
281 | } | 282 | } |
282 | } | 283 | } |
@@ -314,25 +315,25 @@ void PuzzleSerializer::WriteGaps(const Puzzle& p) { | |||
314 | // Reminder: Y goes from 0.0 (bottom) to 1.0 (top) | 315 | // Reminder: Y goes from 0.0 (bottom) to 1.0 (top) |
315 | if (x%2 == 0) { // Vertical gap | 316 | if (x%2 == 0) { // Vertical gap |
316 | _connectionsA.push_back(xy_to_loc(p, x, y-1)); | 317 | _connectionsA.push_back(xy_to_loc(p, x, y-1)); |
317 | _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); // This endpoint | 318 | _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); |
318 | _intersectionLocations.push_back(xPos); | 319 | _intersectionLocations.push_back(xPos); |
319 | _intersectionLocations.push_back(yPos + VERTI_GAP_SIZE / 2); | 320 | _intersectionLocations.push_back(yPos + VERTI_GAP_SIZE / 2); |
320 | _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_VERTI_CONN); | 321 | _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_VERTI_CONN); |
321 | 322 | ||
322 | _connectionsA.push_back(xy_to_loc(p, x, y+1)); | 323 | _connectionsA.push_back(xy_to_loc(p, x, y+1)); |
323 | _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); // This endpoint | 324 | _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); |
324 | _intersectionLocations.push_back(xPos); | 325 | _intersectionLocations.push_back(xPos); |
325 | _intersectionLocations.push_back(yPos - VERTI_GAP_SIZE / 2); | 326 | _intersectionLocations.push_back(yPos - VERTI_GAP_SIZE / 2); |
326 | _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_VERTI_CONN); | 327 | _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_VERTI_CONN); |
327 | } else if (y%2 == 0) { // Horizontal gap | 328 | } else if (y%2 == 0) { // Horizontal gap |
328 | _connectionsA.push_back(xy_to_loc(p, x-1, y)); | 329 | _connectionsA.push_back(xy_to_loc(p, x-1, y)); |
329 | _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); // This endpoint | 330 | _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); |
330 | _intersectionLocations.push_back(xPos - HORIZ_GAP_SIZE / 2); | 331 | _intersectionLocations.push_back(xPos - HORIZ_GAP_SIZE / 2); |
331 | _intersectionLocations.push_back(yPos); | 332 | _intersectionLocations.push_back(yPos); |
332 | _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); | 333 | _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); |
333 | 334 | ||
334 | _connectionsA.push_back(xy_to_loc(p, x+1, y)); | 335 | _connectionsA.push_back(xy_to_loc(p, x+1, y)); |
335 | _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); // This endpoint | 336 | _connectionsB.push_back(static_cast<int>(_intersectionFlags.size())); |
336 | _intersectionLocations.push_back(xPos + HORIZ_GAP_SIZE / 2); | 337 | _intersectionLocations.push_back(xPos + HORIZ_GAP_SIZE / 2); |
337 | _intersectionLocations.push_back(yPos); | 338 | _intersectionLocations.push_back(yPos); |
338 | _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); | 339 | _intersectionFlags.push_back(Flags::HAS_ONE_CONN | Flags::HAS_HORIZ_CONN); |
@@ -371,6 +372,14 @@ void PuzzleSerializer::WriteSequence(const Puzzle& p, int id) { | |||
371 | } | 372 | } |
372 | } | 373 | } |
373 | 374 | ||
375 | Pos endpoint = p.sequence[p.sequence.size() - 1]; | ||
376 | for (auto [x, y, location] : _endpointLocations) { | ||
377 | if (x == endpoint.x && y == endpoint.y) { | ||
378 | sequence.emplace_back(location); | ||
379 | break; | ||
380 | } | ||
381 | } | ||
382 | |||
374 | _memory->WritePanelData<int>(id, SEQUENCE_LEN, {static_cast<int>(sequence.size())}); | 383 | _memory->WritePanelData<int>(id, SEQUENCE_LEN, {static_cast<int>(sequence.size())}); |
375 | _memory->WriteNewArray<int>(id, SEQUENCE, sequence); | 384 | _memory->WriteNewArray<int>(id, SEQUENCE, sequence); |
376 | } | 385 | } |
diff --git a/Source/PuzzlerSerializer.h b/Source/PuzzlerSerializer.h index 535d82f..a49dd90 100644 --- a/Source/PuzzlerSerializer.h +++ b/Source/PuzzlerSerializer.h | |||
@@ -1,9 +1,9 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | #include <memory> | 2 | #include <memory> |
3 | #include <unordered_map> | ||
3 | 4 | ||
4 | #include "Puzzle.h" | 5 | #include "Puzzle.h" |
5 | 6 | ||
6 | |||
7 | class Memory; | 7 | class Memory; |
8 | 8 | ||
9 | class PuzzleSerializer { | 9 | class PuzzleSerializer { |
@@ -56,6 +56,7 @@ private: | |||
56 | std::vector<int> _intersectionFlags; | 56 | std::vector<int> _intersectionFlags; |
57 | std::vector<int> _connectionsA; | 57 | std::vector<int> _connectionsA; |
58 | std::vector<int> _connectionsB; | 58 | std::vector<int> _connectionsB; |
59 | std::vector<std::tuple<int, int, int>> _endpointLocations; | ||
59 | 60 | ||
60 | float MIN, MAX, WIDTH_INTERVAL, HEIGHT_INTERVAL, HORIZ_GAP_SIZE, VERTI_GAP_SIZE; | 61 | float MIN, MAX, WIDTH_INTERVAL, HEIGHT_INTERVAL, HORIZ_GAP_SIZE, VERTI_GAP_SIZE; |
61 | }; | 62 | }; |