#define FLAG_OUTPUT 0x2
#define FLAG_CANAL 0x4
#define FLAG_WALL 0x8
-#define FLAG_DROP_L 0x10
-#define FLAG_SPLIT 0x20
-#define FLAG_MERGER 0x40
-#define FLAG_DROP_R 0x80
#define FLAG_FLIP_FLOP 0x100
#define FLAG_FLIP_ROTATING 0x200
return 1;
}
+// Entire world: 2 -> worldx/y-2
+
+static void fl_world_update( v2i start, v2i end )
+{
+ for( int y = start[1]; y < end[1]; y ++ )
+ {
+ for( int x = start[0]; x < end[0]; 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;
+ }
+ }
+}
+
void vg_update(void)
{
static int curlevel = 0;
world.io[i].recv_count = 0;
}
}
+
+ // There was world reconfiguarion here previously...
+ fl_world_update( (v2i){2,2}, (v2i){world.w-2,world.h-2} );
- // 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;
- }
- }
-
// Fish ticks
if( world.simulating )
{
continue;
}
- if( cell_current->state & FLAG_SPLIT )
+ if( cell_current->config == k_cell_type_split )
{
// Flip flop L/R
fish->dir[0] = cell_current->state&FLAG_FLIP_FLOP?1:-1;
cell_current->state ^= FLAG_FLIP_FLOP;
}
- else if( cell_current->state & FLAG_MERGER )
+ else if( cell_current->config == k_cell_type_merge )
{
// Can only move up
fish->dir[0] = 0;
{
struct cell *cell = pcell((v2i){x,y});
- if( cell->state & FLAG_SPLIT )
+ if( cell->config == k_cell_type_split )
{
float rotation = cell->state & FLAG_FLIP_FLOP? vg_rad( -45.0f ): vg_rad( 45.0f );