From: hgn Date: Fri, 14 Apr 2023 04:56:33 +0000 (+0100) Subject: fnugz's idea X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;h=be8ea6efdbfd9c0fdad97401ed7d92041d8c8778;p=carveJwlIkooP6JGAAIwe30JlM.git fnugz's idea --- diff --git a/audio.h b/audio.h index d1fd1cc..5eb499a 100644 --- a/audio.h +++ b/audio.h @@ -170,52 +170,6 @@ enum audio_sprite_type k_audio_sprite_type_water }; -/* - * Trace out a random point, near the player to try and determine water areas - */ -VG_STATIC enum audio_sprite_type audio_sample_sprite_random( v3f origin, - v3f output ) -{ - v3f chance = { (vg_randf()-0.5f) * 30.0f, - 8.0f, - (vg_randf()-0.5f) * 30.0f }; - - v3f pos; - v3_add( chance, origin, pos ); - - ray_hit contact; - contact.dist = vg_minf( 16.0f, pos[1] ); - - world_instance *world = get_active_world(); - - if( ray_world( world, pos, (v3f){0.0f,-1.0f,0.0f}, &contact ) ){ - struct world_surface *mat = ray_hit_surface( world, &contact ); - - if( mat->info.surface_prop == k_surface_prop_grass){ - v3_copy( contact.pos, output ); - return k_audio_sprite_type_grass; - } - else{ -#if 0 - vg_line( pos, contact.pos, 0xff0000ff ); - vg_line_pt3( contact.pos, 0.3f, 0xff0000ff ); -#endif - return k_audio_sprite_type_none; - } - } - - output[0] = pos[0]; - output[1] = 0.0f; - output[2] = pos[2]; - - float dist = fabsf(output[1] - origin[1]); - - if( world->water.enabled && dist<=40.0f ) - return k_audio_sprite_type_water; - else - return k_audio_sprite_type_none; -} - VG_STATIC void audio_ambient_sprite_play( v3f co, audio_clip *clip ) { audio_lock(); @@ -243,7 +197,7 @@ VG_STATIC void audio_ambient_sprites_update( world_instance *world, v3f co ) v3f sprite_pos; enum audio_sprite_type sprite_type = - audio_sample_sprite_random( co, sprite_pos ); + world_audio_sample_sprite_random( co, sprite_pos ); if( sprite_type != k_audio_sprite_type_none ){ if( sprite_type == k_audio_sprite_type_grass ){ diff --git a/common.h b/common.h index 4c04de7..7823e1a 100644 --- a/common.h +++ b/common.h @@ -8,21 +8,7 @@ #define VG_TIMESTEP_FIXED (1.0/60.0) #define VG_3D #define VG_GAME -//#define VG_STATIC static -#define VG_STATIC -#define VG_FRAMEBUFFER_RESIZE 1 -#include "vg/vg.h" -#include "submodules/anyascii/impl/c/anyascii.c" - -enum menu_controller_type{ - k_menu_controller_type_keyboard, - k_menu_controller_type_xbox, - k_menu_controller_type_playstation, - k_menu_controller_type_steam, - k_menu_controller_type_steam_deck -}; - -VG_STATIC enum menu_controller_type menu_display_controller; +#include "vg/vg.h" #endif /* COMMON_H */ diff --git a/menu.h b/menu.h index 7a00846..b693456 100644 --- a/menu.h +++ b/menu.h @@ -110,7 +110,7 @@ VG_STATIC int menu_vis( struct menu_btn_userdata ud ) VG_STATIC int menu_controller( struct menu_btn_userdata ud ) { if( (game_menu.page & (k_menu_page_main|k_menu_page_settings)) - && (ud.i == menu_display_controller) ) + && (ud.i == steam_display_controller) ) return 1; return 0; } @@ -118,7 +118,7 @@ VG_STATIC int menu_controller( struct menu_btn_userdata ud ) VG_STATIC int menu_controller_inf( struct menu_btn_userdata ud ) { if( (game_menu.page & k_menu_page_settings) - && (ud.i == menu_display_controller) ) + && (ud.i == steam_display_controller) ) return 1; return 0; } @@ -218,16 +218,16 @@ VG_STATIC menu_buttons[] = { "res_info", menu_vis, {k_menu_page_settings}, }, -{ "ctr_xbox", menu_controller_inf, {k_menu_controller_type_xbox}}, -{ "ctr_xbox_text", menu_controller_inf, {k_menu_controller_type_xbox}}, -{ "ctr_steam", menu_controller_inf, {k_menu_controller_type_steam}}, -{ "ctr_steam_text", menu_controller_inf, {k_menu_controller_type_steam}}, -{ "ctr_deck", menu_controller_inf, {k_menu_controller_type_steam_deck}}, -{ "ctr_deck_text", menu_controller_inf, {k_menu_controller_type_steam_deck}}, -{ "ctr_ps", menu_controller_inf, {k_menu_controller_type_playstation}}, -{ "ctr_ps_text", menu_controller_inf, {k_menu_controller_type_playstation}}, -{ "ctr_kbm", menu_controller_inf, {k_menu_controller_type_keyboard}}, -{ "ctr_kbm_text", menu_controller_inf, {k_menu_controller_type_keyboard}}, +{ "ctr_xbox", menu_controller_inf, {k_steam_controller_type_xbox}}, +{ "ctr_xbox_text", menu_controller_inf, {k_steam_controller_type_xbox}}, +{ "ctr_steam", menu_controller_inf, {k_steam_controller_type_steam}}, +{ "ctr_steam_text", menu_controller_inf, {k_steam_controller_type_steam}}, +{ "ctr_deck", menu_controller_inf, {k_steam_controller_type_steam_deck}}, +{ "ctr_deck_text", menu_controller_inf, {k_steam_controller_type_steam_deck}}, +{ "ctr_ps", menu_controller_inf, {k_steam_controller_type_playstation}}, +{ "ctr_ps_text", menu_controller_inf, {k_steam_controller_type_playstation}}, +{ "ctr_kbm", menu_controller_inf, {k_steam_controller_type_keyboard}}, +{ "ctr_kbm_text", menu_controller_inf, {k_steam_controller_type_keyboard}}, { "text_paused", menu_vis, {k_menu_page_main} }, @@ -243,10 +243,9 @@ VG_STATIC int menu_get_loc( const char *loc ) return 0; } -VG_STATIC int __respawn( int argc, const char *argv[] ); VG_STATIC void menu_btn_reset( int event ) { - __respawn(0,NULL); + localplayer_cmd_respawn( 0, NULL ); cl_menu_go_away = 1; game_menu.page = 0; } @@ -641,8 +640,6 @@ VG_STATIC void menu_page_settings(void) } } -player_instance *tmp_localplayer(void); - VG_STATIC void menu_update(void) { vg_input_update( 1, &input_menu_h ); @@ -688,7 +685,7 @@ VG_STATIC void menu_update(void) /* Base */ { - player_instance *player = tmp_localplayer(); + player_instance *player = &localplayer; struct player_avatar *av = player->playeravatar; v3f center_rough; diff --git a/player.c b/player.c index a73122c..48f696a 100644 --- a/player.c +++ b/player.c @@ -5,6 +5,35 @@ #include "camera.h" #include "player_model.h" +VG_STATIC int localplayer_cmd_respawn( int argc, const char *argv[] ) +{ + ent_spawn *rp = NULL, *r; + world_instance *world = localplayer.viewable_world; + + if( argc == 1 ){ + rp = world_find_spawn_by_name( world, argv[0] ); + } + else if( argc == 0 ){ + rp = world_find_closest_spawn( world, localplayer.rb.co ); + } + + if( !rp ) + return 0; + + player__spawn( &localplayer, rp ); + return 1; +} + +VG_STATIC void player_init(void) +{ + for( u32 i=0; isubsystem == k_player_subsystem_dead ){ - __respawn( 0, NULL ); + localplayer_cmd_respawn( 0, NULL ); } else{ /* cant do that */ @@ -476,6 +505,16 @@ PLAYER_API void player__render( camera *cam, player_instance *player ) shader_model_character_view_uTexMain( 0 ); shader_model_character_view_uCamera( cam->transform[3] ); shader_model_character_view_uPv( cam->mtx.pv ); + shader_model_character_view_uTexSceneDepth( 1 ); + render_fb_bind_texture( gpipeline.fb_main, 2, 1 ); + v3f inverse; + render_fb_inverse_ratio( gpipeline.fb_main, inverse ); + inverse[2] = main_camera.farz-main_camera.nearz; + + shader_model_character_view_uInverseRatioDepth( inverse ); + render_fb_inverse_ratio( NULL, inverse ); + inverse[2] = cam->farz-cam->nearz; + shader_model_character_view_uInverseRatioMain( inverse ); world_instance *world = get_active_world(); world_link_lighting_ub( world, _shader_model_character_view.id ); @@ -530,7 +569,6 @@ PLAYER_API void player__spawn( player_instance *player, m3x3_identity( player->invbasis ); player->subsystem = k_player_subsystem_walk; - player->viewable_world = get_active_world(); player->gate_waiting = NULL; if( _player_reset[ player->subsystem ] ) diff --git a/player.h b/player.h index 38e01ad..aa82925 100644 --- a/player.h +++ b/player.h @@ -130,7 +130,8 @@ struct player_instance struct player_walk _walk; struct player_dead _dead; struct player_drive _drive; -}; +} +static localplayer; /* * Gameloop tables @@ -227,14 +228,6 @@ void( *_player_restore[] )( player_instance *player ) = NULL }; -VG_STATIC void player_init(void) -{ - for( u32 i=0; istate.activity >= k_skate_activity_grind_any ){ diff --git a/render.h b/render.h index 64cf8f1..b920983 100644 --- a/render.h +++ b/render.h @@ -112,9 +112,16 @@ framebuffers[] = .attachment = GL_COLOR_ATTACHMENT1 }, { +#if 0 "depth_stencil", k_framebuffer_attachment_type_renderbuffer, .internalformat = GL_DEPTH24_STENCIL8, +#else + "depth_stencil", k_framebuffer_attachment_type_colour, + .internalformat = GL_DEPTH24_STENCIL8, + .format = GL_DEPTH_STENCIL, + .type = GL_UNSIGNED_INT_24_8, +#endif .attachment = GL_DEPTH_STENCIL_ATTACHMENT } } @@ -188,13 +195,18 @@ VG_STATIC void render_fb_get_current_res( struct framebuffer *fb, VG_STATIC void render_fb_inverse_ratio( framebuffer *fb, v2f inverse ) { - int x, y; - render_fb_get_current_res( fb, &x, &y ); + if( fb ){ + int x, y; + render_fb_get_current_res( fb, &x, &y ); - v2f render = { fb->render_w, fb->render_h }, - original = { x, y }; + v2f render = { fb->render_w, fb->render_h }, + original = { x, y }; - v2_div( render, original, inverse ); + v2_div( render, original, inverse ); + } + else{ + v2_div( (v2f){1.0f,1.0f}, (v2f){ vg.window_x, vg.window_y }, inverse ); + } } /* @@ -374,7 +386,7 @@ VG_STATIC void render_fb_allocate_texture( struct framebuffer *fb, if( a->purpose == k_framebuffer_attachment_type_renderbuffer ){ glBindRenderbuffer( GL_RENDERBUFFER, a->id ); - glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, rx, ry ); + glRenderbufferStorage( GL_RENDERBUFFER, a->internalformat, rx, ry ); } else if( a->purpose == k_framebuffer_attachment_type_colour ){ glBindTexture( GL_TEXTURE_2D, a->id ); diff --git a/shaders/model_character_view.fs b/shaders/model_character_view.fs index 4e91e92..afeb78d 100644 --- a/shaders/model_character_view.fs +++ b/shaders/model_character_view.fs @@ -1,5 +1,8 @@ uniform sampler2D uTexMain; +uniform sampler2D uTexSceneDepth; uniform vec3 uCamera; +uniform vec3 uInverseRatioDepth; +uniform vec3 uInverseRatioMain; in vec4 aColour; in vec2 aUv; @@ -10,6 +13,12 @@ in vec3 aWorldCo; #include "common_world.glsl" #include "motion_vectors_fs.glsl" +float linear_depth( float depth, float near, float far ) +{ + float z = depth * 2.0 - 1.0; + return (2.0 * near * far) / (far + near - z * (far - near)); +} + void main() { compute_motion_vectors(); @@ -21,5 +30,19 @@ void main() float dist = distance( aWorldCo, uCamera ) - 0.08; float opacity = clamp( dist*dist, 0.0, 1.0 ); + vec2 back_coord = gl_FragCoord.xy*uInverseRatioMain.xy*uInverseRatioDepth.xy; + float back_depth = texture( uTexSceneDepth, back_coord ).r; + float front_depth = gl_FragCoord.z/gl_FragCoord.w; + + back_depth = linear_depth( back_depth, 0.1, 2100.0 ); + float diff = back_depth - front_depth; + + vec2 ssuv = gl_FragCoord.xy; + vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) ); + float dither = fract( vDither.g / 71.0 ) - 0.5; + + if( step(0.0,diff)+dither<0.3 ) + discard; + oColour = vec4( composite, opacity ); } diff --git a/shaders/model_character_view.h b/shaders/model_character_view.h index 327a7a8..f5a701d 100644 --- a/shaders/model_character_view.h +++ b/shaders/model_character_view.h @@ -75,7 +75,10 @@ static struct vg_shader _shader_model_character_view = { .orig_file = "shaders/model_character_view.fs", .static_src = "uniform sampler2D uTexMain;\n" +"uniform sampler2D uTexSceneDepth;\n" "uniform vec3 uCamera;\n" +"uniform vec3 uInverseRatioDepth;\n" +"uniform vec3 uInverseRatioMain;\n" "\n" "in vec4 aColour;\n" "in vec2 aUv;\n" @@ -385,7 +388,7 @@ static struct vg_shader _shader_model_character_view = { " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n" "}\n" "\n" -"#line 11 0 \n" +"#line 14 0 \n" "#line 1 2 \n" "const float k_motion_lerp_amount = 0.01;\n" "\n" @@ -405,7 +408,13 @@ static struct vg_shader _shader_model_character_view = { " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n" "}\n" "\n" -"#line 12 0 \n" +"#line 15 0 \n" +"\n" +"float linear_depth( float depth, float near, float far ) \n" +"{\n" +" float z = depth * 2.0 - 1.0;\n" +" return (2.0 * near * far) / (far + near - z * (far - near)); \n" +"}\n" "\n" "void main()\n" "{\n" @@ -418,7 +427,22 @@ static struct vg_shader _shader_model_character_view = { " float dist = distance( aWorldCo, uCamera ) - 0.08;\n" " float opacity = clamp( dist*dist, 0.0, 1.0 );\n" "\n" +" vec2 back_coord = gl_FragCoord.xy*uInverseRatioMain.xy*uInverseRatioDepth.xy;\n" +" float back_depth = texture( uTexSceneDepth, back_coord ).r;\n" +" float front_depth = gl_FragCoord.z/gl_FragCoord.w;\n" +"\n" +" back_depth = linear_depth( back_depth, 0.1, 2100.0 );\n" +" float diff = back_depth - front_depth;\n" +"\n" +" vec2 ssuv = gl_FragCoord.xy;\n" +" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n" +" float dither = fract( vDither.g / 71.0 ) - 0.5;\n" +"\n" +" if( step(0.0,diff)+dither<0.3 )\n" +" discard;\n" +"\n" " oColour = vec4( composite, opacity );\n" +" //oColour = vec4( vec3(back_depth), 1.0 );\n" "}\n" ""}, }; @@ -426,7 +450,10 @@ static struct vg_shader _shader_model_character_view = { static GLuint _uniform_model_character_view_uPv; static GLuint _uniform_model_character_view_uTransforms; static GLuint _uniform_model_character_view_uTexMain; +static GLuint _uniform_model_character_view_uTexSceneDepth; static GLuint _uniform_model_character_view_uCamera; +static GLuint _uniform_model_character_view_uInverseRatioDepth; +static GLuint _uniform_model_character_view_uInverseRatioMain; static GLuint _uniform_model_character_view_g_world_depth; static GLuint _uniform_model_character_view_uLightsArray; static GLuint _uniform_model_character_view_uLightsIndex; @@ -436,9 +463,18 @@ static void shader_model_character_view_uPv(m4x4f m){ static void shader_model_character_view_uTexMain(int i){ glUniform1i(_uniform_model_character_view_uTexMain,i); } +static void shader_model_character_view_uTexSceneDepth(int i){ + glUniform1i(_uniform_model_character_view_uTexSceneDepth,i); +} static void shader_model_character_view_uCamera(v3f v){ glUniform3fv(_uniform_model_character_view_uCamera,1,v); } +static void shader_model_character_view_uInverseRatioDepth(v3f v){ + glUniform3fv(_uniform_model_character_view_uInverseRatioDepth,1,v); +} +static void shader_model_character_view_uInverseRatioMain(v3f v){ + glUniform3fv(_uniform_model_character_view_uInverseRatioMain,1,v); +} static void shader_model_character_view_g_world_depth(int i){ glUniform1i(_uniform_model_character_view_g_world_depth,i); } @@ -450,7 +486,10 @@ static void shader_model_character_view_link(void){ _uniform_model_character_view_uPv = glGetUniformLocation( _shader_model_character_view.id, "uPv" ); _uniform_model_character_view_uTransforms = glGetUniformLocation( _shader_model_character_view.id, "uTransforms" ); _uniform_model_character_view_uTexMain = glGetUniformLocation( _shader_model_character_view.id, "uTexMain" ); + _uniform_model_character_view_uTexSceneDepth = glGetUniformLocation( _shader_model_character_view.id, "uTexSceneDepth" ); _uniform_model_character_view_uCamera = glGetUniformLocation( _shader_model_character_view.id, "uCamera" ); + _uniform_model_character_view_uInverseRatioDepth = glGetUniformLocation( _shader_model_character_view.id, "uInverseRatioDepth" ); + _uniform_model_character_view_uInverseRatioMain = glGetUniformLocation( _shader_model_character_view.id, "uInverseRatioMain" ); _uniform_model_character_view_g_world_depth = glGetUniformLocation( _shader_model_character_view.id, "g_world_depth" ); _uniform_model_character_view_uLightsArray = glGetUniformLocation( _shader_model_character_view.id, "uLightsArray" ); _uniform_model_character_view_uLightsIndex = glGetUniformLocation( _shader_model_character_view.id, "uLightsIndex" ); diff --git a/shaders/scene_route.fs b/shaders/scene_route.fs index a4a3b13..4af0907 100644 --- a/shaders/scene_route.fs +++ b/shaders/scene_route.fs @@ -50,6 +50,5 @@ void main() } // Lighting - vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo ); - oColour = vec4(vfrag, 1.0); + oColour = vec4( scene_compute_lighting( vfrag, qnorm, aWorldCo ), 1.0 ); } diff --git a/shaders/scene_route.h b/shaders/scene_route.h index 9961075..47f59c0 100644 --- a/shaders/scene_route.h +++ b/shaders/scene_route.h @@ -470,8 +470,7 @@ static struct vg_shader _shader_scene_route = { " }\n" "\n" " // Lighting\n" -" vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n" -" oColour = vec4(vfrag, 1.0);\n" +" oColour = vec4( scene_compute_lighting( vfrag, qnorm, aWorldCo ), 1.0 );\n" "}\n" ""}, }; diff --git a/skaterift.c b/skaterift.c index df5c147..957498a 100644 --- a/skaterift.c +++ b/skaterift.c @@ -22,16 +22,10 @@ #include "font.h" #include "player.h" -static player_instance localplayer; VG_STATIC struct player_avatar localplayer_avatar; VG_STATIC glmesh localplayer_meshes[3]; vg_tex2d localplayer_texture = { .path = "textures/ch_gradient.qoi" }; -player_instance *tmp_localplayer(void) -{ - return &localplayer; -} - #include "network.h" #include "menu.h" #include "vehicle.h" @@ -59,71 +53,14 @@ VG_STATIC void highscores_save_at_exit(void) VG_STATIC void vg_launch_opt(void) { - -} - -VG_STATIC int __kill( int argc, const char *argv[] ) -{ -#if 0 - player_use_device( &localplayer, &player_device_dead, &localplayer_dead ); -#endif - return 0; -} - -VG_STATIC int __respawn( int argc, const char *argv[] ) -{ - ent_spawn *rp = NULL, *r; - world_instance *world = get_active_world(); - - if( argc == 1 ){ - for( u32 i=0; ient_spawn); i++ ){ - r = mdl_arritm( &world->ent_spawn, i ); - if( !strcmp( mdl_pstr(&world->meta, r->pstr_name),argv[0] ) ){ - rp = r; - break; - } - } - - if( !rp ) - vg_warn( "No spawn named '%s'\n", argv[0] ); - } - - if( !rp ){ - float min_dist = INFINITY; - - for( u32 i=0; ient_spawn); i++ ){ - r = mdl_arritm( &world->ent_spawn, i ); - float d = v3_dist2( r->transform.co, localplayer.rb.co ); - - if( d < min_dist ){ - min_dist = d; - rp = r; - } - } - } - - if( !rp ){ - vg_error( "No spawn found\n" ); - - if( !mdl_arrcount(&world->ent_spawn) ) - return 0; - - rp = mdl_arritm( &world->ent_spawn, 0 ); - } - - player__spawn( &localplayer, rp ); - return 1; } VG_STATIC void vg_preload(void) { g_conf_init(); - vg_console_reg_cmd( "respawn", __respawn, NULL ); - vg_console_reg_cmd( "ded", __kill, NULL ); - vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" ); -vg_info(" 2021-2022 |\\ /| | / | | | | /| \n" ); +vg_info(" 2021-2023 |\\ /| | / | | | | /| \n" ); vg_info(" | \\ / | +-- / +----- +---' | / | \n" ); vg_info(" | \\ / | | / | | \\ | / | \n" ); vg_info(" | \\/ | | / | | \\ | / | \n" ); @@ -229,8 +166,8 @@ VG_STATIC void vg_load(void) /* 'systems' are completely loaded now */ /* load home world */ - world_load( &world_global.worlds[0], "maps/mp_gridmap.mdl" ); - //world_load( &world_global.worlds[0], "maps/mp_mtzero.mdl" ); + //world_load( &world_global.worlds[0], "maps/mp_gridmap.mdl" ); + world_load( &world_global.worlds[0], "maps/mp_mtzero.mdl" ); #if 0 world_load( &world_global.worlds[1], "maps/mp_gridmap.mdl" ); @@ -244,7 +181,8 @@ VG_STATIC void vg_load(void) VG_STATIC void vg_start(void) { - __respawn( 1, (const char *[]){ "start" } ); + localplayer.viewable_world = get_active_world(); + localplayer_cmd_respawn( 1, (const char *[]){ "start" } ); } VG_STATIC void draw_origin_axis(void) @@ -306,82 +244,19 @@ VG_STATIC void vg_update_post(void) { if( vg.is_loaded ){ player__post_update( &localplayer ); - - float inr3 = 0.57735027, - inr2 = 0.70710678118; - - v3f sample_directions[] = { - { -1.0f, 0.0f, 0.0f }, - { 1.0f, 0.0f, 0.0f }, - { 0.0f, 0.0f, 1.0f }, - { 0.0f, 0.0f, -1.0f }, - { 0.0f, 1.0f, 0.0f }, - { 0.0f, -1.0f, 0.0f }, - { -inr3, inr3, inr3 }, - { inr3, inr3, inr3 }, - { -inr3, inr3, -inr3 }, - { inr3, inr3, -inr3 }, - { -inr2, 0.0f, inr2 }, - { inr2, 0.0f, inr2 }, - { -inr2, 0.0f, -inr2 }, - { inr2, 0.0f, -inr2 }, - }; - - static int si = 0; - static float distances[16]; - - ray_hit ray; - ray.dist = 5.0f; - - v3f rc, rd, ro; - v3_copy( sample_directions[ si ], rd ); - v3_add( localplayer.rb.co, (v3f){0.0f,1.5f,0.0f}, ro ); - v3_copy( ro, rc ); - - float dist = 200.0f; - - for( int i=0; i<10; i++ ){ - if( ray_world( get_active_world(), rc, rd, &ray ) ){ - dist = (float)i*5.0f + ray.dist; - break; - } - else{ - v3_muladds( rc, rd, ray.dist, rc ); - } - } - - distances[si] = dist; - - - for( int i=0; i<14; i++ ){ - if( distances[i] != 200.0f ){ - u32 colours[] = { VG__RED, VG__BLUE, VG__GREEN, - VG__CYAN, VG__YELOW, VG__PINK, - VG__WHITE }; - u32 colour = colours[i%7]; + float dist; + int sample_index; + world_audio_sample_distances( localplayer.rb.co, &sample_index, &dist ); - v3f p1; - v3_muladds( ro, sample_directions[i], distances[i], p1 ); - vg_line( ro, p1, colour ); - vg_line_pt3( p1, 0.1f, colour ); - } - } - - si ++; - if( si >= 14 ) - si = 0; - - /* FIXME: TEMP */ audio_lock(); - vg_dsp.echo_distances[si] = dist; + vg_dsp.echo_distances[sample_index] = dist; v3f ears = { 1.0f,0.0f,0.0f }; m3x3_mulv( main_camera.transform, ears, ears ); v3_copy( ears, vg_audio.external_listener_ears ); v3_copy( main_camera.transform[3], vg_audio.external_listener_pos ); - /* TODO: this is transformed back and fourth twice. */ if( localplayer.gate_waiting ){ m4x3_mulv( localplayer.gate_waiting->transport, vg_audio.external_listener_pos, @@ -496,13 +371,16 @@ VG_STATIC void render_scene(void) render_water_texture( view_world, &main_camera, 0 ); render_fb_bind( gpipeline.fb_main, 1 ); render_water_surface( view_world, &main_camera ); +} + +VG_STATIC void render_scene_gate_subview(void) +{ + render_fb_bind( gpipeline.fb_main, 1 ); + world_instance *view_world = localplayer.viewable_world; int depth = 1; if( localplayer.gate_waiting ) depth = 0; render_world_gates( view_world, &main_camera, depth ); - - if( !cl_menu ) - render_player_transparent(); } VG_STATIC void render_main_game(void) @@ -558,12 +436,14 @@ VG_STATIC void render_main_game(void) render_scene(); if( cl_menu ) { - glClear( GL_DEPTH_BUFFER_BIT ); + //glClear( GL_DEPTH_BUFFER_BIT ); menu_render_bg(); glEnable( GL_DEPTH_TEST ); - render_player_transparent(); } + render_player_transparent(); + render_scene_gate_subview(); + present_view_with_post_processing(); if( cl_menu ) diff --git a/steam.h b/steam.h index 7bd0ab8..969f632 100644 --- a/steam.h +++ b/steam.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved + * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved * All trademarks are property of their respective owners */ @@ -14,6 +14,17 @@ #include "vg/vg_steam_http.h" #include "vg/vg_steam_friends.h" #include "vg/vg_steam_user_stats.h" +#include "submodules/anyascii/impl/c/anyascii.c" + +enum steam_controller_type{ + k_steam_controller_type_keyboard, + k_steam_controller_type_xbox, + k_steam_controller_type_playstation, + k_steam_controller_type_steam, + k_steam_controller_type_steam_deck +}; + +VG_STATIC enum steam_controller_type steam_display_controller; /* * We only want to use steamworks if building for the networked version, @@ -295,29 +306,29 @@ VG_STATIC void steam_update(void) if( type == k_ESteamInputType_SteamController ){ vg_input.controller_should_use_trackpad_look = 1; - menu_display_controller = k_menu_controller_type_steam; + steam_display_controller = k_steam_controller_type_steam; } else if( type == k_ESteamInputType_SteamDeckController ){ - menu_display_controller = k_menu_controller_type_steam_deck; + steam_display_controller = k_steam_controller_type_steam_deck; } else if( type == k_ESteamInputType_PS3Controller || type == k_ESteamInputType_PS4Controller || type == k_ESteamInputType_PS5Controller ) { - menu_display_controller = k_menu_controller_type_playstation; + steam_display_controller = k_steam_controller_type_playstation; } else if( type == k_ESteamInputType_XBox360Controller || type == k_ESteamInputType_XBoxOneController ) { - menu_display_controller = k_menu_controller_type_xbox; + steam_display_controller = k_steam_controller_type_xbox; } else{ /* currently unsupported controller */ - menu_display_controller = k_menu_controller_type_xbox; + steam_display_controller = k_steam_controller_type_xbox; } } else - menu_display_controller = k_menu_controller_type_keyboard; + steam_display_controller = k_steam_controller_type_keyboard; } } } diff --git a/vehicle.h b/vehicle.h index 02ceb04..c2429b9 100644 --- a/vehicle.h +++ b/vehicle.h @@ -236,7 +236,6 @@ VG_STATIC void vehicle_solve_friction(void) } } -player_instance *tmp_localplayer(void); VG_STATIC void vehicle_update_fixed(void) { if( !gzoomer.alive ) diff --git a/world.h b/world.h index c782ae0..622837d 100644 --- a/world.h +++ b/world.h @@ -275,6 +275,53 @@ void ray_world_get_tri( world_instance *world, ray_hit *hit, v3f tri[3] ); VG_STATIC int ray_world( world_instance *world, v3f pos, v3f dir, ray_hit *hit ); +VG_STATIC +ent_spawn *world_find_closest_spawn( world_instance *world, v3f position ) +{ + ent_spawn *rp = NULL, *r; + float min_dist = INFINITY; + + for( u32 i=0; ient_spawn); i++ ){ + r = mdl_arritm( &world->ent_spawn, i ); + float d = v3_dist2( r->transform.co, position ); + + if( d < min_dist ){ + min_dist = d; + rp = r; + } + } + + if( !rp ){ + if( mdl_arrcount(&world->ent_spawn) ){ + vg_warn( "Invalid distances to spawns.. defaulting to first one.\n" ); + return mdl_arritm( &world->ent_spawn, 0 ); + } + else{ + vg_error( "There are no spawns in the level!\n" ); + } + } + + return rp; +} + +VG_STATIC +ent_spawn *world_find_spawn_by_name( world_instance *world, const char *name ) +{ + ent_spawn *rp = NULL, *r; + for( u32 i=0; ient_spawn); i++ ){ + r = mdl_arritm( &world->ent_spawn, i ); + if( !strcmp( mdl_pstr(&world->meta, r->pstr_name), name ) ){ + rp = r; + break; + } + } + + if( !rp ) + vg_warn( "No spawn named '%s'\n", name ); + + return rp; +} + /* * Submodules */ @@ -623,29 +670,6 @@ VG_STATIC void world_update( world_instance *world, v3f pos ) } #endif - -#if 0 - - /* process soundscape transactions */ - audio_lock(); - for( int i=0; isoundscape_count; i++ ) - { - struct soundscape *s = &world->soundscapes[i]; - s->usage_count = 0; - - for( int j=0; jmax_instances; j++ ) - { - if( s->channels[j] ) - { - if( audio_channel_finished(s->channels[j]) ) - s->channels[j] = audio_relinquish_channel( s->channels[j] ); - else - s->usage_count ++; - } - } - } - audio_unlock(); -#endif } /* @@ -758,4 +782,130 @@ VG_STATIC struct world_surface *ray_hit_surface( world_instance *world, return world_tri_index_surface( world, hit->tri[0] ); } +/* + * ----------------------------------------------------------------------------- + * Audio sampling + * ----------------------------------------------------------------------------- + */ + +VG_STATIC +enum audio_sprite_type world_audio_sample_sprite_random(v3f origin, v3f output); +VG_STATIC void world_audio_sample_distances( v3f co, int *index, float *value ); + +#include "audio.h" + +/* + * Trace out a random point, near the player to try and determine water areas + */ +VG_STATIC +enum audio_sprite_type world_audio_sample_sprite_random(v3f origin, v3f output) +{ + v3f chance = { (vg_randf()-0.5f) * 30.0f, + 8.0f, + (vg_randf()-0.5f) * 30.0f }; + + v3f pos; + v3_add( chance, origin, pos ); + + ray_hit contact; + contact.dist = vg_minf( 16.0f, pos[1] ); + + world_instance *world = get_active_world(); + + if( ray_world( world, pos, (v3f){0.0f,-1.0f,0.0f}, &contact ) ){ + struct world_surface *mat = ray_hit_surface( world, &contact ); + + if( mat->info.surface_prop == k_surface_prop_grass){ + v3_copy( contact.pos, output ); + return k_audio_sprite_type_grass; + } + else{ + return k_audio_sprite_type_none; + } + } + + output[0] = pos[0]; + output[1] = 0.0f; + output[2] = pos[2]; + + float dist = fabsf(output[1] - origin[1]); + + if( world->water.enabled && dist<=40.0f ) + return k_audio_sprite_type_water; + else + return k_audio_sprite_type_none; +} + +VG_STATIC void world_audio_sample_distances( v3f co, int *index, float *value ) +{ + float inr3 = 0.57735027, + inr2 = 0.70710678118; + + v3f sample_directions[] = { + { -1.0f, 0.0f, 0.0f }, + { 1.0f, 0.0f, 0.0f }, + { 0.0f, 0.0f, 1.0f }, + { 0.0f, 0.0f, -1.0f }, + { 0.0f, 1.0f, 0.0f }, + { 0.0f, -1.0f, 0.0f }, + { -inr3, inr3, inr3 }, + { inr3, inr3, inr3 }, + { -inr3, inr3, -inr3 }, + { inr3, inr3, -inr3 }, + { -inr2, 0.0f, inr2 }, + { inr2, 0.0f, inr2 }, + { -inr2, 0.0f, -inr2 }, + { inr2, 0.0f, -inr2 }, + }; + + static int si = 0; + static float distances[16]; + + ray_hit ray; + ray.dist = 5.0f; + + v3f rc, rd, ro; + v3_copy( sample_directions[ si ], rd ); + v3_add( co, (v3f){0.0f,1.5f,0.0f}, ro ); + v3_copy( ro, rc ); + + float dist = 200.0f; + + for( int i=0; i<10; i++ ){ + if( ray_world( get_active_world(), rc, rd, &ray ) ){ + dist = (float)i*5.0f + ray.dist; + break; + } + else{ + v3_muladds( rc, rd, ray.dist, rc ); + } + } + + distances[si] = dist; + + if( vg_lines.draw ){ + for( int i=0; i<14; i++ ){ + if( distances[i] != 200.0f ){ + u32 colours[] = { VG__RED, VG__BLUE, VG__GREEN, + VG__CYAN, VG__YELOW, VG__PINK, + VG__WHITE }; + + u32 colour = colours[i%7]; + + v3f p1; + v3_muladds( ro, sample_directions[i], distances[i], p1 ); + vg_line( ro, p1, colour ); + vg_line_pt3( p1, 0.1f, colour ); + } + } + } + + *index = si; + *value = dist; + + si ++; + if( si >= 14 ) + si = 0; +} + #endif /* WORLD_H */