Browse Source

Back face culling, log levels, clipboard support.

Thomas Buck 10 years ago
parent
commit
71bf2febc7

+ 8
- 0
ChangeLog.md View File

2
 
2
 
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
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
     [ 20140109 ]
13
     [ 20140109 ]
6
     * Display of Bounding Boxes can be individually toggled for Rooms/StaticMeshes
14
     * Display of Bounding Boxes can be individually toggled for Rooms/StaticMeshes
7
     * Tightened imgui Style and changed colors to match the _OpenRaider-blue_
15
     * Tightened imgui Style and changed colors to match the _OpenRaider-blue_

+ 1
- 1
cmake/Doxyfile.in View File

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

+ 12
- 18
include/Game.h View File

15
 
15
 
16
 class Game {
16
 class Game {
17
   public:
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
   private:
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
 #endif
37
 #endif
44
 
38
 

+ 45
- 20
include/Log.h View File

15
 
15
 
16
 #include <glm/gtc/type_precision.hpp>
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
   public:
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
     const static char endl = '\n';
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
         return (*this) << v.x << " " << v.y;
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
         return (*this) << v.x << " " << v.y;
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
         return (*this) << v.x << " " << v.y << " " << v.z;
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
   private:
78
   private:
52
-    std::vector<std::string> mHistory;
79
+    int level;
53
     std::ostringstream printBuffer;
80
     std::ostringstream printBuffer;
54
 };
81
 };
55
 
82
 
56
-Log& getLog();
57
-
58
 #endif
83
 #endif
59
 
84
 

+ 7
- 5
include/system/Shader.h View File

54
     static int initialize();
54
     static int initialize();
55
     static void shutdown();
55
     static void shutdown();
56
 
56
 
57
+    static void set2DState(bool on);
58
+
57
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, unsigned int texture,
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
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP,
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
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& indices,
64
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& indices,
63
                        unsigned int texture, glm::mat4 MVP,
65
                        unsigned int texture, glm::mat4 MVP,
64
-                       TextureStorage store = TextureStorage::GAME);
66
+                       TextureStorage store = TextureStorage::GAME, Shader& shader = textureShader);
65
 
67
 
66
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
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
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices,
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
   private:
73
   private:
72
     int programID;
74
     int programID;

+ 3
- 0
include/system/Window.h View File

28
 
28
 
29
     static void setTextInput(bool t);
29
     static void setTextInput(bool t);
30
     static bool getTextInput();
30
     static bool getTextInput();
31
+
32
+    static void setClipboard(const char* s);
33
+    static const char* getClipboard();
31
 };
34
 };
32
 
35
 
33
 #endif
36
 #endif

+ 3
- 0
include/system/WindowGLFW.h View File

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

+ 3
- 0
include/system/WindowSDL.h View File

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

+ 55
- 6
src/Console.cpp View File

74
 
74
 
75
     static bool scrollToBottom = false;
75
     static bool scrollToBottom = false;
76
     if (ImGui::Begin("Console", &visible, ImVec2(600, 400))) {
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
             scrollToBottom = true;
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
         ImGui::BeginChild("ConsoleText", ImVec2(0, -ImGui::GetTextLineSpacing() * 2));
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
         if (scrollToBottom) {
135
         if (scrollToBottom) {
87
             ImGui::SetScrollPosHere();
136
             ImGui::SetScrollPosHere();
95
                              | ImGuiInputTextFlags_CallbackCompletion
144
                              | ImGuiInputTextFlags_CallbackCompletion
96
                              | ImGuiInputTextFlags_CallbackHistory,
145
                              | ImGuiInputTextFlags_CallbackHistory,
97
                              &Console::callback)) {
146
                              &Console::callback)) {
98
-            getLog() << "> " << buffer << Log::endl;
147
+            Log::get(LOG_USER) << "> " << buffer << Log::endl;
99
             if (strlen(buffer) > 0) {
148
             if (strlen(buffer) > 0) {
100
                 int error = Command::command(buffer);
149
                 int error = Command::command(buffer);
101
                 if (error != 0) {
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
                 if ((lastCommands.size() == 0) || (lastCommands[lastCommands.size() - 1] != buffer))
154
                 if ((lastCommands.size() == 0) || (lastCommands[lastCommands.size() - 1] != buffer))

+ 1
- 1
src/Entity.cpp View File

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

+ 15
- 24
src/Game.cpp View File

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

+ 6
- 10
src/Log.cpp View File

8
 #include "global.h"
8
 #include "global.h"
9
 #include "Log.h"
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 View File

27
     dialogState = false;
27
     dialogState = false;
28
     dialogFunction = callback;
28
     dialogFunction = callback;
29
 
29
 
30
-    getLog() << dialogText << Log::endl;
30
+    Log::get(LOG_USER) << dialogText << Log::endl;
31
 }
31
 }
32
 
32
 
33
 void Menu::ackDialog() {
33
 void Menu::ackDialog() {

+ 2
- 2
src/MenuFolder.cpp View File

58
             // Check maps for validity
58
             // Check maps for validity
59
             Loader::LoaderVersion version = Loader::checkFile(f.getPath());
59
             Loader::LoaderVersion version = Loader::checkFile(f.getPath());
60
             if (version == Loader::TR_UNKNOWN) {
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
                          << "' invalid" << Log::endl;
62
                          << "' invalid" << Log::endl;
63
                 return true; // delete file from list
63
                 return true; // delete file from list
64
             }
64
             }
117
             showDialog("Error reading subfolder!", "OK", "");
117
             showDialog("Error reading subfolder!", "OK", "");
118
         }
118
         }
119
     } else {
119
     } else {
120
-        int error = getGame().loadLevel(mapFolder->getFile((unsigned long)mCursor
120
+        int error = Game::loadLevel(mapFolder->getFile((unsigned long)mCursor
121
                                         - 1 - mapFolder->folderCount()).getPath().c_str());
121
                                         - 1 - mapFolder->folderCount()).getPath().c_str());
122
         if (error == 0) {
122
         if (error == 0) {
123
             visible = false;
123
             visible = false;

+ 16
- 6
src/Mesh.cpp View File

58
     int vertIndex = 0;
58
     int vertIndex = 0;
59
     for (int i = 0; i < indicesBuff.size(); i++) {
59
     for (int i = 0; i < indicesBuff.size(); i++) {
60
         unsigned int texture = TextureManager::getTile(texturesBuff.at(i)).getTexture();
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
             ind.push_back(vert.size());
67
             ind.push_back(vert.size());
63
             vert.push_back(verticesBuff.at(vertIndex + v));
68
             vert.push_back(verticesBuff.at(vertIndex + v));
64
             uvBuff.push_back(TextureManager::getTile(texturesBuff.at(i)).getUV(v));
69
             uvBuff.push_back(TextureManager::getTile(texturesBuff.at(i)).getUV(v));
66
         }
71
         }
67
 
72
 
68
         if (indicesBuff.at(i) == 0) {
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
         vertIndex += (indicesBuff.at(i) == 0) ? 4 : 3;
78
         vertIndex += (indicesBuff.at(i) == 0) ? 4 : 3;
88
 
93
 
89
     vertIndex = 0;
94
     vertIndex = 0;
90
     for (int i = 0; i < indicesColorBuff.size(); i++) {
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
             indCol.push_back(vertCol.size());
102
             indCol.push_back(vertCol.size());
93
             vertCol.push_back(verticesColorBuff.at(vertIndex + v));
103
             vertCol.push_back(verticesColorBuff.at(vertIndex + v));
94
             cols.push_back(colorsBuff.at(i));
104
             cols.push_back(colorsBuff.at(i));
95
         }
105
         }
96
 
106
 
97
         if (indicesColorBuff.at(i) == 0) {
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
         vertIndex += (indicesColorBuff.at(i) == 0) ? 4 : 3;
112
         vertIndex += (indicesColorBuff.at(i) == 0) ? 4 : 3;

+ 5
- 5
src/Render.cpp View File

132
     }
132
     }
133
 
133
 
134
     if (!stbi_write_png(f.c_str(), w, h, 3, buffer, 0)) {
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
     delete [] image;
138
     delete [] image;
145
     std::vector<glm::vec2> uvs;
145
     std::vector<glm::vec2> uvs;
146
 
146
 
147
     vertices.push_back(glm::vec2(x, y + h));
147
     vertices.push_back(glm::vec2(x, y + h));
148
-    vertices.push_back(glm::vec2(x, y));
149
     vertices.push_back(glm::vec2(x + w, y + h));
148
     vertices.push_back(glm::vec2(x + w, y + h));
149
+    vertices.push_back(glm::vec2(x, y));
150
 
150
 
151
     vertices.push_back(glm::vec2(x + w, y));
151
     vertices.push_back(glm::vec2(x + w, y));
152
-    vertices.push_back(glm::vec2(x + w, y + h));
153
     vertices.push_back(glm::vec2(x, y));
152
     vertices.push_back(glm::vec2(x, y));
153
+    vertices.push_back(glm::vec2(x + w, y + h));
154
 
154
 
155
     uvs.push_back(glm::vec2(0.0f, 1.0f));
155
     uvs.push_back(glm::vec2(0.0f, 1.0f));
156
-    uvs.push_back(glm::vec2(0.0f, 0.0f));
157
     uvs.push_back(glm::vec2(1.0f, 1.0f));
156
     uvs.push_back(glm::vec2(1.0f, 1.0f));
157
+    uvs.push_back(glm::vec2(0.0f, 0.0f));
158
 
158
 
159
     uvs.push_back(glm::vec2(1.0f, 0.0f));
159
     uvs.push_back(glm::vec2(1.0f, 0.0f));
160
-    uvs.push_back(glm::vec2(1.0f, 1.0f));
161
     uvs.push_back(glm::vec2(0.0f, 0.0f));
160
     uvs.push_back(glm::vec2(0.0f, 0.0f));
161
+    uvs.push_back(glm::vec2(1.0f, 1.0f));
162
 
162
 
163
     static ShaderBuffer vert, uv;
163
     static ShaderBuffer vert, uv;
164
     vert.bufferData(vertices);
164
     vert.bufferData(vertices);

+ 8
- 3
src/RoomMesh.cpp View File

39
     int vertIndex = 0;
39
     int vertIndex = 0;
40
     for (int i = 0; i < indicesBuff.size(); i++) {
40
     for (int i = 0; i < indicesBuff.size(); i++) {
41
         unsigned int texture = TextureManager::getTile(texturesBuff.at(i)).getTexture();
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
             ind.push_back(vert.size());
48
             ind.push_back(vert.size());
44
             vert.push_back(verticesBuff.at(vertIndex + v));
49
             vert.push_back(verticesBuff.at(vertIndex + v));
45
             uvBuff.push_back(TextureManager::getTile(texturesBuff.at(i)).getUV(v));
50
             uvBuff.push_back(TextureManager::getTile(texturesBuff.at(i)).getUV(v));
47
         }
52
         }
48
 
53
 
49
         if (indicesBuff.at(i) == 0) {
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
         vertIndex += (indicesBuff.at(i) == 0) ? 4 : 3;
59
         vertIndex += (indicesBuff.at(i) == 0) ? 4 : 3;

+ 2
- 2
src/TextureManager.cpp View File

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

+ 9
- 7
src/UI.cpp View File

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

+ 16
- 16
src/commands/Command.cpp View File

25
 }
25
 }
26
 
26
 
27
 void Command::printHelp() {
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
 void Command::fillCommandList() {
31
 void Command::fillCommandList() {
65
         command >> arg;
65
         command >> arg;
66
         if (arg.length() == 0) {
66
         if (arg.length() == 0) {
67
             // List all available commands
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
             for (auto& x : commands) {
71
             for (auto& x : commands) {
72
                 if (x) {
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
             return 0;
79
             return 0;
80
         } else {
80
         } else {
81
             // Show help for a specific command
81
             // Show help for a specific command
87
                     }
87
                     }
88
                 }
88
                 }
89
             }
89
             }
90
-            getLog() << "Unknown command: \"" << arg << "\"" << Log::endl;
90
+            Log::get(LOG_USER) << "Unknown command: \"" << arg << "\"" << Log::endl;
91
             return -1;
91
             return -1;
92
         }
92
         }
93
     }
93
     }
