enable workshop world submissions
[carveJwlIkooP6JGAAIwe30JlM.git] / world_routes.c
index a66f93ffc00e3f3d8c97d0a9503b694850f29ad7..56e6e4b6c8bbae9dbcb50e3208a845668385366e 100644 (file)
@@ -14,6 +14,7 @@
 #include "font.h"
 #include "pointcloud.h"
 #include "gui.h"
+#include "steam.h"
 
 #include "shaders/scene_route.h"
 #include "shaders/routeui.h"
@@ -21,7 +22,7 @@
 
 VG_STATIC 
 void world_routes_local_set_record( world_instance *world, ent_route *route,
-                                    double lap_time )
+                                    f64 lap_time )
 {
    vg_success( "  NEW LAP TIME: %f\n", lap_time );
 
@@ -30,25 +31,18 @@ void world_routes_local_set_record( world_instance *world, ent_route *route,
       if( time_centiseconds > (float)0xfffe )   /* skill issue */
          return;
 
-      highscore_record temp;
-      temp.trackid  = route->official_track_id;
-      temp.datetime = time(NULL);
-      temp.playerid = 0;
-      temp.points   = 0;
-      temp.time     = time_centiseconds;
-
-#if 0
-      highscores_push_record( &temp );
-#endif
-
       struct track_info *ti = &track_infos[ route->official_track_id ];
+      highscore_record *record = &ti->record;
+      record->trackid  = route->official_track_id;
+      record->datetime = time(NULL);
+      record->playerid = 0;
+      record->points   = 0;
+      record->time     = time_centiseconds;
       ti->push = 1;
       
       if( ti->achievement_id ){
-#if 0
          steam_set_achievement( ti->achievement_id );
          steam_store_achievements();
-#endif
       }
    }
    else{
@@ -268,6 +262,57 @@ void world_routes_pointcloud_spot( world_instance *world,
    }
 }
 
+/* 
+ *    '
+ *    .
+ *    |
+ *    |
+ *   /#\
+ * -'###`-
+ */
+VG_STATIC 
+void world_routes_pointcloud_tower( world_instance *world, 
+                                    pointcloud_buffer *pcbuf, 
+                                    v3f co, f32 radius, f32 height,
+                                    u32 samples, v4f colour )
+{
+   v3f inv_ext;
+   v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext );
+   v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext );
+
+   for( u32 j=0; j<samples; j++ ){
+      if( pcbuf->count >= pcbuf->max )
+         return;
+
+      pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ];
+      
+      v3f point;
+      point[0] = vg_randf64()*2.0f-1.0f;
+      point[1] = 0.0f;
+      point[2] = vg_randf64()*2.0f-1.0f;
+      v3_normalize( point );
+      v3_muls( point, sqrtf(vg_randf64()), point );
+
+      f32 h = vg_randf64();
+      point[1] = h*h*h*height;
+      point[0] *= radius;
+      point[2] *= radius;
+
+      v3_add( point, co, point );
+      v3_sub( point, pcbuf->boundary[0], point );
+      v3_mul( point, inv_ext, point );
+
+      /* TODO....... */
+      for( u32 i=0; i<3; i++ ){
+         vert->pos[i] = (point[i]-0.5f) * 32767.0f;
+      }
+
+      for( u32 i=0; i<4; i++ ){
+         vert->colour[i] = colour[i] * 255.0f;
+      }
+   }
+}
+
 VG_STATIC 
 void world_routes_place_curve( world_instance *world, ent_route *route,
                                v4f h[3], v3f n0, v3f n2, scene_context *scene,
@@ -722,6 +767,33 @@ VG_STATIC void world_routes_surface_grid( world_instance *world,
    }
 }
 
+VG_STATIC void world_write_preview( pointcloud_buffer *pcbuf ){
+   char path_buf[4096];
+   vg_str path;
+   vg_strnull( &path, path_buf, 4096 );
+
+   if( world_loader.reg ){
+      /* Don't want to override the one we get from the workshop */
+      if( world_loader.reg->workshop_id ) return;
+
+      addon_get_content_folder( world_loader.reg, &path );
+   }
+   else{
+      vg_strcat( &path, "maps/" );
+      vg_strcat( &path, world_loader.override_name );
+   }
+
+   vg_strcat( &path, "/preview.bin" );
+
+   if( !vg_strgood( &path ) ) vg_fatal_error( "Path too long\n" );
+   FILE *fp = fopen( path_buf, "wb" );
+   if( !fp ) vg_fatal_error( "Cannot open '%s' for writing\n", path_buf );
+   
+   fwrite( pcbuf, sizeof(struct pointcloud_buffer) + 
+                  sizeof(struct pointcloud_vert)*pcbuf->count, 1, fp );
+   fclose( fp );
+}
+
 /* 
  * Create the strips of colour that run through the world along course paths
  */
@@ -804,13 +876,23 @@ VG_STATIC void world_gen_routes_generate(void)
       f64 area = 0.0;
       area = world_routes_scatter_surface_points( world, pcbuf, 16.0f );
       world_routes_surface_grid( world, pcbuf );
+
+      for( u32 i=0; i<mdl_arrcount( &world->ent_gate ); i++ ){
+         ent_gate *gate = mdl_arritm( &world->ent_gate, i );
+
+         world_routes_pointcloud_tower( world, pcbuf, gate->co[0], 
+                                        2.0f, 50.0f, 128, 
+                                        (v4f){0.2f,0.2f,0.2f,1.0f} );
+      }
+
       vg_info( "Distrubuted %u points over %fkm^2!\n", 
                 pcbuf->count, area/1e6f );
+
+      world_write_preview( pcbuf );
       vg_async_dispatch( call_pointcloud, async_pointcloud_sub );
    }
 
    vg_async_dispatch( call_scene, async_scene_upload );
-
    world_routes_clear( world );
 }