Commit graph

324 commits

Author SHA1 Message Date
Daniel Gibson
f18f7a0b45 CMake: Detect all variations of the clang compiler (hopefully)
According to
https://cmake.org/cmake/help/v3.26/variable/CMAKE_LANG_COMPILER_ID.html
there's at least "Clang" (plain LLVM clang), "AppleClang", "ARMClang",
"FujitsuClang", "XLClang" and "IBMClang" (both of which are variations
of the clang/llvm-based IBM XL compiler).

This should detect all of them (I hope they all behave close enough
to normal clang to work..)

There's also "IntelLLVM", but I have no idea if that's based on Clang
or does its own thing based on LLVM.. I also doubt dhewm3 will ever
be built with any other clang-derivate than "Clang" and "AppleClang" :-p

fixes #510
2024-03-19 03:13:37 +01:00
Daniel Gibson
053749f1ae 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 (NOTE: the sys/platform.h part was merged
 in "Sync sys/platform.h, incl. Workaround for MCST-LCC compiler").
2024-03-19 03:13:37 +01:00
Daniel Gibson
b41b2c4072 CMake: Add GCC/clang-specific options: ASAN, FORCE_COLORED_OUTPUT
-DASAN=ON   enables the Address Sanitizer (ASan), if supported
-DFORCE_COLORED_OUTPUT=ON  forces GCC or Clang to use colors in their
                           messages, useful when building with ninja

Both options default to OFF (though when building with make in a
suitable terminal, GCC and clang automatically use colors)

(no UBSAN, that requires hardlinking the game with the executable,
 which is not possible in the SDK..)
2024-03-19 03:13:37 +01:00
Daniel Gibson
fc5ac15073 merge sys_public.h changes for gamepad support
not sure if any of this is relevant for mods, but shouldn't hurt..
2024-03-18 23:21:41 +01:00
Daniel Gibson
2cab4f8dce Sync sys/platform.h, incl. Workaround for MCST-LCC compiler
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-03-18 23:21:41 +01:00
Daniel Gibson
eb6624fb41 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-18 23:21:41 +01:00
Daniel Gibson
67a07873b4 Fix MSVC non-Release builds (_alloca()/assert() didn't play nice) 2024-03-18 23:21:41 +01:00
James Addison
af3eb70f01 Fixup: typo: 'hiehgt' -> 'height' in a few places around the codebase 2024-03-18 23:21:41 +01:00
Daniel Gibson
3bc7e6f30e Fix/work around other misc. compiler warnings
or, in the case of AF.cpp, at least comment on them

I think this fixes most of the remaining "interesting" GCC 12 on Linux
warnings
2024-03-18 23:21:41 +01:00
Daniel Gibson
af8e8bda20 Fix date/time handling in idParser::ExpandBuiltinDefine()
this was so broken, I think if anyone ever tried to use __DATE__ or
__TIME__ it must've crashed, either from free(curtime) (which was the
return value of ctime()) or from things like token[7] = NULL when token
was a pointer (to a single element!).

I think it could work now.

Also fixed potential memory leaks in cases that don't "return" anything
2024-03-18 23:21:41 +01:00
Daniel Gibson
531f803a02 Work around false positive GCC -W(maybe-)uninitialized warnings
shouldn't hurt too much, and the R_IssueEntityDefCallback() code
even is a bit better now
2024-03-18 23:21:41 +01:00
Daniel Gibson
7ce03ea2a6 Fix GCC -W(maybe-)uninitialized warnings that at least kinda had a point 2024-03-18 23:21:41 +01:00
Daniel Gibson
06e2a1568e Don't use "register" keyword, it was deprecated in C++11
.. and even removed in C++17 - and before that it probably didn't do
much in most compilers
2024-03-18 23:21:41 +01:00
Daniel Gibson
c9f841d058 Fix -Wformat-security warnings - thanks James Addison!
This is based on https://github.com/dhewm/dhewm3/pull/500
by https://github.com/jayaddison

See also https://github.com/blendogames/quadrilateralcowboy/pull/4
2024-03-18 23:21:41 +01:00
Daniel Gibson
46d22b885d Fix renderlights loaded from savegames aliasing other lights
Some entities wrote the handle from gameRenderWorld->AddLightDef()
into savegames and reused it after restoring it.
That's a bad idea, because at that point the handle most likely belongs
to something else (likely some idLight). The most visible issue this
can create is that the flashlight may not work correctly after loading
a savegame with flashlight on, when it happens to alias a light that's
updated each frame to (mostly) being off..

