From 832e46141b4995a8eb40386b18b94a547975ec05 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Thu, 15 May 2014 12:27:31 +0200 Subject: [PATCH] undo/redo with editmeta pressed also restores player position also selects the affected area (less useful in coopedit because always the own position is restored) for testers: editmeta still defaults to LCTRL --- source/src/editing.cpp | 32 +++++++++++++++++++++++++++++--- source/src/world.h | 2 +- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/source/src/editing.cpp b/source/src/editing.cpp index 63bef642..73a92c1b 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -25,6 +25,9 @@ sqr rtex; VAR(editing, 1, 0, 0); +bool editmetakeydown = false; +COMMANDF(editmeta, "d", (bool on) { editmetakeydown = on; } ); + void toggleedit(bool force) { if(player1->state==CS_DEAD) return; // do not allow dead players to edit to avoid state confusion @@ -308,18 +311,43 @@ void pruneundos(int maxremain) // bound memory } } +void storeposition(short p[]) +{ + loopi(3) p[i] = player1->o.v[i] * DMF; + p[3] = player1->yaw; + p[4] = player1->pitch; +} + void makeundo(block &sel) { + storeposition(sel.p); undos.add(blockcopy(sel)); pruneundos(undomegs<<20); } +void restoreposition(short p[]) +{ + loopi(3) player1->o.v[i] = float(p[i]) / DMF; + player1->yaw = p[3]; + player1->pitch = p[4]; + player1->resetinterp(); +} + +void restoreposition(block &sel) +{ + restoreposition(sel.p); + resetselections(); + addselection(sel.x, sel.y, sel.xs, sel.ys, sel.h); // select undone area + checkselections(); +} + void editundo() { EDITMP; if(undos.empty()) { conoutf("nothing more to undo"); return; } block *p = undos.pop(); redos.add(blockcopy(*p)); + if(editmetakeydown) restoreposition(*p); blockpaste(*p); freeblock(p); } @@ -330,6 +358,7 @@ void editredo() if(redos.empty()) { conoutf("nothing more to redo"); return; } block *p = redos.pop(); undos.add(blockcopy(*p)); + if(editmetakeydown) restoreposition(*p); blockpaste(*p); freeblock(p); } @@ -411,9 +440,6 @@ void tofronttex() // maintain most recentl } } -bool editmetakeydown = false; -COMMANDF(editmeta, "d", (bool on) { editmetakeydown = on; } ); - void editdrag(bool isdown) { if((dragging = isdown)) diff --git a/source/src/world.h b/source/src/world.h index 4f628d7a..edd6073f 100644 --- a/source/src/world.h +++ b/source/src/world.h @@ -92,7 +92,7 @@ struct mapstats #define MAXHHITS 50000 // was 6000, which denied my fav. maps - jamz, 2012-06-12; 15000 denies sane map too - lucas #define MINFF 2500 -struct block { int x, y, xs, ys, h; }; +struct block { int x, y, xs, ys, h; short p[5]; }; // vertex array format