2007-11-04 03:51:54 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
QERadiant Undo/Redo
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
basic setup:
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
<-g_undolist---------g_lastundo> <---map data---> <-g_lastredo---------g_redolist->
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
undo/redo on the world_entity is special, only the epair changes are remembered
|
|
|
|
and the world entity never gets deleted.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
FIXME: maybe reset the Undo system at map load
|
|
|
|
maybe also reset the entityId at map load
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
typedef struct undo_s
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
double time; //time operation was performed
|
|
|
|
int id; //every undo has an unique id
|
|
|
|
int done; //true when undo is build
|
|
|
|
const 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
|
2007-11-04 03:51:54 +00:00
|
|
|
} undo_t;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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)
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_MemorySize
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
int Undo_MemorySize( void ){
|
2007-11-04 03:51:54 +00:00
|
|
|
return g_undoMemorySize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_ClearRedo
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_ClearRedo( void ){
|
2007-11-04 03:51:54 +00:00
|
|
|
undo_t *redo, *nextredo;
|
|
|
|
brush_t *pBrush, *pNextBrush;
|
|
|
|
entity_t *pEntity, *pNextEntity;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( redo = g_redolist; redo; redo = nextredo )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
nextredo = redo->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pBrush = redo->brushlist.next ; pBrush != NULL && pBrush != &redo->brushlist ; pBrush = pNextBrush )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
pNextBrush = pBrush->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
Brush_Free( pBrush );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pEntity = redo->entitylist.next; pEntity != NULL && pEntity != &redo->entitylist; pEntity = pNextEntity )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
pNextEntity = pEntity->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
Entity_Free( pEntity );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
free( redo );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
g_redolist = NULL;
|
|
|
|
g_lastredo = NULL;
|
|
|
|
g_redoId = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_Clear
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Clears the undo buffer.
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_Clear( void ){
|
2007-11-04 03:51:54 +00:00
|
|
|
undo_t *undo, *nextundo;
|
|
|
|
brush_t *pBrush, *pNextBrush;
|
|
|
|
entity_t *pEntity, *pNextEntity;
|
|
|
|
|
|
|
|
Undo_ClearRedo();
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( undo = g_undolist; undo; undo = nextundo )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
nextundo = undo->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pBrush = undo->brushlist.next ; pBrush != NULL && pBrush != &undo->brushlist ; pBrush = pNextBrush )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
pNextBrush = pBrush->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
g_undoMemorySize -= Brush_MemorySize( pBrush );
|
|
|
|
Brush_Free( pBrush );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pEntity = undo->entitylist.next; pEntity != NULL && pEntity != &undo->entitylist; pEntity = pNextEntity )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
pNextEntity = pEntity->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
g_undoMemorySize -= Entity_MemorySize( pEntity );
|
|
|
|
Entity_Free( pEntity );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
g_undoMemorySize -= sizeof( undo_t );
|
|
|
|
free( undo );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
g_undolist = NULL;
|
|
|
|
g_lastundo = NULL;
|
|
|
|
g_undoSize = 0;
|
|
|
|
g_undoMemorySize = 0;
|
|
|
|
g_undoId = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_SetMaxSize
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_SetMaxSize( int size ){
|
2007-11-04 03:51:54 +00:00
|
|
|
Undo_Clear();
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( size < 1 ) {
|
|
|
|
g_undoMaxSize = 1;
|
|
|
|
}
|
|
|
|
else{g_undoMaxSize = size; }
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_GetMaxSize
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
int Undo_GetMaxSize( void ){
|
2007-11-04 03:51:54 +00:00
|
|
|
return g_undoMaxSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_SetMaxMemorySize
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_SetMaxMemorySize( int size ){
|
2007-11-04 03:51:54 +00:00
|
|
|
Undo_Clear();
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( size < 1024 ) {
|
|
|
|
g_undoMaxMemorySize = 1024;
|
|
|
|
}
|
|
|
|
else{g_undoMaxMemorySize = size; }
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_GetMaxMemorySize
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
int Undo_GetMaxMemorySize( void ){
|
2007-11-04 03:51:54 +00:00
|
|
|
return g_undoMaxMemorySize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_FreeFirstUndo
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_FreeFirstUndo( void ){
|
2007-11-04 03:51:54 +00:00
|
|
|
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;
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pBrush = undo->brushlist.next ; pBrush != NULL && pBrush != &undo->brushlist ; pBrush = pNextBrush )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
pNextBrush = pBrush->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
g_undoMemorySize -= Brush_MemorySize( pBrush );
|
|
|
|
Brush_Free( pBrush );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pEntity = undo->entitylist.next; pEntity != NULL && pEntity != &undo->entitylist; pEntity = pNextEntity )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
pNextEntity = pEntity->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
g_undoMemorySize -= Entity_MemorySize( pEntity );
|
|
|
|
Entity_Free( pEntity );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
g_undoMemorySize -= sizeof( undo_t );
|
|
|
|
free( undo );
|
2007-11-04 03:51:54 +00:00
|
|
|
g_undoSize--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_GeneralStart
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_GeneralStart( const char *operation ){
|
2007-11-04 03:51:54 +00:00
|
|
|
undo_t *undo;
|
|
|
|
brush_t *pBrush;
|
|
|
|
entity_t *pEntity;
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_lastundo ) {
|
|
|
|
if ( !g_lastundo->done ) {
|
|
|
|
Sys_Printf( "Undo_Start: WARNING last undo not finished.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
undo = (undo_t *) malloc( sizeof( undo_t ) );
|
|
|
|
if ( !undo ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memset( undo, 0, sizeof( undo_t ) );
|
2007-11-04 03:51:54 +00:00
|
|
|
undo->brushlist.next = &undo->brushlist;
|
|
|
|
undo->brushlist.prev = &undo->brushlist;
|
|
|
|
undo->entitylist.next = &undo->entitylist;
|
|
|
|
undo->entitylist.prev = &undo->entitylist;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_lastundo ) {
|
|
|
|
g_lastundo->next = undo;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
g_undolist = undo;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
undo->prev = g_lastundo;
|
|
|
|
undo->next = NULL;
|
|
|
|
g_lastundo = undo;
|
2008-06-26 07:52:02 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
undo->time = Sys_DoubleTime();
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_undoId > g_undoMaxSize * 2 ) {
|
|
|
|
g_undoId = 1;
|
|
|
|
}
|
|
|
|
if ( g_undoId <= 0 ) {
|
|
|
|
g_undoId = 1;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
undo->id = g_undoId++;
|
|
|
|
undo->done = false;
|
|
|
|
undo->operation = operation;
|
|
|
|
//reset the undo IDs of all brushes using the new ID
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pBrush = active_brushes.next; pBrush != NULL && pBrush != &active_brushes; pBrush = pBrush->next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pBrush->undoId == undo->id ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
pBrush->undoId = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pBrush = selected_brushes.next; pBrush != NULL && pBrush != &selected_brushes; pBrush = pBrush->next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pBrush->undoId == undo->id ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
pBrush->undoId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//reset the undo IDs of all entities using thew new ID
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pEntity->next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pEntity->undoId == undo->id ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
pEntity->undoId = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
g_undoMemorySize += sizeof( undo_t );
|
2007-11-04 03:51:54 +00:00
|
|
|
g_undoSize++;
|
|
|
|
//undo buffer is bound to a max
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_undoSize > g_undoMaxSize ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
Undo_FreeFirstUndo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_BrushInUndo
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
int Undo_BrushInUndo( undo_t *undo, brush_t *brush ){
|
2007-11-04 03:51:54 +00:00
|
|
|
/* brush_t *b;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for (b = undo->brushlist.next; b != &undo->brushlist; b = b->next)
|
|
|
|
{
|
2007-11-04 03:51:54 +00:00
|
|
|
// Arnout: NOTE - can't do a pointer compare as the brushes get cloned into the undo brushlist, and not just referenced from it
|
|
|
|
// For entities we have a unique ID, for brushes we have numberID - but brush full clone increases that anyway so it's useless right now.
|
2012-03-17 20:01:54 +00:00
|
|
|
if (b == brush) return true;
|
|
|
|
}*/
|
|
|
|
// Arnout: function is pointless right now, see above explanation
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_EntityInUndo
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
int Undo_EntityInUndo( undo_t *undo, entity_t *ent ){
|
2007-11-04 03:51:54 +00:00
|
|
|
entity_t *e;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( e = undo->entitylist.next; e != &undo->entitylist; e = e->next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
// Arnout: NOTE - can't do a pointer compare as the entities get cloned into the undo entitylist, and not just referenced from it
|
2007-11-04 03:51:54 +00:00
|
|
|
//if (e == ent) return true;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( e->entityId == ent->entityId ) {
|
|
|
|
return true;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_Start
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_Start( const char *operation ){
|
2007-11-04 03:51:54 +00:00
|
|
|
// spog - disable undo if undo levels = 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_PrefsDlg.m_nUndoLevels == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef DBG_UNDO
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "Undo_Start: undo is disabled.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2008-06-26 07:52:02 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
Undo_ClearRedo();
|
2012-03-17 20:01:54 +00:00
|
|
|
Undo_GeneralStart( operation );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_AddBrush
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_AddBrush( brush_t *pBrush ){
|
2007-11-04 03:51:54 +00:00
|
|
|
// spog - disable undo if undo levels = 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_PrefsDlg.m_nUndoLevels == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef DBG_UNDO
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "Undo_AddBrush: undo is disabled.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2008-06-26 07:52:02 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !g_lastundo ) {
|
|
|
|
Sys_Printf( "Undo_AddBrushList: no last undo.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_lastundo->entitylist.next != &g_lastundo->entitylist ) {
|
|
|
|
Sys_Printf( "Undo_AddBrushList: WARNING adding brushes after entity.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
//if the brush is already in the undo
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( Undo_BrushInUndo( g_lastundo, pBrush ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
//clone the brush
|
2012-03-17 20:01:54 +00:00
|
|
|
brush_t* pClone = Brush_FullClone( pBrush );
|
2007-11-04 03:51:54 +00:00
|
|
|
//save the ID of the owner entity
|
|
|
|
pClone->ownerId = pBrush->owner->entityId;
|
|
|
|
//save the old undo ID for previous undos
|
|
|
|
pClone->undoId = pBrush->undoId;
|
2012-03-17 20:01:54 +00:00
|
|
|
Brush_AddToList( pClone, &g_lastundo->brushlist );
|
2007-11-04 03:51:54 +00:00
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
g_undoMemorySize += Brush_MemorySize( pClone );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_AddBrushList
|
|
|
|
TTimo: some brushes are just there for UI, and the information is somewhere else
|
|
|
|
for patches it's in the patchMesh_t structure, so when we clone the brush we get that information (brush_t::pPatch)
|
|
|
|
but: models are stored in pBrush->owner->md3Class, and owner epairs and origin parameters are important
|
|
|
|
so, we detect models and push the entity in the undo session (as well as it's BBox brush)
|
|
|
|
same for other items like weapons and ammo etc.
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_AddBrushList( brush_t *brushlist ){
|
2007-11-04 03:51:54 +00:00
|
|
|
// spog - disable undo if undo levels = 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_PrefsDlg.m_nUndoLevels == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef DBG_UNDO
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "Undo_AddBrushList: undo is disabled.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2008-06-26 07:52:02 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
brush_t *pBrush;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !g_lastundo ) {
|
|
|
|
Sys_Printf( "Undo_AddBrushList: no last undo.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_lastundo->entitylist.next != &g_lastundo->entitylist ) {
|
|
|
|
Sys_Printf( "Undo_AddBrushList: WARNING adding brushes after entity.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
//copy the brushes to the undo
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pBrush = brushlist->next ; pBrush != NULL && pBrush != brushlist; pBrush = pBrush->next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
//if the brush is already in the undo
|
|
|
|
//++timo FIXME: when does this happen?
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( Undo_BrushInUndo( g_lastundo, pBrush ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
// do we need to store this brush's entity in the undo?
|
|
|
|
// if it's a fixed size entity, the brush that reprents it is not really relevant, it's used for selecting and moving around
|
|
|
|
// what we want to store for undo is the owner entity, epairs and origin/angle stuff
|
|
|
|
//++timo FIXME: if the entity is not fixed size I don't know, so I don't do it yet
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pBrush->owner->eclass->fixedsize == 1 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
Undo_AddEntity( pBrush->owner );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
// clone the brush
|
2012-03-17 20:01:54 +00:00
|
|
|
brush_t* pClone = Brush_FullClone( pBrush );
|
2007-11-04 03:51:54 +00:00
|
|
|
// save the ID of the owner entity
|
|
|
|
pClone->ownerId = pBrush->owner->entityId;
|
|
|
|
// save the old undo ID from previous undos
|
|
|
|
pClone->undoId = pBrush->undoId;
|
2012-03-17 20:01:54 +00:00
|
|
|
Brush_AddToList( pClone, &g_lastundo->brushlist );
|
2007-11-04 03:51:54 +00:00
|
|
|
// track memory size used by undo
|
2012-03-17 20:01:54 +00:00
|
|
|
g_undoMemorySize += Brush_MemorySize( pClone );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_EndBrush
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_EndBrush( brush_t *pBrush ){
|
2007-11-04 03:51:54 +00:00
|
|
|
// spog - disable undo if undo levels = 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_PrefsDlg.m_nUndoLevels == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef DBG_UNDO
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "Undo_EndBrush: undo is disabled.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2008-06-26 07:52:02 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !g_lastundo ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
//Sys_Printf("Undo_End: no last undo.\n");
|
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_lastundo->done ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
//Sys_Printf("Undo_End: last undo already finished.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pBrush->undoId = g_lastundo->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_EndBrushList
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_EndBrushList( brush_t *brushlist ){
|
2007-11-04 03:51:54 +00:00
|
|
|
// spog - disable undo if undo levels = 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_PrefsDlg.m_nUndoLevels == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef DBG_UNDO
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "Undo_EndBrushList: undo is disabled.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2008-06-26 07:52:02 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !g_lastundo ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
//Sys_Printf("Undo_End: no last undo.\n");
|
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_lastundo->done ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
//Sys_Printf("Undo_End: last undo already finished.\n");
|
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( brush_t* pBrush = brushlist->next; pBrush != NULL && pBrush != brushlist; pBrush = pBrush->next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
pBrush->undoId = g_lastundo->id;
|
2010-01-08 04:01:08 +00:00
|
|
|
// http://github.com/mfn/GtkRadiant/commit/ee1ef98536470d5680bd9bfecc5b5c9a62ffe9ab
|
|
|
|
if ( pBrush->owner->eclass->fixedsize == 1 ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
pBrush->owner->undoId = pBrush->undoId;
|
2010-01-08 04:01:08 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_AddEntity
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_AddEntity( entity_t *entity ){
|
2007-11-04 03:51:54 +00:00
|
|
|
// spog - disable undo if undo levels = 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_PrefsDlg.m_nUndoLevels == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef DBG_UNDO
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "Undo_AddEntity: undo is disabled.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2008-06-26 07:52:02 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
entity_t* pClone;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !g_lastundo ) {
|
|
|
|
Sys_Printf( "Undo_AddEntity: no last undo.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
//if the entity is already in the undo
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( Undo_EntityInUndo( g_lastundo, entity ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
//clone the entity
|
2012-03-17 20:01:54 +00:00
|
|
|
pClone = Entity_Clone( entity );
|
2007-11-04 03:51:54 +00:00
|
|
|
//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;
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
Entity_AddToList( pClone, &g_lastundo->entitylist );
|
2007-11-04 03:51:54 +00:00
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
g_undoMemorySize += Entity_MemorySize( pClone );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_EndEntity
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_EndEntity( entity_t *entity ){
|
2007-11-04 03:51:54 +00:00
|
|
|
// spog - disable undo if undo levels = 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_PrefsDlg.m_nUndoLevels == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef DBG_UNDO
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "Undo_EndEntity: undo is disabled.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !g_lastundo ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef _DEBUG
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "Undo_End: no last undo.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_lastundo->done ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef _DEBUG
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "Undo_End: last undo already finished.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( entity == world_entity ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
//Sys_Printf("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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_End
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_End( void ){
|
2007-11-04 03:51:54 +00:00
|
|
|
// spog - disable undo if undo levels = 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_PrefsDlg.m_nUndoLevels == 0 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef DBG_UNDO
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "Undo_End: undo is disabled.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2008-06-26 07:52:02 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !g_lastundo ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
//Sys_Printf("Undo_End: no last undo.\n");
|
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_lastundo->done ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
//Sys_Printf("Undo_End: last undo already finished.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
g_lastundo->done = true;
|
|
|
|
|
|
|
|
//undo memory size is bound to a max
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( g_undoMemorySize > g_undoMaxMemorySize )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
//always keep one undo
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_undolist == g_lastundo ) {
|
|
|
|
break;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
Undo_FreeFirstUndo();
|
|
|
|
}
|
|
|
|
//
|
|
|
|
//Sys_Printf("undo size = %d, undo memory = %d\n", g_undoSize, g_undoMemorySize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_Undo
|
|
|
|
=============
|
|
|
|
*/
|
2012-05-28 01:17:32 +00:00
|
|
|
void Undo_Undo( qboolean bSilent ){
|
2007-11-04 03:51:54 +00:00
|
|
|
// spog - disable undo if undo levels = 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_PrefsDlg.m_nUndoLevels == 0 ) {
|
|
|
|
Sys_Printf( "Undo_Undo: undo is disabled.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-06-26 07:52:02 +00:00
|
|
|
|
2007-11-04 03:51:54 +00:00
|
|
|
undo_t *undo, *redo;
|
|
|
|
brush_t *pBrush, *pNextBrush;
|
|
|
|
entity_t *pEntity, *pNextEntity, *pUndoEntity;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !g_lastundo ) {
|
|
|
|
Sys_Printf( "Nothing left to undo.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !g_lastundo->done ) {
|
|
|
|
Sys_Printf( "Undo_Undo: WARNING: last undo not yet finished!\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
// get the last undo
|
|
|
|
undo = g_lastundo;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_lastundo->prev ) {
|
|
|
|
g_lastundo->prev->next = NULL;
|
|
|
|
}
|
|
|
|
else{g_undolist = NULL; }
|
2007-11-04 03:51:54 +00:00
|
|
|
g_lastundo = g_lastundo->prev;
|
|
|
|
|
|
|
|
//allocate a new redo
|
2012-03-17 20:01:54 +00:00
|
|
|
redo = (undo_t *) malloc( sizeof( undo_t ) );
|
|
|
|
if ( !redo ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memset( redo, 0, sizeof( undo_t ) );
|
2007-11-04 03:51:54 +00:00
|
|
|
redo->brushlist.next = &redo->brushlist;
|
|
|
|
redo->brushlist.prev = &redo->brushlist;
|
|
|
|
redo->entitylist.next = &redo->entitylist;
|
|
|
|
redo->entitylist.prev = &redo->entitylist;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_lastredo ) {
|
|
|
|
g_lastredo->next = redo;
|
|
|
|
}
|
|
|
|
else{g_redolist = redo; }
|
2007-11-04 03:51:54 +00:00
|
|
|
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
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pBrush = active_brushes.next; pBrush != NULL && pBrush != &active_brushes; pBrush = pBrush->next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pBrush->redoId == redo->id ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
pBrush->redoId = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pBrush = selected_brushes.next; pBrush != NULL && pBrush != &selected_brushes; pBrush = pBrush->next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pBrush->redoId == redo->id ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
pBrush->redoId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//reset the redo IDs of all entities using thew new ID
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pEntity->next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pEntity->redoId == redo->id ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
pEntity->redoId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// deselect current sutff
|
|
|
|
Select_Deselect();
|
|
|
|
// move "created" brushes to the redo
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pBrush = active_brushes.next; pBrush != NULL && pBrush != &active_brushes; pBrush = pNextBrush )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
pNextBrush = pBrush->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pBrush->undoId == undo->id ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
//Brush_Free(pBrush);
|
|
|
|
//move the brush to the redo
|
2012-03-17 20:01:54 +00:00
|
|
|
Brush_RemoveFromList( pBrush );
|
|
|
|
Brush_AddToList( pBrush, &redo->brushlist );
|
2007-11-04 03:51:54 +00:00
|
|
|
//make sure the ID of the owner is stored
|
|
|
|
pBrush->ownerId = pBrush->owner->entityId;
|
|
|
|
//unlink the brush from the owner entity
|
2012-03-17 20:01:54 +00:00
|
|
|
Entity_UnlinkBrush( pBrush );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// move "created" entities to the redo
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pNextEntity )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
pNextEntity = pEntity->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pEntity->undoId == undo->id ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
// check if this entity is in the undo
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pUndoEntity = undo->entitylist.next; pUndoEntity != NULL && pUndoEntity != &undo->entitylist; pUndoEntity = pUndoEntity->next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
// move brushes to the undo entity
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pUndoEntity->entityId == pEntity->entityId ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
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
|
2012-03-17 20:01:54 +00:00
|
|
|
Entity_RemoveFromList( pEntity );
|
|
|
|
Entity_AddToList( pEntity, &redo->entitylist );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// add the undo entities back into the entity list
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pEntity = undo->entitylist.next; pEntity != NULL && pEntity != &undo->entitylist; pEntity = undo->entitylist.next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
g_undoMemorySize -= Entity_MemorySize( pEntity );
|
2007-11-04 03:51:54 +00:00
|
|
|
//if this is the world entity
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pEntity->entityId == world_entity->entityId ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
epair_t* tmp = world_entity->epairs;
|
|
|
|
world_entity->epairs = pEntity->epairs;
|
2012-03-17 20:01:54 +00:00
|
|
|
pEntity->epairs = tmp;
|
|
|
|
Entity_Free( pEntity );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
Entity_RemoveFromList( pEntity );
|
|
|
|
Entity_AddToList( pEntity, &entities );
|
2007-11-04 03:51:54 +00:00
|
|
|
pEntity->redoId = redo->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// add the undo brushes back into the selected brushes
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pBrush = undo->brushlist.next; pBrush != NULL && pBrush != &undo->brushlist; pBrush = undo->brushlist.next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
//Sys_Printf("Owner ID: %i\n",pBrush->ownerId);
|
2012-03-17 20:01:54 +00:00
|
|
|
g_undoMemorySize -= Brush_MemorySize( pBrush );
|
|
|
|
Brush_RemoveFromList( pBrush );
|
|
|
|
Brush_AddToList( pBrush, &active_brushes );
|
|
|
|
for ( pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pEntity->next ) // fixes broken undo on entities
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
//Sys_Printf("Entity ID: %i\n",pEntity->entityId);
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pEntity->entityId == pBrush->ownerId ) {
|
|
|
|
Entity_LinkBrush( pEntity, pBrush );
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//if the brush is not linked then it should be linked into the world entity
|
|
|
|
//++timo FIXME: maybe not, maybe we've lost this entity's owner!
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pEntity == NULL || pEntity == &entities ) {
|
|
|
|
Entity_LinkBrush( world_entity, pBrush );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
//build the brush
|
|
|
|
//Brush_Build(pBrush);
|
2012-03-17 20:01:54 +00:00
|
|
|
Select_Brush( pBrush );
|
2007-11-04 03:51:54 +00:00
|
|
|
pBrush->redoId = redo->id;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( !bSilent ) {
|
|
|
|
Sys_Printf( "%s undone.\n", undo->operation );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
// free the undo
|
2012-03-17 20:01:54 +00:00
|
|
|
g_undoMemorySize -= sizeof( undo_t );
|
|
|
|
free( undo );
|
2007-11-04 03:51:54 +00:00
|
|
|
g_undoSize--;
|
|
|
|
g_undoId--;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_undoId <= 0 ) {
|
|
|
|
g_undoId = 2 * g_undoMaxSize;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
g_bScreenUpdates = true;
|
|
|
|
UpdateSurfaceDialog();
|
|
|
|
Sys_UpdateWindows( W_ALL );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_Redo
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void Undo_Redo( void ){
|
2007-11-04 03:51:54 +00:00
|
|
|
// spog - disable undo if undo levels = 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_PrefsDlg.m_nUndoLevels == 0 ) {
|
|
|
|
Sys_Printf( "Undo_Redo: undo is disabled.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_t *redo;
|
|
|
|
brush_t *pBrush, *pNextBrush;
|
|
|
|
entity_t *pEntity, *pNextEntity, *pRedoEntity;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !g_lastredo ) {
|
|
|
|
Sys_Printf( "Nothing left to redo.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_lastundo ) {
|
|
|
|
if ( !g_lastundo->done ) {
|
|
|
|
Sys_Printf( "WARNING: last undo not finished.\n" );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// get the last redo
|
|
|
|
redo = g_lastredo;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_lastredo->prev ) {
|
|
|
|
g_lastredo->prev->next = NULL;
|
|
|
|
}
|
|
|
|
else{g_redolist = NULL; }
|
2007-11-04 03:51:54 +00:00
|
|
|
g_lastredo = g_lastredo->prev;
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
Undo_GeneralStart( redo->operation );
|
2007-11-04 03:51:54 +00:00
|
|
|
// remove current selection
|
|
|
|
Select_Deselect();
|
|
|
|
// move "created" brushes back to the last undo
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pBrush = active_brushes.next; pBrush != NULL && pBrush != &active_brushes; pBrush = pNextBrush )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
pNextBrush = pBrush->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pBrush->redoId == redo->id ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
//move the brush to the undo
|
2012-03-17 20:01:54 +00:00
|
|
|
Brush_RemoveFromList( pBrush );
|
|
|
|
Brush_AddToList( pBrush, &g_lastundo->brushlist );
|
|
|
|
g_undoMemorySize += Brush_MemorySize( pBrush );
|
2007-11-04 03:51:54 +00:00
|
|
|
pBrush->ownerId = pBrush->owner->entityId;
|
2012-03-17 20:01:54 +00:00
|
|
|
Entity_UnlinkBrush( pBrush );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// move "created" entities back to the last undo
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pNextEntity )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
pNextEntity = pEntity->next;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pEntity->redoId == redo->id ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
// check if this entity is in the redo
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pRedoEntity = redo->entitylist.next; pRedoEntity != NULL && pRedoEntity != &redo->entitylist; pRedoEntity = pRedoEntity->next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
// move brushes to the redo entity
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pRedoEntity->entityId == pEntity->entityId ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
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
|
2012-03-17 20:01:54 +00:00
|
|
|
Entity_RemoveFromList( pEntity );
|
|
|
|
Entity_AddToList( pEntity, &g_lastundo->entitylist );
|
|
|
|
g_undoMemorySize += Entity_MemorySize( pEntity );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// add the undo entities back into the entity list
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pEntity = redo->entitylist.next; pEntity != NULL && pEntity != &redo->entitylist; pEntity = redo->entitylist.next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
|
|
|
//if this is the world entity
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pEntity->entityId == world_entity->entityId ) {
|
|
|
|
epair_t* tmp = world_entity->epairs;
|
2007-11-04 03:51:54 +00:00
|
|
|
world_entity->epairs = pEntity->epairs;
|
2012-03-17 20:01:54 +00:00
|
|
|
pEntity->epairs = tmp;
|
|
|
|
Entity_Free( pEntity );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
Entity_RemoveFromList( pEntity );
|
|
|
|
Entity_AddToList( pEntity, &entities );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// add the redo brushes back into the selected brushes
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( pBrush = redo->brushlist.next; pBrush != NULL && pBrush != &redo->brushlist; pBrush = redo->brushlist.next )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
Brush_RemoveFromList( pBrush );
|
|
|
|
Brush_AddToList( pBrush, &active_brushes );
|
|
|
|
for ( pEntity = entities.next; pEntity != NULL && pEntity != &entities; pEntity = pEntity->next ) // fixes broken undo on entities
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pEntity->entityId == pBrush->ownerId ) {
|
|
|
|
Entity_LinkBrush( pEntity, pBrush );
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//if the brush is not linked then it should be linked into the world entity
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( pEntity == NULL || pEntity == &entities ) {
|
|
|
|
Entity_LinkBrush( world_entity, pBrush );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
//build the brush
|
|
|
|
//Brush_Build(pBrush);
|
2012-03-17 20:01:54 +00:00
|
|
|
Select_Brush( pBrush );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
//
|
|
|
|
Undo_End();
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "%s redone.\n", redo->operation );
|
2007-11-04 03:51:54 +00:00
|
|
|
//
|
|
|
|
g_redoId--;
|
|
|
|
// free the undo
|
2012-03-17 20:01:54 +00:00
|
|
|
free( redo );
|
2007-11-04 03:51:54 +00:00
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
g_bScreenUpdates = true;
|
|
|
|
UpdateSurfaceDialog();
|
|
|
|
Sys_UpdateWindows( W_ALL );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_RedoAvailable
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
int Undo_RedoAvailable( void ){
|
|
|
|
if ( g_lastredo ) {
|
|
|
|
return true;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int Undo_GetUndoId( void ){
|
|
|
|
if ( g_lastundo ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return g_lastundo->id;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
Undo_UndoAvailable
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
int Undo_UndoAvailable( void ){
|
|
|
|
if ( g_lastundo ) {
|
|
|
|
if ( g_lastundo->done ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return true;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|