The correct way to handle this (THAT FOR SOME REASON WAS ALREADY
IMPLEMENTED IN D3XP BUT NOT THE BASE GAME - WHY?!) is to get a fresh
handle with AddLightDef() when restoring a savegame - unless the handle
was -1, which means that the light didn't exist when saving.

fixes #495
2024-03-18 23:21:41 +01:00
Daniel Gibson
6de9575189 Fix some ubsan warnings 2024-03-18 23:21:41 +01:00
Daniel Gibson
1ae47bf5a1 StartSoundShader() event: special-case for soundName "", refs #494
Some level scripts in d3xp (erebus4, erebus4, phobos2) use
  $entity.startSoundShader( "", SND_CHANNEL_BODY );
(or whatever channel) to stop the sound currently playing there.
With s_playDefaultSound 1 that results in a beep..
Added a special case to that event implementation to call StopSound()
instead when the soundName is "" (or NULL)
2024-03-18 23:21:41 +01:00
Daniel Gibson
71629a8d6a Scale crosshair to 4:3
so it's round in widescreen resolutions
2022-05-28 23:23:40 +02:00
Daniel Gibson
ae2dd3f58c Improve some messages in game code
- TestHugeTranslation() prints positions (and asserts only afterwards),
  from "Work around assertion in alphalabs4, fix #409"
- idCompiler::CompileFile() prints proper filename
  from "Fix usage of invalid pointer in idCompiler::CompileFile()"
2022-05-28 20:59:21 +02:00
Daniel Gibson
477f87ba8c Use idStr::Copynz() instead of strncpy()
to guarantee \0-termination
(only the applicable parts of that dhewm3 commit)
2022-05-28 20:59:21 +02:00
Daniel Gibson
03ef87b11e From dhewm3: Fix most (according to warnings) remaining 64bit issues in tool code
only the TypeInfo changes are applicable to the SDK
2022-05-28 20:59:21 +02:00
Daniel Gibson
b3bc2cb8a9 Remove usage of C++11 nullptr 2022-05-28 20:59:21 +02:00
Daniel Gibson
2752ffd0bb renderer/RenderSystem.h: Changes from dhewm3
only affect glconfig_t which I don't think any mod should use
2022-05-28 20:59:21 +02:00
Daniel Gibson
5f92e27ec7 Add D3_(v)snprintfC99() for C99-compatible implementations
These are now used by idStr::(v)snPrintf(), and in the future can
be used if a (v)snprintf() that's guaranteed not to call
common->Warning() or similar is needed (e.g. used during early startup)
2022-05-28 20:59:21 +02:00
Daniel Gibson
31a3dec004 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
2022-05-28 20:59:21 +02:00
Daniel Gibson
2ecebb7a07 Make sure MAX_OSPATH has sane size 2022-05-28 20:59:21 +02:00
Daniel Gibson
a28aea1a2d From dhewm3: Add absolute mouse mode and refactor mouse grabbing code
The only change really is adding SE_MOUSE_ABS to sysEventType_t.
In theory this breaks the ABI, but in practice I don't think mods use
sysEventType_t, and certainly not the ones above SE_MOUSE
(SE_JOYSTICK_AXIS doesn't make sense as Doom3 never supported Joysticks,
 SE_CONSOLE is for input from TTY or whatever, and doesn't make sense
 for mods to use in any way)

The change in Stub_SDL_endian.h is just me being paranoid.
(side-note: it *might* make sense to replace all that inline-asm in
 Stub_SDL_endian.h with compiler intrinsics like GCC/clangs
 __builtin_bswap* and MSVCs _byteswap_* - if they are supported in
 all relevant compiler versions. GCC supports 32 and 64 bit swaps since
 4.3, 16bit since 4.8 and 128bit since 11.x; clang supports 32 and
 64 bit swaps at least since 3.0 and 16bit swaps since 3.2;
 VS introduced _byteswap_ushort, .._ulong and .._uint64 in VS2003)
