entities zones
[carveJwlIkooP6JGAAIwe30JlM.git] / world_routes.h
index b43ec0ee1fe63762acd9103971002f2e70906490..f8a566c825878b534d2cef5aceef0fde9b5c27bc 100644 (file)
 #include "shaders/routeui.h"
 
 
-VG_STATIC void world_routes_local_set_record( world_instance *world,
-                                              u32 route, double lap_time )
+VG_STATIC 
+void world_routes_local_set_record( world_instance *world, ent_route *route,
+                                    double lap_time )
 {
-#if 0
    vg_success( "  NEW LAP TIME: %f\n", lap_time );
 
-   if( pr->track_id != 0xffffffff )
-   {
+   if( route->official_track_id != 0xffffffff ){
       double time_centiseconds = lap_time * 100.0;
-      if( time_centiseconds > (float)0xfffe )
+      if( time_centiseconds > (float)0xfffe )   /* skill issue */
          return;
 
       highscore_record temp;
-      temp.trackid  = pr->track_id;
+      temp.trackid  = route->official_track_id;
       temp.datetime = time(NULL);
       temp.playerid = 0;
       temp.points   = 0;
@@ -38,21 +37,17 @@ VG_STATIC void world_routes_local_set_record( world_instance *world,
 
       highscores_push_record( &temp );
 
-      struct track_info *pti = &track_infos[ pr->track_id ];
-      pti->push = 1;
+      struct track_info *ti = &track_infos[ route->official_track_id ];
+      ti->push = 1;
       
-      if( pti->achievement_id )
-      {
-         steam_set_achievement( pti->achievement_id );
+      if( ti->achievement_id ){
+         steam_set_achievement( ti->achievement_id );
          steam_store_achievements();
       }
    }
-   else
-   {
+   else{
       vg_warn( "There is no associated track for this record...\n" );
    }
-#endif
-   vg_warn( "set_record unimplemented\n" );
 }
 
 
@@ -63,10 +58,53 @@ VG_STATIC void world_routes_clear( world_instance *world )
       route->active_checkpoint = 0xffffffff;
    }
 
+   for( u32 i=0; i<mdl_arrcount( &world->ent_gate ); i++ ){
+      ent_gate *rg = mdl_arritm( &world->ent_gate, i );
+      rg->timing_version = 0;
+      rg->timing_time = 0.0;
+   }
+
    world_global.current_run_version += 4;
    world_global.last_use = 0.0;
 }
 
+VG_STATIC void world_routes_time_lap( world_instance *world, ent_route *route )
+{
+   vg_info( "------- time lap %s -------\n", 
+            mdl_pstr(&world->meta,route->pstr_name) );
+
+   double total_time = 0.0;
+   u32 last_version;
+   int validated = 1;
+
+   for( u32 i=0; i<route->checkpoints_count; i++ ){
+      u32 cpid  = route->checkpoints_start+(i+route->active_checkpoint);
+          cpid  = cpid % route->checkpoints_count;
+
+      ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, cpid );
+      ent_gate *rg = mdl_arritm( &world->ent_gate, cp->gate_index );
+                rg = mdl_arritm( &world->ent_gate, rg->target );
+
+      if( i == 0 )
+         total_time = rg->timing_time;
+      else{
+         if( last_version+1 != rg->timing_version )
+            validated = 0;
+      }
+
+      last_version = rg->timing_version;
+      vg_info( "%u %f\n", rg->timing_version, rg->timing_time );
+   }
+
+   vg_info( "%u %f\n", world_global.current_run_version, world_global.time );
+
+   if( validated && (world_global.current_run_version == last_version+1)){
+      total_time = world_global.time - total_time;
+      world_routes_local_set_record( world, route, total_time );
+   }
+   vg_info( "----------------------------\n" );
+}
+
 /*
  * When going through a gate this is called for bookkeeping purposes
  */
@@ -76,8 +114,6 @@ VG_STATIC void world_routes_activate_entry_gate( world_instance *world,
    ent_gate *dest = mdl_arritm( &world->ent_gate, rg->target );
 
    world_global.last_use = world_global.time;
-   rg->timing_version = world_global.current_run_version;
-   rg->timing_time = world_global.time;
 
    for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
       ent_route *route = mdl_arritm( &world->ent_route, i );
@@ -94,6 +130,7 @@ VG_STATIC void world_routes_activate_entry_gate( world_instance *world,
                ent_gate *gk = mdl_arritm( &world->ent_gate, cp->gate_index );
                if( gk == rg ){
                   route->active_checkpoint = k;
+                  world_routes_time_lap( world, route );
                   break;
                }
             }
@@ -101,11 +138,10 @@ VG_STATIC void world_routes_activate_entry_gate( world_instance *world,
          }
       }
    }
-   
-   world_global.current_run_version ++;
 
    dest->timing_version = world_global.current_run_version;
    dest->timing_time = world_global.time;
+
    world_global.current_run_version ++;
 }
 
@@ -160,7 +196,7 @@ VG_STATIC void world_routes_debug( world_instance *world )
 }
 
 VG_STATIC void world_routes_place_curve( world_instance *world,
-                                         v4f h[4], v3f n0, v3f n2 )
+                                         v4f h[3], v3f n0, v3f n2 )
 {
    float t;
    v3f p, pd;
@@ -386,7 +422,7 @@ VG_STATIC void world_routes_generate( world_instance *world )
    }
 
    for( u32 i=0; i<mdl_arrcount(&world->ent_route_node); i++ ){
-      ent_route_node *rn = mdl_arritm( &world->ent_route, i );
+      ent_route_node *rn = mdl_arritm( &world->ent_route_node, i );
       rn->ref_count = 0;
       rn->ref_total = 0;
    }
@@ -435,6 +471,8 @@ VG_STATIC void world_routes_generate( world_instance *world )
    }
    vg_release_thread_sync();
    vg_linear_del( world_global.generic_heap, world->scene_lines );
+
+   world_routes_clear( world );
 }
 
 /* load all routes from model header */
@@ -451,6 +489,15 @@ VG_STATIC void world_routes_ent_init( world_instance *world )
 
    for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
       ent_route *route = mdl_arritm(&world->ent_route,i);
+      mdl_transform_m4x3( &route->transform, route->board_transform );
+
+      route->official_track_id = 0xffffffff;
+      for( u32 j=0; j<vg_list_size(track_infos); j ++ ){
+         if( !strcmp(track_infos[j].name, 
+                     mdl_pstr(&world->meta,route->pstr_name))){
+            route->official_track_id = j;
+         }
+      }
 
       for( u32 j=0; j<route->checkpoints_count; j++ ){
          u32 id = route->checkpoints_start + j;
@@ -517,7 +564,8 @@ VG_STATIC void world_bind_light_index( world_instance *world,
                                        GLuint shader, GLuint location, 
                                        int slot );
 
-VG_STATIC void render_world_routes( world_instance *world, camera *cam )
+VG_STATIC void render_world_routes( world_instance *world, camera *cam, 
+                                    int layer_depth )
 {
    m4x3f identity_matrix;
    m4x3_identity( identity_matrix );
@@ -577,8 +625,9 @@ VG_STATIC void render_world_routes( world_instance *world, camera *cam )
 
          shader_model_gate_uColour( colour );
 
-         u32 next = route->checkpoints_start +
-                   (route->active_checkpoint+1) % route->checkpoints_count;
+         u32 next = route->active_checkpoint+1+layer_depth;
+             next = next % route->checkpoints_count;
+             next += route->checkpoints_start;
 
          ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, next );
          ent_gate *gate = mdl_arritm( &world->ent_gate, cp->gate_index );