Commit graph

3288 commits

Author SHA1 Message Date
Kp 6d3fb34268 Abstract out last_hitobj management 2017-01-15 00:03:13 +00:00
Kp 764d20d4e1 Make grs_bitmap::bm_flags private 2017-01-15 00:03:13 +00:00
Kp f4fffeea49 Make more render state const when possible
Make Render_zoom const in builds where there are no statements that can
change it.

Use vcseg, not vseg, for some segment accesses.
2017-01-15 00:03:12 +00:00
Chris Taylor 8c51aa0b1e Fix debugger break at draw_weapon_info_sub when multi player dumped (bug #303)
Also happened when a client to a multiplayer game dropped out due to some network error. Delay call of multi_leave_game() until responding to EVENT_WINDOW_CLOSE, so the game isn't in an unstable state between handling the network event and the game closing.
2017-01-14 17:49:43 +08:00
Chris Taylor 479f5ed584 Fix 'format specifies type 'unsigned short' but the argument has type 'unsigned char'' warning
Replace %hu with %hhu for capped in call to con_printf in powerup_cap_state::cap_secondary_ammo.
2017-01-13 12:32:46 +08:00
Chris Taylor 6ecccd3491 Fix 'equality comparison with extraneous parentheses' warning
Remove offending parentheses around call to multi_i_am_master() in net_udp_leave_game().
2017-01-13 12:30:57 +08:00
Kp 5201218e20 Fix D1 build
Commit 4cc801f changed `object_move_one` to return `window_event_result`
instead of `void` and added a default return value at the bottom.
However, it added the value inside a `#if D2` block, so the D1 build now
fails with:

    similar/main/object.cpp: In function 'dcx::window_event_result d1x::object_move_one(d1x::vobjptridx_t)':
    similar/main/object.cpp:1627:7: error: variable 'result' set but not used [-Werror=unused-but-set-variable]
    similar/main/object.cpp:1866:1: error: control reaches end of non-void function [-Werror=return-type]

Move the return statement out of the conditional block to fix both these
errors.

Fixes: 4cc801f42f ("Remove calls to window_close(Game_wind) when game finished or over")
2017-01-13 03:19:19 +00:00
Chris Taylor 0c5a000328 Remove call to window_close(Game_wind) when a network event tells us to end the game
In multi_do_frame(), replace call to window_close(Game_wind) with returning window_event_result::close whenever multi_quit_game is true. Only using this return value where multi_do_frame() is directly called by GameProcessFrame(). multi_quit_game will only be set back to 0 when a new multi game is started.

Closing a window within its handler is problematic - it can result in an unstable state.
2017-01-10 14:10:39 +08:00
Chris Taylor a418f8caec Remove call to window_close(Game_wind) when multiplayer level syncing fails
Replace call to window_close(Game_wind) with returning window_event_result::close to game_handler. Applies to when there is a failure in net_udp_level_sync(). Closing a window within its handler is problematic - it can result in an unstable state.
2017-01-10 13:02:59 +08:00
Chris Taylor 2ecc4c4a07 Remove call to window_close(Game_wind) when stopping demo playback
Replace call to window_close(Game_wind) with returning window_event_result::close to game_handler. Applies to whenever newdemo_stop_playback() is called. Closing a window within its handler is problematic - it can result in an unstable state.
2017-01-09 19:09:34 +08:00
kreatordxx d10896f116 Merge pull request #297 from dxx-rebirth/newdemo_no_space
Fix crash when ran out of disk space when writing demo
2017-01-09 10:05:25 +08:00
kreatordxx f590ec45c6 Merge pull request #298 from dxx-rebirth/no_game_wind_close
Remove calls to window_close(Game_wind)
2017-01-09 09:32:24 +08:00
Chris Taylor 6e2c3c61b1 Format LevelError text better for the case of an exit that is both regular and secret 2017-01-09 09:30:53 +08:00
Chris Taylor 0daf28e787 Small efficiency improvement for a return value in do_endlevel_frame() 2017-01-09 09:26:32 +08:00
Chris Taylor 06968db4bc Fix crash when ran out of disk space when writing demo
Check for nd_record_v_no_space in _newdemo_write.
2017-01-09 09:15:51 +08:00
Kp 0d5d7a01ad Fold PHYSFS_write calls for Automap_visited 2017-01-08 22:32:01 +00:00
Kp 7b08144aee Poison unused exploding walls 2017-01-08 22:32:00 +00:00
Kp d289fec43b Update hitobj_list in multi_object_rw_to_object 2017-01-08 22:32:00 +00:00
Kp 94716dfab5 Scrub OBJ_NONE objects from multiplayer peers 2017-01-08 22:32:00 +00:00
Kp 7fafc22cca Poison multiplayer object_rw without making it unreadable
`struct object_rw` is poisoned prior to initializing and sending it.
However, some fields are legitimately unininitialized (other than their
memset or poison value) at send time.  Add and use a poison variant that
can clear those fields, without marking them unreadable.
2017-01-08 22:32:00 +00:00
Kp 5da784dbed Pass canvas to gr_{,u}string 2017-01-08 22:32:00 +00:00
Kp 1ef6b9d5bc Pass font to gr_get_string_size 2017-01-08 22:31:59 +00:00
Kp 0480ba8030 Pass canvas to gr_string(int,int,const char*,int,int) 2017-01-08 22:31:59 +00:00
Kp 4b2102f41a Factor out show_framerate x/y for gr_printf 2017-01-08 22:31:58 +00:00
Chris Taylor aac4dd6c0e Remove call to newdemo_stop_playback() in newdemo_record_start_frame
This is in a redundant check, as we shouldn't (and don't) call newdemo_record_start_frame if nd_record_v_no_space is true, i.e. we ran out of disk space recording a demo. We want to return window_event_result::close with every call to newdemo_stop_playback() to close the game, as this is safer than calling window_close on the game window within its handler. In this case, it's much simpler (and safe) to just remove it.

