Commit Graph

127 Commits

Author SHA1 Message Date
Azamat H. Hackimov
2c8081e832 Implement git-contributors.py
Add tool for creating credits file from git history.
2024-11-29 17:14:09 +03:00
Jan Engelhardt
0e6110e78b scripts: resolve 917 instances of -Wunused-variable
scripts/LEVEL0.cpp:1036:27: warning: unused variable "event_data" [-Wunused-variable]
and a lot more.
2024-11-03 23:39:38 +01:00
Jan Engelhardt
ab0e1c7f5b scripts: delete empty function bodies 2024-11-03 23:39:38 +01:00
Jan Engelhardt
7fa31b3aa3 scripts: consistent initialization of memory member
Some classes did set it to nullptr and others did not.
For the sake of consistency, initialize it explicitly everywhere.
2024-11-03 23:39:38 +01:00
Jan Engelhardt
b7838c1a85 scripts: replace in-constructor assignments by initializations 2024-11-03 23:39:37 +01:00
Jan Engelhardt
71772b9c9c Add "final" marker to a number of classes
Devirtualization is an optimization in the generated assembly: when a
class C is polymorphic but also final, ``((C *)ptr)->func()`` can be
turned from an indirect into a static call.
2024-11-03 23:39:37 +01:00
Jan Engelhardt
a58c2752e5 build: resolve 2107 instances of -Wdelete-non-virtual-dtor
scripts/Y2K.cpp:467:5: warning: deleting object of polymorphic class type
"LevelScript_0000" which has non-virtual destructor might cause undefined
behavior [-Wdelete-non-virtual-dtor]
  467 |     delete ((LevelScript_0000 *)ptr);
2024-11-03 23:39:37 +01:00
Azamat H. Hackimov
72e8347fe1 Move Descent3 built targets into "${CMAKE_BINARY_DIR}/build" directory
This solves problem of inability determine generated output directory of libraries targets. Now `add_custom_command()`, used on HOG generation, correctly locates all needed paths and not depends on generated variables.
2024-10-27 22:04:00 +03:00
Azamat H. Hackimov
39b205b957 Optimize building of HOG files and netgames libraries
Don't force building HOG files if dependency files are up-to-date.
Simplify building libraries by copying them into Descent3 directory.
2024-10-21 16:56:40 +03:00
Louis Gombert
770e9e8f22
Merge pull request #593 from jengelh/cxx17
build: work around compile failure under g++-9
2024-09-18 23:48:03 +02:00
Louis Gombert
b33cc21dce
Merge pull request #587 from winterheart/module-fixes
Update module, add logger module
2024-09-18 22:18:13 +02:00
Jan Engelhardt
85f640d0bb build: work around compile failure under g++-9
Under gcc-9 (e.g. used by Ubuntu 20.04), compilation fails with:

```
/usr/include/c++/9/variant: In instantiation of ‘constexpr const size_t std::variant_size_v<user_var>’:
/usr/include/c++/9/variant:1023:10:   required from ‘struct std::__detail::__variant::__gen_vtable<true, void, user_var::operator++(int)::<lambda(auto:22&&)>&&, user_var&>’
/usr/include/c++/9/variant:1656:23:   required from ‘constexpr decltype(auto) std::__do_visit(_Visitor&&, _Variants&& ...) [with bool __use_index = false; bool __same_return_types = true; _Visitor = user_var::operator++(int)::<lambda(auto:22&&)>; _Variants = {user_var&}]’
/usr/include/c++/9/variant:1672:29:   required from ‘constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...) [with _Visitor = user_var::operator++(int)::<lambda(auto:22&&)>; _Variants = {user_var&}; std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> = void]’
scripts/DallasFuncs.h:21:75:   required from here
/usr/include/c++/9/variant:94:29: error: incomplete type ‘std::variant_size<user_var>’ used in nested name specifier
   94 |     inline constexpr size_t variant_size_v = variant_size<_Variant>::value;
```

Judging from the date of P2162, calling std::visit with std::variant
derivatives is only specified for C++20 and onwards. But Descent3
only asks for C++17.

