From: hgn Date: Tue, 5 Dec 2023 11:56:14 +0000 (+0000) Subject: some refactors before the storm X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;h=14267d2fb3d228060aef8e4de729254813ec245f;hp=0c3d1d55160d5ce911ead69de84b1d8200a0036f;p=carveJwlIkooP6JGAAIwe30JlM.git some refactors before the storm --- diff --git a/ent_traffic.c b/ent_traffic.c new file mode 100644 index 0000000..f7167f2 --- /dev/null +++ b/ent_traffic.c @@ -0,0 +1,67 @@ +#ifndef ENT_TRAFFIC_C +#define ENT_TRAFFIC_C + +#include "world.h" + +static void ent_traffic_update( world_instance *world, v3f pos ){ + for( u32 i=0; ient_traffic ); i++ ){ + ent_traffic *traffic = mdl_arritm( &world->ent_traffic, i ); + + u32 i1 = traffic->index, + i0, + i2 = i1+1; + + if( i1 == 0 ) i0 = traffic->node_count-1; + else i0 = i1-1; + + if( i2 >= traffic->node_count ) i2 = 0; + + i0 += traffic->start_node; + i1 += traffic->start_node; + i2 += traffic->start_node; + + v3f h[3]; + + ent_route_node *rn0 = mdl_arritm( &world->ent_route_node, i0 ), + *rn1 = mdl_arritm( &world->ent_route_node, i1 ), + *rn2 = mdl_arritm( &world->ent_route_node, i2 ); + + v3_copy( rn1->co, h[1] ); + v3_lerp( rn0->co, rn1->co, 0.5f, h[0] ); + v3_lerp( rn1->co, rn2->co, 0.5f, h[2] ); + + float const k_sample_dist = 0.0025f; + v3f pc, pd; + eval_bezier3( h[0], h[1], h[2], traffic->t, pc ); + eval_bezier3( h[0], h[1], h[2], traffic->t+k_sample_dist, pd ); + + v3f v0; + v3_sub( pd, pc, v0 ); + float length = vg_maxf( 0.0001f, v3_length( v0 ) ); + v3_muls( v0, 1.0f/length, v0 ); + + float mod = k_sample_dist / length; + + traffic->t += traffic->speed * vg.time_delta * mod; + + if( traffic->t > 1.0f ){ + traffic->t -= 1.0f; + + if( traffic->t > 1.0f ) traffic->t = 0.0f; + + traffic->index ++; + + if( traffic->index >= traffic->node_count ) + traffic->index = 0; + } + + v3_copy( pc, traffic->transform.co ); + + float a = atan2f( -v0[0], v0[2] ); + q_axis_angle( traffic->transform.q, (v3f){0.0f,1.0f,0.0f}, -a ); + + vg_line_point( traffic->transform.co, 0.3f, VG__BLUE ); + } +} + +#endif /* ENT_TRAFFIC_C */ diff --git a/ent_traffic.h b/ent_traffic.h new file mode 100644 index 0000000..bebee23 --- /dev/null +++ b/ent_traffic.h @@ -0,0 +1,7 @@ +#ifndef ENT_TRAFFIC_H +#define ENT_TRAFFIC_H + +#include "world.h" +static void ent_traffic_update( world_instance *world, v3f pos ); + +#endif /* ENT_TRAFFIC_H */ diff --git a/entity.c b/entity.c index 59e9219..44b00df 100644 --- a/entity.c +++ b/entity.c @@ -13,6 +13,7 @@ #include "ent_portal.c" #include "ent_miniworld.c" #include "ent_region.c" +#include "ent_traffic.c" typedef void (*fn_entity_call_handler)( world_instance *, ent_call *); diff --git a/menu.h b/menu.h index cb823b4..ca7cec1 100644 --- a/menu.h +++ b/menu.h @@ -9,7 +9,7 @@ #include "audio.h" #include "input.h" #include "workshop.h" -#include "respawn.h" +#include "world_map.h" #include "gui.h" #include "ent_miniworld.h" @@ -250,11 +250,9 @@ static void menu_trigger_item( ent_menuitem *item ){ if( MDL_CONST_PSTREQ( &menu.model, q, "quit" ) ){ vg.window_should_close = 1; } - else if( MDL_CONST_PSTREQ( &menu.model, q, "map" ) ){ - menu_close(); - respawn_begin_chooser(); + world_map_enter(); } else if( MDL_CONST_PSTREQ( &menu.model, q, "hub" ) ){ if( world_static.active_instance == k_world_purpose_client ){ diff --git a/player.c b/player.c index 74d56f3..2e4bb6f 100644 --- a/player.c +++ b/player.c @@ -14,6 +14,10 @@ #include "ent_miniworld.h" #include "gui.h" +#include "shaders/model_entity.h" +#include "shaders/model_character_view.h" +#include "shaders/model_board_view.h" + static int localplayer_cmd_respawn( int argc, const char *argv[] ){ ent_spawn *rp = NULL, *r; world_instance *world = world_current_instance(); @@ -50,6 +54,10 @@ static void player_init(void){ vg_console_reg_var( "cinema_fixed", &k_cinema_fixed, k_var_dtype_i32, 0 ); vg_console_reg_var( "invert_y", &k_invert_y, k_var_dtype_i32, VG_VAR_PERSISTENT ); + + shader_model_character_view_register(); + shader_model_board_view_register(); + shader_model_entity_register(); } static void player__debugtext( int size, const char *fmt, ... ){ @@ -162,8 +170,6 @@ static void player__pass_gate( u32 id ){ } static void player_apply_transport_to_cam( m4x3f transport ){ - /* FIXME: Applies to skaterift.cam directly! */ - /* Pre-emptively edit the camera matrices so that the motion vectors * are correct */ m4x3f transport_i; @@ -214,7 +220,7 @@ static void player__im_gui(void){ [k_skaterift_replay] = "replay", [k_skaterift_ent_focus] = "ent_focus", [k_skaterift_default] = "default", - [k_skaterift_respawning]= "map" + [k_skaterift_world_map] = "world map" } [skaterift.activity] ); player__debugtext( 1, "time_rate: %.4f", skaterift.time_rate ); diff --git a/respawn.c b/respawn.c deleted file mode 100644 index d8c470a..0000000 --- a/respawn.c +++ /dev/null @@ -1,256 +0,0 @@ -#ifndef RESPAWN_C -#define RESPAWN_C - -#if 1 -#include "respawn.h" -#include "skaterift.h" -#include "world.h" -#include "input.h" -#include "gui.h" -#include "menu.h" -#include "scene.h" - -static void respawn_chooser_get_dir( v3f dir ){ - /* idk */ - dir[0] = -sqrtf(0.5f); - dir[2] = sqrtf(0.5f); - dir[1] = 1.0f; - v3_normalize(dir); -} - -static void respawn_chooser_get_plane( v4f plane ){ - world_instance *world = &world_static.instances[ respawn_chooser.world_id ]; - f32 h = localplayer.rb.co[1]; - if( respawn_chooser.world_id != world_static.active_instance ) - h = (world->scene_geo.bbx[0][1] + world->scene_geo.bbx[1][1]) * 0.5f; - - v4_copy( (v4f){0.0f,1.0f,0.0f,h}, plane ); -} - -static void respawn_world_to_plane_pos( v3f pos, v2f plane_pos ){ - v3f dir; - respawn_chooser_get_dir( dir ); - v3_negate(dir,dir); - v4f plane; - respawn_chooser_get_plane( plane ); - - v3f co; - f32 t = ray_plane( plane, pos, dir ); - v3_muladds( pos, dir, t, co ); - plane_pos[0] = co[0]; - plane_pos[1] = co[2]; -} - -static void respawn_chooser_setworld( u32 next ){ - world_instance *nw = &world_static.instances[next]; - if( nw->status == k_world_status_loaded ){ - respawn_chooser.world_id = next; - - v3f target; - if( next == world_static.active_instance ) - v3_copy( localplayer.rb.co, target ); - else { - scene_context *sc = &nw->scene_geo; - v3_lerp( sc->bbx[0], sc->bbx[1], 0.5f, target ); - } - respawn_world_to_plane_pos( target, respawn_chooser.plane_pos ); - } -} - -static void respawn_chooser_gohome(void){ - respawn_chooser_setworld(0); - world_instance *world = &world_static.instances[ respawn_chooser.world_id ]; - - const char **alias = respawn_homes[respawn_chooser.home_select]; - ent_spawn *spawn = world_find_spawn_by_name( world, alias[0] ); - - if( spawn ){ - respawn_world_to_plane_pos( spawn->transform.co, - respawn_chooser.plane_pos ); - - gui_location_print_ccmd( 1, (const char *[]){ alias[1] } ); - } - else - gui_location_print_ccmd( 1, (const char *[]){ "Invalid home ID" } ); -} - -static void respawn_map_draw_icon( camera *cam, - enum gui_icon icon, v3f pos ){ - v4f v; - v3_copy( pos, v ); - v[3] = 1.0f; - m4x4_mulv( cam->mtx.pv, v, v ); - v2_divs( v, v[3], v ); - - gui_draw_icon( icon, (v2f){ v[0]*0.5f+0.5f,v[1]*0.5f+0.5f }, 1.0f ); -} - -static void respawn_chooser_pre_update(void){ - if( skaterift.activity != k_skaterift_respawning ) return; - - if( button_down( k_srbind_mback ) ){ - gui_helper_clear(); - srinput.state = k_input_state_resume; - skaterift.activity = k_skaterift_menu; - menu.page = 0xffffffff; - menu_open_page( "Main Menu", k_ent_menuitem_stack_append ); - return; - } - - if( button_down( k_srbind_maccept ) ){ - skaterift.activity = k_skaterift_default; - srinput.state = k_input_state_resume; - - if( respawn_chooser.spawn ){ - world_static.active_instance = respawn_chooser.world_id; - player__spawn( respawn_chooser.spawn ); - } - return; - } - - world_instance *world = &world_static.instances[ respawn_chooser.world_id ]; - v3f *bbx = world->scene_geo.bbx; - f32 *pos = respawn_chooser.plane_pos; - - v2f steer; - joystick_state( k_srjoystick_steer, steer ); - v2_normalize_clamp( steer ); - - m2x2f rm; - m2x2_create_rotation( rm, -0.25f*VG_PIf ); - m2x2_mulv( rm, steer, steer ); - - v2_muladds( pos, steer, vg.time_frame_delta * 200.0f, pos ); - v2_minv( (v2f){ bbx[1][0], bbx[1][2] }, pos, pos ); - v2_maxv( (v2f){ bbx[0][0], bbx[0][2] }, pos, pos ); - - /* update camera */ - camera *cam = &respawn_chooser.cam; - v3f dir; - respawn_chooser_get_dir(dir); - - v4f plane; - respawn_chooser_get_plane( plane ); - - v3f co = { pos[0], plane[3]*plane[1], pos[1] }; - v3_muladds( co, dir, respawn_chooser.boom_dist, cam->pos ); - - vg_line_cross( co, VG__RED, 10.0f ); - - cam->angles[0] = 0.25f * VG_PIf; - cam->angles[1] = 0.25f * VG_PIf; - cam->farz = 5000.0f; - cam->nearz = 10.0f; - cam->fov = 40.0f; - - camera_update_transform( cam ); - camera_update_view( cam ); - camera_update_projection( cam ); - camera_finalize( cam ); - - /* pick spawn */ - respawn_chooser.spawn = NULL; - f32 closest2 = INFINITY; - - for( u32 i=0; ient_spawn); i++ ){ - ent_spawn *spawn = mdl_arritm(&world->ent_spawn,i); - - v4f v; - v3_copy( spawn->transform.co, v ); - v[3] = 1.0f; - m4x4_mulv( cam->mtx.pv, v, v ); - v2_divs( v, v[3], v ); - - f32 d2 = v2_length2(v); - if( d2 < closest2 ){ - respawn_chooser.spawn = spawn; - closest2 = d2; - } - } - - /* icons - * ---------------------*/ - for( u32 i=0; ient_challenge); i++ ){ - ent_challenge *challenge = mdl_arritm( &world->ent_challenge, i ); - - enum gui_icon icon = k_gui_icon_exclaim_2d; - if( challenge->status ) - icon = k_gui_icon_tick_2d; - - respawn_map_draw_icon( cam, icon, challenge->transform.co ); - } - - for( u32 i=0; ient_skateshop); i++ ){ - ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, i ); - if( shop->type == k_skateshop_type_boardshop ){ - respawn_map_draw_icon( cam, k_gui_icon_board, shop->transform.co ); - } - else if( shop->type == k_skateshop_type_worldshop ){ - respawn_map_draw_icon( cam, k_gui_icon_world, shop->transform.co ); - } - } - - for( u32 i=0; ient_gate); i++ ){ - ent_gate *gate = mdl_arritm( &world->ent_gate, i ); - if( gate->flags & k_ent_gate_nonlocal ){ - respawn_map_draw_icon( cam, k_gui_icon_rift, gate->co[0] ); - } - } - - for( u32 i=0; ient_route); i++ ){ - ent_route *route = mdl_arritm( &world->ent_route, i ); - - v4f colour; - v4_copy( route->colour, colour ); - v3_muls( colour, 1.6666f, colour ); - gui_icon_setcolour( colour ); - respawn_map_draw_icon( cam, k_gui_icon_rift_run_2d, - route->board_transform[3] ); - } -} - -static void respawn_begin_chooser(void){ - skaterift.activity = k_skaterift_respawning; - respawn_chooser.world_id = world_static.active_instance; - - world_instance *world = &world_static.instances[ respawn_chooser.world_id ]; - v3f *bbx = world->scene_geo.bbx; - - respawn_world_to_plane_pos( localplayer.rb.co, respawn_chooser.plane_pos ); - respawn_chooser.boom_dist = 400.0f; - respawn_chooser.home_select = 0; - - gui_helper_clear(); - - vg_str text; - if( gui_new_helper( input_joy_list[k_srjoystick_steer], &text ) ) - vg_strcat( &text, "move" ); - - if( gui_new_helper( input_button_list[k_srbind_maccept], &text ) ) - vg_strcat( &text, "spawn" ); - - if( gui_new_helper( input_button_list[k_srbind_mback], &text ) ) - vg_strcat( &text, "exit" ); -} - -#if 0 -static void respawn_chooser_shader_uniforms(void){ - v4f uPlayerPos, uSpawnPos; - v4_zero( uPlayerPos ); - v4_zero( uSpawnPos ); - - v3_copy( localplayer.rb.co, uPlayerPos ); - - if( respawn_chooser.spawn ) - v3_copy( respawn_chooser.spawn->transform.co, uSpawnPos ); - - uPlayerPos[3] = v3_dist(uPlayerPos,uSpawnPos); - uSpawnPos[3] = 1.0f/uPlayerPos[3]; - - shader_scene_override_uPlayerPos( uPlayerPos ); - shader_scene_override_uSpawnPos( uSpawnPos ); -} -#endif -#endif - -#endif /* RESPAWN_C */ diff --git a/respawn.h b/respawn.h deleted file mode 100644 index fed65fd..0000000 --- a/respawn.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef RESPAWN_H -#define RESPAWN_H - -#include "skaterift.h" - -struct { - v2f plane_pos; - f32 boom_dist; - u32 world_id; - u32 home_select; - - ent_spawn *spawn; - camera cam; -} -static respawn_chooser; - -static const char *respawn_homes[][2] = { - { "skateshop", "Skateshop" }, - { "world_select", "World Selector" }, -}; - -static void respawn_begin_chooser(void); -static void respawn_chooser_shader_uniforms(void); - -#endif /* RESPAWN_H */ diff --git a/skaterift.c b/skaterift.c index 23b1db0..422202f 100644 --- a/skaterift.c +++ b/skaterift.c @@ -11,10 +11,7 @@ * ============================================================================= */ -#if 1 - #define SR_NETWORKED -#define SR_USE_LOCALHOST #ifndef VG_RELEASE #define VG_DEVWINDOW @@ -51,7 +48,7 @@ #include "addon.c" #include "highscores.c" #include "save.c" -#include "respawn.c" +#include "world_map.c" #include "network.c" #include "player_remote.c" #include "vg/vg_audio_dsp.h" @@ -114,13 +111,6 @@ vg_info(" ' ' '--' [] '----- '----- ' ' '---' " vg_loader_step( network_init, network_end ); } -static void load_playermodels(void){ - /* FIXME: hack */ - shader_model_character_view_register(); - shader_model_board_view_register(); - shader_model_entity_register(); -} - static void async_skaterift_player_start( void *payload, u32 size ){ world_switch_instance(0); } @@ -199,9 +189,6 @@ static void vg_load(void){ vg_loader_step( addon_system_init, NULL ); vg_loader_step( workshop_init, NULL ); vg_loader_step( skateshop_init, NULL ); - - /* ----------------- */ - vg_loader_step( load_playermodels, NULL ); /* player setup */ u32 bytes = 1024*1024*10; @@ -297,7 +284,7 @@ static void vg_pre_update(void){ /* time rate */ f32 target = 1; if( skaterift.activity & (k_skaterift_replay|k_skaterift_menu| - k_skaterift_respawning) ){ + k_skaterift_world_map) ){ target = 0; } @@ -314,7 +301,7 @@ static void vg_pre_update(void){ world_update( world_current_instance(), localplayer.rb.co ); audio_ambient_sprites_update( world_current_instance(), localplayer.rb.co ); - respawn_chooser_pre_update(); + world_map_pre_update(); } static void vg_fixed_update(void){ @@ -466,7 +453,7 @@ static void render_scene(void){ } } - if( skaterift.activity == k_skaterift_respawning ){ + if( skaterift.activity == k_skaterift_world_map ){ world_instance *world = world_current_instance(); glDrawBuffers( 1, (GLenum[]){ GL_COLOR_ATTACHMENT0 } ); @@ -489,7 +476,7 @@ static void render_scene(void){ m4x3f identity; m4x3_identity( identity ); render_world_override( world, world, identity, &skaterift.cam, - respawn_chooser.spawn, + world_map.spawn, (v4f){world->tar_min, world->tar_max, 1.0f, 0.0f}); render_world_routes( world, world, identity, &skaterift.cam, 0, 1 ); return; @@ -498,11 +485,6 @@ static void render_scene(void){ world_instance *view_world = get_view_world(); render_world( view_world, &skaterift.cam, 0, 0, 1, 1 ); -#if 0 - particle_spawn( &particles_grind, localplayer.rb.co, - (v3f){vg_randf64()*2.0f,vg_randf64()*3.0f,vg_randf64()*2.0f}, - vg_randf64(), 0xff0000ff ); -#endif particle_system_update( &particles_grind, vg.time_delta ); //particle_system_debug( &particles_grind ); particle_system_prerender( &particles_grind ); @@ -564,8 +546,8 @@ static void skaterift_composite_maincamera(void){ skaterift.cam.nearz = 0.1f; skaterift.cam.farz = 2100.0f; - if( skaterift.activity == k_skaterift_respawning ){ - camera_copy( &respawn_chooser.cam, &skaterift.cam ); + if( skaterift.activity == k_skaterift_world_map ){ + camera_copy( &world_map.cam, &skaterift.cam ); skaterift.cam.nearz = 4.0f; skaterift.cam.farz = 3100.0f; } @@ -576,12 +558,9 @@ static void skaterift_composite_maincamera(void){ global_miniworld.t += s * dt; if( (global_miniworld.t > 1.0f) || (global_miniworld.t < 0.0f) ){ - /* TODO: maybe next frame! */ global_miniworld.t = vg_clampf( global_miniworld.t, 0.0f, 1.0f ); global_miniworld.transition = 0; } - else { - } } camera_update_transform( &skaterift.cam ); @@ -604,7 +583,7 @@ static void render_main_game(void){ skaterift_composite_maincamera(); /* --------------------------------------------------------------------- */ - if( skaterift.activity != k_skaterift_respawning ){ + if( skaterift.activity != k_skaterift_world_map ){ world_instance *world = world_current_instance(); render_world_cubemaps( world ); @@ -631,7 +610,7 @@ static void render_main_game(void){ /* continue with variable rate */ if( !global_miniworld.transition && - (skaterift.activity != k_skaterift_respawning) ){ + (skaterift.activity != k_skaterift_world_map) ){ render_fb_bind( gpipeline.fb_main, 1 ); render_world_gates( get_view_world(), &skaterift.cam ); } @@ -694,7 +673,7 @@ static void vg_gui(void){ render_view_framebuffer_ui(); remote_player_network_imgui( vg.pv ); - if( skaterift.activity == k_skaterift_respawning ){ + if( skaterift.activity == k_skaterift_world_map ){ remote_players_imgui_world( world_current_instance(), vg.pv, 2000.0f, 0 ); remote_players_imgui_lobby(); } @@ -703,10 +682,3 @@ static void vg_gui(void){ remote_players_imgui_world( world_current_instance(), vg.pv, 100.0f, 1 ); } } - - -#else - -#include "skaterift_imgui_dev.c" - -#endif diff --git a/skaterift.h b/skaterift.h index 35ac9bf..b7fa44c 100644 --- a/skaterift.h +++ b/skaterift.h @@ -57,7 +57,7 @@ struct{ k_skaterift_replay = 0x01, k_skaterift_ent_focus = 0x02, k_skaterift_menu = 0x04, - k_skaterift_respawning = 0x08, + k_skaterift_world_map = 0x08, } activity; diff --git a/world.c b/world.c index f8d7168..5a97d94 100644 --- a/world.c +++ b/world.c @@ -91,7 +91,6 @@ static void skaterift_world_get_save_path( enum world_purpose which, #include "world_water.c" #include "world_audio.c" #include "world_routes.c" -#include "world_traffic.c" static void world_update( world_instance *world, v3f pos ){ world_render.sky_time += world_render.sky_rate * vg.time_delta; @@ -101,7 +100,7 @@ static void world_update( world_instance *world, v3f pos ){ world_routes_update_timer_texts( world ); world_routes_update( world ); - world_traffic_update( world, pos ); + ent_traffic_update( world, pos ); world_sfd_update( world, pos ); world_volumes_update( world, pos ); } diff --git a/world_entity.c b/world_entity.c index 02bbeb2..9095e1b 100644 --- a/world_entity.c +++ b/world_entity.c @@ -11,6 +11,7 @@ #include "ent_challenge.h" #include "ent_skateshop.h" #include "ent_route.h" +#include "ent_traffic.h" static void world_entity_focus( u32 entity_id ){ localplayer.immobile = 1; diff --git a/world_map.c b/world_map.c new file mode 100644 index 0000000..e2fbe7a --- /dev/null +++ b/world_map.c @@ -0,0 +1,202 @@ +#ifndef RESPAWN_C +#define RESPAWN_C + +#include "world_map.h" +#include "skaterift.h" +#include "world.h" +#include "input.h" +#include "gui.h" +#include "menu.h" +#include "scene.h" + +static void world_map_get_dir( v3f dir ){ + /* idk */ + dir[0] = -sqrtf(0.5f); + dir[2] = sqrtf(0.5f); + dir[1] = 1.0f; + v3_normalize(dir); +} + +static void world_map_get_plane( v4f plane ){ + world_instance *world = &world_static.instances[ world_map.world_id ]; + f32 h = localplayer.rb.co[1]; + if( world_map.world_id != world_static.active_instance ) + h = (world->scene_geo.bbx[0][1] + world->scene_geo.bbx[1][1]) * 0.5f; + + v4_copy( (v4f){0.0f,1.0f,0.0f,h}, plane ); +} + +static void respawn_world_to_plane_pos( v3f pos, v2f plane_pos ){ + v3f dir; + world_map_get_dir( dir ); + v3_negate(dir,dir); + v4f plane; + world_map_get_plane( plane ); + + v3f co; + f32 t = ray_plane( plane, pos, dir ); + v3_muladds( pos, dir, t, co ); + plane_pos[0] = co[0]; + plane_pos[1] = co[2]; +} + +static void respawn_map_draw_icon( camera *cam, + enum gui_icon icon, v3f pos ){ + v4f v; + v3_copy( pos, v ); + v[3] = 1.0f; + m4x4_mulv( cam->mtx.pv, v, v ); + v2_divs( v, v[3], v ); + + gui_draw_icon( icon, (v2f){ v[0]*0.5f+0.5f,v[1]*0.5f+0.5f }, 1.0f ); +} + +static void world_map_pre_update(void){ + if( skaterift.activity != k_skaterift_world_map ) return; + + if( button_down( k_srbind_mback ) ){ + gui_helper_clear(); + srinput.state = k_input_state_resume; + skaterift.activity = k_skaterift_menu; + menu.page = 0xffffffff; + menu_open_page( "Main Menu", k_ent_menuitem_stack_append ); + return; + } + + if( button_down( k_srbind_maccept ) ){ + skaterift.activity = k_skaterift_default; + srinput.state = k_input_state_resume; + + if( world_map.spawn ){ + world_static.active_instance = world_map.world_id; + player__spawn( world_map.spawn ); + } + return; + } + + world_instance *world = &world_static.instances[ world_map.world_id ]; + v3f *bbx = world->scene_geo.bbx; + f32 *pos = world_map.plane_pos; + + v2f steer; + joystick_state( k_srjoystick_steer, steer ); + v2_normalize_clamp( steer ); + + m2x2f rm; + m2x2_create_rotation( rm, -0.25f*VG_PIf ); + m2x2_mulv( rm, steer, steer ); + + v2_muladds( pos, steer, vg.time_frame_delta * 200.0f, pos ); + v2_minv( (v2f){ bbx[1][0], bbx[1][2] }, pos, pos ); + v2_maxv( (v2f){ bbx[0][0], bbx[0][2] }, pos, pos ); + + /* update camera */ + camera *cam = &world_map.cam; + v3f dir; + world_map_get_dir(dir); + + v4f plane; + world_map_get_plane( plane ); + + v3f co = { pos[0], plane[3]*plane[1], pos[1] }; + v3_muladds( co, dir, world_map.boom_dist, cam->pos ); + + vg_line_cross( co, VG__RED, 10.0f ); + + cam->angles[0] = 0.25f * VG_PIf; + cam->angles[1] = 0.25f * VG_PIf; + cam->farz = 5000.0f; + cam->nearz = 10.0f; + cam->fov = 40.0f; + + camera_update_transform( cam ); + camera_update_view( cam ); + camera_update_projection( cam ); + camera_finalize( cam ); + + /* pick spawn */ + world_map.spawn = NULL; + f32 closest2 = INFINITY; + + for( u32 i=0; ient_spawn); i++ ){ + ent_spawn *spawn = mdl_arritm(&world->ent_spawn,i); + + v4f v; + v3_copy( spawn->transform.co, v ); + v[3] = 1.0f; + m4x4_mulv( cam->mtx.pv, v, v ); + v2_divs( v, v[3], v ); + + f32 d2 = v2_length2(v); + if( d2 < closest2 ){ + world_map.spawn = spawn; + closest2 = d2; + } + } + + /* icons + * ---------------------*/ + for( u32 i=0; ient_challenge); i++ ){ + ent_challenge *challenge = mdl_arritm( &world->ent_challenge, i ); + + enum gui_icon icon = k_gui_icon_exclaim_2d; + if( challenge->status ) + icon = k_gui_icon_tick_2d; + + respawn_map_draw_icon( cam, icon, challenge->transform.co ); + } + + for( u32 i=0; ient_skateshop); i++ ){ + ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, i ); + if( shop->type == k_skateshop_type_boardshop ){ + respawn_map_draw_icon( cam, k_gui_icon_board, shop->transform.co ); + } + else if( shop->type == k_skateshop_type_worldshop ){ + respawn_map_draw_icon( cam, k_gui_icon_world, shop->transform.co ); + } + } + + for( u32 i=0; ient_gate); i++ ){ + ent_gate *gate = mdl_arritm( &world->ent_gate, i ); + if( gate->flags & k_ent_gate_nonlocal ){ + respawn_map_draw_icon( cam, k_gui_icon_rift, gate->co[0] ); + } + } + + for( u32 i=0; ient_route); i++ ){ + ent_route *route = mdl_arritm( &world->ent_route, i ); + + v4f colour; + v4_copy( route->colour, colour ); + v3_muls( colour, 1.6666f, colour ); + gui_icon_setcolour( colour ); + respawn_map_draw_icon( cam, k_gui_icon_rift_run_2d, + route->board_transform[3] ); + } +} + +static void world_map_enter(void){ + skaterift.activity = k_skaterift_world_map; + world_map.world_id = world_static.active_instance; + + world_instance *world = &world_static.instances[ world_map.world_id ]; + v3f *bbx = world->scene_geo.bbx; + + respawn_world_to_plane_pos( localplayer.rb.co, world_map.plane_pos ); + world_map.boom_dist = 400.0f; + world_map.home_select = 0; + + gui_helper_clear(); + + vg_str text; + if( gui_new_helper( input_joy_list[k_srjoystick_steer], &text ) ) + vg_strcat( &text, "move" ); + + if( gui_new_helper( input_button_list[k_srbind_maccept], &text ) ) + vg_strcat( &text, "spawn" ); + + if( gui_new_helper( input_button_list[k_srbind_mback], &text ) ) + vg_strcat( &text, "exit" ); +} + +#endif /* RESPAWN_C */ diff --git a/world_map.h b/world_map.h new file mode 100644 index 0000000..4fbd6fc --- /dev/null +++ b/world_map.h @@ -0,0 +1,18 @@ +#ifndef RESPAWN_H +#define RESPAWN_H + +#include "skaterift.h" + +struct { + v2f plane_pos; + f32 boom_dist; + u32 world_id; + u32 home_select; + + ent_spawn *spawn; + camera cam; +} +static world_map; +static void world_map_enter(void); + +#endif /* RESPAWN_H */ diff --git a/world_render.c b/world_render.c index 4ba8a4f..613d3bf 100644 --- a/world_render.c +++ b/world_render.c @@ -9,7 +9,7 @@ #include "world_render.h" #include "font.h" #include "gui.h" -#include "respawn.h" +#include "world_map.h" #include "ent_miniworld.h" #include "player_remote.h" #include "ent_skateshop.h" diff --git a/world_traffic.c b/world_traffic.c deleted file mode 100644 index 0083aae..0000000 --- a/world_traffic.c +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef WORLD_TRAFFIC_C -#define WORLD_TRAFFIC_C - -#include "world.h" - -static void world_traffic_update( world_instance *world, v3f pos ){ - for( u32 i=0; ient_traffic ); i++ ){ - ent_traffic *traffic = mdl_arritm( &world->ent_traffic, i ); - - u32 i1 = traffic->index, - i0, - i2 = i1+1; - - if( i1 == 0 ) i0 = traffic->node_count-1; - else i0 = i1-1; - - if( i2 >= traffic->node_count ) i2 = 0; - - i0 += traffic->start_node; - i1 += traffic->start_node; - i2 += traffic->start_node; - - v3f h[3]; - - ent_route_node *rn0 = mdl_arritm( &world->ent_route_node, i0 ), - *rn1 = mdl_arritm( &world->ent_route_node, i1 ), - *rn2 = mdl_arritm( &world->ent_route_node, i2 ); - - v3_copy( rn1->co, h[1] ); - v3_lerp( rn0->co, rn1->co, 0.5f, h[0] ); - v3_lerp( rn1->co, rn2->co, 0.5f, h[2] ); - - float const k_sample_dist = 0.0025f; - v3f pc, pd; - eval_bezier3( h[0], h[1], h[2], traffic->t, pc ); - eval_bezier3( h[0], h[1], h[2], traffic->t+k_sample_dist, pd ); - - v3f v0; - v3_sub( pd, pc, v0 ); - float length = vg_maxf( 0.0001f, v3_length( v0 ) ); - v3_muls( v0, 1.0f/length, v0 ); - - float mod = k_sample_dist / length; - - traffic->t += traffic->speed * vg.time_delta * mod; - - if( traffic->t > 1.0f ){ - traffic->t -= 1.0f; - - if( traffic->t > 1.0f ) traffic->t = 0.0f; - - traffic->index ++; - - if( traffic->index >= traffic->node_count ) - traffic->index = 0; - } - - v3_copy( pc, traffic->transform.co ); - - float a = atan2f( -v0[0], v0[2] ); - q_axis_angle( traffic->transform.q, (v3f){0.0f,1.0f,0.0f}, -a ); - - vg_line_point( traffic->transform.co, 0.3f, VG__BLUE ); - } -} - -#endif /* WORLD_TRAFFIC_C */