From 9a79d058b29149bab9ac506458220ce33a01b34b Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Tue, 15 Oct 2024 21:13:35 +0200 Subject: [PATCH] keep cam pos after undo --- src/src/gundo.cc | 13 ++++++++++++- src/src/gundo.hh | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/src/gundo.cc b/src/src/gundo.cc index a8fd5545..d5ac5dc5 100644 --- a/src/src/gundo.cc +++ b/src/src/gundo.cc @@ -56,7 +56,14 @@ void undo_stack::checkpoint(const char *reason) { ); } -const char* undo_stack::restore() { +const char* undo_stack::restore(bool keep_cam_pos /* = true */) { + float cx, cy, cz; + if (keep_cam_pos) { + cx = G->cam->_position.x; + cy = G->cam->_position.y; + cz = G->cam->_position.z; + } + if (this->items.size() == 0) { tms_fatalf("undo_load: no items to load"); } @@ -68,5 +75,9 @@ const char* undo_stack::restore() { tms_infof("Restored level from undo stack"); free(item.data); + + if (keep_cam_pos) { + G->cam->set_position(cx, cy, cz); + } return item.reason; } diff --git a/src/src/gundo.hh b/src/src/gundo.hh index 9463d999..6bf370dc 100644 --- a/src/src/gundo.hh +++ b/src/src/gundo.hh @@ -36,7 +36,7 @@ struct undo_stack { // Returns the reason for the last checkpoint // // Avoid using this function directly, use P.add_action(ACTION_UNDO_RESTORE, 0) instead - const char* restore(); + const char* restore(bool keep_cam_pos = true); }; extern struct undo_stack undo;