turbo chaos
[carveJwlIkooP6JGAAIwe30JlM.git] / world_load.c
index e8f545c56dff8af10b154dcb9e925d77402b87d2..e2c2bb3f3c6c783304f8e0a540713e325f4792ec 100644 (file)
@@ -68,12 +68,20 @@ static void world_instance_load_mdl( u32 instance_id, const char *path ){
    mdl_load_array( meta, &world->ent_relay,     "ent_relay",      heap );
    mdl_load_array( meta, &world->ent_cubemap,   "ent_cubemap",    heap );
    mdl_load_array( meta, &world->ent_miniworld, "ent_miniworld",  heap );
+   mdl_load_array( meta, &world->ent_prop,      "ent_prop",  heap );
 
    mdl_array_ptr infos;
    mdl_load_array( meta, &infos, "ent_worldinfo", vg_mem.scratch );
 
+   world->skybox = k_skybox_default;
    if( mdl_arrcount(&infos) ){
       world->info = *((ent_worldinfo *)mdl_arritm(&infos,0));
+
+      if( world->meta.info.version >= 104 ){
+         if( MDL_CONST_PSTREQ( &world->meta, world->info.pstr_skybox,"space")){
+            world->skybox = k_skybox_space;
+         }
+      }
    }
    else{
       world->info.pstr_author = 0;
@@ -82,7 +90,7 @@ static void world_instance_load_mdl( u32 instance_id, const char *path ){
       world->info.timezone = 0.0f;
    }
 
-   time_t seconds = time(NULL) % ((u32)k_day_length*60);
+   time_t seconds = time(NULL) % ((u32)vg_maxf(1.0f,k_day_length)*60);
    world->time  = ((f64)(seconds)/(k_day_length*60.0));
    world->time += (world->info.timezone/24.0);
 
@@ -99,7 +107,6 @@ static void world_instance_load_mdl( u32 instance_id, const char *path ){
 
    /* init player position.
     *   - this is overriden by the save state when(if) it loads */
-   v3_zero( world->player_angles );
    ent_spawn *rp = world_find_spawn_by_name( world, "start" );
    if( !rp ) rp = world_find_closest_spawn( world, (v3f){0.0f,0.0f,0.0f} );
 
@@ -130,22 +137,21 @@ struct world_load_complete_data{
 
 static void skaterift_world_load_done( void *payload, u32 size ){
    struct world_load_complete_data *data = payload;
+   world_instance *world = &world_static.instances[ data->purpose ];
 
-   /* TODO(W2): Load player position from this save file */
    vg_msg sav;
    vg_msg_init( &sav, data->save.buf, data->save.len );
 
-   world_instance *world = &world_static.instances[ data->purpose ];
+   if( data->purpose != k_world_purpose_hub ){
+      vg_msg player_frame = sav;
+      if( vg_msg_seekframe( &player_frame, "player" ) ){
+         vg_msg_getkvv3f( &player_frame, "position", world->player_co, NULL );
+      }
+   }
+
    world_entity_start( world, &sav );
    world->status = k_world_status_loaded;
    world_static.load_state = k_world_loader_none;
-
-   for( int i=0; i<k_world_max; i ++ ){
-      world_instance *wi = &world_static.instances[i];
-
-      if( wi->status == k_world_status_loaded )
-         world_entity_relink( wi );
-   }
 }
 
 struct world_load_args {
@@ -157,7 +163,6 @@ struct world_load_args {
  * Does a complete world switch using the remaining free slots
  */
 static void skaterift_world_load_thread( void *_args ){
-   /* FIXME: we need to check all threads that take args. args can dissapear! */
    struct world_load_args args = *((struct world_load_args *)_args);
 
    addon_reg *reg = args.reg;
@@ -305,8 +310,6 @@ static void skaterift_change_world_start( addon_reg *reg ){
          }
       }
 
-      world_entity_relink( &world_static.instances[k_world_purpose_hub] );
-
       world_static.instance_addons[ k_world_purpose_client ] = reg;
       network_send_item( k_netmsg_playeritem_world1 );
       relink_all_remote_player_worlds();