1 // Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
5 #include "fishladder_resources.h"
7 const char *level_pack
[] =
37 "###+##+####;bbb,bb\n"
42 "###-#####-###;a,aaa\n"
49 "######+######;aaaa\n"
54 "###-#####-###;aaa,aa\n"
61 "###+#####+###;aa,aaa\n"
69 #define FLAG_INPUT 0x1
70 #define FLAG_OUTPUT 0x2
71 #define FLAG_CANAL 0x4
73 #define FLAG_FLIP_FLOP 0x100
74 #define FLAG_FLIP_ROTATING 0x200
77 0000 0 | 0001 1 | 0010 2 | 0011 3
81 0100 4 | 0101 5 | 0110 6 | 0111 7
85 1000 8 | 1001 9 | 1010 10 | 1011 11
89 1100 12 | 1101 13 | 1110 14 | 1111 15
97 k_cell_type_split
= 7,
98 k_cell_type_merge
= 13
102 { { 0.9f
, 0.2f
, 0.01f
},
103 { 0.2f
, 0.9f
, 0.14f
},
104 { 0.1f
, 0.3f
, 0.85f
} };
106 static void colour_code_v3( char cc
, v3f target
)
108 if( cc
>= 'a' && cc
<= 'z' )
112 if( id
< vg_list_size( colour_sets
) )
114 v3_copy( colour_sets
[ id
], target
);
119 v3_copy( (v3f
){0.0f
,0.0f
,0.0f
}, target
);
128 static void init_mesh( struct mesh
*m
, float *tris
, u32 length
)
130 m
->elements
= length
/3;
131 glGenVertexArrays( 1, &m
->vao
);
132 glGenBuffers( 1, &m
->vbo
);
134 glBindVertexArray( m
->vao
);
135 glBindBuffer( GL_ARRAY_BUFFER
, m
->vbo
);
136 glBufferData( GL_ARRAY_BUFFER
, length
*sizeof(float), tris
, GL_STATIC_DRAW
);
138 glVertexAttribPointer( 0, 2, GL_FLOAT
, GL_FALSE
, 2 * sizeof(float), (void*)0 );
139 glEnableVertexAttribArray( 0 );
144 static void free_mesh( struct mesh
*m
)
146 glDeleteVertexArrays( 1, &m
->vao
);
147 glDeleteBuffers( 1, &m
->vbo
);
150 static void draw_mesh( int const start
, int const count
)
152 glDrawArrays( GL_TRIANGLES
, start
*3, count
*3 );
155 static void use_mesh( struct mesh
*m
)
157 glBindVertexArray( m
->vao
);
177 // TODO: Split into input/output structures
187 struct mesh tile
, circle
;
189 int selected
, tile_x
, tile_y
;
204 static void map_free(void)
206 for( int i
= 0; i
< arrlen( world
.io
); i
++ )
207 arrfree( world
.io
[ i
].conditions
);
209 arrfree( world
.data
);
218 static void map_reclassify( v2i start
, v2i end
);
219 static int map_load( const char *str
)
228 if( str
[world
.w
] == ';' )
230 else if( !str
[world
.w
] )
232 vg_error( "Unexpected EOF when parsing level\n" );
237 struct cell
*row
= arraddnptr( world
.data
, world
.w
);
239 int reg_start
= 0, reg_end
= 0;
255 if( reg_start
< reg_end
)
257 if( *c
>= 'a' && *c
<= 'z' )
259 arrpush( world
.io
[ reg_start
].conditions
, *c
);
263 if( *c
== ',' || *c
== '\n' )
272 vg_error( "Unkown attribute '%c' (row: %u)\n", *c
, world
.h
);
279 vg_error( "Too many values to assign (row: %u)\n", world
.h
);
287 if( reg_start
!= reg_end
)
289 vg_error( "Not enough values assigned (row: %u, %u of %u)\n", world
.h
, reg_start
, reg_end
);
295 vg_error( "Not enough cells to match previous row definition (row: %u, %u<%u)\n", world
.h
, cx
, world
.w
);
299 row
= arraddnptr( world
.data
, world
.w
);
302 reg_end
= reg_start
= arrlen( world
.io
);
308 vg_error( "Too many cells to match previous row definition (row: %u, %u>%u)\n", world
.h
, cx
, world
.w
);
312 // Tile initialization
315 if( *c
== '+' || *c
== '-' )
317 struct cell_terminal term
= { .id
= cx
+ world
.h
*world
.w
};
318 arrpush( world
.io
, term
);
319 row
[ cx
++ ].state
= *c
== '+'? FLAG_INPUT
: FLAG_OUTPUT
;
324 row
[ cx
++ ].state
= FLAG_WALL
;
328 row
[ cx
++ ].state
= 0x00;
335 map_reclassify( NULL
, NULL
);
336 vg_success( "Map loaded! (%u:%u)\n", world
.w
, world
.h
);
340 static struct cell
*pcell( v2i pos
)
342 return &world
.data
[ pos
[1]*world
.w
+ pos
[0] ];
345 int main( int argc
, char *argv
[] )
347 vg_init( argc
, argv
, "Fish (Marbles Computer) Ladder Simulator 2022 | N,M: change level | SPACE: Test | LeftClick: Toggle tile" );
356 0.0f
, 0.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
,
357 0.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
, 0.0f
,
359 0.48f
, 0.48f
, 0.5f
, 0.52f
, 0.52f
, 0.52f
, // Static dot
360 0.375f
, 0.25f
, 0.5f
, 0.75f
, 0.625f
, 0.25f
, // Downwards pointing arrow
361 0.25f
, 0.625f
, 0.75f
, 0.5f
, 0.25f
, 0.375f
, // Left
362 0.625f
, 0.75f
, 0.5f
, 0.25f
, 0.375f
, 0.75f
, // up
363 0.75f
, 0.375f
, 0.25f
, 0.5f
, 0.75f
, 0.625f
366 init_mesh( &world
.tile
, quad_mesh
, vg_list_size(quad_mesh
) );
371 float circle_mesh
[32*6*3];
372 int res
= vg_list_size( circle_mesh
) / (6*3);
374 for( int i
= 0; i
< res
; i
++ )
376 v2f v0
= { sinf( ((float)i
/(float)res
)*VG_TAUf
), cosf( ((float)i
/(float)res
)*VG_TAUf
) };
377 v2f v1
= { sinf( ((float)(i
+1)/(float)res
)*VG_TAUf
), cosf( ((float)(i
+1)/(float)res
)*VG_TAUf
) };
379 circle_mesh
[ i
*6+0 ] = 0.0f
;
380 circle_mesh
[ i
*6+1 ] = 0.0f
;
382 v2_copy( v0
, circle_mesh
+ 32*6 + i
*12 );
383 v2_muls( v0
, 0.8f
, circle_mesh
+ 32*6 + i
*12+2 );
384 v2_copy( v1
, circle_mesh
+ 32*6 + i
*12+4 );
386 v2_copy( v1
, circle_mesh
+ 32*6 + i
*12+6 );
387 v2_muls( v1
, 0.8f
, circle_mesh
+ 32*6 + i
*12+8 );
388 v2_muls( v0
, 0.8f
, circle_mesh
+ 32*6 + i
*12+10 );
390 v2_copy( v0
, circle_mesh
+ i
*6+4 );
391 v2_copy( v1
, circle_mesh
+ i
*6+2 );
392 v2_copy( v0
, circle_mesh
+i
*6+4 );
393 v2_copy( v1
, circle_mesh
+i
*6+2 );
396 init_mesh( &world
.circle
, circle_mesh
, vg_list_size( circle_mesh
) );
399 resource_load_main();
401 map_load( level_pack
[ 0 ] );
406 resource_free_main();
408 free_mesh( &world
.tile
);
409 free_mesh( &world
.circle
);
414 static int cell_interactive( v2i co
)
417 if( co
[0] < 2 || co
[0] >= world
.w
-2 || co
[1] < 2 || co
[1] >= world
.h
-2 )
421 if( world
.data
[ world
.w
*co
[1] + co
[0] ].state
& (FLAG_WALL
|FLAG_INPUT
|FLAG_OUTPUT
) )
424 // List of 3x3 configurations that we do not allow
425 static u32 invalid_src
[][9] =
457 // Statically compile invalid configurations into bitmasks
458 static u32 invalid
[ vg_list_size(invalid_src
) ];
460 for( int i
= 0; i
< vg_list_size(invalid_src
); i
++ )
464 for( int j
= 0; j
< 3; j
++ )
465 for( int k
= 0; k
< 3; k
++ )
466 comped
|= invalid_src
[i
][ j
*3+k
] << ((j
*5)+k
);
471 // Extract 5x5 grid surrounding tile
473 for( int y
= co
[1]-2; y
< co
[1]+3; y
++ )
474 for( int x
= co
[0]-2; x
< co
[0]+3; x
++ )
476 struct cell
*cell
= pcell((v2i
){x
,y
});
478 if( cell
&& (cell
->state
& (FLAG_CANAL
|FLAG_INPUT
|FLAG_OUTPUT
)) )
479 blob
|= 0x1 << ((y
-(co
[1]-2))*5 + x
-(co
[0]-2));
482 // Run filter over center 3x3 grid to check for invalid configurations
483 int kernel
[] = { 0, 1, 2, 5, 6, 7, 10, 11, 12 };
484 for( int i
= 0; i
< vg_list_size(kernel
); i
++ )
486 if( blob
& (0x1 << (6+kernel
[i
])) )
488 u32 window
= blob
>> kernel
[i
];
490 for( int j
= 0; j
< vg_list_size(invalid
); j
++ )
491 if((window
& invalid
[j
]) == invalid
[j
])
499 static void map_reclassify( v2i start
, v2i end
)
501 v2i full_start
= { 2,2 };
502 v2i full_end
= { world
.w
-2, world
.h
-2 };
510 for( int y
= vg_max( start
[1], full_start
[1] ); y
< vg_min( end
[1], full_end
[1] ); y
++ )
512 for( int x
= vg_max( start
[0], full_start
[0] ); x
< vg_min( end
[0], full_end
[0] ); x
++ )
514 v2i dirs
[] = {{1,0},{0,1},{-1,0},{0,-1}};
518 if( pcell((v2i
){x
,y
})->state
& FLAG_CANAL
)
520 for( int i
= 0; i
< vg_list_size( dirs
); i
++ )
522 struct cell
*neighbour
= pcell((v2i
){x
+dirs
[i
][0], y
+dirs
[i
][1]});
523 if( neighbour
->state
& (FLAG_CANAL
|FLAG_INPUT
|FLAG_OUTPUT
) )
529 pcell((v2i
){x
,y
})->config
= config
;
536 static int curlevel
= 0;
537 int changelvl
= curlevel
;
538 if( vg_get_button_down( "prev" ) ) { if( curlevel
> 0 ) changelvl
--; }
539 else if( vg_get_button_down( "next" ) ) { if( curlevel
< vg_list_size( level_pack
)-1 ) changelvl
++; }
541 if( changelvl
!= curlevel
)
543 map_load( level_pack
[ changelvl
] );
544 curlevel
= changelvl
;
547 world
.simulating
= 0;
548 world
.num_fishes
= 0;
551 for( int i
= 0; i
< arrlen( world
.io
); i
++ )
552 world
.io
[i
].recv_count
= 0;
554 vg_info( "Stopping simulation!\n" );
557 float ratio
= (float)vg_window_y
/ (float)vg_window_x
;
558 float const size
= 9.5f
;
561 origin
[0] = -0.5f
* world
.w
;
562 origin
[1] = -0.5f
* world
.h
;
565 m3x3_projection( m_projection
, -size
, size
, -size
*ratio
, size
*ratio
);
566 m3x3_identity( m_view
);
567 m3x3_translate( m_view
, origin
);
568 m3x3_mul( m_projection
, m_view
, vg_pv
);
569 vg_projection_update();
572 v2_copy( vg_mouse_ws
, world
.tile_pos
);
574 world
.tile_x
= floorf( world
.tile_pos
[0] );
575 world
.tile_y
= floorf( world
.tile_pos
[1] );
578 if( !world
.simulating
)
580 if( cell_interactive( (v2i
){ world
.tile_x
, world
.tile_y
} ))
582 world
.selected
= world
.tile_y
* world
.w
+ world
.tile_x
;
584 if( vg_get_button_down("primary") )
586 world
.data
[ world
.selected
].state
^= FLAG_CANAL
;
588 if( world
.data
[ world
.selected
].state
& FLAG_CANAL
)
589 sfx_set_playrnd( &audio_tile_mod
, &audio_system_sfx
, 3, 6 );
591 sfx_set_playrnd( &audio_tile_mod
, &audio_system_sfx
, 0, 3 );
593 map_reclassify( (v2i
){ world
.tile_x
-2, world
.tile_y
-2 },
594 (v2i
){ world
.tile_x
+2, world
.tile_y
+2 } );
600 else world
.selected
= -1;
602 // Simulation stop/start
603 if( vg_get_button_down("go") )
605 if( world
.simulating
)
607 world
.simulating
= 0;
608 world
.num_fishes
= 0;
611 for( int i
= 0; i
< arrlen( world
.io
); i
++ )
612 world
.io
[i
].recv_count
= 0;
614 vg_info( "Stopping simulation!\n" );
616 sfx_system_fadeout( &audio_system_balls_rolling
, 44100 );
620 vg_success( "Starting simulation!\n" );
622 sfx_set_playrnd( &audio_rolls
, &audio_system_balls_rolling
, 0, 1 );
624 world
.simulating
= 1;
625 world
.num_fishes
= 0;
627 world
.sim_start
= vg_time
;
629 for( int i
= 0; i
< world
.w
*world
.h
; i
++ )
631 world
.data
[ i
].state
&= ~FLAG_FLIP_FLOP
;
634 for( int i
= 0; i
< arrlen( world
.io
); i
++ )
635 world
.io
[i
].recv_count
= 0;
640 if( world
.simulating
)
642 while( world
.sim_frame
< (int)((vg_time
-world
.sim_start
)*2.0f
) )
644 //vg_info( "frame: %u\n", world.sim_frame );
645 sfx_set_playrnd( &audio_random
, &audio_system_balls_switching
, 0, 9 );
647 for( int i
= 0; i
< arrlen( world
.io
); i
++ )
649 struct cell_terminal
*term
= &world
.io
[ i
];
650 int posx
= term
->id
% world
.w
;
651 int posy
= (term
->id
- posx
)/world
.w
;
652 int is_input
= world
.data
[ term
->id
].state
& FLAG_INPUT
;
656 if( world
.sim_frame
< arrlen( term
->conditions
) )
658 struct fish
*fish
= &world
.fishes
[world
.num_fishes
++];
662 fish
->payload
= term
->conditions
[world
.sim_frame
];
666 v2i dirs
[] = {{1,0},{-1,0},{0,-1}};
667 for( int j
= 0; j
< vg_list_size(dirs
); j
++ )
668 if( pcell( (v2i
){ posx
+dirs
[j
][0], posy
+dirs
[j
][1] } )->state
& FLAG_CANAL
)
670 fish
->dir
[0] = dirs
[j
][0];
671 fish
->dir
[1] = dirs
[j
][1];
682 // Update splitter deltas
683 for( int i
= 0; i
< world
.h
*world
.w
; i
++ )
685 struct cell
*cell
= &world
.data
[i
];
686 if( cell
->config
== k_cell_type_split
)
688 cell
->state
&= ~FLAG_FLIP_ROTATING
;
692 for( int i
= 0; i
< world
.num_fishes
; i
++ )
694 struct fish
*fish
= &world
.fishes
[i
];
695 struct cell
*cell_current
= pcell( fish
->pos
);
701 if( cell_current
->state
& FLAG_OUTPUT
)
703 for( int j
= 0; j
< arrlen( world
.io
); j
++ )
705 struct cell_terminal
*term
= &world
.io
[j
];
707 if( term
->id
== fish
->pos
[1]*world
.w
+ fish
->pos
[0] )
709 term
->recv
[ term
->recv_count
++ ] = fish
->payload
;
718 if( cell_current
->config
== k_cell_type_split
)
721 fish
->dir
[0] = cell_current
->state
&FLAG_FLIP_FLOP
?1:-1;
724 cell_current
->state
^= FLAG_FLIP_FLOP
;
726 else if( cell_current
->config
== k_cell_type_merge
)
734 struct cell
*cell_next
= pcell( (v2i
){ fish
->pos
[0]+fish
->dir
[0], fish
->pos
[1]+fish
->dir
[1] } );
735 if( !(cell_next
->state
& (FLAG_CANAL
|FLAG_OUTPUT
)) )
737 // Try other directions for valid, so down, left, right..
738 v2i dirs
[] = {{1,0},{-1,0},{0,-1}};
739 vg_info( "Trying some other directions...\n" );
741 for( int j
= 0; j
< vg_list_size(dirs
); j
++ )
743 if( (dirs
[j
][0] == -fish
->dir
[0]) && (dirs
[j
][1] == -fish
->dir
[1]) )
746 if( pcell( (v2i
){ fish
->pos
[0]+dirs
[j
][0], fish
->pos
[1]+dirs
[j
][1] } )->state
& (FLAG_CANAL
|FLAG_OUTPUT
) )
748 fish
->dir
[0] = dirs
[j
][0];
749 fish
->dir
[1] = dirs
[j
][1];
755 fish
->pos
[0] += fish
->dir
[0];
756 fish
->pos
[1] += fish
->dir
[1];
758 struct cell
*cell_entry
= pcell( fish
->pos
);
760 if( !(cell_entry
->state
& (FLAG_INPUT
|FLAG_CANAL
|FLAG_OUTPUT
) ))
763 if( cell_entry
->config
== k_cell_type_split
)
765 sfx_set_playrnd( &audio_splitter
, &audio_system_balls_important
, 0, 1 );
766 cell_entry
->state
|= FLAG_FLIP_ROTATING
;
775 static void render_tiles( v2i start
, v2i end
, v4f
const regular_colour
, v4f
const selected_colour
)
777 v2i full_start
= { 0,0 };
778 v2i full_end
= { world
.w
, world
.h
};
786 glUniform4fv( SHADER_UNIFORM( shader_tile_main
, "uColour" ), 1, regular_colour
);
788 for( int y
= start
[1]; y
< end
[1]; y
++ )
790 for( int x
= start
[0]; x
< end
[0]; x
++ )
792 struct cell
*cell
= pcell((v2i
){x
,y
});
793 int selected
= world
.selected
== y
*world
.w
+ x
;
795 int tile_offsets
[][2] =
797 {2, 0}, {0, 3}, {0, 2}, {2, 2},
798 {1, 0}, {2, 3}, {3, 2}, {1, 3},
799 {3, 1}, {0, 1}, {1, 2}, {2, 1},
800 {1, 1}, {3, 3}, {2, 1}, {2, 1}
803 int uv
[2] = { 3, 0 };
805 if( cell
->state
& FLAG_CANAL
)
807 uv
[0] = tile_offsets
[ cell
->config
][0];
808 uv
[1] = tile_offsets
[ cell
->config
][1];
811 glUniform4f( SHADER_UNIFORM( shader_tile_main
, "uOffset" ), (float)x
, (float)y
, uv
[0], uv
[1] );
814 glUniform4fv( SHADER_UNIFORM( shader_tile_main
, "uColour" ), 1, selected_colour
);
816 glUniform4fv( SHADER_UNIFORM( shader_tile_main
, "uColour" ), 1, regular_colour
);
826 glViewport( 0,0, vg_window_x
, vg_window_y
);
828 glDisable( GL_DEPTH_TEST
);
829 glClearColor( 0.8f
, 0.8f
, 0.8f
, 1.0f
);
830 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
832 float scaled_time
= 0.0f
, frame_lerp
= 0.0f
;
834 if( world
.simulating
)
836 scaled_time
= (vg_time
-world
.sim_start
)*2.0f
;
837 frame_lerp
= scaled_time
- (float)world
.sim_frame
;
840 v4f
const colour_default
= {1.0f
, 1.0f
, 1.0f
, 1.0f
};
841 v4f
const colour_selected
= {0.90f
, 0.92f
, 1.0f
, 1.0f
};
843 v2f
const curve_3
[] = {{0.5f
,1.0f
},{0.5f
,0.625f
},{0.625f
,0.5f
},{1.0f
,0.5f
}};
844 v2f
const curve_6
[] = {{0.5f
,1.0f
},{0.5f
,0.625f
},{0.375f
,0.5f
},{0.0f
,0.5f
}};
845 v2f
const curve_9
[] = {{1.0f
,0.5f
},{0.625f
,0.5f
},{0.5f
,0.375f
},{0.5f
,0.0f
}};
846 v2f
const curve_12
[]= {{0.0f
,0.5f
},{0.375f
,0.5f
},{0.5f
,0.375f
},{0.5f
,0.0f
}};
848 v2f
const curve_7
[] = {{0.5f
,0.8438f
},{0.875f
,0.8438f
},{0.625f
,0.5f
},{1.0f
,0.5f
}};
849 v2f
const curve_7_1
[] = {{0.5f
,0.8438f
},{1.0f
-0.875f
,0.8438f
},{1.0-0.625f
,0.5f
},{0.0f
,0.5f
}};
851 float const curve_7_linear_section
= 0.1562f
;
853 // TILE SET RENDERING
854 // todo: just slam everything into a mesh...
855 // when user modifies a tile the neighbours can be easily uploaded to gpu mem
857 // Currently we're uploading a fair amount of data every frame anyway.
858 // NOTE: this is for final optimisations ONLY!
859 // ======================================================================
861 use_mesh( &world
.tile
);
863 SHADER_USE( shader_tile_main
);
866 m2x2_identity( subtransform
);
867 glUniformMatrix2fv( SHADER_UNIFORM( shader_tile_main
, "uSubTransform" ), 1, GL_FALSE
, (float *)subtransform
);
868 glUniformMatrix3fv( SHADER_UNIFORM( shader_tile_main
, "uPv" ), 1, GL_FALSE
, (float *)vg_pv
);
869 glUniform1f( SHADER_UNIFORM( shader_tile_main
, "uGhost" ), 0.0f
);
872 vg_tex2d_bind( &tex_tile_data
, 0 );
873 glUniform1i( SHADER_UNIFORM( shader_tile_main
, "uTexGlyphs" ), 0 );
875 vg_tex2d_bind( &tex_wood
, 1 );
876 glUniform1i( SHADER_UNIFORM( shader_tile_main
, "uTexWood" ), 1 );
878 render_tiles( NULL
, NULL
, colour_default
, colour_default
);
881 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
882 glBlendEquation(GL_FUNC_ADD
);
884 SHADER_USE( shader_ball
);
885 glUniformMatrix3fv( SHADER_UNIFORM( shader_ball
, "uPv" ), 1, GL_FALSE
, (float *)vg_pv
);
887 vg_tex2d_bind( &tex_ball
, 0 );
888 glUniform1i( SHADER_UNIFORM( shader_ball
, "uTexMain" ), 0 );
891 if( world
.simulating
)
893 for( int i
= 0; i
< world
.num_fishes
; i
++ )
895 struct fish
*fish
= &world
.fishes
[i
];
901 struct cell
*cell
= pcell(fish
->pos
);
906 float t
= frame_lerp
;
908 switch( cell
->config
)
911 if( fish
->dir
[0] == 1 )
916 case 3: curve
= curve_3
; break;
917 case 6: curve
= curve_6
; break;
918 case 9: curve
= curve_9
; break;
919 case 12: curve
= curve_12
; break;
921 if( t
> curve_7_linear_section
)
923 t
-= curve_7_linear_section
;
924 t
*= (1.0f
/(1.0f
-curve_7_linear_section
));
926 curve
= cell
->state
& FLAG_FLIP_FLOP
? curve_7
: curve_7_1
;
930 default: curve
= NULL
; break;
936 float t3
= t
* t
* t
;
938 float cA
= 3.0f
*t2
- 3.0f
*t3
;
939 float cB
= 3.0f
*t3
- 6.0f
*t2
+ 3.0f
*t
;
940 float cC
= 3.0f
*t2
- t3
- 3.0f
*t
+ 1.0f
;
942 fish_pos
[0] = t3
*curve
[3][0] + cA
*curve
[2][0] + cB
*curve
[1][0] + cC
*curve
[0][0];
943 fish_pos
[1] = t3
*curve
[3][1] + cA
*curve
[2][1] + cB
*curve
[1][1] + cC
*curve
[0][1];
944 fish_pos
[0] += (float)fish
->pos
[0];
945 fish_pos
[1] += (float)fish
->pos
[1];
950 origin
[0] = (float)fish
->pos
[0] + (float)fish
->dir
[0]*-0.5f
+ 0.5f
;
951 origin
[1] = (float)fish
->pos
[1] + (float)fish
->dir
[1]*-0.5f
+ 0.5f
;
953 fish_pos
[0] = origin
[0] + (float)fish
->dir
[0]*t
;
954 fish_pos
[1] = origin
[1] + (float)fish
->dir
[1]*t
;
957 v4f dot_colour
= { 0.0f
, 0.0f
, 0.0f
, 1.0f
};
958 colour_code_v3( fish
->payload
, dot_colour
);
960 glUniform3fv( SHADER_UNIFORM( shader_ball
, "uColour" ), 1, dot_colour
);
961 glUniform2f( SHADER_UNIFORM( shader_ball
, "uOffset" ), fish_pos
[0], fish_pos
[1] );
967 SHADER_USE( shader_tile_main
);
970 vg_tex2d_bind( &tex_tile_data
, 0 );
971 glUniform1i( SHADER_UNIFORM( shader_tile_main
, "uTexGlyphs" ), 0 );
973 vg_tex2d_bind( &tex_wood
, 1 );
974 glUniform1i( SHADER_UNIFORM( shader_tile_main
, "uTexWood" ), 1 );
976 render_tiles( NULL
, NULL
, colour_default
, colour_selected
);
980 for( int y
= 0; y
< world
.h
; y
++ )
982 for( int x
= 0; x
< world
.w
; x
++ )
984 struct cell
*cell
= pcell((v2i
){x
,y
});
986 if( cell
->config
== k_cell_type_split
)
988 float rotation
= cell
->state
& FLAG_FLIP_FLOP
? vg_rad( -45.0f
): vg_rad( 45.0f
);
990 if( cell
->state
& FLAG_FLIP_ROTATING
)
992 if( (frame_lerp
> curve_7_linear_section
) )
994 float const rotation_speed
= 0.4f
;
995 if( (frame_lerp
< 1.0f
-rotation_speed
) )
997 float t
= frame_lerp
- curve_7_linear_section
;
998 t
*= -2.0f
* (1.0f
/(1.0f
-(curve_7_linear_section
+rotation_speed
)));
1008 m2x2_create_rotation( subtransform
, rotation
);
1010 glUniformMatrix2fv( SHADER_UNIFORM( shader_tile_main
, "uSubTransform" ), 1, GL_FALSE
, (float *)subtransform
);
1011 glUniform4f( SHADER_UNIFORM( shader_tile_main
, "uOffset" ), (float)x
, (float)y
+ 0.125f
, 0.0f
, 0.0f
);
1018 if( world
.selected
!= -1 && !(world
.data
[ world
.selected
].state
& FLAG_CANAL
) )
1020 v2i new_begin
= { world
.tile_x
- 2, world
.tile_y
- 2 };
1021 v2i new_end
= { world
.tile_x
+ 2, world
.tile_y
+ 2 };
1023 world
.data
[ world
.selected
].state
^= FLAG_CANAL
;
1024 map_reclassify( new_begin
, new_end
);
1026 m2x2_identity( subtransform
);
1027 glUniform1f( SHADER_UNIFORM( shader_tile_main
, "uGhost" ), 1.0f
);
1028 glUniformMatrix2fv( SHADER_UNIFORM( shader_tile_main
, "uSubTransform" ), 1, GL_FALSE
, (float *)subtransform
);
1029 glUniform2fv( SHADER_UNIFORM( shader_tile_main
, "uMousePos" ), 1, world
.tile_pos
);
1031 render_tiles( new_begin
, new_end
, colour_default
, colour_default
);
1033 world
.data
[ world
.selected
].state
^= FLAG_CANAL
;
1034 map_reclassify( new_begin
, new_end
);
1037 //glDisable(GL_BLEND);
1039 glDisable(GL_BLEND
);
1041 SHADER_USE( shader_tile_colour
);
1042 glUniformMatrix3fv( SHADER_UNIFORM( shader_tile_colour
, "uPv" ), 1, GL_FALSE
, (float *)vg_pv
);
1043 use_mesh( &world
.circle
);
1046 for( int i
= 0; i
< arrlen( world
.io
); i
++ )
1048 struct cell_terminal
*term
= &world
.io
[ i
];
1049 int posx
= term
->id
% world
.w
;
1050 int posy
= (term
->id
- posx
)/world
.w
;
1051 int is_input
= world
.data
[ term
->id
].state
& FLAG_INPUT
;
1053 int const filled_start
= 0;
1054 int const filled_count
= 32;
1055 int const empty_start
= 32;
1056 int const empty_count
= 32*2;
1058 v4f dot_colour
= { 0.0f
, 0.0f
, 0.0f
, 1.0f
};
1060 for( int j
= 0; j
< arrlen( term
->conditions
); j
++ )
1062 glUniform3f( SHADER_UNIFORM( shader_tile_colour
, "uOffset" ), (float)posx
+ 0.2f
+ 0.2f
* (float)j
, (float)posy
+ 0.2f
, 0.1f
);
1066 colour_code_v3( term
->conditions
[j
], dot_colour
);
1067 glUniform4fv( SHADER_UNIFORM( shader_tile_colour
, "uColour" ), 1, dot_colour
);
1069 // Draw filled if tick not passed, draw empty if empty
1070 if( world
.sim_frame
> j
)
1071 draw_mesh( empty_start
, empty_count
);
1073 draw_mesh( filled_start
, filled_count
);
1077 if( term
->recv_count
> j
)
1079 colour_code_v3( term
->recv
[j
], dot_colour
);
1080 v3_muls( dot_colour
, 0.8f
, dot_colour
);
1081 glUniform4fv( SHADER_UNIFORM( shader_tile_colour
, "uColour" ), 1, dot_colour
);
1083 draw_mesh( filled_start
, filled_count
);
1086 colour_code_v3( term
->conditions
[j
], dot_colour
);
1087 glUniform4fv( SHADER_UNIFORM( shader_tile_colour
, "uColour" ), 1, dot_colour
);
1089 draw_mesh( empty_start
, empty_count
);
1094 if( world
.simulating
)
1096 glUniform4f( SHADER_UNIFORM( shader_tile_colour
, "uColour" ), 0.0f
, 0.0f
, 0.0f
, 1.0f
);
1097 glUniform3f( SHADER_UNIFORM( shader_tile_colour
, "uOffset" ), -0.5f
+ cosf( vg_time
* 4.0f
) * 0.2f
, sinf( vg_time
* 4.0f
) * 0.2f
+ (float)world
.h
* 0.5f
, 0.05f
);
1105 sfx_internal_debug_overlay();