1 // Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
4 #define VG_STEAM_APPID 1218140U
6 #include "fishladder_resources.h"
13 3. Merge (and explode)
14 4. Principle 1 (divide colours)
15 5. Principle 2 (combine colours)
25 New things to program:
26 UI text element renderer (SDF) DONE(sorta)
27 Particle system thing for ball collision
28 Level descriptions / titles HALF
30 Play button / Speed controller
37 const char *level_pack_1
[] = {
62 levels
[ vg_list_size( level_pack_1
) ];
64 career
= { .version
= 1 };
67 static void career_serialize(void)
69 vg_asset_write( "sav/game.sav", &career
, sizeof( struct career_state
) );
72 static void career_load(void)
75 struct career_state
*cr
= vg_asset_read_s( "sav/game.sav", &sz
);
77 memset( (void*)career
.levels
, 0, vg_list_size(level_pack_1
) * sizeof(struct career_level
) );
81 if( sz
> sizeof( struct career_state
) )
82 vg_warn( "This save file is too big! Some levels will be lost\n" );
84 if( sz
<= offsetof( struct career_state
, levels
) )
86 vg_error( "This save file is too small to have a header\n" );
91 u32
const size_header
= offsetof(struct career_state
, levels
);
92 u32
const size_levels
= sizeof(struct career_state
)-size_header
;
93 u32
const size_levels_input
= sz
- size_header
;
95 memcpy( (void*)career
.levels
, (void*)cr
->levels
, size_levels_input
);
97 if( sz
< sizeof( struct career_state
) )
99 memset( ((void*)career
.levels
) + size_levels_input
, 0, size_levels
-size_levels_input
);
103 vg_success( "Loaded save file... Info:\n" );
105 for( int i
= 0; i
< vg_list_size( career
.levels
); i
++ )
107 struct career_level
*lvl
= &career
.levels
[i
];
108 vg_info( "Score: %u, Time: %u, Completed: %u\n", lvl
->score
, lvl
->time
, lvl
->completed
);
113 vg_info( "No save file... Using blank one\n" );
121 #define FLAG_CANAL 0x1
122 #define FLAG_IS_TRIGGER 0x2
123 #define FLAG_RESERVED0 0x4
124 #define FLAG_RESERVED1 0x8
126 #define FLAG_INPUT 0x10
127 #define FLAG_OUTPUT 0x20
128 #define FLAG_WALL 0x40
130 #define FLAG_FLIP_FLOP 0x100
131 #define FLAG_TRIGGERED 0x200
132 #define FLAG_FLIP_ROTATING 0x400
133 #define FLAG_TARGETED 0x800
136 0000 0 | 0001 1 | 0010 2 | 0011 3
140 0100 4 | 0101 5 | 0110 6 | 0111 7
144 1000 8 | 1001 9 | 1010 10 | 1011 11
148 1100 12 | 1101 13 | 1110 14 | 1111 15
154 struct cell_description
162 cell_descriptions
[] =
166 { .start
= { 1, 0 }, .end
= { -1, 0 } },
167 { .start
= { 0, 1 }, .end
= { 0, -1 } },
168 { .start
= { 0, 1 }, .end
= { 1, 0 } },
170 { .start
= { -1, 0 }, .end
= { 1, 0 } },
171 { .start
= { -1, 0 }, .end
= { 1, 0 }, .is_linear
= 1 },
172 { .start
= { 0, 1 }, .end
= { -1, 0 } },
173 { .start
= { 0, 1 }, .is_special
= 1 },
175 { .start
= { 0, -1 }, .end
= { 0, 1 } },
176 { .start
= { 1, 0 }, .end
= { 0, -1 } },
177 { .start
= { 0, 1 }, .end
= { 0, -1 }, .is_linear
= 1 },
180 { .start
= { -1, 0 }, .end
= { 0, -1 } },
181 { .end
= { 0, -1 }, .is_special
= 1 },
188 k_cell_type_stub
= 0,
189 k_cell_type_ramp_right
= 3,
190 k_cell_type_ramp_left
= 6,
191 k_cell_type_split
= 7,
192 k_cell_type_merge
= 13,
193 k_cell_type_con_r
= 1,
194 k_cell_type_con_u
= 2,
195 k_cell_type_con_l
= 4,
196 k_cell_type_con_d
= 8
199 v2f
const curve_3
[] = {{0.5f
,1.0f
},{0.5f
,0.625f
},{0.625f
,0.5f
},{1.0f
,0.5f
}};
200 v2f
const curve_6
[] = {{0.5f
,1.0f
},{0.5f
,0.625f
},{0.375f
,0.5f
},{0.0f
,0.5f
}};
201 v2f
const curve_9
[] = {{1.0f
,0.5f
},{0.625f
,0.5f
},{0.5f
,0.375f
},{0.5f
,0.0f
}};
202 v2f
const curve_12
[]= {{0.0f
,0.5f
},{0.375f
,0.5f
},{0.5f
,0.375f
},{0.5f
,0.0f
}};
204 v2f
const curve_1
[] = {{1.0f
,0.5f
},{0.8f
,0.5f
},{0.3f
,0.5f
},{0.2f
,0.5f
}};
205 v2f
const curve_4
[] = {{0.0f
,0.5f
},{0.3f
,0.5f
},{0.5f
,0.5f
},{0.8f
,0.5f
}};
206 v2f
const curve_2
[] = {{0.5f
,1.0f
},{0.5f
,0.8f
},{0.5f
,0.3f
},{0.5f
,0.2f
}};
207 v2f
const curve_8
[] = {{0.5f
,0.0f
},{0.5f
,0.3f
},{0.5f
,0.5f
},{0.5f
,0.8f
}};
209 v2f
const curve_7
[] = {{0.5f
,0.8438f
},{0.875f
,0.8438f
},{0.625f
,0.5f
},{1.0f
,0.5f
}};
210 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
}};
212 float const curve_7_linear_section
= 0.1562f
;
215 { { 1.0f
, 0.9f
, 0.3f
},
216 { 0.2f
, 0.9f
, 0.14f
},
217 { 0.4f
, 0.8f
, 1.00f
} };
219 static void colour_code_v3( char cc
, v3f target
)
221 if( cc
>= 'a' && cc
<= 'z' )
225 if( id
< vg_list_size( colour_sets
) )
227 v3_copy( colour_sets
[ id
], target
);
232 v3_copy( (v3f
){0.0f
,0.0f
,0.0f
}, target
);
241 static void init_mesh( struct mesh
*m
, float const *tris
, u32 length
)
243 m
->elements
= length
/3;
244 glGenVertexArrays( 1, &m
->vao
);
245 glGenBuffers( 1, &m
->vbo
);
247 glBindVertexArray( m
->vao
);
248 glBindBuffer( GL_ARRAY_BUFFER
, m
->vbo
);
249 glBufferData( GL_ARRAY_BUFFER
, length
*sizeof(float), tris
, GL_STATIC_DRAW
);
251 glVertexAttribPointer( 0, 2, GL_FLOAT
, GL_FALSE
, 2 * sizeof(float), (void*)0 );
252 glEnableVertexAttribArray( 0 );
257 static void free_mesh( struct mesh
*m
)
259 glDeleteVertexArrays( 1, &m
->vao
);
260 glDeleteBuffers( 1, &m
->vbo
);
263 static void draw_mesh( int const start
, int const count
)
265 glDrawArrays( GL_TRIANGLES
, start
*3, count
*3 );
268 static void use_mesh( struct mesh
*m
)
270 glBindVertexArray( m
->vao
);
275 k_fish_state_soon_dead
= -1,
276 k_fish_state_dead
= 0,
279 k_fish_state_soon_alive
302 int sim_run
, max_runs
;
317 int condition_count
, recv_count
;
329 struct mesh tile
, circle
, numbers
;
332 GLuint vao
, vbo
, ebo
;
337 GLuint background_data
;
338 GLuint random_samples
;
340 int selected
, tile_x
, tile_y
;
347 enum e_fish_state state
;
359 struct career_level
*ptr_career_level
;
366 static void map_free(void)
368 arrfree( world
.data
);
379 world
.initialzed
= 0;
382 static void io_reset(void)
384 for( int i
= 0; i
< arrlen( world
.io
); i
++ )
386 struct cell_terminal
*term
= &world
.io
[i
];
388 for( int j
= 0; j
< term
->run_count
; j
++ )
389 term
->runs
[j
].recv_count
= 0;
393 static void map_reclassify( v2i start
, v2i end
, int update_texbuffer
);
394 static int map_load( const char *str
, const char *name
)
396 //TODO: It may be worthwhile, at this point, to switch to binary encoding for save data
405 if( c
[world
.w
] == ';' )
407 else if( !c
[world
.w
] )
409 vg_error( "Unexpected EOF when parsing level\n" );
414 struct cell
*row
= arraddnptr( world
.data
, world
.w
);
416 int reg_start
= 0, reg_end
= 0;
418 u32
*links_to_make
= NULL
;
419 int links_satisfied
= 0;
421 char link_id_buffer
[32];
429 if( *c
== '\r' ) { c
++; continue; } // fuck off windows
435 if( *c
== '\r' ) c
++;
442 if( *c
== '\r' ) { c
++; continue; }
444 if( reg_start
< reg_end
)
446 struct cell_terminal
*terminal
= &world
.io
[ reg_start
];
447 struct terminal_run
*run
= &terminal
->runs
[ terminal
->run_count
-1 ];
449 if( *c
>= 'a' && *c
<= 'z' )
451 run
->conditions
[ run
->condition_count
++ ] = *c
;
455 if( *c
== ',' || *c
== '\n' )
464 terminal
->runs
[ terminal
->run_count
].condition_count
= 0;
465 terminal
->run_count
++;
466 world
.max_runs
= vg_max( world
.max_runs
, terminal
->run_count
);
470 vg_error( "Unkown attribute '%c' (row: %u)\n", *c
, world
.h
);
477 if( links_satisfied
< arrlen( links_to_make
) )
479 struct cell
*target
= &world
.data
[ links_to_make
[ links_satisfied
] ];
481 if( (((u32
)*c
>= (u32
)'0') && ((u32
)*c
<= (u32
)'9')) || *c
== '-' )
483 if( link_id_n
>= vg_list_size( link_id_buffer
)-1 )
485 vg_error( "Number was way too long to be parsed (row: %u)\n", world
.h
);
489 link_id_buffer
[ link_id_n
++ ] = *c
;
491 else if( *c
== ',' || *c
== '\n' )
493 link_id_buffer
[ link_id_n
] = 0x00;
494 int value
= atoi( link_id_buffer
);
496 target
->links
[value
>= 0? 1:0] = abs(value
);
505 vg_error( "Invalid character '%c' (row: %u)\n", *c
, world
.h
);
511 vg_error( "Too many values to assign (row: %u)\n", world
.h
);
520 // Registry length-error checks
521 if( reg_start
!= reg_end
)
523 vg_error( "Not enough spawn values assigned (row: %u, %u of %u)\n", world
.h
, reg_start
, reg_end
);
527 if( links_satisfied
!= arrlen( links_to_make
) )
529 vg_error( "Not enough link values assigned (row: %u, %u of %u)\n", world
.h
, links_satisfied
, arrlen( links_to_make
) );
535 vg_error( "Not enough cells to match previous row definition (row: %u, %u<%u)\n", world
.h
, cx
, world
.w
);
539 row
= arraddnptr( world
.data
, world
.w
);
542 reg_end
= reg_start
= arrlen( world
.io
);
544 arrsetlen( links_to_make
, 0 );
551 vg_error( "Too many cells to match previous row definition (row: %u, %u>%u)\n", world
.h
, cx
, world
.w
);
555 // Tile initialization
557 struct cell
*cell
= &row
[ cx
];
560 if( *c
== '+' || *c
== '-' )
562 struct cell_terminal
*term
= arraddnptr( world
.io
, 1 );
563 term
->id
= cx
+ world
.h
*world
.w
;
565 term
->runs
[0].condition_count
= 0;
567 cell
->state
= *c
== '+'? FLAG_INPUT
: FLAG_OUTPUT
;
570 else if( *c
== '#' ) cell
->state
= FLAG_WALL
;
571 else if( ((u32
)*c
>= (u32
)'A') && ((u32
)*c
<= (u32
)'A'+0xf) )
573 // Canal flag bits (4bit/16 value):
579 cell
->state
= ((u32
)*c
- (u32
)'A') & (FLAG_CANAL
|FLAG_IS_TRIGGER
);
581 if( cell
->state
& FLAG_IS_TRIGGER
)
582 arrpush( links_to_make
, cx
+ world
.h
*world
.w
);
588 else cell
->state
= 0x00;
596 // Update data texture to fill out the background
598 u8 info_buffer
[64*64*4];
599 for( int i
= 0; i
< 64*64; i
++ )
601 u8
*px
= &info_buffer
[i
*4];
608 glBindTexture( GL_TEXTURE_2D
, world
.background_data
);
609 glTexSubImage2D( GL_TEXTURE_2D
, 0, 0, 0, 64, 64, GL_RGBA
, GL_UNSIGNED_BYTE
, info_buffer
);
612 arrfree( links_to_make
);
614 map_reclassify( NULL
, NULL
, 1 );
617 for( int i
= 0; i
< world
.h
*world
.w
; i
++ )
619 struct cell
*src
= &world
.data
[i
];
620 if( src
->state
& FLAG_IS_TRIGGER
)
622 int link_id
= src
->links
[0]?0:1;
623 if( src
->links
[link_id
] <= world
.h
*world
.w
)
625 struct cell
*target
= &world
.data
[ src
->links
[link_id
] ];
626 if( (target
->state
& FLAG_CANAL
) && (target
->config
== k_cell_type_split
) )
628 if( target
->links
[ link_id
] )
630 vg_error( "Link target was already targeted\n" );
636 target
->links
[ link_id
] = i
;
637 target
->state
|= FLAG_TARGETED
;
642 vg_error( "Link target was invalid\n" );
648 vg_error( "Link target out of bounds\n" );
654 vg_success( "Map '%s' loaded! (%u:%u)\n", name
, world
.w
, world
.h
);
658 strncpy( world
.map_name
, name
, vg_list_size( world
.map_name
)-1 );
659 world
.initialzed
= 1;
663 arrfree( links_to_make
);
668 static struct cell
*pcell( v2i pos
)
670 return &world
.data
[ pos
[1]*world
.w
+ pos
[0] ];
673 static void map_serialize( FILE *stream
)
675 for( int y
= 0; y
< world
.h
; y
++ )
677 for( int x
= 0; x
< world
.w
; x
++ )
679 struct cell
*cell
= pcell( (v2i
){ x
, y
} );
681 if( cell
->state
& FLAG_WALL
) fputc( '#', stream
);
682 else if( cell
->state
& FLAG_INPUT
) fputc( '+', stream
);
683 else if( cell
->state
& FLAG_OUTPUT
) fputc( '-', stream
);
684 else if( cell
->state
& (FLAG_CANAL
|FLAG_IS_TRIGGER
|FLAG_RESERVED0
|FLAG_RESERVED1
) )
686 fputc( (cell
->state
& (FLAG_CANAL
|FLAG_IS_TRIGGER
|FLAG_RESERVED0
|FLAG_RESERVED1
)) + (u32
)'A', stream
);
688 else fputc( ' ', stream
);
691 fputc( ';', stream
);
693 int terminal_write_count
= 0;
695 for( int x
= 0; x
< world
.w
; x
++ )
697 for( int i
= 0; i
< arrlen( world
.io
); i
++ )
699 struct cell_terminal
*term
= &world
.io
[i
];
700 if( term
->id
== y
*world
.w
+x
)
702 if( terminal_write_count
)
703 fputc( ',', stream
);
704 terminal_write_count
++;
706 for( int j
= 0; j
< term
->run_count
; j
++ )
708 struct terminal_run
*run
= &term
->runs
[j
];
710 for( int k
= 0; k
< run
->condition_count
; k
++ )
711 fputc( run
->conditions
[k
], stream
);
713 if( j
< term
->run_count
-1 )
714 fputc( ':', stream
);
720 for( int x
= 0; x
< world
.w
; x
++ )
722 struct cell
*cell
= pcell( (v2i
){ x
,y
} );
723 if( cell
->state
& FLAG_IS_TRIGGER
)
725 if( terminal_write_count
)
726 fputc( ',', stream
);
727 terminal_write_count
++;
729 fprintf( stream
, "%d", cell
->links
[0]? -cell
->links
[0]: cell
->links
[1] );
733 fputc( '\n', stream
);
737 int main( int argc
, char *argv
[] )
739 vg_init( argc
, argv
, "Marble Computing | SPACE: Test | LeftClick: Toggle tile | RightClick: Drag wire" );
743 static int console_credits( int argc
, char const *argv
[] )
745 vg_info( "Aknowledgements:\n" );
746 vg_info( " GLFW zlib/libpng glfw.org\n" );
747 vg_info( " miniaudio MIT0 miniaud.io\n" );
748 vg_info( " QOI MIT phoboslab.org\n" );
749 vg_info( " STB library MIT nothings.org\n" );
750 vg_info( " Weiholmir font justfredrik.itch.io\n" );
754 static int console_save_map( int argc
, char const *argv
[] )
756 if( !world
.initialzed
)
758 vg_error( "Tried to save uninitialized map!\n" );
762 char map_path
[ 256 ];
764 strcpy( map_path
, "sav/" );
765 strcat( map_path
, world
.map_name
);
766 strcat( map_path
, ".map" );
768 FILE *test_writer
= fopen( map_path
, "wb" );
771 vg_info( "Saving map to '%s'\n", map_path
);
772 map_serialize( test_writer
);
774 fclose( test_writer
);
779 vg_error( "Unable to open stream for writing\n" );
784 static int console_load_map( int argc
, char const *argv
[] )
786 char map_path
[ 256 ];
791 strcpy( map_path
, "sav/" );
792 strcat( map_path
, argv
[0] );
793 strcat( map_path
, ".map" );
795 char *text_source
= vg_textasset_read( map_path
);
799 strcpy( map_path
, "maps/" );
800 strcat( map_path
, argv
[0] );
801 strcat( map_path
, ".map" );
803 text_source
= vg_textasset_read( map_path
);
808 vg_info( "Loading map: '%s'\n", map_path
);
809 world
.ptr_career_level
= NULL
;
811 if( !map_load( text_source
, argv
[0] ) )
819 for( int i
= 0; i
< vg_list_size( level_pack_1
); i
++ )
821 if( !strcmp( level_pack_1
[i
], argv
[0] ) )
823 world
.ptr_career_level
= career
.levels
+ i
;
832 vg_error( "Missing maps '%s'\n", argv
[0] );
838 vg_error( "Missing argument <map_path>\n" );
843 static void simulation_stop(void)
845 world
.simulating
= 0;
846 world
.num_fishes
= 0;
852 sfx_system_fadeout( &audio_system_balls_rolling
, 44100 );
854 vg_info( "Stopping simulation!\n" );
857 static int console_changelevel( int argc
, char const *argv
[] )
861 // Save current level
862 console_save_map( 0, NULL
);
863 if( console_load_map( argc
, argv
) )
871 vg_error( "Missing argument <map_path>\n" );
877 void leaderboard_found( LeaderboardFindResult_t
*pCallback
);
880 // Steamworks callbacks
881 sw_leaderboard_found
= &leaderboard_found
;
883 vg_function_push( (struct vg_cmd
){
884 .name
= "_map_write",
885 .function
= console_save_map
888 vg_function_push( (struct vg_cmd
){
890 .function
= console_load_map
893 vg_function_push( (struct vg_cmd
){
895 .function
= console_changelevel
898 vg_function_push( (struct vg_cmd
){
900 .function
= console_credits
907 0.0f
, 0.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
,
908 0.0f
, 0.0f
, 1.0f
, 1.0f
, 1.0f
, 0.0f
,
910 0.0f
, 0.0f
, 0.0f
, 1.0f
, 4.0f
, 1.0f
,
911 0.0f
, 0.0f
, 4.0f
, 1.0f
, 4.0f
, 0.0f
914 init_mesh( &world
.tile
, quad_mesh
, vg_list_size(quad_mesh
) );
919 float circle_mesh
[32*6*3];
920 int res
= vg_list_size( circle_mesh
) / (6*3);
922 for( int i
= 0; i
< res
; i
++ )
924 v2f v0
= { sinf( ((float)i
/(float)res
)*VG_TAUf
), cosf( ((float)i
/(float)res
)*VG_TAUf
) };
925 v2f v1
= { sinf( ((float)(i
+1)/(float)res
)*VG_TAUf
), cosf( ((float)(i
+1)/(float)res
)*VG_TAUf
) };
927 circle_mesh
[ i
*6+0 ] = 0.0f
;
928 circle_mesh
[ i
*6+1 ] = 0.0f
;
930 v2_copy( v0
, circle_mesh
+ 32*6 + i
*12 );
931 v2_muls( v0
, 0.8f
, circle_mesh
+ 32*6 + i
*12+2 );
932 v2_copy( v1
, circle_mesh
+ 32*6 + i
*12+4 );
934 v2_copy( v1
, circle_mesh
+ 32*6 + i
*12+6 );
935 v2_muls( v1
, 0.8f
, circle_mesh
+ 32*6 + i
*12+8 );
936 v2_muls( v0
, 0.8f
, circle_mesh
+ 32*6 + i
*12+10 );
938 v2_copy( v0
, circle_mesh
+ i
*6+4 );
939 v2_copy( v1
, circle_mesh
+ i
*6+2 );
940 v2_copy( v0
, circle_mesh
+i
*6+4 );
941 v2_copy( v1
, circle_mesh
+i
*6+2 );
944 init_mesh( &world
.circle
, circle_mesh
, vg_list_size( circle_mesh
) );
949 init_mesh( &world
.numbers
,
951 vg_list_size( MESH_NUMBERS_BUFFER
)
954 for( int i
= 0; i
< 10; i
++ )
956 vg_info( "offset: %u, length: %u\n", MESH_NUMBERS_OFFSETS
[i
][0], MESH_NUMBERS_OFFSETS
[i
][1] );
962 int const num_segments
= 64;
964 struct mesh_wire
*mw
= &world
.wire
;
966 v2f wire_points
[ num_segments
* 2 ];
967 u16 wire_indices
[ 6*(num_segments
-1) ];
969 for( int i
= 0; i
< num_segments
; i
++ )
971 float l
= (float)i
/ (float)(num_segments
-1);
973 v2_copy( (v2f
){ l
, -0.5f
}, wire_points
[i
*2+0] );
974 v2_copy( (v2f
){ l
, 0.5f
}, wire_points
[i
*2+1] );
976 if( i
< num_segments
-1 )
978 wire_indices
[ i
*6+0 ] = i
*2 + 0;
979 wire_indices
[ i
*6+1 ] = i
*2 + 1;
980 wire_indices
[ i
*6+2 ] = i
*2 + 3;
981 wire_indices
[ i
*6+3 ] = i
*2 + 0;
982 wire_indices
[ i
*6+4 ] = i
*2 + 3;
983 wire_indices
[ i
*6+5 ] = i
*2 + 2;
987 glGenVertexArrays( 1, &mw
->vao
);
988 glGenBuffers( 1, &mw
->vbo
);
989 glGenBuffers( 1, &mw
->ebo
);
990 glBindVertexArray( mw
->vao
);
992 glBindBuffer( GL_ARRAY_BUFFER
, mw
->vbo
);
994 glBufferData( GL_ARRAY_BUFFER
, sizeof( wire_points
), wire_points
, GL_STATIC_DRAW
);
995 glBindVertexArray( mw
->vao
);
997 glBindBuffer( GL_ELEMENT_ARRAY_BUFFER
, mw
->ebo
);
998 glBufferData( GL_ELEMENT_ARRAY_BUFFER
, sizeof( wire_indices
), wire_indices
, GL_STATIC_DRAW
);
1001 glVertexAttribPointer( 0, 2, GL_FLOAT
, GL_FALSE
, 2*sizeof(float), (void*)0 );
1002 glEnableVertexAttribArray( 0 );
1006 mw
->em
= vg_list_size( wire_indices
);
1009 // Create info data texture
1011 glGenTextures( 1, &world
.background_data
);
1012 glBindTexture( GL_TEXTURE_2D
, world
.background_data
);
1013 glTexImage2D( GL_TEXTURE_2D
, 0, GL_RGBA
, 64, 64, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
1017 // Create random smaples texture
1019 u8
*data
= malloc(512*512*2);
1020 for( int i
= 0; i
< 512*512*2; i
++ )
1021 data
[ i
] = rand()/(RAND_MAX
/255);
1023 glGenTextures( 1, &world
.random_samples
);
1024 glBindTexture( GL_TEXTURE_2D
, world
.random_samples
);
1025 glTexImage2D( GL_TEXTURE_2D
, 0, GL_RG
, 512, 512, 0, GL_RG
, GL_UNSIGNED_BYTE
, data
);
1032 resource_load_main();
1034 // Restore gamestate
1036 console_load_map( 1, level_pack_1
);
1041 console_save_map( 0, NULL
);
1044 resource_free_main();
1046 glDeleteTextures( 1, &world
.background_data
);
1047 glDeleteTextures( 1, &world
.random_samples
);
1049 glDeleteVertexArrays( 1, &world
.wire
.vao
);
1050 glDeleteBuffers( 1, &world
.wire
.vbo
);
1051 glDeleteBuffers( 1, &world
.wire
.ebo
);
1053 free_mesh( &world
.tile
);
1054 free_mesh( &world
.circle
);
1055 free_mesh( &world
.numbers
);
1060 static int world_check_pos_ok( v2i co
)
1062 return (co
[0] < 2 || co
[0] >= world
.w
-2 || co
[1] < 2 || co
[1] >= world
.h
-2)? 0: 1;
1065 static int cell_interactive( v2i co
)
1068 if( !world_check_pos_ok( co
) )
1072 if( world
.data
[ world
.w
*co
[1] + co
[0] ].state
& (FLAG_WALL
|FLAG_INPUT
|FLAG_OUTPUT
) )
1075 // List of 3x3 configurations that we do not allow
1076 static u32 invalid_src
[][9] =
1108 // Statically compile invalid configurations into bitmasks
1109 static u32 invalid
[ vg_list_size(invalid_src
) ];
1111 for( int i
= 0; i
< vg_list_size(invalid_src
); i
++ )
1115 for( int j
= 0; j
< 3; j
++ )
1116 for( int k
= 0; k
< 3; k
++ )
1117 comped
|= invalid_src
[i
][ j
*3+k
] << ((j
*5)+k
);
1119 invalid
[i
] = comped
;
1122 // Extract 5x5 grid surrounding tile
1124 for( int y
= co
[1]-2; y
< co
[1]+3; y
++ )
1125 for( int x
= co
[0]-2; x
< co
[0]+3; x
++ )
1127 struct cell
*cell
= pcell((v2i
){x
,y
});
1129 if( cell
&& (cell
->state
& (FLAG_CANAL
|FLAG_INPUT
|FLAG_OUTPUT
)) )
1130 blob
|= 0x1 << ((y
-(co
[1]-2))*5 + x
-(co
[0]-2));
1133 // Run filter over center 3x3 grid to check for invalid configurations
1134 int kernel
[] = { 0, 1, 2, 5, 6, 7, 10, 11, 12 };
1135 for( int i
= 0; i
< vg_list_size(kernel
); i
++ )
1137 if( blob
& (0x1 << (6+kernel
[i
])) )
1139 u32 window
= blob
>> kernel
[i
];
1141 for( int j
= 0; j
< vg_list_size(invalid
); j
++ )
1142 if((window
& invalid
[j
]) == invalid
[j
])
1150 static void map_reclassify( v2i start
, v2i end
, int update_texbuffer
)
1152 v2i full_start
= { 1,1 };
1153 v2i full_end
= { world
.w
-1, world
.h
-1 };
1155 if( !start
|| !end
)
1162 u8 info_buffer
[64*64*4];
1165 int px0
= vg_max( start
[0], full_start
[0] ),
1166 px1
= vg_min( end
[0], full_end
[0] ),
1167 py0
= vg_max( start
[1], full_start
[1] ),
1168 py1
= vg_min( end
[1], full_end
[1] );
1170 for( int y
= py0
; y
< py1
; y
++ )
1172 for( int x
= px0
; x
< px1
; x
++ )
1174 struct cell
*cell
= pcell((v2i
){x
,y
});
1176 v2i dirs
[] = {{1,0},{0,1},{-1,0},{0,-1}};
1181 if( cell
->state
& (FLAG_CANAL
|FLAG_INPUT
|FLAG_OUTPUT
) )
1183 for( int i
= 0; i
< vg_list_size( dirs
); i
++ )
1185 struct cell
*neighbour
= pcell((v2i
){x
+dirs
[i
][0], y
+dirs
[i
][1]});
1186 if( neighbour
->state
& (FLAG_CANAL
|FLAG_INPUT
|FLAG_OUTPUT
) )
1194 if( cell
->state
& FLAG_WALL
)
1200 pcell((v2i
){x
,y
})->config
= config
;
1202 u8
*info_px
= &info_buffer
[ (pixel_id
++)*4 ];
1203 info_px
[0] = height
;
1204 info_px
[1] = cell
->state
& FLAG_WALL
? 0: 255;
1210 ((cell
->state
& FLAG_IS_TRIGGER
) && (cell
->config
== 0xF || cell
->config
== k_cell_type_split
)) ||
1211 ((cell
->state
& FLAG_TARGETED
) && (cell
->config
!= k_cell_type_split
))
1212 ) && update_texbuffer
1214 cell
->state
&= ~(FLAG_TARGETED
|FLAG_IS_TRIGGER
);
1215 for( u32 i
= 0; i
< 2; i
++ )
1217 if( cell
->links
[i
] )
1219 struct cell
*other_ptr
= &world
.data
[ cell
->links
[i
] ];
1220 other_ptr
->links
[ i
] = 0;
1221 other_ptr
->state
&= ~FLAG_IS_TRIGGER
;
1223 if( other_ptr
->links
[ i
^ 0x1 ] == 0 )
1224 other_ptr
->state
&= ~FLAG_TARGETED
;
1234 if( update_texbuffer
)
1236 glBindTexture( GL_TEXTURE_2D
, world
.background_data
);
1237 glTexSubImage2D( GL_TEXTURE_2D
, 0, px0
+ 16, py0
+ 16, px1
-px0
, py1
-py0
, GL_RGBA
, GL_UNSIGNED_BYTE
, info_buffer
);
1241 u16 id_drag_from
= 0;
1245 void vg_update(void)
1247 // Fit within screen
1249 float r1
= (float)vg_window_y
/ (float)vg_window_x
,
1250 r2
= (float)world
.h
/ (float)world
.w
,
1253 size
= ( r2
< r1
? (float)world
.w
* 0.5f
: ((float)world
.h
* 0.5f
) / r1
) + 2.5f
;
1254 m3x3_projection( m_projection
, -size
, size
, -size
*r1
, size
*r1
);
1257 origin
[0] = floorf( -0.5f
* world
.w
);
1258 origin
[1] = floorf( -0.5f
* world
.h
);
1261 m3x3_identity( m_view
);
1262 m3x3_translate( m_view
, origin
);
1263 m3x3_mul( m_projection
, m_view
, vg_pv
);
1264 vg_projection_update();
1267 v2_copy( vg_mouse_ws
, world
.tile_pos
);
1269 world
.tile_x
= floorf( world
.tile_pos
[0] );
1270 world
.tile_y
= floorf( world
.tile_pos
[1] );
1273 if( !world
.simulating
&& !gui_want_mouse() )
1275 v2_copy( vg_mouse_ws
, drag_to_co
);
1277 if( cell_interactive( (v2i
){ world
.tile_x
, world
.tile_y
} ))
1279 world
.selected
= world
.tile_y
* world
.w
+ world
.tile_x
;
1281 static u32 modify_state
= 0;
1283 struct cell
*cell_ptr
= &world
.data
[world
.selected
];
1285 if( vg_get_button_down("primary") )
1287 modify_state
= (cell_ptr
->state
& FLAG_CANAL
) ^ FLAG_CANAL
;
1290 if( vg_get_button("primary") && ((cell_ptr
->state
& FLAG_CANAL
) != modify_state
) )
1292 cell_ptr
->state
&= ~FLAG_CANAL
;
1293 cell_ptr
->state
|= modify_state
;
1295 if( cell_ptr
->state
& FLAG_CANAL
)
1297 cell_ptr
->links
[0] = 0;
1298 cell_ptr
->links
[1] = 0;
1300 sfx_set_playrnd( &audio_tile_mod
, &audio_system_sfx
, 3, 6 );
1305 sfx_set_playrnd( &audio_tile_mod
, &audio_system_sfx
, 0, 3 );
1309 map_reclassify( (v2i
){ world
.tile_x
-2, world
.tile_y
-2 },
1310 (v2i
){ world
.tile_x
+2, world
.tile_y
+2 }, 1 );
1313 if( vg_get_button_down("secondary") && !(cell_ptr
->config
== k_cell_type_split
) )
1315 id_drag_from
= world
.selected
;
1316 drag_from_co
[0] = world
.tile_x
+ 0.5f
;
1317 drag_from_co
[1] = world
.tile_y
+ 0.5f
;
1320 if( id_drag_from
&& (cell_ptr
->config
== k_cell_type_split
) )
1322 float local_x
= vg_mouse_ws
[0] - (float)world
.tile_x
;
1323 drag_to_co
[0] = (float)world
.tile_x
+ (local_x
> 0.5f
? 0.75f
: 0.25f
);
1324 drag_to_co
[1] = (float)world
.tile_y
+ 0.25f
;
1326 if( vg_get_button_up("secondary") )
1328 struct cell
*drag_ptr
= &world
.data
[id_drag_from
];
1329 u32 link_id
= local_x
> 0.5f
? 1: 0;
1331 // Cleanup existing connections
1332 if( cell_ptr
->links
[ link_id
] )
1334 vg_warn( "Destroying existing connection on link %u (%hu)\n", link_id
, cell_ptr
->links
[ link_id
] );
1336 struct cell
*current_connection
= &world
.data
[ cell_ptr
->links
[ link_id
]];
1337 current_connection
->state
&= ~FLAG_IS_TRIGGER
;
1338 current_connection
->links
[ link_id
] = 0;
1341 if( drag_ptr
->links
[ link_id
^ 0x1 ] )
1343 vg_warn( "Destroying alternate link %u (%hu)\n", link_id
^ 0x1, drag_ptr
->links
[ link_id
^ 0x1 ] );
1345 struct cell
*current_connection
= &world
.data
[ drag_ptr
->links
[ link_id
^ 0x1 ]];
1346 if( !current_connection
->links
[ link_id
] )
1347 current_connection
->state
&= ~FLAG_TARGETED
;
1349 current_connection
->links
[ link_id
^ 0x1 ] = 0;
1350 drag_ptr
->links
[ link_id
^ 0x1 ] = 0;
1353 // Create the new connection
1354 vg_success( "Creating connection on link %u (%hu)\n", link_id
, id_drag_from
);
1356 cell_ptr
->links
[ link_id
] = id_drag_from
;
1357 drag_ptr
->links
[ link_id
] = world
.selected
;
1359 cell_ptr
->state
|= FLAG_TARGETED
;
1360 drag_ptr
->state
|= FLAG_IS_TRIGGER
;
1366 world
.selected
= -1;
1368 if( !(vg_get_button("secondary") && id_drag_from
) )
1373 world
.selected
= -1;
1377 // Simulation stop/start
1378 if( vg_get_button_down("go") )
1380 if( world
.simulating
)
1386 vg_success( "Starting simulation!\n" );
1388 sfx_set_playrnd( &audio_rolls
, &audio_system_balls_rolling
, 0, 1 );
1390 world
.simulating
= 1;
1391 world
.num_fishes
= 0;
1392 world
.sim_frame
= 0;
1393 world
.sim_start
= vg_time
;
1395 world
.sim_speed
= 2.5f
;
1397 for( int i
= 0; i
< world
.w
*world
.h
; i
++ )
1398 world
.data
[ i
].state
&= ~FLAG_FLIP_FLOP
;
1405 if( world
.simulating
)
1407 while( world
.sim_frame
< (int)((vg_time
-world
.sim_start
)*world
.sim_speed
) )
1409 //vg_info( "frame: %u\n", world.sim_frame );
1410 sfx_set_playrnd( &audio_random
, &audio_system_balls_switching
, 0, 9 );
1412 // Update splitter deltas
1413 for( int i
= 0; i
< world
.h
*world
.w
; i
++ )
1415 struct cell
*cell
= &world
.data
[i
];
1416 if( cell
->config
== k_cell_type_split
)
1418 cell
->state
&= ~FLAG_FLIP_ROTATING
;
1420 if( cell
->state
& FLAG_IS_TRIGGER
)
1421 cell
->state
&= ~FLAG_TRIGGERED
;
1424 int alive_count
= 0;
1426 // Update fish positions
1427 for( int i
= 0; i
< world
.num_fishes
; i
++ )
1429 struct fish
*fish
= &world
.fishes
[i
];
1431 if( fish
->state
== k_fish_state_soon_dead
)
1432 fish
->state
= k_fish_state_dead
;
1434 if( fish
->state
== k_fish_state_soon_alive
)
1435 fish
->state
= k_fish_state_alive
;
1437 if( fish
->state
< k_fish_state_alive
)
1440 struct cell
*cell_current
= pcell( fish
->pos
);
1442 if( fish
->state
== k_fish_state_alive
)
1445 if( cell_current
->state
& FLAG_OUTPUT
)
1447 for( int j
= 0; j
< arrlen( world
.io
); j
++ )
1449 struct cell_terminal
*term
= &world
.io
[j
];
1451 if( term
->id
== fish
->pos
[1]*world
.w
+ fish
->pos
[0] )
1453 struct terminal_run
*run
= &term
->runs
[ world
.sim_run
];
1454 if( run
->recv_count
< vg_list_size( run
->recieved
) )
1455 run
->recieved
[ run
->recv_count
++ ] = fish
->payload
;
1461 fish
->state
= k_fish_state_dead
;
1466 if( cell_current
->config
== k_cell_type_merge
)
1471 fish
->flow_reversed
= 0;
1475 if( cell_current
->config
== k_cell_type_split
)
1478 fish
->dir
[0] = cell_current
->state
&FLAG_FLIP_FLOP
?1:-1;
1481 if( !(cell_current
->state
& FLAG_TARGETED
) )
1482 cell_current
->state
^= FLAG_FLIP_FLOP
;
1486 // Apply cell out-flow
1487 struct cell_description
*desc
= &cell_descriptions
[ cell_current
->config
];
1489 v2i_copy( fish
->flow_reversed
? desc
->start
: desc
->end
, fish
->dir
);
1493 v2i_add( fish
->pos
, fish
->dir
, pos_next
);
1495 struct cell
*cell_next
= pcell( pos_next
);
1497 if( cell_next
->state
& (FLAG_CANAL
|FLAG_OUTPUT
) )
1499 struct cell_description
*desc
= &cell_descriptions
[ cell_next
->config
];
1501 if( cell_next
->config
== k_cell_type_merge
)
1503 if( fish
->dir
[0] == 0 )
1504 fish
->state
= k_fish_state_dead
;
1506 fish
->flow_reversed
= 0;
1510 if( cell_next
->config
== k_cell_type_split
)
1512 if( fish
->dir
[0] == 0 )
1514 sfx_set_playrnd( &audio_splitter
, &audio_system_balls_important
, 0, 1 );
1515 cell_next
->state
|= FLAG_FLIP_ROTATING
;
1517 fish
->flow_reversed
= 0;
1520 fish
->state
= k_fish_state_dead
;
1523 fish
->flow_reversed
= ( fish
->dir
[0] != -desc
->start
[0] ||
1524 fish
->dir
[1] != -desc
->start
[1] )? 1: 0;
1528 fish
->state
= world_check_pos_ok( fish
->pos
)? k_fish_state_bg
: k_fish_state_dead
;
1531 //v2i_add( fish->pos, fish->dir, fish->pos );
1533 else if( fish
->state
== k_fish_state_bg
)
1535 v2i_add( fish
->pos
, fish
->dir
, fish
->pos
);
1537 if( !world_check_pos_ok( fish
->pos
) )
1538 fish
->state
= k_fish_state_dead
;
1541 struct cell
*cell_entry
= pcell( fish
->pos
);
1543 if( cell_entry
->state
& FLAG_CANAL
)
1545 if( cell_entry
->config
== k_cell_type_con_r
|| cell_entry
->config
== k_cell_type_con_u
1546 || cell_entry
->config
== k_cell_type_con_l
|| cell_entry
->config
== k_cell_type_con_d
)
1548 sw_set_achievement( "CAN_DO_THAT" );
1550 fish
->state
= k_fish_state_soon_alive
;
1554 fish
->flow_reversed
= 1;
1556 switch( cell_entry
->config
)
1558 case k_cell_type_con_r
: fish
->dir
[0] = 1; break;
1559 case k_cell_type_con_l
: fish
->dir
[0] = -1; break;
1560 case k_cell_type_con_u
: fish
->dir
[1] = 1; break;
1561 case k_cell_type_con_d
: fish
->dir
[1] = -1; break;
1567 else { vg_error( "fish behaviour unimplemented for behaviour type (%d)\n" ); }
1569 if( fish
->state
>= k_fish_state_alive
)
1573 // Second pass (triggers)
1574 for( int i
= 0; i
< world
.num_fishes
; i
++ )
1576 struct fish
*fish
= &world
.fishes
[i
];
1578 if( fish
->state
== k_fish_state_alive
)
1580 v2i_add( fish
->pos
, fish
->dir
, fish
->pos
);
1581 struct cell
*cell_current
= pcell( fish
->pos
);
1583 if( cell_current
->state
& FLAG_IS_TRIGGER
)
1585 int trigger_id
= cell_current
->links
[0]?0:1;
1586 int connection_id
= cell_current
->links
[trigger_id
];
1587 int target_px
= connection_id
% world
.w
;
1588 int target_py
= (connection_id
- target_px
)/world
.w
;
1590 vg_line2( (v2f
){ fish
->pos
[0], fish
->pos
[1] }, (v2f
){ target_px
, target_py
}, 0xffffffff, 0xffffffff );
1592 struct cell
*target_peice
= &world
.data
[ cell_current
->links
[trigger_id
] ];
1594 cell_current
->state
|= FLAG_TRIGGERED
;
1597 target_peice
->state
|= FLAG_FLIP_FLOP
;
1599 target_peice
->state
&= ~FLAG_FLIP_FLOP
;
1604 // Third pass (collisions)
1605 struct fish
*fi
, *fj
;
1607 for( int i
= 0; i
< world
.num_fishes
; i
++ )
1609 fi
= &world
.fishes
[i
];
1611 if( fi
->state
== k_fish_state_alive
)
1613 int continue_again
= 0;
1615 for( int j
= i
+1; j
< world
.num_fishes
; j
++ )
1617 fj
= &world
.fishes
[j
];
1619 if( (fj
->state
== k_fish_state_alive
) )
1624 v2i_sub( fi
->pos
, fi
->dir
, fi_prev
);
1625 v2i_sub( fj
->pos
, fj
->dir
, fj_prev
);
1628 collide_next_frame
= (
1629 (fi
->pos
[0] == fj
->pos
[0]) &&
1630 (fi
->pos
[1] == fj
->pos
[1]))? 1: 0,
1631 collide_this_frame
= (
1632 (fi_prev
[0] == fj
->pos
[0]) &&
1633 (fi_prev
[1] == fj
->pos
[1]) &&
1634 (fj_prev
[0] == fi
->pos
[0]) &&
1635 (fj_prev
[1] == fi
->pos
[1])
1638 if( collide_next_frame
|| collide_this_frame
)
1640 sw_set_achievement( "BANG" );
1642 // Shatter death (+0.5s)
1643 float death_time
= collide_this_frame
? 0.0f
: 0.5f
;
1645 fi
->state
= k_fish_state_soon_dead
;
1646 fj
->state
= k_fish_state_soon_dead
;
1647 fi
->death_time
= death_time
;
1648 fj
->death_time
= death_time
;
1655 if( continue_again
)
1661 for( int i
= 0; i
< arrlen( world
.io
); i
++ )
1663 struct cell_terminal
*term
= &world
.io
[ i
];
1664 int posx
= term
->id
% world
.w
;
1665 int posy
= (term
->id
- posx
)/world
.w
;
1666 int is_input
= world
.data
[ term
->id
].state
& FLAG_INPUT
;
1670 if( world
.sim_frame
< term
->runs
[ world
.sim_run
].condition_count
)
1672 struct fish
*fish
= &world
.fishes
[ world
.num_fishes
];
1673 fish
->pos
[0] = posx
;
1674 fish
->pos
[1] = posy
;
1675 fish
->state
= k_fish_state_alive
;
1676 fish
->payload
= term
->runs
[ world
.sim_run
].conditions
[ world
.sim_frame
];
1678 struct cell
*cell_ptr
= pcell( fish
->pos
);
1680 if( cell_ptr
->config
!= k_cell_type_stub
)
1682 struct cell_description
*desc
= &cell_descriptions
[ cell_ptr
->config
];
1684 v2i_copy( desc
->start
, fish
->dir
);
1685 fish
->flow_reversed
= 1;
1687 world
.num_fishes
++;
1694 if( alive_count
== 0 )
1696 world
.completed
= 1;
1698 for( int i
= 0; i
< arrlen( world
.io
); i
++ )
1700 struct cell_terminal
*term
= &world
.io
[ i
];
1701 int is_input
= world
.data
[ term
->id
].state
& FLAG_INPUT
;
1705 struct terminal_run
*run
= &term
->runs
[ world
.sim_run
];
1707 if( run
->recv_count
== run
->condition_count
)
1709 for( int j
= 0; j
< run
->condition_count
; j
++ )
1711 if( run
->recieved
[j
] != run
->conditions
[j
] )
1713 world
.completed
= 0;
1720 world
.completed
= 0;
1726 if( world
.completed
)
1728 if( world
.sim_run
< world
.max_runs
-1 )
1730 vg_success( "Run passed, starting next\n" );
1732 world
.sim_frame
= 0;
1733 world
.sim_start
= vg_time
;
1734 world
.num_fishes
= 0;
1736 for( int i
= 0; i
< world
.w
*world
.h
; i
++ )
1737 world
.data
[ i
].state
&= ~FLAG_FLIP_FLOP
;
1743 vg_success( "Level passed!\n" );
1746 for( int i
= 0; i
< world
.w
*world
.h
; i
++ )
1747 if( world
.data
[ i
].state
& FLAG_CANAL
)
1750 world
.score
= score
;
1751 world
.time
= world
.sim_frame
;
1756 if( world
.sim_run
> 0 )
1757 sw_set_achievement( "GOOD_ENOUGH" );
1759 vg_error( "Level failed :(\n" );
1762 // Copy into career data
1763 if( world
.ptr_career_level
)
1765 world
.ptr_career_level
->score
= world
.score
;
1766 world
.ptr_career_level
->time
= world
.time
;
1767 world
.ptr_career_level
->completed
= world
.completed
;
1770 simulation_stop(); // TODO: Async?
1777 float scaled_time
= 0.0f
;
1778 scaled_time
= (vg_time
-world
.sim_start
)*world
.sim_speed
;
1779 world
.frame_lerp
= scaled_time
- (float)world
.sim_frame
;
1782 for( int i
= 0; i
< world
.num_fishes
; i
++ )
1784 struct fish
*fish
= &world
.fishes
[i
];
1786 if( fish
->state
== k_fish_state_dead
)
1789 if( fish
->state
== k_fish_state_soon_dead
&& (world
.frame_lerp
> fish
->death_time
) )
1790 continue; // Todo: particle thing?
1792 struct cell
*cell
= pcell(fish
->pos
);
1793 struct cell_description
*desc
= &cell_descriptions
[ cell
->config
];
1797 float t
= world
.frame_lerp
;
1798 if( fish
->flow_reversed
&& !desc
->is_linear
)
1801 v2_copy( fish
->physics_co
, fish
->physics_v
);
1803 switch( cell
->config
)
1805 case k_cell_type_merge
:
1806 if( fish
->dir
[0] == 1 )
1811 case k_cell_type_con_r
: curve
= curve_1
; break;
1812 case k_cell_type_con_l
: curve
= curve_4
; break;
1813 case k_cell_type_con_u
: curve
= curve_2
; break;
1814 case k_cell_type_con_d
: curve
= curve_8
; break;
1815 case 3: curve
= curve_3
; break;
1816 case 6: curve
= curve_6
; break;
1817 case 9: curve
= curve_9
; break;
1818 case 12: curve
= curve_12
; break;
1820 if( t
> curve_7_linear_section
)
1822 t
-= curve_7_linear_section
;
1823 t
*= (1.0f
/(1.0f
-curve_7_linear_section
));
1825 curve
= cell
->state
& FLAG_FLIP_FLOP
? curve_7
: curve_7_1
;
1829 default: curve
= NULL
; break;
1835 float t3
= t
* t
* t
;
1837 float cA
= 3.0f
*t2
- 3.0f
*t3
;
1838 float cB
= 3.0f
*t3
- 6.0f
*t2
+ 3.0f
*t
;
1839 float cC
= 3.0f
*t2
- t3
- 3.0f
*t
+ 1.0f
;
1841 fish
->physics_co
[0] = t3
*curve
[3][0] + cA
*curve
[2][0] + cB
*curve
[1][0] + cC
*curve
[0][0];
1842 fish
->physics_co
[1] = t3
*curve
[3][1] + cA
*curve
[2][1] + cB
*curve
[1][1] + cC
*curve
[0][1];
1843 fish
->physics_co
[0] += (float)fish
->pos
[0];
1844 fish
->physics_co
[1] += (float)fish
->pos
[1];
1849 origin
[0] = (float)fish
->pos
[0] + (float)fish
->dir
[0]*-0.5f
+ 0.5f
;
1850 origin
[1] = (float)fish
->pos
[1] + (float)fish
->dir
[1]*-0.5f
+ 0.5f
;
1852 fish
->physics_co
[0] = origin
[0] + (float)fish
->dir
[0]*t
;
1853 fish
->physics_co
[1] = origin
[1] + (float)fish
->dir
[1]*t
;
1859 static void render_tiles( v2i start
, v2i end
, v4f
const regular_colour
, v4f
const selected_colour
)
1861 v2i full_start
= { 0,0 };
1862 v2i full_end
= { world
.w
, world
.h
};
1864 if( !start
|| !end
)
1870 glUniform4fv( SHADER_UNIFORM( shader_tile_main
, "uColour" ), 1, regular_colour
);
1872 for( int y
= start
[1]; y
< end
[1]; y
++ )
1874 for( int x
= start
[0]; x
< end
[0]; x
++ )
1876 struct cell
*cell
= pcell((v2i
){x
,y
});
1877 int selected
= world
.selected
== y
*world
.w
+ x
;
1879 int tile_offsets
[][2] =
1881 {2, 0}, {0, 3}, {0, 2}, {2, 2},
1882 {1, 0}, {2, 3}, {3, 2}, {1, 3},
1883 {3, 1}, {0, 1}, {1, 2}, {2, 1},
1884 {1, 1}, {3, 3}, {2, 1}, {2, 1}
1887 int uv
[2] = { 3, 0 };
1889 if( cell
->state
& (FLAG_CANAL
|FLAG_INPUT
|FLAG_OUTPUT
) )
1891 uv
[0] = tile_offsets
[ cell
->config
][0];
1892 uv
[1] = tile_offsets
[ cell
->config
][1];
1895 glUniform4f( SHADER_UNIFORM( shader_tile_main
, "uOffset" ), (float)x
, (float)y
, uv
[0], uv
[1] );
1898 glUniform4fv( SHADER_UNIFORM( shader_tile_main
, "uColour" ), 1, selected_colour
);
1900 glUniform4fv( SHADER_UNIFORM( shader_tile_main
, "uColour" ), 1, regular_colour
);
1908 static void draw_numbers( v3f coord
, int number
)
1911 v3_copy( coord
, pos
);
1912 int digits
[8]; int i
= 0;
1914 while( number
> 0 && i
< 8 )
1916 digits
[i
++] = number
% 10;
1917 number
= number
/ 10;
1920 for( int j
= 0; j
< i
; j
++ )
1922 glUniform3fv( SHADER_UNIFORM( shader_tile_colour
, "uOffset" ), 1, pos
);
1923 draw_mesh( MESH_NUMBERS_OFFSETS
[digits
[i
-j
-1]][0], MESH_NUMBERS_OFFSETS
[digits
[i
-j
-1]][1] );
1924 pos
[0] += pos
[2] * 0.75f
;
1928 void vg_render(void)
1930 glViewport( 0,0, vg_window_x
, vg_window_y
);
1932 glDisable( GL_DEPTH_TEST
);
1933 glClearColor( 0.369768f
, 0.3654f
, 0.42f
, 1.0f
);
1934 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
1936 v4f
const colour_default
= {1.0f
, 1.0f
, 1.0f
, 1.0f
};
1937 v4f
const colour_selected
= {0.90f
, 0.92f
, 1.0f
, 1.0f
};
1939 // TILE SET RENDERING
1940 // todo: just slam everything into a mesh...
1941 // when user modifies a tile the neighbours can be easily uploaded to gpu mem
1943 // Currently we're uploading a fair amount of data every frame anyway.
1944 // NOTE: this is for final optimisations ONLY!
1945 // ======================================================================
1947 use_mesh( &world
.tile
);
1953 SHADER_USE( shader_background
);
1954 glUniformMatrix3fv( SHADER_UNIFORM( shader_background
, "uPv" ), 1, GL_FALSE
, (float *)vg_pv
);
1956 glActiveTexture( GL_TEXTURE0
);
1957 glBindTexture( GL_TEXTURE_2D
, world
.background_data
);
1958 glUniform1i( SHADER_UNIFORM( shader_background
, "uTexMain" ), 0 );
1960 glUniform3f( SHADER_UNIFORM( shader_background
, "uOffset" ), -16, -16, 64 );
1961 glUniform1f( SHADER_UNIFORM( shader_background
, "uVariance" ), 0.02f
);
1963 glActiveTexture( GL_TEXTURE1
);
1964 glBindTexture( GL_TEXTURE_2D
, world
.random_samples
);
1965 glUniform1i( SHADER_UNIFORM( shader_background
, "uSamplerNoise" ), 1 );
1973 ui_begin( &ui_global_ctx
, 512, 256 );
1975 ui_global_ctx
.override_colour
= 0xff9a8a89;
1976 //ui_text( &ui_global_ctx, world.map_title, 6, 0 );
1977 ui_global_ctx
.override_colour
= 0xffffffff;
1979 ui_resolve( &ui_global_ctx
);
1982 m3x3_copy( vg_pv
, world_text
);
1983 m3x3_translate( world_text
, (v3f
){ 1.55f
, 1.9f
, 0.0f
} );
1984 m3x3_rotate( world_text
, VG_PIf
*0.5f
);
1985 m3x3_scale( world_text
, (v3f
){0.01f
,-0.01f
,0.01f
} );
1987 ui_draw( &ui_global_ctx
, world_text
);
1990 // =========================================================================================
1992 use_mesh( &world
.tile
);
1993 SHADER_USE( shader_tile_main
);
1996 m2x2_identity( subtransform
);
1997 glUniformMatrix2fv( SHADER_UNIFORM( shader_tile_main
, "uSubTransform" ), 1, GL_FALSE
, (float *)subtransform
);
1998 glUniformMatrix3fv( SHADER_UNIFORM( shader_tile_main
, "uPv" ), 1, GL_FALSE
, (float *)vg_pv
);
1999 glUniform1f( SHADER_UNIFORM( shader_tile_main
, "uGhost" ), 0.0f
);
2000 glUniform1f( SHADER_UNIFORM( shader_tile_main
, "uForeground" ), 0.0f
);
2003 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
2004 glBlendEquation(GL_FUNC_ADD
);
2007 vg_tex2d_bind( &tex_tile_data
, 0 );
2008 glUniform1i( SHADER_UNIFORM( shader_tile_main
, "uTexGlyphs" ), 0 );
2010 vg_tex2d_bind( &tex_wood
, 1 );
2011 glUniform1i( SHADER_UNIFORM( shader_tile_main
, "uTexWood" ), 1 );
2013 render_tiles( NULL
, NULL
, colour_default
, colour_default
);
2017 SHADER_USE( shader_ball
);
2018 glUniformMatrix3fv( SHADER_UNIFORM( shader_ball
, "uPv" ), 1, GL_FALSE
, (float *)vg_pv
);
2020 vg_tex2d_bind( &tex_ball_noise
, 0 );
2021 glUniform1i( SHADER_UNIFORM( shader_ball
, "uTexMain" ), 0 );
2024 if( world
.simulating
)
2026 for( int i
= 0; i
< world
.num_fishes
; i
++ )
2028 struct fish
*fish
= &world
.fishes
[i
];
2030 if( fish
->state
== k_fish_state_dead
|| fish
->state
== k_fish_state_bg
)
2033 if( fish
->state
== k_fish_state_soon_dead
&& (world
.frame_lerp
> fish
->death_time
) )
2036 v4f dot_colour
= { 0.0f
, 0.0f
, 0.0f
, 1.0f
};
2037 colour_code_v3( fish
->payload
, dot_colour
);
2039 glUniform3fv( SHADER_UNIFORM( shader_ball
, "uColour" ), 1, dot_colour
);
2040 glUniform2fv( SHADER_UNIFORM( shader_ball
, "uOffset" ), 1, fish
->physics_co
);
2041 glUniform2f( SHADER_UNIFORM( shader_ball
, "uTexOffset" ), (float)i
* 1.2334, (float)i
* -0.3579f
);
2046 SHADER_USE( shader_tile_main
);
2049 vg_tex2d_bind( &tex_tile_data
, 0 );
2050 glUniform1i( SHADER_UNIFORM( shader_tile_main
, "uTexGlyphs" ), 0 );
2052 vg_tex2d_bind( &tex_wood
, 1 );
2053 glUniform1i( SHADER_UNIFORM( shader_tile_main
, "uTexWood" ), 1 );
2055 glUniform1f( SHADER_UNIFORM( shader_tile_main
, "uForeground" ), 1.0f
);
2056 render_tiles( NULL
, NULL
, colour_default
, colour_selected
);
2059 for( int y
= 2; y
< world
.h
-2; y
++ )
2061 for( int x
= 2; x
< world
.w
-2; x
++ )
2063 struct cell
*cell
= pcell((v2i
){x
,y
});
2065 if( cell
->state
& FLAG_CANAL
)
2067 if( cell
->config
== k_cell_type_split
)
2069 float rotation
= cell
->state
& FLAG_FLIP_FLOP
? vg_rad( -45.0f
): vg_rad( 45.0f
);
2071 if( cell
->state
& FLAG_FLIP_ROTATING
)
2073 if( (world
.frame_lerp
> curve_7_linear_section
) )
2075 float const rotation_speed
= 0.4f
;
2076 if( (world
.frame_lerp
< 1.0f
-rotation_speed
) )
2078 float t
= world
.frame_lerp
- curve_7_linear_section
;
2079 t
*= -2.0f
* (1.0f
/(1.0f
-(curve_7_linear_section
+rotation_speed
)));
2089 m2x2_create_rotation( subtransform
, rotation
);
2091 glUniformMatrix2fv( SHADER_UNIFORM( shader_tile_main
, "uSubTransform" ), 1, GL_FALSE
, (float *)subtransform
);
2092 glUniform4f( SHADER_UNIFORM( shader_tile_main
, "uOffset" ), (float)x
, (float)y
+ 0.125f
, cell
->state
& FLAG_TARGETED
? 3.0f
: 0.0f
, 0.0f
);
2100 if( world
.selected
!= -1 && !(world
.data
[ world
.selected
].state
& FLAG_CANAL
) && !id_drag_from
)
2102 v2i new_begin
= { world
.tile_x
- 2, world
.tile_y
- 2 };
2103 v2i new_end
= { world
.tile_x
+ 2, world
.tile_y
+ 2 };
2105 world
.data
[ world
.selected
].state
^= FLAG_CANAL
;
2106 map_reclassify( new_begin
, new_end
, 0 );
2108 m2x2_identity( subtransform
);
2109 glUniform1f( SHADER_UNIFORM( shader_tile_main
, "uGhost" ), 1.0f
);
2110 glUniformMatrix2fv( SHADER_UNIFORM( shader_tile_main
, "uSubTransform" ), 1, GL_FALSE
, (float *)subtransform
);
2111 glUniform2fv( SHADER_UNIFORM( shader_tile_main
, "uMousePos" ), 1, world
.tile_pos
);
2113 render_tiles( new_begin
, new_end
, colour_default
, colour_default
);
2115 world
.data
[ world
.selected
].state
^= FLAG_CANAL
;
2116 map_reclassify( new_begin
, new_end
, 0 );
2119 //glDisable(GL_BLEND);
2121 // Draw connecting wires
2122 glDisable(GL_BLEND
);
2124 SHADER_USE( shader_wire
);
2125 glBindVertexArray( world
.wire
.vao
);
2127 glUniformMatrix3fv( SHADER_UNIFORM( shader_wire
, "uPv" ), 1, GL_FALSE
, (float *)vg_pv
);
2128 glUniform4f( SHADER_UNIFORM( shader_wire
, "uColour" ), 0.2f
, 0.2f
, 0.2f
, 1.0f
);
2132 glUniform1f( SHADER_UNIFORM( shader_wire
, "uCurve" ), 0.4f
);
2133 glUniform3f( SHADER_UNIFORM( shader_wire
, "uStart" ), drag_from_co
[0], drag_from_co
[1], 0.06f
);
2134 glUniform3f( SHADER_UNIFORM( shader_wire
, "uEnd" ), drag_to_co
[0], drag_to_co
[1], 0.06f
);
2135 glDrawElements( GL_TRIANGLES
, world
.wire
.em
, GL_UNSIGNED_SHORT
, (void*)(0) );
2138 float rp_x1
= world
.frame_lerp
*9.0f
;
2139 float rp_x2
= 1.0f
-rp_x1
*expf(1.0f
-rp_x1
)* 0.36f
;
2141 for( int y
= 2; y
< world
.h
-2; y
++ )
2143 for( int x
= 2; x
< world
.w
-2; x
++ )
2145 struct cell
*cell
= pcell((v2i
){x
,y
});
2147 if( cell
->state
& FLAG_CANAL
)
2149 if( cell
->state
& FLAG_IS_TRIGGER
)
2151 int trigger_id
= cell
->links
[0]?0:1;
2153 int x2
= cell
->links
[trigger_id
] % world
.w
;
2154 int y2
= (cell
->links
[trigger_id
] - x2
) / world
.w
;
2159 startpoint
[0] = (float)x2
+ (trigger_id
? 0.75f
: 0.25f
);
2160 startpoint
[1] = (float)y2
+ 0.25f
;
2162 endpoint
[0] = x
+0.5f
;
2163 endpoint
[1] = y
+0.5f
;
2165 glUniform1f( SHADER_UNIFORM( shader_wire
, "uCurve" ), cell
->state
& FLAG_TRIGGERED
? rp_x2
* 0.4f
: 0.4f
);
2166 glUniform3f( SHADER_UNIFORM( shader_wire
, "uStart" ), startpoint
[0], startpoint
[1], 0.04f
);
2167 glUniform3f( SHADER_UNIFORM( shader_wire
, "uEnd" ), endpoint
[0], endpoint
[1], 0.04f
);
2168 glDrawElements( GL_TRIANGLES
, world
.wire
.em
, GL_UNSIGNED_SHORT
, (void*)(0) );
2174 SHADER_USE( shader_tile_colour
);
2175 glUniformMatrix3fv( SHADER_UNIFORM( shader_tile_colour
, "uPv" ), 1, GL_FALSE
, (float *)vg_pv
);
2176 use_mesh( &world
.circle
);
2178 int const filled_start
= 0;
2179 int const filled_count
= 32;
2180 int const empty_start
= 32;
2181 int const empty_count
= 32*2;
2184 for( int i
= 0; i
< arrlen( world
.io
); i
++ )
2186 struct cell_terminal
*term
= &world
.io
[ i
];
2187 int posx
= term
->id
% world
.w
;
2188 int posy
= (term
->id
- posx
)/world
.w
;
2189 int is_input
= world
.data
[ term
->id
].state
& FLAG_INPUT
;
2191 v4f dot_colour
= { 0.0f
, 0.0f
, 0.0f
, 1.0f
};
2193 for( int k
= 0; k
< term
->run_count
; k
++ )
2195 for( int j
= 0; j
< term
->runs
[k
].condition_count
; j
++ )
2197 float y_offset
= is_input
? 1.2f
: -0.2f
;
2198 y_offset
+= (is_input
? 0.2f
: -0.2f
) * (float)k
;
2200 glUniform3f( SHADER_UNIFORM( shader_tile_colour
, "uOffset" ), (float)posx
+ 0.2f
+ 0.2f
* (float)j
, (float)posy
+ y_offset
, 0.1f
);
2204 colour_code_v3( term
->runs
[k
].conditions
[j
], dot_colour
);
2205 glUniform4fv( SHADER_UNIFORM( shader_tile_colour
, "uColour" ), 1, dot_colour
);
2207 // Draw filled if tick not passed, draw empty if empty
2208 if( (world
.sim_frame
> j
&& world
.sim_run
>= k
) || world
.sim_run
> k
)
2209 draw_mesh( empty_start
, empty_count
);
2211 draw_mesh( filled_start
, filled_count
);
2215 if( term
->runs
[k
].recv_count
> j
)
2217 colour_code_v3( term
->runs
[k
].recieved
[j
], dot_colour
);
2218 v3_muls( dot_colour
, 0.8f
, dot_colour
);
2219 glUniform4fv( SHADER_UNIFORM( shader_tile_colour
, "uColour" ), 1, dot_colour
);
2221 draw_mesh( filled_start
, filled_count
);
2224 colour_code_v3( term
->runs
[k
].conditions
[j
], dot_colour
);
2225 glUniform4fv( SHADER_UNIFORM( shader_tile_colour
, "uColour" ), 1, dot_colour
);
2227 draw_mesh( empty_start
, empty_count
);
2233 if( world
.simulating
)
2235 glUniform4f( SHADER_UNIFORM( shader_tile_colour
, "uColour" ), 0.0f
, 0.0f
, 0.0f
, 1.0f
);
2236 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
);
2237 draw_mesh( filled_start
, filled_count
);
2241 float const score_bright
= 1.25f
;
2242 glUniform4f( SHADER_UNIFORM( shader_tile_colour
, "uColour" ),
2243 0.4f
*score_bright
, 0.39f
*score_bright
, 0.45f
*score_bright
, 1.0f
);
2245 use_mesh( &world
.numbers
);
2246 draw_numbers( (v3f
){ 2.0f
, (float)world
.h
-1.875f
, 0.3333f
}, world
.score
);
2249 static ui_colourset flcol_list_a
= {
2251 .hover
= 0xffa09393,
2252 .active
= 0xffbfb1b0
2254 static ui_colourset flcol_list_b
= {
2256 .hover
= 0xffa09393,
2257 .active
= 0xffbfb1b0
2260 static ui_colourset flcol_list_complete_a
= {
2262 .hover
= 0xff8dc18f,
2263 .active
= 0xffb2ddb3
2266 static ui_colourset flcol_list_complete_b
= {
2268 .hover
= 0xff8dc18f,
2269 .active
= 0xffb2ddb3
2272 static ui_colourset flcol_list_locked
= {
2274 .hover
= 0xff655959,
2275 .active
= 0xff655959
2280 SteamLeaderboard_t steam_leaderboard
;
2281 int leaderboard_matches
;
2283 struct cmp_level
*level_selected
;
2290 static int pack_selection
= 0;
2291 static struct pack_info
2293 struct cmp_level
*levels
;
2300 .levels
= cmp_levels_tutorials
,
2301 .level_count
= vg_list_size(cmp_levels_tutorials
),
2305 .levels
= cmp_levels_basic
,
2306 .level_count
= vg_list_size(cmp_levels_basic
),
2310 .levels
= cmp_levels_grad
,
2311 .level_count
= vg_list_size(cmp_levels_tutorials
),
2317 ui_global_ctx
.cursor
[0] = 0;
2318 ui_global_ctx
.cursor
[1] = 0;
2319 ui_global_ctx
.cursor
[2] = 256;
2323 ui_global_ctx
.id_base
= 4 << 16;
2327 gui_capture_mouse( 9999 );
2328 gui_fill_rect( ui_global_ctx
.cursor
, 0xff5577ff );
2330 gui_text( "ASSIGNMENTS", 8, 0 );
2332 ui_global_ctx
.cursor
[1] += 30;
2333 ui_global_ctx
.cursor
[3] = 25;
2337 ui_rect_pad( ui_global_ctx
.cursor
, 2 );
2338 ui_global_ctx
.cursor
[2] = 84;
2340 for( int i
= 0; i
< 3; i
++ )
2342 if( i
== pack_selection
)
2343 gui_override_colours( &flcol_list_locked
);
2345 if( gui_button( 2000 + i
) == k_button_click
)
2348 ui_global_ctx
.cursor
[1] += 2;
2349 gui_text( pack_infos
[i
].name
, 4, 0 );
2352 gui_reset_colours();
2357 ui_global_ctx
.cursor
[3] = 500;
2359 // DRAW LEVEL SELECTION LIST
2361 struct cmp_level
*levels
= pack_infos
[ pack_selection
].levels
;
2362 int count
= pack_infos
[ pack_selection
].level_count
;
2363 int unlocked
= 3000;
2365 static struct ui_scrollbar sb
= {
2369 ui_px view_height
= ui_global_ctx
.cursor
[3];
2370 ui_px level_height
= 50;
2372 // Level scroll view
2375 gui_fill_rect( ui_global_ctx
.cursor
, 0xff5a4e4d );
2376 gui_set_clip( ui_global_ctx
.cursor
);
2378 ui_global_ctx
.cursor
[2] = 14;
2381 ui_px content_height
= count
*level_height
;
2382 if( content_height
> view_height
)
2384 ui_scrollbar( &ui_global_ctx
, &sb
, 1 );
2385 ui_global_ctx
.cursor
[1] -= ui_calculate_content_scroll( &sb
, content_height
);
2389 gui_fill_rect( ui_global_ctx
.cursor
, 0xff807373 );
2392 ui_global_ctx
.cursor
[2] = 240;
2393 ui_global_ctx
.cursor
[3] = level_height
;
2396 for( int i
= 0; i
< count
; i
++ )
2398 struct cmp_level
*lvl_info
= &levels
[i
];
2402 if( lvl_info
->completed_score
!= 0 )
2403 gui_override_colours( i
&0x1? &flcol_list_complete_a
: &flcol_list_complete_b
);
2405 gui_override_colours( i
&0x1? &flcol_list_a
: &flcol_list_b
);
2408 gui_override_colours( &flcol_list_locked
);
2412 if( gui_button( 2 + i
) == k_button_click
)
2414 ui_data
.level_selected
= &levels
[i
];
2415 ui_data
.leaderboard_matches
= 0;
2416 sw_find_leaderboard( ui_data
.level_selected
->map_name
);
2419 ui_global_ctx
.override_colour
= 0xffffffff;
2420 gui_text( lvl_info
->title
, 6, 0 );
2421 ui_global_ctx
.cursor
[1] += 18;
2422 gui_text( "incomplete", 4, 0 );
2426 gui_button( 2 + i
);
2428 ui_global_ctx
.override_colour
= 0xff786f6f;
2429 gui_text( "???", 6, 0 );
2430 ui_global_ctx
.cursor
[1] += 18;
2431 gui_text( "locked", 4, 0 );
2437 gui_reset_colours();
2445 // Selected level UI
2446 // ============================================================
2448 if( ui_data
.level_selected
)
2450 ui_global_ctx
.cursor
[0] += 16;
2451 ui_global_ctx
.cursor
[1] += 16;
2452 ui_global_ctx
.cursor
[2] = 512-40;
2453 ui_global_ctx
.cursor
[3] = 560-16;
2457 gui_capture_mouse( 9999 );
2459 gui_fill_rect( ui_global_ctx
.cursor
, 0xff5a4e4d );
2460 ui_global_ctx
.cursor
[1] += 4;
2461 gui_text( ui_data
.level_selected
->title
, 6, 0 );
2463 ui_global_ctx
.cursor
[1] += 30;
2464 ui_rect_pad( ui_global_ctx
.cursor
, 8 );
2465 ui_global_ctx
.cursor
[3] = 300;
2469 gui_fill_rect( ui_global_ctx
.cursor
, 0xff655959 );
2473 ui_text_use_paragraph( &ui_global_ctx
);
2474 ui_global_ctx
.cursor
[1] += 2;
2476 gui_text( ui_data
.level_selected
->description
, 5, 0 );
2477 ui_text_use_title( &ui_global_ctx
);
2479 // Buttons at the bottom
2480 ui_global_ctx
.cursor
[3] = 30;
2481 ui_global_ctx
.cursor
[2] = 80;
2484 ui_global_ctx
.cursor
[1] -= 8;
2486 if( gui_button( 3000 ) == k_button_click
)
2488 ui_data
.level_selected
= NULL
;
2490 gui_text( "Back", 6, 0 );
2494 ui_global_ctx
.cursor
[2] = 170;
2495 ui_global_ctx
.cursor
[0] -= 8 + 170 + 2;
2498 gui_override_colours( &flcol_list_locked
);
2499 if( gui_button( 3001 ) == k_button_click
)
2500 vg_error( "UNIMPLEMENTED\n" );
2502 gui_text( "Restore Solution", 6, 0 );
2506 ui_global_ctx
.cursor
[0] += 2;
2507 ui_global_ctx
.cursor
[2] = 80;
2510 gui_override_colours( &flcol_list_complete_a
);
2511 if( gui_button( 3002 ) == k_button_click
)
2513 console_changelevel( 1, &ui_data
.level_selected
->map_name
);
2514 ui_data
.level_selected
= NULL
;
2515 ui_data
.leaderboard_matches
= 0;
2517 gui_text( "Play", 6, 0 );
2521 gui_reset_colours();
2525 if( ui_data
.leaderboard_matches
)
2527 ui_global_ctx
.cursor
[0] += 16;
2528 ui_global_ctx
.cursor
[3] = 250;
2533 gui_fill_rect( ui_global_ctx
.cursor
, 0xff5a4e4d );
2540 void leaderboard_found( LeaderboardFindResult_t
*pCallback
)
2542 if( !pCallback
->m_bLeaderboardFound
)
2543 vg_error( "Leaderboard could not be found\n" );
2545 ui_data
.steam_leaderboard
= pCallback
->m_hSteamLeaderboard
;
2546 ui_data
.leaderboard_matches
= 0;
2548 if( ui_data
.level_selected
)
2549 if( !strcmp( sw_get_leaderboard_name( ui_data
.steam_leaderboard
), ui_data
.level_selected
->map_name
) )
2550 ui_data
.leaderboard_matches
= 1;