101
         }
101
         }
102
     }
102
     }
103
 
103
 
104
-    getLog() << "Unknown command: \"" << cmd << "\"" << Log::endl;
104
+    Log::get(LOG_USER) << "Unknown command: \"" << cmd << "\"" << Log::endl;
105
     return -1;
105
     return -1;
106
 }
106
 }
107
 
107
 
108
 int Command::executeFile(std::string file) {
108
 int Command::executeFile(std::string file) {
109
     std::string configFile = expandHomeDirectory(file);
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
     std::ifstream f(configFile);
112
     std::ifstream f(configFile);
113
     if (!f) {
113
     if (!f) {
114
-        getLog() << "Could not open file!" << Log::endl;
114
+        Log::get(LOG_ERROR) << "Could not open file!" << Log::endl;
115
         return -1;
115
         return -1;
116
     }
116
     }
117
 
117
 
121
 
121
 
122
         int error = Command::command(line);
122
         int error = Command::command(line);
123
         if (error != 0)
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
     f.close();
127
     f.close();
156
     } else {
156
     } else {
157
         std::string common = candidates.at(0);
157
         std::string common = candidates.at(0);
158
         for (int i = 0; i < candidates.size(); i++) {
158
         for (int i = 0; i < candidates.size(); i++) {
159
-            getLog() << candidates.at(i);
159
+            Log::get(LOG_USER) << candidates.at(i);
160
             if (i < (candidates.size() - 1))
160
             if (i < (candidates.size() - 1))
161
-                getLog() << "/";
161
+                Log::get(LOG_USER) << "/";
162
 
162
 
163
             for (int c = 0; (c < common.size()) && (c < candidates.at(i).size()); c++) {
163
             for (int c = 0; (c < common.size()) && (c < candidates.at(i).size()); c++) {
164
                 if (common.at(c) != candidates.at(i).at(c)) {
164
                 if (common.at(c) != candidates.at(i).at(c)) {
167
                 }
167
                 }
168
             }
168
             }
169
         }
169
         }
170
-        getLog() << Log::endl;
170
+        Log::get(LOG_USER) << Log::endl;
171
         return common;
171
         return common;
172
     }
172
     }
173
 }
173
 }

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

19
 }
19
 }
20
 
20
 
21
 void CommandBind::printHelp() {
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
 int CommandBind::execute(std::istream& args) {
41
 int CommandBind::execute(std::istream& args) {
42
     std::string a, b;
42
     std::string a, b;
43
     if (!(args >> a >> b)) {
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
         return -1;
45
         return -1;
46
     } else {
46
     } else {
47
         ActionEvents e = stringToActionEvent(a);
47
         ActionEvents e = stringToActionEvent(a);
48
         if (e == ActionEventCount) {
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
             return -2;
50
             return -2;
51
         }
51
         }
52
 
52
 
53
         KeyboardButton c = stringToKeyboardButton(b);
53
         KeyboardButton c = stringToKeyboardButton(b);
54
         if (c == unknownKey) {
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
             return -3;
56
             return -3;
57
         }
57
         }
58
 
58
 

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

23
 }
23
 }
24
 
24
 
25
 void CommandLoad::printHelp() {
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
 int CommandLoad::execute(std::istream& args) {
30
 int CommandLoad::execute(std::istream& args) {
31
     if (!RunTime::isRunning()) {
31
     if (!RunTime::isRunning()) {
32
-        getLog() << "Use load command interactively!" << Log::endl;
32
+        Log::get(LOG_USER) << "Use load command interactively!" << Log::endl;
33
         return -1;
33
         return -1;
34
     }
34
     }
35
 
35
 
36
     std::string map;
36
     std::string map;
37
     args >> map;
37
     args >> map;
38
-    int error = getGame().loadLevel(map.c_str());
38
+    int error = Game::loadLevel(map.c_str());
39
     return error;
39
     return error;
40
 }
40
 }
41
 
41
 
50
 }
50
 }
51
 
51
 
52
 void CommandScreenshot::printHelp() {
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
 int CommandScreenshot::execute(std::istream& args) {
58
 int CommandScreenshot::execute(std::istream& args) {
59
     if (!RunTime::isRunning()) {
59
     if (!RunTime::isRunning()) {
60
-        getLog() << "Use sshot command interactively!" << Log::endl;
60
+        Log::get(LOG_USER) << "Use sshot command interactively!" << Log::endl;
61
         return -1;
61
         return -1;
62
     }
62
     }
63
 
63
 

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

21
 }
21
 }
22
 
22
 
23
 int CommandPos::execute(std::istream& args) {
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
         return -1;
26
         return -1;
27
     }
27
     }
