Browse Source

Moved getX() methods [skip ci]

Thomas Buck 9 years ago
parent
commit
ae635bd43a
15 changed files with 80 additions and 91 deletions
  1. 1
    0
      ChangeLog.md
  2. 5
    0
      src/Camera.cpp
  3. 5
    0
      src/Console.cpp
  4. 6
    0
      src/Font.cpp
  5. 5
    0
      src/Game.cpp
  6. 6
    0
      src/Menu.cpp
  7. 5
    0
      src/OpenRaider.cpp
  8. 5
    0
      src/Render.cpp
  9. 15
    0
      src/Sound.cpp
  10. 5
    0
      src/TextureManager.cpp
  11. 13
    0
      src/Window.cpp
  12. 5
    0
      src/World.cpp
  13. 2
    86
      src/main.cpp
  14. 2
    3
      test/CMakeLists.txt
  15. 0
    2
      test/Script.cpp

+ 1
- 0
ChangeLog.md View File

@@ -6,6 +6,7 @@
6 6
     * Created abstract UI class handling “windows” like menu and console. Windows
7 7
       can be stacked arbitrarily. The top most gets keyboard/mouse/action events.
8 8
     * Removed old C-String handling utility methods, now using std::string
9
+    * Moved getX() methods from main into their respective cpp file
9 10
 
10 11
     [ 20140831 ]
11 12
     * Moved command specific code from OpenRaider to static Command methods

+ 5
- 0
src/Camera.cpp View File

@@ -11,6 +11,11 @@
11 11
 #include "math/Matrix.h"
12 12
 #include "Camera.h"
13 13
 
