Browse Source

imgui integration working more or less

Thomas Buck 9 years ago
parent
commit
1bb089c311

+ 4
- 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
+    [ 20140903 ]
6
+    * Finishing imgui integration, but now as UI layer and not on top of everything
7
+    * All global objects are now explicitly allocated in main
8
+
5
     [ 20140901 ]
9
     [ 20140901 ]
6
     * Created abstract UI class handling “windows” like menu and console. Windows
10
     * Created abstract UI class handling “windows” like menu and console. Windows
7
       can be stacked arbitrarily. The top most gets keyboard/mouse/action events.
11
       can be stacked arbitrarily. The top most gets keyboard/mouse/action events.

+ 1
- 0
README.md View File

109
 | -----------------:|:--------------------- |
109
 | -----------------:|:--------------------- |
110
 | &lt;Esc&gt;       | Toggle menu           |
110
 | &lt;Esc&gt;       | Toggle menu           |
111
 | &lt;backquote&gt; | Console toggle on/off |
111
 | &lt;backquote&gt; | Console toggle on/off |
112
+| q                 | Toggle debug windows  |
112
 | w                 | Move forward          |
113
 | w                 | Move forward          |
113
 | s                 | Move back             |
114
 | s                 | Move back             |
114
 | a                 | Move left             |
115
 | a                 | Move left             |

+ 0
- 1
TODO.md View File

25
 
25
 
26
 * Depend on physfs for easier file location management
26
 * Depend on physfs for easier file location management
27
 * Depend on libcdio, use it to read original CDs or CUE/TOC/ISO images
27
 * Depend on libcdio, use it to read original CDs or CUE/TOC/ISO images
28
-* Depend on imgui for nicer GUIs?
29
 * Add ability to play the FMVs. Format? VLC can play them!
28
 * Add ability to play the FMVs. Format? VLC can play them!
30
 * Cut TGA image reader, currently only used for menu background?!
29
 * Cut TGA image reader, currently only used for menu background?!
31
     * Need useful, always available image writer alternative for screenshots then
30
     * Need useful, always available image writer alternative for screenshots then

+ 1
- 0
data/OpenRaider.ini View File

22
 
22
 
23
 bind menu     "escape"
23
 bind menu     "escape"
24
 bind console  "backquote"
24
 bind console  "backquote"
25
+bind debug    'q'
25
 bind forward  'w'
26
 bind forward  'w'
26
 bind backward 's'
27
 bind backward 's'
27
 bind left     'a'
28
 bind left     'a'

+ 37
- 0
include/Debug.h View File