28
 
28
 
29
-    getGame().getLara().print();
29
+    Game::getLara().print();
30
     return 0;
30
     return 0;
31
 }
31
 }
32
 
32
 
41
 }
41
 }
42
 
42
 
43
 int CommandViewmodel::execute(std::istream& args) {
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
         return -1;
46
         return -1;
47
     }
47
     }
48
 
48
 
53
     unsigned int n = atoi(s.c_str());
53
     unsigned int n = atoi(s.c_str());
54
 
54
 
55
     if (n < getWorld().sizeSkeletalModel()) {
55
     if (n < getWorld().sizeSkeletalModel()) {
56
-        getGame().getLara().setSkeletalModel(n);
56
+        Game::getLara().setSkeletalModel(n);
57
         return 0;
57
         return 0;
58
     } else {
58
     } else {
59
-        getLog() << "Invalid SkeletalModel index!" << Log::endl;
59
+        Log::get(LOG_USER) << "Invalid SkeletalModel index!" << Log::endl;
60
         return -2;
60
         return -2;
61
     }
61
     }
62
 }
62
 }

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

20
 }
20
 }
21
 
21
 
22
 void CommandMove::printHelp() {
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
 int CommandMove::execute(std::istream& args) {
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
         return -1;
34
         return -1;
35
     }
35
     }
36
 
36
 
37
     std::string s;
37
     std::string s;
38
     args >> s;
38
     args >> s;
39
     if (s.compare("walk") == 0) {
39
     if (s.compare("walk") == 0) {
40
-        getGame().getLara().setMoveType(Entity::MoveTypeWalk);
40
+        Game::getLara().setMoveType(Entity::MoveTypeWalk);
41
     } else if (s.compare("fly") == 0) {
41
     } else if (s.compare("fly") == 0) {
42
-        getGame().getLara().setMoveType(Entity::MoveTypeFly);
42
+        Game::getLara().setMoveType(Entity::MoveTypeFly);
43
     } else if (s.compare("noclip") == 0) {
43
     } else if (s.compare("noclip") == 0) {
44
-        getGame().getLara().setMoveType(Entity::MoveTypeNoClipping);
44
+        Game::getLara().setMoveType(Entity::MoveTypeNoClipping);
45
     } else {
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
         return -2;
47
         return -2;
48
     }
48
     }
49
 
49
 
50
-    getLog() << s  << "ing" << Log::endl;
50
+    Log::get(LOG_USER) << s  << "ing" << Log::endl;
51
     return 0;
51
     return 0;
52
 }
52
 }
53
 
53
 

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

19
 }
19
 }
20
 
20
 
21
 void CommandMode::printHelp() {
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
 
35
 
36
     if (s == "wireframe") {
36
     if (s == "wireframe") {
37
         Render::setMode(RenderMode::Wireframe);
37
         Render::setMode(RenderMode::Wireframe);
38
-        getLog() << "Wireframe mode" << Log::endl;
38
+        Log::get(LOG_USER) << "Wireframe mode" << Log::endl;
39
     } else if (s == "solid") {
39
     } else if (s == "solid") {
40
         Render::setMode(RenderMode::Solid);
40
         Render::setMode(RenderMode::Solid);
41
-        getLog() << "Solid mode" << Log::endl;
41
+        Log::get(LOG_USER) << "Solid mode" << Log::endl;
42
     } else if (s == "texture") {
42
     } else if (s == "texture") {
43
         Render::setMode(RenderMode::Texture);
43
         Render::setMode(RenderMode::Texture);
44
-        getLog() << "Texture Mode" << Log::endl;
44
+        Log::get(LOG_USER) << "Texture Mode" << Log::endl;
45
     } else if (s == "titlescreen") {
45
     } else if (s == "titlescreen") {
46
         Render::setMode(RenderMode::LoadScreen);
46
         Render::setMode(RenderMode::LoadScreen);
47
-        getLog() << "Titlescreen mode" << Log::endl;
47
+        Log::get(LOG_USER) << "Titlescreen mode" << Log::endl;
48
     } else {
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
         return -2;
50
         return -2;
51
     }
51
     }
52
 
52
 

+ 69
- 71
src/commands/CommandSet.cpp View File

24
 }
24
 }
25
 
25
 
26
 void CommandSet::printHelp() {
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
 int CommandSet::execute(std::istream& args) {
66
 int CommandSet::execute(std::istream& args) {
72
     if (var.compare("size") == 0) {
70
     if (var.compare("size") == 0) {
73
         unsigned int w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT;
71
         unsigned int w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT;
74
         if (!(args >> w >> h)) {
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
             return -2;
74
             return -2;
77
         }
75
         }
78
         Window::setSize(glm::i32vec2(w, h));
76
         Window::setSize(glm::i32vec2(w, h));
79
     } else if (var.compare("fullscreen") == 0) {
77
     } else if (var.compare("fullscreen") == 0) {
80
         bool fullscreen = false;
78
         bool fullscreen = false;
81
         if (!(args >> fullscreen)) {
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
             return -3;
81
             return -3;
84
         }
82
         }
85
         Window::setFullscreen(fullscreen);
83
         Window::setFullscreen(fullscreen);
86
     } else if (var.compare("audio") == 0) {
84
     } else if (var.compare("audio") == 0) {
87
         bool audio = false;
85
         bool audio = false;
88
         if (!(args >> audio)) {
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
             return -4;
88
             return -4;
91
         }
89
         }
92
         Sound::setEnabled(audio);
90
         Sound::setEnabled(audio);
93
     } else if (var.compare("volume") == 0) {
91
     } else if (var.compare("volume") == 0) {
94
         float vol = 1.0f;
92
         float vol = 1.0f;
95
         if (!(args >> vol)) {
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
             return -5;
95
             return -5;
98
         }
96
         }
99
         Sound::setVolume(vol);
97
         Sound::setVolume(vol);
100
     } else if (var.compare("mouse_x") == 0) {
98
     } else if (var.compare("mouse_x") == 0) {
101
         float sense = 1.0f;
99
         float sense = 1.0f;
102
         if (!(args >> sense)) {
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
             return -6;
102
             return -6;
105
         }
103
         }
106
         Camera::setSensitivityX(glm::radians(sense));
104
         Camera::setSensitivityX(glm::radians(sense));
107
     } else if (var.compare("mouse_y") == 0) {
105
     } else if (var.compare("mouse_y") == 0) {
108
         float sense = 1.0f;
106
         float sense = 1.0f;
109
         if (!(args >> sense)) {
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
             return -7;
109
             return -7;
112
         }
110
         }
113
         Camera::setSensitivityY(glm::radians(sense));
111
         Camera::setSensitivityY(glm::radians(sense));
114
     } else if (var.compare("fps") == 0) {
112
     } else if (var.compare("fps") == 0) {
115
         bool fps = false;
113
         bool fps = false;
116
         if (!(args >> fps)) {
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
             return -8;
116
             return -8;
119
         }
117
         }
120
         RunTime::setShowFPS(fps);
118
         RunTime::setShowFPS(fps);
139
         args >> temp;
137
         args >> temp;
140
         int error = Font::initialize(expandNames(temp));
138
         int error = Font::initialize(expandNames(temp));
141
         if (error != 0)
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
     } else {
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
         return -1;
143
         return -1;
146
     }
144
     }
147
 
145
 
157
 }
155
 }
158
 
156
 
