int global_message_handler(game_object_t *obj, message_t *mes) { if(mes->type == lapis_hash("sdl-event")) { SDL_Event *event = mes->data->data; if(event->type == SDL_KEYDOWN) { switch(event->key.keysym.sym) { case SDLK_ESCAPE: engine_quit(lapis_get_engine()); return 1; default: break; } } else if(event->type == SDL_QUIT) { engine_quit(lapis_get_engine()); return 1; } else if(event->type == SDL_VIDEORESIZE) { } } return 0; }
int c_engine( int argc, char *argv[] ) { off_t f_offset; int check4poll(); struct stat stat_buf; char spoolfile[100]; time_t time_now, time_prev; long tmin_now, tmin_prev, thour_now, thour_prev; mode_t oldumask; extern FILE *fdsout; extern FILE *fdserr; #ifdef HAVE_LIBXPL long xpl_poll = configp->engine_poll / 1000; Bool xpl_ready = FALSE; #endif sprintf( spoolfile, "%s/%s%s", SPOOLDIR, SPOOLFILE, configp->suffix); (void) signal(SIGINT, engine_quit /*iquit*/); (void) signal(SIGTERM, engine_quit); if (setjmp(mjb)) return(0); i_am_state = 1; i_am_monitor = 1; heyu_parent = D_CMDLINE; openlog( "heyu_engine", 0, LOG_DAEMON); syslog(LOG_ERR, "engine setting up-\n"); if ( read_x10state_file() != 0 ) x10state_init_all(); time_now = time_prev = time(NULL); tmin_now = tmin_prev = (long)time_now / 60L; thour_now = thour_prev = (long)time_now / 3600; engine_local_setup(E_START); fix_tznames(); f_offset = lseek(sptty, 0, SEEK_CUR); /* find current position */ oldumask = umask(configp->log_umask); fdsout = freopen(configp->logfile, "a", stdout); fdserr = freopen(configp->logfile, "a", stderr); umask(oldumask); #ifdef HAVE_LIBXPL /* xPLLib bug? */ if (xpl_poll == 1000) xpl_poll = 999; xpl_ready = xpl_init(); #endif fprintf(fdsout, "%s Engine started\n", datstrf()); fflush(fdsout); while (1) { if ( f_offset == lseek(sptty, 0, SEEK_END) ) { /* find end of file */ if( stat( spoolfile, &stat_buf ) < 0) engine_quit(SIGTERM) /* return(0) */; #ifdef HAVE_LIBXPL if (xpl_ready) xPL_processMessages(xpl_poll); else #endif /* this imposes a delay between the start of new output*/ /* It keeps the disk from being thrashed. */ microsleep(configp->engine_poll); } else { if ( fstat( sptty, &stat_buf ) < 0) return(0); lseek(sptty, f_offset, SEEK_SET); check4poll(1,1); f_offset = lseek(sptty, 0, SEEK_CUR); /* find current position */ } if ( (time_now = time(NULL)) != time_prev ) { if ( is_tomorrow(time_now) ) { /* Local Midnight. STD Time */ midnight_tick(time_now); set_global_tomorrow(time_now); } if ( (thour_now = (long)time_now / 3600L) != thour_prev ) { /* Once every hour */ hour_tick(time_now); thour_prev = thour_now; } if ( (tmin_now = (long)time_now / 60L) != tmin_prev ) { /* Once every minute */ minute_tick(time_now); tmin_prev = tmin_now; } /* Once every second */ /* Activate countdown timers */ second_tick(time_now, (long)(time_now - time_prev)); time_prev = time_now; } } /* return(0); */ }