Пример #1
0
/**	Flush all the device input event queues */
void InputDeviceDB::FlushAll(void)
{
	IInputDevice *temp;

	for(temp=m_mouse;	temp!=NULL;temp=temp->prev)	temp->FlushEventQueue();
	for(temp=m_keyboard;temp!=NULL;temp=temp->prev)	temp->FlushEventQueue();
	for(temp=m_joystick;temp!=NULL;temp=temp->prev)	temp->FlushEventQueue();
}
Пример #2
0
//-----------------------------------------------------------------------------
//! @brief   TODO enter a description
//! @remark
//-----------------------------------------------------------------------------
void InputSystem::initialise( const std::string& inputMapFileName, HWND hwnd )
{
    tinyxml2::XMLDocument actionsDoc;
    std::string availableActionsFileName = extractPathFromFileName(inputMapFileName) + "AvailableActions.xml";
    if (actionsDoc.LoadFile(availableActionsFileName.c_str()) != tinyxml2::XML_NO_ERROR)
    {
        MSG_TRACE_CHANNEL("Input system Error", "Failed to load the input mapping file %s", availableActionsFileName.c_str());
    }

    const tinyxml2::XMLElement* element1 = actionsDoc.FirstChildElement();
    element1 = element1->FirstChildElement();//Skip the <xml> node

    for (; element1; element1 = element1->NextSiblingElement())
    {
        const tinyxml2::XMLAttribute* actionNameAttribute = element1->FindAttribute("name");
        const tinyxml2::XMLAttribute* actionLngNameAttribute = element1->FindAttribute("lng");
        if (actionLngNameAttribute != nullptr)
        {
            MSG_TRACE_CHANNEL("Input SYSTEM", "adding actions for: %s with hash %u", actionNameAttribute->Value(), hashString(actionNameAttribute->Value()));
            m_availableActions.emplace_back(InputActions::ActionType(actionNameAttribute->Value(), actionLngNameAttribute != nullptr ? actionLngNameAttribute->Value() : ""));
#ifdef DEBUG
			m_actionNames.insert(std::make_pair(m_availableActions[m_availableActions.size() - 1],actionNameAttribute->Value()));
#endif
        }
    }

    tinyxml2::XMLDocument doc;
    if (doc.LoadFile(inputMapFileName.c_str()) != tinyxml2::XML_NO_ERROR)
    {
        MSG_TRACE_CHANNEL("Input system Error", "Failed to load the input mapping file %s", inputMapFileName.c_str());
    }

    const tinyxml2::XMLElement* element = doc.FirstChildElement();
    element = element->FirstChildElement();//Skip the <xml> node

    for (; element; element = element->NextSiblingElement())
    {
        IInputDevice* controller = createController(stringToControllerType(element->Name()));
        MSG_TRACE_CHANNEL("INPUT SYSTEM", "controller name: %s", element->Name());
        const tinyxml2::XMLAttribute* attribute = element->FindAttribute("input_map");
        if (controller != nullptr && attribute != nullptr )
        {
            tinyxml2::XMLDocument inputDoc;
            std::string buttonMapFileName = std::string(extractPathFromFileName(inputMapFileName) + attribute->Value());
            if (inputDoc.LoadFile(buttonMapFileName.c_str()) != tinyxml2::XML_NO_ERROR)
            {
                MSG_TRACE_CHANNEL("Input system Error", "Failed to load the input mapping file %s", buttonMapFileName.c_str());
                return;
            }

            tinyxml2::XMLElement* inputElement = inputDoc.FirstChildElement();
            inputElement = inputElement->FirstChildElement();//Skip the <xml> node
            controller->deserialise(inputElement, *this);
            controller->initialise(hwnd);
        }
    }
}
Пример #3
0
/**	Retrieves a device pointer
 *
 *	@param type			The type of device to retrieve
 *	@param DeviceID	The id of the device in the database
 *
 *	@returns	An IInputDevice object or NULL, if the object was not found
 */
IInputDevice * InputDeviceDB::GetDevicePtr(IInputDevice::DeviceType type,unsigned int DeviceID)
{
	IInputDevice *temp;

	if(type == IInputDevice::MOUSE)		for(temp=m_mouse;	temp!=NULL;temp=temp->prev)	if(temp->GetDeviceID() == DeviceID) return temp;
	if(type == IInputDevice::KEYBOARD)	for(temp=m_keyboard;temp!=NULL;temp=temp->prev)	if(temp->GetDeviceID() == DeviceID) return temp;
	if(type == IInputDevice::JOYSTICK)	for(temp=m_joystick;temp!=NULL;temp=temp->prev)	if(temp->GetDeviceID() == DeviceID) return temp;

	return NULL;
}
IInputDevice* CBaseInput::GetDevice(uint16 id, EInputDeviceType deviceType)
{
	for(TInputDevices::const_iterator it = m_inputDevices.begin(); it != m_inputDevices.end(); ++it)
	{
		IInputDevice *pDevice = *it;

		if(id == pDevice->GetDeviceIndex() && pDevice->GetDeviceType() == deviceType)
			return pDevice;
	}

	return NULL;
}
Пример #5
0
/**	Updates all the devices in the database
 *
 *	@returns boolean true or false, but this method ignores any failure and only returns true at this time
 *
 *	Operation:
 *		-#	calls each devices IInputDevice::GetActive() method to find whether the device is active or not
 *		-#	If the device is active, call IInputDevice::Update() method to update the device
 *
 *	Do nothing if the device fails to update properly
 */
