소스 검색

Displaying empty SDL window

Thomas Buck 10 년 전
부모
커밋
c40ad37355
6개의 변경된 파일16개의 추가작업 그리고 26개의 파일을 삭제
  1. 0
    2
      include/OpenRaider.h
  2. 0
    2
      include/Window.h
  3. 0
    2
      include/WindowSDL.h
  4. 4
    5
      src/OpenRaider.cpp
  5. 11
    12
      src/WindowSDL.cpp
  6. 1
    3
      src/main.cpp

+ 0
- 2
include/OpenRaider.h 파일 보기

@@ -36,8 +36,6 @@ public:
36 36
 
37 37
     void run();
38 38
 
39
-    void cleanup();
40
-
41 39
 private:
42 40
     bool mInit;
43 41
     bool mRunning;

+ 0
- 2
include/Window.h 파일 보기

@@ -46,8 +46,6 @@ public:
46 46
     virtual void swapBuffersGL() = 0;
47 47
 
48 48
     virtual void resizeGL(unsigned int w, unsigned int h);
49
-
50
-    virtual void cleanup() = 0;
51 49
 };
52 50
 
53 51
 #endif

+ 0
- 2
include/WindowSDL.h 파일 보기

@@ -46,8 +46,6 @@ public:
46 46
 
47 47
     virtual void swapBuffersGL();
48 48
 
49
-    virtual void cleanup();
50
-
51 49
 private:
52 50
     bool mInit;
53 51
     char *mDriver;

+ 4
- 5
src/OpenRaider.cpp 파일 보기

@@ -15,6 +15,8 @@
15 15
 #include "utils/time.h"
16 16
 #include "OpenRaider.h"
17 17
 
18
+#define MAX_MS_PER_FRAME (1000 / MAXIMUM_FPS)
19
+
18 20
 OpenRaider::OpenRaider() {
19 21
     mInit = false;
20 22
     mRunning = false;
@@ -60,11 +62,8 @@ void OpenRaider::run() {
60 62
         mWindow->eventHandling();
61 63
 
62 64
         clock_t stopTime = systemTimerGet();
63
-        mWindow->delay((1000 / MAXIMUM_FPS) - (stopTime - startTime));
65
+        if (MAX_MS_PER_FRAME > (stopTime - startTime))
66
+            mWindow->delay(MAX_MS_PER_FRAME - (stopTime - startTime));
64 67
     }
65 68
 }
66 69
 
67
-void OpenRaider::cleanup() {
68
-    mWindow->cleanup();
69
-}
70
-

+ 11
- 12
src/WindowSDL.cpp 파일 보기

@@ -12,6 +12,8 @@
12 12
 #include "utils/strings.h"
13 13
 #include "WindowSDL.h"
14 14
 
15
+#define SUBSYSTEMS_USED (SDL_INIT_VIDEO | SDL_INIT_EVENTS)
16
+
15 17
 WindowSDL::WindowSDL() {
16 18
     mInit = false;
17 19
     mDriver = NULL;
@@ -26,6 +28,11 @@ WindowSDL::WindowSDL() {
26 28
 WindowSDL::~WindowSDL() {
27 29
     if (mDriver)
28 30
         delete [] mDriver;
31
+
32
+    if (mInit) {
33
+        SDL_QuitSubSystem(SUBSYSTEMS_USED);
34
+        SDL_Quit();
35
+    }
29 36
 }
30 37
 
31 38
 void WindowSDL::setDriver(const char *driver) {
@@ -76,7 +83,7 @@ void WindowSDL::setMousegrab(bool grab) {
76 83
 int WindowSDL::initialize() {
77 84
     assert(mInit == false);
78 85
 
79
-    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
86
+    if (SDL_Init(SUBSYSTEMS_USED) != 0) {
80 87
         printf("SDL_Init Error: %s\n", SDL_GetError());
81 88
         return -1;
82 89
     }
@@ -142,10 +149,6 @@ void WindowSDL::eventHandling() {
142 149
 
143 150
     while(SDL_PollEvent(&event)) {
144 151
         switch (event.type) {
145
-            case SDL_QUIT:
146
-                exit(0);
147
-                break;
148
-
149 152
             case SDL_MOUSEMOTION:
150 153
 
151 154
                 break;
@@ -164,6 +167,9 @@ void WindowSDL::eventHandling() {
164 167
                 if (event.window.event == SDL_WINDOWEVENT_RESIZED)
165 168
                     setSize(event.window.data1, event.window.data2);
166 169
                 break;
170
+
171
+            case SDL_QUIT:
172
+                exit(0);
167 173
         }
168 174
     }
169 175
 }
@@ -188,10 +194,3 @@ void WindowSDL::swapBuffersGL() {
188 194
     SDL_GL_SwapWindow(mWindow);
189 195
 }
190 196
 
191
-void WindowSDL::cleanup() {
192
-    if (mInit) {
193
-        //SDL_QuitSubSystem(SDL_OPENGL);
194
-        SDL_Quit();
195
-    }
196
-}
197
-

+ 1
- 3
src/main.cpp 파일 보기

@@ -16,10 +16,8 @@
16 16
 OpenRaider *gOpenRaider = NULL;
17 17
 
18 18
 void cleanupHandler() {
19
-    if (gOpenRaider) {
20
-        gOpenRaider->cleanup();
19
+    if (gOpenRaider)
21 20
         delete gOpenRaider;
22
-    }
23 21
 }
24 22
 
25 23
 int main(int argc, char *argv[]) {

Loading…
취소
저장