Ejemplo n.º 1
0
int XinputDevice::UpdateState(InputState &input_state) {
	if (g_Config.iForceInputDevice > 0) return -1;
	if (this->check_delay-- > 0) return -1;
	XINPUT_STATE state;
	ZeroMemory( &state, sizeof(XINPUT_STATE) );

	DWORD dwResult;
	if (this->gamepad_idx >= 0)
		dwResult = XInputGetState( this->gamepad_idx, &state );
	else {
		// use the first gamepad that responds
		for (int i = 0; i < XUSER_MAX_COUNT; i++) {
			dwResult = XInputGetState( i, &state );
			if (dwResult == ERROR_SUCCESS) {
				this->gamepad_idx = i;
				break;
			}
		}
	}
	
	if ( dwResult == ERROR_SUCCESS ) {
		ApplyDiff(state, input_state);
		Stick left = NormalizedDeadzoneFilter(state.Gamepad.sThumbLX, state.Gamepad.sThumbLY);
		Stick right = NormalizedDeadzoneFilter(state.Gamepad.sThumbRX, state.Gamepad.sThumbRY);
		input_state.pad_lstick_x += left.x;
		input_state.pad_lstick_y += left.y;
		input_state.pad_rstick_x += right.x;
		input_state.pad_rstick_y += right.y;

		// Also convert the analog triggers.
		input_state.pad_ltrigger = state.Gamepad.bLeftTrigger / 255.0f;
		input_state.pad_rtrigger = state.Gamepad.bRightTrigger / 255.0f;

		this->prevState = state;
		this->check_delay = 0;

		// If there's an XInput pad, skip following pads. This prevents DInput and XInput
		// from colliding.
		return UPDATESTATE_SKIP_PAD;
	} else {
		// wait check_delay frames before polling the controller again
		this->gamepad_idx = -1;
		this->check_delay = 100;
		return -1;
	}
}
Ejemplo n.º 2
0
	void SyncProxy::Merge (QList<Laretz::Operation>&, const QList<Laretz::Operation>& theirs)
	{
		auto guard = Core::Instance ().GetStager ()->EnterMergeMode ();

		auto storage = Core::Instance ().GetTodoManager ()->GetTodoStorage ();
		for (const auto& op : theirs)
		{
			const auto& items = op.getItems ();
			switch (op.getType ())
			{
			case Laretz::OpType::Fetch:
				for (const auto& item : items)
				{
					const auto pos = storage->FindItem (QString::fromUtf8 (item.getId ().c_str ()));
					if (pos == -1)
					{
						TodoItem_ptr todo (new TodoItem (QString::fromUtf8 (item.getId ().c_str ())));
						todo->ApplyDiff (Util::Sync::ItemToMap (item));
						storage->AddItem (todo);
					}
					else
					{
						auto todo = storage->GetItemAt (pos);
						todo->ApplyDiff (Util::Sync::ItemToMap (item));
						storage->HandleUpdated (todo);
					}
				}
				break;
			case Laretz::OpType::Delete:
				for (const auto& item : items)
					storage->RemoveItem (QString::fromUtf8 (item.getId ().c_str ()));
				break;
			default:
				qWarning () << Q_FUNC_INFO
						<< "unknown operation type"
						<< static_cast<int> (op.getType ());
				break;
			}
		}
	}