Example #1
0
//******************************************************************************
// FunciĆ³n tcj_inicializar(...)
//    Inicializa el sistema, instalando el teclado, el joystick/joypad o ambos.
//******************************************************************************
void tcj_inicializar(unsigned char instalar)
{
 char f,n;

 for(f=0;f<(TCJ_MAX_ENTRADAS*(4+TCJ_NUM_BOTONES));entrada[f++]=NULL);

 if(instalar&TCJ_INSTALAR_T && !ini_t)
  {
   install_keyboard();
   ini_t=1;
  }

 if(instalar&TCJ_INSTALAR_J && !ini_j)
   if(!install_joystick(JOY_TYPE_AUTODETECT))
     if(num_joysticks)
      {
       ini_j=1;
#ifdef ALLEGRO_BIG_ENDIAN
#define BGE 3
#else
#define BGE 0
#endif
       entrada[0]                 =(volatile char *)(&(joy[0].stick[0].axis[1].d1))+BGE;
       entrada[TCJ_MAX_ENTRADAS]  =(volatile char *)(&(joy[0].stick[0].axis[0].d2))+BGE;
       entrada[TCJ_MAX_ENTRADAS*2]=(volatile char *)(&(joy[0].stick[0].axis[1].d2))+BGE;
       entrada[TCJ_MAX_ENTRADAS*3]=(volatile char *)(&(joy[0].stick[0].axis[0].d1))+BGE;

       for(n=0,f=TCJ_MAX_ENTRADAS*4;f<(TCJ_MAX_ENTRADAS*(4+TCJ_NUM_BOTONES));n++,f+=TCJ_MAX_ENTRADAS)
         entrada[f]=(volatile char *)(&(joy[0].button[n].b))+BGE;
#undef BGE
      }
}
Example #2
0
int cControls::Init()
{
   install_keyboard();
   install_joystick(JOY_TYPE_AUTODETECT);
   install_mouse();

   return 0;
}
Example #3
0
int main()
{
  std::srand(std::time(NULL));

  allegro_init();
  install_timer();
  install_keyboard();
//   install_mouse();
  install_joystick(JOY_TYPE_AUTODETECT);

  override_config_file(redir("defnot.ini").c_str());

  gfx_widescreen = get_config_int("Game", "Widescreen", gfx_widescreen);
  gfx_fullscreen = get_config_int("Game", "Fullscreen", gfx_fullscreen);

  if (!setup_gfx() != 0) {
    allegro_message("Unable to setup the graphics mode\n");
    return 1;
  }

//   if (gfx_capabilities & GFX_HW_CURSOR) {
//     enable_hardware_cursor();
//     select_mouse_cursor(MOUSE_CURSOR_ARROW);
//     show_mouse(screen);
//   }

  if (!load_media()) {
    allegro_message("Unable to load data files to play the game\n");
    return 1;
  }

  // install the timer to control the game speed
  LOCK_VARIABLE(beats);
  LOCK_FUNCTION(timer_control);

  beats = 0;
  install_int_ex(timer_control, BPS_TO_TIMER(BPS));

  // insert the callback routine for the close-button
  LOCK_VARIABLE(continuing);
  LOCK_FUNCTION(close_button);

  set_close_button_callback(close_button);

  // play the game
  game_loop();

  set_config_int("Game", "Widescreen", gfx_widescreen);
  set_config_int("Game", "Fullscreen", gfx_fullscreen);

  remove_int(timer_control);
  allegro_exit();
  return 0;
}
Example #4
0
/* initialise_joystick:
 *  Bodge function to preserve backward compatibility with the old API.
 */
