From 377650d9f582e53f5570617c32c6039c97d56c63 Mon Sep 17 00:00:00 2001 From: Alexander Overvoorde Date: Sat, 3 Oct 2015 14:18:43 +0200 Subject: [PATCH] Change autosave system to use wall-clock time based frequencies The autosave system will now use frequencies based on wall-clock time rather than in-game time, for example every 15 minutes. This frequency is not affected by pausing the game or changing the game speed. The default frequency is every 5 minutes. --- data/language/english_uk.txt | 10 +++++----- src/config.c | 2 +- src/config.h | 10 +++++----- src/game.c | 3 +++ src/localisation/string_ids.h | 7 +++++++ src/scenario.c | 37 +++++++++++++++++++---------------- src/scenario.h | 1 + src/windows/options.c | 7 ++++--- 8 files changed, 46 insertions(+), 31 deletions(-) diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index 7de56f5f19..2dc461a654 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -2706,11 +2706,11 @@ STR_2697 :??? STR_2698 :??? STR_2699 :??? STR_2700 :Autosave frequency: -STR_2701 :Every week -STR_2702 :Every 2 weeks -STR_2703 :Every month -STR_2704 :Every 4 months -STR_2705 :Every year +STR_2701 :Every minute +STR_2702 :Every 5 minutes +STR_2703 :Every 15 minutes +STR_2704 :Every 30 minutes +STR_2705 :Every hour STR_2706 :Never STR_2707 :Open new window STR_2708 :{WINDOW_COLOUR_1}Are you sure you want to overwrite {STRINGID}? diff --git a/src/config.c b/src/config.c index 92e8615107..c979af93ea 100644 --- a/src/config.c +++ b/src/config.c @@ -157,7 +157,7 @@ config_enum_definition _dateFormatEnum[] = { config_property_definition _generalDefinitions[] = { { offsetof(general_configuration, always_show_gridlines), "always_show_gridlines", CONFIG_VALUE_TYPE_BOOLEAN, false, NULL }, - { offsetof(general_configuration, autosave_frequency), "autosave", CONFIG_VALUE_TYPE_UINT8, AUTOSAVE_EVERY_MONTH, NULL }, + { offsetof(general_configuration, autosave_frequency), "autosave", CONFIG_VALUE_TYPE_UINT8, AUTOSAVE_EVERY_5MINUTES, NULL }, { offsetof(general_configuration, confirmation_prompt), "confirmation_prompt", CONFIG_VALUE_TYPE_UINT8, 0, NULL }, { offsetof(general_configuration, construction_marker_colour), "construction_marker_colour", CONFIG_VALUE_TYPE_UINT8, false, NULL }, { offsetof(general_configuration, currency_format), "currency_format", CONFIG_VALUE_TYPE_UINT8, CURRENCY_POUNDS, _currencyEnum }, diff --git a/src/config.h b/src/config.h index 660902b46f..127e7602e4 100644 --- a/src/config.h +++ b/src/config.h @@ -98,11 +98,11 @@ enum { }; enum { - AUTOSAVE_EVERY_WEEK, - AUTOSAVE_EVERY_2_WEEKS, - AUTOSAVE_EVERY_MONTH, - AUTOSAVE_EVERY_4_MONTHS, - AUTOSAVE_EVERY_YEAR, + AUTOSAVE_EVERY_MINUTE, + AUTOSAVE_EVERY_5MINUTES, + AUTOSAVE_EVERY_15MINUTES, + AUTOSAVE_EVERY_30MINUTES, + AUTOSAVE_EVERY_HOUR, AUTOSAVE_NEVER }; diff --git a/src/game.c b/src/game.c index f6c65942d6..1eb5ceed19 100644 --- a/src/game.c +++ b/src/game.c @@ -296,6 +296,9 @@ void game_update() } } + // Always perform autosave check, even when paused + scenario_autosave_check(); + network_update(); news_item_update_current(); window_dispatch_update_all(); diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index 5728e84bc9..779e3dac99 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -1393,6 +1393,13 @@ enum { STR_CHEAT_TIP_LARGE_TRAM_GUESTS = 2684, + STR_SAVE_EVERY_MINUTE = 2701, + STR_SAVE_EVERY_5MINUTES = 2702, + STR_SAVE_EVERY_15MINUTES = 2703, + STR_SAVE_EVERY_30MINUTES = 2704, + STR_SAVE_EVERY_HOUR = 2705, + STR_SAVE_NEVER = 2706, + STR_DATE_FORMAT_DMY = 2737, STR_ROLLERCOASTER_TYCOON_1_DROPDOWN = 2740, diff --git a/src/scenario.c b/src/scenario.c index c22be884a0..c6d27a6c32 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -514,34 +514,38 @@ void scenario_entrance_fee_too_high_check() } } -static void scenario_autosave_check() +void scenario_autosave_check() { - uint32 next_month_tick = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONTH_TICKS, uint16) + 4; - uint16 month = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONTH_YEAR, uint16); + // Timestamp in milliseconds + static uint32 last_save = 0; + bool shouldSave = 0; + // Milliseconds since last save + uint32_t time_since_save = SDL_GetTicks() - last_save; + switch (gConfigGeneral.autosave_frequency) { - case AUTOSAVE_EVERY_WEEK: - shouldSave = (next_month_tick % 0x4000 == 0); + case AUTOSAVE_EVERY_MINUTE: + shouldSave = time_since_save >= 1 * 60 * 1000; break; - case AUTOSAVE_EVERY_2_WEEKS: - shouldSave = (next_month_tick % 0x8000 == 0); + case AUTOSAVE_EVERY_5MINUTES: + shouldSave = time_since_save >= 5 * 60 * 1000; break; - case AUTOSAVE_EVERY_MONTH: - shouldSave = (next_month_tick >= 0x10000); + case AUTOSAVE_EVERY_15MINUTES: + shouldSave = time_since_save >= 15 * 60 * 1000; break; - case AUTOSAVE_EVERY_4_MONTHS: - if (next_month_tick >= 0x10000) - shouldSave = (((month + 1) & 3) == 0); + case AUTOSAVE_EVERY_30MINUTES: + shouldSave = time_since_save >= 30 * 60 * 1000; break; - case AUTOSAVE_EVERY_YEAR: - if (next_month_tick >= 0x10000) - shouldSave = (((month + 1) & 7) == 0); + case AUTOSAVE_EVERY_HOUR: + shouldSave = time_since_save >= 60 * 60 * 1000; break; } - if (shouldSave) + if (shouldSave) { + last_save = SDL_GetTicks(); game_autosave(); + } } static void scenario_day_update() @@ -636,7 +640,6 @@ void scenario_update() uint8 currentMonth = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONTH_YEAR, sint16) & 7; uint8 currentDaysInMonth = (uint8)days_in_month[currentMonth]; - scenario_autosave_check(); if ((currentDaysInMonth * nextMonthTick) >> 16 != (currentDaysInMonth * currentMonthTick) >> 16) { scenario_day_update(); } diff --git a/src/scenario.h b/src/scenario.h index a11a2cf9dc..2b5e222225 100644 --- a/src/scenario.h +++ b/src/scenario.h @@ -434,5 +434,6 @@ void scenario_set_filename(const char *value); void scenario_failure(); void scenario_success(); void scenario_success_submit_name(const char *name); +void scenario_autosave_check(); #endif diff --git a/src/windows/options.c b/src/windows/options.c index 40b93d010b..76a1f079ae 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -869,10 +869,11 @@ static void window_options_mousedown(int widgetIndex, rct_window*w, rct_widget* case WINDOW_OPTIONS_PAGE_MISC: switch (widgetIndex) { case WIDX_AUTOSAVE_DROPDOWN: - for (i = AUTOSAVE_EVERY_WEEK; i <= AUTOSAVE_NEVER; i++) { + for (i = AUTOSAVE_EVERY_MINUTE; i <= AUTOSAVE_NEVER; i++) { gDropdownItemsFormat[i] = 1142; - gDropdownItemsArgs[i] = 2701 + i; + gDropdownItemsArgs[i] = STR_SAVE_EVERY_MINUTE + i; } + window_options_show_dropdown(w, widget, AUTOSAVE_NEVER + 1); gDropdownItemsChecked = 1 << gConfigGeneral.autosave_frequency; break; @@ -1371,7 +1372,7 @@ static void window_options_paint(rct_window *w, rct_drawpixelinfo *dpi) gfx_draw_string_left(dpi, 2700, w, w->colours[1], w->x + 10, w->y + window_options_misc_widgets[WIDX_AUTOSAVE].top + 1); gfx_draw_string_left( dpi, - 2701 + gConfigGeneral.autosave_frequency, + STR_SAVE_EVERY_MINUTE + gConfigGeneral.autosave_frequency, NULL, w->colours[1], w->x + window_options_misc_widgets[WIDX_AUTOSAVE].left + 1,