Browse Source

Added (pretty empty) OpenRaider main Singleton

Thomas Buck 10 years ago
parent
commit
383029d5d5
7 changed files with 118 additions and 6 deletions
  1. 36
    0
      include/OpenRaider.h
  2. 2
    0
      include/main.h
  3. 2
    0
      include/utils/strings.h
  4. 1
    0
      src/CMakeLists.txt
  5. 26
    0
      src/OpenRaider.cpp
  6. 51
    5
      src/main.cpp
  7. 0
    1
      src/utils/strings.cpp

+ 36
- 0
include/OpenRaider.h View File

@@ -0,0 +1,36 @@
1
+/*!
2
+ * \file include/OpenRaider.h
3
+ * \brief Main Game Object
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _OPENRAIDER_H_
9
+#define _OPENRAIDER_H_
10
+
11
+/*!
12
+ * \brief Main Game Singleton
13
+ */
14
+class OpenRaider {
15
+public:
16
+
17
+    /*!
18
+     * \brief Constructs an object of OpenRaider
19
+     */
20
+    OpenRaider();
21
+
22
+    /*!
23
+     * \brief Deconstructs an object of OpenRaider
24
+     */
25
+    ~OpenRaider();
26
+
27
+    /*!
28
+     * \brief Load the configuration file
29
+     * \returns 0 on success
30
+     */
31
+    int loadConfig(const char *config);
32
+
33
+private:
34
+};
35
+
36
+#endif

+ 2
- 0
include/main.h View File

@@ -7,6 +7,8 @@
7 7
 #ifndef _MAIN_H_
8 8
 #define _MAIN_H_
9 9
 
10
+extern OpenRaider *gOpenRaider; //!< Main Game Singleton
11
+
10 12
 /*!
11 13
  * \brief atexit() handler
12 14
  */

+ 2
- 0
include/utils/strings.h View File

@@ -9,6 +9,8 @@
9 9
 #ifndef _UTILS_STRINGS_H_
10 10
 #define _UTILS_STRINGS_H_
11 11
 
12
+#include <cstdarg>
13
+
12 14
 /*!
13 15
  * \brief Check if a string ends with another string.
14 16
  * \param str string to check

+ 1
- 0
src/CMakeLists.txt View File

@@ -1,5 +1,6 @@
1 1
 # Set Source files
2 2
 set (SRCS ${SRCS} "main.cpp")
3
+set (SRCS ${SRCS} "OpenRaider.cpp")
3 4
 set (SRCS ${SRCS} "Sound.cpp")
4 5
 
5 6
 #################################################################

+ 26
- 0
src/OpenRaider.cpp View File

@@ -0,0 +1,26 @@
1
+/*!
2
+ * \file src/OpenRaider.cpp
3
+ * \brief Main Game Object
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include <cstdio>
9
+
10
+#include "utils/strings.h"
11
+#include "OpenRaider.h"
12
+
13
+OpenRaider::OpenRaider() {
14
+}
15
+
16
+OpenRaider::~OpenRaider() {
17
+}
18
+
19
+int OpenRaider::loadConfig(const char *config) {
20
+    char *configFile = fullPath(config, 0);
21
+
22
+    printf("Trying to load \"%s\"...\n", configFile);
23
+
24
+    return -1;
25
+}
26
+

+ 51
- 5
src/main.cpp View File

@@ -5,27 +5,73 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
-#include <stdlib.h>
9
-#include <stdio.h>
8
+#include <cstdlib>
9
+#include <cstdio>
10
+#include <cstring>
10 11
 
11 12
 #include "config.h"
13
+#include "OpenRaider.h"
12 14
 #include "main.h"
13 15
 
14
-void cleanupHandler() {
16
+#define DEFAULT_CONFIG_PATH "~/.OpenRaider/"
17
+#define DEFAULT_CONFIG_FILE "OpenRaider.init"
18
+
19
+OpenRaider *gOpenRaider = NULL;
15 20
 
21
+void cleanupHandler() {
22
+    if (gOpenRaider)
23
+        delete gOpenRaider;
16 24
 }
17 25
 
18 26
 int main(int argc, char *argv[]) {
27
+    const char *config = NULL;
28
+
29
+    // Handle arguments
19 30
     if (argc == 1) {
20 31
         // Use default rc file path
32
+        config = DEFAULT_CONFIG_PATH DEFAULT_CONFIG_FILE;
21 33
     } else if (argc == 2) {
22
-        // Use provided rc file
34
+        // Check for command line switches
35
+        if ((strcmp("-h", argv[1]) == 0)
36
+                || (strcmp("--help", argv[1]) == 0)) {
37
+            // Display help text
38
+            printf("%s [OPTIONS | /path/to/config]\n"
39
+                    "Options:\n"
40
+                    "\t--help\n\t-h\tDisplay this help text\n"
41
+                    "\t--version\n\t-v\tDisplay version information\n"
42
+                    "If no options are given, the default config will be loaded from:\n"
43
+                    "\t" DEFAULT_CONFIG_PATH DEFAULT_CONFIG_FILE "\n", argv[0]);
44
+            return 0;
45
+        } else if ((strcmp("-v", argv[1]) == 0)
46
+                || (strcmp("--version", argv[1]) == 0)) {
47
+            // Display version
48
+            printf(VERSION "\n");
49
+            return 0;
50
+        } else {
51
+            // Interpret as rc file name
52
+            config = argv[1];
53
+        }
23 54
     } else {
24
-        printf("Usage:\n%s [/path/to/config.file]\n", argv[0]);
55
+        printf("Usage:\n%s -h\n", argv[0]);
25 56
         return 1;
26 57
     }
27 58
 
59
+    // Create globals
28 60
     atexit(cleanupHandler);
61
+    printf("Initializing " VERSION "\n");
62
+    gOpenRaider = new OpenRaider();
63
+
64
+    // Try to load a configuration
65
+    if (gOpenRaider->loadConfig(config) != 0) {
66
+        if (gOpenRaider->loadConfig(DEFAULT_CONFIG_PATH DEFAULT_CONFIG_FILE) != 0) {
67
+            if (gOpenRaider->loadConfig(DEFAULT_CONFIG_FILE) != 0) {
68
+                printf("Could not find a config file. Aborting...\n");
69
+                return 2;
70
+            }
71
+        }
72
+    }
73
+
74
+    // Initialize the "subsystems"
29 75
 
30 76
     return 0;
31 77
 }

+ 0
- 1
src/utils/strings.cpp View File

@@ -6,7 +6,6 @@
6 6
  * \author Mongoose
7 7
  */
8 8
 
9
-#include <cstdarg>
10 9
 #include <cstdlib>
11 10
 #include <stdio.h>
12 11
 #include <string.h>

Loading…
Cancel
Save