int initialise_joystick()
{
   int type = joy_type;

   if (_joystick_installed)
      remove_joystick();

   if (type == JOY_TYPE_NONE)
      type = JOY_TYPE_STANDARD;

   return install_joystick(type);
}
Example #5
0
/*============================================================================*/
void init_system()
{
	int i, j, k;
	#ifdef __O2EM_DEBUG__
	printf("%s()\n", __func__);
	#endif
	last_line = 0;
	dbstick1 = 0x00;
	dbstick2 = 0x00;
	mstate = 0;
	master_clk = 0;
	h_clk = 0;
	line_count = 0;
	itimer = 0;
	clk_counter = 0;

	init_roms();
	init_rams();

	for (i = 0; i < MAXLINES; i++)
		AudioVector[i] = ColorVector[i] = 0;

	for (i = 0; i < MAXLINES + 2 * MAXSNAP; i++)
		for (j = 0; j < 256; j++)
			for (k = 0; k < 2; k++)
				snapedlines[i][j][k]=0;

	if (app_data.stick[0] == 2 || app_data.stick[1] == 2) {
		#ifdef __O2EM_DEBUG__
		printf("%s() install_joystick()\n", __func__);
		#endif
		i = install_joystick(JOY_TYPE_AUTODETECT);
		if (i || (num_joysticks < 1)) {
			fprintf(stderr, "Error: no joystick detected\n");
			o2em_clean_quit(EXIT_FAILURE);
		}
	}
	for (i = 0; i < KEY_MAX; i++)
		key2[i] = 0;
	key2vcnt = 0;

	if (app_data.euro)
		setvideomode(1);
	else
		setvideomode(0);

	do_kluges();
	init_vpp();
	clear_collision();
	#ifdef __O2EM_DEBUG__
	printf("end of %s()\n", __func__);
	#endif
}
	void InputDeviceSingleton::InitializeJoystick()
	{
		static bool firstCall = true;
		
		// make sure that we only install the joystick driver once
		// because this routine may incorrectly be called multiple times
		if (firstCall)
		{
			/*
			 * check to see if the joysticks have previously been calibrated
			 *
			 * if the joysticks were not calibrated, then we go through a
			 * calibration sequence and then save the calibration data to a file.
			 *
			 * if the calibration file exists, we then try to load the data.
			 * if the loading of the data fails, then we disable the joystick.
			 */
			bool previouslyCalibrated = false;
			
			FILE* fp = fopen("joysettings.dat", "rb"); 
			
			if (fp) 
			{
				fclose(fp); 
				if (0 != load_joystick_data("joysettings.dat"))
				{
					LogWarning("Joystick Data File was found, but it could not be loaded! Possibly has been corrupted!");
				}
				else
				{
					previouslyCalibrated = true;
					joystickAvailable_ = true;
				}
			}
			
			if (!previouslyCalibrated)
			{
				// try to install the joystick driver
				if (0 != install_joystick(JOY_TYPE_AUTODETECT))
				{
					LogFatal("Could not install Allegro Joystick driver!");
				}
				
				// calibrate the joysticks
				BeginJoystickCalibration();
			}
			
			// first-time-only initialize has finished
			firstCall = false;
		}
	}
