backport from uhexen2: read video variables early so that a vid_restart

isn't necessary after init. thanks to Sander van Dijk.

git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@531 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2011-12-20 09:22:19 +00:00
parent 9039243d5f
commit 1303651a7b
10 changed files with 320 additions and 114 deletions

View file

@ -250,6 +250,7 @@ OBJS := \
common.o \
crc.o \
cvar.o \
cfgfile.o \
host.o \
host_cmd.o \
mathlib.o \

View file

@ -276,6 +276,7 @@ OBJS := \
common.o \
crc.o \
cvar.o \
cfgfile.o \
host.o \
host_cmd.o \
mathlib.o \

View file

@ -236,6 +236,7 @@ OBJS := \
common.o \
crc.o \
cvar.o \
cfgfile.o \
host.o \
host_cmd.o \
mathlib.o \

View file

@ -236,6 +236,7 @@ OBJS := \
common.o \
crc.o \
cvar.o \
cfgfile.o \
host.o \
host_cmd.o \
mathlib.o \

160
quakespasm/Quake/cfgfile.c Normal file
View file

@ -0,0 +1,160 @@
/*
cfgfile.c
misc reads from the config file
$Id: cfgfile.c 3880 2011-01-28 21:50:19Z sezero $
Copyright (C) 2008-2010 O.Sezer <sezero@users.sourceforge.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "quakedef.h"
static FILE *cfg_file;
/*
===================
CFG_ReadCvars
used for doing early reads from config.cfg searching the list
of given cvar names for the user-set values. a temporary
solution until we merge a better cvar system.
the num_vars argument must be the exact number of strings in the
array, otherwise I have nothing against going out of bounds.
===================
*/
void CFG_ReadCvars (const char **vars, int num_vars)
{
char buff[1024], *tmp;
int i, j;
if (!cfg_file || num_vars < 1)
return;
j = 0;
do {
i = 0;
memset (buff, 0, sizeof(buff));
fgets(buff, sizeof(buff), cfg_file);
if (!feof(cfg_file))
{
// we expect a line in the format that Cvar_WriteVariables
// writes to the config file. although I'm trying to be as
// much cautious as possible, if the user screws it up by
// editing it, it's his fault.
// remove end-of-line characters
while (buff[i])
{
if (buff[i] == '\r' || buff[i] == '\n')
buff[i] = '\0';
// while we're here, replace tabs with spaces
if (buff[i] == '\t')
buff[i] = ' ';
i++;
}
// go to the last character
while (buff[i] == 0 && i > 0)
i--;
// remove trailing spaces
while (i > 0)
{
if (buff[i] == ' ')
{
buff[i] = '\0';
i--;
}
else
break;
}
// the line must end with a quotation mark
if (buff[i] != '\"')
continue;
buff[i] = '\0';
for (i = 0; i < num_vars && vars[i]; i++)
{
// look for the cvar name + one space
tmp = strstr(buff, va("%s ",vars[i]));
if (tmp != buff)
continue;
// locate the first quotation mark
tmp = strchr(buff, '\"');
if (tmp)
{
Cvar_Set (vars[i], tmp+1);
j++;
break;
}
}
}
if (j == num_vars)
break;
} while (!feof(cfg_file));
fseek (cfg_file, 0, SEEK_SET);
}
void CFG_ReadCvarOverrides (const char **vars, int num_vars)
{
char buff[64];
int i, j;
if (num_vars < 1)
return;
buff[0] = '+';
for (i = 0; i < num_vars; i++)
{
strncpy (&buff[1], vars[i], sizeof(buff) - 1);
buff[sizeof(buff) - 1] = 0;
j = COM_CheckParm(buff);
if (j != 0 && j < com_argc - 1)
{
if (com_argv[j + 1][0] != '-' && com_argv[j + 1][0] != '+')
Cvar_Set(vars[i], com_argv[j + 1]);
}
}
}
void CFG_CloseConfig (void)
{
if (cfg_file)
{
fclose (cfg_file);
cfg_file = NULL;
}
}
int CFG_OpenConfig (const char *cfg_name)
{
CFG_CloseConfig ();
COM_FOpenFile (cfg_name, &cfg_file, NULL);
if (!cfg_file)
return -1;
return 0;
}

