<commit_before>#include <SFML/Graphics.hpp>
#include <Windows.h>
#include <xinput.h>
#include "../System/InputManager.hpp"

SINGLETON_CONSTRUCTOR(InputManager),
	_inputType(kInput_Keyboard),
	_affectorRate(1.0f),
	_leftInput(false),
	_rightInput(false),
	_downInput(false),
	_vibrateAmount(0.0f),
	_vibrateDuration(0.0f)
{
	AddEventListenType(Event_Unload);
}

SINGLETON_DESTRUCTOR(InputManager)
{
	RemoveEventListenType(Event_Unload);

	ClearVibration();
	SetVibratationState();
}

void InputManager::SetUpInput()
{
	//Check for Xbox 360 Connection
	{
		XINPUT_STATE state;
		memset(&state,0, sizeof(XINPUT_STATE));
		DWORD result = XInputGetState(0, &state);
		if(result == ERROR_SUCCESS)
		{
			_inputType = kInput_Xbox;
		}
	}
}

void InputManager::Update(float dt)
{
	_affectorRate = 0.0f;
	_leftInput = false;
	_rightInput = false;
	_downInput = false;

	switch(_inputType)
	{
	case kInput_Keyboard:
		{
			_affectorRate = 1.0f;
			_leftInput = sf::Keyboard::isKeyPressed(sf::Keyboard::Left);
			_rightInput = sf::Keyboard::isKeyPressed(sf::Keyboard::Right);
			_downInput = sf::Keyboard::isKeyPressed(sf::Keyboard::Down);
			break;
		}

	case kInput_Xbox:
		{
			{
				XINPUT_STATE state;
				memset(&state,0, sizeof(XINPUT_STATE));
				DWORD result = XInputGetState(0, &state);

				if(result == ERROR_SUCCESS)
				{
					if( (state.Gamepad.sThumbRX < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE &&
						state.Gamepad.sThumbRX > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) )
					{
						state.Gamepad.sThumbRX = 0;
					}

					if(	(state.Gamepad.sThumbRY < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE &&
						state.Gamepad.sThumbRY > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) )
					{
						state.Gamepad.sThumbRY = 0;
					}

					if(state.Gamepad.sThumbRX > 0)
					{
						_rightInput = true;
					}
					else if(state.Gamepad.sThumbRX < 0)
					{
						_leftInput = true;
					}

					if(state.Gamepad.sThumbRY < 0)
					{
						_downInput = true;
					}

					_affectorRate = std::abs(state.Gamepad.sThumbRX) / 32767.0f;
				}
				else
				{
					_inputType = kInput_Keyboard;
				}
			}

			{
				if(_vibrateDuration > 0.f)
				{
					_vibrateDuration -= dt;
					SetVibratationState();
				}
				else
				{
					ClearVibration();
					SetVibratationState();
				}
			}

			break;
		}

	case kInput_Kinect:
		{
			break;
		}

	case kInput_LEAP:
		{
			break;
		}
	}
}

bool InputManager::HandleEvent( const EventData& theevent )
{
	if( theevent.GetEventType() == Event_Unload )
	{
		ClearVibration();
		return false;
	}

	return false;
}

void InputManager::SetVibratationState( void )
{
	XINPUT_VIBRATION vibration;
	memset(&vibration, 0, sizeof(XINPUT_VIBRATION));

	int leftVib = (int)(_vibrateAmount*65535.0f);
	int rightVib = (int)(_vibrateAmount*65535.0f);

	// Set the Vibration Values
	vibration.wLeftMotorSpeed = leftVib;
	vibration.wRightMotorSpeed = rightVib;
	// Vibrate the controller
	XInputSetState(0, &vibration);
}

void InputManager::ClearVibration( void )
{
	_vibrateAmount = 0.0f;
	_vibrateDuration = 0.0f;
	SetVibratationState();
}

void InputManager::FeedOutput( float amount, float duration )
{
	_vibrateAmount = amount;
	_vibrateDuration = duration;
}<commit_msg>Xbox input error...<commit_after>#include <SFML/Graphics.hpp>
#include <Windows.h>
#include <xinput.h>
#include "../System/InputManager.hpp"

SINGLETON_CONSTRUCTOR(InputManager),
	_inputType(kInput_Keyboard),
	_affectorRate(1.0f),
	_leftInput(false),
	_rightInput(false),
	_downInput(false),
	_vibrateAmount(0.0f),
	_vibrateDuration(0.0f)
{
	AddEventListenType(Event_Unload);
}

