Browse Source

Commander now ezOptionParser. Fixed many warnings.

Thomas Buck 8 years ago
parent
commit
99f07ee6fe

+ 1
- 1
CMakeLists.txt View File

@@ -37,7 +37,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
37 37
     set (WARNINGS "${WARNINGS} -Wno-padded -Wno-packed")
38 38
     set (WARNINGS "${WARNINGS} -Wno-global-constructors -Wno-exit-time-destructors")
39 39
     set (WARNINGS "${WARNINGS} -Wno-documentation-unknown-command -Wno-c++98-compat-pedantic")
40
-    set (WARNINGS "${WARNINGS} -Wno-date-time -Wno-unused-variable")
40
+    set (WARNINGS "${WARNINGS} -Wno-date-time -Wno-unused-variable -Wno-unused-parameter")
41 41
     set (WARNINGS "${WARNINGS} -Wno-shorten-64-to-32 -Wno-sign-compare -Wno-sign-conversion")
42 42
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -std=c++11")
43 43
     set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -g -O0")

+ 4
- 0
ChangeLog.md View File

@@ -2,6 +2,10 @@
2 2
 
3 3
 ## OpenRaider (0.1.4) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20150813 ]
6
+    * Removed commander lib, added ezOptionParser
7
+    * Fixed many warnings
8
+
5 9
     [ 20150811 ]
6 10
     * Can click on RoomModels and RoomSprites
7 11
     * This will show their BoundingSpheres

+ 1
- 2
README.md View File

@@ -107,9 +107,8 @@ There are some included cmake scripts:
107 107
 
108 108
 See the respective files in `cmake` for their licensing.
109 109
 