View file

@ -0,0 +1,49 @@
/*
cfgfile.h
misc reads from the config file
$Id: cfgfile.h 3862 2010-12-30 20:51:57Z sezero $
Copyright (C) 2008-2010 O.Sezer <sezero@users.sourceforge.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef __CFGFILE_H
#define __CFGFILE_H
int CFG_OpenConfig (const char *cfg_name);
// opens the given config file and keeps it open
// until CFG_CloseConfig is called
void CFG_CloseConfig (void);
// closes the currently open config file
void CFG_ReadCvars (const char **vars, int num_vars);
// reads the values of cvars in the given list
// from the currently open config file
void CFG_ReadCvarOverrides (const char **vars, int num_vars);
// reads the "+" command line override values of cvars
// in the given list. doesn't care about the config file.
// call this after CFG_ReadCvars() and before locking your
// cvars.
#endif /* __CFGFILE_H */

View file

@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// gl_vidsdl.c -- SDL GL vid component
#include "quakedef.h"
#include "cfgfile.h"
#include "bgmusic.h"
#include "resource.h"
#include "SDL.h"
@ -1026,20 +1027,29 @@ void VID_InitDIB (void)
modelist[0].type = MODE_WINDOWED;
modelist[0].width = vid_width.value;
modelist[0].height = vid_height.value;
i = COM_CheckParm("-width");
if (i && i < com_argc-1)
{
modelist[0].width = Q_atoi(com_argv[i+1]);
else
modelist[0].width = 800; // QuakeSpasm, was 640
if (modelist[0].width < 320)
modelist[0].width = 320;
if (!COM_CheckParm("-height"))
modelist[0].height = modelist[0].width * 3 / 4;
}
i = COM_CheckParm("-height");
if (i && i < com_argc-1)
{
modelist[0].height = Q_atoi(com_argv[i+1]);
else
modelist[0].height = modelist[0].width * 240/320;
if (!COM_CheckParm("-width"))
modelist[0].width = modelist[0].height * 4 / 3;
}
if (modelist[0].width < 320)
modelist[0].width = 320;
if (modelist[0].height < 200) //johnfitz -- was 240
modelist[0].height = 200; //johnfitz -- was 240
@ -1157,13 +1167,13 @@ void VID_Init (void)
static char vid_center[] = "SDL_VIDEO_CENTERED=center";
const SDL_VideoInfo *info;
int i, existingmode;
int width, height, bpp, findbpp, done;
int width, height, bpp;
int p;
//johnfitz -- clean up init readouts
//Con_Printf("------------- Init Video -------------\n");
//Con_Printf("%cVideo Init\n", 2);
//johnfitz
const char *read_vars[] = { "vid_fullscreen",
"vid_width",
"vid_height",
"vid_bpp" };
#define num_readvars ( sizeof(read_vars)/sizeof(read_vars[0]) )
Cvar_RegisterVariable (&vid_fullscreen, VID_Changed_f); //johnfitz
Cvar_RegisterVariable (&vid_width, VID_Changed_f); //johnfitz
@ -1183,22 +1193,33 @@ void VID_Init (void)
putenv (vid_center); /* SDL_putenv is problematic in versions <= 1.2.9 */
if (CFG_OpenConfig("config.cfg") == 0)
{
CFG_ReadCvars(read_vars, num_readvars);
CFG_CloseConfig();
}
CFG_ReadCvarOverrides(read_vars, num_readvars);
VID_InitDIB();
nummodes = 1;
VID_InitFullDIB();
// Config file is not read yet, so we don't know vid_fullscreen.value
// Changed this to default to -window as otherwise it occasionally forces
// two switches of video mode (window->fullscreen->window) which is bad S.A
// It's still not perfect but, hell, this ancient code can be a pain
if (!COM_CheckParm("-fullscreen") && !COM_CheckParm ("-f"))
if (COM_CheckParm("-window") || COM_CheckParm("-w"))
{
Cvar_Set ("vid_fullscreen", "0");
}
else if (COM_CheckParm("-fullscreen") || COM_CheckParm("-f"))
{
Cvar_Set ("vid_fullscreen", "1");
}
if (!vid_fullscreen.value)
{
windowed = true;
vid_default = MODE_WINDOWED;
}
else
{
Cvar_Set ("vid_fullscreen", "1");
if (nummodes == 1)
Sys_Error ("No RGB fullscreen modes available");
@ -1216,38 +1237,38 @@ void VID_Init (void)
info = SDL_GetVideoInfo();
modelist[MODE_FULLSCREEN_DEFAULT].width = info->current_w;
modelist[MODE_FULLSCREEN_DEFAULT].height = info->current_h;
modelist[MODE_FULLSCREEN_DEFAULT].bpp = info->vfmt->BitsPerPixel;
vid_default = MODE_FULLSCREEN_DEFAULT;
leavecurrentmode = 1;
}
else
{
width = vid_width.value;
height = vid_height.value;
p = COM_CheckParm("-width");
if (p && p < com_argc-1)
{
width = Q_atoi(com_argv[p+1]);
}
else
{
width = 800; // QuakeSpasm, was 640
}
p = COM_CheckParm("-bpp");
if (p && p < com_argc-1)
{
bpp = Q_atoi(com_argv[p+1]);
findbpp = 0;
}
else
{
bpp = 15;
findbpp = 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]);
else
height = width * 3 / 4; // assume 4:3 aspect ratio
bpp = vid_bpp.value;
// if they want to force it, add the specified mode to the list
if (COM_CheckParm("-force") && (nummodes < MAX_MODE_LIST))
@ -1282,70 +1303,53 @@ void VID_Init (void)
}
}
done = 0;
vid_default = 0;
do
{
p = COM_CheckParm("-height");
if (p && p < com_argc-1)
{
height = Q_atoi(com_argv[p+1]);
for (i = 1, vid_default = 0; i < nummodes; i++)
// Try to find a mode with matching width, height and bpp
for (i = 1; i < nummodes; i++)
{
if ((modelist[i].width == width) &&
(modelist[i].height == height) &&
(modelist[i].bpp == bpp))
{
vid_default = i;
done = 1;
break;
}
}
}
else
{
for (i = 1, vid_default = 0; i < nummodes; i++)
{
if ((modelist[i].width == width) && (modelist[i].bpp == bpp))
{
vid_default = i;
done = 1;
break;
}
}
}
if (!done)
{
if (findbpp)
{
switch (bpp)
{
case 15:
bpp = 16;
break;
case 16:
bpp = 32;
break;
case 32:
bpp = 24;
break;
case 24:
done = 1;
break;
}
}
else
{
done = 1;
}
}
} while (!done);
// Try to find a mode with matching width and height
if (!vid_default)
{
Sys_Error ("Specified video mode not available");
for (i = 1; i < nummodes; i++)
{
if ((modelist[i].width == width) &&
(modelist[i].height == height))
{
vid_default = i;
break;
}
}
}
// Try to find a mode with matching width
if (!vid_default)
{
for (i = 1; i < nummodes; i++)
{
if ((modelist[i].width == width))
{
vid_default = i;
break;
}
}
}
// Still no luck? Default to windowed mode
if (!vid_default)
{
Cvar_Set ("vid_fullscreen", "0");
windowed = true;
vid_default = MODE_WINDOWED;
}
}
}
@ -1382,21 +1386,10 @@ void VID_Init (void)
VID_Gamma_Init(); //johnfitz
VID_Menu_Init(); //johnfitz
//johnfitz -- command line vid settings should override config file settings.
//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.
if (COM_CheckParm("-width") || COM_CheckParm("-height") ||
COM_CheckParm("-bpp") ||
COM_CheckParm("-window") || COM_CheckParm("-w") ||
COM_CheckParm("-fullscreen") || COM_CheckParm("-f"))
{
vid_locked = true;
}
//johnfitz
// The problem here is (say) previous video mode is 1024x768 windowed
// And we call "fitzquake -w". This disables setting of 1024x768, and when video lock
// is removed, we get 800x600.
}
// new proc by S.A., called by alt-return key binding.
void VID_Toggle (void)

