it works, fuck you
authorhgn <hgodden00@gmail.com>
Fri, 27 Dec 2024 15:27:44 +0000 (15:27 +0000)
committerhgn <hgodden00@gmail.com>
Fri, 27 Dec 2024 15:27:44 +0000 (15:27 +0000)
src/metascene.c
src/metascene.h
src/skaterift.c
src/skaterift_script.c

index 674337be46021d5a2d6773c222b721d5ebba6d4b..fed57f0037c0254513f75c20fff064fa7acbb5d3 100644 (file)
@@ -44,6 +44,28 @@ struct cs_instance *_cutscene_get_first_model_instance( const char *mdl_name )
    return NULL;
 }
 
+void _cutscene_play(void)
+{
+   _cutscene.state = k_cutscene_state_playing;
+}
+
+void _cutscene_unload(void)
+{
+   vg_info( "Unloading cutscene\n" );
+
+   for( u32 i=0; i<_cutscene.unique_refs; i ++ )
+      mdl_sync_std_unload( &_cutscene.refs[i].mdl );
+
+   vg_allocator_free( _cutscene.arena );
+   _cutscene.arena = NULL;
+   _cutscene.active_camera = NULL;
+   _cutscene.strip = 0;
+   _cutscene.time = 0.0f;
+   _cutscene.active_samplers = 0;
+   _cutscene.state = k_cutscene_state_none;
+   _cutscene.player_binding = NULL;
+}
+
 /*
  * Find associated entity data. We should also probably do this on the world
  * thingy
@@ -298,7 +320,7 @@ static int cmd_cutscene_play( int argc, const char *argv[] )
  * Currently draws everything as skinned meshes.
  */
 void cutscene_render_instance( struct cs_instance *ins, 
-                               world_instance *world, vg_camera *cam )
+      world_instance *world, vg_camera *cam )
 {
    struct model_ref *ref = &_cutscene.refs[ ins->ref_id ];
    mdl_context *mdl = &ref->mdl;
@@ -311,7 +333,7 @@ void cutscene_render_instance( struct cs_instance *ins,
 
    WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, model_character_view );
 
-       glActiveTexture( GL_TEXTURE0 );
+   glActiveTexture( GL_TEXTURE0 );
    shader_model_character_view_uTexMain( 0 );
 
    u32 armature_id = 0x00;
@@ -331,16 +353,16 @@ void cutscene_render_instance( struct cs_instance *ins,
 
          m4x3f *skinning_data = ins->skinning_data + skele->skinning_offset;
          glUniformMatrix4x3fv( _uniform_model_character_view_uTransforms,
-                               skele->sk.bone_count,
-                               0,
-                               (const GLfloat *)skinning_data );
+               skele->sk.bone_count,
+               0,
+               (const GLfloat *)skinning_data );
       }
 
       for( u32 j=0; j<mesh->submesh_count; j ++ )
       {
          mdl_submesh *sm = &mdl->submeshes[ mesh->submesh_start+j ];
          VG_ASSERT( sm->material_id );
-         
+
          if( sm->material_id != material_id )
          {
             mdl_material *m = &mdl->materials[ sm->material_id-1 ];
@@ -369,7 +391,7 @@ struct cs_link_info
 };
 
 static bool link_internal_datapath( struct cs_asoc *asoc, const char *datapath,
-                                    struct cs_link_info *out_link )
+      struct cs_link_info *out_link )
 {
    VG_ASSERT( asoc->entity_type == k_ent_camera );
 
@@ -425,7 +447,7 @@ void cutscene_update( f32 delta )
    for( u32 i=0; i<_cutscene.active_samplers; i ++ )
    {
       struct cs_sampler *si = &_cutscene.samplers[i];
-      
+
       if( frame > (si->strip->offset + si->strip->length) )
       {
          move = 1;
@@ -437,7 +459,7 @@ void cutscene_update( f32 delta )
             struct cs_sampler *sj = &_cutscene.samplers[j];
             *sj = *si;
          }
-         
+
          j ++;
       }
    }
@@ -642,6 +664,12 @@ void cutscene_update( f32 delta )
       ent_camera *cam = af_arritm( &_cutscene.meta.cameras, i );
       vg_line_cross( cam->co, VG__RED, 0.2f );
    }
+
+   if( (_cutscene.strip == af_arrcount(&_cutscene.meta.strips)) &&
+       (_cutscene.active_samplers == 0 ) )
+   {
+      _cutscene.state = k_cutscene_state_done;
+   }
 }
 
 void cutscene_render( world_instance *world, vg_camera *cam )
@@ -662,6 +690,20 @@ void cutscene_render( world_instance *world, vg_camera *cam )
 static void cb_cutscene_view( ui_context *ctx, ui_rect rect, 
                               struct vg_magi_panel *magi )
 {
+   if( _cutscene.state == k_cutscene_state_none )
+   {
+      ui_text( ctx, rect, "No cutscene loaded.", 1, 
+               k_ui_align_middle_center, 0 );
+      return;
+   }
+
+   if( _cutscene.state == k_cutscene_state_loading )
+   {
+      ui_text( ctx, rect, "Cutscene loading..", 1, 
+               k_ui_align_middle_center, 0 );
+      return;
+   }
+
    ms_strip *usage[8];
    for( u32 i=0; i<VG_ARRAY_LEN(usage); i ++ ) usage[i] = NULL;
 
index 010e3a1514fa628032bfefd0b41884589f379279..d4e3598a575b4ea7c235e4f37020fe1654146451 100644 (file)
@@ -146,6 +146,7 @@ struct _cutscene
    u32 active_samplers;
 
    ent_camera *active_camera;
+   struct cs_instance *player_binding;
 
    u32 strip;
    f32 time;
@@ -155,6 +156,8 @@ extern _cutscene;
 void metascene_load( ms_context *ms, const char *path, void *alloc );
 void cutscene_init(void);
 void cutscene_render( world_instance *world, vg_camera *cam );
+void _cutscene_play(void);
+void _cutscene_unload(void);
 void cutscene_update( f32 delta );
 ent_camera *_cutscene_active_camera(void);
 
index ed7acef3e5b132db515585afe51093832d2241d4..261f6617672d2b9b2592fdd913ade9a929c0e1ff 100644 (file)
@@ -508,7 +508,16 @@ static void skaterift_composite_maincamera(void)
 
 static void render_main_game(void)
 {
-   if( skaterift.activity == k_skaterift_replay )
+   if( (_cutscene.state >= k_cutscene_state_ready) && _cutscene.player_binding )
+   {
+      struct cs_instance *inst = _cutscene.player_binding;
+      struct skeleton *sk = &localplayer.skeleton;
+      for( u32 i=0; i<sk->bone_count; i ++ )
+      {
+         m4x3_copy( inst->skinning_data[i], localplayer.final_mtx[i] );
+      }
+   }
+   else if( skaterift.activity == k_skaterift_replay )
    {
       player__animate_from_replay( &player_replay.local );
    }
@@ -519,8 +528,6 @@ static void render_main_game(void)
       localplayer.deferred_frame_record = 0;
    }
 
-   //temp_not_done_1();
-
    animate_remote_players();
    player__pre_render();
 
@@ -695,23 +702,3 @@ void vg_gui( ui_context *ctx )
 #include "control_overlay.c"
 #include "ent_camera.c"
 #include "skaterift_script.c"
-
-#if 0
-static void temp_not_done_1(void)
-{
-   if( _cutscene.ready )
-   {
-      struct cs_instance *inst = _cutscene_get_first_model_instance(
-            "playermodels/skaterift_john/ch_john" );
-
-      if( inst )
-      {
-         struct skeleton *sk = &localplayer.skeleton;
-         for( u32 i=0; i<sk->bone_count; i ++ )
-         {
-            m4x3_copy( inst->skinning_data[i], localplayer.final_mtx[i] );
-         }
-      }
-   }
-}
-#endif
index 95fd7dba1a969c693f2c6f6c0791bf157124df80..c0914e444dde254bbea7885e69793e5406e9152f 100644 (file)
@@ -57,6 +57,8 @@ static bool _skaterift_script_test( enum escript_event ev )
          {
             state = k_escript_state_playing;
             vg_info( "test:state = playing\n" );
+            _cutscene.player_binding = override_inst;
+            _cutscene_play();
          }
          else
          {
@@ -72,7 +74,7 @@ static bool _skaterift_script_test( enum escript_event ev )
       {
          state = k_escript_state_end;
          vg_info( "test:state = end\n" );
-         // TODO: Unload cutscene?
+         _cutscene_unload();
          return 1;
       }
    }