switch to entity list
[carveJwlIkooP6JGAAIwe30JlM.git] / world_gen.c
index f7f8eda03658b8638b41888c33507689e65fbfd7..c31c2c2dd904955be10e8c7fde126cdfd2b2438e 100644 (file)
@@ -148,6 +148,19 @@ VG_STATIC void world_apply_procedural_foliage( scene_context *scene,
    vg_info( "%d foliage models added\n", count );
 }
 
+VG_STATIC 
+void world_unpack_submesh_dynamic( world_instance *world,
+                                   scene_context *scene, mdl_submesh *sm ){
+   if( sm->flags & k_submesh_flag_consumed ) return;
+
+   m4x3f identity;
+   m4x3_identity( identity );
+   scene_add_mdl_submesh( scene, &world->meta, sm, identity );
+
+   scene_copy_slice( scene, sm );
+   sm->flags |= k_submesh_flag_consumed;
+}
+
 /*
  * Create the main meshes for the world
  */
@@ -243,24 +256,29 @@ VG_STATIC void world_gen_generate_meshes(void)
       scene_copy_slice( &world->scene_no_collide, &surf->sm_no_collide );
    }
 
+   /* unpack traffic models.. TODO: should we just put all these submeshes in a
+    * dynamic models list? and then the actual entitities point to the 
+    * models. we only have 2 types at the moment which need dynamic models but
+    * would make sense to do this when/if we have more.
+    */
    for( u32 i=0; i<mdl_arrcount( &world->ent_traffic ); i++ ){
       ent_traffic *vehc = mdl_arritm( &world->ent_traffic, i );
 
       for( u32 j=0; j<vehc->submesh_count; j++ ){
          mdl_submesh *sm = mdl_arritm( &world->meta.submeshs, 
                                        vehc->submesh_start+j );
+         world_unpack_submesh_dynamic( world, &world->scene_no_collide, sm );
+      }
+   }
 
-         if( sm->flags & k_submesh_flag_consumed ){
-            continue;
-         }
-
-         m4x3f identity;
-         m4x3_identity( identity );
-         scene_add_mdl_submesh( &world->scene_no_collide, 
-                                &world->meta, sm, identity );
+   /* unpack challenge models */
+   for( u32 i=0; i<mdl_arrcount( &world->ent_challenge ); i++ ){
+      ent_challenge *challenge = mdl_arritm( &world->ent_challenge, i );
 
-         scene_copy_slice( &world->scene_no_collide, sm );
-         sm->flags |= k_submesh_flag_consumed;
+      for( u32 j=0; j<challenge->submesh_count; j ++ ){
+         mdl_submesh *sm = mdl_arritm( &world->meta.submeshs, 
+                                       challenge->submesh_start+j );
+         world_unpack_submesh_dynamic( world, &world->scene_no_collide, sm );
       }
    }
 
@@ -577,6 +595,19 @@ VG_STATIC void async_world_postprocess_render( void *payload, u32 _size )
    glBindBuffer( GL_UNIFORM_BUFFER, world->ubo_lighting );
    glBufferSubData( GL_UNIFORM_BUFFER, 0, 
                     sizeof(struct ub_world_lighting), &world->ub_lighting );
+
+   /* yes we are using this as the entity begin thing. FIXME */
+   world->probabilities[ k_probability_curve_constant ] = 1.0f;
+   for( u32 i=0; i<mdl_arrcount(&world->ent_audio); i++ ){
+      ent_audio *audio = mdl_arritm(&world->ent_audio,i);
+      if( audio->flags & AUDIO_FLAG_AUTO_START ){
+         ent_call call;
+         call.data = NULL;
+         call.function = k_ent_function_trigger;
+         call.id = mdl_entity_id( k_ent_audio, i );
+         entity_call( world, &call );
+      }
+   }
 }
 
 /* Loads textures from the pack file */