📄 control.c
字号:
CONTROL_NumMouseButtons, CONTROL_MouseButtonState, CONTROL_MouseButtonClickedTime, CONTROL_MouseButtonClickedState, CONTROL_MouseButtonClicked, CONTROL_MouseButtonClickedCount ); } if (CONTROL_JoystickEnabled) { int32 buttons = joyb; if (joynumhats > 0 && joyhat[0] != -1) { static int32 hatstate[] = { 1, 1|2, 2, 2|4, 4, 4|8, 8, 8|1 }; int32_t val; // thanks SDL for this much more sensible method val = ((joyhat[0] + 4500 / 2) % 36000) / 4500; if (val < 8) buttons |= hatstate[val] << min(MAXJOYBUTTONS,joynumbuttons); } DoGetDeviceButtons( buttons, t, CONTROL_NumJoyButtons, CONTROL_JoyButtonState, CONTROL_JoyButtonClickedTime, CONTROL_JoyButtonClickedState, CONTROL_JoyButtonClicked, CONTROL_JoyButtonClickedCount ); }}void CONTROL_DigitizeAxis(int32 axis, controldevice device){ controlaxistype *set, *lastset; switch (device) { case controldevice_mouse: set = CONTROL_MouseAxes; lastset = CONTROL_LastMouseAxes; break; case controldevice_joystick: set = CONTROL_JoyAxes; lastset = CONTROL_LastJoyAxes; break; default: return; } if (set[axis].analog > 0) { if (set[axis].analog > THRESHOLD || (set[axis].analog > MINTHRESHOLD && lastset[axis].digital == 1)) set[axis].digital = 1; } else { if (set[axis].analog < -THRESHOLD || (set[axis].analog < -MINTHRESHOLD && lastset[axis].digital == -1)) set[axis].digital = -1; }}void CONTROL_ScaleAxis(int32 axis, controldevice device){ controlaxistype *set; int32 *scale; switch (device) { case controldevice_mouse: set = CONTROL_MouseAxes; scale = CONTROL_MouseAxesScale; break; case controldevice_joystick: set = CONTROL_JoyAxes; scale = CONTROL_JoyAxesScale; break; default: return; } set[axis].analog = mulscale16(set[axis].analog, scale[axis]);}void CONTROL_ApplyAxis(int32 axis, ControlInfo *info, controldevice device){ controlaxistype *set; controlaxismaptype *map; switch (device) { case controldevice_mouse: set = CONTROL_MouseAxes; map = CONTROL_MouseAxesMap; break; case controldevice_joystick: set = CONTROL_JoyAxes; map = CONTROL_JoyAxesMap; break; default: return; } switch (map[axis].analogmap) { case analog_turning: info->dyaw += set[axis].analog; break; case analog_strafing: info->dx += set[axis].analog; break; case analog_lookingupanddown: info->dpitch += set[axis].analog; break; case analog_elevation: info->dy += set[axis].analog; break; case analog_rolling: info->droll += set[axis].analog; break; case analog_moving: info->dz += set[axis].analog; break; default: break; }}void CONTROL_PollDevices(ControlInfo *info){ memcpy(CONTROL_LastMouseAxes, CONTROL_MouseAxes, sizeof(CONTROL_MouseAxes)); memcpy(CONTROL_LastJoyAxes, CONTROL_JoyAxes, sizeof(CONTROL_JoyAxes)); memset(CONTROL_MouseAxes, 0, sizeof(CONTROL_MouseAxes)); memset(CONTROL_JoyAxes, 0, sizeof(CONTROL_JoyAxes)); memset(info, 0, sizeof(ControlInfo)); if (CONTROL_MouseEnabled) { int32 i = MAXMOUSEAXES-1; CONTROL_GetMouseDelta(); do { CONTROL_DigitizeAxis(i, controldevice_mouse); CONTROL_ScaleAxis(i, controldevice_mouse); LIMITCONTROL(&CONTROL_MouseAxes[i].analog); CONTROL_ApplyAxis(i, info, controldevice_mouse); } while (--i); CONTROL_DigitizeAxis(0, controldevice_mouse); CONTROL_ScaleAxis(0, controldevice_mouse); LIMITCONTROL(&CONTROL_MouseAxes[0].analog); CONTROL_ApplyAxis(0, info, controldevice_mouse); } if (CONTROL_JoystickEnabled) { int32 i = MAXJOYAXES-1; CONTROL_GetJoyDelta(); do { CONTROL_DigitizeAxis(i, controldevice_joystick); CONTROL_ScaleAxis(i, controldevice_joystick); LIMITCONTROL(&CONTROL_JoyAxes[i].analog); CONTROL_ApplyAxis(i, info, controldevice_joystick); } while (--i); CONTROL_DigitizeAxis(0, controldevice_joystick); CONTROL_ScaleAxis(0, controldevice_joystick); LIMITCONTROL(&CONTROL_JoyAxes[0].analog); CONTROL_ApplyAxis(0, info, controldevice_joystick); } CONTROL_GetDeviceButtons();}void CONTROL_AxisFunctionState(int32 *p1){ if (CONTROL_NumMouseAxes) { int32 j, i = CONTROL_NumMouseAxes-1; do { if (!CONTROL_MouseAxes[i].digital) continue; if (CONTROL_MouseAxes[i].digital < 0) j = CONTROL_MouseAxesMap[i].minmap; else j = CONTROL_MouseAxesMap[i].maxmap; if (j != AXISUNDEFINED) p1[j] = 1; } while (i--); } if (CONTROL_NumJoyAxes) { int32 j, i = CONTROL_NumJoyAxes-1; do { if (!CONTROL_JoyAxes[i].digital) continue; if (CONTROL_JoyAxes[i].digital < 0) j = CONTROL_JoyAxesMap[i].minmap; else j = CONTROL_JoyAxesMap[i].maxmap; if (j != AXISUNDEFINED) p1[j] = 1; } while (i--); }}void CONTROL_ButtonFunctionState(int32 *p1){ if (CONTROL_NumMouseButtons) { int32 i = CONTROL_NumMouseButtons-1, j; do { if (!MouseBindings[i].cmd[0]) { j = CONTROL_MouseButtonMapping[i].doubleclicked; if (j != KEYUNDEFINED) p1[j] |= CONTROL_MouseButtonClickedState[i]; j = CONTROL_MouseButtonMapping[i].singleclicked; if (j != KEYUNDEFINED) p1[j] |= CONTROL_MouseButtonState[i]; } if (!bindsenabled) continue; if (MouseBindings[i].cmd[0] && CONTROL_MouseButtonState[i]) { if (MouseBindings[i].repeat || (MouseBindings[i].laststate == 0)) OSD_Dispatch(MouseBindings[i].cmd); } MouseBindings[i].laststate = CONTROL_MouseButtonState[i]; } while (i--); } if (CONTROL_NumJoyButtons) { int32 i=CONTROL_NumJoyButtons-1, j; do { j = CONTROL_JoyButtonMapping[i].doubleclicked; if (j != KEYUNDEFINED) p1[j] |= CONTROL_JoyButtonClickedState[i]; j = CONTROL_JoyButtonMapping[i].singleclicked; if (j != KEYUNDEFINED) p1[j] |= CONTROL_JoyButtonState[i]; } while (i--); }}/*void CONTROL_GetUserInput( UserInput *info ){ ControlInfo ci; CONTROL_PollDevices( &ci ); info->dir = dir_None; // checks if CONTROL_UserInputDelay is too far in the future due to clock skew? if (GetTime() + ((ticrate * USERINPUTDELAY) / 1000) < CONTROL_UserInputDelay) CONTROL_UserInputDelay = -1; if (GetTime() >= CONTROL_UserInputDelay) { if (CONTROL_MouseAxes[1].digital == -1) info->dir = dir_North; else if (CONTROL_MouseAxes[1].digital == 1) info->dir = dir_South; else if (CONTROL_MouseAxes[0].digital == -1) info->dir = dir_West; else if (CONTROL_MouseAxes[0].digital == 1) info->dir = dir_East; if (CONTROL_JoyAxes[1].digital == -1) info->dir = dir_North; else if (CONTROL_JoyAxes[1].digital == 1) info->dir = dir_South; else if (CONTROL_JoyAxes[0].digital == -1) info->dir = dir_West; else if (CONTROL_JoyAxes[0].digital == 1) info->dir = dir_East; } info->button0 = CONTROL_MouseButtonState[0] | CONTROL_JoyButtonState[0]; info->button1 = CONTROL_MouseButtonState[1] | CONTROL_JoyButtonState[1]; if (KB_KeyDown[sc_kpad_8] || KB_KeyDown[sc_UpArrow]) info->dir = dir_North; else if (KB_KeyDown[sc_kpad_2] || KB_KeyDown[sc_DownArrow]) info->dir = dir_South; else if (KB_KeyDown[sc_kpad_4] || KB_KeyDown[sc_LeftArrow]) info->dir = dir_West; else if (KB_KeyDown[sc_kpad_6] || KB_KeyDown[sc_RightArrow]) info->dir = dir_East; if (KB_KeyDown[BUTTON0_SCAN_1] || KB_KeyDown[BUTTON0_SCAN_2] || KB_KeyDown[BUTTON0_SCAN_3]) info->button0 = 1; if (KB_KeyDown[BUTTON1_SCAN]) info->button1 = 1; if (CONTROL_UserInputCleared[1]) { if (!info->button0) CONTROL_UserInputCleared[1] = false; else info->button0 = false; } if (CONTROL_UserInputCleared[2]) { if (!info->button1) CONTROL_UserInputCleared[2] = false; else info->button1 = false; }}void CONTROL_ClearUserInput( UserInput *info ){ switch (info->dir) { case dir_North: case dir_South: case dir_East: case dir_West: CONTROL_UserInputCleared[0] = true; CONTROL_UserInputDelay = GetTime() + ((ticrate * USERINPUTDELAY) / 1000); switch (info->dir) { case dir_North: KB_KeyDown[sc_UpArrow] = KB_KeyDown[sc_kpad_8] = 0; break; case dir_South: KB_KeyDown[sc_DownArrow] = KB_KeyDown[sc_kpad_2] = 0; break; case dir_East: KB_KeyDown[sc_LeftArrow] = KB_KeyDown[sc_kpad_4] = 0; break; case dir_West: KB_KeyDown[sc_RightArrow] = KB_KeyDown[sc_kpad_6] = 0; break; default: break; } break; default: break; } if (info->button0) CONTROL_UserInputCleared[1] = true; if (info->button1) CONTROL_UserInputCleared[2] = true;}*/void CONTROL_ClearButton(int32 whichbutton){ if (CONTROL_CheckRange(whichbutton)) return; BUTTONCLEAR(whichbutton); CONTROL_Flags[whichbutton].cleared = true;}void CONTROL_ProcessBinds(void){ if (!bindsenabled) return; { int32_t i=MAXBOUNDKEYS-1; do { if (KeyBindings[i].cmd[0] && KB_KeyPressed(i)) { if (KeyBindings[i].repeat || (KeyBindings[i].laststate == 0)) OSD_Dispatch(KeyBindings[i].cmd); } KeyBindings[i].laststate = KB_KeyPressed(i); } while (--i); } if (KeyBindings[0].cmd[0] && KB_KeyPressed(0)) { if (KeyBindings[0].repeat || (KeyBindings[0].laststate == 0)) OSD_Dispatch(KeyBindings[0].cmd); } KeyBindings[0].laststate = KB_KeyPressed(0);}void CONTROL_GetInput(ControlInfo *info){ int32 periphs[CONTROL_NUM_FLAGS]; CONTROL_PollDevices(info); memset(periphs, 0, sizeof(periphs)); CONTROL_ButtonFunctionState(periphs); CONTROL_AxisFunctionState(periphs); CONTROL_ButtonHeldState = CONTROL_ButtonState; CONTROL_ButtonState = 0; CONTROL_ProcessBinds(); { int32 i = CONTROL_NUM_FLAGS-1; do { CONTROL_SetFlag(i, CONTROL_KeyboardFunctionPressed(i) | periphs[i] | extinput[i]); if (CONTROL_Flags[i].cleared == false) BUTTONSET(i, CONTROL_Flags[i].active); else if (CONTROL_Flags[i].active == false) CONTROL_Flags[i].cleared = 0; } while (--i); CONTROL_SetFlag(0, CONTROL_KeyboardFunctionPressed(0) | periphs[0] | extinput[0]); if (CONTROL_Flags[0].cleared == false) BUTTONSET(0, CONTROL_Flags[0].active); else if (CONTROL_Flags[0].active == false) CONTROL_Flags[0].cleared = 0; } memset(extinput, 0, sizeof(extinput));}void CONTROL_WaitRelease(void){}void CONTROL_Ack(void){}boolean CONTROL_Startup(controltype which, int32(*TimeFunction)(void), int32 ticspersecond){ int32 i; UNREFERENCED_PARAMETER(which); if (CONTROL_Started) return false; if (TimeFunction) GetTime = TimeFunction; else GetTime = CONTROL_GetTime; ticrate = ticspersecond; CONTROL_DoubleClickSpeed = (ticspersecond*57)/100; if (CONTROL_DoubleClickSpeed <= 0) CONTROL_DoubleClickSpeed = 1; if (initinput()) return true; CONTROL_MousePresent = CONTROL_MouseEnabled = false; CONTROL_JoyPresent = CONTROL_JoystickEnabled = false; CONTROL_NumMouseButtons = CONTROL_NumJoyButtons = 0; CONTROL_NumMouseAxes = CONTROL_NumJoyAxes = 0; KB_Startup(); //switch (which) { // case controltype_keyboard: // break; // case controltype_keyboardandmouse: CONTROL_NumMouseAxes = MAXMOUSEAXES; CONTROL_NumMouseButtons = MAXMOUSEBUTTONS; CONTROL_MousePresent = MOUSE_Init(); CONTROL_MouseEnabled = CONTROL_MousePresent; // break; // case controltype_keyboardandjoystick: CONTROL_NumJoyAxes = min(MAXJOYAXES,joynumaxes); CONTROL_NumJoyButtons = min(MAXJOYBUTTONS,joynumbuttons + 4*(joynumhats>0)); CONTROL_JoyPresent = CONTROL_StartJoy(0);; CONTROL_JoystickEnabled = CONTROL_JoyPresent; // break; //} /* if (CONTROL_MousePresent) initprintf("CONTROL_Startup: Mouse Present\n"); if (CONTROL_JoyPresent) initprintf("CONTROL_Startup: Joystick Present\n"); */ CONTROL_ButtonState = 0; CONTROL_ButtonHeldState = 0; memset(CONTROL_UserInputCleared, 0, sizeof(CONTROL_UserInputCleared)); for (i=0; i<CONTROL_NUM_FLAGS; i++) CONTROL_Flags[i].used = false; CONTROL_Started = true; return false;}void CONTROL_Shutdown(void){ if (!CONTROL_Started) return; CONTROL_JoyPresent = false; MOUSE_Shutdown(); uninitinput(); CONTROL_Started = false;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -