refactor (reduction)
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_skateshop.c
index 7cb0e9aa1e414ac369c7f951e5f0aaeb2430895a..a4cfe22d526afb8cf1a20e9bd9c07468b6085fc6 100644 (file)
@@ -27,7 +27,7 @@ static inline int const_str_eq( u32 hash, const char *str, const char *cmp )
    return 0;
 }
 
-VG_STATIC void skateshop_update_viewpage(void){
+static void skateshop_update_viewpage(void){
    u32 page = global_skateshop.selected_board_id/SKATESHOP_VIEW_SLOT_MAX;
 
    for( u32 i=0; i<SKATESHOP_VIEW_SLOT_MAX; i++ ){
@@ -49,7 +49,7 @@ VG_STATIC void skateshop_update_viewpage(void){
  * -----------------------------------------------------------------------------
  */
 
-VG_STATIC void world_scan_thread( void *_args ){
+static void world_scan_thread( void *_args ){
    addon_mount_content_folder( k_addon_type_world, "maps", ".mdl" );
    addon_mount_workshop_items();
    vg_async_call( async_addon_reg_update, NULL, 0 );
@@ -58,15 +58,15 @@ VG_STATIC void world_scan_thread( void *_args ){
 /*
  * Asynchronous scan of local disk for worlds
  */
-VG_STATIC void skateshop_op_world_scan(void){
+static void skateshop_op_world_scan(void){
    vg_loader_start( world_scan_thread, NULL );
 }
 
-VG_STATIC void board_processview_thread( void *_args ){
+static void board_processview_thread( void *_args ){
    addon_cache_load_loop();
 }
 
-VG_STATIC void board_scan_thread( void *_args ){
+static void board_scan_thread( void *_args ){
    addon_mount_content_folder( k_addon_type_board, "boards", ".mdl" );
    addon_mount_workshop_items();
    vg_async_call( async_addon_reg_update, NULL, 0 );
@@ -74,11 +74,11 @@ VG_STATIC void board_scan_thread( void *_args ){
    board_processview_thread(NULL);
 }
 
-VG_STATIC void skateshop_op_board_scan(void){
+static void skateshop_op_board_scan(void){
    vg_loader_start( board_scan_thread, NULL );
 }
 
-VG_STATIC void skateshop_op_processview(void){
+static void skateshop_op_processview(void){
    vg_loader_start( board_processview_thread, NULL );
 }
 
@@ -90,7 +90,7 @@ VG_STATIC void skateshop_op_processview(void){
 /*
  * VG event init
  */
-VG_STATIC void skateshop_init(void){
+static void skateshop_init(void){
 }
 
 static u16 skateshop_selected_cache_id(void){
@@ -102,18 +102,18 @@ static u16 skateshop_selected_cache_id(void){
    else return 0;
 }
 
-VG_STATIC void pointcloud_async_end(void *_, u32 __)
+static void pointcloud_async_end(void *_, u32 __)
 {
    pointcloud_animate( k_pointcloud_anim_opening );
 }
 
-VG_STATIC void pointcloud_clear_async(void *_, u32 __)
+static void pointcloud_clear_async(void *_, u32 __)
 {
    pointcloud.count = 0;
    pointcloud_animate( k_pointcloud_anim_opening );
 }
 
-VG_STATIC void skateshop_world_preview_loader_thread( void *_data )
+static void skateshop_world_preview_loader_thread( void *_data )
 {
    addon_reg *reg = _data;
 
@@ -151,11 +151,11 @@ VG_STATIC void skateshop_world_preview_loader_thread( void *_data )
    }
 }
 
-VG_STATIC void skateshop_world_preview_loader_thread_and_end( void *_data ){
+static void skateshop_world_preview_loader_thread_and_end( void *_data ){
    skateshop_world_preview_loader_thread( _data );
 }
 
-VG_STATIC void skateshop_load_world_preview( addon_reg *reg ){
+static void skateshop_load_world_preview( addon_reg *reg ){
    vg_loader_start( skateshop_world_preview_loader_thread_and_end, reg );
 }
 
@@ -163,20 +163,11 @@ VG_STATIC void skateshop_load_world_preview( addon_reg *reg ){
  * VG event preupdate 
  */
 void temp_update_playermodel(void);
-VG_STATIC void global_skateshop_preupdate(void){
-   float rate = vg_minf( 1.0f, vg.time_frame_delta * 2.0f );
-   int active = 0;
-   if( skaterift.activity == k_skaterift_skateshop )
-      active = 1;
-
-   vg_slewf( &global_skateshop.factive, active, 
-             vg.time_frame_delta * (1.0f/0.5f) );
-
+static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){
    if( !active ) return;
 
    /* input filter */
    world_instance *world = world_current_instance();
-   ent_skateshop *shop = global_skateshop.ptr_ent;
 
    /* camera positioning */
    ent_camera *ref = mdl_arritm( &world->ent_camera, 
@@ -185,7 +176,7 @@ VG_STATIC void global_skateshop_preupdate(void){
    v3f dir = {0.0f,-1.0f,0.0f};
    mdl_transform_vector( &ref->transform, dir, dir );
    m3x3_mulv( localplayer.invbasis, dir, dir );
-   player_vector_angles( global_skateshop.cam.angles, dir, 1.0f, 0.0f );
+   player_vector_angles( world_static.focus_cam.angles, dir, 1.0f, 0.0f );
 
    v3f lookat;
    if( shop->type == k_skateshop_type_boardshop ||
@@ -202,8 +193,8 @@ VG_STATIC void global_skateshop_preupdate(void){
    q_axis_angle( localplayer.rb.q, (v3f){0.0f,1.0f,0.0f}, 
                  atan2f(lookat[0],lookat[2]) );
 
-   v3_copy( ref->transform.co, global_skateshop.cam.pos );
-   global_skateshop.cam.fov = ref->fov;
+   v3_copy( ref->transform.co, world_static.focus_cam.pos );
+   world_static.focus_cam.fov = ref->fov;
 
    /* input */
    if( shop->type == k_skateshop_type_boardshop ){
@@ -251,8 +242,8 @@ VG_STATIC void global_skateshop_preupdate(void){
          addon_cache_watch( k_addon_type_board, cache_id );
          localplayer.board_view_slot = cache_id;
 
-         global_skateshop_exit();
-         skaterift_write_savedata();
+         world_entity_unfocus();
+         skaterift_autosave(1);
          return;
       }
    }
@@ -290,12 +281,12 @@ VG_STATIC void global_skateshop_preupdate(void){
       }
 
       if( changed ){
-         player__use_model( &localplayer, global_skateshop.selected_player_id );
+         player__use_model( global_skateshop.selected_player_id );
          skateshop_op_processview();
       }
 
       if( button_down( k_srbind_maccept ) ){
-         global_skateshop_exit();
+         world_entity_unfocus();
       }
    }
    else if( shop->type == k_skateshop_type_worldshop ){
@@ -346,9 +337,7 @@ VG_STATIC void global_skateshop_preupdate(void){
          if( loadable && button_down( k_srbind_maccept ) ){
             vg_info( "Select rift (%u)\n", 
                       global_skateshop.selected_world_id );
-            world_loader.reg = reg;
-            world_loader.override_name[0] = '\0';
-            skaterift_change_world_start();
+            skaterift_change_world_start( reg );
             return;
          }
          else{
@@ -379,15 +368,13 @@ VG_STATIC void global_skateshop_preupdate(void){
    }
 
    if( button_down( k_srbind_mback ) ){
-      global_skateshop_exit();
+      world_entity_unfocus();
       return;
    }
 }
 
-VG_STATIC void skateshop_render_boardshop(void){
+static void skateshop_render_boardshop( ent_skateshop *shop ){
    world_instance *world = world_current_instance();
-   ent_skateshop *shop = global_skateshop.ptr_ent;
-
    u32 slot_count = vg_list_size(global_skateshop.shop_view_slots);
 
    ent_marker *mark_rack = mdl_arritm( &world->ent_marker, 
@@ -430,7 +417,7 @@ VG_STATIC void skateshop_render_boardshop(void){
       q_nlerp( xform.q, mark_display->transform.q, t, xform.q );
       v3_lerp( xform.s, mark_display->transform.s, t, xform.s );
 
-      struct board_pose pose = {0};
+      struct player_board_pose pose = {0};
       m4x3f mmdl;
       mdl_transform_m4x3( &xform, mmdl );
       render_board( &skaterift.cam, world, board, mmdl, 
@@ -479,10 +466,11 @@ fade_out:;
       i+=highscore_intl( buf+i, addon_count(k_addon_type_board), 3 );
       buf[i++] = '\0';
 
-      font3d_simple_draw( &gui.font, 0, buf, &skaterift.cam, mmdl );
+      font3d_simple_draw( &gui.font, 0, k_font_shader_default,
+                           buf, &skaterift.cam, mmdl );
    }
    else{
-      font3d_simple_draw( &gui.font, 0, 
+      font3d_simple_draw( &gui.font, 0, k_font_shader_default,
                           "Nothing installed", &skaterift.cam, mmdl );
    }
 
@@ -529,7 +517,8 @@ fade_out:;
    mlocal[3][1] = 0.1f;
    mlocal[3][2] = 0.0f;
    m4x3_mul( mtext, mlocal, mmdl );
-   font3d_simple_draw( &gui.font, 0, global_skateshop.render.item_title, 
+   font3d_simple_draw( &gui.font, 0, k_font_shader_default,
+                        global_skateshop.render.item_title, 
                        &skaterift.cam, mmdl );
 
    /* Author name
@@ -542,21 +531,19 @@ fade_out:;
    mlocal[3][1] = 0.0f;
    mlocal[3][2] = 0.0f;
    m4x3_mul( mtext, mlocal, mmdl );
-   font3d_simple_draw( &gui.font, 0, global_skateshop.render.item_desc, 
+   font3d_simple_draw( &gui.font, 0, k_font_shader_default,
+                        global_skateshop.render.item_desc, 
                        &skaterift.cam, mmdl );
 
    SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
 }
 
-VG_STATIC void skateshop_render_charshop(void)
-{
+static void skateshop_render_charshop( ent_skateshop *shop ){
 }
 
-VG_STATIC void skateshop_render_worldshop(void)
-{
+static void skateshop_render_worldshop( ent_skateshop *shop ){
    world_instance *world = world_current_instance();
 
-   ent_skateshop *shop = global_skateshop.ptr_ent;
    ent_marker *mark_display = mdl_arritm( &world->ent_marker,
                                   mdl_entity_id_id(shop->worlds.id_display)),
               *mark_info = mdl_arritm( &world->ent_marker, 
@@ -631,14 +618,16 @@ VG_STATIC void skateshop_render_worldshop(void)
    mlocal[3][1] = 0.1f;
    mlocal[3][2] = 0.0f;
    m4x3_mul( mtext, mlocal, mtextmdl );
-   font3d_simple_draw( &gui.font, 0, buftext, &skaterift.cam, mtextmdl );
+   font3d_simple_draw( &gui.font, 0, k_font_shader_default,
+                        buftext, &skaterift.cam, mtextmdl );
 
    m3x3_setdiagonalv3( mlocal, (v3f){ scale1, scale1, thickness } );
    mlocal[3][0] = -font3d_string_width( &gui.font, 0, bufsubtext );
    mlocal[3][0] *= scale1*0.5f;
    mlocal[3][1] = -scale1*0.3f;
    m4x3_mul( mtext, mlocal, mtextmdl );
-   font3d_simple_draw( &gui.font, 0, bufsubtext, &skaterift.cam, mtextmdl );
+   font3d_simple_draw( &gui.font, 0, k_font_shader_default,
+                        bufsubtext, &skaterift.cam, mtextmdl );
 
    /* pointcloud */
    m4x3f mmdl;
@@ -656,30 +645,21 @@ VG_STATIC void skateshop_render_worldshop(void)
 /*
  * World: render event
  */
-VG_STATIC void skateshop_render(void){
-   if( skaterift.activity != k_skaterift_skateshop ) return;
-      
-   ent_skateshop *shop = global_skateshop.ptr_ent;
-
-   if( shop->type == k_skateshop_type_boardshop ){
-      skateshop_render_boardshop();
-   }
-   else if( shop->type == k_skateshop_type_charshop ){
-      skateshop_render_charshop();
-   }
-   else if( shop->type == k_skateshop_type_worldshop ){
-      skateshop_render_worldshop();
-   }
-   else{
+static void skateshop_render( ent_skateshop *shop ){
+   if( shop->type == k_skateshop_type_boardshop )
+      skateshop_render_boardshop( shop );
+   else if( shop->type == k_skateshop_type_charshop )
+      skateshop_render_charshop( shop );
+   else if( shop->type == k_skateshop_type_worldshop )
+      skateshop_render_worldshop( shop );
+   else
       vg_fatal_error( "Unknown store (%u)\n", shop->type );
-   }
 }
 
 /*
  * Entity logic: entrance event
  */
-VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call )
-{
+static void ent_skateshop_call( world_instance *world, ent_call *call ){
    u32 index = mdl_entity_id_id( call->id );
    ent_skateshop *shop = mdl_arritm( &world->ent_skateshop, index );
    vg_info( "skateshop_call\n" );
@@ -692,6 +672,8 @@ VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call )
       
       vg_info( "Entering skateshop\n" );
 
+      world_entity_focus( call->id );
+#if 0
       localplayer.immobile = 1;
       menu.disable_open = 1;
       skaterift.activity = k_skaterift_skateshop;
@@ -700,6 +682,7 @@ VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call )
       v3_zero( localplayer.rb.w );
       localplayer._walk.move_speed = 0.0f;
       global_skateshop.ptr_ent = shop;
+#endif
       
       if( shop->type == k_skateshop_type_boardshop ){
          skateshop_update_viewpage();
@@ -715,15 +698,4 @@ VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call )
    }
 }
 
-/*
- * Entity logic: exit event
- */
-VG_STATIC void global_skateshop_exit(void){
-   vg_info( "exit skateshop\n" );
-   localplayer.immobile = 0;
-   skaterift.activity = k_skaterift_default;
-   menu.disable_open = 0;
-   srinput.enabled = 0;
-}
-
 #endif /* ENT_SKATESHOP_C */