clean boardshop idea
authorhgn <hgodden00@gmail.com>
Tue, 25 Apr 2023 17:14:49 +0000 (18:14 +0100)
committerhgn <hgodden00@gmail.com>
Tue, 25 Apr 2023 17:14:49 +0000 (18:14 +0100)
blender_export.py
ent_skateshop.c
entity.h
maps_src/mp_spawn.mdl
menu.h
player.h
player_common.c
player_render.c
world.h
world_gen.h

index b533afee8927e6aa01a6b3ac6c70775b9c76cde9..00c2de474d1d902eb914fd68d90609a8c887a256 100644 (file)
@@ -30,7 +30,8 @@ sr_entity_list = [
    ('ent_font',         'Font',           '', 9  ),
    ('ent_font_variant', 'Font:Variant',   '', 10 ),
    ('ent_traffic',      'Traffic Model',  '', 11 ),
-   ('ent_skateshop',    'Skate Shop',     '', 12 )
+   ('ent_skateshop',    'Skate Shop',     '', 12 ),
+   ('ent_camera',       'Camera',         '', 13 )
 ]
 
 def get_entity_enum_id( alias ):
@@ -342,13 +343,21 @@ class ent_skateshop(Structure):
    _fields_ = [("transform",mdl_transform),
                ("id_display",c_uint32),
                ("id_info",c_uint32),
-               ("id_rack",c_uint32)]
+               ("id_rack",c_uint32),
+               ("id_camera",c_uint32)]
+#}
+
+class ent_camera(Structure):
+#{
+   _fields_ = [("transform",mdl_transform),
+               ("fov",c_float)]
 #}
 
 def obj_ent_type( obj ):
 #{
    if obj.type == 'ARMATURE': return 'mdl_armature'
    elif obj.type == 'LIGHT': return 'ent_light'
+   elif obj.type == 'CAMERA': return 'ent_camera'
    else: return obj.SR_data.ent_type
 #}
 
@@ -1370,6 +1379,12 @@ def sr_compile( collection ):
             light.colour[3] = obj.data.energy
             sr_ent_push( light )
          #}
+         elif ent_type == 'ent_camera': #{
+            cam = ent_camera()
+            compile_obj_transform( obj, cam.transform )
+            cam.fov = obj.data.angle
+            sr_ent_push(cam)
+         #}
          elif ent_type == 'ent_gate': #{
             gate = ent_gate()
             obj_data = obj.SR_data.ent_gate[0]
@@ -1498,6 +1513,7 @@ def sr_compile( collection ):
             skateshop.id_display = sr_entity_id( obj_data.mark_display )
             skateshop.id_info = sr_entity_id( obj_data.mark_info )
             skateshop.id_rack = sr_entity_id( obj_data.mark_rack )
+            skateshop.id_camera = sr_entity_id( obj_data.cam )
             compile_obj_transform( obj, skateshop.transform )
             sr_ent_push(skateshop)
          #}
@@ -2609,6 +2625,9 @@ class SR_OBJECT_ENT_SKATESHOP(bpy.types.PropertyGroup):
    mark_info: bpy.props.PointerProperty( \
            type=bpy.types.Object, name="Selected Board Info", \
            poll=lambda self,obj: sr_filter_ent_type(obj,['ent_marker']))
+   cam: bpy.props.PointerProperty( \
+           type=bpy.types.Object, name="Viewpoint", \
+           poll=lambda self,obj: sr_filter_ent_type(obj,['ent_camera']))
 #}
 
 class SR_OBJECT_PROPERTIES(bpy.types.PropertyGroup):
@@ -3585,7 +3604,7 @@ def cv_draw():
 
             rack_cu = Vector((3.15,2.0,0.1))*0.5
             rack_co = Vector((0.0,0.0,0.0))
-            display_cu = Vector((0.2,1.2,0.1))*0.5
+            display_cu = Vector((0.3,1.2,0.1))*0.5
             display_co = Vector((0.0,0.0,0.1))*0.5
             info_cu = Vector((1.2,0.01,0.3))*0.5
             info_co = Vector((0.0,0.0,0.0))*0.5
