timings
authorhgn <hgodden00@gmail.com>
Sun, 26 Mar 2023 23:39:21 +0000 (00:39 +0100)
committerhgn <hgodden00@gmail.com>
Sun, 26 Mar 2023 23:39:21 +0000 (00:39 +0100)
entity.h
world_gen.h
world_info.h
world_routes.h

index 9af8e79a5a8a27adb8e61397134414b32aeaae38..3215a6933b4aaae70280bed038b12f44dac00d5a 100644 (file)
--- a/entity.h
+++ b/entity.h
@@ -82,7 +82,12 @@ struct ent_checkpoint{
 };
 
 struct ent_route{
-   mdl_transform transform;
+
+   union{
+      mdl_transform transform;
+      u32 official_track_id;
+   };
+
    u32 pstr_name;
    u16 checkpoints_start,
        checkpoints_count;
index 9aaa0f3a7168bf9bb246b5b23709e3a167ad53a8..38d2b6677ed366e43368d0c63e41927908335226 100644 (file)
@@ -885,7 +885,6 @@ VG_STATIC void world_unload( world_instance *world )
    world_global.rewind_from = 0.0;
    world_global.rewind_to = 0.0;
    world_global.last_use = 0.0;
-   world_global.current_run_version = 2;
    world_global.active_route_board = 0;
 
    /* delete textures and meshes */
index 143fb70c6cba56997e0f8f1d12ec6c3b086aebbf..012199eeea5510d93a9d743f9f47144f923ccc17 100644 (file)
@@ -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
  */
 
 #ifndef WORLD_INFO_H
 /* Purely an information header, shares common strings across client and 
  * server programs. */
 
-static struct world_info
-{
-   
-}
-world_info;
-
 static struct track_info
 {
    const char *name, 
index b43ec0ee1fe63762acd9103971002f2e70906490..2454a593c0574aae14c79ffdd68489182a23a5a8 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 ++;
 }
 
@@ -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;