diff --git a/AI/KBlocksAITypeDefine.h b/AI/KBlocksAITypeDefine.h --- a/AI/KBlocksAITypeDefine.h +++ b/AI/KBlocksAITypeDefine.h @@ -27,6 +27,4 @@ #define UNIX -#include - #endif diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,7 @@ AI/KBlocksAIEvaluation.cpp AI/KBlocksAIFeature.cpp AI/KBlocksAILog.cpp + utils.cpp ) ecm_setup_version(${KDE_APPLICATIONS_VERSION} VARIABLE_PREFIX KBLOCKS VERSION_HEADER kblocks_version.h) diff --git a/KBlocksConfigManager.cpp b/KBlocksConfigManager.cpp --- a/KBlocksConfigManager.cpp +++ b/KBlocksConfigManager.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/KBlocksGameRecorder.h b/KBlocksGameRecorder.h --- a/KBlocksGameRecorder.h +++ b/KBlocksGameRecorder.h @@ -41,8 +41,6 @@ void saveBinary(FILE *pFile); void writeByte(FILE *pFile, int value); - timeLong getMillisecOfNow(); - private: list<_game_record_data> mGameRecord; }; diff --git a/KBlocksGameRecorder.cpp b/KBlocksGameRecorder.cpp --- a/KBlocksGameRecorder.cpp +++ b/KBlocksGameRecorder.cpp @@ -8,8 +8,7 @@ * (at your option) any later version. * ***************************************************************************/ #include "KBlocksGameRecorder.h" - -#include +#include "utils.h" KBlocksGameRecorder::KBlocksGameRecorder() { @@ -27,7 +26,7 @@ tmpLastData.index = index; tmpLastData.type = type; tmpLastData.value = value; - tmpLastData.time = getMillisecOfNow(); + tmpLastData.time = Utils::getMillisecOfNow(); mGameRecord.push_back(tmpLastData); } @@ -84,14 +83,3 @@ fputc(tmpByte, pFile); } -timeLong KBlocksGameRecorder::getMillisecOfNow() -{ - timeval tmpCurTime; - - gettimeofday(&tmpCurTime, NULL); - - timeLong tmpMilliTime = (timeLong)tmpCurTime.tv_usec / 1000; - tmpMilliTime += (timeLong)tmpCurTime.tv_sec * 1000; - - return tmpMilliTime; -} diff --git a/KBlocksSingleGame.h b/KBlocksSingleGame.h --- a/KBlocksSingleGame.h +++ b/KBlocksSingleGame.h @@ -10,7 +10,6 @@ #ifndef KBLOCKSSINGLEGAME_H #define KBLOCKSSINGLEGAME_H -#include #include #include "SingleGameInterface.h" @@ -71,8 +70,6 @@ int removeFieldLines(); void prepareNextPiece(); - timeLong getMillisecOfNow(); - protected: KBlocksField *mpField = nullptr; diff --git a/KBlocksSingleGame.cpp b/KBlocksSingleGame.cpp --- a/KBlocksSingleGame.cpp +++ b/KBlocksSingleGame.cpp @@ -10,7 +10,7 @@ #include "KBlocksSingleGame.h" #include "KBlocksField.h" #include "KBlocksPiece.h" - +#include "utils.h" KBlocksSingleGame::KBlocksSingleGame(int gameIndex, int fieldWidth, int fieldHeight, int showPieceCount, int messagePoolSize) { @@ -211,7 +211,7 @@ mCurrentGameState = GameState_Running; - mGameStartTime = getMillisecOfNow(); + mGameStartTime = Utils::getMillisecOfNow(); return mCurrentGameState; } @@ -233,7 +233,7 @@ } else if ((mCurrentGameState == GameState_Pause) && (!flag)) { mCurrentGameState = GameState_Running; - mGameStartTime = getMillisecOfNow(); + mGameStartTime = Utils::getMillisecOfNow(); } return mCurrentGameState; @@ -244,7 +244,7 @@ if ((mCurrentGameState != GameState_Stop) && mStandbyFlag) { mStandbyFlag = false; - mGameStartTime = getMillisecOfNow(); + mGameStartTime = Utils::getMillisecOfNow(); } return mCurrentGameState; @@ -268,7 +268,7 @@ return GameResult_None; } - timeLong tmpCurTime = getMillisecOfNow(); + timeLong tmpCurTime = Utils::getMillisecOfNow(); int gameResult = GameResult_None; @@ -394,14 +394,3 @@ } } -timeLong KBlocksSingleGame::getMillisecOfNow() -{ - timeval tmpCurTime; - - gettimeofday(&tmpCurTime, NULL); - - timeLong tmpMilliTime = (timeLong)tmpCurTime.tv_usec / 1000; - tmpMilliTime += (timeLong)tmpCurTime.tv_sec * 1000; - - return tmpMilliTime; -} diff --git a/utils.h b/utils.h new file mode 100644 --- /dev/null +++ b/utils.h @@ -0,0 +1,9 @@ +#ifndef UTILS_H +#define UTILS_H + +#include "KBlocksDefine.h" + +namespace Utils { + timeLong getMillisecOfNow(); +} +#endif diff --git a/utils.cpp b/utils.cpp new file mode 100644 --- /dev/null +++ b/utils.cpp @@ -0,0 +1,11 @@ +#include "utils.h" + +#include +#include + +timeLong Utils::getMillisecOfNow() +{ + const auto now = std::chrono::system_clock::now(); + + return std::chrono::duration_cast(now.time_since_epoch()).count(); +}