1
+/*!
2
+ * \file include/Debug.h
3
+ * \brief Debug UI
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _DEBUG_H_
9
+#define _DEBUG_H_
10
+
11
+#include "UI.h"
12
+
13
+class Debug : public UI {
14
+public:
15
+    Debug();
16
+    virtual ~Debug();
17
+
18
+    virtual int initialize();
19
+    virtual void eventsFinished();
20
+    virtual void display();
21
+
22
+    virtual void handleKeyboard(KeyboardButton key, bool pressed);
23
+    virtual void handleText(char *text, bool notFinished);
24
+    virtual void handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
25
+    virtual void handleMouseMotion(int xrel, int yrel, int xabs, int yabs);
26
+    virtual void handleMouseScroll(int xrel, int yrel);
27
+
28
+private:
29
+    static void renderImGui(ImDrawList** const draw_lists, int count);
30
+
31
+    static unsigned int fontTex;
32
+};
33
+
34
+Debug &getDebug();
35
+
36
+#endif
37
+

+ 2
- 2
include/Game.h View File

24
     Game();
24
     Game();
25
     ~Game();
25
     ~Game();
26
 
26
 
27
-    int initialize();
27
+    virtual int initialize();
28
 
28
 
29
     bool isLoaded();
29
     bool isLoaded();
30
 
30
 
34
 
34
 
35
     virtual void display();
35
     virtual void display();
36
     virtual void handleAction(ActionEvents action, bool isFinished);
36
     virtual void handleAction(ActionEvents action, bool isFinished);
37
-    virtual void handleMouseMotion(int xrel, int yrel);
37
+    virtual void handleMouseMotion(int xrel, int yrel, int xabs, int yabs);
38
     virtual void moveToTop() { }
38
     virtual void moveToTop() { }
39
     virtual void makeInvisible() { }
39
     virtual void makeInvisible() { }
40
 
40
 

+ 2
- 4
include/MenuFolder.h View File

36
 
36
 
37
 private:
37
 private:
38
 
38
 
39
-    virtual int initialize(std::string s);
40
-
41
-    virtual int initialize(Folder *folder, bool filter = true);
42
-
39
+    int init(std::string s);
40
+    int init(Folder *folder, bool filter = true);
43
     virtual void loadOrOpen();
41
     virtual void loadOrOpen();
44
 
42
 
45
     long mCursor;
43
     long mCursor;

+ 10
- 18
include/UI.h View File

9
 #define _UI_H_
9
 #define _UI_H_
10
 
10
 
11
 #include <functional>
11
 #include <functional>
12
-#include <list>
13
 #include <memory>
12
 #include <memory>
14
-#include <tuple>
15
 #include <vector>
13
 #include <vector>
16
 
14
 
17
 #include "imgui/imgui.h"
15
 #include "imgui/imgui.h"
20
 public:
18
 public:
21
     virtual ~UI();
19
     virtual ~UI();
22
 
20
 
21
+    virtual int initialize();
22
+    virtual void eventsFinished();
23
     virtual void display();
23
     virtual void display();
24
+
24
     virtual void handleKeyboard(KeyboardButton key, bool pressed);
25
     virtual void handleKeyboard(KeyboardButton key, bool pressed);
25
     virtual void handleText(char *text, bool notFinished);
26
     virtual void handleText(char *text, bool notFinished);
26
     virtual void handleAction(ActionEvents action, bool isFinished);
27
     virtual void handleAction(ActionEvents action, bool isFinished);
27
     virtual void handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
28
     virtual void handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
28
-    virtual void handleMouseMotion(int xrel, int yrel);
29
+    virtual void handleMouseMotion(int xrel, int yrel, int xabs, int yabs);
29
     virtual void handleMouseScroll(int xrel, int yrel);
30
     virtual void handleMouseScroll(int xrel, int yrel);
30
 
31
 
31
     virtual bool isOnTop();
32
     virtual bool isOnTop();
32
     virtual void moveToTop();
33
     virtual void moveToTop();
33
     virtual void makeInvisible();
34
     virtual void makeInvisible();
34
 
35
 
35
-    static int initialize();
36
-    static void eventsFinished();
37
-    static void displayInOrder();
36
+    // ----------------------------------
37
+
38
+    static int passInitialize();
39
+    static void passEvents();
40
+    static void passDisplay();
38
     static void passKeyboard(KeyboardButton key, bool pressed);
41
     static void passKeyboard(KeyboardButton key, bool pressed);
39
     static void passText(char *text, bool notFinished);
42
     static void passText(char *text, bool notFinished);
40
     static void passMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
43
     static void passMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
41
-    static void passMouseMotion(int xrel, int yrel);
44
+    static void passMouseMotion(int xrel, int yrel, int xabs, int yabs);
42
     static void passMouseScroll(int xrel, int yrel);
45
     static void passMouseScroll(int xrel, int yrel);
43
 
46
 
44
 protected:
47
 protected:
48
     long zPos;
51
     long zPos;
49
 
52
 
50
 private:
53
 private:
51
-    static void sendKeyboard(KeyboardButton key, bool pressed);
52
-    static void sendText(char *text, bool notFinished);
53
-    static void sendMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
54
-    static void sendMouseMotion(int xrel, int yrel);
55
-    static void sendMouseScroll(int xrel, int yrel);
56
-    static void renderImGui(ImDrawList** const draw_lists, int count);
57
     static void findInList(UI *w, std::function<void (unsigned long i)> func);
54
     static void findInList(UI *w, std::function<void (unsigned long i)> func);
58
     static bool isOnTop(unsigned long windowID);
55
     static bool isOnTop(unsigned long windowID);
59
     static void moveToTop(unsigned long windowID);
56
     static void moveToTop(unsigned long windowID);
61
     static bool compareUIs(UI* a, UI* b);
58
     static bool compareUIs(UI* a, UI* b);
62
 
59
 
63
     static std::vector<UI*> windows;
60
     static std::vector<UI*> windows;
64
-    static std::list<std::tuple<KeyboardButton, bool>> keyboardEvents;
65
-    static std::list<std::tuple<char *, bool>> textEvents;
66
-    static std::list<std::tuple<unsigned int, unsigned int, KeyboardButton, bool>> clickEvents;
67
-    static std::list<std::tuple<int, int>> motionEvents;
68
-    static std::list<std::tuple<int, int>> scrollEvents;
69
 };
61
 };
70
 
62
 
71
 #endif
63
 #endif

+ 3
- 1
include/global.h View File

40
 // Actions that can be bound to a key and sent to the game engine
40
 // Actions that can be bound to a key and sent to the game engine
41
 typedef enum {
41
 typedef enum {
42
     menuAction = 0,
42
     menuAction = 0,
43
-    consoleAction, // menu and console should always be the first two items
43
+    consoleAction,
44
+    debugAction,
45
+
44
     forwardAction,
46
     forwardAction,
45
     backwardAction,
47
     backwardAction,
46
     leftAction,
48
     leftAction,

+ 1
- 0
src/CMakeLists.txt View File

49
 # Set Source files
49
 # Set Source files
50
 set (SRCS ${SRCS} "Camera.cpp")
50
 set (SRCS ${SRCS} "Camera.cpp")
51
 set (SRCS ${SRCS} "Console.cpp")
51
 set (SRCS ${SRCS} "Console.cpp")
52
+set (SRCS ${SRCS} "Debug.cpp")
52
 set (SRCS ${SRCS} "Entity.cpp")
53
 set (SRCS ${SRCS} "Entity.cpp")
53
 set (SRCS ${SRCS} "Exception.cpp")
54
 set (SRCS ${SRCS} "Exception.cpp")
54
 set (SRCS ${SRCS} "Font.cpp")
55
 set (SRCS ${SRCS} "Font.cpp")

+ 0
- 5
src/Camera.cpp View File

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

+ 0
- 5
src/Console.cpp View File

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

+ 169
- 0
src/Debug.cpp View File

1
+/*!
2
+ * \file src/Debug.cpp
3
+ * \brief Debug UI
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include <algorithm>
9
+
10
+#include "global.h"
11
+#include "Debug.h"
12
+#include "TextureManager.h"
13
+#include "Window.h"
14
+
15
+#define STB_IMAGE_IMPLEMENTATION
16
+#include "imgui/stb_image.h"
17
+
18
+unsigned int Debug::fontTex;
19
+
20
+Debug::Debug() {
21
+    zPos = -1;
22
+
23
+    UI::addWindow(this);
24
+}
25
+
26
+Debug::~Debug() {
27
+    UI::removeWindow(this);
28
+}
29
+
30
+int Debug::initialize() {
31
+    ImGuiIO& io = ImGui::GetIO();
32
+    io.DisplaySize = ImVec2((float)getWindow().getWidth(), (float)getWindow().getHeight());
33
+    io.DeltaTime = 1.0f/60.0f;
34
+    io.PixelCenterOffset = 0.0f;
35
+
36
+    io.KeyMap[ImGuiKey_Tab] = tabKey;
37
+    io.KeyMap[ImGuiKey_LeftArrow] = leftKey;
38
+    io.KeyMap[ImGuiKey_RightArrow] = rightKey;
39
+    io.KeyMap[ImGuiKey_UpArrow] = upKey;
40
+    io.KeyMap[ImGuiKey_DownArrow] = downKey;
41
+    io.KeyMap[ImGuiKey_Home] = homeKey;
42
+    io.KeyMap[ImGuiKey_End] = endKey;
43
+    io.KeyMap[ImGuiKey_Delete] = delKey;
44
+    io.KeyMap[ImGuiKey_Backspace] = backspaceKey;
45
+    io.KeyMap[ImGuiKey_Enter] = enterKey;
46
+    io.KeyMap[ImGuiKey_Escape] = escapeKey;
47
+    io.KeyMap[ImGuiKey_A] = aKey;
48
+    io.KeyMap[ImGuiKey_C] = cKey;
49
+    io.KeyMap[ImGuiKey_V] = vKey;
50
+    io.KeyMap[ImGuiKey_X] = xKey;
51
+    io.KeyMap[ImGuiKey_Y] = yKey;
52
+    io.KeyMap[ImGuiKey_Z] = zKey;
53
+
54
+    io.RenderDrawListsFn = Debug::renderImGui;
55
+
56
+    // Load font texture
57
+    //glGenTextures(1, &fontTex);
58
+    //glBindTexture(GL_TEXTURE_2D, fontTex);
59
+    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
60
+    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
61
+    const void* png_data;
62
+    unsigned int png_size;
63
+    ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
64
+    int tex_x, tex_y, tex_comp;
65
+    void* tex_data = stbi_load_from_memory((const unsigned char*)png_data, (int)png_size, &tex_x, &tex_y, &tex_comp, 0);
66
+    //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_x, tex_y, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data);
67
+    fontTex = getTextureManager().loadBufferSlot((unsigned char *)tex_data, tex_x, tex_y, RGBA, 32, 0);
68
+    stbi_image_free(tex_data);
69
+
70
+    return 0;
71
+}
72
+
73
+void Debug::display() {
74
+    ImGui::Render();
75
+}
76
+
77
+void Debug::eventsFinished() {
78
+    ImGui::NewFrame();
79
+}
80
+
81
+void Debug::handleKeyboard(KeyboardButton key, bool pressed) {
82
+    ImGuiIO& io = ImGui::GetIO();
83
+    io.KeysDown[key] = pressed;
84
+    io.KeyCtrl = io.KeysDown[leftctrlKey] | io.KeysDown[rightctrlKey];
85
+    io.KeyShift = io.KeysDown[leftshiftKey] | io.KeysDown[rightshiftKey];
86
+}
87
+
88
+void Debug::handleText(char *text, bool notFinished) {
89
+    ImGuiIO& io = ImGui::GetIO();
90
+    while (*text != '\0') {
91
+        io.AddInputCharacter(*text);
92
+        text++;
93
+    }
94
+}
95
+
96
+void Debug::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
97
+    ImGuiIO& io = ImGui::GetIO();
98
+    io.MousePos = ImVec2((float)x, (float)y);
99
+    if (button == leftmouseKey) {
100
+        io.MouseDown[0] = !released;
101
+    } else if (button == rightmouseKey) {
102
+        io.MouseDown[1] = !released;
103
+    } else if (button == middlemouseKey) {
104
+        io.MouseDown[2] = !released;
105
+    } else if (button == fourthmouseKey) {
106
+        io.MouseDown[3] = !released;
107
+    } else if (button == fifthmouseKey) {
108
+        io.MouseDown[4] = !released;
109
+    }
110
+}
111
+
112
+void Debug::handleMouseMotion(int xrel, int yrel, int xabs, int yabs) {
113
+    ImGuiIO& io = ImGui::GetIO();
114
+    io.MousePos = ImVec2((float)xabs, (float)yabs);
115
+}
116
+
117
+void Debug::handleMouseScroll(int xrel, int yrel) {
118
+    ImGuiIO& io = ImGui::GetIO();
119
+    io.MouseWheel = (yrel != 0) ? yrel > 0 ? 1 : -1 : 0;
120
+}
121
+
122
+void Debug::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
123
+    if (cmd_lists_count == 0)
124
+        return;
125
+
126
+    getWindow().glEnter2D();
127
+
128
+    glDisable(GL_CULL_FACE);
129
+    glDisable(GL_DEPTH_TEST);
130
+    glEnable(GL_SCISSOR_TEST);
131
+    //glEnableClientState(GL_VERTEX_ARRAY);
132
+    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
133
+    glEnableClientState(GL_COLOR_ARRAY);
134
+
135
+    // Setup texture
136
+    getTextureManager().bindTextureId(fontTex);
137
+
138
+    const float width = ImGui::GetIO().DisplaySize.x;
139
+    const float height = ImGui::GetIO().DisplaySize.y;
140
+
141
+    // Render command lists
142
+    for (int n = 0; n < cmd_lists_count; n++) {
143
+        const ImDrawList* cmd_list = cmd_lists[n];
144
+        const unsigned char* vtx_buffer = (const unsigned char*)cmd_list->vtx_buffer.begin();
145
+        glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer));
146
+        glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer+8));
147
+        glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer+16));
148
+
149
+        int vtx_offset = 0;
150
+        const ImDrawCmd* pcmd_end = cmd_list->commands.end();
151
+        for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++) {
152
+            glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w),
153
+                    (int)(pcmd->clip_rect.z - pcmd->clip_rect.x),
154
+                    (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
155
+            glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
156
+            vtx_offset += pcmd->vtx_count;
157
+        }
158
+    }
159
+
160
+    glEnable(GL_CULL_FACE);
161
+    glEnable(GL_DEPTH_TEST);
162
+    glDisable(GL_SCISSOR_TEST);
163
+    glDisableClientState(GL_COLOR_ARRAY);
164
+    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
165
+    //glDisableClientState(GL_VERTEX_ARRAY);
166
+
167
+    getWindow().glExit2D();
168
+}
169
+

+ 0
- 6
src/Font.cpp View File

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

+ 1
- 6
src/Game.cpp View File

29
 std::map<int, int> gMapTex2Bump;
29
 std::map<int, int> gMapTex2Bump;
30
 #endif
30
 #endif
31
 
31
 
32
-Game &getGame() {
33
-    static Game gGame;
34
-    return gGame;
35
-}
36
-
37
 Game::Game() {
32
 Game::Game() {
38
     zPos = 0;
33
     zPos = 0;
39
     mLoaded = false;
34
     mLoaded = false;
171
     }
166
     }
172
 }
167
 }
173
 
168
 
174
-void Game::handleMouseMotion(int xrel, int yrel) {
169
+void Game::handleMouseMotion(int xrel, int yrel, int xabs, int yabs) {
175
     if (mLoaded) {
170
     if (mLoaded) {
176
         // Move Camera on X Axis
171
         // Move Camera on X Axis
177
         if (xrel > 0)
172
         if (xrel > 0)

+ 0
- 5
src/Menu.cpp View File

12
 #include "Menu.h"
12
 #include "Menu.h"
13
 #include "MenuFolder.h"
13
 #include "MenuFolder.h"
14
 
14
 
15
-Menu &getMenu() {
16
-    static MenuFolder gMenu;
17
-    return gMenu;
18
-}
19
-
20
 void Menu::showDialog(std::string msg, std::string btn1, std::string btn2,
15
 void Menu::showDialog(std::string msg, std::string btn1, std::string btn2,
21
         std::function<int (bool state)> callback) {
16
         std::function<int (bool state)> callback) {
22
     // Only show one dialog at a time
17
     // Only show one dialog at a time

+ 8
- 7
src/MenuFolder.cpp View File

33
 }
33
 }
34
 
34
 
35
 int MenuFolder::initialize() {
35
 int MenuFolder::initialize() {
36
-    return initialize(getOpenRaider().getPakDir());
36
+    return init(getOpenRaider().getPakDir());
37
 }
37
 }
38
 
38
 
39
-int MenuFolder::initialize(std::string s) {
40
-    return initialize(new Folder(s));
39
+int MenuFolder::init(std::string s) {
40
+    return init(new Folder(s));
41
 }
41
 }
42
 
42
 
43
-int MenuFolder::initialize(Folder *folder, bool filter) {
43
+int MenuFolder::init(Folder *folder, bool filter) {
44
     if (mapFolder != nullptr)
44
     if (mapFolder != nullptr)
45
         delete mapFolder;
45
         delete mapFolder;
46
+
46
     mapFolder = folder;
47
     mapFolder = folder;
47
     mMin = mCursor = 0;
48
     mMin = mCursor = 0;
48
 
49
 
111
 
112
 
112
 void MenuFolder::loadOrOpen() {
113
 void MenuFolder::loadOrOpen() {
113
     if (mCursor == 0) {
114
     if (mCursor == 0) {
114
-        if (initialize(mapFolder->getParent().getPath()) != 0) {
115
+        if (init(mapFolder->getParent().getPath()) != 0) {
115
             showDialog("Error reading parent folder!", "OK", "");
116
             showDialog("Error reading parent folder!", "OK", "");
116
         }
117
         }
117
     } else if ((mCursor - 1) < mapFolder->folderCount()) {
118
     } else if ((mCursor - 1) < mapFolder->folderCount()) {
118
-        if (initialize(mapFolder->getFolder(mCursor - 1).getPath()) != 0) {
119
+        if (init(mapFolder->getFolder(mCursor - 1).getPath()) != 0) {
119
             showDialog("Error reading subfolder!", "OK", "");
120
             showDialog("Error reading subfolder!", "OK", "");
120
         }
121
         }
121
     } else {
122
     } else {
155
         loadOrOpen();
156
         loadOrOpen();
156
     } else if (key == dotKey) {
157
     } else if (key == dotKey) {
157
         hiddenState = !hiddenState;
158
         hiddenState = !hiddenState;
158
-        initialize(mapFolder->getPath());
159
+        init(mapFolder->getPath());
159
     }
160
     }
160
 
161
 
161
     if (mCursor > (mMin + items - 1)) {
162
     if (mCursor > (mMin + items - 1)) {

+ 8
- 24
src/OpenRaider.cpp View File

23
 #include "Window.h"
23
 #include "Window.h"
24
 #include "OpenRaider.h"
24
 #include "OpenRaider.h"
25
 
25
 
26
-OpenRaider &getOpenRaider() {
27
-    static OpenRaider gOpenRaider;
28
-    return gOpenRaider;
29
-}
30
-
31
 OpenRaider::OpenRaider() {
26
 OpenRaider::OpenRaider() {
32
     mRunning = false;
27
     mRunning = false;
33
     mFPS = false;
28
     mFPS = false;
34
 
29
 
35
     for (int i = 0; i < ActionEventCount; i++)
30
     for (int i = 0; i < ActionEventCount; i++)
36
         keyBindings[i] = unknownKey;
31
         keyBindings[i] = unknownKey;
37
-
38
-    Command::fillCommandList();
39
 }
32
 }
40
 
33
 
41
 std::string OpenRaider::getBaseDir() {
34
 std::string OpenRaider::getBaseDir() {
130
         return -5;
123
         return -5;
131
     }
124
     }
132
 
125
 
133
-    // Initialize game engine
134
-    error = getGame().initialize();
126
+    // Initialize UIs
127
+    error = UI::passInitialize();
135
     if (error != 0) {
128
     if (error != 0) {
136
-        printf("Could not initialize Game (%d)!\n", error);
129
+        printf("Could not initialize UIs (%d)!\n", error);
137
         return -6;
130
         return -6;
138
     }
131
     }
139
 
132
 
140
-    // Initialize main menu
141
-    error = getMenu().initialize();
142
-    if (error != 0) {
143
-        printf("Could not initialize Menu (%d)!\n", error);
144
-        return -7;
145
-    }
146
-
147
-    error = UI::initialize();
148
-    if (error != 0) {
149
-        printf("Could not Initialize UI (%d)!\n", error);
150
-        return -8;
151
-    }
152
-
153
 #ifdef DEBUG
133
 #ifdef DEBUG
154
     mFPS = true;
134
     mFPS = true;
155
 #endif
135
 #endif
177
     // Get keyboard and mouse input
157
     // Get keyboard and mouse input
178
     getWindow().eventHandling();
158
     getWindow().eventHandling();
179
 
159
 
180
-    UI::displayInOrder();
160
+    ImGui::SetNewWindowDefaultPos(ImVec2(50, 50));
161
+    bool show_test_window = true;
162
+    ImGui::ShowTestWindow(&show_test_window);
163
+
164
+    UI::passDisplay();
181
 
165
 
182
     getWindow().glEnter2D();
166
     getWindow().glEnter2D();
183
 
167
 

+ 0
- 5
src/Render.cpp View File

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

+ 0
- 15
src/Sound.cpp View File

8
 #include "global.h"
8
 #include "global.h"
9
 #include "Sound.h"
9
 #include "Sound.h"
10
 
10
 
11
-#ifdef USING_AL
12
-#include "SoundAL.h"
13
-#else
14
-#include "SoundNull.h"
15
-#endif
16
-
17
-Sound &getSound() {
18
-#ifdef USING_AL
19
-    static SoundAL gSound;
20
-#else
21
-    static SoundNull gSound;
22
-#endif
23
-    return gSound;
24
-}
25
-
26
 Sound::~Sound() {
11
 Sound::~Sound() {
27
 }
12
 }
28
 
13
 

+ 0
- 5
src/TextureManager.cpp View File

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

+ 60
- 221
src/UI.cpp View File

9
 
9
 
10
 #include "global.h"
10
 #include "global.h"
11
 #include "Console.h"
11
 #include "Console.h"
12
+#include "Debug.h"
12
 #include "Menu.h"
13
 #include "Menu.h"
13
 #include "OpenRaider.h"
14
 #include "OpenRaider.h"
14
 #include "TextureManager.h"
15
 #include "TextureManager.h"
15
 #include "Window.h"
16
 #include "Window.h"
16
 
17
 
17
-#define STB_IMAGE_IMPLEMENTATION
18
-#include "imgui/stb_image.h"
19
-
20
 std::vector<UI*> UI::windows;
18
 std::vector<UI*> UI::windows;
21
-std::list<std::tuple<KeyboardButton, bool>> UI::keyboardEvents;
22
-std::list<std::tuple<char *, bool>> UI::textEvents;
23
-std::list<std::tuple<unsigned int, unsigned int, KeyboardButton, bool>> UI::clickEvents;
24
-std::list<std::tuple<int, int>> UI::motionEvents;
25
-std::list<std::tuple<int, int>> UI::scrollEvents;
26
-
27
-static GLuint fontTex;
28
 
19
 
29
 UI::~UI() {
20
 UI::~UI() {
30
 }
21
 }
31
 
22
 
23
+int UI::initialize() { return 0; }
24
+void UI::eventsFinished() { }
32
 void UI::display() { }
25
 void UI::display() { }
33
 void UI::handleKeyboard(KeyboardButton key, bool pressed) { }
26
 void UI::handleKeyboard(KeyboardButton key, bool pressed) { }
34
 void UI::handleText(char *text, bool notFinished) { }
27
 void UI::handleText(char *text, bool notFinished) { }
35
 void UI::handleAction(ActionEvents action, bool isFinished) { }
28
 void UI::handleAction(ActionEvents action, bool isFinished) { }
36
 void UI::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) { }
29
 void UI::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) { }
37
-void UI::handleMouseMotion(int xrel, int yrel) { }
30
+void UI::handleMouseMotion(int xrel, int yrel, int xabs, int yabs) { }
38
 void UI::handleMouseScroll(int xrel, int yrel) { }
31
 void UI::handleMouseScroll(int xrel, int yrel) { }
39
 
32
 
40
-int UI::initialize() {
41
-    ImGuiIO& io = ImGui::GetIO();
42
-    io.DisplaySize = ImVec2((float)getWindow().getWidth(), (float)getWindow().getHeight());
43
-    io.DeltaTime = 1.0f/60.0f;
44
-    io.PixelCenterOffset = 0.0f;
45
-
46
-    io.KeyMap[ImGuiKey_Tab] = tabKey;
47
-    io.KeyMap[ImGuiKey_LeftArrow] = leftKey;
48
-    io.KeyMap[ImGuiKey_RightArrow] = rightKey;
49
-    io.KeyMap[ImGuiKey_UpArrow] = upKey;
50
-    io.KeyMap[ImGuiKey_DownArrow] = downKey;
51
-    io.KeyMap[ImGuiKey_Home] = homeKey;
52
-    io.KeyMap[ImGuiKey_End] = endKey;
53
-    io.KeyMap[ImGuiKey_Delete] = delKey;
54
-    io.KeyMap[ImGuiKey_Backspace] = backspaceKey;
55
-    io.KeyMap[ImGuiKey_Enter] = enterKey;
56
-    io.KeyMap[ImGuiKey_Escape] = escapeKey;
57
-    io.KeyMap[ImGuiKey_A] = aKey;
58
-    io.KeyMap[ImGuiKey_C] = cKey;
59
-    io.KeyMap[ImGuiKey_V] = vKey;
60
-    io.KeyMap[ImGuiKey_X] = xKey;
61
-    io.KeyMap[ImGuiKey_Y] = yKey;
62
-    io.KeyMap[ImGuiKey_Z] = zKey;
63
-
64
-    io.RenderDrawListsFn = UI::renderImGui;
65
-
66
-    // Load font texture
67
-    //glGenTextures(1, &fontTex);
68
-    //glBindTexture(GL_TEXTURE_2D, fontTex);
69
-    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
70
-    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
71
-    const void* png_data;
72
-    unsigned int png_size;
73
-    ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
74
-    int tex_x, tex_y, tex_comp;
75
-    void* tex_data = stbi_load_from_memory((const unsigned char*)png_data, (int)png_size, &tex_x, &tex_y, &tex_comp, 0);
76
-    //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_x, tex_y, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data);
77
-    fontTex = getTextureManager().loadBufferSlot((unsigned char *)tex_data, tex_x, tex_y, RGBA, 32, 0);
78
-    stbi_image_free(tex_data);
79
-
80
-    return 0;
81
-}
82
-
83
-void UI::eventsFinished() {
84
-    ImGui::NewFrame();
85
-    ImGuiIO& io = ImGui::GetIO();
86
-
87
-    if (!io.WantCaptureKeyboard) {
88
-        while (keyboardEvents.size() > 0) {
89
-            sendKeyboard(std::get<0>(keyboardEvents.front()), std::get<1>(keyboardEvents.front()));
90
-            keyboardEvents.pop_front();
91
-        }
92
-
93
-        while (textEvents.size() > 0) {
94
-            sendText(std::get<0>(textEvents.front()), std::get<1>(textEvents.front()));
95
-            textEvents.pop_front();
96
-        }
97
-    }
98
-
99
-    if (!io.WantCaptureMouse) {
100
-        while (clickEvents.size() > 0) {
101
-            sendMouseClick(std::get<0>(clickEvents.front()), std::get<1>(clickEvents.front()),
102
-                    std::get<2>(clickEvents.front()), std::get<3>(clickEvents.front()));
103
-            clickEvents.pop_front();
104
-        }
105
-
106
-        while (motionEvents.size() > 0) {
107
-            sendMouseMotion(std::get<0>(motionEvents.front()), std::get<1>(motionEvents.front()));
108
-            motionEvents.pop_front();
109
-        }
110
-
111
-        while (scrollEvents.size() > 0) {
112
-            sendMouseScroll(std::get<0>(scrollEvents.front()), std::get<1>(scrollEvents.front()));
113
-            scrollEvents.pop_front();
33
+void UI::passKeyboard(KeyboardButton key, bool pressed) {
34
+    if (pressed) {
35
+        if (getOpenRaider().keyBindings[menuAction] == key) {
36
+            if (getMenu().isOnTop()) {
37
+                getMenu().makeInvisible();
38
+            } else {
39
+                getMenu().moveToTop();
40
+            }
41
+        } else if (getOpenRaider().keyBindings[consoleAction] == key) {
42
+            if (getConsole().isOnTop()) {
43
+                getConsole().makeInvisible();
44
+            } else {
45
+                getConsole().moveToTop();
46
+            }
47
+        } else if (getOpenRaider().keyBindings[debugAction] == key) {
48
+            if (getDebug().isOnTop()) {
49
+                getDebug().makeInvisible();
50
+            } else {
51
+                getDebug().moveToTop();
52
+            }
114
         }
53
         }
115
     }
54
     }
116
 
55
 
117
-    keyboardEvents.clear();
118
-    textEvents.clear();
119
-    clickEvents.clear();
120
-    motionEvents.clear();
121
-    scrollEvents.clear();
122
-
123
-    ImGui::SetNewWindowDefaultPos(ImVec2(50, 50));
124
-    bool show_test_window = true;
125
-    ImGui::ShowTestWindow(&show_test_window);
126
-}
56
+    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
57
+    (*maxIterator)->handleKeyboard(key, pressed);
127
 
58
 
128
-void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
129
-    if (cmd_lists_count == 0)
130
-        return;
131
-
132
-    glDisable(GL_CULL_FACE);
133
-    glDisable(GL_DEPTH_TEST);
134
-    glEnable(GL_SCISSOR_TEST);
135
-    //glEnableClientState(GL_VERTEX_ARRAY);
136
-    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
137
-    glEnableClientState(GL_COLOR_ARRAY);
138
-
139
-    // Setup texture
140
-    //glBindTexture(GL_TEXTURE_2D, fontTex);
141
-    //glEnable(GL_TEXTURE_2D);
142
-    getTextureManager().bindTextureId(fontTex);
143
-
144
-    const float width = ImGui::GetIO().DisplaySize.x;
145
-    const float height = ImGui::GetIO().DisplaySize.y;
146
-
147
-    /*
148
-    // Setup orthographic projection matrix
149
-    glMatrixMode(GL_PROJECTION);
150
-    glLoadIdentity();
151
-    glOrtho(0.0f, width, height, 0.0f, -1.0f, +1.0f);
152
-    glMatrixMode(GL_MODELVIEW);
153
-    glLoadIdentity();
154
-    */
155
-
156
-    // Render command lists
157
-    for (int n = 0; n < cmd_lists_count; n++) {
158
-        const ImDrawList* cmd_list = cmd_lists[n];
159
-        const unsigned char* vtx_buffer = (const unsigned char*)cmd_list->vtx_buffer.begin();
160
-        glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer));
161
-        glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer+8));
162
-        glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer+16));
163
-
164
-        int vtx_offset = 0;
165
-        const ImDrawCmd* pcmd_end = cmd_list->commands.end();
166
-        for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++) {
167
-            glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w),
168
-                    (int)(pcmd->clip_rect.z - pcmd->clip_rect.x),
169
-                    (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
170
-            glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
171
-            vtx_offset += pcmd->vtx_count;
59
+    for (int i = forwardAction; i < ActionEventCount; i++) {
60
+        if (getOpenRaider().keyBindings[i] == key) {
61
+            (*maxIterator)->handleAction((ActionEvents)i, !pressed);
172
         }
62
         }
173
     }
