Created
June 25, 2014 13:31
-
-
Save sdkfz181tiger/60017fc9f07e497ef73b to your computer and use it in GitHub Desktop.
UtilClock(Cocos2dx_ver3.0)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UtilClock.cpp | |
// Oyadius3 | |
// | |
// Created by Shimeji Ozaki on 2014-04-25. | |
// | |
// | |
#include "UtilClock.h" | |
UtilClock::UtilClock(){ | |
} | |
UtilClock::~UtilClock(){ | |
} | |
// Singleton Object | |
static UtilClock* selfUtilClock = nullptr; | |
UtilClock* UtilClock::getInstance(){ | |
if(!selfUtilClock){ | |
selfUtilClock = new UtilClock(); | |
if(selfUtilClock && selfUtilClock->init()){ | |
return selfUtilClock; | |
} | |
return NULL; | |
}else{ | |
return selfUtilClock; | |
} | |
} | |
bool UtilClock::init(){ | |
log("UtilClock::init"); | |
return true; | |
} | |
void UtilClock::setBasedTime(){ | |
// 現在の時刻を取得 | |
time_t tNow = time(NULL); | |
// 基準時間をUserDefaultに記録 | |
UtilUserDefault::getInstance()->setTimeCount(tNow); | |
} | |
int UtilClock::getBasedTime(){ | |
// 基準時間をUserDefaultから取得 | |
int basedTime = UtilUserDefault::getInstance()->getTimeCount(); | |
return basedTime; | |
} | |
void UtilClock::checkOut(){ | |
// 現在の時刻を取得 | |
time_t tNow = time(NULL); | |
// 現在の時刻との差 | |
setPassedTime(tNow - getBasedTime()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UtilClock.h | |
// Oyadius3 | |
// | |
// Created by Shimeji Ozaki on 2014-04-25. | |
// | |
// | |
#ifndef __Oyadius3__UtilClock__ | |
#define __Oyadius3__UtilClock__ | |
#include <chrono> | |
#include <time.h> | |
#include "cocos2d.h" | |
#include "UtilUserDefault.h" | |
USING_NS_CC; | |
class UtilClock{ | |
public: | |
CC_SYNTHESIZE(int, passedTime, PassedTime); | |
UtilClock(); | |
~UtilClock(); | |
static UtilClock* getInstance(); | |
bool init(); | |
void setBasedTime();// 基準時間を確定してUserDefaultへ | |
int getBasedTime(); // 基準時間をUserDefaultへから取得 | |
void checkOut();// passedTimeの確定 | |
}; | |
#endif /* defined(__Oyadius3__UtilClock__) */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment