large reduction, redoing things
[carveJwlIkooP6JGAAIwe30JlM.git] / world_gen.h
index 293784aa5365d496e3a375326300d2d242525de1..fdbe9e58ee54aa6ddda195cb26a2aed06028de42 100644 (file)
@@ -151,7 +151,7 @@ VG_STATIC void world_ents_allocate( world_instance *world )
 
    struct countable
    {
-      enum   classtype ct;
+      enum   classtype ct, ct1;
       void **to_allocate;
       u32    item_size;
       int    count;
@@ -160,39 +160,28 @@ VG_STATIC void world_ents_allocate( world_instance *world )
    {
       { 
          k_classtype_spawn, 
+         k_classtype_none,
          (void*)&world->spawns,       
          sizeof(struct respawn_point) 
       },
       { 
          k_classtype_audio, 
+         k_classtype_none,
          (void*)&world->audio_things, 
          sizeof(struct world_audio_thing) 
       },
-      {
-         k_classtype_trigger,
-         (void*)&world->triggers,
-         sizeof(struct trigger_zone)
-      },
-      {
-         k_classtype_logic_relay,
-         (void*)&world->logic_relays,
-         sizeof(struct logic_relay)
-      },
-      {
-         k_classtype_logic_achievement,
-         (void*)&world->logic_achievements,
-         sizeof(struct logic_achievement)
-      },
       {
          k_classtype_world_light,
+         k_classtype_none,
          (void*)&world->lights,
          sizeof(struct world_light)
       },
       {
          k_classtype_nonlocal_gate,
+         k_classtype_none,
          (void*)&world->nonlocal_gates,
          sizeof(struct nonlocal_gate)
-      }
+      },
    };
 
    for( int i=0; i<vg_list_size(entity_counts); i++ )
@@ -204,7 +193,8 @@ VG_STATIC void world_ents_allocate( world_instance *world )
       
       for( int j=0; j<vg_list_size(entity_counts); j ++ )
       {
-         if( pnode->classtype == entity_counts[j].ct )
+         if( (pnode->classtype == entity_counts[j].ct) ||
+             (pnode->classtype == entity_counts[j].ct1) )
          {
             pnode->sub_uid = entity_counts[j].count;
             entity_counts[j].count ++;
@@ -220,7 +210,14 @@ VG_STATIC void world_ents_allocate( world_instance *world )
       u32 bufsize = counter->item_size*counter->count;
       *counter->to_allocate = vg_linear_alloc( world_global.generic_heap, 
                                                bufsize );
+      memset( *counter->to_allocate, 0, bufsize );
    }
+
+   world->volume_bh = bh_create( world_global.generic_heap,
+                                  &bh_system_volumes,
+                                  world,
+                                  world->volume_count,
+                                  1 );
 }
 
 VG_STATIC void world_pct_spawn( world_instance *world, mdl_node *pnode )
@@ -255,86 +252,19 @@ VG_STATIC void world_pct_audio( world_instance *world, mdl_node *pnode )
 
    v3_copy( pnode->co, thing->pos );
    
-   if( aud->flags & AUDIO_FLAG_SPACIAL_3D )
-      thing->volume = aud->volume * pnode->s[0];
-   else
-      thing->volume = aud->volume;
+   thing->volume = aud->volume;
+   thing->range = pnode->s[0];
 
    thing->flags = aud->flags;
    thing->temp_embedded_clip.path = mdl_pstr( world->meta, aud->pstr_file );
    thing->temp_embedded_clip.flags = aud->flags;
 
    audio_clip_load( &thing->temp_embedded_clip, world_global.generic_heap );
-   thing->player.name = mdl_pstr( world->meta, pnode->pstr_name );
-   thing->player.enqued = 0;
 
    pnode->sub_uid = world->audio_things_count;
    world->audio_things_count ++;
 }
 