63
     }
174
 
64
 
175
-    glEnable(GL_CULL_FACE);
176
-    glEnable(GL_DEPTH_TEST);
177
-    glDisable(GL_SCISSOR_TEST);
178
-    glDisableClientState(GL_COLOR_ARRAY);
179
-    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
180
-    //glDisableClientState(GL_VERTEX_ARRAY);
181
-}
182
-
183
-void UI::passKeyboard(KeyboardButton key, bool pressed) {
184
-    keyboardEvents.push_back(std::make_tuple(key, pressed));
185
-
186
-    ImGuiIO& io = ImGui::GetIO();
187
-    io.KeysDown[key] = pressed;
188
-    io.KeyCtrl = io.KeysDown[leftctrlKey] | io.KeysDown[rightctrlKey];
189
-    io.KeyShift = io.KeysDown[leftshiftKey] | io.KeysDown[rightshiftKey];
65
+    bool mousegrab = (*maxIterator)->zPos == 0;
66
+    if (mousegrab != getWindow().getMousegrab())
67
+        getWindow().setMousegrab(mousegrab);
190
 }
68
 }
191
 
69
 
192
 void UI::passText(char *text, bool notFinished) {
70
 void UI::passText(char *text, bool notFinished) {
193
-    textEvents.push_back(std::make_tuple(text, notFinished));
194
-    // TODO
71
+    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
72
+    (*maxIterator)->handleText(text, notFinished);
195
 }
73
 }
