Bladeren bron

Back face culling, log levels, clipboard support.

Thomas Buck 10 jaren geleden
bovenliggende
commit
71bf2febc7

+ 8
- 0
ChangeLog.md Bestand weergeven

@@ -2,6 +2,14 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140111 ]
6
+    * Enabled back face culling --> triangles now oriented correctly
7
+    * Game is now completely static
8
+    * Shaders drawGL methods can now be given a specific Shader instance.
9
+    * Log now manages different log levels. Console displays them colored.
10
+    * Console can now log to the TTY, the clipboard or a file.
11
+    * Added system clipboard support for imgui in both WindowSDL and WindowGLFW.
12
+
5 13
     [ 20140109 ]
6 14
     * Display of Bounding Boxes can be individually toggled for Rooms/StaticMeshes
7 15
     * Tightened imgui Style and changed colors to match the _OpenRaider-blue_

+ 1
- 1
cmake/Doxyfile.in Bestand weergeven

@@ -768,7 +768,7 @@ RECURSIVE              = YES
768 768
 # Note that relative paths are relative to the directory from which doxygen is
769 769
 # run.
770 770
 
771
-EXCLUDE                = ../bin ../build ../cmake ../data ../test/greatest.h
771
+EXCLUDE                = ../bin ../build ../cmake ../data ../src/deps
772 772
 
773 773
 # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
774 774
 # directories that are symbolic links (a Unix file system feature) are excluded

+ 12
- 18
include/Game.h Bestand weergeven

@@ -15,30 +15,24 @@
15 15
 
16 16
 class Game {
17 17
   public:
18
-    Game();
18
+    static void destroy();
19 19
 
20
-    int initialize();
21
-    void destroy();
20
+    static bool isLoaded() { return mLoaded; }
21
+    static int loadLevel(const char* level);
22 22
 
23
-    bool isLoaded() { return mLoaded; }
24
-    int loadLevel(const char* level);
23
+    static void handleAction(ActionEvents action, bool isFinished);
24
+    static void handleMouseMotion(int xrel, int yrel, int xabs, int yabs);
25
+    static void handleControllerAxis(float value, KeyboardButton axis);
26
+    static void handleControllerButton(KeyboardButton button, bool released);
25 27
 
26
-    void display();
27
-    void handleAction(ActionEvents action, bool isFinished);
28
-    void handleMouseMotion(int xrel, int yrel, int xabs, int yabs);
29
-    void handleControllerAxis(float value, KeyboardButton axis);
30
-    void handleControllerButton(KeyboardButton button, bool released);
31
-
32
-    Entity& getLara();
33
-    void setLara(long lara);
28
+    static Entity& getLara();
29
+    static void setLara(long lara);
34 30
 
35 31
   private:
36
-    bool mLoaded;
37
-    long mLara;
38
-    bool activeEvents[ActionEventCount];
32
+    static bool mLoaded;
33
+    static long mLara;
34
+    static bool activeEvents[ActionEventCount];
39 35
 };
40 36
 
41
-Game& getGame();
42
-
43 37
 #endif
44 38
 

+ 45
- 20
include/Log.h Bestand weergeven

@@ -15,45 +15,70 @@
15 15
 
16 16
 #include <glm/gtc/type_precision.hpp>
17 17
 
18
-class Log {
18
+#define LOG_USER    0
19
+#define LOG_ERROR   1
20
+#define LOG_WARNING 2
21
+#define LOG_INFO    3
22
+#define LOG_DEBUG   4
23
+#define LOG_COUNT   5
24
+
25
+struct LogEntry {
19 26
   public:
27
+    std::string text;
28
+    int level;
29
+    LogEntry(std::string t, int l) : text(t), level(l) { }
30
+};
20 31
 
32
+class LogLevel;
33
+class Log {
34
+  public:
21 35
     const static char endl = '\n';
22 36
 
23
-    Log();
37
+    static LogLevel& get(int level);
38
+    static unsigned long size() { return wholeLog.size(); }
39
+    static LogEntry getEntry(unsigned long i) { return wholeLog.at(i); }
24 40
 
25
-    unsigned long size();
26
-    std::string get(unsigned long i);
41
+  private:
42
+    static LogLevel logs[LOG_COUNT];
27 43
 
28
-    template<typename T>
29
-    Log& operator<< (const T t) {
30
-        printBuffer << t;
31
-        if (printBuffer.str().back() == endl) {
32
-            mHistory.push_back(printBuffer.str().substr(0, printBuffer.str().length() - 1));
33
-            std::cout << printBuffer.str().substr(0, printBuffer.str().length() - 1) << std::endl;
34
-            printBuffer.str("");
35
-        }
36
-        return (*this);
37
-    }
44
+    static std::vector<LogEntry> wholeLog;
45
+    friend class LogLevel;
46
+};
47
+
48
+class LogLevel {
49
+  public:
50
+    LogLevel(int l) : level(l) { printBuffer << std::boolalpha; }
38 51
 
39
-    Log& operator<< (const glm::vec2& v) {
52
+    LogLevel& operator<< (const glm::vec2& v) {
40 53
         return (*this) << v.x << " " << v.y;
41 54
     }
42 55
 
43
-    Log& operator<< (const glm::i32vec2& v) {
56
+    LogLevel& operator<< (const glm::i32vec2& v) {
44 57
         return (*this) << v.x << " " << v.y;
45 58
     }
46 59
 
47
-    Log& operator<< (const glm::vec3& v) {
60
+    LogLevel& operator<< (const glm::vec3& v) {
48 61
         return (*this) << v.x << " " << v.y << " " << v.z;
49 62
     }
50 63
 
64
+    template<typename T>
65
+    LogLevel& operator<< (const T t) {
66
+        printBuffer << t;
67
+        if (printBuffer.str().back() == Log::endl) {
68
+            std::string s = printBuffer.str().substr(0, printBuffer.str().length() - 1);
69
+            printBuffer.str("");
70
+            Log::wholeLog.emplace_back(s, level);
71
+#ifdef DEBUG
72
+            std::cout << s << std::endl;
73
+#endif
74
+        }
75
+        return (*this);
76
+    }
77
+
51 78
   private:
52
-    std::vector<std::string> mHistory;
79
+    int level;
53 80
     std::ostringstream printBuffer;
54 81
 };
55 82
 
56
-Log& getLog();
57
-
58 83
 #endif
59 84
 

+ 7
- 5
include/system/Shader.h Bestand weergeven

@@ -54,19 +54,21 @@ class Shader {
54 54
     static int initialize();
55 55
     static void shutdown();
56 56
 
57
+    static void set2DState(bool on);
58
+
57 59
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, unsigned int texture,
58
-                       TextureStorage store = TextureStorage::SYSTEM);
60
+                       TextureStorage store = TextureStorage::SYSTEM, Shader& shader = textShader);
59 61
 
60 62
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP,
61
-                       TextureStorage store = TextureStorage::GAME);
63
+                       TextureStorage store = TextureStorage::GAME, Shader& shader = textureShader);
62 64
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& indices,
63 65
                        unsigned int texture, glm::mat4 MVP,
64
-                       TextureStorage store = TextureStorage::GAME);
66
+                       TextureStorage store = TextureStorage::GAME, Shader& shader = textureShader);
65 67
 
66 68
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
67
-                       unsigned int mode = GL_TRIANGLES);
69
+                       unsigned int mode = GL_TRIANGLES, Shader& shader = colorShader);
68 70
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices,
69
-                       glm::mat4 MVP, unsigned int mode = GL_TRIANGLES);
71
+                       glm::mat4 MVP, unsigned int mode = GL_TRIANGLES, Shader& shader = colorShader);
70 72
 
71 73
   private:
72 74
     int programID;

+ 3
- 0
include/system/Window.h Bestand weergeven

@@ -28,6 +28,9 @@ class Window {
28 28
 
29 29
     static void setTextInput(bool t);
30 30
     static bool getTextInput();
31
+
32
+    static void setClipboard(const char* s);
33
+    static const char* getClipboard();
31 34
 };
32 35
 
33 36
 #endif

+ 3
- 0
include/system/WindowGLFW.h Bestand weergeven

