Parcourir la source

RunTime now static. StaticMesh displays bounding boxes.

Thomas Buck il y a 10 ans
Parent
révision
b2436b7de4

+ 4
- 2
ChangeLog.md Voir le fichier

@@ -3,10 +3,12 @@
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5 5
     [ 20141228 ]
6
-    * Room Bounding Boxes are now visualized in Wireframe mode (again)
7
-    * Window/WindowSDL/WindowGLFW are now completely static
6
+    * Room Bounding Boxes are now visualized in Wireframe mode (again).
7
+    * Window/WindowSDL/WindowGLFW are now completely static.
8 8
     * Shader class got some helper methods. Now in own file, system/Shader.
9 9
     * Tried to limit camera vertical rotation.
10
+    * RunTime is now completely static.
11
+    * StaticMeshes store both (?) of their bounding boxes. Displayed in Wireframe mode.
10 12
 
11 13
     [ 20141227 ]
12 14
     * Added rudimentary SDL2 Game Controller support.

+ 1
- 1
include/RoomData.h Voir le fichier

@@ -40,7 +40,7 @@ class BoundingBox {
40 40
         return corner[i];
41 41
     }
42 42
 
43
-    void display(glm::mat4 VP);
43
+    void display(glm::mat4 VP, glm::vec3 colorLine, glm::vec3 colorDot);
44 44
 
45 45
   private:
46 46
     glm::vec3 corner[8];

+ 35
- 38
include/RunTime.h Voir le fichier

@@ -11,56 +11,53 @@
11 11
 #include <string>
12 12
 #include <vector>
13 13
 
14
-/*!
15
- * \brief Main Game Singleton
16
- */
17 14
 class RunTime {
18 15
   public:
16
+    static void initialize();
17
+    static void updateFPS();
18
+    static void display();
19 19
 
20
-    RunTime();
20
+    static KeyboardButton getKeyBinding(ActionEvents event);
21
+    static void setKeyBinding(ActionEvents event, KeyboardButton button);
21 22
 
22
-    std::string getBaseDir();
23
-    void setBaseDir(std::string dir);
24
-    std::string getPakDir();
25
-    void setPakDir(std::string dir);
26
-    std::string getAudioDir();
27
-    void setAudioDir(std::string dir);
28
-    std::string getDataDir();
29
-    void setDataDir(std::string dir);
23
+    static std::string getBaseDir() { return baseDir; }
24
+    static void setBaseDir(std::string dir) { baseDir = dir; }
30 25
 
31
-    KeyboardButton getKeyBinding(ActionEvents event);
32
-    void setKeyBinding(ActionEvents event, KeyboardButton button);
26
+    static std::string getPakDir() { return pakDir; }
27
+    static void setPakDir(std::string dir) { pakDir = dir; }
33 28
 
34
-    bool isRunning();
35
-    void setRunning(bool run);
29
+    static std::string getAudioDir() { return audioDir; }
30
+    static void setAudioDir(std::string dir) { audioDir = dir; }
36 31
 
37
-    bool getShowFPS();
38
-    void setShowFPS(bool fps);
32
+    static std::string getDataDir() { return dataDir; }
33
+    static void setDataDir(std::string dir) { dataDir = dir; }
39 34
 
40
-    void updateFPS();
41
-    unsigned long getFPS();
42
-    const std::vector<float>& getHistoryFPS();
35
+    static bool isRunning() { return gameIsRunning; }
36
+    static void setRunning(bool run) { gameIsRunning = run; }
43 37
 
44
-    float getLastFrameTime();
38
+    static bool getShowFPS() { return showFPS; }
39
+    static void setShowFPS(bool fps) { showFPS = fps; }
40
+
41
+    static unsigned long getFPS() { return fps; }
42
+    static const std::vector<float>& getHistoryFPS() { return history; }
43
+    static float getLastFrameTime() { return lastFrameTime / 1000.0f; }
45 44
 
46 45
   private:
47
-    std::string baseDir;
48
-    std::string pakDir;
49
-    std::string audioDir;
50
-    std::string dataDir;
51
-
52
-    KeyboardButton keyBindings[ActionEventCount];
53
-    bool gameIsRunning;
54
-    bool showFPS;
55
-
56
-    unsigned long lastTime, lastFrameTime;
57
-    unsigned long frameCount, frameCount2;
58
-    unsigned long frameTimeSum, frameTimeSum2;
59
-    unsigned long fps;
60
-    std::vector<float> history;
46
+    static std::string baseDir;
47
+    static std::string pakDir;
48
+    static std::string audioDir;
49
+    static std::string dataDir;
50
+
51
+    static KeyboardButton keyBindings[ActionEventCount];
52
+    static bool gameIsRunning;
53
+    static bool showFPS;
54
+
55
+    static unsigned long lastTime, lastFrameTime;
56
+    static unsigned long frameCount, frameCount2;
57
+    static unsigned long frameTimeSum, frameTimeSum2;
58
+    static unsigned long fps;
59
+    static std::vector<float> history;
61 60
 };
62 61
 
63
-RunTime& getRunTime();
64
-
65 62
 #endif
66 63
 

+ 2
- 0
include/SoundManager.h Voir le fichier