159
 void CommandGet::printHelp() {
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
 int CommandGet::execute(std::istream& args) {
175
 int CommandGet::execute(std::istream& args) {
179
     args >> var;
177
     args >> var;
180
 
178
 
181
     if (var.compare("size") == 0) {
179
     if (var.compare("size") == 0) {
182
-        getLog() << Window::getSize() << Log::endl;
180
+        Log::get(LOG_USER) << Window::getSize() << Log::endl;
183
     } else if (var.compare("fullscreen") == 0) {
181
     } else if (var.compare("fullscreen") == 0) {
184
-        getLog() << Window::getFullscreen() << Log::endl;
182
+        Log::get(LOG_USER) << Window::getFullscreen() << Log::endl;
185
     } else if (var.compare("audio") == 0) {
183
     } else if (var.compare("audio") == 0) {
186
-        getLog() << Sound::getEnabled() << Log::endl;
184
+        Log::get(LOG_USER) << Sound::getEnabled() << Log::endl;
187
     } else if (var.compare("volume") == 0) {
185
     } else if (var.compare("volume") == 0) {
188
-        getLog() << Sound::getVolume() << Log::endl;
186
+        Log::get(LOG_USER) << Sound::getVolume() << Log::endl;
189
     } else if (var.compare("mouse_x") == 0) {
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
     } else if (var.compare("mouse_y") == 0) {
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
     } else if (var.compare("fps") == 0) {
191
     } else if (var.compare("fps") == 0) {
194
-        getLog() << RunTime::getShowFPS() << Log::endl;
192
+        Log::get(LOG_USER) << RunTime::getShowFPS() << Log::endl;
195
     } else if (var.compare("basedir") == 0) {
193
     } else if (var.compare("basedir") == 0) {
196
-        getLog() << RunTime::getBaseDir() << Log::endl;
194
+        Log::get(LOG_USER) << RunTime::getBaseDir() << Log::endl;
197
     } else if (var.compare("pakdir") == 0) {
195
     } else if (var.compare("pakdir") == 0) {
198
-        getLog() << RunTime::getPakDir() << Log::endl;
196
+        Log::get(LOG_USER) << RunTime::getPakDir() << Log::endl;
199
     } else if (var.compare("audiodir") == 0) {
197
     } else if (var.compare("audiodir") == 0) {
200
-        getLog() << RunTime::getAudioDir() << Log::endl;
198
+        Log::get(LOG_USER) << RunTime::getAudioDir() << Log::endl;
201
     } else if (var.compare("datadir") == 0) {
199
     } else if (var.compare("datadir") == 0) {
202
-        getLog() << RunTime::getDataDir() << Log::endl;
200
+        Log::get(LOG_USER) << RunTime::getDataDir() << Log::endl;
203
     } else if (var.compare("font") == 0) {
201
     } else if (var.compare("font") == 0) {
204
-        getLog() << Font::getFontName() << Log::endl;
202
+        Log::get(LOG_USER) << Font::getFontName() << Log::endl;
205
     } else {
203
     } else {
206
-        getLog() << "get-Error: Unknown variable (" << var << ")" << Log::endl;
204
+        Log::get(LOG_USER) << "get-Error: Unknown variable (" << var << ")" << Log::endl;
207
         return -1;
205
         return -1;
208
     }
206
     }
209
 
207
 

+ 52
- 52
src/loader/LoaderTR2.cpp View File

96
     }
96
     }
97
 
97
 
98
     if (numTextiles > 0)
98
     if (numTextiles > 0)
99
-        getLog() << "LoaderTR2: Found " << numTextiles << " Textures!" << Log::endl;
99
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numTextiles << " Textures!" << Log::endl;
100
     else
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
 void LoaderTR2::loadTextures() {
104
 void LoaderTR2::loadTextures() {
138
     }
138
     }
139
 
139
 
140
     if (numObjectTextures > 0)
140
     if (numObjectTextures > 0)
141
-        getLog() << "LoaderTR2: Found " << numObjectTextures << " Textiles!" << Log::endl;
141
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numObjectTextures << " Textiles!" << Log::endl;
142
     else
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
 void LoaderTR2::loadAnimatedTextures() {
146
 void LoaderTR2::loadAnimatedTextures() {
155
     for (unsigned int a = 0; a < numAnimatedTextures; a++) {
155
     for (unsigned int a = 0; a < numAnimatedTextures; a++) {
156
         int count = animatedTextures.at(pos) + 1;
156
         int count = animatedTextures.at(pos) + 1;
157
         if ((pos + count) >= numWords) {
157
         if ((pos + count) >= numWords) {
158
-            getLog() << "LoaderTR2: Invalid AnimatedTextures ("
158
+            Log::get(LOG_DEBUG) << "LoaderTR2: Invalid AnimatedTextures ("
159
                      << pos + count << " >= " << numWords << ")!" << Log::endl;
159
                      << pos + count << " >= " << numWords << ")!" << Log::endl;
160
             return;
160
             return;
161
         }
161
         }
168
     }
168
     }
169
 
169
 
170
     if ((numAnimatedTextures > 0) || (numWords > 0))
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
     else
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
     if (pos != numWords)
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
 // ---- Rooms ----
179
 // ---- Rooms ----
406
         // Sanity check
406
         // Sanity check
407
         if ((numPortals == 0) && (numVertices == 0)
407
         if ((numPortals == 0) && (numVertices == 0)
408
             && (numRectangles == 0) && (numTriangles == 0))
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
                      << numRectangles << "r " << numTriangles << "t " << numVertices
410
                      << numRectangles << "r " << numTriangles << "t " << numVertices
411
                      << "v" << Log::endl;
411
                      << "v" << Log::endl;
412
     }
412
     }
413
 
413
 
414
     if (numRooms > 0)
414
     if (numRooms > 0)
415
-        getLog() << "LoaderTR2: Found " << numRooms << " Rooms!" << Log::endl;
415
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numRooms << " Rooms!" << Log::endl;
416
     else
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
 void LoaderTR2::loadFloorData() {
420
 void LoaderTR2::loadFloorData() {
426
     }
426
     }
427
 
427
 
428
     if (numFloorData > 0)
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
     else
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
 void LoaderTR2::loadSprites() {
434
 void LoaderTR2::loadSprites() {
468
     }
468
     }
469
 
469
 
470
     if ((numSpriteTextures > 0) || (numSpriteSequences > 0))
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
                  " Sequences!" << Log::endl;
472
                  " Sequences!" << Log::endl;
473
     else
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
 // ---- Meshes ----
477
 // ---- Meshes ----
493
         uint32_t meshPointer = file.readU32();
493
         uint32_t meshPointer = file.readU32();
494
 
494
 
495
         if (numMeshData < (meshPointer / 2)) {
495
         if (numMeshData < (meshPointer / 2)) {
496
-            getLog() << "LoaderTR2: Invalid Mesh: "
496
+            Log::get(LOG_DEBUG) << "LoaderTR2: Invalid Mesh: "
497
                      << (meshPointer / 2) << " > " << numMeshData << Log::endl;
497
                      << (meshPointer / 2) << " > " << numMeshData << Log::endl;
498
             continue;
498
             continue;
499
         }
499
         }
601
     }
601
     }
602
 
602
 
603
     if (numMeshPointers > 0)
603
     if (numMeshPointers > 0)
604
-        getLog() << "LoaderTR2: Found " << numMeshPointers << " Meshes!" << Log::endl;
604
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numMeshPointers << " Meshes!" << Log::endl;
605
     else
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
 void LoaderTR2::loadStaticMeshes() {
609
 void LoaderTR2::loadStaticMeshes() {
640
     }
640
     }
641
 
641
 
642
     if (numStaticMeshes > 0)
642
     if (numStaticMeshes > 0)
643
-        getLog() << "LoaderTR2: Found " << numStaticMeshes << " StaticMeshes!" << Log::endl;
643
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numStaticMeshes << " StaticMeshes!" << Log::endl;
644
     else
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
 // ---- Moveables ----
648
 // ---- Moveables ----
711
     }
711
     }
712
 
712
 
713
     if (numAnimations > 0)
713
     if (numAnimations > 0)
714
-        getLog() << "LoaderTR2: Found " << numAnimations << " Animations!" << Log::endl;
714
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numAnimations << " Animations!" << Log::endl;
715
     else
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
     uint32_t numStateChanges = file.readU32();
718
     uint32_t numStateChanges = file.readU32();
719
     std::vector<StateChange_t> stateChanges;
719
     std::vector<StateChange_t> stateChanges;
726
     }
726
     }
727
 
727
 
728
     if (numStateChanges > 0)
728
     if (numStateChanges > 0)
729
-        getLog() << "LoaderTR2: Found " << numStateChanges << " StateChanges!" << Log::endl;
729
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numStateChanges << " StateChanges!" << Log::endl;
730
     else
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
     uint32_t numAnimDispatches = file.readU32();
733
     uint32_t numAnimDispatches = file.readU32();
734
     std::vector<AnimDispatch_t> animDispatches;
