Example #1
0
/*
   =============
   Undo_Start
   =============
 */
void Undo_Start( const char *operation ){
	// spog - disable undo if undo levels = 0
	if ( g_PrefsDlg.m_nUndoLevels == 0 ) {
#ifdef DBG_UNDO
		Sys_Printf( "Undo_Start: undo is disabled.\n" );
#endif
		return;
	}

	Undo_ClearRedo();
	Undo_GeneralStart( operation );
}
Example #2
0
/*
=============
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);
}
Example #3
0
/*
=============
Undo_Start
=============
*/
void Undo_Start(char *operation)
{
	Undo_ClearRedo();
	Undo_GeneralStart(operation);
}
Example #4
0
/*
   =============
   Undo_Redo
   =============
 */
void Undo_Redo( void ){
	// spog - disable undo if undo levels = 0
	if ( g_PrefsDlg.m_nUndoLevels == 0 ) {
		Sys_Printf( "Undo_Redo: undo is disabled.\n" );
		return;
	}

	undo_t *redo;
	brush_t *pBrush, *pNextBrush;
	entity_t *pEntity, *pNextEntity, *pRedoEntity;

	if ( !g_lastredo ) {
		Sys_Printf( "Nothing left to redo.\n" );
		return;
	}
	if ( g_lastundo ) {
		if ( !g_lastundo->done ) {
			Sys_Printf( "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 ) {
			epair_t* tmp = world_entity->epairs;
			world_entity->epairs = pEntity->epairs;
			pEntity->epairs = tmp;
			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 ) // fixes broken undo on entities
		{
			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();
	//
	Sys_Printf( "%s redone.\n", redo->operation );
	//
	g_redoId--;
	// free the undo
	free( redo );
	//
	g_bScreenUpdates = true;
	UpdateSurfaceDialog();
	Sys_UpdateWindows( W_ALL );
}