Skip to content
Browse files

FIX forgot files ==;

  • Loading branch information...
1 parent 599190d commit 6f05ccc13d85d9210d1db2e9ce6e7934aeeca637 @PowerKiKi committed Jun 27, 2009
Showing with 84 additions and 0 deletions.
  1. +40 −0 application/source/PeriodicTimer.cpp
  2. +44 −0 application/source/PeriodicTimer.h
View
40 application/source/PeriodicTimer.cpp
@@ -0,0 +1,40 @@
+#include <PeriodicTimer.h>
+
+#include <Constants.h>
+#include <Console.h>
+
+#include <ogc/lwp_watchdog.h>
+
+namespace Polukili
+{
+
+ /*************************************************/
+ PeriodicTimer::PeriodicTimer(int period)
+ : period(millisecs_to_ticks(period))
+ {
+ this->reset();
+ }
+
+ /*************************************************/
+ PeriodicTimer::~PeriodicTimer()
+ {
+
+ }
+
+ /*************************************************/
+ bool PeriodicTimer::isExpired()
+ {
+ u64 now = gettime();
+ bool expired = now >= this->nextExpiry;
+ if (expired)
+ this->nextExpiry += (((now - this->nextExpiry) / this->period) + 1) * this->period;
+
+ return expired;
+ }
+
+ /*************************************************/
+ void PeriodicTimer::reset()
+ {
+ this->nextExpiry = gettime() + this->period;
+ }
+}
View
44 application/source/PeriodicTimer.h
@@ -0,0 +1,44 @@
+#ifndef Polukili_PeriodicTimer_h
+#define Polukili_PeriodicTimer_h
+
+#include <gctypes.h>
+
+using namespace std;
+
+namespace Polukili
+{
+ /**
+ * Timer Class
+ */
+ class PeriodicTimer
+ {
+ public:
+
+ /**
+ * Constructor a periodic timer with period in milliseconds.
+ */
+ PeriodicTimer(int period);
+
+ /**
+ * Destructor.
+ */
+ ~PeriodicTimer();
+
+ /**
+ * Returns if the period is over. If true, the period must be consumed.
+ */
+ bool isExpired();
+
+ /**
+ * Reset the period starting now.
+ */
+ void reset();
+
+ private:
+ u64 period;
+ u64 nextExpiry;
+ bool isConsumed;
+ };
+}
+
+#endif

0 comments on commit 6f05ccc

Please sign in to comment.
Something went wrong with that request. Please try again.