X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=skaterift.c;h=6343098c874d59ef03c12fe2426c7a6232f7986e;hb=a1056ed8198f0f5be0e0f341da8bd49aa6c47198;hp=201453080afa0f45f5953f3ddbda63fa4d91da61;hpb=d71f87252be197cec95e0b0458140112f75dc8b2;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/skaterift.c b/skaterift.c index 2014530..6343098 100644 --- a/skaterift.c +++ b/skaterift.c @@ -19,31 +19,18 @@ #include "audio.h" #include "world.h" -#if 0 -#include "player.h" -#else + #include "player.h" 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" }; -#if 0 -#include "player_interface.h" -#include "player_device_walk.h" -#include "player_device_skate.h" -#include "player_device_dead.h" -#include "player_model.h" -/* temp */ -VG_STATIC player_interface localplayer; -#endif -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" @@ -85,15 +72,13 @@ VG_STATIC int __kill( int argc, const char *argv[] ) 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; } @@ -103,32 +88,27 @@ 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 ); @@ -208,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(); @@ -232,7 +212,7 @@ 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 *[]){ &localplayer_texture }, 1 ); @@ -265,12 +245,19 @@ VG_STATIC void vg_load(void) 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(); } @@ -301,7 +288,9 @@ VG_STATIC void vg_update(void) #endif player__pre_update( &localplayer ); - world_update( localplayer.rb.co ); + world_update( get_active_world(), localplayer.rb.co ); + + audio_update(); } } @@ -337,6 +326,89 @@ VG_STATIC void vg_update_post(void) 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(); vehicle_update_post(); @@ -417,24 +489,34 @@ 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 ); - 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(); @@ -478,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 ); @@ -509,11 +603,13 @@ 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 ); } @@ -521,11 +617,13 @@ VG_STATIC void run_light_widget( struct light_widget *lw ); VG_STATIC void vg_ui(void) { 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; @@ -560,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();