2022-05-28 20:59:21 +02:00
Daniel Gibson
d1d32f7166 CMake: Fix D3_ARCH, theoretically support Windows on ARM
working around CMake (specifically CMAKE_SYSTEM_PROCESSOR) being useless
and related commits ported from dhewm3, up to including
"CMake: Fix typo in MSVC-specific CPU detection for x64"
2022-05-28 20:59:21 +02:00
Daniel Gibson
3cc7ea926a Port CMake changes from dhewm3 (up to "Fix runtime assert on PPC OS X")
- (Hopefully) better workaround for miscompiled cross products, #147
  (-ffp-contract=off)
- GCC/Clang: Remove -fno-unsafe-math-optimizations
  (redundant as long as -ffast-math isn't used)
- Fix runtime assert on PPC OS X
  (-mone-byte-bool)
2022-05-28 20:59:21 +02:00
Daniel Gibson
fd598744cd 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.
2022-05-28 20:59:21 +02:00
Turo Lamminen
a8cbb466fc Silence an uninitialized variable warning 2022-05-28 20:59:21 +02:00
Turo Lamminen
121ae195d9 Several commits about memcpy() and memset() from turol in idlib squashed
"Don't use memcpy in idMat2 constructor" up to "Don't use memset to zero
non-trivial type volumeIntegrals_t" from Turo Lamminen (in orig dhewm3
repo)
2022-05-28 20:59:21 +02:00
yamir
d208d24b29 Fix ppc64le build 2022-05-28 20:59:21 +02:00
Daniel Gibson
f45b3c270e Fix Win32/VS build on Win64 hosts
Turns out that ${CMAKE_SYSTEM_PROCESSOR} is broken on Windows
(both for Visual Studio and for 32bit MinGW/msys shells which for some
 reason seem to output x86_64 in uname -a)
2021-02-22 05:22:36 +01:00
Daniel Gibson
2bd963b986 Fix player's clipModel->axis when loading savegame, fixes #328
idClipModel::axis is an idMat3 rotation matrix.
Usually it's an identity matrix, but if the player is pushed around by
an idPush entity it's modified and apparently can (wrongly) remain
modified, possibly when saving while idPush is active.
This seems to happen sometimes on the crashing elevator in game/delta1.
The fix/workaround is to reset it to mat3_identity when loading a
savegame.
2021-02-22 05:22:36 +01:00
Daniel Gibson
3bbe350f48 Add information about dhewm3 build to savegames
like the dhewm3 version and the OS and architecture of the dhewm3
version that created the savegame.
Also added an internalSavegameVersion so be independent of BUILD_NUMBER

fixes #344
2021-02-22 05:22:36 +01:00
Daniel Gibson
5989233ed6 Fix savegame-compatibility of scripts, increase BUILD_NUMBER
"Fix "t->c->value.argSize == func->parmTotal" Assertion in Scripts, #303"
had broken old savegames because the script checksum
(idProgram::CalculateChecksum()) changed, see #344.
This is fixed now, also the BUILD_NUMBER is increased so old savegames
can be identified for a workaround.

Don't use this commit without the next one which will further modify the
savegame format (for the new BUILD_NUMBER 1305)
2021-02-22 05:22:36 +01:00
Daniel Gibson
ed4a6ca6e4 Enable building on Apple Silicon
(based on the commit from Petter Uvesten in the main dhewm3 repo)
2021-01-18 03:42:58 +01:00
Daniel Gibson
02f49e55bf Suppress GCC8+ warnings about memcpy()/memset() on classes
.. with "no trivial copy-assignment".
All the cases I checked were harmless; as long as a class has no vptr
or owns memory (or other resources) that need to be handled properly
in the destructor, memcpy() and memset() aren't too dangerous.
2021-01-18 03:42:58 +01:00
Daniel Gibson
8ff66b7eab Fix "t->c->value.argSize == func->parmTotal" Assertion in Scripts, #303
If a "class" (object) in a Script has multiple member function
prototypes, and one function implementation later calls another before
that is implemented, there was an assertion when the script was parsed
(at map start), because the size of function arguments at the call-site
didn't match what the function expected - because the function hadn't
calculated that size yet, that only happened once its own
implementation was parsed.
Now it's calculated (and stored) when the prototype/declaration is
parsed to prevent this issue, which seems to be kinda common with Mods,
esp. Script-only mods, as the release game DLLs had Assertions disabled.
2021-01-18 03:42:58 +01:00
Daniel Gibson
e957bd3460 Disable broken idSIMD_SSE::UpSampleOGGTo44kHz()
It corrupted the stack when called with buffers allocated on the stack
and numSamples that are not a multiple of four, apparently, by writing
4 floats too many, at least in the 22KHz Stereo case..

