Commit graph

320 commits

Author SHA1 Message Date
Daniel Gibson
481e0e84ff 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-19 00:51:40 +01:00
Daniel Gibson
0a3d0f50e2 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-19 00:51:40 +01:00
Daniel Gibson
9104ed2151 Fix some ubsan warnings 2024-03-19 00:51:40 +01:00
Daniel Gibson
15a0711c30 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-19 00:51:40 +01:00
Daniel Gibson
5717894b6c 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()"
2024-03-19 00:51:40 +01:00
Daniel Gibson
a62a799b14 Use idStr::Copynz() instead of strncpy()
to guarantee \0-termination
(only the applicable parts of that dhewm3 commit)
2024-03-19 00:51:40 +01:00
Daniel Gibson
c336410ca5 From dhewm3: Fix most (according to warnings) remaining 64bit issues in tool code
only the TypeInfo changes are applicable to the SDK
2024-03-19 00:51:40 +01:00
Daniel Gibson
c2a1e095d7 Remove usage of C++11 nullptr 2024-03-19 00:51:40 +01:00
Daniel Gibson
c31c916f18 renderer/RenderSystem.h: Changes from dhewm3
only affect glconfig_t which I don't think any mod should use
2024-03-19 00:51:40 +01:00
Daniel Gibson
877c187d16 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)
2024-03-19 00:51:40 +01:00
Daniel Gibson
b2f4c0034a 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
2024-03-19 00:51:40 +01:00
Daniel Gibson
a88f467e5f Make sure MAX_OSPATH has sane size 2024-03-19 00:51:40 +01:00
Daniel Gibson
0258e2c328 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)
2024-03-19 00:51:40 +01:00
Daniel Gibson
6319db6df1 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"
2024-03-19 00:51:40 +01:00
Daniel Gibson
110a6d1948 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)
2024-03-19 00:51:39 +01:00
Daniel Gibson
500756c89a 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.
2024-03-19 00:51:39 +01:00
Turo Lamminen
594c3a23b7 Silence an uninitialized variable warning 2024-03-19 00:51:39 +01:00
Turo Lamminen
a51e99edd0 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)
2024-03-19 00:51:39 +01:00
yamir
4b00b1c6f7 Fix ppc64le build 2024-03-19 00:51:39 +01:00
Daniel Gibson
5f06d75954 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)
2024-03-19 00:51:39 +01:00
Daniel Gibson
239dfabbe1 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.
2024-03-19 00:51:39 +01:00
Daniel Gibson
8a23010abb 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
2024-03-19 00:51:39 +01:00
Daniel Gibson
2ea4371c91 Add explicit Doom3[CC] copyright notice 2021-07-05 23:53:24 +02:00
Daniel Gibson
b74a02dcc1 Enable building on Apple Silicon
(based on the commit from Petter Uvesten in the main dhewm3 repo)
2021-01-18 02:56:22 +01:00
Daniel Gibson
12ea612114 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 02:56:22 +01:00
Daniel Gibson
a91eb7a6a2 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 02:56:22 +01:00
Daniel Gibson
c747a95782 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 02:56:22 +01:00
Daniel Gibson
6e999ee9e3 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 02:56:22 +01:00
Daniel Gibson
e9b3e09d24 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 02:56:22 +01:00
Daniel Gibson
9897c81573 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 02:56:22 +01:00
Daniel Gibson
43681aa64e MSVC: Shut up Compiler warning in Matrix.h if asserts are disabled 2021-01-18 02:56:22 +01:00
Daniel Gibson
3eb97e11dc Increase Script MAX_GLOBALS in game/
It's the same value d3xp uses and thus probably a better default for
mods.
2021-01-18 02:56:22 +01:00
Daniel Gibson
7464570b21 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 02:56:22 +01:00
Daniel Gibson
514749c30e Add documentation for integrating Doom3[CC] C++ code 2020-01-27 01:30:11 +01:00
Daniel Gibson
038a9629a9 Clean CCBst.* up a little bit
fixes indenting, small code improvements, only very little testing
2020-01-23 21:27:18 +01:00
Daniel Gibson
7cef835ca7 Initialize some variables, several TODOs
seems to kinda work though
2020-01-23 21:19:34 +01:00
Daniel Gibson
21cfdc877a integrated doom3cc code
builds (on Linux), but untested
2020-01-23 21:17:25 +01:00
Daniel Gibson
c198d4ebeb
README: formatting 2019-01-05 06:46:40 +01:00
Daniel Gibson
f264b09915
README: Document dhewm3 specific stuff for Mods GUIs
* injecting resolution list into menus
* scaling WIN_DESKTOP GUIs to 4:3
2019-01-05 06:45:01 +01:00
Daniel Gibson
6dcc4ce912
README: Mention how to set build type on Unix 2019-01-05 06:16:14 +01:00
Daniel Gibson
cffcb77038
README: Howto build on Windows 2019-01-05 02:17:03 +01:00
Daniel Gibson
7b4b2a8684 Add first element (FT_IsDemo) to enum idCommon::FunctionType
GetAdditionalFunction() will return a function that returns true
if we're running the Doom3 demo version.