Since ``class user_var`` does not have any members that need would
need to be accessed via std::visit, we can "add a hint" and
explicitly specify the base type.
2024-09-18 22:15:41 +02:00
Azamat H. Hackimov
4f4ab3bd20 Isolate module submodule 2024-09-17 23:16:58 +03:00
Louis Gombert
f80fa0b518
Merge pull request #573 from jengelh/strict-aliasing
Resolve UBSAN strict aliasing reports
2024-09-16 20:44:59 +02:00
Azamat H. Hackimov
9ac702dcda
Merge pull request #569 from ccfly42/online-directip-netcon
Add Descent3 Online netcon
2024-09-15 23:07:38 +03:00
Christian Baumann
7501a5bcdc rename netcon 2024-09-15 13:19:26 +02:00
Jan Engelhardt
e867977543 scripts: resolve strict aliasing violations in level DLLs
$GIT/scripts/LEVEL15.cpp: In function ‘void aMatCenPuzzleInit()’:
$GIT/scripts/LEVEL15.cpp:833:38: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  833 | #define MagicMatCenSwitchSequence (*((int *)(&User_vars[17])))
$GIT/scripts/LEVEL15.cpp:834:25: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  834 | #define MatCenStateA (*((int *)(&User_vars[0])))
...
$GIT/scripts/Level6.cpp: In function ‘void aPriestKeyEnter(int)’:
$GIT/scripts/Level6.cpp:910:47: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  910 | #define Var_ThereIsPlayerInPriestKeyPuzzle (*((int *)(&User_vars[7])))

Turn ``User_var`` into an array of std::variant, the latter of which can hold
either float or int. Savegames do not carry the necessary type information
which variant (float/int) is in use; instead, this is statically decided by
the level DLL logic on a per-index basis. This approach is retained for now.

A lot of ``Var_something = 0`` is used despite Var_something being
logically used as float, so we need to override op= to keep the
variant type as-is.
2024-09-09 15:42:00 +02:00
Jan Engelhardt
b6ef3b591a build: avoid repeat compilation of DallasFuncs.cpp
Due to ``#include "DallasFuncs.cpp"``, DF is recompiled 52 times.
Rework it to build just once. The compile time goes down for me
from 1m45.3s to 1m38.8s on my 1135G7 CPU running make -j8.
2024-09-09 15:29:40 +02:00
Jan Engelhardt
90110e43e9 build: resolve include issue with osiris_import.h
The switcheroo involving OSIRISEXTERN is unnecessary; if it is empty,
it is "extern" anyway.

One function, ``osicommon_Initialize``, is present twice and can lead
to duplicate definitions in the linker stage, which is probably what
the DallasFuncs.cpp comment alluded to. It is moved away into its own
.cpp file.
2024-09-09 15:29:38 +02:00
Jan Engelhardt
006c2fb4ec build: split osiris_vector.h into header and implementation
Both e.g. AIGame3.cpp and DallasFuncs.cpp include
``osiris_vector.h``. Right now, this is not a problem because
DallasFuncs.cpp is not compiled itself, but included from
AIGame3.cpp, in other words, it is all just one translation unit.

I have a plan to do away with ``#include "DallasFuncs.cpp"``, which
means the linker invocation for AIGame3.so will have at least two
translation units, and thus two definitions of the osiris vector
functions, which is not allowed.

This also has the side-effect to reduce compile-time a little,
from 1m57.5s to 1m48.7s on my 1135G7 CPU using `make -j8`.
2024-09-09 14:57:44 +02:00
Jan Engelhardt
ea3f11b6b5 scripts: remove unused files
"lnx" is not mentioned anywhere in CMakeLists.txt, so it also does
not appear on the compiler command lines, which means it is wholly
unused.
2024-09-09 14:35:06 +02:00
Jan Engelhardt
7a53958617 scripts: delete extraneous prototypes in level15 code
I want to namespace the stuff in DallasFuncs.cpp, and when I do that,
there comes about an ambiguity between ``NewNamespace::aUserFlagSet``
and the ``::aUserFlagSet`` declared by LEVEL15 (also ``qUserFlag``).

