Commit graph

662 commits

Author SHA1 Message Date
Daniel Gibson
aedf0b4b21 Fix endless loop when decoding OGGs, #390
In idSampleDecoderLocal::DecodeOGG() `totalSamples` was 1 and
`reqSamples` was 0, which caused an endless loop.. this was caused by
idSoundWorldLocal::ReadFromSaveGame() setting
`chan->openalStreamingOffset` to an odd number, I think due to
`currentSoundTime` being an odd number.
To fix that, I round up `chan->openalStreamingOffset` to a (very) even
number, and to be double-sure I also added a check in DecodeOgg() to
make sure it exits the loop if `reqSamples` is 0.
2021-06-22 02:59:59 +02:00
Daniel Gibson
8eb91c79cb Force SDL to minimize the window when focus is lost, fix #360
This was changed in SDL 2.0.14 and causes problems on several platforms
and window managers.
Fix taken from Yamagi Quake II
2021-06-20 03:59:30 +02:00
Daniel Gibson
fa8ab0ca49 GCC/Clang: Remove -fno-unsafe-math-optimizations
it's redundant because it's default as long as -ffast-math isn't used,
and according to
https://github.com/RobertBeckebans/RBDOOM-3-BFG/pull/575#issuecomment-862044631
in clang12 it causes warnings when used with -fno-trapping-math.
2021-06-20 03:36:39 +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
1b4badfd41 Ignore if stb_vorbis decodes one sample less than expected
In idSampleDecoderLocal::DecodeOGG() sometimes (esp. in The Lost Mission
mod) it happens that stb_vorbis_get_samples_float() decodes one sample
less than expected so one is left and when trying to decode that,
stb_vorbis_get_samples_float() returns 0, which we interpreted as an error.
This case is now handled more gracefully: No warning is printed (except
if developer 1) and failed is not set (setting it would prevent the sound
from being played again, I think).
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
Daniel Gibson
c212148d41 Remove R_LockSurfaceScene(), clean up temporary changes
R_LockSurfaceScene() isn't used anymore, surface locking is implemented
differently (so it actually works now :-p)
2021-06-15 03:27:52 +02:00
Daniel Gibson
a11b2d352c r_lockSurfaces: Make mirrors look only a bit broken
it's still not great, but at least they don't float around anymore
2021-06-15 03:27:52 +02:00
Daniel Gibson
633ce814ca r_lockSurfaces: Cleaner handling of view matrix creation etc 2021-06-15 03:27:52 +02:00
Daniel Gibson
907fc5771b Disable r_useScissor when r_lockSurfaces is active 2021-06-15 03:27:52 +02:00
Daniel Gibson
d17fa6b2b6 Fix rendering of ingame GUIs with r_lockSurfaces 1 2021-06-15 03:27:52 +02:00
Daniel Gibson
dcb933efb5 Fix rendering HUD with r_lockSurfaces 1
only override cmd->viewDef in RB_DrawView() if we're drawing the
primary view (which for several calculations before actual drawing
was set to the saved/locked render view)

Note that r_lockSurfaces is more useful with r_useScissor 0 (otherwise
there's black bars over the screen when moving) and r_shadows 0 (otherwise
areas that weren't visible when locking are black because the lights
there are skipped)

remaining bug: gui surfaces move around the screen when looking around
2021-06-15 03:27:52 +02:00
Daniel Gibson
1a6998781b Make r_locksurfaces kinda work
refs #357
2021-06-15 03:26:44 +02:00
Daniel Gibson
1aedbe7dd8 Fix build if libbacktrace is not installed, update README
set(CMAKE_REQUIRED_LIBRARIES backtrace) tells our custom libbacktrace
availability check that it needs to link against libbacktrace.
Seems like it also tells other unrelated compiler-checks like for
-fvisibility=hidden to link against libbacktrace, so if it's not
available they fail as well.
Fixed by unsetting CMAKE_REQUIRED_LIBRARIES after the backtrace check.

While debian-based distros ship libbacktrace as part of libgcc,
apparently in Arch Linux and openSUSE (and possibly others) it's a
separate package, so I mantion it in the README as an (optional)
dependency now and made CMake print a warning if it's not found.
2021-06-03 01:38:17 +02:00
Daniel Gibson
2521c3dfdb (Hopefully) better workaround for miscompiled cross products, #147
according to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100839
the real compiler flag enabling this bullshit isn't
-fexpensive-optimizations but -ffp-contract=fast which for some(*)
reason is default in optimized builds.
I think it's best to disabled that optimization globally in case it
also breaks other code (I really don't want to spend several days to
hunt such an idiot bug again). I really doubt it makes any measurable
performance difference.
As https://twitter.com/stephentyrone/status/1399424911328874499 says
that clang might also enable this in the future (though to =on instead
of =fast which should be a bit saner but would still break our code),
just set this option for all GCC-ish compilers incl. clang.

