Line | |
---|
1 | // |
---|
2 | // undo.h: |
---|
3 | // Save every variable that changes, so that we can exactly "undo" |
---|
4 | // an operation by putting everything back the way it was. This |
---|
5 | // allows us to try mesh simplification changes, and abort the |
---|
6 | // changes if we detect something bad happening (like a topology |
---|
7 | // change...) |
---|
8 | |
---|
9 | #ifndef UNDO_H |
---|
10 | #define UNDO_H |
---|
11 | |
---|
12 | |
---|
13 | #define MAXUNDOBUFSIZE 40000 |
---|
14 | |
---|
15 | // Variables for storing the undo operation list |
---|
16 | extern bool saveUndo; |
---|
17 | extern char undoBuf[sizeof(void *)*MAXUNDOBUFSIZE]; |
---|
18 | extern char *undoPtr; |
---|
19 | extern void *undoLoc[MAXUNDOBUFSIZE]; |
---|
20 | extern int undoSize[MAXUNDOBUFSIZE]; |
---|
21 | extern int undoN; |
---|
22 | |
---|
23 | // Functions |
---|
24 | template<class T> void save(T &data) |
---|
25 | { |
---|
26 | if (!saveUndo) return; |
---|
27 | void *ptr = &data; |
---|
28 | if (sizeof(T) + undoPtr > MAXUNDOBUFSIZE + undoBuf) { |
---|
29 | // Error checking: |
---|
30 | // Shit. We don't have enough buffer to push this on undo stack |
---|
31 | // Really should make it dynamically allocated. @!#$!#!@# |
---|
32 | fprintf(stderr, "Error. Out of memory, can't push object of size"); |
---|
33 | fprintf(stderr, " %d on the undo stack.\n", sizeof(T)); |
---|
34 | fprintf(stderr, " Recommend increasing MAXUNDOBUFSIZE. :-( \n"); |
---|
35 | exit(-1); |
---|
36 | } |
---|
37 | bcopy((char *) ptr, undoPtr, sizeof(T)); |
---|
38 | undoPtr += sizeof(T); |
---|
39 | undoLoc[undoN] = &data; |
---|
40 | undoSize[undoN] = sizeof(T); |
---|
41 | undoN++; |
---|
42 | } |
---|
43 | |
---|
44 | void SaveCheckpoint(void); |
---|
45 | void undo(void); |
---|
46 | void SaveOff(void); |
---|
47 | |
---|
48 | #endif // UNDO_H |
---|
Note: See
TracBrowser
for help on using the repository browser.