- u32 buffer_id = world.frame & 0x1;
- u32 buffer_next = buffer_id ^ 0x1;
-
- for( int y = 1; y < world.h-1; y ++ )
- {
- for( int x = 1; x < world.w-1; x ++ )
- {
- struct cell *cell = &world.data[y*world.w+x];
-
- if( cell->state & FLAG_OUTPUT )
- cell->water[ buffer_next ] = 16;
- else
- {
- int has_source = 0;
- cell->water[ buffer_next ] = 0;
-
- if( cell->state & FLAG_CANAL )
- {
- v2i dirs[] = {{1,0},{-1,0},{0,-1}};
-
- for( int i = 0; i < vg_list_size( dirs ); i ++ )
- {
- struct cell *neighbour = &world.data[(y+dirs[i][1])*world.w+x+dirs[i][0]];
-
- // Non canals will be ignored
- if( !(neighbour->state & (FLAG_CANAL|FLAG_OUTPUT)) )
- continue;
-
- // Only vertical pulls allowed on neighbour splitters
- if( (neighbour->state & FLAG_SPLIT) && i != 2 )
- continue;
-
- // Only vertical pulls allowed for mergers
- if( (cell->state & FLAG_MERGER) && i != 2 )
- continue;
-
- // Test for renewall cases if we have drop L/R check if i matches direction.
- if( (((cell->state & FLAG_DROP_L)&&i==1) || ((cell->state & FLAG_DROP_R)&&i==0)) && neighbour->water[ buffer_id ] )
- {
- cell->water[ buffer_next ] = 16;
- has_source = 1;
- }
- else
- if( neighbour->water[ buffer_id ] > cell->water[ buffer_next ]+1 )
- {
- has_source = 1;
- cell->water[ buffer_next ] = neighbour->water[ buffer_id ]-1;
- }
- }
- }
-
- if( !has_source && cell->water[ buffer_id ] )
- cell->water[ buffer_next ] = cell->water[ buffer_id ]-1;
- }
- }
- }
-
- world.frame ^= 0x1;
- }
-