734
     std::vector<AnimDispatch_t> animDispatches;
742
     }
742
     }
743
 
743
 
744
     if (numAnimDispatches > 0)
744
     if (numAnimDispatches > 0)
745
-        getLog() << "LoaderTR2: Found " << numAnimDispatches << " AnimationDispatches!" << Log::endl;
745
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numAnimDispatches << " AnimationDispatches!" << Log::endl;
746
     else
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
     uint32_t numAnimCommands = file.readU32();
749
     uint32_t numAnimCommands = file.readU32();
750
     std::vector<int16_t> animCommands;
750
     std::vector<int16_t> animCommands;
756
     }
756
     }
757
 
757
 
758
     if (numAnimCommands > 0)
758
     if (numAnimCommands > 0)
759
-        getLog() << "LoaderTR2: Found " << numAnimCommands << " AnimationCommands!" << Log::endl;
759
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numAnimCommands << " AnimationCommands!" << Log::endl;
760
     else
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
     // This is really one uint32_t flags, followed by
763
     // This is really one uint32_t flags, followed by
764
     // three int32_t x, y, z. However, we're given the number
764
     // three int32_t x, y, z. However, we're given the number
783
     }
783
     }
784
 
784
 
785
     if (numMeshTrees > 0)
785
     if (numMeshTrees > 0)
786
-        getLog() << "LoaderTR2: Found " << numMeshTrees << " MeshTrees!" << Log::endl;
786
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numMeshTrees << " MeshTrees!" << Log::endl;
787
     else
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
     uint32_t numFrames = file.readU32();
790
     uint32_t numFrames = file.readU32();
791
     std::vector<uint16_t> frames;
791
     std::vector<uint16_t> frames;
804
     }
804
     }
805
 
805
 
806
     if (numFrames > 0)
806
     if (numFrames > 0)
807
-        getLog() << "LoaderTR2: Found " << numFrames << " Frames!" << Log::endl;
807
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numFrames << " Frames!" << Log::endl;
808
     else
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
     uint32_t numMoveables = file.readU32();
811
     uint32_t numMoveables = file.readU32();
812
     for (unsigned int m = 0; m < numMoveables; m++) {
812
     for (unsigned int m = 0; m < numMoveables; m++) {
887
     }
887
     }
888
 
888
 
889
     if (numMoveables > 0)
889
     if (numMoveables > 0)
890
-        getLog() << "LoaderTR2: Found " << numMoveables << " Moveables!" << Log::endl;
890
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numMoveables << " Moveables!" << Log::endl;
891
     else
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
 void LoaderTR2::loadItems() {
895
 void LoaderTR2::loadItems() {
930
                 getWorld().addEntity(e);
930
                 getWorld().addEntity(e);
931
 
931
 
932
                 if (objectID == 0) {
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
     if (numItems > 0)
939
     if (numItems > 0)
940
-        getLog() << "LoaderTR2: Found " << numItems << " Items!" << Log::endl;
940
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numItems << " Items!" << Log::endl;
941
     else
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
 void LoaderTR2::loadBoxesOverlapsZones() {
945
 void LoaderTR2::loadBoxesOverlapsZones() {
997
     }
997
     }
998
 
998
 
999
     if ((numBoxes > 0) || (numOverlaps > 0))
999
     if ((numBoxes > 0) || (numOverlaps > 0))
1000
-        getLog() << "LoaderTR2: Found NPC NavigationHints (" << numBoxes
1000
+        Log::get(LOG_INFO) << "LoaderTR2: Found NPC NavigationHints (" << numBoxes
1001
                  << ", " << numOverlaps << ", " << list << "), unimplemented!" << Log::endl;
1001
                  << ", " << numOverlaps << ", " << list << "), unimplemented!" << Log::endl;
1002
     else
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
 // ---- Sound ----
1006
 // ---- Sound ----
1023
     }
1023
     }
1024
 
1024
 
1025
     if (numSoundSources > 0)
1025
     if (numSoundSources > 0)
1026
-        getLog() << "LoaderTR2: Found " << numSoundSources << " SoundSources" << Log::endl;
1026
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numSoundSources << " SoundSources" << Log::endl;
1027
     else
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
 void LoaderTR2::loadSoundMap() {
1031
 void LoaderTR2::loadSoundMap() {
1052
     }
1052
     }
1053
 
1053
 
1054
     if (numSoundDetails > 0)
1054
     if (numSoundDetails > 0)
1055
-        getLog() << "LoaderTR2: Found " << numSoundDetails << " SoundDetails" << Log::endl;
1055
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numSoundDetails << " SoundDetails" << Log::endl;
1056
     else
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
 void LoaderTR2::loadSampleIndices() {
1060
 void LoaderTR2::loadSampleIndices() {
1064
     }
1064
     }
1065
 
1065
 
1066
     if (numSampleIndices > 0)
1066
     if (numSampleIndices > 0)
1067
-        getLog() << "LoaderTR2: Found " << numSampleIndices << " SampleIndices" << Log::endl;
1067
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numSampleIndices << " SampleIndices" << Log::endl;
1068
     else
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
 void LoaderTR2::loadExternalSoundFile(std::string f) {
1072
 void LoaderTR2::loadExternalSoundFile(std::string f) {
1079
 
1079
 
1080
     BinaryFile sfx;
1080
     BinaryFile sfx;
1081
     if (sfx.open(f) != 0) {
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
         return;
1083
         return;
1084
     }
1084
     }
1085
 
1085
 
1091
             test[i] = sfx.read8();
1091
             test[i] = sfx.read8();
1092
 
1092
 
1093
         if (std::string("RIFF") != std::string(test)) {
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
                      << ", \"" << test << "\" != \"RIFF\")" << Log::endl;
1095
                      << ", \"" << test << "\" != \"RIFF\")" << Log::endl;
1096
             return;
1096
             return;
1097
         }
1097
         }
1111
     }
1111
     }
1112
 
1112
 
1113
     if (riffCount > 0)
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
     else
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
 // ---- Stuff ----
1119
 // ---- Stuff ----
1132
     }
1132
     }
1133
 
1133
 
1134
     if (numCameras > 0)
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
 void LoaderTR2::loadCinematicFrames() {
1138
 void LoaderTR2::loadCinematicFrames() {
1151
     }
1151
     }
1152
 
1152
 
1153
     if (numCinematicFrames > 0)
1153
     if (numCinematicFrames > 0)
1154
-        getLog() << "LoaderTR2: Found " << numCinematicFrames
1154
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numCinematicFrames
1155
                  << " CinematicFrames, unimplemented!" << Log::endl;
1155
                  << " CinematicFrames, unimplemented!" << Log::endl;
1156
 }
1156
 }
1157
 
1157
 
1162
 
1162
 
1163
     // TODO store demo data somewhere, find out meaning
1163
     // TODO store demo data somewhere, find out meaning
1164
     if (numDemoData > 0)
1164
     if (numDemoData > 0)
1165
-        getLog() << "LoaderTR2: Found " << numDemoData << " bytes DemoData, unimplemented!" <<
1165
+        Log::get(LOG_INFO) << "LoaderTR2: Found " << numDemoData << " bytes DemoData, unimplemented!" <<
1166
                  Log::endl;
1166
                  Log::endl;
1167
 }
1167
 }
1168
 
1168
 

+ 18
- 39
src/main.cpp View File

10
 
10
 
11
 #include "global.h"
11
 #include "global.h"
12
 #include "Camera.h"
12
 #include "Camera.h"
13
-#include "Game.h"
14
 #include "Log.h"
13
 #include "Log.h"
15
 #include "MenuFolder.h"
14
 #include "MenuFolder.h"
15
+#include "Render.h"
16
 #include "RunTime.h"
16
 #include "RunTime.h"
17
 #include "SoundManager.h"
17
 #include "SoundManager.h"
18
 #include "TextureManager.h"
18
 #include "TextureManager.h"
28
 
28
 
29
 static std::string configFileToUse;
29
 static std::string configFileToUse;
30
 
30
 
31
-static std::shared_ptr<Game> gGame;
32
-static std::shared_ptr<Log> gLog;
33
 static std::shared_ptr<MenuFolder> gMenu;
31
 static std::shared_ptr<MenuFolder> gMenu;
34
 static std::shared_ptr<World> gWorld;
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
 Menu& getMenu() {
34
 Menu& getMenu() {
45
     return *gMenu;
35
     return *gMenu;
46
 }
36
 }
