X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsnapshot.c;h=43a42c34d50920813717c73314337aba168a6ad8;hb=5e13b105ad48e61a5cd46941c61a16ad00445248;hp=1262ee88b2abda4f66173503e70240c2d0f42674;hpb=4b722be68436ced0b7bb3eff61ed14d6c66df949;p=rocksndiamonds.git diff --git a/src/libgame/snapshot.c b/src/libgame/snapshot.c index 1262ee88..43a42c34 100644 --- a/src/libgame/snapshot.c +++ b/src/libgame/snapshot.c @@ -18,11 +18,15 @@ static ListNode *snapshot_current = NULL; static int num_snapshots_in_list = 0; - #ifdef DEBUG #define DEBUG_SNAPSHOTS 0 #endif +#if DEBUG_SNAPSHOTS +static int num_snapshot_buffers = 0; +static int num_snapshot_bytes = 0; +#endif + // ----------------------------------------------------------------------------- // functions for handling buffers for a single snapshot @@ -40,6 +44,11 @@ void SaveSnapshotBuffer(ListNode **snapshot_buffers, void *buffer, int size) memcpy(bi->buffer_copy, buffer, size); addNodeToList(snapshot_buffers, NULL, bi); + +#if DEBUG_SNAPSHOTS + num_snapshot_buffers++; + num_snapshot_bytes += size; +#endif } static void LoadSnapshotBuffer(struct SnapshotNodeInfo *bi) @@ -57,17 +66,30 @@ void LoadSnapshotBuffers(ListNode *snapshot_buffers) } } +static void FreeSnapshotBuffer(void *bi_raw) +{ + struct SnapshotNodeInfo *bi = (struct SnapshotNodeInfo *)bi_raw; + +#if DEBUG_SNAPSHOTS + num_snapshot_buffers--; + num_snapshot_bytes -= bi->size; +#endif + + checked_free(bi->buffer_copy); + checked_free(bi); +} + void FreeSnapshotBuffers(ListNode *snapshot_buffers) { while (snapshot_buffers != NULL) - deleteNodeFromList(&snapshot_buffers, snapshot_buffers->key, checked_free); + deleteNodeFromList(&snapshot_buffers, NULL, FreeSnapshotBuffer); } // ----------------------------------------------------------------------------- -// functions for handling one of several snapshots +// functions for handling single shapshot or list of snapshots // ----------------------------------------------------------------------------- -static void FreeSnapshotExt(void *snapshot_buffers_ptr) +static void FreeSnapshot(void *snapshot_buffers_ptr) { FreeSnapshotBuffers(snapshot_buffers_ptr); } @@ -79,11 +101,16 @@ void FreeSnapshotSingle() snapshot_single = NULL; } -void FreeSnapshotList_UpToNode(ListNode *node) +static void FreeSnapshotList_UpToNode(ListNode *node) { while (snapshot_list != node) { - deleteNodeFromList(&snapshot_list, snapshot_list->key, FreeSnapshotExt); +#if DEBUG_SNAPSHOTS + printf("::: FreeSnapshotList_*() [%s, %d, %d]\n", + snapshot_list->key, num_snapshot_buffers, num_snapshot_bytes); +#endif + + deleteNodeFromList(&snapshot_list, snapshot_list->key, FreeSnapshot); num_snapshots_in_list--; } @@ -91,6 +118,10 @@ void FreeSnapshotList_UpToNode(ListNode *node) void FreeSnapshotList() { +#if DEBUG_SNAPSHOTS + printf("::: FreeSnapshotList()\n"); +#endif + FreeSnapshotList_UpToNode(NULL); snapshot_current = NULL; @@ -117,7 +148,8 @@ void SaveSnapshotToList(ListNode *snapshot_buffers) num_snapshots_in_list++; #if DEBUG_SNAPSHOTS - printf("::: SaveSnapshotToList() [%s]\n", snapshot_current->key); + printf("::: SaveSnapshotToList() [%s, %d, %d]\n", + snapshot_current->key, num_snapshot_buffers, num_snapshot_bytes); #endif } @@ -135,7 +167,7 @@ boolean LoadSnapshotSingle() boolean LoadSnapshotFromList_Older(int steps) { - if (snapshot_current->next) + if (snapshot_current && snapshot_current->next) { while (snapshot_current->next && steps--) snapshot_current = snapshot_current->next; @@ -154,7 +186,7 @@ boolean LoadSnapshotFromList_Older(int steps) boolean LoadSnapshotFromList_Newer(int steps) { - if (snapshot_current->prev) + if (snapshot_current && snapshot_current->prev) { while (snapshot_current->prev && steps--) snapshot_current = snapshot_current->prev; @@ -170,3 +202,8 @@ boolean LoadSnapshotFromList_Newer(int steps) return FALSE; } + +boolean CheckSnapshotList() +{ + return (snapshot_list ? TRUE : FALSE); +}