From: hgn Date: Sat, 23 Oct 2021 16:42:24 +0000 (+0100) Subject: art/sound/textures X-Git-Url: https://skaterift.com/git/?a=commitdiff_plain;h=076dd0fbd6e35277edaf474b041e570728575f56;p=fishladder.git art/sound/textures --- diff --git a/build.sh b/build.sh index fb8efff..9acfd36 100755 --- a/build.sh +++ b/build.sh @@ -81,10 +81,12 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then # Directories to initialize mkdir build.linux/cfg -p mkdir build.linux/textures -p + mkdir build.linux/sound -p cp $target ./build.linux/$target cp ./steam/libsteam_api.so ./build.linux/libsteam_api.so cp -r ./textures/ ./build.linux/ + cp -r ./sound/ ./build.linux/ if [ "$run_after" = true ]; then echo "Playing" @@ -96,9 +98,11 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then else mkdir build.win32/cfg -p mkdir build.win32/textures -p + mkdir build.win32/sound -p cp $target ./build.win32/$target cp -r ./textures/ ./build.win32/ + cp -r ./sound/ ./build.win32/ cp ./lib/glfw3.dll ./build.win32/glfw3.dll if [ "$run_after" = true ]; then diff --git a/fishladder.c b/fishladder.c index 4e41b5a..6d6486b 100644 --- a/fishladder.c +++ b/fishladder.c @@ -41,7 +41,7 @@ SHADER_DEFINE( shader_ball, "aTexCoords = a_co;" // Vertex transform - "vec3 worldpos = vec3( a_co * 0.25 - 0.125 + uOffset, 1.0 );" + "vec3 worldpos = vec3( a_co * 0.5 - 0.25 + uOffset, 1.0 );" "gl_Position = vec4( uPv * worldpos, 1.0 );" "}", @@ -56,7 +56,7 @@ SHADER_DEFINE( shader_ball, "void main()" "{" "vec4 glyph = texture( uTexMain, aTexCoords );" - "FragColor = vec4( glyph.rgb * uColour, glyph.a );" + "FragColor = vec4( uColour + glyph.rgb * 0.2, glyph.a );" "}" , UNIFORMS({ "uTexMain", "uColour", "uOffset", "uPv" }) @@ -178,6 +178,28 @@ GLuint tex_tile_detail; GLuint tex_wood; GLuint tex_ball; +sfx_system_t audio_system_sfx = +{ + .vol = 1.f, + .spd = 1.f, + .ch = 1, + .cur = 0, + .vol_src = &g_vol_sfx, + .flags = 0x00, + .fadeout = FADEOUT_LENGTH, + .name = "sfx" +}; + +sfx_set_t audio_tile_mod = +{ + .sources = "\ +sound/mod00.ogg\0\ +sound/mod01.ogg\0\ +sound/mod02.ogg\0\ +sound/mod03.ogg\0", + .flags = 0 +}; + m3x3f m_projection; m3x3f m_view; m3x3f m_mdl; @@ -537,12 +559,17 @@ void vg_start(void) vg_tex2d_linear_mipmap(); vg_tex2d_repeat(); - tex_ball = vg_tex2d_rgba( "textures/ball_metallic.png" ); + tex_ball = vg_tex2d_rgba( "textures/ball.png" ); vg_tex2d_mipmap(); vg_tex2d_linear_mipmap(); vg_tex2d_clamp(); } + // Audio + { + sfx_set_init( &audio_tile_mod, NULL ); + } + map_load( level_pack[ 0 ] ); } @@ -557,6 +584,8 @@ void vg_free(void) glDeleteTextures( 1, &tex_tile_detail ); glDeleteTextures( 1, &tex_wood ); glDeleteTextures( 1, &tex_ball ); + + sfx_set_free( &audio_tile_mod ); } static int cell_interactive( v2i co ) @@ -699,6 +728,7 @@ void vg_update(void) if( vg_get_button_down("primary") ) { world.data[ world.selected ].state ^= FLAG_CANAL; + sfx_set_playrnd( &audio_tile_mod, &audio_system_sfx ); } } else @@ -865,57 +895,53 @@ void vg_update(void) continue; } - if( !(cell_current->state & (FLAG_INPUT|FLAG_CANAL)) ) + if( cell_current->state & FLAG_SPLIT ) { - fish->alive = 0; + // Flip flop L/R + fish->dir[0] = cell_current->state&FLAG_FLIP_FLOP?1:-1; + fish->dir[1] = 0; + + cell_current->state ^= FLAG_FLIP_FLOP; + } + else if( cell_current->state & FLAG_MERGER ) + { + // Can only move up + fish->dir[0] = 0; + fish->dir[1] = -1; } else { - if( cell_current->state & FLAG_SPLIT ) + struct cell *cell_next = pcell( (v2i){ fish->pos[0]+fish->dir[0], fish->pos[1]+fish->dir[1] } ); + if( !(cell_next->state & (FLAG_CANAL|FLAG_OUTPUT)) ) { - // Flip flop L/R - fish->dir[0] = cell_current->state&FLAG_FLIP_FLOP?1:-1; - fish->dir[1] = 0; + // Try other directions for valid, so down, left, right.. + v2i dirs[] = {{1,0},{-1,0},{0,-1}}; + vg_info( "Trying some other directions...\n" ); - cell_current->state ^= FLAG_FLIP_FLOP; - } - else if( cell_current->state & FLAG_MERGER ) - { - // Can only move up - fish->dir[0] = 0; - fish->dir[1] = -1; - } - else - { - struct cell *cell_next = pcell( (v2i){ fish->pos[0]+fish->dir[0], fish->pos[1]+fish->dir[1] } ); - if( !(cell_next->state & (FLAG_CANAL|FLAG_OUTPUT)) ) + for( int j = 0; j < vg_list_size(dirs); j ++ ) { - // Try other directions for valid, so down, left, right.. - v2i dirs[] = {{1,0},{-1,0},{0,-1}}; - vg_info( "Trying some other directions...\n" ); - - for( int j = 0; j < vg_list_size(dirs); j ++ ) + if( (dirs[j][0] == -fish->dir[0]) && (dirs[j][1] == -fish->dir[1]) ) + continue; + + if( pcell( (v2i){ fish->pos[0]+dirs[j][0], fish->pos[1]+dirs[j][1] } )->state & (FLAG_CANAL|FLAG_OUTPUT) ) { - if( (dirs[j][0] == -fish->dir[0]) && (dirs[j][1] == -fish->dir[1]) ) - continue; - - if( pcell( (v2i){ fish->pos[0]+dirs[j][0], fish->pos[1]+dirs[j][1] } )->state & (FLAG_CANAL|FLAG_OUTPUT) ) - { - fish->dir[0] = dirs[j][0]; - fish->dir[1] = dirs[j][1]; - } + fish->dir[0] = dirs[j][0]; + fish->dir[1] = dirs[j][1]; } } } - - fish->pos[0] += fish->dir[0]; - fish->pos[1] += fish->dir[1]; - - struct cell *cell_entry = pcell( fish->pos ); - + } + + fish->pos[0] += fish->dir[0]; + fish->pos[1] += fish->dir[1]; + + struct cell *cell_entry = pcell( fish->pos ); + + if( !(cell_entry->state & (FLAG_INPUT|FLAG_CANAL|FLAG_OUTPUT) )) + fish->alive = 0; + else if( cell_entry->config == k_cell_type_split ) cell_entry->state |= FLAG_FLIP_ROTATING; - } } world.sim_frame ++; @@ -923,6 +949,37 @@ void vg_update(void) } } +static void render_tiles(void) +{ + for( int y = 0; y < world.h; y ++ ) + { + for( int x = 0; x < world.w; x ++ ) + { + struct cell *cell = pcell((v2i){x,y}); + int selected = world.selected == y*world.w + x; + + int tile_offsets[][2] = + { + {2, 0}, {0, 3}, {0, 2}, {2, 2}, + {1, 0}, {2, 3}, {3, 2}, {1, 3}, + {3, 1}, {0, 1}, {1, 2}, {2, 1}, + {1, 1}, {3, 3}, {2, 1}, {2, 1} + }; + + int uv[2] = { 3, 0 }; + + if( cell->state & FLAG_CANAL ) + { + uv[0] = tile_offsets[ cell->config ][0]; + uv[1] = tile_offsets[ cell->config ][1]; + } + + glUniform4f( SHADER_UNIFORM( shader_tile_main, "uOffset" ), (float)x, (float)y, uv[0], uv[1] ); + draw_mesh( 0, 2 ); + } + } +} + void vg_render(void) { glViewport( 0,0, vg_window_x, vg_window_y ); @@ -949,9 +1006,16 @@ void vg_render(void) float const curve_7_linear_section = 0.1562f; - // TILE SET RENDERING + // TILE SET RENDERING + // todo: just slam everything into a mesh... + // when user modifies a tile the neighbours can be easily uploaded to gpu mem + // in ~3 subBuffers + // Currently we're uploading a fair amount of data every frame anyway. + // NOTE: this is for final optimisations ONLY! // ====================================================================== + use_mesh( &world.tile ); + SHADER_USE( shader_tile_main ); m2x2f subtransform; @@ -968,78 +1032,12 @@ void vg_render(void) glBindTexture( GL_TEXTURE_2D, tex_wood ); glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexWood" ), 1 ); - for( int y = 0; y < world.h; y ++ ) - { - for( int x = 0; x < world.w; x ++ ) - { - struct cell *cell = pcell((v2i){x,y}); - int selected = world.selected == y*world.w + x; - - int tile_offsets[][2] = - { - {2, 0}, {0, 3}, {0, 2}, {2, 2}, - {1, 0}, {2, 3}, {3, 2}, {1, 3}, - {3, 1}, {0, 1}, {1, 2}, {2, 1}, - {1, 1}, {3, 3}, {2, 1}, {2, 1} - }; - - int uv[2] = { 3, 0 }; - - if( cell->state & FLAG_CANAL ) - { - uv[0] = tile_offsets[ cell->config ][0]; - uv[1] = tile_offsets[ cell->config ][1]; - } - - glUniform4f( SHADER_UNIFORM( shader_tile_main, "uOffset" ), (float)x, (float)y, uv[0], uv[1] ); - draw_mesh( 0, 2 ); - } - } - - // Draw splitters + render_tiles(); + glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); - for( int y = 0; y < world.h; y ++ ) - { - for( int x = 0; x < world.w; x ++ ) - { - struct cell *cell = pcell((v2i){x,y}); - - if( cell->state & FLAG_SPLIT ) - { - float rotation = cell->state & FLAG_FLIP_FLOP? vg_rad( -45.0f ): vg_rad( 45.0f ); - - if( cell->state & FLAG_FLIP_ROTATING ) - { - if( (frame_lerp > curve_7_linear_section) ) - { - float const rotation_speed = 0.4f; - if( (frame_lerp < 1.0f-rotation_speed) ) - { - float t = frame_lerp - curve_7_linear_section; - t *= -2.0f * (1.0f/(1.0f-(curve_7_linear_section+rotation_speed))); - t += 1.0f; - - rotation *= t; - } - else - rotation *= -1.0f; - } - } - - m2x2_create_rotation( subtransform, rotation ); - - glUniformMatrix2fv( SHADER_UNIFORM( shader_tile_main, "uSubTransform" ), 1, GL_FALSE, (float *)subtransform ); - glUniform4f( SHADER_UNIFORM( shader_tile_main, "uOffset" ), (float)x, (float)y + 0.125f, 0.0f, 0.0f ); - draw_mesh( 0, 2 ); - } - } - } - - //glDisable(GL_BLEND); - SHADER_USE( shader_ball ); glUniformMatrix3fv( SHADER_UNIFORM( shader_ball, "uPv" ), 1, GL_FALSE, (float *)vg_pv ); @@ -1123,6 +1121,61 @@ void vg_render(void) } } + + SHADER_USE( shader_tile_main ); + + // Bind textures + glActiveTexture( GL_TEXTURE0 ); + glBindTexture( GL_TEXTURE_2D, tex_tile_data ); + glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexGlyphs" ), 0 ); + + glActiveTexture( GL_TEXTURE1 ); + glBindTexture( GL_TEXTURE_2D, tex_wood ); + glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexWood" ), 1 ); + + render_tiles(); + + // Draw splitters + + for( int y = 0; y < world.h; y ++ ) + { + for( int x = 0; x < world.w; x ++ ) + { + struct cell *cell = pcell((v2i){x,y}); + + if( cell->state & FLAG_SPLIT ) + { + float rotation = cell->state & FLAG_FLIP_FLOP? vg_rad( -45.0f ): vg_rad( 45.0f ); + + if( cell->state & FLAG_FLIP_ROTATING ) + { + if( (frame_lerp > curve_7_linear_section) ) + { + float const rotation_speed = 0.4f; + if( (frame_lerp < 1.0f-rotation_speed) ) + { + float t = frame_lerp - curve_7_linear_section; + t *= -2.0f * (1.0f/(1.0f-(curve_7_linear_section+rotation_speed))); + t += 1.0f; + + rotation *= t; + } + else + rotation *= -1.0f; + } + } + + m2x2_create_rotation( subtransform, rotation ); + + glUniformMatrix2fv( SHADER_UNIFORM( shader_tile_main, "uSubTransform" ), 1, GL_FALSE, (float *)subtransform ); + glUniform4f( SHADER_UNIFORM( shader_tile_main, "uOffset" ), (float)x, (float)y + 0.125f, 0.0f, 0.0f ); + draw_mesh( 0, 2 ); + } + } + } + + //glDisable(GL_BLEND); + glDisable(GL_BLEND); SHADER_USE( shader_tile_colour ); diff --git a/sound/mod00.ogg b/sound/mod00.ogg new file mode 100644 index 0000000..0e98c8a Binary files /dev/null and b/sound/mod00.ogg differ diff --git a/sound/mod01.ogg b/sound/mod01.ogg new file mode 100644 index 0000000..07cbae6 Binary files /dev/null and b/sound/mod01.ogg differ diff --git a/sound/mod02.ogg b/sound/mod02.ogg new file mode 100644 index 0000000..43d1bc0 Binary files /dev/null and b/sound/mod02.ogg differ diff --git a/sound/mod03.ogg b/sound/mod03.ogg new file mode 100644 index 0000000..f0866d0 Binary files /dev/null and b/sound/mod03.ogg differ diff --git a/sound/mod04.ogg b/sound/mod04.ogg new file mode 100644 index 0000000..0ecf86c Binary files /dev/null and b/sound/mod04.ogg differ diff --git a/textures/ball.png b/textures/ball.png new file mode 100644 index 0000000..5109a40 Binary files /dev/null and b/textures/ball.png differ diff --git a/textures/ball_metallic.png b/textures/ball_metallic.png index 09fe6ec..5eb527e 100644 Binary files a/textures/ball_metallic.png and b/textures/ball_metallic.png differ diff --git a/textures/tileset.png b/textures/tileset.png index 973ebd7..5e4ce73 100644 Binary files a/textures/tileset.png and b/textures/tileset.png differ diff --git a/textures/wood.png b/textures/wood.png index ea25c5c..79521d4 100644 Binary files a/textures/wood.png and b/textures/wood.png differ diff --git a/vg/vg_audio.h b/vg/vg_audio.h index f154983..330be30 100644 --- a/vg/vg_audio.h +++ b/vg/vg_audio.h @@ -109,6 +109,7 @@ float *sfx_vorbis_stream( const unsigned char *data, int len, int channels, uint if( !buffer ) { + stb_vorbis_close( pv ); vg_error( "out of memory while allocating sound resource\n" ); return NULL; } @@ -120,6 +121,7 @@ float *sfx_vorbis_stream( const unsigned char *data, int len, int channels, uint length_samples = read_samples; } + stb_vorbis_close( pv ); *samples = length_samples; return buffer; }