#include "globals.h" #include "interfaces.h" #include "../common/fio.h" #ifdef __APPLE__ #include "CoreFoundation/CoreFoundation.h" #endif int main(int argc, char *argv[]) { #ifdef __APPLE__ char path[PATH_MAX]; CFURLRef res = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); CFURLGetFileSystemRepresentation(res, TRUE, (UInt8 *)path, PATH_MAX); CFRelease(res); // there's likely a better way to do this! size_t path_len = strlen(path); int i = path_len; int p_c = 0; while (i > 0) { if (path[i] == '/') { p_c++; } if (p_c == 3) break; i--; } char bundle_path[i+1]; memcpy(bundle_path, path, i); bundle_path[i] = '\0'; chdir(bundle_path); #endif // let's load in our config file int buffer_size = 0; char *memory; g_settings = newTable(32); if ((buffer_size = fileToMemory(&memory, "settings.tsc")) >= 0) { int offset = 0; loadConfig_r(g_settings, memory, buffer_size, &offset); } else { // file does not exist! // populate g_settings with default settings addTablePairInt(g_settings, "v_width", 1024); addTablePairInt(g_settings, "v_height", 768); addTablePairInt(g_settings, "v_fullscreen", 0); addTablePairInt(g_settings, "v_renderer", 1); addTablePairInt(g_settings, "v_fps", 60); addTablePairInt(g_settings, "v_framecap", 0); addTablePairInt(g_settings, "tickrate", 40000000); addTablePairInt(g_settings, "clock", 0); } // let's search for modules! if ((g_modules_list = dirToLList("modules", F_DIRS)) == NULL) { printf("ERR: no modules found in \"modules/\"\n"); if ((g_modules_list = dirToLList("../modules", F_DIRS)) == NULL) { printf("ERR: no modules found in \"../modules\"\n"); } } /*printf("modules:\n"); struct LList *llist = g_modules_list; while (llist) { if (strcmp((char*)llist->data, getTablePairValueString(g_settings, "module")) == 0) printf("* "); printf("%s\n", (char*)llist->data); llist = llist->next; }*/ // NULL our module-related stuff g_module_conf = NULL; g_tile_data = NULL; // initialize our interface system (ncurses, SDL, etc.) if (interfaceInit() == 1) { return 1; } g_running = 1; interfaceRun(); interfaceClose(); return 0; }