Jelajahi Sumber

[programming challenge] Our very own sleep.

Michał W. Urbańczyk 14 tahun lalu
induk
melakukan
7b081de638
2 mengubah file dengan 16 tambahan dan 3 penghapusan
  1. 6 2
      VCMI_BattleAiHost/CheckTime.h
  2. 10 1
      VCMI_BattleAiHost/main.cpp

+ 6 - 2
VCMI_BattleAiHost/CheckTime.h

@@ -68,6 +68,8 @@ const int TACTICS_TIME = 1000;
 void postInfoCall(int timeUsed);
 void postDecisionCall(int timeUsed, const std::string &text = "AI was thinking over an action", int timeLimit = MAKE_DECIDION_TIME);
 
+void mySleep(int ms);
+
 struct Bomb
 {
 	std::string txt;
@@ -75,7 +77,8 @@ struct Bomb
 
 	void run(int time)
 	{
-		boost::this_thread::sleep(boost::posix_time::milliseconds(time));
+		//boost::this_thread::sleep(boost::posix_time::milliseconds(time));
+		mySleep(time);
 		if(armed)
 		{
 			tlog1 << "BOOOM! The bomb exploded! AI was thinking for too long!\n";
@@ -97,4 +100,5 @@ struct Bomb
 	{
 		armed = 0;
 	}
-};
+};
+

+ 10 - 1
VCMI_BattleAiHost/main.cpp

@@ -27,7 +27,16 @@ using namespace boost;
 
 std::string NAME = NAME_VER + std::string(" DLL runner");
 
-
+void mySleep(int ms)
+{
+	CheckTime timer;
+#ifdef _WIN32
+	Sleep(ms);
+#else
+	usleep(ms * 1000);
+#endif
+	tlog0 << "We were ordered to sleep for " << ms << " ms and we did for " << timer.timeSinceStart() << std::endl;
+}
 
 int main(int argc, char** argv)
 {