+ // Quad mesh
+ {
+ float quad_mesh[] =
+ {
+ 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
+ 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f,
+
+ 0.48f, 0.48f, 0.5f, 0.52f, 0.52f, 0.52f, // Static dot
+ 0.375f, 0.25f, 0.5f, 0.75f, 0.625f, 0.25f, // Downwards pointing arrow
+ 0.25f, 0.625f, 0.75f, 0.5f, 0.25f, 0.375f, // Left
+ 0.625f, 0.75f, 0.5f, 0.25f, 0.375f, 0.75f, // up
+ 0.75f, 0.375f, 0.25f, 0.5f, 0.75f, 0.625f
+ };
+
+ init_mesh( &world.tile, quad_mesh, vg_list_size(quad_mesh) );
+ }
+
+ // Circle mesh
+ {
+ float circle_mesh[32*6*3];
+ int res = vg_list_size( circle_mesh ) / (6*3);
+
+ for( int i = 0; i < res; i ++ )
+ {
+ v2f v0 = { sinf( ((float)i/(float)res)*VG_TAUf ), cosf( ((float)i/(float)res)*VG_TAUf ) };
+ v2f v1 = { sinf( ((float)(i+1)/(float)res)*VG_TAUf ), cosf( ((float)(i+1)/(float)res)*VG_TAUf ) };
+
+ circle_mesh[ i*6+0 ] = 0.0f;
+ circle_mesh[ i*6+1 ] = 0.0f;
+
+ v2_copy( v0, circle_mesh + 32*6 + i*12 );
+ v2_muls( v0, 0.8f, circle_mesh + 32*6 + i*12+2 );
+ v2_copy( v1, circle_mesh + 32*6 + i*12+4 );
+
+ v2_copy( v1, circle_mesh + 32*6 + i*12+6 );
+ v2_muls( v1, 0.8f, circle_mesh + 32*6 + i*12+8 );
+ v2_muls( v0, 0.8f, circle_mesh + 32*6 + i*12+10 );
+
+ v2_copy( v0, circle_mesh + i*6+4 );
+ v2_copy( v1, circle_mesh + i*6+2 );
+ v2_copy( v0, circle_mesh+i*6+4 );
+ v2_copy( v1, circle_mesh+i*6+2 );
+ }
+
+ init_mesh( &world.circle, circle_mesh, vg_list_size( circle_mesh ) );
+ }
+
+ // Textures
+ {
+ tex_tile_detail = vg_tex2d_rgba( "textures/tile_overlays.png" );
+ vg_tex2d_mipmap();
+ vg_tex2d_linear_mipmap();
+ vg_tex2d_repeat();
+
+ tex_tile_data = vg_tex2d_rgba( "textures/tileset.png" );
+ vg_tex2d_mipmap();
+ vg_tex2d_linear_mipmap();
+ vg_tex2d_repeat();
+
+ tex_wood = vg_tex2d_rgba( "textures/wood.png" );
+ vg_tex2d_mipmap();
+ vg_tex2d_linear_mipmap();
+ vg_tex2d_repeat();
+
+ tex_ball = vg_tex2d_rgba( "textures/ball_metallic.png" );
+ vg_tex2d_mipmap();
+ vg_tex2d_linear_mipmap();
+ vg_tex2d_clamp();
+ }
+
+ map_load( level_pack[ 0 ] );
+}
+
+void vg_free(void)
+{
+ free_mesh( &world.tile );
+ free_mesh( &world.circle );
+
+ map_free();
+
+ glDeleteTextures( 1, &tex_tile_data );
+ glDeleteTextures( 1, &tex_tile_detail );
+ glDeleteTextures( 1, &tex_wood );
+ glDeleteTextures( 1, &tex_ball );
+}
+
+static int cell_interactive( v2i co )
+{
+ // Bounds check
+ if( co[0] < 2 || co[0] >= world.w-2 || co[1] < 2 || co[1] >= world.h-2 )
+ return 0;
+
+ // Flags check
+ if( world.data[ world.w*co[1] + co[0] ].state & (FLAG_WALL|FLAG_INPUT|FLAG_OUTPUT) )
+ return 0;
+
+ // List of 3x3 configurations that we do not allow
+ static u32 invalid_src[][9] =
+ {
+ { 0,1,0,
+ 1,1,1,
+ 0,1,0
+ },
+ { 0,0,0,
+ 0,1,1,
+ 0,1,1
+ },
+ { 0,0,0,
+ 1,1,0,
+ 1,1,0
+ },
+ { 0,1,1,
+ 0,1,1,
+ 0,0,0
+ },
+ { 1,1,0,
+ 1,1,0,
+ 0,0,0
+ },
+ { 0,1,0,
+ 0,1,1,
+ 0,1,0
+ },
+ { 0,1,0,
+ 1,1,0,
+ 0,1,0
+ }
+ };
+
+ // Statically compile invalid configurations into bitmasks
+ static u32 invalid[ vg_list_size(invalid_src) ];
+
+ for( int i = 0; i < vg_list_size(invalid_src); i ++ )
+ {
+ u32 comped = 0x00;
+
+ for( int j = 0; j < 3; j ++ )
+ for( int k = 0; k < 3; k ++ )
+ comped |= invalid_src[i][ j*3+k ] << ((j*5)+k);
+
+ invalid[i] = comped;
+ }
+