14 , currentTime(12, 0, 1)
19 void Clock::update(std::mutex&,
float dt,
float,
float,
float) {
21 const float minutes = std::floor(residual);
24 currentTime.
addMinutes(
static_cast<unsigned int>(minutes + 0.1f));
25 bl::event::Dispatcher::dispatch<event::TimeChange>({currentTime});
31 bl::event::Dispatcher::dispatch<event::TimeChange>({currentTime});
45 const unsigned int nm = minute + m;
46 const unsigned int h = nm / 60;
48 if (h > 0) addHours(h);
52 const unsigned int nh = hour + h;
53 const unsigned int d = nh / 24;
59 return minute == right.
minute && hour == right.
hour &&
60 (right.
day == 0 || day == 0 || day == right.
day);
64 if (day != 0 && right.
day != 0) {
65 if (day < right.
day)
return true;
66 if (day > right.
day)
return false;
68 if (hour < right.
hour)
70 else if (hour == right.
hour)
71 return minute < right.
minute;
76 if (day != 0 && right.
day != 0) {
77 if (day < right.
day)
return false;
78 if (day > right.
day)
return true;
80 if (hour > right.
hour)
82 else if (hour == right.
hour)
83 return minute > right.
minute;
92 bl::event::Dispatcher::dispatch<event::TimeChange>({currentTime});
95 void Clock::init(bl::engine::Engine&) {
96 bl::event::Dispatcher::subscribe(
this);
Core classes and functionality for both the editor and game.
Fired when the game is saving or loading. Allows systems to hook in their data.
file::GameSave & gameSave
Game save being initialized.
Fired when a game save is loaded. Fired after the load is complete.
struct core::file::GameSave::ClockPointers clock
system::Clock::Time * time
const Time & now() const
Returns the current in game time.
virtual void observe(const event::GameSaveInitializing &save) override
Adds saved clock data to the save file.
Clock(Systems &owner)
Initializes the clock system.
void set(const Time &time)
Sets the current time.
Simple struct representing a point in time.
unsigned int minute
Current minute of the hour. In range [0, 59].
Time()
Construct a new Time at noon of day 0.
unsigned int day
Number of days elapsed in game since beginning. Starts at 1.
bool operator<(const Time &right) const
Checks to see if a given time appears later than the current time. Counts days unless either day is 0...
void addHours(unsigned int hours)
Adds the number of hours to this time. Wraps days.
unsigned int hour
Current hour of the day, in range [0, 23].
bool operator>(const Time &right) const
Checks to see if a given time appears earlier than the current time. Counts days unless either day is...
void addMinutes(unsigned int minutes)
Adds the amount of minutes to this time. Wraps hours and days.
bool operator==(const Time &right) const
Checks if two times are the same. Compares days as well unless either day is 0.
Owns all primary systems and a reference to the engine.