update helpers/location to 'frosted' ui
[carveJwlIkooP6JGAAIwe30JlM.git] / player_glide.c
index f7339373869924086ceb02272a80b1af9a01da89..6b5930b9c2f26bed2d4d17ad1f28d3d902303831 100644 (file)
@@ -125,7 +125,7 @@ static void calculate_lift( v3f vl, f32 aoa_bias,
    
    f32 windv2 = v3_length2(wind),
        aoa    = atan2f( v3_dot( up, wind ), v3_dot( back, wind ) ) + aoa_bias,
-       cl     = aoa / VG_PIf, /* TODO: make it a curve */
+       cl     = aoa / VG_PIf,
        L      = windv2 * cl * power;
 
    v3f lift_dir;
@@ -273,11 +273,15 @@ void player_glide_update(void)
    v2f steer;
    joystick_state( k_srjoystick_steer, steer );
 
-   if( glider_physics( steer ) ){
+   if( glider_physics( steer ) )
+   {
       vg_info( "player fell off due to glider hitting ground\n" );
       player__dead_transition( k_player_die_type_generic );
       localplayer.glider_orphan = 1;
    }
+
+   if( !world_water_player_safe( world_current_instance(), 1.0f ) )
+      return;
 }
 
 void player_glide_post_update(void)
@@ -453,32 +457,15 @@ void player_glide_bind(void)
 
    mdl_open( mdl, "models/glider.mdl", alloc );
    mdl_load_metadata_block( mdl, alloc );
-
-   vg_linear_clear( vg_mem.scratch );
-
-   u32 count = mdl_arrcount( &mdl->textures );
-   player_glide.glider_textures = 
-      vg_linear_alloc( alloc, vg_align8(sizeof(GLuint)*(count+1))); 
-   player_glide.glider_textures[0] = vg.tex_missing;
-   mdl_async_load_glmesh( mdl, &player_glide.glider_mesh, NULL );
-
-   for( u32 i=0; i<count; i ++ ){
-      vg_linear_clear( vg_mem.scratch );
-      player_glide.glider_textures[i+1] = vg.tex_missing;
-
-      mdl_texture *tex = mdl_arritm( &mdl->textures, i );
-      void *data = vg_linear_alloc( vg_mem.scratch, tex->file.pack_size );
-      mdl_fread_pack_file( mdl, &tex->file, data );
-      vg_tex2d_load_qoi_async( data, tex->file.pack_size, 
-                               VG_TEX2D_LINEAR|VG_TEX2D_CLAMP,
-                               &player_glide.glider_textures[i+1] );
-   }
+   mdl_async_full_load_std( mdl );
 
    /* load trail positions */
    mdl_array_ptr markers;
    MDL_LOAD_ARRAY( mdl, &markers, ent_marker, vg_mem.scratch );
+   mdl_close( mdl );
 
-   for( u32 i=0; i<mdl_arrcount( &markers ); i ++ ){
+   for( u32 i=0; i<mdl_arrcount( &markers ); i ++ )
+   {
       ent_marker *marker = mdl_arritm( &markers, i );
       v3_copy( marker->transform.co, 
                player_glide.trail_positions[ player_glide.trail_count ++ ] );
@@ -487,10 +474,9 @@ void player_glide_bind(void)
          break;
    }
 
-   mdl_close( mdl );
-
    /* allocate effects */
-   for( u32 i=0; i<vg_list_size(trails_glider); i ++ ){
+   for( u32 i=0; i<vg_list_size(trails_glider); i ++ )
+   {
       trail_alloc( &trails_glider[i], 200 );
    }
 }
@@ -533,13 +519,14 @@ void player_glide_transition(void)
 void render_glider_model( vg_camera *cam, world_instance *world,
                           m4x3f mmdl, enum board_shader shader )
 {
-   u32 current_tex = 0xffffffff;
+   u32 current_mat = 0xffffffff;
    glActiveTexture( GL_TEXTURE0 );
 
    mdl_context *mdl = &player_glide.glider;
-   mesh_bind( &player_glide.glider_mesh );
+   mesh_bind( &player_glide.glider.mesh );
 
-   for( u32 i=0; i<mdl_arrcount(&mdl->meshs); i ++ ){
+   for( u32 i=0; i<mdl_arrcount(&mdl->meshs); i ++ )
+   {
       mdl_mesh *mesh = mdl_arritm( &mdl->meshs, i );
 
       m4x3f mmmdl;
@@ -548,7 +535,8 @@ void render_glider_model( vg_camera *cam, world_instance *world,
 
       if( shader == k_board_shader_player )
          shader_model_board_view_uMdl( mmmdl );
-      else if( shader == k_board_shader_entity ){
+      else if( shader == k_board_shader_entity )
+      {
          m4x4f m4mmmdl;
          m4x3_expand( mmmdl, m4mmmdl );
          m4x4_mul( cam->mtx_prev.pv, m4mmmdl, m4mmmdl );
@@ -557,18 +545,31 @@ void render_glider_model( vg_camera *cam, world_instance *world,
          shader_model_entity_uPvmPrev( m4mmmdl );
       }
 
-      for( u32 j=0; j<mesh->submesh_count; j ++ ){
+      for( u32 j=0; j<mesh->submesh_count; j ++ )
+      {
          mdl_submesh *sm = mdl_arritm( &mdl->submeshs, mesh->submesh_start+j );
-         if( !sm->material_id ) {
+         if( !sm->material_id ) 
+         {
             vg_error( "Invalid material ID 0\n" );
             continue;
          }
 
-         mdl_material *mat = mdl_arritm( &mdl->materials, sm->material_id-1 );
-         if( mat->tex_diffuse != current_tex ){
-            glBindTexture( GL_TEXTURE_2D, 
-                  player_glide.glider_textures[ mat->tex_diffuse ] );
-            current_tex = mat->tex_diffuse;
+         if( sm->material_id != current_mat )
+         {
+            mdl_material *mat = mdl_arritm( &mdl->materials,sm->material_id-1 );
+            GLuint tex = vg.tex_missing;
+
+            if( mat->shader == k_shader_standard )
+            {
+               struct shader_props_standard *props = mat->props.compiled;
+
+               u32 index = props->tex_diffuse-1;
+               mdl_texture *ptex = mdl_arritm( &mdl->textures, index );
+               tex = ptex->glname;
+            }
+
+            glBindTexture( GL_TEXTURE_2D, tex );
+            current_mat = sm->material_id;
          }
 
          mdl_draw_submesh( sm );
@@ -595,8 +596,7 @@ void player_glide_render( vg_camera *cam, world_instance *world,
    shader_model_board_view_uTexMain( 0 );
    shader_model_board_view_uCamera( cam->transform[3] );
    shader_model_board_view_uPv( cam->mtx.pv );
-
-   shader_model_board_view_uDepthCompare(1);
+   shader_model_board_view_uDepthMode(1);
    depth_compare_bind(
       shader_model_board_view_uTexSceneDepth,
       shader_model_board_view_uInverseRatioDepth,