Browse Source

Removed OpenRaider class, added RunTime class

Thomas Buck 9 years ago
parent
commit
53919aa554

+ 3
- 1
ChangeLog.md View File

@@ -4,7 +4,9 @@
4 4
 
5 5
     [ 20140903 ]
6 6
     * Finishing imgui integration, but now as UI layer and not on top of everything
7
-    * All global objects are now explicitly allocated in main
7
+    * All global objects are now explicitly allocated in main and stored in shared_ptrs
8
+    * Created RunTime class for run time settings/options storage
9
+    * Completely removed OpenRaider class
8 10
 
9 11
     [ 20140901 ]
10 12
     * Created abstract UI class handling “windows” like menu and console. Windows

+ 4
- 0
TODO.md View File

@@ -14,6 +14,10 @@
14 14
 ## Bugs
15 15
 
16 16
 * Screenshots are sometimes not written, sometimes distorted?
17
+* imgui integration still very much unfinished
18
+    * toggling with ‘q’ means one can’t use input ‘q’ into a text field
19
+    * clicking outside of the debug window does nothing
20
+    * it seems as if colors aren’t rendering properly
17 21
 
18 22
 ## Cmake
19 23
 

include/OpenRaider.h → include/RunTime.h View File

@@ -1,30 +1,22 @@
1 1
 /*!
2
- * \file include/OpenRaider.h
3
- * \brief Main Game Object
2
+ * \file include/RunTime.h
3
+ * \brief run time configuration storage
4 4
  *
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
-#ifndef _OPENRAIDER_H_
9
-#define _OPENRAIDER_H_
8
+#ifndef _RUNTIME_H_
9
+#define _RUNTIME_H_
10 10
 
11 11
 #include <string>
12 12
 
13 13
 /*!
14 14
  * \brief Main Game Singleton
15 15
  */
16
-class OpenRaider {
16
+class RunTime {
17 17
 public:
18 18
 
19
-    OpenRaider();
20
-
21
-    int initialize();
22
-
23
-    /*!
24
-     * \brief Load the configuration file
25
-     * \returns 0 on success
26
-     */
27
-    int loadConfig(std::string config);
19
+    RunTime();
28 20
 
29 21
     std::string getBaseDir();
30 22
     void setBaseDir(std::string dir);
@@ -35,22 +27,27 @@ public:
35 27
     std::string getDataDir();
36 28
     void setDataDir(std::string dir);
37 29
 
38
-    void run();
39
-    void frame();
30
+    KeyboardButton getKeyBinding(ActionEvents event);
31
+    void setKeyBinding(ActionEvents event, KeyboardButton button);
40 32
 
41
-    //! \fixme should be private
42
-    KeyboardButton keyBindings[ActionEventCount];
43
-    bool mRunning;
44
-    bool mFPS;
33
+    bool isRunning();
34
+    void start();
35
+
36
+    bool getFPS();
37
+    void setFPS(bool fps);
45 38
 
46 39
 private:
47 40
     std::string baseDir;
48 41
     std::string pakDir;
49 42
     std::string audioDir;
50 43
     std::string dataDir;
44
+
45
+    KeyboardButton keyBindings[ActionEventCount];
46
+    bool gameIsRunning;
47
+    bool showFPS;
51 48
 };
52 49
 
53
-OpenRaider &getOpenRaider();
50
+RunTime &getRunTime();
54 51
 
55 52
 #endif
56 53
 

+ 1
- 0
include/commands/Command.h View File

@@ -23,6 +23,7 @@ public:
23 23
 
24 24
     static void fillCommandList();
25 25
     static int command(std::string c);
26
+    static int executeFile(std::string file);
26 27
 
27 28
 private:
28 29
     static std::vector<std::shared_ptr<Command>> commands;

+ 2
- 0
include/global.h View File

@@ -15,6 +15,8 @@
15 15
 #define DEFAULT_WIDTH 640
16 16
 #define DEFAULT_HEIGHT 480
17 17
 
18
+void renderFrame();
19
+
18 20
 // Supported pixelmap color formats
19 21
 enum ColorMode {
20 22
     GREYSCALE,

+ 1
- 1
src/CMakeLists.txt View File

@@ -60,10 +60,10 @@ set (SRCS ${SRCS} "main.cpp")
60 60
 set (SRCS ${SRCS} "Menu.cpp")
61 61
 set (SRCS ${SRCS} "MenuFolder.cpp")
62 62
 set (SRCS ${SRCS} "Mesh.cpp")
63
-set (SRCS ${SRCS} "OpenRaider.cpp")
64 63
 set (SRCS ${SRCS} "Render.cpp")
65 64
 set (SRCS ${SRCS} "Room.cpp")
66 65
 set (SRCS ${SRCS} "RoomData.cpp")
66
+set (SRCS ${SRCS} "RunTime.cpp")
67 67
 set (SRCS ${SRCS} "Script.cpp")
68 68
 set (SRCS ${SRCS} "SkeletalModel.cpp")
69 69
 set (SRCS ${SRCS} "Sound.cpp")

+ 0
- 3
src/Game.cpp View File

@@ -15,7 +15,6 @@
15 15
 #include "Console.h"
16 16
 #include "Game.h"
17 17
 #include "loader/Loader.h"
18
-#include "OpenRaider.h"
19 18
 #include "Render.h"
20 19
 #include "Sound.h"
21 20
 #include "StaticMesh.h"
@@ -40,8 +39,6 @@ Game::Game() {
40 39
 }
41 40
 
42 41
 Game::~Game() {
43
-    destroy();
44
-
45 42
     UI::removeWindow(this);
46 43
 }
47 44
 

+ 2
- 2
src/MenuFolder.cpp View File

@@ -10,7 +10,7 @@
10 10
 #include "Font.h"
11 11
 #include "Game.h"
12 12
 #include "loader/Loader.h"
13
-#include "OpenRaider.h"
13
+#include "RunTime.h"
14 14
 #include "Window.h"
15 15
 #include "MenuFolder.h"
16 16
 
@@ -33,7 +33,7 @@ MenuFolder::~MenuFolder() {
33 33
 }
34 34
 
35 35
 int MenuFolder::initialize() {
36
-    return init(getOpenRaider().getPakDir());
36
+    return init(getRunTime().getPakDir());
37 37
 }
38 38
 
39 39
 int MenuFolder::init(std::string s) {

+ 0
- 200
src/OpenRaider.cpp View File

@@ -1,200 +0,0 @@
1
-/*!
2
- * \file src/OpenRaider.cpp
3
- * \brief Main Game Object
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include <fstream>
9
-#include <sstream>
10
-
11
-#include "global.h"
12
-#include "commands/Command.h"
13
-#include "Console.h"
14
-#include "Font.h"
15
-#include "Game.h"
16
-#include "Menu.h"
17
-#include "Render.h"
18
-#include "Sound.h"
19
-#include "TextureManager.h"
20
-#include "TombRaider.h"
21
-#include "utils/strings.h"
22
-#include "utils/time.h"
23
-#include "Window.h"
24
-#include "OpenRaider.h"
25
-
26
-OpenRaider::OpenRaider() {
27
-    mRunning = false;
28
-    mFPS = false;
29
-
30
-    for (int i = 0; i < ActionEventCount; i++)
31
-        keyBindings[i] = unknownKey;
32
-}
33
-
34
-std::string OpenRaider::getBaseDir() {
35
-    return baseDir;
36
-}
37
-
38
-void OpenRaider::setBaseDir(std::string dir) {
39
-    baseDir = dir;
40
-}
41
-
42
-std::string OpenRaider::getPakDir() {
43
-    return pakDir;
44
-}
45
-
46
-void OpenRaider::setPakDir(std::string dir) {
47
-    pakDir = dir;
48
-}
49
-
50
-std::string OpenRaider::getAudioDir() {
51
-    return audioDir;
52
-}
53
-
54
-void OpenRaider::setAudioDir(std::string dir) {
55
-    audioDir = dir;
56
-}
57
-
58
-std::string OpenRaider::getDataDir() {
59
-    return dataDir;
60
-}
61
-
62
-void OpenRaider::setDataDir(std::string dir) {
63
-    dataDir = dir;
64
-}
65
-
66
-int OpenRaider::loadConfig(std::string config) {
67
-    std::string configFile = expandHomeDirectory(config);
68
-    getConsole() << "Loading config from \"" << configFile << "\"..." << Console::endl;
69
-
70
-    std::ifstream file(configFile);
71
-    if (!file) {
72
-        getConsole() << "Could not open file!" << Console::endl;
73
-        return -1;
74
-    }
75
-
76
-    for (std::string line; std::getline(file, line);) {
77
-        if (line.length() == 0)
78
-            continue;
79
-
80
-        int error = Command::command(line);
81
-        if (error != 0)
82
-            getConsole() << "Error Code: " << error << Console::endl;
83
-    }
84
-
85
-    file.close();
86
-
87
-    return 0;
88
-}
89
-
90
-int OpenRaider::initialize() {
91
-    // Initialize Windowing
92
-    int error = getWindow().initialize();
93
-    if (error != 0) {
94
-        printf("Could not initialize Window (%d)!\n", error);
95
-        return -1;
96
-    }
97
-
98
-    // Initialize OpenGL
99
-    error = getWindow().initializeGL();
100
-    if (error != 0) {
101
-        printf("Could not initialize OpenGL (%d)!\n", error);
102
-        return -2;
103
-    }
104
-
105
-    // Initialize Font
106
-    error = getFont().initialize();
107
-    if (error != 0) {
108
-        printf("Could not initialize Font (%d)!\n", error);
109
-        return -3;
110
-    }
111
-
112
-    // Initialize Sound
113
-    error = getSound().initialize();
114
-    if (error != 0) {
115
-        printf("Could not initialize Sound (%d)!\n", error);
116
-        return -4;
117
-    }
118
-
119
-    // Initialize Texture Manager
120
-    error = getTextureManager().initialize();
121
-    if (error != 0) {
122
-        printf("Could not initialize Textures (%d)!\n", error);
123
-        return -5;
124
-    }
125
-
126
-    // Initialize UIs
127
-    error = UI::passInitialize();
128
-    if (error != 0) {
129
-        printf("Could not initialize UIs (%d)!\n", error);
130
-        return -6;
131
-    }
132
-
133
-#ifdef DEBUG
134
-    mFPS = true;
135
-#endif
136
-
137
-    getMenu().moveToTop();
138
-    systemTimerReset();
139
-
140
-    return 0;
141
-}
142
-
143
-void OpenRaider::run() {
144
-    assert(mRunning == false);
145
-    mRunning = true;
146
-    while (mRunning)
147
-        frame();
148
-}
149
-
150
-void OpenRaider::frame() {
151
-    assert(mRunning == true);
152
-
153
-    static clock_t fpsSum = 0, fpsCount = 0;
154
-    static int fps = 0;
155
-    clock_t startTime = systemTimerGet();
156
-
157
-    // Get keyboard and mouse input
158
-    getWindow().eventHandling();
159
-
160
-    ImGui::SetNewWindowDefaultPos(ImVec2(50, 50));
161
-    bool show_test_window = true;
162
-    ImGui::ShowTestWindow(&show_test_window);
163
-
164
-    UI::passDisplay();
165
-
166
-    getWindow().glEnter2D();
167
-
168
-    // Draw FPS counter
169
-    if (mFPS) {
170
-        std::ostringstream fpsText;
171
-        fpsText << fps << "FPS";
172
-        getFont().drawText(10, getWindow().getHeight() - 20, 0.5f, BLUE, fpsText.str());
173
-    }
174
-
175
-#ifdef DEBUG
176
-    // Draw debug infos
177
-    if (getGame().isLoaded() && (!getMenu().isOnTop())) {
178
-        for (int i = 0; i < 3; i++) {
179
-            std::ostringstream axis;
180
-            axis << getGame().getLara().getPos(i) / 256.0f << " (" << getGame().getLara().getAngle(i) << ")";
181
-            getFont().drawText(10, getWindow().getHeight() - ((4 - i) * 20), 0.5f, BLUE, axis.str());
182
-        }
183
-    }
184
-#endif
185
-
186
-    getWindow().glExit2D();
187
-
188
-    // Put new frame on screen
189
-    getWindow().swapBuffersGL();
190
-
191
-    // Calculate FPS display value
192
-    fpsCount++;
193
-    fpsSum += (systemTimerGet() - startTime);
194
-    if (fpsSum >= 250) {
195
-        // Update every 250ms
196
-        fps = (int)((float)fpsCount * (1000.0f / (float)fpsSum));
197
-        fpsCount = fpsSum = 0;
198
-    }
199
-}
200
-

+ 1
- 15
src/Render.cpp View File

@@ -16,7 +16,6 @@
16 16
 #include "global.h"
17 17
 #include "Camera.h"
18 18
 #include "Game.h"
19
-#include "OpenRaider.h"
20 19
 #include "Render.h"
21 20
 #include "TextureManager.h"
22 21
 #include "utils/strings.h"
@@ -32,7 +31,6 @@ Render::Render() {
32 31
     mFlags = (fRoomAlpha | fEntityModels | fRenderPonytail);
33 32
 }
34 33
 
35
-
36 34
 Render::~Render() {
37 35
     ClearWorld();
38 36
 }
@@ -41,7 +39,6 @@ void Render::ClearWorld() {
41 39
     mRoomRenderList.clear();
42 40
 }
43 41
 
44
-
45 42
 void Render::screenShot(const char *filenameBase)
46 43
 {
47 44
     int sz = getWindow().getWidth() * getWindow().getHeight();
@@ -73,7 +70,6 @@ unsigned int Render::getFlags() {
73 70
     return mFlags;
74 71
 }
75 72
 
76
-
77 73
 void Render::lightRoom(Room &room)
78 74
 {
79 75
     for (unsigned int i = 0; i < room.sizeLights(); ++i)
@@ -110,7 +106,6 @@ void Render::lightRoom(Room &room)
110 106
     }
111 107
 }
112 108
 
113
-
114 109
 void Render::clearFlags(unsigned int flags)
115 110
 {
116 111
     mFlags &= ~flags;
@@ -129,7 +124,6 @@ void Render::clearFlags(unsigned int flags)
129 124
     }
130 125
 }
131 126
 
132
-
133 127
 void Render::setFlags(unsigned int flags)
134 128
 {
135 129
     mFlags |= flags;
@@ -171,13 +165,11 @@ void Render::setFlags(unsigned int flags)
171 165
     }
172 166
 }
173 167
 
174
-
175 168
 int Render::getMode()
176 169
 {
177 170
     return mMode;
178 171
 }
179 172
 
180
-
181 173
 void Render::setMode(int n)
182 174
 {
183 175
     mMode = n;
@@ -208,7 +200,6 @@ void Render::setMode(int n)
208 200
     }
209 201
 }
210 202
 
211
-
212 203
 void Render::display()
213 204
 {
214 205
     switch (mMode)
@@ -427,7 +418,6 @@ void Render::newRoomRenderList(int index)
427 418
     currentRoomId = index;
428 419
 }
429 420
 
430
-
431 421
 void Render::buildRoomRenderList(Room &room)
432 422
 {
433 423
 
@@ -463,7 +453,6 @@ void Render::buildRoomRenderList(Room &room)
463 453
     }
464 454
 }
465 455
 
466
-
467 456
 void Render::drawSkyMesh(float scale)
468 457
 {
469 458
     //skeletal_model_t *model = getWorld().getModel(mSkyMesh);
@@ -484,14 +473,12 @@ void Render::drawSkyMesh(float scale)
484 473
     glEnable(GL_DEPTH_TEST);
485 474
 }
486 475
 
487
-
488 476
 void Render::setSkyMesh(int index, bool rot)
489 477
 {
490 478
     mSkyMesh = index;
491 479
     mSkyMeshRotation = rot;
492 480
 }
493 481
 
494
-
495 482
 void Render::updateViewVolume()
496 483
 {
497 484
     float proj[16], mdl[16];
@@ -512,7 +499,6 @@ bool Render::isVisible(BoundingBox &box) {
512 499
     return mViewVolume.isBboxInFrustum(bbox[0], bbox[1]);
513 500
 }
514 501
 
515
-
516 502
 bool Render::isVisible(float x, float y, float z)
517 503
 {
518 504
     // For debugging purposes
@@ -528,7 +514,6 @@ bool Render::isVisible(float x, float y, float z)
528 514
     return (mViewVolume.isPointInFrustum(x, y, z));
529 515
 }
530 516
 
531
-
532 517
 bool Render::isVisible(float x, float y, float z, float radius)
533 518
 {
534 519
     // For debugging purposes
@@ -543,3 +528,4 @@ bool Render::isVisible(float x, float y, float z, float radius)
543 528
 
544 529
     return (mViewVolume.isSphereInFrustum(x, y, z, radius));
545 530
 }
531
+

+ 89
- 0
src/RunTime.cpp View File

@@ -0,0 +1,89 @@
1
+/*!
2
+ * \file src/RunTime.cpp
3
+ * \brief run time configuration storage
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "global.h"
9
+#include "RunTime.h"
10
+
11
+RunTime::RunTime() {
12
+    gameIsRunning = false;
13
+
14
+#ifdef DEBUG
15
+    showFPS = true;
16
+#else
17
+    showFPS = false;
18
+#endif
19
+
20
+    for (int i = 0; i < ActionEventCount; i++)
21
+        keyBindings[i] = unknownKey;
22
+
23
+    // Default key bindings
24
+    keyBindings[menuAction] = escapeKey;
25
+    keyBindings[consoleAction] = backquoteKey;
26
+    keyBindings[forwardAction] = wKey;
27
+    keyBindings[backwardAction] = sKey;
28
+    keyBindings[leftAction] = aKey;
29
+    keyBindings[rightAction] = dKey;
30
+}
31
+
32
+std::string RunTime::getBaseDir() {
33
+    return baseDir;
34
+}
35
+
36
+void RunTime::setBaseDir(std::string dir) {
37
+    baseDir = dir;
38
+}
39
+
40
+std::string RunTime::getPakDir() {
41
+    return pakDir;
42
+}
43
+
44
+void RunTime::setPakDir(std::string dir) {
45
+    pakDir = dir;
46
+}
47
+
48
+std::string RunTime::getAudioDir() {
49
+    return audioDir;
50
+}
51
+
52
+void RunTime::setAudioDir(std::string dir) {
53
+    audioDir = dir;
54
+}
55
+
56
+std::string RunTime::getDataDir() {
57
+    return dataDir;
58
+}
59
+
60
+void RunTime::setDataDir(std::string dir) {
61
+    dataDir = dir;
62
+}
63
+
64
+KeyboardButton RunTime::getKeyBinding(ActionEvents event) {
65
+    assert(event < ActionEventCount);
66
+    return keyBindings[event];
67
+}
68
+
69
+void RunTime::setKeyBinding(ActionEvents event, KeyboardButton button) {
70
+    assert(event < ActionEventCount);
71
+    keyBindings[event] = button;
72
+}
73
+
74
+bool RunTime::isRunning() {
75
+    return gameIsRunning;
76
+}
77
+
78
+void RunTime::start() {
79
+    gameIsRunning = true;
80
+}
81
+
82
+bool RunTime::getFPS() {
83
+    return showFPS;
84
+}
85
+
86
+void RunTime::setFPS(bool fps) {
87
+    showFPS = fps;
88
+}
89
+

+ 3
- 3
src/TextureManager.cpp View File

@@ -13,7 +13,7 @@
13 13
 
14 14
 #include "global.h"
15 15
 #include "Console.h"
16
-#include "OpenRaider.h"
16
+#include "RunTime.h"
17 17
 #include "utils/pcx.h"
18 18
 #include "utils/pixel.h"
19 19
 #include "utils/strings.h"
@@ -46,11 +46,11 @@ int TextureManager::initialize() {
46 46
     delete [] image;
47 47
 
48 48
     //! \fixme Temporary
49
-    std::string filename(getOpenRaider().getPakDir());
49
+    std::string filename(getRunTime().getPakDir());
50 50
     filename += "/tr2/TITLE.PCX";
51 51
     if (loadPCX(filename.c_str()) < 0) {
52 52
         //! \fixme Error Checking. Return negative error code, check in calling place too
53
-        filename = getOpenRaider().getDataDir();
53
+        filename = getRunTime().getDataDir();
54 54
         filename += "/splash.tga";
55 55
         loadTGA(filename.c_str());
56 56
     }

+ 11
- 6
src/UI.cpp View File

@@ -11,7 +11,7 @@
11 11
 #include "Console.h"
12 12
 #include "Debug.h"
13 13
 #include "Menu.h"
14
-#include "OpenRaider.h"
14
+#include "RunTime.h"
15 15
 #include "TextureManager.h"
16 16
 #include "Window.h"
17 17
 
@@ -32,19 +32,19 @@ void UI::handleMouseScroll(int xrel, int yrel) { }
32 32
 
33 33
 void UI::passKeyboard(KeyboardButton key, bool pressed) {
34 34
     if (pressed) {
35
-        if (getOpenRaider().keyBindings[menuAction] == key) {
35
+        if (getRunTime().getKeyBinding(menuAction) == key) {
36 36
             if (getMenu().isOnTop()) {
37 37
                 getMenu().makeInvisible();
38 38
             } else {
39 39
                 getMenu().moveToTop();
40 40
             }
41
-        } else if (getOpenRaider().keyBindings[consoleAction] == key) {
41
+        } else if (getRunTime().getKeyBinding(consoleAction) == key) {
42 42
             if (getConsole().isOnTop()) {
43 43
                 getConsole().makeInvisible();
44 44
             } else {
45 45
                 getConsole().moveToTop();
46 46
             }
47
-        } else if (getOpenRaider().keyBindings[debugAction] == key) {
47
+        } else if (getRunTime().getKeyBinding(debugAction) == key) {
48 48
             if (getDebug().isOnTop()) {
49 49
                 getDebug().makeInvisible();
50 50
             } else {
@@ -57,7 +57,7 @@ void UI::passKeyboard(KeyboardButton key, bool pressed) {
57 57
     (*maxIterator)->handleKeyboard(key, pressed);
58 58
 
59 59
     for (int i = forwardAction; i < ActionEventCount; i++) {
60
-        if (getOpenRaider().keyBindings[i] == key) {
60
+        if (getRunTime().getKeyBinding((ActionEvents)i) == key) {
61 61
             (*maxIterator)->handleAction((ActionEvents)i, !pressed);
62 62
         }
63 63
     }
@@ -77,7 +77,7 @@ void UI::passMouseClick(unsigned int x, unsigned int y, KeyboardButton button, b
77 77
     (*maxIterator)->handleMouseClick(x, y, button, released);
78 78
 
79 79
     for (int i = forwardAction; i < ActionEventCount; i++) {
80
-        if (getOpenRaider().keyBindings[i] == button) {
80
+        if (getRunTime().getKeyBinding((ActionEvents)i) == button) {
81 81
             (*maxIterator)->handleAction((ActionEvents)i, released);
82 82
         }
83 83
     }
@@ -98,6 +98,11 @@ void UI::addWindow(UI* window) {
98 98
 }
99 99
 
100 100
 void UI::removeWindow(UI *window) {
101
+    if (windows.size() == 0) {
102
+        // It seems as if our list was destroyed before the UIs
103
+        return;
104
+    }
105
+
101 106
     findInList(window, [](unsigned long i){
102 107
         windows.erase(windows.begin() + i);
103 108
     });

+ 25
- 0
src/commands/Command.cpp View File

@@ -5,10 +5,12 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
+#include <fstream>
8 9
 #include <iomanip>
9 10
 
10 11
 #include "global.h"
11 12
 #include "Console.h"
13
+#include "utils/strings.h"
12 14
 #include "commands/Command.h"
13 15
 #include "commands/CommandAnimate.h"
14 16
 #include "commands/CommandBind.h"
@@ -109,3 +111,26 @@ int Command::command(std::string c) {
109 111
     return -1;
110 112
 }
111 113
 
114
+int Command::executeFile(std::string file) {
115
+    std::string configFile = expandHomeDirectory(file);
116
+    getConsole() << "Loading config from \"" << configFile << "\"..." << Console::endl;
117
+
118
+    std::ifstream f(configFile);
119
+    if (!f) {
120
+        getConsole() << "Could not open file!" << Console::endl;
121
+        return -1;
122
+    }
123
+
124
+    for (std::string line; std::getline(f, line);) {
125
+        if (line.length() == 0)
126
+            continue;
127
+
128
+        int error = Command::command(line);
129
+        if (error != 0)
130
+            getConsole() << "Error Code: " << error << Console::endl;
131
+    }
132
+
133
+    f.close();
134
+    return 0;
135
+}
136
+

+ 1
- 2
src/commands/CommandAnimate.cpp View File

@@ -8,7 +8,6 @@
8 8
 #include "global.h"
9 9
 #include "Console.h"
10 10
 #include "Game.h"
11
-#include "OpenRaider.h"
12 11
 #include "Render.h"
13 12
 #include "World.h"
14 13
 #include "commands/CommandAnimate.h"
@@ -31,7 +30,7 @@ void CommandAnimate::printHelp() {
31 30
 }
32 31
 
33 32
 int CommandAnimate::execute(std::istream& args) {
34
-    if ((!getOpenRaider().mRunning) || (!getGame().isLoaded())) {
33
+    if (!getGame().isLoaded()) {
35 34
         getConsole() << "Use animate command interactively!" << Console::endl;
36 35
         return -1;
37 36
     }

+ 2
- 2
src/commands/CommandBind.cpp View File

@@ -7,7 +7,7 @@
7 7
 
8 8
 #include "global.h"
9 9
 #include "Console.h"
10
-#include "OpenRaider.h"
10
+#include "RunTime.h"
11 11
 #include "commands/CommandBind.h"
12 12
 
13 13
 std::string CommandBind::name() {
@@ -57,7 +57,7 @@ int CommandBind::execute(std::istream& args) {
57 57
             return -3;
58 58
         }
59 59
 
60
-        getOpenRaider().keyBindings[e] = c;
60
+        getRunTime().setKeyBinding(e, c);
61 61
         return 0;
62 62
     }
63 63
 }

+ 6
- 6
src/commands/CommandEngine.cpp View File

@@ -9,7 +9,7 @@
9 9
 #include "Console.h"
10 10
 #include "Game.h"
11 11
 #include "Menu.h"
12
-#include "OpenRaider.h"
12
+#include "RunTime.h"
13 13
 #include "Render.h"
14 14
 #include "commands/CommandEngine.h"
15 15
 
@@ -27,7 +27,7 @@ void CommandLoad::printHelp() {
27 27
 }
28 28
 
29 29
 int CommandLoad::execute(std::istream& args) {
30
-    if (!getOpenRaider().mRunning) {
30
+    if (!getRunTime().isRunning()) {
31 31
         getConsole() << "Use load command interactively!" << Console::endl;
32 32
         return -1;
33 33
     }
@@ -55,12 +55,12 @@ void CommandScreenshot::printHelp() {
55 55
 }
56 56
 
57 57
 int CommandScreenshot::execute(std::istream& args) {
58
-    if (!getOpenRaider().mRunning) {
58
+    if (!getRunTime().isRunning()) {
59 59
         getConsole() << "Use sshot command interactively!" << Console::endl;
60 60
         return -1;
61 61
     }
62 62
 
63
-    std::string filename(getOpenRaider().getBaseDir());
63
+    std::string filename(getRunTime().getBaseDir());
64 64
     filename += "/sshots/";
65 65
     filename += VERSION_SHORT;
66 66
 
@@ -81,8 +81,8 @@ int CommandScreenshot::execute(std::istream& args) {
81 81
     else if (temp2 == "menu")
82 82
         getMenu().moveToTop();
83 83
 
84
-    getOpenRaider().frame();
85
-    getOpenRaider().frame(); // Double buffered
84
+    renderFrame();
85
+    renderFrame(); // Double buffered
86 86
     getRender().screenShot(filename.c_str());
87 87
 
88 88
     getMenu().makeInvisible();

+ 5
- 5
src/commands/CommandGame.cpp View File

@@ -8,7 +8,7 @@
8 8
 #include "global.h"
9 9
 #include "Console.h"
10 10
 #include "Game.h"
11
-#include "OpenRaider.h"
11
+#include "RunTime.h"
12 12
 #include "World.h"
13 13
 #include "commands/CommandGame.h"
14 14
 
@@ -21,7 +21,7 @@ std::string CommandPos::brief() {
21 21
 }
22 22
 
23 23
 int CommandPos::execute(std::istream& args) {
24
-    if ((!getOpenRaider().mRunning) || (!getGame().isLoaded())) {
24
+    if ((!getRunTime().isRunning()) || (!getGame().isLoaded())) {
25 25
         getConsole() << "Use pos command interactively!" << Console::endl;
26 26
         return -1;
27 27
     }
@@ -41,7 +41,7 @@ std::string CommandViewmodel::brief() {
41 41
 }
42 42
 
43 43
 int CommandViewmodel::execute(std::istream& args) {
44
-    if ((!getOpenRaider().mRunning) || (!getGame().isLoaded())) {
44
+    if ((!getRunTime().isRunning()) || (!getGame().isLoaded())) {
45 45
         getConsole() << "Use viewmodel command interactively!" << Console::endl;
46 46
         return -1;
47 47
     }
@@ -72,7 +72,7 @@ std::string CommandPigtail::brief() {
72 72
 }
73 73
 
74 74
 int CommandPigtail::execute(std::istream& args) {
75
-    if ((!getOpenRaider().mRunning) || (!getGame().isLoaded())) {
75
+    if ((!getRunTime().isRunning()) || (!getGame().isLoaded())) {
76 76
         getConsole() << "Use pigtail command interactively!" << Console::endl;
77 77
         return -1;
78 78
     }
@@ -100,7 +100,7 @@ std::string CommandPonypos::brief() {
100 100
 }
101 101
 
102 102
 int CommandPonypos::execute(std::istream& args) {
103
-    if ((!getOpenRaider().mRunning) || (!getGame().isLoaded())) {
103
+    if ((!getRunTime().isRunning()) || (!getGame().isLoaded())) {
104 104
         getConsole() << "Use ponypos command interactively!" << Console::endl;
105 105
         return -1;
106 106
     }

+ 2
- 2
src/commands/CommandMove.cpp View File

@@ -8,7 +8,7 @@
8 8
 #include "global.h"
9 9
 #include "Console.h"
10 10
 #include "Game.h"
11
-#include "OpenRaider.h"
11
+#include "RunTime.h"
12 12
 #include "commands/CommandMove.h"
13 13
 
14 14
 std::string CommandMove::name() {
@@ -29,7 +29,7 @@ void CommandMove::printHelp() {
29 29
 }
30 30
 
31 31
 int CommandMove::execute(std::istream& args) {
32
-    if ((!getOpenRaider().mRunning) || (!getGame().isLoaded())) {
32
+    if ((!getRunTime().isRunning()) || (!getGame().isLoaded())) {
33 33
         getConsole() << "Use move command interactively!" << Console::endl;
34 34
         return -1;
35 35
     }

+ 2
- 2
src/commands/CommandRender.cpp View File

@@ -8,7 +8,7 @@
8 8
 #include "global.h"
9 9
 #include "Console.h"
10 10
 #include "Game.h"
11
-#include "OpenRaider.h"
11
+#include "RunTime.h"
12 12
 #include "Render.h"
13 13
 #include "commands/CommandRender.h"
14 14
 
@@ -86,7 +86,7 @@ void CommandRenderflag::printHelp() {
86 86
 }
87 87
 
88 88
 int CommandRenderflag::execute(std::istream& args) {
89
-    if (!getOpenRaider().mRunning) {
89
+    if (!getRunTime().isRunning()) {
90 90
         getConsole() << "Use renderflag-Command interactively!" << Console::endl;
91 91
         return -1;
92 92
     }

+ 10
- 10
src/commands/CommandSet.cpp View File

@@ -9,7 +9,7 @@
9 9
 #include "Camera.h"
10 10
 #include "Console.h"
11 11
 #include "Font.h"
12
-#include "OpenRaider.h"
12
+#include "RunTime.h"
13 13
 #include "Sound.h"
14 14
 #include "Window.h"
15 15
 #include "utils/strings.h"
@@ -53,10 +53,10 @@ namespace {
53 53
         }
54 54
 
55 55
         // Expand Names
56
-        s = findAndReplace(s, "$(pakdir)", getOpenRaider().getPakDir());
57
-        s = findAndReplace(s, "$(audiodir)", getOpenRaider().getAudioDir());
58
-        s = findAndReplace(s, "$(datadir)", getOpenRaider().getDataDir());
59
-        s = findAndReplace(s, "$(basedir)", getOpenRaider().getBaseDir());
56
+        s = findAndReplace(s, "$(pakdir)", getRunTime().getPakDir());
57
+        s = findAndReplace(s, "$(audiodir)", getRunTime().getAudioDir());
58
+        s = findAndReplace(s, "$(datadir)", getRunTime().getDataDir());
59
+        s = findAndReplace(s, "$(basedir)", getRunTime().getBaseDir());
60 60
 
61 61
         // Full path
62 62
         s = expandHomeDirectory(s);
@@ -117,23 +117,23 @@ int CommandSet::execute(std::istream& args) {
117 117
             getConsole() << "set-fps-Error: Invalid value" << Console::endl;
118 118
             return -8;
119 119
         }
120
-        getOpenRaider().mFPS = fps;
120
+        getRunTime().setFPS(fps);
121 121
     } else if (var.compare("basedir") == 0) {
122 122
         std::string temp;
123 123
         args >> temp;
124
-        getOpenRaider().setBaseDir(expandNames(temp));
124
+        getRunTime().setBaseDir(expandNames(temp));
125 125
     } else if (var.compare("pakdir") == 0) {
126 126
         std::string temp;
127 127
         args >> temp;
128
-        getOpenRaider().setPakDir(expandNames(temp));
128
+        getRunTime().setPakDir(expandNames(temp));
129 129
     } else if (var.compare("audiodir") == 0) {
130 130
         std::string temp;
131 131
         args >> temp;
132
-        getOpenRaider().setAudioDir(expandNames(temp));
132
+        getRunTime().setAudioDir(expandNames(temp));
133 133
     } else if (var.compare("datadir") == 0) {
134 134
         std::string temp;
135 135
         args >> temp;
136
-        getOpenRaider().setDataDir(expandNames(temp));
136
+        getRunTime().setDataDir(expandNames(temp));
137 137
     } else if (var.compare("font") == 0) {
138 138
         std::string temp;
139 139
         args >> temp;

+ 2
- 2
src/commands/CommandSound.cpp View File

@@ -8,7 +8,7 @@
8 8
 #include "global.h"
9 9
 #include "Console.h"
10 10
 #include "Game.h"
11
-#include "OpenRaider.h"
11
+#include "RunTime.h"
12 12
 #include "Sound.h"
13 13
 #include "commands/CommandSound.h"
14 14
 
@@ -28,7 +28,7 @@ void CommandSound::printHelp() {
28 28
 }
29 29
 
30 30
 int CommandSound::execute(std::istream& args) {
31
-    if ((!getOpenRaider().mRunning) || (!getGame().isLoaded())) {
31
+    if (!getGame().isLoaded()) {
32 32
         getConsole() << "Use sound command interactively!" << Console::endl;
33 33
         return -1;
34 34
     }

+ 126
- 90
src/main.cpp View File

@@ -6,13 +6,16 @@
6 6
  */
7 7
 
8 8
 #include <iostream>
9
+#include <memory>
9 10
 
10 11
 #include "global.h"
11 12
 #include "Console.h"
12 13
 #include "Exception.h"
13
-#include "OpenRaider.h"
14 14
 #include "commander/commander.h"
15 15
 #include "commands/Command.h"
16
+#include "utils/time.h"
17
+
18
+#ifndef UNIT_TEST
16 19
 
17 20
 #include "Camera.h"
18 21
 #include "Debug.h"
@@ -20,7 +23,10 @@
20 23
 #include "Game.h"
21 24
 #include "MenuFolder.h"
22 25
 #include "Render.h"
26
+#include "RunTime.h"
23 27
 #include "TextureManager.h"
28
+#include "UI.h"
29
+#include "Window.h"
24 30
 #include "World.h"
25 31
 
26 32
 #ifdef USING_AL
@@ -35,78 +41,30 @@
35 41
 #error No Windowing Library selected!
36 42
 #endif
37 43
 
38
-#ifndef UNIT_TEST
39
-
40
-namespace {
41
-    Camera* gCamera;
42
-    Console* gConsole;
43
-    Debug* gDebug;
44
-    FontManager* gFont;
45
-    Game* gGame;
46
-    MenuFolder* gMenu;
47
-    OpenRaider* gOpenRaider;
48
-    Render* gRender;
49
-    Sound* gSound;
50
-    TextureManager* gTextureManager;
51
-    Window* gWindow;
52
-    World* gWorld;
53
-
54
-    void createGlobals() {
55
-        gOpenRaider = new OpenRaider();
56
-        gCamera = new Camera();
57
-        gConsole = new Console();
58
-        gDebug = new Debug();
59
-        gFont = new FontManager();
60
-        gGame = new Game();
61
-        gMenu = new MenuFolder();
62
-        gRender = new Render();
63
-        gTextureManager = new TextureManager();
64
-        gWorld = new World();
65
-
66
-#ifdef USING_AL
67
-        gSound = new SoundAL();
68
-#else
69
-        gSound = new SoundNull();
70
-#endif
71
-
72
-#ifdef USING_SDL
73
-        gWindow = new WindowSDL();
74
-#endif
75
-    }
76
-
77
-    void deleteGlobals() {
78
-        delete gCamera;
79
-        delete gConsole;
80
-        delete gFont;
81
-        delete gGame;
82
-        delete gMenu;
83
-        delete gOpenRaider;
84
-        delete gRender;
85
-        delete gSound;
86
-        delete gTextureManager;
87
-        delete gWindow;
88
-        delete gWorld;
89
-    }
90
-
91
-    bool configFileWasSpecified = false;
92
-
93
-    void configFileCallback(command_t *self) {
94
-        getOpenRaider().loadConfig(self->arg);
95
-        configFileWasSpecified = true;
96
-    }
97
-
98
-    void cleanupHandler(void) {
44
+static std::string configFileToUse;
45
+
46
+static std::shared_ptr<Camera> gCamera;
47
+static std::shared_ptr<Console> gConsole;
48
+static std::shared_ptr<Debug> gDebug;
49
+static std::shared_ptr<FontManager> gFont;
50
+static std::shared_ptr<Game> gGame;
51
+static std::shared_ptr<MenuFolder> gMenu;
52
+static std::shared_ptr<Render> gRender;
53
+static std::shared_ptr<RunTime> gRunTime;
54
+static std::shared_ptr<Sound> gSound;
55
+static std::shared_ptr<TextureManager> gTextureManager;
56
+static std::shared_ptr<Window> gWindow;
57
+static std::shared_ptr<World> gWorld;
58
+
59
+static void cleanupHandler(void) {
99 60
 #ifdef DEBUG
100
-        std::cout << std::endl;
101
-        std::cout << "Thanks for testing " << VERSION << std::endl;
102
-        std::cout << "Build date: " << __DATE__ << " @ " << __TIME__ << std::endl;
103
-        std::cout << "Build host: " << BUILD_HOST << std::endl;
104
-        std::cout << "Web site  : http://github.com/xythobuz/OpenRaider" << std::endl;
105
-        std::cout << "Contact   : xythobuz@xythobuz.de" << std::endl;
61
+    std::cout << std::endl;
62
+    std::cout << "Thanks for testing " << VERSION << std::endl;
63
+    std::cout << "Build date: " << __DATE__ << " @ " << __TIME__ << std::endl;
64
+    std::cout << "Build host: " << BUILD_HOST << std::endl;
65
+    std::cout << "Web site  : http://github.com/xythobuz/OpenRaider" << std::endl;
66
+    std::cout << "Contact   : xythobuz@xythobuz.de" << std::endl;
106 67
 #endif
107
-
108
-        deleteGlobals();
109
-    }
110 68
 }
111 69
 
112 70
 Camera &getCamera() {
@@ -133,14 +91,14 @@ Menu &getMenu() {
133 91
     return *gMenu;
134 92
 }
135 93
 
136
-OpenRaider &getOpenRaider() {
137
-    return *gOpenRaider;
138
-}
139
-
140 94
 Render &getRender() {
141 95
     return *gRender;
142 96
 }
143 97
 
98
+RunTime &getRunTime() {
99
+    return *gRunTime;
100
+}
101
+
144 102
 Sound &getSound() {
145 103
     return *gSound;
146 104
 }
@@ -158,40 +116,118 @@ World &getWorld() {
158 116
 }
159 117
 
160 118
 int main(int argc, char* argv[]) {
161
-    createGlobals();
162
-    atexit(cleanupHandler);
163
-    Command::fillCommandList();
164
-
165 119
     command_t cmd;
166 120
     command_init(&cmd, argv[0], VERSION);
167
-    //command_option(&cmd, "-v", "--verbose", "enable verbose output", functionPointer);
168
-    command_option(&cmd, "-c", "--config <file>", "select config file to use", configFileCallback);
121
+    command_option(&cmd, "-c", "--config <file>", "select config file to use",
122
+            [](command_t *self) {
123
+        configFileToUse = self->arg;
124
+    });
169 125
     command_parse(&cmd, argc, argv);
126
+    command_free(&cmd);
127
+
128
+    gCamera.reset(new Camera());
129
+    gConsole.reset(new Console());
130
+    gDebug.reset(new Debug());
131
+    gFont.reset(new FontManager());
132
+    gGame.reset(new Game());
133
+    gMenu.reset(new MenuFolder());
134
+    gRender.reset(new Render());
135
+    gRunTime.reset(new RunTime());
136
+    gTextureManager.reset(new TextureManager());
137
+    gWorld.reset(new World());
170 138
 
171
-    if (!configFileWasSpecified) {
172
-        if (getOpenRaider().loadConfig(DEFAULT_CONFIG_FILE) != 0) {
173
-            getOpenRaider().loadConfig(DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE);
139
+#ifdef USING_AL
140
+    gSound.reset(new SoundAL());
141
+#else
142
+    gSound.reset(new SoundNull());
143
+#endif
144
+
145
+#ifdef USING_SDL
146
+    gWindow.reset(new WindowSDL());
147
+#endif
148
+
149
+    atexit(cleanupHandler);
150
+    Command::fillCommandList();
151
+
152
+    if (configFileToUse == "") {
153
+        if (Command::executeFile(DEFAULT_CONFIG_FILE) != 0) {
154
+            Command::executeFile(DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE);
174 155
         }
156
+    } else {
157
+        Command::executeFile(configFileToUse);
175 158
     }
176 159
 
177
-#ifdef DEBUG
178 160
     getConsole() << "Initializing " << VERSION << Console::endl;
179
-#endif
180 161
 
181
-    int error = getOpenRaider().initialize();
162
+    // Initialize Windowing
163
+    int error = getWindow().initialize();
182 164
     if (error != 0) {
183
-        std::cout << "Could not initialize OpenRaider (" << error << ")!" << std::endl;
165
+        std::cout << "Could not initialize Window (" << error << ")!" << std::endl;
184 166
         return -1;
185 167
     }
186 168
 
187
-    command_free(&cmd);
169
+    // Initialize OpenGL
170
+    error = getWindow().initializeGL();
171
+    if (error != 0) {
172
+        std::cout << "Could not initialize OpenGL (" << error << ")!" << std::endl;
173
+        return -2;
174
+    }
175
+
176
+    // Initialize Font
177
+    error = getFont().initialize();
178
+    if (error != 0) {
179
+        std::cout << "Could not initialize Font (" << error << ")!" << std::endl;
180
+        return -3;
181
+    }
182
+
183
+    // Initialize Sound
184
+    error = getSound().initialize();
185
+    if (error != 0) {
186
+        std::cout << "Could not initialize Sound (" << error << ")!" << std::endl;
187
+        return -4;
188
+    }
189
+
190
+    // Initialize Texture Manager
191
+    error = getTextureManager().initialize();
192
+    if (error != 0) {
193
+        std::cout << "Could not initialize TextureManager (" << error << ")!" << std::endl;
194
+        return -5;
195
+    }
196
+
197
+    // Initialize UIs
198
+    error = UI::passInitialize();
199
+    if (error != 0) {
200
+        std::cout << "Could not initialize UIs (" << error << ")!" << std::endl;
201
+        return -6;
202
+    }
188 203
 
189 204
     getConsole() << "Starting " << VERSION << Console::endl;
190
-    getOpenRaider().run();
205
+    getMenu().moveToTop();
206
+    systemTimerReset();
207
+    getRunTime().start();
208
+
209
+    while (getRunTime().isRunning()) {
210
+        renderFrame();
211
+    }
191 212
 
192 213
     return 0;
193 214
 }
194 215
 
216
+void renderFrame() {
217
+    // Get keyboard and mouse input
218
+    getWindow().eventHandling();
219
+
220
+    ImGui::SetNewWindowDefaultPos(ImVec2(50, 50));
221
+    bool show_test_window = false;
222
+    ImGui::ShowTestWindow(&show_test_window);
223
+
224
+    // Render everything
225
+    UI::passDisplay();
226
+
227
+    // Put new frame on screen
228
+    getWindow().swapBuffersGL();
229
+}
230
+
195 231
 #endif // UNIT_TEST
196 232
 
197 233
 #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)

Loading…
Cancel
Save