From f01a25e33a54c92e4d6bca0889b76f33af5e51eb Mon Sep 17 00:00:00 2001 From: hgn Date: Tue, 19 Mar 2024 13:33:08 +0000 Subject: [PATCH] (50c0271) --- ent_challenge.c | 22 ++++++++++-------- ent_challenge.h | 2 +- ent_glider.c | 19 ++++++++------- ent_glider.h | 2 +- ent_miniworld.c | 17 ++++++++++---- ent_miniworld.h | 2 +- ent_npc.c | 25 ++++++++++++++------ ent_npc.h | 2 +- ent_objective.c | 33 ++++++++++++++++---------- ent_objective.h | 2 +- ent_region.c | 26 ++++++++++++++------- ent_region.h | 2 +- ent_relay.c | 18 ++++++++------- ent_relay.h | 2 +- ent_route.c | 14 ++++++------ ent_route.h | 2 +- ent_skateshop.c | 13 +++++++---- ent_skateshop.h | 2 +- entity.c | 18 ++++++++++----- entity.h | 26 +++++++++++++++------ shaders/impl.c | 13 +++++++---- world_entity.c | 61 +++++++++++++++++++++++++++++++++---------------- world_entity.h | 6 ++--- world_gate.c | 18 +++++++++------ world_gate.h | 2 +- 25 files changed, 225 insertions(+), 124 deletions(-) diff --git a/ent_challenge.c b/ent_challenge.c index 8f8c277..9499d0f 100644 --- a/ent_challenge.c +++ b/ent_challenge.c @@ -4,13 +4,15 @@ #include "gui.h" #include "audio.h" -void ent_challenge_call( world_instance *world, ent_call *call ) +entity_call_result ent_challenge_call( world_instance *world, ent_call *call ) { u32 index = mdl_entity_id_id( call->id ); ent_challenge *challenge = mdl_arritm( &world->ent_challenge, index ); - if( call->function == 0 ){ /* unlock() */ - if( !challenge->status ){ + if( call->function == 0 ) /* unlock() */ + { + if( !challenge->status ) + { vg_info( "challenge( '%s' )\n", mdl_pstr( &world->meta, challenge->pstr_alias) ); ent_call call; @@ -20,10 +22,13 @@ void ent_challenge_call( world_instance *world, ent_call *call ) entity_call( world, &call ); } challenge->status = 1; + return k_entity_call_result_OK; } - else if( call->function == 1 ){ /* view() */ + else if( call->function == 1 ) /* view() */ + { if( (localplayer.subsystem == k_player_subsystem_walk) && - (world_static.challenge_target == NULL) ){ + (world_static.challenge_target == NULL) ) + { world_static.challenge_target = NULL; world_entity_set_focus( call->id ); world_entity_focus_modal(); @@ -35,11 +40,10 @@ void ent_challenge_call( world_instance *world, ent_call *call ) if( gui_new_helper( input_button_list[k_srbind_mback], &text )) vg_strcat( &text, "exit" ); } + return k_entity_call_result_OK; } - else { - vg_print_backtrace(); - vg_error( "Unhandled function id: %u\n", call->function ); - } + else + return k_entity_call_result_unhandled; } void ent_challenge_preupdate( ent_challenge *challenge, int active ) diff --git a/ent_challenge.h b/ent_challenge.h index 9b9ea10..d5108a8 100644 --- a/ent_challenge.h +++ b/ent_challenge.h @@ -2,4 +2,4 @@ #include "entity.h" void ent_challenge_preupdate( ent_challenge *challenge, int active ); -void ent_challenge_call( world_instance *world, ent_call *call ); +entity_call_result ent_challenge_call( world_instance *world, ent_call *call ); diff --git a/ent_glider.c b/ent_glider.c index dbea8ea..12b0575 100644 --- a/ent_glider.c +++ b/ent_glider.c @@ -2,21 +2,24 @@ #include "entity.h" #include "player_glide.h" -void ent_glider_call( world_instance *world, ent_call *call ) +entity_call_result ent_glider_call( world_instance *world, ent_call *call ) { u32 index = mdl_entity_id_id( call->id ); ent_glider *glider = mdl_arritm( &world->ent_glider, index ); - if( call->function == 0 ){ + if( call->function == 0 ) + { glider->flags |= 0x1; + return k_entity_call_result_OK; } - else if( call->function == 1 ){ - if( glider->flags & 0x1 ){ + else if( call->function == 1 ) + { + if( glider->flags & 0x1 ) + { player_glide_equip_glider(); } + return k_entity_call_result_OK; } - else { - vg_print_backtrace(); - vg_error( "Unhandled function id: %i\n", call->function ); - } + else + return k_entity_call_result_unhandled; } diff --git a/ent_glider.h b/ent_glider.h index 51857b2..5815dda 100644 --- a/ent_glider.h +++ b/ent_glider.h @@ -1,4 +1,4 @@ #pragma once #include "entity.h" -void ent_glider_call( world_instance *world, ent_call *call ); +entity_call_result ent_glider_call( world_instance *world, ent_call *call ); diff --git a/ent_miniworld.c b/ent_miniworld.c index fcdba0b..2fed031 100644 --- a/ent_miniworld.c +++ b/ent_miniworld.c @@ -9,14 +9,15 @@ struct global_miniworld global_miniworld; -void ent_miniworld_call( world_instance *world, ent_call *call ) +entity_call_result ent_miniworld_call( world_instance *world, ent_call *call ) { ent_miniworld *miniworld = mdl_arritm( &world->ent_miniworld, mdl_entity_id_id(call->id) ); int world_id = world - world_static.instances; - if( call->function == 0 ){ /* zone() */ + if( call->function == 0 ) /* zone() */ + { const char *uid = mdl_pstr( &world->meta, miniworld->pstr_world ); skaterift_load_world_command( 1, (const char *[]){ uid } ); @@ -28,17 +29,25 @@ void ent_miniworld_call( world_instance *world, ent_call *call ) if( gui_new_helper( input_button_list[k_srbind_miniworld_resume], &text )) vg_strcat( &text, "Enter World" ); + + return k_entity_call_result_OK; } - else if( call->function == 1 ){ + else if( call->function == 1 ) + { global_miniworld.active = NULL; gui_helper_clear(); - if( miniworld->proxy ){ + if( miniworld->proxy ) + { ent_prop *prop = mdl_arritm( &world->ent_prop, mdl_entity_id_id(miniworld->proxy) ); prop->flags &= ~0x1; } + + return k_entity_call_result_OK; } + else + return k_entity_call_result_unhandled; } static void miniworld_icon( vg_camera *cam, enum gui_icon icon, diff --git a/ent_miniworld.h b/ent_miniworld.h index b1aed55..278cf75 100644 --- a/ent_miniworld.h +++ b/ent_miniworld.h @@ -12,7 +12,7 @@ struct global_miniworld } extern global_miniworld; -void ent_miniworld_call( world_instance *world, ent_call *call ); +entity_call_result ent_miniworld_call( world_instance *world, ent_call *call ); void ent_miniworld_render( world_instance *host_world, vg_camera *cam ); void ent_miniworld_goback(void); void ent_miniworld_preupdate(void); diff --git a/ent_npc.c b/ent_npc.c index d431223..8fccd29 100644 --- a/ent_npc.c +++ b/ent_npc.c @@ -70,7 +70,7 @@ static struct npc *npc_resolve( u32 id ) else return NULL; } -static void npc_slowmo_call( ent_npc *npc, ent_call *call ) +static entity_call_result npc_slowmo_call( ent_npc *npc, ent_call *call ) { if( call->function == 0 ) { @@ -96,22 +96,26 @@ static void npc_slowmo_call( ent_npc *npc, ent_call *call ) if( gui_new_helper( input_button_list[k_srbind_replay_resume], &text )) vg_strcat( &text, "Resume" ); } + return k_entity_call_result_OK; } else if( call->function == -1 ) { world_entity_clear_focus(); gui_helper_clear(); + return k_entity_call_result_OK; } + else + return k_entity_call_result_unhandled; } -void ent_npc_call( world_instance *world, ent_call *call ) +entity_call_result ent_npc_call( world_instance *world, ent_call *call ) { u32 index = mdl_entity_id_id( call->id ); ent_npc *npc = mdl_arritm( &world->ent_npc, index ); if( npc->id == 2 ) { - npc_slowmo_call( npc, call ); + return npc_slowmo_call( npc, call ); } else if( npc->id == 3 ) { @@ -122,12 +126,16 @@ void ent_npc_call( world_instance *world, ent_call *call ) vg_str text; if( gui_new_helper( input_button_list[k_srbind_maccept], &text )) vg_strcat( &text, "Preview course" ); + return k_entity_call_result_OK; } else if( call->function == -1 ) { world_entity_clear_focus(); gui_helper_clear(); + return k_entity_call_result_OK; } + else + return k_entity_call_result_unhandled; } else if( npc->id == 4 ) { @@ -137,11 +145,15 @@ void ent_npc_call( world_instance *world, ent_call *call ) vg_str text; if( gui_new_helper( input_button_list[k_srbind_camera], &text )) vg_strcat( &text, "First/Thirdperson" ); + return k_entity_call_result_OK; } else if( call->function == -1 ) { gui_helper_clear(); + return k_entity_call_result_OK; } + else + return k_entity_call_result_unhandled; } else { @@ -152,17 +164,16 @@ void ent_npc_call( world_instance *world, ent_call *call ) vg_str text; if( gui_new_helper( input_button_list[k_srbind_maccept], &text )) vg_strcat( &text, "Talk to ???" ); + return k_entity_call_result_OK; } else if( call->function == -1 ) { world_entity_clear_focus(); gui_helper_clear(); + return k_entity_call_result_OK; } else - { - vg_print_backtrace(); - vg_error( "Unhandled function id: %i\n", call->function ); - } + return k_entity_call_result_unhandled; } } diff --git a/ent_npc.h b/ent_npc.h index 24e7e02..648f447 100644 --- a/ent_npc.h +++ b/ent_npc.h @@ -22,7 +22,7 @@ enum npc_id void npc_load_model( struct npc *npc, const char *path ); void ent_npc_preupdate( ent_npc *ent, int active ); -void ent_npc_call( world_instance *world, ent_call *call ); +entity_call_result ent_npc_call( world_instance *world, ent_call *call ); void npc_update( ent_npc *ent ); void npc_render( ent_npc *ent, world_instance *world, vg_camera *cam ); void npc_init(void); diff --git a/ent_objective.c b/ent_objective.c index 66b822d..6a8bbe5 100644 --- a/ent_objective.c +++ b/ent_objective.c @@ -81,21 +81,26 @@ static int ent_objective_check_filter( ent_objective *objective ){ } } -void ent_objective_call( world_instance *world, ent_call *call ) +entity_call_result ent_objective_call( world_instance *world, ent_call *call ) { u32 index = mdl_entity_id_id( call->id ); ent_objective *objective = mdl_arritm( &world->ent_objective, index ); - if( call->function == 0 ){ - if( objective->flags & (k_ent_objective_hidden| - k_ent_objective_passed)) return; + if( call->function == 0 ) + { + if( objective->flags & (k_ent_objective_hidden|k_ent_objective_passed)) + { + return k_entity_call_result_OK; + } - if( world_static.challenge_target ){ + if( world_static.challenge_target ) + { if( (world_static.challenge_target == objective) && ent_objective_check_filter( objective )){ ent_objective_pass( world, objective ); } - else { + else + { audio_lock(); audio_oneshot_3d( &audio_challenge[6], localplayer.rb.co, 30.0f, 1.0f ); @@ -106,25 +111,29 @@ void ent_objective_call( world_instance *world, ent_call *call ) world_static.focused_entity = 0; } } + + return k_entity_call_result_OK; } - else if( call->function == 2 ){ + else if( call->function == 2 ) + { objective->flags &= ~k_ent_objective_hidden; if( mdl_entity_id_type( objective->id_next ) == k_ent_objective ){ call->id = objective->id_next; entity_call( world, call ); } + return k_entity_call_result_OK; } - else if( call->function == 3 ){ + else if( call->function == 3 ) + { objective->flags |= k_ent_objective_hidden; if( mdl_entity_id_type( objective->id_next ) == k_ent_objective ){ call->id = objective->id_next; entity_call( world, call ); } + return k_entity_call_result_OK; } - else { - vg_print_backtrace(); - vg_error( "Unhandled function id: %u\n", call->function ); - } + else + return k_entity_call_result_unhandled; } diff --git a/ent_objective.h b/ent_objective.h index 0f3e4e5..9d94772 100644 --- a/ent_objective.h +++ b/ent_objective.h @@ -1,4 +1,4 @@ #pragma once #include "entity.h" #include "world.h" -void ent_objective_call( world_instance *world, ent_call *call ); +entity_call_result ent_objective_call( world_instance *world, ent_call *call ); diff --git a/ent_region.c b/ent_region.c index e58d594..5e0ec03 100644 --- a/ent_region.c +++ b/ent_region.c @@ -15,29 +15,33 @@ u32 region_spark_colour( u32 flags ) return 0x00; } -void ent_region_call( world_instance *world, ent_call *call ) +entity_call_result ent_region_call( world_instance *world, ent_call *call ) { ent_region *region = mdl_arritm( &world->ent_region, mdl_entity_id_id(call->id) ); if( !region->zone_volume ) - return; + return k_entity_call_result_invalid; ent_volume *volume = mdl_arritm( &world->ent_volume, mdl_entity_id_id(region->zone_volume) ); - if( call->function == 0 ){ /* enter */ - for( u32 i=0; ient_route); i ++ ){ + if( call->function == 0 ) /* enter */ + { + for( u32 i=0; ient_route); i ++ ) + { ent_route *route = mdl_arritm( &world->ent_route, i ); v3f local; m4x3_mulv( volume->to_local, route->board_transform[3], local ); if( (fabsf(local[0]) <= 1.0f) && (fabsf(local[1]) <= 1.0f) && - (fabsf(local[2]) <= 1.0f) ){ + (fabsf(local[2]) <= 1.0f) ) + { route->flags &= ~k_ent_route_flag_out_of_zone; } - else { + else + { route->flags |= k_ent_route_flag_out_of_zone; } } @@ -52,14 +56,20 @@ void ent_region_call( world_instance *world, ent_call *call ) network_send_region(); localplayer.effect_data.spark.colour = region_spark_colour(region->flags); + return k_entity_call_result_OK; } - else if( call->function == 1 ){ /* leave */ - for( u32 i=0; ient_route); i ++ ){ + else if( call->function == 1 ) /* leave */ + { + for( u32 i=0; ient_route); i ++ ) + { ent_route *route = mdl_arritm( &world->ent_route, i ); route->flags |= k_ent_route_flag_out_of_zone; } localplayer.effect_data.spark.colour = 0x00; + return k_entity_call_result_OK; } + else + return k_entity_call_result_unhandled; } /* diff --git a/ent_region.h b/ent_region.h index 8aed240..6a86a32 100644 --- a/ent_region.h +++ b/ent_region.h @@ -11,4 +11,4 @@ extern global_ent_region; u32 region_spark_colour( u32 flags ); void ent_region_re_eval( world_instance *world ); -void ent_region_call( world_instance *world, ent_call *call ); +entity_call_result ent_region_call( world_instance *world, ent_call *call ); diff --git a/ent_relay.c b/ent_relay.c index 50bbeab..1f97584 100644 --- a/ent_relay.c +++ b/ent_relay.c @@ -1,13 +1,16 @@ #include "ent_relay.h" -void ent_relay_call( world_instance *world, ent_call *call ) +entity_call_result ent_relay_call( world_instance *world, ent_call *call ) { u32 index = mdl_entity_id_id( call->id ); ent_relay *relay = mdl_arritm( &world->ent_relay, index ); - if( call->function == 0 ){ - for( u32 i=0; itargets); i++ ){ - if( relay->targets[i][0] ){ + if( call->function == 0 ) + { + for( u32 i=0; itargets); i++ ) + { + if( relay->targets[i][0] ) + { ent_call call; call.data = NULL; call.function = relay->targets[i][1]; @@ -15,9 +18,8 @@ void ent_relay_call( world_instance *world, ent_call *call ) entity_call( world, &call ); } } + return k_entity_call_result_OK; } - else { - vg_print_backtrace(); - vg_error( "Unhandled function id: %u\n", call->function ); - } + else + return k_entity_call_result_unhandled; } diff --git a/ent_relay.h b/ent_relay.h index acbe943..054570c 100644 --- a/ent_relay.h +++ b/ent_relay.h @@ -1,3 +1,3 @@ #pragma once #include "entity.h" -void ent_relay_call( world_instance *world, ent_call *call ); +entity_call_result ent_relay_call( world_instance *world, ent_call *call ); diff --git a/ent_route.c b/ent_route.c index 11b680d..026bf70 100644 --- a/ent_route.c +++ b/ent_route.c @@ -4,12 +4,13 @@ struct global_ent_route global_ent_route; -void ent_route_call( world_instance *world, ent_call *call ) +entity_call_result 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( call->function == 0 ) + { /* view() */ if( localplayer.subsystem == k_player_subsystem_walk ) { world_entity_set_focus( call->id ); @@ -29,12 +30,11 @@ void ent_route_call( world_instance *world, ent_call *call ) if( gui_new_helper( input_button_list[k_srbind_mback], &text ) ) vg_strcat( &text, "exit" ); } + + return k_entity_call_result_OK; } - else { - /* TODO: Comrpession */ - vg_print_backtrace(); - vg_error( "Unhandled function id: %u\n", call->function ); - } + + return k_entity_call_result_unhandled; } /* TODO: these should recieve the world instance */ diff --git a/ent_route.h b/ent_route.h index ecc3278..7c5dfa3 100644 --- a/ent_route.h +++ b/ent_route.h @@ -7,5 +7,5 @@ struct global_ent_route } extern global_ent_route; -void ent_route_call( world_instance *world, ent_call *call ); +entity_call_result ent_route_call( world_instance *world, ent_call *call ); void ent_route_preupdate( ent_route *route, int active ); diff --git a/ent_skateshop.c b/ent_skateshop.c index d5128f0..1065d4b 100644 --- a/ent_skateshop.c +++ b/ent_skateshop.c @@ -797,18 +797,20 @@ static void world_scan_thread( void *_args ) /* * Entity logic: entrance event */ -void ent_skateshop_call( world_instance *world, ent_call *call ) +entity_call_result 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" ); - if( skaterift.activity != k_skaterift_default ) return; - if( !vg_loader_availible() ) return; + if( (skaterift.activity != k_skaterift_default) || + !vg_loader_availible() ) + return k_entity_call_result_invalid; if( call->function == k_ent_function_trigger ) { - if( localplayer.subsystem != k_player_subsystem_walk ) return; + if( localplayer.subsystem != k_player_subsystem_walk ) + return k_entity_call_result_OK; vg_info( "Entering skateshop\n" ); @@ -840,5 +842,8 @@ void ent_skateshop_call( world_instance *world, ent_call *call ) vg_strcat( &text, "exit" ); skateshop_server_helper_update(); } + return k_entity_call_result_OK; } + else + return k_entity_call_result_unhandled; } diff --git a/ent_skateshop.h b/ent_skateshop.h index cf8b983..ed03ecd 100644 --- a/ent_skateshop.h +++ b/ent_skateshop.h @@ -50,5 +50,5 @@ void skateshop_render( ent_skateshop *shop ); void skateshop_render_nonfocused( world_instance *world, vg_camera *cam ); void skateshop_autostart_loading(void); void skateshop_world_preupdate( world_instance *world ); -void ent_skateshop_call( world_instance *world, ent_call *call ); +entity_call_result ent_skateshop_call( world_instance *world, ent_call *call ); void skateshop_world_preview_preupdate(void); diff --git a/entity.c b/entity.c index 557ba79..ae506bd 100644 --- a/entity.c +++ b/entity.c @@ -12,11 +12,10 @@ #include "ent_glider.h" #include "ent_npc.h" -typedef void (*fn_entity_call_handler)( world_instance *, ent_call *); - void entity_call( world_instance *world, ent_call *call ) { - u32 type = mdl_entity_id_type( call->id ); + u32 type = mdl_entity_id_type( call->id ), + index = mdl_entity_id_id( call->id ); fn_entity_call_handler table[] = { [k_ent_volume] = ent_volume_call, @@ -41,12 +40,19 @@ void entity_call( world_instance *world, ent_call *call ) fn_entity_call_handler fn = table[ type ]; - if( !fn ){ - vg_error( "call to entity type: %u is undefined\n", type ); + if( !fn ) + { + vg_error( "Entity type %u does not have a call handler, " + "but was called anyway\n", type ); return; } - fn( world, call ); + enum entity_call_result res = fn( world, call ); + + if( res == k_entity_call_result_unhandled ) + { + vg_warn( "Call to entity %u#%u was unhandled.\n", type, index ); + } } ent_marker *ent_find_marker( mdl_context *mdl, mdl_array_ptr *arr, diff --git a/entity.h b/entity.h index d67c5f3..80f4df7 100644 --- a/entity.h +++ b/entity.h @@ -38,6 +38,25 @@ typedef struct ent_list ent_list; typedef struct ent_glider ent_glider; typedef struct ent_npc ent_npc; +typedef struct ent_call ent_call; +struct ent_call{ + u32 id; + i32 function; + void *data; +}; + +typedef enum entity_call_result entity_call_result; +enum entity_call_result +{ + k_entity_call_result_OK, + k_entity_call_result_unhandled, + k_entity_call_result_invalid +}; + +typedef enum entity_call_result + (*fn_entity_call_handler)( world_instance *, ent_call *); + + enum entity_alias{ k_ent_none = 0, k_ent_gate = 1, @@ -527,13 +546,6 @@ struct ent_cubemap { framebuffer_id, renderbuffer_id, placeholder[2]; }; -typedef struct ent_call ent_call; -struct ent_call{ - u32 id; - i32 function; - void *data; -}; - struct ent_miniworld { mdl_transform transform; u32 pstr_world; diff --git a/shaders/impl.c b/shaders/impl.c index dbcebf8..7462794 100644 --- a/shaders/impl.c +++ b/shaders/impl.c @@ -4507,7 +4507,9 @@ struct vg_shader _shader_scene_depth = { "\n" " float d = dot( pnorm, halfview );\n" " float t = dot((pnorm*pdist - pos), pnorm) / d;\n" -" return t * g_water_fog;\n" +"\n" +" // TODO: Make g_water_fog a material param\n" +" return t * 0.3;//g_water_fog;\n" "}\n" "\n" "void main()\n" @@ -6018,7 +6020,8 @@ struct vg_shader _shader_scene_water = { "{\n" " vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);\n" "\n" -" float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);\n" +" //TODO: Make exponent a material param (default: 5.0)\n" +" float ffresnel = pow(1.0-dot( vnorm, halfview ),0.8);\n" "\n" " vec3 lightdir = vec3(0.95,0.0,-0.3);\n" " vec3 specdir = reflect( -lightdir, vnorm );\n" @@ -6062,8 +6065,10 @@ struct vg_shader _shader_scene_water = { " // Surface colour composite\n" " float depthvalue = clamp( -world_water_depth(aCo)*(1.0/25.0), 0.0,1.0 );\n" "\n" -" vec2 world_coord = aCo.xz * 0.008;\n" -" vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );\n" +" //TODO: Material param (default: 0.008)\n" +" vec2 world_coord = aCo.xz * 0.12;\n" +" //TODO: Material param ( 0.008, 0.006, 0.003, 0.03 );\n" +" vec4 time_offsets = vec4( uTime ) * vec4( 0.08, -0.08, -0.03, -0.01 );\n" " vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;\n" " vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;\n" "\n" diff --git a/world_entity.c b/world_entity.c index 88e0e7e..13c89a0 100644 --- a/world_entity.c +++ b/world_entity.c @@ -347,16 +347,20 @@ void world_default_spawn_pos( world_instance *world, v3f pos ) } } -void ent_volume_call( world_instance *world, ent_call *call ) +entity_call_result ent_volume_call( world_instance *world, ent_call *call ) { u32 index = mdl_entity_id_id( call->id ); ent_volume *volume = mdl_arritm( &world->ent_volume, index ); - if( !volume->target ) return; - if( call->function == k_ent_function_trigger ){ + if( !volume->target ) + return k_entity_call_result_OK; + + if( call->function == k_ent_function_trigger ) + { call->id = volume->target; - if( volume->flags & k_ent_volume_flag_particles ){ + if( volume->flags & k_ent_volume_flag_particles ) + { float *co = alloca( sizeof(float)*3 ); co[0] = vg_randf64(&vg.rand)*2.0f-1.0f; co[1] = vg_randf64(&vg.rand)*2.0f-1.0f; @@ -367,29 +371,40 @@ void ent_volume_call( world_instance *world, ent_call *call ) call->data = co; entity_call( world, call ); } - else{ + else + { call->function = volume->trigger.event; entity_call( world, call ); } + + return k_entity_call_result_OK; } - else if( call->function == k_ent_function_trigger_leave ){ + else if( call->function == k_ent_function_trigger_leave ) + { call->id = volume->target; - if( volume->flags & k_ent_volume_flag_particles ){ + if( volume->flags & k_ent_volume_flag_particles ) + { vg_warn( "Invalid condition; calling leave on particle volume.\n" ); } - else{ + else + { call->function = volume->trigger.event_leave; entity_call( world, call ); } + + return k_entity_call_result_OK; } + + return k_entity_call_result_unhandled; } -void ent_audio_call( world_instance *world, ent_call *call ) +entity_call_result ent_audio_call( world_instance *world, ent_call *call ) { - if( world->status == k_world_status_unloading ){ + if( world->status == k_world_status_unloading ) + { vg_warn( "cannot modify audio while unloading world\n" ); - return; + return k_entity_call_result_invalid; } u8 world_id = (world - world_static.instances) + 1; @@ -398,14 +413,16 @@ void ent_audio_call( world_instance *world, ent_call *call ) v3f sound_co; - if( call->function == k_ent_function_particle_spawn ){ + if( call->function == k_ent_function_particle_spawn ) + { v3_copy( call->data, sound_co ); } - else if( call->function == k_ent_function_trigger ){ + else if( call->function == k_ent_function_trigger ) + { v3_copy( audio->transform.co, sound_co ); } else - return; + return k_entity_call_result_unhandled; float chance = vg_randf64(&vg.rand)*100.0f, bar = 0.0f; @@ -458,7 +475,7 @@ void ent_audio_call( world_instance *world, ent_call *call ) if( existing ){ if( existing->source == &clip->_.clip ){ audio_unlock(); - return; + return k_entity_call_result_OK; } existing->group = 0; @@ -479,20 +496,24 @@ void ent_audio_call( world_instance *world, ent_call *call ) } audio_unlock(); - return; + return k_entity_call_result_OK; } } + return k_entity_call_result_OK; } -void ent_ccmd_call( world_instance *world, ent_call *call ) +entity_call_result ent_ccmd_call( world_instance *world, ent_call *call ) { - if( call->function == k_ent_function_trigger ){ + if( call->function == k_ent_function_trigger ) + { u32 index = mdl_entity_id_id( call->id ); ent_ccmd *ccmd = mdl_arritm( &world->ent_ccmd, index ); - vg_execute_console_input( mdl_pstr(&world->meta, ccmd->pstr_command), - 0 ); + vg_execute_console_input( mdl_pstr(&world->meta, ccmd->pstr_command), 0 ); + return k_entity_call_result_OK; } + else + return k_entity_call_result_unhandled; } /* diff --git a/world_entity.h b/world_entity.h index f9a3ec9..5f784d2 100644 --- a/world_entity.h +++ b/world_entity.h @@ -13,9 +13,9 @@ void world_default_spawn_pos( world_instance *world, v3f pos ); void world_entity_start( world_instance *world, vg_msg *sav ); void world_entity_serialize( world_instance *world, vg_msg *sav ); -void ent_volume_call( world_instance *world, ent_call *call ); -void ent_audio_call( world_instance *world, ent_call *call ); -void ent_ccmd_call( world_instance *world, ent_call *call ); +entity_call_result ent_volume_call( world_instance *world, ent_call *call ); +entity_call_result ent_audio_call( world_instance *world, ent_call *call ); +entity_call_result ent_ccmd_call( world_instance *world, ent_call *call ); void entity_bh_expand_bound( void *user, boxf bound, u32 item_index ); float entity_bh_centroid( void *user, u32 item_index, int axis ); diff --git a/world_gate.c b/world_gate.c index 26ce092..2a236d4 100644 --- a/world_gate.c +++ b/world_gate.c @@ -295,17 +295,19 @@ u32 world_intersect_gates( world_instance *world, v3f pos, v3f last ) return 0; } -void ent_gate_call( world_instance *world, ent_call *call ) +entity_call_result ent_gate_call( world_instance *world, ent_call *call ) { u32 index = mdl_entity_id_id( call->id ); ent_gate *gate = mdl_arritm( &world->ent_gate, index ); - if( call->function == 0 ){ /* unlock() */ + if( call->function == 0 ) /* unlock() */ + { gate->flags &= ~k_ent_gate_locked; + return k_entity_call_result_OK; } - else { - vg_print_backtrace(); - vg_error( "Unhandled function id: %u\n", call->function ); + else + { + return k_entity_call_result_unhandled; } } @@ -315,10 +317,12 @@ void ent_gate_call( world_instance *world, ent_call *call ) */ void world_unlink_nonlocal( world_instance *world ) { - for( u32 j=0; jent_gate); j ++ ){ + for( u32 j=0; jent_gate); j ++ ) + { ent_gate *gate = mdl_arritm( &world->ent_gate, j ); - if( gate->flags & k_ent_gate_nonlocal ){ + if( gate->flags & k_ent_gate_nonlocal ) + { gate->flags &= ~k_ent_gate_linked; } } diff --git a/world_gate.h b/world_gate.h index 13b1478..a071e4b 100644 --- a/world_gate.h +++ b/world_gate.h @@ -27,7 +27,7 @@ int render_gate( world_instance *world, world_instance *world_inside, int gate_intersect( ent_gate *gate, v3f pos, v3f last ); u32 world_intersect_gates( world_instance *world, v3f pos, v3f last ); -void ent_gate_call( world_instance *world, ent_call *call ); +entity_call_result ent_gate_call( world_instance *world, ent_call *call ); void ent_gate_get_mdl_mtx( ent_gate *gate, m4x3f mmdl ); void world_link_gates_async( void *payload, u32 size ); -- 2.25.1