Due to ``#include "DallasFuncs.cpp"``, LEVEL15.cpp already has a
declaration (and definition) for ``aUserFlagSet``, and so we can jsut
remove the two lines.
2024-09-09 12:55:27 +02:00
Jan Engelhardt
b7b2f1e9aa Delete unused fixed math functions
gcc warns about strict aliasing violations in fix.cpp:

fix/fix.cpp: In function "int FloatRound(float)":
fix/fix.cpp:157:14: warning: dereferencing type-punned pointer will
break strict-aliasing rules [-Wstrict-aliasing]
  157 |   return ((*((int *)&nf)) & 0x7FFFFF) - 2048;

But these functions and then some are unused, so delete them altogether.
2024-09-09 12:55:27 +02:00
Louis Gombert
9fcd4e7857
Merge pull request #558 from jengelh/crashes.2
Fix some 8 other game crashes [ASAN]
2024-09-07 21:57:49 +02:00
Christian Baumann
7ff07b137a init 2024-09-05 17:48:42 +02:00
Jan Engelhardt
5f0bdf8184 Fix spello "it's" 2024-09-03 13:26:51 +02:00
Jan Engelhardt
38b835a03b Fix spello "its" 2024-09-03 13:26:51 +02:00
Jan Engelhardt
a3a31c77a2 Fix spello "seperate.." 2024-09-03 13:26:51 +02:00
Jan Engelhardt
4d9ff9cdc6 Fix some one-off spellos 2024-09-03 13:26:51 +02:00
Jan Engelhardt
1c32732f59 Fix spello "wierd" 2024-09-03 13:26:51 +02:00
Jan Engelhardt
1036c3c677 Fix spello "targett" 2024-09-03 13:26:51 +02:00
Jan Engelhardt
edbde82918 Fix spello "agression" 2024-09-03 13:26:51 +02:00
Jan Engelhardt
ad9c2ba1d0 Fix spello "guarentee" 2024-09-03 13:26:51 +02:00
Jan Engelhardt
c3a6b1258c Resolve assertion when CollectorNomad2 dies
It is possible to cause the death of the CollectorNomad2 object (rush
to it before it possibly leaves again into the sidepackets the ship
won't fit through). The transition happens here:

```
f0  KillObject (objp=0x3d4d3e0 <Objects+384000>, killer=0x3cef7e0 <Objects>, damage=3) at /home/jengelh/D3/Descent3/damage.cpp:1036
f1  ApplyDamageToGeneric (hit_obj=0x3d4d3e0 <Objects+384000>, killer=0x3cef7e0 <Objects>, damage_type=6, damage=3, server_says=0, weapon_id=255) at /home/jengelh/D3/Descent3/damage.cpp:1401
f2  collide_generic_and_player (robotobj=0x3d4d3e0 <Objects+384000>, playerobj=0x3cef7e0 <Objects>, collision_point=0x7f877f40a830, collision_normal=0x7f877f40a858, f_reverse_normal=true, hit_info=0x7f877f40a810) at /home/jengelh/D3/physics/collide.cpp:2127
f3  collide_two_objects (A=0x3cef7e0 <Objects>, B=0x3d4d3e0 <Objects+384000>, collision_point=0x7f877f40a830, collision_normal=0x7f877f40a858, hit_info=0x7f877f40a810) at /home/jengelh/D3/physics/collide.cpp:2505
f4  do_physics_sim (obj=0x3cef7e0 <Objects>) at /home/jengelh/D3/physics/physics.cpp:1515
f5  ObjDoFrame (obj=0x3cef7e0 <Objects>) at /home/jengelh/D3/Descent3/object.cpp:2824
f6  ObjDoFrameAll () at /home/jengelh/D3/Descent3/object.cpp:2988
f7  GameFrame () at /home/jengelh/D3/Descent3/GameLoop.cpp:2980
f8  GameSequencer () at /home/jengelh/D3/Descent3/gamesequence.cpp:1221
f9  PlayGame () at /home/jengelh/D3/Descent3/game.cpp:834
f10 MainLoop () at /home/jengelh/D3/Descent3/descent.cpp:550
f11 Descent3 () at /home/jengelh/D3/Descent3/descent.cpp:508
f12 oeD3LnxApp::run (this=0x7f877f00db50) at /home/jengelh/D3/Descent3/sdlmain.cpp:151

<frame 2> (gdb) p robotobj
$1 = {
	type = 2 '\002' (OBJ_ROBOT), dummy_type = 255 '\377', id = 276,
	flags = 2135072, name = 0x5020000aff30 "CollectorNomad2",
	handle = 2432, next = 178, prev = -1,
	control_type = 1 '\001' (CT_AI), movement_type = 2 '\002' (MC_ROLLING),
	render_type = 1 '\001' (LRT_GOURAUD), lighting_render_type = 1 '\001', roomnum = 58,
	pos = {x = 2350.21484, y = -263.523956, z = 1868.59888},
	orient = {
		rvec = {x = 0.882905424, y = 1.63964216e-14, z = -0.469550878},
		uvec = {x = -1.25793295e-14, y = 1, z = 1.12662192e-14},
		fvec = {x = 0.469550878, y = -4.04037088e-15, z = 0.882905424}
	},...}
```

Thus, KillObject sets obj->control_type=CT_DYING. In the same game
tick, Level6.cpp then calls aAIGoalFollowPathSimple which triggers
the assertion.

```
Int3 in $GIT/Descent3/osiris_predefs.cpp at line 571.(Descent 3 Debug Break)

f0  osipf_AIGoalFollowPathSimple (objhandle=2432, path_id=21, guid=7, flags=1052928, slot=3) at $GIT/Descent3/osiris_predefs.cpp:571
f1  AI_GoalFollowPathSimple (objhandle=2432, path_id=21, guid=7, flags=1052928, slot=3) at $GIT/scripts/osiris_import.h:170
f2  aAIGoalFollowPathSimple (objhandle=2432, pathid=21, flags=1052928, goalid=7, priority=3) at $GIT/scripts/DallasFuncs.cpp:3649
f3  LevelScript_0000::CallEvent (this=0x5020000ba430, event=256, data=0x7f963e71d930) at $GIT/scripts/Level6.cpp:2465
f4  CallInstanceEvent (id=0, ptr=0x5020000ba430, event=256, data=0x7f963e71d930) at $GIT/scripts/Level6.cpp:2209
f5  Osiris_CallLevelEvent (event=256, data=0x7f963e71d930) at $GIT/Descent3/OsirisLoadandBind.cpp:2000
f6  GameFrame () at $GIT/Descent3/GameLoop.cpp:3020
f7  GameSequencer () at $GIT/Descent3/gamesequence.cpp:1221
f8  PlayGame () at $GIT/Descent3/game.cpp:834
f9  MainLoop () at $GIT/Descent3/descent.cpp:550
f10 Descent3 () at $GIT/Descent3/descent.cpp:508
f11 oeD3LnxApp::run (this=0x7f963e80db50) at $GIT/Descent3/sdlmain.cpp:151
```
2024-09-02 22:53:27 +02:00
Azamat H. Hackimov
32286ded46 Don't mix D3_RAND_MAX and rand()
rand() gives numbers in range [0, RAND_MAX] (INT_MAX, 0x7fffffff) while D3_RAND_MAX is only 0x7fff.
2024-09-02 16:19:15 +03:00
Azamat H. Hackimov
ddc6fd0857 Fix lightning effect probability
For lightning effect we using ps_rand() function which expects number in range [0, 0x7fff], but RAND_MAX is 0x7fffffff (INT_MAX, for 64-bit systems). In result lightnings strikes on every allowed frame and leads to epilepsy.
2024-09-02 16:07:36 +03:00
Jan Engelhardt
97eeab914b Resolve out-of-bounds access in _splitpath
Crash at the start of every level.

==43628==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x5020000c5a6f at pc 0x7efd39f3868a bp 0x7ffe5a39ec80 sp 0x7ffe5a39ec78
READ of size 1 at 0x5020000c5a6f thread T0
    f0 _splitpath(char const*, char*, char*, char*, char*) $GIT/scripts/linux_lib.cpp:37
    f1 InitializeDLL $GIT/scripts/level1.cpp:705
    f2 Osiris_LoadLevelModule(char*) $GIT/Descent3/OsirisLoadandBind.cpp:1095
    f3 InitLevelScript() $GIT/Descent3/Mission.cpp:1699
    f4 StartLevel() $GIT/Descent3/gamesequence.cpp:1622
    f5 LoadAndStartCurrentLevel() $GIT/Descent3/gamesequence.cpp:1675
    f6 GameSequencer() $GIT/Descent3/gamesequence.cpp:1197
    f7 PlayGame() $GIT/Descent3/game.cpp:834
    f8 MainLoop() $GIT/Descent3/descent.cpp:555
    f9 Descent3() $GIT/Descent3/descent.cpp:508
    f10 oeD3LnxApp::run() $GIT/Descent3/sdlmain.cpp:151

0x5020000c5a6f is located 1 bytes before 7-byte region [0x5020000c5a70,0x5020000c5a77)
allocated by thread T0 here:
    f0 strdup (/lib64/libasan.so.8+0xf68e0) (BuildId: 5615a04b8d0a5a8eafa661f7235e2d98fa2b9137)
    f1 Osiris_LoadLevelModule(char*) $GIT/Descent3/OsirisLoadandBind.cpp:1046
    f2 InitLevelScript() $GIT/Descent3/Mission.cpp:1699
    f3 StartLevel() $GIT/Descent3/gamesequence.cpp:1622
    f4 LoadAndStartCurrentLevel() $GIT/Descent3/gamesequence.cpp:1675
    f5 GameSequencer() $GIT/Descent3/gamesequence.cpp:1197
    f6 PlayGame() $GIT/Descent3/game.cpp:834
    f7 MainLoop() $GIT/Descent3/descent.cpp:555
    f8 Descent3() $GIT/Descent3/descent.cpp:508
    f9 oeD3LnxApp::run() $GIT/Descent3/sdlmain.cpp:151
2024-08-31 12:13:44 +02:00
Azamat H. Hackimov
79db9aa3e2 Move platform-specific defines and macros to own file crossplat.h 2024-08-20 23:09:27 +03:00
Thomas Roß
7b71873a69 [Cleanup] Removed function declarations that are not implemented. 2024-08-20 20:03:02 +02:00
thfrwn
35bcbe8bf0 build on OpenBSD via Linux pathways 2024-08-20 10:03:24 -04:00
Louis Gombert
60c5dbf1fe CMake: add all headers to target sources
This can help with CMake IDE integration and file indexing.
2024-08-09 17:09:14 +02:00
C.W. Betts
1384aa62af Quiet warnings about uninitialized values. 2024-07-31 15:40:16 -06:00
Chris Sarbora
3da53e567f
Programmatically replace all __LINUX__ with POSIX
Steps:
```sh
srcs=$(mktemp)
find . -name "*.cpp" -or -name "*.c" -or -name "*.h" -or -name "*.hpp" -or -name "*.cc" -or -name "*.hh" > $srcs
xargs sed -i 's/ifndef __LINUX__/if !defined(POSIX)/' < $srcs
xargs sed -i 's/ifdef __LINUX__/if defined(POSIX)/' < $srcs
xargs sed -i 's/defined(__LINUX__)/defined(POSIX)/' < $srcs
```
2024-07-12 18:11:54 -05:00
Thomas Roß
12ec7c50c7 [CMake] Enabled the CMake property USE_FOLDERS to provide a more structured project list in IDEs with the help of set(CMAKE_FOLDER "...") calls. 2024-07-03 19:55:04 +02:00
Thomas Roß
d55dc5c321 [Scripts] Fixed 100 warnings of type C4101 'foo': unreferenced local variable, since this cpp file gets included in alot of scripts. 2024-06-29 21:50:50 +02:00
Azamat H. Hackimov
59487976f6 Isolate misc module
Isolate misc module for better dependency handling.
2024-06-27 01:26:35 +03:00
GravisZro
f7ae658fe2 Modernize struct/enum/unions type declarations 2024-05-30 03:35:17 -04:00
GravisZro
9cf9781369 Properly format/use variadic macros 2024-05-24 20:57:17 -04:00
GravisZro
dc91b22635 Fix rebase breakage 2024-05-24 09:13:36 -04:00
GravisZro
ec73d3fe1f Remove excess stricmp definitions 2024-05-24 08:53:02 -04:00