some refactors before the storm
authorhgn <hgodden00@gmail.com>
Tue, 5 Dec 2023 11:56:14 +0000 (11:56 +0000)
committerhgn <hgodden00@gmail.com>
Tue, 5 Dec 2023 11:56:14 +0000 (11:56 +0000)
15 files changed:
ent_traffic.c [new file with mode: 0644]
ent_traffic.h [new file with mode: 0644]
entity.c
menu.h
player.c
respawn.c [deleted file]
respawn.h [deleted file]
skaterift.c
skaterift.h
world.c
world_entity.c
world_map.c [new file with mode: 0644]
world_map.h [new file with mode: 0644]
world_render.c
world_traffic.c [deleted file]

diff --git a/ent_traffic.c b/ent_traffic.c
new file mode 100644 (file)
index 0000000..f7167f2
--- /dev/null
@@ -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; i<mdl_arrcount( &world->ent_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 (file)
index 0000000..bebee23
--- /dev/null
@@ -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 */
index 59e9219abcfe58a7baaab9a574b19c5b83091b16..44b00df235f0f1d9e8ddc4d60f17390abd109c32 100644 (file)
--- 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 cb823b4ea6208a0291142717bc0cfa3ac2900e1e..ca7cec188289979a340f960bffe58bab16525cb6 100644 (file)
--- 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 ){
index 74d56f30d08de71817844512a09c822eeb0508cb..2e4bb6fb02ca9c822479759513ceebb705fc2b4c 100644 (file)
--- a/player.c
+++ b/player.c
 #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 (file)
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; i<mdl_arrcount(&world->ent_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; i<mdl_arrcount(&world->ent_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; i<mdl_arrcount(&world->ent_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; i<mdl_arrcount(&world->ent_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; i<mdl_arrcount(&world->ent_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 (file)
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 */
index 23b1db0311dd68a53079e491f714f16bd94d1983..422202f5655cb3151ebbbffc6a93b777dd58fd1d 100644 (file)
  * =============================================================================
  */
 
-#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
index 35ac9bfd7126ce3630e2b65622a17688abb4cace..b7fa44c78ec7561491f0c9171ca54fe2c0e99759 100644 (file)
@@ -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 f8d7168a1ca781a99c60fe1a733d2394035bedff..5a97d944b5f0bb6c79899765a636bab0398b450e 100644 (file)
--- 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 );
 }
index 02bbeb2b342d26141ef52c4a674688106cc50732..9095e1b4310a63f7ebbc5a97ccc0de4a0610e5dd 100644 (file)
@@ -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 (file)
index 0000000..e2fbe7a
--- /dev/null
@@ -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; i<mdl_arrcount(&world->ent_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; i<mdl_arrcount(&world->ent_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; i<mdl_arrcount(&world->ent_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; i<mdl_arrcount(&world->ent_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; i<mdl_arrcount(&world->ent_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 (file)
index 0000000..4fbd6fc
--- /dev/null
@@ -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 */
index 4ba8a4f48730fdf4064f41ad03f05ce5dd500cf0..613d3bffa6af21c473ff170938391b7357971624 100644 (file)
@@ -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 (file)
index 0083aae..0000000
+++ /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; i<mdl_arrcount( &world->ent_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 */