Cube  Diff

Differences From Artifact [2700645c79]:

To Artifact [8eeba4e2ca]:


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
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







-
-
+
+





+
-
-
-
-
-
+
+
+
+
+
+
+






+
+
+
+
-
+
+







-
+



-
+
+








	if (selset) {
		linestyle(GRIDS, 0xFF, 0x40, 0x40);
		box(sel, (float)selh, (float)selh, (float)selh, (float)selh);
	}
}

vector<block *> undos;    // unlimited undo
VARP(undomegs, 0, 1, 10); // bounded by n megs
static OFMutableData *undos; // unlimited undo
VARP(undomegs, 0, 1, 10);    // bounded by n megs

void
pruneundos(int maxremain) // bound memory
{
	int t = 0;
	for (ssize_t i = (ssize_t)undos.count - 1; i >= 0; i--) {
	loopvrev(undos)
	{
		t += undos[i]->xs * undos[i]->ys * sizeof(sqr);
		if (t > maxremain)
			OFFreeMemory(undos.remove(i));
		block *undo = *(block **)[undos itemAtIndex:i];

		t += undo->xs * undo->ys * sizeof(sqr);
		if (t > maxremain) {
			OFFreeMemory(undo);
			[undos removeItemAtIndex:i];
		}
	}
}

void
makeundo()
{
	if (undos == nil)
		undos =
		    [[OFMutableData alloc] initWithItemSize:sizeof(block *)];

	undos.add(blockcopy(sel));
	block *copy = blockcopy(sel);
	[undos addItem:&copy];
	pruneundos(undomegs << 20);
}

void
editundo()
{
	EDITMP;
	if (undos.empty()) {
	if (undos.count == 0) {
		conoutf(@"nothing more to undo");
		return;
	}
	block *p = undos.pop();
	block *p = *(block **)undos.lastItem;
	[undos removeLastItem];
	blockpaste(*p);
	OFFreeMemory(p);
}

block *copybuf = NULL;

void