X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fclock.cpp;h=286ce966873af6b6735398ba1e5908f879460eda;hb=b78b49d85fbb9b2901c77e6450cfd41c0a818ac1;hp=5f87c44a90d6f38cc78c29e3377f91f2af798ce7;hpb=9f4f169affcedcf249e935f93e0a15ed60232f6a;p=r2c2.git diff --git a/source/libr2c2/clock.cpp b/source/libr2c2/clock.cpp index 5f87c44..286ce96 100644 --- a/source/libr2c2/clock.cpp +++ b/source/libr2c2/clock.cpp @@ -1,11 +1,13 @@ #include "clock.h" +using namespace std; using namespace Msp; namespace R2C2 { Clock::Clock(): - rate(1) + rate(1), + stopped(false) { } void Clock::set_rate(float s) @@ -13,9 +15,47 @@ void Clock::set_rate(float s) rate = s; } +void Clock::set_current_time(const Time::TimeDelta &t) +{ + current_time = t; +} + +void Clock::stop(bool s) +{ + stopped = s; +} + void Clock::tick(const Time::TimeDelta &dt) { + if(stopped) + return; + + unsigned prev_minute = current_time/Time::min; current_time += dt*rate; + if(current_time>=Time::day) + current_time -= Time::day; + unsigned minute = current_time/Time::min; + if(minute!=prev_minute) + signal_minute.emit(); +} + +void Clock::save(list &st) const +{ + st.push_back((DataFile::Statement("rate"), rate)); + st.push_back((DataFile::Statement("time"), current_time.raw())); +} + + +Clock::Loader::Loader(Clock &c): + DataFile::ObjectLoader(c) +{ + add("rate", &Clock::rate); + add("time", &Loader::time); +} + +void Clock::Loader::time(Time::RawTime t) +{ + obj.set_current_time(Time::TimeDelta(t)); } } // namespace R2C2