oh yeah mr crabs
[carveJwlIkooP6JGAAIwe30JlM.git] / world.h
diff --git a/world.h b/world.h
index a7b5a587b1e0a55318dc1de1990de5db456579f4..3b30973099152990e276dbc780869f1f08dc623c 100644 (file)
--- a/world.h
+++ b/world.h
@@ -58,6 +58,37 @@ static struct gworld
    spawns[32];
    u32 spawn_count;
 
+   struct world_audio_thing
+   {
+      v3f pos;
+      float volume;
+      u32 flags;
+
+      audio_player player;
+      audio_clip temp_embedded_clip;
+   }
+   * audio_things;
+   
+   u32 audio_things_count,
+       audio_things_cap;
+
+   struct achievement_zone
+   {
+      m4x3f transform, inv_transform;
+      char name[32];
+      int triggered;
+
+      union
+      {
+         mdl_node *ptarget_delegated;
+         struct world_audio_thing *ptarget;
+      };
+   }
+   * achievement_zones;
+
+   u32 achievement_zones_count,
+       achievement_zones_cap;
+
    struct subworld_routes
    {
       struct route_node
@@ -113,7 +144,7 @@ static struct gworld
       }
       *routes;
 
-      double last_interaction;
+      double time, rewind_from, rewind_to, last_use;
 
       u32 route_count,
           route_cap;
@@ -182,6 +213,8 @@ static struct gworld
 #if 0
    traffic_driver van_man[6];
 #endif
+
+   double sky_time, sky_rate, sky_target_rate;
    
    /* Physics */
    
@@ -214,7 +247,7 @@ static struct gworld
    v3f render_gate_pos;
    int active_route_board;
 }
-world;
+world ;
 
 /*
  * API
@@ -243,6 +276,9 @@ static int ray_world( v3f pos, v3f dir, ray_hit *hit );
 
 static void world_init(void)
 {
+   world.sky_rate = 1.0;
+   world.sky_target_rate = 1.0;
+
    shader_terrain_register();
    shader_sky_register();
    shader_planeinf_register();
@@ -288,12 +324,24 @@ static void world_free( void *_ )
 {
    mesh_free( &world.cars );
    mesh_free( &world.skydome );
+   vg_free( world.achievement_zones );
+
+   /* FIXME: This fucks with the audio player. Use-after-free */
+#if 0
+   vg_free( world.audio_things );
+#endif
 }
 
 static void world_update( v3f pos )
 {
+   world.sky_time += world.sky_rate * vg.time_delta;
+   world.sky_rate = vg_lerp( world.sky_rate, world.sky_target_rate, 
+                                 vg.time_delta * 5.0 );
+
    world_routes_update();
+#if 0
    world_routes_debug();
+#endif
    
    int closest = 0;
    float min_dist = INFINITY;
@@ -329,6 +377,47 @@ static void world_update( v3f pos )
          }
       }
    }
+
+   static int in_zone = 0;
+
+   int in_zone_this_time = 0;
+
+   for( int i=0; i<world.achievement_zones_count; i++ )
+   {
+      struct achievement_zone *zone = &world.achievement_zones[i];
+
+      v3f local;
+      m4x3_mulv( zone->inv_transform, pos, local );
+      
+      if( (fabsf(local[0]) <= 1.0f) &&
+          (fabsf(local[1]) <= 1.0f) &&
+          (fabsf(local[2]) <= 1.0f) )
+      {
+         in_zone_this_time = 1;
+
+         if( !in_zone && zone->ptarget )
+         {
+            audio_lock();
+            audio_player_playclip( &zone->ptarget->player, 
+                                   &zone->ptarget->temp_embedded_clip );
+            audio_unlock();
+         }
+
+         if( !zone->triggered )
+         {
+            steam_set_achievement( zone->name );
+            steam_store_achievements();
+         }
+
+         zone->triggered = 1;
+      }
+
+      vg_line_boxf_transformed( zone->transform, (boxf){{-1.0f,-1.0f,-1.0f},
+                                                        { 1.0f, 1.0f, 1.0f}}, 
+                                                        0xff00ff00 );
+   }
+
+   in_zone = in_zone_this_time;
    
    sfd_update( &world.sfd.tester );
 }