uhh
authorhgn <hgodden00@gmail.com>
Fri, 17 Sep 2021 20:52:05 +0000 (21:52 +0100)
committerhgn <hgodden00@gmail.com>
Fri, 17 Sep 2021 20:52:05 +0000 (21:52 +0100)
fishladder.c

index 5ad95d6844efef42a71a8c8d2e0e4ec6fb54732e..f342895d4ed669f445e3cb69b16f1477b4dc4af6 100644 (file)
@@ -125,34 +125,41 @@ int main( int argc, char *argv[] )
 #define CELL_FLAG_UPLVL 0x100
 #define CELL_FLAG_MERGE 0x200
 
+// Cell data:
+// | byte 3 | byte 2 | byte 1 | byte 0 |
+// | anim   | cfg    | rflags | sflags |
+
+// Static flags
+// Level defined (fixed)
+#define FLAG_WALL                      0x1     /* Border cells // non passable */
+#define FLAG_LEVEL_CANAL       0x2     /* Used to mark canals from IO or static sections etc */
+
+// Player defined
+#define FLAG_CANAL     0x4                     /* Cell is marked as canal and can transport water */
+#define FLAG_UNUSED0   0x8
+#define FLAG_UNUSED1 0x10
+#define FLAG_UNUSED2 0x20
+#define FLAG_UNUSED3   0x40
+#define FLAG_UNUSED4   0x80
+
+// Volatile flags
+#define FLAG_WATER     0x100                   /* Does this cell have water flowing through it */
+#define FLAG_UNUSED5 0x200
+#define FLAG_UNUSED6 0x400
+#define FLAG_UNUSED7 0x800
+
+#define FLAG_UNUSED8 0x1000
+#define FLAG_UNUSED9 0x2000
+#define FLAG_UNUSEDA 0x4000
+#define FLAG_UNUSEDB 0x8000
+
+// Combined
+#define CFLAG_TRANSPORT (FLAG_CANAL|FLAG_LEVEL_CANAL)
+
 static struct
 {
        u32 x,y;
-       
-       struct cell
-       {       
-               u32 flags;
-               u32 model_id;
-               
-               char *conditions;
                
-               int level;
-               int state;
-               int flowing[2];
-               int source_count;
-       }
-       * cells;
-       
-       struct fish
-       {
-               int alive;
-               int co[2];
-               int dir[2];
-               char data;
-       }
-       fishes[ 20 ];
-       int num_fishes;
-       
        v2f origin;
        struct cell *selected;
        int select_valid;
@@ -290,28 +297,13 @@ static void map_stack_current_coords( int coords[2], int offset )
        coords[1] = map.stack.frames[ map.stack.level+offset ].y;
 }
 
