Skip to content

Commit

Permalink
use clock() instead of SDL_GetTicks() to save the hero data periodically
Browse files Browse the repository at this point in the history
  • Loading branch information
pionere committed Sep 17, 2024
1 parent 06a8eb2 commit 398aade
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Source/pfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "diabloui.h"
#include "utils/file_util.h"
#include "DiabloUI/diablo.h"
#include <time.h>

DEVILUTION_BEGIN_NAMESPACE

Expand All @@ -22,7 +23,7 @@ DEVILUTION_BEGIN_NAMESPACE

unsigned mySaveIdx;
bool gbValidSaveFile;
static Uint32 guNextSaveTc;
static uint32_t guNextSaveTc;

#define PASSWORD_SINGLE "xrgyrkj1"
#define PASSWORD_MULTI "szqnlsk1"
Expand Down Expand Up @@ -304,7 +305,8 @@ void pfile_read_hero_from_save()
mypnum = 0;
gbValidSaveFile = pfile_archive_contains_game(archive);
SFileCloseArchive(archive);
guNextSaveTc = SDL_GetTicks() + PFILE_SAVE_INTERVAL;
static_assert(CLOCKS_PER_SEC == 1000, "pfile uses clock to time saving.");
guNextSaveTc = clock() + PFILE_SAVE_INTERVAL;
}

void pfile_rename_temp_to_perm()
Expand Down Expand Up @@ -418,7 +420,7 @@ void pfile_read_save_file(bool full)
void pfile_update(bool force_save)
{
if (IsMultiGame) {
Uint32 currTc = SDL_GetTicks();
uint32_t currTc = clock();
if (force_save || currTc > guNextSaveTc) {
guNextSaveTc = currTc + PFILE_SAVE_INTERVAL;
pfile_write_hero(false);
Expand Down

0 comments on commit 398aade

Please sign in to comment.