Example #7
0
int main(int argc, char **argv)
{
	bool fullScreen;
	int windowW, windowH;

	srand(time(0));
	allegro_init();

	install_keyboard();
	install_mouse();
	install_timer();
	install_joystick(JOY_TYPE_AUTODETECT);

	set_color_depth(32);

	CheckMIDIs();
	set_config_file("trog.cfg");

	CfgLoad();

	set_gfx_mode(cfgFull ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, std::atoi(cfgW), std::atoi(cfgH), 0, 0);
	install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, 0);

	set_window_title("The Revenge of Gregorius");
	set_display_switch_mode(SWITCH_BACKGROUND);
	set_display_switch_callback(SWITCH_OUT, &SwitchOut);
	
	LoadSoundVolumes("sounds.cfg");
	game.Init();

	bool notQuit = true;
	while(notQuit)
	{
		int ret = MainMenu();
		switch(ret)
		{
			case 0:
				game.zoomMode = cfgZoom;
				game.Start(-1);
				break;
			case 1:
				DoConfiguration();
				break;
			case 2:
				notQuit = false;
				break;
		}
	}
	return 0;
}
Example #8
0
void Init_video(char* argv[])
{
	allegro_init();
	install_timer();
	install_keyboard(); 
	install_joystick(JOY_TYPE_AUTODETECT);
	request_refresh_rate(FPS_VIDEO);
	set_color_depth(32);
	/*set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 320, 240, 0, 0);*/
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, 320, 240, 0, 0);
	set_window_title(game_name);
	clear_to_color(screen, makecol(0, 0, 0));
	LOCK_VARIABLE(ticks);
	LOCK_FUNCTION(ticker);
	install_int_ex(ticker, BPS_TO_TIMER(FPS_VIDEO));
}
Example #9
0
void init_system(void){
	int i,j,k;

	last_line=0;
	dbstick1=0x00;
	dbstick2=0x00;
	mstate=0;
	master_clk=0;
	h_clk=0;
	line_count=0;
	itimer=0;
	clk_counter=0;
	init_roms();
	for(i=0; i<256; i++) {
		VDCwrite[i]=0;
		extRAM[i]=0;
	}
	for(i=0; i<64; i++) {
		intRAM[i]=0;
	}
	for (i=0; i<MAXLINES; i++) AudioVector[i] = ColorVector[i] = 0;
	
	for (i=0; i<MAXLINES+2*MAXSNAP; i++)
		for (j=0; j<256; j++)
			for (k=0; k<2; k++)
				snapedlines[i][j][k]=0;

	if (app_data.stick[0] == 2 || app_data.stick[1] == 2) {
		i = install_joystick(JOY_TYPE_AUTODETECT);
		if (i || (num_joysticks<1)) {
			fprintf(stderr,"Error: no joystick detected\n");
			exit(EXIT_FAILURE);
		}
	}
	for (i=0; i<128; i++) key2[i] = 0;
	key2vcnt=0;
	if (app_data.euro)
		setvideomode(1);
	else
		setvideomode(0);
	do_kluges();
	init_vpp();
	clear_collision();
}
Example #10
0
/* init_window_modules:
 *  Initialises the modules that are specified by the WM argument.
 */
static int init_window_modules(struct WINDOW_MODULES *wm)
{
   if (wm->keyboard)
      install_keyboard();

   if (wm->mouse)
      install_mouse();

   if (wm->joystick)
      install_joystick(wm->joy_type);

   if (wm->sound)
      install_sound(wm->digi_card, wm->midi_card, NULL);

   if (wm->sound_input)
      install_sound_input(wm->digi_input_card, wm->midi_input_card);

   return 0;
}
Example #11
0
/* load_joystick_data:
 *  Restores a set of joystick calibration data previously saved by
 *  save_joystick_data().
 */
