From: hgn Date: Thu, 12 Oct 2023 16:56:44 +0000 (+0100) Subject: add basic controls to ent_routes X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;h=4eb81766e4e7c54599b057ebf57b7fab01cd0726;hp=9a63a9dde9257c8f140af3a96816bcda232fe739;p=carveJwlIkooP6JGAAIwe30JlM.git add basic controls to ent_routes --- diff --git a/blender_export.py b/blender_export.py index db6e97c..1646d83 100644 --- a/blender_export.py +++ b/blender_export.py @@ -42,9 +42,9 @@ sr_entity_list = [ ('ent_relay', 'Relay', '', 20 ) ] -MDL_VERSION_NR = 102 +MDL_VERSION_NR = 103 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 ): #{ @@ -263,7 +263,11 @@ class ent_route(Structure): ("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): @@ -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.id_camera = sr_entity_id( obj_data.cam ) 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") + 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' ) + layout.prop( data[0], 'cam' ) layout.label( text='Checkpoints' ) layout.template_list('SR_UL_ROUTE_NODE_LIST', 'Checkpoints', \ diff --git a/ent_challenge.c b/ent_challenge.c index 02fac7d..10196bf 100644 --- a/ent_challenge.c +++ b/ent_challenge.c @@ -66,26 +66,7 @@ static void ent_challenge_preupdate( ent_challenge *challenge, int active ){ 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" ); diff --git a/ent_route.c b/ent_route.c new file mode 100644 index 0000000..a114640 --- /dev/null +++ b/ent_route.c @@ -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 index 0000000..786d850 --- /dev/null +++ b/ent_route.h @@ -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 */ diff --git a/entity.c b/entity.c index 21815f4..287016a 100644 --- a/entity.c +++ b/entity.c @@ -9,6 +9,7 @@ #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 *); @@ -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_challenge] = ent_challenge_call + [k_ent_challenge] = ent_challenge_call, + [k_ent_route] = ent_route_call }; if( type >= vg_list_size(table) ){ diff --git a/entity.h b/entity.h index 4046452..0423791 100644 --- a/entity.h +++ b/entity.h @@ -177,10 +177,12 @@ struct ent_route{ u16 active_checkpoint, valid_checkpoints; - float factive; + f32 factive; m4x3f board_transform; mdl_submesh sm; - double timing_base; + f64 timing_base; + + u32 id_camera; /* v103+ */ }; struct ent_water{ diff --git a/maps_src/mp_mtzero/main.mdl b/maps_src/mp_mtzero/main.mdl index 29eebf3..8e98f1a 100644 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 c28455d..dae6038 100644 --- a/model.h +++ b/model.h @@ -8,7 +8,7 @@ #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, diff --git a/world_entity.c b/world_entity.c index 3b2837f..bf7916e 100644 --- a/world_entity.c +++ b/world_entity.c @@ -10,6 +10,7 @@ #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; @@ -29,6 +30,27 @@ static void world_entity_unfocus(void){ 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 ); @@ -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(); + /* TODO: Table. */ 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 ); } + 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.. */ @@ -67,7 +94,8 @@ static void world_entity_focus_render(void){ skateshop_render( skateshop ); } else if( type == k_ent_challenge ){ - + } + else if( type == k_ent_route ){ } else { vg_fatal_error( "Programming error\n" ); diff --git a/world_entity.h b/world_entity.h index 49e2cd5..1e5e70c 100644 --- a/world_entity.h +++ b/world_entity.h @@ -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_camera( world_instance *world, u32 uid ); static bh_system bh_system_entity_list = { .expand_bound = entity_bh_expand_bound,