diff --git a/fluid_sim.cpp b/fluid_sim.cpp index 909cb7e..ba37f62 100644 --- a/fluid_sim.cpp +++ b/fluid_sim.cpp @@ -252,27 +252,44 @@ void mpuActiveMonitorMode() { -struct GridCell { - uint8_t particles[10]; - uint8_t count; -}; - -GridCell grid[GRID_SIZE][GRID_SIZE]; +// Optimized spatial grid using single array + cell indices +uint8_t gridParticles[NUM_PARTICLES]; // All particles in grid order +uint16_t gridCellStart[GRID_SIZE * GRID_SIZE]; // Start index for each cell +uint8_t gridCellCount[GRID_SIZE * GRID_SIZE]; // Count for each cell #ifdef DEBUG bool blinkState = true; #endif void buildSpatialGrid() { - memset(grid, 0, sizeof(grid)); - - for(int i=0; i= GRID_SIZE) continue; if(gy+dy < 0 || gy+dy >= GRID_SIZE) continue; - GridCell &cell = grid[gx+dx][gy+dy]; - for(int c=0; c