18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 16:36:53 +01:00
Files
maszyna/utilities/inionlysettings.h
T
jerrrrycho a8e8313343 feat(odometer): stamp each state with the day it was last updated, drop states not updated for a year (#435)
* feat(odometer): stamp the states with the day they were last updated, drop those not updated for a year

The odometer store kept every vehicle ever run. Each state now carries the
day it was last updated, written as a comment line "# updated <yyyy-mm-dd>"
before the states of that day, which the builds without the stamps skip.
A state with no stamp counts as updated the day it is read. A save drops
the states not updated for more than 365 days, those the other simulations
saved included. Refs #283.

* test(odometer): cover the stamps of the states and their expiry

* fix(odometer): a wrong clock doesn't drop the states, odometer.expiry sets the period

Review of #435. A stamp later than today was taken as today on every read, so a session with the clock set back
rewrote every state with that day, and the next session with the right clock dropped them all. The stamps are now
kept as written and a recorded state keeps its later day, so a day never goes back.

The expiry was measured from today, so a clock set forward, or the first save after a break of a year, dropped every
state not run in that session. It is now measured from the latest day of the states read at the start of the
session when that is earlier than today. The states this session records are stamped today, so the newest day of
the merged store would always be today in a save that writes.

The period is odometer.expiry <days> in eu07.ini, 365 unless set, 0 for never. A scenery's config block doesn't
change it, it would drop the player's states.

The states dropped are logged by the save that writes the file without them, not at every save while the write
fails. as_written() reads with the day given to save().
2026-11-26 22:27:27 +01:00

59 lines
2.0 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "utilities/Globals.h"
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
// the settings only eu07.ini sets. a scenery's config block is read by the parser of eu07.ini
// (state_serializer::deserialize_config, global_settings::ConfigParse), and with these keys it would run a program
// (execonexit, extcam.cmd, extcam.rec), write the screenshots elsewhere (screenshotsdir), open connections and ports
// (network.server, network.client, zmq.address, motiontelemetry, uart, feedbackmode, feedbackport), switch back on a
// script runtime the player switched off (python.enabled, luascreens.enabled, wasm.enabled), take its own scripts
// out of the sandbox (lua.fulllibraries) or drop the odometer states the player keeps (odometer.expiry). they keep
// what eu07.ini set; a scenery may still switch a runtime off, or keep its scripts in the sandbox when eu07.ini didn't,
// as it always could
class ini_only_settings
{
public:
// what Settings holds now, as eu07.ini set it
explicit ini_only_settings(global_settings const &Settings);
// puts back into Settings what changed since, and gives the keys of eu07.ini whose settings changed
std::vector<std::string_view> restore(global_settings &Settings) const;
private:
std::string m_exec_on_exit;
std::string m_screenshot_dir;
std::string m_extcam_cmd;
std::string m_extcam_rec;
std::vector<std::pair<std::string, std::string>> m_network_servers;
std::optional<std::pair<std::string, std::string>> m_network_client;
#ifdef WITH_ZMQ
std::string m_zmq_address;
#endif
motiontelemetry::conf_t m_motiontelemetry;
#ifdef WITH_UART
uart_input::conf_t m_uart;
#endif
int m_feedback_mode;
int m_feedback_port;
bool m_python_enabled;
bool m_luascreens_enabled;
bool m_lua_fulllibraries;
bool m_wasm_enabled;
int m_odometer_expiry;
};