index b126abf3a3defee29929916521ff765378568bee..adccac50c0521ada3f09c45da2c8b48dab30235f 100644 (file)
 
 struct{
    v3f look_target;
-   mdl_transform rack_root,
-                 display_root,
-                 info_root;
-
-   enum camera_mode prev_camera_mode;
+   ent_skateshop *ptr_ent;
 
    int active;
    float factive;
@@ -326,8 +322,8 @@ next_file: tinydir_next( &dir );
 
 VG_STATIC void global_skateshop_exit(void)
 {
+   localplayer.immobile = 0;
    global_skateshop.active = 0;
-   localplayer.camera_mode = global_skateshop.prev_camera_mode;
 }
 
 VG_STATIC void skateshop_request_viewpage( u32 page )
@@ -390,8 +386,6 @@ VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call )
       vg_info( "Entering skateshop\n" );
 
       localplayer.immobile = 1;
-      global_skateshop.prev_camera_mode = localplayer.camera_mode;
-      localplayer.camera_mode = k_cam_firstperson;
       global_skateshop.active = 1;
       global_skateshop.interface_loc = k_skateshop_loc_page__viewing;
 
@@ -399,32 +393,7 @@ VG_STATIC void ent_skateshop_call( world_instance *world, ent_call *call )
       v3_zero( localplayer.rb.w );
       localplayer._walk.move_speed = 0.0f;
 
-      struct{
-         mdl_transform *transform;
-         u32 id;
-      }
-      targets[] = {
-         { &global_skateshop.rack_root, shop->id_rack, },
-         { &global_skateshop.info_root, shop->id_info, },
-         { &global_skateshop.display_root, shop->id_display, },
-      };
-      
-      v3_copy( shop->transform.co, global_skateshop.look_target );
-
-      for( u32 i=0; i<vg_list_size(targets); i++ ){
-         
-         u32 type = mdl_entity_id_type( targets[i].id ),
-             index = mdl_entity_id_id( targets[i].id );
-
-         if( type == k_ent_marker ){
-            ent_marker *m = mdl_arritm( &world->ent_marker, index );
-
-            *targets[i].transform = m->transform;
-         }
-         else{
-            transform_identity( targets[i].transform );
-         }
-      }
+      global_skateshop.ptr_ent = shop;
 
       skateshop_request_viewpage(0);
       skateshop_loader_start( skateshop_scan_for_items );
@@ -437,18 +406,30 @@ VG_STATIC void global_skateshop_preupdate(void)
    global_skateshop.factive = vg_lerpf( global_skateshop.factive, 
                                         global_skateshop.active, rate );
 
-
    if( !global_skateshop.active ) return;
 
-   v3f delta;
-   v3_sub( global_skateshop.look_target, localplayer.cam.pos, delta );
-   v3_normalize( delta );
+   world_instance *world = get_active_world();
+
+   ent_skateshop *shop = global_skateshop.ptr_ent;
+   ent_camera *ref = mdl_arritm( &world->ent_camera, 
+                                 mdl_entity_id_id(shop->id_camera) );
+   ent_marker *display = mdl_arritm( &world->ent_marker,
+                                 mdl_entity_id_id(shop->id_display) );
+   
+   v3f dir = {0.0f,-1.0f,0.0f};
+   mdl_transform_vector( &ref->transform, dir, dir );
+   player_vector_angles( localplayer.cam_override_angles, dir, 1.0f, 0.0f );
+   
+   v3f lookat;
+   v3_sub( display->transform.co, localplayer.rb.co, lookat );
+   
+   q_axis_angle( localplayer.rb.q, (v3f){0.0f,1.0f,0.0f}, 
+                 atan2f(lookat[0],lookat[2]) );
 
-   v3f target;
-   player_vector_angles( target, delta, 1.0f, 0.0f );
+   v3_copy( ref->transform.co, localplayer.cam_override_pos );
+   localplayer.cam_override_fov = ref->fov;
 