View file

@ -11,7 +11,7 @@
<PRE>
</PRE>
</P>
<P>QuakeSpasm 0.85.5 (16 December 2011)</P>
<P>QuakeSpasm 0.85.5 (20 December 2011)</P>
<P>
<H2><A NAME="toc1">1.</A> <A HREF="README.html#s1">About </A></H2>
@ -162,6 +162,7 @@ Compile time options include
<LI> Fixed a crash in net play in maps with extended limits</LI>
<LI> Verified successful compilation using gcc-4.6</LI>
<LI> Added a cvar gl_zfix to stop GL texture flicker (z fighting)</LI>
<LI> Read video variables early so that a vid_restart isn't necessary after init</LI>
<LI> mlook and lookspring fixes</LI>
<LI> Added support for loading external entity files, controlled by new cvar external_ents.</LI>
<LI> Made mp3 playback to allocate system memory instead of zone</LI>
@ -264,7 +265,6 @@ Compile time options include
<LI>Test usb keyboards. Do the keypads work? Make the OSX apple key work.</LI>
<LI>Complete the unix user directories support</LI>
<LI>Finalize OSX automatic updating feature</LI>
<LI>There is still an unnecessary screen render on program init under some conditions, when using the "-window/-fullscreen" options.</LI>
</UL>
</P>

