Explorar el Código

Some small changes.

Using namespace for file-scope declarations.
SoundNull now pretends to have even more functionality.
Mousegrab state can be queried. Should now grab more reliably.
Thomas Buck hace 10 años
padre
commit
39e274460d
Se han modificado 8 ficheros con 59 adiciones y 19 borrados
  1. 1
    0
      ChangeLog.md
  2. 3
    0
      include/SoundNull.h
  3. 2
    0
      include/Window.h
  4. 2
    0
      include/WindowSDL.h
  5. 21
    5
      src/OpenRaider.cpp
  6. 10
    1
      src/SoundNull.cpp
  7. 4
    0
      src/WindowSDL.cpp
  8. 16
    13
      src/main.cpp

+ 1
- 0
ChangeLog.md Ver fichero

@@ -5,6 +5,7 @@
5 5
     [ 20140728 ]
6 6
     * Implemented binary file reading utility in preparation of
7 7
       TombRaider.cpp/h rewrite
8
+    * Added clibs/commander dependency used for command line argument parsing
8 9
 
9 10
     [ 20140714 ]
10 11
     * Fixed a bug where std::sort did not use the objects operator<

+ 3
- 0
include/SoundNull.h Ver fichero

@@ -95,6 +95,9 @@ public:
95 95
      * \param source sound source to stop
96 96
      */
97 97
     virtual void stop(unsigned long source);
98
+
99
+private:
100
+    unsigned long sources;
98 101
 };
99 102
 
100 103
 #endif

+ 2
- 0
include/Window.h Ver fichero

@@ -22,6 +22,8 @@ public:
22 22
 
23 23
     virtual void setMousegrab(bool grab) = 0;
24 24
 
25
+    virtual bool getMousegrab() = 0;
26
+
25 27
     virtual int initialize() = 0;
26 28
 
27 29
     virtual void eventHandling() = 0;

+ 2
- 0
include/WindowSDL.h Ver fichero

@@ -34,6 +34,8 @@ public:
34 34
 
35 35
     virtual void setMousegrab(bool grab);
36 36
 
37
+    virtual bool getMousegrab();
38
+
37 39
     virtual int initialize();
38 40
 
39 41
     virtual void eventHandling();

+ 21
- 5
src/OpenRaider.cpp Ver fichero

@@ -148,8 +148,8 @@ void OpenRaider::frame() {
148 148
     // Calculate FPS display value
149 149
     fpsCount++;
150 150
     fpsSum += (systemTimerGet() - startTime);
151
-    if (fpsSum >= 500) {
152
-        // Update every 500ms
151
+    if (fpsSum >= 250) {
152
+        // Update every 250ms
153 153
         fps = (int)((float)fpsCount * (1000.0f / (float)fpsSum));
154 154
         fpsCount = fpsSum = 0;
155 155
     }
@@ -177,9 +177,9 @@ void OpenRaider::handleKeyboard(KeyboardButton key, bool pressed) {
177 177
         getMenu().handleKeyboard(key, pressed);
178 178
     }
179 179
 
180
-    //! \fixme Menu/Console visibility could also change in other ways,
181
-    // that should still result in the correct mousegrab state
182
-    getWindow().setMousegrab(!(getMenu().isVisible() || getConsole().isVisible()));
180
+    bool mousegrab = !(getMenu().isVisible() || getConsole().isVisible());
181
+    if (mousegrab != getWindow().getMousegrab())
182
+        getWindow().setMousegrab(mousegrab);
183 183
 }
184 184
 
185 185
 void OpenRaider::handleText(char *text, bool notFinished) {
@@ -190,6 +190,10 @@ void OpenRaider::handleText(char *text, bool notFinished) {
190 190
     if ((getConsole().isVisible()) && (!getMenu().isVisible())) {
191 191
         getConsole().handleText(text, notFinished);
192 192
     }
193
+
194
+    bool mousegrab = !(getMenu().isVisible() || getConsole().isVisible());
195
+    if (mousegrab != getWindow().getMousegrab())
196
+        getWindow().setMousegrab(mousegrab);
193 197
 }
194 198
 
195 199
 void OpenRaider::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
@@ -205,6 +209,10 @@ void OpenRaider::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton
205 209
             }
206 210
         }
207 211
     }
212
+
213
+    bool mousegrab = !(getMenu().isVisible() || getConsole().isVisible());
214
+    if (mousegrab != getWindow().getMousegrab())
215
+        getWindow().setMousegrab(mousegrab);
208 216
 }
209 217
 
