numerous
authorhgn <hgodden00@gmail.com>
Fri, 30 Sep 2022 22:52:37 +0000 (23:52 +0100)
committerhgn <hgodden00@gmail.com>
Fri, 30 Sep 2022 22:52:37 +0000 (23:52 +0100)
audio.h
common.h
gate.h
main.c
models_src/mp_dev.mdl
models_src/rs_gate.mdl
network.h
player.h
server.c
world.h
world_sfd.h

diff --git a/audio.h b/audio.h
index 3eeace9575098e51d1dbbdf4d5b5e29dde965710..3e4fc77b7ba9c1fdc87a094d735f61856094b77d 100644 (file)
--- a/audio.h
+++ b/audio.h
@@ -43,6 +43,22 @@ audio_clip audio_lands[] = {
    { .path = "sound/revert4.ogg", .source_mode=k_audio_source_compressed }
 };
 
+audio_clip audio_water[] = {
+   { .path = "sound/wave0.ogg", .source_mode=k_audio_source_compressed },
+   { .path = "sound/wave1.ogg", .source_mode=k_audio_source_compressed },
+   { .path = "sound/wave2.ogg", .source_mode=k_audio_source_compressed },
+   { .path = "sound/wave3.ogg", .source_mode=k_audio_source_compressed },
+   { .path = "sound/wave4.ogg", .source_mode=k_audio_source_compressed },
+   { .path = "sound/wave5.ogg", .source_mode=k_audio_source_compressed }
+};
+
+audio_clip audio_grass[] = {
+   { .path = "sound/grass0.ogg", .source_mode=k_audio_source_compressed },
+   { .path = "sound/grass1.ogg", .source_mode=k_audio_source_compressed },
+   { .path = "sound/grass2.ogg", .source_mode=k_audio_source_compressed },
+   { .path = "sound/grass3.ogg", .source_mode=k_audio_source_compressed },
+};
+
 audio_clip audio_ambience[] =
 {
    {.path="sound/town_generic.ogg", 
@@ -66,6 +82,14 @@ audio_player ambient_player =
    .name = "Ambience"
 };
 
+audio_player ambient_sprites[4] =
+{
+   { .name = "Ambient Sprites 0" },
+   { .name = "Ambient Sprites 1" },
+   { .name = "Ambient Sprites 2" },
+   { .name = "Ambient Sprites 3" },
+};
+
 audio_player audio_player0 =
 {
    .name = "Player0",
@@ -104,6 +128,10 @@ static void audio_init(void)
    audio_player_init( &audio_player3 );
    audio_player_init( &audio_player_gate );
    audio_player_init( &ambient_player );
+   audio_player_init( &ambient_sprites[0] );
+   audio_player_init( &ambient_sprites[1] );
+   audio_player_init( &ambient_sprites[2] );
+   audio_player_init( &ambient_sprites[3] );
    audio_player_init( &audio_player_extra );
 
    audio_clip_loadn( audio_board, vg_list_size(audio_board) );
@@ -114,6 +142,8 @@ static void audio_init(void)
    audio_clip_loadn( &audio_gate_ambient, 1 );
    audio_clip_loadn( audio_jumps, vg_list_size(audio_jumps) );
    audio_clip_loadn( audio_lands, vg_list_size(audio_lands) );
+   audio_clip_loadn( audio_water, vg_list_size(audio_water) );
+   audio_clip_loadn( audio_grass, vg_list_size(audio_grass) );
    audio_clip_loadn( audio_footsteps, vg_list_size(audio_footsteps) );
 
    audio_lock();
@@ -125,6 +155,10 @@ static void audio_init(void)
    audio_player_set_flags( &audio_player_gate, flags );
    audio_player_set_flags( &audio_player3, AUDIO_FLAG_LOOP );
    audio_player_set_flags( &ambient_player, AUDIO_FLAG_LOOP );
+   audio_player_set_flags( &ambient_sprites[0], AUDIO_FLAG_SPACIAL_3D );
+   audio_player_set_flags( &ambient_sprites[1], AUDIO_FLAG_SPACIAL_3D );
+   audio_player_set_flags( &ambient_sprites[2], AUDIO_FLAG_SPACIAL_3D );
+   audio_player_set_flags( &ambient_sprites[3], AUDIO_FLAG_SPACIAL_3D );
    audio_player_set_vol( &ambient_player, 1.0f );
    audio_player_set_vol( &audio_player_gate, 5.0f );
    audio_player_set_vol( &audio_player_extra, 1.0f );
@@ -207,6 +241,50 @@ static void audio_sample_occlusion( v3f origin )
    audio_occlusion_current = vg_lerpf( audio_occlusion_current, target, rate );
 }
 
+enum audio_sprite_type 
+{
+   k_audio_sprite_type_none,
+   k_audio_sprite_type_grass,
+   k_audio_sprite_type_water
+};
+
+/*
+ * Trace out a random point, near the player to try and determine water areas
+ */
+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] );
+
+   
+   if( ray_world( pos, (v3f){0.0f,-1.0f,0.0f}, &contact ) )
+   {
+      if( ray_hit_is_ramp( &contact ) )
+      {
+         vg_line( pos, contact.pos, 0xff0000ff );
+         vg_line_pt3( contact.pos, 0.3f, 0xff0000ff );
+         return k_audio_sprite_type_none;
+      }
+
+      v3_copy( contact.pos, output );
+      return k_audio_sprite_type_grass;
+   }
+
+   output[0] = pos[0];
+   output[1] = 0.0f;
+   output[2] = pos[2];
+
+   return k_audio_sprite_type_water;
+}
+
 static void audio_debug_soundscapes(void)
 {
    if( !k_audio_debug_soundscape ) return;
index 587c31b551011c3e60f2b1d100bbfdb72b20a8a3..f4239630e4c5f60081c3f460c8c82556e66ae754 100644 (file)
--- a/common.h
+++ b/common.h
@@ -47,4 +47,7 @@ static void eval_bezier_time( v3f p0, v3f p1, v3f h0, v3f h1, float t, v3f p )
    v3_muladds( p, p0, 3.0f*tt  -ttt -3.0f*t +1.0f, p );
 }
 