Even if newdemo_record_start_frame is called when nd_record_v_no_space is true, we don't want to close the game, just exit the function.
2017-01-08 21:08:50 +08:00
Chris Taylor 4cc801f42f Remove calls to window_close(Game_wind) when game finished or over
Replace calls to window_close(Game_wind) with returning window_event_result::close to game handler. Applies to when DoEndGame() is called, DoGameOver() is called, aborting in the kmatrix screen (multiplayer game) during AdvanceLevel() and playing one demo frame causes playback to stop in GameProcessFrame(). Closing a window within its handler is problematic - it can result in an unstable state.
2017-01-08 21:08:50 +08:00
Kp f339e60606 Scrub object subtypes on load
Old versions of Rebirth sometimes saved games with bogus object data,
such that `obj->type == OBJ_NONE`, but `obj->movement_type`,
`obj->control_type`, or `obj->render_type` were not their respective
*_NONE constants.  This confused the game loader code such that it would
load invalid data from the `mtype`, `ctype`, or `rtype` unions and use
it without checking.

Try to counter some of this by exiting early if the object has type
OBJ_NONE.
2017-01-07 23:34:18 +00:00
Kp fe04c3fef6 Initialize obsolete fields
Valgrind warns when writing uninitialized data to a file.  The Descent
savegame format requires writing certain fields that are no longer used.
Set those fields to 0 to prevent leaking stack data into the file.
2017-01-01 23:19:21 +00:00
Kp 3fab4bfeb5 Fix uninitialized write of segment light_subtracted
Levels which fit in MAX_SEGMENTS_ORIGINAL read exactly
MAX_SEGMENTS_ORIGINAL segments worth of light_subtracted, even though
fewer segments were defined.  Prepare light_subtracted into a temporary
stack buffer instead of doing byte-at-a-time writes.  Initialize this
stack buffer to 0 when necessary.  Write the buffer once it is fully
prepared.
2017-01-01 00:45:46 +00:00
Kp a7ec4ccd63 Avoid uninitialized reads when saving game
player_info::cloak_time is only defined if the player is cloaked.
player_info::invulnerable_time is only defined if the player is
invulnerable.

In both cases, the game save code tried to read the ::*_time variable
even when it was undefined.  Modify the saving code to check player
flags before reading the associated timer.
2017-01-01 00:45:46 +00:00
Kp 2c7e36ef1e Cache KEY_M vsegptridx 2017-01-01 00:45:45 +00:00
Kp 22e364e030 Pass canvas to gr_clear_canvas 2017-01-01 00:45:45 +00:00
Kp 0905aefa0a Pass canvas to gr_rect 2017-01-01 00:45:45 +00:00
Kp 794dcce327 Pass canvas to gr_urect 2017-01-01 00:45:44 +00:00
Kp 774dedd21d Pass canvas to gr_bm_pixel 2017-01-01 00:45:44 +00:00
Kp 77c22d3a7f Pass canvas to gr_settransblend 2017-01-01 00:45:44 +00:00
Kp dac1a69f7c Pass canvas to gr_ubox 2017-01-01 00:45:44 +00:00
Kp 1b57e9a5ff Pass canvas to show_fullscr 2017-01-01 00:45:43 +00:00
Kp 250bf58e51 Pass canvas to gr_bitmapm 2017-01-01 00:45:43 +00:00
zico 24bd4170f4 Added debug key combo DEL+M to generate a morphing robot in the player segment, rotating through all available bots. Handy for testing purposes. 2016-12-30 14:45:47 +01:00
Kp 3a4eafac03 Add workaround for passive thief bot
zicodxx reports that f7d0c85 made the thief bot passive and timid.
His analysis suggests that the problem is because f7d0c85 changed
find_connected_distance to return vm_distance::maximum_value() in places
where it previously returned magic values that were not maximum (caching
a distance of F1_0*1000 and returning a distance of -1).  Rather than
try to fix the underlying code that relied on these magic values, revert
those return paths to return these unusual values.  Move the unusual
values to named constants in file scope so that they are easier to find
and correlate.