@@ -42,6 +42,8 @@ class SoundManager {
42 42
     // index --> SoundMap --> SoundDetails --> SampleIndices --> play
43 43
     static int playSound(int index);
44 44
 
45
+    static void display();
46
+
45 47
   private:
46 48
     static std::vector<SoundSource> soundSources;
47 49
     static std::vector<int> soundMap;

+ 7
- 1
include/StaticMesh.h Voir le fichier

@@ -8,9 +8,14 @@
8 8
 #ifndef _STATIC_MODEL_H_
9 9
 #define _STATIC_MODEL_H_
10 10
 
11
+#include <memory>
12
+
13
+#include "RoomData.h"
14
+
11 15
 class StaticMesh {
12 16
   public:
13
-    StaticMesh(int i, int m) : id(i), mesh(m) { }
17
+    StaticMesh(int i, int m, BoundingBox* b1, BoundingBox* b2)
18
+        : id(i), mesh(m), bbox1(b1), bbox2(b2) { }
14 19
     void display(glm::mat4 model, glm::mat4 view, glm::mat4 projection);
15 20
 
16 21
     int getID() { return id; }
@@ -18,6 +23,7 @@ class StaticMesh {
18 23
   private:
19 24
     int id;
20 25
     int mesh;
26
+    std::unique_ptr<BoundingBox> bbox1, bbox2;
21 27
 };
22 28
 
23 29
 #endif

+ 1
- 1
src/Camera.cpp Voir le fichier

@@ -161,7 +161,7 @@ bool Camera::update() {
161 161
     if ((!dirty) && equal(posSpeed, 0.0f) && equal(rotSpeed, 0.0f))
162 162
         return false;
163 163
 
164
-    float dT = getRunTime().getLastFrameTime();
164
+    float dT = RunTime::getLastFrameTime();
165 165
     pos += quaternion * posSpeed * dT;
166 166
 
167 167
     if (glm::epsilonNotEqual(rotSpeed.x, 0.0f, controllerDeadZone))

+ 2
- 2
src/Game.cpp Voir le fichier

@@ -50,9 +50,9 @@ int Game::initialize() {
50 50
 void Game::display() {
51 51
     Render::display();
52 52
 
53
-    if (getRunTime().getShowFPS()) {
53
+    if (RunTime::getShowFPS()) {
54 54
         std::ostringstream s;
55
-        s << getRunTime().getFPS() << "FPS";
55
+        s << RunTime::getFPS() << "FPS";
56 56
         Font::drawText(10, Window::getSize().y - 25, 0.6f, BLUE, s.str());
57 57
 
58 58
         s.str("");

+ 1
- 1
src/MenuFolder.cpp Voir le fichier

@@ -30,7 +30,7 @@ MenuFolder::~MenuFolder() {
30 30
 }
31 31
 
32 32
 int MenuFolder::initialize() {
33
-    return init(getRunTime().getPakDir());
33
+    return init(RunTime::getPakDir());
34 34
 }
35 35
 
36 36
 int MenuFolder::init(std::string s) {

+ 1
- 1
src/Room.cpp Voir le fichier

@@ -25,7 +25,7 @@ void Room::display(glm::mat4 view, glm::mat4 projection) {
25 25
     }
26 26
 
27 27
     if (Render::getMode() == RenderMode::Wireframe)
28
-        bbox->display(projection * view);
28
+        bbox->display(projection * view, glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(1.0f, 0.0f, 1.0f));
29 29
 }
30 30
 
31 31
 bool Room::isWall(unsigned long sector) {

+ 6
- 5
src/RoomData.cpp Voir le fichier

@@ -13,14 +13,14 @@
13 13
 #include "system/Window.h"
14 14
 #include "RoomData.h"
15 15
 
16
-void BoundingBox::display(glm::mat4 VP) {
16
+void BoundingBox::display(glm::mat4 VP, glm::vec3 colorLine, glm::vec3 colorDot) {
17 17
     std::vector<glm::vec3> verts;
18 18
     std::vector<glm::vec3> cols;
19 19
     std::vector<unsigned short> inds;
20 20
 
21 21
     for (int i = 0; i < 8; i++) {
22 22
         verts.push_back(corner[i]);
23
-        cols.push_back(glm::vec3(0.0f, 1.0f, 0.0f));
23
+        cols.push_back(colorLine);
24 24
     }
25 25
 
26 26
     inds.push_back(0);
@@ -46,7 +46,7 @@ void BoundingBox::display(glm::mat4 VP) {
46 46
     inds.clear();
47 47
 
48 48
     for (int i = 0; i < 8; i++) {
49
-        cols.push_back(glm::vec3(1.0f, 0.0f, 0.0f));
49
+        cols.push_back(colorDot);
50 50
         inds.push_back(i);
51 51
     }
52 52
 
@@ -65,8 +65,9 @@ void StaticModel::display(glm::mat4 view, glm::mat4 projection) {
65 65
         assert(cache >= 0);
66 66
     }
67 67
 
68
-    glm::mat4 model = glm::rotate(glm::translate(glm::mat4(1.0f), pos),
69
-                                  angle, glm::vec3(0.0f, 1.0f, 0.0f));
68
+    glm::mat4 translate = glm::translate(glm::mat4(1.0f), pos);
69
+    glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(0.0f, 1.0f, 0.0f));
70
+    glm::mat4 model = translate * rotate;
70 71
     getWorld().getStaticMesh(cache).display(model, view, projection);
71 72
 }
72 73
 

+ 150
- 70
src/RunTime.cpp Voir le fichier

@@ -6,22 +6,39 @@
6 6
  */
7 7
 
8 8
 #include "global.h"
9
+#include "Camera.h"
10
+#include "Render.h"
11
+#include "UI.h"
12
+#include "system/Sound.h"
13
+#include "system/Window.h"
9 14
 #include "utils/strings.h"
10 15
 #include "utils/time.h"
11 16
 #include "RunTime.h"
12 17
 
13
-RunTime::RunTime()
14
-    : baseDir(expandHomeDirectory("~/.OpenRaider")) {
18
+std::string RunTime::baseDir;
19
+std::string RunTime::pakDir;
20
+std::string RunTime::audioDir;
21
+std::string RunTime::dataDir;
22
+KeyboardButton RunTime::keyBindings[ActionEventCount];
23
+bool RunTime::gameIsRunning = false;
24
+bool RunTime::showFPS = false;
25
+unsigned long RunTime::lastTime = 0;
26
+unsigned long RunTime::lastFrameTime = 0;
27
+unsigned long RunTime::frameCount = 0;
28
+unsigned long RunTime::frameCount2 = 0;
29
+unsigned long RunTime::frameTimeSum = 0;
30
+unsigned long RunTime::frameTimeSum2 = 0;
31
+unsigned long RunTime::fps = 0;
32
+std::vector<float> RunTime::history;
33
+
34
+void RunTime::initialize() {
35
+    baseDir = expandHomeDirectory("~/.OpenRaider");
15 36
     pakDir = baseDir + "/paks";
16 37
     audioDir = baseDir + "/music";
17 38
     dataDir = baseDir + "/data";
18 39
 
19
-    gameIsRunning = false;
20
-
21 40
 #ifdef DEBUG
22 41
     showFPS = true;
23
-#else
24
-    showFPS = false;
25 42
 #endif
26 43
 
27 44
     for (int i = 0; i < ActionEventCount; i++)
@@ -34,45 +51,6 @@ RunTime::RunTime()
34 51
     keyBindings[backwardAction] = sKey;
35 52
     keyBindings[leftAction] = aKey;
36 53
     keyBindings[rightAction] = dKey;
37
-
38
-    lastTime = 0;
39
-    frameCount = 0;
40
-    frameCount2 = 0;
41
-    frameTimeSum = 0;
42
-    frameTimeSum2 = 0;
43
-    fps = 0;
44
-}
45
-
46
-std::string RunTime::getBaseDir() {
47
-    return baseDir;
48
-}
49
-
50
-void RunTime::setBaseDir(std::string dir) {
51
-    baseDir = dir;
52
-}
53
-
54
-std::string RunTime::getPakDir() {
55
-    return pakDir;
56
-}
57
-
58
-void RunTime::setPakDir(std::string dir) {
59
-    pakDir = dir;
60
-}
61
-
62
-std::string RunTime::getAudioDir() {
63
-    return audioDir;
64
-}
65
-
66
-void RunTime::setAudioDir(std::string dir) {
67
-    audioDir = dir;
68
-}
69
-
70
-std::string RunTime::getDataDir() {
71
-    return dataDir;
72
-}
73
-
74
-void RunTime::setDataDir(std::string dir) {
75
-    dataDir = dir;
76 54
 }
77 55
 
78 56
 KeyboardButton RunTime::getKeyBinding(ActionEvents event) {
@@ -85,22 +63,6 @@ void RunTime::setKeyBinding(ActionEvents event, KeyboardButton button) {
85 63
     keyBindings[event] = button;
86 64
 }
87 65
 
88
-bool RunTime::isRunning() {
89
-    return gameIsRunning;
90
-}
91
-
92
-void RunTime::setRunning(bool run) {
93
-    gameIsRunning = run;
94
-}
95
-
96
-bool RunTime::getShowFPS() {
97
-    return showFPS;
98
-}
99
-
100
-void RunTime::setShowFPS(bool fps) {
101
-    showFPS = fps;
102
-}
103
-
104 66
 void RunTime::updateFPS() {
105 67
     frameCount++;
106 68
     lastFrameTime = systemTimerGet() - lastTime;
@@ -119,15 +81,133 @@ void RunTime::updateFPS() {
119 81
     frameCount2++;
120 82
 }
121 83
 
122
-unsigned long RunTime::getFPS() {
123
-    return fps;
124
-}
125
-
126
-const std::vector<float>& RunTime::getHistoryFPS() {
127
-    return history;
128
-}
84
+void RunTime::display() {
85
+    if (ImGui::CollapsingHeader("RunTime Settings")) {
86
+        bool showFPS = getShowFPS();
87
+        if (ImGui::Checkbox("Show FPS##runtime", &showFPS)) {
88
+            setShowFPS(showFPS);
89
+        }
90
+        ImGui::SameLine();
91
+        bool running = isRunning();
92
+        if (ImGui::Checkbox("Running (!)##runtime", &running)) {
93
+            setRunning(running);
94
+        }
95
+        ImGui::SameLine();
96
+        bool sound = Sound::getEnabled();
97
+        if (ImGui::Checkbox("Sound##runtime", &sound)) {
98
+            Sound::setEnabled(sound);
99
+        }
100
+        ImGui::SameLine();
101
+        bool fullscreen = Window::getFullscreen();
102
+        if (ImGui::Checkbox("Fullscreen##runtime", &fullscreen)) {
103
+            Window::setFullscreen(fullscreen);
104
+        }
105
+
106
+        bool updateViewFrustum = Camera::getUpdateViewFrustum();
107
+        if (ImGui::Checkbox("Update Frustum##runtime", &updateViewFrustum)) {
108
+            Camera::setUpdateViewFrustum(updateViewFrustum);
109
+        }
110
+        ImGui::SameLine();
111
+        bool displayViewFrustum = Render::getDisplayViewFrustum();
112
+        if (ImGui::Checkbox("Show Frustum##runtime", &displayViewFrustum)) {
113
+            Render::setDisplayViewFrustum(displayViewFrustum);
114
+        }
115
+
116
+        float vol = Sound::getVolume();
117
+        if (ImGui::InputFloat("Volume##runtime", &vol, 0.0f, 0.0f, 3,
118
+                              ImGuiInputTextFlags_EnterReturnsTrue)) {
119
+            if (vol < 0.0f)
120
+                vol = 0.0f;
121
+            if (vol > 1.0f)
122
+                vol = 1.0f;
123
+            Sound::setVolume(vol);
124
+        }
125
+
126
+        int w = Window::getSize().x;
127
+        if (ImGui::InputInt("Width##runtime", &w, 10, 100, ImGuiInputTextFlags_EnterReturnsTrue)) {
128
+            if (w < 1)
129
+                w = 1;
130
+            Window::setSize(glm::vec2(w, Window::getSize().y));
131
+        }
132
+        int h = Window::getSize().y;
133
+        if (ImGui::InputInt("Height##runtime", &h, 10, 100, ImGuiInputTextFlags_EnterReturnsTrue)) {
134
+            if (h < 1)
135
+                h = 1;
136
+            Window::setSize(glm::vec2(Window::getSize().x, h));
137
+        }
138
+
139
+        static int fr = 0;
140
+        char buff[1024];
141
+        strncpy(buff, getBaseDir().c_str(), 1024);
142
+        if (ImGui::InputText("BaseDir##runtime", buff, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
143
+            setBaseDir(buff);
144
+            fr = getFPS();
145
+        }
146
+        if (fr > 0) {
147
+            ImGui::SameLine();
148
+            ImGui::Text("Done!##runtime1");
149
+            fr--;
150
+        }
151
+
152
+        static int fr2 = 0;
153
+        char buff2[1024];
154
+        strncpy(buff2, getPakDir().c_str(), 1024);
155
+        if (ImGui::InputText("PakDir##runtime", buff2, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
156
+            setPakDir(buff2);
157
+            fr2 = getFPS();
158
+        }
159
+        if (fr2 > 0) {
160
+            ImGui::SameLine();
161
+            ImGui::Text("Done!##runtime2");
162
+            fr2--;
163
+        }
164
+
165
+        static int fr3 = 0;
166
+        char buff3[1024];
167
+        strncpy(buff3, getAudioDir().c_str(), 1024);
168
+        if (ImGui::InputText("AudioDir##runtime", buff3, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
169
+            setAudioDir(buff3);
170
+            fr3 = getFPS();
171
+        }
172
+        if (fr3 > 0) {
173
+            ImGui::SameLine();
174
+            ImGui::Text("Done!##runtime3");
175
+            fr3--;
176
+        }
177
+
178
+        static int fr4 = 0;
179
+        char buff4[1024];
180
+        strncpy(buff4, getDataDir().c_str(), 1024);
181
+        if (ImGui::InputText("DataDir##runtime", buff4, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
182
+            setDataDir(buff4);
183
+            fr4 = getFPS();
184
+        }
185
+        if (fr4 > 0) {
186
+            ImGui::SameLine();
187
+            ImGui::Text("Done!##runtime4");
188
+            fr4--;
189
+        }
190
+    }
129 191
 
130
-float RunTime::getLastFrameTime() {
131
-    return lastFrameTime / 1000.0f;
192
+    if (ImGui::CollapsingHeader("Performance")) {
193
+        ImGui::Text("Uptime: %lums", systemTimerGet());
194
+        ImGui::Text("Frames per Second: %luFPS", getFPS());
195
+        if (getHistoryFPS().size() > 1) {
196
+            static bool scroll = true;
197
+            if (scroll) {
198
+                int offset = getHistoryFPS().size() - 1;
199
+                if (offset > 10)
200
+                    offset = 10;
201
+                ImGui::PlotLines("FPS", &getHistoryFPS()[1],
202
+                                 getHistoryFPS().size() - 1,
203
+                                 getHistoryFPS().size() - offset - 1);
204
+            } else {
205
+                ImGui::PlotLines("FPS", &getHistoryFPS()[1],
206
+                                 getHistoryFPS().size() - 1);
207
+            }
208
+            ImGui::SameLine();
209
+            ImGui::Checkbox("Scroll##fpsscroll", &scroll);
210
+        }
211
+    }
132 212
 }
133 213
 

+ 39
- 0
src/SoundManager.cpp Voir le fichier

@@ -6,6 +6,7 @@
6 6
  */
7 7
 
8 8
 #include "global.h"
9
+#include "UI.h"
9 10
 #include "system/Sound.h"
10 11
 #include "SoundManager.h"
11 12
 
@@ -116,3 +117,41 @@ int SoundManager::playSound(int index) {
116 117
     }
117 118
 }
118 119
 
120
+void SoundManager::display() {
121
+    if (ImGui::CollapsingHeader("Sound Map Player")) {
122
+        if (!Sound::getEnabled()) {
123
+            ImGui::Text("Please enable Sound first!");
124
+            if (ImGui::Button("Enable Sound!")) {
125
+                Sound::setEnabled(true);
126
+            }
127
+        } else if (Sound::numBuffers() == 0) {
128
+            ImGui::Text("Please load a level!");
129
+        } else {
130
+            static int index = 0;
131
+            ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
132
+            ImGui::SliderInt("##soundslide", &index, 0, sizeSoundMap() - 1);
133
+            ImGui::PopItemWidth();
134
+            ImGui::SameLine();
135
+            if (ImGui::Button("+##soundplus", ImVec2(0, 0), true)) {
136
+                if (index < (sizeSoundMap() - 1))
137
+                    index++;
138
+                else
139
+                    index = 0;
140
+            }
141
+            ImGui::SameLine();
142
+            if (ImGui::Button("-##soundminus", ImVec2(0, 0), true)) {
143
+                if (index > 0)
144
+                    index--;
145
+                else
146
+                    index = sizeSoundMap() - 1;
147
+            }
148
+            ImGui::SameLine();
149
+            if (ImGui::Button("Play##soundplay")) {
150
+                playSound(index);
151
+            }
152
+
153
+            ImGui::Text("Index: %d", getIndex(index));
154
+        }
155
+    }
156
+}
157
+

+ 8
- 0
src/StaticMesh.cpp Voir le fichier

@@ -6,10 +6,18 @@
6 6
  */
7 7
 
8 8
 #include "global.h"
9
+#include "Render.h"
9 10
 #include "World.h"
10 11
 #include "StaticMesh.h"
11 12
 
12 13
 void StaticMesh::display(glm::mat4 model, glm::mat4 view, glm::mat4 projection) {
13 14
     getWorld().getMesh(mesh).display(model, view, projection);
15
+
16
+    if (Render::getMode() == RenderMode::Wireframe) {
17
+        bbox1->display(projection * view * model,
18
+                       glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
19
+        bbox2->display(projection * view * model,
20
+                       glm::vec3(1.0f, 0.0f, 1.0f), glm::vec3(0.0f, 0.0f, 1.0f));
21
+    }
14 22
 }
15 23
 

+ 2
- 2
src/TextureManager.cpp Voir le fichier

@@ -149,9 +149,9 @@ int TextureManager::initializeSplash() {
149 149
     }
150 150
 
151 151
     //! \fixme Temporary?
152
-    std::string filename = getRunTime().getPakDir() + "/tr2/TITLE.PCX";
152
+    std::string filename = RunTime::getPakDir() + "/tr2/TITLE.PCX";
153 153
     if (loadPCX(filename.c_str(), TextureStorage::SYSTEM, TEXTURE_SPLASH) < 0) {
154
-        filename = getRunTime().getDataDir() + "/splash.tga";
154
+        filename = RunTime::getDataDir() + "/splash.tga";
155 155
         if (loadTGA(filename.c_str(), TextureStorage::SYSTEM, TEXTURE_SPLASH) < 0) {
156 156
             return -2;
157 157
         }

+ 9
- 174
src/UI.cpp Voir le fichier

@@ -40,8 +40,8 @@ std::list<std::tuple<int, int, int, int>> UI::motionEvents;
40 40
 std::list<std::tuple<int, int>> UI::scrollEvents;
41 41
 
42 42
 int UI::initialize() {
43
-    iniFilename = getRunTime().getBaseDir() + "/imgui.ini";
44
-    logFilename = getRunTime().getBaseDir() + "/imgui_log.txt";
43
+    iniFilename = RunTime::getBaseDir() + "/imgui.ini";
44
+    logFilename = RunTime::getBaseDir() + "/imgui_log.txt";
45 45
 
46 46
     ImGuiIO& io = ImGui::GetIO();
47 47
     io.DisplaySize = ImVec2(Window::getSize().x, Window::getSize().y);
@@ -136,7 +136,7 @@ void UI::eventsFinished() {
136 136
                 getMenu().handleKeyboard(std::get<0>(i), std::get<1>(i));
137 137
             } else {
138 138
                 for (int n = forwardAction; n < ActionEventCount; n++) {
139
-                    if (getRunTime().getKeyBinding((ActionEvents)n) == std::get<0>(i))
139
+                    if (RunTime::getKeyBinding((ActionEvents)n) == std::get<0>(i))
140 140
                         getGame().handleAction((ActionEvents)n, !std::get<1>(i));
141 141
                 }
142 142
             }
@@ -144,13 +144,13 @@ void UI::eventsFinished() {
144 144
 
145 145
         if (std::get<1>(i)) {
146 146
             if (!visible) {
147
-                if (getRunTime().getKeyBinding(menuAction) == std::get<0>(i)) {
147
+                if (RunTime::getKeyBinding(menuAction) == std::get<0>(i)) {
148 148
                     getMenu().setVisible(!getMenu().isVisible());
149 149
                 }
150 150
             }
151 151
 
152 152
             if ((!io.WantCaptureKeyboard) || (!visible)) {
153
-                if (getRunTime().getKeyBinding(debugAction) == std::get<0>(i)) {
153
+                if (RunTime::getKeyBinding(debugAction) == std::get<0>(i)) {
154 154
                     if (!metaKeyIsActive)
155 155
                         visible = !visible;
156 156
                 }
@@ -192,171 +192,8 @@ void UI::display() {
192 192
     Console::display();
193 193
 
194 194
     if (ImGui::Begin("Engine")) {
195
-        if (ImGui::CollapsingHeader("Engine Info")) {
196
-            ImGui::Text("Uptime: %lums", systemTimerGet());
197
-            ImGui::Text("Frames per Second: %luFPS", getRunTime().getFPS());
198
-            if (getRunTime().getHistoryFPS().size() > 1) {
199
-                static bool scroll = true;
200
-                if (scroll) {
201
-                    int offset = getRunTime().getHistoryFPS().size() - 1;
202
-                    if (offset > 10)
203
-                        offset = 10;
204
-                    ImGui::PlotLines("FPS", &getRunTime().getHistoryFPS()[1],
205
-                                     getRunTime().getHistoryFPS().size() - 1,
206
-                                     getRunTime().getHistoryFPS().size() - offset - 1);
207
-                } else {
208
-                    ImGui::PlotLines("FPS", &getRunTime().getHistoryFPS()[1],
209
-                                     getRunTime().getHistoryFPS().size() - 1);
210
-                }
211
-                ImGui::SameLine();
212
-                ImGui::Checkbox("Scroll##fpsscroll", &scroll);
213
-            }
214
-        }
215
-
216
-        if (ImGui::CollapsingHeader("RunTime Settings")) {
217
-            bool showFPS = getRunTime().getShowFPS();
218
-            if (ImGui::Checkbox("Show FPS##runtime", &showFPS)) {
219
-                getRunTime().setShowFPS(showFPS);
220
-            }
221
-            ImGui::SameLine();
222
-            bool running = getRunTime().isRunning();
223
-            if (ImGui::Checkbox("Running (!)##runtime", &running)) {
224
-                getRunTime().setRunning(running);
225
-            }
226
-            ImGui::SameLine();
227
-            bool sound = Sound::getEnabled();
228
-            if (ImGui::Checkbox("Sound##runtime", &sound)) {
229
-                Sound::setEnabled(sound);
230
-            }
231
-            ImGui::SameLine();
232
-            bool fullscreen = Window::getFullscreen();
233
-            if (ImGui::Checkbox("Fullscreen##runtime", &fullscreen)) {
234
-                Window::setFullscreen(fullscreen);
235
-            }
236
-
237
-            bool updateViewFrustum = Camera::getUpdateViewFrustum();
238
-            if (ImGui::Checkbox("Update Frustum##runtime", &updateViewFrustum)) {
239
-                Camera::setUpdateViewFrustum(updateViewFrustum);
240
-            }
241
-            ImGui::SameLine();
242
-            bool displayViewFrustum = Render::getDisplayViewFrustum();
243
-            if (ImGui::Checkbox("Show Frustum##runtime", &displayViewFrustum)) {
244
-                Render::setDisplayViewFrustum(displayViewFrustum);
245
-            }
246
-
247
-            float vol = Sound::getVolume();
248
-            if (ImGui::InputFloat("Volume##runtime", &vol, 0.0f, 0.0f, 3,
249
-                                  ImGuiInputTextFlags_EnterReturnsTrue)) {
250
-                if (vol < 0.0f)
251
-                    vol = 0.0f;
252
-                if (vol > 1.0f)
253
-                    vol = 1.0f;
254
-                Sound::setVolume(vol);
255
-            }
256
-
257
-            int w = Window::getSize().x;
258
-            if (ImGui::InputInt("Width##runtime", &w, 10, 100, ImGuiInputTextFlags_EnterReturnsTrue)) {
259
-                if (w < 1)
260
-                    w = 1;
261
-                Window::setSize(glm::vec2(w, Window::getSize().y));
262
-            }
263
-            int h = Window::getSize().y;
264
-            if (ImGui::InputInt("Height##runtime", &h, 10, 100, ImGuiInputTextFlags_EnterReturnsTrue)) {
265
-                if (h < 1)
266
-                    h = 1;
267
-                Window::setSize(glm::vec2(Window::getSize().x, h));
268
-            }
269
-
270
-            static int fr = 0;
271
-            char buff[1024];
272
-            strncpy(buff, getRunTime().getBaseDir().c_str(), 1024);
273
-            if (ImGui::InputText("BaseDir##runtime", buff, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
274
-                getRunTime().setBaseDir(buff);
275
-                fr = getRunTime().getFPS();
276
-            }
277
-            if (fr > 0) {
278
-                ImGui::SameLine();
279
-                ImGui::Text("Done!##runtime1");
280
-                fr--;
281
-            }
282
-
283
-            static int fr2 = 0;
284
-            char buff2[1024];
285
-            strncpy(buff2, getRunTime().getPakDir().c_str(), 1024);
286
-            if (ImGui::InputText("PakDir##runtime", buff2, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
287
-                getRunTime().setPakDir(buff2);
288
-                fr2 = getRunTime().getFPS();
289
-            }
290
-            if (fr2 > 0) {
291
-                ImGui::SameLine();
292
-                ImGui::Text("Done!##runtime2");
293
-                fr2--;
294
-            }
295
-
296
-            static int fr3 = 0;
297
-            char buff3[1024];
298
-            strncpy(buff3, getRunTime().getAudioDir().c_str(), 1024);
299
-            if (ImGui::InputText("AudioDir##runtime", buff3, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
300
-                getRunTime().setAudioDir(buff3);
301
-                fr3 = getRunTime().getFPS();
302
-            }
303
-            if (fr3 > 0) {
304
-                ImGui::SameLine();
305
-                ImGui::Text("Done!##runtime3");
306
-                fr3--;
307
-            }
308
-
309
-            static int fr4 = 0;
310
-            char buff4[1024];
311
-            strncpy(buff4, getRunTime().getDataDir().c_str(), 1024);
312
-            if (ImGui::InputText("DataDir##runtime", buff4, 1024, ImGuiInputTextFlags_EnterReturnsTrue)) {
313
-                getRunTime().setDataDir(buff4);
314
-                fr4 = getRunTime().getFPS();
315
-            }
316
-            if (fr4 > 0) {
317
-                ImGui::SameLine();
318
-                ImGui::Text("Done!##runtime4");
319
-                fr4--;
320
-            }
321
-        }
322
-
323
-        ImGui::Separator();
324
-
325
-        if (ImGui::CollapsingHeader("Sound Map Player")) {
326
-            if (!Sound::getEnabled()) {
327
-                ImGui::Text("Please enable Sound first!");
328
-                if (ImGui::Button("Enable Sound!")) {
329
-                    Sound::setEnabled(true);
330
-                }
331
-            } else if (Sound::numBuffers() == 0) {
332
-                ImGui::Text("Please load a level!");
333
-            } else {
334
-                static int index = 0;
335
-                ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
336
-                ImGui::SliderInt("##soundslide", &index, 0, SoundManager::sizeSoundMap() - 1);
337
-                ImGui::PopItemWidth();
338
-                ImGui::SameLine();
339
-                if (ImGui::Button("+##soundplus", ImVec2(0, 0), true)) {
340
-                    if (index < (SoundManager::sizeSoundMap() - 1))
341
-                        index++;
342
-                    else
343
-                        index = 0;
344
-                }
345
-                ImGui::SameLine();
346
-                if (ImGui::Button("-##soundminus", ImVec2(0, 0), true)) {
347
-                    if (index > 0)
348
-                        index--;
349
-                    else
350
-                        index = SoundManager::sizeSoundMap() - 1;
351
-                }
352
-                ImGui::SameLine();
353
-                if (ImGui::Button("Play##soundplay")) {
354
-                    SoundManager::playSound(index);
355
-                }
356
-
357
-                ImGui::Text("Index: %d", SoundManager::getIndex(index));
358
-            }
359
-        }
195
+        RunTime::display();
196
+        SoundManager::display();
360 197
 
361 198
         /*
362 199
         static bool visibleTex = false;
@@ -509,7 +346,7 @@ void UI::display() {
509 346
                                                         ImGui::GetWindowPos().x - (ImGui::GetWindowWidth() / 2),
510 347
                                                         ImGui::GetWindowPos().y,
511 348
                                                         (ImGui::GetWindowWidth() / 2), (ImGui::GetWindowWidth() / 2));
512
-                        fr = getRunTime().getFPS() / 2;
349
+                        fr = RunTime::getFPS() / 2;
513 350
                         tile = getTextureManager().getNextTileAnimation(tile);
514 351
                     }
515 352
                     ImGui::Text("Current Tile: %d", tile);
@@ -567,7 +404,7 @@ void UI::display() {
567 404
                                                        ImGui::GetWindowPos().x - (ImGui::GetWindowWidth() / 2),
568 405
                                                        ImGui::GetWindowPos().y,
569 406
                                                        (ImGui::GetWindowWidth() / 2), (ImGui::GetWindowWidth() / 2));
570
-                        fr = getRunTime().getFPS() / 10;
407
+                        fr = RunTime::getFPS() / 10;
571 408
                         if (sprite < (getWorld().getSprite(index).size() - 1))
572 409
                             sprite++;
573 410
                         else
@@ -580,8 +417,6 @@ void UI::display() {
580 417
         }
581 418
         */
582 419
 
583
-        ImGui::Separator();
584
-
585 420
         if (ImGui::CollapsingHeader("ImGui/Debug UI Help")) {
586 421
             //ImGui::TextWrapped("DebugViewer Textures/Textiles/Sprites will be drawn on"
587 422
             //                   " the left side and scale with the size of this window!");

+ 1
- 1
src/commands/CommandBind.cpp Voir le fichier

@@ -56,7 +56,7 @@ int CommandBind::execute(std::istream& args) {
56 56
             return -3;
57 57
         }
58 58
 
59
-        getRunTime().setKeyBinding(e, c);
59
+        RunTime::setKeyBinding(e, c);
60 60
         return 0;
61 61
     }
62 62
 }

+ 3
- 3
src/commands/CommandEngine.cpp Voir le fichier

@@ -28,7 +28,7 @@ void CommandLoad::printHelp() {
28 28
 }
29 29
 
30 30
 int CommandLoad::execute(std::istream& args) {
31
-    if (!getRunTime().isRunning()) {
31
+    if (!RunTime::isRunning()) {
32 32
         getLog() << "Use load command interactively!" << Log::endl;
33 33
         return -1;
34 34
     }
@@ -56,12 +56,12 @@ void CommandScreenshot::printHelp() {
56 56
 }
57 57
 
58 58
 int CommandScreenshot::execute(std::istream& args) {
59
-    if (!getRunTime().isRunning()) {
59
+    if (!RunTime::isRunning()) {
60 60
         getLog() << "Use sshot command interactively!" << Log::endl;
61 61
         return -1;
62 62
     }
63 63
 
64
-    std::string filename(getRunTime().getBaseDir());
64
+    std::string filename(RunTime::getBaseDir());
65 65
     filename += "/sshots/";
66 66
     filename += VERSION_SHORT;
67 67
 

+ 2
- 2
src/commands/CommandGame.cpp Voir le fichier

@@ -21,7 +21,7 @@ std::string CommandPos::brief() {
21 21
 }
22 22
 
23 23
 int CommandPos::execute(std::istream& args) {
24
-    if ((!getRunTime().isRunning()) || (!getGame().isLoaded())) {
24
+    if ((!RunTime::isRunning()) || (!getGame().isLoaded())) {
25 25
         getLog() << "Use pos command interactively!" << Log::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 ((!getRunTime().isRunning()) || (!getGame().isLoaded())) {
44
+    if ((!RunTime::isRunning()) || (!getGame().isLoaded())) {
45 45
         getLog() << "Use viewmodel command interactively!" << Log::endl;
46 46
         return -1;
47 47
     }

+ 1
- 1
src/commands/CommandMove.cpp Voir le fichier

@@ -29,7 +29,7 @@ void CommandMove::printHelp() {
29 29
 }
30 30
 
31 31
 int CommandMove::execute(std::istream& args) {
32
-    if ((!getRunTime().isRunning()) || (!getGame().isLoaded())) {
32
+    if ((!RunTime::isRunning()) || (!getGame().isLoaded())) {
33 33
         getLog() << "Use move command interactively!" << Log::endl;
34 34
         return -1;
35 35
     }

+ 14
- 14
src/commands/CommandSet.cpp Voir le fichier

@@ -55,10 +55,10 @@ namespace {
55 55
         }
56 56
 
57 57
         // Expand Names
58
-        s = findAndReplace(s, "$(pakdir)", getRunTime().getPakDir());
59
-        s = findAndReplace(s, "$(audiodir)", getRunTime().getAudioDir());
60
-        s = findAndReplace(s, "$(datadir)", getRunTime().getDataDir());
61
-        s = findAndReplace(s, "$(basedir)", getRunTime().getBaseDir());
58
+        s = findAndReplace(s, "$(pakdir)", RunTime::getPakDir());
59
+        s = findAndReplace(s, "$(audiodir)", RunTime::getAudioDir());
60
+        s = findAndReplace(s, "$(datadir)", RunTime::getDataDir());
61
+        s = findAndReplace(s, "$(basedir)", RunTime::getBaseDir());
62 62
 
63 63
         // Full path
64 64
         s = expandHomeDirectory(s);
@@ -119,23 +119,23 @@ int CommandSet::execute(std::istream& args) {
119 119
             getLog() << "set-fps-Error: Invalid value" << Log::endl;
120 120
             return -8;
121 121
         }
122
-        getRunTime().setShowFPS(fps);
122
+        RunTime::setShowFPS(fps);
123 123
     } else if (var.compare("basedir") == 0) {
124 124
         std::string temp;
125 125
         args >> temp;
126
-        getRunTime().setBaseDir(expandNames(temp));
126
+        RunTime::setBaseDir(expandNames(temp));
127 127
     } else if (var.compare("pakdir") == 0) {
128 128
         std::string temp;
129 129
         args >> temp;
130
-        getRunTime().setPakDir(expandNames(temp));
130
+        RunTime::setPakDir(expandNames(temp));
131 131
     } else if (var.compare("audiodir") == 0) {
132 132
         std::string temp;
133 133
         args >> temp;
134
-        getRunTime().setAudioDir(expandNames(temp));
134
+        RunTime::setAudioDir(expandNames(temp));
135 135
     } else if (var.compare("datadir") == 0) {
136 136
         std::string temp;
137 137
         args >> temp;
138
-        getRunTime().setDataDir(expandNames(temp));
138
+        RunTime::setDataDir(expandNames(temp));
139 139
     } else if (var.compare("font") == 0) {
140 140
         std::string temp;
141 141
         args >> temp;
@@ -193,15 +193,15 @@ int CommandGet::execute(std::istream& args) {
193 193
     } else if (var.compare("mouse_y") == 0) {
194 194
         getLog() << glm::degrees(Camera::getSensitivityY()) << Log::endl;
195 195
     } else if (var.compare("fps") == 0) {
196
-        getLog() << getRunTime().getShowFPS() << Log::endl;
196
+        getLog() << RunTime::getShowFPS() << Log::endl;
197 197
     } else if (var.compare("basedir") == 0) {
198
-        getLog() << getRunTime().getBaseDir() << Log::endl;
198
+        getLog() << RunTime::getBaseDir() << Log::endl;
199 199
     } else if (var.compare("pakdir") == 0) {
200
-        getLog() << getRunTime().getPakDir() << Log::endl;
200
+        getLog() << RunTime::getPakDir() << Log::endl;
201 201
     } else if (var.compare("audiodir") == 0) {
202
-        getLog() << getRunTime().getAudioDir() << Log::endl;
202
+        getLog() << RunTime::getAudioDir() << Log::endl;
203 203
     } else if (var.compare("datadir") == 0) {
204
-        getLog() << getRunTime().getDataDir() << Log::endl;
204
+        getLog() << RunTime::getDataDir() << Log::endl;
205 205
     } else if (var.compare("font") == 0) {
206 206
         getLog() << Font::getFontName() << Log::endl;
207 207
     } else {

+ 3
- 1
src/loader/LoaderTR2.cpp Voir le fichier

@@ -634,7 +634,9 @@ void LoaderTR2::loadStaticMeshes() {
634 634
         // travel through, like TR2s skeletons and underwater plants
635 635
         uint16_t flags = file.readU16();
636 636
 
637
-        getWorld().addStaticMesh(new StaticMesh(objectID, mesh));
637
+        BoundingBox* bbox1 = new BoundingBox(glm::vec3(x11, y11, z11), glm::vec3(x12, y12, z12));
638
+        BoundingBox* bbox2 = new BoundingBox(glm::vec3(x21, y21, z21), glm::vec3(x22, y22, z22));
639
+        getWorld().addStaticMesh(new StaticMesh(objectID, mesh, bbox1, bbox2));
638 640
     }
639 641
 
640 642
     if (numStaticMeshes > 0)

+ 4
- 9
src/main.cpp Voir le fichier

@@ -33,7 +33,6 @@ static std::string configFileToUse;
33 33
 static std::shared_ptr<Game> gGame;
34 34
 static std::shared_ptr<Log> gLog;
35 35
 static std::shared_ptr<MenuFolder> gMenu;
36
-static std::shared_ptr<RunTime> gRunTime;
37 36
 static std::shared_ptr<TextureManager> gTextureManager;
38 37
 static std::shared_ptr<World> gWorld;
39 38
 
@@ -49,10 +48,6 @@ Menu& getMenu() {
49 48
     return *gMenu;
50 49
 }
51 50
 
52
-RunTime& getRunTime() {
53
-    return *gRunTime;
54
-}
55
-
56 51
 TextureManager& getTextureManager() {
57 52
     return *gTextureManager;
58 53
 }
@@ -72,7 +67,7 @@ int main(int argc, char* argv[]) {
72 67
     command_free(&cmd);
73 68
 
74 69
     // RunTime is required by other constructors
75
-    gRunTime.reset(new RunTime());
70
+    RunTime::initialize();
76 71
 
77 72
     gGame.reset(new Game());
78 73
     gLog.reset(new Log());
@@ -149,9 +144,9 @@ int main(int argc, char* argv[]) {
149 144
     getLog() << "Starting " << VERSION << Log::endl;
150 145
     getMenu().setVisible(true);
151 146
     systemTimerReset();
152
-    getRunTime().setRunning(true);
147
+    RunTime::setRunning(true);
153 148
 
154
-    while (getRunTime().isRunning()) {
149
+    while (RunTime::isRunning()) {
155 150
         Window::eventHandling();
156 151
         renderFrame();
157 152
     }
@@ -178,7 +173,7 @@ void renderFrame() {
178 173
     getMenu().display();
179 174
     UI::display();
180 175
     Window::swapBuffers();
181
-    getRunTime().updateFPS();
176
+    RunTime::updateFPS();
182 177
 }
183 178
 
184 179
 #endif // UNIT_TEST

+ 1
- 1
src/system/WindowGLFW.cpp Voir le fichier

@@ -60,7 +60,7 @@ void WindowGLFW::eventHandling() {
60 60
     glfwPollEvents();
61 61
 
62 62
     if (glfwWindowShouldClose(window)) {
63
-        getRunTime().setRunning(false);
63
+        RunTime::setRunning(false);
64 64
     }
65 65
 
66 66
     UI::eventsFinished();

+ 1
- 1
src/system/WindowSDL.cpp Voir le fichier

@@ -462,7 +462,7 @@ void WindowSDL::eventHandling() {
462 462
                 break;
463 463
 
464 464
             case SDL_QUIT:
465
-                getRunTime().setRunning(false);
465
+                RunTime::setRunning(false);
466 466
                 break;
467 467
         }
468 468
     }

Chargement…
Annuler
Enregistrer