better tile classification
authorhgn <hgodden00@gmail.com>
Wed, 21 Jul 2021 21:13:46 +0000 (22:13 +0100)
committerhgn <hgodden00@gmail.com>
Wed, 21 Jul 2021 21:13:46 +0000 (22:13 +0100)
fishladder.c

index a06f0751b02c691782011ca6b3d4684fe01e515e..af6a2a3d68f995dc2dac2e20892fdf00d058d40a 100644 (file)
@@ -44,9 +44,11 @@ int main( int argc, char *argv[] )
 #define CELL_FLAG_HOVER 0x8
 #define CELL_FLAG_ITER 0x10
 #define CELL_FLAG_CANAL 0x20
-#define CELL_FLAG_CONNECTOR 0x40 /* Does this cell split and have an incoming vertical connection? */
+#define CELL_FLAG_SPLIT 0x40 /* Does this cell split and have an incoming vertical connection? */
 #define CELL_FLAG_WALKABLE (CELL_FLAG_IO|CELL_FLAG_CANAL)
 #define CELL_FLAG_VISITED 0x80
+#define CELL_FLAG_UPLVL 0x100
+#define CELL_FLAG_MERGE 0x200
 
 static struct
 {
@@ -120,7 +122,16 @@ static struct cell *map_tile_at( int pos[2] )
        return NULL;
 }
 
-void map_tile_coords_from_index( int i, int coords[2] )
+static struct cell *map_tile_at_cond( int pos[2], u32 flags )
+{
+       struct cell *cell = map_tile_at( pos );
+       if( cell && (cell->flags & flags) )
+               return cell;
+               
+       return NULL;
+}
+
+static void map_tile_coords_from_index( int i, int coords[2] )
 {
        coords[0] = i % map.x;
        coords[1] = (i - coords[0])/map.x;
@@ -360,30 +371,61 @@ void vg_update(void)
        {
                for( int x = 0; x < map.x; x ++ )
                {
-                       // Cell is a connector if it has at least 3 connections
-                       int output_dirs[][2] = { {0,-1}, {-1,0}, {1,0}, {0,1} };
-                       u32 output_count = 0;
-                       struct cell *tile, *thistile;
-                       thistile = map_tile_at( (int [2]){x,y} );
-
-                       if( thistile->flags & CELL_FLAG_CANAL )
+                       struct cell *tile, *upper, *lower, *l, *r;      
+                       tile = map_tile_at( (int [2]){ x, y } );
+                       tile->flags &= ~(CELL_FLAG_SPLIT|CELL_FLAG_MERGE|CELL_FLAG_UPLVL);
+                       
+                       if( tile->flags & CELL_FLAG_WALKABLE )
                        {
-                               for( int i = 0; i < vg_list_size( output_dirs ); i ++ )
+                               r = map_tile_at_cond( (int[2]){ x+1, y }, CELL_FLAG_WALKABLE );
+                               l = map_tile_at_cond( (int[2]){ x-1, y }, CELL_FLAG_WALKABLE );
+
+                               if( r && l )
                                {
-                                       tile = map_tile_at( (int [2]){ x+output_dirs[i][0], y+output_dirs[i][1] } );
+                                       upper = map_tile_at_cond( (int[2]){ x, y-1 }, CELL_FLAG_WALKABLE );
+                                       lower = map_tile_at_cond( (int[2]){ x, y+1 }, CELL_FLAG_WALKABLE );
+                                       
+                                       if( upper )
+                                       {
+                                               tile->flags |= CELL_FLAG_MERGE | CELL_FLAG_UPLVL;
+                                       }
                                        
-                                       if( tile && tile->flags & CELL_FLAG_CANAL )
-                                               output_count ++;
+                                       if( lower )
+                                       {
+                                               tile->flags |= CELL_FLAG_SPLIT;
+                                               l->flags |= CELL_FLAG_UPLVL;
+                                               r->flags |= CELL_FLAG_UPLVL;
+                                       }
                                }
-                               
-                               if( output_count >= 3 )
-                                       thistile->flags |= CELL_FLAG_CONNECTOR;
-                               else
-                                       thistile->flags &= ~CELL_FLAG_CONNECTOR;
                        }
                }
        }
        
+       // Compute classification
+       /*
+       map_stack_refresh();
+       
+       for( int i = 0; i < arrlen( map.io ); i ++ )
+       {
+               struct *cell cell = &map.cells[ map.io ];
+               int coords[2];
+               
+               if( cell->flags & CELL_FLAG_INPUT )
+               {
+                       map_tile_coords_from_index( map.io, coords );
+                       map_stack_init( coords );
+                       
+                       do
+                       {
+                               if( cell->flags & CELL_FLAG_CONNECTOR )
+                               {
+                                       
+                               }
+                       }
+                       while( (cell = map_stack_next()) );
+               }
+       }*/
+       
        // Get mouse ray
        vec3 ray_origin;
        vec3 ray_dir;
@@ -436,7 +478,7 @@ void vg_update(void)
                                }
                                
                                int die = 0;
-                               if( tile->flags & CELL_FLAG_CONNECTOR )
+                               if( tile->flags & CELL_FLAG_SPLIT )
                                {
                                        die = 1;
                                        int new_dir[][2] = { {0,-1},{1,0},{-1,0} };
@@ -548,7 +590,7 @@ void vg_update(void)
                                {
                                        if( map.selected->flags & CELL_FLAG_CANAL )
                                        {
-                                               map.selected->flags &= ~(CELL_FLAG_CANAL | CELL_FLAG_CONNECTOR);
+                                               map.selected->flags &= ~(CELL_FLAG_CANAL);
                                        }
                                        else
                                        {
@@ -599,8 +641,10 @@ void vg_render(void)
                        else if( cell->flags & CELL_FLAG_WALL ) glm_vec3_copy( (vec3){ 0.1f,0.1f,0.1f }, colour );
                        else if( cell->flags & CELL_FLAG_CANAL ) glm_vec3_copy( (vec3){ 0.5f,0.5f,0.8f }, colour );
                        
-                       if( cell->flags & CELL_FLAG_CONNECTOR )
+                       if( cell->flags & CELL_FLAG_SPLIT )
                                glm_vec3_copy( (vec3){ 0.6f, 0.f, 0.9f }, colour );
+                       else if( cell->flags & CELL_FLAG_MERGE )
+                               glm_vec3_copy( (vec3){ 0.f, 0.6f, 0.8f }, colour );
                        
                        if( map.selected == cell )
                        {