(*) the reason of course is that GCC developers don't develop GCC for
    their users but to win idiotic SPEC benchmarks
2021-05-31 21:37:31 +02:00
Daniel Gibson
320c15f63a Fix dmap bug if compiled with GCC and x86 FMA enabled
Only happend if `ONATIVE` was enabled (or some other flag was set
that enables the FMA extension), the root cause was that the cross
product didn't return 0 when it should, but a small value < 0.
Caused some faces to be missing in maps compiled with dmap.
https://github.com/RobertBeckebans/RBDOOM-3-BFG/issues/436#issuecomment-851061826
has lots of explanation.

I think this is a compiler bug, this commit works around it.

fixes #147
2021-05-31 02:03:46 +02:00
Daniel Gibson
0b28322500 Fix loading .ASE models with no materials
The "A Place of Malice" custom map has such a model which caused a crash
(models/z13sp2/temple/pushable_collision_box.ASE), see #382
2021-05-19 02:48:31 +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
HarrievG
e67b77ba5d - Wrapped GetDpiForWindow in GetWindowScalingFactor
- Use GetDeviceCaps for dpi on anything else than win10.
2021-05-10 01:09:47 +02:00
HarrievG
67d325cc61 update cmake
- Upped windows version ( needs to go back, and a runtime dpi check comes in place )
- Changed warning settings for msvc to confirm latest compilers
- Fixed up _afxdll
2021-05-10 01:09:47 +02:00
HarrievG
86866b73d5 - 4K / DPI aware Tool fixes
- Nullptr guard/Crashfix in material editor : meMainFrame can be null
  when starting immedeatly from commandline.
2021-05-10 01:09:47 +02:00
Daniel Gibson
981857f067 Fix PDAEditor (editPDAs opens it now), #378 2021-05-09 20:20:18 +02:00
Daniel Gibson
2dc2d3adb5 Fix "Save as" in Particle Editor
In idDeclManagerLocal::CreateNewDecl() decl->self->DefaultDefinition();
crashed because self was uninitialized.
Now it gets set to NULL in the constructor and initialized to something
sensible in decl->AllocateSelf();

this is part of #378
2021-05-08 21:05:56 +02:00
Daniel Gibson
5f137955ac Make rvGEWindowWrapper (for GUI editor) 64bit clean
it wants to store a pointer to itself in an idWinVar - on 32bit idWinInt
was suitable for that, on 64bit it's not, so instead convert the pointer
to a hex-string and stuff it in a idWinStr

also fix a crash when adding a choiceDef in the gui editor
2021-05-08 07:03:55 +02:00
Daniel Gibson
e1c9e7a351 MSVC: Treat pointer truncation warnings as errors, adjust idCVar for that
All pointer<->integer conversion truncation warnings I'm aware of are
now enabled for MSVC, to hopefully finally get that tool code 64bit-clean.

I had to adjust the idCVar code for this - it should've been safe enough
(highly unlikely that a valid pointer is exactly 0xFFFFFFFF on 64bit),
but triggered those warnings - now it should behave the same as before
but the warnings (which are now errors) are silenced.

The only thing that still prevents dhewm3 from building with these
warnings-as-errors is rvGEWindowWrapper
2021-05-08 05:54:42 +02:00
Daniel Gibson
5dc9b69374 Fix most (according to warnings) remaining 64bit issues in tool code
rvGEWindowWrapper is still TODO - it's not as straightforward, because
it insists on storing a pointer in an idWinVar (using idWinInt), but there
is no idWinVar type for pointers
2021-05-08 05:43:52 +02:00
raynorpat
bd37c3f91a Some additional LONG to LONG_PTR fixes for the tools as well as some warning fixes 2021-05-07 16:06:06 -04:00
raynorpat
d4c3d4a9df Resolve Win32-isms trying to build tools with x64 MSVC 2021-05-06 03:31:56 +02:00
Daniel Gibson
409dd8e3d9 Fix crash if both image_useCache and image_downSize are 1
the commented out code clamped the loaded filesize of affected .dds
images (crash observed with dds/guis/assets/splash/pdtempa.dds) to
200KB - but then later tries to load it and skip the first mipmap,
resuling in reading invalid memory (> 200KB into the file).
No idea what this was supposed to achieve, but it's disabled now
and the crash (at startup) is gone.

