void load_pause_open(void) { // use map background if it exists if (load_pause_map_name!=NULL) { if (file_paths_data_exist(&file_path_setup,"Bitmaps/Backgrounds_Map",load_pause_map_name,"png")) { gui_initialize("Bitmaps/Backgrounds_Map",load_pause_map_name); return; } } // otherwise generic load background gui_initialize("Bitmaps/Backgrounds","load"); }
void title_open(void) { int buffer_idx; // titles gui_initialize(title_dir,title_name); // sound if (title_sound_name[0]!=0x0) { buffer_idx=al_find_buffer(title_sound_name); al_play_source(buffer_idx,NULL,1.0f,FALSE,FALSE,TRUE,FALSE); } // fades title_fade_tick=-1; title_fade_mode=title_fade_mode_in; // force server state, there are a couple // places where this isn't being switch in, // like an app intro server.state=gs_title; }
void setup_game_open(void) { // setup gui gui_initialize("Bitmaps/Backgrounds","main"); // remember if we came here // from within the game setup_in_game=(server.last_state==gs_running); // waiting for an action flag setup_action_set_flag=FALSE; // save/restore flag setup_close_save_flag=FALSE; // start with first tab setup_tab_value=0; setup_game_create_pane(); // save setup memmove(&setup_backup,&setup,sizeof(setup_type)); }
void score_limit_open(void) { gui_initialize(NULL,NULL,TRUE); score_limit_start_tick=time_get(); server.state=gs_score_limit; }
int main(int argc, char **argv) { gui_initialize(&argc, &argv); nu_cities = 100; srandom(0); initialize_cities(); gui_create_window_layout(); gui_draw_window(); gui_run(); }
int main(int argc, char *argv[]) { DATAFILE *datf; BITMAP *scrFlip; BITMAP *scrMap; PALETTE pal; WINDOW *winInfo; long frames = 0L; float start_time, end_time; MAP *map, *overlay; int x = 0, y = 0; int old_x = -1, old_y = -1; int dx = 1, dy = 1; int view_w, view_h; int do_idle = 1; char s[128]; // Default screen resolution to 320x200. screen_width = 320; screen_height = 200; // Read command line args. Set screen size accordingly. if (argc > 2) { screen_width = atoi(argv[1]); screen_height = atoi(argv[2]); } right_size = 0; bottom_size = 0; printf("screen: %dX%d\n", screen_width, screen_height); // Initialize Allegro. Great library! allegro_init(); install_timer(); install_keyboard(); // Set graphics mode. if (set_gfx_mode(GFX_AUTODETECT, screen_width, screen_height, 0, 0) == -1) { printf("Cannot set video mode to %d, %d.\n", screen_width, screen_height); return 1; } // load comic font from ex4. datf = load_datafile_object("ex.dat", "comic12"); if (datf == NULL) { allegro_exit(); printf("Error loading ex.dat\n"); return 1; } text_mode(-1); // load map //printf("loading map\n"); map = load_map("tile1.wmp", "tile1.spr", pal); if (map == NULL) { allegro_exit(); printf("Error loading map file.\n"); return 1; } // load overlay //printf("loading overlay\n"); overlay = load_map("tile1ovr.wmp", NULL, NULL); if (overlay == NULL) { allegro_exit(); printf("Error loading overlay file.\n"); return 1; } map_settileset(overlay, map->tileset); // Allocate buffers for our rendering. //printf("allocating buffers\n"); scrFlip = create_bitmap(SCREEN_W, SCREEN_H); clear(scrFlip); scrMap = create_bitmap(SCREEN_W + map->t_width*2, SCREEN_H + map->t_height*2); // set palette //printf("setting palette\n"); gui_setpalette(pal); // Build rgb_table. text_mode(makecol8(0, 0, 0)); textout_centre(screen, font, "Building RGB table.", SCREEN_W>>1, 10, 100); create_rgb_table(&rgb_table, pal, rgb_table_callback); rgb_map = &rgb_table; // Build lighting table. text_mode(makecol8(0, 0, 0)); textout_centre(screen, font, "Building lighting table.", SCREEN_W>>1, 10, 100); create_light_table(&light_table, pal, 64, 64, 64, rgb_table_callback); // Build translucency table. text_mode(makecol8(0, 0, 0)); textout_centre(screen, font, "Building translucency table.", SCREEN_W>>1, 10, 100); create_trans_table(&trans_table, pal, 128, 128, 128, rgb_table_callback); color_map = &trans_table; // initialize gui gui_initialize(&light_table, &trans_table); // set map and overlay color tables map_settables(map, &trans_table, &light_table); map_settables(overlay, &trans_table, &light_table); // create info window winInfo = gui_create_window(128, 200, WB_THICK, WD_TRANSLUCENT); gui_move_window(winInfo, SCREEN_W-winInfo->window.w, 0); // set up vars. view_w = scrMap->w/map->t_width; view_h = scrMap->h/map->t_height; // setup time_to_blit interrupt. LOCK_VARIABLE(time_to_blit); LOCK_FUNCTION(time_to_blit_timer); install_int_ex(time_to_blit_timer, BPS_TO_TIMER(30)); missed_frames = 0; // main loop. start_time = clock(); while (1) { idle_time = 0; if (do_idle) while (!time_to_blit) idle_proc(); // lock it in at around 30 fps. time_to_blit = 0; if (idle_time < lowest_idle) lowest_idle = idle_time; if (idle_time > highest_idle) highest_idle = idle_time; // render map if (map_getx_tile(map, x) != old_x || map_gety_tile(map, y) != old_y) { render_map(map, scrMap, 0, 0, x, y, view_w, view_h); render_map(overlay, scrMap, 0, 0, x, y, view_w, view_h); old_x = map_getx_tile(map, x); old_y = map_gety_tile(map, y); } blit(scrMap, scrFlip, map_getx_offset(map, x), map_gety_offset(map, y), 0, 0, SCREEN_W-right_size, SCREEN_H-bottom_size); gui_clear_window(winInfo, makecol8(0, 0, 0)); gui_textout_centre_window(winInfo, "Map Demo", 2, makecol8(255, 0, 0), -1); sprintf(s, "X: %d, Y: %d", x, y); gui_textout_centre_window(winInfo, s, 14, makecol8(0, 0, 255), -1); sprintf(s, "DX: %d, DY: %d", dx, dy); gui_textout_centre_window(winInfo, s, 24, makecol8(0, 0, 255), -1); sprintf(s, "X Ofs: %d", map_getx_offset(map, x)); gui_textout_centre_window(winInfo, s, 34, makecol8(0, 0, 255), -1); sprintf(s, "Y Ofs: %d", map_gety_offset(map, y)); gui_textout_centre_window(winInfo, s, 44, makecol8(0, 0, 255), -1); sprintf(s, "Idle: %d", idle_time); gui_textout_centre_window(winInfo, s, 64, makecol8(0, 255, 255), -1); sprintf(s, "Missed: %d", missed_frames); gui_textout_centre_window(winInfo, s, 74, makecol8(0, 255, 255), -1); gui_draw_window(winInfo, scrFlip); // blit it //vsync(); blit(scrFlip, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); // check keys if (key[KEY_SPACE]) { break; } if (key[KEY_LSHIFT]) do_idle = 0; else do_idle = 1; if (key[KEY_CONTROL]) gui_set_window_styles(winInfo, -1, WD_BLIT); else gui_set_window_styles(winInfo, -1, WD_TRANSLUCENT); if (key[KEY_PGDN]) { dx--; if (dx < 1) dx = 1; dy--; if (dy < 1) dy = 1; } if (key[KEY_PGUP]) { dx++; dy++; } if (key[KEY_RIGHT]) { x+=dx; if (x > (map->w_width-1) - SCREEN_W) { x-=dx; } } if (key[KEY_DOWN]) { y+=dy; if (y > (map->w_height-1) - SCREEN_H) { y-=dy; } } if (key[KEY_LEFT]) { x-=dx; if (x < 0) { x = 0; } } if (key[KEY_UP]) { y-=dy; if (y < 0) { y = 0; } } // Increment frame counter. frames++; } end_time = clock(); // Clean up. unload_datafile_object(datf); destroy_map(map); overlay->tileset=NULL; destroy_map(overlay); destroy_bitmap(scrFlip); destroy_bitmap(scrMap); // Close down allegro. allegro_exit(); // Report. printf("Tile Map, Copyright 1997 by Scott Deming.\n"); printf("\nHow'd we do?\n"); printf("===============================================================================\n"); printf(" Time: %3.2f\n", (float) ((end_time-start_time) / 100)); printf("Frames: %lu\n", frames); printf(" FPS: %3.2f\n", (float) (float) frames / (float) ((end_time-start_time) / 100)); printf("Missed: %d\n", missed_frames); printf(" Idle: %d (lowest was %d, highest %d)\n", idle_time, lowest_idle, highest_idle); printf("Screen: %dX%d\n", screen_width, screen_height); printf("-------------------------------------------------------------------------------\n"); printf("Note: If \"Idle\" starts to get close to zero then things should be done to\n"); printf(" speed things up. When idle proc hits zero, we'll start missing frames\n"); printf(" (indicated by \"Missed\") and things can start to get a bit jerky.\n"); printf(" If \"Missed\" is greater than 0, start optimizing.\n"); printf(" If you turned off the 30 fps timer halt then your lowest idle will be 0.\n"); return 0; }
void file_open(void) { int x,y,fx,fy,ty,wid,high,mx,tx,half_wid,pic_high, table_high,margin,padding; element_frame_button_type butts_save[3]={{file_button_delete_id,"Delete",FALSE},{file_button_cancel_id,"Cancel",TRUE},{file_button_save_id,"New Save",TRUE}}, butts_load[3]={{file_button_delete_id,"Delete",FALSE},{file_button_cancel_id,"Cancel",TRUE},{file_button_load_id,"Load",TRUE}}; element_column_type cols[4]; file_last_state=server.last_state; // setup gui gui_initialize("Bitmaps/Backgrounds","main"); // the frame margin=element_get_margin(); padding=element_get_padding(); fx=margin; fy=margin; wid=iface.scale_x-(margin*2); high=iface.scale_y-(margin*2); if (file_is_save) { element_frame_add("Save Game",file_frame_id,fx,fy,wid,high,-1,0,NULL,3,butts_save); } else { element_frame_add("Load Game",file_frame_id,fx,fy,wid,high,-1,0,NULL,3,butts_load); } element_get_frame_inner_space(file_frame_id,&x,&y,&wid,&table_high); half_wid=(wid>>1)-padding; mx=((x+wid)-half_wid)-padding; // make the file list file_build_list(); // info pic_high=(half_wid*3)/4; ty=y+((table_high-(pic_high+margin+iface.font.text_size_medium+(element_get_control_high()*2)))>>1); element_bitmap_add(NULL,file_info_bitmap_id,x,ty,half_wid,pic_high,TRUE); tx=x+(half_wid>>2); ty+=(pic_high+margin+iface.font.text_size_medium); element_text_add("Map:",-1,tx,ty,iface.font.text_size_medium,tx_right,&iface.color.control.text,FALSE); element_text_add("",file_info_name_id,(tx+10),ty,iface.font.text_size_medium,tx_left,&iface.color.control.text,FALSE); ty+=element_get_control_high(); element_text_add("Time:",-1,tx,ty,iface.font.text_size_medium,tx_right,&iface.color.control.text,FALSE); element_text_add("",file_info_time_id,(tx+10),ty,iface.font.text_size_medium,tx_left,&iface.color.control.text,FALSE); ty+=element_get_control_high(); element_text_add("Elapsed:",-1,tx,ty,iface.font.text_size_medium,tx_right,&iface.color.control.text,FALSE); element_text_add("",file_info_elapsed_id,(tx+10),ty,iface.font.text_size_medium,tx_left,&iface.color.control.text,FALSE); // files strcpy(cols[0].name,"Saved Games"); cols[0].percent_size=1.0f; element_table_add(cols,file_table_data,file_info_table_id,1,(mx+padding),y,half_wid,table_high,FALSE,element_table_bitmap_none); // if a first item, select it if (file_has_list) element_set_value(file_info_table_id,0); // enable buttons file_save_selected(); }
int main(int argc, char **argv) { gui_initialize(&argc, &argv); gui_create_window_layout(); gui_draw_window(); if (argc == 2 && strcmp(argv[1], "--help") == 0) { printf("texview -- a texture and image file viewer.\n" "Usage: texview <filename1> <filename2>\n" "<filename2> is optional.\n"); exit(1); } option_quiet = 1; current_nu_image_sets = 0; if (argc >= 2) { source_filename[0] = argv[1]; source_filetype[0] = determine_filename_type(source_filename[0]); if (!(source_filetype[0] & FILE_TYPE_TEXTURE_BIT) && !(source_filetype[0] & FILE_TYPE_IMAGE_BIT)) { printf("Error -- expected image or texture filename as argument.\n"); exit(1); } if (!file_exists(source_filename[0])) { printf("Error -- source file %s doesn't exist or is unreadable.\n", source_filename[0]); exit(1); } current_nu_image_sets = 1; } if (argc >= 3) { source_filename[1] = argv[2]; source_filetype[1] = determine_filename_type(source_filename[1]); if (!(source_filetype[1] & FILE_TYPE_TEXTURE_BIT) && !(source_filetype[1] & FILE_TYPE_IMAGE_BIT)) { printf("Error -- expected image or texture filename as second argument.\n"); exit(1); } if (!file_exists(source_filename[1])) { printf("Error -- source file %s doesn't exist or is unreadable.\n", source_filename[1]); exit(1); } current_nu_image_sets = 2; } for (int j = 0; j < current_nu_image_sets; j++) { current_file_type[j] = source_filetype[j]; if (source_filetype[j] & FILE_TYPE_TEXTURE_BIT) { current_nu_mipmaps[j] = load_texture(source_filename[j], source_filetype[j], 32, ¤t_texture[j][0]); for (int i = 0 ; i < current_nu_mipmaps[j]; i++) convert_texture_to_image(¤t_texture[j][i], ¤t_image[j][i]); } else { load_image(source_filename[j], source_filetype[j], ¤t_image[j][0]); current_nu_mipmaps[j] = 1; } if (current_nu_mipmaps[j] > 1) printf("Found %d mipmap levels.\n", current_nu_mipmaps[j]); } current_rmse[0] = -1.0; if (current_nu_image_sets > 1) current_rmse[0] = compare_images(¤t_image[0][0], ¤t_image[1][0]); for (int i = 0; i < current_nu_image_sets; i++) { if (!current_image[i][0].is_half_float && current_image[i][0].bits_per_component == 8 && current_image[i][0].nu_components > 2) convert_image_set(i); } gui_zoom_fit_to_window(); for (int i = 0; i < current_nu_image_sets; i++) gui_create_base_surface(i); gui_draw_and_show_window(); gui_run(); }