Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////**** timer.h ****////
- #ifndef _Timer_H_
- #define _Timer_H_
- #include <oslib/oslib.h>
- #define getClock sceKernelLibcClock
- #define clockType clock_t
- class Timer{
- public:
- //Constructor
- Timer(void);
- //Variables
- bool timer_running;
- //Time variables
- clockType lastTime;
- clockType pauseTime;
- //Methods
- void start();
- void stop();
- void reset();
- void osc();
- bool running();
- int time();
- };
- #endif
- ////**** timer.c ****////
- #include "timer.h"
- //Constructor
- Timer::Timer(void){
- timer_running = false;
- reset();
- }
- //Methods
- void Timer::start(){
- if(!timer_running){
- timer_running = true;
- lastTime = lastTime + (getClock()-pauseTime);
- }
- }
- void Timer::stop(){
- if(timer_running){
- timer_running = false;
- pauseTime = getClock();
- }
- }
- void Timer::reset(){
- lastTime = getClock();
- pauseTime = lastTime;
- }
- void Timer::osc(){
- if(timer_running){
- stop();
- }else{
- start();
- }
- }
- bool Timer::running(){
- return timer_running;
- }
- int Timer::time(){
- if(timer_running){
- return (int)((getClock()-lastTime)/1000);
- }else{
- return (int)((pauseTime-lastTime)/1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement