1 #ifndef CORE_SYSTEMS_CLOCK_HPP
2 #define CORE_SYSTEMS_CLOCK_HPP
4 #include <BLIB/Engine/System.hpp>
5 #include <BLIB/Serialization.hpp>
6 #include <BLIB/Util/NonCopyable.hpp>
23 :
private bl::util::NonCopyable
24 ,
public bl::engine::System
25 ,
public bl::event::Listener<event::GameSaveInitializing, event::GameSaveLoaded> {
98 stream << std::setfill(
'0') << std::setw(2) << time.hour <<
":" << std::setfill(
'0')
99 << std::setw(2) << time.minute;
145 virtual void init(bl::engine::Engine&)
override;
146 virtual void update(std::mutex&,
float dt,
float,
float,
float)
override;
157 struct SerializableObject<
core::system::Clock::Time> :
public SerializableObjectBase {
160 SerializableField<1, T, unsigned int>
day;
161 SerializableField<2, T, unsigned int>
hour;
162 SerializableField<3, T, unsigned int>
minute;
165 : SerializableObjectBase(
"ClockTime")
166 , day(
"day", *this, &
T::day, SerializableFieldBase::Required{})
167 , hour(
"hour", *this, &
T::hour, SerializableFieldBase::Required{})
168 , minute(
"minute", *this, &
T::minute, SerializableFieldBase::Required{}) {}
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.
Fired when a game save is loaded. Fired after the load is complete.
Simple time keeping systems. Tracks in game time and date based on real elapsed play 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.
virtual ~Clock()=default
Destroys the system.
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.
friend std::ostream & operator<<(std::ostream &stream, const Time &time)
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.
SerializableField< 1, T, unsigned int > day
SerializableField< 2, T, unsigned int > hour
SerializableField< 3, T, unsigned int > minute
Owns all primary systems and a reference to the engine.