mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 11:15:23 +01:00
2953bedafa
--snapshot-at <seconds> <file> writes a snapshot when the simulation has run that long, --load-snapshot <file> puts one over the scenery once it has loaded, before the first frame. This layer keeps the clock and the simulation timer, the weather with the wind, the random engine, the memory cells, the switches, the tracks an event can change and the ones made on the run, the traction power sources, the event queue, the timers of the launchers and the lamps of the signals. While a snapshot is put back the event manager is suspended, so nothing in the scenery reacts to it. Existing classes only get accessors for what was private (the fraction of the second, launcher timers, the speed limit of a track, the wind, the state of a power source, the event queue). Without the switches nothing changes.
98 lines
2.7 KiB
C++
98 lines
2.7 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 <string>
|
|
|
|
#include "winheaders.h"
|
|
|
|
// wrapper for scenario time
|
|
class scenario_time {
|
|
|
|
public:
|
|
scenario_time() {
|
|
m_time.wHour = 10; m_time.wMinute = 30; }
|
|
void
|
|
init(time_t timestamp = 0);
|
|
void
|
|
update( double const Deltatime );
|
|
inline
|
|
SYSTEMTIME &
|
|
data() {
|
|
return m_time; }
|
|
inline
|
|
SYSTEMTIME const &
|
|
data() const {
|
|
return m_time; }
|
|
inline
|
|
double
|
|
second() const {
|
|
return m_time.wMilliseconds * 0.001 + m_time.wSecond; }
|
|
inline
|
|
int
|
|
year_day() const {
|
|
return m_yearday; }
|
|
int
|
|
julian_day() const;
|
|
inline
|
|
double
|
|
zone_bias() const {
|
|
return m_timezonebias; }
|
|
void
|
|
set_time(int yearday, int minute);
|
|
// the part of the running second gone by [ms], with its fraction
|
|
inline
|
|
double
|
|
milliseconds() const {
|
|
return m_milliseconds; }
|
|
// sets the clock to a saved moment: the date and time of Time, Milliseconds into its second (simulation snapshot)
|
|
void
|
|
restore( SYSTEMTIME const &Time, double const Milliseconds );
|
|
|
|
/** Returns std::string in format: `"mm:ss"`. */
|
|
operator std::string();
|
|
private:
|
|
// converts provided time transition date to regular date
|
|
void
|
|
convert_transition_time( SYSTEMTIME &Time ) const;
|
|
// calculates day and month from given day of year
|
|
void
|
|
daymonth( WORD &Day, WORD &Month, WORD const Year, WORD const Yearday ) const;
|
|
// calculates day of year from given date
|
|
int
|
|
year_day( int Day, int const Month, int const Year ) const;
|
|
// calculates day of week for provided date
|
|
int
|
|
day_of_week( int const Day, int const Month, int const Year ) const;
|
|
// calculates day of month for specified weekday of specified month of the year
|
|
int
|
|
day_of_month( int const Week, int const Weekday, int const Month, int const Year ) const;
|
|
// returns number of days between specified days of week
|
|
int
|
|
weekdays( int const First, int const Second ) const;
|
|
// returns true if specified year is a leap year, false otherwise
|
|
bool
|
|
is_leap( int const Year ) const;
|
|
|
|
SYSTEMTIME m_time;
|
|
double m_milliseconds{ 0.0 };
|
|
int m_yearday;
|
|
char m_monthdaycounts[ 2 ][ 13 ];
|
|
double m_timezonebias{ 0.0 };
|
|
};
|
|
|
|
namespace simulation {
|
|
|
|
extern scenario_time Time;
|
|
|
|
} // simulation
|
|
|
|
//---------------------------------------------------------------------------
|