/*! * \file src/main.cpp * \brief Where main() is * * \author xythobuz */ #include #include #include #include "global.h" #include "Camera.h" #include "Console.h" #include "Game.h" #include "Menu.h" #include "OpenRaider.h" #include "Render.h" #include "World.h" #include "utils/strings.h" #include "utils/time.h" #ifdef USING_AL #include "SoundAL.h" #else #include "SoundNull.h" #endif #ifdef USING_SDL #include "WindowSDL.h" #else #error No Windowing Library selected! #endif Camera gCamera; Console gConsole; Game gGame; Menu gMenu; OpenRaider gOpenRaider; Render gRender; World gWorld; #ifdef USING_AL SoundAL gSound; #else SoundNull gSound; #endif #ifdef USING_SDL WindowSDL gWindow; #endif Camera &getCamera() { return gCamera; } Console &getConsole() { return gConsole; } Game &getGame() { return gGame; } Menu &getMenu() { return gMenu; } OpenRaider &getOpenRaider() { return gOpenRaider; } Render &getRender() { return gRender; } Sound &getSound() { return gSound; } Window &getWindow() { return gWindow; } World &getWorld() { return gWorld; } void cleanupHandler(void) { #ifdef DEBUG printf("\nThanks for testing %s\n", VERSION); printf("Build date: %s @ %s\n", __DATE__, __TIME__); printf("Build host: %s\n", BUILD_HOST); printf("Web site : http://github.com/xythobuz/OpenRaider\n"); printf("Contact : xythobuz@xythobuz.de\n"); #endif } int main(int argc, char *argv[]) { const char *config = NULL; // Handle arguments if (argc == 1) { // Use default rc file path config = DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE; } else if (argc == 2) { // Check for command line switches if ((strcmp("-h", argv[1]) == 0) || (strcmp("--help", argv[1]) == 0)) { // Display help text printf("%s [OPTIONS | /path/to/config]\n" "Options:\n" "\t--help\n\t-h\tDisplay this help text\n" "\t--version\n\t-v\tDisplay version information\n" "If no options are given, the default config will be loaded from:\n" "\t" DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE "\n", argv[0]); return 0; } else if ((strcmp("-v", argv[1]) == 0) || (strcmp("--version", argv[1]) == 0)) { // Display version printf(VERSION "\n"); return 0; } else { // Interpret as rc file name config = argv[1]; } } else { printf("Usage:\n%s -h\n", argv[0]); return 1; } #ifdef DEBUG printf("Initializing %s\n", VERSION); #endif atexit(cleanupHandler); // Try to load a configuration if (gOpenRaider.loadConfig(config) != 0) { if (gOpenRaider.loadConfig(DEFAULT_CONFIG_PATH "/" DEFAULT_CONFIG_FILE) != 0) { if (gOpenRaider.loadConfig(DEFAULT_CONFIG_FILE) != 0) { printf("Could not find a config file. Aborting...\n"); return 2; } } } // Initialize everything int error = gOpenRaider.initialize(); if (error != 0) { printf("Could not initialize OpenRaider (%d)!\n", error); return 3; } // Enter Main loop gConsole.print("Starting %s", VERSION); gOpenRaider.run(); return 0; } #if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS) && (!defined(NDEBUG)) #include void assertImplementation(const char *exp, const char *file, int line) { const unsigned int maxSize = 128; void *callstack[maxSize]; int frames = backtrace(callstack, maxSize); char **strs = backtrace_symbols(callstack, frames); printf("\nassertion failed:\n"); printf("\t%s\n", exp); printf("in %s:%d\n\n", file, line); for (int i = 0; i < frames; i++) printf("%s\n", strs[i]); delete [] strs; abort(); } #endif ActionEvents stringToActionEvent(const char *action) { if (strcmp(action, "menu") == 0) { return menuAction; } else if (strcmp(action, "console") == 0) { return consoleAction; } else if (strcmp(action, "forward") == 0) { return forwardAction; } else if (strcmp(action, "backward") == 0) { return backwardAction; } else if (strcmp(action, "left") == 0) { return leftAction; } else if (strcmp(action, "right") == 0) { return rightAction; } else if (strcmp(action, "jump") == 0) { return jumpAction; } else if (strcmp(action, "crouch") == 0) { return crouchAction; } else if (strcmp(action, "use") == 0) { return useAction; } else if (strcmp(action, "holster") == 0) { return holsterAction; } else if (strcmp(action, "walk") == 0) { return walkAction; } else { return ActionEventCount; } } KeyboardButton stringToKeyboardButton(const char *key) { size_t length = strlen(key); if ((key[0] == '\'') && (key[length - 1] == '\'') && (length == 3)) { // Literal character like w, a, s, d, 0, 1... char c = key[1]; if (((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'z'))) return (KeyboardButton)c; } else if ((key[0] == '\"') && (key[length - 1] == '\"')) { // Special characters like tilde, esc, quote... char *tmp = stringRemoveQuotes(key); if (strcmp(tmp, "quote") == 0) { delete [] tmp; return quoteKey; } else if (strcmp(tmp, "backslash") == 0) { delete [] tmp; return backslashKey; } else if (strcmp(tmp, "backspace") == 0) { delete [] tmp; return backspaceKey; } else if (strcmp(tmp, "capslock") == 0) { delete [] tmp; return capslockKey; } else if (strcmp(tmp, "comma") == 0) { delete [] tmp; return commaKey; } else if (strcmp(tmp, "del") == 0) { delete [] tmp; return delKey; } else if (strcmp(tmp, "up") == 0) { delete [] tmp; return upKey; } else if (strcmp(tmp, "down") == 0) { delete [] tmp; return downKey; } else if (strcmp(tmp, "left") == 0) { delete [] tmp; return leftKey; } else if (strcmp(tmp, "right") == 0) { delete [] tmp; return rightKey; } else if (strcmp(tmp, "end") == 0) { delete [] tmp; return endKey; } else if (strcmp(tmp, "equals") == 0) { delete [] tmp; return equalsKey; } else if (strcmp(tmp, "escape") == 0) { delete [] tmp; return escapeKey; } else if (strcmp(tmp, "f1") == 0) { delete [] tmp; return f1Key; } else if (strcmp(tmp, "f2") == 0) { delete [] tmp; return f2Key; } else if (strcmp(tmp, "f3") == 0) { delete [] tmp; return f3Key; } else if (strcmp(tmp, "f4") == 0) { delete [] tmp; return f4Key; } else if (strcmp(tmp, "f5") == 0) { delete [] tmp; return f5Key; } else if (strcmp(tmp, "f6") == 0) { delete [] tmp; return f6Key; } else if (strcmp(tmp, "f7") == 0) { delete [] tmp; return f7Key; } else if (strcmp(tmp, "f8") == 0) { delete [] tmp; return f8Key; } else if (strcmp(tmp, "f9") == 0) { delete [] tmp; return f9Key; } else if (strcmp(tmp, "f10") == 0) { delete [] tmp; return f10Key; } else if (strcmp(tmp, "f11") == 0) { delete [] tmp; return f11Key; } else if (strcmp(tmp, "f12") == 0) { delete [] tmp; return f12Key; } else if (strcmp(tmp, "backquote") == 0) { delete [] tmp; return backquoteKey; } else if (strcmp(tmp, "home") == 0) { delete [] tmp; return homeKey; } else if (strcmp(tmp, "insert") == 0) { delete [] tmp; return insertKey; } else if (strcmp(tmp, "leftalt") == 0) { delete [] tmp; return leftaltKey; } else if (strcmp(tmp, "leftctrl") == 0) { delete [] tmp; return leftctrlKey; } else if (strcmp(tmp, "leftbracket") == 0) { delete [] tmp; return leftbracketKey; } else if (strcmp(tmp, "leftgui") == 0) { delete [] tmp; return leftguiKey; } else if (strcmp(tmp, "leftshift") == 0) { delete [] tmp; return leftshiftKey; } else if (strcmp(tmp, "minus") == 0) { delete [] tmp; return minusKey; } else if (strcmp(tmp, "numlock") == 0) { delete [] tmp; return numlockKey; } else if (strcmp(tmp, "pagedown") == 0) { delete [] tmp; return pagedownKey; } else if (strcmp(tmp, "pageup") == 0) { delete [] tmp; return pageupKey; } else if (strcmp(tmp, "pause") == 0) { delete [] tmp; return pauseKey; } else if (strcmp(tmp, "dot") == 0) { delete [] tmp; return dotKey; } else if (strcmp(tmp, "rightalt") == 0) { delete [] tmp; return rightaltKey; } else if (strcmp(tmp, "rightctrl") == 0) { delete [] tmp; return rightctrlKey; } else if (strcmp(tmp, "enter") == 0) { delete [] tmp; return enterKey; } else if (strcmp(tmp, "rightgui") == 0) { delete [] tmp; return rightguiKey; } else if (strcmp(tmp, "rightbracket") == 0) { delete [] tmp; return rightbracketKey; } else if (strcmp(tmp, "rightshift") == 0) { delete [] tmp; return rightshiftKey; } else if (strcmp(tmp, "scrolllock") == 0) { delete [] tmp; return scrolllockKey; } else if (strcmp(tmp, "semicolon") == 0) { delete [] tmp; return semicolonKey; } else if (strcmp(tmp, "slash") == 0) { delete [] tmp; return slashKey; } else if (strcmp(tmp, "space") == 0) { delete [] tmp; return spaceKey; } else if (strcmp(tmp, "tab") == 0) { delete [] tmp; return tabKey; } else if (strcmp(tmp, "leftmouse") == 0) { delete [] tmp; return leftmouseKey; } else if (strcmp(tmp, "middlemouse") == 0) { delete [] tmp; return middlemouseKey; } else if (strcmp(tmp, "rightmouse") == 0) { delete [] tmp; return rightmouseKey; } delete [] tmp; } return unknownKey; }