From: hgn Date: Sun, 26 Sep 2021 00:28:35 +0000 (+0100) Subject: refactor cell references to use pcell X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;h=9eeaea6d706b25491a7bc32b73d3b409be1ed4c3;p=fishladder.git refactor cell references to use pcell --- diff --git a/fishladder.c b/fishladder.c index 8d1443b..dc87527 100644 --- a/fishladder.c +++ b/fishladder.c @@ -424,7 +424,7 @@ static int cell_interactive( v2i co ) for( int y = co[1]-2; y < co[1]+3; y ++ ) for( int x = co[0]-2; x < co[0]+3; x ++ ) { - struct cell *cell = &world.data[ world.w*y + x ]; + struct cell *cell = pcell((v2i){x,y}); if( cell && (cell->state & (FLAG_CANAL|FLAG_INPUT|FLAG_OUTPUT)) ) blob |= 0x1 << ((y-(co[1]-2))*5 + x-(co[0]-2)); @@ -532,18 +532,18 @@ void vg_update(void) u8 config = 0x00; - if( world.data[y*world.w+x].state & FLAG_CANAL ) + if( pcell((v2i){x,y})->state & FLAG_CANAL ) { 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]]; + 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; - world.data[ y*world.w+x ].config = config; - world.data[ y*world.w+x ].state &= ~(FLAG_DROP_L|FLAG_DROP_R|FLAG_SPLIT|FLAG_MERGER); + pcell((v2i){x,y})->config = config; + pcell((v2i){x,y})->state &= ~(FLAG_DROP_L|FLAG_DROP_R|FLAG_SPLIT|FLAG_MERGER); } } @@ -554,7 +554,7 @@ void vg_update(void) // R,-,L,U - 1011 (merger, 2 drop created) - u8 config = world.data[y*world.w+x].config; + u8 config = pcell((v2i){x,y})->config; if( config == 0x7 ) // splitter { @@ -583,7 +583,7 @@ void vg_update(void) { for( int x = 1; x < world.w-1; x ++ ) { - struct cell *cell = &world.data[y*world.w+x]; + struct cell *cell = pcell((v2i){x,y}); if( cell->state & FLAG_OUTPUT ) cell->water[ buffer_next ] = 16; @@ -780,7 +780,7 @@ void vg_render(void) v4f colour; - struct cell *cell = &world.data[y*world.w+x]; + struct cell *cell = pcell((v2i){x,y}); if( cell->state & FLAG_WALL ) { v4_copy( (v4f){ 0.2f, 0.2f, 0.2f, 1.0f }, colour ); } else if( cell->state & FLAG_CANAL ) { v4_copy( (v4f){ 0.6f, 0.6f, 0.6f, 1.0f }, colour ); }