X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=cd28493f1ece06a549ee4517e1f369d14bd00571;hb=38ea4e57bc9b730abf7a15f8cc235465e6f0ad4c;hp=9125a4e142740346420966d5957ed6711463a27c;hpb=2a1101854ff7336e35d52f76a3114870c8a6b15d;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 9125a4e1..cd28493f 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -450,38 +450,6 @@ char *getRealName() return real_name; } -char *getHomeDir() -{ - static char *dir = NULL; - -#if defined(PLATFORM_WIN32) - if (dir == NULL) - { - dir = checked_malloc(MAX_PATH + 1); - - if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, dir))) - strcpy(dir, "."); - } -#elif defined(PLATFORM_UNIX) - if (dir == NULL) - { - if ((dir = getenv("HOME")) == NULL) - { - struct passwd *pwd; - - if ((pwd = getpwuid(getuid())) != NULL) - dir = getStringCopy(pwd->pw_dir); - else - dir = "."; - } - } -#else - dir = "."; -#endif - - return dir; -} - /* ------------------------------------------------------------------------- */ /* path manipulation functions */ @@ -1932,6 +1900,48 @@ int get_auto_parameter_value(char *token, char *value_raw) return get_parameter_value(value_raw, suffix, TYPE_INTEGER); } +struct ScreenModeInfo *get_screen_mode_from_string(char *screen_mode_string) +{ + static struct ScreenModeInfo screen_mode; + char *screen_mode_string_x = strchr(screen_mode_string, 'x'); + char *screen_mode_string_copy; + char *screen_mode_string_pos_w; + char *screen_mode_string_pos_h; + + if (screen_mode_string_x == NULL) /* invalid screen mode format */ + return NULL; + + screen_mode_string_copy = getStringCopy(screen_mode_string); + + screen_mode_string_pos_w = screen_mode_string_copy; + screen_mode_string_pos_h = strchr(screen_mode_string_copy, 'x'); + *screen_mode_string_pos_h++ = '\0'; + + screen_mode.width = atoi(screen_mode_string_pos_w); + screen_mode.height = atoi(screen_mode_string_pos_h); + + return &screen_mode; +} + +void get_aspect_ratio_from_screen_mode(struct ScreenModeInfo *screen_mode, + int *x, int *y) +{ + float aspect_ratio = (float)screen_mode->width / (float)screen_mode->height; + float aspect_ratio_new; + int i = 1; + + do + { + *x = i * aspect_ratio + 0.000001; + *y = i; + + aspect_ratio_new = (float)*x / (float)*y; + + i++; + } + while (aspect_ratio_new != aspect_ratio && *y < screen_mode->height); +} + static void FreeCustomArtworkList(struct ArtworkListInfo *, struct ListNodeInfo ***, int *); @@ -2799,7 +2809,7 @@ void FreeCustomArtworkLists(struct ArtworkListInfo *artwork_info) char *getErrorFilename(char *basename) { - return getPath2(getUserDataDir(), basename); + return getPath2(getUserGameDataDir(), basename); } void openErrorFile()