Переглянути джерело

Moved getX() methods [skip ci]

Thomas Buck 9 роки тому
джерело
коміт
ae635bd43a
15 змінених файлів з 80 додано та 91 видалено
  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 Переглянути файл

6
     * Created abstract UI class handling “windows” like menu and console. Windows
6
     * Created abstract UI class handling “windows” like menu and console. Windows
7
       can be stacked arbitrarily. The top most gets keyboard/mouse/action events.
7
       can be stacked arbitrarily. The top most gets keyboard/mouse/action events.
8
     * Removed old C-String handling utility methods, now using std::string
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
     [ 20140831 ]
11
     [ 20140831 ]
11
     * Moved command specific code from OpenRaider to static Command methods
12
     * Moved command specific code from OpenRaider to static Command methods

+ 5
- 0
src/Camera.cpp Переглянути файл

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

+ 5
- 0
src/Console.cpp Переглянути файл

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

+ 6
- 0
src/Font.cpp Переглянути файл

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

+ 5
- 0
src/Game.cpp Переглянути файл

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

+ 6
- 0
src/Menu.cpp Переглянути файл

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

+ 5
- 0
src/OpenRaider.cpp Переглянути файл

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

+ 5
- 0
src/Render.cpp Переглянути файл

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

+ 15
- 0
src/Sound.cpp Переглянути файл

8
 #include "global.h"
8
 #include "global.h"
9
 #include "Sound.h"
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
 Sound::~Sound() {
26
 Sound::~Sound() {
12
 }
27
 }
13
 
28
 

+ 5
- 0
src/TextureManager.cpp Переглянути файл

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

+ 13
- 0
src/Window.cpp Переглянути файл

15
 #include "utils/strings.h"
15
 #include "utils/strings.h"
16
 #include "Window.h"
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
 unsigned int Window::getWidth() {
31
 unsigned int Window::getWidth() {
19
     return mWidth;
32
     return mWidth;
20
 }
33
 }

+ 5
- 0
src/World.cpp Переглянути файл

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

+ 2
- 86
src/main.cpp Переглянути файл

6
  */
6
  */
7
 
7
 
8
 #include <iostream>
8
 #include <iostream>
9
-#include <cstdlib>
10
-#include <cstring>
11
 
9
 
12
 #include "global.h"
10
 #include "global.h"
13
-#include "Camera.h"
14
 #include "Console.h"
11
 #include "Console.h"
15
 #include "Exception.h"
12
 #include "Exception.h"
16
-#include "FontManager.h"
17
-#include "Game.h"
18
-#include "MenuFolder.h"
19
 #include "OpenRaider.h"
13
 #include "OpenRaider.h"
20
-#include "Render.h"
21
-#include "TextureManager.h"
22
-#include "World.h"
23
 #include "commander/commander.h"
14
 #include "commander/commander.h"
24
-#include "utils/strings.h"
25
-#include "utils/time.h"
26
 
15
 
27
 #ifndef UNIT_TEST
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
 namespace {
18
 namespace {
103
     bool configFileWasSpecified = false;
19
     bool configFileWasSpecified = false;
104
 
20
 
119
     }
35
     }
120
 }
36
 }
121
 
37
 
122
-int main(int argc, char *argv[]) {
38
+int main(int argc, char* argv[]) {
123
     command_t cmd;
39
     command_t cmd;
124
     command_init(&cmd, argv[0], VERSION);
40
     command_init(&cmd, argv[0], VERSION);
125
     //command_option(&cmd, "-v", "--verbose", "enable verbose output", functionPointer);
41
     //command_option(&cmd, "-v", "--verbose", "enable verbose output", functionPointer);
141
     int error = getOpenRaider().initialize();
57
     int error = getOpenRaider().initialize();
142
     if (error != 0) {
58
     if (error != 0) {
143
         std::cout << "Could not initialize OpenRaider (" << error << ")!" << std::endl;
59
         std::cout << "Could not initialize OpenRaider (" << error << ")!" << std::endl;
144
-        return 2;
60
+        return -1;
145
     }
61
     }
146
 
62
 
147
     command_free(&cmd);
63
     command_free(&cmd);

+ 2
- 3
test/CMakeLists.txt Переглянути файл

27
 #################################################################
27
 #################################################################
28
 
28
 
29
 add_executable (tester_script EXCLUDE_FROM_ALL
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
 find_package (ZLIB REQUIRED)
34
 find_package (ZLIB REQUIRED)

+ 0
- 2
test/Script.cpp Переглянути файл

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

Завантаження…
Відмінити
Зберегти