📄 timemanager.cpp
字号:
//////////////////////////////////////////////////////////////////////////////// Filename : TimeManager.cpp// Written By : Reiot//////////////////////////////////////////////////////////////////////////////#include "TimeManager.h"#include "Properties.h"#include <time.h>//////////////////////////////////////////////////////////////////////////////// initialize //////////////////////////////////////////////////////////////////////////////void TimeManager::init () throw (Error){ __BEGIN_TRY try { // 扁霖 霸烙 矫埃, 扁霖 角力 矫埃阑 券版 颇老俊辑 佬绢柯促. string strBaseGameTime = g_pConfig->getProperty("BaseGameTime"); string strBaseRealTime = g_pConfig->getProperty("BaseRealTime"); int yearEnd = strBaseGameTime.find('-' , 0); int monEnd = strBaseGameTime.find('-' , yearEnd + 1); int dayEnd = strBaseGameTime.find_last_not_of(' '); string year = strBaseGameTime.substr(0 , yearEnd); string month = strBaseGameTime.substr(yearEnd + 1 , monEnd - yearEnd); string day = strBaseGameTime.substr(monEnd + 1 , dayEnd - monEnd); //cout << yearEnd << ":" << monEnd << ":" << dayEnd << endl; //cout << "BaseGameTime : " << year << "/" << month << "/" << day << endl; yearEnd = strBaseRealTime.find('-' , 0); monEnd = strBaseRealTime.find('-' , yearEnd + 1); dayEnd = strBaseRealTime.find_last_not_of(' '); year = strBaseRealTime.substr(0 , yearEnd); month = strBaseRealTime.substr(yearEnd + 1 , monEnd); day = strBaseRealTime.substr(monEnd + 1 , string::npos); //cout << yearEnd << ":" << monEnd << ":" << dayEnd << endl; //cout << "BaseRealTime : " << year << "/" << month << "/" << day << endl; // 扁霖 霸烙 矫埃 : 1999斥 8岿 18老 // 扁霖 霸烙 矫埃 : 1990斥 7岿 20老 // 斥,老阑 力寇茄 葛电 矫埃蔼甸篮 0 何磐 矫累茄促绰 单 蜡狼且 巴. struct tm baseGameTime; baseGameTime.tm_year = 90; // 1990斥 baseGameTime.tm_mon = 6; // 7岿 baseGameTime.tm_mday = 20; // 20老 baseGameTime.tm_hour = 0; // 0矫 baseGameTime.tm_min = 0; // 0盒 baseGameTime.tm_sec = 0; // 0檬 baseGameTime.tm_isdst = 0; // !级赣鸥烙 // 扁霖 角力 矫埃 : 2003斥 1岿 1老 struct tm baseRealTime; baseRealTime.tm_year = 103; // 2003斥 baseRealTime.tm_mon = 9; // 10岿 baseRealTime.tm_mday = 1; // 1老 baseRealTime.tm_hour = 0; // 0矫 baseRealTime.tm_min = 0; // 0盒 baseRealTime.tm_sec = 0; // 0檬 baseRealTime.tm_isdst = 0; // !级赣鸥烙 //cout << "asctime(m_BaseGameTime) : " << asctime(&baseGameTime); //cout << "asctime(m_BaseRealTime) : " << asctime(&baseRealTime); m_BaseGameTime = mktime(&baseGameTime); m_BaseRealTime = mktime(&baseRealTime); //cout << "BaseGameTime(" << m_BaseGameTime << ") :" << ctime(&m_BaseGameTime); //cout << "BaseRealTime(" << m_BaseRealTime << ") :" << ctime(&m_BaseRealTime); } catch (NoSuchElementException & nsee) { throw Error(nsee.toString()); } __END_CATCH}//////////////////////////////////////////////////////////////////////////////// 泅犁 霸烙 矫埃阑 舅酒辰促.//////////////////////////////////////////////////////////////////////////////GameTime TimeManager::getGameTime () const throw (){ __BEGIN_TRY // 泅犁 矫埃阑 螟沥茄促. time_t currentTime = time(0); // // 角矫埃捞 霸烙矫埃俊 厚秦辑 5硅 蠢府霸 柳青等促绰 痢阑 捞侩秦辑 // 霸烙 矫埃阑 备茄促. // // (霸烙矫埃 = 扁霖霸烙矫埃 + (泅犁角矫埃 - 扁霖角矫埃)* 5 // //time_t gameTime = m_BaseGameTime + (currentTime - m_BaseRealTime)* 24; time_t gameTime = (currentTime - m_BaseRealTime)* 24;// ITV侩 全焊侩.// time_t gameTime = m_BaseGameTime + (currentTime - m_BaseRealTime)* 1440; // GameTime 按眉甫 檬扁拳窍扁 困秦辑绰, tm 胶飘钒贸甫 掘绢郴具 茄促. // tm 胶飘钒贸俊辑 斥,老阑 力寇茄 蔼甸捞 0何磐 矫累茄促绰 痢俊 蜡狼且 巴. tm ltm; localtime_r( &gameTime, <m ); //struct tm* ptm = localtime(&gameTime); GameTime result; result.setYear(1930 + ltm.tm_year); result.setMonth(ltm.tm_mon + 1); result.setDay(ltm.tm_mday); result.setHour(ltm.tm_hour); result.setMinute(ltm.tm_min); result.setSecond(ltm.tm_sec); return result; __END_CATCH}//////////////////////////////////////////////////////////////////////////////// 泅犁 霸烙 矫埃阑 time_t 蔼栏肺 舅酒辰促.//////////////////////////////////////////////////////////////////////////////time_t TimeManager::getgametime () const throw (){ __BEGIN_TRY // // 角矫埃捞 霸烙矫埃俊 厚秦辑 5硅 蠢府霸 柳青等促绰 痢阑 捞侩秦辑 // 霸烙 矫埃阑 备茄促. // // (霸烙矫埃 = 扁霖霸烙矫埃 + (泅犁角矫埃 - 扁霖角矫埃)* 5 // return m_BaseGameTime + (time(0) - m_BaseRealTime)* 24; // ITV 全焊侩.// return m_BaseGameTime + (time(0) - m_BaseRealTime)* 1440; __END_CATCH}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////bool TimeManager::isDawnTime() const throw(){ __BEGIN_TRY if (getTimeband() == TIME_DAWN) return true; return false; __END_CATCH}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////bool TimeManager::isDayTime() const throw(){ __BEGIN_TRY if (getTimeband() == TIME_DAY) return true; return false; __END_CATCH}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////bool TimeManager::isDuskTime() const throw(){ __BEGIN_TRY if (getTimeband() == TIME_DUSK) return true; return false; __END_CATCH}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////bool TimeManager::isNightTime() const throw(){ __BEGIN_TRY if (getTimeband() == TIME_NIGHT) return true; return false; __END_CATCH}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////uint TimeManager::getTimeband(void) const throw(){ __BEGIN_TRY GameTime gameTime = getGameTime(); BYTE hour = gameTime.getHour(); if (DAWN_START_HOUR < hour && hour <= DAWN_END_HOUR) { return TIME_DAWN; } else if (DAY_START_HOUR < hour && hour <= DAY_END_HOUR) { return TIME_DAY; } else if (DUSK_START_HOUR < hour && hour <= DUSK_END_HOUR) { return TIME_DUSK; } else return TIME_NIGHT; __END_CATCH}//////////////////////////////////////////////////////////////////////////////// get debug string//////////////////////////////////////////////////////////////////////////////string TimeManager::toString () const throw (){ __BEGIN_TRY StringStream msg; msg << "TimeManager:(" << "BaseGameTime:" << (int)ctime(&m_BaseGameTime) << "BaseRealTime:" << (int)ctime(&m_BaseRealTime) << ")"; return msg.toString(); __END_CATCH}// global variable definitionTimeManager* g_pTimeManager = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -