X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=skaterift.c;h=daac040234cbfd89f99c2c063f26a6b159680ba6;hb=38e07d851915d4ea3d25eeb28a3ace78fb0d1c12;hp=f31e1f602e5d811fec8b1e364c8794652dfc362d;hpb=e60af4143b9157e582e28c9dd8580681b3d07ea9;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/skaterift.c b/skaterift.c index f31e1f6..daac040 100644 --- a/skaterift.c +++ b/skaterift.c @@ -2,7 +2,7 @@ * ============================================================================= * * Copyright . . . -----, ,----- ,---. .---. - * 2021-2022 |\ /| | / | | | | /| + * 2021-2023 |\ /| | / | | | | /| * | \ / | +-- / +----- +---' | / | * | \ / | | / | | \ | / | * | \/ | | / | | \ | / | @@ -11,27 +11,37 @@ * ============================================================================= */ +#if 1 + #define SR_NETWORKED +#define VG_DEVWINDOW + #include "common.h" #include "conf.h" #include "steam.h" #include "render.h" #include "audio.h" #include "world.h" +#include "font.h" #include "player.h" + +#include "entity.c" +#include "workshop.c" + #include "network.h" #include "menu.h" +#include "vehicle.h" +#include "pointcloud.h" + +static struct player_avatar localplayer_avatar; +static struct player_model localplayer_models[3]; -static int cl_ui = 1, - cl_view_id = 0, - cl_light_edit = 0; int main( int argc, char *argv[] ) { vg_mem.use_libc_malloc = 0; - vg_set_mem_quota( 128*1024*1024 ); + vg_set_mem_quota( 160*1024*1024 ); vg_enter( argc, argv, "Voyager Game Engine" ); - return 0; } @@ -42,39 +52,14 @@ VG_STATIC void highscores_save_at_exit(void) VG_STATIC void vg_launch_opt(void) { - } VG_STATIC void vg_preload(void) { g_conf_init(); - vg_convar_push( (struct vg_convar){ - .name = "cl_ui", - .data = &cl_ui, - .data_type = k_convar_dtype_i32, - .opt_i32 = { .min=0, .max=1, .clamp=1 }, - .persistent = 0 - }); - - vg_convar_push( (struct vg_convar){ - .name = "cl_view_id", - .data = &cl_view_id, - .data_type = k_convar_dtype_i32, - .opt_i32 = { .min=0, .max=1, .clamp=1 }, - .persistent = 0 - }); - - vg_convar_push( (struct vg_convar){ - .name = "ledit", - .data = &cl_light_edit, - .data_type = k_convar_dtype_i32, - .opt_i32 = { .min=0, .max=1, .clamp=1 }, - .persistent = 0 - }); - vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" ); -vg_info(" 2021-2022 |\\ /| | / | | | | /| \n" ); +vg_info(" 2021-2023 |\\ /| | / | | | | /| \n" ); vg_info(" | \\ / | +-- / +----- +---' | / | \n" ); vg_info(" | \\ / | | / | | \\ | / | \n" ); vg_info(" | \\/ | | / | | \\ | / | \n" ); @@ -92,27 +77,71 @@ vg_info(" ' ' '--' [] '----- '----- ' ' '---' " vg_loader_step( network_init, network_end ); } +VG_STATIC void load_playermodels(void) +{ + player_model_load( &localplayer_models[0], "models/ch_new.mdl" ); + player_model_load( &localplayer_models[1], "models/ch_outlaw.mdl" ); + player_model_load( &localplayer_models[2], "models/ch_jordan.mdl" ); + + /* FIXME: hack */ + shader_model_character_view_register(); + shader_model_board_view_register(); + shader_model_entity_register(); +} + +void temp_update_playermodel(void){ + player__use_model( &localplayer, &localplayer_models[cl_playermdl_id] ); +} + +VG_STATIC void async_skaterift_complete( void *payload, u32 size ) +{ + localplayer.viewable_world = get_active_world(); + localplayer_cmd_respawn( 1, (const char *[]){ "start" } ); + + skaterift_end_op(); +} + 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( menu_init, NULL ); + vg_loader_step( pointcloud_init, NULL ); vg_loader_step( world_init, NULL ); + vg_loader_step( vehicle_init, NULL ); + vg_loader_step( font3d_init, NULL ); + + font3d_load( &world_global.font, "models/rs_font.mdl", vg_mem.rtmemory ); + vg_loader_step( player_init, NULL ); + vg_loader_step( player_ragdoll_init, NULL ); + vg_loader_step( workshop_init, NULL ); + vg_loader_step( skateshop_init, NULL ); + + /* ----------------- */ + vg_loader_step( load_playermodels, NULL ); + + /* player setup */ + player__create( &localplayer ); + player_avatar_load( &localplayer_avatar, "models/ch_new.mdl" ); + player__use_avatar( &localplayer, &localplayer_avatar ); + player__use_model( &localplayer, &localplayer_models[cl_playermdl_id] ); + player__bind( &localplayer ); + + /* --------------------- */ vg_bake_shaders(); vg_loader_step( audio_init, audio_free ); - world_audio_init(); /* 'systems' are completely loaded now */ - strcpy( world.world_name, "maps/mp_mtzero.mdl" ); - strcpy( world.world_name, "maps/mp_gridmap.mdl" ); - world_load(); + /* load home/permanent world */ + world_load( 0, "maps/mp_spawn.mdl" ); + vg_console_load_autos(); -} + menu_link(); -VG_STATIC void vg_start(void) -{ - reset_player( 1, (const char *[]){ "start" } ); + vg_async_call( async_skaterift_complete, NULL, 0 ); } VG_STATIC void draw_origin_axis(void) @@ -122,35 +151,65 @@ VG_STATIC void draw_origin_axis(void) vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 0.0f, 0.0f, 1.0f }, 0xff0000ff ); } +static void skaterift_change_world_preupdate(void); VG_STATIC void vg_update(void) { steam_update(); + skaterift_preupdate_inputs(); + if( skaterift.async_op == k_async_op_clientloading ) return; + if( skaterift.async_op == k_async_op_world_preloading ){ + skaterift_change_world_preupdate(); + } - if( vg.is_loaded ) - { - draw_origin_axis(); - network_update(); + draw_origin_axis(); + network_update(); + + player__pre_update( &localplayer ); + global_skateshop_preupdate(); - player_update_pre(); - world_update( player.phys.rb.co ); - } + world_update( get_active_world(), localplayer.rb.co ); + audio_ambient_sprites_update( get_active_world(), localplayer.rb.co ); + //gui_helper_action( localplayer.input_use, "\x7f Hello \x1f""A \x1e\x84" ); } VG_STATIC void vg_update_fixed(void) { - if( vg.is_loaded ) - { - player_update_fixed(); - } + if( skaterift.async_op == k_async_op_clientloading ) return; + + world_routes_fixedupdate( get_active_world() ); + player__update( &localplayer ); + vehicle_update_fixed(); } VG_STATIC void vg_update_post(void) { - if( vg.is_loaded ) - { - player_update_post(); - menu_update(); + if( skaterift.async_op == k_async_op_clientloading ) return; + + player__post_update( &localplayer ); + + float dist; + int sample_index; + world_audio_sample_distances( localplayer.rb.co, &sample_index, &dist ); + + audio_lock(); + vg_dsp.echo_distances[sample_index] = dist; + + v3f ears = { 1.0f,0.0f,0.0f }; + m3x3_mulv( main_camera.transform, ears, ears ); + v3_copy( ears, vg_audio.external_listener_ears ); + v3_copy( main_camera.transform[3], vg_audio.external_listener_pos ); + + if( localplayer.gate_waiting ){ + m4x3_mulv( localplayer.gate_waiting->transport, + vg_audio.external_listener_pos, + vg_audio.external_listener_pos ); } + + v3_copy( localplayer.rb.v, vg_audio.external_lister_velocity ); + audio_unlock(); + + vg.time_rate = 1.0f-menu.factive; + vehicle_update_post(); } VG_STATIC void vg_framebuffer_resize( int w, int h ) @@ -161,36 +220,35 @@ VG_STATIC void vg_framebuffer_resize( int w, int h ) VG_STATIC void present_view_with_post_processing(void) { glBindFramebuffer( GL_FRAMEBUFFER, 0 ); + glViewport( 0,0, vg.window_x, vg.window_y ); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA); glBlendEquation(GL_FUNC_ADD); - if( cl_blur ) - { + v2f inverse; + render_fb_inverse_ratio( gpipeline.fb_main, inverse ); + + if( cl_blur ){ shader_blitblur_use(); shader_blitblur_uTexMain( 0 ); shader_blitblur_uTexMotion( 1 ); - shader_blitblur_uBlurStrength(cl_blur_strength / (vg.frame_delta*60.0f)); + shader_blitblur_uBlurStrength( cl_blur_strength / + (vg.time_frame_delta*60.0) ); + shader_blitblur_uInverseRatio( inverse ); v2f menu_blurring; - v2_muls( (v2f){ 0.04f, 0.001f }, menu_opacity, menu_blurring ); + v2_muls( (v2f){ 0.04f, 0.001f }, menu.factive, menu_blurring ); shader_blitblur_uOverrideDir( menu_blurring ); - if( cl_view_id == 0 ) - render_fb_bind_texture( gpipeline.fb_main, 0, 0 ); - else if( cl_view_id == 1 ) - render_fb_bind_texture( gpipeline.fb_main, 1, 0 ); - else - render_fb_bind_texture( gpipeline.fb_main, 0, 0 ); - + render_fb_bind_texture( gpipeline.fb_main, 0, 0 ); render_fb_bind_texture( gpipeline.fb_main, 1, 1 ); } - else - { + else{ shader_blit_use(); shader_blit_uTexMain( 0 ); + shader_blit_uInverseRatio( inverse ); render_fb_bind_texture( gpipeline.fb_main, 0, 0 ); } @@ -213,58 +271,72 @@ VG_STATIC void render_player_transparent(void) camera_finalize( &small_cam ); /* Draw player to window buffer and blend background ontop */ - glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - draw_player( &small_cam ); + 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 ); + 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 ); + glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT ); /* Draw world */ glEnable( GL_DEPTH_TEST ); - render_world( &main_camera ); + world_instance *view_world = localplayer.viewable_world; - int player_transparent = !(player.is_dead || freecam), - player_draw = !cl_menu; + if( view_world == NULL ){ + glClearColor( 0.25f, 0.25f, 0.0f, 1.0f ); + glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT ); + return; + } - if( !player_transparent && player_draw ) - draw_player( &main_camera ); + for( u32 i=0; ig_ambient_colour }; + menu_update(); + if( menu.active ){ + glClear( GL_DEPTH_BUFFER_BIT ); + menu_render(); + } - struct ui_slider - s8 = { .min=0.0f, .max=2.0f, .data = &gpipeline.shadow_spread }, - s9 = { .min=0.0f, .max=25.0f, .data = &gpipeline.shadow_length }; +#if 0 + player__im_gui( &localplayer ); +#endif + world_instance *world = get_active_world(); - for( int i=0; i<3; i++ ) - run_light_widget( &gpipeline.widgets[i] ); - - ui_text( vg_uictx.cursor, "Ambient", 1, 0 ); - vg_uictx.cursor[1] += 16; - ui_slider_vector( &s5 ); + workshop_form_gui(); + render_view_framebuffer_ui(); +} - ui_text( vg_uictx.cursor, "Shadows", 1, 0 ); - vg_uictx.cursor[1] += 16; - ui_slider( &s8 ); - ui_slider( &s9 ); +static void async_skaterift_world_loaded( void *payload, u32 size ) +{ + skaterift_end_op(); +} - ui_text( vg_uictx.cursor, "Misc", 1, 0 ); - vg_uictx.cursor[1] += 16; - struct ui_checkbox c1 = {.data = &wl->g_light_preview}; - ui_checkbox( &c1 ); +static void skaterift_world_changer_thread( void *data ) +{ + const char *path = data; + world_load( 1, world_global.load_target ); + vg_async_call( async_skaterift_world_loaded, NULL, 0 ); +} - render_update_lighting_ub(); - } - - //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); - if( cl_ui ) - { - render_world_routes_ui(); +/* holding pattern before we can start loading the new world, since we might be + * waiting for audio to stop */ +static void skaterift_change_world_preupdate(void) +{ + for( u32 i=1; istatus == k_world_status_unloading ){ + if( world_freeable( inst ) ){ + world_free( inst ); + } + return; + } } - //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); - - audio_debug_soundscapes(); - render_view_framebuffer_ui(); + + vg_info( "worlds cleared, begining load\n" ); + skaterift_shift_op( k_async_op_world_loading ); + + /* finally can start the loader */ + vg_loader_start( skaterift_world_changer_thread, NULL ); } -VG_STATIC void run_light_widget( struct light_widget *lw ) +/* places all loaded worlds into unloading state */ +static void skaterift_change_world( const char *world_path ) { - struct ui_checkbox c1 = { .data=&lw->enabled }; + vg_info( "switching to %s\n", world_path ); - ui_checkbox( &c1 ); - - if( lw->enabled ) - { - struct ui_slider_vector - colour = { .min=0.0f, .max=2.0f, .len=3, .data=lw->colour }, - dir = { .min=-VG_PIf, .max=VG_PIf, .len=2, .data=lw->dir }; - - ui_slider_vector( &colour ); - vg_uictx.cursor[1] += 4; - ui_slider_vector( &dir ); + if( world_global.active_world != 0 ){ + vg_error( "Cannot change worlds while in non-root world\n" ); } -} + else{ + skaterift_begin_op( k_async_op_world_preloading ); -VG_STATIC void run_debug_info(void) -{ - char buf[40]; - - snprintf( buf, 40, "%.2fm/s", v3_length( player.phys.rb.v ) ); - ui_text( (ui_px [2]){ 0, 0 }, buf, 1, k_text_align_left ); - - snprintf( buf, 40, "%.2f %.2f %.2f m/s", - player.phys.a[0], player.phys.a[1], player.phys.a[2] ); - ui_text( (ui_px [2]){ 0, 20 }, buf, 1, k_text_align_left ); - - snprintf( buf, 40, "pos %.2f %.2f %.2f", - player.phys.rb.co[0], player.phys.rb.co[1], player.phys.rb.co[2] ); - ui_text( (ui_px [2]){ 0, 40 }, buf, 1, k_text_align_left ); - - if( vg_input.controller_handle ) - { - for( int i=0; istatus == k_world_status_loaded ){ + inst->status = k_world_status_unloading; + world_fadeout_audio( inst ); + } } } - else - { - ui_text( (ui_px [2]){ 0, 60 }, - "Gamepad not ready", 1, k_text_align_left ); - } } + +static int skaterift_change_world_command( int argc, const char *argv[] ) +{ + if( argc == 1 ) + skaterift_change_world( argv[0] ); + + return 0; +} + +#else + +#include "skaterift_imgui_dev.c" + +#endif