review save method
[carveJwlIkooP6JGAAIwe30JlM.git] / world_routes.c
index 44d055b1686409fa68015036d5993f194ce29028..26261a1ed72cc56e4658827dbf83af118e24b1c6 100644 (file)
@@ -745,22 +745,20 @@ VG_STATIC void world_routes_surface_grid( world_instance *world,
    }
 }
 
-VG_STATIC void world_write_preview( pointcloud_buffer *pcbuf ){
+VG_STATIC void world_write_preview( addon_reg *reg, pointcloud_buffer *pcbuf ){
+   if( reg->alias.workshop_id ) return;
+
+   /* 
+    * FIXME: BUG: cannot correctly handle workshop because there is a stalling
+    * call below, which deadlocks the scene upload. TODO: improve the async
+    * stack to handle out of order execution. MAYBE
+    */
+
    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->alias.workshop_id ) return;
-
-      addon_get_content_folder( world_loader.reg, &path );
-   }
-   else{
-      vg_strcat( &path, "maps/" );
-      vg_strcat( &path, world_loader.override_name );
-   }
-
+   addon_get_content_folder( reg, &path );
    vg_strcat( &path, "/preview.bin" );
 
    if( !vg_strgood( &path ) ) vg_fatal_error( "Path too long\n" );
@@ -770,14 +768,14 @@ VG_STATIC void world_write_preview( pointcloud_buffer *pcbuf ){
    fwrite( pcbuf, sizeof(struct pointcloud_buffer) + 
                   sizeof(struct pointcloud_vert)*pcbuf->count, 1, fp );
    fclose( fp );
+   vg_info( "written %s\n", path_buf );
 }
 
 /* 
  * Create the strips of colour that run through the world along course paths
  */
-VG_STATIC void world_gen_routes_generate(void)
-{
-   world_instance *world = world_loading_instance();
+VG_STATIC void world_gen_routes_generate( u32 instance_id ){
+   world_instance *world = &world_static.instances[ instance_id ];
    vg_info( "Generating route meshes\n" );
    vg_async_stall();
 
@@ -789,7 +787,7 @@ VG_STATIC void world_gen_routes_generate(void)
    vg_async_item *call_pointcloud = NULL;
    pointcloud_buffer *pcbuf = NULL;
 
-   if( world_loader.generate_point_cloud ){
+   if( instance_id <= 1 /*world_loader.generate_point_cloud*/ ){
       call_pointcloud = vg_async_alloc( 
             sizeof(pointcloud_buffer) + 
             sizeof(pointcloud_vert)*POINTCLOUD_POINTS );
@@ -850,7 +848,7 @@ VG_STATIC void world_gen_routes_generate(void)
       world_routes_gen_meshes( world, i, &world->scene_lines, pcbuf );
    }
 
-   if( world_loader.generate_point_cloud ){
+   if( instance_id <= 1 /*world_loader.generate_point_cloud*/ ){
       f64 area = 0.0;
       area = world_routes_scatter_surface_points( world, pcbuf, 16.0f );
       world_routes_surface_grid( world, pcbuf );
@@ -866,7 +864,9 @@ VG_STATIC void world_gen_routes_generate(void)
       vg_info( "Distrubuted %u points over %fkm^2!\n", 
                 pcbuf->count, area/1e6f );
 
-      world_write_preview( pcbuf );
+      world_write_preview( instance_id? world_static.addon_client:
+                                        world_static.addon_hub, 
+                                        pcbuf );
       vg_async_dispatch( call_pointcloud, async_pointcloud_sub );
    }
 
@@ -875,9 +875,7 @@ VG_STATIC void world_gen_routes_generate(void)
 }
 
 /* load all routes from model header */
-VG_STATIC void world_gen_routes_ent_init(void)
-{
-   world_instance *world = world_loading_instance();
+VG_STATIC void world_gen_routes_ent_init( world_instance *world ){
    vg_info( "Initializing routes\n" );
 
    for( u32 i=0; i<mdl_arrcount(&world->ent_gate); i++ ){