FWinRTInputInterface::FWinRTInputInterface( const TSharedRef< FGenericApplicationMessageHandler >& InMessageHandler ) : MessageHandler( InMessageHandler ) , ControllerScanTime( 0 ) , InitialButtonRepeatDelay( 0 ) , ButtonRepeatDelay( 0 ) , NextControllerToScan( 0 ) { XInputEnable(true); FMemory::Memzero(WinRTKeyState, WinRTKeyCount); FMemory::Memzero(WinRTKeyLastState, WinRTKeyCount); FMemory::Memzero(WinRTCharState, WinRTKeyCount); FMemory::Memzero(WinRTCharLastState, WinRTKeyCount); for ( int32 ControllerIndex=0; ControllerIndex < MAX_NUM_XINPUT_CONTROLLERS; ++ControllerIndex ) { FControllerState& ControllerState = ControllerStates[ControllerIndex]; FMemory::Memzero( &ControllerState, sizeof(FControllerState) ); ControllerState.ControllerId = ControllerIndex; } ControllerScanTime = 0.5f; InitialButtonRepeatDelay = 0.2f; ButtonRepeatDelay = 0.1f; // In the engine, all controllers map to xbox controllers for consistency X360ToXboxControllerMapping[0] = 0; // A X360ToXboxControllerMapping[1] = 1; // B X360ToXboxControllerMapping[2] = 2; // X X360ToXboxControllerMapping[3] = 3; // Y X360ToXboxControllerMapping[4] = 4; // L1 X360ToXboxControllerMapping[5] = 5; // R1 X360ToXboxControllerMapping[6] = 7; // Back X360ToXboxControllerMapping[7] = 6; // Start X360ToXboxControllerMapping[8] = 8; // Left thumbstick X360ToXboxControllerMapping[9] = 9; // Right thumbstick X360ToXboxControllerMapping[10] = 10; // L2 X360ToXboxControllerMapping[11] = 11; // R2 X360ToXboxControllerMapping[12] = 12; // Dpad up X360ToXboxControllerMapping[13] = 13; // Dpad down X360ToXboxControllerMapping[14] = 14; // Dpad left X360ToXboxControllerMapping[15] = 15; // Dpad right Buttons[0] = EControllerButtons::FaceButtonBottom; Buttons[1] = EControllerButtons::FaceButtonRight; Buttons[2] = EControllerButtons::FaceButtonLeft; Buttons[3] = EControllerButtons::FaceButtonTop; Buttons[4] = EControllerButtons::LeftShoulder; Buttons[5] = EControllerButtons::RightShoulder; Buttons[6] = EControllerButtons::SpecialRight; Buttons[7] = EControllerButtons::SpecialLeft; Buttons[8] = EControllerButtons::LeftThumb; Buttons[9] = EControllerButtons::RightThumb; Buttons[10] = EControllerButtons::LeftTriggerThreshold; Buttons[11] = EControllerButtons::RightTriggerThreshold; Buttons[12] = EControllerButtons::DPadUp; Buttons[13] = EControllerButtons::DPadDown; Buttons[14] = EControllerButtons::DPadLeft; Buttons[15] = EControllerButtons::DPadRight; }
//Inits this. bool AlwynD3DInterfaceImpl::init() { device->logger->debug("AlwynD3DInterfaceImpl::init\n."); adapter = new XFileMeshAdapter(device); viewingFrustum = new AlwynD3DViewingFrustum(device); //Define and initialise an FPS counter, this uses a high performance memory timer, //which uses very little processing power to compute. fpsCounter = new AlwynFPSCounter(); globalDecals = new GlobalDecals(); worldScale = new AlwynD3DWorldScale(5.8f); //Initialise temp matrices. D3DXMatrixIdentity(&tmp); D3DXMatrixIdentity(&tmp2); //Create xinput devices, for keyboard and gamepad. input = new AlwynD3DInput(); XInputEnable(true); input->mouseXY[0] = device->width/2; input->mouseXY[1] = device->height/2; //Initialise and poll input device. device->getInput(input); //Initialises the shader. if (!initialiseShader(device)) return false; //Initialise and fill decals. if (!initDecals(device)) return false; //Initialises the camera/view matrix. if (!initCamera(device)) return false; //Initialises the raster states. //if (!initRaster(device)) //return false; //Init the font system. if (!initFontSystem(device)) return false; //Init lights initLights(); //Framework init; if (!frameworkInit(device)) return false; if (adapter) delete adapter; return true; }
Input::~Input() { XInputEnable(false); di->Release(); keyboard->Release(); mouse->Release(); }
void OnInitial(DEVICEINSTANCE *device) { XInputEnable(true); D3DXMATRIX projection; D3DXMatrixPerspectiveFovLH(&projection, D3DX_PI / 4, 800 / 600.0f, 1.0f, 10000.0f); device->d3dDevice->SetTransform(D3DTS_PROJECTION, &projection); D3DXLoadMeshFromX(L"skybox.x", 0, device->d3dDevice, nullptr, nullptr, nullptr, nullptr, &skybox); D3DXCreateTextureFromFile(device->d3dDevice, L"sky copy.png", &texture); D3DXCreateTextureFromFile(device->d3dDevice, L"terrain_01.jpg", &heightMap); D3DXCreateTextureFromFile(device->d3dDevice, L"terrain_02.jpg", &heightMapTexture); D3DXIMAGE_INFO heightMapInfo = { 0, }; D3DXGetImageInfoFromFile(L"terrain_01.jpg", &heightMapInfo); terrainWidth = heightMapInfo.Width; terrainHeight = heightMapInfo.Height; D3DCOLOR * colors; D3DLOCKED_RECT lockedRect = { 0, }; RECT rect = { 0, 0, terrainWidth, terrainHeight }; terrainVertices = new TerrainVertex[numOfVertices = terrainWidth * terrainHeight]; heightMap->LockRect(0, &lockedRect, &rect, 0); colors = (D3DCOLOR*)lockedRect.pBits; TerrainVertex * tempVertices = terrainVertices; for (int x = 0; x < terrainHeight; x++) { for (int z = 0; z < terrainWidth; z++) { int location = x * terrainWidth + z; *tempVertices = TerrainVertex( (x - terrainWidth / 2) * 5.0f, (colors[location] & 0xff) * 5.0f / 2, (z - terrainWidth / 2) * 5.0f, z / (float)terrainWidth, x / (float)terrainHeight ); tempVertices++; } } heightMap->UnlockRect(0); heightMap->Release(); terrainIndices = new int[numOfIndices = (terrainWidth - 1) * (terrainHeight - 1) * 2 * 3]; struct Polygon { int index[3]; } *tempIndices = (Polygon*)terrainIndices; for (int z = 0; z < terrainHeight - 1; z++) { for (int x = 0; x < terrainWidth - 1; x++) { (*tempIndices).index[0] = z * terrainWidth + x; (*tempIndices).index[1] = z * terrainWidth + (x + 1); (*tempIndices).index[2] = (z + 1) * terrainWidth + x; tempIndices++; (*tempIndices).index[0] = (z + 1) * terrainWidth + x; (*tempIndices).index[1] = z * terrainWidth + (x + 1); (*tempIndices).index[2] = (z + 1) * terrainWidth + (x + 1); tempIndices++; } } }
bool Input::Initialise(HINSTANCE hinstance, HWND hwnd) { HRESULT result; //Enable XInput XInputEnable(true); // Initialise the main direct input interface. result = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL); if (FAILED(result)) { return false; } // Initialise the direct input interface for the keyboard. result = m_directInput->CreateDevice(GUID_SysKeyboard, &m_keyboard, NULL); if (FAILED(result)) { return false; } // Set the data format. In this case since it is a keyboard we can use the predefined data format. result = m_keyboard->SetDataFormat(&c_dfDIKeyboard); if (FAILED(result)) { return false; } // Set the cooperative level of the keyboard to not share with other programs. result = m_keyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE); if (FAILED(result)) { return false; } // Now acquire the keyboard. result = m_keyboard->Acquire(); if (FAILED(result)) { return false; } return true; }
/****************************************************************** Function: RomOpen Purpose: This function is called when a rom is open. (from the emulation thread) input: none output: none *******************************************************************/ EXPORT void CALL RomOpen (void) { DebugWriteA("CALLED: RomOpen\n"); XInputEnable( TRUE ); // enables xinput --tecnicors if( !g_strEmuInfo.fInitialisedPlugin ) { ErrorMessage(IDS_ERR_NOINIT, 0, false); return; } EnterCriticalSection( &g_critical ); // re-init our paks and shortcuts InitiatePaks( true ); // LoadShortcuts( &g_scShortcuts ); WHY are we loading shortcuts again?? Should already be loaded! LeaveCriticalSection( &g_critical ); g_bRunning = true; return; }
void Input::Startup() { RAWINPUTDEVICE Rid[2]; Rid[0].usUsagePage = 0x01; Rid[0].usUsage = 0x02; Rid[0].dwFlags = 0; Rid[0].hwndTarget = 0; Rid[1].usUsagePage = 0x01; Rid[1].usUsage = 0x06; Rid[1].dwFlags = 0; Rid[1].hwndTarget = 0; if (RegisterRawInputDevices(Rid, 2, sizeof(Rid[0])) == FALSE) { // raw input registration failed. Call GetLastError for the cause of the error assert(0); } XInputEnable(true); }
Input::Input(HWND wndw,int numControllers) { window = wndw; ZeroMemory(keyState,256); ZeroMemory(&mouseState,sizeof(mouseState)); ZeroMemory(&state,sizeof(XINPUT_STATE)*4); DirectInput8Create(GetModuleHandle(NULL),DIRECTINPUT_VERSION,IID_IDirectInput8,(void**)&di,NULL); di->CreateDevice(GUID_SysKeyboard,&keyboard,NULL); keyboard->SetDataFormat(&c_dfDIKeyboard); keyboard->SetCooperativeLevel(window,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); keyboard->Acquire(); di->CreateDevice(GUID_SysMouse,&mouse,NULL); mouse->SetDataFormat(&c_dfDIMouse); mouse->SetCooperativeLevel(window,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); mouse->Acquire(); XInputEnable(true); this->numControllers = numControllers; }
//----------------------------------------------------------------------------- // Window message handler //----------------------------------------------------------------------------- LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { case WM_ACTIVATEAPP: { #if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) || defined(USE_DIRECTX_SDK) // // XInputEnable is implemented by XInput 1.3 and 1.4, but not 9.1.0 // if( wParam == TRUE ) { // App is now active, so re-enable XInput XInputEnable( TRUE ); } else { // App is now inactive, so disable XInput to prevent // user input from effecting application and to // disable rumble. XInputEnable( FALSE ); } #endif break; } case WM_PAINT: { // Paint some simple explanation text PAINTSTRUCT ps; HDC hDC = BeginPaint( hWnd, &ps ); SetBkColor( hDC, 0xFF0000 ); SetTextColor( hDC, 0xFFFFFF ); RECT rect; GetClientRect( hWnd, &rect ); rect.top = 20; rect.left = 20; DrawText( hDC, L"Use the controller's left/right trigger to adjust the speed of the left/right rumble motor.\n" L"Press any controller button to lock or unlock at the current rumble speed.\n", -1, &rect, 0 ); for( DWORD i = 0; i < MAX_CONTROLLERS; i++ ) { rect.top = i * 80 + 90; rect.left = 20; DrawText( hDC, g_szMessage[i], -1, &rect, 0 ); } EndPaint( hWnd, &ps ); return 0; } case WM_DESTROY: { PostQuitMessage( 0 ); break; } } return DefWindowProc( hWnd, msg, wParam, lParam ); }
GraphicsManager::GraphicsManager(): System(GRAPHICS) { pApplicationWindow = new Window(1024, 768); HRESULT hr = InitDevice(pApplicationWindow->getHwnd(), &pDevice, &pContext, &pSwapChain); if (FAILED(hr)) { return; } // TODO Remove this test code // Create vertex buffer simpleVertex vertices[] = { { XMFLOAT3( -1.0f, 1.0f, -1.0f ), XMFLOAT3( 0.0f, 1.0f, 0.0f ) }, { XMFLOAT3( 1.0f, 1.0f, -1.0f ), XMFLOAT3( 0.0f, 1.0f, 0.0f ) }, { XMFLOAT3( 1.0f, 1.0f, 1.0f ), XMFLOAT3( 0.0f, 1.0f, 0.0f ) }, { XMFLOAT3( -1.0f, 1.0f, 1.0f ), XMFLOAT3( 0.0f, 1.0f, 0.0f ) }, { XMFLOAT3( -1.0f, -1.0f, -1.0f ), XMFLOAT3( 0.0f, -1.0f, 0.0f ) }, { XMFLOAT3( 1.0f, -1.0f, -1.0f ), XMFLOAT3( 0.0f, -1.0f, 0.0f ) }, { XMFLOAT3( 1.0f, -1.0f, 1.0f ), XMFLOAT3( 0.0f, -1.0f, 0.0f ) }, { XMFLOAT3( -1.0f, -1.0f, 1.0f ), XMFLOAT3( 0.0f, -1.0f, 0.0f ) }, { XMFLOAT3( -1.0f, -1.0f, 1.0f ), XMFLOAT3( -1.0f, 0.0f, 0.0f ) }, { XMFLOAT3( -1.0f, -1.0f, -1.0f ), XMFLOAT3( -1.0f, 0.0f, 0.0f ) }, { XMFLOAT3( -1.0f, 1.0f, -1.0f ), XMFLOAT3( -1.0f, 0.0f, 0.0f ) }, { XMFLOAT3( -1.0f, 1.0f, 1.0f ), XMFLOAT3( -1.0f, 0.0f, 0.0f ) }, { XMFLOAT3( 1.0f, -1.0f, 1.0f ), XMFLOAT3( 1.0f, 0.0f, 0.0f ) }, { XMFLOAT3( 1.0f, -1.0f, -1.0f ), XMFLOAT3( 1.0f, 0.0f, 0.0f ) }, { XMFLOAT3( 1.0f, 1.0f, -1.0f ), XMFLOAT3( 1.0f, 0.0f, 0.0f ) }, { XMFLOAT3( 1.0f, 1.0f, 1.0f ), XMFLOAT3( 1.0f, 0.0f, 0.0f ) }, { XMFLOAT3( -1.0f, -1.0f, -1.0f ), XMFLOAT3( 0.0f, 0.0f, -1.0f ) }, { XMFLOAT3( 1.0f, -1.0f, -1.0f ), XMFLOAT3( 0.0f, 0.0f, -1.0f ) }, { XMFLOAT3( 1.0f, 1.0f, -1.0f ), XMFLOAT3( 0.0f, 0.0f, -1.0f ) }, { XMFLOAT3( -1.0f, 1.0f, -1.0f ), XMFLOAT3( 0.0f, 0.0f, -1.0f ) }, { XMFLOAT3( -1.0f, -1.0f, 1.0f ), XMFLOAT3( 0.0f, 0.0f, 1.0f ) }, { XMFLOAT3( 1.0f, -1.0f, 1.0f ), XMFLOAT3( 0.0f, 0.0f, 1.0f ) }, { XMFLOAT3( 1.0f, 1.0f, 1.0f ), XMFLOAT3( 0.0f, 0.0f, 1.0f ) }, { XMFLOAT3( -1.0f, 1.0f, 1.0f ), XMFLOAT3( 0.0f, 0.0f, 1.0f ) }, }; // Create index buffer WORD indices[] = { 3,1,0, 2,1,3, 6,4,5, 7,4,6, 11,9,8, 10,9,11, 14,12,13, 15,12,14, 19,17,16, 18,17,19, 22,20,21, 23,20,22 }; initializeFbxSdk(); pTestMesh = new Mesh(); pTestMesh->init(pDevice, vertices, 24, indices, 36); std::cout << pTestMesh->dumpData(); pCurrentRenderer = new ForwardRenderer(); pCurrentRenderer->init(pApplicationWindow->getHwnd(), pDevice, pContext, pSwapChain ); pTestShader = new Shader("testShader.fx", pDevice, pContext); XInputEnable(true); }