-static void map_update_visual(void)
+static void map_reclassify( v4i bounds )
 {
        u8 celldata[ 4096 ];
        
-       static int compute_flow_counter = 0;
-       compute_flow_counter ^= 0x1;
-       
-       for( int i = 0; i < map.y*map.x; i ++ ) 
+       for( int y = bounds[1]; y < bounds[3]; y ++ )
        {
-               struct cell *cell = map.cells + i;
-               
-               cell->flowing[compute_flow_counter] = cell->flowing[compute_flow_counter^0x1];
-               
-               if( !map.cells[i].source_count )
-                       cell->flowing[ compute_flow_counter ] = vg_max( cell->flowing[ compute_flow_counter ] - 10, 0 );
-       
-               map.cells[i].source_count = 0;
-       }
-       
-       for( int y = 0; y < map.y; y ++ )
-       {
-               for( int x = 0; x < map.x; x ++ )
+               for( int x = bounds[0]; x < bounds[2]; x ++ )
                {
                        struct cell *cur = map.cells + y*map.x + x;
                        u8 *cellbytes = celldata + (y*map.x+x)*4; 
@@ -327,96 +319,19 @@ static void map_update_visual(void)
                                
                                u32 config = (a?0x1:0x0) | (b?0x2:0x0) | (c?0x4:0x0) | (d?0x8:0x0);
                                cellbytes[ 0 ] = config;
-                               
-                               if( cur->flags & CELL_FLAG_OUTPUT )
-                                       cur->flowing[ compute_flow_counter ] = 128;
                        }
                        else
                        {
                                // TODO: Random background tiles
                                cellbytes[ 0 ] = 15;
                        }
-               }
-       }
-       
-       int const k_rate_flow = 16;
-       
-       map_stack_refresh();
-       for( int i = 0; i < arrlen( map.io ); i ++ )
-       {
-               int inputcoord[2];
-               if( map.cells[ map.io[i] ].flags & CELL_FLAG_OUTPUT )
-               {
-                       map_tile_coords_from_index( map.io[i], inputcoord );
-                       map_stack_init( inputcoord );
-                       struct cell *cell = gettile( inputcoord );
                        
-                       int cr[2];
-                       
-                       do
-                       {
-                               map_stack_current_coords( cr, 0 );
-                               
-                               u8 *cellbytes = celldata + (cr[1]*map.x+cr[0])*4; 
-                               
-                               int outflow = cell->flowing[ compute_flow_counter ^ 0x1 ];
-                               int sourcing = outflow? 1: 0;
-                               int outrate = outflow == 128? k_rate_flow: 0;
-                               
-                               struct cell *a, *b, *d;
-                               a = gettile( (int[2]){ cr[0], cr[1]+1 } );
-                               b = gettile( (int[2]){ cr[0]+1, cr[1] } );
-                               d = gettile( (int[2]){ cr[0]-1, cr[1] } );
-                       
-                               int compute_l = 0, compute_r = 0;
-                       
-                               switch( cellbytes[0] )
-                               {
-                                       // DOWN
-                                       case 1: case 5: case 11: case 9: case 3:
-                                               a->flowing[ compute_flow_counter ] += outrate;
-                                               a->source_count += sourcing;
-                                       break;
-                                       case 2: case 6: compute_r = 1; break;
-                                       case 8: case 12: compute_l = 1; break;
-                                       case 10: case 14: compute_l = 1; compute_r = 1; break;
-                                       default: break;
-                               }
-                               
-                               if( compute_r && (celldata[ (cr[1]*map.x+cr[0]+1)*4 ] != 14) )
-                               {
-                                       b->flowing[ compute_flow_counter ] += outrate;
-                                       b->source_count += sourcing;
-                               }
-                               
-                               if( compute_l && (celldata[ (cr[1]*map.x+cr[0]-1)*4 ] != 14) )
-                               {
-                                       d->flowing[ compute_flow_counter ] += outrate;
-                                       d->source_count += sourcing;
-                               }
-                               
-                               if( cellbytes[0] == 10 )
-                               {
-                                       int crl[2];
-                                       map_stack_current_coords( crl, -1 );
-                                       
-                                       if( crl[0] < cr[0] )
-                                       {
-                                               // TODO: Add reverse flag
-                                               //cellbytes[1] = 1;
-                                       }
-                               }
-                       }
-                       while( (cell = map_stack_next()) );
+                       cellbytes[ 1 ] = 0x00;
+                       cellbytes[ 2 ] = 0x00;
+                       cellbytes[ 3 ] = 0x00;
                }
        }
        
-       for( int i = 0; i < map.y*map.x; i ++ )
-       {
-               map.cells[i].flowing[ compute_flow_counter ] = vg_min( 128, map.cells[i].flowing[ compute_flow_counter ] );
-               celldata[ i*4+2 ] = map.cells[i].flowing[ compute_flow_counter ];
-       }
-       
        glBindBuffer( GL_ARRAY_BUFFER, map.tiles_vbo );
        glBufferSubData( GL_ARRAY_BUFFER, 16*sizeof(float) + 1024*2*sizeof(float), map.x*map.y*4, celldata );
 }
@@ -515,8 +430,6 @@ static int map_load( const char *str )
                        }
                        
                        row[ cx ].conditions = NULL;
-                       row[ cx ].flowing[ 0 ] = 0;
-                       row[ cx ].source_count = 0;
                
                        // Parse the various cell types
                        if( *c == '+' || *c == '-' )
@@ -636,6 +549,8 @@ void vg_update(void)
                        }
                }
        }
+       
+       map_reclassify();
                
        v2f tile_pos;
        v2_copy( vg_mouse_ws, tile_pos );
@@ -698,7 +613,7 @@ void vg_render(void)
        
        glBindVertexArray( map.tiles_vao );
        
-       map_update_visual();
+       //map_update_visual();
        
        SHADER_USE( tilemap_shader );
        glUniformMatrix3fv( SHADER_UNIFORM( tilemap_shader, "uPv" ), 1, GL_FALSE, (float *)vg_pv );