196
 
74
 
197
 void UI::passMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
75
 void UI::passMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
198
-    clickEvents.push_back(std::make_tuple(x, y, button, released));
199
-    // TODO
76
+    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
77
+    (*maxIterator)->handleMouseClick(x, y, button, released);
78
+
79
+    for (int i = forwardAction; i < ActionEventCount; i++) {
80
+        if (getOpenRaider().keyBindings[i] == button) {
81
+            (*maxIterator)->handleAction((ActionEvents)i, released);
82
+        }
83
+    }
200
 }
84
 }
201
 
85
 
202
-void UI::passMouseMotion(int xrel, int yrel) {
203
-    motionEvents.push_back(std::make_tuple(xrel, yrel));
204
-    // TODO
86
+void UI::passMouseMotion(int xrel, int yrel, int xabs, int yabs) {
87
+    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
88
+    (*maxIterator)->handleMouseMotion(xrel, yrel, xabs, yabs);
205
 }
89
 }
206
 
90
 
207
 void UI::passMouseScroll(int xrel, int yrel) {
91
 void UI::passMouseScroll(int xrel, int yrel) {
208
-    scrollEvents.push_back(std::make_tuple(xrel, yrel));
209
-
210
-    ImGuiIO& io = ImGui::GetIO();
211
-    io.MouseWheel = (yrel != 0) ? yrel > 0 ? 1 : -1 : 0;
92
+    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
93
+    (*maxIterator)->handleMouseScroll(xrel, yrel);
212
 }
94
 }
