X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=entity.c;h=ffb5deed5d9c0c9e905e1c39335b80c8173e04fe;hb=HEAD;hp=f5e8004510d104c3eb9799b572a6e9c168cef7d6;hpb=4c95c9c3e6033cd1360adacef3c80fc4da933715;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/entity.c b/entity.c index f5e8004..ffb5dee 100644 --- a/entity.c +++ b/entity.c @@ -1,25 +1,77 @@ -#ifndef ENTITY_C -#define ENTITY_C - #include "world.h" #include "entity.h" #include "world_entity.h" -#include "ent_skateshop.c" +#include "ent_objective.h" +#include "ent_skateshop.h" +#include "ent_relay.h" +#include "ent_challenge.h" +#include "ent_route.h" +#include "ent_miniworld.h" +#include "ent_region.h" +#include "ent_glider.h" +#include "ent_npc.h" +#include "world_water.h" + +#include + +void entity_call( world_instance *world, ent_call *call ) +{ + 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, + [k_ent_audio] = ent_audio_call, + [k_ent_skateshop] = ent_skateshop_call, + [k_ent_objective] = ent_objective_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_route] = ent_route_call, + [k_ent_miniworld] = ent_miniworld_call, + [k_ent_region] = ent_region_call, + [k_ent_glider] = ent_glider_call, + [k_ent_npc] = ent_npc_call, + [k_ent_water] = ent_water_call, + }; + + if( type >= vg_list_size(table) ){ + vg_error( "call to entity type: %u is out of range\n", type ); + return; + } + + fn_entity_call_handler fn = table[ type ]; -VG_STATIC void entity_call( world_instance *world, ent_call *call ) + if( !fn ) + { + vg_error( "Entity type %u does not have a call handler, " + "but was called anyway\n", type ); + return; + } + + 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, + const char *alias ) { - u32 type = mdl_entity_id_type( call->id ); - - if( type == k_ent_volume ){ - ent_volume_call( world, call ); - } else if( type == k_ent_audio ){ - ent_audio_call( world, call ); - } else if( type == k_ent_skateshop ){ - ent_skateshop_call( world, call ); - } else if( type == k_ent_ccmd ){ - ent_ccmd_call( world, call ); + for( u32 i=0; ipstr_alias ), alias ) ) + { + return marker; + } } + + return NULL; } -#endif /* ENTITY_C */