Kaynağa Gözat

fixed sleep error on windows and ubuntu

Luis 9 yıl önce
ebeveyn
işleme
235d3a06ad
1 değiştirilmiş dosya ile 18 ekleme ve 3 silme
  1. 18
    3
      functions.cpp

+ 18
- 3
functions.cpp Dosyayı Görüntüle

7
 
7
 
8
 #include <QMessageBox>
8
 #include <QMessageBox>
9
 #include <QMap>
9
 #include <QMap>
10
+#include <windows.h>
10
 #include "functions.h"
11
 #include "functions.h"
11
 #ifdef _WIN32
12
 #ifdef _WIN32
12
 #include <windows.h>
13
 #include <windows.h>
115
     //This loop is used to simulate the dice rolling by
116
     //This loop is used to simulate the dice rolling by
116
     //changing the images at a slowing down speed
117
     //changing the images at a slowing down speed
117
     for (int i = 0; i<=150000 ; i=i+5000){
118
     for (int i = 0; i<=150000 ; i=i+5000){
119
+
120
+#ifdef _WIN32
118
         Sleep(i);
121
         Sleep(i);
122
+#else
123
+        usleep(i);
124
+#endif
119
 
125
 
120
         //First dice image. Since we want random pictures
126
         //First dice image. Since we want random pictures
121
         //on each iteration, we get a random number, converted
127
         //on each iteration, we get a random number, converted
173
     QString a, b;
179
     QString a, b;
174
 
180
 
175
     for (int i = 0; i<=150000 ; i=i+5000){
181
     for (int i = 0; i<=150000 ; i=i+5000){
182
+#ifdef _WIN32
176
         Sleep(i);
183
         Sleep(i);
177
-
184
+#else
185
+        usleep(i);
186
+#endif
178
         a = ":/images/resources/d";
187
         a = ":/images/resources/d";
179
         a.append(QString::number(rand()%6 + 1));
188
         a.append(QString::number(rand()%6 + 1));
180
         a.append(".png");
189
         a.append(".png");
205
     QString a, b;
214
     QString a, b;
206
 
215
 
207
     for (int i = 0; i<=150000 ; i=i+5000){
216
     for (int i = 0; i<=150000 ; i=i+5000){
217
+#ifdef _WIN32
208
         Sleep(i);
218
         Sleep(i);
209
-
219
+#else
220
+        usleep(i);
221
+#endif
210
         a = ":/images/resources/d";
222
         a = ":/images/resources/d";
211
         a.append(QString::number(rand()%6 + 1));
223
         a.append(QString::number(rand()%6 + 1));
212
         a.append(".png");
224
         a.append(".png");
239
     QString a, b;
251
     QString a, b;
240
 
252
 
241
     for (int i = 0; i<=150000 ; i=i+5000){
253
     for (int i = 0; i<=150000 ; i=i+5000){
254
+#ifdef _WIN32
242
         Sleep(i);
255
         Sleep(i);
243
-
256
+#else
257
+        usleep(i);
258
+#endif
244
         a = ":/images/resources/d";
259
         a = ":/images/resources/d";
245
         a.append(QString::number(rand()%6 + 1));
260
         a.append(QString::number(rand()%6 + 1));
246
         a.append(".png");
261
         a.append(".png");