Beispiel #1
0
static void undo_stack_push_end(UndoStack *stack)
{
	UndoElem *uel;
	uintptr_t totmem, maxmem;
	int totundo = 0;

	/* first limit to undo steps */
	uel = stack->elems.last;

	while (uel) {
		totundo++;
		if (totundo > U.undosteps) break;
		uel = uel->prev;
	}

	if (uel) {
		UndoElem *first;

		/* in case the undo steps are zero, the current pointer will be invalid */
		if (uel == stack->current)
			stack->current = NULL;

		do {
			first = stack->elems.first;
			undo_elem_free(stack, first);
			BLI_freelinkN(&stack->elems, first);
		} while (first != uel);
	}

	if (U.undomemory != 0) {
		/* limit to maximum memory (afterwards, we can't know in advance) */
		totmem = 0;
		maxmem = ((uintptr_t)U.undomemory) * 1024 * 1024;

		uel = stack->elems.last;
		while (uel) {
			totmem += uel->undosize;
			if (totmem > maxmem) break;
			uel = uel->prev;
		}

		if (uel) {
			while (stack->elems.first != uel) {
				UndoElem *first = stack->elems.first;
				undo_elem_free(stack, first);
				BLI_freelinkN(&stack->elems, first);
			}
		}
	}
}
Beispiel #2
0
static void undo_stack_push_end(UndoStack *stack)
{
	UndoElem *uel;
	uintptr_t totmem, maxmem;

	if(U.undomemory != 0) {
		/* limit to maximum memory (afterwards, we can't know in advance) */
		totmem= 0;
		maxmem= ((uintptr_t)U.undomemory)*1024*1024;

		uel= stack->elems.last;
		while(uel) {
			totmem+= uel->undosize;
			if(totmem>maxmem) break;
			uel= uel->prev;
		}

		if(uel) {
			while(stack->elems.first!=uel) {
				UndoElem *first= stack->elems.first;
				undo_elem_free(stack, first);
				BLI_freelinkN(&stack->elems, first);
			}
		}
	}
}
Beispiel #3
0
static void undo_stack_free(UndoStack *stack)
{
	UndoElem *uel;
	
	for(uel=stack->elems.first; uel; uel=uel->next)
		undo_elem_free(stack, uel);

	BLI_freelistN(&stack->elems);
	stack->current= NULL;
}
Beispiel #4
0
static void undo_stack_push_begin(UndoStack *stack, const char *name, UndoRestoreCb restore, UndoFreeCb free)
{
	UndoElem *uel;
	int nr;
	
	/* Undo push is split up in begin and end, the reason is that as painting
	 * happens more tiles/nodes are added to the list, and at the very end we
	 * know how much memory the undo used to remove old undo elements */

	/* remove all undos after (also when stack->current==NULL) */
	while(stack->elems.last != stack->current) {
		uel= stack->elems.last;
		undo_elem_free(stack, uel);
		BLI_freelinkN(&stack->elems, uel);
	}
	
	/* make new */
	stack->current= uel= MEM_callocN(sizeof(UndoElem), "undo file");
	uel->restore= restore;
	uel->free= free;
	BLI_addtail(&stack->elems, uel);

	/* name can be a dynamic string */
	strncpy(uel->name, name, MAXUNDONAME-1);
	
	/* limit amount to the maximum amount*/
	nr= 0;
	uel= stack->elems.last;
	while(uel) {
		nr++;
		if(nr==U.undosteps) break;
		uel= uel->prev;
	}
	if(uel) {
		while(stack->elems.first!=uel) {
			UndoElem *first= stack->elems.first;
			undo_elem_free(stack, first);
			BLI_freelinkN(&stack->elems, first);
		}
	}
}