213
 
95
 
214
 void UI::addWindow(UI* window) {
96
 void UI::addWindow(UI* window) {
281
     });
163
     });
282
 }
164
 }
283
 
165
 
284
-void UI::displayInOrder() {
285
-    std::sort(windows.begin(), windows.end(), compareUIs);
166
+int UI::passInitialize() {
286
     for (auto &x : windows) {
167
     for (auto &x : windows) {
287
-        if (x->zPos >= 0) {
288
-            x->display();
289
-        }
168
+        int error = x->initialize();
169
+        if (error != 0)
170
+            return error;
290
     }
171
     }
291
 
172
 
292
-    ImGui::Render();
173
+    return 0;
293
 }
174
 }
294
 
175
 
295
-void UI::sendKeyboard(KeyboardButton key, bool pressed) {
296
-    if (pressed) {
297
-        if (getOpenRaider().keyBindings[menuAction] == key) {
298
-            if (getMenu().isOnTop()) {
299
-                getMenu().makeInvisible();
300
-            } else {
301
-                getMenu().moveToTop();
302
-            }
303
-        } else if (getOpenRaider().keyBindings[consoleAction] == key) {
304
-            if (getConsole().isOnTop()) {
305
-                getConsole().makeInvisible();
306
-            } else {
307
-                getConsole().moveToTop();
308
-            }
309
-        }
310
-    }
311
-
312
-    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
313
-    (*maxIterator)->handleKeyboard(key, pressed);
314
-
315
-    for (int i = forwardAction; i < ActionEventCount; i++) {
316
-        if (getOpenRaider().keyBindings[i] == key) {
317
-            (*maxIterator)->handleAction((ActionEvents)i, !pressed);
318
-        }
176
+void UI::passEvents() {
177
+    for (auto &x : windows) {
178
+        x->eventsFinished();
319
     }
179
     }
320
-
321
-    bool mousegrab = (*maxIterator)->zPos == 0;
322
-    if (mousegrab != getWindow().getMousegrab())
323
-        getWindow().setMousegrab(mousegrab);
324
 }
180
 }