210 218
 void OpenRaider::handleMouseMotion(int xrel, int yrel) {
@@ -214,6 +222,10 @@ void OpenRaider::handleMouseMotion(int xrel, int yrel) {
214 222
     if ((!getConsole().isVisible()) && (!getMenu().isVisible())) {
215 223
         getGame().handleMouseMotion(xrel, yrel);
216 224
     }
225
+
226
+    bool mousegrab = !(getMenu().isVisible() || getConsole().isVisible());
227
+    if (mousegrab != getWindow().getMousegrab())
228
+        getWindow().setMousegrab(mousegrab);
217 229
 }
218 230
 
219 231
 void OpenRaider::handleMouseScroll(int xrel, int yrel) {
@@ -223,5 +235,9 @@ void OpenRaider::handleMouseScroll(int xrel, int yrel) {
223 235
     if ((getConsole().isVisible()) && (!getMenu().isVisible())) {
224 236
         getConsole().handleMouseScroll(xrel, yrel);
225 237
     }
238
+
239
+    bool mousegrab = !(getMenu().isVisible() || getConsole().isVisible());
240
+    if (mousegrab != getWindow().getMousegrab())
241
+        getWindow().setMousegrab(mousegrab);
226 242
 }
227 243
 

+ 10
- 1
src/SoundNull.cpp Ver fichero

@@ -9,6 +9,7 @@
9 9
 #include "SoundNull.h"
10 10
 
11 11
 SoundNull::SoundNull() {
12
+    sources = 0;
12 13
 }
13 14
 
14 15
 SoundNull::~SoundNull() {
@@ -25,29 +26,37 @@ void SoundNull::setVolume(float vol) {
25 26
 }
26 27
 
27 28
 unsigned long SoundNull::registeredSources() {
28
-    return 0;
29
+    return sources;
29 30
 }
30 31
 
31 32
 void SoundNull::clear() {
33
+    sources = 0;
32 34
 }
33 35
 
34 36
 void SoundNull::listenAt(float pos[3], float angle[3]) {
35 37
 }
36 38
 
37 39
 void SoundNull::sourceAt(unsigned long source, float pos[3]) {
40
+    assert(source < sources);
38 41
 }
39 42
 
40 43
 int SoundNull::addFile(const char *filename, unsigned long *source, unsigned int flags) {
44
+    *source = sources;
45
+    sources++;
41 46
     return 0;
42 47
 }
43 48
 
44 49
 int SoundNull::addWave(unsigned char *wav, unsigned int length, unsigned long *source, unsigned int flags) {
50
+    *source = sources;
51
+    sources++;
45 52
     return 0;
46 53
 }
47 54
 
48 55
 void SoundNull::play(unsigned long source) {
56
+    assert(source < sources);
49 57
 }
50 58
 
51 59
 void SoundNull::stop(unsigned long source) {
60
+    assert(source < sources);
52 61
 }
53 62
 

+ 4
- 0
src/WindowSDL.cpp Ver fichero

@@ -70,6 +70,10 @@ void WindowSDL::setMousegrab(bool grab) {
70 70
     }
71 71
 }
72 72
 
73
+bool WindowSDL::getMousegrab() {
74
+    return mMousegrab;
75
+}
76
+
73 77
 int WindowSDL::initialize() {
74 78
     assert(mInit == false);
75 79
 

+ 16
- 13
src/main.cpp Ver fichero

@@ -96,21 +96,24 @@ World &getWorld() {
96 96
     return gWorld;
97 97
 }
98 98
 
99
-static void cleanupHandler(void) {
99
+namespace {
100
+    bool configFileWasSpecified = false;
101
+
102
+    void configFileCallback(command_t *self) {
103
+        getOpenRaider().loadConfig(self->arg);
104
+        configFileWasSpecified = true;
105
+    }
106
+
107
+    void cleanupHandler(void) {
100 108
 #ifdef DEBUG
101
-    std::cout << std::endl;
102
-    std::cout << "Thanks for testing " << VERSION << std::endl;
103
-    std::cout << "Build date: " << __DATE__ << " @ " << __TIME__ << std::endl;
104
-    std::cout << "Build host: " << BUILD_HOST << std::endl;
105
-    std::cout << "Web site  : http://github.com/xythobuz/OpenRaider" << std::endl;
106
-    std::cout << "Contact   : xythobuz@xythobuz.de" << std::endl;
109
+        std::cout << std::endl;
110
+        std::cout << "Thanks for testing " << VERSION << std::endl;
111
+        std::cout << "Build date: " << __DATE__ << " @ " << __TIME__ << std::endl;
112
+        std::cout << "Build host: " << BUILD_HOST << std::endl;
113
+        std::cout << "Web site  : http://github.com/xythobuz/OpenRaider" << std::endl;
114
+        std::cout << "Contact   : xythobuz@xythobuz.de" << std::endl;
107 115
 #endif
108
-}
109
-
110
-static bool configFileWasSpecified = false;
111
-static void configFileCallback(command_t *self) {
112
-    getOpenRaider().loadConfig(self->arg);
113
-    configFileWasSpecified = true;
116
+    }
114 117
 }
115 118
 
116 119
 int main(int argc, char *argv[]) {

Loading…
Cancelar
Guardar