-   camera_lerp_angles( localplayer.angles, target,
-                       global_skateshop.factive, localplayer.angles);
+   localplayer.cam_override_strength = global_skateshop.factive;
 
    if( global_skateshop.interaction_cooldown > 0.0f ){
       global_skateshop.interaction_cooldown -= vg.time_delta;
@@ -478,29 +459,10 @@ VG_STATIC void global_skateshop_preupdate(void)
       }
 
       if( vg_input_button_down( &input_menu_back ) ){
-         global_skateshop.active = 0;
+         global_skateshop_exit();
          return;
       }
    }
-   else if( global_skateshop.interface_loc <= k_skateshop_loc_page__selected ){
-      if( vg_input_button_down( &input_menu_back ) ){
-         global_skateshop.interface_loc = k_skateshop_loc_page__viewing;
-         return;
-      }
-
-      if( fabsf(h) > 0.25f ){
-         if( global_skateshop.interface_loc == k_skateshop_loc_select_use ){
-            global_skateshop.interface_loc = k_skateshop_loc_select_cancel;
-            return;
-         }
-      }
-      else{
-         if( global_skateshop.interface_loc == k_skateshop_loc_select_cancel ){
-            global_skateshop.interface_loc = k_skateshop_loc_select_use;
-            return;
-         }
-      }
-   }
 }
 
 VG_STATIC void skateshop_init(void)
@@ -534,6 +496,7 @@ VG_STATIC void skateshop_render(void)
 {
    if( !global_skateshop.active ) return;
       
+   ent_skateshop *shop = global_skateshop.ptr_ent;
    world_instance *world = get_active_world();
 
    u32 slot_count = vg_list_size(global_skateshop.shop_view_slots);
@@ -549,28 +512,29 @@ VG_STATIC void skateshop_render(void)
       if( slot->db->state != k_dynamic_board_state_loaded ) 
          goto set_fade_amt;
 
-      mdl_transform rack_xform;
-      transform_identity( &rack_xform );
+      mdl_transform xform;
+      transform_identity( &xform );
+
+      xform.co[0] = -((float)i - ((float)slot_count)*0.5f)*0.45f;
 
-      rack_xform.co[0] = -((float)i - ((float)slot_count)*0.5f)*0.45f;
+      ent_marker *rack = mdl_arritm( &world->ent_marker, 
+                                     mdl_entity_id_id(shop->id_rack)),
+                 *display = mdl_arritm( &world->ent_marker,
+                                     mdl_entity_id_id(shop->id_display));
 
-      mdl_transform_mul( &global_skateshop.rack_root, 
-                         &rack_xform, &rack_xform );
+      mdl_transform_mul( &rack->transform, &xform, &xform );
 
       if( slot->db->registry_id == global_skateshop.selected_registry_id ){
          selected = 1.0f;
       }
 
       float t = slot->view_blend;
-      v3_lerp( rack_xform.co, global_skateshop.display_root.co, 
-               t, rack_xform.co );
-      q_nlerp( rack_xform.q, global_skateshop.display_root.q, 
-               t, rack_xform.q );
-      v3_lerp( rack_xform.s, global_skateshop.display_root.s, 
-               t, rack_xform.s );
+      v3_lerp( xform.co, display->transform.co, t, xform.co );
+      q_nlerp( xform.q, display->transform.q, t, xform.q );
+      v3_lerp( xform.s, display->transform.s, t, xform.s );
 
       m4x3f mmdl;
-      mdl_transform_m4x3( &rack_xform, mmdl );
+      mdl_transform_m4x3( &xform, mmdl );
       render_board( &main_camera, world, &slot->db->board, mmdl,
                     k_board_shader_entity );
 
@@ -579,21 +543,38 @@ set_fade_amt:;
       slot->view_blend = vg_lerpf( slot->view_blend, selected, rate );
    }
 
+   ent_marker *info = mdl_arritm( &world->ent_marker, 
+                                  mdl_entity_id_id(shop->id_info));
    m4x3f mtext;