-VG_STATIC void world_pct_trigger( world_instance *world, mdl_node *pnode )
-{
-   struct trigger_zone *trigger = &world->triggers[ world->trigger_count ];
-   struct classtype_trigger *inf = mdl_get_entdata( world->meta, pnode );
-   
-   if( inf->target )
-   {
-      mdl_node *target_node = mdl_node_from_id( world->meta, inf->target );
-
-      trigger->target.sub_id = target_node->sub_uid;
-      trigger->target.classtype = target_node->classtype;
-   }
-   else
-   {
-      vg_warn( "Trigger with no target...\n" );
-      return;
-   }
-
-   mdl_node_transform( pnode, trigger->transform );
-   m4x3_invert_full( trigger->transform, trigger->inv_transform );
-
-   world->trigger_count ++;
-}
-
-
-VG_STATIC void world_pct_relay( world_instance *world, mdl_node *pnode )
-{
-   struct logic_relay *relay = &world->logic_relays[ world->relay_count ];
-   struct classtype_logic_relay *inf = mdl_get_entdata( world->meta, pnode );
-
-   relay->target_count = 0;
-
-   for( int i=0; i<vg_list_size(relay->targets); i++ )
-   {
-      if( inf->targets[i] )
-      {
-         struct relay_target *target = &relay->targets[relay->target_count ++];
-         mdl_node *other = mdl_node_from_id( world->meta, inf->targets[i] );
-         
-         target->classtype = other->classtype;
-         target->sub_id = other->sub_uid;
-      }
-   }
-
-   v3_copy( pnode->co, relay->pos );
-   world->relay_count ++;
-}
-
-
-VG_STATIC void world_pct_achievement( world_instance *world, mdl_node *pnode )
-{
-   struct logic_achievement *ach = 
-      &world->logic_achievements[ world->achievement_count ];
-   struct classtype_logic_achievement *inf = 
-      mdl_get_entdata( world->meta, pnode );
-
-   v3_copy( pnode->co, ach->pos );
-   ach->achievement_id = mdl_pstr( world->meta, inf->pstr_name );
-   ach->achieved = 0;
-
-   world->achievement_count ++;
-}
-
 VG_STATIC void world_pct_world_light( world_instance *world, mdl_node *pnode )
 {
    struct world_light *light = &world->lights[ world->light_count ++ ];
@@ -373,9 +303,6 @@ VG_STATIC void world_entities_process( world_instance *world )
       { k_classtype_spawn,    world_pct_spawn },
       { k_classtype_water,    world_pct_water },
       { k_classtype_audio,    world_pct_audio },
-      { k_classtype_trigger,  world_pct_trigger },
-      { k_classtype_logic_relay, world_pct_relay },
-      { k_classtype_logic_achievement, world_pct_achievement },
       { k_classtype_world_light, world_pct_world_light },
       { k_classtype_nonlocal_gate, world_pct_nonlocal_gate }
    };
@@ -396,7 +323,6 @@ VG_STATIC void world_entities_process( world_instance *world )
       }
    }
 }
-
 VG_STATIC void world_link_nonlocal_gates( int index_a, int index_b )
 {
    vg_info( "Linking non-local gates\n" );
@@ -764,17 +690,18 @@ VG_STATIC void world_post_process( world_instance *world )
    for( int i=0; i<world->audio_things_count; i++ )
    {
       struct world_audio_thing *thingy = &world->audio_things[ i ];
-      
-      audio_player_init( &thingy->player );
-      audio_player_set_flags( &thingy->player, thingy->flags );
-      audio_player_set_vol( &thingy->player, thingy->volume );
-      audio_player_set_pan( &thingy->player, 0.0f );
-
-      if( thingy->flags & AUDIO_FLAG_SPACIAL_3D )
-         audio_player_set_position( &thingy->player, thingy->pos );
 
       if( thingy->flags & AUDIO_FLAG_AUTO_START )
-         audio_player_playclip( &thingy->player, &thingy->temp_embedded_clip );
+      {
+         audio_channel *ch = 
+            audio_request_channel( &thingy->temp_embedded_clip, thingy->flags );
+
+         audio_channel_edit_volume( ch, thingy->volume, 1 );
+         audio_channel_set_spacial( ch, thingy->pos, thingy->range );
+
+         if( !(ch->flags & AUDIO_FLAG_LOOP) )
+            ch = audio_relinquish_channel( ch );
+      }
    }
    audio_unlock();
 
@@ -1020,6 +947,10 @@ VG_STATIC void world_clean( world_instance *world )
    /* clean dangling pointers */
    world->meta = NULL;
 
+   /*
+    * TODO: Theres probably a better way to do this? 
+    */
+
    world->textures = NULL;
    world->texture_count = 0;
    world->materials = NULL;
@@ -1030,7 +961,7 @@ VG_STATIC void world_clean( world_instance *world )
    world->scene_lines = NULL;
 
    world->geo_bh = NULL;
-   world->trigger_bh = NULL;
+   world->volume_bh = NULL;
    world->audio_bh = NULL;
 
    world->spawns = NULL;
@@ -1039,18 +970,12 @@ VG_STATIC void world_clean( world_instance *world )
    world->audio_things = NULL;
    world->audio_things_count = 0;
 
-   world->triggers = NULL;
-   world->trigger_count = 0;
+   world->volumes = NULL;
+   world->volume_count = 0;
 
    world->lights = NULL;
    world->light_count = 0;
 
-   world->logic_relays = NULL;
-   world->relay_count = 0;
-
-   world->logic_achievements = NULL;
-   world->achievement_count = 0;
-
    world->nodes = NULL;
    world->node_count = 0;
 
@@ -1063,6 +988,9 @@ VG_STATIC void world_clean( world_instance *world )
    world->collectors = NULL;
    world->collector_count = 0;
 
+   world->soundscapes = NULL;
+   world->soundscape_count = 0;
+
    world->nonlocal_gates = NULL;
    world->nonlocalgate_count = 0;