View file

@ -4,7 +4,7 @@
<toc>
<verb></verb>
QuakeSpasm 0.85.5 (16 December 2011)
QuakeSpasm 0.85.5 (20 December 2011)
<sect> About <p>
@ -96,6 +96,7 @@ Alternatively, have a look at <bf>Makefile.darwin</bf> for more instructions on
<item> Fixed a crash in net play in maps with extended limits
<item> Verified successful compilation using gcc-4.6
<item> Added a cvar gl_zfix to stop GL texture flicker (z fighting)
<item> Read video variables early so that a vid_restart isn't necessary after init
<item> mlook and lookspring fixes
<item> Added support for loading external entity files, controlled by new cvar external_ents.
<item> Made mp3 playback to allocate system memory instead of zone
@ -183,7 +184,6 @@ Alternatively, have a look at <bf>Makefile.darwin</bf> for more instructions on
<item>Test usb keyboards. Do the keypads work? Make the OSX apple key work.
<item>Complete the unix user directories support
<item>Finalize OSX automatic updating feature
<item>There is still an unnecessary screen render on program init under some conditions, when using the "-window/-fullscreen" options.
</itemize>

View file

@ -29,7 +29,7 @@
______________________________________________________________________
QuakeSpasm 0.85.5 (16 December 2011)
QuakeSpasm 0.85.5 (20 December 2011)
1. About
@ -165,6 +165,9 @@
o Added a cvar gl_zfix to stop GL texture flicker (z fighting)
o Read video variables early so that a vid_restart isn't necessary
after init
o mlook and lookspring fixes
o Added support for loading external entity files, controlled by new
@ -327,9 +330,6 @@
o Finalize OSX automatic updating feature
o There is still an unnecessary screen render on program init under
some conditions, when using the "-window/-fullscreen" options.
7. Links