17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 14:29:20 +02:00
Files
maszyna/simulation/simulationtime.cppm
maj00r b8f040e6fd propagate template headers transitively, import Console where used
AnimModel.cpp reaches cParser through the simulation core, not a direct
import, so the previous pass missed it; the propagation now follows the
whole import closure. Train.cpp, drivermode.cpp and Globals.cpp call
Console:: inside _WIN32 guards without importing eu07.console - invisible
on Linux, where those blocks are skipped.
2026-09-10 01:41:24 +02:00

108 lines
2.6 KiB
C++

module;
#include <array>
#include <chrono>
#include <cstddef>
#include <deque>
#include <limits>
#include <mutex>
#include <ostream>
#include <sstream>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
#include <string>
#include "winheaders.h"
export module eu07.simulation.simulationtime;
export {
/*
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/.
*/
// 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);
/** 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 );
// 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
//---------------------------------------------------------------------------
} // export