Browse Source

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 10 years ago
parent
commit
39e274460d
8 changed files with 59 additions and 19 deletions
  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 View File

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

+ 3
- 0
include/SoundNull.h View File

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

+ 2
- 0
include/Window.h View File

22
 
22
 
23
     virtual void setMousegrab(bool grab) = 0;
23
     virtual void setMousegrab(bool grab) = 0;
24
 
24
 
25
+    virtual bool getMousegrab() = 0;
26
+
25
     virtual int initialize() = 0;
27
     virtual int initialize() = 0;
26
 
28
 
27
     virtual void eventHandling() = 0;
29
     virtual void eventHandling() = 0;

+ 2
- 0
include/WindowSDL.h View File

34
 
34
 
35
     virtual void setMousegrab(bool grab);
35
     virtual void setMousegrab(bool grab);
36
 
36
 
37
+    virtual bool getMousegrab();
38
+
37
     virtual int initialize();
39
     virtual int initialize();
38
 
40
 
39
     virtual void eventHandling();
41
     virtual void eventHandling();

+ 21
- 5
src/OpenRaider.cpp View File

148
     // Calculate FPS display value
148
     // Calculate FPS display value
149
     fpsCount++;
149
     fpsCount++;
150
     fpsSum += (systemTimerGet() - startTime);
150
     fpsSum += (systemTimerGet() - startTime);
151
-    if (fpsSum >= 500) {
152
-        // Update every 500ms
151
+    if (fpsSum >= 250) {
152
+        // Update every 250ms
153
         fps = (int)((float)fpsCount * (1000.0f / (float)fpsSum));
153
         fps = (int)((float)fpsCount * (1000.0f / (float)fpsSum));
154
         fpsCount = fpsSum = 0;
154
         fpsCount = fpsSum = 0;
155
     }
155
     }
177
         getMenu().handleKeyboard(key, pressed);
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
 void OpenRaider::handleText(char *text, bool notFinished) {
185
 void OpenRaider::handleText(char *text, bool notFinished) {
190
     if ((getConsole().isVisible()) && (!getMenu().isVisible())) {
190
     if ((getConsole().isVisible()) && (!getMenu().isVisible())) {
191
         getConsole().handleText(text, notFinished);
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
 void OpenRaider::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
199
 void OpenRaider::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
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
 void OpenRaider::handleMouseMotion(int xrel, int yrel) {
218
 void OpenRaider::handleMouseMotion(int xrel, int yrel) {
214
     if ((!getConsole().isVisible()) && (!getMenu().isVisible())) {
222
     if ((!getConsole().isVisible()) && (!getMenu().isVisible())) {
215
         getGame().handleMouseMotion(xrel, yrel);
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
 void OpenRaider::handleMouseScroll(int xrel, int yrel) {
231
 void OpenRaider::handleMouseScroll(int xrel, int yrel) {
223
     if ((getConsole().isVisible()) && (!getMenu().isVisible())) {
235
     if ((getConsole().isVisible()) && (!getMenu().isVisible())) {
224
         getConsole().handleMouseScroll(xrel, yrel);
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 View File

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

+ 4
- 0
src/WindowSDL.cpp View File

70
     }
70
     }
71
 }
71
 }
72
 
72
 
73
+bool WindowSDL::getMousegrab() {
74
+    return mMousegrab;
75
+}
76
+
73
 int WindowSDL::initialize() {
77
 int WindowSDL::initialize() {
74
     assert(mInit == false);
78
     assert(mInit == false);
75
 
79
 

+ 16
- 13
src/main.cpp View File

96
     return gWorld;
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
 #ifdef DEBUG
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
 #endif
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
 int main(int argc, char *argv[]) {
119
 int main(int argc, char *argv[]) {

Loading…
Cancel
Save