62
     // RunTime is required by other constructors
52
     // RunTime is required by other constructors
63
     RunTime::initialize();
53
     RunTime::initialize();
64
 
54
 
65
-    gGame.reset(new Game());
66
-    gLog.reset(new Log());
67
     gMenu.reset(new MenuFolder());
55
     gMenu.reset(new MenuFolder());
68
     gWorld.reset(new World());
56
     gWorld.reset(new World());
69
 
57
 
70
     Command::fillCommandList();
58
     Command::fillCommandList();
71
 
59
 
72
-    getLog() << "Initializing " << VERSION << Log::endl;
60
+    Log::get(LOG_INFO) << "Initializing " << VERSION << Log::endl;
73
 
61
 
74
     // Initialize Windowing
62
     // Initialize Windowing
75
     int error = Window::initialize();
63
     int error = Window::initialize();
132
         return -7;
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
     Camera::setSize(Window::getSize());
124
     Camera::setSize(Window::getSize());
144
     getMenu().setVisible(true);
125
     getMenu().setVisible(true);
145
     systemTimerReset();
126
     systemTimerReset();
146
     RunTime::setRunning(true);
127
     RunTime::setRunning(true);
128
+    Render::setMode(RenderMode::LoadScreen);
147
 
129
 
148
     while (RunTime::isRunning()) {
130
     while (RunTime::isRunning()) {
149
         Window::eventHandling();
131
         Window::eventHandling();
169
 }
151
 }
170
 
152
 
171
 void renderFrame() {
153
 void renderFrame() {
172
-    getGame().display();
154
+    Render::display();
173
     getMenu().display();
155
     getMenu().display();
174
     UI::display();
156
     UI::display();
175
     Window::swapBuffers();
157
     Window::swapBuffers();
182
 #include <exception>
164
 #include <exception>
183
 #include <execinfo.h>
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
 #endif // NODEBUG
186
 #endif // NODEBUG

+ 1
- 1
src/system/Font.cpp View File

30
     }
30
     }
31
 
31
 
32
     if (font != "") {
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
         return -1;
34
         return -1;
35
     } else {
35
     } else {
36
         return 0;
36
         return 0;

+ 6
- 6
src/system/FontTTF.cpp View File

43
     unsigned char* pixels = new unsigned char[MAP_WIDTH * MAP_HEIGHT];
43
     unsigned char* pixels = new unsigned char[MAP_WIDTH * MAP_HEIGHT];
44
     if (!stbtt_PackBegin(&context, pixels, MAP_WIDTH, MAP_HEIGHT, 0, 1, nullptr)) {
44
     if (!stbtt_PackBegin(&context, pixels, MAP_WIDTH, MAP_HEIGHT, 0, 1, nullptr)) {
45
         delete [] pixels;
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
         return -1;
47
         return -1;
48
     }
48
     }
49
 
49
 
58
         delete [] pixels;
58
         delete [] pixels;
59
         delete [] charInfo;
59
         delete [] charInfo;
60
         charInfo = nullptr;
60
         charInfo = nullptr;
61
-        getLog() << "Error packing font map!" << Log::endl;
61
+        Log::get(LOG_ERROR) << "Error packing font map!" << Log::endl;
62
         return -2;
62
         return -2;
63
     }
63
     }
64
 
64
 
72
     if (texture < 0) {
72
     if (texture < 0) {
73
         delete [] charInfo;
73
         delete [] charInfo;
74
         charInfo = nullptr;
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
         return -3;
76
         return -3;
77
     }
77
     }
78
 
78
 
102
 
102
 
103
     std::ifstream file(f, std::ios::binary);
103
     std::ifstream file(f, std::ios::binary);
104
     if (!file) {
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
         return -1;
106
         return -1;
107
     }
107
     }
108
 
108
 
119
 
119
 
120
     fontData = new unsigned char[size];
120
     fontData = new unsigned char[size];
121
     if (!file.read(reinterpret_cast<char*>(fontData), size)) {
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
         delete [] fontData;
123
         delete [] fontData;
124
         fontData = nullptr;
124
         fontData = nullptr;
125
         return -2;
125
         return -2;
254
     if (c >= (MAP_NUM_CHARS / 2))
254
     if (c >= (MAP_NUM_CHARS / 2))
255
         begin -= (MAP_NUM_CHARS / 2);
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
              << begin + MAP_NUM_CHARS - 1 << "..." << Log::endl;
258
              << begin + MAP_NUM_CHARS - 1 << "..." << Log::endl;
259
 
259
 
260
     int p = maps.size();
260
     int p = maps.size();

+ 45
- 38
src/system/Shader.cpp View File

62
     assert(programID >= 0);
62
     assert(programID >= 0);
63
     int r = glGetUniformLocation(programID, name);
63
     int r = glGetUniformLocation(programID, name);
64
     if (r < 0) {
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
         return -1;
66
         return -1;
67
     }
67
     }
68
     uniforms.push_back(r);
68
     uniforms.push_back(r);
117
         std::vector<char> message(logLength + 1);
117
         std::vector<char> message(logLength + 1);
118
         glGetShaderInfoLog(vertexID, logLength, nullptr, &message[0]);
118
         glGetShaderInfoLog(vertexID, logLength, nullptr, &message[0]);
119
         if (result != GL_TRUE)
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
         glDeleteShader(vertexID);
122
         glDeleteShader(vertexID);
123
         glDeleteShader(fragmentID);
123
         glDeleteShader(fragmentID);
124
         return -1;
124
         return -1;
135
         std::vector<char> message(logLength + 1);
135
         std::vector<char> message(logLength + 1);
136
         glGetShaderInfoLog(fragmentID, logLength, nullptr, &message[0]);
136
         glGetShaderInfoLog(fragmentID, logLength, nullptr, &message[0]);
137
         if (result != GL_TRUE)
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
         glDeleteShader(vertexID);
140
         glDeleteShader(vertexID);
141
         glDeleteShader(fragmentID);
141
         glDeleteShader(fragmentID);
142
         return -2;
142
         return -2;
155
         std::vector<char> message(logLength + 1);
155
         std::vector<char> message(logLength + 1);
156
         glGetProgramInfoLog(programID, logLength, nullptr, &message[0]);
156
         glGetProgramInfoLog(programID, logLength, nullptr, &message[0]);
157
         if (result != GL_TRUE)
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
         glDeleteShader(vertexID);
160
         glDeleteShader(vertexID);
161
         glDeleteShader(fragmentID);
161
         glDeleteShader(fragmentID);
162
         glDeleteProgram(programID);
162
         glDeleteProgram(programID);
176
 unsigned int Shader::vertexArrayID = 0;
176
 unsigned int Shader::vertexArrayID = 0;
177
 
177
 
178
 int Shader::initialize() {
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
     glGenVertexArrays(1, &vertexArrayID);
184
     glGenVertexArrays(1, &vertexArrayID);
185
     glBindVertexArray(vertexArrayID);
185
     glBindVertexArray(vertexArrayID);
188
     //glClearColor(BLACK[0] / 256.0f, BLACK[1] / 256.0f, BLACK[2] / 256.0f, BLACK[3] / 256.0f);
188
     //glClearColor(BLACK[0] / 256.0f, BLACK[1] / 256.0f, BLACK[2] / 256.0f, BLACK[3] / 256.0f);
189
     glClearColor(0.0f, 0.0f, 0.4f, 1.0f);
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
     glDepthFunc(GL_LESS);
192
     glDepthFunc(GL_LESS);
195
 
193
 
196
     glEnable(GL_BLEND);
194
     glEnable(GL_BLEND);
197
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
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
     glPointSize(5.0f);
197
     glPointSize(5.0f);
203
 
198
 
204
     if (textShader.compile(textShaderVertex, textShaderFragment) < 0)
199
     if (textShader.compile(textShaderVertex, textShaderFragment) < 0)
229
     glDeleteVertexArrays(1, &vertexArrayID);
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
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color,
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
     assert(vertices.getSize() == uvs.getSize());
239
     assert(vertices.getSize() == uvs.getSize());
235
     assert((vertices.getSize() % 3) == 0);
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
     vertices.bindBuffer(0, 2);
246
     vertices.bindBuffer(0, 2);
242
     uvs.bindBuffer(1, 2);
247
     uvs.bindBuffer(1, 2);
243
 
248
 
244
-    glDisable(GL_DEPTH_TEST);
249
+    set2DState(true);
245
     glDrawArrays(GL_TRIANGLES, 0, vertices.getSize());
250
     glDrawArrays(GL_TRIANGLES, 0, vertices.getSize());
246
-    glEnable(GL_DEPTH_TEST);
251
+    set2DState(false);
247
 
252
 
248
     vertices.unbind(0);
253
     vertices.unbind(0);
249
     uvs.unbind(1);
254
     uvs.unbind(1);
250
 }
