void EMSCRIPTEN_KEEPALIVE main_2(void *arg) { #if 0 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); darea = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE); printf("Init: %d\n", TTF_Init()); #endif time_t now; struct tm *tm; SDL_Thread*gth = NULL; /* thread id */ gboolean run_flag = TRUE; /* used as exit flag for threads */ gint i; printf("main2\n"); init_trees(); init_fonts(); font = get_font(12, 0); font_bold = get_font(12, 1); now = time(NULL); tm = localtime(&now); current_year = tm->tm_year+1900; srand(now); //srandom(now); my_address = now + getpid()*10000; emscripten_async_wget("/menuicon.png", "menuicon.png", menuicononload, menupiconerror); emscripten_async_wget("/menupicinfo.png", "menupicinfo.png", menupiconload, menupiconerror); emscripten_set_main_loop(main_loop, 10, 0); }
int create_and_open_screen(int sizex, int sizey, int bpp, int mode) { static bool first = true; static bool dofree = false; #ifndef WIN32 set_sdl_env(); #endif if (dofree == true) { dofree = false; SDL_FreeSurface(gfx->buff); } if (first == true) { if (!(gfx = (t_gfx*)malloc(sizeof(*gfx)))) { printf("Out of memory.\n"); exit(42); } gfx->videoinfo = (SDL_VideoInfo *)SDL_GetVideoInfo(); first = false; } gfx->win = (t_display*)xmalloc(sizeof(*(gfx->win))); #ifdef GRAPHICS_DEBUG fprintf(fd_log, "Checking mode %dx%d@%dbpp.\n", sizex, sizey, bpp); #endif gfx->bpp = SDL_VideoModeOK(sizex, sizey, bpp, mode); if(!gfx->bpp) { #ifdef GRAPHICS_DEBUG fprintf(fd_log, "Mode not available, trying another..\n"); #endif gfx->bpp = SDL_VideoModeOK(sizex, sizey, bpp, SDL_ANYFORMAT); if (!gfx->bpp) return (-1); if (!(gfx->main = SDL_SetVideoMode(sizex, sizey, bpp, mode | SDL_GLSDL))) return (-1); } else if (!(gfx->main = SDL_SetVideoMode(sizex, sizey, bpp, mode | SDL_GLSDL))) return (-1); gfx->win->sdlMainScreen = gfx->main; gfx->win->text = NULL; SDL_WM_SetCaption("Freewar", "fw.ico"); gfx->buff = xSDL_DisplayFormatAlpha(gfx->main); init_gfx(); if (init_fonts()) return (-1); dofree = true; return (0); }
/** * Initializes the graphics sub-system, making it ready to draw. * Also determines the number of pixels on the screen and uses * that to set the SCALE global variable. */ void Gi::InitializeGraphics() { XSetWindowAttributes xswa; XGCValues gcv; if (dpy == NULL) { /* Open access to local display */ if ((dpy = XOpenDisplay (NULL)) == NULL) { printf ("XOpenDisplay returned NULL\n"); exit (1); } // Get some colors create_colors(); /* Get size of root window. (Will be used to limit size of RARS window) */ { Window w; int x,y; unsigned b,d; XGetGeometry(dpy,DefaultRootWindow(dpy),&w,&x,&y,&maxx,&maxy,&b,&d); } /* Make RARS window smaller than root window (need space for borders etc.) */ maxx-=64; maxy-=48; // Don't make the RARS window larger than 960x720. We don't know the size of // the area visible on the monitor. It might be smaller than the root window. if (maxx>960) maxx=960; if (maxy>700) maxy=700; /* Aspect ratio of RARS window should be 4/3 */ if (maxx>maxy*4/3) maxx=maxy*4/3; if (maxy>maxx*3/4) maxy=maxx*3/4; // uncomment this if you prefer to hardcode the size of the RARS window: // maxx=960; // maxy=720; fprintf( stderr, "XWindow size: maxx %d, maxy %d\n", maxx, maxy ); /* These three used in XCreateWindow */ /* Set the events you want */ xswa.event_mask = VisibilityChangeMask|ExposureMask|KeyPressMask|ButtonPressMask; /* Set the background colors */ xswa.background_pixel = tran_table[FIELD_COLOR]; /* Set to store when overlapped? */ xswa.backing_store = Always; /* Make window */ win = XCreateWindow (dpy, DefaultRootWindow (dpy), 0, 10, maxx, maxy, 2, 0, InputOutput, CopyFromParent, CWEventMask | CWBackPixel | CWBackingStore, & xswa); /* Set name of window */ XStoreName (dpy, win, "RARS"); /* Make a graphics context */ gcv.function = GXcopy; gcv.plane_mask = AllPlanes; /* Set foreground color */ gcv.foreground = BlackPixel(dpy,DefaultScreen(dpy)); /* Set background color */ gcv.background = WhitePixel(dpy,DefaultScreen(dpy)); /* Set width of lines */ gcv.line_width = 0; /* The edge of the track needs CapButt, but it's faster with CapNotLast. */ gcv.cap_style = CapButt; /* Set fill and line style to solid */ gcv.fill_style = FillSolid; gcv.line_style = LineSolid; /* Create the GC for solid lines */ gc = XCreateGC (dpy, win, GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth | GCFillStyle | GCLineStyle | GCCapStyle, & gcv); fill_gc = XCreateGC (dpy, win, GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth | GCFillStyle | GCLineStyle | GCCapStyle, & gcv); /* Ready the window for drawing */ XMapWindow (dpy, win); /* Tell X to display the window */ XFlush(dpy); init_fonts(); maxx = get_width(); maxy = get_height(); /* * Create pixmap. * The pixmap is created after the display of the windows due that some * window manager decides to change the size of the window */ pixmap = XCreatePixmap(dpy, win, maxx, maxy, DefaultDepth(dpy, XDefaultScreen(dpy))); drawable = pixmap; } // End of system dependent code. // The rest of this function is portable: // determine the distance in feet that each pixel will represent: SCALE = currentTrack->m_fXMax / (double)maxx; // Either m_fXMax or m_fYMax will if(currentTrack->m_fYMax / (double)maxy > SCALE) // determine the SCALE; The { SCALE = currentTrack->m_fYMax / (double)maxy; // SCALE will be the smallest that currentTrack->m_fXMax = maxx * SCALE; // will show both m_fXMax & m_fYMax. } else { currentTrack->m_fYMax = maxy * SCALE; } CHR_HGT = CHR_HGT_PIX * SCALE; // compute character height in feet CHR_WID = CHR_WID_PIX * SCALE; // compute character width in feet }
void sourceview_prefs_init(Sourceview* sv) { GtkSourceDrawSpacesFlags flags = 0; /* We create a new GSettings object here because if we used the one from * the editor might be destroyed while the plugin is still alive */ sv->priv->settings = g_settings_new (PREF_SCHEMA); sv->priv->docman_settings = g_settings_new (DOCMAN_PREF_SCHEMA); sv->priv->msgman_settings = g_settings_new (MSGMAN_PREF_SCHEMA); /* Bind simple options to GSettings */ g_settings_bind (sv->priv->settings, HIGHLIGHT_SYNTAX, sv->priv->document, "highlight-syntax", G_SETTINGS_BIND_GET); g_settings_bind (sv->priv->settings, HIGHLIGHT_CURRENT_LINE, sv->priv->view, "highlight-current-line", G_SETTINGS_BIND_GET); g_settings_bind (sv->priv->settings, TAB_SIZE, sv->priv->view, "tab-width", G_SETTINGS_BIND_GET); g_settings_bind (sv->priv->settings, HIGHLIGHT_BRACKETS, sv->priv->document, "highlight-matching-brackets", G_SETTINGS_BIND_GET); g_settings_bind (sv->priv->settings, VIEW_MARKS, sv->priv->view, "show-line-marks", G_SETTINGS_BIND_GET); g_settings_bind (sv->priv->settings, RIGHTMARGIN_POSITION, sv->priv->view, "right-margin-position", G_SETTINGS_BIND_GET); g_settings_bind (sv->priv->settings, VIEW_RIGHTMARGIN, sv->priv->view, "show-right-margin", G_SETTINGS_BIND_GET); g_settings_bind (sv->priv->settings, VIEW_LINENUMBERS, sv->priv->view, "show-line-numbers", G_SETTINGS_BIND_GET); /* Init non-simple options */ gtk_source_view_set_indent_width(GTK_SOURCE_VIEW(sv->priv->view), -1); /* Same as tab width */ gtk_source_view_set_insert_spaces_instead_of_tabs(GTK_SOURCE_VIEW(sv->priv->view), !g_settings_get_boolean (sv->priv->settings, USE_TABS)); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (sv->priv->view), g_settings_get_boolean (sv->priv->docman_settings, DOCMAN_VIEW_EOL) ? GTK_WRAP_WORD : GTK_WRAP_NONE); if (g_settings_get_boolean (sv->priv->docman_settings, DOCMAN_VIEW_WHITE_SPACES)) flags |= (GTK_SOURCE_DRAW_SPACES_SPACE | GTK_SOURCE_DRAW_SPACES_TAB); if (g_settings_get_boolean (sv->priv->docman_settings, DOCMAN_VIEW_EOL)) flags |= GTK_SOURCE_DRAW_SPACES_NEWLINE; gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (sv->priv->view), flags); init_fonts(sv); on_notify_autocompletion(sv->priv->settings, AUTOCOMPLETION, sv); /* Register notifications */ REGISTER_NOTIFY (sv->priv->settings, USE_TABS, on_notify_use_tab_for_indentation); REGISTER_NOTIFY (sv->priv->settings, AUTOCOMPLETION, on_notify_autocompletion); REGISTER_NOTIFY (sv->priv->docman_settings, DOCMAN_VIEW_WHITE_SPACES, on_notify_view_spaces); REGISTER_NOTIFY (sv->priv->docman_settings, DOCMAN_VIEW_EOL, on_notify_view_eol); REGISTER_NOTIFY (sv->priv->docman_settings, DOCMAN_VIEW_LINE_WRAP, on_notify_line_wrap); REGISTER_NOTIFY (sv->priv->settings, FONT_THEME, on_notify_font_theme); REGISTER_NOTIFY (sv->priv->settings, FONT, on_notify_font); g_signal_connect (sv->priv->msgman_settings, "changed::" MSGMAN_COLOR_ERROR, G_CALLBACK (on_notify_indic_colors), sv); g_signal_connect (sv->priv->msgman_settings, "changed::" MSGMAN_COLOR_WARNING, G_CALLBACK (on_notify_indic_colors), sv); }
void init_stuff() { int i; int seed; chdir(DATA_DIR); #ifndef WINDOWS setlocale(LC_NUMERIC,"en_US"); #endif init_translatables(); //create_error_mutex(); init_globals(); init_crc_tables(); init_zip_archives(); cache_system_init(MAX_CACHE_SYSTEM); init_texture_cache(); init_vars(); read_config(); file_check_datadir(); #ifdef LOAD_XML //Well, the current version of the map editor doesn't support having a datadir - will add that later ;-) load_translatables(); #endif #ifdef LINUX #ifdef GTK2 init_filters(); #else file_selector = create_fileselection(); #endif #endif //LINUX init_gl(); window_resize(); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); // glDepthFunc(GL_LEQUAL); glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); glFrontFace(GL_CCW); glCullFace(GL_BACK); glEnable(GL_NORMALIZE); glClearColor( 0.0, 0.0, 0.0, 0.0 ); glClearStencil(0); seed = time (NULL); srand (seed); init_texture_cache(); init_particles (); init_e3d_cache(); init_2d_obj_cache(); for(i=0; i<256; i++) tile_list[i]=0; for (i = 0; i < MAX_LIGHTS; i++) lights_list[i] = NULL; new_map(256,256); load_all_tiles(); //lights setup build_global_light_table(); build_sun_pos_table(); reset_material(); init_lights(); //disable_local_lights(); //clear_error_log(); // Setup the new eye candy system #ifdef EYE_CANDY ec_init(); #endif //EYE_CANDY init_gl_extensions(); if(have_multitexture) #ifdef NEW_TEXTURES ground_detail_text = load_texture_cached("./textures/ground_detail.bmp", tt_mesh); #else /* NEW_TEXTURES */ ground_detail_text = load_texture_cache ("./textures/ground_detail.bmp",255); #endif /* NEW_TEXTURES */ //load the fonts texture init_fonts(); #ifdef NEW_TEXTURES icons_text=load_texture_cached("./textures/gamebuttons.bmp", tt_gui); buttons_text=load_texture_cached("./textures/buttons.bmp", tt_gui); #else /* NEW_TEXTURES */ icons_text=load_texture_cache("./textures/gamebuttons.bmp",0); buttons_text=load_texture_cache("./textures/buttons.bmp",0); #endif /* NEW_TEXTURES */ //get the application home dir have_multitexture=0;//debug only #ifndef LINUX GetCurrentDirectory(sizeof(exec_path),exec_path); #else exec_path[0]='.';exec_path[1]='/';exec_path[2]=0; #endif init_browser(); if(SDL_InitSubSystem(SDL_INIT_TIMER)<0) { char str[120]; snprintf(str, sizeof(str), "Couldn't initialize the timer: %s\n", SDL_GetError()); log_error(__FILE__, __LINE__, str); SDL_Quit(); exit(1); } SDL_SetTimer (1000/(18*4), my_timer); SDL_EnableUNICODE(1); //we might want to do this later. // creating windows display_browser(); toggle_window(browser_win); display_o3dow(); toggle_window(o3dow_win); display_replace_window(); toggle_window(replace_window_win); display_edit_window(); toggle_window(edit_window_win); create_particles_window (); }
int main( int argc, char **argv ) { /* Print copyright notice */ fprintf( stderr, "Tux Rider World Challenge -- http://www.barlow-server.com\n" "a fork from:\n" "Tux Racer " VERSION " -- a Sunspire Studios Production " "(http://www.sunspirestudios.com)\n" "(c) 1999-2000 Jasmin F. Patry " "<*****@*****.**>\n" "\"Tux Racer\" is a trademark of Jasmin F. Patry\n" "Tux Rider World Challenge comes with ABSOLUTELY NO WARRANTY. " "This is free software,\nand you are welcome to redistribute " "it under certain conditions.\n" "See http://www.gnu.org/copyleft/gpl.html for details.\n\n" ); /* Init the game clock */ g_game.secs_since_start = 0; /* Seed the random number generator */ srand( time(NULL) ); /* * Set up the game configuration */ /* Don't support multiplayer, yet... */ g_game.num_players = 2; /* Create a Tcl interpreter */ g_game.tcl_interp = Tcl_CreateInterp(); if ( g_game.tcl_interp == NULL ) { handle_error( 1, "cannot create Tcl interpreter" ); } /* Setup the configuration variables and read the ~/.tuxracer/options file */ init_game_configuration(); read_config_file(); /* Set up the debugging modes */ init_debug(); /* Setup diagnostic log if requested */ if ( getparam_write_diagnostic_log() ) { setup_diagnostic_log(); } /* * Setup Tcl stdout and stderr channels to point to C stdout and stderr * streams */ setup_tcl_std_channels(); /* * Initialize rendering context, create window */ winsys_init( &argc, argv, WINDOW_TITLE, WINDOW_TITLE ); /* Ingore key-repeat messages */ winsys_enable_key_repeat(0); /* Set up a function to clean up when program exits */ winsys_atexit( cleanup ); /* * Initial OpenGL settings */ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); init_opengl_extensions(); /* Print OpenGL debugging information if requested */ if ( debug_mode_is_active( DEBUG_GL_INFO ) ) { print_debug( DEBUG_GL_INFO, "OpenGL information:" ); print_gl_info(); } /* * Load the game data and initialize game state */ register_game_config_callbacks( g_game.tcl_interp ); register_course_load_tcl_callbacks( g_game.tcl_interp ); register_key_frame_callbacks( g_game.tcl_interp ); register_fog_callbacks( g_game.tcl_interp ); register_course_light_callbacks( g_game.tcl_interp ); register_particle_callbacks( g_game.tcl_interp ); register_texture_callbacks( g_game.tcl_interp ); register_font_callbacks( g_game.tcl_interp ); register_sound_tcl_callbacks( g_game.tcl_interp ); register_sound_data_tcl_callbacks( g_game.tcl_interp ); register_course_manager_callbacks( g_game.tcl_interp ); init_saved_games(); load_tux(); init_textures(); init_fonts(); init_audio_data(); init_audio(); init_ui_manager(); init_course_manager(); init_joystick(); /* Read the tuxracer_init.tcl file */ read_game_init_script(); /* Need to set up an initial view position for select_course (quadtree simplification) */ //Player 0 = classic mode player ; Player 1 = Speed Only Mode Player g_game.player[0].view.pos = make_point( 0., 0., 0. ); g_game.player[1].view.pos = make_point( 0., 0., 0. ); /* Placeholder name until we give players way to enter name */ g_game.player[0].name = "noname"; g_game.player[1].name = "nonameSpeedOnly"; init_preview(); splash_screen_register(); intro_register(); racing_register(); game_over_register(); paused_register(); reset_register(); game_type_select_register(); racing_mode_select_register(); event_select_register(); race_select_register(); credits_register(); loading_register(); g_game.mode = NO_MODE; set_game_mode( SPLASH ); g_game.difficulty = DIFFICULTY_LEVEL_NORMAL; init_keyboard(); winsys_show_cursor( False ); /* We use this to "prime" the GLUT loop */ winsys_set_idle_func( main_loop ); /* * ...and off we go! */ winsys_process_events(); return 0; }
int load_font_textures () { #ifndef NEW_TEXTURES int poor_man_save=poor_man; int use_mipmaps_save=use_mipmaps; #endif /* NEW_TEXTURES */ size_t i = 0; char *glob_pattern; #ifdef WINDOWS struct _finddata_t c_file; long hFile; #else //WINDOWS int ret; glob_t glob_res; size_t j; #endif //WINDOWS char file[60] = ""; char str[60] = ""; if (fonts[0] == NULL || fonts[1] == NULL || fonts[2] == NULL || fonts[3]==NULL ) { for (i = 0; i < FONTS_ARRAY_SIZE; i++) { if (fonts[i] != NULL) free (fonts[i]); fonts[i] = NULL; } if ( !init_fonts () ) return 0; } #ifndef NEW_TEXTURES poor_man=0; use_mipmaps=0; #endif /* NEW_TEXTURES */ #ifdef NEW_TEXTURES fonts[0]->texture_id = load_texture_cached("textures/font.dds", tt_font); #else /* NEW_TEXTURES */ fonts[0]->texture_id = load_texture_cache("./textures/font.bmp", 0); #endif /* NEW_TEXTURES */ i = 1; // Force the selection of the base font. add_multi_option("chat_font", "Type 1"); add_multi_option("name_font", "Type 1"); // Find what font's exist and load them glob_pattern = malloc(strlen(datadir)+sizeof(texture_dir)+10+1); //+10 = font*.bmp* #ifdef NEW_TEXTURES sprintf(glob_pattern, "%s%sfont*.dds", datadir, texture_dir); #else /* NEW_TEXTURES */ sprintf(glob_pattern, "%s%sfont*.bmp*", datadir, texture_dir); #endif /* NEW_TEXTURES */ #ifdef WINDOWS if( (hFile = _findfirst( glob_pattern, &c_file )) == -1L ){ free(glob_pattern); return 0; } do { int len; safe_strncpy(file, c_file.name, sizeof(file)); #else //!WINDOWS ret = glob(glob_pattern, 0, NULL, &glob_res); if(ret != 0) { LOG_ERROR("Unable to find any font textures\n"); free(glob_pattern); return 0; } j = 0; while (j < glob_res.gl_pathc && i < FONTS_ARRAY_SIZE) { int len; safe_strncpy(file, glob_res.gl_pathv[j]+sizeof(texture_dir)-1+strlen(datadir), sizeof(file)); #endif //WINDOWS len= strlen(file); #ifdef NEW_TEXTURES if (((len + sizeof(texture_dir) - 1) < sizeof(str)) && !strncasecmp(file, "font", 4) && has_suffix(file, len, ".dds", 4)) { safe_snprintf(str, sizeof(str), "./textures/%s", file); //Use a relative path here, load_texture_cache_deferred() is using the path wrappers. file[len - 4] = 0; fonts[i]->texture_id = load_texture_cached(str, tt_font); #else /* NEW_TEXTURES */ if (len+sizeof(texture_dir)-1 < sizeof(str) && !strncasecmp(file, "font", 4) && (has_suffix(file, len, ".bmp", 4) || has_suffix(file, len, ".bmp.gz", 7)) && (!has_suffix(file, len, "_alpha.bmp", 10)) && (!has_suffix(file, len, "_alpha.bmp.gz", 13))) { // Get the filename, remove the .bmp and add _alpha.bmp to a copy, then replace the .bmp safe_snprintf(str, sizeof(str), "./textures/%s", file); //Use a relative path here, load_texture_cache_deferred() is using the path wrappers. if(has_suffix(file, len, ".bmp.gz", 7)){ file[len - 7]= 0; } else { file[len - 4]= 0; } fonts[i]->texture_id = load_texture_cache_deferred(str, 0); #endif /* NEW_TEXTURES */ safe_snprintf(font_names[i], sizeof(font_names[i]), "Type %i - %s", i + 1, file); add_multi_option("chat_font", font_names[i]); add_multi_option("name_font", font_names[i]); i++; } #ifndef WINDOWS j++; #endif //WINDOWS } #ifdef WINDOWS while ( _findnext( hFile, &c_file ) == 0 ); _findclose( hFile ); #else //!WINDOWS globfree(&glob_res); #endif //WINDOWS free(glob_pattern); #ifndef NEW_TEXTURES poor_man=poor_man_save; use_mipmaps=use_mipmaps_save; #endif /* NEW_TEXTURES */ //set the default font cur_font_num = 0; font_text = fonts[0]->texture_id; return 1; } int set_font_parameters (int num) { int i; // error checking if(num < 0 || num >= FONTS_ARRAY_SIZE) { return -1; } // allocate space if needed if(fonts[num] == NULL) { fonts[num]=(font_info *)calloc(1, sizeof(font_info)); if(fonts[num] == NULL) { LOG_ERROR(cant_load_font); return -1; } } //watch the highest font if(num >= max_fonts) { max_fonts=num+1; } // set default font info my_strcp (fonts[num]->name, "default"); fonts[num]->spacing=0; // load font information // TODO: write this and remove the hack! if(num!=1||num!=2)for(i=0; i<FONTS_ARRAY_SIZE*FONT_CHARS_PER_LINE; i++) fonts[num]->widths[i]=12; if(num==1){ static int widths[]={ 4,2,7,11,8,12,12,2,7,7,9,10,3,8, 2,10,10,10,8,8,10,7,9,9,9,9,3,3, 10,10,10,9,12,12,9,10,10,9,9,10,9,8, 7,11,8,11,10,11,9,11,11,9,10,9,12,12, 12,12,10,6,10,6,10,12,3,11,9,9,9,9, 8,9,9,4,6,10,4,11,9,10,9,9,8,8, 8,9,10,12,10,10,9,8,2,8,10,8,12,12, 12,12,12,12,12,12,12,12,12,12,12,12,12,12, 12,12,12,12,12,12,12,12,12,12,12,12,12,12, 12,12,12,12,12,12,12,12,12,12,12,12,12,12, }; memcpy(fonts[num]->widths, widths, sizeof(widths)); fonts[num]->spacing=4; } if(num==2){ static int widths[]={ 8, 8, 8, 10, 8, 10, 10, 8, 8, 8, 8, 10, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 8, 12, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8, 8, 8, 10, 8, 8, 8, 8, 8, 8, 10, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 8, 8, 8, 10, 8, 10, 10, 8, 10, 8, 8, 8, 10, 10, 10, 8, 10, 10, 8, 8, 8, 12, 12, 12, 10, 10, 12, 10, 12, 12, 12, }; memcpy(fonts[num]->widths, widths, sizeof(widths)); fonts[num]->spacing=2; } //and return return num; } int set_font(int num) { if(num >= 0 && num < max_fonts && fonts[num] && fonts[num]->texture_id >= 0) { cur_font_num=num; font_text=fonts[cur_font_num]->texture_id; } return cur_font_num; }
void init_stuff() { int seed; Uint32 (*my_timer_pointer) (unsigned int) = my_timer; //TODO: process command line options chdir(datadir); //Initialize all strings init_translatables(); #ifdef WRITE_XML load_translatables();//Write to the current working directory - hopefully we'll have write rights here... #endif //read the config file read_config(); //Parse command line options read_command_line(); //OK, we have the video mode settings... setup_video_mode(full_screen,video_mode); //now you may set the video mode using the %<foo> in-game video_mode_set=1; //Good, we should be in the right working directory - load all translatables from their files load_translatables(); init_video(); resize_window(); init_gl_extensions(); #ifdef CAL3D create_cal3d_model(); init_cal3d_model(); #endif seed = time (NULL); srand (seed); cache_system_init(MAX_CACHE_SYSTEM); init_texture_cache(); init_md2_cache(); init_e3d_cache(); init_2d_obj_cache(); load_ignores(); load_filters(); load_e3d_list(); load_e2d_list(); load_part_list(); load_knowledge_list(); load_cursors(); build_cursors(); change_cursor(CURSOR_ARROW); build_glow_color_table(); init_actors_lists(); memset(tile_list, 0, sizeof(tile_list)); memset(lights_list, 0, sizeof(lights_list)); init_particles_list(); memset(actors_defs, 0, sizeof(actors_defs)); init_actor_defs(); load_map_tiles(); //lights setup build_global_light_table(); build_sun_pos_table(); reset_material(); init_lights(); disable_local_lights(); init_colors(); clear_error_log(); clear_conn_log(); clear_thunders(); build_rain_table(); read_bin_cfg(); build_levels_table();//for some HUD stuff init_scale_array(); if(!no_sound)init_sound(); //initialize the fonts init_fonts(); check_gl_errors(); //load the necesary textures //font_text=load_texture_cache("./textures/font.bmp",0); icons_text=load_texture_cache("./textures/gamebuttons.bmp",0); hud_text=load_texture_cache("./textures/gamebuttons2.bmp",0); cons_text=load_texture_cache("./textures/console.bmp",255); sky_text_1=load_texture_cache("./textures/sky.bmp",70); particle_textures[0]=load_texture_cache("./textures/particle0.bmp",0); particle_textures[1]=load_texture_cache("./textures/particle1.bmp",0); particle_textures[2]=load_texture_cache("./textures/particle2.bmp",0); particle_textures[3]=load_texture_cache("./textures/particle3.bmp",0); particle_textures[4]=load_texture_cache("./textures/particle4.bmp",0); particle_textures[5]=load_texture_cache("./textures/particle5.bmp",0); particle_textures[6]=load_texture_cache("./textures/particle6.bmp",0); particle_textures[7]=load_texture_cache("./textures/particle7.bmp",0); items_text_1=load_texture_cache("./textures/items1.bmp",0); items_text_2=load_texture_cache("./textures/items2.bmp",0); items_text_3=load_texture_cache("./textures/items3.bmp",0); items_text_4=load_texture_cache("./textures/items4.bmp",0); items_text_5=load_texture_cache("./textures/items5.bmp",0); items_text_6=load_texture_cache("./textures/items6.bmp",0); items_text_7=load_texture_cache("./textures/items7.bmp",0); items_text_8=load_texture_cache("./textures/items8.bmp",0); items_text_9=load_texture_cache("./textures/items9.bmp",0); portraits1_tex=load_texture_cache("./textures/portraits1.bmp",0); portraits2_tex=load_texture_cache("./textures/portraits2.bmp",0); portraits3_tex=load_texture_cache("./textures/portraits3.bmp",0); portraits4_tex=load_texture_cache("./textures/portraits4.bmp",0); portraits5_tex=load_texture_cache("./textures/portraits5.bmp",0); halo_tex=load_texture_cache("./textures/halo.bmp",0); if(have_multitexture)ground_detail_text=load_texture_cache("./textures/ground_detail.bmp",255); check_gl_errors(); create_char_error_str[0]=0; init_opening_interface(); init_hud_interface(); if(SDLNet_Init()<0) { char str[120]; sprintf(str,"%s: %s\n",failed_sdl_net_init,SDLNet_GetError()); log_error(str); SDLNet_Quit(); SDL_Quit(); exit(2); } if(SDL_InitSubSystem(SDL_INIT_TIMER)<0) { char str[120]; sprintf(str, "%s: %s\n", failed_sdl_timer_init,SDL_GetError()); log_error(str); SDL_Quit(); exit(1); } SDL_SetTimer (1000/(18*4), my_timer_pointer); ReadXML("languages/en/Encyclopedia/index.xml"); read_key_config(); load_questlog(); init_buddy(); //initiate function pointers init_attribf(); //we might want to do this later. connect_to_server(); }
int lincity_main (int argc, char *argv[]) { #if defined (LC_X11) char *geometry = NULL; #endif #if defined (SVGALIB) int q; vga_init (); #endif #if !defined (WIN32) signal (SIGPIPE, SIG_IGN); /* broken pipes are ignored. */ #endif /* Initialize some global variables */ make_dir_ok_flag = 1; main_screen_originx = 1; main_screen_originy = 1; given_scene[0] = 0; quit_flag = network_flag = load_flag = save_flag = prefs_flag = cheat_flag = monument_bul_flag = river_bul_flag = shanty_bul_flag; prefs_drawn_flag = 0; kmouse_val = 8; #ifdef LC_X11 borderx = 0; bordery = 0; parse_xargs (argc, argv, &geometry); #endif /* I18n */ lincity_set_locale (); /* Set up the paths to certain files and directories */ init_path_strings (); /* Make sure that things are installed where they should be */ verify_package (); /* Make sure the save directory exists */ check_savedir (); /* Load preferences */ load_lincityrc (); #ifndef CS_PROFILE #ifdef SEED_RAND srand (time (0)); #endif #endif #ifdef LC_X11 #if defined (commentout) borderx = 0; bordery = 0; parse_xargs (argc, argv, &geometry); #endif Create_Window (geometry); pirate_cursor = XCreateFontCursor (display.dpy, XC_pirate); #elif defined (WIN32) /* Deal with all outstanding messages */ ProcessPendingEvents (); #else parse_args (argc, argv); q = vga_setmode (G640x480x256); gl_setcontextvga (G640x480x256); #endif #if defined (WIN32) || defined (LC_X11) initialize_pixmap (); #endif init_fonts (); #if defined (SKIP_OPENING_SCENE) skip_splash_screen = 1; #endif if (!skip_splash_screen) { load_start_image (); } #ifdef LC_X11 unlock_window_size (); #endif Fgl_setfont (8, 8, main_font); Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR); initialize_geometry (&scr); #if defined (SVGALIB) set_vga_mode (); #endif initialize_monthgraph (); init_mouse_registry (); init_mini_map_mouse (); #ifdef LC_X11 x_key_value = 0; #elif defined (WIN32) RefreshScreen (); #endif setcustompalette (); draw_background (); prog_box (_("Loading the game"), 1); init_types (); init_modules(); init_mappoint_array (); initialize_tax_rates (); prog_box ("", 95); mouse_hide_count = 0; suppress_ok_buttons = 0; prog_box ("", 100); #ifdef USE_PIXMAPS prog_box (_("Creating pixmaps"), 1); init_pixmaps (); prog_box ("", 100); #endif //draw_normal_mouse (1, 1); #if defined (LC_X11) init_x_mouse (); #endif init_timer_buttons(); mouse_initialized = 1; //set_selected_module (CST_TRACK_LR); screen_setup (); /* Main loop! */ client_main_loop (); #if defined (SVGALIB) mouse_close (); vga_setmode (TEXT); #endif print_results (); #if defined (WIN32) || defined (LC_X11) free_pixmap (); #endif #if defined (WIN32) return 0; #else exit (0); #endif }
int main() { char pressKey; int ret; bitmap *bm; u_char *w; sys_init(); sleep(2); add_dbs_beep(NULL, 0, 1); bm = new_bitmap("./test.bmp"); SetSrceenColor(0xFFFF); if (init_fonts() != -1) { disp_line("123-:+09", 0, 0, disp12_char); disp_line("123-:+09", 0, 100, disp36_char); } char *path_b = gppath(getpid()); char *path_d = strdup(path_b); printf("This program path is: '%s' at '%s'\n", basename(path_b), dirname(path_d)); u_char dt[7]; get_bcd_datetime(dt); DBG_MEM("BCD datetime:", dt, 7); /* int i; for (i=319; i>-320; i--) { if (i>0) { disp_bitmap(bm, 0, i, 320-i, 240, 0, 0); } else { disp_bitmap(bm, 0, 0, 320+i, 240, 0, -i); } } */ u_char *buf = NULL; u_char factor[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; u_char key[8] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01}; u_char m_key[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; int p_len = 0; u_long t1, t2; cpu_card_data_t *ccd = NULL; u_long csn; /* alarm test code begin DBG("Syn alarm 4 times..."); ret = add_syn_beep(&t1, 0, 4); DBG("OK, wait 5 sec(ret: %d)\n", ret); sleep(5); DBG("Syn alarm 4 sec..."); ret = add_syn_beep(&t2, 4000, 0); DBG("OK(ret: %d)\n", ret); sleep(1); terminate_alarm(t2); /* alarm test code end */ while (1) { printf("Press 'b' to test beep\n"); printf("Press 'c' to test COM1\n"); printf("Press 'g' to test GPRS\n"); printf("Press 'p' to test PSAM\n"); printf("Press 'm' to test MIFARE\n"); printf("Press 'e' to enter test screen\n"); pressKey=getchar(); switch (pressKey) { case 'b': test_beep(); break; case 'c': test_COM1(); break; case 'g': startup_poll(); break; case 'p': /* pc = new_ty_psam_cos(); if (NULL == pc) { DBG("Create psam card fail!\n"); break; } DBG("Select file 0x3F00..."); ret = psam_select_id(pc, &buf, 0x3F00); if (ret == -1) { DBG("fail!\n"); break; } DBG_MEM("ok!\nResponse:", buf, ret); DBG("Select file 0x1001..."); ret = psam_select_id(pc, &buf, 0x1001); if (ret == -1) { DBG("fail!\n"); break; } DBG_MEM("ok!\nResponse:", buf, ret); t1 = get_tickcount(); ret = calc_descrypt1(pc, factor, key, 0x0D); t2 = get_tickcount(); if (ret == 0) { DBG("Calcuate descrype OK\n"); DBG_MEM("factor:", factor, 8); DBG_MEM("key:", key, 8); } else DBG("Calcuate descrypt fail!\n"); */ DBG("Calculate descrype consumed %d ms.\n", t2-t1); break; case 'm': /* ret = get_card_sn(&buf); DBG("Get card SN ret: %d (buf: %d)\n", ret, malloc_usable_size(buf)); if (ret != -1) DBG_MEM("SN:", buf, ret); else break; csn = (u_long)(*buf); if ((buf[4] & 0x20)) { DBG("**** CPU Card ****\nReset card ..."); ret = reset_cpu_card(&buf); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG_MEM("ok!\nATS:", buf, ret); if (NULL == ccd) { DBG("To create cpu_card_data_t...\n"); ccd = new_cpu_card_data(6001, 1, 21); if (NULL == ccd) { DBG("fail!\n"); break; } else DBG("Ok.\n"); } init_cpu_card_data(ccd, csn, buf, ret, 8, 8); DBG("Fast debit wallet 0.01..."); ret = fast_debit_wallet_PUB1(&fmcos2_opr, ccd, 1); if (-1 == ret) { DBG("fail! ret: %d, errno: %d\n", ret, get_cpu_carderr(ccd)); break; } DBG("Ok! Balance: %d.%d\n", get_pub_wallet_balance(ccd)/100, get_pub_wallet_balance(ccd)%100); */ /* memcpy(factor, buf+ret-8, 8); DBG_MEM("factor:", factor, 8); DBG("\nGet Callagne..."); ret = rf_get_challenge(&fmcos2_opr, &buf, 4); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG_MEM("ok!\nResponse:", buf, ret); memcpy(key, buf, 4); memset(key+4, 0, 4); DBG_MEM("key:", key, 8); DBG("Calculate descrypt..."); ret = calc_descrypt1(factor, key, 0x0D); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG_MEM("ok!\nResopnse:", key, 8); DBG("Select ADF1..."); ret = rf_select_file_id(&fmcos2_opr, &buf, 0x1001); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG_MEM("ok!\nResopnse:", buf, ret); DBG("Read Person file(id=2)..."); ret = rf_read_binary(&fmcos2_opr, &buf, 2, 0, NULL, 0); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG_MEM("ok!\nResponse:", buf, ret); DBG("Read wallet file (id=4)..."); ret = rf_read_record(&fmcos2_opr, &buf, 1, 4, NULL, 12); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG_MEM("ok!\nResponse:", buf, ret); DBG("Authenticate Key(id=0x0E)..."); ret = rf_extern_authent(&fmcos2_opr, &buf, 0x0E, key); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG_MEM("ok!\nResponse:", buf, ret); t2 = get_tickcount(); printf("CPU card time %dms", t2-t1); */ /* } else { DBG("**** Mifare Card ****\nAuthent sector 1..."); ret = authent_mifare_card(m_key, 3, MIFARE_KEYA); if (ret != 0) { DBG("fail!(%d)\n", ret); break; } DBG("ok!\nRead block 0..."); ret = read_mifare_card(&buf, 0); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG("ok!(%d)\n", ret); DBG_MEM("Block 0:", buf, ret); DBG("Write x0FF to block 1..."); memset(buf, 0xff, sizeof(buf)); ret = write_mifare_card(buf, 1); if (ret != 0) { DBG("fail!(%d)\n", ret); break; } DBG("ok!\nRead block 1..."); ret = read_mifare_card(&buf, 1); if (ret == -1) { DBG("fail!(%d)\n", ret); break; } DBG("ok!(%d)\n", ret); DBG_MEM("Block 1:", buf, ret); }*/ break; } if (pressKey=='e') break; } }