Only autosave when the data actually changed.

This commit is contained in:
Themaister 2011-09-17 10:57:55 +02:00
parent 38e7fc6659
commit efe3f943d5
2 changed files with 24 additions and 16 deletions

View File

@ -48,26 +48,33 @@ static int autosave_thread(void *data)
while (!save->quit) while (!save->quit)
{ {
autosave_lock(save); autosave_lock(save);
memcpy(save->buffer, save->snes_buffer, save->bufsize); bool differ = memcmp(save->buffer, save->snes_buffer, save->bufsize) != 0;
if (differ)
memcpy(save->buffer, save->snes_buffer, save->bufsize);
autosave_unlock(save); autosave_unlock(save);
// Should probably deal with this more elegantly. if (differ)
FILE *file = fopen(save->path, "wb");
if (file)
{ {
// Avoid spamming down stderr ... :) // Should probably deal with this more elegantly.
if (first_log) FILE *file = fopen(save->path, "wb");
if (file)
{ {
SSNES_LOG("Autosaving SRAM to \"%s\", will continue to autosave every %u seconds ...\n", save->path, save->interval); // Avoid spamming down stderr ... :)
first_log = false; if (first_log)
} {
SSNES_LOG("Autosaving SRAM to \"%s\", will continue to check every %u seconds ...\n", save->path, save->interval);
first_log = false;
}
else
SSNES_LOG("SRAM changed ... autosaving ...\n");
bool failed = false; bool failed = false;
failed |= fwrite(save->buffer, 1, save->bufsize, file) != save->bufsize; failed |= fwrite(save->buffer, 1, save->bufsize, file) != save->bufsize;
failed |= fflush(file) != 0; failed |= fflush(file) != 0;
failed |= fclose(file) != 0; failed |= fclose(file) != 0;
if (failed) if (failed)
SSNES_WARN("Failed to autosave SRAM! Disk might be full.\n"); SSNES_WARN("Failed to autosave SRAM! Disk might be full.\n");
}
} }
SDL_mutexP(save->cond_lock); SDL_mutexP(save->cond_lock);
@ -96,6 +103,7 @@ autosave_t *autosave_new(const char *path, const void *data, size_t size, unsign
free(handle); free(handle);
return NULL; return NULL;
} }
memcpy(handle->buffer, handle->snes_buffer, handle->bufsize);
handle->lock = SDL_CreateMutex(); handle->lock = SDL_CreateMutex();
handle->cond_lock = SDL_CreateMutex(); handle->cond_lock = SDL_CreateMutex();

View File

@ -1619,7 +1619,7 @@ int main(int argc, char *argv[])
#endif #endif
// Main loop // Main loop
for(;;) for (;;)
{ {
// DSP plugin GUI events. // DSP plugin GUI events.
if (g_extern.audio_data.dsp_handle && g_extern.audio_data.dsp_plugin->events) if (g_extern.audio_data.dsp_handle && g_extern.audio_data.dsp_plugin->events)