* =============================================================================
*/
-#if 1
+#if 0
#define SR_NETWORKED
-#define VG_DEVWINDOW
+
+#ifndef VG_RELEASE
+ #define VG_DEVWINDOW
+#endif
/*
* system headers
#include "addon.c"
#include "highscores.c"
#include "save.c"
+#include "respawn.c"
static struct player_avatar localplayer_avatar;
-int main( int argc, char *argv[] )
-{
+int main( int argc, char *argv[] ){
vg_mem.use_libc_malloc = 0;
vg_set_mem_quota( 160*1024*1024 );
vg_enter( argc, argv, "Voyager Game Engine" );
return 0;
}
-VG_STATIC void vg_launch_opt(void)
-{
-}
+VG_STATIC void vg_launch_opt(void){}
-VG_STATIC void vg_preload(void)
-{
- skaterift_read_savedata();
+VG_STATIC void vg_preload(void){
+ //skaterift_read_savedata();
vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" );
vg_info(" 2021-2023 |\\ /| | / | | | | /| \n" );
vg_loader_step( network_init, network_end );
}
-VG_STATIC void load_playermodels(void)
-{
+VG_STATIC void load_playermodels(void){
/* FIXME: hack */
shader_model_character_view_register();
shader_model_board_view_register();
}
static void skaterift_restore_state(void){
- vg_msg sav = {0};
- sav.buf = savedata.buf;
- sav.len = savedata.len;
- sav.max = sizeof(savedata.buf);
+ savedata_file sav;
+ strcpy( sav.path, str_skaterift_main_save );
+ savedata_file_read( &sav );
- vg_msg player = sav;
+ vg_msg kvsav = {0};
+ kvsav.buf = sav.buf;
+ kvsav.len = sav.len;
+ kvsav.max = sizeof(sav.buf);
+
+ u32 board_reg_id = 0,
+ player_reg_id = 0;
+
+ vg_msg player = kvsav;
if( vg_msg_seekframe( &player, "player", 0 ) ){
addon_alias q;
/* board */
skaterift_read_addon_alias( &player, "board", k_addon_type_board, &q );
u32 reg_id = addon_match( &q );
- if( reg_id != 0xffffffff ){
- localplayer.board_view_slot =
- addon_cache_create_viewer( k_addon_type_board, reg_id );
- }
+ if( reg_id != 0xffffffff )
+ board_reg_id = reg_id;
+
/* playermodel */
skaterift_read_addon_alias( &player, "playermodel",
k_addon_type_player, &q );
reg_id = addon_match( &q );
-
- if( reg_id == 0xffffffff ) reg_id = 0;
- localplayer.playermodel_view_slot =
- addon_cache_create_viewer( k_addon_type_player, reg_id );
+ if( reg_id != 0xffffffff )
+ player_reg_id = reg_id;
}
- vg_msg world = sav;
+ localplayer.board_view_slot =
+ addon_cache_create_viewer( k_addon_type_board, board_reg_id );
+ localplayer.playermodel_view_slot =
+ addon_cache_create_viewer( k_addon_type_player, player_reg_id );
+
+ vg_msg world = kvsav;
if( vg_msg_seekframe( &world, "world", 0 ) ){
addon_alias q;
if( reg_id != 0xffffffff ){
addon_reg *reg = get_addon_from_index( k_addon_type_world, reg_id );
- world_loader.generate_point_cloud = 0;
- world_loader.reg = reg;
- world_loader.state = k_world_loader_load;
- skaterift_world_changer_thread(NULL);
+ world_static.load_state = k_world_loader_load;
+ struct world_load_args args = {
+ .purpose = k_world_purpose_client,
+ .reg = reg
+ };
+ skaterift_world_load_thread( &args );
- world_static.active_world = vg_msg_seekkvu32( &world, "index", 0 );
+ world_set_active_instance( vg_msg_seekkvu32( &world, "index", 0 ) );
world_static.active_trigger_volume_count = 0;
localplayer.viewable_world = world_current_instance();
+ }
- vg_msg_cmd position = vg_msg_seekkv( &world, "position", 0 );
- v3f pos;
- vg_msg_convert_num( &position, k_vg_msg_float|k_vg_msg_32b, 3, pos );
+ vg_msg_cmd position = vg_msg_seekkv( &world, "position", 0 );
+ v3f pos;
+ vg_msg_convert_num( &position, k_vg_msg_float|k_vg_msg_32b, 3, pos );
+
+ if( v3_length2(pos) > 1.0f )
player__setpos( &localplayer, pos );
- }
}
}
-VG_STATIC void vg_load(void)
-{
+VG_STATIC void vg_load(void){
vg_console_reg_cmd( "changeworld", skaterift_change_world_command, NULL );
vg_loader_step( render_init, NULL );
vg_loader_step( load_playermodels, NULL );
/* player setup */
- local_replay_init( (1024*1024*1)/2 );
+ u32 bytes = 1024*1024*10;
+ skaterift.replay.data = vg_linear_alloc( vg_mem.rtmemory, bytes );
+ skaterift.replay.size = bytes;
+ replay_clear( &skaterift.replay );
+
player__create( &localplayer );
player_avatar_load( &localplayer_avatar, "models/ch_none.mdl" );
player__use_avatar( &localplayer, &localplayer_avatar );
vg_loader_step( audio_init, audio_free );
/* 'systems' are completely loaded now */
-
- /* load home/permanent world manually */
- world_loader.reg = NULL;
- strcpy( world_loader.override_name, "mp_spawn" );
- world_loader.generate_point_cloud = 1;
- world_loader.world_index = 0;
- world_load_mdl( "maps/mp_spawn/main.mdl" );
-
- vg_async_call( async_skaterift_player_start, NULL, 0 );
- vg_async_stall();
/* Completing addon registrations
* -------------------------------------
mtzero->metadata_len = msg.cur;
}
+ /* load home/permanent world manually */
+ world_static.load_state = k_world_loader_load;
+ struct world_load_args args = {
+ .purpose = k_world_purpose_hub,
+ .reg = spawn
+ };
+ skaterift_world_load_thread( &args );
+
+ vg_async_call( async_skaterift_player_start, NULL, 0 );
+ vg_async_stall();
+
+
global_skateshop.selected_world_id=1;
global_skateshop.pointcloud_world_id=1;
skateshop_world_preview_loader_thread( mtzero ); /* HACK */
/* and now */
skaterift_restore_state();
- vg_loader_step( NULL, skaterift_write_savedata );
+ vg_loader_step( NULL, skaterift_autosave_synchronous );
board_processview_thread(NULL);
vg_async_call( async_call_ready, NULL, 0 );
}
-VG_STATIC void draw_origin_axis(void)
-{
+VG_STATIC void draw_origin_axis(void){
vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 1.0f, 0.0f, 0.0f }, 0xffff0000 );
vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 0.0f, 1.0f, 0.0f }, 0xff00ff00 );
vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 0.0f, 0.0f, 1.0f }, 0xff0000ff );
}
+static void skaterift_change_client_world_preupdate(void);
+
+/*
+ * UPDATE LOOP
+ * ---------------------------------------------------------------------------*/
+
+VG_STATIC void vg_pre_update(void){
+ srinput.enabled = 1;
-static void skaterift_change_world_preupdate(void);
-VG_STATIC void vg_update(void)
-{
steam_update();
skaterift_preupdate_inputs();
if( skaterift.op == k_async_op_clientloading ) return;
-
- if( world_loader.state == k_world_loader_preload ){
- skaterift_change_world_preupdate();
- }
+ if( world_static.load_state == k_world_loader_preload )
+ skaterift_change_client_world_preupdate();
draw_origin_axis();
network_update();
+
+ /* time rate */
+ f32 target = 1;
+ if( skaterift.activity & (k_skaterift_replay|k_skaterift_menu|
+ k_skaterift_respawning) ) {
+ target = 0;
+ }
+
+ vg_slewf( &skaterift.time_rate, target, vg.time_frame_delta * (1.0f/0.3f) );
+ vg.time_rate = vg_smoothstepf( skaterift.time_rate );
player__pre_update( &localplayer );
- global_skateshop_preupdate();
+ world_entity_focus_preupdate();
+ skaterift_replay_pre_update();
world_update( world_current_instance(), localplayer.rb.co );
audio_ambient_sprites_update( world_current_instance(), localplayer.rb.co );
- //gui_helper_action( localplayer.input_use, "\x7f Hello \x1f""A \x1e\x84" );
+ respawn_chooser_pre_update();
}
-VG_STATIC void vg_update_fixed(void)
-{
+VG_STATIC void vg_fixed_update(void){
if( skaterift.op == k_async_op_clientloading ) return;
world_routes_fixedupdate( world_current_instance() );
vehicle_update_fixed();
}
-VG_STATIC void vg_update_post(void)
-{
+VG_STATIC void vg_post_update(void){
if( skaterift.op == k_async_op_clientloading ) return;
player__post_update( &localplayer );
vg_dsp.echo_distances[sample_index] = dist;
v3f ears = { 1.0f,0.0f,0.0f };
- m3x3_mulv( main_camera.transform, ears, ears );
+ m3x3_mulv( skaterift.cam.transform, ears, ears );
v3_copy( ears, vg_audio.external_listener_ears );
- v3_copy( main_camera.transform[3], vg_audio.external_listener_pos );
+ v3_copy( skaterift.cam.transform[3], vg_audio.external_listener_pos );
if( localplayer.gate_waiting ){
m4x3_mulv( localplayer.gate_waiting->transport,
v3_copy( localplayer.rb.v, vg_audio.external_lister_velocity );
audio_unlock();
- vg.time_rate = 1.0f-menu.factive;
vehicle_update_post();
+
+ if( vg.time - skaterift.last_autosave > 20.0 ){
+ if( skaterift_autosave(1) ){
+ skaterift.last_autosave = vg.time;
+ }
+ }
}
-VG_STATIC void vg_framebuffer_resize( int w, int h )
-{
+/*
+ * RENDERING
+ * ---------------------------------------------------------------------------*/
+
+VG_STATIC void vg_framebuffer_resize( int w, int h ){
render_fb_resize();
}
-VG_STATIC void present_view_with_post_processing(void)
-{
+VG_STATIC void present_view_with_post_processing(void){
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
glViewport( 0,0, vg.window_x, vg.window_y );
(vg.time_frame_delta*60.0) );
shader_blitblur_uInverseRatio( inverse );
- v2f menu_blurring;
- v2_muls( (v2f){ 0.04f, 0.001f }, menu.factive, menu_blurring );
- shader_blitblur_uOverrideDir( menu_blurring );
+ inverse[0] -= 0.0001f;
+ inverse[1] -= 0.0001f;
+ shader_blitblur_uClampUv( inverse );
+
+ static f64 effect_time = 133.0;
+ effect_time += vg.time_frame_delta;
+ shader_blitblur_uTime( effect_time );
+
+ f32 glitch_strength = 0.0f;
+ if( skaterift.activity == k_skaterift_replay ){
+ glitch_strength = 0.005f;
+ if( skaterift.replay_control == k_replay_control_play )
+ glitch_strength = 0.005f;
+ else
+ glitch_strength += 0.005f*skaterift.track_velocity;
+ }
+ shader_blitblur_uGlitchStrength( glitch_strength );
+
+ v2f override;
+ if( skaterift.activity == k_skaterift_menu )
+ v2_muls( (v2f){ 0.04f, 0.001f }, 1.0f-skaterift.time_rate, override );
+ else
+ v2_zero( override );
+ shader_blitblur_uOverrideDir( override );
render_fb_bind_texture( gpipeline.fb_main, 0, 0 );
render_fb_bind_texture( gpipeline.fb_main, 1, 1 );
render_fsquad();
}
-VG_STATIC void render_player_transparent(void)
-{
+VG_STATIC void render_player_transparent(void){
static camera small_cam; /* DOES NOT NEED TO BE STATIC BUT MINGW
SAIS OTHERWISE */
- m4x3_copy( main_camera.transform, small_cam.transform );
+ m4x3_copy( skaterift.cam.transform, small_cam.transform );
- small_cam.fov = main_camera.fov;
+ small_cam.fov = skaterift.cam.fov;
small_cam.nearz = 0.05f;
small_cam.farz = 60.0f;
camera_finalize( &small_cam );
/* Draw player to window buffer and blend background ontop */
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- glViewport( 0,0, vg.window_x, vg.window_y );
player__render( &small_cam, &localplayer );
}
-VG_STATIC void render_scene(void)
-{
- render_fb_bind( gpipeline.fb_main, 1 );
- glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
- glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT );
-
+VG_STATIC void render_scene(void){
/* Draw world */
glEnable( GL_DEPTH_TEST );
return;
}
- for( u32 i=0; i<vg_list_size(world_static.worlds); i++ ){
- if( world_static.worlds[i].status == k_world_status_loaded ){
- world_prerender( &world_static.worlds[i] );
+ for( u32 i=0; i<vg_list_size(world_static.instances); i++ ){
+ if( world_static.instances[i].status == k_world_status_loaded ){
+ world_prerender( &world_static.instances[i] );
}
}
- render_world( view_world, &main_camera, 0 );
-
- render_water_texture( view_world, &main_camera, 0 );
- render_fb_bind( gpipeline.fb_main, 1 );
- render_water_surface( view_world, &main_camera );
+ if( skaterift.activity == k_skaterift_respawning ){
+ glDrawBuffers( 1, (GLenum[]){ GL_COLOR_ATTACHMENT0 } );
+ glClearColor( 0.624f, 0.659f, 0.769f, 0.0f );
+ glClear( GL_COLOR_BUFFER_BIT );
+ glDrawBuffers( 2, (GLenum[]){ GL_COLOR_ATTACHMENT0,
+ GL_COLOR_ATTACHMENT1 } );
+ view_world = &world_static.instances[respawn_chooser.world_id];
+ render_world_override( view_world );
+ }
+ else{
+ render_world( view_world, &skaterift.cam, 0 );
+ render_water_texture( view_world, &skaterift.cam, 0 );
+ render_fb_bind( gpipeline.fb_main, 1 );
+ render_water_surface( view_world, &skaterift.cam );
+ }
}
-VG_STATIC void render_scene_gate_subview(void)
-{
+VG_STATIC void render_scene_gate_subview(void){
render_fb_bind( gpipeline.fb_main, 1 );
world_instance *view_world = localplayer.viewable_world;
if( !view_world ) return; /* ??? */
+ if( skaterift.activity == k_skaterift_respawning ) return;
int depth = 1;
if( localplayer.gate_waiting ) depth = 0;
- render_world_gates( view_world, &main_camera, depth );
+ render_world_gates( view_world, &skaterift.cam, depth );
}
-VG_STATIC void render_main_game(void)
-{
- player__pre_render( &localplayer );
- main_camera.fov = localplayer.cam.fov;
- v3_copy( localplayer.cam.pos, main_camera.pos );
- v3_copy( localplayer.cam.angles, main_camera.angles );
+VG_STATIC void skaterift_composite_maincamera(void){
+ camera_lerp( &localplayer.cam, &world_static.focus_cam,
+ vg_smoothstepf(world_static.focus_strength), &skaterift.cam );
- main_camera.nearz = 0.1f;
- main_camera.farz = 2100.0f;
+ if( skaterift.activity == k_skaterift_replay ){
+ skaterift_get_replay_camera( &skaterift.cam );
+ }
- camera_update_transform( &main_camera );
+ skaterift.cam.nearz = 0.1f;
+ skaterift.cam.farz = 2100.0f;
- if( localplayer.gate_waiting ){
- m3x3_mul( localplayer.basis_gate, main_camera.transform,
- main_camera.transform );
+ if( skaterift.activity == k_skaterift_respawning ){
+ camera_copy( &respawn_chooser.cam, &skaterift.cam );
+ skaterift.cam.nearz = 4.0f;
+ skaterift.cam.farz = 3100.0f;
}
- else{
- m3x3_mul( localplayer.basis, main_camera.transform,
- main_camera.transform );
+
+ camera_update_transform( &skaterift.cam );
+
+ if( skaterift.activity != k_skaterift_respawning ){
+ if( localplayer.gate_waiting ){
+ m3x3_mul( localplayer.basis_gate, skaterift.cam.transform,
+ skaterift.cam.transform );
+ }
+ else{
+ m3x3_mul( localplayer.basis, skaterift.cam.transform,
+ skaterift.cam.transform );
+ }
}
- camera_update_view( &main_camera );
- camera_update_projection( &main_camera );
- camera_finalize( &main_camera );
+ camera_update_view( &skaterift.cam );
+ camera_update_projection( &skaterift.cam );
+ camera_finalize( &skaterift.cam );
+}
- /* ========== Begin Frame ========== */
+VG_STATIC void render_main_game(void){
+ if( skaterift.activity == k_skaterift_replay ){
+ player__animate_from_replay( &localplayer, &skaterift.replay );
+ }
+ else{
+ player__animate( &localplayer );
+ skaterift_record_frame( &skaterift.replay, 0 );
+ }
+ player__pre_render( &localplayer );
- render_scene();
+ skaterift_composite_maincamera();
+
+ /* --------------------------------------------------------------------- */
+
+ world_instance *view_world = localplayer.viewable_world;
+ if( view_world != NULL ){
+ render_world_cubemaps( view_world );
+
+ ent_gate *gate = view_world->rendering_gate;
+ if( gate ){
+ if( gate->flags & k_ent_gate_nonlocal ){
+ world_instance *dest = &world_static.instances[ gate->target ];
+ render_world_cubemaps( dest );
+ }
+ }
+ }
+
+ /* variable res target */
+ render_fb_bind( gpipeline.fb_main, 1 );
+ glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
+ glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT );
+ render_scene();
glEnable( GL_DEPTH_TEST );
- render_player_transparent();
+ /* full res target */
+ glBindFramebuffer( GL_FRAMEBUFFER, 0 );
+ glViewport( 0,0, vg.window_x, vg.window_y );
+
+ render_player_transparent(); /* needs to read the depth buffer before we fuck
+ it up with the oblique rendering inside the
+ portals */
+
+ /* continue with variable rate */
render_scene_gate_subview();
+ /* composite */
present_view_with_post_processing();
- /* =========== End Frame =========== */
+
+ /* --------------------------------------------------------------------- */
+
+ /* capture the current resume frame at the very last point */
+ if( button_down( k_srbind_reset ) ){
+ if( skaterift.activity == k_skaterift_default ){
+ skaterift.activity = k_skaterift_replay;
+ skaterift_record_frame( &skaterift.replay, 1 );
+ if( skaterift.replay.head ){
+ skaterift.replay.cursor = skaterift.replay.head->time;
+ skaterift.replay.cursor_frame = skaterift.replay.head;
+ }
+ skaterift.replay_control = k_replay_control_scrub;
+ }
+ }
}
-VG_STATIC void vg_render(void)
-{
+VG_STATIC void vg_render(void){
if( skaterift.op == k_async_op_clientloading ){
_vg_loader_render();
return;
glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
render_main_game();
-
- m4x4_copy( main_camera.mtx.pv, vg.pv );
+ m4x4_copy( skaterift.cam.mtx.pv, vg.pv );
/* Other shite */
glDisable(GL_BLEND);
gui_draw();
}
-VG_STATIC void vg_gui(void)
-{
+VG_STATIC void vg_gui(void){
if( skaterift.op == k_async_op_clientloading ) return;
menu_update();
- if( menu.active ){
+ if( skaterift.activity == k_skaterift_menu ){
glClear( GL_DEPTH_BUFFER_BIT );
menu_render();
}
player__im_gui( &localplayer );
world_instance *world = world_current_instance();
- replay_imgui( &localplayer );
+ skaterift_replay_imgui();
workshop_form_gui();
render_view_framebuffer_ui();
}