1 /****************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2012 OmegaSDG **
5 ****************************/
7 #include <boost/format.hpp>
13 static Timer
pythonNewTimer()
20 : running(false), prev_count(0)
24 bool Timer::isRunning() const
29 void Timer::setRunning(bool running
)
33 prev_time
= World::instance()->time();
37 this->running
= false;
45 double Timer::count() const
47 time_t prev_count
= this->prev_count
;
50 time_t now
= World::instance()->time();
51 prev_count
= prev_count
+ (now
- prev_time
);
54 return (double)prev_count
/ 1000.0;
60 time_t now
= World::instance()->time();
61 prev_count
= prev_count
+ (now
- prev_time
);
65 return (double)prev_count
/ 1000.0;
68 std::string
Timer::repr() const
70 using namespace boost
;
72 return str(format("<timer count=%.02fsec running=%s />")
73 % count() % (isRunning() ? "true" : "false"));
78 using namespace boost::python
;
80 class_
<Timer
> ("Timer", no_init
)
81 .add_property("running", &Timer::isRunning
, &Timer::setRunning
)
82 .add_property("count",
83 static_cast<double (Timer::*) ()> (&Timer::count
))
84 .def("reset", &Timer::reset
)
85 .def("__repr__", &Timer::repr
)
88 pythonAddFunction("new_timer", pythonNewTimer
);