325
 
181
 
326
-void UI::sendText(char *text, bool notFinished) {
327
-    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
328
-    (*maxIterator)->handleText(text, notFinished);
329
-}
330
-
331
-void UI::sendMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
332
-    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
333
-    (*maxIterator)->handleMouseClick(x, y, button, released);
334
-
335
-    for (int i = forwardAction; i < ActionEventCount; i++) {
336
-        if (getOpenRaider().keyBindings[i] == button) {
337
-            (*maxIterator)->handleAction((ActionEvents)i, released);
182
+void UI::passDisplay() {
183
+    std::sort(windows.begin(), windows.end(), compareUIs);
184
+    for (auto &x : windows) {
185
+        if (x->zPos >= 0) {
186
+            x->display();
338
         }
187
         }
339
     }
188
     }
340
 }
189
 }
341
 
190
 
342
-void UI::sendMouseMotion(int xrel, int yrel) {
343
-    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
344
-    (*maxIterator)->handleMouseMotion(xrel, yrel);
345
-}
346
-
347
-void UI::sendMouseScroll(int xrel, int yrel) {
348
-    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
349
-    (*maxIterator)->handleMouseScroll(xrel, yrel);
350
-}
351
-

+ 0
- 13
src/Window.cpp View File

15
 #include "utils/strings.h"
