home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-12-27 | 55.2 KB | 2,137 lines |
- Newsgroups: comp.sources.misc
- From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Subject: v27i019: sfs - Space Flight Simulator, Part19/21
- Message-ID: <1991Dec24.191956.21203@sparky.imd.sterling.com>
- X-Md4-Signature: b6dbc23978d5721f228d9db7acd15d58
- Date: Tue, 24 Dec 1991 19:19:56 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Posting-number: Volume 27, Issue 19
- Archive-name: sfs/part19
- Environment: IBMPC && EGA/VGA, UNIX-PC && MGR, UNIX && X11
-
- #!/bin/sh
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file sfs/sfs/sfs_pr.c continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 19; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping sfs/sfs/sfs_pr.c'
- else
- echo 'x - continuing file sfs/sfs/sfs_pr.c'
- sed 's/^X//' << 'SHAR_EOF' >> 'sfs/sfs/sfs_pr.c' &&
- X }
- X }
- X
- X fclose( data );
- X
- X /* Initialize all orbits utilizing data entered */
- X
- X for ( orbit = 0; orbit < ORBITS; ++orbit )
- X {
- X if ( sorbit_array[ orbit ] != NULL )
- X {
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "[pr:] sfs_pr(): reinitializing orbit %d",
- X orbit );
- X bw_debug( bw_ebuf );
- #endif
- X
- X or_init( sorbit_array[ orbit ]->aorbit,
- X sorbit_array[ orbit ]->aorbit->periapsis,
- X sorbit_array[ orbit ]->aorbit->apoapsis );
- X }
- X }
- X
- X return TRUE;
- X }
- X
- pr_parse( buffer, fdfile, sorbit_array, n_orbits )
- X char *buffer;
- X char *fdfile;
- X struct sfs_orbit **sorbit_array;
- X int n_orbits;
- X {
- X int n; /* number of arguments */
- X int i;
- X long l;
- X double d;
- X static char x_name[] = "";
- X
- X n = pr_getargs( buffer ); /* get arguments */
- X if ( n == FALSE )
- X {
- X return;
- X }
- X
- X if ( strcmp( arguments[ 0 ], "FOCUS" ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_message( "reading focus" );
- #endif
- X i = atoi( arguments[ 1 ] );
- X strncpy( fdfile, fntolc( arguments[ 2 ] ), (size_t) FDFILESIZE );
- X if ( sorbit_array[ i - 1 ] == NULL )
- X {
- X pr_default( sorbit_array, i - 1, n_orbits, fdfile );
- X }
- X else
- X {
- X sorbit_array[ i - 1 ]->aorbit->focus
- X = pr_getfd( sorbit_array, i - 1, n_orbits, fdfile );
- X }
- X }
- X
- X else if ( strcmp( arguments[ 0 ], "ORB" ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_message( "reading orb" );
- #endif
- X i = atoi( arguments[ 1 ] );
- X if ( sorbit_array[ i - 1 ] == NULL )
- X {
- X pr_default( sorbit_array, i - 1, n_orbits, fdfile );
- X }
- X strncpy( sorbit_array[ i - 1 ]->orbfile,
- X fntolc( arguments[ 2 ] ), (size_t) SFS_FILESIZE - 1 );
- X }
- X
- X else if ( strcmp( arguments[ 0 ], "GRID" ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_message( "reading grid" );
- #endif
- X i = atoi( arguments[ 1 ] );
- X if ( sorbit_array[ i - 1 ] == NULL )
- X {
- X pr_default( sorbit_array, i - 1, n_orbits, fdfile );
- X }
- X strncpy( sorbit_array[ i - 1 ]->gridfile,
- X fntolc( arguments[ 2 ] ), (size_t) SFS_FILESIZE - 1 );
- X }
- X
- X else if ( strcmp( arguments[ 0 ], "SURFACE" ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_message( "reading surface" );
- #endif
- X i = atoi( arguments[ 1 ] );
- X if ( sorbit_array[ i - 1 ] == NULL )
- X {
- X pr_default( sorbit_array, i - 1, n_orbits, fdfile );
- X }
- X strncpy( sorbit_array[ i - 1 ]->surfile,
- X fntolc( arguments[ 2 ] ), (size_t) SFS_FILESIZE - 1 );
- X }
- X
- X else if ( strcmp( arguments[ 0 ], "PERIAPSIS" ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_message( "reading periapsis" );
- #endif
- X i = atoi( arguments[ 1 ] );
- X d = atof( arguments[ 2 ] );
- X if ( sorbit_array[ i - 1 ] == NULL )
- X {
- X pr_default( sorbit_array, i - 1, n_orbits, DEFAULTFD );
- X }
- X if ( d < 0 )
- X {
- X bw_error( PRERR_PRI );
- X }
- X else
- X {
- X sorbit_array[ i - 1 ]->aorbit->periapsis = d;
- X }
- X }
- X
- X else if ( strcmp( arguments[ 0 ], "APOAPSIS" ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_message( "reading apoapsis" );
- #endif
- X i = atoi( arguments[ 1 ] );
- X d = atof( arguments[ 2 ] );
- X
- X if ( sorbit_array[ i - 1 ] == NULL )
- X {
- X pr_default( sorbit_array, i - 1, n_orbits, DEFAULTFD );
- X }
- X if ( ( d < 0 ) || ( d < sorbit_array[ i - 1 ]->aorbit->periapsis ))
- X {
- X bw_error( PRERR_APO );
- X }
- X else
- X {
- X sorbit_array[ i - 1 ]->aorbit->apoapsis = d;
- X }
- X }
- X
- X else if ( strcmp( arguments[ 0 ], "INCLINATION" ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_message( "reading inclination" );
- #endif
- X i = atoi( arguments[ 1 ] );
- X d = atof( arguments[ 2 ] );
- X if ( sorbit_array[ i - 1 ] == NULL )
- X {
- X pr_default( sorbit_array, i - 1, n_orbits, DEFAULTFD );
- X }
- X if ( ( d < OR_INC_MIN ) || ( d > OR_INC_MAX ) )
- X {
- X sprintf( bw_ebuf, PRERR_INC, OR_INC_MIN, OR_INC_MAX );
- X bw_error( bw_ebuf );
- X }
- X else
- X {
- X sorbit_array[ i - 1 ]->aorbit->inclination = d;
- X }
- X }
- X
- X else if ( strcmp( arguments[ 0 ], "LONAN" ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_message( "reading lon asc. node" );
- #endif
- X i = atoi( arguments[ 1 ] );
- X d = atof( arguments[ 2 ] );
- X if ( sorbit_array[ i - 1 ] == NULL )
- X {
- X pr_default( sorbit_array, i - 1, n_orbits, DEFAULTFD );
- X }
- X if ( ( d < OR_LAN_MIN ) || ( d > OR_LAN_MAX ) )
- X {
- X sprintf( bw_ebuf, PRERR_LAN, OR_LAN_MIN, OR_LAN_MAX );
- X bw_error( bw_ebuf );
- X }
- X else
- X {
- X sorbit_array[ i - 1 ]->aorbit->lon_an = d;
- X }
- X }
- X
- X else if ( strcmp( arguments[ 0 ], "ARGPER" ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_message( "reading arg. perigee" );
- #endif
- X i = atoi( arguments[ 1 ] );
- X d = atof( arguments[ 2 ] );
- X if ( sorbit_array[ i - 1 ] == NULL )
- X {
- X pr_default( sorbit_array, i - 1, n_orbits, DEFAULTFD );
- X }
- X if ( ( d < OR_ARP_MIN ) || ( d > OR_ARP_MAX ) )
- X {
- X sprintf( bw_ebuf, PRERR_ARP, OR_ARP_MIN, OR_ARP_MAX );
- X bw_error( bw_ebuf );
- X }
- X else
- X {
- X sorbit_array[ i - 1 ]->aorbit->arg_per = d;
- X }
- X }
- X
- X else if ( strcmp( arguments[ 0 ], "NAME" ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_message( "reading name" );
- #endif
- X i = atoi( arguments[ 1 ] );
- X if ( sorbit_array[ i - 1 ] == NULL )
- X {
- X pr_default( sorbit_array, i - 1, n_orbits, DEFAULTFD );
- X }
- X if ( ( sorbit_array[ i - 1 ]->name
- X = malloc( (size_t) strlen( arguments[ 2 ] ) + 2 )) == NULL )
- X {
- X bw_error( PRMEMERR_NAME );
- X sfs_exit();
- X exit(1);
- X }
- X
- X pr_stripcr( arguments[ 2 ] );
- X strcpy( sorbit_array[ i - 1 ]->name, arguments[ 2 ] );
- X }
- X
- X else if ( strcmp( arguments[ 0 ], "TFACTOR" ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_message( "reading tfactor" );
- #endif
- X l = atol( arguments[ 1 ] );
- X if ( l < 1 )
- X {
- X bw_error( PRERR_TF );
- X }
- X else
- X {
- X sfs_tfactor = l;
- X }
- X }
- X
- X else if ( strcmp( arguments[ 0 ], "UPDATE" ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_message( "reading update time" );
- #endif
- X l = atol( arguments[ 1 ] );
- X if ( l < 1 )
- X {
- X bw_error( PRERR_UI );
- X }
- X else
- X {
- X sfs_inc = l;
- X }
- X }
- X
- X else if ( strcmp( arguments[ 0 ], "TRIG" ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_message( "reading trig level" );
- #endif
- X l = atol( arguments[ 1 ] );
- X if ( ( l < 1 ) || ( l > 2 ) )
- X {
- X bw_error( PRERR_TL );
- X }
- X else
- X {
- X vpt_level = l;
- X }
- X }
- X
- X else if ( strcmp( arguments[ 0 ], "INSERTION" ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_message( "reading insertion" );
- #endif
- X l = atol( arguments[ 1 ] );
- X if ( l < 0 )
- X {
- X sprintf( bw_ebuf, PRERR_INS );
- X bw_error( bw_ebuf );
- X }
- X else
- X {
- X sfs_insertion = l;
- X }
- X }
- X
- #ifdef USEGO
- X else if ( strcmp( arguments[ 0 ], "GO" ) == 0 )
- X {
- X sfs_go = 1;
- X }
- #endif
- X
- X else
- X {
- X sprintf( bw_ebuf, PRERR_UNKNOWN, arguments[ 0 ] );
- X bw_error( bw_ebuf );
- X }
- X }
- X
- pr_getargs( buffer )
- X char *buffer;
- X {
- X int y; /* yes continue to loop */
- X int n; /* number of agument */
- X int p; /* position in argument string */
- X register char *c; /* character position in buffer */
- X
- X c = buffer;
- X y = TRUE;
- X n = 0;
- X
- X /* check for null line */
- X
- X if ( ( ( *c & 255 ) == 0xa ) || ( ( *c & 255 ) == 0xc ) )
- X {
- X return 0;
- X }
- X
- X /* loop to get each argument */
- X
- X while( y == TRUE )
- X {
- X p = 0;
- X arguments[ n ][ p ] = 0;
- X while( ( isspace( *c ) == 0 ) && ( *c != 0 ))
- X {
- X if ( n == 0 )
- X {
- X arguments[ n ][ p ] = toupper( *c );
- X }
- X else
- X {
- X arguments[ n ][ p ] = *c;
- X }
- X arguments[ n ][ p + 1 ] = 0;
- X ++c;
- X ++p;
- X }
- X
- X /* Eat up any remaining whitespace before next argument */
- X
- X while( isspace( *c ) != 0 )
- X {
- X ++c;
- X }
- X
- X /* if *c == 0, then end of line has been reached */
- X
- X if ( *c == 0 )
- X {
- X y = FALSE;
- X }
- X else
- X {
- X ++n;
- X }
- X if ( ( n + 1 ) == MAXARGS )
- X {
- X y = FALSE;
- X }
- X
- X }
- X return n + 1;
- X }
- X
- pr_default( sorbit_array, orbit, n_orbits, fdfile )
- X struct sfs_orbit **sorbit_array;
- X int orbit, n_orbits;
- X char *fdfile;
- X {
- X static char x_name[] = "";
- X
- X /* Allocate memory for orbit structure */
- X
- X if ( ( sorbit_array[ orbit ] = (struct sfs_orbit *) malloc( sizeof( struct sfs_orbit ) )) == NULL )
- X {
- X bw_error( PRMEMERR_SORBIT );
- X sfs_exit();
- X exit(1);
- X }
- X
- X if ( ( sorbit_array[ orbit ]->aorbit = (struct as_orbit *)
- X malloc( sizeof( struct as_orbit ) )) == NULL )
- X {
- X bw_error( PRMEMERR_AORBIT );
- X sfs_exit();
- X exit(1);
- X }
- X
- X sorbit_array[ orbit ]->aorbit->focus
- X = pr_getfd( sorbit_array, orbit, n_orbits, fdfile );
- X
- X /* Now fill in defaults */
- X
- X sorbit_array[ orbit ]->name = x_name;
- X sorbit_array[ orbit ]->aorbit->lon_an = 0.0;
- X sorbit_array[ orbit ]->aorbit->arg_per = 0.0;
- X sorbit_array[ orbit ]->aorbit->inclination = 0.0;
- X sorbit_array[ orbit ]->aorbit->periapsis = sorbit_array[ orbit ]->aorbit->focus->radius * 0.1;
- X sorbit_array[ orbit ]->aorbit->apoapsis = sorbit_array[ orbit ]->aorbit->focus->radius * 4;
- X
- X strncpy ( sorbit_array[ orbit ]->orbfile, DEFAULTORB, SFS_FILESIZE - 1 );
- X strncpy ( sorbit_array[ orbit ]->gridfile, DEFAULTGRID, SFS_FILESIZE - 1 );
- X strncpy ( sorbit_array[ orbit ]->surfile, DEFAULTSD, SFS_FILESIZE - 1 );
- #ifdef USEPOINTS
- X strncpy ( sorbit_array[ orbit ]->pdfile, DEFAULTPT, SFS_FILESIZE - 1 );
- #endif
- X
- X or_init( sorbit_array[ orbit ]->aorbit,
- X sorbit_array[ orbit ]->aorbit->periapsis,
- X sorbit_array[ orbit ]->aorbit->apoapsis );
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "[pr:] pr_default(): orbit %d, focus %s, mass %le",
- X orbit, sorbit_array[ orbit ]->aorbit->focus->name,
- X sorbit_array[ orbit ]->aorbit->focus->mass );
- X bw_debug( bw_ebuf );
- #endif
- X
- X }
- X
- pr_save( filename, sorbit_array, n_orbits, pr_name )
- X char *filename;
- X struct sfs_orbit **sorbit_array;
- X int n_orbits;
- X char *pr_name;
- X {
- X FILE *data;
- X register int orbit;
- X static time_t ticks;
- X static struct tm *tp;
- X
- X /* get the date and time */
- X
- X ticks = time( NULL );
- X tp = localtime( &ticks );
- X
- X /* Open the program file */
- X
- X if ( ( data = fopen( filename, "w" )) == NULL )
- X {
- X sprintf( bw_ebuf, PRERR_WRITE,
- X filename );
- X bw_error( bw_ebuf );
- X return BW_ERROR;
- X }
- X
- X pr_stripcr( pr_name );
- X fprintf( data, FILE_DELIMITER );
- X fprintf( data, ";\t%s \n", filename );
- X fprintf( data, ";\t%s %s", PR_CREATED, asctime( tp ) );
- X fprintf( data, FILE_DELIMITER );
- X fprintf( data, "%s \n", pr_name );
- X fprintf( data, "tfactor\t\t%ld\n", sfs_tfactor );
- X fprintf( data, "update\t\t%ld\n", sfs_inc );
- X fprintf( data, "trig\t\t%d\n", vpt_level );
- X fprintf( data, "insertion\t%ld\n", sfs_insertion );
- X
- X for ( orbit = 0; orbit < n_orbits; ++orbit )
- X {
- X if ( sorbit_array[ orbit ] != NULL )
- X {
- X fprintf( data, FILE_DELIMITER );
- X fprintf( data, ";\t%s %d\n", PR_PARAMS, orbit + 1 );
- X fprintf( data, FILE_DELIMITER );
- X fprintf( data, "name\t\t%d\t%s\n", orbit + 1,
- X sorbit_array[ orbit ]->name );
- X fprintf( data, "focus\t\t%d\t%s\n", orbit + 1,
- X sorbit_array[ orbit ]->aorbit->focus->fdfile );
- X fprintf( data, "periapsis\t%d\t%lf\n", orbit + 1,
- X sorbit_array[ orbit ]->aorbit->periapsis );
- X fprintf( data, "apoapsis\t%d\t%lf\n", orbit + 1,
- X sorbit_array[ orbit ]->aorbit->apoapsis );
- X fprintf( data, "inclination\t%d\t%lf\n", orbit + 1,
- X sorbit_array[ orbit ]->aorbit->inclination );
- X fprintf( data, "argper\t\t%d\t%lf\n", orbit + 1,
- X sorbit_array[ orbit ]->aorbit->arg_per );
- X fprintf( data, "lonan\t\t%d\t%lf\n", orbit + 1,
- X sorbit_array[ orbit ]->aorbit->lon_an );
- X fprintf( data, "orb\t\t%d\t%s\n", orbit + 1,
- X sorbit_array[ orbit ]->orbfile );
- X fprintf( data, "grid\t\t%d\t%s\n", orbit + 1,
- X sorbit_array[ orbit ]->gridfile );
- X fprintf( data, "surface\t\t%d\t%s\n", orbit + 1,
- X sorbit_array[ orbit ]->surfile );
- X }
- X }
- X
- X fprintf( data, FILE_DELIMITER );
- X fprintf( data, ";\t%s %s \n", PR_ENDOF, filename );
- X fprintf( data, FILE_DELIMITER );
- X fclose( data );
- X }
- X
- pr_stripcr( s )
- X char *s;
- X {
- X char *p;
- X
- X p = s;
- X while ( *p != 0 )
- X {
- X switch( *p )
- X {
- X case 0x0d:
- X case 0x0a:
- X *p = 0;
- X break;
- X }
- X ++p;
- X }
- X *p = 0;
- X }
- X
- struct as_focus *
- pr_getfd( sorbit_array, orbit_n, n_orbits, fdfile )
- X struct sfs_orbit **sorbit_array;
- X int orbit_n, n_orbits;
- X char *fdfile;
- X {
- X register int orbit;
- X struct as_focus *newfocus;
- X
- X /* first cycle through orbits to see if this focus has already
- X been initialized */
- X
- X for ( orbit = 0; orbit < n_orbits; ++orbit )
- X {
- X if ( ( orbit != orbit_n ) && ( sorbit_array[ orbit ] != NULL ))
- X {
- X if ( strcmp( sorbit_array[ orbit ]->aorbit->focus->fdfile,
- X fdfile ) == 0 )
- X {
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "Reinit %s for orbit %d from orbit %d",
- X fdfile, orbit_n, orbit );
- X bw_debug( bw_ebuf );
- #endif
- X return sorbit_array[ orbit ]->aorbit->focus;
- X }
- X }
- X }
- X
- X /* the focus has not been initialized; initialize it now */
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "Init %s for orbit %d", fdfile, orbit_n );
- X bw_debug( bw_ebuf );
- #endif
- X if ( ( newfocus = (struct as_focus *)
- X malloc( sizeof( struct as_focus ) )) == NULL )
- X {
- X bw_error( PRMEMERR_FOCUS );
- X sfs_exit();
- X exit(1);
- X }
- X
- X /* read in focal data */
- X
- X as_readfd( fdfile, newfocus );
- X return newfocus;
- X
- X }
- X
- char *
- fntolc( s )
- X char *s;
- X {
- X char *p;
- X
- X p = s;
- X while( *p != 0 )
- X {
- X *p = tolower( *p );
- X ++p;
- X }
- X return s;
- X }
- SHAR_EOF
- echo 'File sfs/sfs/sfs_pr.c is complete' &&
- chmod 0644 sfs/sfs/sfs_pr.c ||
- echo 'restore of sfs/sfs/sfs_pr.c failed'
- Wc_c="`wc -c < 'sfs/sfs/sfs_pr.c'`"
- test 17557 -eq "$Wc_c" ||
- echo 'sfs/sfs/sfs_pr.c: original size 17557, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/sfs/sfs_vi.c ==============
- if test -f 'sfs/sfs/sfs_vi.c' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/sfs/sfs_vi.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/sfs/sfs_vi.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfs_vi.c' &&
- /***************************************************************
- X
- X sfs_vi.c Visual Simulation Routines for SFS
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ***************************************************************/
- X
- #include "stdio.h"
- #include "ctype.h"
- #include "math.h"
- #include "bw.h"
- #include "gr.h"
- #include "kb.h"
- #include "ui.h"
- #include "as.h"
- #include "sfs.h"
- X
- /* #define NOT_HIDDEN */
- X
- /***************************************************************
- X
- X vi_draw() Draw visual simulation screen
- X
- ***************************************************************/
- X
- vi_draw( uiwind, focus, elements, g_start, g_end, s_start, s_end,
- X o_start, o_end, radius, distance, sorbit_array, orbit_n )
- X struct uiwindow *uiwind; /* ui window to draw in */
- X struct as_focus *focus; /* orbital focus to display */
- X unsigned int elements; /* elements to draw */
- X struct spj_pt *g_start; /* start array of points for grid */
- X struct spj_pt *g_end; /* end array of points for grid */
- X struct spj_pt *s_start; /* start array of points for surface */
- X struct spj_pt *s_end; /* end array of points for surface */
- X struct spj_pt *o_start; /* start array for orb data */
- X struct spj_pt *o_end; /* end array for orb data */
- X double radius; /* radius for size/horizon calculation */
- X double distance; /* distance for size/horizon calculation */
- X struct sfs_orbit **sorbit_array;
- X int orbit_n;
- X {
- X int l, c; /* line, column for title display */
- X int x, y; /* coordinates to locate orb */
- X static int clip_status = FALSE; /* is clipping allowed? */
- X int x_screen;
- X
- #ifdef DEBUG
- X if ( distance == 0.0 )
- X {
- X sprintf( bw_ebuf, "[pr: vi_draw() received distance = %.2lf",
- X distance );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( radius == 0.0 )
- X {
- X sprintf( bw_ebuf, "[pr: vi_draw() received radius = %.2lf",
- X radius );
- X bw_error( bw_ebuf );
- X return;
- X }
- #endif
- X
- X /*** inform the viewer */
- X
- X bw_message( VI_DRAW );
- X
- X /*** initial screen setup */
- X
- #ifdef NOT_HIDDEN
- X x_screen = GR_PRIMARY;
- #else
- X if ( gr_screens > 1 )
- X {
- X x_screen = GR_HIDDEN;
- X }
- X else
- X {
- X x_screen = GR_PRIMARY;
- X }
- X ui_setscreen( x_screen );
- #endif
- X
- #ifdef OLD_DEBUG
- X bw_message( "DEBUG: Blank window..." );
- #endif
- X
- X /*** Blank the user area of the window */
- X
- X ui_fbox( uiwind->u_x1, uiwind->u_y1,
- X uiwind->u_x2, uiwind->u_y2, BLACK, SOLID );
- X
- #ifdef OLD_DEBUG
- X bw_message( "DEBUG: Set font..." );
- #endif
- X
- X /*** Set appropriate font */
- X
- X gr_font( x_screen, F_DEFAULT, ui_grwind->ymax / 40 );
- X
- X /*** Element 1: Blank the orb */
- X
- X /*** Element 2: Draw the orb */
- X
- X if ( ( elements & VI_ORBOUTLINE ) > 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_debug( "ready to draw orb..." );
- #endif
- X vi_showseq( o_start, o_end, uiwind, HORDEGS, radius, distance,
- X cl_grid, SOLID, AL_HORIZON, SPJ_ALLSIDES, x_screen );
- X }
- X
- X /*** Element 3: Draw front of the grid */
- X
- X if ( ( elements & VI_GRIDFRONT ) > 0 )
- X {
- X vi_showseq( g_start, g_end, uiwind, HORDEGS, radius, distance,
- X cl_grid, GRID, AL_HORIZON, SPJ_NEARSIDE, x_screen );
- X }
- X
- X /*** Element 4: Draw reverse of the grid */
- X
- X if ( ( elements & VI_GRIDBACK ) > 0 )
- X {
- X vi_showseq( g_start, g_end, uiwind, HORDEGS, radius, distance,
- X cl_grid, GRID, AL_HORIZON, SPJ_FARSIDE, x_screen );
- X }
- X
- X /*** Element 5: Draw reverse of the surface features */
- X
- X if ( ( elements & VI_SURBACK ) > 0 )
- X {
- X vi_showseq( s_start, s_end, uiwind, HORDEGS, radius, distance,
- X cl_surface, GRID, AL_HORIZON, SPJ_FARSIDE, x_screen );
- X }
- X
- X /*** Element 6: Draw front of the surface features */
- X
- X if ( ( elements & VI_SURFRONT ) > 0 )
- X {
- X vi_showseq( s_start, s_end, uiwind, HORDEGS, radius, distance,
- X cl_surface, SOLID, AL_HORIZON, SPJ_NEARSIDE, x_screen );
- X }
- X
- X /*** Element 7: Show the points */
- X
- #ifdef USEPOINTS
- X if ( ( elements & VI_POINTS ) > 0 )
- X {
- X vi_showseq( p_start, p_end, uiwind, HORDEGS, radius, distance,
- X cl_marker, GRID, AL_HORIZON, SPJ_NEARSIDE, x_screen );
- X }
- #endif
- X
- X /*** Element 8: Show titles for point data */
- X
- #ifdef USEPOINTS
- X if ( ( elements & VI_PTITLES ) > 0 )
- X {
- X vi_titles( p_start, p_end, uiwind, HORDEGS, radius, distance,
- X cl_mback, cl_mfore, AL_HORIZON, SPJ_NEARSIDE, x_screen );
- X }
- #endif
- X
- X /*** Element 9: Show crosshairs */
- X
- X if ( ( elements & VI_CROSSH ) > 0 )
- X {
- X pe_crosshair( uiwind, HORDEGS, x_screen );
- X }
- X
- X /*** Element 10: Show screen title */
- X
- X if ( ( elements & VI_STITLE ) > 0 )
- X {
- X sprintf( bw_ebuf, "%s: %s %ld %s %.2lf %s %.2lf %s %.0lf km",
- X VI_POS, VI_ORBIT, sorbit_array[ orbit_n ]->ssp_n,
- X VI_LAT, sorbit_array[ orbit_n ]->ssp_lat,
- X VI_LON, sorbit_array[ orbit_n ]->ssp_lon,
- X VI_ALT, sorbit_array[ orbit_n ]->ssp_r - focus->radius );
- X gr_rectangle( x_screen, uiwind->u_x1 + 1, uiwind->u_y1 + 1,
- X uiwind->u_x2 - 1, uiwind->u_y1 + 1 + ui_grwind->fysize + 1,
- X cl_marker, SOLID );
- X gr_text( x_screen, uiwind->u_x1 + 1, uiwind->u_y1 + 1,
- X bw_ebuf, cl_mfore, cl_marker );
- X }
- X
- X /*** Restore font */
- X
- X sfsx_font( 0 );
- X
- X /* Show toggle status */
- X
- X el_show( x_screen, uiwind, elements );
- X
- X /*** blit and return screen to original state */
- X
- #ifndef NOT_HIDDEN
- X if ( gr_screens > 1 )
- X {
- X gr_blit( GR_HIDDEN, GR_PRIMARY, uiwind->u_x1, uiwind->u_y1,
- X uiwind->u_x2, uiwind->u_y2 );
- X }
- X ui_setscreen( GR_PRIMARY );
- #endif
- X
- X /* Title the screen */
- X
- X sprintf( bw_ebuf, VI_WTITLE,
- X focus->name,
- X sorbit_array[ orbit_n ]->name );
- X ui_wtitle( uiwind, bw_ebuf );
- X
- X }
- X
- /***************************************************************
- X
- X vi_titles() Show point titles on visual display
- X
- ***************************************************************/
- X
- #ifdef USEPOINTS
- X
- vi_titles( start, end, uiwind, hor_deg, radius, distance,
- X background, foreground, alignment, spjmode, screen )
- X struct spj_pt *start, *end;
- X struct uiwindow *uiwind;
- X double hor_deg, radius, distance;
- X int background, foreground;
- X int alignment, spjmode, screen;
- X {
- X struct spj_pt *current;
- X static struct uiwindow *oldwind; /* save window pointer to avoid recalculation */
- X static int x_midx, x_midy; /* x, y mid points of window */
- X static double x_xfactor, x_yfactor; /* factors for x, y expansion in window */
- X static double old_hdeg; /* save horizontal degrees to avoid recalculation */
- X static double vert_degrees; /* calculate vertical degrees */
- X static int old_align; /* save alignment to avoid recalculation */
- X int v; /* is the point visible? */
- X
- X if ( ( uiwind != oldwind ) || ( alignment != old_align )
- X || ( hor_deg != old_hdeg ))
- X {
- X x_xfactor = ( uiwind->u_x2 - uiwind->u_x1 ) / hor_deg;
- X vert_degrees = hor_deg * ( ( ( uiwind->u_y2 - (double) uiwind->u_y1 )
- X * ( gr_pysize / (double) gr_pxsize ) )
- X / ( uiwind->u_x2 - (double) uiwind->u_x1 ) );
- X x_yfactor = ( uiwind->u_y2 - uiwind->u_y1 ) / vert_degrees;
- X old_hdeg = hor_deg;
- X x_midx = uiwind->u_x1 + (( uiwind->u_x2 - uiwind->u_x1 ) / 2 );
- X if ( alignment == AL_HORIZON )
- X {
- X x_midy = ( ( ( uiwind->u_y2 - uiwind->u_y1 ) / 3 ) * 2 )
- X - ( x_yfactor * spj_angrad( distance, radius ));
- X }
- X else
- X {
- X x_midy = uiwind->u_y1 + (( uiwind->u_y2 - uiwind->u_y1 ) / 2 );
- X }
- X old_align = alignment;
- X oldwind = uiwind;
- X }
- X
- X current = start;
- X while( current != end )
- X {
- X
- X /* Check to see if the coordinates are within the bounds
- X of the whole screen */
- X
- X v = TRUE;
- X if ( current->name == NULL )
- X {
- X v = FALSE;
- X }
- X else if ( ( current->x < 0 ) || ( current->x > ui_grwind->xmax ) )
- X {
- X v = FALSE;
- X }
- X else if ( ( current->y < 0 ) || ( current->y > ui_grwind->ymax ) )
- X {
- X v = FALSE;
- X }
- X else if ( current->side != spjmode )
- X {
- X v = FALSE;
- X }
- X
- X if ( v == TRUE )
- X {
- X gr_text( screen,
- X (int) ( current->x * x_xfactor ) + 3 + x_midx,
- X (int) ( current->y * x_yfactor ) - ( ui_grwind->fysize / 2 )
- X + x_midy,
- X current->name, foreground, background );
- X }
- X
- X current = current->next;
- X }
- X }
- X
- #endif
- X
- /***************************************************************
- X
- X vi_showseq() Show a linked sequence of spherical
- X projection data points in a ui window
- X
- ***************************************************************/
- X
- vi_showseq( start, end, uiwind, hor_deg, radius, distance,
- X color, linestyle, alignment, spjmode, screen )
- X struct spj_pt *start, *end; /* start, end structures for
- X spherical projection data */
- X struct uiwindow *uiwind; /* ui window for display */
- X double hor_deg; /* degrees of horizontal axis */
- X double radius; /* radius for horizon position calculation */
- X double distance; /* distance for horizon position calculation */
- X int color; /* gr color for lines, points */
- X int linestyle; /* gr line style for lines */
- X int alignment; /* horizon or centered alignment */
- X int spjmode; /* spj mode (sides) for display */
- X int screen; /* screen for display */
- X {
- X struct spj_pt *current; /* current point structure */
- X static struct uiwindow *oldwind; /* save window pointer to avoid recalculation */
- X static int x_midx, x_midy; /* x, y mid points of window */
- X int x, y, side; /* current x, y, side values */
- X int prevcode, prevx, prevy, prevside; /* save previous values */
- X static double x_xfactor, x_yfactor; /* factors for x, y expansion in window */
- X static double old_hdeg; /* save horizontal degrees to avoid recalculation */
- X static double vert_degrees; /* calculate vertical degrees */
- X static double old_distance; /* save distance to avoid recalc */
- X static int old_align; /* save alignment to avoid recalculation */
- #ifdef DEBUG
- X int Dc;
- #endif
- X
- #ifdef DEBUG
- X if ( distance == 0.0 )
- X {
- X sprintf( bw_ebuf, "[pr: vi_showseq() received distance = %.2lf",
- X distance );
- X bw_error( bw_ebuf );
- X return;
- X }
- X if ( radius == 0.0 )
- X {
- X sprintf( bw_ebuf, "[pr: vi_showseq() received radius = %.2lf",
- X radius );
- X bw_error( bw_ebuf );
- X return;
- X }
- #endif
- X
- X if ( ( uiwind != oldwind ) || ( alignment != old_align )
- X || ( distance != old_distance ) || ( hor_deg != old_hdeg ))
- X {
- X
- #ifdef DEBUG
- X bw_message( "DEBUG: recalculating for showseq()..." );
- #endif
- X
- X x_xfactor = ( uiwind->u_x2 - (double) uiwind->u_x1 ) / hor_deg;
- X vert_degrees = hor_deg * (double)
- X ( ( ( uiwind->u_y2 - (double) uiwind->u_y1 )
- X * ( gr_pysize / (double) gr_pxsize ) )
- X / ( uiwind->u_x2 - (double) uiwind->u_x1 ) );
- X x_yfactor = ( uiwind->u_y2 - (double) uiwind->u_y1 ) / vert_degrees;
- X old_hdeg = hor_deg;
- X x_midx = uiwind->u_x1 + (( uiwind->u_x2 - (double) uiwind->u_x1 ) / 2.0 );
- X if ( alignment == AL_HORIZON )
- X {
- X x_midy = uiwind->y1 +
- X ( ( (double) uiwind->u_y2 - (double) uiwind->u_y1 ) * 0.7 )
- X - ( x_yfactor * spj_angrad( distance, radius ));
- X }
- X else
- X {
- X x_midy = uiwind->u_y1 + (( uiwind->u_y2 - (double) uiwind->u_y1 ) / 2 );
- X }
- X old_align = alignment;
- X oldwind = uiwind;
- X old_distance = distance;
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "vert_degrees = %.2lf xfactor = %.2lf, yfactor = %.2lf",
- X vert_degrees, x_xfactor, x_yfactor );
- X bw_debug( bw_ebuf );
- #endif
- X
- X }
- X
- #ifdef OLD_DEBUG
- X Dc = 0;
- X sprintf( bw_ebuf, "ready to draw points, mode %d", spjmode );
- X bw_debug( bw_ebuf );
- #endif
- X
- X current = start->next;
- X prevside = 255;
- X
- X while( current != end )
- X {
- X x = current->x * x_xfactor;
- X y = current->y * x_yfactor;
- X side = current->side;
- #ifdef DEBUG
- X ++Dc;
- #endif
- X
- X switch ( spjmode )
- X {
- X case SPJ_ALLSIDES:
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "DEBUG: allsides point %d: x %d y %d", Dc, x, y );
- X bw_message( bw_ebuf );
- #endif
- X if ( current->code < 1000 )
- X {
- X sfs_line( screen,
- X x_midx + x,
- X x_midy + y,
- X x_midx + prevx,
- X x_midy + prevy, color, linestyle );
- X }
- X else
- X {
- X sfs_pixel( screen, x_midx + x,
- X x_midy + y, color );
- X }
- X break;
- X case SPJ_FARSIDE:
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "DEBUG: farside point %d: x %d y %d", Dc, x, y );
- X bw_message( bw_ebuf );
- #endif
- X if ( ( prevside == SPJ_FARSIDE ) && ( side == SPJ_FARSIDE ))
- X {
- X if ( current->code < 1000 )
- X {
- X sfs_line( screen,
- X x_midx + x,
- X x_midy + y,
- X x_midx + prevx,
- X x_midy + prevy, color, linestyle );
- X }
- X else
- X {
- X sfs_pixel( screen, x_midx + x,
- X x_midy + y, color );
- X }
- X }
- X break;
- X default:
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "DEBUG: nearside point %d: x %d y %d", Dc, x, y );
- X bw_message( bw_ebuf );
- #endif
- X if ( ( prevside == SPJ_NEARSIDE ) && ( side == SPJ_NEARSIDE ))
- X {
- X if ( current->code < 1000 )
- X {
- X sfs_line( screen,
- X x_midx + x,
- X x_midy + y,
- X x_midx + prevx,
- X x_midy + prevy, color, linestyle );
- X }
- X else
- X {
- X sfs_pixel( screen, x_midx + x,
- X x_midy + y, color );
- X }
- X }
- X break;
- X }
- X
- X prevx = x;
- X prevy = y;
- X prevside = side;
- X prevcode = current->code;
- X current = current->next;
- X }
- X }
- X
- /***************************************************************
- X
- X vi_rotate() Calculate rotation based on 2 positions
- X
- ***************************************************************/
- X
- double
- vi_rotate( current_x, current_y, next_x, next_y )
- X double current_x; /* current x coordinate */
- X double current_y; /* current y coordinate */
- X double next_x; /* next x coordinate */
- X double next_y; /* next y coordinate */
- X {
- X double x, y, r;
- X
- X x = next_x - current_x;
- X y = next_y - current_y;
- X
- X if ( x == 0.0 )
- X {
- X if ( y == 0.0 )
- X {
- X return 270.0;
- X }
- X else if ( y > 0.0 )
- X {
- X return 0.0;
- X }
- X else if ( y < 0.0 )
- X {
- X return 180.0;
- X }
- X }
- X
- X if ( y == 0.0 )
- X {
- X if ( x > 0.0 )
- X {
- X return 270.0;
- X }
- X else if ( x < 0.0 )
- X {
- X return 90.0;
- X }
- X }
- X
- X r = atan2( y, x ) * RAD_DEG;
- X
- #ifdef OLD_DEBUG
- X sprintf( bw_ebuf, "exit vi_rotate(), current_x %.2lf next_x %.2lf x %.2lf y %.2lf r %.2lf",
- X current_x, next_x, x, y, r );
- X bw_debug( bw_ebuf );
- #endif
- X
- X return spj_degfix( 270.0 + r );
- X }
- X
- sfs_line( screen, x1, y1, x2, y2, color, style )
- X int screen, x1, y1, x2, y2, color, style;
- X {
- X
- X if ( ( x1 < 0 ) || ( x1 > ui_grwind->xmax ))
- X {
- X return FALSE;
- X }
- X if ( ( x2 < 0 ) || ( x2 > ui_grwind->xmax ))
- X {
- X return FALSE;
- X }
- X if ( ( y1 < 0 ) || ( y1 > ui_grwind->ymax ))
- X {
- X return FALSE;
- X }
- X if ( ( y2 < 0 ) || ( y2 > ui_grwind->ymax ))
- X {
- X return FALSE;
- X }
- X
- X gr_line( screen, x1, y1, x2, y2, color, style );
- X
- X }
- X
- sfs_pixel( screen, x, y, color )
- X int screen, x, y, color;
- X {
- X
- X if ( ( x < 0 ) || ( x > ui_grwind->xmax ))
- X {
- X return FALSE;
- X }
- X if ( ( y < 0 ) || ( y > ui_grwind->ymax ))
- X {
- X return FALSE;
- X }
- X
- X gr_pixel( screen, x, y, color );
- X
- X }
- X
- SHAR_EOF
- chmod 0644 sfs/sfs/sfs_vi.c ||
- echo 'restore of sfs/sfs/sfs_vi.c failed'
- Wc_c="`wc -c < 'sfs/sfs/sfs_vi.c'`"
- test 16784 -eq "$Wc_c" ||
- echo 'sfs/sfs/sfs_vi.c: original size 16784, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/sfs/sfsm.c ==============
- if test -f 'sfs/sfs/sfsm.c' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/sfs/sfsm.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/sfs/sfsm.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfsm.c' &&
- /***************************************************************
- X
- X sfsm.c Space Flight Simulator
- X Main Menu and Orbital Modeling Module
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ***************************************************************/
- X
- #include "stdio.h"
- #include "time.h"
- #include "signal.h"
- #include "ctype.h"
- #include "math.h"
- X
- #ifdef __STDC__
- #include "malloc.h"
- #else
- extern char * malloc();
- #endif
- X
- #include "sfsm.h"
- X
- #ifndef __STDC__
- #define time_t long
- #define size_t int
- #endif
- X
- extern int sfs_sigint();
- X
- #define MM_TITLES 4
- /* #define SMALL_DEBUG */
- #define MAXYSIZE 375
- X
- struct dir_ent *d_entries[ MAX_ENTRIES ];
- char *d_titles[ MAX_ENTRIES ];
- X
- char *mm_titles[ MM_TITLES ] = {
- X MM_SETPROGFILE,
- X MM_OM,
- X MM_OS,
- X MM_EXIT };
- X
- /*** Colors */
- X
- int cl_mback; /* Main background color */
- int cl_mfore; /* Main foreground color */
- int cl_marker; /* Color for prompt markers */
- int cl_grid; /* Color for planetary grid */
- int cl_surface; /* Color for planetary surface */
- int cl_orbits[ OR_COLORS ]; /* Colors for different orbits */
- X
- char sfs_program[ 36 ];
- char sfs_tbuf[ 512 ];
- int sfs_curorbit = 0;
- long sfs_insertion;
- long sfs_inc;
- long sfs_tfactor; /* time factor */
- X
- #define LOGOPAUSE 5
- X
- struct uiwindow *main_window; /* structure for main window */
- struct menu_box w1, w2, w3, w4; /* structures quad windows */
- X
- int stat_y1; /* line for status display */
- int stat_y2; /* top of status display */
- int stat_x1; /* column for status display */
- int stat_x2; /* max col for status display */
- X
- char sfs_prname[ 128 ];
- char bw_ebuf[ BW_EBUFSIZE ];
- X
- static int midx, midy;
- static FILE *data;
- X
- main( argc, argv )
- X int argc;
- X char **argv;
- X {
- X int x1, y1, x2, y2, incr, sfs_resume;
- X register int c, goodbye;
- X static char tbuf[ 64 ];
- X static struct sfs_orbit *sorbit_array[ ORBITS ];
- X
- X /*** First some precautionary measures */
- X /*** Load "chain" so that the loader (sfs) will exit */
- X /*** in the case of any unexpected exit */
- X
- X if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != 0 )
- X {
- X fprintf( data, "%s \n", SFSCH_EXIT );
- X fclose( data );
- X }
- X
- X /*** Now set a signal handler so that a SIGINT */
- X /*** (control-C under DOS, DEL under Unix) will */
- X /*** exit gracefully */
- X
- X signal( SIGINT, sfs_sigint );
- X
- X /* Process arguments */
- X
- X strcpy( sfs_program, SFS_DEFAULTPROG );
- X if ( argc > 1 )
- X {
- X if ( ( data = fopen( argv[ 1 ], "r" ) ) != 0 )
- X {
- X fclose( data );
- X strcpy( sfs_program, argv[ 1 ] );
- X }
- #ifdef DEBUG
- X else
- X {
- X fprintf( stderr, "Failed to open file %s\n", argv[ 1 ] );
- X exit( 0 );
- X }
- #endif
- X }
- X
- X sfs_resume = 0;
- X if ( argc > 2 )
- X {
- X if ( strncmp( argv[ 2 ], SFS_CONTARG, (size_t) 4 ) == 0 )
- X {
- X sfs_resume = TRUE;
- X }
- X }
- X
- X /* Initialize the toolkit */
- X
- X ui_init();
- X
- X /* Return if initialization failed */
- X
- X if ( ui_grwind->initialized == FALSE )
- X {
- X fprintf( stderr, "Graphics system is not initialized.\n" );
- X return -1;
- X }
- X
- X /* assign colors */
- X
- X sfs_colors(); /* Set colors */
- X
- X
- X /* reset icon colors */
- X
- X if ( gr_colors > 2 )
- X {
- X ui_seticons( cl_mback, cl_marker );
- X }
- X
- X /* Initialize variable-precision trig */
- X
- X vpt_init();
- X sfs_font( 0 );
- X
- X /* get memory for directory/menu arrays */
- X
- X for ( c = 0; c < MAX_ENTRIES; ++c )
- X {
- X if ( ( d_entries[ c ] =
- X (struct dir_ent *) malloc( sizeof( struct dir_ent ))) == NULL )
- X {
- X gr_deinit();
- X kb_deinit();
- X fprintf( stderr, MEMERR_DS, c );
- X exit( 1 );
- X }
- X if ( ( d_titles[ c ] = malloc( TITLE_SIZE )) == NULL )
- X {
- X gr_deinit();
- X kb_deinit();
- X fprintf( stderr, MEMERR_TA, c );
- X exit( 1 );
- X }
- X }
- X
- X /* Clear the screen */
- X
- X gr_cls( GR_PRIMARY );
- X
- X sfs_font( 0 );
- X
- X /* Draw the main screen */
- X
- X sfs_ms();
- X
- #ifdef OLD_DEBUG
- X kb_rx();
- #endif
- X
- X if ( sfs_resume == FALSE )
- X {
- X
- X /* Show the program logo */
- X
- X sfs_logo();
- X sfs_wait( LOGOPAUSE );
- X
- X }
- X
- #ifdef OLD_DEBUG
- X bw_error( "Test error message" );
- #endif
- X
- X /* Set default values */
- X
- X sfs_curorbit = 0;
- X strcpy( sfs_prname, UNTPROG );
- X sfs_tfactor = 1;
- X sfs_inc = 30;
- X sfs_insertion = 0;
- X
- X /* Read the initial program file */
- X
- X sfs_pr( sfs_program, sfs_prname, sorbit_array, ORBITS );
- X bw_message( " " );
- X
- X /* Cycle through the main menu */
- X
- X goodbye = 0;
- X while( goodbye == 0 )
- X {
- X
- X c = sfs_mm();
- X
- X switch( c )
- X {
- X case 0:
- X sfs_setpr( sorbit_array, ORBITS );
- X bw_message( " " );
- X sfs_curorbit = 0;
- X break;
- X case 1:
- X sfs_om( sorbit_array, ORBITS );
- X break;
- X case 2:
- X if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != 0 )
- X {
- #ifdef OLD_DEBUG
- X bw_debug( "Setting up chain file" );
- #endif
- X fprintf( data, "%s %s %s\n", SFSCH_SIMUL, sfs_program,
- X SFS_CONTARG );
- X fclose( data );
- X }
- X sfs_exit();
- X exit( 1 );
- X break;
- #ifdef BLOCKEDOUT
- X case 3:
- X if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != 0 )
- X {
- X fprintf( data, "%s %s %s %s\n", SFSCH_ATLAS, sfs_fdfile,
- X SFS_CONTARG, sfs_program );
- X fclose( data );
- X }
- X sfs_exit();
- X exit( 1 );
- X break;
- #endif
- X case TK_EXIT:
- X case 3:
- X if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != 0 )
- X {
- X fprintf( data, "%s \n", SFS_EXITARG );
- X fclose( data );
- X }
- X sfs_exit();
- X exit( 1 );
- X goodbye = 1;
- X break;
- X }
- X }
- X
- X sfs_exit();
- X
- X }
- X
- sfs_colors()
- X {
- X register int c;
- X int n;
- X
- X if ( gr_colors > 8 )
- X {
- X cl_mback = WHITE;
- X cl_mfore = BLACK;
- X cl_marker = DARK_CYAN;
- X cl_grid = DARK_BLUE;
- X cl_surface = DARK_GREEN;
- X n = LIGHT_RED;
- X for ( c = 0; c < OR_COLORS; ++c )
- X {
- X cl_orbits[ c ] = n;
- X ++n;
- X }
- X }
- X else if ( gr_colors > 2 )
- X {
- X cl_mback = WHITE;
- X cl_mfore = BLACK;
- X cl_marker = BLACK;
- X cl_grid = WHITE;
- X cl_surface = WHITE;
- X for ( c = 0; c < OR_COLORS; ++c )
- X {
- X cl_orbits[ c ] = WHITE;
- X }
- X }
- X else
- X {
- X cl_mback = WHITE;
- X cl_mfore = BLACK;
- X cl_marker = WHITE;
- X cl_grid = WHITE;
- X cl_surface = WHITE;
- X for ( c = 0; c < OR_COLORS; ++c )
- X {
- X cl_orbits[ c ] = WHITE;
- X }
- X }
- X
- X }
- X
- /*** Main SFS Screen */
- X
- sfs_ms()
- X {
- X
- X /* Draw the window itself */
- X
- X sprintf( sfs_tbuf, "%s, %s %s", SFS_TITLE, VERABB, VERSION );
- X main_window = ui_window( 0, 0, ui_grwind->xmax, ui_grwind->ymax,
- X TRUE, cl_marker, cl_mfore,
- X sfs_tbuf, FALSE, cl_mback,
- X FALSE, BLACK, cl_mback, GRID, BUT_CLOSE );
- X ui_fbox( main_window->u_x1, main_window->u_y1,
- X main_window->u_x2, main_window->u_y2, cl_mback, GRID );
- X
- X /* Draw two lines demarcating Status area */
- X
- X gr_line( GR_PRIMARY, ui_grwind->xmax / 2, main_window->tbar_y1,
- X ui_grwind->xmax / 2, main_window->y2, cl_mfore, SOLID );
- X gr_line( GR_PRIMARY, ( ui_grwind->xmax / 2 ) + 2,
- X main_window->tbar_y1,
- X ( ui_grwind->xmax / 2 ) + 2,
- X main_window->y2, cl_mfore, SOLID );
- X
- X /* Record the status area */
- X
- X stat_y1 = main_window->tbar_y1;
- X stat_y2 = main_window->y2 + ( ( ui_grwind->fysize ) * 0.3 );
- X stat_x1 = ( main_window->x2 / 2 ) + 5;
- X stat_x2 = main_window->tbar_x2;
- X
- X }
- X
- /*** Display Program Logo */
- X
- sfs_logo()
- X {
- X struct uiwindow *logo_window;
- X int x1, x2, y1, y2, height, length, midx, midy;
- X
- X midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
- X midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
- X
- X length = ( main_window->u_x2 * 7 ) / 10;
- X x1 = midx - length / 2;
- X x2 = midx + length / 2;
- X height = main_window->u_y2 / 2;
- X y1 = midy - height / 2;
- X y2 = midy + height / 2;
- X
- X logo_window = ui_window( x1, y1, x2, y2, FALSE, cl_marker, cl_mfore,
- X "", TRUE, cl_mfore, TRUE, cl_mfore, cl_mback, SOLID, FALSE );
- X
- X sfs_font( 2 );
- X y1 = midy + ui_grwind->fysize;
- X gr_text( GR_PRIMARY, midx - ( gr_strlen( SFS_TITLE ) / 2 ),
- X y1, SFS_TITLE, cl_mfore, cl_mback );
- X sfs_font( 0 );
- X y1 -= ui_grwind->fysize * 2;
- X gr_text( GR_PRIMARY, midx - ( gr_strlen( SFSM_PAX ) / 2 ),
- X y1, SFSM_PAX, cl_mfore, cl_mback );
- X y1 -= ui_grwind->fysize * 2;
- X gr_text( GR_PRIMARY, midx - ( gr_strlen( SFSM_CPRT ) / 2 ),
- X y1, SFSM_CPRT, cl_mfore, cl_mback );
- X y1 -= ( ui_grwind->fysize * 4 ) / 3;
- X gr_text( GR_PRIMARY, midx - ( gr_strlen( SFSM_BWS ) / 2 ),
- X y1, SFSM_BWS, cl_mfore, cl_mback );
- X
- X }
- X
- /*** Main Menu */
- X
- sfs_mm()
- X {
- X static struct uiwindow *pr_box;
- X static struct menu_box m_box;
- X
- X /* Clear the entire area */
- X
- X ui_fbox( main_window->u_x1, main_window->u_y1,
- X main_window->u_x2, main_window->u_y2,
- X BLACK, SOLID );
- X ui_fbox( main_window->u_x1, main_window->u_y1,
- X main_window->u_x2, main_window->u_y2,
- X cl_mback, GRID );
- X
- X bw_message( MES_MM );
- X
- X /* Display the program box */
- X
- X if ( pr_box == NULL )
- X {
- X pr_box = ui_window( main_window->u_x1 + 2 +
- X (( main_window->u_x2 - main_window->u_x1 )/2),
- X main_window->u_y2 -
- X ( ui_grwind->fysize * ( MM_TITLES + 3 )),
- X main_window->u_x2, main_window->u_y2,
- X TRUE, cl_marker, cl_mfore, SFSM_CPFX,
- X TRUE, cl_mfore, FALSE, BLACK, cl_mback, SOLID, FALSE );
- X }
- X else
- X {
- X ui_rewindow( pr_box, SFSM_CPFX );
- X }
- X sprintf( sfs_tbuf, SFSM_CPFI,
- X sfs_program, sfs_prname );
- X ui_text( pr_box->u_x1, pr_box->u_y1, pr_box->u_x2, pr_box->u_y2,
- X 64, cl_mback, cl_mfore, sfs_tbuf );
- X
- X /* get the main menu item and return it */
- X
- X m_box.is_drawn = FALSE;
- X return ui_list( MENU_SLIDERS, main_window->u_x1,
- X main_window->u_y2 -
- X ( ui_grwind->fysize * ( MM_TITLES + 3 )),
- X main_window->u_x2 -
- X (( main_window->u_x2 - main_window->u_x1 )/2),
- X main_window->u_y2,
- X MM_TTL, MM_TITLES, mm_titles,
- X cl_mfore, cl_mback, cl_marker, &m_box );
- X
- X }
- X
- sfs_setpr( sorbit_array, n_orbits )
- X struct sfs_orbit **sorbit_array;
- X int n_orbits;
- X {
- X static struct menu_box setp_box;
- X int x1, x2, y1, y2, height, length, midx, midy;
- X int item;
- X
- X midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
- X midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
- X
- X length = ( main_window->u_x2 * 7 ) / 10;
- X x1 = midx - length / 2;
- X x2 = midx + length / 2;
- X height = main_window->u_y2 / 2;
- X y1 = midy - height / 2;
- X y2 = midy + height / 2;
- X
- X setp_box.is_drawn = FALSE;
- X item = ui_ftext( x1, y1, x2, y2, "*.sfs", SFSM_SPF,
- X &setp_box, d_titles, d_entries, MAX_ENTRIES,
- X cl_mback, cl_mfore, cl_marker );
- X
- X fntolc( d_entries[ item ] );
- X strcpy( sfs_program, d_entries[ item ] );
- X sfs_pr( sfs_program, sfs_prname, sorbit_array, n_orbits );
- X
- X }
- X
- sfs_font( size )
- X int size;
- X {
- X static oldsize = 159;
- X int rq_height, calcy;
- X
- X if ( size == oldsize )
- X {
- X return;
- X }
- X
- X if ( ui_grwind->ymax > MAXYSIZE )
- X {
- X calcy = MAXYSIZE;
- X }
- X else
- X {
- X calcy = ui_grwind->ymax;
- X }
- X
- X switch( size )
- X {
- X case 1:
- X rq_height = calcy / 25;
- X break;
- X case 2:
- X rq_height = calcy / 15;
- X break;
- X default:
- X rq_height = calcy / 30;
- X break;
- X }
- X
- X gr_font( GR_PRIMARY, F_DEFAULT, rq_height );
- X }
- X
- bw_error( mes )
- X char *mes;
- X {
- X static char buffer[ BW_EBUFSIZE ];
- X static int x_mem;
- X static size_t x_size;
- X static int x1, x2, y1, y2, height, length, midx, midy, c;
- X static struct uiwindow *err_window;
- X
- X if ( x_mem == NULL )
- X {
- X
- X midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
- X midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
- X
- X length = main_window->u_x2 / 2;
- X x1 = midx - length / 2;
- X x2 = midx + length / 2;
- X height = main_window->u_y2 / 2;
- X y1 = midy - height / 2;
- X y2 = midy + height / 2;
- X
- X }
- X
- X gr_imsave( GR_PRIMARY, TRUE, x1, y1, x2, y2, &x_mem );
- X buffer[ 0 ] = 0;
- X sprintf( buffer, ERR_PROMPT, mes );
- X c = ui_yn( x1, y1, x2, y2, cl_mback, cl_mfore, cl_marker, TRUE,
- X buffer, ERRP_NO, ERRP_YES, &err_window );
- X gr_imsave( GR_PRIMARY, FALSE, x1, y1, x2, y2, &x_mem );
- X gr_imfree( x_mem );
- X
- X if ( c == FALSE )
- X {
- X sfs_exit();
- X exit( 1 );
- X }
- X }
- X
- #ifdef DEBUG
- bw_debug( mes )
- X char *mes;
- X {
- X static char buffer[ 256 ];
- X static int x_mem;
- X static size_t x_size;
- X static int x1, x2, y1, y2, height, length, midx, midy, c;
- X static struct uiwindow *deb_window;
- X
- #ifdef SMALL_DEBUG
- X sprintf( buffer, "DEBUG: %s ", mes );
- X gr_text( GR_PRIMARY, 5, 5, buffer, BLACK, WHITE );
- X ui_wait();
- #else
- X if ( x_mem == NULL )
- X {
- X
- X midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
- X midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
- X
- X length = main_window->u_x2 / 2;
- X x1 = midx - length / 2;
- X x2 = midx + length / 2;
- X height = main_window->u_y2 / 2;
- X y1 = midy - height / 2;
- X y2 = midy + height / 2;
- X
- X }
- X
- X gr_imsave( GR_PRIMARY, TRUE, x1, y1, x2, y2, &x_mem );
- X buffer[ 0 ] = 0;
- X sprintf( buffer, "DEBUG: %s ", mes );
- X c = ui_alarm( x1, y1, x2, y2, cl_mback, cl_mfore, cl_marker, TRUE,
- X buffer, "Press Any Key to Continue", &deb_window );
- X gr_imsave( GR_PRIMARY, FALSE, x1, y1, x2, y2, &x_mem );
- X gr_imfree( x_mem );
- X
- #endif
- X
- X }
- #endif
- X
- sfs_exit()
- X {
- X gr_cls( GR_PRIMARY );
- X gr_deinit();
- X }
- X
- sfs_wait( seconds )
- X int seconds;
- X {
- X static time_t start, current;
- X time( &start );
- X current = start;
- X while ( current < ( start + seconds ) )
- X {
- X time( ¤t );
- X }
- X }
- X
- tl_window( title )
- X char *title;
- X {
- X
- X midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
- X midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
- X
- X if ( w1.window == NULL )
- X {
- X w1.window = ui_window( main_window->u_x1 + 1, midy + 1,
- X midx - 1, main_window->u_y2 - 1, TRUE, cl_marker, BLACK,
- X title, 1, 0, 0, 0, 1, 1, BUT_CLOSE );
- X }
- X else
- X {
- X ui_rewindow( w1.window, title );
- X }
- X }
- X
- tr_window( title )
- X char *title;
- X {
- X
- X midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
- X midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
- X
- X if ( w2.window == NULL )
- X {
- X w2.window = ui_window( midx + 1, midy + 1,
- X main_window->u_x2 - 1, main_window->u_y2 - 1, TRUE, cl_marker, cl_mfore,
- X title, 1, 0, 0, 0, 1, 1, BUT_CLOSE );
- X }
- X else
- X {
- X ui_rewindow( w2.window, title );
- X }
- X }
- X
- bl_window( title )
- X char *title;
- X {
- X
- X midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
- X midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
- X
- X if ( w3.window == NULL )
- X {
- X w3.window = ui_window( main_window->u_x1 + 1, main_window->u_y1 + 1,
- X midx - 1, midy - 1, TRUE, cl_marker, BLACK,
- X title, TRUE, BLACK, FALSE, BLACK, WHITE, GRID, BUT_CLOSE );
- X }
- X else
- X {
- X ui_rewindow( w3.window, title );
- X }
- X sfsm_clpe();
- X }
- X
- br_window( title )
- X char *title;
- X {
- X
- X midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 );
- X midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 );
- X
- X if ( w4.window == NULL )
- X {
- X w4.window = ui_window( midx + 1, main_window->u_y1 + 1,
- X main_window->u_x2 - 1, midy - 1, TRUE, cl_marker, cl_mfore,
- X title, 1, 0, 0, 0, 1, 1, BUT_CLOSE );
- X }
- X else
- X {
- X ui_rewindow( w4.window, title );
- X }
- X }
- X
- sfs_sigint()
- X {
- X if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != 0 )
- X {
- X fprintf( data, "%s \n", SFS_EXITARG );
- X fclose( data );
- X }
- X sfs_exit();
- X exit( 1 );
- X }
- X
- ui_poll()
- X {
- X ;
- X }
- X
- bw_message( m )
- X char *m;
- X {
- X ui_fbox( stat_x1, main_window->tbar_y1 + 1,
- X main_window->tbar_x2, main_window->y2 - 1,
- X main_window->t_bcolor, SOLID );
- X
- X ui_str( stat_x1, stat_y1, stat_x2, cl_marker, cl_mfore, m );
- X
- X }
- X
- matherr( xstruct )
- X struct exception *xstruct;
- X {
- X sprintf( bw_ebuf, ERR_MATH, xstruct->name );
- X bw_error( bw_ebuf );
- X }
- X
- X
- SHAR_EOF
- chmod 0644 sfs/sfs/sfsm.c ||
- echo 'restore of sfs/sfs/sfsm.c failed'
- Wc_c="`wc -c < 'sfs/sfs/sfsm.c'`"
- test 17785 -eq "$Wc_c" ||
- echo 'sfs/sfs/sfsm.c: original size 17785, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= sfs/sfs/sfsm.h ==============
- if test -f 'sfs/sfs/sfsm.h' -a X"$1" != X"-c"; then
- echo 'x - skipping sfs/sfs/sfsm.h (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting sfs/sfs/sfsm.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfsm.h' &&
- /***************************************************************
- X
- X sfsm.h General Header File for
- X Space Flight Simulator,
- X Main Menu and Orbital Modeling Module
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ***************************************************************/
- X
- /*** Include Files */
- X
- #include "bw.h" /* header for generic Bywater handlers */
- #include "as.h" /* header for astronomy routines */
- #include "gr.h" /* header for graphics routines */
- #include "dr.h" /* header for directory routines */
- #include "ui.h" /* header for user interface routines */
- #include "sfs.h" /* header for sfs specific information */
- X
- /*** Program-specific definitions */
- X
- #define MAX_ENTRIES 64
- #define TITLE_SIZE 64
- X
- /***************************************************************
- X
- X language-specific definitions
- X
- X English is taken as a default, and if SFSMNAME
- X has not been defined, the English definitions will be
- X utilized. To translate into other languages, we suggest
- X that the following section be copied, a language name
- X defined as one, and then each of the definitions rendered
- X into the language. Example:
- X
- X ;#define LATIN 1
- X ;
- X ;
- X ;#if LATIN
- X ;#define SFSMNAME " Pars Prima "
- X ;......etc.
- X ;#endif
- X
- X SFSMNAME will then be defined, and the English language
- X tags will not be called.
- X
- ***************************************************************/
- X
- #ifndef SFSMNAME
- #define SFSMNAME " Main Module "
- #define SFSM_PAX "VENIMVS IN PACE PRO OMNIBVS"
- #define SFSM_CPRT "Copyright (c) 1991, Ted A. Campbell"
- #define SFSM_BWS "Bywater Software"
- #define SFSM_PEBL "[Perspective Window Blocked]"
- #define MM_SETPROGFILE " Set SFS Program File"
- #define MM_OM " Orbital Modeling "
- #define MM_OS " Orbital Simulation "
- #define MM_EXIT " Exit from SFS "
- #define SFSERR_GRINIT "ERROR: Failed to initialize graphics system.\n"
- #define MEMERR_DS "Cannot allocate memory for directory structure %d \n"
- #define MEMERR_TA "Cannot allocate memory for title array %d \n"
- #define UNTPROG "(As yet untitled)"
- SHAR_EOF
- true || echo 'restore of sfs/sfs/sfsm.h failed'
- fi
- echo 'End of part 19'
- echo 'File sfs/sfs/sfsm.h is continued in part 20'
- echo 20 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-