1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
15 static ListNode *snapshot_single = NULL;
16 static ListNode *snapshot_list = NULL;
17 static ListNode *snapshot_current = NULL;
19 static int num_snapshots_in_list = 0;
23 #define DEBUG_SNAPSHOTS 0
27 // -----------------------------------------------------------------------------
28 // functions for handling buffers for a single snapshot
29 // -----------------------------------------------------------------------------
31 void SaveSnapshotBuffer(ListNode **snapshot_buffers, void *buffer, int size)
33 struct SnapshotNodeInfo *bi =
34 checked_calloc(sizeof(struct SnapshotNodeInfo));
36 bi->buffer_orig = buffer;
37 bi->buffer_copy = checked_malloc(size);
40 memcpy(bi->buffer_copy, buffer, size);
42 addNodeToList(snapshot_buffers, NULL, bi);
45 static void LoadSnapshotBuffer(struct SnapshotNodeInfo *bi)
47 memcpy(bi->buffer_orig, bi->buffer_copy, bi->size);
50 void LoadSnapshotBuffers(ListNode *snapshot_buffers)
52 while (snapshot_buffers != NULL)
54 LoadSnapshotBuffer((struct SnapshotNodeInfo *)snapshot_buffers->content);
56 snapshot_buffers = snapshot_buffers->next;
60 void FreeSnapshotBuffers(ListNode *snapshot_buffers)
62 while (snapshot_buffers != NULL)
63 deleteNodeFromList(&snapshot_buffers, snapshot_buffers->key, checked_free);
66 // -----------------------------------------------------------------------------
67 // functions for handling one of several snapshots
68 // -----------------------------------------------------------------------------
70 static void FreeSnapshotExt(void *snapshot_buffers_ptr)
72 FreeSnapshotBuffers(snapshot_buffers_ptr);
75 void FreeSnapshotSingle()
77 FreeSnapshotBuffers(snapshot_single);
79 snapshot_single = NULL;
82 void FreeSnapshotList_UpToNode(ListNode *node)
84 while (snapshot_list != node)
86 deleteNodeFromList(&snapshot_list, snapshot_list->key, FreeSnapshotExt);
88 num_snapshots_in_list--;
92 void FreeSnapshotList()
94 FreeSnapshotList_UpToNode(NULL);
96 snapshot_current = NULL;
99 void SaveSnapshotSingle(ListNode *snapshot_buffers)
102 FreeSnapshotSingle();
104 snapshot_single = snapshot_buffers;
107 void SaveSnapshotToList(ListNode *snapshot_buffers)
109 if (snapshot_current != snapshot_list)
110 FreeSnapshotList_UpToNode(snapshot_current);
112 addNodeToList(&snapshot_list, i_to_a(num_snapshots_in_list),
115 snapshot_current = snapshot_list;
117 num_snapshots_in_list++;
120 printf("::: SaveSnapshotToList() [%s]\n", snapshot_current->key);
124 boolean LoadSnapshotSingle()
128 LoadSnapshotBuffers(snapshot_single);
136 boolean LoadSnapshotFromList_Older(int steps)
138 if (snapshot_current->next)
140 while (snapshot_current->next && steps--)
141 snapshot_current = snapshot_current->next;
143 LoadSnapshotBuffers(snapshot_current->content);
146 printf("::: LoadSnapshotFromList_Older() [%s]\n", snapshot_current->key);
155 boolean LoadSnapshotFromList_Newer(int steps)
157 if (snapshot_current->prev)
159 while (snapshot_current->prev && steps--)
160 snapshot_current = snapshot_current->prev;
162 LoadSnapshotBuffers(snapshot_current->content);
165 printf("::: LoadSnapshotFromList_Newer() [%s]\n", snapshot_current->key);