515aeb09d5e456b813dbb00c40642cc7fa72348a
[carveJwlIkooP6JGAAIwe30JlM.git] / ent_challenge.c
1 #ifndef ENT_CHALLENGE_C
2 #define ENT_CHALLENGE_C
3
4 #include "entity.h"
5 #include "input.h"
6
7 VG_STATIC void ent_challenge_call( world_instance *world, ent_call *call ){
8 u32 index = mdl_entity_id_id( call->id );
9 ent_challenge *challenge = mdl_arritm( &world->ent_challenge, index );
10
11 if( call->function == 0 ){ /* challenge() */
12 if( !challenge->status ){
13 vg_info( "challenge( '%s' )\n",
14 mdl_pstr( &world->meta, challenge->pstr_alias) );
15 ent_call call;
16 call.data = NULL;
17 call.function = challenge->target_event;
18 call.id = challenge->target;
19 entity_call( world, &call );
20 }
21 challenge->status = 1;
22 }
23 else if( call->function == 1 ){ /* view() */
24 world_entity_focus( call->id );
25 }
26 else {
27 vg_print_backtrace();
28 vg_error( "Unhandled function id: %u\n", call->function );
29 }
30 }
31
32 VG_STATIC void ent_challenge_preupdate( ent_challenge *challenge ){
33 world_instance *world = world_current_instance();
34
35 if( mdl_entity_id_type( challenge->camera ) == k_ent_camera ){
36 u32 index = mdl_entity_id_id( challenge->camera );
37 ent_camera *cam = mdl_arritm( &world->ent_camera, index );
38
39 /* TODO COMPRESSION */
40 v3f dir = {0.0f,-1.0f,0.0f};
41 mdl_transform_vector( &cam->transform, dir, dir );
42 m3x3_mulv( localplayer.invbasis, dir, dir );
43 player_vector_angles( world_static.focus_cam.angles, dir, 1.0f, 0.0f );
44 v3_copy( cam->transform.co, world_static.focus_cam.pos );
45 world_static.focus_cam.fov = cam->fov;
46 }
47 else {
48 /* TODO COMPRESSION */
49 v3_copy( localplayer.cam.pos, world_static.focus_cam.pos );
50 v3_copy( localplayer.cam.angles, world_static.focus_cam.angles );
51 world_static.focus_cam.fov = localplayer.cam.fov;
52 world_static.focus_cam.nearz = localplayer.cam.nearz;
53 world_static.focus_cam.farz = localplayer.cam.farz;
54 }
55
56 if( button_down( k_srbind_mback ) ){
57 world_entity_unfocus();
58 return;
59 }
60 }
61
62 VG_STATIC void ent_challenge_render( ent_challenge *challenge ){
63
64 }
65
66 #endif /* ENT_CHALLENGE_C */