DEADSOFTWARE

"dbg_holmes" console command; draw line to monster target
[d2df-sdl.git] / src / game / g_window.pas
index c91ff6cc555cedcf224827fcd9fac0f0f12437ea..1ac9c9e097f6300ae7d8b33874e657a05d41f52b 100644 (file)
@@ -41,6 +41,7 @@ var
   gwin_has_stencil: Boolean = false;
   gwin_k8_enable_light_experiments: Boolean = false;
 
+
 implementation
 
 uses
@@ -48,7 +49,7 @@ 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;
@@ -69,6 +70,10 @@ var
   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
@@ -191,6 +196,7 @@ begin
   g_Game_SetupScreenSize();
   g_Menu_Reset();
   g_Game_ClearLoading();
+  g_Holmes_VidModeChanged();
 end;
 
 function g_Window_SetSize(W, H: Word; FScreen: Boolean): Boolean;
@@ -242,6 +248,8 @@ begin
 
     SDL_WINDOWEVENT_MINIMIZED:
     begin
+      curMsButState := 0;
+      curKbState := 0;
       if not wMinimized then
       begin
         e_ResizeWindow(0, 0);
@@ -258,6 +266,8 @@ begin
 
     SDL_WINDOWEVENT_RESIZED:
     begin
+      curMsButState := 0;
+      curKbState := 0;
       gScreenWidth := ev.data1;
       gScreenHeight := ev.data2;
       ChangeWindowSize();
@@ -274,6 +284,8 @@ begin
 
     SDL_WINDOWEVENT_MAXIMIZED:
     begin
+      curMsButState := 0;
+      curKbState := 0;
       if wMinimized then
       begin
         e_ResizeWindow(gScreenWidth, gScreenHeight);
@@ -293,6 +305,8 @@ begin
 
     SDL_WINDOWEVENT_RESTORED:
     begin
+      curMsButState := 0;
+      curKbState := 0;
       if wMinimized then
       begin
         e_ResizeWindow(gScreenWidth, gScreenHeight);
@@ -310,14 +324,20 @@ begin
 
     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;
 
@@ -373,8 +393,33 @@ var
   key, keychr: Word;
   uc: UnicodeChar;
   //joy: Integer;
+  msev: THMouseEvent;
+
+  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);
@@ -400,6 +445,55 @@ begin
       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);
@@ -579,6 +673,7 @@ begin
   end;
 
   g_Map_ProfilersBegin();
+  g_Mons_ProfilersBegin();
 
   t := Time_Delta div 28{(27777 div 1000)};
   if t > 0 then
@@ -598,6 +693,7 @@ begin
   end;
 
   g_Map_ProfilersEnd();
+  g_Mons_ProfilersEnd();
 
   if wLoadingQuit then
   begin
@@ -709,12 +805,33 @@ 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) = '--tree-draw' then gdbg_map_use_tree_draw := true;
+    //if ParamStr(idx) = '--grid-draw' then gdbg_map_use_tree_draw := false;
+    //if ParamStr(idx) = '--tree-coldet' then gdbg_map_use_tree_coldet := true;
+    //if ParamStr(idx) = '--grid-coldet' then gdbg_map_use_tree_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 g_holmes_enabled := false;
   end;
 
+  //if gdbg_map_use_tree_draw then e_WriteLog('using TREE renderer', MSG_NOTIFY);
+  //if not gdbg_map_use_tree_draw then e_WriteLog('using GRID renderer', MSG_NOTIFY);
+
+  //if gdbg_map_use_tree_coldet then e_WriteLog('using TREE coldet', MSG_NOTIFY);
+  //if not gdbg_map_use_tree_coldet then e_WriteLog('using GRID coldet', MSG_NOTIFY);
+
   e_WriteLog('Initializing OpenGL', MSG_NOTIFY);
   InitOpenGL(gVSync);