fixes #374
2021-04-28 00:04:24 +02:00
Daniel Gibson
5f346c7355 Add s_alReverbGain CVar to reduce intensity of reverb effects, fix #365
It can be set to a value between 0.0 and 1.0.
1.0 sounds like it did before introducing this cvar; as many people
found the the effect way to strong, I made 0.5 the default value
2021-04-27 20:08:59 +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
1b61053c53 idSoundSample::Load() uses s_decompressionLimit for oggs again
The code to decompress OGG files directly on load if they're shorter
than s_decompressionLimit seconds (usually 6) accidentally got broken
when removing the non-OpenAL soundbackends:
`if ( objectInfo.wFormatTag == WAVE_FORMAT_TAG_OGG )` slipped into the
`if ( objectInfo.wFormatTag == WAVE_FORMAT_TAG_PCM )` block - obviously
both can't be true at the same time so the OGG case was never executed.
Now it's in its own block again. I put it into a {} scope so it doesn't
have to be re-indented (=> more useful with git blame)
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
1ae268a20e Fix stb_vorbis failing to load .ogg files without comments
fix taken from https://github.com/nothings/stb/pull/1095
2021-04-27 20:08:59 +02:00
Daniel Gibson
c1c8de214a Add stb_vorbis so it can replace libogg/vorbis(file)
from https://github.com/nothings/stb/

renamed it from .c to .h so build systems don't get confused.
2021-04-27 20:08:59 +02:00
Daniel Gibson
b0e0883f6e Replace libjpeg with stb_image.h
libjpeg is a pain in the ass, especially due to Ubuntu shipping
libjpeg-turbo in jpeg8 mode as their default libjpeg, while every other
distro I checked (including debian!) ships libjpeg-turbo in jpeg6.2 mode

Thankfully stb_image.h exists - just a single header and it even
has a (much!) friendlier API.

It's not like Doom3 (or any of the mods I checked) actually use JPEGs,
but I'm sure if I'd drop support completely, someone would complain
(perhaps rightfully so).
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
13ac657ebf Make deleting listenerSlot in idSoundWorldLocal::Shutdown() work
the problem was that the sources were still associated to it, because
they get deleted after the listenerSlot: the sources get freed in
idSoundSystemLocal::Shutdown() which is called by
idCommonLocal::ShutdownGame() in line 3217,
while the listenerSlot is deleted via idSessionLocal::Shutdown()
-> delete sw/rw -> idSoundWorldLocal::~idSoundWorldLocal()
-> idSoundWorldLocal::Shutdown() - and idSessionLocal::Shutdown() is
called in idCommonLocal::ShutdownGame() line 3211, before the other.

I'm not gonna mess with the order of deleting things in ShutdownGame(),
but it's sufficient to unassociate the effect slot from the source
when destroying the emitters in idSoundWorldLocal::Shutdown(),
by adding a call for that to idSoundChannel::ALStop() - and destroying
the emitters before deleting listenerSlot.

Before this fix, with ALSOFT_LOGLEVEL=3 you got the following warning:
  (WW) Error generated on context 0x5578fce2a280, code 0xa004,
  "Deleting in-use effect slot 1"
Thanks for openal-soft's KittyCat for pointing this out!
2021-04-12 19:17:12 +02:00
Turo Lamminen
9c6b835f16 Fix uninitialized members of drawInteraction_t in RB_CreateSingleDrawInteractions 2021-04-12 19:13:39 +02:00
Turo Lamminen
cbd59321a8 Fix uninitialized members in idSoundWorldLocal 2021-04-12 19:13:39 +02:00
Daniel Gibson
81a8611aba
Merge pull request #342 from turol/warnings
Fix some warnings
2021-04-08 17:22:33 +02:00
Daniel Gibson
5adff43c6f Update ENGINE_VERSION to 1.5.2pre 2021-04-08 04:13:08 +02:00
Turo Lamminen
7aee2af217 Silence misleading indentation warnings 2021-03-15 13:02:45 +02:00
Turo Lamminen
8cfeb51b84 Silence an uninitialized variable warning 2021-03-15 13:02:45 +02:00
Turo Lamminen
1ae9ff7d74 Don't use memset to zero non-trivial type volumeIntegrals_t 2021-03-15 13:02:45 +02:00