X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=skaterift.c;h=eb69bc7c18a1af50a71d3a9001044a3dcc9b8c3f;hb=6b9993651343af73bd48e2213910bbaadb41edaf;hp=1db6db52ab3e8c4d939f4ea91d1a9cee95dd3557;hpb=72c40f1bc7a732f6a628dbf8a4135ac0bf3efa4e;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/skaterift.c b/skaterift.c index 1db6db5..eb69bc7 100644 --- a/skaterift.c +++ b/skaterift.c @@ -12,40 +12,37 @@ */ #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" -static player_instance localplayer; + VG_STATIC struct player_avatar localplayer_avatar; VG_STATIC glmesh localplayer_meshes[3]; vg_tex2d localplayer_texture = { .path = "textures/ch_gradient.qoi" }; -player_instance *tmp_localplayer(void) -{ - return &localplayer; -} - #include "network.h" #include "menu.h" #include "vehicle.h" -static int cl_ui = 1, - cl_view_id = 0, - cl_light_edit = 0; +#define DEV_AARON +#ifdef DEV_AARON +static rb_object aaron={ + .type=k_rb_shape_box, + .rb.bbx = {{ -2.0f, -1.0f, -1.0f }, { 2.0f, 1.0f, 1.0f }} +}; +#endif 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; } @@ -56,106 +53,14 @@ VG_STATIC void highscores_save_at_exit(void) VG_STATIC void vg_launch_opt(void) { - -} - -VG_STATIC int __kill( int argc, const char *argv[] ) -{ -#if 0 - player_use_device( &localplayer, &player_device_dead, &localplayer_dead ); -#endif - return 0; -} - -VG_STATIC int __respawn( int argc, const char *argv[] ) -{ - ent_spawn *rp = NULL, *r; - world_instance *world = get_active_world(); - - if( argc == 1 ){ - for( u32 i=0; ient_spawn); i++ ){ - r = mdl_arritm( &world->ent_spawn, i ); - if( !strcmp( mdl_pstr(&world->meta, r->pstr_name),argv[0] ) ){ - rp = r; - break; - } - } - - if( !rp ) - vg_warn( "No spawn named '%s'\n", argv[0] ); - } - - if( !rp ){ - float min_dist = INFINITY; - - for( u32 i=0; ient_spawn); i++ ){ - r = mdl_arritm( &world->ent_spawn, i ); - float d = v3_dist2( r->transform.co, localplayer.rb.co ); - - if( d < min_dist ){ - min_dist = d; - rp = r; - } - } - } - - if( !rp ){ - vg_error( "No spawn found\n" ); - - if( !mdl_arrcount(&world->ent_spawn) ) - return 0; - - rp = mdl_arritm( &world->ent_spawn, 0 ); - } - - player__spawn( &localplayer, rp ); - return 1; } VG_STATIC void vg_preload(void) { g_conf_init(); - common_var_temp(); - - vg_var_push( (struct vg_var){ - .name = "cl_ui", - .data = &cl_ui, - .data_type = k_var_dtype_i32, - .opt_i32 = { .min=0, .max=1, .clamp=1 }, - .persistent = 0 - }); - - vg_var_push( (struct vg_var){ - .name = "cl_view_id", - .data = &cl_view_id, - .data_type = k_var_dtype_i32, - .opt_i32 = { .min=0, .max=1, .clamp=1 }, - .persistent = 0 - }); - - vg_var_push( (struct vg_var){ - .name = "ledit", - .data = &cl_light_edit, - .data_type = k_var_dtype_i32, - .opt_i32 = { .min=0, .max=1, .clamp=1 }, - .persistent = 0 - }); - - vg_function_push( (struct vg_cmd) { - .name = "respawn", - .function = __respawn, - //.poll_suggest = reset_player_poll - }); - - vg_function_push( (struct vg_cmd) { - .name = "ded", - .function = __kill, - //.poll_suggest = reset_player_poll - }); - vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" ); -vg_info(" 2021-2022 |\\ /| | / | | | | /| \n" ); +vg_info(" 2021-2023 |\\ /| | / | | | | /| \n" ); vg_info(" | \\ / | +-- / +----- +---' | / | \n" ); vg_info(" | \\ / | | / | | \\ | / | \n" ); vg_info(" | \\/ | | / | | \\ | / | \n" ); @@ -171,6 +76,14 @@ vg_info(" ' ' '--' [] '----- '----- ' ' '---' " steam_init(); vg_loader_step( NULL, steam_end ); vg_loader_step( network_init, network_end ); + +#ifdef DEV_AARON + q_identity( aaron.rb.q ); + v3_zero( aaron.rb.w ); + v3_zero( aaron.rb.co ); + v3_zero( aaron.rb.v ); + rb_init_object( &aaron ); +#endif } VG_STATIC void load_playermodels(void) @@ -226,10 +139,13 @@ VG_STATIC void vg_load(void) vg_loader_step( render_init, NULL ); vg_loader_step( menu_init, NULL ); vg_loader_step( world_init, NULL ); - //vg_loader_step( player_init, NULL ); - //vg_loader_step( vehicle_init, NULL ); - // - //vg_loader_step( player_model_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( load_playermodels, NULL ); @@ -250,7 +166,8 @@ VG_STATIC void vg_load(void) /* 'systems' are completely loaded now */ /* load home world */ - world_load( &world_global.worlds[0], "maps/mp_mtzero.mdl" ); + world_load( 0, "maps/mp_spawn.mdl" ); + world_load( 1, "maps/mp_mtzero.mdl" ); #if 0 world_load( &world_global.worlds[1], "maps/mp_gridmap.mdl" ); @@ -264,7 +181,8 @@ VG_STATIC void vg_load(void) VG_STATIC void vg_start(void) { - __respawn( 1, (const char *[]){ "start" } ); + localplayer.viewable_world = get_active_world(); + localplayer_cmd_respawn( 1, (const char *[]){ "start" } ); } VG_STATIC void draw_origin_axis(void) @@ -278,132 +196,67 @@ VG_STATIC void vg_update(void) { steam_update(); - if( vg.is_loaded ) - { + if( vg.is_loaded ){ draw_origin_axis(); network_update(); -#if 0 - if( !gzoomer.inside ) - player_update_pre(); -#endif - player__pre_update( &localplayer ); - world_update( get_active_world(), localplayer.rb.co ); - audio_update(); + world_update( get_active_world(), localplayer.rb.co ); + audio_ambient_sprites_update( get_active_world(), localplayer.rb.co ); } } VG_STATIC void vg_update_fixed(void) { - if( vg.is_loaded ) - { -#if 0 - if( !gzoomer.inside ) - player_update_fixed(); + if( vg.is_loaded ){ + world_routes_fixedupdate( get_active_world() ); + player__update( &localplayer ); vehicle_update_fixed(); -#endif - player__update( &localplayer ); - } -} +#ifdef DEV_AARON + world_instance *world = get_active_world(); + rb_solver_reset(); + rb_ct *buf = rb_global_buffer(); -VG_STATIC void vg_update_post(void) -{ - if( vg.is_loaded ) - { -#if 0 - if( gzoomer.inside ) - { - vehicle_camera(); - } - else - { - player_update_post(); + int l = rb_box__scene( aaron.rb.to_world, aaron.rb.bbx, + NULL, &world->rb_geo.inf.scene, buf ); + for( int j=0; jrb_geo.rb; } -#endif - - player__post_update( &localplayer ); + rb_contact_count += l; + rb_presolve_contacts( rb_contact_buffer, rb_contact_count ); - - float inr3 = 0.57735027, - inr2 = 0.70710678118; - - v3f sample_directions[] = { - { -1.0f, 0.0f, 0.0f }, - { 1.0f, 0.0f, 0.0f }, - { 0.0f, 0.0f, 1.0f }, - { 0.0f, 0.0f, -1.0f }, - { 0.0f, 1.0f, 0.0f }, - { 0.0f, -1.0f, 0.0f }, - { -inr3, inr3, inr3 }, - { inr3, inr3, inr3 }, - { -inr3, inr3, -inr3 }, - { inr3, inr3, -inr3 }, - { -inr2, 0.0f, inr2 }, - { inr2, 0.0f, inr2 }, - { -inr2, 0.0f, -inr2 }, - { inr2, 0.0f, -inr2 }, - }; - - static int si = 0; - static float distances[16]; - - ray_hit ray; - ray.dist = 5.0f; - - v3f rc, rd, ro; - v3_copy( sample_directions[ si ], rd ); - v3_add( localplayer.rb.co, (v3f){0.0f,1.5f,0.0f}, ro ); - v3_copy( ro, rc ); - - float dist = 200.0f; - - for( int i=0; i<10; i++ ){ - if( ray_world( get_active_world(), rc, rd, &ray ) ){ - dist = (float)i*5.0f + ray.dist; - break; - } - else{ - v3_muladds( rc, rd, ray.dist, rc ); - } + for( int j=0; j<8; j++ ){ + rb_solve_contacts( rb_contact_buffer, rb_contact_count ); } - distances[si] = dist; - - - for( int i=0; i<14; i++ ){ - if( distances[i] != 200.0f ){ - u32 colours[] = { VG__RED, VG__BLUE, VG__GREEN, - VG__CYAN, VG__YELOW, VG__PINK, - VG__WHITE }; - - u32 colour = colours[i%7]; + rb_iter( &aaron.rb ); + rb_update_transform( &aaron.rb ); +#endif - v3f p1; - v3_muladds( ro, sample_directions[i], distances[i], p1 ); - vg_line( ro, p1, colour ); - vg_line_pt3( p1, 0.1f, colour ); - } - } + } +} - si ++; - if( si >= 14 ) - si = 0; +VG_STATIC void vg_update_post(void) +{ + if( vg.is_loaded ){ + player__post_update( &localplayer ); + float dist; + int sample_index; + world_audio_sample_distances( localplayer.rb.co, &sample_index, &dist ); - /* FIXME: TEMP */ audio_lock(); - vg_dsp.echo_distances[si] = dist; + 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 ); - /* TODO: this is transformed back and fourth twice. */ if( localplayer.gate_waiting ){ m4x3_mulv( localplayer.gate_waiting->transport, vg_audio.external_listener_pos, @@ -414,8 +267,20 @@ VG_STATIC void vg_update_post(void) audio_unlock(); menu_update(); -#if 0 vehicle_update_post(); + +#ifdef DEV_AARON + SDL_Scancode sc = SDL_GetScancodeFromKey( SDLK_q ); + if( vg_input.sdl_keys[sc] ){ + m4x3_mulv( main_camera.transform, (v3f){0.0f,0.0f,-3.0f}, + aaron.rb.co ); + + v3_zero( aaron.rb.v ); + v3_zero( aaron.rb.w ); + rb_update_transform( &aaron.rb ); + } + + rb_object_debug( &aaron, VG__PINK ); #endif } } @@ -428,34 +293,34 @@ 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); + 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_uInverseRatio( inverse ); v2f menu_blurring; v2_muls( (v2f){ 0.04f, 0.001f }, menu_opacity, 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{ shader_blit_use(); shader_blit_uTexMain( 0 ); + shader_blit_uInverseRatio( inverse ); render_fb_bind_texture( gpipeline.fb_main, 0, 0 ); } @@ -479,12 +344,13 @@ VG_STATIC void render_player_transparent(void) /* 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 ); + 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 ); @@ -499,19 +365,22 @@ VG_STATIC void render_scene(void) return; } + world_prerender( view_world ); render_world( view_world, &main_camera, 0 ); - render_water_texture( view_world, &main_camera, 0 ); - render_fb_bind( gpipeline.fb_main ); + render_fb_bind( gpipeline.fb_main, 1 ); render_water_surface( view_world, &main_camera ); +} + +VG_STATIC void render_scene_gate_subview(void) +{ + render_fb_bind( gpipeline.fb_main, 1 ); + world_instance *view_world = localplayer.viewable_world; int depth = 1; if( localplayer.gate_waiting ) depth = 0; render_world_gates( view_world, &main_camera, depth ); - - if( !cl_menu ) - render_player_transparent(); } VG_STATIC void render_main_game(void) @@ -567,12 +436,14 @@ VG_STATIC void render_main_game(void) render_scene(); if( cl_menu ) { - glClear( GL_DEPTH_BUFFER_BIT ); + //glClear( GL_DEPTH_BUFFER_BIT ); menu_render_bg(); glEnable( GL_DEPTH_TEST ); - render_player_transparent(); } + render_player_transparent(); + render_scene_gate_subview(); + present_view_with_post_processing(); if( cl_menu ) @@ -602,7 +473,6 @@ VG_STATIC void vg_render(void) glViewport( 0,0, vg.window_x, vg.window_y ); } -VG_STATIC void run_light_widget( struct light_widget *lw ); VG_STATIC void vg_ui(void) { #if 0 @@ -610,98 +480,6 @@ VG_STATIC void vg_ui(void) #endif world_instance *world = get_active_world(); menu_crap_ui(); - -#if 0 - if( cl_light_edit ) - { - vg_uictx.cursor[0] = 10; - vg_uictx.cursor[1] = 10; - vg_uictx.cursor[2] = 200; - vg_uictx.cursor[3] = 20; - - struct ub_world_lighting *wl = &gpipeline.ub_world_lighting; - struct ui_slider_vector - s5 = { .min=0.0f, .max=2.0f, .len=3, .data=wl->g_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] ); - - ui_text( vg_uictx.cursor, "Ambient", 1, 0 ); - vg_uictx.cursor[1] += 16; - ui_slider_vector( &s5 ); - - ui_text( vg_uictx.cursor, "Shadows", 1, 0 ); - vg_uictx.cursor[1] += 16; - ui_slider( &s8 ); - ui_slider( &s9 ); - - 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 ); - - render_update_lighting_ub(); - } -#endif - audio_debug_soundscapes(); render_view_framebuffer_ui(); - -#if 0 - player_physics_gui(); -#endif -} - -VG_STATIC void run_light_widget( struct light_widget *lw ) -{ - struct ui_checkbox c1 = { .data=&lw->enabled }; - - 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 ); - } -} - -VG_STATIC void run_debug_info(void) -{ -#if 0 - char buf[40]; - - snprintf( buf, 40, "%.2fm/s", v3_length( player.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; i