aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Time
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/Time')
-rw-r--r--src/libjin/Time/Timer.cpp158
-rw-r--r--src/libjin/Time/Timer.h110
2 files changed, 134 insertions, 134 deletions
diff --git a/src/libjin/Time/Timer.cpp b/src/libjin/Time/Timer.cpp
index 94d790d..426f2d5 100644
--- a/src/libjin/Time/Timer.cpp
+++ b/src/libjin/Time/Timer.cpp
@@ -5,96 +5,96 @@
namespace jin
{
-namespace time
-{
+ namespace time
+ {
- Timers::Timers()
- : timers()
- {
- }
+ Timers::Timers()
+ : timers()
+ {
+ }
- Timers::~Timers()
- {
- for (int i = 0; i < timers.size(); ++i)
- delete timers[i];
- }
+ Timers::~Timers()
+ {
+ for (int i = 0; i < timers.size(); ++i)
+ delete timers[i];
+ }
- void Timers::update(int ms)
- {
- std::vector<Timer*>::iterator it = timers.begin();
- for (; it != timers.end(); )
- {
- if (!(*it)->process(ms))
- {
- Timer* t = *it;
- timers.erase(it);
- delete t;
- return;
- }
- ++it;
- }
- }
+ void Timers::update(int ms)
+ {
+ std::vector<Timer*>::iterator it = timers.begin();
+ for (; it != timers.end(); )
+ {
+ if (!(*it)->process(ms))
+ {
+ Timer* t = *it;
+ timers.erase(it);
+ delete t;
+ return;
+ }
+ ++it;
+ }
+ }
- void Timers::every(int ms, timer_callback callback, void* p)
- {
- Timer* t = new Timer(Timer::EVERY, ms, 0, callback, p);
- timers.push_back(t);
- }
+ void Timers::every(int ms, timer_callback callback, void* p)
+ {
+ Timer* t = new Timer(Timer::EVERY, ms, 0, callback, p);
+ timers.push_back(t);
+ }
- void Timers::after(int ms, timer_callback callback, void* p)
- {
- Timer* t = new Timer(Timer::AFTER, ms, 0, callback, p);
- timers.push_back(t);
- }
+ void Timers::after(int ms, timer_callback callback, void* p)
+ {
+ Timer* t = new Timer(Timer::AFTER, ms, 0, callback, p);
+ timers.push_back(t);
+ }
- void Timers::repeat(int ms, int count, timer_callback callback, void* p)
- {
- Timer* t = new Timer(Timer::REPEAT, ms, count, callback, p);
- timers.push_back(t);
- }
+ void Timers::repeat(int ms, int count, timer_callback callback, void* p)
+ {
+ Timer* t = new Timer(Timer::REPEAT, ms, count, callback, p);
+ timers.push_back(t);
+ }
- Timers::Timer::Timer(Type t, int d, int c, timer_callback f, void* p)
- : type(t)
- , duration(d)
- , count(c)
- , tickdown(d)
- , countdown(c)
- , callback(f)
- , paramters(p)
- {
- }
+ Timers::Timer::Timer(Type t, int d, int c, timer_callback f, void* p)
+ : type(t)
+ , duration(d)
+ , count(c)
+ , tickdown(d)
+ , countdown(c)
+ , callback(f)
+ , paramters(p)
+ {
+ }
- Timers::Timer::~Timer()
- {
- }
+ Timers::Timer::~Timer()
+ {
+ }
- bool Timers::Timer::process(int ms)
- {
- tickdown -= ms;
- if (tickdown <= 0)
- {
- tickdown = duration;
- if (callback != nullptr)
- callback(paramters);
- if (type == EVERY)
- {
- }
- else if (type == AFTER)
- {
- return false;
- }
- else if (type == REPEAT)
- {
- --countdown;
- if (countdown <= 0)
- return false;
- }
- }
- return true;
- }
+ bool Timers::Timer::process(int ms)
+ {
+ tickdown -= ms;
+ if (tickdown <= 0)
+ {
+ tickdown = duration;
+ if (callback != nullptr)
+ callback(paramters);
+ if (type == EVERY)
+ {
+ }
+ else if (type == AFTER)
+ {
+ return false;
+ }
+ else if (type == REPEAT)
+ {
+ --countdown;
+ if (countdown <= 0)
+ return false;
+ }
+ }
+ return true;
+ }
-} // time
+ } // time
} // jin
#endif // LIBJIN_MODULES_TIME
diff --git a/src/libjin/Time/Timer.h b/src/libjin/Time/Timer.h
index 7a58e14..93a90ae 100644
--- a/src/libjin/Time/Timer.h
+++ b/src/libjin/Time/Timer.h
@@ -8,69 +8,69 @@
namespace jin
{
-namespace time
-{
+ namespace time
+ {
- class Timers
- {
- public:
- typedef void(*timer_callback)(void* prameters);
+ class Timers
+ {
+ public:
+ typedef void(*timer_callback)(void* prameters);
- Timers();
- ~Timers();
- void update(int ms);
- void every(int ms, timer_callback callback, void* paramters);
- void after(int ms, timer_callback callback, void* paramters);
- void repeat(int ms, int count, timer_callback callback, void* paramters);
+ Timers();
+ ~Timers();
+ void update(int ms);
+ void every(int ms, timer_callback callback, void* paramters);
+ void after(int ms, timer_callback callback, void* paramters);
+ void repeat(int ms, int count, timer_callback callback, void* paramters);
- private:
- class Timer
- {
- public:
- enum Type
- {
- EVERY,
- AFTER,
- REPEAT,
- };
- Timer(Type type, int duration, int count = 0, timer_callback callback = nullptr, void* paramters = nullptr);
- virtual ~Timer();
- bool process(int ms);
- private:
- int duration;
- int count;
- int tickdown;
- int countdown;
- Type type;
- timer_callback callback;
- void* paramters;
- };
- std::vector<Timer*> timers;
+ private:
+ class Timer
+ {
+ public:
+ enum Type
+ {
+ EVERY,
+ AFTER,
+ REPEAT,
+ };
+ Timer(Type type, int duration, int count = 0, timer_callback callback = nullptr, void* paramters = nullptr);
+ virtual ~Timer();
+ bool process(int ms);
+ private:
+ int duration;
+ int count;
+ int tickdown;
+ int countdown;
+ Type type;
+ timer_callback callback;
+ void* paramters;
+ };
+ std::vector<Timer*> timers;
- };
+ };
- inline void sleep(int ms)
- {
- #if LIBJIN_TIME_SDL
- SDL_Delay(ms);
- #endif
- }
+ inline void sleep(int ms)
+ {
+ #if LIBJIN_TIME_SDL
+ SDL_Delay(ms);
+ #endif
+ }
- inline double getSecond()
- {
- #if LIBJIN_TIME_SDL
- return SDL_GetTicks() / 1000.f;
- #endif
- }
+ inline double getSecond()
+ {
+ #if LIBJIN_TIME_SDL
+ return SDL_GetTicks() / 1000.f;
+ #endif
+ }
- inline double getMilliSecond()
- {
- #if LIBJIN_TIME_SDL
- return SDL_GetTicks();
- #endif
- }
+ inline double getMilliSecond()
+ {
+ #if LIBJIN_TIME_SDL
+ return SDL_GetTicks();
+ #endif
+ }
-} // time
+ } // time
} // jin
#endif // LIBJIN_MODULES_TIME