int main(int argc, char **argv) #endif { #ifdef USE_BREAKPAD google_breakpad::ExceptionHandler *pHandler = new google_breakpad::ExceptionHandler( L"dumps\\", DmpFilter, DmpCallback, 0, google_breakpad::ExceptionHandler::HANDLER_ALL, MiniDumpNormal, L"", 0 ); #endif srand( time( 0 ) ); ISystem & sys = GetSystem(); if ( !sys.Init( "Return of Dr. Destructo", "game.log" ) ) return -1; #ifdef ALLEGRO_ANDROID al_android_set_apk_file_interface(); #endif sys.SetConfigName( "dd.cfg" ); sys.LoadConfig(); ++g_options_version; ISound & sound = GetSound(); sound.Init(); const int masterVolume = sys.HasConfigValue( "DD_Sound", "Master" ) ? sys.GetConfigValue_Int( "DD_Sound", "Master" ) : 100; const int soundVolume = sys.HasConfigValue( "DD_Sound", "Sound" ) ? sys.GetConfigValue_Int( "DD_Sound", "Sound" ) : 100; const int musicVolume = sys.HasConfigValue( "DD_Sound", "Music" ) ? sys.GetConfigValue_Int( "DD_Sound", "Music" ) : 100; sound.SetMasterVolume( masterVolume / 100.0f ); sound.SetVolumeByType( ISample::TYPE_SOUND, soundVolume / 100.0f ); sound.SetVolumeByType( ISample::TYPE_MUSIC, musicVolume / 100.0f ); int cfgW = sys.GetConfigValue_Int( "DD_Graphics", "Width" ); int cfgH = sys.GetConfigValue_Int( "DD_Graphics", "Height" ); int cfgB = sys.GetConfigValue_Int( "DD_Graphics", "Depth" ); int scaling = sys.GetConfigValue_Int( "DD_Graphics", "Scaling" ); if ( scaling == 0 ) scaling = SCALING_KEEP_ASPECT; bool fullscreen = sys.GetConfigValue_Int( "DD_Graphics", "Fullscreen" ); bool vsync = sys.HasConfigValue( "DD_Graphics", "VSync" ) ? sys.GetConfigValue_Int( "DD_Graphics", "VSync" ) : false; if ( cfgW <= 0 ) cfgW = 1280; if ( cfgH <= 0 ) cfgH = 960; if ( cfgB <= 0 ) cfgB = 32; //cfgW = 320; //cfgH = 200; IRender & render = GetRender(); int renderType = sys.GetConfigValue_Int( "DD_Graphics", "RenderMode" ); ERenderType realType = renderType == 0 ? RENDERTYPE_DIRECT3D : RENDERTYPE_OPENGL; if ( !render.Init( realType, cfgW, cfgH, cfgB, fullscreen, vsync, "Data/Fonts/111-catatan-perjalanan.otf" ) ) return -1; render.SetGlobalScaling( (EScalingMode)scaling, SCREEN_W, SCREEN_H ); IInput & input = GetInput(); if ( !input.Init( true, true, true, true ) ) return -1; sys.SetWindowTitle( "Return of Dr. Destructo v1.0" ); Game game; game.Run(); render.Clear(); return 0; }
int init_bitmaps(Board *b){ // will load bitmaps from folders named 0, 1,..., 7 // inside the folder "icons", each containing 8 square bitmaps int i,j, k=0; char pathname[1000]; ALLEGRO_PATH *path; ALLEGRO_BITMAP *dispbuf = al_get_target_bitmap(); al_set_target_bitmap(NULL); // this is a workaround for android -- try removing later #ifdef ALLEGRO_ANDROID al_android_set_apk_file_interface(); #endif al_set_target_bitmap(dispbuf); for(i=0;i<b->h+1;i++){ for(j=0;j<b->n; j++){ al_utf8_encode(symbol_char[i][j], BF_CODEPOINT_START+ j + i*b->n); symbol_char[i][j][al_utf8_width(BF_CODEPOINT_START+ j + i*b->n)] = '\0'; } } // create buttons // xxx todo: improve these default_font = al_load_font(DEFAULT_FONT_FILE, 16, 0); if(!default_font) errlog("Error loading default font"); b->info_text_bmp = NULL; b->info_panel.bmp = NULL; // if this fails, buttons will be created anyway at update_bitmaps b->button_bmp[0] = al_load_bitmap("buttons/light-bulb.png"); b->button_bmp[1] = al_load_bitmap("buttons/question.png"); b->button_bmp[2] = al_load_bitmap("buttons/gear.png"); b->button_bmp[3] = al_load_bitmap("buttons/undo.png"); if(b->type_of_tiles == 2) return init_bitmaps_classic(b); if(b->type_of_tiles == 1){ // use bitmaps #ifndef ALLEGRO_ANDROID path = al_get_standard_path(ALLEGRO_RESOURCES_PATH); al_path_cstr(path, '/'); #else path = al_create_path(""); #endif for(j=0; j<b->h; j++){ for(k=0; k<b->n; k++){ snprintf(pathname, 999, "%sicons/%d/%d.png", al_path_cstr(path, '/'), j, k); basic_bmp[j][k] = al_load_bitmap(pathname); if(!basic_bmp[j][k]){ errlog("Error loading %s.", pathname); unload_basic_bmps(b, j,k-1); al_destroy_path(path); return -1; } } } al_destroy_path(path); } // create symbols (alternatively we could load these from files!)) symbol_bmp[SYM_FORBIDDEN] = al_create_bitmap(256, 256); symbol_bmp[SYM_SWAPPABLE] = al_create_bitmap(3*256 + 2*b->clue_unit_space, 256); symbol_bmp[SYM_ONE_SIDE] = al_create_bitmap(256, 256); symbol_bmp[SYM_ONLY_ONE] = al_create_bitmap(256, 3*256); if( (!symbol_bmp[SYM_FORBIDDEN]) || (!symbol_bmp[SYM_SWAPPABLE]) || (!symbol_bmp[SYM_ONE_SIDE]) || !symbol_bmp[SYM_ONLY_ONE]){ fprintf(stderr, "Error creating bitmap.\n"); return -1; } al_set_target_bitmap(symbol_bmp[SYM_FORBIDDEN]); al_clear_to_color(NULL_COLOR); al_draw_line(1, 1, 254, 254, al_map_rgba_f(1,0,0,0.5),4); al_draw_line(1, 254, 254, 1, al_map_rgba_f(1,0,0,0.5),4); al_set_target_bitmap(symbol_bmp[SYM_SWAPPABLE]); al_clear_to_color(NULL_COLOR); al_draw_line(256*0.7,256*0.9, 256*(3-0.7),256*0.9, al_map_rgba_f(1,0,0,0.5), 2); al_draw_filled_triangle(256*0.5,256*0.9, 256*0.7,256, 256*0.7, 256*0.8, al_map_rgba_f(1,0,0,0.35)); al_set_target_bitmap(symbol_bmp[SYM_ONE_SIDE]); al_clear_to_color(NULL_COLOR); al_draw_filled_circle(256/2, 256/2, 0.03*256, WHITE_COLOR); al_draw_filled_circle(256/2 - 0.2*256, 256/2, 0.03*256, WHITE_COLOR); al_draw_filled_circle(256/2 + 0.2*256, 256/2, 0.03*256, WHITE_COLOR); al_set_target_bitmap(symbol_bmp[SYM_ONLY_ONE]); al_clear_to_color(NULL_COLOR); al_draw_filled_triangle(256*0.3, 256, 256*0.7, 256, 256*0.5, 256*0.7, al_map_rgba_f(1,0,0,0.5)); al_draw_filled_triangle(256*0.3, 256, 256*0.7, 256, 256*0.5, 256*1.3, al_map_rgba_f(1,0,0,0.5)); al_draw_line(256*0.5, 256*0.8, 256*0.5, 256*1.2, WHITE_COLOR, 3); al_set_target_bitmap(dispbuf); return 0; }
/* * keyboard driver is called first, so initialize allegro here */ int init_allegro(void){ if(!al_init()) { #if _ANDROID_ __android_log_print(ANDROID_LOG_INFO,"AllegroActivity","Error!, Allegro has failed to initialize."); #else fprintf(stderr,"Error!, Allegro has failed to initialize.\n"); #endif return -1; } else { //fprintf(stderr,"al_init successful\n"); } #if _ANDROID_ //al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); al_set_new_display_flags(ALLEGRO_WINDOWED); //al_set_new_display_option(ALLEGRO_COLOR_SIZE,32,ALLEGRO_SUGGEST); //al_set_new_display_option(ALLEGRO_CAN_DRAW_INTO_BITMAP,1,ALLEGRO_REQUIRE); #endif //al_set_new_display_option(ALLEGRO_COLOR_SIZE,32,ALLEGRO_SUGGEST); display = al_create_display(SCREEN_WIDTH, SCREEN_HEIGHT); //display = al_create_display(800, 600); if(display == NULL) { #if _ANDROID_ __android_log_print(ANDROID_LOG_INFO,"AllegroActivity","Error!, Failed to create the display."); #else fprintf(stderr,"Error!, Failed to create the display."); #endif return -1; } al_set_system_mouse_cursor(display,ALLEGRO_SYSTEM_MOUSE_CURSOR_DEFAULT); if(!al_install_keyboard()) { fprintf(stderr,"Error!, Failed to install keyboard.\n"); return -1; } else { //fprintf(stderr,"al_install_keyboard successful\n"); } if(!al_install_mouse()) { fprintf(stderr,"Error!, Failed to install mouse."); return -1; } a_event_queue_k = al_create_event_queue(); if(a_event_queue_k == NULL) { fprintf(stderr,"Error!, Failed to create the keyboard event queue."); return -1; } al_register_event_source(a_event_queue_k, al_get_keyboard_event_source()); a_event_queue_m = al_create_event_queue(); if(a_event_queue_m == NULL) { fprintf(stderr,"Error!, Failed to create the mouse event queue."); return -1; } #if _ANDROID_ //do below at touch input #else al_register_event_source(a_event_queue_m, al_get_mouse_event_source()); #endif a_event_queue_d = al_create_event_queue(); if(a_event_queue_d == NULL) { fprintf(stderr,"Error!, Failed to create the display event queue."); return -1; } al_register_event_source(a_event_queue_d, al_get_display_event_source(display)); #if _ANDROID_ if(!al_install_touch_input()) { __android_log_print(ANDROID_LOG_INFO,"AllegroActivity","Error!, Failed to install touch_input."); } else { __android_log_print(ANDROID_LOG_INFO,"AllegroActivity","Installed touch_input successfully."); al_set_mouse_emulation_mode(ALLEGRO_MOUSE_EMULATION_5_0_x); al_register_event_source(a_event_queue_m, al_get_touch_input_mouse_emulation_event_source()); } #endif #if _ANDROID_ //allow to use al_open to read (only) files from the apk store, e.g. fonts al_android_set_apk_file_interface(); #endif return 1; //ok }