1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
|
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "tools/edit_gui_common.h"
#include "qe3.h"
#include "Radiant.h"
/*
QERadiant Undo/Redo
basic setup:
<-g_undolist---------g_lastundo> <---map data---> <-g_lastredo---------g_redolist->
undo/redo on the world_entity is special, only the epair changes are remembered
and the world entity never gets deleted.
FIXME: maybe reset the Undo system at map load
maybe also reset the entityId at map load
*/
typedef struct undo_s
{
double time; //time operation was performed
int id; //every undo has an unique id
int done; //true when undo is build
char *operation; //name of the operation
brush_t brushlist; //deleted brushes
entity_t entitylist; //deleted entities
struct undo_s *prev, *next; //next and prev undo in list
} undo_t;
undo_t *g_undolist; //first undo in the list
undo_t *g_lastundo; //last undo in the list
undo_t *g_redolist; //first redo in the list
undo_t *g_lastredo; //last undo in list
int g_undoMaxSize = 64; //maximum number of undos
int g_undoSize = 0; //number of undos in the list
int g_undoMaxMemorySize = 2*1024*1024; //maximum undo memory (default 2 MB)
int g_undoMemorySize = 0; //memory size of undo buffer
int g_undoId = 1; //current undo ID (zero is invalid id)
int g_redoId = 1; //current redo ID (zero is invalid id)
/*
=============
Undo_MemorySize
=============
*/
int Undo_MemorySize(void)
{
/*
int size;
undo_t *undo;
brush_t *pBrush;
entity_t *pEntity;
size = 0;
for (undo = g_undolist; undo; undo = undo->next)
{
for (pBrush = undo->brushlist.next ; pBrush != NULL && pBrush != &undo->brushlist ; pBrush = pBrush->next)
{
size += Brush_MemorySize(pBrush);
}
for (pEntity = undo->entitylist.next; pEntity != NULL && pEntity != &undo->entitylist; pEntity = pEntity->next)
{
size += Entity_MemorySize(pEntity);
}
size += sizeof(undo_t);
}
return size;
*/
return g_undoMemorySize;
}
/*
=============
Undo_ClearRedo
=============
*/
void Undo_ClearRedo(void)
{
undo_t *redo, *nextredo;
brush_t *pBrush, *pNextBrush;
entity_t *pEntity, *pNextEntity;
for (redo = g_redolist; redo; redo = nextredo)
{
nextredo = redo->next;
for (pBrush = redo->brushlist.next ; pBrush != NULL && pBrush != &redo->brushlist ; pBrush = pNextBrush)
{
pNextBrush = pBrush->next;
Brush_Free(pBrush);
}
for (pEntity = redo->entitylist.next; pEntity != NULL && pEntity != &redo->entitylist; pEntity = pNextEntity)
{
pNextEntity = pEntity->next;
Entity_Free(pEntity);
}
Mem_Free(redo);
}
g_redolist = NULL;
g_lastredo = NULL;
g_redoId = 1;
}
/*
=============
Undo_Clear
Clears the undo buffer.
=============
*/
void Undo_Clear(void)
{
undo_t *undo, *nextundo;
brush_t *pBrush, *pNextBrush;
entity_t *pEntity, *pNextEntity;
Undo_ClearRedo();
for (undo = g_undolist; undo; undo = nextundo)
{
nextundo = undo->next;
for (pBrush = undo->brushlist.next ; pBrush != NULL && pBrush != &undo->brushlist ; pBrush = pNextBrush)
{
pNextBrush = pBrush->next;
g_undoMemorySize -= Brush_MemorySize(pBrush);
Brush_Free(pBrush);
}
for (pEntity = undo->entitylist.next; pEntity != NULL && pEntity != &undo->entitylist; pEntity = pNextEntity)
{
pNextEntity = pEntity->next;
g_undoMemorySize -= Entity_MemorySize(pEntity);
Entity_Free(pEntity);
}
g_undoMemorySize -= sizeof(undo_t);
Mem_Free(undo);
}
g_undolist = NULL;
g_lastundo = NULL;
g_undoSize = 0;
g_undoMemorySize = 0;
g_undoId = 1;
}
/*
=============
Undo_SetMaxSize
=============
*/
void Undo_SetMaxSize(int size)
{
Undo_Clear();
if (size < 1) g_undoMaxSize = 1;
else g_undoMaxSize = size;
}
/*
=============
Undo_GetMaxSize
=============
*/
int Undo_GetMaxSize(void)
{
return g_undoMaxSize;
}
/*
=============
Undo_SetMaxMemorySize
=============
*/
void Undo_SetMaxMemorySize(int size)
{
Undo_Clear();
if (size < 1024) g_undoMaxMemorySize = 1024;
else g_undoMaxMemorySize = size;
}
/*
=============
Undo_GetMaxMemorySize
=============
*/
int Undo_GetMaxMemorySize(void)
{
return g_undoMaxMemorySize;
}
/*
=============
Undo_FreeFirstUndo
=============
*/
void Undo_FreeFirstUndo(void)
{
undo_t *undo;
brush_t *pBrush, *pNextBrush;
entity_t *pEntity, *pNextEntity;
//remove the oldest undo from the undo buffer
undo = g_undolist;
g_undolist = g_undolist->next;
g_undolist->prev = NULL;
//
for (pBrush = undo->brushlist.next ; pBrush != NULL && pBrush != &undo->brushlist ; pBrush = pNextBrush)
{
pNextBrush = pBrush->next;
g_undoMemorySize -= Brush_MemorySize(pBrush);
Brush_Free(pBrush);
}
for (pEntity = undo->entitylist.next; pEntity != NULL && pEntity != &undo->entitylist; pEntity = pNextEntity)
{
pNextEntity = pEntity->next;
g_undoMemorySize -= Entity_MemorySize(pEntity);
Entity_Free(pEntity);
}
g_undoMemorySize -= sizeof(undo_t);
Mem_Free(undo);
g_undoSize--;
}
/*
=============
Undo_GeneralStart
=============
*/
void Undo_GeneralStart(char *operation)
{
undo_t *undo;
brush_t *pBrush;
entity_t *pEntity;
if (g_lastundo)
{
if (!g_lastundo->done)
{
common->Printf("Undo_Start: WARNING last undo not finished.\n");
}
}
undo = (undo_t *) Mem_ClearedAlloc(sizeof(undo_t));
if (!undo) return;
memset(undo, 0, sizeof(undo_t));
undo->brushlist.next = &undo->brushlist;
undo->brushlist.prev = &undo->brushlist;
undo->entitylist.next = &undo->entitylist;
undo->entitylist.prev = &undo->entitylist;
if (g_lastundo) g_lastundo->next = undo;
else g_undolist = undo;
undo->prev = g_lastundo;
undo->next = NULL;
g_lastundo = undo;
undo->time = Sys_DoubleTime();
//
if (g_undoId > g_undoMaxSize * 2) g_undoId = 1;
if (g_undoId <= 0) g_undoId = 1;
undo->id = g_undoId++;
undo->done = false;
undo->operation = operation;
//reset the undo IDs of all brushes using the new ID
for (pBrush = active_brushes.next; pBrush != NULL && pBrush != &active_brushes; pBrush = pBrush->next)
{
if (pBrush->undoId == undo->id)
{
pBrush->undoId = 0;
}
}
for (pBrush = selected_brushes.next; pBrush != NULL && pBrush != &selected_brushes; pBrush = pBrush->next)
{
if (pBrush->undoId == undo->id)
{
pBrush->undoId = 0;
}
}
//reset the undo IDs of all entities using thew new ID
for (pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pEntity->next)
{
if (pEntity->undoId == undo->id)
{
pEntity->undoId = 0;
}
}
g_undoMemorySize += sizeof(undo_t);
g_undoSize++;
//undo buffer is bound to a max
if (g_undoSize > g_undoMaxSize)
{
Undo_FreeFirstUndo();
}
}
/*
=============
Undo_BrushInUndo
=============
*/
int Undo_BrushInUndo(undo_t *undo, brush_t *brush)
{
brush_t *b;
for (b = undo->brushlist.next; b != &undo->brushlist; b = b->next)
{
if (b == brush) return true;
}
return false;
}
/*
=============
Undo_EntityInUndo
=============
*/
int Undo_EntityInUndo(undo_t *undo, entity_t *ent)
{
entity_t *e;
for (e = undo->entitylist.next; e != &undo->entitylist; e = e->next)
{
if (e == ent) return true;
}
return false;
}
/*
=============
Undo_Start
=============
*/
void Undo_Start(char *operation)
{
Undo_ClearRedo();
Undo_GeneralStart(operation);
}
/*
=============
Undo_AddBrush
=============
*/
void Undo_AddBrush(brush_t *pBrush)
{
if (!g_lastundo)
{
Sys_Status("Undo_AddBrushList: no last undo.\n");
return;
}
if (g_lastundo->entitylist.next != &g_lastundo->entitylist)
{
Sys_Status("Undo_AddBrushList: WARNING adding brushes after entity.\n");
}
//if the brush is already in the undo
if (Undo_BrushInUndo(g_lastundo, pBrush))
return;
//clone the brush
brush_t* pClone = Brush_FullClone(pBrush);
//save the ID of the owner entity
pClone->ownerId = pBrush->owner->entityId;
if (pBrush->owner && !(pBrush->owner->eclass->nShowFlags & ECLASS_WORLDSPAWN)) {
Undo_AddEntity(pBrush->owner);
}
//save the old undo ID for previous undos
pClone->undoId = pBrush->undoId;
Brush_AddToList (pClone, &g_lastundo->brushlist);
//
g_undoMemorySize += Brush_MemorySize(pClone);
}
/*
=============
Undo_AddBrushList
=============
*/
void Undo_AddBrushList(brush_t *brushlist)
{
brush_t *pBrush;
if (!g_lastundo)
{
Sys_Status("Undo_AddBrushList: no last undo.\n");
return;
}
if (g_lastundo->entitylist.next != &g_lastundo->entitylist)
{
Sys_Status("Undo_AddBrushList: WARNING adding brushes after entity.\n");
}
//copy the brushes to the undo
for (pBrush = brushlist->next ; pBrush != NULL && pBrush != brushlist; pBrush=pBrush->next)
{
//if the brush is already in the undo
if (Undo_BrushInUndo(g_lastundo, pBrush))
continue;
//clone the brush
brush_t* pClone = Brush_FullClone(pBrush);
//save the ID of the owner entity
pClone->ownerId = pBrush->owner->entityId;
//save the old undo ID from previous undos
pClone->undoId = pBrush->undoId;
if ( pBrush->owner && pBrush->owner != world_entity ) {
Undo_AddEntity(pBrush->owner);
}
Brush_AddToList (pClone, &g_lastundo->brushlist);
//
g_undoMemorySize += Brush_MemorySize(pClone);
}
}
/*
=============
Undo_EndBrush
=============
*/
void Undo_EndBrush(brush_t *pBrush)
{
if (!g_lastundo)
{
//Sys_Status("Undo_End: no last undo.\n");
return;
}
if (g_lastundo->done)
{
//Sys_Status("Undo_End: last undo already finished.\n");
return;
}
pBrush->undoId = g_lastundo->id;
}
/*
=============
Undo_EndBrushList
=============
*/
void Undo_EndBrushList(brush_t *brushlist)
{
if (!g_lastundo)
{
//Sys_Status("Undo_End: no last undo.\n");
return;
}
if (g_lastundo->done)
{
//Sys_Status("Undo_End: last undo already finished.\n");
return;
}
for (brush_t* pBrush = brushlist->next; pBrush != NULL && pBrush != brushlist; pBrush=pBrush->next)
{
pBrush->undoId = g_lastundo->id;
}
}
/*
=============
Undo_AddEntity
=============
*/
void Undo_AddEntity(entity_t *entity)
{
entity_t* pClone;
if (!g_lastundo)
{
Sys_Status("Undo_AddEntity: no last undo.\n");
return;
}
//if the entity is already in the undo
if (Undo_EntityInUndo(g_lastundo, entity))
return;
//clone the entity
pClone = Entity_Clone(entity);
//NOTE: Entity_Clone adds the entity to the entity list
// so we remove it from that list here
Entity_RemoveFromList(pClone);
//save the old undo ID for previous undos
pClone->undoId = entity->undoId;
//save the entity ID (we need a full clone)
pClone->entityId = entity->entityId;
//
Entity_AddToList(pClone, &g_lastundo->entitylist);
//
g_undoMemorySize += Entity_MemorySize(pClone);
}
/*
=============
Undo_EndEntity
=============
*/
void Undo_EndEntity(entity_t *entity)
{
if (!g_lastundo)
{
//Sys_Status("Undo_End: no last undo.\n");
return;
}
if (g_lastundo->done)
{
//Sys_Status("Undo_End: last undo already finished.\n");
return;
}
if (entity == world_entity)
{
//Sys_Status("Undo_AddEntity: undo on world entity.\n");
//NOTE: we never delete the world entity when undoing an operation
// we only transfer the epairs
return;
}
entity->undoId = g_lastundo->id;
}
/*
=============
Undo_End
=============
*/
void Undo_End(void)
{
if (!g_lastundo)
{
//Sys_Status("Undo_End: no last undo.\n");
return;
}
if (g_lastundo->done)
{
//Sys_Status("Undo_End: last undo already finished.\n");
return;
}
g_lastundo->done = true;
//undo memory size is bound to a max
while (g_undoMemorySize > g_undoMaxMemorySize)
{
//always keep one undo
if (g_undolist == g_lastundo) break;
Undo_FreeFirstUndo();
}
//
//Sys_Status("undo size = %d, undo memory = %d\n", g_undoSize, g_undoMemorySize);
}
/*
=============
Undo_Undo
=============
*/
void Undo_Undo(void)
{
undo_t *undo, *redo;
brush_t *pBrush, *pNextBrush;
entity_t *pEntity, *pNextEntity, *pUndoEntity;
if (!g_lastundo)
{
Sys_Status("Nothing left to undo.\n");
return;
}
if (!g_lastundo->done)
{
Sys_Status("Undo_Undo: WARNING: last undo not yet finished!\n");
}
// get the last undo
undo = g_lastundo;
if (g_lastundo->prev) g_lastundo->prev->next = NULL;
else g_undolist = NULL;
g_lastundo = g_lastundo->prev;
//allocate a new redo
redo = (undo_t *) Mem_ClearedAlloc(sizeof(undo_t));
if (!redo) return;
memset(redo, 0, sizeof(undo_t));
redo->brushlist.next = &redo->brushlist;
redo->brushlist.prev = &redo->brushlist;
redo->entitylist.next = &redo->entitylist;
redo->entitylist.prev = &redo->entitylist;
if (g_lastredo) g_lastredo->next = redo;
else g_redolist = redo;
redo->prev = g_lastredo;
redo->next = NULL;
g_lastredo = redo;
redo->time = Sys_DoubleTime();
redo->id = g_redoId++;
redo->done = true;
redo->operation = undo->operation;
//reset the redo IDs of all brushes using the new ID
for (pBrush = active_brushes.next; pBrush != NULL && pBrush != &active_brushes; pBrush = pBrush->next)
{
if (pBrush->redoId == redo->id)
{
pBrush->redoId = 0;
}
}
for (pBrush = selected_brushes.next; pBrush != NULL && pBrush != &selected_brushes; pBrush = pBrush->next)
{
if (pBrush->redoId == redo->id)
{
pBrush->redoId = 0;
}
}
//reset the redo IDs of all entities using thew new ID
for (pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pEntity->next)
{
if (pEntity->redoId == redo->id)
{
pEntity->redoId = 0;
}
}
// remove current selection
Select_Deselect();
// move "created" brushes to the redo
for (pBrush = active_brushes.next; pBrush != NULL && pBrush != &active_brushes; pBrush=pNextBrush)
{
pNextBrush = pBrush->next;
if (pBrush->undoId == undo->id)
{
//Brush_Free(pBrush);
//move the brush to the redo
Brush_RemoveFromList(pBrush);
Brush_AddToList(pBrush, &redo->brushlist);
//make sure the ID of the owner is stored
pBrush->ownerId = pBrush->owner->entityId;
//unlink the brush from the owner entity
Entity_UnlinkBrush(pBrush);
}
}
// move "created" entities to the redo
for (pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pNextEntity)
{
pNextEntity = pEntity->next;
if (pEntity->undoId == undo->id)
{
// check if this entity is in the undo
for (pUndoEntity = undo->entitylist.next; pUndoEntity != NULL && pUndoEntity != &undo->entitylist; pUndoEntity = pUndoEntity->next)
{
// move brushes to the undo entity
if (pUndoEntity->entityId == pEntity->entityId)
{
pUndoEntity->brushes.next = pEntity->brushes.next;
pUndoEntity->brushes.prev = pEntity->brushes.prev;
pEntity->brushes.next = &pEntity->brushes;
pEntity->brushes.prev = &pEntity->brushes;
}
}
//
//Entity_Free(pEntity);
//move the entity to the redo
Entity_RemoveFromList(pEntity);
Entity_AddToList(pEntity, &redo->entitylist);
}
}
// add the undo entities back into the entity list
for (pEntity = undo->entitylist.next; pEntity != NULL && pEntity != &undo->entitylist; pEntity = undo->entitylist.next)
{
g_undoMemorySize -= Entity_MemorySize(pEntity);
//if this is the world entity
if (pEntity->entityId == world_entity->entityId)
{
//free the epairs of the world entity
Entity_FreeEpairs(world_entity);
//set back the original epairs
world_entity->epairs = pEntity->epairs;
//free the world_entity clone that stored the epairs
Entity_Free(pEntity);
}
else
{
Entity_RemoveFromList(pEntity);
Entity_AddToList(pEntity, &entities);
pEntity->redoId = redo->id;
}
}
// add the undo brushes back into the selected brushes
for (pBrush = undo->brushlist.next; pBrush != NULL && pBrush != &undo->brushlist; pBrush = undo->brushlist.next)
{
g_undoMemorySize -= Brush_MemorySize(pBrush);
Brush_RemoveFromList(pBrush);
Brush_AddToList(pBrush, &active_brushes);
for (pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pEntity->next)
{
if (pEntity->entityId == pBrush->ownerId)
{
Entity_LinkBrush(pEntity, pBrush);
break;
}
}
//if the brush is not linked then it should be linked into the world entity
if (pEntity == NULL || pEntity == &entities)
{
Entity_LinkBrush(world_entity, pBrush);
}
//build the brush
//Brush_Build(pBrush);
Select_Brush(pBrush);
pBrush->redoId = redo->id;
}
//
common->Printf("%s undone.\n", undo->operation);
// free the undo
g_undoMemorySize -= sizeof(undo_t);
Mem_Free(undo);
g_undoSize--;
g_undoId--;
if (g_undoId <= 0) g_undoId = 2 * g_undoMaxSize;
//
Sys_BeginWait();
brush_t *b, *next;
for (b = active_brushes.next ; b != NULL && b != &active_brushes ; b=next) {
next = b->next;
Brush_Build( b, true, false, false );
}
for (b = selected_brushes.next ; b != NULL && b != &selected_brushes ; b=next) {
next = b->next;
Brush_Build( b, true, false, false );
}
Sys_EndWait();
g_bScreenUpdates = true;
Sys_UpdateWindows(W_ALL);
}
/*
=============
Undo_Redo
=============
*/
void Undo_Redo(void)
{
undo_t *redo;
brush_t *pBrush, *pNextBrush;
entity_t *pEntity, *pNextEntity, *pRedoEntity;
if (!g_lastredo)
{
Sys_Status("Nothing left to redo.\n");
return;
}
if (g_lastundo)
{
if (!g_lastundo->done)
{
Sys_Status("WARNING: last undo not finished.\n");
}
}
// get the last redo
redo = g_lastredo;
if (g_lastredo->prev) g_lastredo->prev->next = NULL;
else g_redolist = NULL;
g_lastredo = g_lastredo->prev;
//
Undo_GeneralStart(redo->operation);
// remove current selection
Select_Deselect();
// move "created" brushes back to the last undo
for (pBrush = active_brushes.next; pBrush != NULL && pBrush != &active_brushes; pBrush = pNextBrush)
{
pNextBrush = pBrush->next;
if (pBrush->redoId == redo->id)
{
//move the brush to the undo
Brush_RemoveFromList(pBrush);
Brush_AddToList(pBrush, &g_lastundo->brushlist);
g_undoMemorySize += Brush_MemorySize(pBrush);
pBrush->ownerId = pBrush->owner->entityId;
Entity_UnlinkBrush(pBrush);
}
}
// move "created" entities back to the last undo
for (pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pNextEntity)
{
pNextEntity = pEntity->next;
if (pEntity->redoId == redo->id)
{
// check if this entity is in the redo
for (pRedoEntity = redo->entitylist.next; pRedoEntity != NULL && pRedoEntity != &redo->entitylist; pRedoEntity = pRedoEntity->next)
{
// move brushes to the redo entity
if (pRedoEntity->entityId == pEntity->entityId)
{
pRedoEntity->brushes.next = pEntity->brushes.next;
pRedoEntity->brushes.prev = pEntity->brushes.prev;
pEntity->brushes.next = &pEntity->brushes;
pEntity->brushes.prev = &pEntity->brushes;
}
}
//
//Entity_Free(pEntity);
//move the entity to the redo
Entity_RemoveFromList(pEntity);
Entity_AddToList(pEntity, &g_lastundo->entitylist);
g_undoMemorySize += Entity_MemorySize(pEntity);
}
}
// add the undo entities back into the entity list
for (pEntity = redo->entitylist.next; pEntity != NULL && pEntity != &redo->entitylist; pEntity = redo->entitylist.next)
{
//if this is the world entity
if (pEntity->entityId == world_entity->entityId)
{
//free the epairs of the world entity
Entity_FreeEpairs(world_entity);
//set back the original epairs
world_entity->epairs = pEntity->epairs;
//free the world_entity clone that stored the epairs
Entity_Free(pEntity);
}
else
{
Entity_RemoveFromList(pEntity);
Entity_AddToList(pEntity, &entities);
}
}
// add the redo brushes back into the selected brushes
for (pBrush = redo->brushlist.next; pBrush != NULL && pBrush != &redo->brushlist; pBrush = redo->brushlist.next)
{
Brush_RemoveFromList(pBrush);
Brush_AddToList(pBrush, &active_brushes);
for (pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pEntity->next)
{
if (pEntity->entityId == pBrush->ownerId)
{
Entity_LinkBrush(pEntity, pBrush);
break;
}
}
//if the brush is not linked then it should be linked into the world entity
if (pEntity == NULL || pEntity == &entities)
{
Entity_LinkBrush(world_entity, pBrush);
}
//build the brush
//Brush_Build(pBrush);
Select_Brush(pBrush);
}
//
Undo_End();
//
common->Printf("%s redone.\n", redo->operation);
//
g_redoId--;
// free the undo
Mem_Free(redo);
//
g_bScreenUpdates = true;
Sys_UpdateWindows(W_ALL);
}
/*
=============
Undo_RedoAvailable
=============
*/
int Undo_RedoAvailable(void)
{
if (g_lastredo) return true;
return false;
}
/*
=============
Undo_UndoAvailable
=============
*/
int Undo_UndoAvailable(void)
{
if (g_lastundo)
{
if (g_lastundo->done)
return true;
}
return false;
}
|