- // Simulation stuff
- // ========================================================
-
- for( int y = 2; y < world.h-2; y ++ )
- {
- for( int x = 2; x < world.w-2; x ++ )
- {
- v2i dirs[] = {{1,0},{0,1},{-1,0},{0,-1}};
-
- u8 config = 0x00;
-
- if( pcell((v2i){x,y})->state & FLAG_CANAL )
- {
- for( int i = 0; i < vg_list_size( dirs ); i ++ )
- {
- struct cell *neighbour = pcell((v2i){x+dirs[i][0], y+dirs[i][1]});
- if( neighbour->state & (FLAG_CANAL|FLAG_INPUT|FLAG_OUTPUT) )
- config |= 0x1 << i;
- }
- } else config = 0xF;
-
- pcell((v2i){x,y})->config = config;
- pcell((v2i){x,y})->state &= ~(FLAG_DROP_L|FLAG_DROP_R|FLAG_SPLIT|FLAG_MERGER);
- }
- }
-
- for( int y = 2; y < world.h-2; y ++ )
- for( int x = 2; x < world.w-2; x ++ )
- {
- // R,D,L,- 1110 (splitter, 1 drop created)
-
- // R,-,L,U - 1011 (merger, 2 drop created)
-
- u8 config = pcell((v2i){x,y})->config;
-
- if( config == k_cell_type_split ) // splitter
- {
- struct cell *cell = pcell((v2i){x,y});
-
- cell->state |= (FLAG_SPLIT | FLAG_DROP_L | FLAG_DROP_R);
- }
- else if( config == k_cell_type_merge )
- {
- world.data[y*world.w+x-1].state |= FLAG_DROP_R;
- world.data[y*world.w+x+1].state |= FLAG_DROP_L;
- world.data[y*world.w+x].state |= FLAG_MERGER;
- }
- }
-