-   mdl_transform_m4x3( &global_skateshop.info_root, mtext );
+   mdl_transform_m4x3( &info->transform, mtext );
 
-   m4x3f mlocal = {{0.2f,0.0f,0.0f},{0.0f,0.2f,0.0f},{0.0f,0.0f,0.03f},
-                   {-font3d_string_width( &world_global.font,0, 
-                        "Made by... Bob man 123" )*0.2f*0.5f,0.0f,0.0f}
-   };
+   const char *text_title = "Fish - Title";
+   const char *text_author = "by Shaniqua";
 
-   m4x3_mul( mtext, mlocal, mtext );
+   m4x3f mlocal, mmdl;
+   m4x3_identity( mlocal );
+
+   float scale = 0.2f;
+
+   mlocal[0][0] = scale; mlocal[1][1] = scale;
+   mlocal[2][2] = 0.03f;
+   mlocal[3][0] = -font3d_string_width(&world_global.font,0,text_title);
+   mlocal[3][0] *= scale*0.5f;
+   mlocal[3][1] = 0.1f;
+   m4x3_mul( mtext, mlocal, mmdl );
 
    font3d_bind( &world_global.font, &main_camera );
 
-   shader_model_font_uColour( (v4f){1.0f,0.5f,0.1f,1.0f} );
-   font3d_simple_draw( &world_global.font, 0, "Made by... Bob man 123",
-                       &main_camera, mtext );
+   shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
+   font3d_simple_draw( &world_global.font, 0, text_title, &main_camera, mmdl );
+
+   scale *= 0.4f;
+   mlocal[0][0] = scale; mlocal[1][1] = scale;
+   mlocal[3][0] = -font3d_string_width(&world_global.font,0,text_author);
+   mlocal[3][0] *= scale*0.5f;
+   mlocal[3][1] = 0.0f;
+   m4x3_mul( mtext, mlocal, mmdl );
+   font3d_simple_draw( &world_global.font, 0, text_author, &main_camera, mmdl );
 }
 
 #endif /* ENT_SKATESHOP_C */
index e8b9d411a91d04452e5e7b58216bfacb714b9297..d56d70271d043a7b239b64df174f2fc6b29a33b3 100644 (file)
--- a/entity.h
+++ b/entity.h
@@ -22,6 +22,7 @@ typedef struct ent_font ent_font;
 typedef struct ent_font_variant ent_font_variant;
 typedef struct ent_glyph ent_glyph;
 typedef struct ent_skateshop ent_skateshop;
