Commit graph

10639 commits

Author SHA1 Message Date
Kp 0fb82b47f6 SDL2: fix size of letterbox sequences
andrew-strong reported that using SDL2, with the window set to full
screen, but a windowed size less than full screen, caused letterbox
sequences, such as the player ship destroyed sequence, to render in a
subwindow sized to the dimensions game would have when unmaximized, even
if the game window is maximized at the time of the sequence.

tycho suggested a change that resolves this issue, and basic testing
showed no unwanted side effects.

Reported-by: andrew-strong <https://github.com/dxx-rebirth/dxx-rebirth/issues/399>
Suggested-by: tycho <https://github.com/dxx-rebirth/dxx-rebirth/issues/399#issuecomment-583688998>
2020-03-28 17:32:34 +00:00
Kp 2e682e140d Prevent sound stacking when all primary weapons are exhausted
ziplantil reported that in Descent 1, if a player has an empty Vulcan
cannon, and no energy, then attempting to fire a weapon would play the
SOUND_ALREADY_SELECTED clip every frame until the player ceased trying
to fire.  The problem does not impact Descent 2 since Descent 2 does not
play this sound sample when trying to activate a weapon that is already
active.

If the current weapon is already LASER_INDEX, then
select_primary_weapon(LASER_INDEX) simplifies to:

```

	// Pointless, player already using this weapon
	newdemo_record_player_weapon(LASER_INDEX)
	if (Primary_weapon != LASER_INDEX) {
		// skipped, path is false
	}
	else
	{
		if (wait_for_rearm)	// true for this path
			// Bad, plays every frame
			digi_play_sample(SOUND_ALREADY_SELECTED);
	}
	// Pointless, Primary_weapon already is LASER_INDEX
	Primary_weapon = LASER_INDEX;
	if (weapon_name)
	{
		// skipped, path is false
	}

```

Skipping the call avoids two pointless statements, one bad statement,
and nothing useful.  Therefore, the simplest fix for the problem is to
call select_primary_weapon(LASER_INDEX) only if the primary weapon is
not currently LASER_INDEX.

Reported-by: ziplantil <https://github.com/dxx-rebirth/dxx-rebirth/issues/499>
2020-03-28 17:09:28 +00:00
Kp af8adaef1b Defer digi_mixer_start_sound work until it is needed
If no channel is available, the mix parameters are unused.  Move their
construction to occur after a channel for the sound is found.
2020-03-28 16:55:43 +00:00
Kp b19496ca72 Set digi_mixer channel callback once at startup
The callback is never changed, so it does not need to be reset on every
new sound.
2020-03-28 16:54:28 +00:00
Kp 6a27ae3544 Prevent copying RAIIMix_Chunk
No code tried to copy it, but if a copy was created, it would cause a
double-free later.  Prevent copying to avoid introduction of a
double-free bug.
2020-03-28 16:51:43 +00:00
Kp 7478eab4c9 Remove references to DXX forum
The forum vanished several months ago and now points to a server with a
bad certificate.  Stop directing people to that hostname.
2020-03-25 02:31:10 +00:00
Kp ed4cb636b7 Fix memory leak when deleting listbox items 2020-03-14 03:41:30 +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 ce7cf4f7ef Rename gauges span to avoid conflict with C++20 type of the same name 2020-02-26 05:07:34 +00:00
Kp 5a08c40878 Use zip for morph update_points 2020-02-26 05:07:34 +00:00
Kp 27a96d0337 Simplify partial_range check for unsigned offset/length 2020-02-26 05:07:34 +00:00
Kp 4ec6a13bfa Zip morph polymodel sequences 2020-02-26 05:07:34 +00:00
Kp 9db512a9d6 Simplify Descent2 briefing removal of carriage returns
Read the entire buffer at once, then remove the carriage returns and set
a null terminator.  This reduces the number of calls to PHYSFS_read from
len to 1.
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 d876874475 Factor out morph model header parsing 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 c088f15384 Use std::fill to overwrite poisoned ranges
gcc can replace std::fill with memset when the code would be a loop
writing byte values.
2020-02-11 04:48:14 +00:00
Kp 8997b5c801 Fix check_header_includes for Python 3 2020-02-11 04:48:14 +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 bcf06623a5 Disable morph processing in demo files
It reads uninitialized values, so it was barely functional before
morph_data became a dynamic allocation, and it is broken now.  Disable
it to avoid crashing the game.  The demo code should have initialized
the morph_data structure properly, but does not.

Reported-by: tycho <https://github.com/dxx-rebirth/dxx-rebirth/issues/496>
Fixes: cac5f1da56 ("Move morph_data into dynamic allocations")
2020-02-06 03:22:45 +00:00
Kp f1c6177338 Poison morph_data on allocation
Require the caller to provide sane values later.
2020-02-06 03:22:45 +00:00
Kp edc8819409 Add hint about range of bitmap indices
When building with AddressSanitizer, gcc warns that `i` may not fit,
because the compiler fails to adequately constrain the possible values
for `i`.  Add a control-flow hint to inform gcc about valid values.
2020-02-06 03:22:45 +00:00
Kp 74271443ed Add definition of d_level_shared_boss_state::D1_Boss_*_interval
These variables are used, but optimized builds eliminate all reference
to their address, so the build normally succeeds.  Unoptimized builds
retain references to the address, so a definition is required for them.

