void Player::LimitSpeed() { auto len = _velocity.length(); if (len > 2) { _velocity.normalize(); _velocity *= 2; } if (NothingPressed() && len < 0.1) { _velocity = Vec3(0, 0, 0); } }
//Callback function for the dialog where the user can change hotkeys. BOOL CALLBACK ChangeInputDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { static HANDLE hThread = NULL; static DWORD dwThreadId = 0; static struct INPUTDLGTHREADARGS threadargs; static int key = 0; switch (uMsg) { case WM_INITDIALOG: { // Start the message thread. threadargs.hThreadExit = CreateEvent(NULL, TRUE, FALSE, NULL); threadargs.hwndDlg = hwndDlg; hThread = CreateThread(NULL, 0, NewInputDialogThread, (LPVOID)&threadargs, 0, &dwThreadId); key = 0; memset(keyonce, 0, sizeof(keyonce)); KeyboardSetBackgroundAccess(true); SetFocus(GetDlgItem(hwndDlg, LBL_KEY_COMBO)); CenterWindowOnScreen(hwndDlg); } return FALSE; case WM_COMMAND: switch(LOWORD(wParam)) // CaH4e3: BN_CLICKED redundant define removed since it always 0, Esc mapping used to be handled as well (I need it too :)) { case BTN_OK: // Send quit message. PostMessage(hwndDlg, WM_USER + 99, 0, 0); break; case BTN_CLEAR: key = -1; // Send quit message. PostMessage(hwndDlg, WM_USER + 99, 0, 0); break; default: break; } break; case WM_USER: { // Our thread sent us a timer signal. int newkey; int meta = GetKeyMeta(key); KeyboardUpdateState(); if((newkey = GetKeyPressed()) != 0) { key = newkey | meta; ClearExtraMeta(&key); SetDlgItemText(hwndDlg, LBL_KEY_COMBO, GetKeyComboName(key)); } else if(NothingPressed() && key) { PostMessage(hwndDlg, WM_USER + 99, 0, 0); // Send quit message. } } break; case WM_CLOSE: // exit without changing the key mapping key = 0; case WM_USER + 99: // Done with keyboard. KeyboardSetBackgroundAccess(false); // Kill the thread. SetEvent(threadargs.hThreadExit); WaitForSingleObject(hThread, INFINITE); CloseHandle(hThread); CloseHandle(threadargs.hThreadExit); // End the dialog. EndDialog(hwndDlg, key); return TRUE; default: break; } return FALSE; }