Commit graph

311 commits

Author SHA1 Message Date
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
Daniel Gibson
67d0b7cf01 dhewm3log.txt for Windows, update changelog
I was lazy and just renamed SDL_win32_main's stdout.txt - but I still
added the dhewm3log-old.txt backup function.

I also renamed Sys_GetHomeDir() to Win_GetHomeDir() as it's Win32-only

On Windows it's in Documents\My Games\dhewm3\dhewm3log.txt
2022-01-16 18:17:39 +01:00
Daniel Gibson
5438c9409f dhewm3log.txt for AROS
basically the same as for POSIX, except I don't know where the
save dir is. I hope this works, can't test it myself..
2022-01-16 06:12:51 +01:00
Daniel Gibson
952292b4a6 POSIX: log output to save_path/dhewm3log.txt
and refactorings needed for that (I want to create the log right at the
 beginning before much else has been initialized, so using things like
 idStr or Sys_GetPath() isn't safe)

save_path being $XDG_DATA_HOME/dhewm3/ (usually ~/.local/share/dhewm3/)
on most POSIX systems, $HOME/Library/Application Support/dhewm3/ on Mac

If the log file already exists, it's renamed to dhewm3log-old.txt first,
so there's always the most recent and the last log available.
2022-01-16 06:11:20 +01:00
Daniel Gibson
4f74c15afe Make sure MAX_OSPATH has sane size; fix some typos 2022-01-16 06:02:40 +01:00
Daniel Gibson
ae63021d00 Add absolute mouse mode and refactor mouse grabbing code
There were lots of places in the code that called Sys_GrabInput(),
some of them each frame.
Most of this is unified in events.cpp now, in handleMouseGrab() which
is called once per frame by Sys_GenerateEvents() - this makes reasoning
about when the mouse is grabbed and when not a lot easier.
Sys_GrabInput(false) still is called in a few places, before operations
that tend to take long (like loading a map or vid_restart), but
(hopefully) not regularly anymore.

The other big change is that the game now uses SDLs absolute mouse mode
for fullscreen menus (except the PDA which is an ugly hack), so the
ingame cursor is at the same position as the system cursor, which
especially helps when debugging with `in_nograb 1` and should also help
if someone wants to integrate an additional GUI toolkit like Dear ImGui.
2022-01-10 00:46:32 +01:00
Daniel Gibson
00b58d1f0f Print available displays and mouse position before creating window
to debug issues like "dhewm3 chose wrong fullscreen resolution"
or "dhewm3 started on wrong display"
2022-01-08 18:10:06 +01:00
Daniel Gibson
8cb4843022 Shorten file path in backtraces
The build dir isn't relevant, only the source path starting with neo/ is

Also removed instances of nullptr
2022-01-08 17:02:24 +01:00
Daniel Gibson
ea781c577e Use idStr::Copynz() instead of strncpy()
to guarantee \0-termination
2022-01-08 16:58:48 +01:00
Daniel Gibson
df0916ecf8 Mac: Fix RAM detection for >2GB
Sys_GetSystemRam() for OSX used some deprecated MacOS function from 1989
that used int32 for the amount of bytes.
Now using sysctl() instead, should be supported since at least 10.2.8
at least it's in
https://github.com/phracker/MacOSX-SDKs/blob/master/MacOSX10.2.8.sdk/usr/include/sys/sysctl.h
2022-01-08 16:07:22 +01:00
Felipe Woods
8e0d28374d Prevent user from running dhewm3 as root. 2021-12-16 23:08:09 +01:00
David CARLIER
3bf55225ab SDL backend, macOs warning build fixes proposal. 2021-10-30 23:55:31 +02:00
SiliconExarch
4f0c54f63f Fix compatibility with Mac OSX 10.4 and 10.5
- Fix build with SDL <=2.0.3
  SDL_GetGlobalMouseState was introduced in 2.0.4
  (which doesn't support OSX 10.5 or older)
- Don't include execinfo.h on Mac OS X 10.4
  This file isn't included in the 10.4 SDK
- Use custom typedef for PFNGLSTENCILOPSEPARATEPROC on OSX 10.4/10.5
  because the system OpenGL headers for those versions don't have it
2021-10-12 19:07:41 +02:00
HarrievG
5897ad09f0 correctly reset iconvDesc 2021-07-19 01:28:43 +02:00
Daniel Gibson
4ce48965a5 SDL2: Better non-ASCII supprt (text input, scancode names)
as long as it's chars Doom3 supports, i.e. it can be converted
to ISO-8859-1

also renamed kbdNames to _in_kbdNames to reduce likelyhood of clashes
(as it can't be static)
2021-07-18 03:30:56 +02:00
Daniel Gibson
06ff49c6b6 Restore C++98 compatibility (NULL instead of nullptr)
and print a message when libcurl has been found
2021-07-17 18:24:46 +02:00
Daniel Gibson
5e4e1d61be Merge branch 'debugger' 2021-07-16 02:21:16 +02:00
Daniel Gibson
78ab625edd Improve handling of "console key", add in_ignoreConsoleKey CVar
If in_ignoreConsoleKey is set, the console can only be opened with
Shift+Esc, not `/^/whatever, so you can easily type whatever character
is on your "console key" into the game, or even bind that key.
Otherwise, with SDL2, that key (KEY_SCANCODE_GRAVE) always generates the
newly added K_CONSOLE.
in_kbd has a new (SDL2-only) "auto" mode which tries to detect the
keyboard layout based on SDL_GetKeyFromScancode( SDL_SCANCODE_GRAVE ).
Wherever Sys_GetConsoleKey() is called, I now take the current state of
Shift into account, so we don't discard more chars than necessary, esp.
when they keyboard-layout (in_kbd) is *not* correctly set.

(TBH the only reason besides SDL1.2 to keep in_kbd around is to ignore
 the char generated by the "console key" in the console..)
2021-07-15 07:00:18 +02:00
Daniel Gibson
f88812c56f Add in_grabKeyboard CVar to grab keyboard if mouse is grabbed, #323
It's set to 0 by default (which is the original behavior), if set to 1,
SDL2 will grab the keyboard, so Alt-Tab or the Windows Key etc will not
be handled by the operating system but by dhewm3 (=> you can bind the
Windows key like any normal key and it won't open the start menu)
2021-07-15 07:00:18 +02:00
Daniel Gibson
24a6643a60 Add explicit support for Right Ctrl and Right Shift keys, #323
so far they were handled the same as their Left counterparts
2021-07-15 07:00:18 +02:00
Daniel Gibson
ae2d3a7e99 Support (hopefully) all keyboard keys via scancodes, #323
If a key is pressed whichs SDL_Keycode isn't known to Doom3 (has no
corresponding K_* constant), its SDL_Scancode is mapped to the
corresponding newly added K_SC_* scancode constant.
I think I have K_SC_* constants for all keys that differ between
keyboard layouts (which is mostly printable characters; F1-F12, Ctrl,
Shift, ... should be the same on all layouts, which means that e.g.
SDL_SCANCODE_F1 always belongs to SDLK_F1 which the old code already
maps to Doom3's K_F1).
What's extra nice (IMO) is that when Doom3 requests a *localized* name
of the key (like for showing in the bindings menu), we actually use the
name of the SDL_Keycode that *currently* belongs to the scancode, and
esp. the "Western High-ASCII characters" (ISO-8859-1) supported by Doom3
like Ä or Ñ are displayed correctly.

(I already implemented a very similar hack in Yamagi Quake II and
 reused the list of scancodes)

This should fix most of the problems reported in #323
2021-07-15 07:00:18 +02:00
HarrievG
b9833e7e6e - Fixed Once Breakpoints
- Send scriptlist on connect.
- upped version info
2021-07-13 20:36:53 +02:00
Daniel Gibson
61a49a2547 Implement clipboard support on POSIX platforms with SDL2
Added Sys_FreeClipboardData(char*) so I don't have to copy the string
from SDL_GetClipboardText() into a Mem_Alloc() buffer, but can just
do the right thing per platform, which in case of POSIX/SDL2 is
SDL_free().
SDL1.2 doesn't have clipboard support, otherwise I'd have removed all
platform-specific implementations and used SDL_Get/SetClipboardText()
everywhere (IIRC AROS only supports SDL1.2?)
2021-07-03 02:25:20 +02:00
Daniel Gibson
d55b7fa6c9 Don't use stringDataAllocator in idStr, it's not thread-safe
idStr is used in both the main thread and the async sound thread, so
it should better be thread-safe.. idDynamicBlockAlloc is not.
Use realloc() and free() instead.

For some reason this caused a lot more crashes (due to inconsistencies
in the allocator's heap) with newer Linux distros (like XUbuntu 20.04)
and when using GCC9, while they rarely reproduced with GCC7 or on
XUbuntu 18.04

fixes #391
2021-06-24 03:26:51 +02:00
HarrievG
7e367a0e62 - Added Console input / command exec to debugger 2021-06-21 14:59:28 +02:00
Daniel Gibson
d5fd0990a1 Win32: Fix deadlocks if Sys_Printf() or Sys_Error() was called in thread
If those functions (e.g. called by common->Printf(), common->Error())
weren't called from the mainthread and win_outputEditString was set to 1,
a deadlock could occur.
Specifically, the async thread (handling sound) was calling
common->Warning() -> Sys_Printf() -> Conbuf_AppendText() which called
SendMessageA() which blocks until the main thread handles the message.
The main thread however was in idSampleDecoderLocal::Decode() trying to
enter CRITICAL_SECTION_ONE, which was held by the async thread
(it's used to synchronize sound handling between main and async thread).

So now if Sys_Printf() (or Sys_Error() which should have the same problem)
is not called by the main thread, the text is buffered and
Conbuf_AppendText() is called for the buffered lines in the next frame
in Win_Frame().
2021-06-20 03:36:39 +02:00
Daniel Gibson
a523c28c18 Add SysIsMainThread() function
returns true if called in the main thread
2021-06-20 03:36:39 +02:00
Daniel Gibson
52ea5b3877 Fix endless loop in GLimp_Init(), #386
shouldn't have reused i in the inner loop..
2021-06-20 03:36:39 +02:00
Daniel Gibson
dc42bdc873 Do gamma correction (r_gamma, r_brightness) in shaders
by injecting code to do it into fragment shaders.

Can be disabled with r_gammaInShaders 0

refs #385
2021-06-20 03:36:39 +02:00
HarrievG
cd9284d876 - Debugger is guarded behind tools. 2021-06-17 05:44:23 +02:00
HarrievG
af5f395256 - Putting back the "Original by Raven" texts 2021-06-17 05:44:23 +02:00
HarrievG
7a2ccee330 debugger 2021-06-17 05:44:23 +02:00
Daniel Gibson
227fe5fc92 Use backtrace in crash handler on POSIX platforms
Non-ancient versions of GCC and clang should ship it, and in contrast
to the <execinfo.h> backtrace_symbols() it also works with
-fvisibility=hidden
2021-05-12 07:56:57 +02:00
Daniel Gibson
64b21fcd0c Add Posix_GetExePath() function
I'm gonna use it with libbacktrace - I'll need the path of the
executable before I can use idStr (and thus before I could call
Sys_GetPath(PATH_EXE, str)).
2021-05-12 07:44:07 +02:00
Daniel Gibson
b054261a0e Make MFC Tools work with MSAA enabled
The problem was that the editors called ChoosePixelFormat() instead of
wglChoosePixelFormatARB() - and the normal ChoosePixelFormat() has no
attribute for MSAA, so if MSAA is enabled (by SDL2 which calls the wgl
variant), ChoosePixelFormat() will return an incomaptible format and
the editors don't get a working OpenGL context.
So I wrote a wrapper around ChoosePixelFormat() that calls the wgl variant
if available, and all the necessary plumbing around that.

While at it, removed the unused qwgl*PixelFormat function pointers and
supressed the "inconsistent dll linkage" warnings for the gl stubs
2021-05-11 00:39:00 +02:00
Daniel Gibson
c3d480afe4 Rename GetWindowScalingFactor() to Win_GetW.., support older Win versions
Minimum required Windows version is XP again (instead of Win10).
Win_GetWindowScalingFactor() tries to use two dynamically loaded functions
from newer windows versions (8.1+, Win10 1607+) and has a fallback for
older versions that also seems to work (at least if all displays have
the same DPI).

Moved the function to win_main.cpp so the dynamically loaded functions
can be loaded at startup; so edit_gui_common.cpp could be removed again.
2021-05-10 03:18:24 +02:00
Daniel Gibson
981857f067 Fix PDAEditor (editPDAs opens it now), #378 2021-05-09 20:20:18 +02:00
Daniel Gibson
954ff88759 Properly pause sounds when entering menu, fixes #330
Otherwise especially looped sounds continue playing while the menu
is open, especially noticeable when opening the menu while firing
the chaingun (the whirring sound continues playing).
2021-04-27 20:08:59 +02:00
Daniel Gibson
1c13fe2d39 Use stb_vorbis instead of libogg and libvorbis(file)
Seems to work; note that idWaveFile is only ever used in idSoundSample::Load()

As stb_vorbis doesn't support custom callbacks for reading, I feed it
the full .ogg files as a buffer. Shouldn't make much of a difference
though - either the whole file is decoded on load anyway (so the buffer
is freed after decoding, or it's streamed, but in that case the old code
also kept the whole ogg file in memory by using idFily_Memory.

I also added warning messages in places where calls to stb_vorbis_*()
can fail, where there were none in the equivalent libvorbis code.
2021-04-27 20:08:59 +02:00
Daniel Gibson
bb7346579e GLimp_Init() Print actually received color/alpha/stencil/depth bits
to help debugging #368 and #348
2021-04-24 20:27:16 +02:00
Daniel Gibson
2139a122c5 Revert "Use SDL2's own SDL2.cmake."
This reverts commit 01ac144b09.

Looks like this broke the build on some systems, because some
package managers pack SDL2Config.cmake and others pack sdl2-config.cmake
in their SDL2 development packages (for some reason, SDL2 seems
to ship both in their source, and they appear to be incompatible).

Shipping our own FindSDL2.cmake might be unclean/ugly/whatever, but
at least it works (most of the time? at least it appears to work better
than not shipping it)
2021-01-24 04:10:18 +01:00