void gkXboxInputDevice::UpdateConnectedState(bool isConnected) { if (m_connected != isConnected) { SInputEvent event; event.deviceIndex = (uint8)m_deviceNo; event.deviceId = eDI_XBox; event.state = eIS_Changed; // state has changed, emit event here if (isConnected) { // connect //printf("xinput%d connected\n", m_deviceNo); event.keyId = eKI_SYS_ConnectDevice; gkLogMessage(_T("Xbox Controller [#%d] connected."), m_deviceNo); } else { // disconnect //printf("xinput%d disconnected\n", m_deviceNo); event.keyId = eKI_SYS_DisconnectDevice; gkLogMessage(_T("Xbox Controller [#%d] disconnected."), m_deviceNo); } m_connected = isConnected; GetInputManager().PostInputEvent(event); // Send generalized keyId connect/disconnect // eKI_Xbox_Connect & eKI_Xbox_Disconnect should be deprecated because all devices can be connected/disconnected event.keyId = (isConnected) ? eKI_SYS_ConnectDevice : eKI_SYS_DisconnectDevice; GetInputManager().PostInputEvent(event,true); } }
void gkMouse::PostEvent(SInputSymbol* pSymbol) { // Post Input events. SInputEvent event; pSymbol->AssignTo(event, GetInputManager().GetModifiers()); GetInputManager().PostInputEvent(event); }
bool gkMouse::SetExclusiveMode(bool value) { if (!GetDirectInputDevice()) return false; HRESULT hr; Unacquire(); if (value) { hr = GetDirectInputDevice()->SetCooperativeLevel(GetInputManager().getHwnd(), DISCL_EXCLUSIVE | DISCL_FOREGROUND); } else { hr = GetDirectInputDevice()->SetCooperativeLevel(GetInputManager().getHwnd(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); } if (FAILED(hr)) { gkLogError(_T("Mouse:SetExclusiveMode(%s) failed\n"), value?"true":"false"); return false; } return Acquire(); }
bool ConceptionApp::ShouldRedrawRegardless() { if ( false && // HACK: Since I have a TimeWidget... 0 == m_CurrentProject.m_BackgroundState && glfwGetTime() >= m_CurrentProject.m_ProcessEndedTime + 1 && !GetInputManager().AnyActivePointers() && GetInputManager().EmptyInputEventQueue()) return false; // If idle, don't redraw regardless of input else return true; // If background thread is doing something, we should redraw }
void Keyboard::ProcessKey(uint32 devSpecId, bool pressed) { SKeyState& keyState = dik2ekiMap[devSpecId]; if (keyState.keyId == eKI_Unknown) return; EInputState newState; if (pressed) { newState = eIS_Pressed; keyState.value = 1.0f; } else { newState = eIS_Released; keyState.value = 0.0f; } if (newState == keyState.state) { return; } keyState.state = newState; SInputEvent event; keyState.MakeEvent(event); GetInputManager()->PostInputEvent(event); }
void InputManager::setWindow(Window* window) { this->window = window; if( window == nullptr ) { Keyboard* keyboard = GetInputManager()->getKeyboard(); if(keyboard) keyboard->resetKeys(); } }
void ConceptionApp::Render() { m_CurrentProject.SomethingFromAppRenderTEST(); App::Render(); // TODO, LOWER_PRIORITY: Perhaps generalize TypingModule to a Renderable object (rather than Widget) and standardize back into App, removing need for overloaded Render() { m_TypingModule->Render(GetInputManager()); } }
void gkXboxInputDevice::ProcessAnalogStick(SInputSymbol* pSymbol, SHORT prev, SHORT current, SHORT threshold) { bool send = false; if(threshold>0.0f) { if (prev >= threshold && current < threshold) { // release send = true; pSymbol->PressEvent(false); } else if (prev <= threshold && current > threshold) { // press send = true; pSymbol->PressEvent(true); } } else { if (prev <= threshold && current > threshold) { // release send = true; pSymbol->PressEvent(false); } else if (prev >= threshold && current < threshold) { // press send = true; pSymbol->PressEvent(true); } } if (send) { SInputEvent event; event.deviceIndex = (uint8)m_deviceNo; pSymbol->AssignTo(event); event.deviceId = eDI_XBox; GetInputManager().PostInputEvent(event); } }
bool Application::Run(bool isAsync) { // 프레임 계산에 쓰일 변수들 float fpsTimer = 0.f; int prevTime = 0; int nowTime = 0; int frameCount = 0; MSG msg; ZeroMemory( &msg, sizeof(msg) ); do { if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { if ( msg.message == WM_QUIT ) return true; TranslateMessage( &msg ); DispatchMessage( &msg ); } else { _UpdateFrame( fpsTimer, prevTime, nowTime, frameCount ); if ( GetKeyState(VK_ESCAPE) & 0x8000 ) { //mRenderer->ToggleFullscreen(); break; } //mKeyEventDispatcher->Dispatch( mKeyEventList ); //mMouseEventDispatcher->Dispatch( mMouseEventList ); GetInputManager().GetKey(); mSceneManager->Update( mDeltaTime ); mCountDPCall = 0; mSceneManager->Render(); } } while (isAsync == false); return true; }
// winproc LRESULT CALLBACK Application::_WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch ( message ) { case WM_CREATE: { break; } case WM_DESTROY: { PostQuitMessage(0); break; } case WM_SOCKET: { if (WSAGETSELECTERROR(lParam)) { MessageBox(hWnd, L"WSAGETSELECTERROR", L"Error", MB_OK | MB_ICONERROR); SendMessage(hWnd, WM_DESTROY, NULL, NULL); break; } switch (WSAGETSELECTEVENT(lParam)) { case FD_CONNECT: { NetworkSystem::GetInstance(); break; } case FD_READ: { NetworkSystem::GetInstance()->Read(); break; } case FD_WRITE: { /// 실제로 버퍼에 있는것들 꺼내서 보내기 NetworkSystem::GetInstance()->Send(); } break; case FD_CLOSE: { MessageBox(hWnd, L"Server closed connection", L"Connection closed!", MB_ICONINFORMATION | MB_OK); NetworkSystem::GetInstance()->Disconnect(); SendMessage(hWnd, WM_DESTROY, NULL, NULL); break; } } break; // WM_SOCKET end; } case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint( hWnd, &ps ); EndPaint( hWnd, &ps ); break; } case WM_MOUSEMOVE: { // MouseEvent* pMouseEvent = new MouseEvent(); // pMouseEvent->SetMouseEventType( MouseEventType::MOUSE_MOVE ); // pMouseEvent->SetX( (int)(short)LOWORD(lParam) ); // pMouseEvent->SetY( (int)(short)HIWORD(lParam) ); // // GetInstance()->mMouseEventList.push_front( pMouseEvent ); GetInputManager().SetX((int)(short)LOWORD(lParam)); GetInputManager().SetY((int)(short)HIWORD(lParam)); break; } case WM_LBUTTONDOWN: { // if ( GetInstance()->mMouseEventDispatcher->IsMouseButtonPressed( MOUSE_LBUTTON ) == false ) { // MouseEvent* pMouseEvent = new MouseEvent(); // pMouseEvent->SetMouseEventType( MouseEventType::MOUSE_LBUTTON_DOWN ); // pMouseEvent->SetMouseButton( MOUSE_LBUTTON ); // pMouseEvent->SetX( (int)(short)LOWORD(lParam) ); // pMouseEvent->SetY( (int)(short)HIWORD(lParam) ); // // GetInstance()->mMouseEventDispatcher->SetMouseButtonState( MOUSE_LBUTTON, true ); // // GetInstance()->mMouseEventList.push_front( pMouseEvent ); // } GetInputManager().SetX((int)(short)LOWORD(lParam)); GetInputManager().SetY((int)(short)HIWORD(lParam)); break; } case WM_LBUTTONUP: { // if ( GetInstance()->mMouseEventDispatcher->IsMouseButtonPressed( MOUSE_LBUTTON ) == true ) { // GetInstance()->mMouseEventDispatcher->SetMouseButtonState( MOUSE_LBUTTON, false ); // } GetInputManager().SetX((int)(short)LOWORD(lParam)); GetInputManager().SetY((int)(short)HIWORD(lParam)); break; } case WM_MBUTTONDOWN: { // if ( GetInstance()->mMouseEventDispatcher->IsMouseButtonPressed( MOUSE_MBUTTON ) == false ) { // MouseEvent* pMouseEvent = new MouseEvent(); // pMouseEvent->SetMouseEventType( MouseEventType::MOUSE_MBUTTON_DOWN ); // pMouseEvent->SetMouseButton( MOUSE_MBUTTON ); // // GetInstance()->mMouseEventDispatcher->SetMouseButtonState( MOUSE_MBUTTON, true ); // pMouseEvent->SetX( (int)(short)LOWORD(lParam) ); // pMouseEvent->SetY( (int)(short)HIWORD(lParam) ); // // GetInstance()->mMouseEventList.push_front( pMouseEvent ); // } GetInputManager().SetX((int)(short)LOWORD(lParam)); GetInputManager().SetY((int)(short)HIWORD(lParam)); break; } case WM_MBUTTONUP: { // if ( GetInstance()->mMouseEventDispatcher->IsMouseButtonPressed( MOUSE_MBUTTON ) == true ) { // GetInstance()->mMouseEventDispatcher->SetMouseButtonState( MOUSE_MBUTTON, false ); // } GetInputManager().SetX((int)(short)LOWORD(lParam)); GetInputManager().SetY((int)(short)HIWORD(lParam)); break; } case WM_RBUTTONDOWN: { // if ( GetInstance()->mMouseEventDispatcher->IsMouseButtonPressed( MOUSE_RBUTTON ) == false ) { // MouseEvent* pMouseEvent = new MouseEvent(); // pMouseEvent->SetMouseEventType( MouseEventType::MOUSE_RBUTTON_DOWN ); // pMouseEvent->SetMouseButton( MOUSE_RBUTTON ); // // GetInstance()->mMouseEventDispatcher->SetMouseButtonState( MOUSE_RBUTTON, true ); // pMouseEvent->SetX( (int)(short)LOWORD(lParam) ); // pMouseEvent->SetY( (int)(short)HIWORD(lParam) ); // // GetInstance()->mMouseEventList.push_front( pMouseEvent ); // } GetInputManager().SetX((int)(short)LOWORD(lParam)); GetInputManager().SetY((int)(short)HIWORD(lParam)); break; } case WM_RBUTTONUP: { // if ( GetInstance()->mMouseEventDispatcher->IsMouseButtonPressed( MOUSE_RBUTTON ) == true ) { // GetInstance()->mMouseEventDispatcher->SetMouseButtonState( MOUSE_RBUTTON, false ); // } GetInputManager().SetX((int)(short)LOWORD(lParam)); GetInputManager().SetY((int)(short)HIWORD(lParam)); break; } case WM_MOUSEWHEEL: { // if( (SHORT)HIWORD(wParam) > 0 ) { // MouseEvent* pMouseEvent = new MouseEvent(); // pMouseEvent->SetMouseEventType( MouseEventType::MOUSE_WHEEL_UP ); // GetInstance()->mMouseEventList.push_front( pMouseEvent ); // } // else { // MouseEvent* pMouseEvent = new MouseEvent(); // pMouseEvent->SetMouseEventType( MouseEventType::MOUSE_WHEEL_DOWN ); // GetInstance()->mMouseEventList.push_front( pMouseEvent ); // } GetInputManager().SetX((int)(short)LOWORD(lParam)); GetInputManager().SetY((int)(short)HIWORD(lParam)); break; } case WM_SYSKEYDOWN: case WM_KEYDOWN: { // if ( GetInstance()->mKeyEventDispatcher->IsKeyPressed( wParam ) == false ) { // KeyEvent* pKeyEvent = new KeyEvent(); // pKeyEvent->SetKeyEventType( KeyEventType::KEY_DOWN ); // pKeyEvent->SetKeyCode( wParam ); // // GetInstance()->mKeyEventDispatcher->SetKeyPressed( wParam, true ); // // GetInstance()->mKeyEventList.push_front( pKeyEvent ); // } break; } case WM_SYSKEYUP: case WM_KEYUP: { // if ( GetInstance()->mKeyEventDispatcher->IsKeyPressed( wParam ) == true ) { // GetInstance()->mKeyEventDispatcher->SetKeyPressed( wParam, false ); // } break; } } return(DefWindowProc(hWnd,message,wParam,lParam)); }
void gkXboxInputDevice::Update(bool bFocus) { float now = gEnv->pTimer->GetCurrTime(); // if((m_fVibrationTimer && m_fVibrationTimer < now) || g_pInputCVars->i_forcefeedback == 0 || gEnv->pSystem->IsPaused()) // { // m_fVibrationTimer = 0; // //SetVibration(0, 0, 0.0f); // } // interpret input if (true || bFocus) { XINPUT_STATE state; memset( &state, 0, sizeof(XINPUT_STATE) ); if ( ERROR_SUCCESS != XInputGetState(m_deviceNo, &state) ) { // disconnected. UpdateConnectedState(false); return; } else { // connected. UpdateConnectedState(true); } if (true || state.dwPacketNumber != m_state.dwPacketNumber) { SInputEvent event; SInputSymbol* pSymbol = 0; event.deviceIndex = (uint8)m_deviceNo; const float INV_VALIDRANGE = (1.0f / (INPUT_MAX - m_fDeadZone)); // make the inputs move smoothly out of the deadzone instead of snapping straight to m_fDeadZone float fraction=max(abs(state.Gamepad.sThumbLX) - m_fDeadZone, 0) * INV_VALIDRANGE; float oldVal=state.Gamepad.sThumbLX; state.Gamepad.sThumbLX = fraction * INPUT_MAX * sgn(state.Gamepad.sThumbLX); fraction = max(abs(state.Gamepad.sThumbLY) - m_fDeadZone, 0) * INV_VALIDRANGE; oldVal = state.Gamepad.sThumbLY; state.Gamepad.sThumbLY = fraction * INPUT_MAX * sgn(state.Gamepad.sThumbLY); // make the inputs move smoothly out of the deadzone instead of snapping straight to m_fDeadZone fraction=max(abs(state.Gamepad.sThumbRX) - m_fDeadZone, 0) * INV_VALIDRANGE; oldVal=state.Gamepad.sThumbRX; state.Gamepad.sThumbRX = fraction * INPUT_MAX * sgn(state.Gamepad.sThumbRX); fraction = max(abs(state.Gamepad.sThumbRY) - m_fDeadZone, 0) * INV_VALIDRANGE; oldVal = state.Gamepad.sThumbRY; state.Gamepad.sThumbRY = fraction * INPUT_MAX * sgn(state.Gamepad.sThumbRY); // compare new values against cached value and only send out changes as new input WORD buttonsChange = m_state.Gamepad.wButtons ^ state.Gamepad.wButtons; if (buttonsChange) { for (int i = 0; i < 16; ++i) { uint32 id = (1 << i); if (buttonsChange & id && (pSymbol = DevSpecIdToSymbol(id))) { pSymbol->PressEvent((state.Gamepad.wButtons & id) != 0); pSymbol->AssignTo(event); event.deviceId = eDI_XBox; GetInputManager().PostInputEvent(event); } } } // now we have done the digital buttons ... let's do the analog stuff if (m_state.Gamepad.bLeftTrigger != state.Gamepad.bLeftTrigger) { pSymbol = DevSpecIdToSymbol(_XINPUT_GAMEPAD_LEFT_TRIGGER); pSymbol->ChangeEvent(state.Gamepad.bLeftTrigger / 255.0f); pSymbol->AssignTo(event); event.deviceId = eDI_XBox; GetInputManager().PostInputEvent(event); //--- Check previous and current trigger against threshold for digital press/release event bool bIsPressed=state.Gamepad.bLeftTrigger>XINPUT_GAMEPAD_TRIGGER_THRESHOLD ? true : false; bool bWasPressed=m_state.Gamepad.bLeftTrigger>XINPUT_GAMEPAD_TRIGGER_THRESHOLD ? true : false; if(bIsPressed!=bWasPressed) { pSymbol=DevSpecIdToSymbol(_XINPUT_GAMEPAD_LEFT_TRIGGER_BTN); pSymbol->PressEvent(bIsPressed); pSymbol->AssignTo(event); event.deviceId = eDI_XBox; GetInputManager().PostInputEvent(event); } } if (m_state.Gamepad.bRightTrigger != state.Gamepad.bRightTrigger) { pSymbol = DevSpecIdToSymbol(_XINPUT_GAMEPAD_RIGHT_TRIGGER); pSymbol->ChangeEvent(state.Gamepad.bRightTrigger / 255.0f); pSymbol->AssignTo(event); event.deviceId = eDI_XBox; GetInputManager().PostInputEvent(event); //--- Check previous and current trigger against threshold for digital press/release event bool bIsPressed=state.Gamepad.bRightTrigger>XINPUT_GAMEPAD_TRIGGER_THRESHOLD; bool bWasPressed=m_state.Gamepad.bRightTrigger>XINPUT_GAMEPAD_TRIGGER_THRESHOLD; if(bIsPressed!=bWasPressed) { pSymbol=DevSpecIdToSymbol(_XINPUT_GAMEPAD_RIGHT_TRIGGER_BTN); pSymbol->PressEvent(bIsPressed); pSymbol->AssignTo(event); event.deviceId = eDI_XBox; GetInputManager().PostInputEvent(event); } } if (1) { pSymbol = DevSpecIdToSymbol(_XINPUT_GAMEPAD_LEFT_THUMB_X); if(state.Gamepad.sThumbLX==0.f) pSymbol->ChangeEvent(0.f); else pSymbol->ChangeEvent((state.Gamepad.sThumbLX + 32768) / 32767.5f - 1.0f); pSymbol->AssignTo(event); event.deviceId = eDI_XBox; GetInputManager().PostInputEvent(event); //--- Check previous and current state to generate digital press/release event static SInputSymbol* pSymbolLeft = DevSpecIdToSymbol(_XINPUT_GAMEPAD_LEFT_THUMB_LEFT); ProcessAnalogStick(pSymbolLeft, m_state.Gamepad.sThumbLX, state.Gamepad.sThumbLX, -25000); static SInputSymbol* pSymbolRight = DevSpecIdToSymbol(_XINPUT_GAMEPAD_LEFT_THUMB_RIGHT); ProcessAnalogStick(pSymbolRight, m_state.Gamepad.sThumbLX, state.Gamepad.sThumbLX, 25000); } if (1) { pSymbol = DevSpecIdToSymbol(_XINPUT_GAMEPAD_LEFT_THUMB_Y); if(state.Gamepad.sThumbLY==0.f) pSymbol->ChangeEvent(0.f); else pSymbol->ChangeEvent((state.Gamepad.sThumbLY + 32768.0f) / 32767.5f - 1.0f); pSymbol->AssignTo(event); event.deviceId = eDI_XBox; GetInputManager().PostInputEvent(event); //--- Check previous and current state to generate digital press/release event static SInputSymbol* pSymbolUp = DevSpecIdToSymbol(_XINPUT_GAMEPAD_LEFT_THUMB_UP); ProcessAnalogStick(pSymbolUp, m_state.Gamepad.sThumbLY, state.Gamepad.sThumbLY, 25000); static SInputSymbol* pSymbolDown = DevSpecIdToSymbol(_XINPUT_GAMEPAD_LEFT_THUMB_DOWN); ProcessAnalogStick(pSymbolDown, m_state.Gamepad.sThumbLY, state.Gamepad.sThumbLY, -25000); } if (1) { pSymbol = DevSpecIdToSymbol(_XINPUT_GAMEPAD_RIGHT_THUMB_X); if(state.Gamepad.sThumbRX==0.f) pSymbol->ChangeEvent(0.f); else pSymbol->ChangeEvent((state.Gamepad.sThumbRX + 32768) / 32767.5f - 1.0f); pSymbol->AssignTo(event); event.deviceId = eDI_XBox; GetInputManager().PostInputEvent(event); //--- Check previous and current state to generate digital press/release event static SInputSymbol* pSymbolLeft = DevSpecIdToSymbol(_XINPUT_GAMEPAD_RIGHT_THUMB_LEFT); ProcessAnalogStick(pSymbolLeft, m_state.Gamepad.sThumbRX, state.Gamepad.sThumbRX, -25000); static SInputSymbol* pSymbolRight = DevSpecIdToSymbol(_XINPUT_GAMEPAD_RIGHT_THUMB_RIGHT); ProcessAnalogStick(pSymbolRight, m_state.Gamepad.sThumbRX, state.Gamepad.sThumbRX, 25000); } if (1) { pSymbol = DevSpecIdToSymbol(_XINPUT_GAMEPAD_RIGHT_THUMB_Y); if(state.Gamepad.sThumbRY==0.f) pSymbol->ChangeEvent(0.f); else pSymbol->ChangeEvent((state.Gamepad.sThumbRY + 32768) / 32767.5f - 1.0f); pSymbol->AssignTo(event); event.deviceId = eDI_XBox; GetInputManager().PostInputEvent(event); //--- Check previous and current state to generate digital press/release event static SInputSymbol* pSymbolUp = DevSpecIdToSymbol(_XINPUT_GAMEPAD_RIGHT_THUMB_UP); ProcessAnalogStick(pSymbolUp, m_state.Gamepad.sThumbRY, state.Gamepad.sThumbRY, 25000); static SInputSymbol* pSymbolDown = DevSpecIdToSymbol(_XINPUT_GAMEPAD_RIGHT_THUMB_DOWN); ProcessAnalogStick(pSymbolDown, m_state.Gamepad.sThumbRY, state.Gamepad.sThumbRY, -25000); } // update cache m_state = state; } } }
void CCore::CheckActionsFromInputs() { float delta = 0.0; //logger if(GetInputManager()->GetActionToInput()->DoAction("Logger") != 0.0f) { CLogger *l = LOGGER; const std::vector <SLog> &log = l->GetLogs(); } //console if(GetInputManager()->GetActionToInput()->DoAction("Console") != 0.0f) { //CLogger *l = LOGGER; //l->GetLogs(); } //SaveLogsInFile if(GetInputManager()->GetActionToInput()->DoAction("SaveLogsInFile") != 0.0f) { CLogger *l = LOGGER; l->SaveLogsInFile(); } //ReloadTTFs if(GetInputManager()->GetActionToInput()->DoAction("ReloadTTFs") != 0.0f ) { CFontManager *fm = CORE->GetFontManager(); fm->ReloadTTFs(); } //ReloadLanguageXMLs if(GetInputManager()->GetActionToInput()->DoAction("ReloadLanguageXMLs") != 0.0f ) { CORE->GetLanguageManager()->Reload(); } //ReloadActions if(GetInputManager()->GetActionToInput()->DoAction("ReloadActions") != 0.0f ) { CActionToInput *i = CORE->GetInputManager()->GetActionToInput(); i->Reload(); } if(GetInputManager()->GetActionToInput()->DoAction("ToogleDebugRender") != 0.0f ) { m_bDebugRender = !m_bDebugRender; CORE->GetPhysicsManager()->SetDebugRenderMode(m_bDebugRender); } if(GetInputManager()->GetActionToInput()->DoAction("ReloadEffects") != 0.0f ) { //CEffectManager* ef=m_pCore->GetEffectManager(); //ef->Reload(); //CStaticMeshManager *sm=m_pCore->GetStaticMeshManager(); //sm->Reload(); //CRenderableObjectsManager *ro = m_pCore->GetRenderableObjectsManager(); //ro->Reload(); ////falta parametros de effects.xml //CSceneEffectManager *sem = m_pCore->GetSceneEffectManager(); ////sem->Destroy(); //sem->LoadXML("Data/scene_effects.xml"); } if(GetInputManager()->GetActionToInput()->DoAction("ReloadInvisibleBoxes") != 0.0f ) { CORE->GetPhysicsManager()->ReloadInvisibleBlockingBoxes(); } /* if(GetInputManager()->GetActionToInput()->DoAction("ReloadTriggers") != 0.0f ) { m_pCore->GetTriggerManager()->Reload(); } */ if(GetInputManager()->GetActionToInput()->DoAction("ReloadLights") != 0.0f ) { CORE->GetLigthManager()->Reload(); } }