SINGLETON_DESTRUCTOR(InputManager)
{
	RemoveEventListenType(Event_Unload);

	if(_inputType == kInput_Xbox)
	{
		ClearVibration();
		SetVibratationState();
	}
}

void InputManager::SetUpInput()
{
	//Check for Xbox 360 Connection
	{
		XINPUT_STATE state;
		memset(&state,0, sizeof(XINPUT_STATE));
		DWORD result = XInputGetState(0, &state);
		if(result == ERROR_SUCCESS)
		{
			_inputType = kInput_Xbox;
		}
	}
}

void InputManager::Update(float dt)
{
	_affectorRate = 0.0f;
	_leftInput = false;
	_rightInput = false;
	_downInput = false;

	/*
	{
		XINPUT_STATE state;
		memset(&state,0, sizeof(XINPUT_STATE));
		DWORD result = XInputGetState(0, &state);
		if(result == ERROR_SUCCESS)
		{
			_inputType = kInput_Xbox;
		}
	}
	*/

	switch(_inputType)
	{
	case kInput_Keyboard:
		{
			_affectorRate = 1.0f;
			_leftInput = sf::Keyboard::isKeyPressed(sf::Keyboard::Left);
			_rightInput = sf::Keyboard::isKeyPressed(sf::Keyboard::Right);
			_downInput = sf::Keyboard::isKeyPressed(sf::Keyboard::Down);
			break;
		}

	case kInput_Xbox:
		{
			{
				XINPUT_STATE state;
				memset(&state,0, sizeof(XINPUT_STATE));
				DWORD result = XInputGetState(0, &state);

				if(result == ERROR_SUCCESS)
				{
					if( (state.Gamepad.sThumbRX < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE &&
						state.Gamepad.sThumbRX > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) )
					{
						state.Gamepad.sThumbRX = 0;
					}

					if(	(state.Gamepad.sThumbRY < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE &&
						state.Gamepad.sThumbRY > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) )
					{
						state.Gamepad.sThumbRY = 0;
					}

					if(state.Gamepad.sThumbRX > 0)
					{
						_rightInput = true;
					}
					else if(state.Gamepad.sThumbRX < 0)
					{
						_leftInput = true;
					}

					if(state.Gamepad.sThumbRY < 0)
					{
						_downInput = true;
					}

					_affectorRate = std::abs(state.Gamepad.sThumbRX) / 32767.0f;
				}
				else
				{
					_inputType = kInput_Keyboard;
				}
			}

			{
				if(_vibrateDuration > 0.f)
				{
					_vibrateDuration -= dt;
					SetVibratationState();
				}
				else
				{
					ClearVibration();
					SetVibratationState();
				}
			}

			break;
		}

	case kInput_Kinect:
		{
			break;
		}

	case kInput_LEAP:
		{
			break;
		}
	}
}

bool InputManager::HandleEvent( const EventData& theevent )
{
	if( theevent.GetEventType() == Event_Unload )
	{
		ClearVibration();
		return false;
	}

	return false;
}

void InputManager::SetVibratationState( void )
{
	if(_inputType == kInput_Xbox)
	{
		XINPUT_VIBRATION vibration;
		memset(&vibration, 0, sizeof(XINPUT_VIBRATION));

		int leftVib = (int)(_vibrateAmount*65535.0f);
		int rightVib = (int)(_vibrateAmount*65535.0f);

		// Set the Vibration Values
		vibration.wLeftMotorSpeed = leftVib;
		vibration.wRightMotorSpeed = rightVib;
		// Vibrate the controller
		XInputSetState(0, &vibration);
	}
}

void InputManager::ClearVibration( void )
{
	_vibrateAmount = 0.0f;
	_vibrateDuration = 0.0f;
	SetVibratationState();
}

void InputManager::FeedOutput( float amount, float duration )
{
	_vibrateAmount = amount;
	_vibrateDuration = duration;
}
{'fraction_non_alphanumeric': 0.12471757794848622, 'fraction_numerical': 0.014460009037505649, 'mean_word_length': 3.6175243393602226, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6255421', 'n_tokens_mistral': 3136, 'n_tokens_neox': 2635, 'n_words': 380}