This caused the crash described in
  https://github.com/dhewm/dhewm3/issues/303#issuecomment-678809662

Now it just uses the generic C code, like all platforms besides MSVC/x86
already do.
2021-01-18 03:42:58 +01:00
Daniel Gibson
273b1d4a4f Fix lingering messages in HUD after loading savegame
If you save, you get a message like "Game Saved..." which goes away
after a few seconds. This happens at the very end of idPlayer::Save():
    if ( hud ) {
        hud->SetStateString( "message", /* .. left out .. */ );
        hud->HandleNamedEvent( "Message" );
    }
And handled in hud.gui, "onNamedEvent Message { ..."

However, if you save again before it's gone, it'll be shown after
loading the savegame and not go away until you save again..
This works around that issue by setting an empty message after
loading a savegame.

The underlying problem (which is not fixed!) seems to be that the
transition GUI command (that's executed when hud.gui handles the
"Message" event that's used to show this message) is probably not
properly saved/restored so fading out the message isn't continued
after loading.
2021-01-18 03:42:58 +01:00
Daniel Gibson
cad0660add Fix handling of paths with dots in dir names, fix #299, #301
idStr::StripFileExtension() (and SetFileExtension() which uses it) and
others didn't work correctly if there was a dot in a directory name,
because they just searched from last to first char for '.', so if the
current filename didn't have an extension to cut off, they'd just cut
off at any other '.' they found.
So D:\dev\doom3.data\base\maps\bla could turn into D:\dev\doom3
(or, for SetFileExtension(), D:\dev\doom3.map)

While at it, I made most of the idStr code that explicitly checked for
'\\' and '/' (and maybe ':' for AROS) use a little
"bool isDirSeparator(int c)" function so we don't have the #ifdefs
for different platforms all over the place.
2021-01-18 03:42:58 +01:00
Daniel Gibson
912f2d6dd7 ID_MAYBE_INLINE for not-forced inlining
On Windows, ID_INLINE does __forceinline, which is bad if the function
calls alloca() and is called in a loop..
So use just __inline there so the compiler can choose not to inline
(if called in a loop).
This didn't cause actual stack overflows as far as I know, but it could
(and MSVC warns about it).

(This includes "Fix ID_MAYBE_INLINE on non-Windows platforms")
2021-01-18 03:42:58 +01:00
Daniel Gibson
c921508eef MSVC: Shut up Compiler warning in Matrix.h if asserts are disabled 2021-01-18 03:42:58 +01:00
Daniel Gibson
a9f0df28c0 Port CMake-changes that were added to dhewm3 since the SDK was created
Make source files listing in VS usable (incl. fallback for old CMake)
CMake: Fix build in path with spaces
2021-01-18 03:42:58 +01:00
Daniel Gibson
ddc635a03c Hopefully fix "shooting arrows at Dead Souls" freezing game (Rivensin)
For some reason the idMoveableArrow's animator didn't have a modelDef,
which caused masterAnimator->GetJointTransform() to return immediately
without setting masterAxis or masterOrigin - so they contained garbage
data which lead to NaNs which lead to trouble.

I check for that issue now to make sure they're initialized, but I'm not
100% sure this is a proper fix - the underlying issue is that this
animator has no modelDef. Is that bad? Could it create other issues?
No idea.
2021-01-18 03:42:58 +01:00
Daniel Gibson
4c6341ed3d idProjectile::Launch() warns about missing snd_tracer 2021-01-18 03:42:58 +01:00
Daniel Gibson
522a8fc330 Bugfix from Rivensin: idAnimState::Save() checks if(animator != NULL)
at least in Rivensin this caused crashes, possible that it causes
trouble here as well (Rivensin is based on Dentonmod after all)
2021-01-18 03:42:58 +01:00
Daniel Gibson
4a2d4751ac (Hopefully) fix one of the assertions rarely happening in Rivensen
I hope I guessed this right: This could prevent the rare assertion
in RenderWorld.cpp:954 ("bounds[0][0] <= bounds[1][0]
  && bounds[0][1] <= bounds[1][1] && bounds[0][2] <= bounds[1][2]").
2021-01-18 03:42:58 +01:00