small refactor of model loading
[carveJwlIkooP6JGAAIwe30JlM.git] / entity.c
1 #include "world.h"
2 #include "entity.h"
3 #include "world_entity.h"
4
5 #include "ent_objective.h"
6 #include "ent_skateshop.h"
7 #include "ent_relay.h"
8 #include "ent_challenge.h"
9 #include "ent_route.h"
10 #include "ent_miniworld.h"
11 #include "ent_region.h"
12 #include "ent_glider.h"
13 #include "ent_npc.h"
14
15 typedef void (*fn_entity_call_handler)( world_instance *, ent_call *);
16
17 void entity_call( world_instance *world, ent_call *call )
18 {
19 u32 type = mdl_entity_id_type( call->id );
20
21 fn_entity_call_handler table[] = {
22 [k_ent_volume] = ent_volume_call,
23 [k_ent_audio] = ent_audio_call,
24 [k_ent_skateshop] = ent_skateshop_call,
25 [k_ent_objective] = ent_objective_call,
26 [k_ent_ccmd] = ent_ccmd_call,
27 [k_ent_gate] = ent_gate_call,
28 [k_ent_relay] = ent_relay_call,
29 [k_ent_challenge] = ent_challenge_call,
30 [k_ent_route] = ent_route_call,
31 [k_ent_miniworld] = ent_miniworld_call,
32 [k_ent_region] = ent_region_call,
33 [k_ent_glider] = ent_glider_call,
34 [k_ent_npc] = ent_npc_call
35 };
36
37 if( type >= vg_list_size(table) ){
38 vg_error( "call to entity type: %u is out of range\n", type );
39 return;
40 }
41
42 fn_entity_call_handler fn = table[ type ];
43
44 if( !fn ){
45 vg_error( "call to entity type: %u is undefined\n", type );
46 return;
47 }
48
49 fn( world, call );
50 }
51
52 ent_marker *ent_find_marker( mdl_context *mdl, mdl_array_ptr *arr,
53 const char *alias )
54 {
55 for( u32 i=0; i<mdl_arrcount(arr); i++ ){
56 ent_marker *marker = mdl_arritm( arr, i );
57
58 if( !strcmp( mdl_pstr( mdl, marker->pstr_alias ), alias ) ){
59 return marker;
60 }
61 }
62
63 return NULL;
64 }
65