Reported-by: tycho <https://github.com/dxx-rebirth/dxx-rebirth/issues/496>
Fixes: 595c3ca086 ("Move Boss_cloak_interval to d_level_shared_boss_state")
Fixes: c61dee7e6a ("Move Boss_teleport_interval to d_level_shared_boss_state")
2020-02-06 03:22:45 +00:00
Kp 8ebb66c5c9 Remember player's hostages_on_board across secret level return
Returning from a secret level clears the player's `hostages_on_board` to
0 as part of initializing a "new" ship, but this is not desirable
behavior.  Copy the counter out before and back afterward.

    ```
    Thread 1 "d2x-rebirth-edi" hit Hardware watchpoint 1: -location d2x::LevelUniqueObjectState.Objects._M_elems[0].ctype.player_info.mission.hostages_on_board

    Old value = 5 '\005'
    New value = 0 '\000'

    #0  d2x::init_player_stats_ship (GameTime64=<optimized out>, plrobj=...) at similar/main/gameseq.cpp:613
    #1  d2x::init_player_stats_level (secret_flag=d2x::secret_restore::survived, plrobj=..., plr=...) at similar/main/gameseq.cpp:615
    #2  d2x::StartNewLevelSub (level_num=level_num@entry=3, page_in_textures=page_in_textures@entry=1, secret_flag=secret_flag@entry=d2x::secret_restore::survived) at similar/main/gameseq.cpp:1901
    #3  d2x::state_restore_all_sub (LevelSharedDestructibleLightState=..., secret=d2x::secret_restore::survived, filename=<optimized out>) at similar/main/state.cpp:1670
    #4  d2x::state_restore_all (in_game=in_game@entry=1, secret=secret@entry=d2x::secret_restore::survived, filename_override=<optimized out>, blind=blind@entry=dcx::blind_save::no) at similar/main/state.cpp:1490
    #5  d2x::ExitSecretLevel ()
    ```

Reported-by: teratorn <https://github.com/dxx-rebirth/dxx-rebirth/issues/495>
2020-02-01 22:33:31 +00:00
Kp 0ea0a5ff31 Avoid scaling morph vector by length 0 2020-02-01 22:33:31 +00:00
Kp 7c9b8d61b8 Zip morph elements for traversal
This generates code that increments a group of pointers, instead of
incrementing an index and repeatedly multiplying it to compute each
index.
2020-02-01 22:33:31 +00:00
Kp 2bbda9d92c Factor out morph bounding box setup 2020-02-01 22:33:31 +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 ab55d26051 Zip ranges passed to rotate_point_list
This gains a range check on the output, and makes the relation of input
and output parameters clear in the function signature.
2020-02-01 22:33:31 +00:00
Kp 0db0230689 Use enumerate to manage morph index/pointer 2020-02-01 22:33:31 +00:00
Kp 25d782812c Make some update_points variables const 2020-02-01 22:33:31 +00:00
Kp f65ce8bbe4 Make some init_points variables const 2020-02-01 22:33:31 +00:00
Kp b6e782d128 Add unit tests for xrange 2020-02-01 22:33:31 +00:00
Kp 7eaa8f03d7 Hold polymodel data const in morph code 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 03b6e604eb Fix valptridx build break in <gcc-7
gcc before gcc-7 failed to build valptridx:

```
common/include/valptridx.h: In instantiation of 'valptridx<managed_type>::ptridx<policy>::ptridx(const valptridx<managed_type>::ptridx<rpolicy>&) [with rpolicy =
 valptridx<dcx::segment>::vm; typename std::enable_if<(policy:: allow_nullptr || (! rpolicy:: allow_nullptr)), int>::type <anonymous> = 0; policy = valptridx<dcx::segment>::vc; managed_type = dcx::segment]':
similar/main/endlevel.cpp:586:105:   required from here
common/include/valptridx.h:686:14: error: 'using vptr_type = class valptridx<dcx::segment>::ptr<valptridx<dcx::segment>::vm>' is protected within this context
    vptr_type(static_cast<const typename ptridx<rpolicy>::vptr_type &>(rhs)),
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
common/include/valptridx.h:666:31: note: declared protected here
  using vptr_type = ptr<policy>;
```

This cannot be fixed in the obvious way because the error message is
wrong:

```
   664		using containing_type = valptridx<managed_type>;
   665	public:
   666		using vptr_type = ptr<policy>;
   667		using vidx_type = idx<policy>;
   668		using typename vidx_type::array_managed_type;
```

The type declarations _already are_ *public*, not *protected* as the
message states.  Relaxing the protection on the containing class
resolves the error.  This looks bad from an encapsulation perspective,
but does not make the code incorrect.
2020-01-24 03:49:32 +00:00
AlumiuN 915172478f Initial fix for doors with linked walls other than their connected side 2020-01-24 14:12:43 +13:00