110
-The included [clibs/commander](https://github.com/clibs/commander) lib is Copyright (c) 2012 TJ Holowaychuk (tj@vision-media.ca) and licensed under the [MIT License](http://opensource.org/licenses/MIT).
110
+The included header [ezOptionParser](http://ezoptionparser.sourceforge.net) is licensed under the [MIT License](http://opensource.org/licenses/MIT).
111 111
 
112 112
 The included GUI lib, [imgui](https://github.com/ocornut/imgui/) is Copyright (c) 2014 Omar Cornut. See src/deps/imgui/LICENSE for more informations about the MIT license used. 
113 113
 
114 114
 Also included is the imgui addon [imguifilesystem by Flix01](https://gist.github.com/Flix01/f34b5efa91e50a241c1b).
115
-

+ 2
- 2
include/Log.h View File

@@ -47,8 +47,8 @@ class Log {
47 47
 
48 48
 class LogLevel {
49 49
   public:
50
-    LogLevel(int l) : level(l) { printBuffer << std::boolalpha; }
51
-    LogLevel(LogLevel&& l) : level(l.level) { }
50
+    explicit LogLevel(int l) : level(l) { printBuffer << std::boolalpha; }
51
+    LogLevel(LogLevel&& l) : level(l.level) { printBuffer << std::boolalpha; }
52 52
 
53 53
     LogLevel& operator<< (const glm::vec2& v) {
54 54
         return (*this) << v.x << " " << v.y;

+ 3
- 3
include/SkeletalModel.h View File

@@ -30,7 +30,7 @@ class BoneTag {
30 30
 
31 31
 class BoneFrame {
32 32
   public:
33
-    BoneFrame(glm::vec3 p) : pos(p) { }
33
+    explicit BoneFrame(glm::vec3 p) : pos(p) { }
34 34
     ~BoneFrame();
35 35
 
36 36
     glm::vec3 getPosition() { return pos; }
@@ -46,7 +46,7 @@ class BoneFrame {
46 46
 
47 47
 class AnimationFrame {
48 48
   public:
49
-    AnimationFrame(char r) : rate(r) { }
49
+    explicit AnimationFrame(char r) : rate(r) { }
50 50
     ~AnimationFrame();
51 51
 
52 52
     unsigned long size();
@@ -60,7 +60,7 @@ class AnimationFrame {
60 60
 
61 61
 class SkeletalModel {
62 62
   public:
63
-    SkeletalModel(int i) : id(i) { }
63
+    explicit SkeletalModel(int i) : id(i) { }
64 64
     ~SkeletalModel();
65 65
     void display(glm::mat4 MVP, int aframe, int bframe, ShaderTexture* shaderTexture = nullptr);
66 66
 

+ 1
- 1
include/utils/Folder.h View File

@@ -15,7 +15,7 @@
15 15
 
16 16
 class File {
17 17
   public:
18
-    File(std::string file);
18
+    explicit File(std::string file);
19 19
 
20 20
     std::string& getName() { return name; }
21 21
     std::string& getPath() { return path; }

+ 1
- 1
include/utils/binary.h View File

@@ -39,7 +39,7 @@ class BinaryReader {
39 39
 
40 40
 class BinaryFile : public BinaryReader {
41 41
   public:
42
-    BinaryFile(std::string f = "");
42
+    explicit BinaryFile(std::string f = "");
43 43
     virtual ~BinaryFile();
44 44
 
45 45
     int open(std::string f = "");

+ 6
- 6
src/Camera.cpp View File

@@ -349,12 +349,12 @@ void Camera::calculateFrustumPlanes() {
349 349
 
350 350
     if (indexBuffer.size() == 0) {
351 351
         for (int i = 0; i < 6; i++) {
352
-            indexBuffer.push_back(4 * i);
353
-            indexBuffer.push_back((4 * i) + 1);
354
-            indexBuffer.push_back((4 * i) + 2);
355
-            indexBuffer.push_back((4 * i) + 3);
356
-            indexBuffer.push_back((4 * i) + 2);
357
-            indexBuffer.push_back(4 * i);
352
+            indexBuffer.push_back(static_cast<unsigned short>(4 * i));
353
+            indexBuffer.push_back(static_cast<unsigned short>((4 * i) + 1));
354
+            indexBuffer.push_back(static_cast<unsigned short>((4 * i) + 2));
355
+            indexBuffer.push_back(static_cast<unsigned short>((4 * i) + 3));
356
+            indexBuffer.push_back(static_cast<unsigned short>((4 * i) + 2));
357
+            indexBuffer.push_back(static_cast<unsigned short>(4 * i));
358 358
         }
359 359
     }
360 360
 }

+ 6
- 6
src/Mesh.cpp View File

@@ -70,7 +70,7 @@ void Mesh::prepare() {
70 70
                 v = 2;
71 71
             else if (v == 2)
72 72
                 v = 0;
73
-            ind.push_back(vert.size());
73
+            ind.push_back(static_cast<unsigned short>(vert.size()));
74 74
             vert.push_back(verticesBuff.at(vertIndex + v));
75 75
             uvBuff.push_back(TextureManager::getTile(texturesBuff.at(i)).getUV(v));
76 76
             tex.push_back(texture);
@@ -109,7 +109,7 @@ void Mesh::prepare() {
109 109
                 v = 2;
110 110
             else if (v == 2)
111 111
                 v = 0;
112
-            indCol.push_back(vertCol.size());
112
+            indCol.push_back(static_cast<unsigned short>(vertCol.size()));
113 113
             vertCol.push_back(verticesColorBuff.at(vertIndex + v));
114 114
             glm::vec4 c = TextureManager::getPalette(colorsIndexBuff.at(i));
115 115
             cols.push_back(glm::vec3(c.x, c.y, c.z));
@@ -135,12 +135,12 @@ void Mesh::prepare() {
135 135
 
136 136
     glm::vec3 center = average / float(averageCount);
137 137
     float radius = 0.0f;
138
-    for (auto& vert : verticesBuff) {
139
-        float dist = glm::distance(center, vert);
138
+    for (auto& v : verticesBuff) {
139
+        float dist = glm::distance(center, v);
140 140
         if (dist > radius) radius = dist;
141 141
     }
142
-    for (auto& vert : verticesColorBuff) {
143
-        float dist = glm::distance(center, vert);
142
+    for (auto& v : verticesColorBuff) {
143
+        float dist = glm::distance(center, v);
144 144
         if (dist > radius) radius = dist;
145 145
     }
146 146
 

+ 1
- 1
src/RoomMesh.cpp View File

@@ -45,7 +45,7 @@ void RoomMesh::prepare() {
45 45
                 v = 2;
46 46
             else if (v == 2)
47 47
                 v = 0;
48
-            ind.push_back(vert.size());
48
+            ind.push_back(static_cast<unsigned short>(vert.size()));
49 49
             vert.push_back(verticesBuff.at(vertIndex + v));
50 50
             uvsBuff.push_back(TextureManager::getTile(texturesBuff.at(i)).getUV(v));
51 51
             tex.push_back(texture);

+ 1
- 1
src/SkeletalModel.cpp View File

@@ -61,7 +61,7 @@ void AnimationFrame::add(BoneFrame* f) {
61 61
 
62 62
 class MatrixStack {
63 63
   public:
64
-    MatrixStack(glm::mat4 start) : startVal(start) { stack.push_back(startVal); }
64
+    explicit MatrixStack(glm::mat4 start) : startVal(start) { stack.push_back(startVal); }
65 65
 
66 66
     void push() {
67 67
         //orAssertGreaterThan(stack.size(), 0);

+ 8
- 2
src/SoundManager.cpp View File

@@ -156,7 +156,6 @@ int SoundManager::playSound(int index) {
156 156
 }
157 157
 
158 158
 void SoundManager::display() {
159
-    static bool offsets = false;
160 159
     if (ImGui::CollapsingHeader("Sound Sources")) {
161 160
         ImGui::Columns(5, "soundsources");
162 161
         ImGui::Text("No");
@@ -170,6 +169,8 @@ void SoundManager::display() {
170 169
         ImGui::Text("Tools");
171 170
         ImGui::NextColumn();
172 171
         ImGui::Separator();
172
+
173
+        static bool offsets = false;
173 174
         if (!offsets) {
174 175
             ImGui::SetColumnOffset(1, 40.0f);
175 176
             ImGui::SetColumnOffset(2, 80.0f);
@@ -177,6 +178,7 @@ void SoundManager::display() {
177 178
             ImGui::SetColumnOffset(4, 350.0f);
178 179
             offsets = true;
179 180
         }
181
+
180 182
         for (int i = 0; i < soundSources.size(); i++) {
181 183
             auto& ss = soundSources.at(i);
182 184
             ImGui::Text("%03d", i);
@@ -208,10 +210,10 @@ void SoundManager::display() {
208 210
             ImGui::PopID();
209 211
             ImGui::NextColumn();
210 212
         }
213
+
211 214
         ImGui::Columns(1);
212 215
     }
213 216
 
214
-    static bool offsets2 = false;
215 217
     if (ImGui::CollapsingHeader("Sound Details")) {
216 218
         ImGui::Columns(4, "sounddetails");
217 219
         ImGui::Text("No");
@@ -223,12 +225,15 @@ void SoundManager::display() {
223 225
         ImGui::Text("Tools");
224 226
         ImGui::NextColumn();
225 227
         ImGui::Separator();
228
+
229
+        static bool offsets2 = false;
226 230
         if (!offsets2) {
227 231
             ImGui::SetColumnOffset(1, 40.0f);
228 232
             ImGui::SetColumnOffset(2, 80.0f);
229 233
             ImGui::SetColumnOffset(3, 180.0f);
230 234
             offsets2 = true;
231 235
         }
236
+
232 237
         for (int i = 0; i < soundDetails.size(); i++) {
233 238
             auto& sd = soundDetails.at(i);
234 239
             ImGui::Text("%03d", i);
@@ -250,6 +255,7 @@ void SoundManager::display() {
250 255
             ImGui::PopID();
251 256
             ImGui::NextColumn();
252 257
         }
258
+
253 259
         ImGui::Columns(1);
254 260
     }
255 261
 

+ 2
- 2
src/Sprite.cpp View File

@@ -20,8 +20,8 @@ Sprite::Sprite(int tile, int x, int y, int width, int height) : texture(tile) {
20 20
     width >>= 8;
21 21
     height >>= 8;
22 22
 
23
-    int width2 = (int)(width * scale);
24
-    int height2 = (int)(height * scale);
23
+    int width2 = static_cast<int>(width * scale);
24
+    int height2 = static_cast<int>(height * scale);
25 25
 
26 26
     uvBuff.emplace_back(float(x + texelOffset) / texelScale, float(y + height) / texelScale);
27 27
     uvBuff.emplace_back(float(x + texelOffset) / texelScale, float(y + texelOffset) / texelScale);

+ 6
- 6
src/TextureManager.cpp View File

@@ -330,12 +330,12 @@ void TextureManager::prepare() {
330 330
         unsigned int width = std::get<1>(tex);
331 331
         unsigned int height = std::get<2>(tex);
332 332
         unsigned char* image = new unsigned char[width * height * 4];
333
-        for (unsigned int i = 0; i < (width * height); i++) {
334
-            auto col = getPalette(img[i]);
335
-            image[i * 4] = col.x * 255;
336
-            image[(i * 4) + 1] = col.y * 255;
337
-            image[(i * 4) + 2] = col.z * 255;
338
-            image[(i * 4) + 3] = col.w * 255;
333
+        for (unsigned int j = 0; j < (width * height); j++) {
334
+            auto col = getPalette(img[j]);
335
+            image[j * 4] = static_cast<unsigned char>(col.x * 255);
336
+            image[(j * 4) + 1] = static_cast<unsigned char>(col.y * 255);
337
+            image[(j * 4) + 2] = static_cast<unsigned char>(col.z * 255);
338
+            image[(j * 4) + 3] = static_cast<unsigned char>(col.w * 255);
339 339
         }
340 340
         delete [] img;
341 341
         loadBufferSlot(image, width, height, ColorMode::RGBA, 32, TextureStorage::GAME, i, true);

+ 4
- 4
src/UI.cpp View File

@@ -567,10 +567,10 @@ void UI::renderImGui(ImDrawData* draw_data) {
567 567
                 orAssert(bm != nullptr);
568 568
                 imguiShader.loadUniform(1, bm->getTextureID(), bm->getTextureStorage());
569 569
 
570
-                gl::glScissor(pcmd->ClipRect.x,
571
-                              Window::getSize().y - pcmd->ClipRect.w,
572
-                              pcmd->ClipRect.z - pcmd->ClipRect.x,
573
-                              pcmd->ClipRect.w - pcmd->ClipRect.y);
570
+                gl::glScissor(static_cast<gl::GLint>(pcmd->ClipRect.x),
571
+                              static_cast<gl::GLint>(Window::getSize().y - pcmd->ClipRect.w),
572
+                              static_cast<gl::GLsizei>(pcmd->ClipRect.z - pcmd->ClipRect.x),
573
+                              static_cast<gl::GLsizei>(pcmd->ClipRect.w - pcmd->ClipRect.y));
574 574
 
575 575
                 gl::glDrawElements(gl::GL_TRIANGLES, pcmd->ElemCount, gl::GL_UNSIGNED_SHORT, idx_buffer_offset);
576 576
             }

+ 12
- 3
src/World.cpp View File

@@ -121,7 +121,6 @@ Mesh& World::getMesh(unsigned long index) {
121 121
 
122 122
 void World::displayUI() {
123 123
     // Rooms
124
-    static bool offsets = false;
125 124
     if (ImGui::CollapsingHeader("Room Listing")) {
126 125
         ImGui::Columns(8, "rooms");
127 126
         ImGui::Text("No");
@@ -141,6 +140,8 @@ void World::displayUI() {
141 140
         ImGui::Text("Tools");
142 141
         ImGui::NextColumn();
143 142
         ImGui::Separator();
143
+
144
+        static bool offsets = false;
144 145
         if (!offsets) {
145 146
             ImGui::SetColumnOffset(1, 40.0f);
146 147
             ImGui::SetColumnOffset(2, 80.0f);
@@ -151,16 +152,17 @@ void World::displayUI() {
151 152
             ImGui::SetColumnOffset(7, 400.0f);
152 153
             offsets = true;
153 154
         }
155
+
154 156
         for (int i = 0; i < rooms.size(); i++) {
155 157
             ImGui::Text("%03d", i);
156 158
             ImGui::NextColumn();
157 159
             rooms.at(i)->displayUI();
158 160
         }
161
+
159 162
         ImGui::Columns(1);
160 163
     }
161 164
 
162 165
     // Entities
163
-    static bool offsets2 = false;
164 166
     if (ImGui::CollapsingHeader("Entity Listing")) {
165 167
         ImGui::Columns(4, "entities");
166 168
         ImGui::Text("No");
@@ -172,22 +174,25 @@ void World::displayUI() {
172 174
         ImGui::Text("Index");
173 175
         ImGui::NextColumn();
174 176
         ImGui::Separator();
177
+
178
+        static bool offsets2 = false;
175 179
         if (!offsets2) {
176 180
             ImGui::SetColumnOffset(1, 40.0f);
177 181
             ImGui::SetColumnOffset(2, 80.0f);
178 182
             ImGui::SetColumnOffset(3, 200.0f);
179 183
             offsets2 = true;
180 184
         }
185
+
181 186
         for (int i = 0; i < entities.size(); i++) {
182 187
             ImGui::Text("%03d", i);
183 188
             ImGui::NextColumn();
184 189
             entities.at(i)->displayUI();
185 190
         }
191
+
186 192
         ImGui::Columns(1);
187 193
     }
188 194
 
189 195
     // Static Meshes
190
-    static bool offsets3 = false;
191 196
     if (ImGui::CollapsingHeader("StaticMesh Listing")) {
192 197
         ImGui::Columns(3, "staticmeshes");
193 198
         ImGui::Text("No");
@@ -197,16 +202,20 @@ void World::displayUI() {
197 202
         ImGui::Text("Mesh");
198 203
         ImGui::NextColumn();
199 204
         ImGui::Separator();
205
+
206
+        static bool offsets3 = false;
200 207
         if (!offsets3) {
201 208
             ImGui::SetColumnOffset(1, 40.0f);
202 209
             ImGui::SetColumnOffset(2, 80.0f);
203 210
             offsets3 = true;
204 211
         }
212
+
205 213
         for (int i = 0; i < staticMeshes.size(); i++) {
206 214
             ImGui::Text("%03d", i);
207 215
             ImGui::NextColumn();
208 216
             staticMeshes.at(i)->displayUI();
209 217
         }
218
+
210 219
         ImGui::Columns(1);
211 220
     }
212 221
 }

+ 1
- 1
src/deps/CMakeLists.txt View File

@@ -1,5 +1,5 @@
1 1
 # Source files
2
-set (DEPS_SRCS ${DEPS_SRCS} "commander/commander.c" "commander/commander.h")
2
+set (DEPS_SRCS ${DEPS_SRCS} "ezoptionparser/ezOptionParser.hpp")
3 3
 set (DEPS_SRCS ${DEPS_SRCS} "imgui/imgui.cpp" "imgui/imgui.h" "imgui/imconfig.h" "imgui/stb_textedit.h")
4 4
 set (DEPS_SRCS ${DEPS_SRCS} "stb/stb.cpp" "stb/stb_image.h" "stb/stb_image_write.h")
5 5
 

+ 0
- 270
src/deps/commander/commander.c View File

@@ -1,270 +0,0 @@
1
-
2
-//
3
-// commander.c
4
-//
5
-// Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
6
-//
7
-
8
-#include <stdio.h>
9
-#include <stdlib.h>
10
-#include <string.h>
11
-#include <assert.h>
12
-#include "commander.h"
13
-
14
-/*
15
- * Output error and exit.
16
- */
17
-
18
-static void
19
-error(char *msg) {
20
-  fprintf(stderr, "%s\n", msg);
21
-  exit(1);
22
-}
23
-
24
-/*
25
- * Output command version.
26
- */
27
-
28
-static void
29
-command_version(command_t *self) {
30
-  printf("%s\n", self->version);
31
-  command_free(self);
32
-  exit(0);
33
-}
34
-
35
-/*
36
- * Output command help.
37
- */
38
-
39
-void
40
-command_help(command_t *self) {
41
-  printf("\n");
42
-  printf("  Usage: %s %s\n", self->name, self->usage);
43
-  printf("\n");
44
-  printf("  Options:\n");
45
-  printf("\n");
46
-
47
-  int i;
48
-  for (i = 0; i < self->option_count; ++i) {
49
-    command_option_t *option = &self->options[i];
50
-    printf("    %s, %-25s %s\n"
51
-      , option->small
52
-      , option->large_with_arg
53
-      , option->description);
54
-  }
55
-
56
-  printf("\n");
57
-  command_free(self);
58
-  exit(0);
59
-}
60
-
61
-/*
62
- * Initialize with program `name` and `version`.
63
- */
64
-
65
-void
66
-command_init(command_t *self, const char *name, const char *version) {
67
-  self->arg = NULL;
68
-  self->name = name;
69
-  self->version = version;
70
-  self->option_count = self->argc = 0;
71
-  self->usage = "[options]";
72
-  self->nargv = NULL;
73
-  command_option(self, "-V", "--version", "output program version", command_version);
74
-  command_option(self, "-h", "--help", "output help information", command_help);
75
-}
76
-
77
-/*
78
- * Free up commander after use.
79
- */
80
-
81
-void
82
-command_free(command_t *self) {
83
-  int i;
84
-
85
-  for (i = 0; i < self->option_count; ++i) {
86
-    command_option_t *option = &self->options[i];
87
-    free(option->argname);
88
-    free(option->large);
89
-  }
90
-
91
-  if (self->nargv) {
92
-    for (i = 0; self->nargv[i]; ++i) {
93
-      free(self->nargv[i]);
94
-    }
95
-    free(self->nargv);
96
-  }
97
-}
98
-
99
-/*
100
- * Parse argname from `str`. For example
101
- * Take "--required <arg>" and populate `flag`
102
- * with "--required" and `arg` with "<arg>".
103
- */
104
-
105
-static void
106
-parse_argname(const char *str, char *flag, char *arg) {
107
-  int buffer = 0;
108
-  size_t flagpos = 0;
109
-  size_t argpos = 0;
110
-  size_t len = strlen(str);
111
-  size_t i;
112
-
113
-  for (i = 0; i < len; ++i) {
114
-    if (buffer || '[' == str[i] || '<' == str[i]) {
115
-      buffer = 1;
116
-      arg[argpos++] = str[i];
117
-    } else {
118
-      if (' ' == str[i]) continue;
119
-      flag[flagpos++] = str[i];
120
-    }
121
-  }
122
-
123
-  arg[argpos] = '\0';
124
-  flag[flagpos] = '\0';
125
-}
126
-
127
-/*
128
- * Normalize the argument vector by exploding
129
- * multiple options (if any). For example
130
- * "foo -abc --scm git" -> "foo -a -b -c --scm git"
131
- */
132
-
133
-static char **
134
-normalize_args(int *argc, char **argv) {
135
-  int size = 0;
136
-  int alloc = *argc + 1;
137
-  char **nargv = malloc(alloc * sizeof(char *));
138
-  int i;
139
-
140
-  for (i = 0; argv[i]; ++i) {
141
-    const char *arg = argv[i];
142
-    size_t len = strlen(arg);
143
-
144
-    // short flag
145
-    if (len > 2 && '-' == arg[0] && !strchr(arg + 1, '-')) {
146
-      alloc += len - 2;
147
-      nargv = realloc(nargv, alloc * sizeof(char *));
148
-      size_t j;
149
-      for (j = 1; j < len; ++j) {
150
-        nargv[size] = malloc(3);
151
-        sprintf(nargv[size], "-%c", arg[j]);
152
-        size++;
153
-      }
154
-      continue;
155
-    }
156
-
157
-    // regular arg
158
-    nargv[size] = malloc(len + 1);
159
-    strcpy(nargv[size], arg);
160
-    size++;
161
-  }
162
-
163
-  nargv[size] = NULL;
164
-  *argc = size;
165
-  return nargv;
166
-}
167
-
168
-/*
169
- * Define an option.
170
- */
171
-
172
-void
173
-command_option(command_t *self, const char *small, const char *large, const char *desc, command_callback_t cb) {
174
-  if (self->option_count == COMMANDER_MAX_OPTIONS) {
175
-    command_free(self);
176
-    error("Maximum option definitions exceeded");
177
-  }
178
-  int n = self->option_count++;
179
-  command_option_t *option = &self->options[n];
180
-  option->cb = cb;
181
-  option->small = small;
182
-  option->description = desc;
183
-  option->required_arg = option->optional_arg = 0;
184
-  option->large_with_arg = large;
185
-  option->argname = malloc(strlen(large) + 1);
186
-  assert(option->argname);
187
-  option->large = malloc(strlen(large) + 1);
188
-  assert(option->large);
189
-  parse_argname(large, option->large, option->argname);
190
-  if ('[' == option->argname[0]) option->optional_arg = 1;
191
-  if ('<' == option->argname[0]) option->required_arg = 1;
192
-}
193
-
194
-/*
195
- * Parse `argv` (internal).
196
- * Input arguments should be normalized first
197
- * see `normalize_args`.
198
- */
199
-
200
-static void
201
-command_parse_args(command_t *self, int argc, char **argv) {
202
-  int literal = 0;
203
-  int i, j;
204
-
205
-  for (i = 1; i < argc; ++i) {
206
-    const char *arg = argv[i];
207
-    for (j = 0; j < self->option_count; ++j) {
208
-      command_option_t *option = &self->options[j];
209
-
210
-      // match flag
211
-      if (!strcmp(arg, option->small) || !strcmp(arg, option->large)) {
212
-        self->arg = NULL;
213
-
214
-        // required
215
-        if (option->required_arg) {
216
-          arg = argv[++i];
217
-          if (!arg || '-' == arg[0]) {
218
-            fprintf(stderr, "%s %s argument required\n", option->large, option->argname);
219
-            command_free(self);
220
-            exit(1);
221
-          }
222
-          self->arg = arg;
223
-        }
224
-
225
-        // optional
226
-        if (option->optional_arg) {
227
-          if (argv[i + 1] && '-' != argv[i + 1][0]) {
228
-            self->arg = argv[++i];
229
-          }
230
-        }
231
-
232
-        // invoke callback
233
-        option->cb(self);
234
-        goto match;
235
-      }
236
-    }
237
-
238
-    // --
239
-    if ('-' == arg[0] && '-' == arg[1] && 0 == arg[2]) {
240
-      literal = 1;
241
-      goto match;
242
-    }
243
-
244
-    // unrecognized
245
-    if ('-' == arg[0] && !literal) {
246
-      fprintf(stderr, "unrecognized flag %s\n", arg);
247
-      command_free(self);
248
-      exit(1);
249
-    }
250
-
251
-    int n = self->argc++;
252
-    if (n == COMMANDER_MAX_ARGS) {
253
-      command_free(self);
254
-      error("Maximum number of arguments exceeded");
255
-    }
256
-    self->argv[n] = (char *) arg;
257
-    match:;
258
-  }
259
-}
260
-
261
-/*
262
- * Parse `argv` (public).
263
- */
264
-
265
-void
266
-command_parse(command_t *self, int argc, char **argv) {
267
-  self->nargv = normalize_args(&argc, argv);
268
-  command_parse_args(self, argc, self->nargv);
269
-  self->argv[self->argc] = NULL;
270
-}

+ 0
- 96
src/deps/commander/commander.h View File

@@ -1,96 +0,0 @@
1
-
2
-//
3
-// commander.h
4
-//
5
-// Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
6
-//
7
-
8
-#ifndef COMMANDER_H
9
-#define COMMANDER_H
10
-
11
-#ifdef __cplusplus
12
-extern "C" {
13
-#endif
14
-
15
-/*
16
- * Max options that can be defined.
17
- */
18
-
19
-#ifndef COMMANDER_MAX_OPTIONS
20
-#define COMMANDER_MAX_OPTIONS 32
21
-#endif
22
-
23
-/*
24
- * Max arguments that can be passed.
25
- */
26
-
27
-#ifndef COMMANDER_MAX_ARGS
28
-#define COMMANDER_MAX_ARGS 32
29
-#endif
30
-
31
-/*
32
- * Command struct.
33
- */
34
-
35
-struct command;
36
-
37
-/*
38
- * Option callback.
39
- */
40
-
41
-typedef void (* command_callback_t)(struct command *self);
42
-
43
-/*
44
- * Command option.
45
- */
46
-
47
-typedef struct {
48
-  int optional_arg;
49
-  int required_arg;
50
-  char *argname;
51
-  char *large;
52
-  const char *small;
53
-  const char *large_with_arg;
54
-  const char *description;
55
-  command_callback_t cb;
56
-} command_option_t;
57
-
58
-/*
59
- * Command.
60
- */
61
-
62
-typedef struct command {
63
-  void *data;
64
-  const char *usage;
65
-  const char *arg;
66
-  const char *name;
67
-  const char *version;
68
-  int option_count;
69
-  command_option_t options[COMMANDER_MAX_OPTIONS];
70
-  int argc;
71
-  char *argv[COMMANDER_MAX_ARGS];
72
-  char **nargv;
73
-} command_t;
74
-
75
-// prototypes
76
-
77
-void
78
-command_init(command_t *self, const char *name, const char *version);
79
-
80
-void
81
-command_free(command_t *self);
82
-
83
-void
84
-command_help(command_t *self);
85
-
86
-void
87
-command_option(command_t *self, const char *small, const char *large, const char *desc, command_callback_t cb);
88
-
89
-void
90
-command_parse(command_t *self, int argc, char **argv);
91
-
92
-#ifdef __cplusplus
93
-}
94
-#endif
95
-
96
-#endif /* COMMANDER_H */

+ 0
- 9
src/deps/commander/package.json View File

@@ -1,9 +0,0 @@
1
-{
2
-  "name": "commander",
3
-  "version": "1.3.2",
4
-  "repo": "clibs/commander",
5
-  "description": "Command-line argument parser",
6
-  "keywords": ["cli", "command", "parser", "argv", "args", "options"],
7
-  "license": "MIT",
8
-  "src": ["src/commander.h", "src/commander.c"]
9
-}

+ 2158
- 0
src/deps/ezoptionparser/ezOptionParser.hpp
File diff suppressed because it is too large
View File


+ 3
- 0
src/deps/imguifilesystem/imguifilesystem.cpp View File

@@ -37,6 +37,9 @@
37 37
 #include <stdio.h>  // FILENAME_MAX
38 38
 #include <new>      // operator new
39 39
 
40
+#ifndef PATH_MAX
41
+#define PATH_MAX 4096
42
+#endif
40 43
 
41 44
 namespace ImGuiFs {
42 45
 

+ 2
- 0
src/loader/LoaderTR1.cpp View File

@@ -295,6 +295,8 @@ void LoaderTR1::loadAngleSet(BoneFrame* bf, BinaryReader& frame, uint16_t numMes
295 295
      */
296 296
     uint16_t numValues = frame.readU16();
297 297
 
298
+    orAssertEqual(numValues, numMeshes);
299
+
298 300
     for (int i = 0; i < numValues; i++) {
299 301
         int mesh = startingMesh + i;
300 302
         glm::vec3 offset(0.0f, 0.0f, 0.0f);

+ 60
- 19
src/main.cpp View File

@@ -18,7 +18,6 @@
18 18
 #include "TextureManager.h"
19 19
 #include "UI.h"
20 20
 #include "World.h"
21
-#include "commander/commander.h"
22 21
 #include "commands/Command.h"
23 22
 #include "system/Shader.h"
24 23
 #include "system/Sound.h"
@@ -26,6 +25,7 @@
26 25
 #include "utils/time.h"
27 26
 
28 27
 #include <glbinding/Binding.h>
28
+#include <ezoptionparser/ezOptionParser.hpp>
29 29
 
30 30
 #ifdef DEBUG
31 31
 #include <glbinding/callbacks.h>
@@ -75,15 +75,51 @@ static void glUnresolvedCallback(const glbinding::AbstractFunction& func) {
75 75
 }
76 76
 #endif
77 77
 
78
-int main(int argc, char* argv[]) {
79
-    command_t cmd;
80
-    command_init(&cmd, argv[0], VERSION);
81
-    command_option(&cmd, "-c", "--config <file>", "select config file to use",
82
-    [](command_t* self) {
83
-        configFileToUse = self->arg;
84
-    });
85
-    command_parse(&cmd, argc, argv);
86
-    command_free(&cmd);
78
+int main(int argc, const char* argv[]) {
79
+    ez::ezOptionParser opt;
80
+    opt.overview = "Open Tomb Raider Game Engine";
81
+    opt.syntax = "OpenRaider [OPTIONS]";
82
+    opt.example = "OpenRaider --config ~/.OpenRaider/OpenRaider.ini";
83
+    opt.footer = VERSION;
84
+
85
+    opt.add("", 0, 0, 0, "Display usage instructions.", "-h", "-help", "--help", "--usage");
86
+    opt.add("", 0, 1, 0, "Config file to use", "-c", "--conf", "--config");
87
+
88
+    opt.parse(argc, argv);
89
+
90
+    if (opt.isSet("-h")) {
91
+        std::string usage;
92
+        opt.getUsage(usage);
93
+        std::cout << usage << std::endl;
94
+        return -1;
95
+    }
96
+
97
+    std::vector<std::string> badOptions;
98
+    if (!opt.gotRequired(badOptions)) {
99
+        for (int i = 0; i < badOptions.size(); i++) {
100
+            std::cout << "ERROR: Missing required option " << badOptions[i] << "." << std::endl;
101
+        }
102
+        std::string usage;
103
+        opt.getUsage(usage);
104
+        std::cout << usage << std::endl;
105
+        return -2;
106
+    }
107
+
108
+    if (!opt.gotExpected(badOptions)) {
109
+        for (int i = 0; i < badOptions.size(); i++) {
110
+            std::cout << "ERROR: Got unexpected number of arguments for option " << badOptions[i] << "." <<
111
+                      std::endl;
112
+        }
113
+        std::string usage;
114
+        opt.getUsage(usage);
115
+        std::cout << usage << std::endl;
116
+        return -3;
117
+    }
118
+
119
+    if (opt.isSet("-c")) {
120
+        std::cout << "Test!" << std::endl;
121
+        opt.get("-c")->getString(configFileToUse);
122
+    }
87 123
 
88 124
     glbinding::Binding::initialize();
89 125
     Log::initialize();
@@ -105,20 +141,20 @@ int main(int argc, char* argv[]) {
105 141
     int error = Window::initialize();
106 142
     if (error != 0) {
107 143
         std::cout << "Could not initialize Window (" << error << ")!" << std::endl;
108
-        return -1;
144
+        return -4;
109 145
     }
110 146
 
111 147
     error = Shader::initialize();
112 148
     if (error != 0) {
113 149
         std::cout << "Could not initialize OpenGL (" << error << ")!" << std::endl;
114
-        return -2;
150
+        return -5;
115 151
     }
116 152
 
117 153
     // Initialize Texture Manager
118 154
     error = TextureManager::initialize();
119 155
     if (error != 0) {
120 156
         std::cout << "Could not initialize TextureManager (" << error << ")!" << std::endl;
121
-        return -3;
157
+        return -6;
122 158
     }
123 159
 
124 160
     if (configFileToUse == "") {
@@ -128,38 +164,43 @@ int main(int argc, char* argv[]) {
128 164
                 if (p != "/")
129 165
                     p += "/";
130 166
                 p += "share/OpenRaider/";
131
-                Command::executeFile(p + DEFAULT_CONFIG_FILE);
167
+                if (Command::executeFile(p + DEFAULT_CONFIG_FILE) != 0) {
168
+                    std::cout << "Could not find any config files. Trying to continue..." << std::endl;
169
+                }
132 170
             }
133 171
         }
134 172
     } else {
135
-        Command::executeFile(configFileToUse);
173
+        if (Command::executeFile(configFileToUse) != 0) {
174
+            std::cout << "Could not find specified config file!" << std::endl;
175
+            return -7;
176
+        }
136 177
     }
137 178
 
138 179
     error = TextureManager::initializeSplash();
139 180
     if (error != 0) {
140 181
         std::cout << "Coult not load Splash Texture (" << error << ")!" << std::endl;
141
-        return -4;
182
+        return -8;
142 183
     }
143 184
 
144 185
     // Initialize Sound
145 186
     error = Sound::initialize();
146 187
     if (error != 0) {
147 188
         std::cout << "Could not initialize Sound (" << error << ")!" << std::endl;
148
-        return -5;
189
+        return -9;
149 190
     }
150 191
 
151 192
     // Initialize Debug UI
152 193
     error = UI::initialize();
153 194
     if (error != 0) {
154 195
         std::cout << "Could not initialize Debug UI (" << error << ")!" << std::endl;
155
-        return -6;
196
+        return -10;
156 197
     }
157 198
 
158 199
     // Initialize Menu
159 200
     error = Menu::initialize();
160 201
     if (error != 0) {
161 202
         std::cout << "Could not initialize Menu (" << error << ")!" << std::endl;
162
-        return -7;
203
+        return -11;
163 204
     }
164 205
 
165 206
     Log::get(LOG_INFO) << "Starting " << VERSION << Log::endl;

+ 5
- 5
src/system/WindowGLFW.cpp View File

@@ -187,12 +187,12 @@ void WindowGLFW::keyCallback(GLFWwindow* w, int key, int scancode, int action, i
187 187
 }
188 188
 
189 189
 void WindowGLFW::charCallback(GLFWwindow* w, unsigned int codepoint) {
190
-    static std::codecvt_utf8<char32_t> conv;
191
-    static mbstate_t state;
192
-    static const int bufferSize = 42;
193
-    static char buffer[bufferSize + 1];
194
-
195 190
     if (textinput) {
191
+        static std::codecvt_utf8<char32_t> conv;
192
+        static mbstate_t state;
193
+        static const int bufferSize = 42;
194
+        static char buffer[bufferSize + 1];
195
+
196 196
         char32_t inBuff[2] = { codepoint, '\0' };
197 197
         const char32_t* in = nullptr;
198 198
         char* ex = nullptr;

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

@@ -21,7 +21,7 @@ uint8_t BinaryReader::readU8() {
21 21
 uint16_t BinaryReader::readU16() {
22 22
     uint16_t a = readU8();
23 23
     uint16_t b = readU8();
24
-    return (a | (b << 8));
24
+    return static_cast<uint16_t>(a | (b << 8));
25 25
 }
26 26
 
27 27
 uint32_t BinaryReader::readU32() {

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

@@ -51,7 +51,7 @@ unsigned char* argb16to32(unsigned char* image, unsigned int w, unsigned int h)
51 51
         // arrr.rrgg gggb.bbbb shift to 5bit
52 52
         img[i * 4] = (image[(i * 2) + 1] & 0x80) ? 0xFF : 0; // A
53 53
         img[(i * 4) + 1] = (image[(i * 2) + 1] & 0x7C) >> 2; // R
54
-        img[(i * 4) + 2] = (image[(i * 2) + 1] & 0x03) << 3;
54
+        img[(i * 4) + 2] = static_cast<unsigned char>((image[(i * 2) + 1] & 0x03) << 3);
55 55
         img[(i * 4) + 2] |= (image[i * 2] & 0xE0) >> 5; // G
56 56
         img[(i * 4) + 3] = image[i * 2] & 0x1F; // B
57 57
 

Loading…
Cancel
Save