Reported-by: zicodxx <https://github.com/dxx-rebirth/dxx-rebirth/issues/286>
Analyzed-by: zicodxx

Fixes: f7d0c853ba ("Use special types for distance/magnitude")
2016-12-29 03:27:14 +00:00
Kp 362d526546 Pass canvas to gr_disk 2016-12-29 03:27:13 +00:00
Kp acd309099b Pass canvas to gr_ucircle 2016-12-29 03:27:13 +00:00
Kp 08d0aa9b59 Pass canvas to gr_bitmap 2016-12-29 03:27:13 +00:00
Kp d7cd6d17c3 Pass canvas to gr_ubitmapm 2016-12-29 03:27:13 +00:00
Kp 6ab3b18657 Pass canvas to gr_ubitmap 2016-12-29 03:27:12 +00:00
Kp 99f5cfbb10 Pass canvas to ogl_ubitmapm_cs 2016-12-29 03:27:12 +00:00
Kp 1e1272fcf2 Cache temporaries in show_briefing_bitmap
Avoid recomputing the same width/height expressions.  This saves ~20
instructions and ~100 bytes on x86_64-pc-linux-gnu.
2016-12-29 03:27:11 +00:00
Kp 1fa5aef9ac Pass canvas to gr_line 2016-12-29 03:27:10 +00:00
Kp 7439949595 Pass canvas to gr_uline 2016-12-29 03:27:10 +00:00
Kp ef06aa089a Pass canvas to gr_pixel 2016-12-29 03:27:09 +00:00
zico a10d9e0bba Prevent access of potentially uninitialized r.value in nm_trigger_radio_button() 2016-12-28 20:36:00 +01:00
zico 3672bbd1f2 Made show_briefing_bitmap() properly consider HIRESMODE (i.e. Mac data), using scaling logic from show_animated_bitmap(). 2016-12-28 16:28:08 +01:00
zico 03f5cbf3a4 Fixed issue in frame_animation_angle(): Due to deltaang.*a being usually small values and frametime getting smaller with higher FPS, the usual use of fixmul will have scaled_delta_angle result in 0 way too often and long, making the robot animation run circles around itself. So multiply deltaang by DELTA_ANG_SCALE when passed to fixmul. 2016-12-28 15:26:33 +01:00
Kp 879070f814 Fix uninitialized value usage during init_player_stats_new_ship
init_player_stats_new_ship used select_primary_weapon and
select_secondary_weapon to assign the player's weapons.  However, those
functions read the current weapon and jumped according to its value.  A
new ship has no defined value for current weapons, so the jump triggered
an uninitialized value warning from Valgrind.

Add new functions set_primary_weapon, set_secondary_weapon that work
like the previous select_* functions, but always take the path used
for weapons not equal, without checking.  This prevents the warnings
from Valgrind, as well as a theoretical risk of initializing the ship
improperly.
2016-12-25 00:33:25 +00:00
Kp fed011df94 Exclude OBJ_NONE objects from can_collide flags test 2016-12-25 00:33:24 +00:00
Kp 5d752e741d Factor out object_create_explosion_sub collision test
An 11-line if() test is unreadable.  Split it out into a helper.
2016-12-25 00:33:24 +00:00
Kp b05325d0ab Initialize lavafall_hiss_playing for each ship 2016-12-25 00:33:24 +00:00
Kp fa1f8488f0 Use uint8_t for sidenum 2016-12-24 22:44:08 +00:00
Kp e07f5072cb Fix inverted change_light test
An optimization meant to allow change_light to stop early caused it to
stop much too early, so it rarely did any work.  Flip the sense of the
test so it does not stop early.

