From fa973969393767240654360576a5a786c6de9ce0 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 16 Jun 1997 19:32:50 +0000 Subject: [PATCH] Starting to add general timer support. --- Main/GLmain.c | 69 +++++++++++----------------------------------- Main/Makefile | 11 ++++++-- Main/mesh2GL.c | 9 ++++-- Simulator/Makefile | 5 +++- Simulator/README | 5 ++++ 5 files changed, 39 insertions(+), 60 deletions(-) diff --git a/Main/GLmain.c b/Main/GLmain.c index bb1b6aad9..c3244a8e6 100644 --- a/Main/GLmain.c +++ b/Main/GLmain.c @@ -23,17 +23,10 @@ * (Log is kept at end of this file) **************************************************************************/ - #include #include #include -#include /* for timer routines */ -#if defined(__WATCOMC__) || defined(__MSC__) -# include -#else -# include -#endif #ifdef GLUT #include @@ -47,6 +40,7 @@ #include "../aircraft/aircraft.h" #include "../scenery/scenery.h" #include "../mat3/mat3.h" +#include "../timer/fg_timer.h" #define DEG_TO_RAD 0.017453292 @@ -211,31 +205,14 @@ static void fgUpdateVisuals( void ) { /************************************************************************** - * Timer management routines + * Update internal time dependent calculations (i.e. flight model) **************************************************************************/ -static struct itimerval t, ot; - -/* This routine catches the SIGALRM */ -void fgTimerCatch() { +void fgUpdateTimeDepCalcs() { struct flight_params *f; - static double lastSimtime = -99.9; - int Overrun; - - /* ignore any SIGALRM's until we come back from our EOM iteration */ - signal(SIGALRM, SIG_IGN); f = ¤t_aircraft.flight; - /* printf("In fgTimerCatch()\n"); */ - - Overrun = (lastSimtime == Simtime); - - /* add this back in when you get simtime working */ - /* if ( Overrun ) { - printf("OVERRUN!!!\n"); - } */ - /* update the flight model */ fgFlightModelUpdate(FG_LARCSIM, f, DEFAULT_MULTILOOP); @@ -262,29 +239,12 @@ void fgTimerCatch() { view_offset += PI2; } } - - lastSimtime = Simtime; - signal(SIGALRM, fgTimerCatch); } -/* this routine initializes the interval timer to generate a SIGALRM after - * the specified interval (dt) */ -void fgTimerInit(float dt) { - int terr; - int isec; - float usec; - isec = (int) dt; - usec = 1000000* (dt - (float) isec); - - t.it_interval.tv_sec = isec; - t.it_interval.tv_usec = usec; - t.it_value.tv_sec = isec; - t.it_value.tv_usec = usec; - /* printf("fgTimerInit() called\n"); */ - fgTimerCatch(); /* set up for SIGALRM signal catch */ - terr = setitimer( ITIMER_REAL, &t, &ot ); - if (terr) perror("Error returned from setitimer"); +void fgInitTimeDepCalcs() { + /* initialize timer */ + fgTimerInit( 1.0 / DEFAULT_MODEL_HZ, fgUpdateTimeDepCalcs ); } @@ -318,9 +278,8 @@ static void fgSceneryDraw() { * ready for the next move?*/ static void fgMainLoop( void ) { - fgSlewUpdate(); + printf("Time interval is = %d\n", fgGetTimeInterval()); aircraft_debug(1); - fgUpdateVisuals(); } @@ -436,12 +395,13 @@ int main( int argc, char *argv[] ) { fgFlightModelInit(FG_LARCSIM, f, 1.0/(DEFAULT_MODEL_HZ*DEFAULT_MULTILOOP)); + printf("Ready to initialize timer\n"); + /* init timer routines, signals, etc. */ + fgInitTimeDepCalcs(); + /* build all objects */ fgSceneryInit(); - /* initialize timer */ - fgTimerInit( 1.0 / DEFAULT_MODEL_HZ ); - #ifdef GLUT /* call fgReshape() on window resizes */ glutReshapeFunc( fgReshape ); @@ -483,9 +443,12 @@ int main( int argc, char *argv[] ) { /* $Log$ -/* Revision 1.13 1997/06/02 03:40:06 curt -/* A tiny bit more view tweaking. +/* 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 + * A tiny bit more view tweaking. + * * Revision 1.12 1997/06/02 03:01:38 curt * Working on views (side, front, back, transitions, etc.) * diff --git a/Main/Makefile b/Main/Makefile index e5e54484e..3c343496c 100644 --- a/Main/Makefile +++ b/Main/Makefile @@ -24,7 +24,7 @@ #--------------------------------------------------------------------------- -TARGET=viewer +TARGET=proto CC = gcc @@ -68,7 +68,8 @@ CFILES = GLmain.c $(INTERFACE_FILES) mesh2GL.c OFILES = $(CFILES:.c=.o) AFILES = ../aircraft/libaircraft.a ../controls/libcontrols.a \ ../flight/libflight.a ../flight/LaRCsim/libLaRCsim.a \ - ../flight/slew/libslew.a ../mat3/libmat3.a ../scenery/libscenery.a + ../flight/slew/libslew.a ../mat3/libmat3.a ../scenery/libscenery.a \ + ../timer/libtimer.a #--------------------------------------------------------------------------- @@ -88,7 +89,8 @@ clean: # Secondary Targets #--------------------------------------------------------------------------- -GLmain.o: GLmain.c GLUTkey.h ../aircraft/aircraft.h ../scenery/scenery.h +GLmain.o: GLmain.c GLUTkey.h ../aircraft/aircraft.h ../scenery/scenery.h \ + ../timer/fg_timer.h $(CC) $(CFLAGS) $(INCLUDES) -c GLmain.c GLUTkey.o: GLUTkey.c GLUTkey.h ../aircraft/aircraft.h @@ -103,6 +105,9 @@ mesh2GL.o: mesh2GL.c ../scenery/mesh.h #--------------------------------------------------------------------------- # $Log$ +# Revision 1.12 1997/06/16 19:32:51 curt +# Starting to add general timer support. +# # Revision 1.11 1997/05/31 19:16:25 curt # Elevator trim added. # diff --git a/Main/mesh2GL.c b/Main/mesh2GL.c index cd0b59635..ebbd5ce50 100644 --- a/Main/mesh2GL.c +++ b/Main/mesh2GL.c @@ -44,7 +44,7 @@ GLint mesh2GL(struct mesh *m) { int i, j, istep, jstep, iend, jend; float temp; - istep = jstep = 20; /* Detail level 1 -- 1200 ... */ + istep = jstep = 15; /* Detail level 1 -- 1200 ... */ mesh = glGenLists(1); glNewList(mesh, GL_COMPILE); @@ -104,9 +104,12 @@ GLint mesh2GL(struct mesh *m) { /* $Log$ -/* Revision 1.16 1997/06/02 03:40:07 curt -/* A tiny bit more view tweaking. +/* Revision 1.17 1997/06/16 19:32:52 curt +/* Starting to add general timer support. /* + * Revision 1.16 1997/06/02 03:40:07 curt + * A tiny bit more view tweaking. + * * Revision 1.15 1997/06/02 03:01:38 curt * Working on views (side, front, back, transitions, etc.) * diff --git a/Simulator/Makefile b/Simulator/Makefile index 2f535c671..6380c9732 100644 --- a/Simulator/Makefile +++ b/Simulator/Makefile @@ -28,7 +28,7 @@ CC = gcc SUBSUBDIRS = flight/LaRCsim flight/slew -SUBDIRS = aircraft controls flight mat3 scenery +SUBDIRS = aircraft controls flight mat3 scenery timer MAIN = OpenGL @@ -53,6 +53,9 @@ clean: #--------------------------------------------------------------------------- # $Log$ +# Revision 1.6 1997/06/16 19:32:50 curt +# Starting to add general timer support. +# # Revision 1.5 1997/05/30 19:26:56 curt # The LaRCsim flight model is starting to look like it is working. # diff --git a/Simulator/README b/Simulator/README index af84417d8..597253556 100644 --- a/Simulator/README +++ b/Simulator/README @@ -30,3 +30,8 @@ Contains miscellaneous matrix/vector routines. scenery/ -------- Scenery parsing/generating code. + + +timer/ +------ +Code to handle time and timing of events.