1
0
Fork 0

Nonsignal based interval timing is now working.

This would be a good time to look at cleaning up the code structure a bit.
This commit is contained in:
curt 1997-06-17 03:41:10 +00:00
parent fa97396939
commit c24e18e0fc
2 changed files with 55 additions and 18 deletions

View file

@ -70,10 +70,15 @@ double view_offset = 0.0;
double goal_view_offset = 0.0; double goal_view_offset = 0.0;
/* Another hack */ /* Another hack */
#define DEFAULT_MODEL_HZ 20 #define DEFAULT_TIMER_HZ 20
#define DEFAULT_MULTILOOP 6 #define DEFAULT_MULTILOOP 6
#define DEFAULT_MODEL_HZ (DEFAULT_TIMER_HZ * DEFAULT_MULTILOOP)
double Simtime; double Simtime;
/* Another hack */
int use_signals = 0;
/************************************************************************** /**************************************************************************
* fgInitVisuals() -- Initialize various GL/view parameters * fgInitVisuals() -- Initialize various GL/view parameters
@ -208,13 +213,19 @@ static void fgUpdateVisuals( void ) {
* Update internal time dependent calculations (i.e. flight model) * Update internal time dependent calculations (i.e. flight model)
**************************************************************************/ **************************************************************************/
void fgUpdateTimeDepCalcs() { void fgUpdateTimeDepCalcs(int multi_loop) {
struct flight_params *f; struct flight_params *f;
f = &current_aircraft.flight; f = &current_aircraft.flight;
/* update the flight model */ /* update the flight model */
fgFlightModelUpdate(FG_LARCSIM, f, DEFAULT_MULTILOOP); if ( multi_loop < 0 ) {
printf("updating flight model with default = %d\n", DEFAULT_MULTILOOP);
fgFlightModelUpdate(FG_LARCSIM, f, DEFAULT_MULTILOOP);
} else {
printf("updating flight model with dynamic = %d\n", multi_loop);
fgFlightModelUpdate(FG_LARCSIM, f, multi_loop);
}
if ( fabs(goal_view_offset - view_offset) < 0.09 ) { if ( fabs(goal_view_offset - view_offset) < 0.09 ) {
view_offset = goal_view_offset; view_offset = goal_view_offset;
@ -244,7 +255,7 @@ void fgUpdateTimeDepCalcs() {
void fgInitTimeDepCalcs() { void fgInitTimeDepCalcs() {
/* initialize timer */ /* initialize timer */
fgTimerInit( 1.0 / DEFAULT_MODEL_HZ, fgUpdateTimeDepCalcs ); fgTimerInit( 1.0 / DEFAULT_TIMER_HZ, fgUpdateTimeDepCalcs );
} }
@ -276,11 +287,25 @@ static void fgSceneryDraw() {
/* What should we do when we have nothing else to do? How about get /* What should we do when we have nothing else to do? How about get
* ready for the next move?*/ * ready for the next move?*/
static void fgMainLoop( void ) static void fgMainLoop( void ) {
{ static int remainder = 0;
printf("Time interval is = %d\n", fgGetTimeInterval()); int elapsed, multi_loop;
elapsed = fgGetTimeInterval();
printf("Time interval is = %d, previous remainder is = %d\n", elapsed,
remainder);
multi_loop = ((float)elapsed * 0.001) * DEFAULT_MODEL_HZ;
remainder = elapsed - ((multi_loop*1000) / DEFAULT_MODEL_HZ);
printf("Model iterations needed = %d, new remainder = %d\n", multi_loop,
remainder);
aircraft_debug(1); aircraft_debug(1);
fgUpdateVisuals(); fgUpdateVisuals();
if ( ! use_signals ) {
fgUpdateTimeDepCalcs(multi_loop);
}
} }
@ -393,11 +418,13 @@ int main( int argc, char *argv[] ) {
/* fgSlewInit(-335340,162540, 15, 4.38); */ /* fgSlewInit(-335340,162540, 15, 4.38); */
/* fgSlewInit(-398673.28,120625.64, 53, 4.38); */ /* fgSlewInit(-398673.28,120625.64, 53, 4.38); */
fgFlightModelInit(FG_LARCSIM, f, 1.0/(DEFAULT_MODEL_HZ*DEFAULT_MULTILOOP)); fgFlightModelInit( FG_LARCSIM, f, 1.0 / DEFAULT_MODEL_HZ );
printf("Ready to initialize timer\n"); if ( use_signals ) {
/* init timer routines, signals, etc. */ /* init timer routines, signals, etc. Arrange for an alarm
fgInitTimeDepCalcs(); signal to be generated, etc. */
fgInitTimeDepCalcs();
}
/* build all objects */ /* build all objects */
fgSceneryInit(); fgSceneryInit();
@ -443,9 +470,13 @@ int main( int argc, char *argv[] ) {
/* $Log$ /* $Log$
/* Revision 1.14 1997/06/16 19:32:51 curt /* Revision 1.15 1997/06/17 03:41:10 curt
/* Starting to add general timer support. /* Nonsignal based interval timing is now working.
/* This would be a good time to look at cleaning up the code structure a bit.
/* /*
* Revision 1.14 1997/06/16 19:32:51 curt
* Starting to add general timer support.
*
* Revision 1.13 1997/06/02 03:40:06 curt * Revision 1.13 1997/06/02 03:40:06 curt
* A tiny bit more view tweaking. * A tiny bit more view tweaking.
* *

View file

@ -35,7 +35,7 @@
unsigned long int fgSimTime; unsigned long int fgSimTime;
static struct itimerval t, ot; static struct itimerval t, ot;
static void (*callbackfunc)(); static void (*callbackfunc)(int multi_loop);
/* This routine catches the SIGALRM */ /* This routine catches the SIGALRM */
@ -45,7 +45,9 @@ void fgTimerCatch() {
/* printf("In fgTimerCatch()\n"); */ /* printf("In fgTimerCatch()\n"); */
callbackfunc(); /* -1 tells the routine to use default interval rather than something
dynamically calculated based on frame rate */
callbackfunc(-1);
signal(SIGALRM, fgTimerCatch); signal(SIGALRM, fgTimerCatch);
} }
@ -94,15 +96,19 @@ int fgGetTimeInterval() {
ftime(&current); ftime(&current);
interval = 1000 * (current.time - last.time) + interval = 1000 * (current.time - last.time) +
(current.millitm - last.millitm); (current.millitm - last.millitm);
last = current;
} }
last = current;
return(interval); return(interval);
} }
/* $Log$ /* $Log$
/* Revision 1.1 1997/06/16 19:24:20 curt /* Revision 1.2 1997/06/17 03:41:10 curt
/* Initial revision. /* Nonsignal based interval timing is now working.
/* This would be a good time to look at cleaning up the code structure a bit.
/* /*
* Revision 1.1 1997/06/16 19:24:20 curt
* Initial revision.
*
*/ */