+/* TODO: he needs a home somewhere */
+static float *player_get_pos(void);
+
 #endif /* COMMON_H */
diff --git a/gate.h b/gate.h
index c3f922967cba1a015584019bc7ce67c138669e3d..175a8c68572faa1e63fa2927bec186a1f7f36b45 100644 (file)
--- a/gate.h
+++ b/gate.h
@@ -71,10 +71,9 @@ static void gate_fb_resize(void)
    fb_resize( &grender.fb );
 }
 
-static int render_gate( teleport_gate *gate, m4x3f camera )
+static int render_gate( teleport_gate *gate, v3f viewpos, m4x3f camera )
 {
-   v3f viewpos, viewdir, gatedir;
-   v3_copy( camera[3], viewpos );
+   v3f viewdir, gatedir;
    m3x3_mulv( camera, (v3f){0.0f,0.0f,-1.0f}, viewdir );
    m3x3_mulv( gate->to_world, (v3f){0.0f,0.0f,-1.0f}, gatedir );
 
diff --git a/main.c b/main.c
index 7495ff34d9b5368422934a50063a89a64c2d8cdc..c90a945622d62b46eb38cdaeaf22886999008343 100644 (file)
--- a/main.c
+++ b/main.c
@@ -334,7 +334,7 @@ static void render_main_game(void)
    render_water_surface( vg_pv, player.camera );
 
    vg_tex2d_bind( &tex_water, 1 ); /*TODO: ?*/
-   render_world_gates( vg_pv, player.camera );
+   render_world_gates( vg_pv, player.rb.co, player.camera );
    
    /* Copy the RGB of what we have into the background buffer */
    glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 );
index d33e7b18ef6eb6ba56ea999e626e2fa0731ad8d2..22145932b9dc48487977bf61a60bafec15cc5206 100644 (file)
Binary files a/models_src/mp_dev.mdl and b/models_src/mp_dev.mdl differ
index 9f4cddfbf267a7997f97dd72b83329735b03870d..30c54bc22b46b7f9f73310a02d0fb7d612a032b6 100644 (file)
Binary files a/models_src/rs_gate.mdl and b/models_src/rs_gate.mdl differ
index 1ffb06b8bb496d5996016adc27ff231d66e96c42..ef3455de14f77f873f8425a1e7d46405f57da949 100644 (file)
--- a/network.h
+++ b/network.h
@@ -9,7 +9,7 @@
 /* 
  * Interface
  */
