small compression
[carveJwlIkooP6JGAAIwe30JlM.git] / world_routes.c
index 87b21c8572504917cb21150389426b59f900f819..75ebae8af66a92afdc58d81eb1f6971d3ba89cb1 100644 (file)
 #include "pointcloud.h"
 #include "gui.h"
 #include "steam.h"
+#include "network_msg.h"
+#include "network_common.h"
 
 #include "shaders/scene_route.h"
 #include "shaders/routeui.h"
 
-#if 0
-static 
-void world_routes_local_set_record( world_instance *world, ent_route *route,
-                                    f64 lap_time )
-{
-   vg_success( "  NEW LAP TIME: %f\n", lap_time );
-
-   if( route->anon.official_track_id != 0xffffffff ){
-      double time_centiseconds = lap_time * 100.0;
-      if( time_centiseconds > (float)0xfffe )   /* skill issue */
-         return;
-
-      struct track_info *ti = &track_infos[ route->anon.official_track_id ];
-      highscore_record *record = &ti->record;
-      record->trackid  = route->anon.official_track_id;
-      record->datetime = time(NULL);
-      record->playerid = 0;
-      record->points   = 0;
-      record->time     = time_centiseconds;
-      ti->push = 1;
-      
-      if( ti->achievement_id ){
-         steam_set_achievement( ti->achievement_id );
-         steam_store_achievements();
-      }
-   }
-   else{
-      vg_warn( "There is no associated track for this record...\n" );
-   }
-}
-#endif
-
 static void world_routes_clear( world_instance *world )
 {
    for( u32 i=0; i<mdl_arrcount( &world->ent_route ); i++ ){
@@ -868,7 +838,6 @@ static void world_gen_routes_generate( u32 instance_id ){
    if( instance_id <= 1 /*world_loader.generate_point_cloud*/ ){
       f64 area = 0.0;
 
-#if VG_RELEASE
       area = world_routes_scatter_surface_points( world, pcbuf, 16.0f );
       world_routes_surface_grid( world, pcbuf );
 
@@ -879,7 +848,6 @@ static void world_gen_routes_generate( u32 instance_id ){
                                         2.0f, 50.0f, 128, 
                                         (v4f){0.2f,0.2f,0.2f,1.0f} );
       }
-#endif
 
       vg_info( "Distributed %u points over %fkm^2!\n", 
                 pcbuf->count, area/1e6f );
@@ -953,14 +921,37 @@ static void world_gen_routes_ent_init( world_instance *world ){
    world_routes_clear( world );
 }
 
+static void world_routes_recv_scoreboard( world_instance *world, 
+                                          vg_msg *body, u32 route_id,
+                                          enum request_status status ){
+   if( route_id >= mdl_arrcount( &world->ent_route ) ){
+      vg_error( "Scoreboard route_id out of range (%u)\n", route_id );
+      return;
+   }
+
+   struct leaderboard_cache *board = &world->leaderboard_cache[ route_id ];
+   board->status = status;
+
+   if( body == NULL )
+      board->data_len = 0;
+
+   if( body->max > NETWORK_LEADERBOARD_MAX_SIZE ){
+      vg_error( "Scoreboard leaderboard too big (%u>%u)\n", body->max,
+                NETWORK_LEADERBOARD_MAX_SIZE );
+      return;
+   }
+
+   memcpy( board->data, body->buf, body->max );
+   board->data_len = body->max;
+}
+
 /* 
  * -----------------------------------------------------------------------------
  *                                    Events
  * -----------------------------------------------------------------------------
  */
 
-static void world_routes_init(void)
-{
+static void world_routes_init(void){
    world_static.current_run_version = 200;
    world_static.time = 300.0;
    world_static.last_use = 0.0;
@@ -969,8 +960,7 @@ static void world_routes_init(void)
    shader_routeui_register();
 }
 
-static void world_routes_update( world_instance *world )
-{
+static void world_routes_update( world_instance *world ){
    world_static.time += vg.time_delta;
 
    for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){