@@ -31,6 +31,9 @@ class WindowGLFW {
31 31
     static void setTextInput(bool t);
32 32
     static bool getTextInput() { return textinput; }
33 33
 
34
+    static void setClipboard(const char* s);
35
+    static const char* getClipboard();
36
+
34 37
   private:
35 38
     static void errorCallback(int error, const char* desc);
36 39
     static void sizeCallback(GLFWwindow* w, int width, int height);

+ 3
- 0
include/system/WindowSDL.h Bestand weergeven

@@ -31,6 +31,9 @@ class WindowSDL {
31 31
     static void setTextInput(bool t);
32 32
     static bool getTextInput() { return textinput; }
33 33
 
34
+    static void setClipboard(const char* s);
35
+    static const char* getClipboard();
36
+
34 37
   private:
35 38
     static glm::i32vec2 size;
36 39
     static bool fullscreen;

+ 55
- 6
src/Console.cpp Bestand weergeven

@@ -74,14 +74,63 @@ void Console::display() {
74 74
 
75 75
     static bool scrollToBottom = false;
76 76
     if (ImGui::Begin("Console", &visible, ImVec2(600, 400))) {
77
-        if (lastLogLength != getLog().size()) {
78
-            lastLogLength = getLog().size();
77
+        if (lastLogLength != Log::size()) {
78
+            lastLogLength = Log::size();
79 79
             scrollToBottom = true;
80 80
         }
81 81
 
82
+        static bool visibleLogs[LOG_COUNT] = { true, true, true, true, false };
83
+        ImGui::Checkbox("Error##log", &visibleLogs[1]);
84
+        ImGui::SameLine();
85
+        ImGui::Checkbox("Warning##log", &visibleLogs[2]);
86
+        ImGui::SameLine();
87
+        ImGui::Checkbox("User##log", &visibleLogs[0]);
88
+        ImGui::SameLine();
89
+        ImGui::Checkbox("Info##log", &visibleLogs[3]);
90
+        ImGui::SameLine();
91
+        ImGui::Checkbox("Debug##log", &visibleLogs[4]);
92
+        ImGui::SameLine();
93
+        static bool logToTTY = false, logToClipboard = false, logToFile = false;
94
+        if (ImGui::Button("Log to TTY")) { logToTTY = true; }
95
+        ImGui::SameLine();
96
+        if (ImGui::Button("Log to Clipboard")) { logToClipboard = true; }
97
+        ImGui::SameLine();
98
+        if (ImGui::Button("Log to File")) { logToFile = true; }
99
+        ImGui::Separator();
100
+
82 101
         ImGui::BeginChild("ConsoleText", ImVec2(0, -ImGui::GetTextLineSpacing() * 2));
83
-        for (unsigned long i = 0; i < getLog().size(); i++) {
84
-            ImGui::TextUnformatted(getLog().get(i).c_str());
102
+        if (logToTTY)
103
+            ImGui::LogToTTY();
104
+        else if (logToClipboard)
105
+            ImGui::LogToClipboard();
106
+        else if (logToFile)
107
+            ImGui::LogToFile();
108
+        for (unsigned long i = 0; i < Log::size(); i++) {
109
+            auto entry = Log::getEntry(i);
110
+
111
+            assert(entry.level < LOG_COUNT);
112
+            if (!visibleLogs[entry.level]) {
113
+                continue;
114
+            }
115
+
116
+            ImVec4 col(1.0f, 1.0f, 1.0f, 1.0f);
117
+            if (entry.level == LOG_ERROR) {
118
+                col = ImVec4(1.0f, 0.0f, 0.0f, 1.0f);
119
+            } else if (entry.level == LOG_WARNING) {
120
+                col = ImVec4(1.0f, 1.0f, 0.0f, 1.0f);
121
+            } else if (entry.level == LOG_DEBUG) {
122
+                col = ImVec4(0.0f, 1.0f, 0.0f, 1.0f);
123
+            } else if (entry.level == LOG_USER) {
124
+                col = ImVec4(0.5f, 0.75f, 1.0f, 1.0f);
125
+            }
126
+
127
+            ImGui::PushStyleColor(ImGuiCol_Text, col);
128
+            ImGui::TextUnformatted(entry.text.c_str());
129
+            ImGui::PopStyleColor();
130
+        }
131
+        if (logToTTY || logToClipboard || logToFile) {
132
+            ImGui::LogFinish();
133
+            logToTTY = logToClipboard = logToFile = false;
85 134
         }
86 135
         if (scrollToBottom) {
87 136
             ImGui::SetScrollPosHere();
@@ -95,11 +144,11 @@ void Console::display() {
95 144
                              | ImGuiInputTextFlags_CallbackCompletion
96 145
                              | ImGuiInputTextFlags_CallbackHistory,
97 146
                              &Console::callback)) {
98
-            getLog() << "> " << buffer << Log::endl;
147
+            Log::get(LOG_USER) << "> " << buffer << Log::endl;
99 148
             if (strlen(buffer) > 0) {
100 149
                 int error = Command::command(buffer);
101 150
                 if (error != 0) {
102
-                    getLog() << "Error code: " << error << Log::endl;
151
+                    Log::get(LOG_USER) << "Error code: " << error << Log::endl;
103 152
                 }
104 153
 
105 154
                 if ((lastCommands.size() == 0) || (lastCommands[lastCommands.size() - 1] != buffer))

+ 1
- 1
src/Entity.cpp Bestand weergeven

@@ -42,7 +42,7 @@ void Entity::move(char movement) {
42 42
 }
43 43
 
44 44
 void Entity::print() {
45
-    getLog() << "Entity " << objectId << ":" << Log::endl
45
+    Log::get(LOG_INFO) << "Entity " << objectId << ":" << Log::endl
46 46
              << "  Room " << room << " (" << getWorld().getRoom(room).getFlags()
47 47
              << ")" << Log::endl
48 48
              << "  " << pos[0] << "x " << pos[1] << "y " << pos[2] << "z"

+ 15
- 24
src/Game.cpp Bestand weergeven

@@ -7,6 +7,7 @@
7 7
 
8 8
 #include "global.h"
9 9
 #include "Camera.h"
10
+#include "Console.h"
10 11
 #include "Game.h"
11 12
 #include "loader/Loader.h"
12 13
 #include "Log.h"
@@ -16,31 +17,19 @@
16 17
 #include "UI.h"
17 18
 #include "World.h"
18 19
 
19
-Game::Game() {
20
+bool Game::mLoaded = false;
21
+long Game::mLara = -1;
22
+bool Game::activeEvents[ActionEventCount];
23
+
24
+void Game::destroy() {
20 25
     mLoaded = false;
21 26
     mLara = -1;
22 27
 
23 28
     for (int i = 0; i < ActionEventCount; i++) {
24 29
         activeEvents[i] = false;
25 30
     }
26
-}
27 31
 
28
-int Game::initialize() {
29
-    // Enable Renderer
30 32
     Render::setMode(RenderMode::LoadScreen);
31
-
32
-    return 0;
33
-}
34
-
35
-void Game::display() {
36
-    Render::display();
37
-}
38
-
39
-void Game::destroy() {
40
-    mLoaded = false;
41
-    mLara = -1;
42
-    Render::setMode(RenderMode::LoadScreen);
43
-
44 33
     Camera::reset();
45 34
     Render::clearRoomList();
46 35
     SoundManager::clear();
@@ -50,12 +39,13 @@ void Game::destroy() {
50 39
 
51 40
 int Game::loadLevel(const char* level) {
52 41
     destroy();
53
-    getLog() << "Loading " << level << Log::endl;
42
+
43
+    Log::get(LOG_INFO) << "Loading " << level << Log::endl;
54 44
     auto loader = Loader::createLoader(level);
55 45
     if (loader) {
56 46
         int error = loader->load(level);
57 47
         if (error != 0) {
58
-            getLog() << "Error loading level (" << error << ")..." << Log::endl;
48
+            Log::get(LOG_ERROR) << "Error loading level (" << error << ")..." << Log::endl;
59 49
             destroy();
60 50
             return -2;
61 51
         }
@@ -70,19 +60,20 @@ int Game::loadLevel(const char* level) {
70 60
 
71 61
         SoundManager::prepareSources();
72 62
 
63
+        mLoaded = true;
64
+        Render::setMode(RenderMode::Texture);
65
+
73 66
         if (mLara == -1) {
74
-            getLog() << "Can't find Lara entity in level?!" << Log::endl;
67
+            Log::get(LOG_WARNING) << "Can't find Lara entity in level?!" << Log::endl;
68
+            Console::setVisible(true);
75 69
             UI::setVisible(true);
76 70
         } else {
77
-            mLoaded = true;
78
-            Render::setMode(RenderMode::Texture);
79
-
80 71
             Camera::setPosition(glm::vec3(getLara().getPos(0),
81 72
                                           getLara().getPos(1) - 1024.0f,
82 73
                                           getLara().getPos(2)));
83 74
         }
84 75
     } else {
85
-        getLog() << "No suitable loader for this level!" << Log::endl;
76
+        Log::get(LOG_ERROR) << "No suitable loader for this level!" << Log::endl;
86 77
         return -1;
87 78
     }
88 79
 

+ 6
- 10
src/Log.cpp Bestand weergeven

@@ -8,16 +8,12 @@
8 8
 #include "global.h"
9 9
 #include "Log.h"
10 10
 
11
-Log::Log() {
12
-    printBuffer << std::boolalpha;
13
-}
14
-
15
-unsigned long Log::size() {
16
-    return mHistory.size();
17
-}
11
+LogLevel Log::logs[LOG_COUNT] = { 0, 1, 2, 3, 4 };
12
+std::vector<LogEntry> Log::wholeLog;
18 13
 
19
-std::string Log::get(unsigned long i) {
20
-    assert(i < mHistory.size());
21
-    return mHistory.at(i);
14
+LogLevel& Log::get(int level) {
15
+    assert(level >= 0);
16
+    assert(level < LOG_COUNT);
17
+    return logs[level];
22 18
 }
23 19
 

+ 1
- 1
src/Menu.cpp Bestand weergeven

@@ -27,7 +27,7 @@ void Menu::showDialog(std::string msg, std::string btn1, std::string btn2,
27 27
     dialogState = false;
28 28
     dialogFunction = callback;
29 29
 
30
-    getLog() << dialogText << Log::endl;
30
+    Log::get(LOG_USER) << dialogText << Log::endl;
31 31
 }
32 32
 
33 33
 void Menu::ackDialog() {

+ 2
- 2
src/MenuFolder.cpp Bestand weergeven

@@ -58,7 +58,7 @@ int MenuFolder::init(Folder* folder, bool filter) {
58 58
             // Check maps for validity
59 59
             Loader::LoaderVersion version = Loader::checkFile(f.getPath());
60 60
             if (version == Loader::TR_UNKNOWN) {
61
-                getLog() << "Error: pak file '" << f.getName().c_str()
61
+                Log::get(LOG_ERROR) << "Error: pak file '" << f.getName().c_str()
62 62
                          << "' invalid" << Log::endl;
63 63
                 return true; // delete file from list
64 64
             }
@@ -117,7 +117,7 @@ void MenuFolder::loadOrOpen() {
117 117
             showDialog("Error reading subfolder!", "OK", "");
118 118
         }
119 119
     } else {
120
-        int error = getGame().loadLevel(mapFolder->getFile((unsigned long)mCursor
120
+        int error = Game::loadLevel(mapFolder->getFile((unsigned long)mCursor
121 121
                                         - 1 - mapFolder->folderCount()).getPath().c_str());
122 122
         if (error == 0) {
123 123
             visible = false;

+ 16
- 6
src/Mesh.cpp Bestand weergeven

@@ -58,7 +58,12 @@ void Mesh::prepare() {
58 58
     int vertIndex = 0;
59 59
     for (int i = 0; i < indicesBuff.size(); i++) {
60 60
         unsigned int texture = TextureManager::getTile(texturesBuff.at(i)).getTexture();
61
-        for (int v = 0; v < ((indicesBuff.at(i) == 0) ? 4 : 3); v++) {
61
+        for (int x = 0; x < ((indicesBuff.at(i) == 0) ? 4 : 3); x++) {
62
+            int v = x;
63
+            if (v == 0)
64
+                v = 2;
65
+            else if (v == 2)
66
+                v = 0;
62 67
             ind.push_back(vert.size());
63 68
             vert.push_back(verticesBuff.at(vertIndex + v));
64 69
             uvBuff.push_back(TextureManager::getTile(texturesBuff.at(i)).getUV(v));
@@ -66,8 +71,8 @@ void Mesh::prepare() {
66 71
         }
67 72
 
68 73
         if (indicesBuff.at(i) == 0) {
69
-            ind.push_back(ind.at(ind.size() - 2));
70
-            ind.push_back(ind.at(ind.size() - 5));
74
+            ind.push_back(ind.at(ind.size() - 4));
75
+            ind.push_back(ind.at(ind.size() - 3));
71 76
         }
72 77
 
73 78
         vertIndex += (indicesBuff.at(i) == 0) ? 4 : 3;
@@ -88,15 +93,20 @@ void Mesh::prepare() {
88 93
 
89 94
     vertIndex = 0;
90 95
     for (int i = 0; i < indicesColorBuff.size(); i++) {
91
-        for (int v = 0; v < ((indicesColorBuff.at(i) == 0) ? 4 : 3); v++) {
96
+        for (int x = 0; x < ((indicesColorBuff.at(i) == 0) ? 4 : 3); x++) {
97
+            int v = x;
98
+            if (v == 0)
99
+                v = 2;
100
+            else if (v == 2)
101
+                v = 0;
92 102
             indCol.push_back(vertCol.size());
93 103
             vertCol.push_back(verticesColorBuff.at(vertIndex + v));
94 104
             cols.push_back(colorsBuff.at(i));
95 105
         }
96 106
 
97 107
         if (indicesColorBuff.at(i) == 0) {
98
-            indCol.push_back(indCol.at(indCol.size() - 2));
99
-            indCol.push_back(indCol.at(indCol.size() - 5));
108
+            indCol.push_back(indCol.at(indCol.size() - 4));
109
+            indCol.push_back(indCol.at(indCol.size() - 3));
100 110
         }
101 111
 
102 112
         vertIndex += (indicesColorBuff.at(i) == 0) ? 4 : 3;

+ 5
- 5
src/Render.cpp Bestand weergeven

@@ -132,7 +132,7 @@ void Render::screenShot(const char* filenameBase) {
132 132
     }
133 133
 
134 134
     if (!stbi_write_png(f.c_str(), w, h, 3, buffer, 0)) {
135
-        getLog() << "Error saving image \"" << f << "\"!" << Log::endl;
135
+        Log::get(LOG_ERROR) << "Error saving image \"" << f << "\"!" << Log::endl;
136 136
     }
137 137
 
138 138
     delete [] image;
@@ -145,20 +145,20 @@ void Render::drawTexture(float x, float y, float w, float h, glm::vec4 color,
145 145
     std::vector<glm::vec2> uvs;
146 146
 
147 147
     vertices.push_back(glm::vec2(x, y + h));
148
-    vertices.push_back(glm::vec2(x, y));
149 148
     vertices.push_back(glm::vec2(x + w, y + h));
149
+    vertices.push_back(glm::vec2(x, y));
150 150
 
151 151
     vertices.push_back(glm::vec2(x + w, y));
152
-    vertices.push_back(glm::vec2(x + w, y + h));
153 152
     vertices.push_back(glm::vec2(x, y));
153
+    vertices.push_back(glm::vec2(x + w, y + h));
154 154
 
155 155
     uvs.push_back(glm::vec2(0.0f, 1.0f));
156
-    uvs.push_back(glm::vec2(0.0f, 0.0f));
157 156
     uvs.push_back(glm::vec2(1.0f, 1.0f));
157
+    uvs.push_back(glm::vec2(0.0f, 0.0f));
158 158
 
159 159
     uvs.push_back(glm::vec2(1.0f, 0.0f));
160
-    uvs.push_back(glm::vec2(1.0f, 1.0f));
161 160
     uvs.push_back(glm::vec2(0.0f, 0.0f));
161
+    uvs.push_back(glm::vec2(1.0f, 1.0f));
162 162
 
163 163
     static ShaderBuffer vert, uv;
164 164
     vert.bufferData(vertices);

+ 8
- 3
src/RoomMesh.cpp Bestand weergeven

@@ -39,7 +39,12 @@ void RoomMesh::prepare() {
39 39
     int vertIndex = 0;
40 40
     for (int i = 0; i < indicesBuff.size(); i++) {
41 41
         unsigned int texture = TextureManager::getTile(texturesBuff.at(i)).getTexture();
42
-        for (int v = 0; v < ((indicesBuff.at(i) == 0) ? 4 : 3); v++) {
42
+        for (int x = 0; x < ((indicesBuff.at(i) == 0) ? 4 : 3); x++) {
43
+            int v = x;
44
+            if (v == 0)
45
+                v = 2;
46
+            else if (v == 2)
47
+                v = 0;
43 48
             ind.push_back(vert.size());
44 49
             vert.push_back(verticesBuff.at(vertIndex + v));
45 50
             uvBuff.push_back(TextureManager::getTile(texturesBuff.at(i)).getUV(v));
@@ -47,8 +52,8 @@ void RoomMesh::prepare() {
47 52
         }
48 53
 
49 54
         if (indicesBuff.at(i) == 0) {
50
-            ind.push_back(ind.at(ind.size() - 2));
51
-            ind.push_back(ind.at(ind.size() - 5));
55
+            ind.push_back(ind.at(ind.size() - 4));
56
+            ind.push_back(ind.at(ind.size() - 3));
52 57
         }
53 58
 
54 59
         vertIndex += (indicesBuff.at(i) == 0) ? 4 : 3;

+ 2
- 2
src/TextureManager.cpp Bestand weergeven

@@ -245,7 +245,7 @@ int TextureManager::loadImage(std::string filename, TextureStorage s, int slot)
245 245
         unsigned char* data = stbi_load(filename.c_str(), &x, &y, &n, 0);
246 246
         if (data) {
247 247
             if ((n < 3) || (n > 4)) {
248
-                getLog() << "Image \"" << filename << "\" has unsupported format ("
248
+                Log::get(LOG_ERROR) << "Image \"" << filename << "\" has unsupported format ("
249 249
                          << n << ")!" << Log::endl;
250 250
                 stbi_image_free(data);
251 251
                 return -2;
@@ -255,7 +255,7 @@ int TextureManager::loadImage(std::string filename, TextureStorage s, int slot)
255 255
             stbi_image_free(data);
256 256
             return id;
257 257
         } else {
258
-            getLog() << "Can't load image \"" << filename << "\"!" << Log::endl;
258
+            Log::get(LOG_ERROR) << "Can't load image \"" << filename << "\"!" << Log::endl;
259 259
             return -1;
260 260
         }
261 261
     }

+ 9
- 7
src/UI.cpp Bestand weergeven

@@ -79,6 +79,8 @@ int UI::initialize() {
79 79
     io.KeyMap[ImGuiKey_Z] = zKey;
80 80
 
81 81
     io.RenderDrawListsFn = UI::renderImGui;
82
+    io.GetClipboardTextFn = Window::getClipboard;
83
+    io.SetClipboardTextFn = Window::setClipboard;
82 84
 
83 85
     // Load font texture
84 86
     //! \todo Use our own font subsystem instead of this?
@@ -172,7 +174,7 @@ void UI::eventsFinished() {
172 174
         while (!motionEvents.empty()) {
173 175
             auto i = motionEvents.front();
174 176
             if (!getMenu().isVisible()) {
175
-                getGame().handleMouseMotion(std::get<0>(i), std::get<1>(i),
177
+                Game::handleMouseMotion(std::get<0>(i), std::get<1>(i),
176 178
                                             std::get<2>(i), std::get<3>(i));
177 179
             }
178 180
             motionEvents.pop_front();
@@ -196,7 +198,7 @@ void UI::eventsFinished() {
196 198
             } else {
197 199
                 for (int n = forwardAction; n < ActionEventCount; n++) {
198 200
                     if (RunTime::getKeyBinding((ActionEvents)n) == std::get<0>(i))
199
-                        getGame().handleAction((ActionEvents)n, !std::get<1>(i));
201
+                        Game::handleAction((ActionEvents)n, !std::get<1>(i));
200 202
                 }
201 203
             }
202 204
         }
@@ -285,7 +287,7 @@ void UI::display() {
285 287
         static bool visibleAnim = false;
286 288
         static bool visibleSprite = false;
287 289
         if (ImGui::CollapsingHeader("Texture Viewer")) {
288
-            static bool game = getGame().isLoaded();
290
+            static bool game = Game::isLoaded();
289 291
             static int index = 0;
290 292
             ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
291 293
             ImGui::SliderInt("##texslide", &index, 0, TextureManager::.numTextures(
@@ -583,11 +585,11 @@ void UI::handleMouseScroll(int xrel, int yrel) {
583 585
 }
584 586
 
585 587
 void UI::handleControllerAxis(float value, KeyboardButton axis) {
586
-    getGame().handleControllerAxis(value, axis);
588
+    Game::handleControllerAxis(value, axis);
587 589
 }
588 590
 
589 591
 void UI::handleControllerButton(KeyboardButton button, bool released) {
590
-    getGame().handleControllerButton(button, released);
592
+    Game::handleControllerButton(button, released);
591 593
 }
592 594
 
593 595
 void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
@@ -597,7 +599,7 @@ void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
597 599
     static ShaderBuffer vert, uv, col;
598 600
 
599 601
     glEnable(GL_SCISSOR_TEST);
600
-    glDisable(GL_DEPTH_TEST);
602
+    Shader::set2DState(true);
601 603
 
602 604
     imguiShader.use();
603 605
     imguiShader.loadUniform(0, Window::getSize());
@@ -652,7 +654,7 @@ void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
652 654
     uv.unbind(1);
653 655
     col.unbind(2);
654 656
 
655
-    glEnable(GL_DEPTH_TEST);
657
+    Shader::set2DState(false);
656 658
     glDisable(GL_SCISSOR_TEST);
657 659
 }
658 660
 

+ 16
- 16
src/commands/Command.cpp Bestand weergeven

@@ -25,7 +25,7 @@ Command::~Command() {
25 25
 }
26 26
 
27 27
 void Command::printHelp() {
28
-    getLog() << "No help available!" << Log::endl;
28
+    Log::get(LOG_USER) << "No help available!" << Log::endl;
29 29
 }
30 30
 
31 31
 void Command::fillCommandList() {
@@ -65,17 +65,17 @@ int Command::command(std::string c) {
65 65
         command >> arg;
66 66
         if (arg.length() == 0) {
67 67
             // List all available commands
68
-            getLog() << "Available commands:" << Log::endl;
69
-            getLog() << std::right << std::setw(11);
70
-            getLog() << "help" << " - print command help" << Log::endl;
68
+            Log::get(LOG_USER) << "Available commands:" << Log::endl;
69
+            Log::get(LOG_USER) << std::right << std::setw(11);
70
+            Log::get(LOG_USER) << "help" << " - print command help" << Log::endl;
71 71
             for (auto& x : commands) {
72 72
                 if (x) {
73
-                    getLog() << std::right << std::setw(11);
74
-                    getLog() << x->name() << " - " << x->brief() << Log::endl;
73
+                    Log::get(LOG_USER) << std::right << std::setw(11);
74
+                    Log::get(LOG_USER) << x->name() << " - " << x->brief() << Log::endl;
75 75
                 }
76 76
             }
77
-            getLog() << "Use help COMMAND to get additional info" << Log::endl;
78
-            getLog() << "Pass BOOLs as true or false" << Log::endl;
77
+            Log::get(LOG_USER) << "Use help COMMAND to get additional info" << Log::endl;
78
+            Log::get(LOG_USER) << "Pass BOOLs as true or false" << Log::endl;
79 79
             return 0;
80 80
         } else {
81 81
             // Show help for a specific command
@@ -87,7 +87,7 @@ int Command::command(std::string c) {
87 87
                     }
88 88
                 }
89 89
             }
90
-            getLog() << "Unknown command: \"" << arg << "\"" << Log::endl;
90
+            Log::get(LOG_USER) << "Unknown command: \"" << arg << "\"" << Log::endl;
91 91
             return -1;
92 92
         }
93 93
     }
@@ -101,17 +101,17 @@ int Command::command(std::string c) {
101 101
         }
102 102
     }
103 103
 
104
-    getLog() << "Unknown command: \"" << cmd << "\"" << Log::endl;
104
+    Log::get(LOG_USER) << "Unknown command: \"" << cmd << "\"" << Log::endl;
105 105
     return -1;
106 106
 }
107 107
 
108 108
 int Command::executeFile(std::string file) {
109 109
     std::string configFile = expandHomeDirectory(file);
110
-    getLog() << "Loading config from \"" << configFile << "\"..." << Log::endl;
110
+    Log::get(LOG_INFO) << "Loading config from \"" << configFile << "\"..." << Log::endl;
111 111
 
112 112
     std::ifstream f(configFile);
113 113
     if (!f) {
114
-        getLog() << "Could not open file!" << Log::endl;
114
+        Log::get(LOG_ERROR) << "Could not open file!" << Log::endl;
115 115
         return -1;
116 116
     }
117 117
 
@@ -121,7 +121,7 @@ int Command::executeFile(std::string file) {
121 121
 
122 122
         int error = Command::command(line);
123 123
         if (error != 0)
124
-            getLog() << "Error Code: " << error << Log::endl;
124
+            Log::get(LOG_ERROR) << "Error Code: " << error << Log::endl;
125 125
     }
126 126
 
127 127
     f.close();
@@ -156,9 +156,9 @@ std::string Command::autoComplete(std::string begin) {
156 156
     } else {
157 157
         std::string common = candidates.at(0);
158 158
         for (int i = 0; i < candidates.size(); i++) {
159
-            getLog() << candidates.at(i);
159
+            Log::get(LOG_USER) << candidates.at(i);
160 160
             if (i < (candidates.size() - 1))
161
-                getLog() << "/";
161
+                Log::get(LOG_USER) << "/";
162 162
 
163 163
             for (int c = 0; (c < common.size()) && (c < candidates.at(i).size()); c++) {
164 164
                 if (common.at(c) != candidates.at(i).at(c)) {
@@ -167,7 +167,7 @@ std::string Command::autoComplete(std::string begin) {
167 167
                 }
168 168
             }
169 169
         }
170
-        getLog() << Log::endl;
170
+        Log::get(LOG_USER) << Log::endl;
171 171
         return common;
172 172
     }
173 173
 }

+ 20
- 20
src/commands/CommandBind.cpp Bestand weergeven

@@ -19,40 +19,40 @@ std::string CommandBind::brief() {
19 19
 }
20 20
 
21 21
 void CommandBind::printHelp() {
22
-    getLog() << "bind-Command Usage:" << Log::endl;
23
-    getLog() << "  bind ACTION KEY" << Log::endl;
24
-    getLog() << "Available Actions:" << Log::endl;
25
-    getLog() << "  menu" << Log::endl;
26
-    getLog() << "  debug" << Log::endl;
27
-    getLog() << "  forward" << Log::endl;
28
-    getLog() << "  backward" << Log::endl;
29
-    getLog() << "  left" << Log::endl;
30
-    getLog() << "  right" << Log::endl;
31
-    getLog() << "  jump" << Log::endl;
32
-    getLog() << "  crouch" << Log::endl;
33
-    getLog() << "  use" << Log::endl;
34
-    getLog() << "  holster" << Log::endl;
35
-    getLog() << "  walk" << Log::endl;
36
-    getLog() << "Key-Format:" << Log::endl;
37
-    getLog() << "  'a' or '1'    for character/number keys" << Log::endl;
38
-    getLog() << "  \"leftctrl\"  for symbols and special keys" << Log::endl;
22
+    Log::get(LOG_USER) << "bind-Command Usage:" << Log::endl;
23
+    Log::get(LOG_USER) << "  bind ACTION KEY" << Log::endl;
24
+    Log::get(LOG_USER) << "Available Actions:" << Log::endl;
25
+    Log::get(LOG_USER) << "  menu" << Log::endl;
26
+    Log::get(LOG_USER) << "  debug" << Log::endl;
27
+    Log::get(LOG_USER) << "  forward" << Log::endl;
28
+    Log::get(LOG_USER) << "  backward" << Log::endl;
29
+    Log::get(LOG_USER) << "  left" << Log::endl;
30
+    Log::get(LOG_USER) << "  right" << Log::endl;
31
+    Log::get(LOG_USER) << "  jump" << Log::endl;
32
+    Log::get(LOG_USER) << "  crouch" << Log::endl;
33
+    Log::get(LOG_USER) << "  use" << Log::endl;
34
+    Log::get(LOG_USER) << "  holster" << Log::endl;
35
+    Log::get(LOG_USER) << "  walk" << Log::endl;
36
+    Log::get(LOG_USER) << "Key-Format:" << Log::endl;
37
+    Log::get(LOG_USER) << "  'a' or '1'    for character/number keys" << Log::endl;
38
+    Log::get(LOG_USER) << "  \"leftctrl\"  for symbols and special keys" << Log::endl;
39 39
 }
40 40
 
41 41
 int CommandBind::execute(std::istream& args) {
42 42
     std::string a, b;
43 43
     if (!(args >> a >> b)) {
44
-        getLog() << "Invalid use of bind-command" << Log::endl;
44
+        Log::get(LOG_USER) << "Invalid use of bind-command" << Log::endl;
45 45
         return -1;
46 46
     } else {
47 47
         ActionEvents e = stringToActionEvent(a);
48 48
         if (e == ActionEventCount) {
49
-            getLog() << "bind-Error: Unknown action (" << a << ")" << Log::endl;
49
+            Log::get(LOG_USER) << "bind-Error: Unknown action (" << a << ")" << Log::endl;
50 50
             return -2;
51 51
         }
52 52
 
53 53
         KeyboardButton c = stringToKeyboardButton(b);
54 54
         if (c == unknownKey) {
55
-            getLog() << "bind-Error: Unknown key (" << b << ")" << Log::endl;
55
+            Log::get(LOG_USER) << "bind-Error: Unknown key (" << b << ")" << Log::endl;
56 56
             return -3;
57 57
         }
58 58
 

+ 8
- 8
src/commands/CommandEngine.cpp Bestand weergeven

@@ -23,19 +23,19 @@ std::string CommandLoad::brief() {
23 23
 }
24 24
 
25 25
 void CommandLoad::printHelp() {
26
-    getLog() << "load-Command Usage:" << Log::endl;
27
-    getLog() << "  load /path/to/level" << Log::endl;
26
+    Log::get(LOG_USER) << "load-Command Usage:" << Log::endl;
27
+    Log::get(LOG_USER) << "  load /path/to/level" << Log::endl;
28 28
 }
29 29
 
30 30
 int CommandLoad::execute(std::istream& args) {
31 31
     if (!RunTime::isRunning()) {
32
-        getLog() << "Use load command interactively!" << Log::endl;
32
+        Log::get(LOG_USER) << "Use load command interactively!" << Log::endl;
33 33
         return -1;
34 34
     }
35 35
 
36 36
     std::string map;
37 37
     args >> map;
38
-    int error = getGame().loadLevel(map.c_str());
38
+    int error = Game::loadLevel(map.c_str());
39 39
     return error;
40 40
 }
41 41
 
@@ -50,14 +50,14 @@ std::string CommandScreenshot::brief() {
50 50
 }
51 51
 
52 52
 void CommandScreenshot::printHelp() {
53
-    getLog() << "sshot-Command Usage:" << Log::endl;
54
-    getLog() << "  sshot" << Log::endl;
55
-    getLog() << "You wont be able to capture imgui..." << Log::endl;
53
+    Log::get(LOG_USER) << "sshot-Command Usage:" << Log::endl;
54
+    Log::get(LOG_USER) << "  sshot" << Log::endl;
55
+    Log::get(LOG_USER) << "You wont be able to capture imgui..." << Log::endl;
56 56
 }
57 57
 
58 58
 int CommandScreenshot::execute(std::istream& args) {
59 59
     if (!RunTime::isRunning()) {
60
-        getLog() << "Use sshot command interactively!" << Log::endl;
60
+        Log::get(LOG_USER) << "Use sshot command interactively!" << Log::endl;
61 61
         return -1;
62 62
     }
63 63
 

+ 7
- 7
src/commands/CommandGame.cpp Bestand weergeven

@@ -21,12 +21,12 @@ std::string CommandPos::brief() {
21 21
 }
22 22
 
23 23
 int CommandPos::execute(std::istream& args) {
24
-    if ((!RunTime::isRunning()) || (!getGame().isLoaded())) {
25
-        getLog() << "Use pos command interactively!" << Log::endl;
24
+    if ((!RunTime::isRunning()) || (!Game::isLoaded())) {
25
+        Log::get(LOG_USER) << "Use pos command interactively!" << Log::endl;
26 26
         return -1;
27 27
     }
28 28
 
29
-    getGame().getLara().print();
29
+    Game::getLara().print();
30 30
     return 0;
31 31
 }
32 32
 
@@ -41,8 +41,8 @@ std::string CommandViewmodel::brief() {
41 41
 }
42 42
 
43 43
 int CommandViewmodel::execute(std::istream& args) {
44
-    if ((!RunTime::isRunning()) || (!getGame().isLoaded())) {
45
-        getLog() << "Use viewmodel command interactively!" << Log::endl;
44
+    if ((!RunTime::isRunning()) || (!Game::isLoaded())) {
45
+        Log::get(LOG_USER) << "Use viewmodel command interactively!" << Log::endl;
46 46
         return -1;
47 47
     }
48 48
 
@@ -53,10 +53,10 @@ int CommandViewmodel::execute(std::istream& args) {
53 53
     unsigned int n = atoi(s.c_str());
54 54
 
55 55
     if (n < getWorld().sizeSkeletalModel()) {
56
-        getGame().getLara().setSkeletalModel(n);
56
+        Game::getLara().setSkeletalModel(n);
57 57
         return 0;
58 58
     } else {
59
-        getLog() << "Invalid SkeletalModel index!" << Log::endl;
59
+        Log::get(LOG_USER) << "Invalid SkeletalModel index!" << Log::endl;
60 60
         return -2;
61 61
     }
62 62
 }

+ 13
- 13
src/commands/CommandMove.cpp Bestand weergeven

@@ -20,34 +20,34 @@ std::string CommandMove::brief() {
20 20
 }
21 21
 
22 22
 void CommandMove::printHelp() {
23
-    getLog() << "move-Command Usage:" << Log::endl;
24
-    getLog() << "  move COMMAND" << Log::endl;
25
-    getLog() << "Where COMMAND is one of the following:" << Log::endl;
26
-    getLog() << "  walk" << Log::endl;
27
-    getLog() << "  fly" << Log::endl;
28
-    getLog() << "  noclip" << Log::endl;
23
+    Log::get(LOG_USER) << "move-Command Usage:" << Log::endl;
24
+    Log::get(LOG_USER) << "  move COMMAND" << Log::endl;
25
+    Log::get(LOG_USER) << "Where COMMAND is one of the following:" << Log::endl;
26
+    Log::get(LOG_USER) << "  walk" << Log::endl;
27
+    Log::get(LOG_USER) << "  fly" << Log::endl;
28
+    Log::get(LOG_USER) << "  noclip" << Log::endl;
29 29
 }
30 30
 
31 31
 int CommandMove::execute(std::istream& args) {
32
-    if ((!RunTime::isRunning()) || (!getGame().isLoaded())) {
33
-        getLog() << "Use move command interactively!" << Log::endl;
32
+    if ((!RunTime::isRunning()) || (!Game::isLoaded())) {
33
+        Log::get(LOG_USER) << "Use move command interactively!" << Log::endl;
34 34
         return -1;
35 35
     }
36 36
 
37 37
     std::string s;
38 38
     args >> s;
39 39
     if (s.compare("walk") == 0) {
40
-        getGame().getLara().setMoveType(Entity::MoveTypeWalk);
40
+        Game::getLara().setMoveType(Entity::MoveTypeWalk);
41 41
     } else if (s.compare("fly") == 0) {
42
-        getGame().getLara().setMoveType(Entity::MoveTypeFly);
42
+        Game::getLara().setMoveType(Entity::MoveTypeFly);
43 43
     } else if (s.compare("noclip") == 0) {
44
-        getGame().getLara().setMoveType(Entity::MoveTypeNoClipping);
44
+        Game::getLara().setMoveType(Entity::MoveTypeNoClipping);
45 45
     } else {
46
-        getLog() << "Invalid use of move command (" << s << ")!" << Log::endl;
46
+        Log::get(LOG_USER) << "Invalid use of move command (" << s << ")!" << Log::endl;
47 47
         return -2;
48 48
     }
49 49
 
50
-    getLog() << s  << "ing" << Log::endl;
50
+    Log::get(LOG_USER) << s  << "ing" << Log::endl;
51 51
     return 0;
52 52
 }
53 53
 

+ 12
- 12
src/commands/CommandRender.cpp Bestand weergeven

@@ -19,13 +19,13 @@ std::string CommandMode::brief() {
19 19
 }
20 20
 
21 21
 void CommandMode::printHelp() {
22
-    getLog() << "mode-Command Usage:" << Log::endl;
23
-    getLog() << "  mode MODE" << Log::endl;
24
-    getLog() << "Where MODE is one of the following:" << Log::endl;
25
-    getLog() << "  wireframe" << Log::endl;
26
-    getLog() << "  solid" << Log::endl;
27
-    getLog() << "  texture" << Log::endl;
28
-    getLog() << "  titlescreen" << Log::endl;
22
+    Log::get(LOG_USER) << "mode-Command Usage:" << Log::endl;
23
+    Log::get(LOG_USER) << "  mode MODE" << Log::endl;
24
+    Log::get(LOG_USER) << "Where MODE is one of the following:" << Log::endl;
25
+    Log::get(LOG_USER) << "  wireframe" << Log::endl;
26
+    Log::get(LOG_USER) << "  solid" << Log::endl;
27
+    Log::get(LOG_USER) << "  texture" << Log::endl;
28
+    Log::get(LOG_USER) << "  titlescreen" << Log::endl;
29 29
 
30 30
 }
31 31
 
@@ -35,18 +35,18 @@ int CommandMode::execute(std::istream& args) {
35 35
 
36 36
     if (s == "wireframe") {
37 37
         Render::setMode(RenderMode::Wireframe);
38
-        getLog() << "Wireframe mode" << Log::endl;
38
+        Log::get(LOG_USER) << "Wireframe mode" << Log::endl;
39 39
     } else if (s == "solid") {
40 40
         Render::setMode(RenderMode::Solid);
41
-        getLog() << "Solid mode" << Log::endl;
41
+        Log::get(LOG_USER) << "Solid mode" << Log::endl;
42 42
     } else if (s == "texture") {
43 43
         Render::setMode(RenderMode::Texture);
44
-        getLog() << "Texture Mode" << Log::endl;
44
+        Log::get(LOG_USER) << "Texture Mode" << Log::endl;
45 45
     } else if (s == "titlescreen") {
46 46
         Render::setMode(RenderMode::LoadScreen);
47
-        getLog() << "Titlescreen mode" << Log::endl;
47
+        Log::get(LOG_USER) << "Titlescreen mode" << Log::endl;
48 48
     } else {
49
-        getLog() << "Invalid use of mode command (" << s << ")!" << Log::endl;
49
+        Log::get(LOG_USER) << "Invalid use of mode command (" << s << ")!" << Log::endl;
50 50
         return -2;
51 51
     }
52 52
 

+ 69
- 71
src/commands/CommandSet.cpp Bestand weergeven

@@ -24,45 +24,43 @@ std::string CommandSet::brief() {
24 24
 }
25 25
 
26 26
 void CommandSet::printHelp() {
27
-    getLog() << "set-Command Usage:" << Log::endl;
28
-    getLog() << "  set VAR VAL" << Log::endl;
29
-    getLog() << "Available Variables:" << Log::endl;
30
-    getLog() << "  basedir    STRING" << Log::endl;
31
-    getLog() << "  pakdir     STRING" << Log::endl;
32
-    getLog() << "  audiodir   STRING" << Log::endl;
33
-    getLog() << "  datadir    STRING" << Log::endl;
34
-    getLog() << "  font       STRING" << Log::endl;
35
-    getLog() << "  size       INT INT" << Log::endl;
36
-    getLog() << "  fullscreen BOOL" << Log::endl;
37
-    getLog() << "  audio      BOOL" << Log::endl;
38
-    getLog() << "  volume     BOOL" << Log::endl;
39
-    getLog() << "  mouse_x    FLOAT" << Log::endl;
40
-    getLog() << "  mouse_y    FLOAT" << Log::endl;
41
-    getLog() << "  fps        BOOL" << Log::endl;
42
-    getLog() << "Enclose STRINGs with \"\"!" << Log::endl;
27
+    Log::get(LOG_USER) << "set-Command Usage:" << Log::endl;
28
+    Log::get(LOG_USER) << "  set VAR VAL" << Log::endl;
29
+    Log::get(LOG_USER) << "Available Variables:" << Log::endl;
30
+    Log::get(LOG_USER) << "  basedir    STRING" << Log::endl;
31
+    Log::get(LOG_USER) << "  pakdir     STRING" << Log::endl;
32
+    Log::get(LOG_USER) << "  audiodir   STRING" << Log::endl;
33
+    Log::get(LOG_USER) << "  datadir    STRING" << Log::endl;
34
+    Log::get(LOG_USER) << "  font       STRING" << Log::endl;
35
+    Log::get(LOG_USER) << "  size       INT INT" << Log::endl;
36
+    Log::get(LOG_USER) << "  fullscreen BOOL" << Log::endl;
37
+    Log::get(LOG_USER) << "  audio      BOOL" << Log::endl;
38
+    Log::get(LOG_USER) << "  volume     BOOL" << Log::endl;
39
+    Log::get(LOG_USER) << "  mouse_x    FLOAT" << Log::endl;
40
+    Log::get(LOG_USER) << "  mouse_y    FLOAT" << Log::endl;
41
+    Log::get(LOG_USER) << "  fps        BOOL" << Log::endl;
42
+    Log::get(LOG_USER) << "Enclose STRINGs with \"\"!" << Log::endl;
43 43
 }
44 44
 
45
-namespace {
46
-    std::string expandNames(std::string s) {
47
-        // Remove quotes
48
-        if ((s.length() >= 3) &&
49
-            (((s[0] == '"') && (s[s.length() - 1] == '"'))
50
-             || ((s[0] == '\'') && (s[s.length() - 1] == '\'')))) {
51
-            s.erase(0, 1);
52
-            s.erase(s.length() - 1, 1);
53
-        }
45
+static std::string expandNames(std::string s) {
46
+    // Remove quotes
47
+    if ((s.length() >= 3) &&
48
+        (((s[0] == '"') && (s[s.length() - 1] == '"'))
49
+         || ((s[0] == '\'') && (s[s.length() - 1] == '\'')))) {
50
+        s.erase(0, 1);
51
+        s.erase(s.length() - 1, 1);
52
+    }
54 53
 
55
-        // Expand Names
56
-        s = findAndReplace(s, "$(pakdir)", RunTime::getPakDir());
57
-        s = findAndReplace(s, "$(audiodir)", RunTime::getAudioDir());
58
-        s = findAndReplace(s, "$(datadir)", RunTime::getDataDir());
59
-        s = findAndReplace(s, "$(basedir)", RunTime::getBaseDir());
54
+    // Expand Names
55
+    s = findAndReplace(s, "$(pakdir)", RunTime::getPakDir());
56
+    s = findAndReplace(s, "$(audiodir)", RunTime::getAudioDir());
57
+    s = findAndReplace(s, "$(datadir)", RunTime::getDataDir());
58
+    s = findAndReplace(s, "$(basedir)", RunTime::getBaseDir());
60 59
 
61
-        // Full path
62
-        s = expandHomeDirectory(s);
60
+    // Full path
61
+    s = expandHomeDirectory(s);
63 62
 
64
-        return s;
65
-    }
63
+    return s;
66 64
 }
67 65
 
68 66
 int CommandSet::execute(std::istream& args) {
@@ -72,49 +70,49 @@ int CommandSet::execute(std::istream& args) {
72 70
     if (var.compare("size") == 0) {
73 71
         unsigned int w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT;
74 72
         if (!(args >> w >> h)) {
75
-            getLog() << "set-size-Error: Invalid value(s)" << Log::endl;
73
+            Log::get(LOG_USER) << "set-size-Error: Invalid value(s)" << Log::endl;
76 74
             return -2;
77 75
         }
78 76
         Window::setSize(glm::i32vec2(w, h));
79 77
     } else if (var.compare("fullscreen") == 0) {
80 78
         bool fullscreen = false;
81 79
         if (!(args >> fullscreen)) {
82
-            getLog() << "set-fullscreen-Error: Invalid value" << Log::endl;
80
+            Log::get(LOG_USER) << "set-fullscreen-Error: Invalid value" << Log::endl;
83 81
             return -3;
84 82
         }
85 83
         Window::setFullscreen(fullscreen);
86 84
     } else if (var.compare("audio") == 0) {
87 85
         bool audio = false;
88 86
         if (!(args >> audio)) {
89
-            getLog() << "set-audio-Error: Invalid value" << Log::endl;
87
+            Log::get(LOG_USER) << "set-audio-Error: Invalid value" << Log::endl;
90 88
             return -4;
91 89
         }
92 90
         Sound::setEnabled(audio);
93 91
     } else if (var.compare("volume") == 0) {
94 92
         float vol = 1.0f;
95 93
         if (!(args >> vol)) {
96
-            getLog() << "set-volume-Error: Invalid value" << Log::endl;
94
+            Log::get(LOG_USER) << "set-volume-Error: Invalid value" << Log::endl;
97 95
             return -5;
98 96
         }
99 97
         Sound::setVolume(vol);
100 98
     } else if (var.compare("mouse_x") == 0) {
101 99
         float sense = 1.0f;
102 100
         if (!(args >> sense)) {
103
-            getLog() << "set-mouse_x-Error: Invalid value" << Log::endl;
101
+            Log::get(LOG_USER) << "set-mouse_x-Error: Invalid value" << Log::endl;
104 102
             return -6;
105 103
         }
106 104
         Camera::setSensitivityX(glm::radians(sense));
107 105
     } else if (var.compare("mouse_y") == 0) {
108 106
         float sense = 1.0f;
109 107
         if (!(args >> sense)) {
110
-            getLog() << "set-mouse_y-Error: Invalid value" << Log::endl;
108
+            Log::get(LOG_USER) << "set-mouse_y-Error: Invalid value" << Log::endl;
111 109
             return -7;
112 110
         }
113 111
         Camera::setSensitivityY(glm::radians(sense));
114 112
     } else if (var.compare("fps") == 0) {
115 113
         bool fps = false;
116 114
         if (!(args >> fps)) {
117
-            getLog() << "set-fps-Error: Invalid value" << Log::endl;
115
+            Log::get(LOG_USER) << "set-fps-Error: Invalid value" << Log::endl;
118 116
             return -8;
119 117
         }
120 118
         RunTime::setShowFPS(fps);
@@ -139,9 +137,9 @@ int CommandSet::execute(std::istream& args) {
139 137
         args >> temp;
140 138
         int error = Font::initialize(expandNames(temp));
141 139
         if (error != 0)
142
-            getLog() << "Error initializing font: " << expandNames(temp) << "(" << error << ")" << Log::endl;
140
+            Log::get(LOG_USER) << "Error initializing font: " << expandNames(temp) << "(" << error << ")" << Log::endl;
143 141
     } else {
144
-        getLog() << "set-Error: Unknown variable (" << var.c_str() << ")" << Log::endl;
142
+        Log::get(LOG_USER) << "set-Error: Unknown variable (" << var.c_str() << ")" << Log::endl;
145 143
         return -1;
146 144
     }
147 145
 
@@ -157,21 +155,21 @@ std::string CommandGet::brief() {
157 155
 }
158 156
 
159 157
 void CommandGet::printHelp() {
160
-    getLog() << "get-Command Usage:" << Log::endl;
161
-    getLog() << "  get VAR" << Log::endl;
162
-    getLog() << "Available Variables:" << Log::endl;
163
-    getLog() << "  basedir" << Log::endl;
164
-    getLog() << "  pakdir" << Log::endl;
165
-    getLog() << "  audiodir" << Log::endl;
166
-    getLog() << "  datadir" << Log::endl;
167
-    getLog() << "  font" << Log::endl;
168
-    getLog() << "  size" << Log::endl;
169
-    getLog() << "  fullscreen" << Log::endl;
170
-    getLog() << "  audio" << Log::endl;
171
-    getLog() << "  volume" << Log::endl;
172
-    getLog() << "  mouse_x" << Log::endl;
173
-    getLog() << "  mouse_y" << Log::endl;
174
-    getLog() << "  fps" << Log::endl;
158
+    Log::get(LOG_USER) << "get-Command Usage:" << Log::endl;
159
+    Log::get(LOG_USER) << "  get VAR" << Log::endl;
160
+    Log::get(LOG_USER) << "Available Variables:" << Log::endl;
161
+    Log::get(LOG_USER) << "  basedir" << Log::endl;
162
+    Log::get(LOG_USER) << "  pakdir" << Log::endl;
163
+    Log::get(LOG_USER) << "  audiodir" << Log::endl;
164
+    Log::get(LOG_USER) << "  datadir" << Log::endl;
165
+    Log::get(LOG_USER) << "  font" << Log::endl;
166
+    Log::get(LOG_USER) << "  size" << Log::endl;
167
+    Log::get(LOG_USER) << "  fullscreen" << Log::endl;
168
+    Log::get(LOG_USER) << "  audio" << Log::endl;
169
+    Log::get(LOG_USER) << "  volume" << Log::endl;
170
+    Log::get(LOG_USER) << "  mouse_x" << Log::endl;
171
+    Log::get(LOG_USER) << "  mouse_y" << Log::endl;
172
+    Log::get(LOG_USER) << "  fps" << Log::endl;
175 173
 }
176 174
 
177 175
 int CommandGet::execute(std::istream& args) {
@@ -179,31 +177,31 @@ int CommandGet::execute(std::istream& args) {
179 177
     args >> var;
180 178
 
181 179
     if (var.compare("size") == 0) {
182
-        getLog() << Window::getSize() << Log::endl;
180
+        Log::get(LOG_USER) << Window::getSize() << Log::endl;
183 181
     } else if (var.compare("fullscreen") == 0) {
184
-        getLog() << Window::getFullscreen() << Log::endl;
182
+        Log::get(LOG_USER) << Window::getFullscreen() << Log::endl;
185 183
     } else if (var.compare("audio") == 0) {
186
-        getLog() << Sound::getEnabled() << Log::endl;
184
+        Log::get(LOG_USER) << Sound::getEnabled() << Log::endl;
187 185
     } else if (var.compare("volume") == 0) {
188
-        getLog() << Sound::getVolume() << Log::endl;
186
+        Log::get(LOG_USER) << Sound::getVolume() << Log::endl;
189 187
     } else if (var.compare("mouse_x") == 0) {
190
-        getLog() << glm::degrees(Camera::getSensitivityX()) << Log::endl;
188
+        Log::get(LOG_USER) << glm::degrees(Camera::getSensitivityX()) << Log::endl;
191 189
     } else if (var.compare("mouse_y") == 0) {
192
-        getLog() << glm::degrees(Camera::getSensitivityY()) << Log::endl;
190
+        Log::get(LOG_USER) << glm::degrees(Camera::getSensitivityY()) << Log::endl;
193 191
     } else if (var.compare("fps") == 0) {
194
-        getLog() << RunTime::getShowFPS() << Log::endl;
192
+        Log::get(LOG_USER) << RunTime::getShowFPS() << Log::endl;
195 193
     } else if (var.compare("basedir") == 0) {
196
-        getLog() << RunTime::getBaseDir() << Log::endl;
194
+        Log::get(LOG_USER) << RunTime::getBaseDir() << Log::endl;
197 195
     } else if (var.compare("pakdir") == 0) {
198
-        getLog() << RunTime::getPakDir() << Log::endl;
196
+        Log::get(LOG_USER) << RunTime::getPakDir() << Log::endl;
199 197
     } else if (var.compare("audiodir") == 0) {
200
-        getLog() << RunTime::getAudioDir() << Log::endl;
198
+        Log::get(LOG_USER) << RunTime::getAudioDir() << Log::endl;
201 199
     } else if (var.compare("datadir") == 0) {
202
-        getLog() << RunTime::getDataDir() << Log::endl;
200
+        Log::get(LOG_USER) << RunTime::getDataDir() << Log::endl;
203 201
     } else if (var.compare("font") == 0) {
204
-        getLog() << Font::getFontName() << Log::endl;
202
+        Log::get(LOG_USER) << Font::getFontName() << Log::endl;
205 203
     } else {
206
-        getLog() << "get-Error: Unknown variable (" << var << ")" << Log::endl;
204
+        Log::get(LOG_USER) << "get-Error: Unknown variable (" << var << ")" << Log::endl;
207 205
         return -1;
208 206
     }
209 207
 

+ 52
- 52
src/loader/LoaderTR2.cpp Bestand weergeven

@@ -96,9 +96,9 @@ void LoaderTR2::loadPaletteTextiles() {
96 96
     }
97 97
 
98 98
     if (numTextiles > 0)
99
-        getLog() << "LoaderTR2: Found " << numTextiles << " Textures!" << Log::endl;
99
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numTextiles << " Textures!" << Log::endl;
100 100
     else
101
-        getLog() << "LoaderTR2: No Textures in this level?!" << Log::endl;
101
+        Log::get(LOG_INFO) << "LoaderTR2: No Textures in this level?!" << Log::endl;
102 102
 }
103 103
 
104 104
 void LoaderTR2::loadTextures() {
@@ -138,9 +138,9 @@ void LoaderTR2::loadTextures() {
138 138
     }
139 139
 
140 140
     if (numObjectTextures > 0)
141
-        getLog() << "LoaderTR2: Found " << numObjectTextures << " Textiles!" << Log::endl;
141
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numObjectTextures << " Textiles!" << Log::endl;
142 142
     else
143
-        getLog() << "LoaderTR2: No Textiles in this level?!" << Log::endl;
143
+        Log::get(LOG_INFO) << "LoaderTR2: No Textiles in this level?!" << Log::endl;
144 144
 }
145 145
 
146 146
 void LoaderTR2::loadAnimatedTextures() {
@@ -155,7 +155,7 @@ void LoaderTR2::loadAnimatedTextures() {
155 155
     for (unsigned int a = 0; a < numAnimatedTextures; a++) {
156 156
         int count = animatedTextures.at(pos) + 1;
157 157
         if ((pos + count) >= numWords) {
158
-            getLog() << "LoaderTR2: Invalid AnimatedTextures ("
158
+            Log::get(LOG_DEBUG) << "LoaderTR2: Invalid AnimatedTextures ("
159 159
                      << pos + count << " >= " << numWords << ")!" << Log::endl;
160 160
             return;
161 161
         }
@@ -168,12 +168,12 @@ void LoaderTR2::loadAnimatedTextures() {
168 168
     }
169 169
 
170 170
     if ((numAnimatedTextures > 0) || (numWords > 0))
171
-        getLog() << "LoaderTR2: Found " << numAnimatedTextures << " Animated Textures!" << Log::endl;
171
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numAnimatedTextures << " Animated Textures!" << Log::endl;
172 172
     else
173
-        getLog() << "LoaderTR2: No Animated Textures in this level?!" << Log::endl;
173
+        Log::get(LOG_INFO) << "LoaderTR2: No Animated Textures in this level?!" << Log::endl;
174 174
 
175 175
     if (pos != numWords)
176
-        getLog() << "LoaderTR2: Extra bytes at end of AnimatedTextures?!" << Log::endl;
176
+        Log::get(LOG_DEBUG) << "LoaderTR2: Extra bytes at end of AnimatedTextures?!" << Log::endl;
177 177
 }
178 178
 
179 179
 // ---- Rooms ----
@@ -406,15 +406,15 @@ void LoaderTR2::loadRooms() {
406 406
         // Sanity check
407 407
         if ((numPortals == 0) && (numVertices == 0)
408 408
             && (numRectangles == 0) && (numTriangles == 0))
409
-            getLog() << "LoaderTR2: Room " << i << " seems invalid: " << numPortals << "p "
409
+            Log::get(LOG_DEBUG) << "LoaderTR2: Room " << i << " seems invalid: " << numPortals << "p "
410 410
                      << numRectangles << "r " << numTriangles << "t " << numVertices
411 411
                      << "v" << Log::endl;
412 412
     }
413 413
 
414 414
     if (numRooms > 0)
415
-        getLog() << "LoaderTR2: Found " << numRooms << " Rooms!" << Log::endl;
415
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numRooms << " Rooms!" << Log::endl;
416 416
     else
417
-        getLog() << "LoaderTR2: No Rooms in this Level?!" << Log::endl;
417
+        Log::get(LOG_INFO) << "LoaderTR2: No Rooms in this Level?!" << Log::endl;
418 418
 }
419 419
 
420 420
 void LoaderTR2::loadFloorData() {
@@ -426,9 +426,9 @@ void LoaderTR2::loadFloorData() {
426 426
     }
427 427
 
428 428
     if (numFloorData > 0)
429
-        getLog() << "LoaderTR2: Found " << numFloorData << " words FloorData, unimplemented!" << Log::endl;
429
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numFloorData << " words FloorData, unimplemented!" << Log::endl;
430 430
     else
431
-        getLog() << "LoaderTR2: No FloorData in this level?!" << Log::endl;
431
+        Log::get(LOG_INFO) << "LoaderTR2: No FloorData in this level?!" << Log::endl;
432 432
 }
433 433
 
434 434
 void LoaderTR2::loadSprites() {
@@ -468,10 +468,10 @@ void LoaderTR2::loadSprites() {
468 468
     }
469 469
 
470 470
     if ((numSpriteTextures > 0) || (numSpriteSequences > 0))
471
-        getLog() << "LoaderTR2: Found " << numSpriteTextures << " Sprites in " << numSpriteSequences <<
471
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numSpriteTextures << " Sprites in " << numSpriteSequences <<
472 472
                  " Sequences!" << Log::endl;
473 473
     else
474
-        getLog() << "LoaderTR2: No Sprites in this level?!" << Log::endl;
474
+        Log::get(LOG_INFO) << "LoaderTR2: No Sprites in this level?!" << Log::endl;
475 475
 }
476 476
 
477 477
 // ---- Meshes ----
@@ -493,7 +493,7 @@ void LoaderTR2::loadMeshes() {
493 493
         uint32_t meshPointer = file.readU32();
494 494
 
495 495
         if (numMeshData < (meshPointer / 2)) {
496
-            getLog() << "LoaderTR2: Invalid Mesh: "
496
+            Log::get(LOG_DEBUG) << "LoaderTR2: Invalid Mesh: "
497 497
                      << (meshPointer / 2) << " > " << numMeshData << Log::endl;
498 498
             continue;
499 499
         }
@@ -601,9 +601,9 @@ void LoaderTR2::loadMeshes() {
601 601
     }
602 602
 
603 603
     if (numMeshPointers > 0)
604
-        getLog() << "LoaderTR2: Found " << numMeshPointers << " Meshes!" << Log::endl;
604
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numMeshPointers << " Meshes!" << Log::endl;
605 605
     else
606
-        getLog() << "LoaderTR2: No Meshes in this level?!" << Log::endl;
606
+        Log::get(LOG_INFO) << "LoaderTR2: No Meshes in this level?!" << Log::endl;
607 607
 }
608 608
 
609 609
 void LoaderTR2::loadStaticMeshes() {
@@ -640,9 +640,9 @@ void LoaderTR2::loadStaticMeshes() {
640 640
     }
641 641
 
642 642
     if (numStaticMeshes > 0)
643
-        getLog() << "LoaderTR2: Found " << numStaticMeshes << " StaticMeshes!" << Log::endl;
643
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numStaticMeshes << " StaticMeshes!" << Log::endl;
644 644
     else
645
-        getLog() << "LoaderTR2: No StaticMeshes in this level?!" << Log::endl;
645
+        Log::get(LOG_INFO) << "LoaderTR2: No StaticMeshes in this level?!" << Log::endl;
646 646
 }
647 647
 
648 648
 // ---- Moveables ----
@@ -711,9 +711,9 @@ void LoaderTR2::loadMoveables() {
711 711
     }
712 712
 
713 713
     if (numAnimations > 0)
714
-        getLog() << "LoaderTR2: Found " << numAnimations << " Animations!" << Log::endl;
714
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numAnimations << " Animations!" << Log::endl;
715 715
     else
716
-        getLog() << "LoaderTR2: No Animations in this level?!" << Log::endl;
716
+        Log::get(LOG_INFO) << "LoaderTR2: No Animations in this level?!" << Log::endl;
717 717
 
718 718
     uint32_t numStateChanges = file.readU32();
719 719
     std::vector<StateChange_t> stateChanges;
@@ -726,9 +726,9 @@ void LoaderTR2::loadMoveables() {
726 726
     }
727 727
 
728 728
     if (numStateChanges > 0)
729
-        getLog() << "LoaderTR2: Found " << numStateChanges << " StateChanges!" << Log::endl;
729
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numStateChanges << " StateChanges!" << Log::endl;
730 730
     else
731
-        getLog() << "LoaderTR2: No StateChanges in this level?!" << Log::endl;
731
+        Log::get(LOG_INFO) << "LoaderTR2: No StateChanges in this level?!" << Log::endl;
732 732
 
733 733
     uint32_t numAnimDispatches = file.readU32();
734 734
     std::vector<AnimDispatch_t> animDispatches;
@@ -742,9 +742,9 @@ void LoaderTR2::loadMoveables() {
742 742
     }
743 743
 
744 744
     if (numAnimDispatches > 0)
745
-        getLog() << "LoaderTR2: Found " << numAnimDispatches << " AnimationDispatches!" << Log::endl;
745
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numAnimDispatches << " AnimationDispatches!" << Log::endl;
746 746
     else
747
-        getLog() << "LoaderTR2: No AnimationDispatches in this level?!" << Log::endl;
747
+        Log::get(LOG_INFO) << "LoaderTR2: No AnimationDispatches in this level?!" << Log::endl;
748 748
 
749 749
     uint32_t numAnimCommands = file.readU32();
750 750
     std::vector<int16_t> animCommands;
@@ -756,9 +756,9 @@ void LoaderTR2::loadMoveables() {
756 756
     }
757 757
 
758 758
     if (numAnimCommands > 0)
759
-        getLog() << "LoaderTR2: Found " << numAnimCommands << " AnimationCommands!" << Log::endl;
759
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numAnimCommands << " AnimationCommands!" << Log::endl;
760 760
     else
761
-        getLog() << "LoaderTR2: No AnimationCommands in this level?!" << Log::endl;
761
+        Log::get(LOG_INFO) << "LoaderTR2: No AnimationCommands in this level?!" << Log::endl;
762 762
 
763 763
     // This is really one uint32_t flags, followed by
764 764
     // three int32_t x, y, z. However, we're given the number
@@ -783,9 +783,9 @@ void LoaderTR2::loadMoveables() {
783 783
     }
784 784
 
785 785
     if (numMeshTrees > 0)
786
-        getLog() << "LoaderTR2: Found " << numMeshTrees << " MeshTrees!" << Log::endl;
786
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numMeshTrees << " MeshTrees!" << Log::endl;
787 787
     else
788
-        getLog() << "LoaderTR2: No MeshTrees in this level?!" << Log::endl;
788
+        Log::get(LOG_INFO) << "LoaderTR2: No MeshTrees in this level?!" << Log::endl;
789 789
 
790 790
     uint32_t numFrames = file.readU32();
791 791
     std::vector<uint16_t> frames;
@@ -804,9 +804,9 @@ void LoaderTR2::loadMoveables() {
804 804
     }
805 805
 
806 806
     if (numFrames > 0)
807
-        getLog() << "LoaderTR2: Found " << numFrames << " Frames!" << Log::endl;
807
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numFrames << " Frames!" << Log::endl;
808 808
     else
809
-        getLog() << "LoaderTR2: No Frames in this level?!" << Log::endl;
809
+        Log::get(LOG_INFO) << "LoaderTR2: No Frames in this level?!" << Log::endl;
810 810
 
811 811
     uint32_t numMoveables = file.readU32();
812 812
     for (unsigned int m = 0; m < numMoveables; m++) {
@@ -887,9 +887,9 @@ void LoaderTR2::loadMoveables() {
887 887
     }
888 888
 
889 889
     if (numMoveables > 0)
890
-        getLog() << "LoaderTR2: Found " << numMoveables << " Moveables!" << Log::endl;
890
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numMoveables << " Moveables!" << Log::endl;
891 891
     else
892
-        getLog() << "LoaderTR2: No Moveables in this level?!" << Log::endl;
892
+        Log::get(LOG_INFO) << "LoaderTR2: No Moveables in this level?!" << Log::endl;
893 893
 }
894 894
 
895 895
 void LoaderTR2::loadItems() {
@@ -930,16 +930,16 @@ void LoaderTR2::loadItems() {
930 930
                 getWorld().addEntity(e);
931 931
 
932 932
                 if (objectID == 0) {
933
-                    getGame().setLara(getWorld().sizeEntity() - 1);
933
+                    Game::setLara(getWorld().sizeEntity() - 1);
934 934
                 }
935 935
             }
936 936
         }
937 937
     }
938 938
 
939 939
     if (numItems > 0)
940
-        getLog() << "LoaderTR2: Found " << numItems << " Items!" << Log::endl;
940
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numItems << " Items!" << Log::endl;
941 941
     else
942
-        getLog() << "LoaderTR2: No Items in this level?!" << Log::endl;
942
+        Log::get(LOG_INFO) << "LoaderTR2: No Items in this level?!" << Log::endl;
943 943
 }
944 944
 
945 945
 void LoaderTR2::loadBoxesOverlapsZones() {
@@ -997,10 +997,10 @@ void LoaderTR2::loadBoxesOverlapsZones() {
997 997
     }
998 998
 
999 999
     if ((numBoxes > 0) || (numOverlaps > 0))
1000
-        getLog() << "LoaderTR2: Found NPC NavigationHints (" << numBoxes
1000
+        Log::get(LOG_INFO) << "LoaderTR2: Found NPC NavigationHints (" << numBoxes
1001 1001
                  << ", " << numOverlaps << ", " << list << "), unimplemented!" << Log::endl;
1002 1002
     else
1003
-        getLog() << "LoaderTR2: No NPC NavigationHints in this level?!" << Log::endl;
1003
+        Log::get(LOG_INFO) << "LoaderTR2: No NPC NavigationHints in this level?!" << Log::endl;
1004 1004
 }
1005 1005
 
1006 1006
 // ---- Sound ----
@@ -1023,9 +1023,9 @@ void LoaderTR2::loadSoundSources() {
1023 1023
     }
1024 1024
 
1025 1025
     if (numSoundSources > 0)
1026
-        getLog() << "LoaderTR2: Found " << numSoundSources << " SoundSources" << Log::endl;
1026
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numSoundSources << " SoundSources" << Log::endl;
1027 1027
     else
1028
-        getLog() << "LoaderTR2: No SoundSources in this level?!" << Log::endl;
1028
+        Log::get(LOG_INFO) << "LoaderTR2: No SoundSources in this level?!" << Log::endl;
1029 1029
 }
1030 1030
 
1031 1031
 void LoaderTR2::loadSoundMap() {
@@ -1052,9 +1052,9 @@ void LoaderTR2::loadSoundDetails() {
1052 1052
     }
1053 1053
 
1054 1054
     if (numSoundDetails > 0)
1055
-        getLog() << "LoaderTR2: Found " << numSoundDetails << " SoundDetails" << Log::endl;
1055
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numSoundDetails << " SoundDetails" << Log::endl;
1056 1056
     else
1057
-        getLog() << "LoaderTR2: No SoundDetails in this level?!" << Log::endl;
1057
+        Log::get(LOG_INFO) << "LoaderTR2: No SoundDetails in this level?!" << Log::endl;
1058 1058
 }
1059 1059
 
1060 1060
 void LoaderTR2::loadSampleIndices() {
@@ -1064,9 +1064,9 @@ void LoaderTR2::loadSampleIndices() {
1064 1064
     }
1065 1065
 
1066 1066
     if (numSampleIndices > 0)
1067
-        getLog() << "LoaderTR2: Found " << numSampleIndices << " SampleIndices" << Log::endl;
1067
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numSampleIndices << " SampleIndices" << Log::endl;
1068 1068
     else
1069
-        getLog() << "LoaderTR2: No SampleIndices in this level?!" << Log::endl;
1069
+        Log::get(LOG_INFO) << "LoaderTR2: No SampleIndices in this level?!" << Log::endl;
1070 1070
 }
1071 1071
 
1072 1072
 void LoaderTR2::loadExternalSoundFile(std::string f) {
@@ -1079,7 +1079,7 @@ void LoaderTR2::loadExternalSoundFile(std::string f) {
1079 1079
 
1080 1080
     BinaryFile sfx;
1081 1081
     if (sfx.open(f) != 0) {
1082
-        getLog() << "LoaderTR2: Can't open \"" << f << "\"!" << Log::endl;
1082
+        Log::get(LOG_INFO) << "LoaderTR2: Can't open \"" << f << "\"!" << Log::endl;
1083 1083
         return;
1084 1084
     }
1085 1085
 
@@ -1091,7 +1091,7 @@ void LoaderTR2::loadExternalSoundFile(std::string f) {
1091 1091
             test[i] = sfx.read8();
1092 1092
 
1093 1093
         if (std::string("RIFF") != std::string(test)) {
1094
-            getLog() << "LoaderTR2: External SFX invalid! (" << riffCount
1094
+            Log::get(LOG_DEBUG) << "LoaderTR2: External SFX invalid! (" << riffCount
1095 1095
                      << ", \"" << test << "\" != \"RIFF\")" << Log::endl;
1096 1096
             return;
1097 1097
         }
@@ -1111,9 +1111,9 @@ void LoaderTR2::loadExternalSoundFile(std::string f) {
1111 1111
     }
1112 1112
 
1113 1113
     if (riffCount > 0)
1114
-        getLog() << "LoaderTR2: Found " << riffCount << " SoundSamples in SFX" << Log::endl;
1114
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << riffCount << " SoundSamples in SFX" << Log::endl;
1115 1115
     else
1116
-        getLog() << "LoaderTR2: No SoundSamples in SFX?!" << Log::endl;
1116
+        Log::get(LOG_INFO) << "LoaderTR2: No SoundSamples in SFX?!" << Log::endl;
1117 1117
 }
1118 1118
 
1119 1119
 // ---- Stuff ----
@@ -1132,7 +1132,7 @@ void LoaderTR2::loadCameras() {
1132 1132
     }
1133 1133
 
1134 1134
     if (numCameras > 0)
1135
-        getLog() << "LoaderTR2: Found " << numCameras << " Cameras, unimplemented!" << Log::endl;
1135
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numCameras << " Cameras, unimplemented!" << Log::endl;
1136 1136
 }
1137 1137
 
1138 1138
 void LoaderTR2::loadCinematicFrames() {
@@ -1151,7 +1151,7 @@ void LoaderTR2::loadCinematicFrames() {
1151 1151
     }
1152 1152
 
1153 1153
     if (numCinematicFrames > 0)
1154
-        getLog() << "LoaderTR2: Found " << numCinematicFrames
1154
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numCinematicFrames
1155 1155
                  << " CinematicFrames, unimplemented!" << Log::endl;
1156 1156
 }
1157 1157
 
@@ -1162,7 +1162,7 @@ void LoaderTR2::loadDemoData() {
1162 1162
 
1163 1163
     // TODO store demo data somewhere, find out meaning
1164 1164
     if (numDemoData > 0)
1165
-        getLog() << "LoaderTR2: Found " << numDemoData << " bytes DemoData, unimplemented!" <<
1165
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numDemoData << " bytes DemoData, unimplemented!" <<
1166 1166
                  Log::endl;
1167 1167
 }
1168 1168
 

+ 18
- 39
src/main.cpp Bestand weergeven

@@ -10,9 +10,9 @@
10 10
 
11 11
 #include "global.h"
12 12
 #include "Camera.h"
13
-#include "Game.h"
14 13
 #include "Log.h"
15 14
 #include "MenuFolder.h"
15
+#include "Render.h"
16 16
 #include "RunTime.h"
17 17
 #include "SoundManager.h"
18 18
 #include "TextureManager.h"
@@ -28,19 +28,9 @@
28 28
 
29 29
 static std::string configFileToUse;
30 30
 
31
-static std::shared_ptr<Game> gGame;
32
-static std::shared_ptr<Log> gLog;
33 31
 static std::shared_ptr<MenuFolder> gMenu;
34 32
 static std::shared_ptr<World> gWorld;
35 33
 
36
-Game& getGame() {
37
-    return *gGame;
38
-}
39
-
40
-Log& getLog() {
41
-    return *gLog;
42
-}
43
-
44 34
 Menu& getMenu() {
45 35
     return *gMenu;
46 36
 }
@@ -62,14 +52,12 @@ int main(int argc, char* argv[]) {
62 52
     // RunTime is required by other constructors
63 53
     RunTime::initialize();
64 54
 
65
-    gGame.reset(new Game());
66
-    gLog.reset(new Log());
67 55
     gMenu.reset(new MenuFolder());
68 56
     gWorld.reset(new World());
69 57
 
70 58
     Command::fillCommandList();
71 59
 
72
-    getLog() << "Initializing " << VERSION << Log::endl;
60
+    Log::get(LOG_INFO) << "Initializing " << VERSION << Log::endl;
73 61
 
74 62
     // Initialize Windowing
75 63
     int error = Window::initialize();
@@ -132,18 +120,12 @@ int main(int argc, char* argv[]) {
132 120
         return -7;
133 121
     }
134 122
 
135
-    // Initialize Game Engine
136
-    error = getGame().initialize();
137
-    if (error != 0) {
138
-        std::cout << "Could not initialize Game (" << error << ")!" << std::endl;
139
-        return -8;
140
-    }
141
-
142
-    getLog() << "Starting " << VERSION << Log::endl;
123
+    Log::get(LOG_INFO) << "Starting " << VERSION << Log::endl;
143 124
     Camera::setSize(Window::getSize());
144 125
     getMenu().setVisible(true);
145 126
     systemTimerReset();
146 127
     RunTime::setRunning(true);
128
+    Render::setMode(RenderMode::LoadScreen);
147 129
 
148 130
     while (RunTime::isRunning()) {
149 131
         Window::eventHandling();
@@ -169,7 +151,7 @@ int main(int argc, char* argv[]) {
169 151
 }
170 152
 
171 153
 void renderFrame() {
172
-    getGame().display();
154
+    Render::display();
173 155
     getMenu().display();
174 156
     UI::display();
175 157
     Window::swapBuffers();
@@ -182,26 +164,23 @@ void renderFrame() {
182 164
 #include <exception>
183 165
 #include <execinfo.h>
184 166
 
185
-namespace {
186
-    extern std::terminate_handler oldTerminateHandler;
187
-
188
-    [[noreturn]] void terminateHandler() {
189
-        const unsigned int maxSize = 128;
190
-        void* callstack[maxSize];
191
-        int frames = backtrace(callstack, maxSize);
192
-        char** strs = backtrace_symbols(callstack, frames);
167
+[[noreturn]] static void terminateHandler();
168
+static std::terminate_handler oldTerminateHandler = std::set_terminate(terminateHandler);
193 169
 
194
-        std::cout << std::endl;
195
-        for (int i = frames; i > 0; i++)
196
-            std::cout << strs[i - 1] << std::endl;
170
+[[noreturn]] static void terminateHandler() {
171
+    const unsigned int maxSize = 128;
172
+    void* callstack[maxSize];
173
+    int frames = backtrace(callstack, maxSize);
174
+    char** strs = backtrace_symbols(callstack, frames);
197 175
 
198
-        delete [] strs;
176
+    std::cout << std::endl;
177
+    for (int i = frames; i > 0; i++)
178
+        std::cout << strs[i - 1] << std::endl;
199 179
 
200
-        oldTerminateHandler();
201
-        abort();
202
-    }
180
+    delete [] strs;
203 181
 
204
-    std::terminate_handler oldTerminateHandler = std::set_terminate(terminateHandler);
182
+    oldTerminateHandler();
183
+    abort();
205 184
 }
206 185
 
207 186
 #endif // NODEBUG

+ 1
- 1
src/system/Font.cpp Bestand weergeven

@@ -30,7 +30,7 @@ int Font::initialize(std::string font) {
30 30
     }
31 31
 
32 32
     if (font != "") {
33
-        getLog() << "Unknown font file format: " << font << Log::endl;
33
+        Log::get(LOG_ERROR) << "Unknown font file format: " << font << Log::endl;
34 34
         return -1;
35 35
     } else {
36 36
         return 0;

+ 6
- 6
src/system/FontTTF.cpp Bestand weergeven

@@ -43,7 +43,7 @@ int FontMapTTF::initialize(unsigned char* fontData, int firstChar) {
43 43
     unsigned char* pixels = new unsigned char[MAP_WIDTH * MAP_HEIGHT];
44 44
     if (!stbtt_PackBegin(&context, pixels, MAP_WIDTH, MAP_HEIGHT, 0, 1, nullptr)) {
45 45
         delete [] pixels;
46
-        getLog() << "Error initializing font map in stbtt_PackBegin!" << Log::endl;
46
+        Log::get(LOG_ERROR) << "Error initializing font map in stbtt_PackBegin!" << Log::endl;
47 47
         return -1;
48 48
     }
49 49
 
@@ -58,7 +58,7 @@ int FontMapTTF::initialize(unsigned char* fontData, int firstChar) {
58 58
         delete [] pixels;
59 59
         delete [] charInfo;
60 60
         charInfo = nullptr;
61
-        getLog() << "Error packing font map!" << Log::endl;
61
+        Log::get(LOG_ERROR) << "Error packing font map!" << Log::endl;
62 62
         return -2;
63 63
     }
64 64
 
@@ -72,7 +72,7 @@ int FontMapTTF::initialize(unsigned char* fontData, int firstChar) {
72 72
     if (texture < 0) {
73 73
         delete [] charInfo;
74 74
         charInfo = nullptr;
75
-        getLog() << "Error loading new font map texture!" << Log::endl;
75
+        Log::get(LOG_ERROR) << "Error loading new font map texture!" << Log::endl;
76 76
         return -3;
77 77
     }
78 78
 
@@ -102,7 +102,7 @@ int FontTTF::initialize(std::string f) {
102 102
 
103 103
     std::ifstream file(f, std::ios::binary);
104 104
     if (!file) {
105
-        getLog() << "Couldn't open file \"" << f << "\"!" << Log::endl;
105
+        Log::get(LOG_ERROR) << "Couldn't open file \"" << f << "\"!" << Log::endl;
106 106
         return -1;
107 107
     }
108 108
 
@@ -119,7 +119,7 @@ int FontTTF::initialize(std::string f) {
119 119
 
120 120
     fontData = new unsigned char[size];
121 121
     if (!file.read(reinterpret_cast<char*>(fontData), size)) {
122
-        getLog() << "Couldn't read data in \"" << f << "\"" << Log::endl;
122
+        Log::get(LOG_ERROR) << "Couldn't read data in \"" << f << "\"" << Log::endl;
123 123
         delete [] fontData;
124 124
         fontData = nullptr;
125 125
         return -2;
@@ -254,7 +254,7 @@ int FontTTF::charIsMapped(int c) {
254 254
     if (c >= (MAP_NUM_CHARS / 2))
255 255
         begin -= (MAP_NUM_CHARS / 2);
256 256
 
257
-    getLog() << "Unmapped character '" << char(c) << "', new map from " << begin << " to "
257
+    Log::get(LOG_INFO) << "Unmapped character '" << char(c) << "', new map from " << begin << " to "
258 258
              << begin + MAP_NUM_CHARS - 1 << "..." << Log::endl;
259 259
 
260 260
     int p = maps.size();

+ 45
- 38
src/system/Shader.cpp Bestand weergeven

@@ -62,7 +62,7 @@ int Shader::addUniform(const char* name) {
62 62
     assert(programID >= 0);
63 63
     int r = glGetUniformLocation(programID, name);
64 64
     if (r < 0) {
65
-        getLog() << "Can't find GLSL Uniform \"" << name << "\"!" << Log::endl;
65
+        Log::get(LOG_ERROR) << "Can't find GLSL Uniform \"" << name << "\"!" << Log::endl;
66 66
         return -1;
67 67
     }
68 68
     uniforms.push_back(r);
@@ -117,8 +117,8 @@ int Shader::compile(const char* vertex, const char* fragment) {
117 117
         std::vector<char> message(logLength + 1);
118 118
         glGetShaderInfoLog(vertexID, logLength, nullptr, &message[0]);
119 119
         if (result != GL_TRUE)
120
-            getLog() << "Vertex Shader compilation error:" << Log::endl;
121
-        getLog() << &message[0] << Log::endl;
120
+            Log::get(LOG_ERROR) << "Vertex Shader compilation error:" << Log::endl;
121
+        Log::get(LOG_ERROR) << &message[0] << Log::endl;
122 122
         glDeleteShader(vertexID);
123 123
         glDeleteShader(fragmentID);
124 124
         return -1;
@@ -135,8 +135,8 @@ int Shader::compile(const char* vertex, const char* fragment) {
135 135
         std::vector<char> message(logLength + 1);
136 136
         glGetShaderInfoLog(fragmentID, logLength, nullptr, &message[0]);
137 137
         if (result != GL_TRUE)
138
-            getLog() << "Fragment Shader compilation error:" << Log::endl;
139
-        getLog() << &message[0] << Log::endl;
138
+            Log::get(LOG_ERROR) << "Fragment Shader compilation error:" << Log::endl;
139
+        Log::get(LOG_ERROR) << &message[0] << Log::endl;
140 140
         glDeleteShader(vertexID);
141 141
         glDeleteShader(fragmentID);
142 142
         return -2;
@@ -155,8 +155,8 @@ int Shader::compile(const char* vertex, const char* fragment) {
155 155
         std::vector<char> message(logLength + 1);
156 156
         glGetProgramInfoLog(programID, logLength, nullptr, &message[0]);
157 157
         if (result != GL_TRUE)
158
-            getLog() << "Shader link error:" << Log::endl;
159
-        getLog() << &message[0] << Log::endl;
158
+            Log::get(LOG_ERROR) << "Shader link error:" << Log::endl;
159
+        Log::get(LOG_ERROR) << &message[0] << Log::endl;
160 160
         glDeleteShader(vertexID);
161 161
         glDeleteShader(fragmentID);
162 162
         glDeleteProgram(programID);
@@ -176,10 +176,10 @@ Shader Shader::colorShader;
176 176
 unsigned int Shader::vertexArrayID = 0;
177 177
 
178 178
 int Shader::initialize() {
179
-    getLog() << "GL Ven.: " << glGetString(GL_VENDOR) << Log::endl;
180
-    getLog() << "GL Ren.: " << glGetString(GL_RENDERER) << Log::endl;
181
-    getLog() << "GL Ver.: " << glGetString(GL_VERSION) << Log::endl;
182
-    getLog() << "GLSL V.: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << Log::endl;
179
+    Log::get(LOG_DEBUG) << "GL Ven.: " << glGetString(GL_VENDOR) << Log::endl;
180
+    Log::get(LOG_DEBUG) << "GL Ren.: " << glGetString(GL_RENDERER) << Log::endl;
181
+    Log::get(LOG_DEBUG) << "GL Ver.: " << glGetString(GL_VERSION) << Log::endl;
182
+    Log::get(LOG_DEBUG) << "GLSL V.: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << Log::endl;
183 183
 
184 184
     glGenVertexArrays(1, &vertexArrayID);
185 185
     glBindVertexArray(vertexArrayID);
@@ -188,17 +188,12 @@ int Shader::initialize() {
188 188
     //glClearColor(BLACK[0] / 256.0f, BLACK[1] / 256.0f, BLACK[2] / 256.0f, BLACK[3] / 256.0f);
189 189
     glClearColor(0.0f, 0.0f, 0.4f, 1.0f);
190 190
 
191
-    // Set up Z buffer
192
-    glEnable(GL_DEPTH_TEST);
193
-    // Accept fragment if closer to camera
191
+    set2DState(false);
194 192
     glDepthFunc(GL_LESS);
195 193
 
196 194
     glEnable(GL_BLEND);
197 195
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
198 196
 
199
-    // Set up culling
200
-    //glEnable(GL_CULL_FACE); //! \todo Transparency?
201
-
202 197
     glPointSize(5.0f);
203 198
 
204 199
     if (textShader.compile(textShaderVertex, textShaderFragment) < 0)
@@ -229,34 +224,44 @@ void Shader::shutdown() {
229 224
     glDeleteVertexArrays(1, &vertexArrayID);
230 225
 }
231 226
 
227
+void Shader::set2DState(bool on) {
228
+    if (on) {
229
+        glDisable(GL_CULL_FACE);
230
+        glDisable(GL_DEPTH_TEST);
231
+    } else {
232
+        glEnable(GL_DEPTH_TEST);
233
+        glEnable(GL_CULL_FACE);
234
+    }
235
+}
236
+
232 237
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color,
233
-                    unsigned int texture, TextureStorage store) {
238
+                    unsigned int texture, TextureStorage store, Shader& shader) {
234 239
     assert(vertices.getSize() == uvs.getSize());
235 240
     assert((vertices.getSize() % 3) == 0);
236 241
 
237
-    textShader.use();
238
-    textShader.loadUniform(0, Window::getSize());
239
-    textShader.loadUniform(1, texture, store);
240
-    textShader.loadUniform(2, color);
242
+    shader.use();
243
+    shader.loadUniform(0, Window::getSize());
244
+    shader.loadUniform(1, texture, store);
245
+    shader.loadUniform(2, color);
241 246
     vertices.bindBuffer(0, 2);
242 247
     uvs.bindBuffer(1, 2);
243 248
 
244
-    glDisable(GL_DEPTH_TEST);
249
+    set2DState(true);
245 250
     glDrawArrays(GL_TRIANGLES, 0, vertices.getSize());
246
-    glEnable(GL_DEPTH_TEST);
251
+    set2DState(false);
247 252
 
248 253
     vertices.unbind(0);
249 254
     uvs.unbind(1);
250 255
 }
251 256
 
252 257
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture,
253
-                    glm::mat4 MVP, TextureStorage store) {
258
+                    glm::mat4 MVP, TextureStorage store, Shader& shader) {
254 259
     assert(vertices.getSize() == uvs.getSize());
255 260
     assert((vertices.getSize() % 3) == 0);
256 261
 
257
-    textureShader.use();
258
-    textureShader.loadUniform(0, MVP);
259
-    textureShader.loadUniform(1, texture, store);
262
+    shader.use();
263
+    shader.loadUniform(0, MVP);
264
+    shader.loadUniform(1, texture, store);
260 265
     vertices.bindBuffer(0, 3);
261 266
     uvs.bindBuffer(1, 2);
262 267
     glDrawArrays(GL_TRIANGLES, 0, vertices.getSize());
@@ -265,13 +270,14 @@ void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int text
265 270
 }
266 271
 
267 272
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& indices,
268
-                    unsigned int texture, glm::mat4 MVP, TextureStorage store) {
273
+                    unsigned int texture, glm::mat4 MVP, TextureStorage store,
274
+                    Shader& shader) {
269 275
     assert(vertices.getSize() == uvs.getSize());
270 276
     assert((indices.getSize() % 3) == 0);
271 277
 
272
-    textureShader.use();
273
-    textureShader.loadUniform(0, MVP);
274
-    textureShader.loadUniform(1, texture, store);
278
+    shader.use();
279
+    shader.loadUniform(0, MVP);
280
+    shader.loadUniform(1, texture, store);
275 281
     vertices.bindBuffer(0, 3);
276 282
     uvs.bindBuffer(1, 2);
277 283
     indices.bindBuffer();
@@ -280,11 +286,12 @@ void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& ind
280 286
     uvs.unbind(1);
281 287
 }
282 288
 
283
-void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP, unsigned int mode) {
289
+void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
290
+                    unsigned int mode, Shader& shader) {
284 291
     assert(vertices.getSize() == colors.getSize());
285 292
 
286
-    colorShader.use();
287
-    colorShader.loadUniform(0, MVP);
293
+    shader.use();
294
+    shader.loadUniform(0, MVP);
288 295
     vertices.bindBuffer(0, 3);
289 296
     colors.bindBuffer(1, 3);
290 297
     glDrawArrays(mode, 0, vertices.getSize());
@@ -293,11 +300,11 @@ void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
293 300
 }
294 301
 
295 302
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices,
296
-                    glm::mat4 MVP, unsigned int mode) {
303
+                    glm::mat4 MVP, unsigned int mode, Shader& shader) {
297 304
     assert(vertices.getSize() == colors.getSize());
298 305
 
299
-    colorShader.use();
300
-    colorShader.loadUniform(0, MVP);
306
+    shader.use();
307
+    shader.loadUniform(0, MVP);
301 308
     vertices.bindBuffer(0, 3);
302 309
     colors.bindBuffer(1, 3);
303 310
     indices.bindBuffer();

+ 10
- 10
src/system/SoundAL.cpp Bestand weergeven

@@ -35,7 +35,7 @@ int SoundAL::initialize() {
35 35
     alcMakeContextCurrent(context);
36 36
 
37 37
     if (alutInitWithoutContext(nullptr, nullptr) == AL_FALSE) {
38
-        getLog() << "SoundAL Error: " << alutGetErrorString(alutGetError()) << Log::endl;
38
+        Log::get(LOG_ERROR) << "SoundAL Error: " << alutGetErrorString(alutGetError()) << Log::endl;
39 39
         return -1;
40 40
     }
41 41
 
@@ -50,7 +50,7 @@ void SoundAL::shutdown() {
50 50
 
51 51
     clear();
52 52
     if (alutExit() == AL_FALSE)
53
-        getLog() << "SoundAL Error: " << alutGetErrorString(alutGetError()) << Log::endl;
53
+        Log::get(LOG_ERROR) << "SoundAL Error: " << alutGetErrorString(alutGetError()) << Log::endl;
54 54
     init = false;
55 55
 }
56 56
 
@@ -64,21 +64,21 @@ void SoundAL::clear() {
64 64
     alDeleteSources(sources.size(), &sources[0]);
65 65
     sources.clear();
66 66
     if (alGetError() != AL_NO_ERROR) {
67
-        getLog() << "SoundAL: Error while deleting sources!" << Log::endl;
67
+        Log::get(LOG_ERROR) << "SoundAL: Error while deleting sources!" << Log::endl;
68 68
     }
69 69
 
70 70
     alGetError();
71 71
     alDeleteSources(listenerSources.size(), &listenerSources[0]);
72 72
     listenerSources.clear();
73 73
     if (alGetError() != AL_NO_ERROR) {
74
-        getLog() << "SoundAL: Error while deleting listener sources!" << Log::endl;
74
+        Log::get(LOG_ERROR) << "SoundAL: Error while deleting listener sources!" << Log::endl;
75 75
     }
76 76
 
77 77
     alGetError();
78 78
     alDeleteBuffers(buffers.size(), &buffers[0]);
79 79
     buffers.clear();
80 80
     if (alGetError() != AL_NO_ERROR) {
81
-        getLog() << "SoundAL: Error while deleting buffers!" << Log::endl;
81
+        Log::get(LOG_ERROR) << "SoundAL: Error while deleting buffers!" << Log::endl;
82 82
     }
83 83
 
84 84
     for (int i = 0; i < 3; i++)
@@ -99,7 +99,7 @@ int SoundAL::loadBuffer(unsigned char* buffer, unsigned int length) {
99 99
     alGetError();
100 100
     unsigned int r = alutCreateBufferFromFileImage(buffer, length);
101 101
     if (r == AL_NONE) {
102
-        getLog() << "SoundAL Error: " << alutGetErrorString(alutGetError()) << Log::endl;
102
+        Log::get(LOG_ERROR) << "SoundAL Error: " << alutGetErrorString(alutGetError()) << Log::endl;
103 103
         return -2;
104 104
     }
105 105
     buffers.push_back(r);
@@ -122,7 +122,7 @@ int SoundAL::addSource(int buffer, float volume, bool atListener, bool loop) {
122 122
     alGetError();
123 123
     alGenSources(1, &id);
124 124
     if (alGetError() != AL_NO_ERROR) {
125
-        getLog() << "SoundAL Error: Could not create source!" << Log::endl;
125
+        Log::get(LOG_ERROR) << "SoundAL Error: Could not create source!" << Log::endl;
126 126
         return -2;
127 127
     }
128 128
 
@@ -147,7 +147,7 @@ int SoundAL::sourceAt(int source, float pos[3]) {
147 147
         return -1;
148 148
 
149 149
     if ((source < 0) || (source >= sources.size()) || (pos == nullptr)) {
150
-        getLog() << "SoundAL: Can't position non-existing source!" << Log::endl;
150
+        Log::get(LOG_ERROR) << "SoundAL: Can't position non-existing source!" << Log::endl;
151 151
         return -2;
152 152
     }
153 153
 
@@ -179,12 +179,12 @@ void SoundAL::play(int source, bool atListener) {
179 179
         if ((source >= 0) && (source < listenerSources.size()))
180 180
             alSourcePlay(listenerSources.at(source));
181 181
         else
182
-            getLog() << "SoundAL: Can't play non-existing listener source!" << Log::endl;
182
+            Log::get(LOG_ERROR) << "SoundAL: Can't play non-existing listener source!" << Log::endl;
183 183
     } else {
184 184
         if ((source >= 0) && (source < sources.size()))
185 185
             alSourcePlay(sources.at(source));
186 186
         else
187
-            getLog() << "SoundAL: Can't play non-existing source!" << Log::endl;
187
+            Log::get(LOG_ERROR) << "SoundAL: Can't play non-existing source!" << Log::endl;
188 188
     }
189 189
 }
190 190
 

+ 28
- 0
src/system/Window.cpp Bestand weergeven

@@ -20,6 +20,7 @@
20 20
 
21 21
 int Window::initialize() {
22 22
     int res;
23
+
23 24
 #ifdef USING_SDL
24 25
     res = WindowSDL::initialize();
25 26
 #elif defined(USING_GLFW)
@@ -27,6 +28,7 @@ int Window::initialize() {
27 28
 #else
28 29
     res = -1;
29 30
 #endif
31
+
30 32
     return res;
31 33
 }
32 34
 
@@ -68,6 +70,7 @@ void Window::setSize(glm::i32vec2 s) {
68 70
 
69 71
 glm::i32vec2 Window::getSize() {
70 72
     glm::i32vec2 ret(-1, -1);
73
+
71 74
 #ifdef USING_SDL
72 75
     ret = WindowSDL::getSize();
73 76
 #elif defined(USING_GLFW)
@@ -87,6 +90,7 @@ void Window::setFullscreen(bool f) {
87 90
 
88 91
 bool Window::getFullscreen() {
89 92
     bool ret;
93
+
90 94
 #ifdef USING_SDL
91 95
     ret = WindowSDL::getFullscreen();
92 96
 #elif defined(USING_GLFW)
@@ -108,6 +112,7 @@ void Window::setMousegrab(bool g) {
108 112
 
109 113
 bool Window::getMousegrab() {
110 114
     bool ret;
115
+
111 116
 #ifdef USING_SDL
112 117
     ret = WindowSDL::getMousegrab();
113 118
 #elif defined(USING_GLFW)
@@ -129,6 +134,7 @@ void Window::setTextInput(bool t) {
129 134
 
130 135
 bool Window::getTextInput() {
131 136
     bool ret;
137
+
132 138
 #ifdef USING_SDL
133 139
     ret = WindowSDL::getTextInput();
134 140
 #elif defined(USING_GLFW)
@@ -140,3 +146,25 @@ bool Window::getTextInput() {
140 146
     return ret;
141 147
 }
142 148
 
149
+void Window::setClipboard(const char* s) {
150
+#ifdef USING_SDL
151
+    WindowSDL::setClipboard(s);
152
+#elif defined(USING_GLFW)
153
+    WindowGLFW::setClipboard(s);
154
+#endif
155
+}
156
+
157
+const char* Window::getClipboard() {
158
+    const char* ret;
159
+
160
+#ifdef USING_SDL
161
+    ret = WindowSDL::getClipboard();
162
+#elif defined(USING_GLFW)
163
+    ret = WindowGLFW::getClipboard();
164
+#else
165
+    ret = nullptr;
166
+#endif
167
+
168
+    return ret;
169
+}
170
+

+ 13
- 1
src/system/WindowGLFW.cpp Bestand weergeven

@@ -106,8 +106,20 @@ void WindowGLFW::setTextInput(bool t) {
106 106
     textinput = t;
107 107
 }
108 108
 
109
+void WindowGLFW::setClipboard(const char* s) {
110
+    if (window)
111
+        glfwSetClipboardString(window, s);
112
+}
113
+
114
+const char* WindowGLFW::getClipboard() {
115
+    if (window)
116
+        return glfwGetClipboardString(window);
117
+
118
+    return nullptr;
119
+}
120
+
109 121
 void WindowGLFW::errorCallback(int error, const char* desc) {
110
-    getLog() << "GLFW Error (" << error << "): " << desc << Log::endl;
122
+    Log::get(LOG_ERROR) << "GLFW Error (" << error << "): " << desc << Log::endl;
111 123
 }
112 124
 
113 125
 void WindowGLFW::sizeCallback(GLFWwindow* w, int width, int height) {

+ 30
- 9
src/system/WindowSDL.cpp Bestand weergeven

@@ -24,7 +24,7 @@ SDL_GameController* WindowSDL::controller = nullptr;
24 24
 
25 25
 int WindowSDL::initialize() {
26 26
     if (SDL_Init(SUBSYSTEMS_USED) != 0) {
27
-        getLog() << "SDL_Init Error: " << SDL_GetError() << Log::endl;
27
+        Log::get(LOG_ERROR) << "SDL_Init Error: " << SDL_GetError() << Log::endl;
28 28
         return -1;
29 29
     }
30 30
 
@@ -44,20 +44,20 @@ int WindowSDL::initialize() {
44 44
         || (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3) != 0)
45 45
         || (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3) != 0)
46 46
         || (SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE))) {
47
-        getLog() << "SDL_GL_SetAttribute Error: " << SDL_GetError() << Log::endl;
47
+        Log::get(LOG_ERROR) << "SDL_GL_SetAttribute Error: " << SDL_GetError() << Log::endl;
48 48
         return -2;
49 49
     }
50 50
 
51 51
     window = SDL_CreateWindow(VERSION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
52 52
                               size.x, size.y, flags);
53 53
     if (!window) {
54
-        getLog() << "SDL_CreateWindow Error: " << SDL_GetError() << Log::endl;
54
+        Log::get(LOG_ERROR) << "SDL_CreateWindow Error: " << SDL_GetError() << Log::endl;
55 55
         return -3;
56 56
     }
57 57
 
58 58
     context = SDL_GL_CreateContext(window);
59 59
     if (!context) {
60
-        getLog() << "SDL_GL_CreateContext Error: " << SDL_GetError() << Log::endl;
60
+        Log::get(LOG_ERROR) << "SDL_GL_CreateContext Error: " << SDL_GetError() << Log::endl;
61 61
         return -4;
62 62
     }
63 63
 
@@ -65,7 +65,7 @@ int WindowSDL::initialize() {
65 65
     setTextInput(textinput);
66 66
 
67 67
     if (SDL_NumJoysticks() == 0) {
68
-        getLog() << "No Joystick found!" << Log::endl;
68
+        Log::get(LOG_INFO) << "No Joystick found!" << Log::endl;
69 69
         return 0;
70 70
     }
71 71
 
@@ -73,16 +73,16 @@ int WindowSDL::initialize() {
73 73
         if (SDL_IsGameController(i)) {
74 74
             controller = SDL_GameControllerOpen(i);
75 75
             if (controller) {
76
-                getLog() << "Using controller \"" << SDL_GameControllerName(controller)
76
+                Log::get(LOG_INFO) << "Using controller \"" << SDL_GameControllerName(controller)
77 77
                          << "\"..." << Log::endl;
78 78
                 break;
79 79
             } else {
80
-                getLog() << "Couldn't open controller \"" << SDL_GameControllerNameForIndex(i)
80
+                Log::get(LOG_WARNING) << "Couldn't open controller \"" << SDL_GameControllerNameForIndex(i)
81 81
                          << "\"!" << Log::endl;
82 82
             }
83 83
         } else {
84
-            getLog() << "Joystick \"" << SDL_JoystickNameForIndex(i)
85
-                     << "\" is no controller!" << Log::endl;
84
+            Log::get(LOG_WARNING) << "Joystick \"" << SDL_JoystickNameForIndex(i)
85
+                     << "\" is no compatible controller!" << Log::endl;
86 86
         }
87 87
     }
88 88
 
@@ -534,3 +534,24 @@ void WindowSDL::setTextInput(bool t) {
534 534
         SDL_StopTextInput();
535 535
 }
536 536
 
537
+void WindowSDL::setClipboard(const char* s) {
538
+    if (window) {
539
+        if (SDL_SetClipboardText(s) < 0) {
540
+            Log::get(LOG_ERROR) << "SDL_SetClipboardText Error: " << SDL_GetError() << Log::endl;
541
+        }
542
+    }
543
+}
544
+
545
+const char* WindowSDL::getClipboard() {
546
+    if (window) {
547
+        //! \fixme Should be freed with SDL_free(). But how, where, when?
548
+        const char* ret = SDL_GetClipboardText();
549
+        if (ret == nullptr) {
550
+            Log::get(LOG_ERROR) << "SDL_GetClipboardText Error: " << SDL_GetError() << Log::endl;
551
+        }
552
+        return ret;
553
+    }
554
+
555
+    return nullptr;
556
+}
557
+

+ 1
- 1
src/utils/Folder.cpp Bestand weergeven

@@ -122,7 +122,7 @@ void Folder::createFolderItems() {
122 122
 
123 123
     std::vector<std::string> foundFiles, foundFolders;
124 124
     if (readFolderItems(foundFiles, foundFolders) != 0) {
125
-        getLog() << "Could not open folder " << name << Log::endl;
125
+        Log::get(LOG_ERROR) << "Could not open folder " << name << Log::endl;
126 126
     }
127 127
 
128 128
     if (!listDot) {

+ 12
- 14
src/utils/binary.cpp Bestand weergeven

@@ -49,22 +49,20 @@ float BinaryReader::readFloat() {
49 49
     return ret;
50 50
 }
51 51
 
52
-namespace {
53
-    /*! \fixme Left-Shift with signed integer is undefined!
54
-     *  So we can't use the same method as for unsigned integers.
55
-     *  Is there a portable way to read multi-byte signed integers,
56
-     *  without having to detect the endianness at run-time?
57
-     */
58
-    const int bigendiandetection = 1;
52
+/*! \fixme Left-Shift with signed integer is undefined!
53
+ *  So we can't use the same method as for unsigned integers.
54
+ *  Is there a portable way to read multi-byte signed integers,
55
+ *  without having to detect the endianness at run-time?
56
+ */
57
+const static int bigendiandetection = 1;
59 58
 #define ISBIGENDIAN() ((*reinterpret_cast<const char *>(&bigendiandetection)) == 0)
60 59
 
61
-    void swapByteOrder(char* d, unsigned int n) {
62
-        if (ISBIGENDIAN()) {
63
-            for (unsigned int i = 0; i < (n / 2); i++) {
64
-                char tmp = d[i];
65
-                d[i] = d[n - i - 1];
66
-                d[n - i - 1] = tmp;
67
-            }
60
+static void swapByteOrder(char* d, unsigned int n) {
61
+    if (ISBIGENDIAN()) {
62
+        for (unsigned int i = 0; i < (n / 2); i++) {
63
+            char tmp = d[i];
64
+            d[i] = d[n - i - 1];
65
+            d[n - i - 1] = tmp;
68 66
         }
69 67
     }
70 68
 }

+ 19
- 19
src/utils/pcx.cpp Bestand weergeven

@@ -25,38 +25,38 @@ int pcxCheck(const char* filename) {
25 25
 
26 26
     // Basic validation
27 27
     if (!file.read((char*)(&header[0]), 128)) {
28
-        getLog() << "File not big enough for valid PCX header!" << Log::endl;
28
+        Log::get(LOG_ERROR) << "File not big enough for valid PCX header!" << Log::endl;
29 29
         delete [] header;
30 30
         return -1;
31 31
     }
32 32
 
33 33
     if (header[0] != 0x0A) {
34
-        getLog() << "Magic number at file start is wrong (" << header[0] << " != 0x0A)" << Log::endl;
34
+        Log::get(LOG_ERROR) << "Magic number at file start is wrong (" << header[0] << " != 0x0A)" << Log::endl;
35 35
         delete [] header;
36 36
         return -2;
37 37
     }
38 38
 
39 39
     if ((header[1] != 0) && ((header[1] < 2) || (header[1] > 5))) {
40 40
         // Valid: 0, 2, 3, 4, 5
41
-        getLog() << "Unknown PCX file format version (" << header[1] << ")" << Log::endl;
41
+        Log::get(LOG_ERROR) << "Unknown PCX file format version (" << header[1] << ")" << Log::endl;
42 42
         delete [] header;
43 43
         return -3;
44 44
     }
45 45
 
46 46
     if ((header[2] != 0) && (header[2] != 1)) {
47
-        getLog() << "Unknown PCX file encoding (" << header[2] << ")" << Log::endl;
47
+        Log::get(LOG_ERROR) << "Unknown PCX file encoding (" << header[2] << ")" << Log::endl;
48 48
         delete [] header;
49 49
         return -4;
50 50
     }
51 51
 
52 52
     if (header[3] != 8) {
53
-        getLog() << "Only supporting 8bit (" << header[3] << "bit)" << Log::endl;
53
+        Log::get(LOG_ERROR) << "Only supporting 8bit (" << header[3] << "bit)" << Log::endl;
54 54
         delete [] header;
55 55
         return -5;
56 56
     }
57 57
 
58 58
     if (header[64] != 0) {
59
-        getLog() << "Reserved field is  used (" << header[64] << " != 0)" << Log::endl;
59
+        Log::get(LOG_ERROR) << "Reserved field is  used (" << header[64] << " != 0)" << Log::endl;
60 60
         delete [] header;
61 61
         return -6;
62 62
     }
@@ -83,38 +83,38 @@ int pcxLoad(const char* filename, unsigned char** image,
83 83
 
84 84
     // Basic validation
85 85
     if (!file.read((char*)(&header[0]), 128)) {
86
-        getLog() << "File not big enough for valid PCX header!" << Log::endl;
86
+        Log::get(LOG_ERROR) << "File not big enough for valid PCX header!" << Log::endl;
87 87
         delete [] header;
88 88
         return -1;
89 89
     }
90 90
 
91 91
     if (header[0] != 0x0A) {
92
-        getLog() << "Magic number at file start is wrong (" << header[0] << " != 0x0A)" << Log::endl;
92
+        Log::get(LOG_ERROR) << "Magic number at file start is wrong (" << header[0] << " != 0x0A)" << Log::endl;
93 93
         delete [] header;
94 94
         return -2;
95 95
     }
96 96
 
97 97
     if ((header[1] != 0) && ((header[1] < 2) || (header[1] > 5))) {
98 98
         // Valid: 0, 2, 3, 4, 5
99
-        getLog() << "Unknown PCX file format version (" << header[1] << ")" << Log::endl;
99
+        Log::get(LOG_ERROR) << "Unknown PCX file format version (" << header[1] << ")" << Log::endl;
100 100
         delete [] header;
101 101
         return -3;
102 102
     }
103 103
 
104 104
     if ((header[2] != 0) && (header[2] != 1)) {
105
-        getLog() << "Unknown PCX file encoding (" << header[2] << ")" << Log::endl;
105
+        Log::get(LOG_ERROR) << "Unknown PCX file encoding (" << header[2] << ")" << Log::endl;
106 106
         delete [] header;
107 107
         return -4;
108 108
     }
109 109
 
110 110
     if (header[3] != 8) {
111
-        getLog() << "Only supporting 8bit (" << header[3] << "bit)" << Log::endl;
111
+        Log::get(LOG_ERROR) << "Only supporting 8bit (" << header[3] << "bit)" << Log::endl;
112 112
         delete [] header;
113 113
         return -5;
114 114
     }
115 115
 
116 116
     if (header[64] != 0) {
117
-        getLog() << "Reserved field is  used (" << header[64] << " != 0)" << Log::endl;
117
+        Log::get(LOG_ERROR) << "Reserved field is  used (" << header[64] << " != 0)" << Log::endl;
118 118
         delete [] header;
119 119
         return -6;
120 120
     }
@@ -151,8 +151,8 @@ int pcxLoad(const char* filename, unsigned char** image,
151 151
         unsigned int n = 1; // Run-length-encoding assumes 1
152 152
         int c = file.get();
153 153
         if (!file) {
154
-            getLog() << "Could not read data (" << i
155
-                      << (file.eof() ? " EOF" : "") << ")" << Log::endl;
154
+            Log::get(LOG_ERROR) << "Could not read data (" << i
155
+                                << (file.eof() ? " EOF" : "") << ")" << Log::endl;
156 156
             delete [] buffer;
157 157
             return -7;
158 158
         }
@@ -163,8 +163,8 @@ int pcxLoad(const char* filename, unsigned char** image,
163 163
                 n = c & 0x3F;
164 164
                 c = file.get();
165 165
                 if (!file) {
166
-                    getLog() << "Could not read data rle (" << i
167
-                              << (file.eof() ? " EOF" : "") << ")" << Log::endl;
166
+                    Log::get(LOG_ERROR) << "Could not read data rle (" << i
167
+                                        << (file.eof() ? " EOF" : "") << ")" << Log::endl;
168 168
                     delete [] buffer;
169 169
                     return -8;
170 170
                 }
@@ -186,7 +186,7 @@ int pcxLoad(const char* filename, unsigned char** image,
186 186
             for (unsigned int i = 0; i < 768; i++) {
187 187
                 palette[i] = (unsigned char)file.get();
188 188
                 if (!file) {
189
-                    getLog() << "Could not read 256 color palette (" << i << ")" << Log::endl;
189
+                    Log::get(LOG_ERROR) << "Could not read 256 color palette (" << i << ")" << Log::endl;
190 190
                     delete [] buffer;
191 191
                     delete [] palette;
192 192
                     return -9;
@@ -209,7 +209,7 @@ int pcxLoad(const char* filename, unsigned char** image,
209 209
                     green = palette[(buffer[(y * totalBytes) + x] * 3) + 1];
210 210
                     blue = palette[(buffer[(y * totalBytes) + x] * 3) + 2];
211 211
                 } else {
212
-                    getLog() << "Unsupported number of planes (" << nPlanes << ")" << Log::endl;
212
+                    Log::get(LOG_ERROR) << "Unsupported number of planes (" << nPlanes << ")" << Log::endl;
213 213
                     delete [] buffer;
214 214
                     delete [] palette;
215 215
                     delete [] *image;
@@ -226,7 +226,7 @@ int pcxLoad(const char* filename, unsigned char** image,
226 226
                 } else if (nPlanes == 1) {
227 227
                     red = green = blue = buffer[(y * totalBytes) + x];
228 228
                 } else {
229
-                    getLog() << "Unsupported number of planes (" << nPlanes << ")" << Log::endl;
229
+                    Log::get(LOG_ERROR) << "Unsupported number of planes (" << nPlanes << ")" << Log::endl;
230 230
                     delete [] buffer;
231 231
                     delete [] palette;
232 232
                     delete [] *image;

+ 125
- 127
test/Script.cpp Bestand weergeven

@@ -46,152 +46,150 @@
46 46
     }); \
47 47
 }
48 48
 
49
-namespace {
50
-    int printDataScript(Script& s, bool strings) {
51
-        if (strings) {
52
-            printStrings(s.levelCount(), s.getLevelName, "Level Names");
53
-            printStrings(s.levelCount(), s.getLevelFilename, "Level Filenames");
54
-            printStrings(s.pictureCount(), s.getPictureFilename, "Picture Filenames");
55
-            printStrings(s.cutsceneCount(), s.getCutsceneFilename, "Cutscenes");
56
-            printStrings(s.titleCount(), s.getTitleFilename, "Titles");
57
-            printStrings(s.videoCount(), s.getVideoFilename, "Videos");
58
-            printStrings(s.gameStringCount(), s.getGameString, "Game Strings");
59
-            printStrings(s.pcStringCount(), s.getPCString, "PC Strings");
60
-
61
-            printStrings2D(4, s.levelCount(), s.getPuzzleString, "Puzzles");
62
-            printStrings2D(2, s.levelCount(), s.getPickupString, "Pickups");
63
-            printStrings2D(4, s.levelCount(), s.getKeyString, "Keys");
64
-        } else {
65
-            registerLambda(Script::OP_PICTURE, "Picture");
66
-            registerLambda(Script::OP_PSX_TRACK, "PSX-Track");
67
-            registerLambda(Script::OP_PSX_FMV, "PSX-FMV");
68
-            registerLambda(Script::OP_FMV, "Show FMV");
69
-            registerLambda(Script::OP_GAME, "Load level");
70
-            registerLambda(Script::OP_CUT, "Cutscene");
71
-            registerLambda(Script::OP_COMPLETE, "Level finished");
72
-            registerLambda(Script::OP_DEMO, "Demo sequence");
73
-            registerLambda(Script::OP_PSX_DEMO, "PSX-Demo");
74
-            registerLambda(Script::OP_END, "End of script");
75
-            registerLambda(Script::OP_TRACK, "Sound Track");
76
-            registerLambda(Script::OP_SUNSET, "Sunset");
77
-            registerLambda(Script::OP_LOAD_PIC, "Load picture");
78
-            registerLambda(Script::OP_DEADLY_WATER, "Deadly water");
79
-            registerLambda(Script::OP_REMOVE_WEAPONS, "Remove weapons");
80
-            registerLambda(Script::OP_GAMECOMPLETE, "End of game!");
81
-            registerLambda(Script::OP_CUTANGLE, "Cutscene angle");
82
-            registerLambda(Script::OP_NOFLOOR, "No floor, fall death");
83
-            registerLambda(Script::OP_STARTINV, "Inventory/Bonus");
84
-            registerLambda(Script::OP_STARTANIM, "Start animation");
85
-            registerLambda(Script::OP_SECRETS, "Secrets");
86
-            registerLambda(Script::OP_KILLTOCOMPLETE, "Kill to complete level");
87
-            registerLambda(Script::OP_REMOVE_AMMO, "Remove ammo");
88
-
89
-            for (unsigned int i = 0; i < (s.levelCount() + 1); i++) {
90
-                if (i == 0)
91
-                    std::cout << "Script for Title:" << std::endl;
92
-                else
93
-                    std::cout << "Script for \"" << s.getLevelName(i - 1) << "\" (" << i - 1 << "):" << std::endl;
94
-                int error = s.runScript(i);
95
-                if (error != 0) {
96
-                    std::cout << "Returned " << error << "..." << std::endl;
97
-                    return error;
98
-                }
99
-                std::cout << std::endl;
49
+static int printDataScript(Script& s, bool strings) {
50
+    if (strings) {
51
+        printStrings(s.levelCount(), s.getLevelName, "Level Names");
52
+        printStrings(s.levelCount(), s.getLevelFilename, "Level Filenames");
53
+        printStrings(s.pictureCount(), s.getPictureFilename, "Picture Filenames");
54
+        printStrings(s.cutsceneCount(), s.getCutsceneFilename, "Cutscenes");
55
+        printStrings(s.titleCount(), s.getTitleFilename, "Titles");
56
+        printStrings(s.videoCount(), s.getVideoFilename, "Videos");
57
+        printStrings(s.gameStringCount(), s.getGameString, "Game Strings");
58
+        printStrings(s.pcStringCount(), s.getPCString, "PC Strings");
59
+
60
+        printStrings2D(4, s.levelCount(), s.getPuzzleString, "Puzzles");
61
+        printStrings2D(2, s.levelCount(), s.getPickupString, "Pickups");
62
+        printStrings2D(4, s.levelCount(), s.getKeyString, "Keys");
63
+    } else {
64
+        registerLambda(Script::OP_PICTURE, "Picture");
65
+        registerLambda(Script::OP_PSX_TRACK, "PSX-Track");
66
+        registerLambda(Script::OP_PSX_FMV, "PSX-FMV");
67
+        registerLambda(Script::OP_FMV, "Show FMV");
68
+        registerLambda(Script::OP_GAME, "Load level");
69
+        registerLambda(Script::OP_CUT, "Cutscene");
70
+        registerLambda(Script::OP_COMPLETE, "Level finished");
71
+        registerLambda(Script::OP_DEMO, "Demo sequence");
72
+        registerLambda(Script::OP_PSX_DEMO, "PSX-Demo");
73
+        registerLambda(Script::OP_END, "End of script");
74
+        registerLambda(Script::OP_TRACK, "Sound Track");
75
+        registerLambda(Script::OP_SUNSET, "Sunset");
76
+        registerLambda(Script::OP_LOAD_PIC, "Load picture");
77
+        registerLambda(Script::OP_DEADLY_WATER, "Deadly water");
78
+        registerLambda(Script::OP_REMOVE_WEAPONS, "Remove weapons");
79
+        registerLambda(Script::OP_GAMECOMPLETE, "End of game!");
80
+        registerLambda(Script::OP_CUTANGLE, "Cutscene angle");
81
+        registerLambda(Script::OP_NOFLOOR, "No floor, fall death");
82
+        registerLambda(Script::OP_STARTINV, "Inventory/Bonus");
83
+        registerLambda(Script::OP_STARTANIM, "Start animation");
84
+        registerLambda(Script::OP_SECRETS, "Secrets");
85
+        registerLambda(Script::OP_KILLTOCOMPLETE, "Kill to complete level");
86
+        registerLambda(Script::OP_REMOVE_AMMO, "Remove ammo");
87
+
88
+        for (unsigned int i = 0; i < (s.levelCount() + 1); i++) {
89
+            if (i == 0)
90
+                std::cout << "Script for Title:" << std::endl;
91
+            else
92
+                std::cout << "Script for \"" << s.getLevelName(i - 1) << "\" (" << i - 1 << "):" << std::endl;
93
+            int error = s.runScript(i);
94
+            if (error != 0) {
95
+                std::cout << "Returned " << error << "..." << std::endl;
96
+                return error;
100 97
             }
98
+            std::cout << std::endl;
101 99
         }
102
-
103
-        return 0;
104 100
     }
105 101
 
106
-    int test(const char* file, unsigned int n) {
107
-        Script s;
102
+    return 0;
103
+}
108 104
 
109
-        std::cout << "Testing " << testDescription[n] << std::endl;
105
+static int test(const char* file, unsigned int n) {
106
+    Script s;
110 107
 
111
-        if (s.load(file) != 0) {
112
-            std::cout << "Could not open file " << file << std::endl;
113
-            return 1;
114
-        }
108
+    std::cout << "Testing " << testDescription[n] << std::endl;
115 109
 
116
-        if (s.gameStringCount() != testExpectedGameStringCount[n]) {
117
-            std::cout << "Game String Count " << s.gameStringCount() << " != " << testExpectedGameStringCount[n]
118
-                      << std::endl;
119
-            return 2;
120
-        }
110
+    if (s.load(file) != 0) {
111
+        std::cout << "Could not open file " << file << std::endl;
112
+        return 1;
113
+    }
121 114
 
122
-        if (s.pcStringCount() != testExpectedPlatformStringCount[n]) {
123
-            std::cout << "Platform String Count " << s.pcStringCount() << " != " <<
124
-                      testExpectedPlatformStringCount[n] << std::endl;
125
-            return 3;
126
-        }
115
+    if (s.gameStringCount() != testExpectedGameStringCount[n]) {
116
+        std::cout << "Game String Count " << s.gameStringCount() << " != " << testExpectedGameStringCount[n]
117
+                  << std::endl;
118
+        return 2;
119
+    }
127 120
 
128
-        std::cout << "Success!" << std::endl << std::endl;
129
-        return 0;
121
+    if (s.pcStringCount() != testExpectedPlatformStringCount[n]) {
122
+        std::cout << "Platform String Count " << s.pcStringCount() << " != " <<
123
+                  testExpectedPlatformStringCount[n] << std::endl;
124
+        return 3;
130 125
     }
131 126
 
132
-    int readPayloadChunk(const unsigned char* data, unsigned int size, const char* file) {
133
-        static const unsigned int bufferSize = 16384; // 16K should be enough for everybody :)
134
-        unsigned char buffer[bufferSize];
135
-
136
-        // Initialize decompression
137
-        z_stream stream;
138
-        stream.zalloc = Z_NULL;
139
-        stream.zfree =  Z_NULL;
140
-        stream.opaque = Z_NULL;
141
-        int error = inflateInit(&stream);
142
-        if (error != Z_OK) {
143
-            std::cout << "inflateInit() Error " << error << std::endl;
144
-            return 1;
145
-        }
127
+    std::cout << "Success!" << std::endl << std::endl;
128
+    return 0;
129
+}
146 130
 
147
-        // Inflate data in one go
148
-        stream.avail_in = size;
149
-        stream.next_in = const_cast<unsigned char*>(data);
150
-        stream.avail_out = bufferSize;
151
-        stream.next_out = buffer;
152
-        error = inflate(&stream, Z_FINISH);
153
-        if (error != Z_STREAM_END) {
154
-            std::cout << "inflate() Error " << error << std::endl;
155
-            return 2;
156
-        }
157
-        inflateEnd(&stream);
131
+static int readPayloadChunk(const unsigned char* data, unsigned int size, const char* file) {
132
+    static const unsigned int bufferSize = 16384; // 16K should be enough for everybody :)
133
+    unsigned char buffer[bufferSize];
134
+
135
+    // Initialize decompression
136
+    z_stream stream;
137
+    stream.zalloc = Z_NULL;
138
+    stream.zfree =  Z_NULL;
139
+    stream.opaque = Z_NULL;
140
+    int error = inflateInit(&stream);
141
+    if (error != Z_OK) {
142
+        std::cout << "inflateInit() Error " << error << std::endl;
143
+        return 1;
144
+    }
158 145
 
159
-        // Write buffer to file
160
-        std::ofstream s(file, std::ios_base::out | std::ios_base::binary);
161
-        s.write(reinterpret_cast<const char*>(buffer), bufferSize - stream.avail_out);
146
+    // Inflate data in one go
147
+    stream.avail_in = size;
148
+    stream.next_in = const_cast<unsigned char*>(data);
149
+    stream.avail_out = bufferSize;
150
+    stream.next_out = buffer;
151
+    error = inflate(&stream, Z_FINISH);
152
+    if (error != Z_STREAM_END) {
153
+        std::cout << "inflate() Error " << error << std::endl;
154
+        return 2;
155
+    }
156
+    inflateEnd(&stream);
162 157
 
163
-        return 0;
158
+    // Write buffer to file
159
+    std::ofstream s(file, std::ios_base::out | std::ios_base::binary);
160
+    s.write(reinterpret_cast<const char*>(buffer), bufferSize - stream.avail_out);
161
+
162
+    return 0;
163
+}
164
+
165
+static int runForPayload(unsigned int n, bool print, bool printData) {
166
+    assert(n < testPayloadCount);
167
+    // Get temp file name
168
+    char tmpFile[] = "/tmp/openraider_unit_test_0";
169
+    FILE* f;
170
+    while ((f = fopen(tmpFile, "r")) != NULL) {
171
+        fclose(f);
172
+        tmpFile[26]++;
164 173
     }
165 174
 
166
-    int runForPayload(unsigned int n, bool print, bool printData) {
167
-        assert(n < testPayloadCount);
168
-        // Get temp file name
169
-        char tmpFile[] = "/tmp/openraider_unit_test_0";
170
-        FILE* f;
171
-        while ((f = fopen(tmpFile, "r")) != NULL) {
172
-            fclose(f);
173
-            tmpFile[26]++;
174
-        }
175
+    std::cout << "Temporary test file: " << tmpFile << std::endl;
175 176
 
176
-        std::cout << "Temporary test file: " << tmpFile << std::endl;
177
-
178
-        int error = readPayloadChunk(testPayloads[n], testSizes[n], tmpFile);
179
-        if (error == 0) {
180
-            if (print) {
181
-                Script s;
182
-                error = s.load(tmpFile);
183
-                if (error == 0)
184
-                    error = printDataScript(s, printData);
185
-                else
186
-                    std::cout << "Error loading script!" << std::endl;
187
-            } else {
188
-                error = test(tmpFile, n);
189
-            }
177
+    int error = readPayloadChunk(testPayloads[n], testSizes[n], tmpFile);
178
+    if (error == 0) {
179
+        if (print) {
180
+            Script s;
181
+            error = s.load(tmpFile);
182
+            if (error == 0)
183
+                error = printDataScript(s, printData);
184
+            else
185
+                std::cout << "Error loading script!" << std::endl;
186
+        } else {
187
+            error = test(tmpFile, n);
190 188
         }
191
-
192
-        remove(tmpFile);
193
-        return error;
194 189
     }
190
+
191
+    remove(tmpFile);
192
+    return error;
195 193
 }
196 194
 
197 195
 int main(int argc, char* argv[]) {

+ 85
- 88
test/binary.cpp Bestand weergeven

@@ -12,98 +12,95 @@
12 12
 #include "global.h"
13 13
 #include "utils/binary.h"
14 14
 
15
+const static char testData[] = {
16
+    // Unsigned Integers
17
+    -1,
18
+    -1, -1,
19
+    42, 42, 42, 42,
20
+    -1, -1, -1, -1, -1, 0, 0, 0,
21
+
22
+    // Signed Integers
23
+    -1,
24
+    92, -2,
25
+    102, -3, -1, -1,
26
+    66, 66, 66, 66, 66, 66, 66, 66
27
+};
28
+
29
+static float f1 = 3.1415926f;
30
+static float f2 = 42.23f;
31
+
32
+static void fillFile(const char* name) {
33
+    std::ofstream file(name, std::ios_base::out | std::ios_base::binary);
34
+    file.write(testData, sizeof(testData) / sizeof(testData[0]));
35
+    file.write(reinterpret_cast<char*>(&f1), sizeof(f1));
36
+    file.write(reinterpret_cast<char*>(&f2), sizeof(f2));
37
+}
38
+
39
+static int test(const char* name) {
40
+    BinaryFile file;
41
+    if (file.open(name) != 0) {
42
+        std::cout << "Error opening file " << name << std::endl;
43
+        return 1;
44
+    }
45
+
46
+    if (file.readU8() != 255) {
47
+        std::cout << "Error reading U8!" << std::endl;
48
+        return 2;
49
+    }
50
+
51
+    if (file.readU16() != 65535) {
52
+        std::cout << "Error reading U16!" << std::endl;
53
+        return 3;
54
+    }
55
+
56
+    if (file.readU32() != 707406378) {
57
+        std::cout << "Error reading U32!" << std::endl;
58
+        return 4;
59
+    }
15 60
 
16
-namespace {
17
-    const char testData[] = {
18
-        // Unsigned Integers
19
-        -1,
20
-        -1, -1,
21
-        42, 42, 42, 42,
22
-        -1, -1, -1, -1, -1, 0, 0, 0,
23
-
24
-        // Signed Integers
25
-        -1,
26
-        92, -2,
27
-        102, -3, -1, -1,
28
-        66, 66, 66, 66, 66, 66, 66, 66
29
-    };
30
-
31
-    float f1 = 3.1415926f;
32
-    float f2 = 42.23f;
33
-
34
-    void fillFile(const char* name) {
35
-        std::ofstream file(name, std::ios_base::out | std::ios_base::binary);
36
-        file.write(testData, sizeof(testData) / sizeof(testData[0]));
37
-        file.write(reinterpret_cast<char*>(&f1), sizeof(f1));
38
-        file.write(reinterpret_cast<char*>(&f2), sizeof(f2));
61
+    if (file.readU64() != 1099511627775) {
62
+        std::cout << "Error reading U64!" << std::endl;
63
+        return 5;
39 64
     }
40 65
 
41
-    int test(const char* name) {
42
-        BinaryFile file;
43
-        if (file.open(name) != 0) {
44
-            std::cout << "Error opening file " << name << std::endl;
45
-            return 1;
46
-        }
47
-
48
-        if (file.readU8() != 255) {
49
-            std::cout << "Error reading U8!" << std::endl;
50
-            return 2;
51
-        }
52
-
53
-        if (file.readU16() != 65535) {
54
-            std::cout << "Error reading U16!" << std::endl;
55
-            return 3;
56
-        }
57
-
58
-        if (file.readU32() != 707406378) {
59
-            std::cout << "Error reading U32!" << std::endl;
60
-            return 4;
61
-        }
62
-
63
-        if (file.readU64() != 1099511627775) {
64
-            std::cout << "Error reading U64!" << std::endl;
65
-            return 5;
66
-        }
67
-
68
-        if (file.read8() != -1) {
69
-            std::cout << "Error reading 8!" << std::endl;
70
-            return 6;
71
-        }
72
-
73
-        if (file.read16() != -420) {
74
-            std::cout << "Error reading 16!" << std::endl;
75
-            return 7;
76
-        }
77
-
78
-        if (file.read32() != -666) {
79
-            std::cout << "Error reading 32!" << std::endl;
80
-            return 8;
81
-        }
82
-
83
-        if (file.read64() != 4774451407313060418) {
84
-            std::cout << "Error reading 64!" << std::endl;
85
-            return 9;
86
-        }
87
-
88
-        std::cout << "This test will fail on big-endian machines!" << std::endl;
89
-
90
-        if (file.readFloat() != f1) {
91
-            std::cout << "Error reading float1!" << std::endl;
92
-            return 10;
93
-        }
94
-
95
-        if (file.readFloat() != f2) {
96
-            std::cout << "Error reading float2!" << std::endl;
97
-            return 11;
98
-        }
99
-
100
-        if (file.tell() != 38) {
101
-            std::cout << "Error, file position wrong!" << std::endl;
102
-            return 12;
103
-        }
104
-
105
-        return 0;
66
+    if (file.read8() != -1) {
67
+        std::cout << "Error reading 8!" << std::endl;
68
+        return 6;
106 69
     }
70
+
71
+    if (file.read16() != -420) {
72
+        std::cout << "Error reading 16!" << std::endl;
73
+        return 7;
74
+    }
75
+
76
+    if (file.read32() != -666) {
77
+        std::cout << "Error reading 32!" << std::endl;
78
+        return 8;
79
+    }
80
+
81
+    if (file.read64() != 4774451407313060418) {
82
+        std::cout << "Error reading 64!" << std::endl;
83
+        return 9;
84
+    }
85
+
86
+    std::cout << "This test will fail on big-endian machines!" << std::endl;
87
+
88
+    if (file.readFloat() != f1) {
89
+        std::cout << "Error reading float1!" << std::endl;
90
+        return 10;
91
+    }
92
+
93
+    if (file.readFloat() != f2) {
94
+        std::cout << "Error reading float2!" << std::endl;
95
+        return 11;
96
+    }
97
+
98
+    if (file.tell() != 38) {
99
+        std::cout << "Error, file position wrong!" << std::endl;
100
+        return 12;
101
+    }
102
+
103
+    return 0;
107 104
 }
108 105
 
109 106
 int main() {

Laden…
Annuleren
Opslaan