15
 #include "utils/strings.h"
16
 #include "Window.h"
16
 #include "Window.h"
17
 
17
 
18
-#ifdef USING_SDL
19
-#include "WindowSDL.h"
20
-#else
21
-#error No Windowing Library selected!
22
-#endif
23
-
24
-Window &getWindow() {
25
-#ifdef USING_SDL
26
-    static WindowSDL gWindow;
27
-#endif
28
-    return gWindow;
29
-}
30
-
31
 unsigned int Window::getWidth() {
18
 unsigned int Window::getWidth() {
32
     return mWidth;
19
     return mWidth;
33
 }
20
 }

+ 2
- 2
src/WindowSDL.cpp View File

127
     while(SDL_PollEvent(&event)) {
127
     while(SDL_PollEvent(&event)) {
128
         switch (event.type) {
128
         switch (event.type) {
129
             case SDL_MOUSEMOTION:
129
             case SDL_MOUSEMOTION:
130
-                UI::passMouseMotion(event.motion.xrel, event.motion.yrel);
130
+                UI::passMouseMotion(event.motion.xrel, event.motion.yrel, event.motion.x, event.motion.y);
131
                 break;
131
                 break;
132
 
132
 
133
             case SDL_MOUSEBUTTONDOWN:
133
             case SDL_MOUSEBUTTONDOWN:
440
         }
440
         }
441
     }
441
     }
442
 
442
 
443
-    UI::eventsFinished();
443
+    UI::passEvents();
444
 }
444
 }
445
 
445
 