255
 }
251
 
256
 
252
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture,
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
     assert(vertices.getSize() == uvs.getSize());
259
     assert(vertices.getSize() == uvs.getSize());
255
     assert((vertices.getSize() % 3) == 0);
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
     vertices.bindBuffer(0, 3);
265
     vertices.bindBuffer(0, 3);
261
     uvs.bindBuffer(1, 2);
266
     uvs.bindBuffer(1, 2);
262
     glDrawArrays(GL_TRIANGLES, 0, vertices.getSize());
267
     glDrawArrays(GL_TRIANGLES, 0, vertices.getSize());
265
 }
270
 }
266
 
271
 
267
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& indices,
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
     assert(vertices.getSize() == uvs.getSize());
275
     assert(vertices.getSize() == uvs.getSize());
270
     assert((indices.getSize() % 3) == 0);
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
     vertices.bindBuffer(0, 3);
281
     vertices.bindBuffer(0, 3);
276
     uvs.bindBuffer(1, 2);
282
     uvs.bindBuffer(1, 2);
277
     indices.bindBuffer();
283
     indices.bindBuffer();
280
     uvs.unbind(1);
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
     assert(vertices.getSize() == colors.getSize());
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
     vertices.bindBuffer(0, 3);
295
     vertices.bindBuffer(0, 3);
289
     colors.bindBuffer(1, 3);
296
     colors.bindBuffer(1, 3);
290
     glDrawArrays(mode, 0, vertices.getSize());
297
     glDrawArrays(mode, 0, vertices.getSize());
293
 }
300
 }
294
 
301
 
295
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices,
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
     assert(vertices.getSize() == colors.getSize());
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
     vertices.bindBuffer(0, 3);
308
     vertices.bindBuffer(0, 3);
302
     colors.bindBuffer(1, 3);
309
     colors.bindBuffer(1, 3);
303
     indices.bindBuffer();
310
     indices.bindBuffer();

+ 10
- 10
src/system/SoundAL.cpp View File

35
     alcMakeContextCurrent(context);
35
     alcMakeContextCurrent(context);
36
 
36
 
37
     if (alutInitWithoutContext(nullptr, nullptr) == AL_FALSE) {
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
         return -1;
39
         return -1;
40
     }
40
     }
41
 
41
 
50
 
50
 
51
     clear();
51
     clear();
52
     if (alutExit() == AL_FALSE)
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
     init = false;
54
     init = false;
55
 }
55
 }
56
 
56
 
64
     alDeleteSources(sources.size(), &sources[0]);
64
     alDeleteSources(sources.size(), &sources[0]);
65
     sources.clear();
65
     sources.clear();
66
     if (alGetError() != AL_NO_ERROR) {
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
     alGetError();
70
     alGetError();
71
     alDeleteSources(listenerSources.size(), &listenerSources[0]);
71
     alDeleteSources(listenerSources.size(), &listenerSources[0]);
72
     listenerSources.clear();
72
     listenerSources.clear();
73
     if (alGetError() != AL_NO_ERROR) {
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
     alGetError();
77
     alGetError();
78
     alDeleteBuffers(buffers.size(), &buffers[0]);
78
     alDeleteBuffers(buffers.size(), &buffers[0]);
79
     buffers.clear();
79
     buffers.clear();
80
     if (alGetError() != AL_NO_ERROR) {
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
     for (int i = 0; i < 3; i++)
84
     for (int i = 0; i < 3; i++)
99
     alGetError();
99
     alGetError();
100
     unsigned int r = alutCreateBufferFromFileImage(buffer, length);
100
     unsigned int r = alutCreateBufferFromFileImage(buffer, length);
101
     if (r == AL_NONE) {
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
         return -2;
103
         return -2;
104
     }
104
     }
105
     buffers.push_back(r);
105
     buffers.push_back(r);
122
     alGetError();
122
     alGetError();
123
     alGenSources(1, &id);
123
     alGenSources(1, &id);
124
     if (alGetError() != AL_NO_ERROR) {
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
         return -2;
126
         return -2;
127
     }
127
     }
128
 
128
 
147
         return -1;
147
         return -1;
148
 
148
 
149
     if ((source < 0) || (source >= sources.size()) || (pos == nullptr)) {
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
         return -2;
151
         return -2;
152
     }
152
     }
153
 
153
 
179
         if ((source >= 0) && (source < listenerSources.size()))
179
         if ((source >= 0) && (source < listenerSources.size()))
180
             alSourcePlay(listenerSources.at(source));
180
             alSourcePlay(listenerSources.at(source));