-//#define SR_USE_LOCALHOST
+#define SR_USE_LOCALHOST
 
 /* Call it at start; Connects us to the gameserver */
 static void network_init(void);
@@ -38,6 +38,7 @@ static void network_submit_highscore( u32 trackid, u16 points, u16 time );
 static u8 steam_app_ticket[ 1024 ];
 static u32 steam_app_ticket_length;
 static int network_name_update = 1;
+static int network_scores_updated = 0;
 
 static HSteamNetConnection cremote;
 static ESteamNetworkingConnectionState cremote_state = 
@@ -263,6 +264,8 @@ static void on_inet_scoreboard( SteamNetworkingMessage_t *msg )
    /* We dont need to stay on the server currently */
    SteamAPI_ISteamNetworkingSockets_CloseConnection(
          hSteamNetworkingSockets, cremote, 0, NULL, 1 );
+
+   network_scores_updated = 1;
 }
 
 static void poll_connection(void)
index 97c799ee61ca7d151999b14ca0aa5a9c38b4621d..0e9be562e97b99ff8a5ec30ae3bbab32ad118b60 100644 (file)
--- a/player.h
+++ b/player.h
@@ -46,6 +46,7 @@ static struct gplayer
 
    /* TODO: eugh */
    m3x3f gate_vr_frame, gate_vr_pstep_frame;
+   int on_board_frame, in_air_frame;
 
    v3f a, v_last, m, bob, vl;
 
@@ -108,6 +109,11 @@ player =
  * Player API
  */
 
+static float *player_get_pos(void)
+{
+   return player.rb.co;
+}
+
 
 /*
  * Free camera movement
@@ -811,6 +817,19 @@ static void player_do_motion(void)
          
          world_routes_activate_gate( i );
          player.rb_gate_frame = player.rb;
+         player.in_air_frame = player.in_air;
+         player.on_board_frame = player.on_board;
+
+         if( !player.on_board )
+         {
+            v3f fwd_dir = {cosf(player.angles[0]),
+                           0.0f,
+                           sinf(player.angles[0])};
+            m3x3_mulv( gate->transport, fwd_dir, fwd_dir );
+
+            player.angles[0] = atan2f( fwd_dir[2], fwd_dir[0] );
+                                    
+         }
 
          m3x3_copy( player.vr, player.gate_vr_frame );
          m3x3_copy( player.vr_pstep, player.gate_vr_pstep_frame );
@@ -1214,6 +1233,41 @@ static void player_audio(void)
 
    /* Tunnel / occlusion */
    audio_sample_occlusion( player.camera[3] );
+
+   int sprite_avail = -1;
+   for( int i=0; i<vg_list_size(ambient_sprites); i++ )
+   {
+      if( !audio_player_is_playing( &ambient_sprites[i] ) )
+      {
+         sprite_avail = i;
+         break;
+      }
+   }
+   
+   if( sprite_avail != -1 )
+   {
+      v3f waterpos;
+      enum audio_sprite_type sprite_type = 
+         audio_sample_sprite_random( player.rb.co, waterpos );
+
+      if( sprite_type != k_audio_sprite_type_none )
+      {
+         audio_player *avail = &ambient_sprites[ sprite_avail ];
+
+         audio_player_set_vol( avail, 20.0f );
+         audio_player_set_flags( avail, AUDIO_FLAG_SPACIAL_3D );
+         audio_player_set_position( avail, waterpos );
+
+         if( sprite_type == k_audio_sprite_type_grass )
+         {
+            audio_player_playclip( avail, &audio_grass[rand()%4] );
+         }
+         else if( sprite_type == k_audio_sprite_type_water )
+         {
+            audio_player_playclip( avail, &audio_water[rand()%6] );
+         }
+      }
+   }
    
    if( freecam || player.is_dead || !player.on_board )
    {
@@ -1338,6 +1392,8 @@ static int reset_player( int argc, char const *argv[] )
    m3x3_identity( player.gate_vr_pstep_frame );
 
    player.rb_gate_frame = player.rb;
+   player.on_board_frame = player.on_board;
+   player.in_air_frame = player.in_air;
    return 1;
 }
 
