add basic controls to ent_routes
authorhgn <hgodden00@gmail.com>
Thu, 12 Oct 2023 16:56:44 +0000 (17:56 +0100)
committerhgn <hgodden00@gmail.com>
Thu, 12 Oct 2023 16:56:44 +0000 (17:56 +0100)
blender_export.py
ent_challenge.c
ent_route.c [new file with mode: 0644]
ent_route.h [new file with mode: 0644]
entity.c
entity.h
maps_src/mp_mtzero/main.mdl
model.h
world_entity.c
world_entity.h

index db6e97c517e6af71cd57ae2354e1c70fd507df13..1646d83a252a3e5f6469ca05a407b080c831e521 100644 (file)
@@ -42,9 +42,9 @@ sr_entity_list = [
    ('ent_relay',        'Relay',          '', 20 )
 ]
 
    ('ent_relay',        'Relay',          '', 20 )
 ]
 
-MDL_VERSION_NR = 102
+MDL_VERSION_NR = 103
 SR_TRIGGERABLE = [ 'ent_audio', 'ent_ccmd', 'ent_gate', 'ent_challenge', \
 SR_TRIGGERABLE = [ 'ent_audio', 'ent_ccmd', 'ent_gate', 'ent_challenge', \
-                   'ent_relay', 'ent_skateshop', 'ent_objective' ]
+                   'ent_relay', 'ent_skateshop', 'ent_objective', 'ent_route' ]
 
 def get_entity_enum_id( alias ):
 #{
 
 def get_entity_enum_id( alias ):
 #{
@@ -263,7 +263,11 @@ class ent_route(Structure):
                ("factive",c_float),
                ("board_transform",(c_float*3)*4),
                ("sm",mdl_submesh),
                ("factive",c_float),
                ("board_transform",(c_float*3)*4),
                ("sm",mdl_submesh),
-               ("latest_pass",c_double)]
+               ("latest_pass",c_double),
+               ("id_camera",c_uint32), # v103+ 
+               ]
+
+   sr_functions = { 0: 'view' }
 #}
 
 class ent_water(Structure):
 #}
 
 class ent_water(Structure):
@@ -1989,6 +1993,7 @@ def sr_compile( collection ):
          route.pstr_name = sr_compile_string( obj_data.alias )
          route.checkpoints_start = checkpoint_count
          route.checkpoints_count = 0
          route.pstr_name = sr_compile_string( obj_data.alias )
          route.checkpoints_start = checkpoint_count
          route.checkpoints_count = 0
+         route.id_camera = sr_entity_id( obj_data.cam )
 
          for ci in range(3):
             route.colour[ci] = obj_data.colour[ci]
 
          for ci in range(3):
             route.colour[ci] = obj_data.colour[ci]
@@ -2889,11 +2894,16 @@ class SR_OBJECT_ENT_ROUTE(bpy.types.PropertyGroup):
           name="Alias",\
           default="Untitled Course")
 
           name="Alias",\
           default="Untitled Course")
 
+   cam: bpy.props.PointerProperty( \
+           type=bpy.types.Object, name="Viewpoint", \
+           poll=lambda self,obj: sr_filter_ent_type(obj,['ent_camera']))
+
    @staticmethod
    def sr_inspector( layout, data ):
    #{
       layout.prop( data[0], 'alias' )
       layout.prop( data[0], 'colour' )
    @staticmethod
    def sr_inspector( layout, data ):
    #{
       layout.prop( data[0], 'alias' )
       layout.prop( data[0], 'colour' )
