X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=skaterift.c;h=6343098c874d59ef03c12fe2426c7a6232f7986e;hb=a1056ed8198f0f5be0e0f341da8bd49aa6c47198;hp=be5d4d699f3cc5859eac179fb6c5bbc3e529fed3;hpb=07d0834b13ecf5de312cf3578e8aca8f106f5ef1;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/skaterift.c b/skaterift.c index be5d4d6..6343098 100644 --- a/skaterift.c +++ b/skaterift.c @@ -19,20 +19,18 @@ #include "audio.h" #include "world.h" -#if 0 + + #include "player.h" -#else -#include "player_interface.h" -#include "player_device_walk.h" -#include "player_model.h" - -/* temp */ -VG_STATIC player_interface localplayer; -VG_STATIC struct player_device_walk localplayer_walk; +VG_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" }; + + + + -#endif #include "network.h" @@ -48,7 +46,7 @@ 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; @@ -64,17 +62,23 @@ 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[] ) { - struct respawn_point *rp = NULL, *r; + ent_spawn *rp = NULL, *r; + world_instance *world = get_active_world(); - if( argc == 1 ) - { - for( int i=0; iname, argv[0] ) ) - { + 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; } @@ -84,35 +88,30 @@ VG_STATIC int __respawn( int argc, const char *argv[] ) vg_warn( "No spawn named '%s'\n", argv[0] ); } - if( !rp ) - { + if( !rp ){ float min_dist = INFINITY; - for( int i=0; ico, localplayer.rb.co ); + for( u32 i=0; ient_spawn); i++ ){ + r = mdl_arritm( &world->ent_spawn, i ); + float d = v3_dist2( r->transform.co, localplayer.rb.co ); - vg_info( "Dist %s : %f\n", r->name, d ); - if( d < min_dist ) - { + if( d < min_dist ){ min_dist = d; rp = r; } } } - if( !rp ) - { + if( !rp ){ vg_error( "No spawn found\n" ); - if( !world.spawn_count ) + if( !mdl_arrcount(&world->ent_spawn) ) return 0; - rp = &world.spawns[0]; + rp = mdl_arritm( &world->ent_spawn, 0 ); } - player_spawn( &localplayer, rp ); + player__spawn( &localplayer, rp ); return 1; } @@ -120,6 +119,8 @@ VG_STATIC void vg_preload(void) { g_conf_init(); + common_var_temp(); + vg_var_push( (struct vg_var){ .name = "cl_ui", .data = &cl_ui, @@ -150,6 +151,12 @@ VG_STATIC void vg_preload(void) //.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(" | \\ / | +-- / +----- +---' | / | \n" ); @@ -181,19 +188,19 @@ VG_STATIC void load_playermodels(void) ctx_outlaw, ctx_jordan; - mdl_open( &ctx_default, "models/ch_new.mdl" ); - mdl_load_metadata( &ctx_default, vg_mem.scratch ); - mdl_load_mesh_data( &ctx_default, vg_mem.scratch ); + mdl_open( &ctx_default, "models/ch_new.mdl", vg_mem.scratch ); + mdl_load_metadata_block( &ctx_default, vg_mem.scratch ); + mdl_load_mesh_block( &ctx_default, vg_mem.scratch ); mdl_close( &ctx_default ); - mdl_open( &ctx_outlaw, "models/ch_outlaw.mdl" ); - mdl_load_metadata( &ctx_outlaw, vg_mem.scratch ); - mdl_load_mesh_data( &ctx_outlaw, vg_mem.scratch ); + mdl_open( &ctx_outlaw, "models/ch_outlaw.mdl", vg_mem.scratch ); + mdl_load_metadata_block( &ctx_outlaw, vg_mem.scratch ); + mdl_load_mesh_block( &ctx_outlaw, vg_mem.scratch ); mdl_close( &ctx_outlaw ); - mdl_open( &ctx_jordan, "models/ch_jordan.mdl" ); - mdl_load_metadata( &ctx_jordan, vg_mem.scratch ); - mdl_load_mesh_data( &ctx_jordan, vg_mem.scratch ); + mdl_open( &ctx_jordan, "models/ch_jordan.mdl", vg_mem.scratch ); + mdl_load_metadata_block( &ctx_jordan, vg_mem.scratch ); + mdl_load_mesh_block( &ctx_jordan, vg_mem.scratch ); mdl_close( &ctx_jordan ); vg_acquire_thread_sync(); @@ -205,10 +212,10 @@ VG_STATIC void load_playermodels(void) vg_release_thread_sync(); /* FIXME: hack */ - shader_viewchar_register(); + shader_model_character_view_register(); vg_acquire_thread_sync(); { - vg_tex2d_init( (vg_tex2d *[]){ &tex_characters }, 1 ); + vg_tex2d_init( (vg_tex2d *[]){ &localplayer_texture }, 1 ); } vg_release_thread_sync(); } @@ -227,23 +234,30 @@ VG_STATIC void vg_load(void) vg_loader_step( load_playermodels, NULL ); /* player setup */ - player_interface_create_player( &localplayer ); - + player__create( &localplayer ); player_avatar_load( &localplayer_avatar, "models/ch_new.mdl" ); - player_use_avatar( &localplayer, &localplayer_avatar ); - player_use_mesh( &localplayer, &localplayer_meshes[0] ); - player_use_device( &localplayer, &player_device_walk, &localplayer_walk ); + player__use_avatar( &localplayer, &localplayer_avatar ); + player__use_mesh( &localplayer, &localplayer_meshes[0] ); + player__use_texture( &localplayer, &localplayer_texture ); + 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 world */ + world_load( &world_global.worlds[0], "maps/mp_gridmap.mdl" ); + +#if 0 + world_load( &world_global.worlds[1], "maps/mp_gridmap.mdl" ); + world_link_nonlocal_gates( 0, 1 ); + world_load( &world_global.worlds[2], "maps/mp_mtzero.mdl" ); + world_link_nonlocal_gates( 0, 2 ); +#endif + vg_console_load_autos(); } @@ -273,8 +287,10 @@ VG_STATIC void vg_update(void) player_update_pre(); #endif - player_pre_update( &localplayer ); - world_update( localplayer.rb.co ); + player__pre_update( &localplayer ); + world_update( get_active_world(), localplayer.rb.co ); + + audio_update(); } } @@ -289,7 +305,7 @@ VG_STATIC void vg_update_fixed(void) vehicle_update_fixed(); #endif - player_update( &localplayer ); + player__update( &localplayer ); } } @@ -308,7 +324,90 @@ VG_STATIC void vg_update_post(void) } #endif - player_post_update( &localplayer ); + player__post_update( &localplayer ); + + + 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 ); + } + } + + 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]; + + 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; + + + /* FIXME: TEMP */ + audio_lock(); + vg_dsp.echo_distances[si] = dist; + + v3f ears = { 1.0f,0.0f,0.0f }; + m3x3_mulv( main_camera.transform, ears, ears ); + v3_copy( ears, vg_audio.listener_ears ); + v3_copy( main_camera.transform[3], vg_audio.listener_pos ); + v3_copy( localplayer.rb.v, vg_audio.listener_velocity ); + audio_unlock(); #if 0 menu_update(); @@ -379,7 +478,7 @@ VG_STATIC void render_player_transparent(void) /* Draw player to window buffer and blend background ontop */ glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - player_render( &small_cam, &localplayer ); + player__render( &small_cam, &localplayer ); } VG_STATIC void render_scene(void) @@ -391,20 +490,33 @@ VG_STATIC void render_scene(void) /* Draw world */ glEnable( GL_DEPTH_TEST ); - render_world( &main_camera ); + 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; + } + render_world( view_world, &main_camera ); int player_transparent = 1, player_draw = 1; +#if 0 + if( (localplayer.subsystem == k_player_subsystem_dead) || + (localplayer.camera_mode == k_cam_thirdperson) ) + player_transparent = 0; +#endif + if( !player_transparent && player_draw ) - player_render( &main_camera, &localplayer ); + player__render( &main_camera, &localplayer ); + - render_water_texture( &main_camera ); + render_water_texture( view_world, &main_camera ); render_fb_bind( gpipeline.fb_main ); - render_water_surface( &main_camera ); - render_world_gates( &main_camera ); + render_water_surface( view_world, &main_camera ); + render_world_gates( view_world, &main_camera ); if( player_transparent && player_draw ) render_player_transparent(); @@ -439,7 +551,7 @@ VG_STATIC void render_main_game(void) * TODO: blend with camera from menu */ /* FIXME: TEMP!! */ - player_pre_render( &localplayer ); + player__pre_render( &localplayer ); v3_copy( localplayer.cam.pos, main_camera.pos ); v3_copy( localplayer.cam.angles, main_camera.angles ); @@ -448,6 +560,18 @@ VG_STATIC void render_main_game(void) main_camera.farz = 2100.0f; camera_update_transform( &main_camera ); + + if( localplayer.gate_waiting ) + { + m3x3_mul( localplayer.basis_gate, main_camera.transform, + main_camera.transform ); + } + else + { + m3x3_mul( localplayer.basis, main_camera.transform, + main_camera.transform ); + } + camera_update_view( &main_camera ); camera_update_projection( &main_camera ); camera_finalize( &main_camera ); @@ -479,23 +603,27 @@ VG_STATIC void vg_render(void) glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ); render_main_game(); + + m4x4_copy( main_camera.mtx.pv, vg.pv ); /* Other shite */ glDisable(GL_BLEND); glDisable( GL_DEPTH_TEST ); - vg_lines_drawall( (float *)main_camera.mtx.pv ); + vg_lines_drawall(); 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) { - player_ui( &localplayer ); + player__im_gui( &localplayer ); + world_instance *world = get_active_world(); #if 0 menu_crap_ui(); #endif +#if 0 if( cl_light_edit ) { vg_uictx.cursor[0] = 10; @@ -530,13 +658,7 @@ VG_STATIC void vg_ui(void) render_update_lighting_ub(); } - - //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); - if( cl_ui ) - { - render_world_routes_ui(); - } - //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); +#endif audio_debug_soundscapes(); render_view_framebuffer_ui();