int CFG_OpenConfig (const char *cfg_name) { FILE *f; long length; qboolean pak; CFG_CloseConfig (); length = (long) COM_FOpenFile (cfg_name, &f, NULL); pak = file_from_pak; if (length == -1) return -1; cfg_file = (fshandle_t *) Z_Malloc(sizeof(fshandle_t)); cfg_file->file = f; cfg_file->start = ftell(f); cfg_file->pos = 0; cfg_file->length = length; cfg_file->pak = pak; return 0; }
/* =================== VID_Init =================== */ void VID_Init (void) { static char vid_center[] = "SDL_VIDEO_CENTERED=center"; const SDL_VideoInfo *info; int width, height, bpp; qboolean fullscreen; const char *read_vars[] = { "vid_fullscreen", "vid_width", "vid_height", "vid_bpp", "vid_vsync" }; #define num_readvars ( sizeof(read_vars)/sizeof(read_vars[0]) ) Cvar_RegisterVariable (&vid_fullscreen); //johnfitz Cvar_RegisterVariable (&vid_width); //johnfitz Cvar_RegisterVariable (&vid_height); //johnfitz Cvar_RegisterVariable (&vid_bpp); //johnfitz Cvar_RegisterVariable (&vid_vsync); //johnfitz Cvar_SetCallback (&vid_fullscreen, VID_Changed_f); Cvar_SetCallback (&vid_width, VID_Changed_f); Cvar_SetCallback (&vid_height, VID_Changed_f); Cvar_SetCallback (&vid_bpp, VID_Changed_f); Cvar_SetCallback (&vid_vsync, VID_Changed_f); Cmd_AddCommand ("vid_unlock", VID_Unlock); //johnfitz Cmd_AddCommand ("vid_restart", VID_Restart); //johnfitz Cmd_AddCommand ("vid_test", VID_Test); //johnfitz Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f); Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f); putenv (vid_center); /* SDL_putenv is problematic in versions <= 1.2.9 */ if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) Sys_Error("Could not initialize SDL Video"); info = SDL_GetVideoInfo(); Cvar_SetValueQuick (&vid_bpp, (float)info->vfmt->BitsPerPixel); if (CFG_OpenConfig("config.cfg") == 0) { CFG_ReadCvars(read_vars, num_readvars); CFG_CloseConfig(); } CFG_ReadCvarOverrides(read_vars, num_readvars); VID_InitModelist(); width = (int)vid_width.value; height = (int)vid_height.value; bpp = (int)vid_bpp.value; fullscreen = (int)vid_fullscreen.value; if (COM_CheckParm("-current")) { width = info->current_w; height = info->current_h; bpp = info->vfmt->BitsPerPixel; fullscreen = true; } else { int p; p = COM_CheckParm("-width"); if (p && p < com_argc-1) { width = Q_atoi(com_argv[p+1]); if(!COM_CheckParm("-height")) height = width * 3 / 4; } p = COM_CheckParm("-height"); if (p && p < com_argc-1) { height = Q_atoi(com_argv[p+1]); if(!COM_CheckParm("-width")) width = height * 4 / 3; } p = COM_CheckParm("-bpp"); if (p && p < com_argc-1) bpp = Q_atoi(com_argv[p+1]); if (COM_CheckParm("-window") || COM_CheckParm("-w")) fullscreen = false; else if (COM_CheckParm("-fullscreen") || COM_CheckParm("-f")) fullscreen = true; } if (!VID_ValidMode(width, height, bpp, fullscreen)) { width = (int)vid_width.value; height = (int)vid_height.value; bpp = (int)vid_bpp.value; fullscreen = (int)vid_fullscreen.value; } if (!VID_ValidMode(width, height, bpp, fullscreen)) { width = 640; height = 480; bpp = info->vfmt->BitsPerPixel; fullscreen = false; } vid_initialized = true; vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpheight = WARP_HEIGHT; vid.colormap = host_colormap; vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048)); // set window icon PL_SetWindowIcon(); VID_SetMode (width, height, bpp, fullscreen); GL_Init (); GL_SetupState (); Cmd_AddCommand ("gl_info", GL_Info_f); //johnfitz //johnfitz -- removed code creating "glquake" subdirectory vid_menucmdfn = VID_Menu_f; //johnfitz vid_menudrawfn = VID_MenuDraw; vid_menukeyfn = VID_MenuKey; VID_Gamma_Init(); //johnfitz VID_Menu_Init(); //johnfitz //QuakeSpasm: current vid settings should override config file settings. //so we have to lock the vid mode from now until after all config files are read. vid_locked = true; }