re-fix challenges master
authorhgn <hgodden00@gmail.com>
Thu, 20 Feb 2025 19:25:14 +0000 (19:25 +0000)
committerhgn <hgodden00@gmail.com>
Thu, 20 Feb 2025 19:25:14 +0000 (19:25 +0000)
src/ent_challenge.c
src/ent_objective.c
src/player.c
src/world.h
src/world_render.c

index 6041377feff6bc5c316e7c0a25dffb11c43578a1..f4681ed8e3e502d64b0ece0dec8790b7f5ed7111 100644 (file)
@@ -29,11 +29,12 @@ entity_call_result ent_challenge_call( world_instance *world, ent_call *call )
       {
          if( world_set_event( k_world_event_challenge ) )
          {
-            _world.active_challenge = challenge;
+            _world.challenge_state = k_challenge_state_none;
+            _world.active_challenge_id = call->id;
             gui_helper_reset( 1 );
             vg_str text;
             if( gui_new_helper( input_button_list[k_srbind_maccept], &text ))
-               vg_strcat( &text, "Start" );
+               vg_strcat( &text, "View Challenge" );
          }
       }
 
@@ -41,88 +42,55 @@ entity_call_result ent_challenge_call( world_instance *world, ent_call *call )
    }
    else if( call->function == -1 ) /* unview() */
    {
-      if( world_clear_event( k_world_event_challenge ) )
-      {
-         _world.active_challenge = NULL;
-         gui_helper_reset( k_gui_helper_mode_clear );
-      }
-      return k_entity_call_result_OK;
-
-#if 0
-      if( (localplayer.subsystem == k_player_subsystem_walk) &&
-          (_world.challenge_target == NULL) )
+      if( _world.challenge_state != k_challenge_state_running )
       {
-         _world.challenge_target = NULL;
-         world_entity_set_focus( call->id );
-         world_entity_focus_modal();
-
-         gui_helper_clear();
-         vg_str text;
-         if( gui_new_helper( input_button_list[k_srbind_maccept], &text ))
-            vg_strcat( &text, "Start" );
-         if( gui_new_helper( input_button_list[k_srbind_mback], &text ))
-            vg_strcat( &text, "Exit" );
+         if( world_clear_event( k_world_event_challenge ) )
+         {
+            _world.challenge_state = k_challenge_state_none;
+            _world.active_challenge_id = 0;
+            gui_helper_reset( k_gui_helper_mode_clear );
+         }
       }
       return k_entity_call_result_OK;
-#endif
    }
    else 
       return k_entity_call_result_unhandled;
 }
 
