X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=skaterift.c;h=2edd7dc5231a84d5fa148270f815b124dbeb2e2b;hb=a8ba9cc44e1ae9aeca62fb579a3105c625e59133;hp=21a7981793ba6ccd6149de3a5aaaccb483ecdf0d;hpb=a1741ec4aed057cbafff2d6bc9e5cf8a15ae322b;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/skaterift.c b/skaterift.c index 21a7981..2edd7dc 100644 --- a/skaterift.c +++ b/skaterift.c @@ -2,67 +2,63 @@ * ============================================================================= * * Copyright . . . -----, ,----- ,---. .---. - * 2021-2022 |\ /| | / | | | | /| + * 2021-2023 |\ /| | / | | | | /| * | \ / | +-- / +----- +---' | / | * | \ / | | / | | \ | / | * | \/ | | / | | \ | / | * ' ' '--' [] '----- '----- ' ' '---' SOFTWARE * * ============================================================================= - * - * register: shader register & init scheduling - * init: initialization - * update: logic - * render: graphics - * free: resource free - * */ -#define VG_3D -#define VG_STATIC static -//#define VG_STATIC - -//#define VG_MINIMAL_TEST -#ifndef VG_MINIMAL_TEST +#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" + +static struct player_avatar localplayer_avatar; +static struct player_model localplayer_models[3]; -static int cl_ui = 1; 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; } -VG_STATIC void highscores_save_at_exit(void*_) +VG_STATIC void highscores_save_at_exit(void) { highscores_serialize_all(); } -VG_STATIC void vg_preload(void) +VG_STATIC void vg_launch_opt(void) { +} - 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 = 1 - }); +VG_STATIC void vg_preload(void) +{ + g_conf_init(); vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" ); -vg_info(" 2021-2022 |\\ /| | / | | | | /| \n" ); +vg_info(" 2021-2023 |\\ /| | / | | | | /| \n" ); vg_info(" | \\ / | +-- / +----- +---' | / | \n" ); vg_info(" | \\ / | | / | | \\ | / | \n" ); vg_info(" | \\/ | | / | | \\ | / | \n" ); @@ -73,35 +69,77 @@ vg_info(" ' ' '--' [] '----- '----- ' ' '---' " if( !highscores_read() ) highscores_create_db(); - vg_loader_highwater( NULL, highscores_save_at_exit, NULL ); - - //vg_sleep_ms(200); + vg_loader_step( NULL, highscores_save_at_exit ); steam_init(); - vg_loader_highwater( NULL, steam_end, NULL ); - vg_loader_highwater( network_init, network_end, NULL ); + vg_loader_step( NULL, steam_end ); + 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_loader_highwater( render_init, NULL, NULL ); - vg_loader_highwater( menu_init, NULL, NULL ); - vg_loader_highwater( world_init, NULL, NULL ); - vg_loader_highwater( player_init, NULL, NULL ); + 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( 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_highwater( audio_init, audio_free, NULL ); - world_audio_init(); + vg_loader_step( audio_init, audio_free ); /* 'systems' are completely loaded now */ - strcpy( world.world_name, "models/mp_dev.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) @@ -111,319 +149,330 @@ VG_STATIC void draw_origin_axis(void) vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 0.0f, 0.0f, 1.0f }, 0xff0000ff ); } -VG_STATIC void vg_update( int loaded ) +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( 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( int loaded ) +VG_STATIC void vg_update_fixed(void) { - if( 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( int loaded ) +VG_STATIC void vg_update_post(void) { - if( 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 ) { render_fb_resize(); - water_fb_resize(); } -VG_STATIC void render_main_game(void) +VG_STATIC void present_view_with_post_processing(void) { - m4x4f world_4x4; - m4x3_expand( camera_mtx_inverse, world_4x4 ); + glBindFramebuffer( GL_FRAMEBUFFER, 0 ); + glViewport( 0,0, vg.window_x, vg.window_y ); - static float fov = 97.0f; + glEnable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA); + glBlendEquation(GL_FUNC_ADD); - float fov_target = 108.0f; - if( player.phys.on_board ) - fov_target = 118.0f; + v2f inverse; + render_fb_inverse_ratio( gpipeline.fb_main, inverse ); - if( cl_menu ) - fov_target = menu_fov_target; + if( cl_blur ){ + shader_blitblur_use(); + shader_blitblur_uTexMain( 0 ); + shader_blitblur_uTexMotion( 1 ); + shader_blitblur_uBlurStrength( cl_blur_strength / + (vg.time_frame_delta*60.0) ); + shader_blitblur_uInverseRatio( inverse ); - fov = vg_lerpf( fov, fov_target, vg.frame_delta * 2.0f ); + v2f menu_blurring; + v2_muls( (v2f){ 0.04f, 0.001f }, menu.factive, menu_blurring ); + shader_blitblur_uOverrideDir( menu_blurring ); - gpipeline.fov = freecam? 60.0f: fov; /* 120 */ - m4x4_projection( vg.pv, gpipeline.fov, - (float)vg.window_x / (float)vg.window_y, - 0.1f, 2100.0f ); + render_fb_bind_texture( gpipeline.fb_main, 0, 0 ); + render_fb_bind_texture( gpipeline.fb_main, 1, 1 ); + } + else{ + shader_blit_use(); + shader_blit_uTexMain( 0 ); + shader_blit_uInverseRatio( inverse ); + render_fb_bind_texture( gpipeline.fb_main, 0, 0 ); + } - m4x4_mul( vg.pv, world_4x4, vg.pv ); - glEnable( GL_DEPTH_TEST ); - - /* - * Draw world - */ + render_fsquad(); +} + +VG_STATIC void render_player_transparent(void) +{ + static camera small_cam; /* DOES NOT NEED TO BE STATIC BUT MINGW + SAIS OTHERWISE */ - int draw_solid = player.is_dead | freecam; - render_world( vg.pv, camera_mtx ); + m4x3_copy( main_camera.transform, small_cam.transform ); - if( draw_solid ) - draw_player( camera_mtx ); + small_cam.fov = main_camera.fov; + small_cam.nearz = 0.05f; + small_cam.farz = 60.0f; - render_water_texture( camera_mtx ); + camera_update_view( &small_cam ); + camera_update_projection( &small_cam ); + camera_finalize( &small_cam ); + /* Draw player to window buffer and blend background ontop */ glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - render_water_surface( vg.pv, camera_mtx ); - render_world_gates( vg.pv, player.phys.rb.co, camera_mtx ); + glViewport( 0,0, vg.window_x, vg.window_y ); + player__render( &small_cam, &localplayer ); +} - if( cl_menu ) - { - glClear( GL_DEPTH_BUFFER_BIT ); - menu_render( vg.pv ); +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 ); + + /* Draw world */ + glEnable( GL_DEPTH_TEST ); + + world_instance *view_world = localplayer.viewable_world; + + 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; } - - /* Copy the RGB of what we have into the background buffer */ - glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 ); - glBindFramebuffer( GL_DRAW_FRAMEBUFFER, gpipeline.fb_background ); - glBlitFramebuffer( 0,0, vg.window_x, vg.window_y, - 0,0, vg.window_x, vg.window_y, - GL_COLOR_BUFFER_BIT, - GL_LINEAR ); - - /* Clear out the colour buffer, but keep depth */ - glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); - if( !player.is_dead ) - glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ); - else - glClear( GL_COLOR_BUFFER_BIT ); - - if( !draw_solid ) - { - m4x4_projection( vg.pv, gpipeline.fov, - (float)vg.window_x / (float)vg.window_y, - 0.05f, 60.0f ); - m4x4_mul( vg.pv, world_4x4, vg.pv ); - draw_player( camera_mtx ); + for( u32 i=0; ig_ambient_colour }; - - 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 }; - - for( int i=0; i<3; i++ ) - run_light_widget( &gpipeline.widgets[i] ); - - gui_text( ui_global_ctx.cursor, "Ambient", 1, 0 ); - ui_global_ctx.cursor[1] += 16; - ui_slider_vector( &ui_global_ctx, &s5 ); - - gui_text( ui_global_ctx.cursor, "Shadows", 1, 0 ); - ui_global_ctx.cursor[1] += 16; - ui_slider( &ui_global_ctx, &s8 ); - ui_slider( &ui_global_ctx, &s9 ); - - gui_text( ui_global_ctx.cursor, "Misc", 1, 0 ); - ui_global_ctx.cursor[1] += 16; - struct ui_checkbox c1 = {.data = &wl->g_light_preview}; - ui_checkbox( &ui_global_ctx, &c1 ); - - render_update_lighting_ub(); - } -#endif - - //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); - if( cl_ui ) - { - render_world_routes_ui(); + if( skaterift.async_op == k_async_op_clientloading ) return; + + menu_update(); + if( menu.active ){ + glClear( GL_DEPTH_BUFFER_BIT ); + menu_render(); } - //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); - - audio_debug_soundscapes(); -} #if 0 -VG_STATIC void run_light_widget( struct light_widget *lw ) -{ - struct ui_checkbox c1 = { .data=&lw->enabled }; - - ui_checkbox( &ui_global_ctx, &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( &ui_global_ctx, &colour ); - ui_global_ctx.cursor[1] += 4; - ui_slider_vector( &ui_global_ctx, &dir ); - } -} + player__im_gui( &localplayer ); #endif + world_instance *world = get_active_world(); -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.gamepad_ready ) - { - for( int i=0; i<6; i++ ) - { - snprintf( buf, 40, "%.2f", vg.gamepad.axes[i] ); - ui_text( (ui_px [2]){ 0, (i+3)*20 }, buf, 1, k_text_align_left ); - } - } - else - { - ui_text( (ui_px [2]){ 0, 60 }, - "Gamepad not ready", 1, k_text_align_left ); - } + workshop_form_gui(); + render_view_framebuffer_ui(); } -#else - -#define VG_TIMESTEP_FIXED (1.0/60.0) -#define VG_3D -#define VG_FRAMEBUFFER_RESIZE 1 -#include "vg/vg.h" - -int main( int argc, char *argv[] ) +static void async_skaterift_world_loaded( void *payload, u32 size ) { - vg_prealloc_quota( 512*1024*1024 ); - vg_enter( argc, argv, "Voyager Game Engine" ); + skaterift_end_op(); } -VG_STATIC void vg_preload(void) +static void skaterift_world_changer_thread( void *data ) { -vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" ); -vg_info(" 2021-2022 |\\ /| | / | | | | /| \n" ); -vg_info(" | \\ / | +-- / +----- +---' | / | \n" ); -vg_info(" | \\ / | | / | | \\ | / | \n" ); -vg_info(" | \\/ | | / | | \\ | / | \n" ); -vg_info(" ' ' '--' [] '----- '----- ' ' '---' " - "SOFTWARE\n" ); + const char *path = data; + world_load( 1, world_global.load_target ); + vg_async_call( async_skaterift_world_loaded, NULL, 0 ); } -VG_STATIC void vg_load(void) +/* 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) { - vg_bake_shaders(); - vg_console_load_autos(); -} + for( u32 i=1; istatus == k_world_status_unloading ){ + if( world_freeable( inst ) ){ + world_free( inst ); + } + return; + } + } -VG_STATIC void vg_start(void) -{ -} + vg_info( "worlds cleared, begining load\n" ); + skaterift_shift_op( k_async_op_world_loading ); -VG_STATIC void vg_update( int loaded ) -{ + /* finally can start the loader */ + vg_loader_start( skaterift_world_changer_thread, NULL ); } -VG_STATIC void vg_update_fixed( int loaded ) +/* places all loaded worlds into unloading state */ +static void skaterift_change_world( const char *world_path ) { -} + vg_info( "switching to %s\n", world_path ); -VG_STATIC void vg_update_post( int loaded ) -{ -} - -VG_STATIC void vg_framebuffer_resize( int w, int h ) -{ + 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_linear_clear( vg_mem.scratch ); + world_global.load_target = vg_linear_alloc( vg_mem.scratch, 1024 ); + vg_strncpy( world_path, world_global.load_target, + 1024, k_strncpy_overflow_fatal ); + + vg_info( "unloading old worlds\n" ); + world_unlink_nonlocal( &world_global.worlds[0] ); + + for( u32 i=1; istatus == k_world_status_loaded ){ + inst->status = k_world_status_unloading; + world_fadeout_audio( inst ); + } + } + } } -VG_STATIC void vg_render(void) +static int skaterift_change_world_command( int argc, const char *argv[] ) { - glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - glViewport( 0,0, vg.window_x, vg.window_y ); - glDisable( GL_DEPTH_TEST ); + if( argc == 1 ) + skaterift_change_world( argv[0] ); - glClearColor( 0.11f, 0.35f, 0.37f, 1.0f ); - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); - - /* Other shite */ - glDisable(GL_BLEND); - glDisable( GL_DEPTH_TEST ); - vg_lines_drawall( (float *)vg.pv ); - glViewport( 0,0, vg.window_x, vg.window_y ); + return 0; } -VG_STATIC void vg_ui(void) -{ -} +#else + +#include "skaterift_imgui_dev.c" #endif