Not really relevant for mods, but I use this to enable some
Demo-specific hacks/workarounds in base.dll
Adding this here anyway to make sure the next function type added will
get another ID (maybe 2).
2019-01-04 20:29:38 +01:00
Daniel Gibson
b7d77c468a
README: Mention Fitz, link 1.5.0 binary downloads 2018-12-16 04:04:57 +01:00
Daniel Gibson
00472d7286 CMake 2.8 is sufficient
this way I can build it in my wheezy chroot for release binaries
without upgrading cmake there.
2018-12-15 05:35:12 +01:00
Daniel Gibson
85a1020490 Fix pot. Crash in idWinding2D::ExpandForAxialBox()
it could happen that i is 1 but numPlanes is still 0
(=> if for i = 0:  ( p[j] - p[i] ).LengthSqr() < 0.01f )
so planes[-1] would be accessed which of course is invalid and can crash
2018-12-09 04:23:41 +01:00
Daniel Gibson
5b3d99275f
link rivensin in the README 2018-11-29 01:45:23 +01:00
Daniel Gibson
48d83d0e6f
Link Win32 binaries from 1.5.0RC1 2018-11-12 04:09:48 +01:00
Daniel Gibson
e040194cfa README: Make existing mods its own section so it's more visible 2018-11-12 00:25:08 +01:00
Daniel Gibson
fb0708fad4 change engine version to "dhewm3 SDK 1.5.x"; no -ffast-math
it's only shown in the g_version CVar, but if we have this constant
in the SDK make it show something sensible.. and this SDK code should
be compatible with all dhewm 1.5.x releases (=> dhewm3 version will
be bumped to 1.6.x if game API compatibility is broken)

Also disabled (GCC/Clang-specific) -ffast-math - even with
 -fno-unsafe-math-optimizations I don't trust it.
2018-11-12 00:21:13 +01:00
Daniel Gibson
6d3b26e2fc idCommon::SetCallback() + GetAdditionalFunction(); GAME_API_VERSION=9
This is an ugly hack that allows both exporting additional functions
(incl. methods via static function + void* userArg) to Game DLLs
and setting callback functions from the Game DLL that the Engine will
call, without breaking the Game API (again after this change).
This is mostly meant for replacing ugly hacks with SourceHook and
similar and mods (yes, this is still an ugly hack, but less ugly).

See the huge comment in Common.h for more information.

Right now the only thing implemented is a Callback for when images
are reloaded (via reloadImages or vid_restart) - Ruiner needs that.

Also increased GAME_API_VERSION to 9, because this breaks the A[PB]I
(hopefully after the next release it won't be broken in the foreseeable
 future)
2018-09-30 05:43:42 +02:00