-#if 0
-void ent_challenge_preupdate( ent_focus_context *ctx )
+void ent_challenge_update(void)
 {
-   world_instance *world = ctx->world;
-   ent_challenge *challenge = af_arritm( &world->ent_challenge, ctx->index );
-
-   /* maximum distance from active challenge */
-   if( !ctx->active )
-   {
-      f32 min_dist2 = 999999.9f;
+   if( _world.event != k_world_event_challenge )
+      return;
 
-      if( mdl_entity_id_type( challenge->first ) == k_ent_objective )
-      {
-         u32 next = challenge->first;
-         while( mdl_entity_id_type(next) == k_ent_objective ){
-            u32 index = mdl_entity_id_id( next );
-            ent_objective *objective = af_arritm(&world->ent_objective,index);
-            next = objective->id_next;
+   world_instance *world = &_world.main;
 
-            f32 d2 = v3_dist2( localplayer.rb.co, objective->transform.co );
-            if( d2 < min_dist2 ) 
-               min_dist2 = d2;
-         }
-      }
+   u32 index = mdl_entity_id_id( _world.active_challenge_id );
+   ent_challenge *challenge = af_arritm( &world->ent_challenge, index );
 
-      f32 max_dist = 100.0f;
-      if( min_dist2 > max_dist*max_dist ){
-         _world.challenge_target = NULL;
-         _world.challenge_timer = 0.0f;
-         world_entity_clear_focus();
-         audio_lock();
-         audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co,
-                           30.0f, 1.0f );
-         audio_unlock();
+   if( _world.challenge_state == k_challenge_state_viewing )
+   {
+      if( challenge->camera )
+      {
+         vg_camera temp;
+         ent_camera_unpack( af_arritm( &world->ent_camera, mdl_entity_id_id(challenge->camera) ), &temp );
+         world_set_entity_driven_camera( &temp );
       }
-      return;
-   }
 
-   world_entity_focus_camera( world, challenge->camera );
-
-   if( mdl_entity_id_type( challenge->first ) == k_ent_objective )
-   {
       if( button_down( k_srbind_maccept ) )
       {
-         u32 index = mdl_entity_id_id( challenge->first );
-         _world.challenge_target = af_arritm( &world->ent_objective, 
-                                                     index );
+         gui_helper_reset( k_gui_helper_mode_clear );
+         _world.challenge_state = k_challenge_state_running;
+         localplayer.immobile = 0; /* TODO: Unify this probably after eating some potats */
+         menu.disable_open = 0;
+         srinput.state = k_input_state_resume;
+
+         u32 first_objective_index = mdl_entity_id_id( challenge->first );
+         _world.challenge_target = af_arritm( &world->ent_objective, first_objective_index );
          _world.challenge_timer = 0.0f;
-         world_entity_exit_modal();
-         gui_helper_clear();
 
          u32 next = challenge->first;
-         while( mdl_entity_id_type(next) == k_ent_objective ){
+         while( mdl_entity_id_type(next) == k_ent_objective )
+         {
             u32 index = mdl_entity_id_id( next );
             ent_objective *objective = af_arritm(&world->ent_objective,index);
             objective->flags &= ~k_ent_objective_passed;
@@ -132,50 +100,52 @@ void ent_challenge_preupdate( ent_focus_context *ctx )
          audio_lock();
          audio_oneshot( &audio_challenge[5], 1.0f, 0.0f );
          audio_unlock();
-         return;
       }
-   }
-   else
-   {
-      if( button_down( k_srbind_maccept ) )
+      else if( button_down( k_srbind_mback ) )
       {
-         ent_call call;
-         call.data = NULL;
-         call.function = challenge->target_event;
-         call.id = challenge->target;
-         entity_call( world, &call );
+         gui_helper_reset( k_gui_helper_mode_clear );
+         _world.challenge_state = k_challenge_state_none;
+         localplayer.immobile = 0; /* TODO: Unify this probably after eating some potats */
+         menu.disable_open = 0;
+         srinput.state = k_input_state_resume;
       }
    }
-
-   if( button_down( k_srbind_mback ) )
+   else if( _world.challenge_state == k_challenge_state_running )
    {
-      _world.challenge_target = NULL;
-      world_entity_exit_modal();
-      world_entity_clear_focus();
-      gui_helper_clear();
-      audio_lock();
-      audio_oneshot( &audio_challenge[4], 1.0f, 0.0f );
-      audio_unlock();
-      return;
-   }
-}
+      f32 min_dist2 = 999999.9f;
 
-static void ent_challenge_render( ent_challenge *challenge ){
-   
-}
-#endif
+      if( mdl_entity_id_type( challenge->first ) == k_ent_objective )
+      {
+         u32 next = challenge->first;
+         while( mdl_entity_id_type(next) == k_ent_objective )
+         {
+            u32 index = mdl_entity_id_id( next );
+            ent_objective *objective = af_arritm(&world->ent_objective,index);
+            next = objective->id_next;
 
-void ent_challenge_update(void)
-{
-   if( _world.event != k_world_event_challenge )
-      return;
+            f32 d2 = v3_dist2( localplayer.rb.co, objective->transform.co );
+            if( d2 < min_dist2 ) 
+               min_dist2 = d2;
+         }
+      }
 
-   if( _world.challenge_running )
-   {
+      f32 max_dist = 100.0f;
+      if( min_dist2 > max_dist*max_dist )
+      {
+         if( world_clear_event( k_world_event_challenge ) )
+         {
+            _world.active_challenge_id = 0;
+            _world.challenge_target = NULL;
+            _world.challenge_timer = 0.0f;
+            audio_lock();
+            audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co, 30.0f, 1.0f );
+            audio_unlock();
+            vg_info( "Challenge expired due to player being out of range.\n" );
+         }
+      }
    }
-   else
+   else if( _world.challenge_state == k_challenge_state_none )
    {
-      ent_challenge *challenge = _world.active_challenge;
       if( challenge->flags & k_ent_challenge_is_story )
       {
          if( button_down( k_srbind_maccept ) )
@@ -190,7 +160,20 @@ void ent_challenge_update(void)
       }
       else
       {
-         /* activate the actual challenge blah blah */
+         if( button_down( k_srbind_maccept ) )
+         {
+            gui_helper_reset( k_gui_helper_mode_clear );
+            vg_str text;
+            if( gui_new_helper( input_button_list[k_srbind_maccept], &text ))
+               vg_strcat( &text, "Start" );
+            if( gui_new_helper( input_button_list[k_srbind_mback], &text ))
+               vg_strcat( &text, "Exit" );
+
+            localplayer.immobile = 1;
+            menu.disable_open = 1;
+            srinput.state = k_input_state_resume;
+            _world.challenge_state = k_challenge_state_viewing;
+         }
       }
    }
 }
index 886329cf6bfab5682a3b3b1becb11b282ac48402..7fa1bf86f73a2e1384a1e42f9035ff40ad22cca7 100644 (file)
@@ -7,8 +7,8 @@
 #include "player.h"
 #include "player_skate.h"
 
-static void ent_objective_pass( world_instance *world, 
-                                   ent_objective *objective ){
+static void ent_objective_pass( world_instance *world, ent_objective *objective )
+{
    if( objective->id_next )
    {
       u32 index = mdl_entity_id_id( objective->id_next );
@@ -18,23 +18,23 @@ static void ent_objective_pass( world_instance *world,
 
       if( next->filter & k_ent_objective_filter_passthrough )
          ent_objective_pass( world, next );
-      else{
+      else
+      {
          vg_info( "pass challenge point\n" );
          audio_lock();
-         audio_oneshot_3d( &audio_challenge[0], localplayer.rb.co,
-                           30.0f, 1.0f );
+         audio_oneshot_3d( &audio_challenge[0], localplayer.rb.co, 30.0f, 1.0f );
          audio_unlock();
       }
    }
-   else {
+   else 
+   {
       vg_success( "challenge win\n" );
       audio_lock();
       audio_oneshot( &audio_challenge[2], 1.0f, 0.0f );
       audio_unlock();
-      _world.challenge_target = NULL;
-      //_world.focused_entity = 0;
 
-      if( objective->id_win ){
+      if( objective->id_win )
+      {
          ent_call call;
          call.data = NULL;
          call.function = objective->win_event;
@@ -43,11 +43,20 @@ static void ent_objective_pass( world_instance *world,
       }
 
       ent_region_re_eval( world );
+
+      if( world_clear_event( k_world_event_challenge ) )
+      {
+         _world.active_challenge_id = 0;
+         _world.challenge_target = NULL;
+         _world.challenge_timer = 0.0f;
+      }
    }
 }
 
-static int ent_objective_check_filter( ent_objective *objective ){
-   if( objective->filter ){
+static int ent_objective_check_filter( ent_objective *objective )
+{
+   if( objective->filter )
+   {
       struct player_skate_state *s = &player_skate.state;
       enum trick_type trick = s->trick_type;
 
@@ -74,7 +83,8 @@ static int ent_objective_check_filter( ent_objective *objective ){
       return ((objective->filter  & state) || !objective->filter) && 
              ((objective->filter2 & state) || !objective->filter2);
    }
-   else {
+   else 
+   {
       return 1;
    }
 }
@@ -93,19 +103,23 @@ entity_call_result ent_objective_call( world_instance *world, ent_call *call )
 
       if( _world.challenge_target )
       {
-         if( (_world.challenge_target == objective) && 
-              ent_objective_check_filter( objective )){
+         if( (_world.challenge_target == objective) && ent_objective_check_filter( objective ))
+         {
             ent_objective_pass( world, objective );
          }
          else 
          {
             audio_lock();
-            audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co,
-                              30.0f, 1.0f );
+            audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co, 30.0f, 1.0f );
             audio_unlock();
-            vg_error( "challenge failed\n" );
-            _world.challenge_target = NULL;
-            //_world.focused_entity = 0;
+            vg_error( "challenge failed, filter was not met\n" );
+
+            if( world_clear_event( k_world_event_challenge ) )
+            {
+               _world.active_challenge_id = 0;
+               _world.challenge_target = NULL;
+               _world.challenge_timer = 0.0f;
+            }
          }
       }
 
@@ -115,7 +129,8 @@ entity_call_result ent_objective_call( world_instance *world, ent_call *call )
    {
       objective->flags &= ~k_ent_objective_hidden;
 
-      if( mdl_entity_id_type( objective->id_next ) == k_ent_objective ){
+      if( mdl_entity_id_type( objective->id_next ) == k_ent_objective )
+      {
          call->id = objective->id_next;
          entity_call( world, call );
       }
@@ -125,7 +140,8 @@ entity_call_result ent_objective_call( world_instance *world, ent_call *call )
    {
       objective->flags |=  k_ent_objective_hidden;
 
-      if( mdl_entity_id_type( objective->id_next ) == k_ent_objective ){
+      if( mdl_entity_id_type( objective->id_next ) == k_ent_objective )
+      {
          call->id = objective->id_next;
          entity_call( world, call );
       }
index 9e3f0c98b1e5238fa25da647059395d5a5e11167..12f53364a144c9bc51221613d896837dea300798 100644 (file)
@@ -312,10 +312,7 @@ void player__clean_refs(void)
    _world.challenge_target = NULL;
    _world.challenge_timer = 0.0f;
    _world.active_trigger_volume_count = 0;
-#if 0
-   world_entity_exit_modal();
-   world_entity_clear_focus();
-#endif
+   _world.event = k_world_event_none;
 
    localplayer.boundary_hash ^= NETMSG_BOUNDARY_BIT;
    world_routes_clear( &_world.main );
index 9683202577224cb35100ae2308a3cfbb4cf74bc6..9a5102124fe8e7a5b96d862922803069ebc2b5be 100644 (file)
@@ -271,8 +271,15 @@ struct world_static
    event;
 
    /* World event: Challenges */
-   ent_challenge *active_challenge;
-   bool challenge_running;
+   u32 active_challenge_id;
+
+   enum challenge_state
+   {
+      k_challenge_state_none = 0,
+      k_challenge_state_viewing,
+      k_challenge_state_running
+   }
+   challenge_state;
 
    ent_objective *challenge_target;
    f32 challenge_timer; /* unused */
index 49d941e2f974dc78533d4c77014d28b7d59860da..3e3e1a6374de20a053fd4bdf63329297899fc28b 100644 (file)
@@ -491,10 +491,8 @@ static void render_world_foliage( world_instance *world, vg_camera *cam )
    glEnable(GL_CULL_FACE);
 }
 
-static void world_render_challenges( world_instance *world, 
-                                     struct world_pass *pass, v3f pos )
+static void world_render_challenges( world_instance *world, struct world_pass *pass, v3f pos )
 {
-#if 0
    if( !world ) return;
    if( skaterift.activity == k_skaterift_replay ) return;
    if( world != &_world.main ) return;
@@ -505,37 +503,18 @@ static void world_render_challenges( world_instance *world,
    u32 objective_list[ 32 ],
        challenge_list[ 16 ];
 
-   v2f objective_uv_offsets[ 32 ];
-
    u32 objective_count = 0,
        challenge_count = 0;
 
-   ent_challenge *active_challenge = NULL;
-   int running = 0;
-   if( mdl_entity_id_type( _world.focused_entity ) == k_ent_challenge )
-   {
-      if( (skaterift.activity == k_skaterift_default) &&
-           _world.challenge_target )
-      {
-         running = 1;
-      }
+   u32 challenge_index = mdl_entity_id_id( _world.active_challenge_id );
+   ent_challenge *challenge = af_arritm( &world->ent_challenge, challenge_index );
 
-      if( !((skaterift.activity != k_skaterift_ent_focus) &&
-            !_world.challenge_target) )
-      {
-         world_instance *challenge_world = &_world.main;
-         u32 index = mdl_entity_id_id( _world.focused_entity );
-         active_challenge = af_arritm(&challenge_world->ent_challenge, index);
-      }
-   }
-
-   if( active_challenge )
+   if( (_world.event == k_world_event_challenge) && (_world.challenge_state == k_challenge_state_running) )
    {
       shader_scene_fxglow_uUvOffset( (v2f){ 8.0f/256.0f, 0.0f } );
-      challenge_list[ challenge_count ++ ] = 
-         mdl_entity_id_id( _world.focused_entity );
+      challenge_list[ challenge_count ++ ] = challenge_index;
 
-      u32 next = active_challenge->first;
+      u32 next = challenge->first;
       while( mdl_entity_id_type(next) == k_ent_objective )
       {
          u32 index = mdl_entity_id_id( next );
@@ -580,12 +559,11 @@ static void world_render_challenges( world_instance *world,
    {
       u32 index = objective_list[ i ];
       ent_objective *objective = af_arritm( &world->ent_objective, index );
-      if( (objective->flags & k_ent_objective_hidden) && !active_challenge ) 
-         continue;
 
       f32 scale = 1.0f;
 
-      if( running )
+      if( (_world.event == k_world_event_challenge) && 
+          (_world.challenge_state == k_challenge_state_running || _world.challenge_state == k_challenge_state_viewing) )
       {
          u32 passed = objective->flags & k_ent_objective_passed;
          f32 target = passed? 0.0f: 1.0f;
@@ -597,8 +575,12 @@ static void world_render_challenges( world_instance *world,
          else
             shader_scene_fxglow_uUvOffset( (v2f){ 8.0f/256.0f, 0.0f } );
       }
-      else 
+      else
       {
+         /* TODO: Rename this flag. its misleading */
+         if( objective->flags & k_ent_objective_hidden ) 
+            continue;
+
          f32 dist = v3_dist( objective->transform.co, pos ) * (1.0f/radius);
          scale = vg_smoothstepf( vg_clampf( 5.0f-dist*5.0f, 0.0f,1.0f ) );
       }
@@ -626,11 +608,11 @@ static void world_render_challenges( world_instance *world,
    font3d_bind( &gui.font, k_font_shader_world, 0, world, &g_render.cam );
 
    u32 count = 0;
-
    for( u32 i=0; i<af_arrcount(&world->ent_challenge); i++ )
    {
       ent_challenge *challenge = af_arritm( &world->ent_challenge, i );
-      if( challenge->status ) count ++;
+      if( challenge->status ) 
+         count ++;
    }
 
    char buf[32];
@@ -669,7 +651,6 @@ static void world_render_challenges( world_instance *world,
       shader_scene_font_uColourize( colour );
       font3d_simple_draw( 1, buf, &g_render.cam, mmdl );
    }
-#endif
 }
 
 static void bindpoint_fxglow( world_instance *world,
@@ -1143,10 +1124,14 @@ void render_world( world_instance *world, vg_camera *cam,
    if( !viewing_from_gate )
    {
       f32 greyout = 0.0f;
-#if 0
-      if( mdl_entity_id_type(_world.focused_entity) == k_ent_challenge )
-         greyout = _world.focus_strength;
-#endif
+
+      if( _world.event == k_world_event_challenge )
+      {
+         if( _world.challenge_state == k_challenge_state_viewing )
+         {
+            greyout = 1.0f;
+         }
+      }
 
       if( greyout > 0.0f )
       {