From 11fabe1f293ecb28ee05d0b11741a506f1be3e0d Mon Sep 17 00:00:00 2001 From: Dejvino Date: Sat, 28 Feb 2026 19:49:27 +0100 Subject: [PATCH] better grid generator --- main.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/main.cpp b/main.cpp index c6fd4e5..4c7be0f 100644 --- a/main.cpp +++ b/main.cpp @@ -398,6 +398,7 @@ void drawGridCell(SDL_Renderer* renderer, int x, int y, int size, SynthEngine::G } else if (cell.type == SynthEngine::GridCell::GATE_INPUT) { SDL_Rect box = {cx - r, cy - r, r*2, r*2}; SDL_RenderDrawRect(renderer, &box); + drawDirectionArrow(renderer, cx, cy, size, cell.rotation); if (cell.value > 0.5f) SDL_RenderFillRect(renderer, &box); drawString(renderer, cx - 8, cy - 5, 12, "G-IN"); drawTypeLabel(renderer, x, y, 'K'); @@ -738,10 +739,10 @@ void randomizeGrid() { } int attempts = 0; - bool inputOscillatorReachable = false; + bool validGrid = false; bool visited[SynthEngine::GRID_W][SynthEngine::GRID_H]; - while (!inputOscillatorReachable && attempts < 1000) { + while (!validGrid && attempts < 1000) { attempts++; // 2. Randomize (without allocation) @@ -817,20 +818,27 @@ void randomizeGrid() { } } - // After BFS, check if an input oscillator is reachable + // After BFS, check if requirements are met + bool hasSoundSource = false; + bool hasGate = false; for (int x = 0; x < SynthEngine::GRID_W; ++x) { for (int y = 0; y < SynthEngine::GRID_H; ++y) { - if (visited[x][y] && engine.grid[x][y].type == SynthEngine::GridCell::INPUT_OSCILLATOR) { - inputOscillatorReachable = true; - break; + if (visited[x][y]) { + if (engine.grid[x][y].type == SynthEngine::GridCell::INPUT_OSCILLATOR || + engine.grid[x][y].type == SynthEngine::GridCell::WAVETABLE) { + hasSoundSource = true; + } + if (engine.grid[x][y].type == SynthEngine::GridCell::GATE_INPUT) { + hasGate = true; + } } } - if (inputOscillatorReachable) break; } + validGrid = hasSoundSource && hasGate; } // 4. Prune unreachable elements if a valid grid was found - if (inputOscillatorReachable) { + if (validGrid) { for (int x = 0; x < SynthEngine::GRID_W; ++x) { for (int y = 0; y < SynthEngine::GRID_H; ++y) { if (!visited[x][y]) { @@ -854,7 +862,7 @@ void randomizeGrid() { } } - printf("Randomized in %d attempts. Input Osc reachable: %s\n", attempts, inputOscillatorReachable ? "YES" : "NO"); + printf("Randomized in %d attempts. Valid: %s\n", attempts, validGrid ? "YES" : "NO"); } void loadPreset(int preset) {