120 lines
2.2 KiB
C
120 lines
2.2 KiB
C
#include "FxEngine.h"
|
|
|
|
#include <libprof.h>
|
|
#include "coord.h"
|
|
#include <stdbool.h>
|
|
#include <gint/keyboard.h>
|
|
#include <gint/clock.h>
|
|
#include <gint/display.h>
|
|
|
|
FE_position FE_user={0,0,0};
|
|
double FE_dh,FE_dv,FE_roulis;
|
|
|
|
static double px,py,pz;
|
|
|
|
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() // call at each frame
|
|
{
|
|
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)
|
|
break;
|
|
}
|
|
FE_user.x=px;
|
|
FE_user.y=py;
|
|
FE_user.z=pz;
|
|
|
|
}
|
|
|
|
void FE_new_frame(void)
|
|
{
|
|
if (loaded_before)
|
|
{
|
|
prof_leave(0);
|
|
frame_interval=prof_time(0);
|
|
if (frame_interval<frame_interval_min)
|
|
frame_interval_min=frame_interval;
|
|
if (frame_interval>frame_interval_max)
|
|
frame_interval_max=frame_interval;
|
|
}
|
|
else
|
|
{
|
|
prof_init(1,0);
|
|
loaded_before=true;
|
|
}
|
|
prof_clear(0);
|
|
prof_enter(0);
|
|
|
|
FE_move(); // Not implemented yet !
|
|
FE_set_matrice();
|
|
FE_zbuffer_clear();
|
|
|
|
dupdate();
|
|
dclear(C_WHITE);
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
static const uint32_t unite=1000000;
|
|
unsigned int FE_get_fps_current(void)
|
|
{return unite/frame_interval;}
|
|
|
|
unsigned int FE_get_fps_min(void)
|
|
{return unite/frame_interval_max;}
|
|
|
|
unsigned int FE_get_fps_max(void)
|
|
{return unite/frame_interval_min;} |