Starting to add general timer support.
This commit is contained in:
parent
90f83b6ce1
commit
fa97396939
5 changed files with 39 additions and 60 deletions
|
@ -23,17 +23,10 @@
|
||||||
* (Log is kept at end of this file)
|
* (Log is kept at end of this file)
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <signal.h> /* for timer routines */
|
|
||||||
|
|
||||||
#if defined(__WATCOMC__) || defined(__MSC__)
|
|
||||||
# include <time.h>
|
|
||||||
#else
|
|
||||||
# include <sys/time.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GLUT
|
#ifdef GLUT
|
||||||
#include <GL/glut.h>
|
#include <GL/glut.h>
|
||||||
|
@ -47,6 +40,7 @@
|
||||||
#include "../aircraft/aircraft.h"
|
#include "../aircraft/aircraft.h"
|
||||||
#include "../scenery/scenery.h"
|
#include "../scenery/scenery.h"
|
||||||
#include "../mat3/mat3.h"
|
#include "../mat3/mat3.h"
|
||||||
|
#include "../timer/fg_timer.h"
|
||||||
|
|
||||||
|
|
||||||
#define DEG_TO_RAD 0.017453292
|
#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;
|
void fgUpdateTimeDepCalcs() {
|
||||||
|
|
||||||
/* This routine catches the SIGALRM */
|
|
||||||
void fgTimerCatch() {
|
|
||||||
struct flight_params *f;
|
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;
|
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 */
|
/* update the flight model */
|
||||||
fgFlightModelUpdate(FG_LARCSIM, f, DEFAULT_MULTILOOP);
|
fgFlightModelUpdate(FG_LARCSIM, f, DEFAULT_MULTILOOP);
|
||||||
|
|
||||||
|
@ -262,29 +239,12 @@ void fgTimerCatch() {
|
||||||
view_offset += PI2;
|
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;
|
void fgInitTimeDepCalcs() {
|
||||||
usec = 1000000* (dt - (float) isec);
|
/* initialize timer */
|
||||||
|
fgTimerInit( 1.0 / DEFAULT_MODEL_HZ, fgUpdateTimeDepCalcs );
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -318,9 +278,8 @@ static void fgSceneryDraw() {
|
||||||
* ready for the next move?*/
|
* ready for the next move?*/
|
||||||
static void fgMainLoop( void )
|
static void fgMainLoop( void )
|
||||||
{
|
{
|
||||||
fgSlewUpdate();
|
printf("Time interval is = %d\n", fgGetTimeInterval());
|
||||||
aircraft_debug(1);
|
aircraft_debug(1);
|
||||||
|
|
||||||
fgUpdateVisuals();
|
fgUpdateVisuals();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,12 +395,13 @@ int main( int argc, char *argv[] ) {
|
||||||
|
|
||||||
fgFlightModelInit(FG_LARCSIM, f, 1.0/(DEFAULT_MODEL_HZ*DEFAULT_MULTILOOP));
|
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 */
|
/* build all objects */
|
||||||
fgSceneryInit();
|
fgSceneryInit();
|
||||||
|
|
||||||
/* initialize timer */
|
|
||||||
fgTimerInit( 1.0 / DEFAULT_MODEL_HZ );
|
|
||||||
|
|
||||||
#ifdef GLUT
|
#ifdef GLUT
|
||||||
/* call fgReshape() on window resizes */
|
/* call fgReshape() on window resizes */
|
||||||
glutReshapeFunc( fgReshape );
|
glutReshapeFunc( fgReshape );
|
||||||
|
@ -483,9 +443,12 @@ int main( int argc, char *argv[] ) {
|
||||||
|
|
||||||
|
|
||||||
/* $Log$
|
/* $Log$
|
||||||
/* Revision 1.13 1997/06/02 03:40:06 curt
|
/* Revision 1.14 1997/06/16 19:32:51 curt
|
||||||
/* A tiny bit more view tweaking.
|
/* 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
|
* Revision 1.12 1997/06/02 03:01:38 curt
|
||||||
* Working on views (side, front, back, transitions, etc.)
|
* Working on views (side, front, back, transitions, etc.)
|
||||||
*
|
*
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
TARGET=viewer
|
TARGET=proto
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
|
|
||||||
|
@ -68,7 +68,8 @@ CFILES = GLmain.c $(INTERFACE_FILES) mesh2GL.c
|
||||||
OFILES = $(CFILES:.c=.o)
|
OFILES = $(CFILES:.c=.o)
|
||||||
AFILES = ../aircraft/libaircraft.a ../controls/libcontrols.a \
|
AFILES = ../aircraft/libaircraft.a ../controls/libcontrols.a \
|
||||||
../flight/libflight.a ../flight/LaRCsim/libLaRCsim.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
|
# 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
|
$(CC) $(CFLAGS) $(INCLUDES) -c GLmain.c
|
||||||
|
|
||||||
GLUTkey.o: GLUTkey.c GLUTkey.h ../aircraft/aircraft.h
|
GLUTkey.o: GLUTkey.c GLUTkey.h ../aircraft/aircraft.h
|
||||||
|
@ -103,6 +105,9 @@ mesh2GL.o: mesh2GL.c ../scenery/mesh.h
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# $Log$
|
# $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
|
# Revision 1.11 1997/05/31 19:16:25 curt
|
||||||
# Elevator trim added.
|
# Elevator trim added.
|
||||||
#
|
#
|
||||||
|
|
|
@ -44,7 +44,7 @@ GLint mesh2GL(struct mesh *m) {
|
||||||
int i, j, istep, jstep, iend, jend;
|
int i, j, istep, jstep, iend, jend;
|
||||||
float temp;
|
float temp;
|
||||||
|
|
||||||
istep = jstep = 20; /* Detail level 1 -- 1200 ... */
|
istep = jstep = 15; /* Detail level 1 -- 1200 ... */
|
||||||
|
|
||||||
mesh = glGenLists(1);
|
mesh = glGenLists(1);
|
||||||
glNewList(mesh, GL_COMPILE);
|
glNewList(mesh, GL_COMPILE);
|
||||||
|
@ -104,9 +104,12 @@ GLint mesh2GL(struct mesh *m) {
|
||||||
|
|
||||||
|
|
||||||
/* $Log$
|
/* $Log$
|
||||||
/* Revision 1.16 1997/06/02 03:40:07 curt
|
/* Revision 1.17 1997/06/16 19:32:52 curt
|
||||||
/* A tiny bit more view tweaking.
|
/* 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
|
* Revision 1.15 1997/06/02 03:01:38 curt
|
||||||
* Working on views (side, front, back, transitions, etc.)
|
* Working on views (side, front, back, transitions, etc.)
|
||||||
*
|
*
|
||||||
|
|
|
@ -28,7 +28,7 @@ CC = gcc
|
||||||
|
|
||||||
|
|
||||||
SUBSUBDIRS = flight/LaRCsim flight/slew
|
SUBSUBDIRS = flight/LaRCsim flight/slew
|
||||||
SUBDIRS = aircraft controls flight mat3 scenery
|
SUBDIRS = aircraft controls flight mat3 scenery timer
|
||||||
MAIN = OpenGL
|
MAIN = OpenGL
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,6 +53,9 @@ clean:
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# $Log$
|
# $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
|
# Revision 1.5 1997/05/30 19:26:56 curt
|
||||||
# The LaRCsim flight model is starting to look like it is working.
|
# The LaRCsim flight model is starting to look like it is working.
|
||||||
#
|
#
|
||||||
|
|
|
@ -30,3 +30,8 @@ Contains miscellaneous matrix/vector routines.
|
||||||
scenery/
|
scenery/
|
||||||
--------
|
--------
|
||||||
Scenery parsing/generating code.
|
Scenery parsing/generating code.
|
||||||
|
|
||||||
|
|
||||||
|
timer/
|
||||||
|
------
|
||||||
|
Code to handle time and timing of events.
|
||||||
|
|
Loading…
Reference in a new issue