446
 void WindowSDL::setTextInput(bool on) {
446
 void WindowSDL::setTextInput(bool on) {

+ 0
- 5
src/World.cpp View File

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

+ 3
- 0
src/commands/CommandBind.cpp View File

24
     getConsole() << "Available Actions:" << Console::endl;
24
     getConsole() << "Available Actions:" << Console::endl;
25
     getConsole() << "  menu" << Console::endl;
25
     getConsole() << "  menu" << Console::endl;
26
     getConsole() << "  console" << Console::endl;
26
     getConsole() << "  console" << Console::endl;
27
+    getConsole() << "  debug" << Console::endl;
27
     getConsole() << "  forward" << Console::endl;
28
     getConsole() << "  forward" << Console::endl;
28
     getConsole() << "  backward" << Console::endl;
29
     getConsole() << "  backward" << Console::endl;
29
     getConsole() << "  left" << Console::endl;
30
     getConsole() << "  left" << Console::endl;
66
         return menuAction;
67
         return menuAction;
67
     } else if (action == "console") {
68
     } else if (action == "console") {
68
         return consoleAction;
69
         return consoleAction;
70
+    } else if (action == "debug") {
71
+        return debugAction;
69
     } else if (action == "forward") {
72
     } else if (action == "forward") {
70
         return forwardAction;
73
         return forwardAction;
71
     } else if (action == "backward") {
74
     } else if (action == "backward") {

+ 126
- 2
src/main.cpp View File

12
 #include "Exception.h"
12
 #include "Exception.h"
13
 #include "OpenRaider.h"
13
 #include "OpenRaider.h"
14
 #include "commander/commander.h"
14
 #include "commander/commander.h"
15
+#include "commands/Command.h"
16
+
17
+#include "Camera.h"
18
+#include "Debug.h"
19
+#include "FontManager.h"
20
+#include "Game.h"
21
+#include "MenuFolder.h"
22
+#include "Render.h"
23
+#include "TextureManager.h"
24
+#include "World.h"
25
+
26
+#ifdef USING_AL
27
+#include "SoundAL.h"
28
+#else
29
+#include "SoundNull.h"
30
+#endif
31
+
32
+#ifdef USING_SDL
33
+#include "WindowSDL.h"
34
+#else
35
+#error No Windowing Library selected!
36
+#endif
15
 
37
 
16
 #ifndef UNIT_TEST
38
 #ifndef UNIT_TEST
17
 
39
 
18
 namespace {
40
 namespace {
41
+    Camera* gCamera;
42
+    Console* gConsole;
43
+    Debug* gDebug;
44
+    FontManager* gFont;
45
+    Game* gGame;
46
+    MenuFolder* gMenu;
47
+    OpenRaider* gOpenRaider;
48
+    Render* gRender;
49
+    Sound* gSound;
50
+    TextureManager* gTextureManager;
51
+    Window* gWindow;
52
+    World* gWorld;
53
+
54
+    void createGlobals() {
55
+        gOpenRaider = new OpenRaider();
56
+        gCamera = new Camera();
57
+        gConsole = new Console();
58
+        gDebug = new Debug();
59
+        gFont = new FontManager();
60
+        gGame = new Game();
61
+        gMenu = new MenuFolder();
62
+        gRender = new Render();
63
+        gTextureManager = new TextureManager();
64
+        gWorld = new World();
65
+
66
+#ifdef USING_AL
67
+        gSound = new SoundAL();
68
+#else
69
+        gSound = new SoundNull();
70
+#endif
71
+
72
+#ifdef USING_SDL
73
+        gWindow = new WindowSDL();
74
+#endif
75
+    }
76
+
77
+    void deleteGlobals() {
78
+        delete gCamera;
79
+        delete gConsole;
80
+        delete gFont;
81
+        delete gGame;
82
+        delete gMenu;
83
+        delete gOpenRaider;
84
+        delete gRender;
85
+        delete gSound;
86
+        delete gTextureManager;
87
+        delete gWindow;
88
+        delete gWorld;
89
+    }
90
+
19
     bool configFileWasSpecified = false;
91
     bool configFileWasSpecified = false;
20
 
92
 
21
     void configFileCallback(command_t *self) {
93
     void configFileCallback(command_t *self) {
32
         std::cout << "Web site  : http://github.com/xythobuz/OpenRaider" << std::endl;
104
         std::cout << "Web site  : http://github.com/xythobuz/OpenRaider" << std::endl;
33
         std::cout << "Contact   : xythobuz@xythobuz.de" << std::endl;
105
         std::cout << "Contact   : xythobuz@xythobuz.de" << std::endl;
34
 #endif
106
 #endif
107
+
108
+        deleteGlobals();
35
     }
109
     }
36
 }
110
 }
37
 
111
 
112
+Camera &getCamera() {
113
+    return *gCamera;
114
+}
115
+
116
+Console &getConsole() {
117
+    return *gConsole;
118
+}
119
+
120
+Debug& getDebug() {
121
+    return *gDebug;
122
+}
123
+
124
+Font &getFont() {
125
+    return *gFont;
126
+}
127
+
128
+Game &getGame() {
129
+    return *gGame;
130
+}
131
+
132
+Menu &getMenu() {
133
+    return *gMenu;
134
+}
135
+
136
+OpenRaider &getOpenRaider() {
137
+    return *gOpenRaider;
138
+}
139
+
140
+Render &getRender() {
141
+    return *gRender;
142
+}
143
+
144
+Sound &getSound() {
145
+    return *gSound;
146
+}
147
+
148
+TextureManager &getTextureManager() {
149
+    return *gTextureManager;
150
+}
151
+
152
+Window &getWindow() {
153
+    return *gWindow;
154
+}
155
+
156
+World &getWorld() {
157
+    return *gWorld;
158
+}
159
+
38
 int main(int argc, char* argv[]) {
160
 int main(int argc, char* argv[]) {
161
+    createGlobals();
162
+    atexit(cleanupHandler);
163
+    Command::fillCommandList();
164
+
39
     command_t cmd;
165
     command_t cmd;
40
     command_init(&cmd, argv[0], VERSION);
166
     command_init(&cmd, argv[0], VERSION);
41
     //command_option(&cmd, "-v", "--verbose", "enable verbose output", functionPointer);
167
     //command_option(&cmd, "-v", "--verbose", "enable verbose output", functionPointer);
52
     getConsole() << "Initializing " << VERSION << Console::endl;
178
     getConsole() << "Initializing " << VERSION << Console::endl;
53
 #endif
179
 #endif
54
 
180
 
55
-    atexit(cleanupHandler);
56
-
57
     int error = getOpenRaider().initialize();
181
     int error = getOpenRaider().initialize();
58
     if (error != 0) {
182
     if (error != 0) {
59
         std::cout << "Could not initialize OpenRaider (" << error << ")!" << std::endl;
183
         std::cout << "Could not initialize OpenRaider (" << error << ")!" << std::endl;

+ 1
- 1
src/utils/tga.cpp View File

152
         fread(&comment, 1, header.comment_lenght, f);
152
         fread(&comment, 1, header.comment_lenght, f);
153
         for (i = 0; i < 255; ++i) {
153
         for (i = 0; i < 255; ++i) {
154
             if (!(comment[i] > 32 && comment[i] < 127))
154
             if (!(comment[i] > 32 && comment[i] < 127))
155
-                comment[i] = 183; // print a dot for invalid text
155
+                comment[i] = '.'; // print a dot for invalid text
156
         }
156
         }
157
         comment[255] = 0;
157
         comment[255] = 0;
158
         printf("Comment: '%s'\n", comment);
158
         printf("Comment: '%s'\n", comment);

Loading…
Cancel
Save