Example #1
0
/* Initializes the XInput haptic system. */
static bool hapxi_init_haptic(void)
{
   int i;

   ASSERT(hapxi_mutex == NULL);
   ASSERT(hapxi_thread == NULL);
   ASSERT(hapxi_cond == NULL);


   /* Create the mutex and a condition vaiable. */
   hapxi_mutex = al_create_mutex_recursive();
   if (!hapxi_mutex)
      return false;
   hapxi_cond = al_create_cond();
   if (!hapxi_cond)
      return false;

   al_lock_mutex(hapxi_mutex);

   for (i = 0; i < HAPTICS_MAX; i++) {
      haptics[i].active = false;
   }

   /* Now start a polling background thread, since XInput is a polled API,
      and also to make it possible for effects to stop running when their
      duration has passed. */
   hapxi_thread = al_create_thread(hapxi_poll_thread, NULL);
   al_unlock_mutex(hapxi_mutex);
   if (hapxi_thread) al_start_thread(hapxi_thread);
   return(hapxi_thread != NULL);
}
Example #2
0
ALLEGRO_MUTEX *
create_mutex_recursive (void)
{
    ALLEGRO_MUTEX *mutex = al_create_mutex_recursive ();
    if (! mutex)
        error (-1, 0, "%s (void): failed to create recursive mutex",
               __func__);
    return mutex;
}
Example #3
0
Input::Input()
{
	descriptor.left = false;
	descriptor.right = false;
	descriptor.up = false;
	descriptor.down = false;
	descriptor.button1 = false;
	descriptor.button2 = false;
	descriptor.button3 = false;
	sets = descriptor;
	descriptor.direction = DIRECTION_SOUTH;
	startDirection = DIRECTION_NONE;
	timeOfNextNotification = tguiCurrentTimeMillis();
	orRelease = -1;
	mutex = al_create_mutex_recursive();
}
Example #4
0
Framework::Framework( int Width, int Height, int Framerate, bool DropFrames )
{
	System = this;

#ifdef WRITE_LOG
	LogFile = fopen( "sjkt.txt", "a" );
	
	fprintf( LogFile, "Framework: Startup: Allegro\n" );
#endif

	if( !al_init() )
	{
		fprintf( LogFile, "Framework: Error: Cannot init Allegro\n" );
		quitProgram = true;
		return;
	}
	
	al_init_font_addon();
	if( !al_install_keyboard() || !al_install_mouse() || !al_install_joystick() || !al_init_primitives_addon() || !al_init_ttf_addon() || !al_init_image_addon() )
	{
		fprintf( LogFile, "Framework: Error: Cannot init Allegro plugin\n" );
		quitProgram = true;
		return;
	}

#ifdef NETWORK_SUPPORT
#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Network\n" );
#endif
	if( enet_initialize() != 0 )
	{
		fprintf( LogFile, "Framework: Error: Cannot init enet\n" );
		quitProgram = true;
		return;
	}
#endif

#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Default Variables\n" );
#endif
	quitProgram = false;
  ProgramStages = new StageStack();
  framesToProcess = 0;
	framesPerSecond = Framerate;
	enableSlowDown = DropFrames;

#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Settings file\n" );
#endif
  Settings = new ConfigFile( "settings.cfg" );


#ifdef DOWNLOAD_SUPPORT
#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Download Manager\n" );
#endif
	DOWNLOADS = new DownloadManager( Settings->GetQuickIntegerValue( "Downloads.Concurrent", 3 ) );
#endif

#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Allegro Events\n" );
#endif
	eventAllegro = al_create_event_queue();
	eventMutex = al_create_mutex_recursive();
	frameTimer = al_create_timer( 1.0 / (double)framesPerSecond );

	srand( (unsigned int)al_get_time() );

#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Display\n" );
#endif
	DISPLAY = new Display( Width, Height );
	DISPLAY->Initialise( Settings->GetQuickIntegerValue( "Video.Width", Width ), Settings->GetQuickIntegerValue( "Video.Height", Height ), Settings->GetQuickBooleanValue( "Video.Fullscreen", false ), (DisplayScaleMode::ScaleMode)Settings->GetQuickIntegerValue( "Video.ScaleMode", DisplayScaleMode::Letterbox ) );
	AUDIO = new Audio();

#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Register event sources\n" );
#endif
	RegisterEventSource( DISPLAY->GetEventSource() );
	RegisterEventSource( al_get_keyboard_event_source() );
	RegisterEventSource( al_get_mouse_event_source() );
	RegisterEventSource( al_get_joystick_event_source() );
	RegisterEventSource( al_get_timer_event_source( frameTimer ) );

#ifdef WRITE_LOG
	fprintf( LogFile, "Framework: Startup: Joystick IDs\n" );
#endif
	GetJoystickIDs();
}