Commit graph

1740 commits

Author SHA1 Message Date
Kp ddc25b59b7 Explicitly zero-initialize object structure members
C++17 will require this in order for `object::object()` to be constexpr.
Add it here, before switching over.
2020-05-02 21:18:42 +00:00
Kp df19889f61 Prefer NSDMI over simple default constructors
This protects against mistakes if more constructors are added, and makes
the code easier to read.
2020-04-26 17:26:23 +00:00
Kp a431f23817 Use enumerated constant for save slot indexes 2020-04-26 17:26:23 +00:00
Kp b396445efa Require support for std::index_sequence, std::make_index_sequence
The minimum supported compiler versions now provide a depth-efficient
implementation of std::make_index_sequence, which removes the last
reason to carry a private implementation.  In the case of clang, it
appears to have a special compiler intrinsic used to implement its
std::make_index_sequence.

Switch to the compiler-provided version for both gcc and clang.
2020-04-26 17:26:23 +00:00
Kp 5fa8c06914 Add experimental support for autosaves
Set autosave interval to 10 minutes, unless specified in the player's
configuration file.  Players can change the autosave to 0 minutes to
disable it.
2020-04-19 20:47:07 +00:00
Kp a1b3a86cba Use std::chrono::duration for ThisLevelTime, PlayTimeAllowed
Store PlayTimeAllowed in ticks since it is frequently accessed for logic
tests, but only rarely accessed for display.
2020-04-19 20:47:07 +00:00
Kp 714c13b3c1 Move WallAnims into d_game_shared_state 2020-04-04 19:30:22 +00:00
Kp a645fd2eba Allocate morph_data vectors dynamically
This greatly reduces the size of morph_data for most uses.
2020-02-26 05:07:34 +00:00
Kp 85a9034137 Move morph_data::morph_deltas into a trailing allocation
Initially, this just makes the code more complicated.  In the end, it
will allow choosing the array size dynamically.
2020-02-26 05:07:34 +00:00
Kp 73612f6667 Move morph_data::morph_vecs into a trailing allocation
Initially, this just makes the code more complicated.  In the end, it
will allow choosing the array size dynamically.
2020-02-26 05:07:34 +00:00
Kp 74f8fd0d4d Move morph_data::morph_times into a trailing allocation
Initially, this just makes the code more complicated.  In the end, it
will allow choosing the array size dynamically.
2020-02-26 05:07:34 +00:00
Kp 00df407381 Use a custom allocation for morph_data
This will enable shrinking the morph arrays to allocate only what is
needed.
2020-02-26 05:07:34 +00:00
Kp d4c48d80b5 Fix some failures in check_header_includes=1 builds 2020-02-26 05:07:34 +00:00
Kp 707df7b9de Move some newdemo functions into namespace dsx 2020-02-26 05:07:34 +00:00
Kp fd134851d1 Pass context to morph_start 2020-02-26 05:07:34 +00:00
Kp aaaf212dca Add unit test for zip iterator 2020-02-26 05:07:34 +00:00
Kp 94401b4085 Pass LevelUniqueMorphObjectState to find_morph_data 2020-02-26 05:07:34 +00:00
Kp 40726aa580 Mark xrange as returning unowned storage
It returns integers by value, not by reference.
2020-02-26 05:07:34 +00:00
Kp 3f7149a346 Simplify text decoding 2020-02-11 04:48:14 +00:00
Kp 88087fbbab Move Text_string to dsx 2020-02-11 04:48:14 +00:00
Kp 669c341147 Move d_level_unique_morph_object_state to d_level_unique_object_state 2020-02-01 22:33:31 +00:00
Kp cac5f1da56 Move morph_data into dynamic allocations
This improves poison detection, and eliminates some large static
allocations (MAX_VECS * ((2 * vms_vector) + fix)).
2020-02-01 22:33:31 +00:00
Kp c55c7d1bd6 Move morph_data to dcx
Only one member was part of dsx, and it could be dcx instead.
2020-02-01 22:33:31 +00:00
Kp 0aaa263adf Use enum class for morph_data submodel_state
Name the state members, instead of using magic constants.  Also, switch
from `int` to `uint8_t`, since there are only 3 valid values.
2020-02-01 22:33:31 +00:00
Kp 003fb2697b Use uint8_t for morph_data::n_submodels_active
The array it controls is only 10 elements long.  uint8_t can easily
represent all valid indices.
2020-02-01 22:33:31 +00:00
Kp 5653124a43 Move MAX_VECS into morph_data 2020-02-01 22:33:31 +00:00
Kp 1a2cfa35ba Fix saving/loading games for missions in subdirectories
The historical savegame format cannot support finding a mission in a
subdirectory.  Add a backwards-incompatible modification to store the
full path in the savegame, and store it in a way that old versions will
fail gracefully.[1]  When loading demos, or legacy savegames, search for
the mission in all available directories.  Demos are still written with
an unqualified path because the demo loading code would crash if given
an oversized path.  Mission names sent over the network as part of
multiplayer use the guess logic now, so that guests do not need to have
the mission in the same path as the host.

