X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=723f8af0e2597b1a5924c86104ed4e365cb0b5f6;hb=68d1418be737276c8214780106399c0dae588d1c;hp=307350325c759bfecd14640cc8027f120e3ca1f6;hpb=e5367ee42312c8835125438511d8479aa2daa094;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index 30735032..723f8af0 100644 --- a/src/init.c +++ b/src/init.c @@ -38,9 +38,6 @@ #define CONFIG_TOKEN_FONT_INITIAL "font.initial" #define CONFIG_TOKEN_GLOBAL_BUSY "global.busy" -#define DEBUG_PRINT_INIT_TIMESTAMPS TRUE -#define DEBUG_PRINT_INIT_TIMESTAMPS_DEPTH 0 - static struct FontBitmapInfo font_initial[NUM_INITIAL_FONTS]; static struct GraphicInfo anim_initial; @@ -89,72 +86,6 @@ static int copy_properties[][5] = }; -static void print_timestamp_ext(char *message, char *mode) -{ -#if DEBUG -#if DEBUG_PRINT_INIT_TIMESTAMPS - static char *debug_message = NULL; - static char *last_message = NULL; - static int counter_nr = 0; - int max_depth = DEBUG_PRINT_INIT_TIMESTAMPS_DEPTH; - - checked_free(debug_message); - debug_message = getStringCat3(mode, " ", message); - - if (strEqual(mode, "INIT")) - { - debug_print_timestamp(counter_nr, NULL); - - if (counter_nr + 1 < max_depth) - debug_print_timestamp(counter_nr, debug_message); - - counter_nr++; - - debug_print_timestamp(counter_nr, NULL); - } - else if (strEqual(mode, "DONE")) - { - counter_nr--; - - if (counter_nr + 1 < max_depth || - (counter_nr == 0 && max_depth == 1)) - { - last_message = message; - - if (counter_nr == 0 && max_depth == 1) - { - checked_free(debug_message); - debug_message = getStringCat3("TIME", " ", message); - } - - debug_print_timestamp(counter_nr, debug_message); - } - } - else if (!strEqual(mode, "TIME") || - !strEqual(message, last_message)) - { - if (counter_nr < max_depth) - debug_print_timestamp(counter_nr, debug_message); - } -#endif -#endif -} - -static void print_timestamp_init(char *message) -{ - print_timestamp_ext(message, "INIT"); -} - -static void print_timestamp_time(char *message) -{ - print_timestamp_ext(message, "TIME"); -} - -static void print_timestamp_done(char *message) -{ - print_timestamp_ext(message, "DONE"); -} - void DrawInitAnim() { struct GraphicInfo *graphic_info_last = graphic_info; @@ -1196,7 +1127,6 @@ static int get_graphic_parameter_value(char *value_raw, char *suffix, int type) if (strEqual(value_raw, ARG_UNDEFINED)) return ARG_UNDEFINED_VALUE; -#if 1 if (type == TYPE_ELEMENT) { char *value = getHashEntry(element_token_hash, value_raw); @@ -1210,36 +1140,6 @@ static int get_graphic_parameter_value(char *value_raw, char *suffix, int type) return (value != NULL ? atoi(value) : IMG_UNDEFINED); } -#else - - int i; - int x = 0; - - /* !!! THIS IS BUGGY !!! NOT SURE IF YOU GET ELEMENT ID OR GRAPHIC ID !!! */ - /* !!! (possible reason why ".clone_from" with elements doesn't work) !!! */ - - /* !!! OPTIMIZE THIS BY USING HASH !!! */ - for (i = 0; i < MAX_NUM_ELEMENTS; i++) - if (strEqual(element_info[i].token_name, value_raw)) - return i; - - /* !!! OPTIMIZE THIS BY USING HASH !!! */ - for (i = 0; image_config[i].token != NULL; i++) - { - int len_config_value = strlen(image_config[i].value); - - if (!strEqual(&image_config[i].value[len_config_value - 4], ".pcx") && - !strEqual(&image_config[i].value[len_config_value - 4], ".wav") && - !strEqual(image_config[i].value, UNDEFINED_FILENAME)) - continue; - - if (strEqual(image_config[i].token, value_raw)) - return x; - - x++; - } -#endif - return -1; } @@ -5059,7 +4959,8 @@ static void InitGlobal() /* create hash from graphic token list */ graphic_token_hash = newSetupFileHash(); for (graphic = 0, i = 0; image_config[i].token != NULL; i++) - if (strSuffix(image_config[i].value, ".pcx") || + if (strSuffix(image_config[i].value, ".png") || + strSuffix(image_config[i].value, ".pcx") || strSuffix(image_config[i].value, ".wav") || strEqual(image_config[i].value, UNDEFINED_FILENAME)) setHashEntry(graphic_token_hash, @@ -5312,8 +5213,56 @@ void Execute_Command(char *command) } #if DEBUG -#if defined(TARGET_SDL) -#if !defined(TARGET_SDL2) +#if defined(TARGET_SDL2) + else if (strEqual(command, "SDL_ListModes")) + { + SDL_Init(SDL_INIT_VIDEO); + + int num_displays = SDL_GetNumVideoDisplays(); + + // check if there are any displays available + if (num_displays < 0) + { + printf("No displays available: %s\n", SDL_GetError()); + + exit(-1); + } + + for (i = 0; i < num_displays; i++) + { + int num_modes = SDL_GetNumDisplayModes(i); + int j; + + printf("Available display modes for display %d:\n", i); + + // check if there are any display modes available for this display + if (num_modes < 0) + { + printf("No display modes available for display %d: %s\n", + i, SDL_GetError()); + + exit(-1); + } + + for (j = 0; j < num_modes; j++) + { + SDL_DisplayMode mode; + + if (SDL_GetDisplayMode(i, j, &mode) < 0) + { + printf("Cannot get display mode %d for display %d: %s\n", + j, i, SDL_GetError()); + + exit(-1); + } + + printf("- %d x %d\n", mode.w, mode.h); + } + } + + exit(0); + } +#elif defined(TARGET_SDL) else if (strEqual(command, "SDL_ListModes")) { SDL_Rect **modes; @@ -5339,16 +5288,15 @@ void Execute_Command(char *command) } else { - printf("Available Modes:\n"); + printf("Available display modes:\n"); - for(i = 0; modes[i]; i++) - printf(" %d x %d\n", modes[i]->w, modes[i]->h); + for (i = 0; modes[i]; i++) + printf("- %d x %d\n", modes[i]->w, modes[i]->h); } exit(0); } #endif -#endif #endif else @@ -5644,91 +5592,6 @@ void InitGfx() font_height = getFontHeight(FC_RED); - - - - - - - - -#if 0 - Delay(1000); - -#if 0 - Bitmap new_bitmap; - printf("::: MARK 1.1\n"); - new_bitmap.surface = SDL_LoadBMP("TEST.bmp"); - printf("::: MARK 1.2\n"); -#endif - - char *filename = getCustomImageFilename("RocksFontSmall.pcx"); - - printf("::: FILENAME == '%s'\n", filename); - -#if 1 - Bitmap *new_bitmap = LoadImage(filename); -#else -#if 1 - Bitmap *new_bitmap = CreateBitmapStruct(); - SDL_Surface *sdl_image_tmp; - sdl_image_tmp = IMG_Load(filename); - new_bitmap->surface = SDL_DisplayFormat(sdl_image_tmp); - -#else - SDL_Surface *sdl_image_tmp = IMG_Load(filename); - SDL_Surface *sdl_image = SDL_DisplayFormat(sdl_image_tmp); -#endif -#endif - - // SDL_Surface *image = SDL_LoadBMP("TEST.bmp"); - // SDL_LoadBMP("TEST.bmp"); - - // bitmap_font_initial->surface = SDL_LoadBMP("TEST.bmp"); - -#if 0 - printf("::: MARK 1 [%08x, %08xd]\n", - (unsigned int)bitmap_font_initial->surface, - (unsigned int)backbuffer->surface); -#endif - - // SDL_BlitSurface(image, NULL, backbuffer->surface, NULL); - // SDL_BlitSurface(new_bitmap.surface, NULL,backbuffer->surface, NULL); - SDL_BlitSurface(new_bitmap->surface, NULL,backbuffer->surface, NULL); - // SDL_BlitSurface(sdl_image, NULL,backbuffer->surface, NULL); - // SDL_BlitSurface(bitmap_font_initial->surface, NULL,backbuffer->surface, NULL); - -#if 0 - printf("::: MARK 1 [%08x, %08xd, %08xd]\n", - (unsigned int)bitmap_font_initial->surface, - (unsigned int)backbuffer->surface, - (unsigned int)image); -#endif - - extern SDL_Window *sdl_window; - SDL_UpdateWindowSurface(sdl_window); - -#if 1 -#if 0 - SDL_BlitSurface(bitmap_font_initial->surface, NULL,backbuffer->surface, NULL); -#endif - // SDL_UpdateWindowSurface(sdl_window); - - Delay(1000); - exit(0); -#endif -#endif - - - - - - - - - - - #if 1 DrawInitText(getWindowTitleString(), 20, FC_YELLOW); #else @@ -6363,6 +6226,10 @@ void KeyboardAutoRepeatOffUnlessAutoplay() void DisplayExitMessage(char *format, va_list ap) { + // check if draw buffer and fonts for exit message are already available + if (drawto == NULL || font_initial[NUM_INITIAL_FONTS - 1].bitmap == NULL) + return; + int font_1 = FC_RED; int font_2 = FC_YELLOW; int font_3 = FC_BLUE; @@ -6552,6 +6419,24 @@ void OpenAll() DrawMainMenu(); InitNetworkServer(); + +#if 0 + Error(ERR_DEBUG, "::: SDL_GetBasePath() == '%s'", + SDL_GetBasePath()); + Error(ERR_DEBUG, "::: SDL_GetPrefPath() == '%s'", + SDL_GetPrefPath("artsoft", "rocksndiamonds")); +#if defined(PLATFORM_ANDROID) + Error(ERR_DEBUG, "::: SDL_AndroidGetInternalStoragePath() == '%s'", + SDL_AndroidGetInternalStoragePath()); + Error(ERR_DEBUG, "::: SDL_AndroidGetExternalStoragePath() == '%s'", + SDL_AndroidGetExternalStoragePath()); + Error(ERR_DEBUG, "::: SDL_AndroidGetExternalStorageState() == '%s'", + (SDL_AndroidGetExternalStorageState() == + SDL_ANDROID_EXTERNAL_STORAGE_READ ? "read" : + SDL_AndroidGetExternalStorageState() == + SDL_ANDROID_EXTERNAL_STORAGE_WRITE ? "write" : "not available")); +#endif +#endif } void CloseAllAndExit(int exit_value)