Fixes: 2bd538f353 ("Sort delta light indices")
2016-12-24 18:12:18 +00:00
Kp 539629c14b Avoid leaking uninitialized bytes to the network 2016-12-24 18:12:17 +00:00
Kp 2ba300be8c Remove bogus demo messages
Demos do not record difficulty level or track hostages correctly.  Do
not show these fields in the demo pause dialog, since they reflect
the state of the player's last played game, not the state of the player
recording the demo.
2016-12-22 05:21:16 +00:00
Kp d085175cbd Scrub invalid primary textures at level load
Past releases, when rendering an invalid primary texture, would
Int3() and then reset the texture to zero.  Commit d767f7c changed the
logic to return without resetting the texture, since the reset seemed to
be unnecessary.  Unfortunately, it is necessary.  Some levels, including
those shipped with the retail game data, specify bogus primary textures
on some surfaces.  After d767f7c, rendering a surface with an invalid
primary texture causes the surface to be invisible, even if it has a
valid secondary texture.

Remove the return statement added in d767f7c.  Extend
validate_segment_side to validate the primary texture on the tested
side.  When an invalid texture is found, reset it and log a diagnostic.
For built-in levels, log at level CON_VERBOSE since players cannot
readily fix the level.  For external levels, log at level CON_URGENT so
that level authors know to fix their level before releasing it.

Fixes: d767f7cd5e ("Pass vcsegptridx to render_face")
2016-12-22 05:21:16 +00:00
Kp 29b9c255fa Remove unnecessary FuelCenter operator- 2016-12-22 05:21:16 +00:00
Kp 10aa2e5106 Move some kconfig symbols into namespace dsx 2016-12-22 05:21:16 +00:00
Kp 0109355ae0 Switch kconfig_handler to D2 mouse button semantics
Presumably, D2 switched to EVENT_MOUSE_BUTTON_UP for a good reason.
Switch D1 to that rule too.
2016-12-22 05:21:16 +00:00
Kp bb6b548540 Remove unused listbox_get_window 2016-12-22 05:21:16 +00:00
Kp 44d1536969 Narrow scope of state_restore_all_sub variables
The previous attempt to assign defaults for values that the savegame
lacks was ignored because it overwrote a variable after the last read.
An early draft of that patch worked, but a last minute reorganization to
keep similar purpose code together made the change ineffective.

Narrow the scope of that variable and write to the correct variable.

Fixes: f62ed80205 ("Reset values that should have been in the savegame, but are not")
2016-12-21 03:54:18 +00:00
Kp 76c44b3a64 Mark DemoWBUType constexpr 2016-12-20 05:17:33 +00:00
Kp f62ed80205 Reset values that should have been in the savegame, but are not 2016-12-17 18:39:18 +00:00
Kp 171e87a1e7 Fix failure to unmap custom hogs 2016-12-17 18:39:18 +00:00
Kp 8eb295beeb Factor out get_console_color_by_priority gr_find_closest_color calls 2016-12-17 18:39:17 +00:00
Kp 4a01fab66d Fix failure to remove expired walls
std::remove_if can be called on an iterator that returns a proxy object,
but the results of that call are not generally useful.  When remove_if
attempts to move-assign over removed elements, it instead assigns over
the temporary proxy object.  If the proxy object has typical move
semantics, move-assigning over it has no effect on the underlying
container.

Revert to using partial_range on the underlying container.

Reported-by: Mako88 <https://github.com/dxx-rebirth/dxx-rebirth/issues/283>
Fixes: 1f434f98ad ("Use valptridx for ActiveDoors")
2016-12-11 23:47:40 +00:00
Kp 17a50272f0 Pass player_info to more gauges functions 2016-12-11 01:56:43 +00:00
Kp 2cd4fdc70b Fold show_homing_warning call to hud_gauge_bitblt 2016-12-11 01:56:43 +00:00
Kp 06034a53f9 Print key kill goal statistics to console
When the reactor is forcibly destroyed by the kill goal code, print to
the console and the game log the data that players could otherwise
capture with a screenshot of the network player information.
2016-12-10 17:51:11 +00:00
Kp 3e2150c470 Remove some of the weirder quirks of timeout killgoal handling
Require that at least one player have at least one kill.  If all players
have at most zero kills, return without declaring a winner.
2016-12-10 17:51:11 +00:00
Kp 87be333d29 Fold automap pause_game setup 2016-12-10 17:51:11 +00:00
Kp 0169f10728 Pass player_info to gauge functions 2016-12-10 17:51:10 +00:00
Kp 6fbcef75b1 Pass player object to draw_hud 2016-12-10 17:51:10 +00:00
Kp 83043ebd72 Pass player_info to compute_vis_and_vec 2016-12-10 17:51:10 +00:00
Kp e669e71dda Pass player_info to ai_fire_laser_at_player 2016-12-10 17:51:10 +00:00
Kp 442af298cb Pass player_info to allowed_to_fire_missile 2016-12-10 17:51:10 +00:00
Kp 7e6c9fb172 Pass player_info to allowed_to_fire_flare 2016-12-10 17:51:10 +00:00
Kp ad055dc60e Fold calls to hud_printf_vulcan_ammo
The conditional is a bit ugly due to the D1 test.