[1] Versions affected by issue #486 may fail ungracefully.

Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/491>
2020-01-18 21:57:39 +00:00
Kp 3e2d47f879 Track mission type correctly when loading mission list
- In D2X, do not accept Descent2-specific directives from Descent 1
  `.msn` files.
- Set the descent_version field correctly in the `mle`.  Previously,
  `.msn` was set to descent1 and all `.mn2` were set to descent2,
  regardless of whether the `.mn2` used `name`, `xname`, `zname`, or
  `!name`.
- Avoid rewinding the file and rereading the same line while checking
  the possible name types.
- Avoid recomputing end-of-string when it is already known.
- Avoid re-reading the mission file's version when the mission is
  chosen.  Instead, use the version that was recorded when the mission
  was loaded into the mission list.  This also fixes a bug where Descent
  1 `.msn` files would be classified as descent_version_type::descent2
  since both use `name =`, but that string has a different meaning
  depending on whether the file is `.msn` or `.mn2`.
2020-01-18 21:57:39 +00:00
Kp 3d09f4544b Remove macro Current_mission_filename 2020-01-18 21:57:39 +00:00
Kp 99356e0cdb Use enum for include/exclude anarchy mode 2020-01-18 21:57:39 +00:00
Kp 05a54ef7c1 Merge pull #479 into master 2019-12-27 02:08:58 +00:00
Kp c9b1b5b1ec Use susegment for WALL_IS_DOORWAY 2019-12-27 02:02:23 +00:00
ziplantil 398d9013ef Merge remote-tracking branch 'upstream/master' into vertigo-exit-fix 2019-12-24 01:49:11 +02:00
Kp dfae1c7203 Split object_move_all for game/endlevel
endlevel wants to freeze the console player's last in-mine position.
Instead of copying the position out and back, refactor the flow to let
endlevel skip the update of the position.
2019-12-22 05:34:08 +00:00
Kp 5dfd62c4f6 Use susegment for references introduced by valptridx conversion 2019-12-22 05:34:08 +00:00
Kp c93e7f44c3 Move object::last_pos to LevelUniqueObjectState
Only the console player's last position needs to be remembered across
frames.  Copy the console player's position out before processsing
object movement.  For all other objects, retain a temporary for use by
the position recovery code.
2019-12-22 05:34:08 +00:00
Kp 30091902af Simplify valptridx types where possible
Switch valptridx::ptr to a reference type.
Switch valptridx::ptridx to a reference type or to ::ptr.

Fix up uses of operator-> accordingly.
2019-12-22 05:34:08 +00:00
Kp 3eedd9234e Add susegment to pair references to shared_segment/unique_segment
Various functions need to access both `shared_segment` and
`unique_segment` data.  Using `segment &` for this blocks eliminating
the `segment` type.  Add `susegment` and type aliases to it.
`susegment` records a reference to a `shared_segment` and a
`unique_segment` together, so that users cannot accidentally mismatch
`shared_segment` #1 with `unique_segment` #2 when passing references
down to a function which needs both `shared_segment` and
`unique_segment`.
2019-12-22 05:34:08 +00:00
ziplantil 0a21784aa7 some changes as per comments in #479 2019-12-18 13:44:43 +02:00
Kp 219a3fcd11 Move laser_info::get_last_hitobj out of line
It is only used in two places, neither of which are hot paths.  Move it
out of line so that other files do not need to parse it.
2019-12-16 01:56:59 +00:00
ziplantil cb2b844af3 do not free extra models when loading exit stuff on D2 2019-12-12 17:25:11 +02:00
Kp 075b14373a Change Difficulty_level_type from unsigned to signed
Difficulty_level_type is used in arithmetic expressions.  If
Difficulty_level_type is unsigned, then those expressions use unsigned
terms, but some of the expressions were designed to use signed terms and
produce incorrect results when used with unsigned terms.  There is no
strong reason to make Difficulty_level_type unsigned, so switch it to
signed instead of trying to fix every site that uses it.

Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/471>
Fixes: 1eaaff3016 ("Move Difficulty_level to GameUniqueState")
2019-11-17 23:27:13 +00:00
Kp f43665917e Merge branch ziplantil/win32-sdl2-cdaudio-sync into master 2019-10-28 00:45:34 +00:00
ziplantil 2c5ab8e739 initial version of this, trying to catch MCI events 2019-10-27 02:47:45 +03:00
Kp d2640462cb Backport D2's Dont_start_sound_objects to D1
Descent 2 has a hack, present as far back as I can trace, that
suppresses starting sounds during level load.  The original reason was
not recorded, but this hack has the useful side effect that it avoids
using uninitialized data when set_sound_sources tries to use a Viewer
that has not been reset for the objects of the new level.

