better grid generator
This commit is contained in:
parent
0cecb05044
commit
11fabe1f29
26
main.cpp
26
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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user