diff --git a/src/game/g_window.pas b/src/game/g_window.pas
index c91ff6cc555cedcf224827fcd9fac0f0f12437ea..40f74029241e05bdffc5aee7fc686c0d009fd98f 100644 (file)
--- a/src/game/g_window.pas
+++ b/src/game/g_window.pas
gwin_has_stencil: Boolean = false;
gwin_k8_enable_light_experiments: Boolean = false;
+
implementation
uses
SDL2, GL, GLExt, e_graphics, e_log, g_main,
g_console, SysUtils, e_input, g_options, g_game,
g_basic, g_textures, e_sound, g_sound, g_menu, ENet, g_net,
- g_map;
+ g_map, g_gfx, g_monsters, g_holmes;
var
h_Wnd: PSDL_Window;
ticksOverflow: Int64 = -1;
lastTicks: Uint32 = 0; // to detect overflow
{$ENDIF}
+ curMsButState: Word = 0;
+ curKbState: Word = 0;
+ curMsX: Integer = 0;
+ curMsY: Integer = 0;
const
// TODO: move this to a separate file
g_Game_SetupScreenSize();
g_Menu_Reset();
g_Game_ClearLoading();
+ g_Holmes_VidModeChanged();
end;
function g_Window_SetSize(W, H: Word; FScreen: Boolean): Boolean;
SDL_WINDOWEVENT_MINIMIZED:
begin
+ curMsButState := 0;
+ curKbState := 0;
if not wMinimized then
begin
e_ResizeWindow(0, 0);
SDL_WINDOWEVENT_RESIZED:
begin
+ curMsButState := 0;
+ curKbState := 0;
gScreenWidth := ev.data1;
gScreenHeight := ev.data2;
ChangeWindowSize();
SDL_WINDOWEVENT_MAXIMIZED:
begin
+ curMsButState := 0;
+ curKbState := 0;
if wMinimized then
begin
e_ResizeWindow(gScreenWidth, gScreenHeight);
SDL_WINDOWEVENT_RESTORED:
begin
+ curMsButState := 0;
+ curKbState := 0;
if wMinimized then
begin
e_ResizeWindow(gScreenWidth, gScreenHeight);
SDL_WINDOWEVENT_FOCUS_GAINED:
begin
+ curMsButState := 0;
+ curKbState := 0;
wActivate := True;
//e_WriteLog('window gained focus!', MSG_NOTIFY);
+ g_Holmes_WindowFocused();
end;
SDL_WINDOWEVENT_FOCUS_LOST:
begin
+ curMsButState := 0;
+ curKbState := 0;
wDeactivate := True;
//e_WriteLog('window lost focus!', MSG_NOTIFY);
+ g_Holmes_WindowBlured();
end;
end;
key, keychr: Word;
uc: UnicodeChar;
//joy: Integer;
+ msev: THMouseEvent;
+ kbev: THKeyEvent;
+
+ function buildBut (b: Byte): Word;
+ begin
+ result := 0;
+ case b of
+ SDL_BUTTON_LEFT: result := result or THMouseEvent.Left;
+ SDL_BUTTON_MIDDLE: result := result or THMouseEvent.Middle;
+ SDL_BUTTON_RIGHT: result := result or THMouseEvent.Right;
+ end;
+ end;
+
+ procedure updateKBState ();
+ var
+ kbstate: PUint8;
+ begin
+ curKbState := 0;
+ kbstate := SDL_GetKeyboardState(nil);
+ if (kbstate[SDL_SCANCODE_LCTRL] <> 0) or (kbstate[SDL_SCANCODE_RCTRL] <> 0) then curKbState := curKbState or THKeyEvent.ModCtrl;
+ if (kbstate[SDL_SCANCODE_LALT] <> 0) or (kbstate[SDL_SCANCODE_RALT] <> 0) then curKbState := curKbState or THKeyEvent.ModAlt;
+ if (kbstate[SDL_SCANCODE_LSHIFT] <> 0) or (kbstate[SDL_SCANCODE_RSHIFT] <> 0) then curKbState := curKbState or THKeyEvent.ModShift;
+ end;
+
begin
Result := False;
+ updateKBState();
+
case ev.type_ of
SDL_WINDOWEVENT:
Result := WindowEventHandler(ev.window);
SDL_QUITEV:
- begin
- if gExit <> EXIT_QUIT then
begin
- if not wLoadingProgress then
+ if gExit <> EXIT_QUIT then
begin
- g_Game_Free();
- g_Game_Quit();
- end
- else
- wLoadingQuit := True;
+ if not wLoadingProgress then
+ begin
+ g_Game_Free();
+ g_Game_Quit();
+ end
+ else
+ wLoadingQuit := True;
+ end;
+ Result := True;
end;
- Result := True;
- end;
- SDL_KEYDOWN:
- begin
- key := ev.key.keysym.scancode;
- KeyPress(key);
- end;
+ SDL_KEYDOWN, SDL_KEYUP:
+ begin
+ key := ev.key.keysym.scancode;
+ if (g_holmes_enabled) then
+ begin
+ if (ev.type_ = SDL_KEYDOWN) then kbev.kind := THKeyEvent.Press else kbev.kind := THKeyEvent.Release;
+ kbev.scan := ev.key.keysym.scancode;
+ kbev.sym := ev.key.keysym.sym;
+ kbev.bstate := curMsButState;
+ kbev.kstate := curKbState;
+ if g_Holmes_keyEvent(kbev) then exit;
+ end;
+ if (ev.type_ = SDL_KEYDOWN) then KeyPress(key);
+ end;
+
+ SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP:
+ begin
+ msev.dx := ev.button.x-curMsX;
+ msev.dy := ev.button.y-curMsY;
+ curMsX := ev.button.x;
+ curMsY := ev.button.y;
+ if (ev.type_ = SDL_MOUSEBUTTONDOWN) then msev.kind := THMouseEvent.Press else msev.kind := THMouseEvent.Release;
+ msev.but := buildBut(ev.button.button);
+ msev.x := curMsX;
+ msev.y := curMsY;
+ if (msev.but <> 0) then
+ begin
+ // ev.button.clicks: Byte
+ curMsButState := curMsButState or msev.but;
+ msev.bstate := curMsButState;
+ msev.kstate := curKbState;
+ if (g_holmes_enabled) then g_Holmes_mouseEvent(msev);
+ end;
+ end;
+ SDL_MOUSEWHEEL:
+ begin
+ if (ev.wheel.y <> 0) then
+ begin
+ msev.dx := 0;
+ msev.dy := ev.wheel.y;
+ msev.kind := THMouseEvent.Press;
+ if (ev.wheel.y < 0) then msev.but := THMouseEvent.WheelUp else msev.but := THMouseEvent.WheelDown;
+ msev.x := curMsX;
+ msev.y := curMsY;
+ msev.bstate := curMsButState;
+ msev.kstate := curKbState;
+ if (g_holmes_enabled) then g_Holmes_mouseEvent(msev);
+ end;
+ end;
+ SDL_MOUSEMOTION:
+ begin
+ msev.dx := ev.button.x-curMsX;
+ msev.dy := ev.button.y-curMsY;
+ curMsX := ev.button.x;
+ curMsY := ev.button.y;
+ msev.kind := THMouseEvent.Motion;
+ msev.but := 0;
+ msev.x := curMsX;
+ msev.y := curMsY;
+ msev.bstate := curMsButState;
+ msev.kstate := curKbState;
+ if (g_holmes_enabled) then g_Holmes_mouseEvent(msev);
+ end;
SDL_TEXTINPUT:
- begin
- Utf8ToUnicode(@uc, PChar(ev.text.text), 1);
- keychr := Word(uc);
- if (keychr > 127) then
- keychr := WCharToCP1251(keychr);
- CharPress(Chr(keychr));
- end;
+ begin
+ Utf8ToUnicode(@uc, PChar(ev.text.text), 1);
+ keychr := Word(uc);
+ if (keychr > 127) then keychr := WCharToCP1251(keychr);
+ CharPress(Chr(keychr));
+ end;
// other key presses and joysticks are handled in e_input
end;
end;
g_Map_ProfilersBegin();
+ g_Mons_ProfilersBegin();
t := Time_Delta div 28{(27777 div 1000)};
if t > 0 then
end;
g_Map_ProfilersEnd();
+ g_Mons_ProfilersEnd();
if wLoadingQuit then
begin
if ParamStr(idx) = '--opengl-dump-exts' then gwin_dump_extensions := true;
if ParamStr(idx) = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
if ParamStr(idx) = '--jah' then g_profile_history_size := 100;
- if ParamStr(idx) = '--sap-draw' then gdbg_map_use_sap_draw := true;
- if ParamStr(idx) = '--grid-draw' then gdbg_map_use_sap_draw := false;
- if ParamStr(idx) = '--sap-coldet' then gdbg_map_use_sap_coldet := true;
- if ParamStr(idx) = '--grid-coldet' then gdbg_map_use_sap_coldet := false;
+ if ParamStr(idx) = '--no-particles' then gpart_dbg_enabled := false;
+ if ParamStr(idx) = '--no-los' then gmon_dbg_los_enabled := false;
+
+ if ParamStr(idx) = '--profile-render' then g_profile_frame_draw := true;
+ if ParamStr(idx) = '--profile-coldet' then g_profile_collision := true;
+ if ParamStr(idx) = '--profile-los' then g_profile_los := true;
+
+ if ParamStr(idx) = '--no-part-phys' then gpart_dbg_phys_enabled := false;
+ if ParamStr(idx) = '--no-part-physics' then gpart_dbg_phys_enabled := false;
+ if ParamStr(idx) = '--no-particles-phys' then gpart_dbg_phys_enabled := false;
+ if ParamStr(idx) = '--no-particles-physics' then gpart_dbg_phys_enabled := false;
+ if ParamStr(idx) = '--no-particle-phys' then gpart_dbg_phys_enabled := false;
+ if ParamStr(idx) = '--no-particle-physics' then gpart_dbg_phys_enabled := false;
+
+ if ParamStr(idx) = '--holmes' then begin g_holmes_enabled := true; g_Game_SetDebugMode(); end;
end;
e_WriteLog('Initializing OpenGL', MSG_NOTIFY);