+typedef struct ent_camera ent_camera;
 
 enum entity_alias{
    k_ent_none        = 0,
@@ -36,7 +37,8 @@ enum entity_alias{
    k_ent_font        = 9,
    k_ent_font_variant= 10,
    k_ent_traffic     = 11,
-   k_ent_skateshop   = 12
+   k_ent_skateshop   = 12,
+   k_ent_camera      = 13
 };
 
 static u32 mdl_entity_id_type( u32 entity_id )
@@ -214,7 +216,8 @@ struct ent_skateshop{
    mdl_transform transform;
    u32 id_display,
        id_info,
-       id_rack;
+       id_rack,
+       id_camera;
 };
 
 struct ent_traffic{
@@ -228,6 +231,11 @@ struct ent_traffic{
    u32 index;     /* into the path */
 };
 
+struct ent_camera{
+   mdl_transform transform;
+   float fov;
+};
+
 VG_STATIC ent_marker *ent_find_marker( mdl_context *mdl,
                                        mdl_array_ptr *arr, const char *alias )
 {
index c33fb0d3db9f48a0b5a8ccc1a89a6c464662754e..3692a9c02746eac9c88a307b5231dfc9419ecc97 100644 (file)
Binary files a/maps_src/mp_spawn.mdl and b/maps_src/mp_spawn.mdl differ
diff --git a/menu.h b/menu.h
index 7e6649a2ca5bf71cd9ca0a1d36757c9498402eca..4f9e671304c89ce0ea04df8e4508f7058a4578f5 100644 (file)
--- a/menu.h
+++ b/menu.h
@@ -646,6 +646,7 @@ VG_STATIC void menu_update(void)
    vg_input_update( 1, &input_menu_press );
    vg_input_update( 1, &input_menu_toggle );
    vg_input_update( 1, &input_menu_toggle_kbm );
+   return;
 
    int toggle_gp = vg_input_button_down( &input_menu_toggle ),
        toggle_kb = vg_input_button_down( &input_menu_toggle_kbm ),
index 77a01fc512d9896dc627b3578f13b5bcbff4992b..72c26edb5d1cd8b8d0325520d67e4b600aea137f 100644 (file)
--- a/player.h
+++ b/player.h
@@ -46,7 +46,8 @@ struct player_instance
        cam_velocity_smooth;
 
    v3f cam_override_pos;
-   v2f cam_override_angles;
+   v3f cam_override_angles;
+   float cam_override_fov;
    float cam_override_strength;
 
    float cam_velocity_influence,
index 21d52aa76871c6f978d10f3bda4334ae614e5671..4991d231a31f00671635c154c246f9d0b1643e87 100644 (file)
@@ -226,6 +226,8 @@ VG_STATIC void player__cam_iterate( player_instance *player )
                  player->cam_override_strength );
    v3_lerp( player->cam.pos, player->cam_override_pos, 
             player->cam_override_strength, player->cam.pos );
+   player->cam.fov = vg_lerpf( player->cam.fov, player->cam_override_fov, 
+                               player->cam_override_strength );
 
    /* portal transitions */
    player_camera_portal_correction( player );
index 171b339ebe4e88bb52b7f782d649e0504909c045..33724245771fe10b0f07a3a13d5e74ee9e883fbe 100644 (file)
@@ -177,6 +177,11 @@ VG_STATIC void player__pre_render( player_instance *player )
    m4x3_mulv( av->sk.final_mtx[ av->id_board ], vp0, ubo->g_board_0 );
    m4x3_mulv( av->sk.final_mtx[ av->id_board ], vp1, ubo->g_board_1 );
 
+   if( player->immobile ){
+      player__cam_iterate( player );
+      return;
+   }
+
    if( player->rewinding ){
       if( player->rewind_time <= 0.0f ){
          double taken = vg.time - player->rewind_start;
@@ -265,6 +270,7 @@ VG_STATIC void player__pre_render( player_instance *player )
             vg_alerpf( fr->ang[0], fr1->ang[0], sub );
          player->cam_override_angles[1] = 
             vg_lerpf ( fr->ang[1], fr1->ang[1], sub );
+         player->cam_override_fov = player->cam.fov;
 
          float blend = player->rewind_time * 0.25f;
          player->cam_override_strength = vg_clampf( blend, 0.0f, 1.0f );
diff --git a/world.h b/world.h
index 01b12b9d3d090ae6c2cc0fbbed56d4cec31a6b22..f065cb3ccf78abe82a48966da1c396b8d30e9408 100644 (file)
--- a/world.h
+++ b/world.h
@@ -167,7 +167,8 @@ struct world_instance {
                  ent_volume,
                  ent_traffic,
                  ent_skateshop,
-                 ent_marker;
+                 ent_marker,
+                 ent_camera;
 
    ent_gate *rendering_gate;
 
index a9cd91fd68726281bffb70a02cf123f442d5001e..79bb754aaf5b6f4d04388a6be663b67782874ec5 100644 (file)
@@ -820,6 +820,7 @@ VG_STATIC void world_load( u32 index, const char *path )
    mdl_load_mesh_block( meta, world->heap );
 
    mdl_load_array( meta, &world->ent_gate,      "ent_gate",       heap );
+   mdl_load_array( meta, &world->ent_camera,    "ent_camera",     heap );
    mdl_load_array( meta, &world->ent_spawn,     "ent_spawn",      heap );
    mdl_load_array( meta, &world->ent_light,     "ent_light",      heap );
    mdl_load_array( meta, &world->ent_route_node,"ent_route_node", heap );