2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2001-11-03 10:52:42 +00:00
|
|
|
#include "RageInput.h"
|
2002-05-01 19:14:55 +00:00
|
|
|
#include "RageLog.h"
|
2003-04-12 02:21:50 +00:00
|
|
|
#include "RageException.h"
|
2003-02-16 02:25:22 +00:00
|
|
|
#include "arch/InputHandler/InputHandler.h"
|
2005-03-15 00:30:26 +00:00
|
|
|
#include "arch/arch.h"
|
2005-12-31 02:20:03 +00:00
|
|
|
#include "arch/arch_default.h"
|
2005-08-17 05:56:59 +00:00
|
|
|
#include "Foreach.h"
|
2005-12-31 02:20:03 +00:00
|
|
|
#include "Preference.h"
|
2005-03-15 00:30:26 +00:00
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
RageInput* INPUTMAN = NULL; // globally accessable input device
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2006-01-22 01:00:06 +00:00
|
|
|
static Preference<RString> g_sInputDrivers( "InputDrivers", "" ); // "" == DEFAULT_INPUT_DRIVER_LIST
|
2005-12-31 02:20:03 +00:00
|
|
|
|
|
|
|
|
RageInput::RageInput()
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
2002-07-31 19:40:40 +00:00
|
|
|
LOG->Trace( "RageInput::RageInput()" );
|
2002-05-19 01:59:48 +00:00
|
|
|
|
2005-12-31 02:20:03 +00:00
|
|
|
m_sDriverList = g_sInputDrivers;
|
|
|
|
|
if( m_sDriverList.empty() )
|
|
|
|
|
m_sDriverList = DEFAULT_INPUT_DRIVER_LIST;
|
2003-04-12 02:21:50 +00:00
|
|
|
|
2005-12-18 21:24:33 +00:00
|
|
|
LoadDrivers();
|
2001-11-03 10:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
2002-11-29 20:37:12 +00:00
|
|
|
RageInput::~RageInput()
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
2003-02-16 02:25:22 +00:00
|
|
|
/* Delete optional devices. */
|
2005-05-14 09:26:05 +00:00
|
|
|
for( unsigned i = 0; i < m_pDevices.size(); ++i )
|
|
|
|
|
delete m_pDevices[i];
|
2002-11-29 20:37:12 +00:00
|
|
|
}
|
2002-08-20 23:12:52 +00:00
|
|
|
|
2005-12-18 21:24:33 +00:00
|
|
|
void RageInput::LoadDrivers()
|
|
|
|
|
{
|
|
|
|
|
for( unsigned i = 0; i < m_pDevices.size(); ++i )
|
|
|
|
|
delete m_pDevices[i];
|
|
|
|
|
m_pDevices.clear();
|
|
|
|
|
|
|
|
|
|
/* Init optional devices. */
|
|
|
|
|
MakeInputHandlers( m_sDriverList, m_pDevices );
|
|
|
|
|
|
|
|
|
|
/* If no input devices are loaded, the user won't be able to input anything. */
|
|
|
|
|
if( m_pDevices.size() == 0 )
|
|
|
|
|
LOG->Warn( "No input devices were loaded." );
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-18 22:53:47 +00:00
|
|
|
void RageInput::Update()
|
2002-11-29 20:37:12 +00:00
|
|
|
{
|
2003-02-16 02:25:22 +00:00
|
|
|
/* Update optional devices. */
|
2005-05-14 09:26:05 +00:00
|
|
|
for( unsigned i = 0; i < m_pDevices.size(); ++i )
|
2005-12-18 22:51:12 +00:00
|
|
|
m_pDevices[i]->Update();
|
2003-02-16 01:35:48 +00:00
|
|
|
}
|
2002-08-20 23:12:52 +00:00
|
|
|
|
2005-12-18 03:08:12 +00:00
|
|
|
bool RageInput::DevicesChanged()
|
|
|
|
|
{
|
|
|
|
|
/* Update optional devices. */
|
|
|
|
|
for( unsigned i = 0; i < m_pDevices.size(); ++i )
|
|
|
|
|
{
|
|
|
|
|
if( m_pDevices[i]->DevicesChanged() )
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-22 01:00:06 +00:00
|
|
|
void RageInput::GetDevicesAndDescriptions( vector<InputDevice>& vDevicesOut, vector<RString>& vDescriptionsOut )
|
2003-05-28 02:35:05 +00:00
|
|
|
{
|
2005-05-14 09:26:05 +00:00
|
|
|
for( unsigned i = 0; i < m_pDevices.size(); ++i )
|
|
|
|
|
m_pDevices[i]->GetDevicesAndDescriptions( vDevicesOut, vDescriptionsOut );
|
2003-05-28 02:35:05 +00:00
|
|
|
}
|
2003-06-18 05:43:12 +00:00
|
|
|
|
|
|
|
|
void RageInput::WindowReset()
|
|
|
|
|
{
|
2005-05-14 09:26:05 +00:00
|
|
|
for( unsigned i = 0; i < m_pDevices.size(); ++i )
|
|
|
|
|
m_pDevices[i]->WindowReset();
|
2003-06-18 05:43:12 +00:00
|
|
|
}
|
2004-05-06 00:42:06 +00:00
|
|
|
|
2005-05-14 09:23:30 +00:00
|
|
|
void RageInput::AddHandler( InputHandler *pHandler )
|
|
|
|
|
{
|
|
|
|
|
ASSERT( pHandler != NULL );
|
2005-05-14 09:26:05 +00:00
|
|
|
m_pDevices.push_back( pHandler );
|
2005-05-14 09:23:30 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-22 01:00:06 +00:00
|
|
|
RString RageInput::GetDeviceSpecificInputString( const DeviceInput &di )
|
2005-08-17 05:56:59 +00:00
|
|
|
{
|
|
|
|
|
FOREACH( InputHandler*, m_pDevices, i )
|
|
|
|
|
{
|
|
|
|
|
vector<InputDevice> vDevices;
|
2006-01-22 01:00:06 +00:00
|
|
|
vector<RString> vDescriptions;
|
2005-08-17 05:56:59 +00:00
|
|
|
(*i)->GetDevicesAndDescriptions( vDevices, vDescriptions );
|
|
|
|
|
|
|
|
|
|
bool bMatch = find(vDevices.begin(), vDevices.end(), di.device) != vDevices.end();
|
|
|
|
|
if( bMatch )
|
|
|
|
|
return (*i)->GetDeviceSpecificInputString(di);
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-09 01:48:20 +00:00
|
|
|
return di.ToString();
|
2005-08-17 05:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
2005-08-20 22:49:25 +00:00
|
|
|
InputDeviceState RageInput::GetInputDeviceState( InputDevice id )
|
|
|
|
|
{
|
|
|
|
|
FOREACH( InputHandler*, m_pDevices, i )
|
|
|
|
|
{
|
|
|
|
|
vector<InputDevice> vDevices;
|
2006-01-22 01:00:06 +00:00
|
|
|
vector<RString> vDescriptions;
|
2005-08-20 22:49:25 +00:00
|
|
|
(*i)->GetDevicesAndDescriptions( vDevices, vDescriptions );
|
|
|
|
|
|
|
|
|
|
bool bMatch = find(vDevices.begin(), vDevices.end(), id) != vDevices.end();
|
|
|
|
|
if( bMatch )
|
|
|
|
|
return (*i)->GetInputDeviceState(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return InputDeviceState_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-04 01:56:03 +00:00
|
|
|
|
|
|
|
|
// lua start
|
|
|
|
|
#include "LuaBinding.h"
|
|
|
|
|
|
2005-06-20 05:02:03 +00:00
|
|
|
class LunaRageInput: public Luna<RageInput>
|
2005-06-04 01:56:03 +00:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
LunaRageInput() { LUA->Register( Register ); }
|
|
|
|
|
|
|
|
|
|
static int GetDescriptions( T* p, lua_State *L )
|
|
|
|
|
{
|
|
|
|
|
vector<InputDevice> vDevices;
|
2006-01-22 01:00:06 +00:00
|
|
|
vector<RString> vsDescriptions;
|
2005-06-04 01:56:03 +00:00
|
|
|
p->GetDevicesAndDescriptions( vDevices, vsDescriptions );
|
|
|
|
|
LuaHelpers::CreateTableFromArray( vsDescriptions, L );
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Register(lua_State *L)
|
|
|
|
|
{
|
2005-09-10 02:47:04 +00:00
|
|
|
ADD_METHOD( GetDescriptions );
|
|
|
|
|
|
2005-06-04 01:56:03 +00:00
|
|
|
Luna<T>::Register( L );
|
|
|
|
|
|
|
|
|
|
// Add global singleton if constructed already. If it's not constructed yet,
|
|
|
|
|
// then we'll register it later when we reinit Lua just before
|
|
|
|
|
// initializing the display.
|
|
|
|
|
if( INPUTMAN )
|
|
|
|
|
{
|
|
|
|
|
lua_pushstring(L, "INPUTMAN");
|
2005-06-15 02:27:16 +00:00
|
|
|
INPUTMAN->PushSelf( L );
|
2005-06-04 01:56:03 +00:00
|
|
|
lua_settable(L, LUA_GLOBALSINDEX);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LUA_REGISTER_CLASS( RageInput )
|
|
|
|
|
// lua end
|
|
|
|
|
|
|
|
|
|
|
2004-05-06 00:42:06 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2001-2004 Chris Danford, Glenn Maynard
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
|
|
|
|
* whom the Software is furnished to do so, provided that the above
|
|
|
|
|
* copyright notice(s) and this permission notice appear in all copies of
|
|
|
|
|
* the Software and that both the above copyright notice(s) and this
|
|
|
|
|
* permission notice appear in supporting documentation.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
|
|
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
|
|
|
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|