home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char sccsid[] = "@(#)dstar.c 1.2 92/05/28 SMI" ;
- /* from dstar.c 1.5 90/05/02 SMI */
- #endif
-
- /*
- * Copyright (c) 1986 by Sun Microsystems, Inc.
- */
-
- #include <fcntl.h>
- #include <stdio.h>
- #include <math.h>
- #include <sys/types.h>
- #include <sys/time.h>
- #include <signal.h>
- #include "dstar.h"
- #include "object_types.h"
- #ifdef XV
- #include <xview/notify.h>
- #else
- #include <sunwindow/notify.h>
- #endif XV
-
-
-
- extern int optind ;
- extern char *optarg ;
-
-
- static struct timeval Last_Poll ;
- static struct timeval countdown ;
- static Blast_State blast_state ;
- static int sigint() ;
-
-
- #ifdef COMMENT
- extern Notify_value dstar_prioritizer() ;
- #endif COMMENT
- void timefunc(), sleepfunc() ;
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- int i,j,k,iret ;
- int c ;
- Pt3d p1, p2, p3, p4, p5 ;
-
- gettimeofday(&Now, NULL) ;
- Last_Time.tv_sec = -1 ;
- Last_Poll = Now ;
-
- debug_level = 0 ;
-
- srandom(getpid()) ;
-
- Main_Timer.it_interval.tv_usec = DISPLAY_INTERVAL ;
- Main_Timer.it_interval.tv_sec = 0 ;
- Main_Timer.it_value.tv_usec = 0 ;
- Main_Timer.it_value.tv_sec = 1 ;
-
- Sleep_Timer.it_interval.tv_usec = 0 ;
- Sleep_Timer.it_interval.tv_sec = SLEEP_INTERVAL ;
- Sleep_Timer.it_value.tv_usec = 0 ;
- Sleep_Timer.it_value.tv_sec = POLL_INTERVAL ;
-
- blast_state = B_NIL ;
-
- init_objects() ; /* init object descriptions */
- Me = &objects[0] ; /* gets changed later */
-
- init_game_special(argc,argv) ; /* init graphic stuff (if any) */
-
-
- notify_set_signal_func(&Main_Timer, sigint, SIGHUP, NOTIFY_SYNC) ;
- notify_set_signal_func(&Main_Timer, sigint, SIGINT, NOTIFY_SYNC) ;
- notify_set_signal_func(&Main_Timer, sigint, SIGTERM, NOTIFY_SYNC) ;
- notify_set_signal_func(&Main_Timer, sigint, SIGXCPU, NOTIFY_SYNC) ;
- #ifdef COMMENT
- notify_set_prioritizer_func(&Main_Timer, dstar_prioritizer) ;
- #endif COMMENT
-
- if( Me->status == OBJ_SLEEPING )
- (void) notify_set_itimer_func(&Main_Timer, sleepfunc,
- ITIMER_REAL, &Sleep_Timer, 0) ;
- else
- (void) notify_set_itimer_func(&Main_Timer, timefunc,
- ITIMER_REAL, &Main_Timer, 0) ;
-
- dstar_main_loop() ;
- exit(0) ;
- }
-
-
-
-
- /* this routine called at start-up to zero out all objects */
-
- init_objects()
- {
- int i ;
- Pt3d p1,p2,p3 ;
-
- for(i=0; i<MAX_OBJECTS; objects[i++].class = OBJ_EMPTY ) ;
- for(i=0; i<MAX_DESCRIPTIONS; descriptions[i++] = NULL ) ;
- }
-
-
-
-
-
-
-
- /* interrupt handler. Simply tells the notifier to get the hell out */
-
-
- static int
- sigint(me, signal, when)
- int *me, signal ;
- Notify_signal_mode when ;
- {
- terminate_game() ;
- }
-
-
-
-
-
-
- /* this routine called whenever the clock ticks. Current mode affects
- what happens */
-
-
- void
- timefunc(client, which)
- int *client ;
- int which ;
- {
- long interval ;
-
- gettimeofday(&Now, NULL) ;
- if(Last_Time.tv_sec == -1)
- Last_Time = Now ;
-
- Dtime = (Now.tv_sec - Last_Time.tv_sec) +
- (Now.tv_usec - Last_Time.tv_usec) * .000001 ;
-
- switch(Me->status)
- {
- case OBJ_ACTIVE:
- normal_action() ;
- break ;
-
- case OBJ_DEAD:
- switch(blast_state)
- {
- case B_NIL:
- blast_state = B_FLASH ;
- set_blast_state(blast_state) ;
- countdown = Now ;
- break ;
-
- case B_FLASH:
- interval = (Now.tv_sec - countdown.tv_sec)*1000000 +
- Now.tv_usec - countdown.tv_usec ;
- if(interval > FLASH_INTERVAL)
- {
- blast_state = B_WAIT ;
- set_blast_state(blast_state) ;
- }
- blast_action() ;
- break ;
-
- case B_WAIT:
- interval = Now.tv_sec - countdown.tv_sec ;
- if(interval > DEATH_INTERVAL)
- {
- blast_state = B_NIL ;
- set_blast_state(blast_state) ;
- }
- else
- blast_action() ;
- break ;
- }
- break ;
- }
-
- if(Now.tv_sec - Last_Poll.tv_sec > POLL_INTERVAL)
- {
- net_poll() ;
- Last_Poll = Now ;
- }
- Last_Time = Now ;
-
- if( Me->id != -1 )
- net_flush() ;
- }
-
-
-
-
-
-
- /* this routine called whenever the clock ticks while asleep. */
-
-
- void
- sleepfunc(client, which)
- int *client ;
- int which ;
- {
- long interval ;
-
- gettimeofday(&Now, NULL) ;
-
- net_poll() ;
- Last_Poll = Now ;
- Last_Time = Now ;
-
- special_sleep_func() ;
-
- if( Me->id != -1 )
- net_flush() ;
- }
-