14
+Camera &getCamera() {
15
+    static Camera gCamera;
16
+    return gCamera;
17
+}
18
+
14 19
 Camera::Camera() {
15 20
     mViewDistance = 14.0f;
16 21
     mRotationDeltaX = 1.0f;

+ 5
- 0
src/Console.cpp View File

@@ -16,6 +16,11 @@
16 16
 #include "Window.h"
17 17
 #include "Console.h"
18 18
 
19
+Console &getConsole() {
20
+    static Console gConsole;
21
+    return gConsole;
22
+}
23
+
19 24
 Console::Console() {
20 25
     zPos = -1;
21 26
     mHistoryPointer = 0;

+ 6
- 0
src/Font.cpp View File

@@ -9,6 +9,12 @@
9 9
 #include "utils/strings.h"
10 10
 #include "Window.h"
11 11
 #include "Font.h"
12
+#include "FontManager.h"
13
+
14
+Font &getFont() {
15
+    static FontManager gFont;
16
+    return gFont;
17
+}
12 18
 
13 19
 Font::~Font() {
14 20
 }

+ 5
- 0
src/Game.cpp View File

@@ -29,6 +29,11 @@
29 29
 std::map<int, int> gMapTex2Bump;
30 30
 #endif
31 31
 
32
+Game &getGame() {
33
+    static Game gGame;
34
+    return gGame;
35
+}
36
+
32 37
 Game::Game() {
33 38
     zPos = 0;
34 39
     mLoaded = false;

+ 6
- 0
src/Menu.cpp View File

@@ -10,6 +10,12 @@
10 10
 #include "Font.h"
11 11
 #include "Window.h"
12 12
 #include "Menu.h"
13
+#include "MenuFolder.h"
14
+
15
+Menu &getMenu() {
16
+    static MenuFolder gMenu;
17
+    return gMenu;
18
+}
13 19
 
14 20
 void Menu::showDialog(std::string msg, std::string btn1, std::string btn2,
15 21
         std::function<int (bool state)> callback) {

+ 5
- 0
src/OpenRaider.cpp View File

@@ -23,6 +23,11 @@
23 23
 #include "Window.h"
24 24
 #include "OpenRaider.h"
25 25
 
26
+OpenRaider &getOpenRaider() {
27
+    static OpenRaider gOpenRaider;
28
+    return gOpenRaider;
29
+}
30
+
26 31
 OpenRaider::OpenRaider() {
27 32
     mRunning = false;
28 33
     mFPS = false;

+ 5
- 0
src/Render.cpp View File

@@ -24,6 +24,11 @@
24 24
 #include "Window.h"
25 25
 #include "World.h"
26 26
 
27
+Render &getRender() {
28
+    static Render gRender;
29
+    return gRender;
30
+}
31
+
27 32
 Render::Render() {
28 33
     mSkyMesh = -1;
29 34
     mSkyMeshRotation = false;

+ 15
- 0
src/Sound.cpp View File

@@ -8,6 +8,21 @@
8 8
 #include "global.h"
9 9
 #include "Sound.h"
10 10
 
11
+#ifdef USING_AL
12
+#include "SoundAL.h"
13
+#else
14
+#include "SoundNull.h"
15
+#endif
16
+
17
+Sound &getSound() {
18
+#ifdef USING_AL
19
+    static SoundAL gSound;
20
+#else
21
+    static SoundNull gSound;
22
+#endif
23
+    return gSound;
24
+}
25
+
11 26
 Sound::~Sound() {
12 27
 }
13 28
 

+ 5
- 0
src/TextureManager.cpp View File

@@ -24,6 +24,11 @@
24 24
 #include "utils/png.h"
25 25
 #endif
26 26
 
27
+TextureManager &getTextureManager() {
28
+    static TextureManager gTextureManager;
29
+    return gTextureManager;
30
+}
31
+
27 32
 TextureManager::TextureManager() {
28 33
     mFlags = 0;
29 34
 }

+ 13
- 0
src/Window.cpp View File

@@ -15,6 +15,19 @@
15 15
 #include "utils/strings.h"
16 16
 #include "Window.h"
17 17
 
18
+#ifdef USING_SDL
19
+#include "WindowSDL.h"
20
+#else
21
+#error No Windowing Library selected!
22
+#endif
23
+
24
+Window &getWindow() {
25
+#ifdef USING_SDL
26
+    static WindowSDL gWindow;
27
+#endif
28
+    return gWindow;
29
+}
30
+
18 31
 unsigned int Window::getWidth() {
19 32
     return mWidth;
20 33
 }

+ 5
- 0
src/World.cpp View File

@@ -11,6 +11,11 @@
11 11
 #include "global.h"
12 12
 #include "World.h"
13 13
 
14
+World &getWorld() {
15
+    static World gWorld;
16
+    return gWorld;
17
+}
18
+
14 19
 World::~World() {
15 20
     destroy();
16 21
 }

+ 2
- 86
src/main.cpp View File

@@ -6,99 +6,15 @@
6 6
  */
7 7
 
8 8
 #include <iostream>
9
-#include <cstdlib>
10
-#include <cstring>
11 9
 
12 10
 #include "global.h"
13
-#include "Camera.h"
14 11
 #include "Console.h"
15 12
 #include "Exception.h"
16
-#include "FontManager.h"
17
-#include "Game.h"
18
-#include "MenuFolder.h"
19 13
 #include "OpenRaider.h"
20
-#include "Render.h"
21
-#include "TextureManager.h"
22
-#include "World.h"
23 14
 #include "commander/commander.h"
24
-#include "utils/strings.h"
25
-#include "utils/time.h"
26 15
 
27 16
 #ifndef UNIT_TEST
28 17
 
29
-#ifdef USING_AL
30
-#include "SoundAL.h"
31
-#else
32
-#include "SoundNull.h"
33
-#endif
34
-
35
-#ifdef USING_SDL
36
-#include "WindowSDL.h"
37
-#else
38
-#error No Windowing Library selected!
39
-#endif
40
-
41
-Camera &getCamera() {
42
-    static Camera gCamera;
43
-    return gCamera;
44
-}
45
-
46
-Console &getConsole() {
47
-    static Console gConsole;
48
-    return gConsole;
49
-}
50
-
51
-Font &getFont() {
52
-    static FontManager gFont;
53
-    return gFont;
54
-}
55
-
56
-Game &getGame() {
57
-    static Game gGame;
58
-    return gGame;
59
-}
60
-
61
-Menu &getMenu() {
62
-    static MenuFolder gMenu;
63
-    return gMenu;
64
-}
65
-
66
-OpenRaider &getOpenRaider() {
67
-    static OpenRaider gOpenRaider;
68
-    return gOpenRaider;
69
-}
70
-
71
-Render &getRender() {
72
-    static Render gRender;
73
-    return gRender;
74
-}
75
-
76
-Sound &getSound() {
77
-#ifdef USING_AL
78
-    static SoundAL gSound;
79
-#else
80
-    static SoundNull gSound;
81
-#endif
82
-    return gSound;
83
-}
84
-
85
-TextureManager &getTextureManager() {
86
-    static TextureManager gTextureManager;
87
-    return gTextureManager;
88
-}
89
-
90
-Window &getWindow() {
91
-#ifdef USING_SDL
92
-    static WindowSDL gWindow;
93
-#endif
94
-    return gWindow;
95
-}
96
-
97
-World &getWorld() {
98
-    static World gWorld;
99
-    return gWorld;
100
-}
101
-
102 18
 namespace {
103 19
     bool configFileWasSpecified = false;
104 20
 
@@ -119,7 +35,7 @@ namespace {
119 35
     }
120 36
 }
121 37
 
122
-int main(int argc, char *argv[]) {
38
+int main(int argc, char* argv[]) {
123 39
     command_t cmd;
124 40
     command_init(&cmd, argv[0], VERSION);
125 41
     //command_option(&cmd, "-v", "--verbose", "enable verbose output", functionPointer);
@@ -141,7 +57,7 @@ int main(int argc, char *argv[]) {
141 57
     int error = getOpenRaider().initialize();
142 58
     if (error != 0) {
143 59
         std::cout << "Could not initialize OpenRaider (" << error << ")!" << std::endl;
144
-        return 2;
60
+        return -1;
145 61
     }
146 62
 
147 63
     command_free(&cmd);

+ 2
- 3
test/CMakeLists.txt View File

@@ -27,9 +27,8 @@ add_dependencies (check tester_folder)
27 27
 #################################################################
28 28
 
29 29
 add_executable (tester_script EXCLUDE_FROM_ALL
30
-    "Script.cpp" "../src/Script.cpp" "../src/utils/strings.cpp"
31
-    "../src/utils/binary.cpp" "../src/utils/filesystem.cpp"
32
-    "../src/Exception.cpp" "../src/main.cpp"
30
+    "Script.cpp" "../src/Script.cpp" "../src/main.cpp"
31
+    "../src/utils/binary.cpp" "../src/Exception.cpp"
33 32
 )
34 33
 
35 34
 find_package (ZLIB REQUIRED)

+ 0
- 2
test/Script.cpp View File

@@ -6,12 +6,10 @@
6 6
  */
7 7
 
8 8
 #include <iostream>
9
-#include <cstring>
10 9
 #include <cstdlib>
11 10
 #include <zlib.h>
12 11
 
13 12
 #include "global.h"
14
-#include "utils/strings.h"
15 13
 #include "Script.h"
16 14
 #include "ScriptTest.h"
17 15
 

Loading…
Cancel
Save