From ceb730c43643caee3fb389b09b4ba65862100336 Mon Sep 17 00:00:00 2001 From: hgn Date: Wed, 27 Dec 2023 02:32:15 +0000 Subject: [PATCH] first sorta working port --- build.c | 15 +- fishladder_resources_vg1.h | 485 ++------------------------- fishladder_vg1.c | 654 ++++++++++++++++--------------------- input.h | 179 ++++++++++ marblecomp.c | 40 ++- shaders/background.h | 101 ++++++ shaders/ball.h | 95 ++++++ shaders/button.h | 75 +++++ shaders/buttons.h | 8 + shaders/post_blur.h | 64 ++++ shaders/post_comp.h | 65 ++++ shaders/post_darken.h | 47 +++ shaders/sprite.h | 68 ++++ shaders/tile_colour.h | 53 +++ shaders/tile_main.h | 161 +++++++++ shaders/wire.h | 117 +++++++ vg_config.h | 4 - 17 files changed, 1390 insertions(+), 841 deletions(-) create mode 100644 input.h create mode 100644 shaders/background.h create mode 100644 shaders/ball.h create mode 100644 shaders/button.h create mode 100644 shaders/buttons.h create mode 100644 shaders/post_blur.h create mode 100644 shaders/post_comp.h create mode 100644 shaders/post_darken.h create mode 100644 shaders/sprite.h create mode 100644 shaders/tile_colour.h create mode 100644 shaders/tile_main.h create mode 100644 shaders/wire.h diff --git a/build.c b/build.c index 8827489..bf4173e 100644 --- a/build.c +++ b/build.c @@ -15,7 +15,9 @@ u32 optimize_test_compile = 0; void build_game_content(void){ const char *project_name = vg_build.project_name.buffer; vg_low( "Building game content structure\n" ); - vg_symlink( "textures", "textures" ); + vg_symlink( "textures_qoi", "textures" ); + vg_symlink( "maps", "maps" ); + vg_symlink( "sound", "sound" ); vg_syscall( "mkdir -p bin/%s/cfg", project_name ); } @@ -117,5 +119,14 @@ void build_shaders(void){ vg_shader_set_include_dir( "shaders" ); /* Scene */ - //_S( "scene_standard", "scene.vs", "scene_standard.fs" ); + _S( "tile_colour", "tile_colour.vs.glsl", "tile_colour.fs.glsl" ); + _S( "tile_main", "tile_main.vs.glsl", "tile_main.fs.glsl" ); + _S( "ball", "ball.vs.glsl", "ball.fs.glsl" ); + _S( "background", "background.vs.glsl", "background.fs.glsl" ); + _S( "wire", "wire.vs.glsl", "wire.fs.glsl" ); + _S( "button", "button.vs.glsl", "button.fs.glsl" ); + _S( "sprite", "sprite.vs.glsl", "sprite.fs.glsl" ); + _S( "post_darken", "post_darken.vs.glsl", "post_darken.fs.glsl" ); + _S( "post_comp", "post_comp.vs.glsl", "post_comp.fs.glsl" ); + _S( "post_blur", "post_blur.vs.glsl", "post_blur.fs.glsl" ); } diff --git a/fishladder_resources_vg1.h b/fishladder_resources_vg1.h index 196f0e5..7d0ea2f 100644 --- a/fishladder_resources_vg1.h +++ b/fishladder_resources_vg1.h @@ -1,3 +1,30 @@ +#include "shaders/tile_colour.h" +#include "shaders/tile_main.h" +#include "shaders/ball.h" +#include "shaders/background.h" +#include "shaders/wire.h" +#include "shaders/button.h" +#include "shaders/sprite.h" +#include "shaders/post_darken.h" +#include "shaders/post_comp.h" +#include "shaders/post_blur.h" + +/* FIXME */ +#define UI_GLYPH_SPACING_X 8 + +void _mc_vg1_register(void){ + shader_tile_colour_register(); + shader_tile_main_register(); + shader_ball_register(); + shader_background_register(); + shader_wire_register(); + shader_button_register(); + shader_sprite_register(); + shader_post_darken_register(); + shader_post_comp_register(); + shader_post_blur_register(); +} + // TEXTURES // =========================================================================================================== @@ -112,7 +139,7 @@ static void *load_and_play_bgm( void *_inf ) #define INIT_AUDIO( X ) audio_clip_loadn( X, vg_list_size(X), NULL ); -static void resource_load_main(void){ +static void _mc_resource_load_main(void){ // Textures // UI for( u32 i=0; ielements = length/3; glGenVertexArrays( 1, &m->vao ); glGenBuffers( 1, &m->vbo ); @@ -530,23 +526,18 @@ static void init_mesh( struct mesh *m, float const *tris, u32 length ) glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(float), (void*)0 ); glEnableVertexAttribArray( 0 ); - - VG_CHECK_GL(); } -static void free_mesh( struct mesh *m ) -{ +static void free_mesh( struct mesh *m ){ glDeleteVertexArrays( 1, &m->vao ); glDeleteBuffers( 1, &m->vbo ); } -static void draw_mesh( int const start, int const count ) -{ +static void draw_mesh( int const start, int const count ){ glDrawArrays( GL_TRIANGLES, start*3, count*3 ); } -static void use_mesh( struct mesh *m ) -{ +static void use_mesh( struct mesh *m ){ glBindVertexArray( m->vao ); } @@ -702,6 +693,7 @@ static void map_reclassify( v2i start, v2i end, int update_texbuffer ) static void gen_level_text(void) { +#if 0 ui_px const unit_scale_px = 4*UI_GLYPH_SPACING_X; ui_begin( &world.st.world_text, world.w*unit_scale_px, world.h*unit_scale_px ); @@ -763,6 +755,7 @@ static void gen_level_text(void) } ui_resolve( &world.st.world_text ); +#endif } /* Usually for ignoring windows crap */ @@ -1449,7 +1442,6 @@ static void career_reset_level( struct cmp_level *lvl ) static void career_load(void) { - i64 sz; struct dcareer_state encoded; /* Blank save state */ @@ -1462,7 +1454,8 @@ static void career_load(void) * without crashing. Old saves will load fine, too new saves will lose data, * such a situation should rarely (never) happen with the steam version. */ - void *cr = vg_asset_read_s( "sav/game.sv2", &sz ); + u32 sz; + void *cr = vg_file_read( NULL, "sav/game.sv2", &sz ); if( cr ) { @@ -1563,7 +1556,9 @@ static void simulation_stop(void) io_reset(); +#if 0 sfx_system_fadeout( &audio_system_balls_rolling, 44100 ); +#endif clear_animation_flags(); @@ -1573,15 +1568,17 @@ static void simulation_stop(void) static void simulation_start(void) { vg_success( "Starting simulation!\n" ); - - sfx_set_playrnd( &audio_rolls, &audio_system_balls_rolling, 0, 1 ); + audio_lock(); + audio_oneshot( &audio_rolls[ vg_randu32(&vg.rand) % 2 ], 1.0f, 0.0f ); + audio_unlock(); world.num_fishes = 0; world.sim_frame = 0; world.sim_run = 0; - world.sim_delta_speed = world.st.buttons[ k_world_button_speedy ].state? 10.0f: 2.5f; - world.sim_delta_ref = vg_time; + world.sim_delta_speed = world.st.buttons[ k_world_button_speedy ].state? + 10.0f: 2.5f; + world.sim_delta_ref = vg.time; world.sim_internal_ref = 0.0f; world.sim_internal_time = 0.0f; world.pause_offset_target = 0.0f; @@ -1698,14 +1695,14 @@ static int cell_interactive( v2i co ) return 1; } -static void vg_update(void) +static void _mc_vg1_update(void) { // Async events if( world.st.lvl_to_load ) { - world.st.world_transition = (world.st.lvl_load_time-vg_time) * 4.0f; + world.st.world_transition = (world.st.lvl_load_time-vg.time) * 4.0f; - if( vg_time > world.st.lvl_load_time ) + if( vg.time > world.st.lvl_load_time ) { if( console_changelevel( 1, &world.st.lvl_to_load->map_name ) ) { @@ -1718,13 +1715,13 @@ static void vg_update(void) } else { - world.st.world_transition = vg_minf( 1.0f, (vg_time-world.st.lvl_load_time) * 4.0f ); + world.st.world_transition = vg_minf( 1.0f, (vg.time-world.st.lvl_load_time) * 4.0f ); } // Camera // ======================================================================================================== - float r1 = (float)vg_window_y / (float)vg_window_x, + float r1 = (float)vg.window_y / (float)vg.window_x, r2 = (float)world.h / (float)world.w, size; @@ -1750,40 +1747,42 @@ static void vg_update(void) v2_add( origin, result_view, vt_target ); // Lerp towards target - size_current = vg_lerpf( size_current, size - world.st.zoom, vg_time_delta * 6.0f ); - v2_lerp( origin_current, vt_target, vg_time_delta * 6.0f, origin_current ); + size_current = vg_lerpf( size_current, size - world.st.zoom, vg.time_delta * 6.0f ); + v2_lerp( origin_current, vt_target, vg.time_delta * 6.0f, origin_current ); m3x3_projection( m_projection, -size_current, size_current, -size_current*r1, size_current*r1 ); m3x3_identity( m_view ); m3x3_translate( m_view, origin_current ); - m3x3_mul( m_projection, m_view, vg_pv ); + m3x3_mul( m_projection, m_view, vg.pv ); + +#if 0 vg_projection_update(); +#endif if( world.st.state == k_game_state_update ) return; // Mouse input // ======================================================================================================== - v2_copy( vg_mouse_ws, world.tile_pos ); - + v2_copy( marblecomp.mouse_ws, world.tile_pos ); world.tile_x = floorf( world.tile_pos[0] ); world.tile_y = floorf( world.tile_pos[1] ); + v2f vg_mouse = { vg.mouse_pos[0], vg.mouse_pos[1] }; // Camera dragging { static v2f drag_origin; // x/y pixel - if( vg_get_button_down( "tertiary" ) ) - v2_copy( vg_mouse, drag_origin ); - else if( vg_get_button( "tertiary" ) ) - { + if( button_down( k_srbind_tertiary ) ){ + v2_copy( vg_mouse, drag_origin ); + } + else if( button_press( k_srbind_tertiary ) ){ // get offset v2_sub( vg_mouse, drag_origin, drag_offset ); - v2_div( drag_offset, (v2f){ vg_window_x, vg_window_y }, drag_offset ); + v2_div( drag_offset, (v2f){ vg.window_x, vg.window_y }, drag_offset ); v2_mul( drag_offset, (v2f){ size_current*2.0f, -size_current*r1*2.0f }, drag_offset ); } - else - { + else{ v2_copy( result_view, view_point ); v2_copy( (v2f){0.0f,0.0f}, drag_offset ); } @@ -1799,10 +1798,10 @@ static void vg_update(void) rsize = size-world.st.zoom; - v2_div( vg_mouse, (v2f){ vg_window_x*0.5f, vg_window_y*0.5f }, mview_local ); + v2_div( vg_mouse, (v2f){ vg.window_x*0.5f, vg.window_y*0.5f }, mview_local ); v2_add( (v2f){ -rsize, -rsize*r1 }, (v2f){ mview_local[0]*rsize, (2.0f-mview_local[1])*rsize*r1 }, mview_cur ); - world.st.zoom = vg_clampf( world.st.zoom + vg_mouse_wheel[1], 0.0f, size - 4.0f ); + world.st.zoom = vg_clampf( world.st.zoom + vg.mouse_wheel[1], 0.0f, size - 4.0f ); // Recalculate new position rsize = size-world.st.zoom; @@ -1815,9 +1814,8 @@ static void vg_update(void) // Tilemap // ======================================================================================================== - if( !is_simulation_running() && !gui_want_mouse() ) - { - v2_copy( vg_mouse_ws, world.drag_to_co ); + if( !is_simulation_running() ){ + v2_copy( marblecomp.mouse_ws, world.drag_to_co ); if( cell_interactive( (v2i){ world.tile_x, world.tile_y } )) { @@ -1828,33 +1826,37 @@ static void vg_update(void) if( !(cell_ptr->state & FLAG_EMITTER) ) { - if( vg_get_button_down("primary") ) + if( button_down(k_srbind_primary) ) modify_state = (cell_ptr->state & FLAG_CANAL) ^ FLAG_CANAL; - if( vg_get_button("primary") && ((cell_ptr->state & FLAG_CANAL) != modify_state) ) + if( button_press(k_srbind_primary) && ((cell_ptr->state & FLAG_CANAL) != modify_state) ) { cell_ptr->state &= ~FLAG_CANAL; cell_ptr->state |= modify_state; + audio_lock(); if( cell_ptr->state & FLAG_CANAL ) { cell_ptr->links[0] = 0; cell_ptr->links[1] = 0; - sfx_set_playrnd( &audio_tile_mod, &audio_system_sfx, 3, 6 ); + audio_oneshot( &audio_tile_mod[ vg_randu32(&vg.rand)%4+2 ], + 1.0f, 0.0f ); world.score ++; } else - { - sfx_set_playrnd( &audio_tile_mod, &audio_system_sfx, 0, 3 ); + { + audio_oneshot( &audio_tile_mod[ vg_randu32(&vg.rand)%3 ], + 1.0f, 0.0f ); world.score --; } + audio_unlock(); map_reclassify((v2i){ world.tile_x -2, world.tile_y -2 }, (v2i){ world.tile_x +2, world.tile_y +2 }, 1 ); } - if( vg_get_button_down("secondary") && (cell_ptr->state & FLAG_CANAL) && !(cell_ptr->config == k_cell_type_split) ) + if( button_down(k_srbind_secondary) && (cell_ptr->state & FLAG_CANAL) && !(cell_ptr->config == k_cell_type_split) ) { world.id_drag_from = world.selected; @@ -1863,9 +1865,9 @@ static void vg_update(void) } } - float local_x = vg_mouse_ws[0] - (float)world.tile_x; + float local_x = marblecomp.mouse_ws[0] - (float)world.tile_x; - if( vg_get_button_up("secondary") && world.id_drag_from == world.selected ) + if( button_up(k_srbind_secondary) && world.id_drag_from == world.selected ) { u32 link_id = cell_ptr->links[ 0 ]? 0: 1; @@ -1891,7 +1893,7 @@ static void vg_update(void) world.drag_to_co[0] = (float)world.tile_x + (local_x > 0.5f? 0.75f: 0.25f); world.drag_to_co[1] = (float)world.tile_y + 0.25f; - if( vg_get_button_up("secondary") ) + if( button_up( k_srbind_secondary) ) { struct cell *drag_ptr = &world.data[world.id_drag_from]; u32 link_id = local_x > 0.5f? 1: 0; @@ -1938,7 +1940,7 @@ static void vg_update(void) world.selected = -1; } - if( !(vg_get_button("secondary") && world.id_drag_from) ) + if( !(button_press(k_srbind_secondary) && world.id_drag_from) ) world.id_drag_from = 0; } else @@ -1954,9 +1956,9 @@ static void vg_update(void) float old_time = world.sim_internal_time; if( !world.st.buttons[ k_world_button_pause ].state ) - world.sim_internal_time = world.sim_internal_ref + (vg_time-world.sim_delta_ref) * world.sim_delta_speed; + world.sim_internal_time = world.sim_internal_ref + (vg.time-world.sim_delta_ref) * world.sim_delta_speed; else - world.sim_internal_time = vg_lerpf( world.sim_internal_time, world.sim_internal_ref + world.pause_offset_target, vg_time_delta*15.0f ); + world.sim_internal_time = vg_lerpf( world.sim_internal_time, world.sim_internal_ref + world.pause_offset_target, vg.time_delta*15.0f ); world.sim_internal_delta = world.sim_internal_time-old_time; world.sim_target = (int)floorf(world.sim_internal_time); @@ -1966,7 +1968,9 @@ static void vg_update(void) while( world.sim_frame < world.sim_target ) { - sfx_set_playrnd( &audio_random, &audio_system_balls_switching, 0, 8 ); + audio_lock(); + audio_oneshot( &audio_random[ vg_randu32(&vg.rand) % 8 ], 1.0f, 0.0f ); + audio_unlock(); // Update splitter deltas for( int i = 0; i < world.h*world.w; i ++ ) @@ -2083,7 +2087,9 @@ static void vg_update(void) { if( fish->dir[0] == 0 ) { - sfx_set_playrnd( &audio_splitter, &audio_system_balls_important, 0, 1 ); + audio_lock(); + audio_oneshot( &audio_splitter[0], 1.0f, 0.0f ); + audio_unlock(); cell_next->state |= FLAG_FLIP_ROTATING; fish->flow_reversed = 0; @@ -2357,7 +2363,7 @@ static void vg_update(void) world.num_fishes = 0; // Reset timing reference points - world.sim_delta_ref = vg_time; + world.sim_delta_ref = vg.time; world.sim_internal_ref = 0.0f; if( world.st.buttons[ k_world_button_pause ].state ) @@ -2390,7 +2396,9 @@ static void vg_update(void) career_pass_level( world.pCmpLevel, world.score, 1 ); } - sfx_set_play( &audio_tones, &audio_system_balls_extra, 9 ); + audio_lock(); + audio_oneshot( &audio_tones[9], 1.0f, 0.0f ); + audio_unlock(); failure_this_frame = 0; success_this_frame = 0; } @@ -2415,13 +2423,17 @@ static void vg_update(void) // Sounds if( failure_this_frame ) { - sfx_set_play( &audio_tones, &audio_system_balls_extra, 0 ); + audio_lock(); + audio_oneshot( &audio_tones[0], 1.0f, 0.0f ); + audio_unlock(); } else if( success_this_frame ) { static int succes_counter = 0; - sfx_set_play( &audio_tones, &audio_system_balls_extra, 1+(succes_counter++) ); + audio_lock(); + audio_oneshot( &audio_tones[1+(succes_counter++)], 1.0f, 0.0f ); + audio_unlock(); if( succes_counter == 7 ) succes_counter = 0; @@ -2521,37 +2533,26 @@ static void render_tile( v2i pos, struct cell *ptr, v4f const regular_colour, uv[0] = ptr->config & 0x3; uv[1] = ptr->config >> 2; - glUniform4f( SHADER_UNIFORM( shader_tile_main, "uOffset" ), + shader_tile_main_uOffset( (v4f){ (float)pos[0], (float)pos[1], uv[0], uv[1] - ); + }); - if( with_glow ) - { - glUniform3fv( SHADER_UNIFORM( shader_tile_main, "uGlowA" ), - 1, ptr->glow[0] ); - glUniform3fv( SHADER_UNIFORM( shader_tile_main, "uGlowB" ), - 1, ptr->glow[1] ); + if( with_glow ){ + shader_tile_main_uGlowA( ptr->glow[0] ); + shader_tile_main_uGlowB( ptr->glow[1] ); } - else - { - glUniform3f( SHADER_UNIFORM( shader_tile_main, "uGlowA" ), - 0.0f, - 0.0f, - 0.0f ); - glUniform3f( SHADER_UNIFORM( shader_tile_main, "uGlowB" ), - 0.0f, - 0.0f, - 0.0f ); + else{ + shader_tile_main_uGlowA( (v3f){0,0,0} ); + shader_tile_main_uGlowB( (v3f){0,0,0} ); } - if( selected ) - { - glUniform4fv( SHADER_UNIFORM( shader_tile_main, "uColour" ), 1, selected_colour ); + if( selected ){ + shader_tile_main_uColour( selected_colour ); draw_mesh( 0, 2 ); - glUniform4fv( SHADER_UNIFORM( shader_tile_main, "uColour" ), 1, regular_colour ); + shader_tile_main_uColour( regular_colour ); } else draw_mesh( 0, 2 ); @@ -2586,7 +2587,7 @@ static void render_tile_block( v2i start, v2i end, v4f const regular_colour, v4f static void render_tiles( v4f const regular_colour, v4f const selected_colour, int with_glow ) { - glUniform4fv( SHADER_UNIFORM( shader_tile_main, "uColour" ), 1, regular_colour ); + shader_tile_main_uColour( regular_colour ); struct render_list { @@ -2653,7 +2654,7 @@ static int world_button_exec( struct world_button *btn, v2f texture, v3f colour, v2i click_tile = { world.tile_x, world.tile_y }; int triggered = 0; - int is_hovering = v2i_eq( click_tile, btn->position ) && !gui_want_mouse(); + int is_hovering = v2i_eq( click_tile, btn->position ); // Set up light targets before logic runs if( btn->state ) @@ -2661,15 +2662,15 @@ static int world_button_exec( struct world_button *btn, v2f texture, v3f colour, else btn->light_target = is_hovering? 0.2f: 0.0f; - if( vg_get_button( "primary" ) && is_hovering ) + if( button_press( k_srbind_primary ) && is_hovering ) btn->light_target = 1.0f; // Process click action if( is_hovering ) { - if( vg_get_button_down( "primary" ) && is_hovering ) + if( button_down( k_srbind_primary ) && is_hovering ) v2i_copy( click_tile, click_grab ); - else if( v2i_eq( click_grab, click_tile ) && vg_get_button_up( "primary" ) ) + else if( v2i_eq( click_grab, click_tile ) && button_up(k_srbind_primary)) { // Click event *status = btn->state? k_world_button_on_disable: k_world_button_on_enable; @@ -2677,7 +2678,9 @@ static int world_button_exec( struct world_button *btn, v2f texture, v3f colour, if( btn->mode == k_world_button_mode_toggle ) btn->state ^= 0x1; - sfx_set_play( &audio_clicks, &audio_system_ui, btn->state? 1:0 ); + audio_lock(); + audio_oneshot( &audio_clicks[ btn->state?1:0 ], 1.0f, 0.0f ); + audio_unlock(); triggered = 1; } } @@ -2685,18 +2688,18 @@ static int world_button_exec( struct world_button *btn, v2f texture, v3f colour, // Drawing stage v4f final_colour; - btn->light = vg_lerpf( btn->light, btn->light_target + btn->extra_light, vg_time_delta*26.0f ); + btn->light = vg_lerpf( btn->light, btn->light_target + btn->extra_light, vg.time_delta*26.0f ); v3_copy( colour, final_colour ); final_colour[3] = btn->light; - glUniform4f( SHADER_UNIFORM( shader_buttons, "uOffset" ), + shader_button_uOffset( (v4f){ btn->position[0], btn->position[1], texture[0], texture[1] - ); - glUniform4fv( SHADER_UNIFORM( shader_buttons, "uColour" ), 1, final_colour ); + }); + shader_button_uColour( final_colour ); draw_mesh( 0, 2 ); return triggered; @@ -2718,7 +2721,7 @@ static void level_selection_buttons(void) struct cmp_level *lvl = &grid->pack[ j ]; if( world.pCmpLevel == lvl ) - lvl->btn.extra_light = 0.35f + fabsf(sinf( vg_time * 2.0f )) * 0.05f; + lvl->btn.extra_light = 0.35f + fabsf(sinf( vg.time * 2.0f )) * 0.05f; else lvl->btn.extra_light = 0.2f; if( lvl->completed_score ) @@ -2741,7 +2744,7 @@ static void level_selection_buttons(void) if( switch_level_to ) { world.st.lvl_to_load = switch_level_to; - world.st.lvl_load_time = vg_time + 0.25f; + world.st.lvl_load_time = vg.time + 0.25f; world.st.world_transition = 1.0f; /* @@ -2754,19 +2757,17 @@ static void level_selection_buttons(void) } } -static void render_sprite( enum sprites_auto_combine_index id, v3f pos ) -{ +static void render_sprite( enum sprites_auto_combine_index id, v3f pos ){ struct vg_sprite *sp = &sprites_auto_combine[ id ]; - glUniform4fv( SHADER_UNIFORM( shader_sprite, "uUv" ), 1, sp->uv_xywh ); - glUniform3f( SHADER_UNIFORM( shader_sprite, "uPos" ), - pos[0], pos[1], pos[2] * world.st.world_transition ); - + shader_sprite_uUv( sp->uv_xywh ); + shader_sprite_uPos( (v3f){ pos[0], + pos[1], + pos[2] * world.st.world_transition } ); draw_mesh( 0, 2 ); } -static void vg_framebuffer_resize(int w, int h) -{ +static void _mc_vg1_framebuffer_resize(int w, int h){ glBindTexture( GL_TEXTURE_2D, world.st.colourbuffer ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL ); @@ -2780,14 +2781,13 @@ static void vg_framebuffer_resize(int w, int h) } } -void vg_render(void) -{ +static void _mc_vg1_render(void){ if( enable_bloom || enable_vignette ) glBindFramebuffer( GL_FRAMEBUFFER, world.st.framebuffer ); else glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - glViewport( 0,0, vg_window_x, vg_window_y ); + glViewport( 0,0, vg.window_x, vg.window_y ); glDisable( GL_DEPTH_TEST ); glClearColor( 0.14f, 0.14f, 0.14f, 1.0f ); @@ -2854,60 +2854,62 @@ void vg_render(void) // ======================================================================================================== use_mesh( &world.shapes ); - SHADER_USE( shader_background ); - glUniformMatrix3fv( SHADER_UNIFORM( shader_background, "uPv" ), 1, GL_FALSE, (float *)vg_pv ); + shader_background_use(); + shader_background_uPv( vg.pv ); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, world.background_data ); - glUniform1i( SHADER_UNIFORM( shader_background, "uTexMain" ), 0 ); + shader_background_uTexMain( 0 ); - glUniform3f( SHADER_UNIFORM( shader_background, "uOffset" ), -16, -16, 64 ); - glUniform1f( SHADER_UNIFORM( shader_background, "uVariance" ), 0.05f ); + shader_background_uOffset( (v3f){ -16, -16, 64 } ); + shader_background_uVariance( 0.05f ); glActiveTexture( GL_TEXTURE1 ); glBindTexture( GL_TEXTURE_2D, world.random_samples ); - glUniform1i( SHADER_UNIFORM( shader_background, "uSamplerNoise" ), 1 ); - glUniform1f( SHADER_UNIFORM( shader_background, "uVisibility" ), 1.0f ); //world.st.world_transition ); + shader_background_uSamplerNoise( 1 ); + shader_background_uVisibility( 1.0f ); draw_mesh( 0, 2 ); // TILESET BACKGROUND LAYER // ======================================================================================================== use_mesh( &world.shapes ); - SHADER_USE( shader_tile_main ); - + shader_tile_main_use(); m2x2f subtransform; m2x2_identity( subtransform ); - glUniformMatrix2fv( SHADER_UNIFORM( shader_tile_main, "uSubTransform" ), 1, GL_FALSE, (float *)subtransform ); - glUniformMatrix3fv( SHADER_UNIFORM( shader_tile_main, "uPv" ), 1, GL_FALSE, (float *)vg_pv ); - glUniform1f( SHADER_UNIFORM( shader_tile_main, "uGhost" ), 0.0f ); - glUniform1f( SHADER_UNIFORM( shader_tile_main, "uForeground" ), 0.0f ); - glUniform1f( SHADER_UNIFORM( shader_tile_main, "uVisibility" ), world.st.world_transition * 2.0f ); + shader_tile_main_uSubTransform( subtransform ); + shader_tile_main_uPv( vg.pv ); + shader_tile_main_uGhost( 0.0f ); + shader_tile_main_uForeground( 0.0f ); + shader_tile_main_uVisibility( world.st.world_transition * 2.0f ); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); // rebind textures - vg_tex2d_bind( &tex_tile_data, 0 ); - vg_tex2d_bind( theme->tex_tiles, 1 ); - vg_tex2d_bind( &tex_tile_glow, 2 ); - - glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexGlyphs" ), 0 ); - glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexWood" ), 1 ); - glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexGlow" ), 2 ); + glActiveTexture( GL_TEXTURE0 ); + glBindTexture( GL_TEXTURE_2D, tex_tile_data.name ); - glUniform3fv( SHADER_UNIFORM( shader_tile_main, "uShadowing" ), 1, theme->col_shadow ); + glActiveTexture( GL_TEXTURE1 ); + glBindTexture( GL_TEXTURE_2D, theme->tex_tiles->name ); + glActiveTexture( GL_TEXTURE2 ); + glBindTexture( GL_TEXTURE_2D, tex_tile_glow.name ); + + shader_tile_main_uTexGlyphs(0); + shader_tile_main_uTexWood(1); + shader_tile_main_uTexGlow(2); + shader_tile_main_uShadowing( theme->col_shadow ); render_tiles( colour_default, colour_default, 1 ); // MARBLES // ======================================================================================================== - SHADER_USE( shader_ball ); - glUniformMatrix3fv( SHADER_UNIFORM( shader_ball, "uPv" ), 1, GL_FALSE, (float *)vg_pv ); - - vg_tex2d_bind( &tex_ball_noise, 0 ); - glUniform1i( SHADER_UNIFORM( shader_ball, "uTexMain" ), 0 ); + shader_ball_use(); + shader_ball_uPv( vg.pv ); + glActiveTexture( GL_TEXTURE0 ); + glBindTexture( GL_TEXTURE_2D, tex_ball_noise.name ); + shader_ball_uTexMain( 0 ); if( world.st.buttons[ k_world_button_sim ].state ) { @@ -2940,23 +2942,29 @@ void vg_render(void) v4f dot_colour = { 0.0f, 0.0f, 0.0f, 1.0f }; colour_code_v3( fish->colour, dot_colour ); - glUniform3fv( SHADER_UNIFORM( shader_ball, "uColour" ), 1, dot_colour ); - glUniform3fv( SHADER_UNIFORM( shader_ball, "uOffset" ), 1, render_pos ); - glUniform2f( SHADER_UNIFORM( shader_ball, "uTexOffset" ), (float)i * 1.2334, (float)i * -0.3579f ); + shader_ball_uColour( dot_colour ); + shader_ball_uOffset( render_pos ); + shader_ball_uTexOffset( (v2f){ (f32)i*1.2334f, (f32)i*-0.3579f } ); draw_mesh( 0, 2 ); } } // TILESET FOREGROUND LAYER // ======================================================================================================== - SHADER_USE( shader_tile_main ); + shader_tile_main_use(); // Re Bind textures - vg_tex2d_bind( &tex_tile_data, 0 ); - vg_tex2d_bind( theme->tex_tiles, 1 ); - vg_tex2d_bind( &tex_tile_glow, 2 ); + + glActiveTexture( GL_TEXTURE0 ); + glBindTexture( GL_TEXTURE_2D, tex_tile_data.name ); + + glActiveTexture( GL_TEXTURE1 ); + glBindTexture( GL_TEXTURE_2D, theme->tex_tiles->name ); + + glActiveTexture( GL_TEXTURE2 ); + glBindTexture( GL_TEXTURE_2D, tex_tile_glow.name ); - glUniform1f( SHADER_UNIFORM( shader_tile_main, "uForeground" ), 1.0f ); + shader_tile_main_uForeground(1.0f); render_tiles( colour_default, colour_selected, 0 ); // Draw splitters @@ -2989,15 +2997,13 @@ void vg_render(void) 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)cmd->pos[0], - (float)cmd->pos[1] + 0.125f, + shader_tile_main_uSubTransform( subtransform ); + shader_tile_main_uOffset( (v4f){ + (f32)cmd->pos[0], + (f32)cmd->pos[1] + 0.125f, cell->state & FLAG_TARGETED? 3.0f: 2.0f, 3.0f - ); + }); draw_mesh( 0, 2 ); } } @@ -3013,10 +3019,9 @@ void vg_render(void) map_reclassify( new_begin, new_end, 0 ); m2x2_identity( subtransform ); - glUniform1f( SHADER_UNIFORM( shader_tile_main, "uGhost" ), 1.0f ); - glUniformMatrix2fv( SHADER_UNIFORM( shader_tile_main, "uSubTransform" ), 1, GL_FALSE, (float *)subtransform ); - glUniform2fv( SHADER_UNIFORM( shader_tile_main, "uMousePos" ), 1, world.tile_pos ); - + shader_tile_main_uGhost(1.0f); + shader_tile_main_uSubTransform( subtransform ); + shader_tile_main_uMousePos( world.tile_pos ); render_tile_block( new_begin, new_end, colour_default, colour_default ); world.data[ world.selected ].state ^= FLAG_CANAL; @@ -3025,11 +3030,12 @@ void vg_render(void) // BUTTONS // ======================================================================================================== - SHADER_USE( shader_buttons ); - glUniformMatrix3fv( SHADER_UNIFORM( shader_buttons, "uPv" ), 1, GL_FALSE, (float *)vg_pv ); - - vg_tex2d_bind( &tex_buttons, 0 ); - glUniform1i( SHADER_UNIFORM( shader_buttons, "uTexMain" ), 0 ); + shader_button_use(); + shader_button_uPv( vg.pv ); + + glActiveTexture(GL_TEXTURE0); + glBindTexture( GL_TEXTURE_2D, tex_buttons.name ); + shader_button_uTexMain(0); enum world_button_status stat; int world_paused = world.st.buttons[k_world_button_pause].state; @@ -3067,7 +3073,7 @@ void vg_render(void) if( world_button_exec( &world.st.buttons[k_world_button_pause], (v2f){ 1.0f, 3.0f }, btn_dark_blue, &stat )) { world.sim_internal_ref = world.sim_internal_time; - world.sim_delta_ref = vg_time; + world.sim_delta_ref = vg.time; if( stat == k_world_button_on_enable ) { @@ -3084,7 +3090,7 @@ void vg_render(void) if( !world_paused ) { - world.sim_delta_ref = vg_time; + world.sim_delta_ref = vg.time; world.sim_internal_ref = world.sim_internal_time; } } @@ -3097,15 +3103,15 @@ void vg_render(void) level_selection_buttons(); - if( vg_get_button_up( "primary" ) ) + if( button_up( k_srbind_primary ) ) world_button_exec( NULL, NULL, NULL, NULL ); // I/O ARRAYS // ======================================================================================================== //glEnable(GL_BLEND); - SHADER_USE( shader_tile_colour ); - glUniformMatrix3fv( SHADER_UNIFORM( shader_tile_colour, "uPv" ), 1, GL_FALSE, (float *)vg_pv ); + shader_tile_colour_use(); + shader_tile_colour_uPv( vg.pv ); for( int i = 0; i < arrlen( world.io ); i ++ ) { @@ -3123,13 +3129,13 @@ void vg_render(void) { colour_code_v3( cell->emit[j], dot_colour ); - glUniform3f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), + shader_tile_colour_uOffset( (v3f){ term->pos[0] + 0.25f + (float)j * 0.5f, term->pos[1] + 0.25f, 0.12f - ); + }); - glUniform4fv( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 1, dot_colour ); + shader_tile_colour_uColour( dot_colour ); draw_mesh( filled_start, filled_count ); } } @@ -3151,7 +3157,7 @@ void vg_render(void) { if( k == world.sim_run ) { - float a = fabsf(sinf( vg_time * 2.0f )) * 0.075f + 0.075f; + float a = fabsf(sinf( vg.time * 2.0f )) * 0.075f + 0.075f; v4_copy( (v4f){ 1.0f, 1.0f, 1.0f, a }, bar_colour ); } @@ -3172,20 +3178,20 @@ void vg_render(void) if( bar_draw ) { - glUniform4fv( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 1, bar_colour ); - glUniform3f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), - (float)term->pos[0], y_position - 0.1f, 1.0f ); + shader_tile_colour_uColour( bar_colour ); + shader_tile_colour_uOffset( (v3f){ + (float)term->pos[0], y_position - 0.1f, 1.0f }); draw_mesh( 2, 2 ); } for( int j = 0; j < term->runs[k].step_count; j ++ ) { - glUniform3f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), + shader_tile_colour_uOffset( (v3f){ (float)term->pos[0] + 0.2f + 0.2f * (float)j, y_position, 0.1f - ); + }); if( is_input ) { @@ -3193,7 +3199,7 @@ void vg_render(void) if( colour != -1 ) { colour_code_v3( colour, dot_colour ); - glUniform4fv( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 1, dot_colour ); + shader_tile_colour_uColour( dot_colour ); // Draw filled if tick not passed, draw empty if empty if( (world.sim_frame > j && world.sim_run >= k) || world.sim_run > k ) @@ -3209,13 +3215,12 @@ void vg_render(void) { colour_code_v3( term->runs[k].recieved[j], dot_colour ); v3_muls( dot_colour, 0.8f, dot_colour ); - glUniform4fv( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 1, dot_colour ); - + shader_tile_colour_uColour( dot_colour ); draw_mesh( filled_start, filled_count ); } colour_code_v3( term->runs[k].steps[j], dot_colour ); - glUniform4fv( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 1, dot_colour ); + shader_tile_colour_uColour( dot_colour ); draw_mesh( empty_start, empty_count ); } @@ -3225,14 +3230,14 @@ void vg_render(void) // SPRITES // ======================================================================================================== - SHADER_USE( shader_sprite ); - glUniformMatrix3fv( SHADER_UNIFORM( shader_sprite, "uPv" ), 1, GL_FALSE, (float *)vg_pv ); + shader_sprite_use(); + shader_sprite_uPv( vg.pv ); - vg_tex2d_bind( &tex_sprites, 0 ); - glUniform1i( SHADER_UNIFORM( shader_sprite, "uTexMain" ), 0 ); + glActiveTexture( GL_TEXTURE0 ); + glBindTexture( GL_TEXTURE_2D, tex_sprites.name ); + shader_sprite_uTexMain(0); - for( int i = 0; i < world.tile_special_count; i ++ ) - { + for( int i = 0; i < world.tile_special_count; i ++ ){ struct render_cmd *cmd = &world.cmd_buf_specials[i]; struct cell *cell = cmd->ptr; @@ -3271,32 +3276,40 @@ void vg_render(void) 1.0f }); - m3x3_mul( vg_pv, mvp_text, mvp_text ); + m3x3_mul( vg.pv, mvp_text, mvp_text ); + + /* FIXME */ +#if 0 ui_draw( &world.st.world_text, mvp_text ); +#endif // WIRES // ======================================================================================================== glEnable(GL_BLEND); - SHADER_USE( shader_wire ); + shader_wire_use(); glBindVertexArray( world.wire.vao ); - - glUniformMatrix3fv( SHADER_UNIFORM( shader_wire, "uPv" ), 1, GL_FALSE, (float *)vg_pv ); + shader_wire_uPv(vg.pv); v4f const wire_left_colour = { 0.9f, 0.9f, 0.9f, 1.0f }; v4f const wire_right_colour = { 0.5f, 0.5f, 0.5f, 1.0f }; v4f const wire_drag_colour = { 0.3f, 0.3f, 0.3f, 0.6f }; - glUniform1f( SHADER_UNIFORM( shader_wire, "uTime" ), world.frame_lerp ); - glUniform1f( SHADER_UNIFORM( shader_wire, "uGlow" ), 0.0f ); + shader_wire_uTime( world.frame_lerp ); + shader_wire_uGlow( 0.0f ); if( world.id_drag_from ) { - glUniform4fv( SHADER_UNIFORM( shader_wire, "uColour" ), 1, wire_drag_colour ); - glUniform1f( SHADER_UNIFORM( shader_wire, "uCurve" ), 0.4f ); - glUniform3f( SHADER_UNIFORM( shader_wire, "uStart" ), world.drag_from_co[0], world.drag_from_co[1], 0.20f*world.st.world_transition ); - glUniform3f( SHADER_UNIFORM( shader_wire, "uEnd" ), world.drag_to_co[0], world.drag_to_co[1], 0.20f*world.st.world_transition ); - glDrawElements( GL_TRIANGLES, world.wire.em, GL_UNSIGNED_SHORT, (void*)(0) ); + shader_wire_uColour( wire_drag_colour ); + shader_wire_uCurve( 0.4f ); + shader_wire_uStart( (v3f){ world.drag_from_co[0], + world.drag_from_co[1], + 0.20f*world.st.world_transition } ); + shader_wire_uEnd( (v3f){ world.drag_to_co[0], + world.drag_to_co[1], + 0.20f*world.st.world_transition } ); + glDrawElements( GL_TRIANGLES, world.wire.em, + GL_UNSIGNED_SHORT, (void*)(0) ); } // Pulling animation @@ -3339,16 +3352,22 @@ void vg_render(void) colour_code_v3( cmd->ptr->emit[j], wire_colour ); wire_colour[3] = 1.0f; - glUniform4fv( SHADER_UNIFORM( shader_wire, "uColour" ), 1, wire_colour ); + shader_wire_uColour( wire_colour ); } else - glUniform4fv( SHADER_UNIFORM( shader_wire, "uColour" ), 1, j? wire_right_colour: wire_left_colour ); - - glUniform1f( SHADER_UNIFORM( shader_wire, "uCurve" ), other_cell->state & FLAG_TRIGGERED? rp_x2 * 0.4f: 0.4f ); - glUniform1f( SHADER_UNIFORM( shader_wire, "uGlow" ), other_cell->state & FLAG_TRIGGERED? rp_xa: 0.0f ); - glUniform3f( SHADER_UNIFORM( shader_wire, "uEnd" ), startpoint[0], startpoint[1], 0.18f*world.st.world_transition ); - glUniform3f( SHADER_UNIFORM( shader_wire, "uStart" ), endpoint[0], endpoint[1], 0.18f*world.st.world_transition ); - glDrawElements( GL_TRIANGLES, world.wire.em, GL_UNSIGNED_SHORT, (void*)(0) ); + shader_wire_uColour( j? wire_right_colour: wire_left_colour ); + + shader_wire_uCurve( + other_cell->state & FLAG_TRIGGERED? rp_x2 * 0.4f: 0.4f ); + shader_wire_uGlow( + other_cell->state & FLAG_TRIGGERED? rp_xa: 0.0f ); + shader_wire_uEnd( (v3f){ + startpoint[0], startpoint[1], + 0.18f*world.st.world_transition } ); + shader_wire_uStart( (v3f){ + endpoint[0], endpoint[1], 0.18f*world.st.world_transition } ); + glDrawElements( GL_TRIANGLES, world.wire.em, + GL_UNSIGNED_SHORT, (void*)(0) ); } } } @@ -3356,7 +3375,7 @@ void vg_render(void) // WIRE ENDPOINTS // ======================================================================================================== - SHADER_USE( shader_tile_colour ); + shader_tile_colour_use(); use_mesh( &world.shapes ); for( int i = 0; i < world.tile_special_count; i ++ ) @@ -3395,18 +3414,18 @@ void vg_render(void) v3_muls( wire_colour, 0.8f, wire_colour ); wire_colour[3] = 1.0f; - glUniform4fv( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 1, wire_colour ); + shader_tile_colour_uColour( wire_colour ); } else - glUniform4fv( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 1,j?wire_right_colour: wire_left_colour ); + shader_tile_colour_uColour( + j?wire_right_colour: wire_left_colour ); - for( int i = 0; i < 2; i ++ ) - { - glUniform3f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), + for( int i = 0; i < 2; i ++ ){ + shader_tile_colour_uOffset( (v3f){ pts[i][0], pts[i][1], 0.08f * world.st.world_transition - ); + }); draw_mesh( filled_start, filled_count ); } } @@ -3437,10 +3456,10 @@ void vg_render(void) glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_ADD); - SHADER_USE( shader_sprite ); - - vg_tex2d_bind( &tex_sprites, 0 ); - glUniform1i( SHADER_UNIFORM( shader_sprite, "uTexMain" ), 0 ); + shader_sprite_use(); + glActiveTexture( GL_TEXTURE0 ); + glBindTexture( GL_TEXTURE_2D, tex_sprites.name ); + shader_sprite_uTexMain(0); for( int i = 0; i < world.tile_special_count; i ++ ) { @@ -3494,23 +3513,23 @@ void vg_render(void) /* Scale down image and remap colour values */ glViewport( 0,0, - vg_window_x/EFFECT_BUFFER_RATIO, vg_window_y/EFFECT_BUFFER_RATIO ); + vg.window_x/EFFECT_BUFFER_RATIO, vg.window_y/EFFECT_BUFFER_RATIO ); glBindFramebuffer( GL_FRAMEBUFFER, world.st.bloomframebuffer[0] ); - SHADER_USE( shader_post_darken ); + shader_post_darken_use(); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, world.st.colourbuffer ); - glUniform1i( SHADER_UNIFORM( shader_post_darken, "uTexMain" ), 0 ); + shader_post_darken_uTexMain(0); draw_mesh( 0, 2 ); /* Two pass blur */ v2f res_inv, blur_dir; - res_inv[0] = 1.0f / (float)( vg_window_x/EFFECT_BUFFER_RATIO ); - res_inv[1] = 1.0f / (float)( vg_window_y/EFFECT_BUFFER_RATIO ); + res_inv[0] = 1.0f / (float)( vg.window_x/EFFECT_BUFFER_RATIO ); + res_inv[1] = 1.0f / (float)( vg.window_y/EFFECT_BUFFER_RATIO ); - SHADER_USE( shader_post_blur ); - glUniform1i( SHADER_UNIFORM( shader_post_blur, "uTexMain" ), 0 ); + shader_post_blur_use(); + shader_post_blur_uTexMain(0); for( int i=0; i<1; i++ ) { @@ -3518,7 +3537,7 @@ void vg_render(void) v2_mul( (v2f){ 1.0f*(float)(i+1), 0.0f }, res_inv, blur_dir ); - glUniform2fv( SHADER_UNIFORM(shader_post_blur,"uDir"), 1, blur_dir ); + shader_post_blur_uDir( blur_dir ); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, world.st.bloomcolourbuffer[0] ); @@ -3527,42 +3546,44 @@ void vg_render(void) v2_mul( (v2f){ 0.0f, 1.0f*(float)(i+1) }, res_inv, blur_dir ); glBindFramebuffer( GL_FRAMEBUFFER, world.st.bloomframebuffer[0] ); - glUniform2fv( SHADER_UNIFORM(shader_post_blur,"uDir"), 1, blur_dir ); + shader_post_blur_uDir( blur_dir ); glBindTexture( GL_TEXTURE_2D, world.st.bloomcolourbuffer[1] ); draw_mesh( 0, 2 ); } /* Scene composite */ - glViewport( 0,0, vg_window_x, vg_window_y ); + glViewport( 0,0, vg.window_x, vg.window_y ); image_composite: glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - SHADER_USE( shader_post_comp ); + shader_post_comp_use(); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, world.st.colourbuffer ); - glUniform1i( SHADER_UNIFORM( shader_post_comp, "uTexMain" ), 0 ); + shader_post_comp_uTexMain(0); glActiveTexture( GL_TEXTURE1 ); glBindTexture( GL_TEXTURE_2D, world.st.bloomcolourbuffer[0] ); - glUniform1i( SHADER_UNIFORM( shader_post_comp, "uTexBloom" ), 1 ); + shader_post_comp_uTexBloom(1); - glUniform2f( SHADER_UNIFORM( shader_post_comp, "uComp" ), + shader_post_comp_uComp( (v2f){ enable_bloom? 1.0f: 0.0f, - enable_vignette? 0.0f: 1.0f ); + enable_vignette? 0.0f: 1.0f + }); draw_mesh( 0, 2 ); } -void vg_ui(void) -{ +void _mc_vg1_ui(void) { // Drawing world name +#if 0 if( world.pCmpLevel ) { - gui_text( (ui_px [2]){ vg_window_x / 2, 4 }, world.pCmpLevel->title, 2, k_text_align_center ); - gui_text( (ui_px [2]){ vg_window_x / 2, 28 }, world.pCmpLevel->description, 1, k_text_align_center ); + gui_text( (ui_px [2]){ vg.window_x / 2, 4 }, world.pCmpLevel->title, 2, k_text_align_center ); + gui_text( (ui_px [2]){ vg.window_x / 2, 28 }, world.pCmpLevel->description, 1, k_text_align_center ); } +#endif #if 0 if( world.st.state == k_game_state_update ) @@ -3571,8 +3592,8 @@ void vg_ui(void) ui_global_ctx.cursor[2] = 458; ui_global_ctx.cursor[3] = 316; - ui_global_ctx.cursor[0] = vg_window_x / 2 - 229; - ui_global_ctx.cursor[1] = vg_window_y / 2 - 158; + ui_global_ctx.cursor[0] = vg.window_x / 2 - 229; + ui_global_ctx.cursor[1] = vg.window_y / 2 - 158; gui_new_node(); { @@ -3621,6 +3642,8 @@ void vg_ui(void) } else #endif + +#if 0 if( world.st.state == k_game_state_settings ) { gui_group_id( 35 ); @@ -3845,112 +3868,8 @@ void vg_ui(void) } gui_end(); } -} - -#if STEAM_LEADERBOARDS -void leaderboard_dispatch_score(void) -{ - - sw_upload_leaderboard_score( - ui_data.upload_request.level->steam_leaderboard, - k_ELeaderboardUploadScoreMethodKeepBest, - ui_data.upload_request.score, - NULL, - 0 - ); - - ui_data.upload_request.is_waiting = 0; - - vg_success( "Dispatched leaderboard score\n" ); -} - -void leaderboard_found( LeaderboardFindResult_t *pCallback ) -{ - if( !pCallback->m_bLeaderboardFound ) - { - vg_error( "Leaderboard could not be found\n" ); - ui_data.steam_leaderboard = 0; - } - else - { - const char *recieved_name = sw_get_leaderboard_name( pCallback->m_hSteamLeaderboard ); - - // Update UI state and request entries if this callback found the current UI level - if( ui_data.level_selected ) - { - if( !strcmp( recieved_name, ui_data.level_selected->map_name ) ) - { - sw_download_leaderboard_entries( pCallback->m_hSteamLeaderboard, k_ELeaderboardDataRequestFriends, 0, 8 ); - ui_data.level_selected->steam_leaderboard = pCallback->m_hSteamLeaderboard; - } - } - - // Dispatch the waiting request if there was one - if( ui_data.upload_request.is_waiting ) - { - if( !strcmp( recieved_name, ui_data.upload_request.level->map_name ) ) - { - ui_data.upload_request.level->steam_leaderboard = pCallback->m_hSteamLeaderboard; - leaderboard_dispatch_score(); - } - } - } -} - -void leaderboard_downloaded( LeaderboardScoresDownloaded_t *pCallback ) -{ - // Update UI if this leaderboard matches what we currently have in view - if( ui_data.level_selected->steam_leaderboard == pCallback->m_hSteamLeaderboard ) - { - vg_info( "Recieved %d entries\n", pCallback->m_cEntryCount ); - ui_data.leaderboard_count = VG_MIN( pCallback->m_cEntryCount, 8 ); - - u64_steamid local_player = sw_get_steamid(); - - for( int i = 0; i < ui_data.leaderboard_count; i ++ ) - { - LeaderboardEntry_t entry; - sw_get_downloaded_entry( pCallback->m_hSteamLeaderboardEntries, i, &entry, NULL, 0 ); - - struct leaderboard_player *player = &ui_data.leaderboard_players[i]; - - player->id = entry.m_steamIDUser.m_unAll64Bits; - strncpy( player->player_name, sw_get_friend_persona_name( player->id ), vg_list_size( player->player_name )-1 ); - player->score = entry.m_nScore; - - snprintf( player->score_text, vg_list_size(player->score_text), "%d", player->score ); - player->texture = sw_get_player_image( player->id ); - - if( player->texture == 0 ) - player->texture = tex_unkown.name; - - player->is_local_player = local_player == player->id? 1: 0; - } - - if( ui_data.leaderboard_count ) - ui_data.leaderboard_show = 1; - else - ui_data.leaderboard_show = 0; - } - else vg_warn( "Downloaded leaderboard does not match requested!\n" ); -} - -void leaderboard_set_score( struct cmp_level *cmp_level, u32 score ) -{ - if( ui_data.upload_request.is_waiting ) - vg_warn( "You are uploading leaderboard entries too quickly!\n" ); - - ui_data.upload_request.level = cmp_level; - ui_data.upload_request.score = score; - ui_data.upload_request.is_waiting = 1; - - // If leaderboard ID has been downloaded already then just immediately dispatch this - if( cmp_level->steam_leaderboard ) - leaderboard_dispatch_score(); - else - sw_find_leaderboard( cmp_level->map_name ); -} #endif +} // CONSOLE COMMANDS // =========================================================================================================== @@ -4006,7 +3925,8 @@ static int console_load_map( int argc, char const *argv[] ) strcat( map_path, argv[0] ); strcat( map_path, ".map" ); - char *text_source = vg_textasset_read( map_path ); + u32 sz; + char *text_source = vg_file_read_text( NULL, map_path, &sz ); if( !text_source ) { @@ -4014,7 +3934,7 @@ static int console_load_map( int argc, char const *argv[] ) strcat( map_path, argv[0] ); strcat( map_path, ".map" ); - text_source = vg_textasset_read( map_path ); + text_source = vg_file_read_text( NULL, map_path, &sz ); } if( text_source ) @@ -4072,14 +3992,14 @@ static int console_changelevel( int argc, char const *argv[] ) #define TRANSFORM_TRI_2D( S, OX, OY, X1, Y1, X2, Y2, X3, Y3 ) \ X1*S+OX, Y1*S+OY, X2*S+OX, Y2*S+OY, X3*S+OX, Y3*S+OY -void vg_start(void) -{ +void _mc_vg1_start(void){ // Steamworks callbacks #ifdef STEAM_LEADERBOARDS sw_leaderboard_found = &leaderboard_found; sw_leaderboard_downloaded = &leaderboard_downloaded; #endif +#if 0 vg_function_push( (struct vg_cmd){ .name = "_map_write", .function = console_save_map @@ -4143,6 +4063,7 @@ void vg_start(void) .persistent = 1, .update = music_volume_update }); +#endif // Combined quad, long quad / empty circle / filled circle mesh { @@ -4229,8 +4150,6 @@ void vg_start(void) glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(float), (void*)0 ); glEnableVertexAttribArray( 0 ); - VG_CHECK_GL(); - mw->em = vg_list_size( wire_indices ); } @@ -4239,7 +4158,8 @@ void vg_start(void) glGenTextures( 1, &world.background_data ); glBindTexture( GL_TEXTURE_2D, world.background_data ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); - vg_tex2d_nearest(); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); } // Create random smaples texture @@ -4251,18 +4171,21 @@ void vg_start(void) glGenTextures( 1, &world.random_samples ); glBindTexture( GL_TEXTURE_2D, world.random_samples ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RG, 512, 512, 0, GL_RG, GL_UNSIGNED_BYTE, data ); - vg_tex2d_nearest(); - vg_tex2d_repeat(); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); free( data ); } - - resource_load_main(); // Init world text + /* FIXME */ +#if 0 { ui_init_context( &world.st.world_text, 15000 ); } +#endif // Restore gamestate career_local_data_init(); @@ -4274,7 +4197,7 @@ void vg_start(void) glGenTextures( 1, &world.st.colourbuffer ); glBindTexture( GL_TEXTURE_2D, world.st.colourbuffer ); - glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vg_window_x, vg_window_y, + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vg.window_x, vg.window_y, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); @@ -4292,9 +4215,10 @@ void vg_start(void) glBindTexture( GL_TEXTURE_2D, world.st.bloomcolourbuffer[i] ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, - vg_window_x/EFFECT_BUFFER_RATIO, vg_window_y/EFFECT_BUFFER_RATIO, + vg.window_x/EFFECT_BUFFER_RATIO, vg.window_y/EFFECT_BUFFER_RATIO, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); - vg_tex2d_clamp(); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); @@ -4303,6 +4227,7 @@ void vg_start(void) } } +/* FIXME: run this at vg exit */ void vg_free(void) { #ifdef VG_STEAM @@ -4311,25 +4236,4 @@ void vg_free(void) console_save_map( 0, NULL ); career_serialize(); - - resource_free_main(); - - glDeleteTextures( 1, &world.background_data ); - glDeleteTextures( 1, &world.random_samples ); - - glDeleteVertexArrays( 1, &world.wire.vao ); - glDeleteBuffers( 1, &world.wire.vbo ); - glDeleteBuffers( 1, &world.wire.ebo ); - - free_mesh( &world.shapes ); - - ui_context_free( &world.st.world_text ); - - map_free(); -} - -int main( int argc, char *argv[] ) -{ - vg_init( argc, argv, "Marble Computing" ); - return 0; } diff --git a/input.h b/input.h new file mode 100644 index 0000000..787a61b --- /dev/null +++ b/input.h @@ -0,0 +1,179 @@ +#ifndef INPUT_H +#define INPUT_H + +#define VG_GAME +#include "vg/vg.h" +#include "vg/vg_platform.h" +#include "vg/vg_console.h" +#include "vg/vg_input.h" +#include "vg/vg_m.h" + +enum sr_bind{ + k_srbind_primary = 0, + k_srbind_secondary, + k_srbind_tertiary, + k_srbind_go, + k_srbind_max, +}; + +enum sr_joystick{ + k_srjoystick_max +}; + +enum sr_axis{ + k_sraxis_max +}; + + +#define INPUT_BASIC( KB, JS ) \ + (vg_input_op[]){vg_keyboard, KB, vg_joy_button, JS, vg_end} + +static vg_input_op *input_button_list[] = { +[k_srbind_primary] = (vg_input_op[]){ + vg_mouse, SDL_BUTTON_LEFT, vg_end +}, +[k_srbind_secondary] = (vg_input_op[]){ + vg_mouse, SDL_BUTTON_RIGHT, vg_end +}, +[k_srbind_tertiary] = (vg_input_op[]){ + vg_mouse, SDL_BUTTON_MIDDLE, vg_end +}, +[k_srbind_go] = (vg_input_op[]){ + vg_keyboard, SDLK_SPACE, vg_end +}, +[k_srbind_max]=NULL +}; + +static vg_input_op *input_axis_list[] = { +[k_sraxis_max]=NULL +}; + +static vg_input_op *input_joy_list[] = { +[k_srjoystick_max]=NULL +}; + +struct { + float axis_states[ k_sraxis_max ][2]; + v2f joystick_states[ k_srjoystick_max ][2]; + u8 button_states[ k_srbind_max ][2]; + + enum input_state { + k_input_state_enabled, + k_input_state_resume, + k_input_state_resuming, + k_input_state_pause + } + state; +} +static srinput; + +static int input_filter_generic(void){ + if( (srinput.state != k_input_state_enabled) || vg_console.enabled ) + return 1; + else + return 0; +} + +static int buttons_filter_fixed(void){ + if( input_filter_generic() ) + return 1; + + if( vg.engine_stage == k_engine_stage_update_fixed ) + if( vg.fixed_iterations > 0 ) + return 1; + + return 0; +} + +/* Rising edge of button */ +static int button_down( enum sr_bind button ){ + if( buttons_filter_fixed() ) return 0; + + if( srinput.button_states[ button ][0] && + !srinput.button_states[ button ][1] ) + return 1; + else + return 0; +} + +/* Falling edge of button */ +static int button_up( enum sr_bind button ){ + if( buttons_filter_fixed() ) return 0; + + if( !srinput.button_states[ button ][0] && + srinput.button_states[ button ][1] ) + return 1; + else + return 0; +} + +/* State of button */ +static int button_press( enum sr_bind button ){ + if( input_filter_generic() ) + return 0; + return + srinput.button_states[ button ][0]; +} + +static void joystick_state( enum sr_joystick joystick, v2f state ){ + if( input_filter_generic() ) + v2_zero( state ); + else + v2_copy( srinput.joystick_states[ joystick ][0], state ); +} + +static float axis_state( enum sr_axis axis ){ + if( input_filter_generic() ) + return 0.0f; + else + return srinput.axis_states[axis][0]; +} + +static void skaterift_preupdate_inputs(void){ + if( srinput.state == k_input_state_resuming ) + srinput.state = k_input_state_enabled; + + if( srinput.state == k_input_state_resume ) + srinput.state = k_input_state_resuming; + + for( u32 i=0; i