+      layout.prop( data[0], 'cam' )
 
       layout.label( text='Checkpoints' )
       layout.template_list('SR_UL_ROUTE_NODE_LIST', 'Checkpoints', \
 
       layout.label( text='Checkpoints' )
       layout.template_list('SR_UL_ROUTE_NODE_LIST', 'Checkpoints', \
index 02fac7deaad77e1b9d27fa1a5bb3c9505b3c771a..10196bf635fce0ed5297ae84ef513391412ef900 100644 (file)
@@ -66,26 +66,7 @@ static void ent_challenge_preupdate( ent_challenge *challenge, int active ){
       return;
    }
 
       return;
    }
 
-   if( mdl_entity_id_type( challenge->camera ) == k_ent_camera ){
-      u32 index = mdl_entity_id_id( challenge->camera );
-      ent_camera *cam = mdl_arritm( &world->ent_camera, index );
-
-      /* TODO COMPRESSION */
-      v3f dir = {0.0f,-1.0f,0.0f};
-      mdl_transform_vector( &cam->transform, dir, dir );
-      m3x3_mulv( localplayer.invbasis, dir, dir );
-      player_vector_angles( world_static.focus_cam.angles, dir, 1.0f, 0.0f );
-      v3_copy( cam->transform.co, world_static.focus_cam.pos );
-      world_static.focus_cam.fov = cam->fov;
-   }
-   else {
-      /* TODO COMPRESSION */
-      v3_copy( localplayer.cam.pos, world_static.focus_cam.pos );
-      v3_copy( localplayer.cam.angles, world_static.focus_cam.angles );
-      world_static.focus_cam.fov = localplayer.cam.fov;
-      world_static.focus_cam.nearz = localplayer.cam.nearz;
-      world_static.focus_cam.farz = localplayer.cam.farz;
-   }
+   world_entity_focus_camera( world, challenge->camera );
 
    gui_helper_action( button_display_string( k_srbind_maccept ), "start" );
    gui_helper_action( button_display_string( k_srbind_mback ), "exit" );
 
    gui_helper_action( button_display_string( k_srbind_maccept ), "start" );
    gui_helper_action( button_display_string( k_srbind_mback ), "exit" );
diff --git a/ent_route.c b/ent_route.c
new file mode 100644 (file)
index 0000000..a114640
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef ENT_ROUTE_C
+#define ENT_ROUTE_C
+
+#include "ent_route.h"
+#include "input.h"
+#include "gui.h"
+
+static void ent_route_call( world_instance *world, ent_call *call ){
+   u32 index = mdl_entity_id_id( call->id );
+   ent_route *route = mdl_arritm( &world->ent_route, index );
+
+   if( call->function == 0 ){ /* view() */
+      if( localplayer.subsystem == k_player_subsystem_walk ){
+         world_entity_focus( call->id );
+      }
+   }
+   else {
+      /* TODO: Comrpession */
+      vg_print_backtrace();
+      vg_error( "Unhandled function id: %u\n", call->function );
+   }
+}
+
+/* TODO: these should recieve the world instance */
+static void ent_route_preupdate( ent_route *route, int active ){
+   if( !active ) return;
+
+   world_instance *world = world_current_instance();
+   u32 cam_id = 0;
+   
+   if( __builtin_expect( world->meta.info.version >= 103, 1 ) )
+      cam_id = route->id_camera;
+
+   world_entity_focus_camera( world, cam_id );
+
+   gui_helper_action( button_display_string( k_srbind_mleft ), "weekly" );
+   gui_helper_action( button_display_string( k_srbind_mright ), "all time" );
+
+   gui_helper_action( button_display_string( k_srbind_mback ), "exit" );
+
+   if( button_down( k_srbind_mback ) ){
+      world_entity_unfocus();
+      return;
+   }
+}
+
+#endif /* ENT_ROUTE_C */
diff --git a/ent_route.h b/ent_route.h
new file mode 100644 (file)
index 0000000..786d850
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef ENT_ROUTE_H
+#define ENT_ROUTE_H
+
+#include "entity.h"
+
+static void ent_route_call( world_instance *world, ent_call *call );
+static void ent_route_preupdate( ent_route *route, int active );
+
+#endif /* ENT_ROUTE_H */
index 21815f461973b2337c31da02df2622a7bc9dea42..287016a60a15fb28433bb48123e3daded8420fd9 100644 (file)
--- a/entity.c
+++ b/entity.c
@@ -9,6 +9,7 @@
 #include "ent_objective.c"
 #include "ent_challenge.c"
 #include "ent_relay.c"
 #include "ent_objective.c"
 #include "ent_challenge.c"
 #include "ent_relay.c"
+#include "ent_route.c"
 
 typedef void (*fn_entity_call_handler)( world_instance *, ent_call *);
 
 
 typedef void (*fn_entity_call_handler)( world_instance *, ent_call *);
 
@@ -23,7 +24,8 @@ static void entity_call( world_instance *world, ent_call *call ){
       [k_ent_ccmd]      = ent_ccmd_call,
       [k_ent_gate]      = ent_gate_call,
       [k_ent_relay]     = ent_relay_call,
       [k_ent_ccmd]      = ent_ccmd_call,
       [k_ent_gate]      = ent_gate_call,
       [k_ent_relay]     = ent_relay_call,
-      [k_ent_challenge] = ent_challenge_call
+      [k_ent_challenge] = ent_challenge_call,
+      [k_ent_route]     = ent_route_call
    };
 
    if( type >= vg_list_size(table) ){
    };
 
    if( type >= vg_list_size(table) ){
index 40464526c982c2c157fd7810d18784b3f3283324..04237919605fde85772fe8ebae5a88593d58c46b 100644 (file)
--- a/entity.h
+++ b/entity.h
@@ -177,10 +177,12 @@ struct ent_route{
    u16 active_checkpoint, 
        valid_checkpoints;
 
    u16 active_checkpoint, 
        valid_checkpoints;
 
-   float factive;
+   f32 factive;
    m4x3f board_transform;
    mdl_submesh sm;
    m4x3f board_transform;
    mdl_submesh sm;
-   double timing_base;
+   f64 timing_base;
+
+   u32 id_camera; /* v103+ */
 };
 
 struct ent_water{
 };
 
 struct ent_water{
index 29eebf3032ab9b7dc5858ae95bf206f4bec93265..8e98f1a5fe5f736c7ab2091b34ffaeff1f570804 100644 (file)
Binary files a/maps_src/mp_mtzero/main.mdl and b/maps_src/mp_mtzero/main.mdl differ
diff --git a/model.h b/model.h
index c28455d1faf4689d8cda17b7e7185f9fe24b55fe..dae6038bbc04543d4221449829ba5e6eee386610 100644 (file)
--- a/model.h
+++ b/model.h
@@ -8,7 +8,7 @@
 #include "skaterift.h"
 
 #define MDL_VERSION_MIN 101
 #include "skaterift.h"
 
 #define MDL_VERSION_MIN 101
-#define MDL_VERSION_NR 102
+#define MDL_VERSION_NR 103
 
 enum mdl_shader{
    k_shader_standard                = 0,
 
 enum mdl_shader{
    k_shader_standard                = 0,
index 3b2837fa09e329a22436ea038c849c8458264637..bf7916e33369a94ea7017d59ce8e664ca1c5b12d 100644 (file)
@@ -10,6 +10,7 @@
 #include "menu.h"
 #include "ent_challenge.h"
 #include "ent_skateshop.h"
 #include "menu.h"
 #include "ent_challenge.h"
 #include "ent_skateshop.h"
+#include "ent_route.h"
 
 static void world_entity_focus( u32 entity_id ){
    localplayer.immobile = 1;
 
 static void world_entity_focus( u32 entity_id ){
    localplayer.immobile = 1;
@@ -29,6 +30,27 @@ static void world_entity_unfocus(void){
    srinput.enabled = 0;
 }
 
    srinput.enabled = 0;
 }
 
+static void world_entity_focus_camera( world_instance *world, u32 uid ){
+   if( mdl_entity_id_type( uid ) == k_ent_camera ){
+      u32 index = mdl_entity_id_id( uid );
+      ent_camera *cam = mdl_arritm( &world->ent_camera, index );
+
+      v3f dir = {0.0f,-1.0f,0.0f};
+      mdl_transform_vector( &cam->transform, dir, dir );
+      m3x3_mulv( localplayer.invbasis, dir, dir );
+      player_vector_angles( world_static.focus_cam.angles, dir, 1.0f, 0.0f );
+      v3_copy( cam->transform.co, world_static.focus_cam.pos );
+      world_static.focus_cam.fov = cam->fov;
+   }
+   else {
+      camera_copy( &localplayer.cam, &world_static.focus_cam );
+
+      /* TODO ? */
+      world_static.focus_cam.nearz = localplayer.cam.nearz;
+      world_static.focus_cam.farz = localplayer.cam.farz;
+   }
+}
+
 /* logic preupdate */
 static void world_entity_focus_preupdate(void){
    f32 rate = vg_minf( 1.0f, vg.time_frame_delta * 2.0f );
 /* logic preupdate */
 static void world_entity_focus_preupdate(void){
    f32 rate = vg_minf( 1.0f, vg.time_frame_delta * 2.0f );
@@ -43,6 +65,7 @@ static void world_entity_focus_preupdate(void){
        index = mdl_entity_id_id( world_static.focused_entity );
    world_instance *world = world_current_instance();
 
        index = mdl_entity_id_id( world_static.focused_entity );
    world_instance *world = world_current_instance();
 
+   /* TODO: Table. */
    if( type == k_ent_skateshop ){
       ent_skateshop *skateshop = mdl_arritm( &world->ent_skateshop, index );
       ent_skateshop_preupdate( skateshop, active );
    if( type == k_ent_skateshop ){
       ent_skateshop *skateshop = mdl_arritm( &world->ent_skateshop, index );
       ent_skateshop_preupdate( skateshop, active );
@@ -51,6 +74,10 @@ static void world_entity_focus_preupdate(void){
       ent_challenge *challenge = mdl_arritm( &world->ent_challenge, index );
       ent_challenge_preupdate( challenge, active );
    }
       ent_challenge *challenge = mdl_arritm( &world->ent_challenge, index );
       ent_challenge_preupdate( challenge, active );
    }
+   else if( type == k_ent_route ){
+      ent_route *route = mdl_arritm( &world->ent_route, index );
+      ent_route_preupdate( route, active );
+   }
 }
 
 /* additional renderings like text etc.. */
 }
 
 /* additional renderings like text etc.. */
@@ -67,7 +94,8 @@ static void world_entity_focus_render(void){
       skateshop_render( skateshop );
    }
    else if( type == k_ent_challenge ){
       skateshop_render( skateshop );
    }
    else if( type == k_ent_challenge ){
-      
+   }
+   else if( type == k_ent_route ){
    }
    else {
       vg_fatal_error( "Programming error\n" );
    }
    else {
       vg_fatal_error( "Programming error\n" );
index 49e2cd5a77b1ed13912aa58cbb66ed0dd6806629..1e5e70c684d55e4ace42df0749ce31d008a602fb 100644 (file)
@@ -30,6 +30,7 @@ static void world_entity_focus( u32 entity_id );
 static void world_entity_focus_preupdate(void);
 static void world_entity_focus_render(void);
 static void world_entity_unfocus();
 static void world_entity_focus_preupdate(void);
 static void world_entity_focus_render(void);
 static void world_entity_unfocus();
+static void world_entity_focus_camera( world_instance *world, u32 uid );
 
 static bh_system bh_system_entity_list = {
    .expand_bound = entity_bh_expand_bound,
 
 static bh_system bh_system_entity_list = {
    .expand_bound = entity_bh_expand_bound,