Advertisement
xerpi

PSP (OSLIB) Timer

Feb 14th, 2012
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. ////****   timer.h ****////
  2.  
  3. #ifndef _Timer_H_
  4. #define _Timer_H_
  5.  
  6. #include <oslib/oslib.h>
  7.  
  8. class Timer{
  9.     public:
  10.         //Constructor
  11.             Timer(void);
  12.         //Variables
  13.             bool timer_running;
  14.             //Time variables
  15.                 clock_t lastTime;
  16.                 clock_t pauseTime;
  17.         //Methods
  18.             void start();
  19.             void stop();
  20.             void reset();
  21.             bool running();
  22.             int time();
  23. };
  24.  
  25. #endif
  26.  
  27. ////****   timer.c ****////
  28.  
  29. #include "timer.h"
  30.  
  31.     //Constructor
  32.         Timer::Timer(void){
  33.             timer_running = false;
  34.             reset();
  35.         }
  36.        
  37.     //Methods              
  38.     void Timer::start(){
  39.         if(!timer_running){
  40.             timer_running = true;
  41.             lastTime = lastTime + (sceKernelLibcClock()-pauseTime);
  42.         }
  43.     }
  44.    
  45.     void Timer::stop(){
  46.         if(timer_running){
  47.             timer_running = false;
  48.             pauseTime = sceKernelLibcClock();
  49.         }
  50.     }
  51.    
  52.     void Timer::reset(){
  53.         lastTime = sceKernelLibcClock();
  54.         pauseTime = lastTime;
  55.     }
  56.    
  57.     bool Timer::running(){
  58.         return timer_running;
  59.     }
  60.    
  61.     int Timer::time(){
  62.         if(timer_running){
  63.             return (int)((sceKernelLibcClock()-lastTime)/1000);
  64.         }else{
  65.             return (int)((pauseTime-lastTime)/1000);
  66.         }
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement