From dfae1c720375404380d6cfb8df6cba18c5c252c9 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 22 Dec 2019 05:34:08 +0000 Subject: [PATCH] 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. --- common/main/fwd-object.h | 3 ++- similar/main/endlevel.cpp | 4 +--- similar/main/game.cpp | 2 +- similar/main/object.cpp | 13 +++++++++++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/common/main/fwd-object.h b/common/main/fwd-object.h index 4b17ead02..f592c4637 100644 --- a/common/main/fwd-object.h +++ b/common/main/fwd-object.h @@ -244,7 +244,8 @@ void reset_objects(d_level_unique_object_state &, unsigned n_objs); void compress_objects(); // move all objects for the current frame -window_event_result object_move_all(); // moves all objects +window_event_result game_move_all_objects(); // moves all objects +window_event_result endlevel_move_all_objects(); // set viewer object to next object in array void object_goto_next_viewer(); diff --git a/similar/main/endlevel.cpp b/similar/main/endlevel.cpp index 61f47dd52..b79c48131 100644 --- a/similar/main/endlevel.cpp +++ b/similar/main/endlevel.cpp @@ -531,9 +531,7 @@ window_event_result do_endlevel_frame() static fix explosion_wait2=0; static fix ext_expl_halflife; - const auto save_last_pos = LevelUniqueObjectState.last_console_player_position; //don't let move code change this - auto result = object_move_all(); - LevelUniqueObjectState.last_console_player_position = save_last_pos; + auto result = endlevel_move_all_objects(); if (ext_expl_playing) { diff --git a/similar/main/game.cpp b/similar/main/game.cpp index 75503bef2..1b71a758b 100644 --- a/similar/main/game.cpp +++ b/similar/main/game.cpp @@ -1856,7 +1856,7 @@ window_event_result GameProcessFrame() #ifndef NEWHOMER player_info.homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this. #endif - result = std::max(object_move_all(), result); + result = std::max(game_move_all_objects(), result); powerup_grab_cheat_all(); if (Endlevel_sequence) //might have been started during move diff --git a/similar/main/object.cpp b/similar/main/object.cpp index aeb0adfcb..67bfc7a15 100644 --- a/similar/main/object.cpp +++ b/similar/main/object.cpp @@ -2019,7 +2019,7 @@ static window_event_result object_move_one(const vmobjptridx_t obj) //-------------------------------------------------------------------- //move all objects for the current frame -window_event_result object_move_all() +static window_event_result object_move_all() { auto &Objects = LevelUniqueObjectState.Objects; auto &vmobjptridx = Objects.vmptridx; @@ -2034,7 +2034,6 @@ window_event_result object_move_all() ConsoleObject->mtype.phys_info.flags |= PF_LEVELLING; else ConsoleObject->mtype.phys_info.flags &= ~PF_LEVELLING; - LevelUniqueObjectState.last_console_player_position = ConsoleObject->pos; // Move all objects range_for (const auto &&objp, vmobjptridx) @@ -2050,6 +2049,16 @@ window_event_result object_move_all() return result; } +window_event_result game_move_all_objects() +{ + LevelUniqueObjectState.last_console_player_position = ConsoleObject->pos; + return object_move_all(); +} + +window_event_result endlevel_move_all_objects() +{ + return object_move_all(); +} //--unused-- // ----------------------------------------------------------- //--unused-- // Moved here from eobject.c on 02/09/94 by MK.