--------

    #include <cstdio>

    void hud_printf_vulcan_ammo(int mline, int x, int y, int line = __builtin_LINE())
    {
	    printf("mline=%2i line=%2i x=%2i y=%2i\n", mline, line, x, y);
    }

    void expanded_form(int full, int vertical, int mline = __builtin_LINE())
    {
	    const int x = 10, y = 20, line_spacing = 5;
	    if (full)
	    {
		    if (!vertical)
			    hud_printf_vulcan_ammo(mline, x, y - line_spacing);
    #if defined(DXX_BUILD_DESCENT_I)
		    else
			    hud_printf_vulcan_ammo(mline, x, y);
    #endif
	    }
	    else
		    hud_printf_vulcan_ammo(mline, x - 2, y - 3);
    }

    void folded_form(int full, int vertical, int mline = __builtin_LINE())
    {
	    const int x = 10, y = 20, line_spacing = 5;
	    int vx, vy;
	    if (full ? (
		    vertical ?
    #if defined(DXX_BUILD_DESCENT_I)
		    (vx = x, vy = y, true)
    #else
		    false
    #endif
		    : (vx = x, vy = y - line_spacing, true)
		    ) : (vx = x - 2, vy = y - 3, true))
		    hud_printf_vulcan_ammo(mline, vx, vy);
    }

    int main()
    {
    #define run(f)	\
	    f(0, 0);	\
	    f(1, 0);	\
	    f(0, 1);	\
	    f(1, 1)
	    run(expanded_form);
	    run(folded_form);
    }

--------
2016-12-10 17:51:09 +00:00
Kp fe0c97ebb9 Move Player_eggs_dropped to player_info 2016-12-10 17:51:09 +00:00
Kp c7634a1923 Move Auto_fire_fusion_cannon_time to player_info 2016-12-10 17:51:09 +00:00
Kp 51b06f6cdc Move Fusion_charge to player_info
This eliminates some ugly hacks regarding remotely generated fusion
shots.
2016-12-10 17:51:09 +00:00
Kp 117e205ff0 Fold spreadfire calls to Laser_player_fire_spread 2016-12-10 17:51:09 +00:00
Kp 2646bfe005 Fold Fusion_charge PALETTE_FLASH_ADD calls 2016-12-10 17:51:08 +00:00
Kp ccd71dd579 Remove unnecessary scores_maybe_add_player close of Game_wind
scores_maybe_add_player might close Game_wind, if it does not return
early.  All two callers unconditionally close Game_wind.  Remove the
unnecessary closure in scores_maybe_add_player.
2016-12-10 17:51:08 +00:00
Kp 4cec1910e2 Propagate scores_maybe_add_player argument 2016-12-10 17:51:08 +00:00
Kp a88eb5867d Fold score saying copy 2016-12-10 17:51:08 +00:00
Kp 1f434f98ad Use valptridx for ActiveDoors 2016-12-10 17:51:08 +00:00
Kp 6c85086a43 Pass vcsegptridx to multi_send_light_specific 2016-12-10 17:51:07 +00:00
kreatordxx 62abd810a4 Merge pull request #282 from dxx-rebirth/demo_fix
Fix freeze when aborting game while demo is recording
2016-12-08 13:22:24 +08:00
Kp 6e03e6b4c1 Add hack to compensate for memdebug premature scan 2016-12-08 03:32:06 +00:00
Chris Taylor 17ca665ed5 Only return window_event_result::deleted from game_handler when Game_wind was deleted in that call of game_handler
Fixes freeze when aborting game while demo is recording
2016-12-07 09:38:03 +08:00
Kp 515476f02b Propagate constant third parameter of call_object_create_egg 2016-12-05 00:26:11 +00:00
Kp 0fb59c225c Move add_points_to_score into namespace dsx 2016-12-05 00:26:10 +00:00