int load_joystick_data(char *filename)
{
   int ret, c;

   joy_loading = TRUE;

   if (_joystick_installed)
      remove_joystick();

   if (filename) {
      push_config_state();
      set_config_file(filename);
   }

   joy_type = get_config_id("joystick", "joytype", -1);

   if (joy_type < 0) {
      joy_type = JOY_TYPE_NONE;
      ret = -1;
   }
   else {
      ret = install_joystick(joy_type);

      if (ret == 0) {
	 if (joystick_driver->load_data)
	    ret = joystick_driver->load_data();
      }
   }

   if (filename)
      pop_config_state();

   if (ret == 0) {
      for (c=0; c<num_joysticks; c++)
	 update_calib(c);

      poll_joystick();
   }

   joy_loading = FALSE;

   return ret;
}
adv_error joystickb_lgallegro_init(int id)
{
	log_std(("joystickb:lgallegro: joystickb_lgallegro_init(id:%d)\n", id));

	if (id == JOY_TYPE_AUTODETECT) {
		error_set("No auto detection");
		return -1;
	}

	lgallegro_state.id = id;

	lgallegro_state.last = target_clock();

	log_std(("joystickb:lgallegro: joystick initialization\n"));
	if (install_joystick(lgallegro_state.id) != 0) {
		log_std(("joystickb:lgallegro: joystick initialization failed\n"));
		return -1;
	}

	return 0;
}
int install()
{
    int screen_mode;

    if(IsInstalled)
        return 0;
    if(allegro_init())
        return 1;
    if(install_allegro_gl())
        return 1;
    set_window_title("Sharp Fighters");

    Resolutions=get_gfx_mode_list(GFX_OPENGL_FULLSCREEN);

    LoadSettings();

   LoadCollisionData();

    if(install_keyboard())
        return 1;
    if(install_timer())
        return 1;
    if(install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL))
        return 1;

    JoyStickEnabled=(install_joystick(JOY_TYPE_AUTODETECT)==0);
    JoyStickEnabled=JoyStickEnabled && num_joysticks;
    LoadInput();

    if(install_fonts())
        printf("One or more font files were not loaded.\n");

    allegro_gl_set(AGL_COLOR_DEPTH, depth);
    allegro_gl_set(AGL_RENDERMETHOD, 1);
    allegro_gl_set(AGL_DOUBLEBUFFER, 1);
    allegro_gl_set(AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_DOUBLEBUFFER | AGL_RENDERMETHOD);

    if(Fullscreen)
        screen_mode=GFX_OPENGL_FULLSCREEN;
    else
        screen_mode=GFX_OPENGL_WINDOWED;

    if (set_gfx_mode(screen_mode, Width,Height, 0, 0))
    {
        set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
        allegro_message("Unable to set graphic mode\n%s\n", allegro_error);
        return 1;
    }
    set_close_button_callback(close_button_handler);
    SetOpenGL2D();
    screenimage=(IMAGE*)malloc(sizeof(IMAGE));
    screenimage->ID=0;
    AspectRatio=(float)SCREEN_W/(float)SCREEN_H;

    if(install_int(Ticks,1))
        return 1;
    if(install_int(ProcessKeys,25))
        return 1;

    IsInstalled=1;
    return 0;
}
Example #14
0
int main(int argc, char *argv[])
{
   int c, w, h;
   char buf[256], buf2[256];
   ANIMATION_TYPE type;

   for (c = 1; c < argc; c++) {
      if (stricmp(argv[c], "-cheat") == 0)
         cheat = TRUE;

      if (stricmp(argv[c], "-jumpstart") == 0)
         jumpstart = TRUE;
   }

   /* The fonts we are using don't contain the full latin1 charset (not to
    * mention Unicode), so in order to display correctly author names in
    * the credits with 8-bit characters, we will convert them down to 7
    * bits with a custom mapping table. Fortunately, Allegro comes with a
    * default custom mapping table which reduces Latin-1 and Extended-A
    * characters to 7 bits. We don't even need to call set_ucodepage()!
    */
   set_uformat(U_ASCII_CP);
   
   srand(time(NULL));
   if (allegro_init() != 0)
      return 1;
   install_keyboard();
   install_timer();
   install_mouse();

   if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) {
      allegro_message("Error initialising sound\n%s\n", allegro_error);
      install_sound(DIGI_NONE, MIDI_NONE, NULL);
   }

   if (install_joystick(JOY_TYPE_AUTODETECT) != 0) {
      allegro_message("Error initialising joystick\n%s\n", allegro_error);
      install_joystick(JOY_TYPE_NONE);
   }

   if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
         set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
         allegro_message("Unable to set any graphic mode\n%s\n",
                         allegro_error);
         return 1;
      }
   }

   get_executable_name(buf, sizeof(buf));
   replace_filename(buf2, buf, "demo.dat", sizeof(buf2));
   set_color_conversion(COLORCONV_NONE);
   data = load_datafile(buf2);
   if (!data) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error loading %s\n", buf2);
      exit(1);
   }

   if (!jumpstart) {
      intro_screen();
   }

   clear_bitmap(screen);
   set_gui_colors();
   set_mouse_sprite(NULL);

   if (!gfx_mode_select(&c, &w, &h))
      exit(1);

   if (pick_animation_type(&type) < 0)
      exit(1);

   init_display(c, w, h, type);

   generate_explosions();

   //stop_sample(data[INTRO_SPL].dat);

   clear_bitmap(screen);

   while (title_screen())
      play_game();

   destroy_display();

   destroy_explosions();

   stop_midi();

   set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);

   end_title();

   unload_datafile(data);

   allegro_exit();

   return 0;
}
void joystick_init()
{
        install_joystick(JOY_TYPE_AUTODETECT);
        joysticks_present = MIN(num_joysticks, 2);
}
Example #16
0
int
main (int argc, char *argv[]) 
{
  int DesiredJoystick = 0, i, j, Joystick, Stick, Axis, Offset, Changed = 0;
  float Factor;
  char *s;

#ifdef WIN32
  Out = stdout; // fopen ("yaACA.txt", "w");
#else
  Out = stdout;
#endif

  fprintf (Out, "Apollo Attitude Controller Assembly (ACA) emulation, version " NVER 
  	  ", built " __DATE__ "\n");
  fprintf (Out, "(c)2005,2009 Ronald S. Burkey\n");
  fprintf (Out, "Refer to http://www.ibiblio.org/apollo/index.html for more information.\n");
  fflush (Out);
  
  // Initialize Allegro.
Retry:
  allegro_init ();
  if (install_joystick (JOY_TYPE_AUTODETECT) || num_joysticks <= 0)
    {
      fprintf (Out, "Couldn\'t find any joysticks. Retrying ...\n");
      fflush (Out);
      //return (1);
#ifdef WIN32
      Sleep (5000);	    
#else // WIN32
      {
	struct timespec req, rem;
	req.tv_sec = 5;
	req.tv_nsec = 0;
	nanosleep (&req, &rem);
      }
#endif // WIN32
      allegro_exit ();
      goto Retry;
    }
    
    {
      GetParameters (Controller);
           
      //fprintf (Out, "%d joysticks found:\n", num_joysticks);
      for (i = 0; i < num_joysticks; i++)
        {
	  int k;
	  fprintf (Out, "Joystick device #%d:\n", i);
	  if (joy[i].flags & JOYFLAG_DIGITAL)
	    fprintf (Out, "\tThis control provides a digital input.\n");
	  else if (joy[i].flags & JOYFLAG_ANALOGUE)
	    fprintf (Out, "\tThis control provides an analog input.\n");
	  else if (joy[i].flags & JOYFLAG_CALIB_DIGITAL)
	    fprintf (Out, "\tThis control will provide a digital input after calibration.\n");
	  else if (joy[i].flags & JOYFLAG_CALIB_ANALOGUE)
	    fprintf (Out, "\tThis control will provide an analog input after calibration.\n"); 
	  else if (joy[i].flags & JOYFLAG_CALIBRATE)
	    fprintf (Out, "\tThis control needs calibration.\n");
	  else if (joy[i].flags & JOYFLAG_SIGNED)
	    fprintf (Out, "\tThis control provides signed data (i.e., -127 to 127).\n");
	  else if (joy[i].flags & JOYFLAG_UNSIGNED)
	    fprintf (Out, "\tThis control provides unsigned data (i.e., 0 to 255).\n");
	  for (j = 0; j < joy[i].num_sticks; j++)
	    {
	      fprintf (Out, "\tStick #%d of joystick device #%d:\n", j, i);
	      if (joy[i].stick[j].flags & JOYFLAG_DIGITAL)
		fprintf (Out, "\t\tThis control provides a digital input.\n");
	      else if (joy[i].stick[j].flags & JOYFLAG_ANALOGUE)
		fprintf (Out, "\t\tThis control provides an analog input.\n");
	      else if (joy[i].stick[j].flags & JOYFLAG_CALIB_DIGITAL)
		fprintf (Out, "\t\tThis control will provide a digital input after calibration.\n");
	      else if (joy[i].stick[j].flags & JOYFLAG_CALIB_ANALOGUE)
		fprintf (Out, "\t\tThis control will provide an analog input after calibration.\n"); 
	      else if (joy[i].stick[j].flags & JOYFLAG_CALIBRATE)
		fprintf (Out, "\t\tThis control needs calibration.\n");
	      else if (joy[i].stick[j].flags & JOYFLAG_SIGNED)
		fprintf (Out, "\t\tThis control provides signed data (i.e., -127 to 127).\n");
	      else if (joy[i].stick[j].flags & JOYFLAG_UNSIGNED)
		fprintf (Out, "\t\tThis control provides unsigned data (i.e., 0 to 255).\n");
	      fprintf (Out, "\t\tDescription = %s\n", joy[i].stick[j].name);
	      for (k = 0; k < joy[i].stick[j].num_axis; k++)
	        fprintf (Out, "\t\tAxis #%d description = %s\n", k, joy[i].stick[j].axis[k].name);
	    }
	  for (j = 0; j < joy[i].num_buttons; j++)
	    {
	      fprintf (Out, "\tButton %d = %s\n", j, joy[i].button[j].name);
	    }
	}
      fprintf (Out, "\n");
      fprintf (Out, "Note that only 3 degrees of freedom and no buttons are used by yaACA.\n");
      fprintf (Out, "Right roll, upward pitch, and clockwise yaw are positive values.\n");
      fprintf (Out, "Left roll, downward pitch, and counter-clockwise yaw are negative values.\n");
    }
    
  // Parse the command-line arguments.
  for (i = 1; i < argc; i++)
    {
      if (!strcmp (argv[i], "--help"))
        {
	  fprintf (Out, 
	    "\n"
	    "USAGE:\n"
	    "\tyaACA [OPTIONS]\n"
	    "The recognized options are:\n"
	    "--help\n"
	    "\tDisplays this message.\n"
	    "--roll=J,S,A,F,O  or  --pitch=J,S,A,F,O  or  --yaw=J,S,A,F,O\n"
	    "\tThese options allow you to configure how the roll/pitch/yaw degrees\n"
	    "\tof freedom map to the characteristics of the joystick as recognized\n"
	    "\tby the computer's operating system.  J is the joystick number (in \n"
	    "\tcase multiple joysticks are installed), S is the stick number within\n"
	    "\tthe joystick, and A is the axis within the stick.  F is a factor which\n"
	    "\tthe joystick reading is multiplied by, and O is an offset added to the\n"
	    "\tjoystick reading (after multiplication is completed).  The factor is \n"
	    "\tuseful (for example) in swapping right-to-left, back-to-front, or \n"
	    "\tclockwise-to-counter-clockwise.  The offset would be useful when the\n"
	    "\tthe joystick provides unsigned readings (0-255) rather than the desired\n"
	    "\tsigned readings (-127 to 127).  The defaults are:\n"
	    "\t\t\tRoll\t\t0,0,0,+1.0,0\n"
	    "\t\t\tPitch\t\t0,0,1,+1.0,0\n"
#ifdef __APPLE__
	    "\t\t\tYaw\t\t0,2,0,+1.0,%d\n"
#else	    
	    "\t\t\tYaw\t\t0,1,0,+1.0,%d\n"
#endif
	    "\t(By the way, the defaults work with a Logitech Extreme 3D Pro.)\n"
	    "\tAlthough it would appear that you can select a different joystick\n"
	    "\tcontroller (the first field) for each of the pitch/roll/yaw axes,\n"
	    "\tyou really cannot, so please do not do so.  For versions 20090406\n"
	    "\tand later, your selections are automatically stored in a configuration\n"
	    "\tfile called yaACA-N.cfg, where N is the joystick controller number,\n"
	    "\tand become the new defaults the next time the program is run.  In\n"
	    "\tother words, once you've determined the appropriate command-line\n"
	    "\tsettings for --roll, --pitch, and --yaw, you don't need to use the\n"
	    "\tcommand-line parameters again.  An exception is if the joystick\n"
	    "\tcontroller-number is non-zero.  If so, you will need to use at least\n"
	    "\tone of these command-line switches every time, or else the saved\n"
	    "\tsettings for controller 0 will be used.\n"
	    "--ip=Hostname\n"
	    "\tThe yaACA program and the yaAGC Apollo Guidance Computer simulation\n"
	    "\texist in a \"client/server\" relationship, in which the yaACA program\n"
	    "\tneeds to be aware of the IP address or symbolic name of the host\n"
	    "\tcomputer running the yaAGC program.  By default, this is \"localhost\",\n"
	    "\tmeaning that both yaACA and yaAGC are running on the same computer.\n"
            "--port=Portnumber\n"
	    "\tBy default, yaACA attempts to connect to the yaAGC program using port\n"
	    "\tnumber %d.  However, if more than one instance of yaACA is being\n"
	    "\trun, or if yaAGC has been configured to listen on different ports, then\n"
	    "\tdifferent port settings for yaACA are needed.  Note that by default,\n"
	    "\tyaAGC listens for new connections on ports 19697-19706, but that the\n"
	    "\trecommended port range when using yaAGC in the LM is 19797-19806.\n",
	    YawOffset, sPortnum
	  );
	  fprintf (Out, "--delay=N\n");
	  fprintf (Out, "\t\"Start-up delay\", in ms.  Defaults to %d.  What the start-up\n", StartupDelay);
	  fprintf (Out, "\tdelay does is to prevent yaACA from attempting to communicate with\n");
	  fprintf (Out, "\tyaAGC for a brief time after power-up.  This option is really only\n");
	  fprintf (Out, "\tuseful in Win32, to work around a problem with race-conditions in\n");
	  fprintf (Out, "\tat start-up time.\n");
	  return (0);
	}
      else if (5 == sscanf (argv[i], "--roll=%d,%d,%d,%f,%d", &Joystick, &Stick, &Axis, &Factor, &Offset) ||
               5 == sscanf (argv[i], "--pitch=%d,%d,%d,%f,%d", &Joystick, &Stick, &Axis, &Factor, &Offset) ||
	       5 == sscanf (argv[i], "--yaw=%d,%d,%d,%f,%d", &Joystick, &Stick, &Axis, &Factor, &Offset) )
        {
	  if (Joystick >= 0 && Joystick < num_joysticks)
	    {
	      DesiredJoystick = Joystick;
	      if (Stick < 0 || Stick >= joy[Joystick].num_sticks)
	        {
		  fprintf (Out, "\nJoystick #%d stick numbers must be >=0 and < %d.  Sorry!\n",
		          Joystick, joy[Joystick].num_sticks);
		  return (1);
		}
	      if (Axis < 0 || Axis >= joy[Joystick].stick[Stick].num_axis)
	        {
		  fprintf (Out, "\nJoystick #%d, stick #%d axis numbers must be >=0 and < %d.  Sorry!\n",
		          Joystick, Stick, joy[Joystick].stick[Stick].num_axis);
		  return (1);
		}
	      if (0 == (JOYFLAG_ANALOGUE & joy[Joystick].stick[Stick].flags))
	        {
		  fprintf (Out, "\nJoystick #%d, stick #%d is not analog.  Sorry!\n",
		          Joystick, Stick);
		  return (1);
		}
	      if ('r' == argv[i][2])
	        {
	          Roll = &joy[Joystick].stick[Stick].axis[Axis].pos;
		  RollFactor = Factor;
		  RollOffset = Offset;
		  Controller = Joystick;
		  RollStick = Stick;
		  RollAxis = Axis;
		  Changed = 1;
		}
	      else if ('p' == argv[i][2])
	        {
	          Pitch = &joy[Joystick].stick[Stick].axis[Axis].pos;
		  PitchFactor = Factor;
		  PitchOffset = Offset;
		  Controller = Joystick;
		  PitchStick = Stick;
		  PitchAxis = Axis;
		  Changed = 1;
		}
	      else
	        {
	          Yaw = &joy[Joystick].stick[Stick].axis[Axis].pos;
		  YawFactor = Factor;
		  YawOffset = Offset;
		  Controller = Joystick;
		  YawStick = Stick;
		  YawAxis = Axis;
		  Changed = 1;
		}
	    }
	  else
	    {
	      fprintf (Out, "\nJoystick numbers must be >= 0 and < %d.  Sorry!\n", num_joysticks);
	      return (1);
	    }  
	}
      else if (1 == sscanf (argv[i], "--delay=%d", &j))
        StartupDelay = j;
      else 
        {
	  fprintf (Out, "Unknown command-line switch \"%s\".\n", argv[i]);
	  fprintf (Out, "Try \"yaACA --help\".\n");
	  return (1);
	}	
    }
  if (Changed || !CfgExisted)
    WriteParameters (Controller);
    
  // Set up variables for quick access to just the desired joystick, and check for minimum
  // requirements.  Note that the ACA requires no pushbuttons (there are associated toggle
  // switches, but they're not physically on the hand-control, and they are toggle switches
  // anyhow).  
  s = (char *) calibrate_joystick_name (DesiredJoystick);
  if (s != NULL)
    {
      fprintf (Out, "%s\n", calibrate_joystick_name (DesiredJoystick));
      if (calibrate_joystick (DesiredJoystick))
	{
	  fprintf (Out, "Joystick calibration problem.\n");
	  return (1);
	}
    }
  PrintJoy ();
    
  // Now we start polling the joystick from time to time.  The way Allegro works is to 
  // maintain an array containing info on each joystick.  This array is updated only when
  // poll_joystick is called (which you have to do explicitly).  To see what has changed,
  // we maintain a copy of the joy[] array.
  while (1)
    {
      // Sleep for a while so that this job won't monopolize CPU cycles.
#ifdef WIN32
      Sleep (UPDATE_INTERVAL);	    
#else // WIN32
      struct timespec req, rem;
      req.tv_sec = 0;
      req.tv_nsec = 1000000 * UPDATE_INTERVAL;
      nanosleep (&req, &rem);
#endif // WIN32
      poll_joystick ();				// Get joystick values.
      PrintJoy ();				// Display them locally.
      PulseACA ();				// Manage server connection.
#if 0      
      {
        static int Count = 0;
        fprintf (Out, "*");
	Count++;
	if (Count >= 32)
	  {
	    Count = 0;
	    fflush (Out);
	  }
      }
#endif      
    }

  return (0);
}
Example #17
0
//Main function
int main(){
  allegro_init();
  alpng_init();
  install_timer();
  install_keyboard();
  install_mouse();
  install_joystick(JOY_TYPE_AUTODETECT);
  install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,".");
  set_color_depth(32);

  // Setup basic functionality
  setup();

  //Set the current state ID
  stateID = STATE_INIT;

  //Set the current game state object
  currentState = new Init();


  while(!game_closed_esc && !close_button_pressed && stateID != STATE_EXIT){
    while(ticks == 0){
      rest(1);
    }
    while(ticks > 0){
      //Esc key handler
     if(key[KEY_ESC]){
           if(alert(NULL, "Are you sure you want to exit the game?",NULL,"&Resume Game", "&Exit", 'r','e' )==2)
           game_closed_esc=true;

      }


      int old_ticks = ticks;

      //Do state logic
      currentState -> update();

      //Change state if needed
      change_state();

      // Counter for FPS
      frames_done++;

      ticks--;
      if(old_ticks <= ticks){
        break;
      }
    }
    if(game_time - old_time >= 10){
      fps = frames_done;
      frames_done = 0;
      old_time = game_time;
    }
    //Do state rendering
    currentState -> draw( true);
  }

  //Clean up
  clean_up();

  return 0;
}