@@ -1350,10 +1406,20 @@ static void player_update(void)
    if( vg_get_axis("grabl")>0.0f)
    {
       player.rb = player.rb_gate_frame;
+      player.on_board = player.on_board_frame;
+      player.in_air = player.in_air_frame;
       m3x3_copy( player.gate_vr_frame, player.vr );
       m3x3_copy( player.gate_vr_pstep_frame, player.vr_pstep );
       player.is_dead = 0;
       player.in_air = 1;
+
+
+      if( !player.on_board )
+      {
+         player.angles[0] = atan2f( -player.rb.forward[2], 
+                                    -player.rb.forward[0] );
+      }
+
       m3x3_identity( player.vr );
 
       player.mdl.shoes[0] = 1;
index 1f2863380ecf254a75f93797d110f72d39e32612..f8639965a2214e7e8495073ac3bd9760f4943c27 100644 (file)
--- a/server.c
+++ b/server.c
@@ -142,7 +142,7 @@ static void on_inet_auth( SteamNetworkingMessage_t *msg )
    }
 
    u8 decrypted[1024];
-   u32 ticket_len;
+   u32 ticket_len = 1024;
 
    int success = SteamEncryptedAppTicket_BDecryptTicket(
          auth->ticket, auth->ticket_length, decrypted,
diff --git a/world.h b/world.h
index 9d35d304be7e8c6682f73e5cdae665857cd43749..cf721e8402c097d95bcc5a5ba274acb9c43f0a5a 100644 (file)
--- a/world.h
+++ b/world.h
@@ -19,6 +19,8 @@ static int ray_world( v3f pos, v3f dir, ray_hit *hit );
 #include "world_routes.h"
 #include "world_sfd.h"
 #include "world_audio.h"
+#include "network.h"
+#include "network_msg.h"
 
 #include "shaders/terrain.h"
 #include "shaders/sky.h"
@@ -44,11 +46,6 @@ static struct gworld
    struct subworld_routes routes;
    struct subworld_sfd sfd;
 
-   /* ...
-   struct subworld_spawns system_spawns;
-   struct subworld_physics system_physics;
-   */
-
    /* Paths */
    traffic_node traffic[128];
    u32 traffic_count;
@@ -552,6 +549,41 @@ static void world_update(void)
    world_routes_update();
    world_routes_debug();
    
+   int closest = 0;
+   float min_dist = INFINITY;
+
+   for( int i=0; i<world.routes.route_count; i++ )
+   {
+      float dist = v3_dist2( world.routes.routes[i].scoreboard_transform[3],
+                              player_get_pos() );
+
+      if( dist < min_dist )
+      {
+         min_dist = dist;
+         closest = i;
+      }
+   }
+
+   if( (world.active_route_board != closest) || network_scores_updated )
+   {
+      network_scores_updated = 0;
+      world.active_route_board = closest;
+      struct subworld_sfd *sfd = subworld_sfd();
+
+      struct route *route = &world.routes.routes[closest];
+
+      u32 id = route->track_id;
+
+      if( id != 0xffffffff )
+      {
+         struct netmsg_board *local_board = &scoreboard_client_data.boards[id];
+
+         for( int i=0; i<13; i++ )
+         {
+            sfd_encode( &sfd->tester, i, &local_board->data[27*i] );
+         }
+      }
+   }
    
    sfd_update( &world.sfd.tester );
 
@@ -723,7 +755,7 @@ static void render_sky(m4x3f camera)
    glDepthMask( GL_TRUE );
 }
 
-static void render_world_gates( m4x4f projection, m4x3f camera )
+static void render_world_gates( m4x4f projection, v3f playerco, m4x3f camera )
 {
    float closest = INFINITY;
    int   id = 0;
@@ -740,7 +772,7 @@ static void render_world_gates( m4x4f projection, m4x3f camera )
       }
    }
 
-   render_gate( &world.routes.gates[id].gate, camera );
+   render_gate( &world.routes.gates[id].gate, playerco, camera );
    v3_lerp( world.render_gate_pos, 
             world.routes.gates[id].gate.co[0],
             1.0f,
index 71fee37a59acacd60417f7bd0e3bd52c321c9f00..515232cf31dc8daea63fe5c6671359f7d8a40be0 100644 (file)
@@ -216,7 +216,7 @@ static void world_sfd_init(void)
    free( mboard );
    vg_tex2d_init( (vg_tex2d *[]){ &tex_scoretext }, 1 );
 
-   sfd_new( &sfd->tester, 16, 8 );
+   sfd_new( &sfd->tester, 27, 13 );
 }
 
 static void world_sfd_register(void)