Commit graph

351 commits

Author SHA1 Message Date
Daniel Gibson
49ed8ec439 Adjust imgui_savestyle.cpp for 1.90.8
ImGuiDir now is a proper enum, not just a typedef of int that happens
to have a similar name to the actual enum
2024-06-06 20:07:30 +02:00
Daniel Gibson
51270dd390 Store imgui.ini and user.imstyle in dhewm3 config dir instead of $PWD 2024-06-04 10:52:30 +02:00
Daniel Gibson
5376c6d74c HighDPI support, hopefully 2024-06-03 14:49:23 +02:00
Daniel Gibson
7aa6c6a70f "Properly" scale ImGui font by reloading font with scaled size 2024-06-02 16:50:28 +02:00
Daniel Gibson
cb5d988058 Fix SDL1.2 build and some runtime issues with SDL1.2 2024-06-02 15:40:09 +02:00
Daniel Gibson
6dc36c6175 Add some functions to handle UTF-8 strings
- convert to/from ISO8859-1 (Doom3's "High ASCII" encoding)
- count Unicode codepoints in UTF-8 string
- cut UTF-8 string off after N codepoints
- use the conversion function to replace iconv in sys/events.cpp
2024-06-02 13:14:30 +02:00
Daniel Gibson
410d2791ae Dhewm3SettingsMenu: More video settings, a few other tweaks 2024-05-30 08:59:28 +02:00
Daniel Gibson
e3d67f0ac9 Allow changing r_swapInterval (VSync) on-the-fly
Not supported with SDL1.2 - but that's only still supported by dhewm3
because I'm too lazy to rip it out :-p
2024-05-30 05:54:18 +02:00
Daniel Gibson
1697831e74 ImGui: Draw ImGui cursor on black bars in main menu; tweak some colors
In the main menu the ImGui/SDL/System cursor was only drawn when it was
over an ImGui window, so only the Doom3 cursor is shown when outside
of ImGui windows.
The only problem with this is that the Doom3 cursor is only shown in
the parst of the window actually covered by the main menu, not the black
bars that are drawn on the left/right for widescreen-resolutions when
scaling the menu to 4:3 is enabled (which it is by default).
So now the ImGui cursor is also drawn when the cursor is on those
black bars (if any).

Also tweaked the windowtitle background colors a bit.
2024-05-30 01:26:40 +02:00
Daniel Gibson
7af7508a7f ImGui stuff: Some tweaks
* Binding menu makes sure that the AllBindingsMenu always gets focus
  when opened
* Give binding-related popups slightly rounder edges
* Move Game Options tab behind Video and Audio Options
* Make warning overlays a bit less translucent
2024-05-28 04:49:24 +02:00
Daniel Gibson
4bdee4f638 Dhewm3SettingsMenu: Improve cursor handling and opening menu ingame
Pause the game (with g_stopTime) when the settings menu is opened
while ingame, unpause it when it's closed.
If the menu is open while ingame and an ImGui window has focus,
the mouse cursor is shown. If the player clicks outside an ImGui window,
it gets unfocused and the cursor is hidden and the player can look
around. Pressing F10 (or whatever key is bound to "dhewm3Settings")
will give focus back to an open ImGui window, pressing it again then
will close the settings window, pressing it once again afterwards will
open the settings window again.

handleMouseGrab() (in sys/events.cpp) now checks if sys_imgui thinks
that a cursor should be shown (via D3::ImGuiHooks::ShouldShowCursor())
and if so, shows it and ungrabs the mouse. This, together with
D3::ImGuiHooks::NewFrame() checking ShouldShowCursor() to (unset)
ImGuiConfigFlags_NoMouseCursorChange, should prevent flickering cursor
problems that sometimes occurred when ImGui's SDL2 backend and dhewm3
disagreed on whether the cursor should be visible.
2024-05-28 04:49:24 +02:00
Daniel Gibson
c0b6660389 ImGui styles: Allow writing only changed values to C++ code 2024-05-26 03:56:28 +02:00
Daniel Gibson
2a7683ebaa imgui_savestyle.cpp - some improvements
- write code uses fewer/shorter string literals
- code generated by WriteImGuiStyleToCode() has nicer alignment
- small improvements in some comments
2024-05-26 01:23:30 +02:00
Daniel Gibson
894aa67a8f Dhewm3SettingsMenu: Add button to copy current style to clipboard as C++ 2024-05-25 18:16:00 +02:00
Daniel Gibson
99b65a3edf Add WriteImGuiStyleToCode() to imgui_savestyle.cpp 2024-05-25 18:15:07 +02:00
Daniel Gibson
fd36e8e477 imgui_savestyle.cpp: use common->Warning() for warnPrintf() 2024-05-25 06:58:19 +02:00
Daniel Gibson
bb0511ac7b sys_imgui.cpp: Move code to read/write style to imgui_savestyle.cpp
it's nicely self-contained, I'll release it as a mini-library/addon
for Dear ImGui on https://github.com/DanielGibson/Snippets/
2024-05-25 06:58:19 +02:00
Daniel Gibson
2e8cbc1344 Allow saving ImGui Userstyles
You can pry X macros from my cold dead hands
2024-05-24 16:16:47 +02:00
Daniel Gibson
ef529cf49a Bind F10 to open dhewm3Settings menu, unless F10 is already bound
Also fix MSVC build: For some reason Microsoft's sad excuse of a compiler
 only sets __cplusplus to a value from this millenium if the
/Zc:__cplusplus compiler option is set, but that's only supported from
VS2017 15.7 on. The alternative is to use _MSVC_LANG, which always holds
the version that __cplusplus *should* have...
2024-05-23 19:29:38 +02:00
Daniel Gibson
6d508eac17 Some functions that will be used by the ImGui keybinding menu 2024-05-22 19:46:38 +02:00
Daniel Gibson
c9a8901dbd ImGui: Improve integration, use scalable font, Control Options menu 2024-05-22 19:46:38 +02:00
Daniel Gibson
86be2eb513 initial support for DPI scaling of imgui 2024-05-22 19:46:38 +02:00
Daniel Gibson
ffaf135758 Start ImGui-based settings menu
the integration of that at least, the menu is still a stub
2024-05-22 19:46:38 +02:00
Daniel Gibson
8fce796680 improve imgui integration 2024-05-22 19:46:38 +02:00
Daniel Gibson
c0c82e763a Initial ImGui integration in the engine
still a bit hacky, but shows imgui windows that can be clicked etc
2024-05-22 19:46:38 +02:00
Daniel Gibson
6daf1e9e7f Don't use GCC's __builtin_alloca_with_align(), fix #572
turns out that __builtin_alloca_with_align() might releases the
allocated memory at the end of the block it was allocated in, instead
of the end of the function (which is the behavior of regular alloca()
and __builtin_alloca()): "The lifetime of the allocated object ends at
 the end of the block in which the function was called. The allocated
 storage is released no later than just before the calling function
 returns to its caller, but may be released at the end of the block in
 which the function was called."
https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005falloca_005fwith_005falign

Clang also supports __builtin_alloca_with_align(), but always releases
the memory at the end of the function.

And it seems that newer GCC versions also tend to release it at the
end of the function, but GCC 4.7.2 (that I use for the official Linux
release binaries) didn't, and that caused weird graphical glitches.
But as I don't want to rely on newer GCC versions behaving like this
(and the documentation explicitly says that it *may* be released at
 the end of the block, but will definitely be released at the end of
 the function), I removed all usage of __builtin_alloca_with_align().

(Side-Note: GCC only started documenting the behavior of
 __builtin_alloca and __builtin_alloca_with_align at all with GCC 6.1.0)
2024-04-19 07:24:32 +02:00
Daniel Gibson
d6c0bb2003 Make it build and work on old PPC Macs again (#568)
also added the changelog entry for in_namePressed
2024-03-27 01:04:11 +01:00
Daniel Gibson
27aeda205c Make Sys_SetInteractiveIngameGuiActive() work better
it could happen that UIs are added to the internal list twice,
and also that the last UI wasn't removed from the list when a new one
was focused fast enough.

That should work better now, I hope I didn't break anything..
2024-03-17 04:03:27 +01:00
r-a-sattarov
6ed10c1dac Workaround for MCST-LCC compiler < 1.28 version
mcst-lcc < 1.28 does not support __builtin_alloca_with_align()
Ref: http://mcst.ru/lcc
2024-02-06 17:20:05 +01:00
Daniel Gibson
5b8e67762b Also allow using "Pad Y" for leftclick in menus 2024-01-22 05:50:45 +01:00
Daniel Gibson
9e8d399257 Further gamepad improvements
- the gamepad button (or trigger) bound to attack (fire) now always
  acts like the left mouse button in menus
- Display correct button name for "Back" button on Playstation-like
  gamepads, even depending on whether it's PS3-like ("Select") or
  PS4/5-like ("Share")
- Log some more information about detected gamepads
2024-01-18 19:53:45 +01:00
Daniel Gibson
e7eb7d17fe Improve Nintendo Pro Controller support
and some general gamepad support improvements, like logging the
detected gamepad name and type
2024-01-18 06:09:33 +01:00
Daniel Gibson
09c89206a4 Fix gamepad button names for nintendo gamepads
oops, forgot to switch X and Y
2024-01-18 03:11:23 +01:00
Daniel Gibson
bb568bc3da Gamepad layout autodetection (for SDL 2.0.12 and newer)
turns out SDL 2.0.12 added SDL_GameControllerGetType() which tells you
what kind of controller it is (xbox, playstation, nintendo, ..).

Using this to implement an auto-mode for joy_gamepadLayout, when it's
set to -1 (the new default).

This should still build with older versions of SDL2 (but won't have
that autodetection then).
2024-01-17 21:25:33 +01:00
Daniel Gibson
86690df24e Add joy_gamepadLayout CVar to better support nintendo/PS-style gamepads
The button names shown in the controls menu now depend on this CVar.
So if you set it to 1 (Nintendo), the "A" button (which, based on its
position, would be "B" on XBox/XInput gamepads) is actually shown as
"Pad A", and if it's set to 2 (Playstation), it's shown as "Pad Cross".

The "real" names, used in the config, remain the same and are based on
position: JOY_BTN_SOUTH, JOY_BTN_EAST, JOY_BTN_WEST, JOY_BTN_NORTH
2024-01-17 18:54:09 +01:00
Daniel Gibson
cf5d10f4e6 Fix gamepad pseudo-mouse input for UIs in multiplayer mode
also, only generate pseudo-mouse-move events for gamecode
(by modifying idUsercmdGenLocal::continuousMouseX/Y) when an
interactive ingame UI is active
2024-01-17 17:45:43 +01:00
Daniel Gibson
03ec74fd6f Make PDA work with gamepad, incl. making Pad A emulate leftclick
this is a bit hacky and ugly, and doesn't work properly in multiplayer
mode yet, see FIXME in idUserInterfaceLocal::Activate()
2024-01-17 07:06:52 +01:00
Daniel Gibson
6eac0540bf Various gamepad improvements
- treat DPad as 4 regular buttons (was already the case mostly, but now
  the code is simpler)
- rename in_invertLook to joy_invertLook and in_useJoystick to
  in_useGamepad and remove unused CVars
- make controller Start button generate K_ESCAPE events, so it can
  always be used to open/close the menu (similar to D3BFG)
- move mousecursor with sticks, A button (south) for left-click,
  B button (east) for right-click (doesn't work in PDA yet)
- removed special handling of K_JOY_BTN_* in idWindow::HandleEvent()
  by generating fake mouse button events for gamepad A/B
  in idUserInterfaceLocal::HandleEvent()
2024-01-16 17:29:30 +01:00
Daniel Gibson
700b3ee558 Clean up gamepad code a bit, rename buttons
- renamed gamepad/joystick actions and keys to have some meaning
  for buttons (instead of just JOY1, JOY2 etc)
- compiles with SDL1.2 again (there gamepads aren't supported though)
- shorter names for gamepad keys/axis in the key bindings menu
2024-01-08 05:26:27 +01:00
Daniel Gibson
ab53e9aa13 Merge GameController support from Quadrilateral Cowboy
https://github.com/blendogames/quadrilateralcowboy

pretty much as it is there, with only minimal changes required to work
with dhewm3
2024-01-07 01:26:45 +01:00
Daniel Gibson
6f35ce045d _alloca16(): Use __builtin_alloca_with_align() on GCC
we're already using it with MinGW, no reason not to use it with
"normal" GCC on Unix (and clang, which also defines __GNUC__) as well.
2023-03-28 19:14:29 +02:00
James Addison
d57f438db1 Fixup: typo: 'hiehgt' -> 'height' in a few places around the codebase 2023-02-04 19:34:29 +01:00
Daniel Gibson
dee76dbb21 Increase stack size on Windows to 8MB, so huge models work
The HD version of the "Birdman" Hellknight model crashed the game,
because on Linux it triggered the 600KB _alloca() assertion and on
Windows (that didn't have such an assertion up to this commit) it
overflowed the stack.
Thde default stacksize on Windows is 1MB, increasing that to 8MB fixes the
problem (in Doom3 1.3.1 it was 4MB).
I also implemented the _alloca() size check assertion for Windows, and
increased the allowed size to 2MB (so it can be safely called multiple
times per function)
Model: https://www.moddb.com/mods/birdman-doom3/downloads/birdman-doom3-v11
2023-01-21 19:26:11 +01:00
Daniel Gibson
e7e06d05f1 Fix SDL1.2 build and type of xthreadInfo::threadId 2023-01-16 03:22:01 +01:00
Daniel Gibson
6940d7f678 Fix build with Visual Studio's builtin CMake support
For some reason MSVCs integrated CMake doesn't set CMAKE_GENERATOR_PLATFORM
so my CPU arch detection magic in CMakeLists.txt didn't work in that case..
Now (when using MSVC) the CPU architecture (D3_ARCH) is set in
neo/sys/platform.h instead.
2022-12-31 02:01:52 +01:00
PLG
cc0f49f9a8 Remove deprecated warnings on mac for cString use. 2022-07-07 22:47:12 +02:00
Daniel Gibson
699779e9ca Make window alpha chan opaque on Wayland, fix #426
For some reason Wayland thought it would be clever to be the only
windowing system that (non-optionally) uses the alpha chan of the
window's default OpenGL framebuffer for window transparency.
This always caused glitches with dhewm3, as Doom3 uses that alpha-chan
for blending tricks (with GL_DST_ALPHA) - especially visible in the main
menu or when the flashlight is on.
So far the workaround has been r_waylandcompat which requests an OpenGL
context/visual without alpha chan (0 alpha bits), but that also causes
glitches.
There's an EGL extension that's supposed to fix this issue
(EGL_EXT_present_opaque), and newer SDL2 versions use it (when using
the wayland backend) - but unfortunately the Mesa implementation is
broken (seems to provide a visual without alpha channel even if one was
requested), see https://gitlab.freedesktop.org/mesa/mesa/-/issues/5886
and https://github.com/libsdl-org/SDL/pull/4306#issuecomment-1014770600
for the corresponding SDL2 discussion

To work around this issue, dhewm3 now disables the use of that EGL
extension and (optionally) makes sure the alpha channel is opaque at
the end of the frame.
This behavior is controlled with the r_fillWindowAlphaChan CVar:
If it's 1, this always is done (regardless if wayland is used or not),
if it's 0 it's not done (even on wayland),
if it's -1 (the default) it's only done if the SDL "video driver" is
  wayland (this could be easily enhanced later in case other windowing
  systems have the same issue)

r_waylandcompat has been removed (it never worked properly anyway),
so now the window always has an alpha chan
2022-02-05 16:34:34 +01:00
Daniel Gibson
d09ccb8539 If creating window fails, first try to reduce MSAA level, fix #440
so if someone configured 16x AA on a system that doesn't support it
(like when using AMDs open source driver), 8x will be tried before
falling back to a 640x480 window with no AA at all.
(and then it'll try 4x and then 2x and then no AA at all, and only then
 reducing color depth will start, and even later it'll fall back to
 a small 640x480 window)
2022-01-24 06:00:55 +01:00
Daniel Gibson
d34832e4fc Fix Mac build 2022-01-17 15:31:10 +01:00
Daniel Gibson
eff9fd6ac3 GLimp_Init(): Log r_mode and resolution used for creating window 2022-01-16 19:39:35 +01:00