181
         else
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
     } else {
183
     } else {
184
         if ((source >= 0) && (source < sources.size()))
184
         if ((source >= 0) && (source < sources.size()))
185
             alSourcePlay(sources.at(source));
185
             alSourcePlay(sources.at(source));
186
         else
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 View File

20
 
20
 
21
 int Window::initialize() {
21
 int Window::initialize() {
22
     int res;
22
     int res;
23
+
23
 #ifdef USING_SDL
24
 #ifdef USING_SDL
24
     res = WindowSDL::initialize();
25
     res = WindowSDL::initialize();
25
 #elif defined(USING_GLFW)
26
 #elif defined(USING_GLFW)
27
 #else
28
 #else
28
     res = -1;
29
     res = -1;
29
 #endif
30
 #endif
31
+
30
     return res;
32
     return res;
31
 }
33
 }
32
 
34
 
68
 
70
 
69
 glm::i32vec2 Window::getSize() {
71
 glm::i32vec2 Window::getSize() {
70
     glm::i32vec2 ret(-1, -1);
72
     glm::i32vec2 ret(-1, -1);
73
+
71
 #ifdef USING_SDL
74
 #ifdef USING_SDL
72
     ret = WindowSDL::getSize();
75
     ret = WindowSDL::getSize();
73
 #elif defined(USING_GLFW)
76
 #elif defined(USING_GLFW)
87
 
90
 
88
 bool Window::getFullscreen() {
91
 bool Window::getFullscreen() {
89
     bool ret;
92
     bool ret;
93
+
90
 #ifdef USING_SDL
94
 #ifdef USING_SDL
91
     ret = WindowSDL::getFullscreen();
95
     ret = WindowSDL::getFullscreen();
92
 #elif defined(USING_GLFW)
96
 #elif defined(USING_GLFW)
108
 
112
 
109
 bool Window::getMousegrab() {
113
 bool Window::getMousegrab() {
110
     bool ret;
114
     bool ret;
115
+
111
 #ifdef USING_SDL
116
 #ifdef USING_SDL
112
     ret = WindowSDL::getMousegrab();
117
     ret = WindowSDL::getMousegrab();
113
 #elif defined(USING_GLFW)
118
 #elif defined(USING_GLFW)
129
 
134
 
130
 bool Window::getTextInput() {
135
 bool Window::getTextInput() {
131
     bool ret;
136
     bool ret;
137
+
132
 #ifdef USING_SDL
138
 #ifdef USING_SDL
133
     ret = WindowSDL::getTextInput();
139
     ret = WindowSDL::getTextInput();
134
 #elif defined(USING_GLFW)
140
 #elif defined(USING_GLFW)
140
     return ret;
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 View File

106
     textinput = t;
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
 void WindowGLFW::errorCallback(int error, const char* desc) {
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
 void WindowGLFW::sizeCallback(GLFWwindow* w, int width, int height) {
125
 void WindowGLFW::sizeCallback(GLFWwindow* w, int width, int height) {

+ 30
- 9
src/system/WindowSDL.cpp View File

24
 
24
 
25
 int WindowSDL::initialize() {
25
 int WindowSDL::initialize() {
26
     if (SDL_Init(SUBSYSTEMS_USED) != 0) {
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
         return -1;
28
         return -1;
29
     }
29
     }
30
 
30
 
44
         || (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3) != 0)
44
         || (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3) != 0)
45
         || (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3) != 0)
45
         || (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3) != 0)
46
         || (SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE))) {
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
         return -2;
48
         return -2;
49
     }
49
     }
50
 
50
 
51
     window = SDL_CreateWindow(VERSION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
51
     window = SDL_CreateWindow(VERSION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
52
                               size.x, size.y, flags);
52
                               size.x, size.y, flags);
53
     if (!window) {
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
         return -3;
55
         return -3;
56
     }
56
     }
57
 
57
 
58
     context = SDL_GL_CreateContext(window);
58
     context = SDL_GL_CreateContext(window);
59
     if (!context) {
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
         return -4;
61
         return -4;
62
     }
62
     }
63
 
63
 
65
     setTextInput(textinput);
65
     setTextInput(textinput);
66
 
66
 
67
     if (SDL_NumJoysticks() == 0) {
67
     if (SDL_NumJoysticks() == 0) {
68
-        getLog() << "No Joystick found!" << Log::endl;
68
+        Log::get(LOG_INFO) << "No Joystick found!" << Log::endl;
69
         return 0;
69
         return 0;
70
     }
70
     }
71
 
71
 
73
         if (SDL_IsGameController(i)) {
73
         if (SDL_IsGameController(i)) {
74
             controller = SDL_GameControllerOpen(i);
74
             controller = SDL_GameControllerOpen(i);
75
             if (controller) {
75
             if (controller) {
76
-                getLog() << "Using controller \"" << SDL_GameControllerName(controller)
76
+                Log::get(LOG_INFO) << "Using controller \"" << SDL_GameControllerName(controller)
77
                          << "\"..." << Log::endl;
77
                          << "\"..." << Log::endl;
78
                 break;
78
                 break;
79
             } else {
79
             } else {
80
-                getLog() << "Couldn't open controller \"" << SDL_GameControllerNameForIndex(i)
80
+                Log::get(LOG_WARNING) << "Couldn't open controller \"" << SDL_GameControllerNameForIndex(i)
81
                          << "\"!" << Log::endl;
81
                          << "\"!" << Log::endl;
82
             }
82
             }
83
         } else {
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
         SDL_StopTextInput();
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 View File

122
 
122
 
123
     std::vector<std::string> foundFiles, foundFolders;
123
     std::vector<std::string> foundFiles, foundFolders;
124
     if (readFolderItems(foundFiles, foundFolders) != 0) {
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
     if (!listDot) {
128
     if (!listDot) {

+ 12
- 14
src/utils/binary.cpp View File

49
     return ret;
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
 #define ISBIGENDIAN() ((*reinterpret_cast<const char *>(&bigendiandetection)) == 0)
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 View File

25
 
25
 
26
     // Basic validation
26
     // Basic validation
27
     if (!file.read((char*)(&header[0]), 128)) {
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
         delete [] header;
29
         delete [] header;
30
         return -1;
30
         return -1;
31
     }
31
     }
32
 
32
 
33
     if (header[0] != 0x0A) {
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
         delete [] header;
35
         delete [] header;
36
         return -2;
36
         return -2;
37
     }
37
     }
38
 
38
 
39
     if ((header[1] != 0) && ((header[1] < 2) || (header[1] > 5))) {
39
     if ((header[1] != 0) && ((header[1] < 2) || (header[1] > 5))) {
40
         // Valid: 0, 2, 3, 4, 5
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
         delete [] header;
42
         delete [] header;
43
         return -3;
43
         return -3;
44
     }
44
     }
45
 
45
 
46
     if ((header[2] != 0) && (header[2] != 1)) {
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
         delete [] header;
48
         delete [] header;
49
         return -4;
49
         return -4;
50
     }
50
     }
51
 
51
 
52
     if (header[3] != 8) {
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
         delete [] header;
54
         delete [] header;
55
         return -5;
55
         return -5;
56
     }
56
     }
57
 
57
 
58
     if (header[64] != 0) {
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
         delete [] header;
60
         delete [] header;
61
         return -6;
61
         return -6;
62
     }
62
     }
83
 
83
 
84
     // Basic validation
84
     // Basic validation
85
     if (!file.read((char*)(&header[0]), 128)) {
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
         delete [] header;
87
         delete [] header;
88
         return -1;
88
         return -1;
89
     }
89
     }
90
 
90
 
91
     if (header[0] != 0x0A) {
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
         delete [] header;
93
         delete [] header;
94
         return -2;
94
         return -2;
95
     }
95
     }
96
 
96
 
97
     if ((header[1] != 0) && ((header[1] < 2) || (header[1] > 5))) {
97
     if ((header[1] != 0) && ((header[1] < 2) || (header[1] > 5))) {
98
         // Valid: 0, 2, 3, 4, 5
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
         delete [] header;
100
         delete [] header;
101
         return -3;
101
         return -3;
102
     }
102
     }
103
 
103
 
104
     if ((header[2] != 0) && (header[2] != 1)) {
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
         delete [] header;
106
         delete [] header;
107
         return -4;
107
         return -4;
108
     }
108
     }
109
 
109
 
110
     if (header[3] != 8) {
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
         delete [] header;
112
         delete [] header;
113
         return -5;
113
         return -5;
114
     }
114
     }
115
 
115
 
116
     if (header[64] != 0) {
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
         delete [] header;
118
         delete [] header;
119
         return -6;
119
         return -6;
120
     }
120
     }
151
         unsigned int n = 1; // Run-length-encoding assumes 1
151
         unsigned int n = 1; // Run-length-encoding assumes 1
152
         int c = file.get();
152
         int c = file.get();
153
         if (!file) {
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
             delete [] buffer;
156
             delete [] buffer;
157
             return -7;
157
             return -7;
158
         }
158
         }
163
                 n = c & 0x3F;
163
                 n = c & 0x3F;
164
                 c = file.get();
164
                 c = file.get();
165
                 if (!file) {
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
                     delete [] buffer;
168
                     delete [] buffer;
169
                     return -8;
169
                     return -8;
170
                 }
170
                 }
186
             for (unsigned int i = 0; i < 768; i++) {
186
             for (unsigned int i = 0; i < 768; i++) {
187
                 palette[i] = (unsigned char)file.get();
187
                 palette[i] = (unsigned char)file.get();
188
                 if (!file) {
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
                     delete [] buffer;
190
                     delete [] buffer;
191
                     delete [] palette;
191
                     delete [] palette;
192
                     return -9;
192
                     return -9;
209
                     green = palette[(buffer[(y * totalBytes) + x] * 3) + 1];
209
                     green = palette[(buffer[(y * totalBytes) + x] * 3) + 1];
210
                     blue = palette[(buffer[(y * totalBytes) + x] * 3) + 2];
210
                     blue = palette[(buffer[(y * totalBytes) + x] * 3) + 2];
211
                 } else {
211
                 } else {
212
-                    getLog() << "Unsupported number of planes (" << nPlanes << ")" << Log::endl;
212
+                    Log::get(LOG_ERROR) << "Unsupported number of planes (" << nPlanes << ")" << Log::endl;
213
                     delete [] buffer;
213
                     delete [] buffer;
214
                     delete [] palette;
214
                     delete [] palette;
215
                     delete [] *image;
215
                     delete [] *image;
226
                 } else if (nPlanes == 1) {
226
                 } else if (nPlanes == 1) {
227
                     red = green = blue = buffer[(y * totalBytes) + x];
227
                     red = green = blue = buffer[(y * totalBytes) + x];
228
                 } else {
228
                 } else {
229
-                    getLog() << "Unsupported number of planes (" << nPlanes << ")" << Log::endl;
229
+                    Log::get(LOG_ERROR) << "Unsupported number of planes (" << nPlanes << ")" << Log::endl;
230
                     delete [] buffer;
230
                     delete [] buffer;
231
                     delete [] palette;
231
                     delete [] palette;
232
                     delete [] *image;
232
                     delete [] *image;

+ 125
- 127
test/Script.cpp View File

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
 int main(int argc, char* argv[]) {
195
 int main(int argc, char* argv[]) {

+ 85
- 88
test/binary.cpp View File

12
 #include "global.h"
12
 #include "global.h"
13
 #include "utils/binary.h"
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
 int main() {
106
 int main() {

Loading…
Cancel
Save