X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=entity.c;fp=entity.c;h=cfc710618e60af5a26d6d1064c95ced82b4631e4;hb=7eba38b8178c82040618a518634d8ff4813e2ff2;hp=f5e8004510d104c3eb9799b572a6e9c168cef7d6;hpb=7d8f90d019453ff1186f16c2d36a08d5a53ad638;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/entity.c b/entity.c index f5e8004..cfc7106 100644 --- a/entity.c +++ b/entity.c @@ -6,20 +6,34 @@ #include "world_entity.h" #include "ent_skateshop.c" +#include "ent_challenge.c" -VG_STATIC void entity_call( world_instance *world, ent_call *call ) -{ +typedef void (*fn_entity_call_handler)( world_instance *, ent_call *); + +VG_STATIC void entity_call( world_instance *world, ent_call *call ){ 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 ); + 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_challenge] = ent_challenge_call, + [k_ent_ccmd] = ent_ccmd_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 ]; + + if( !fn ){ + vg_error( "call to entity type: %u is undefined\n", type ); + return; } + + fn( world, call ); } #endif /* ENTITY_C */