Descent 1 lacks this hack, so an invalid Viewer is used, which may
trigger a valptridx trap if the undefined data has an invalid segment
number, and could cause memory corruption in builds which do not
validate the segment index.  The valptridx trap:

```
terminate called after throwing an instance of 'valptridx<dcx::segment>::index_range_exception'
  what():  similar/main/digiobj.cpp:389: invalid index used in array subscript: base=(nil) size=9000 index=65021
```

The backtrace leading to the trap:
```
d1x::digi_link_sound_common (viewer=..., so=..., pos=..., forever=<optimized out>, max_volume=<optimized out>, max_distance=..., soundnum=42, segnum=...) at similar/main/digiobj.cpp:389
0x00005555555a4e2d in d1x::digi_link_sound_to_pos2 (vcobjptr=..., max_distance=..., max_volume=32768, forever=1, pos=..., sidenum=4, segnum=..., org_soundnum=121) at similar/main/digiobj.cpp:483
d1x::digi_link_sound_to_pos (soundnum=soundnum@entry=121, segnum=..., sidenum=sidenum@entry=4, pos=..., forever=forever@entry=1, max_volume=32768) at similar/main/digiobj.cpp:490
0x00005555555c140d in d1x::set_sound_sources (vcsegptridx=..., vcvertptr=...) at similar/main/gameseq.cpp:817
d1x::LoadLevel (level_num=<optimized out>, page_in_textures=1) at similar/main/gameseq.cpp:1022
0x00005555555c2654 in d1x::StartNewLevelSub (level_num=-1, page_in_textures=<optimized out>) at similar/main/gameseq.cpp:1865
```

Backport this hack into Descent 1.  Ultimately, the hack should go away
and data should be loaded in an order that does not access undefined
memory.

Reported-by: Spacecpp <https://github.com/dxx-rebirth/dxx-rebirth/issues/463>
2019-10-26 23:13:14 +00:00
Kp 781a7366a9 Whitelist Vertigo smelter's phoenix cannon
Reported-by: ziplantil <https://github.com/dxx-rebirth/dxx-rebirth/issues/458>
Fixes: 2bcc7bb371 ("Only create lasers for known weapon types")
2019-10-21 03:45:29 +00:00
daivuk 74ef8b02e6 Added axis buttons
Each axis can act as two buttons in both ways.
For example, a player might map slide left and slide right to J1 -A1 and J1 +A1 as button presses instead of the slide L/R axis.

This is mostly to fix XBox 360 Controller Left and Right triggers. But it can work on every axis if the player wishes to bind them.
2019-09-01 13:11:14 -04:00
Kp c355e207fe Refactor song loading
Use an RAII object to manage allocations and keep the length and pointer
together.
2019-08-25 16:43:17 +00:00
Kp 2b2ca67de5 Add enumerated_iterator::operator==
Defining _GLIBCXX_DEBUG introduces a dependency on this method.
Implement it so that _GLIBCXX_DEBUG can be used.
2019-08-24 18:14:16 +00:00
Kp dd0f639176 Avoid reducing player's highest-level when replaying a non-MRU level
If the level was not the most recently played, a save is forced so that
it can be marked as most recently played.  However, the logic to force
the save also forced an update of the highest-level field, even if that
reduced it.

- Rename the parameter to clarify its meaning.
- Add comments explaining the logic to force the save.
- Only update the highest-level field when the update would increase the saved value
2019-08-24 04:32:24 +00:00