fnugz's idea
authorhgn <hgodden00@gmail.com>
Fri, 14 Apr 2023 04:56:33 +0000 (05:56 +0100)
committerhgn <hgodden00@gmail.com>
Fri, 14 Apr 2023 04:56:33 +0000 (05:56 +0100)
15 files changed:
audio.h
common.h
menu.h
player.c
player.h
player_skate.c
render.h
shaders/model_character_view.fs
shaders/model_character_view.h
shaders/scene_route.fs
shaders/scene_route.h
skaterift.c
steam.h
vehicle.h
world.h

diff --git a/audio.h b/audio.h
index d1fd1cc6277196453fcb3c8fad653457f127dc85..5eb499a0c44ce2eebfeca0f7a3daba7b0736bf3c 100644 (file)
--- 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 ){
index 4c04de762df02ce97de46eb4739527b3ab827e73..7823e1a7e122141245eeacb20e6411e8cef0c410 100644 (file)
--- 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 7a008468802d1775848fdf358c48ec8002db9a41..b69345659642f2bdf9c589fd1e37d7e64c8c5f77 100644 (file)
--- 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;
index a73122c57c5351cf5afa929b6b3ff995490fe3be..48f696a163b9240d4e227ea495d609c18f222c60 100644 (file)
--- 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; i<vg_list_size(_player_system_register); i++ ){
+      if( _player_system_register[i] )
+         _player_system_register[i]();
+   }
+
+   vg_console_reg_cmd( "respawn", localplayer_cmd_respawn, NULL );
+}
+
 PLAYER_API
 void player__debugtext( int size, const char *fmt, ... )
 {
@@ -202,7 +231,7 @@ void player__pre_update( player_instance *player )
       }
       else{
          if( player->subsystem == 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 ] )
index 38e01ad2865bf73d72b12e64e43c433b007ef3e8..aa82925502bf6e59a07b7cd6b593c78165de20d8 100644 (file)
--- 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; i<vg_list_size(_player_system_register); i++ ){
-      if( _player_system_register[i] )
-         _player_system_register[i]();
-   }
-}
-
 /* implementation */
 
 #include "player.c"
index d67d055669bd03cf9baba373b8f155ba5826600c..f1670c827e3b77245d7abe521aff152094a976a7 100644 (file)
@@ -2388,7 +2388,8 @@ begin_collision:;
 
    manifold_len += l;
 
-   debug_capsule( mtx, capsule.radius, capsule.height, VG__WHITE );
+   if( vg_lines.draw )
+      debug_capsule( mtx, capsule.radius, capsule.height, VG__WHITE );
 
    /* add limits */
    if( s->state.activity >= k_skate_activity_grind_any ){
index 64cf8f1ecaa432d8f5e2013672b064269f4df26a..b920983d7970b18b24b83faa25a4854ee988eac1 100644 (file)
--- 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 );
index 4e91e921516de0b4bfda63bc21f7b9354195f28a..afeb78d40d9095964ec9848a64064a976dccd1a6 100644 (file)
@@ -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 );
 }
index 327a7a8c79cca38beff7453a4910989fe0960a6a..f5a701dad1efa3c212edc644282a7a86e10d3e30 100644 (file)
@@ -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" );
index a4a3b133603335a07a6ecf329588e58edd548f1f..4af09071cfd886292c97043b4ab20526861a81a5 100644 (file)
@@ -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 );
 }
index 99610753c125f6599d936b537e1a0973d8ed4ace..47f59c0c4a6f167a6e3b79d95ee5d18e51bacd10 100644 (file)
@@ -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"
 ""},
 };
index df5c1479f8fd01ea8729570474f71d2c7834567b..957498ab846e48548116da849c1b380108f46548 100644 (file)
 #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; i<mdl_arrcount(&world->ent_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; i<mdl_arrcount(&world->ent_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 7bd0ab84a42bed5ae86d7695066cd306d2ef12ce..969f632aadeb0500de27fe474f72ee63efb03794 100644 (file)
--- 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
  */
 
 #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;
       }
    }
 }
index 02ceb041440a084dae3817f8a91dd9c64f3ea4ed..c2429b90ae12ec6b1c18684a295e1f8d6b273034 100644 (file)
--- 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 c782ae09d7369cd90ddb51c3b25ef774166feced..622837d778728f42a6c1eb95a6aa2b59ecd9336d 100644 (file)
--- 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; i<mdl_arrcount(&world->ent_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; i<mdl_arrcount(&world->ent_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; i<world->soundscape_count; i++ )
-   {
-      struct soundscape *s = &world->soundscapes[i];
-      s->usage_count = 0;
-
-      for( int j=0; j<s->max_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 */