X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_window.pas;h=88b229aa220b888697903da121c21f01e0bbe0f4;hb=683e1735a7efbf7342dec58a49d7f559a1e75fea;hp=8336ea9b82cb39b11cd0b5b95c8e992e8cc3b0dd;hpb=a9ab7bf0c72e15b932b20aad24b10db60138bb21;p=d2df-sdl.git diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 8336ea9..88b229a 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -45,6 +45,7 @@ var gwin_has_stencil: Boolean = false; gwin_k8_enable_light_experiments: Boolean = false; g_dbg_aimline_on: Boolean = false; + g_dbg_input: Boolean = False; implementation @@ -55,12 +56,12 @@ uses {$IFDEF ENABLE_HOLMES} g_holmes, sdlcarcass, fui_ctls, {$ENDIF} - SysUtils, Classes, MAPDEF, + SysUtils, Classes, MAPDEF, Math, SDL2, e_graphics, e_log, e_texture, g_main, g_console, e_input, g_options, g_game, g_basic, g_textures, e_sound, g_sound, g_menu, ENet, g_net, g_map, g_gfx, g_monsters, xprofiler, - g_touch; + g_touch, g_gui; const @@ -84,7 +85,9 @@ var ticksOverflow: Int64 = -1; lastTicks: Uint32 = 0; // to detect overflow {$ENDIF} - + JoystickHandle: array [0..e_MaxJoys - 1] of PSDL_Joystick; + JoystickHatState: array [0..e_MaxJoys - 1, 0..e_MaxJoyHats - 1, HAT_LEFT..HAT_DOWN] of Boolean; + JoystickZeroAxes: array [0..e_MaxJoys - 1, 0..e_MaxJoyAxes - 1] of Integer; procedure KillGLWindow (preserveGL: Boolean); begin @@ -314,8 +317,6 @@ begin SDL_WINDOWEVENT_MINIMIZED: begin e_UnpressAllKeys(); - if (gPlayer1 <> nil) then gPlayer1.releaseAllWeaponSwitchKeys(); - if (gPlayer2 <> nil) then gPlayer2.releaseAllWeaponSwitchKeys(); if not wMinimized then begin e_ResizeWindow(0, 0); @@ -404,8 +405,6 @@ begin begin wDeactivate := true; e_UnpressAllKeys(); - if (gPlayer1 <> nil) then gPlayer1.releaseAllWeaponSwitchKeys(); - if (gPlayer2 <> nil) then gPlayer2.releaseAllWeaponSwitchKeys(); //e_WriteLog('window lost focus!', MSG_NOTIFY); end; end; @@ -415,8 +414,7 @@ begin if gWinActive then begin e_WriteLog('deactivating window', TMsgType.Notify); - e_EnableInput := false; - e_ClearInputBuffer(); + e_UnpressAllKeys; if gMuteWhenInactive then begin @@ -442,7 +440,6 @@ begin if not gWinActive then begin //e_WriteLog('activating window', MSG_NOTIFY); - e_EnableInput := true; if gMuteWhenInactive then begin @@ -468,9 +465,11 @@ end; function EventHandler (var ev: TSDL_Event): Boolean; var - key, keychr: Word; + key, keychr, minuskey: Word; uc: UnicodeChar; down: Boolean; + i: Integer; + hat: array [HAT_LEFT..HAT_DOWN] of Boolean; begin result := false; @@ -509,8 +508,144 @@ begin exit; end; {$ENDIF} + if ev.key._repeat = 0 then + begin + if g_dbg_input then + e_LogWritefln('Input Debug: keysym, press=%s, scancode=%s', [down, key]); + e_KeyUpDown(key, down); + g_Console_ProcessBind(key, down); + end + else if gConsoleShow or gChatShow or (g_ActiveWindow <> nil) then + begin + // key repeat in menus and shit + KeyPress(key); + end; + end; + + SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP: + if (ev.jbutton.which < e_MaxJoys) and (ev.jbutton.button < e_MaxJoyBtns) then + begin + key := e_JoyButtonToKey(ev.jbutton.which, ev.jbutton.button); + down := ev.type_ = SDL_JOYBUTTONDOWN; + if g_dbg_input then + e_LogWritefln('Input Debug: jbutton, joy=%s, button=%s, keycode=%s, press=%s', [ev.jbutton.which, ev.jbutton.button, key, down]); e_KeyUpDown(key, down); - if down then KeyPress(key); + g_Console_ProcessBind(key, down); + end + else + begin + if g_dbg_input then + begin + down := ev.type_ = SDL_JOYBUTTONDOWN; + e_LogWritefln('Input Debug: NOT IN RANGE! jbutton, joy=%s, button=%s, press=%s', [ev.jbutton.which, ev.jbutton.button, down]) + end + end; + + SDL_JOYAXISMOTION: + if (ev.jaxis.which < e_MaxJoys) and (ev.jaxis.axis < e_MaxJoyAxes) then + begin + key := e_JoyAxisToKey(ev.jaxis.which, ev.jaxis.axis, AX_PLUS); + minuskey := e_JoyAxisToKey(ev.jaxis.which, ev.jaxis.axis, AX_MINUS); + + if g_dbg_input then + e_LogWritefln('Input Debug: jaxis, joy=%s, axis=%s, value=%s, zeroaxes=%s, deadzone=%s', [ev.jaxis.which, ev.jaxis.axis, ev.jaxis.value, JoystickZeroAxes[ev.jaxis.which, ev.jaxis.axis], e_JoystickDeadzones[ev.jaxis.which]]); + + if ev.jaxis.value < JoystickZeroAxes[ev.jaxis.which, ev.jaxis.axis] - e_JoystickDeadzones[ev.jaxis.which] then + begin + if (e_KeyPressed(key)) then + begin + e_KeyUpDown(key, False); + g_Console_ProcessBind(key, False); + end; + e_KeyUpDown(minuskey, True); + g_Console_ProcessBind(minuskey, True); + end + else if ev.jaxis.value > JoystickZeroAxes[ev.jaxis.which, ev.jaxis.axis] + e_JoystickDeadzones[ev.jaxis.which] then + begin + if (e_KeyPressed(minuskey)) then + begin + e_KeyUpDown(minuskey, False); + g_Console_ProcessBind(minuskey, False); + end; + e_KeyUpDown(key, True); + g_Console_ProcessBind(key, True); + end + else + begin + if (e_KeyPressed(minuskey)) then + begin + e_KeyUpDown(minuskey, False); + g_Console_ProcessBind(minuskey, False); + end; + if (e_KeyPressed(key)) then + begin + e_KeyUpDown(key, False); + g_Console_ProcessBind(key, False); + end; + end; + end + else + begin + if g_dbg_input then + e_LogWritefln('Input Debug: NOT IN RANGE! jaxis, joy=%s, axis=%s, value=%s, zeroaxes=%s, deadzone=%s', [ev.jaxis.which, ev.jaxis.axis, ev.jaxis.value, JoystickZeroAxes[ev.jaxis.which, ev.jaxis.axis], e_JoystickDeadzones[ev.jaxis.which]]) + end; + + SDL_JOYHATMOTION: + if (ev.jhat.which < e_MaxJoys) and (ev.jhat.hat < e_MaxJoyHats) then + begin + if g_dbg_input then + e_LogWritefln('Input Debug: jhat, joy=%s, hat=%s, value=%s', [ev.jhat.which, ev.jhat.hat, ev.jhat.value]); + hat[HAT_UP] := LongBool(ev.jhat.value and SDL_HAT_UP); + hat[HAT_DOWN] := LongBool(ev.jhat.value and SDL_HAT_DOWN); + hat[HAT_LEFT] := LongBool(ev.jhat.value and SDL_HAT_LEFT); + hat[HAT_RIGHT] := LongBool(ev.jhat.value and SDL_HAT_RIGHT); + for i := HAT_LEFT to HAT_DOWN do + begin + if JoystickHatState[ev.jhat.which, ev.jhat.hat, i] <> hat[i] then + begin + down := hat[i]; + key := e_JoyHatToKey(ev.jhat.which, ev.jhat.hat, i); + e_KeyUpDown(key, down); + g_Console_ProcessBind(key, down); + end + end; + JoystickHatState[ev.jhat.which, ev.jhat.hat] := hat + end + else + begin + if g_dbg_input then + e_LogWritefln('Input Debug: NOT IN RANGE! jhat, joy=%s, hat=%s, value=%s', [ev.jhat.which, ev.jhat.hat, ev.jhat.value]) + end; + + SDL_JOYDEVICEADDED: + if (ev.jdevice.which < e_MaxJoys) then + begin + JoystickHandle[ev.jdevice.which] := SDL_JoystickOpen(ev.jdevice.which); + if JoystickHandle[ev.jdevice.which] <> nil then + begin + e_LogWritefln('Added Joystick %s', [ev.jdevice.which]); + e_JoystickAvailable[ev.jdevice.which] := True; + for i := 0 to Min(SDL_JoystickNumAxes(JoystickHandle[ev.jdevice.which]), e_MaxJoyAxes) - 1 do + JoystickZeroAxes[ev.jdevice.which, i] := SDL_JoystickGetAxis(JoystickHandle[ev.jdevice.which], i) + end + else + e_LogWritefln('Warning! Failed to open Joystick %s', [ev.jdevice.which]) + end + else + begin + e_LogWritefln('Warning! Added Joystick %s, but we support only <= %s', [ev.jdevice.which, e_MaxJoys]) + end; + + SDL_JOYDEVICEREMOVED: + begin + e_LogWritefln('Removed Joystick %s', [ev.jdevice.which]); + if (ev.jdevice.which < e_MaxJoys) then + begin + e_JoystickAvailable[ev.jdevice.which] := False; + if JoystickHandle[ev.jdevice.which] <> nil then + SDL_JoystickClose(JoystickHandle[ev.jdevice.which]); + JoystickHandle[ev.jdevice.which] := nil + end end; {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)} @@ -520,6 +655,8 @@ begin SDL_TEXTINPUT: begin + if g_dbg_input then + e_LogWritefln('Input Debug: text, text=%s', [ev.text.text]); Utf8ToUnicode(@uc, PChar(ev.text.text), 1); keychr := Word(uc); if (keychr > 127) then keychr := Word(wchar2win(WideChar(keychr))); @@ -652,7 +789,6 @@ var procedure ProcessLoading (forceUpdate: Boolean=false); var ev: TSDL_Event; - ID: LongWord; stt: UInt64; begin FillChar(ev, sizeof(ev), 0); @@ -663,7 +799,7 @@ begin EventHandler(ev); if (ev.type_ = SDL_QUITEV) then break; end; - e_PollJoysticks(); + //e_PollJoysticks(); if (ev.type_ = SDL_QUITEV) or (gExit = EXIT_QUIT) then begin @@ -689,17 +825,11 @@ begin if forceUpdate then begin - if g_Texture_Get('INTER', ID) then - begin - e_DrawSize(ID, 0, 0, 0, false, false, gScreenWidth, gScreenHeight); - e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150); - end - else - begin - e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0); - end; + DrawMenuBackground('INTER'); + e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150); DrawLoadingStat(); + g_Console_Draw(True); SwapBuffers(); end; end; @@ -730,7 +860,7 @@ begin result := EventHandler(ev); if (ev.type_ = SDL_QUITEV) then exit; end; - e_PollJoysticks(); + //e_PollJoysticks(); end; @@ -837,7 +967,7 @@ begin {$IFDEF USE_GLES1} SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); {$ELSE} SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); @@ -941,6 +1071,8 @@ begin if arg = '--no-particle-phys' then gpart_dbg_phys_enabled := false; if arg = '--no-particle-physics' then gpart_dbg_phys_enabled := false; + if arg = '--debug-input' then g_dbg_input := True; + {.$IF DEFINED(D2F_DEBUG)} if arg = '--aimline' then g_dbg_aimline_on := true; {.$ENDIF} @@ -1058,4 +1190,6 @@ begin end; +initialization + conRegVar('d_input', @g_dbg_input, '', '') end.