if( vg_long_opt( "no-asan", NULL ) )
vg_test_env.debug_asan = 0;
+
+ if( (arg = vg_long_opt_arg( "strdjb2", NULL )) )
+ printf( "vg_strdjb2('%s'): %u\n", arg, vg_strdjb2(arg) );
}
vg_success( "All scripts completed\n" );
#include "metascene.h"
#include "vg/vg_magi.h"
+struct _cutscene _cutscene;
+
void metascene_load( ms_context *ms, const char *path, void *alloc )
{
af_open( &ms->af, path, MS_VERSION_MIN, MS_VERSION_NR, alloc );
}
}
-struct
+struct cs_instance *_cutscene_get_first_model_instance( const char *mdl_name )
{
- ms_context meta;
- void *arena;
-
- bool ready;
-
- struct model_ref
+ for( u32 i=0; i<_cutscene.instance_count; i ++ )
{
- const char *name;
- u32 name_hash;
- u32 reference_count;
-
- mdl_context mdl;
-
- struct cs_skeleton
+ struct cs_instance *inst = &_cutscene.instances[i];
+ struct model_ref *mref = &_cutscene.refs[ inst->ref_id ];
+
+ if( vg_str_eq( mdl_name, mref->name ) )
{
- struct skeleton sk;
- u32 skinning_offset;
+ return inst;
}
- *skeletons;
- u32 total_skinning_bones;
- }
- * refs;
- u32 unique_refs;
-
- struct cs_instance
- {
- u32 ref_id;
- m4x3f *skinning_data;
}
- * instances;
- u32 instance_count;
-
- struct cs_sampler
- {
- ms_strip *strip;
- ms_override *override;
- union
- {
- struct
- {
- ms_track *track;
- f32 *target;
- u32 keyframe;
- u32 semantic;
- }
- curves;
-
- struct
- {
- struct skeleton *ref_sk;
- m4x3f *skinning_data;
- }
- skeleton;
- };
- }
- samplers[32];
- u32 active_samplers;
-
- ent_camera *active_camera;
- u32 strip;
- f32 time;
+ return NULL;
}
-_cutscene;
/*
* Find associated entity data. We should also probably do this on the world
static void sync_cutscene_loaded( void *payload, u32 size )
{
- vg_info( "Cutscene ready\n" );
- _cutscene.ready = 1;
+ vg_info( "Cutscene loaded\n" );
+ _cutscene.state = k_cutscene_state_ready;
}
static void cutscene_load_thread( void *data )
{
if( argc == 1 )
{
- if( _cutscene.ready )
+ if( _cutscene.state != k_cutscene_state_none )
{
vg_info( "Resetting cutscene..\n" );
_cutscene.time = 0.0f;
if( vg_loader_availible() )
{
- _cutscene.ready = 0;
+ _cutscene.state = k_cutscene_state_loading;
_cutscene.time = 0.0f;
_cutscene.strip = 0;
_cutscene.active_samplers = 0;
void cutscene_update( f32 delta )
{
- if( !_cutscene.ready )
+ if( _cutscene.state != k_cutscene_state_playing )
return;
_cutscene.time += delta;
void cutscene_render( world_instance *world, vg_camera *cam )
{
- if( _cutscene.ready )
+ if( _cutscene.state >= k_cutscene_state_ready )
{
for( u32 i=0; i<_cutscene.instance_count; i ++ )
{
v2f co, l, r;
};
+struct cs_instance
+{
+ u32 ref_id;
+ m4x3f *skinning_data;
+};
+
+#include "skeleton.h"
+
+struct _cutscene
+{
+ ms_context meta;
+ void *arena;
+
+ enum cutscene_state
+ {
+ k_cutscene_state_none,
+ k_cutscene_state_loading,
+ k_cutscene_state_ready,
+ k_cutscene_state_playing,
+ k_cutscene_state_done
+ }
+ state;
+
+ struct model_ref
+ {
+ const char *name;
+ u32 name_hash;
+ u32 reference_count;
+
+ mdl_context mdl;
+
+ struct cs_skeleton
+ {
+ struct skeleton sk;
+ u32 skinning_offset;
+ }
+ *skeletons;
+ u32 total_skinning_bones;
+ }
+ * refs;
+ u32 unique_refs;
+
+ struct cs_instance *instances;
+ u32 instance_count;
+
+ struct cs_sampler
+ {
+ ms_strip *strip;
+ ms_override *override;
+ union
+ {
+ struct
+ {
+ ms_track *track;
+ f32 *target;
+ u32 keyframe;
+ u32 semantic;
+ }
+ curves;
+
+ struct
+ {
+ struct skeleton *ref_sk;
+ m4x3f *skinning_data;
+ }
+ skeleton;
+ };
+ }
+ samplers[32];
+ u32 active_samplers;
+
+ ent_camera *active_camera;
+
+ u32 strip;
+ f32 time;
+}
+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_update( f32 delta );
ent_camera *_cutscene_active_camera(void);
+
+struct cs_instance *_cutscene_get_first_model_instance( const char *mdl_name );
#include "player_render.h"
#include "control_overlay.h"
#include "client.h"
+#include "skaterift_script.h"
struct skaterift_globals skaterift =
{
void game_load(void)
{
+ _skaterift_script_init();
vg_console_reg_cmd( "load_world", skaterift_load_world_command, NULL );
vg_console_reg_var( "immobile", &localplayer.immobile, k_var_dtype_i32, 0 );
vg_loader_step( menu_init, NULL );
if( !g_client.loaded ) return;
- draw_origin_axis();
+ //draw_origin_axis();
+ _skaterift_script_update();
addon_system_pre_update();
skateshop_world_preview_preupdate();
network_update();
vg_camera_finalize( &g_render.cam );
}
-static void temp_not_done_1(void);
-
static void render_main_game(void)
{
if( skaterift.activity == k_skaterift_replay )
localplayer.deferred_frame_record = 0;
}
- temp_not_done_1();
+ //temp_not_done_1();
animate_remote_players();
player__pre_render();
#include "metascene.c"
#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 skeleton *sk = &localplayer.skeleton;
- for( u32 i=0; i<sk->bone_count; i ++ )
+ struct cs_instance *inst = _cutscene_get_first_model_instance(
+ "playermodels/skaterift_john/ch_john" );
+
+ if( inst )
{
- m4x3_copy( _cutscene.instances[1].skinning_data[i],
- localplayer.final_mtx[i] );
+ 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
--- /dev/null
+/*
+ * One day in the future, all will be well with the abstraction gods, and these
+ * scripts will run in an interpreter just like a real scripting language. That
+ * of course assumes I believe in the abstraction gods, but I am not a religious
+ * man.
+ */
+
+enum escript_event
+{
+ k_escript_event_call = 0,
+ k_escript_event_update = 1
+};
+
+/* you can add anything you want to this. */
+enum escript_state
+{
+ k_escript_state_none,
+ k_escript_state_loading,
+ k_escript_state_initializing,
+ k_escript_state_playing,
+ k_escript_state_end
+};
+
+/* This is the development one */
+static bool _skaterift_script_test( enum escript_event ev )
+{
+ static u32 state;
+ static struct cs_instance *override_inst;
+
+ if( ev == k_escript_event_call )
+ {
+ state = k_escript_state_loading;
+ override_inst = NULL;
+ vg_info( "test:state = loading\n" );
+ }
+
+ /* scene
+ * --------------------------------------------------------------- */
+
+ if( state == k_escript_state_loading )
+ {
+ if( cmd_cutscene_play( 1, (const char *[]){ "metascenes/test_scene.ms" } ) )
+ {
+ state = k_escript_state_initializing;
+ vg_info( "test:state = initializing\n" );
+ }
+ }
+
+ if( state == k_escript_state_initializing )
+ {
+ if( _cutscene.state == k_cutscene_state_ready )
+ {
+ override_inst = _cutscene_get_first_model_instance(
+ "playermodels/skaterift_john/ch_john" );
+
+ if( override_inst )
+ {
+ state = k_escript_state_playing;
+ vg_info( "test:state = playing\n" );
+ }
+ else
+ {
+ vg_error( "test: Failed to find player target" );
+ return 1;
+ }
+ }
+ }
+
+ if( state == k_escript_state_playing )
+ {
+ if( _cutscene.state == k_cutscene_state_done )
+ {
+ state = k_escript_state_end;
+ vg_info( "test:state = end\n" );
+ // TODO: Unload cutscene?
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+enum escript_script_id
+{
+ k_escript_script_id_test = 0,
+ k_escript_script_id_max
+};
+
+struct
+{
+ enum escript_script_id script_id;
+}
+static _script = { .script_id = k_escript_script_id_max };
+
+struct script_binding
+{
+ const char *alias;
+ bool( *jump )( enum escript_event ev );
+}
+_script_bindings[] =
+{
+ [k_escript_script_id_test] = { "test", _skaterift_script_test }
+};
+
+static int _skaterift_script_hook( int argc, const char *argv[] )
+{
+ if( argc != 1 )
+ {
+ vg_error( "Usage: script <x>\n" );
+ return 0;
+ }
+
+ for( u32 i=0; i<k_escript_script_id_max; i ++ )
+ {
+ struct script_binding *bind = &_script_bindings[i];
+ if( vg_str_eq( argv[0], bind->alias ) )
+ {
+ _script.script_id = i;
+ if( bind->jump( k_escript_event_call ) )
+ _script.script_id = k_escript_script_id_max;
+
+ return 1;
+ }
+ }
+
+ vg_error( "No such script '%s'\n", argv[0] );
+ return 1;
+}
+
+void _skaterift_script_update(void)
+{
+ if( _script.script_id != k_escript_script_id_max )
+ {
+ if( _script_bindings[ _script.script_id ].jump( k_escript_event_update ) )
+ _script.script_id = k_escript_script_id_max;
+ }
+}
+
+void _skaterift_script_init(void)
+{
+ vg_console_reg_cmd( "script", _skaterift_script_hook, NULL );
+}
--- /dev/null
+#pragma once
+
+void _skaterift_script_update(void);
+void _skaterift_script_init(void);
#pragma once
#include "vg/vg_lines.h"
#include "model.h"
+#include "metascene.h"
struct skeleton
{