#include "FxEngine.h" FE_position FE_user={0,0,0}; double FE_dh,FE_dv,FE_roulis; static double px,py,pz; // instance flottante des coordonnées des joueurs static uint32_t frame_interval=0, frame_interval_min=1000001, frame_interval_max=1; // in milliseconds static bool loaded_before=false; static double dh_vel=0.05; static double dv_vel=0.05; static double roulis_vel=0.05; static void FE_move() { key_event_t event; while (true) { event=pollevent(); if (event.type&KEYEV_DOWN) { if (event.key==KEY_LEFT) FE_dh -= dh_vel; if (event.key==KEY_RIGHT) FE_dh += dh_vel; if (event.key==KEY_UP) FE_dv += dv_vel; if (event.key==KEY_DOWN) FE_dv -= dv_vel; if (event.key==KEY_PLUS) FE_roulis += roulis_vel; FE_dh = FE_modulo_2pi(FE_dh); FE_dv = FE_modulo_2pi(FE_dv); FE_roulis = FE_modulo_2pi(FE_roulis); if (event.key==KEY_8) { py += FE_cos(FE_dh); px += FE_sin(FE_dh); } if (event.key==KEY_5) { py += FE_cos(FE_dh + pi); px += FE_sin(FE_dh + pi); } if (event.key==KEY_4) { py += FE_cos(FE_dh - pi_sur2); px += FE_sin(FE_dh - pi_sur2); } if (event.key==KEY_6) { py += FE_cos(FE_dh + pi_sur2); px += FE_sin(FE_dh + pi_sur2); } } if (event.type==KEYEV_NONE) // si tous les évènements ont été traités break; } FE_user.x = px; // actualisation des coordonnées de position FE_user.y = py; FE_user.z = pz; } void FE_new_frame() { dupdate(); // fin du cycle précédent // gestion du temps avec libprof if (loaded_before) { prof_leave(0); frame_interval = prof_time(0); if (frame_intervalframe_interval_max) frame_interval_max = frame_interval; } else { prof_init(1, 0); loaded_before=true; } prof_clear(0); prof_enter(0); FE_zbuffer_clear(); //actualisation de la position, de la direction et des données liées FE_move(); FE_set_matrice(); dclear(C_WHITE); } #define MICROSECOND = 1000000; unsigned uint32_t FE_get_fps_current() { return MICROSECOND / frame_interval; } unsigned uint32_t FE_get_fps_min() { return MICROSECOND / frame_interval_max; } unsigned uint32_t FE_get_fps_max() { return MICROSECOND / frame_interval_min; } static char fps_history[15]; char* FE_get_fps_history() { sprintf(fps_history, "%d/%d/%d", FE_get_fps_min(), FE_get_fps_current(), FE_get_fps_max()); return fps_history; }