d28ae349e585acb88d8a4c1daa617f0d465d19ab
[rocksndiamonds.git] / src / libgame / snapshot.c
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * snapshot.c                                               *
12 ***********************************************************/
13
14 #include "snapshot.h"
15
16
17 static ListNode *engine_snapshot_list = NULL;
18
19 void SaveEngineSnapshotBuffer(void *buffer, int size)
20 {
21   struct EngineSnapshotNodeInfo *bi =
22     checked_calloc(sizeof(struct EngineSnapshotNodeInfo));
23
24   bi->buffer_orig = buffer;
25   bi->buffer_copy = checked_malloc(size);
26   bi->size = size;
27
28   memcpy(bi->buffer_copy, buffer, size);
29
30   addNodeToList(&engine_snapshot_list, NULL, bi);
31 }
32
33 static void LoadEngineSnapshotBuffer(struct EngineSnapshotNodeInfo *bi)
34 {
35   memcpy(bi->buffer_orig, bi->buffer_copy, bi->size);
36 }
37
38 void LoadEngineSnapshotBuffers()
39 {
40   ListNode *node = engine_snapshot_list;
41
42   while (node != NULL)
43   {
44     LoadEngineSnapshotBuffer((struct EngineSnapshotNodeInfo *)node->content);
45
46     node = node->next;
47   }
48 }
49
50 void FreeEngineSnapshotBuffers()
51 {
52   while (engine_snapshot_list != NULL)
53     deleteNodeFromList(&engine_snapshot_list, engine_snapshot_list->key,
54                        checked_free);
55 }