bool InputDeviceDB::Update(void)
{
	IInputDevice *temp;

	//	For now, do nothing when a device fails to update 
	//	(havent figured out what is best to do in this situation, just carry on, or do some interrogation)
	for(temp=m_mouse;	temp!=NULL;temp=temp->prev)	if(temp->GetActive() == true)	if(temp->Update() == false){}
	for(temp=m_keyboard;temp!=NULL;temp=temp->prev)	if(temp->GetActive() == true)	if(temp->Update() == false){}
	for(temp=m_joystick;temp!=NULL;temp=temp->prev)	if(temp->GetActive() == true)	if(temp->Update() == false){}

	return true;
}
Пример #6
0
//-----------------------------------------------------------------------------
//! @brief   TODO enter a description
//! @remark
//-----------------------------------------------------------------------------
void InputSystem::update( float elapsedTime, double time )
{
    for (ControllersAndStateIt it = m_controllers.begin(); it != m_controllers.end(); ++it)
    {
        IInputDevice* controller = (*it).first;
        (*it).second = controller->update(m_rawKeyBoardInput, m_rawMouseInput, m_rawHidInput);
    }

	m_rawHidInput.clear();
	m_rawMouseInput.clear();
	m_rawKeyBoardInput.clear();

    elapsedTime = 0.0f;
    time = 0.0;
}
Пример #7
0
char CBaseInput::GetInputCharAscii(const SInputEvent& event)
{
	for (TInputDevices::iterator i = m_inputDevices.begin(); i != m_inputDevices.end(); ++i)
	{
		IInputDevice* pInputDevice = (*i);
		CRY_ASSERT(pInputDevice != NULL);
		if (event.deviceType == eIDT_Unknown || pInputDevice->GetDeviceType() == event.deviceType)
		{
			char inputChar = pInputDevice->GetInputCharAscii(event);
			if (inputChar)
			{
				return inputChar;
			}
		}
	}

	return '\0';
}
Пример #8
0
//-----------------------------------------------------------------------------
//! @brief   TODO enter a description
//! @remark
//-----------------------------------------------------------------------------
IInputDevice* InputSystem::createController(const ControllerType type)
{
    IInputDevice* controller = nullptr;
    if (type == Gamepad)
    {
        controller = new XInputDevice(0);
    }
    else if (type == Keyboard)
    {
        controller = new KeyboardInputDevice();
    }
    else if (type == Mouse)
    {
        controller = new MouseController();
    }

    if (nullptr != controller)
    {
        controller->enableController();
        m_controllers.insert(ControllerAndStatePair(controller, controller->getState()));
    }

    return controller;
}
Пример #9
0
SInputSymbol* CBaseInput::LookupSymbol( EInputDeviceType deviceType, int deviceIndex, EKeyId keyId )
{
	for (TInputDevices::iterator i = m_inputDevices.begin(); i != m_inputDevices.end(); ++i)
	{
		IInputDevice *pDevice = *i;
		if (pDevice->GetDeviceType() == deviceType && pDevice->GetDeviceIndex() == deviceIndex)
		{
			return pDevice->LookupSymbol(keyId);
		}
	}

	// if no symbol found try finding it in any device
	for (TInputDevices::iterator i = m_inputDevices.begin(); i != m_inputDevices.end(); ++i)
	{
		IInputDevice *pDevice = *i;
		SInputSymbol *pSym = pDevice->LookupSymbol(keyId);
		if (pSym)
			return pSym;
	}

	return NULL;
}
Пример #10
0
//
// ISDL12InputSubsystem::resumeJoystick
//
void ISDL12InputSubsystem::resumeJoystick()
{
	IInputDevice* device = getJoystickInputDevice();
	if (device)
		device->resume();
}
Пример #11
0
//
// ISDL12InputSubsystem::pauseJoystick
//
void ISDL12InputSubsystem::pauseJoystick()
{
	IInputDevice* device = getJoystickInputDevice();
	if (device)
		device->pause();
}
Пример #12
0
//
// ISDL12InputSubsystem::resumeMouse
//
void ISDL12InputSubsystem::resumeMouse()
{
	IInputDevice* device = getMouseInputDevice();
	if (device)
		device->resume();
}
Пример #13
0
//
// ISDL12InputSubsystem::pauseMouse
//
void ISDL12InputSubsystem::pauseMouse()
{
	IInputDevice* device = getMouseInputDevice();
	if (device)
		device->pause();
}
Пример #14
0
//
// ISDL12InputSubsystem::resumeKeyboard
//
void ISDL12InputSubsystem::resumeKeyboard()
{
	IInputDevice* device = getKeyboardInputDevice();
	if (device)
		device->resume();
}
Пример #15
0
//
// ISDL12InputSubsystem::pauseKeyboard
//
void ISDL12InputSubsystem::pauseKeyboard()
{
	IInputDevice* device = getKeyboardInputDevice();
	if (device)
		device->pause();
}