ok, so this is leaching, but hey, that's part of what the gpl is for :)

Bring in Jamie Wilkinson's patches for quake2_3.21-1. this gives us sdl
support, ~/.quake2, sane default for gl_driver, and several other fixups.
This commit is contained in:
Bill Currie 2002-01-03 04:22:46 +00:00
parent b6acf44cbd
commit 6f4d107011
30 changed files with 3400 additions and 111 deletions

1277
Makefile Normal file

File diff suppressed because it is too large Load diff

156
README.sdl Normal file
View file

@ -0,0 +1,156 @@
id Software's Quake2 3.21+Changes by Steven Fuller <relnev@icculus.org>,
et al.
For this to be of any use, you _must_ own a copy of Quake 2. The demo would
also work, but you might as well buy the full thing now.
These modifications are intended for Linux users, as I do not have have
access to other platforms.
Be sure to install SDL 1.2 (http://www.libsdl.org) if you want to use the
softsdl or sdlgl drivers, or the sdlquake2 binary.
You can change what drivers you wish to build by editing the Makefile and
changing the BUILD_ lines at the very top.
'make' will, by default, build both the debug and release files.
To build fully optimized binaries: make build_release
The resulting binaries are then put in releasei386.
To install the Quake2 gamedata:
-------------------------------
(installdir is wherever you want to install quake2, and cdromdir is wherever
you mount the Quake 2 CD-ROM)
1. copy <cdromdir>/Install/Data/baseq2/pak0.pak to <installdir>/baseq2/
2. copy <cdromdir>/Install/Data/baseq2/videos/ to <installdir>/baseq2/
(optional)
3. Download q2-3.20-x86-full.exe from
ftp://ftp.idsoftware.com/idstuff/quake2/ or a mirror site, and extract the
contents to a temporary directory (use unzip -L, as this is a standard zip
file).
4. copy <q2-3.20-x86-full.exe temp directory>/baseq2/pak1.pak to
<installdir>/baseq2/
5. copy <q2-3.20-x86-full.exe temp directory>/baseq2/pak2.pak to
<installdir>/baseq2/
6. copy <q2-3.20-x86-full.exe temp directory>/baseq2/players/ to
<installdir>/baseq2/
To install this program:
------------------------
(builddir is either debugi386 or releasei386)
1. copy <builddir>/gamei386.so to <installdir>/baseq2/
2. copy <builddir>/ref_*.so to <installdir>
3. copy <builddir>/quake2 to <installdir>
4. copy <builddir>/sdlquake2 to <installdir> (optional)
To run:
-------
cd <installdir> && ./quake2
Or:
quake2 +set basedir <installdir>
/etc/quake2.conf is no longer needed; instead, the ref_*.so files are loaded
from basedir (basedir is "." by default, and can only be set at the command
line).
Configuration files and such are saved in ~/.quake2/, so <installdir> can be
made read-only or whatever.
WARNING: Please do not make quake2 or any of the libraries suid root!
NOTE: Save games will most likely not work across different versions or
builds (this is due to how savegames were stored).
Commonly used commands:
-----------------------
cd_nocd 0 // disable CD audio
s_initsound 0 // disable sound
_windowed_mouse 0 // disable mouse-grabbing
gl_ext_multitexture 0 // disable OpenGL Multitexturing (requires a
vid_restart)
vid_ref <driver> // select a video driver (softx is the original
X11-only, softsdl is SDL software, sdlgl is
SDL OpenGL)
vid_fullscreen 0 // disable fullscreen mode
vid_restart // restart video driver
snd_restart // restart sound driver
basedir <dir> // point quake2 to where the data is
gl_driver <libGL.so> // point quake2 to your libGL
Website:
--------
I'll post any updates I make at http://www.icculus.org/quake/
(which currently redirects to http://www.icculus.org/~relnev/)
Anonymous CVS access:
---------------------
cvs -d:pserver:anonymous@icculus.org:/cvs/cvsroot login
(password is "anonymous" without the quotes.)
cvs -z3 -d:pserver:anonymous@icculus.org:/cvs/cvsroot co quake2
Questions:
----------
What's the best way of handling international keyboards with SDL?
TODO:
-----
Fix save games.
Suggestions, anyone?
v0.0.7: [12/28/01]
-------
+ Merged in Quake2 3.21 source.
v0.0.6: [12/27/01]
-------
+ Made Makefile somewhat easier to configure.
+ X11 GLX driver now included.
+ Added "ctrl-g" (toggle mouse grab) and "alt-enter" (toggle fullscreen)
to SDL drivers.
+ SDL audio and cdrom support. (Robert Bäuml)
+ ~/.quake2/ support (Stephen Anthony, Ludwig Nussel)
+ LinuxPPC support (William Aoki)
v0.0.5: [12/23/01]
-------
+ Better SDL de/initialization (fixes crashes for some people).
+ Removed trailing '\r's from files; removed a few files.
v0.0.4: [12/23/01]
-------
+ Mouse Wheel (SDL buttons 4 and 5).
+ Fixed bug with changing the sound options in game (using the menus).
+ Fixed Makefile to build both build_debug and build_release by default.
v0.0.3: [12/22/01]
-------
+ Fixed the texture wrapping with movies.
+ Enabled the OpenGL extensions under Linux.
+ Added support for GL_ARB_multitexture.
v0.0.2: [12/22/01]
-------
+ Added ref_sdlgl.so (SDL OpenGL Renderer).
+ v0.0.1 Bugfixes.
v0.0.1: [12/22/01]
-------
+ Updates to Linux Makefile (it was missing a few files).
+ Added ref_softsdl.so (Software SDL Renderer).
- OpenGL not yet supported.
Thanks:
-------
John Allensworth
Stephen Anthony
William Aoki
Robert Bäuml
Ryan C. Gordon
Ludwig Nussel
Zachary 'zakk' Slater
Matti Valtonen

23
debian/README.Debian vendored Normal file
View file

@ -0,0 +1,23 @@
quake2 for Debian
-----------------
quake2 is just a game engine, and as such is fairly useless without data files
(unless you are using this package for educational purposes, in which case you
might be better off just grabbing the source), so you will need something that
provides quake2-data. The easiest solution (but by no means endorsed by the
Debian project ;) is to get the commercial Quake 2 CD-ROM and install the
quake2-data package. There is talk of creating DFSG-free data for this engine,
but currently this maintainer knows of no tools to build such data for Linux,
let alone Debian.
This package contains the SDL patches made by Steven Fuller (downloaded from
http://icculus.org/~relnev/download.php), for more details please read
README.sdl. This patch was rearranged slightly to fit the original source from
iD. The top-level Makefile is also thanks to Steven.
The following may only be of interest to other maintainers:
The .orig.tar.gz has had ^Ms removed from the source files, and the file
quake2-3.21/linux/map.out has been removed. Apart from that, no other changes
have been made.
-- Jamie Wilkinson <jaq@spacepants.org>, Sat, 29 Dec 2001 17:42:41 +1100

11
debian/changelog vendored Normal file
View file

@ -0,0 +1,11 @@
quake2 (3.21-1) unstable; urgency=low
* Initial Release. (Closes: #126716)
* Applied SDL patch from http://icculus.org/~relnev/download.php, thanks
to Steven Fuller. See README.sdl for more.
-- Jamie Wilkinson <jaq@spacepants.org> Sat, 29 Dec 2001 17:42:41 +1100
Local variables:
mode: debian-changelog
End:

21
debian/control vendored Normal file
View file

@ -0,0 +1,21 @@
Source: quake2
Section: contrib/games
Priority: optional
Maintainer: Jamie Wilkinson <jaq@spacepants.org>
Build-Depends: debhelper (>> 3.0.0), libsdl1.2-dev, libgl-dev, svgalibg1-dev
Standards-Version: 3.5.2
Package: quake2
Architecture: any
Depends: ${shlibs:Depends}
Recommends: quake2-data
Description: popular 3D first person shooter game (engine only)
Quake 2 is a 3D action game engine in first-person perspective, commonly
known as a First Person Shooter.
.
This package contains no data files. You will need to either install the
commercial data from the Quake 2 CD-ROM with the quake2-data package, or
install some free data files.
.
This game currently supports software rendering with X11, SDL, or SVGAlib,
or hardware accelerated rendering with OpenGL (directly or via SDL).

27
debian/copyright vendored Normal file
View file

@ -0,0 +1,27 @@
This package was debianized by Jamie Wilkinson <jaq@spacepants.org> on
Sat, 29 Dec 2001 17:42:41 +1100.
It was downloaded from
ftp://ftp.idsoftware.com/idstuff/source/q2source-3.21.zip
Upstream Author(s): iD software, but I do not expect them to maintain it.
Copyright:
This package 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; version 2 dated June, 1991.
This package 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 package; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
On Debian GNU/Linux systems, the complete text of the GNU General
Public License can be found in `/usr/share/common-licenses/GPL'.

4
debian/dirs vendored Normal file
View file

@ -0,0 +1,4 @@
usr/games
usr/lib/games/quake2
usr/lib/games/quake2/baseq2
usr/share/pixmaps

6
debian/docs vendored Normal file
View file

@ -0,0 +1,6 @@
readme.txt
quake2-3.21/README.sdl
quake2-3.21/joystick.txt
quake2-3.21/linux/README
quake2-3.21/linux/README-3.21-RELEASE
quake2-3.21/linux/README.AXP

3
debian/menu vendored Normal file
View file

@ -0,0 +1,3 @@
?package(quake2):needs=X11 section=Games/Arcade\
title="Quake II" command="/usr/games/quake2" \
icon="/usr/share/pixmaps/quake2.xpm"

51
debian/quake2.6 vendored Normal file
View file

@ -0,0 +1,51 @@
.\" Hey, EMACS: -*- nroff -*-
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH QUAKE2 6 "December 29, 2001"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
.\" .nh disable hyphenation
.\" .hy enable hyphenation
.\" .ad l left justify
.\" .ad b justify to both left and right margins
.\" .nf disable filling
.\" .fi enable filling
.\" .br insert line break
.\" .sp <n> insert n+1 empty lines
.\" for manpage-specific macros, see man(7)
.SH NAME
quake2 \- popular 3D action game
.SH SYNOPSIS
.B quake2
.\" .RI [ options ] " files" ...
.SH DESCRIPTION
This manual page documents briefly the
.B quake2
command, which is used to launch the Quake 2 game engine.
.br
This manual page was written for the Debian GNU/Linux distribution
because the original program does not have a manual page.
.PP
.\" TeX users may be more comfortable with the \fB<whatever>\fP and
.\" \fI<whatever>\fP escape sequences to invode bold face and italics,
.\" respectively.
.\" \fBquake2\fP is a program that...
.\" .SH OPTIONS
.\" These programs follow the usual GNU command line syntax, with long
.\" options starting with two dashes (`-').
.\" A summary of options is included below.
.\" For a complete description, see the Info files.
.\" .TP
.\" .B \-h, \-\-help
.\" Show summary of options.
.\" .TP
.\" .B \-v, \-\-version
.\" Show version of program.
.\" .SH SEE ALSO
.\" .BR bar (1),
.\" .BR baz (1).
.SH AUTHOR
This manual page was written by Jamie Wilkinson <jaq@spacepants.org>,
for the Debian GNU/Linux system (but may be used by others).

3
debian/quake2.sh vendored Normal file
View file

@ -0,0 +1,3 @@
#!/bin/sh
cd /usr/lib/games/quake2 && ./quake2 $*

118
debian/quake2.xpm vendored Normal file
View file

@ -0,0 +1,118 @@
/* XPM */
static char * quake2_xpm[] = {
"32 32 83 1",
" c None",
". c #000000",
"+ c #212129",
"@ c #315A39",
"# c #000800",
"$ c #293931",
"% c #4A5A5A",
"& c #395A39",
"* c #080810",
"= c #103131",
"- c #31524A",
"; c #4A8C6B",
"> c #211818",
", c #292921",
"' c #082108",
") c #213139",
"! c #313139",
"~ c #295242",
"{ c #213931",
"] c #4A735A",
"^ c #292129",
"/ c #637B6B",
"( c #315A4A",
"_ c #294A4A",
": c #182921",
"< c #4A947B",
"[ c #395239",
"} c #5A8C7B",
"| c #101810",
"1 c #080818",
"2 c #395A42",
"3 c #214229",
"4 c #397B4A",
"5 c #31634A",
"6 c #313939",
"7 c #213939",
"8 c #525252",
"9 c #5A6B6B",
"0 c #314A42",
"a c #425A52",
"b c #213118",
"c c #394239",
"d c #294231",
"e c #101000",
"f c #295A42",
"g c #395252",
"h c #426B5A",
"i c #183121",
"j c #101818",
"k c #396352",
"l c #526B5A",
"m c #314239",
"n c #182110",
"o c #292931",
"p c #102129",
"q c #424239",
"r c #7B948C",
"s c #397363",
"t c #315231",
"u c #425A42",
"v c #425239",
"w c #316B5A",
"x c #213131",
"y c #213929",
"z c #293942",
"A c #4A7363",
"B c #5A736B",
"C c #73847B",
"D c #39736B",
"E c #102110",
"F c #5A9C8C",
"G c #101010",
"H c #213129",
"I c #295239",
"J c #313931",
"K c #181008",
"L c #396B42",
"M c #5A6B5A",
"N c #21314A",
"O c #394A42",
"P c #395A4A",
"Q c #183929",
"R c #082110",
"................................",
"...........+.........@..........",
"..........#.....................",
".........$.............#........",
"........%...............&.......",
".......*.................=......",
".......-.................;......",
"......>,.................#'.....",
"......)...................+.....",
"......!...................~.....",
"......{#..................].....",
"......-...................^.....",
"......+/.................(_.....",
"......:<.................[}.....",
"......|12....3456578....90......",
".......ab.....cd.ef.....gh......",
".......#d+....{i.jk...._lm......",
"........no+...mp.+@..qehr.......",
"..........>ns.+t.uvtw0t.........",
"..........xynm>:+:zjABC.........",
".............Di+:E$F]...........",
"..............+>Gxd.............",
"..............>H.IJ.............",
"..............pK.3L.............",
"..............cm.HM.............",
"..............Nj.O-.............",
"...............g.Pj.............",
"...............2.Q..............",
"...............c.R..............",
"...............n.#..............",
"................................",
"................................"};

101
debian/rules vendored Executable file
View file

@ -0,0 +1,101 @@
#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
# This is the debhelper compatability version to use.
export DH_COMPAT=3
qdir = quake2-3.21
lib_dir = usr/lib/games/quake2
bin_dir = usr/games
xpm_dir = usr/share/pixmaps
ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/alpha/axp/)
configure: configure-stamp
configure-stamp:
rm $(qdir)/makefile
dh_testdir
# Add here commands to configure the package.
touch configure-stamp
build: configure-stamp build-stamp
build-stamp:
dh_testdir
# Add here commands to compile the package.
cd $(qdir) && $(MAKE) build_release
#/usr/bin/docbook-to-man debian/quake2.sgml > quake2.1
touch build-stamp
clean:
dh_testdir
dh_testroot
rm -f build-stamp configure-stamp
# Add here commands to clean up after the build process.
-cd $(qdir) && $(MAKE) clean
-cd $(qdir) && $(MAKE) distclean
dh_clean
install: build
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs
# Add here commands to install the package into debian/quake2.
#$(MAKE) install DESTDIR=$(CURDIR)/debian/quake2
install -p -m 755 $(qdir)/release$(ARCH)/quake2 debian/quake2/$(lib_dir)/quake2
for i in $(qdir)/release$(ARCH)/ref*.so; do \
install -p -m 755 $$i debian/quake2/$(lib_dir)/`basename $$i` ; \
done;
install -p -m 755 $(qdir)/release$(ARCH)/gamei386.so debian/quake2/$(lib_dir)/baseq2/gamei386.so
install -p -m 755 debian/quake2.sh debian/quake2/$(bin_dir)/quake2
install -p -m 644 debian/quake2.xpm debian/quake2/$(xpm_dir)/quake2.xpm
# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.
# Build architecture-dependent files here.
binary-arch: build install
dh_testdir
dh_testroot
# dh_installdebconf
dh_installdocs
dh_installexamples
dh_installmenu
# dh_installlogrotate
# dh_installemacsen
# dh_installpam
# dh_installmime
# dh_installinit
dh_installcron
dh_installman
dh_installinfo
# dh_undocumented
cp quake2-3.21/changes.txt quake2-3.21/3.1*anges.txt \
quake2-3.21/3.20_Changes.txt debian/quake2/usr/share/doc/quake2
dh_installchangelogs -k quake2-3.21/3.21_Changes.txt upstream
dh_link
dh_strip
dh_compress
dh_fixperms
# dh_makeshlibs
dh_installdeb
# dh_perl
dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure

View file

@ -500,11 +500,11 @@ void ReadGame (char *filename)
gi.error ("Couldn't open %s", filename);
fread (str, sizeof(str), 1, f);
if (strcmp (str, __DATE__))
{
fclose (f);
gi.error ("Savegame from an older version.\n");
}
//if (strcmp (str, __DATE__))
//{
//fclose (f);
//gi.error ("Savegame from an older version.\n");
//}
g_edicts = gi.TagMalloc (game.maxentities * sizeof(g_edicts[0]), TAG_GAME);
globals.edicts = g_edicts;

View file

@ -1053,7 +1053,7 @@ char *va(char *format, ...)
static char string[1024];
va_start (argptr, format);
vsprintf (string, format,argptr);
vsnprintf (string, 1024, format, argptr);
va_end (argptr);
return string;
@ -1224,10 +1224,10 @@ void Com_sprintf (char *dest, int size, char *fmt, ...)
{
int len;
va_list argptr;
char bigbuffer[0x10000];
static char bigbuffer[0x10000];
va_start (argptr,fmt);
len = vsprintf (bigbuffer,fmt,argptr);
len = vsnprintf (bigbuffer,0x10000,fmt,argptr);
va_end (argptr);
if (len >= size)
Com_Printf ("Com_sprintf: overflow of %i in %i\n", len, size);

281
linux/cd_sdl.c Normal file
View file

@ -0,0 +1,281 @@
/*
snd_sdl.c
CD code taken from SDLQuake and modified to work with Quake2
Robert Bäuml 2001-12-25
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.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#include <stdio.h>
#include "SDL.h"
#include "../client/client.h"
static qboolean cdValid = false;
static qboolean initialized = false;
static qboolean enabled = true;
static qboolean playLooping = false;
static SDL_CD *cd_id;
static float cdvolume = 1.0;
cvar_t *cd_volume;
cvar_t *cd_nocd;
cvar_t *cd_dev;
static void CD_f();
static void CDAudio_Eject()
{
if(!cd_id || !enabled) return;
if(SDL_CDEject(cd_id))
Com_DPrintf("Unable to eject CD-ROM tray.\n");
}
void CDAudio_Play(int track, qboolean looping)
{
CDstatus cd_stat;
if(!cd_id || !enabled) return;
if(!cdValid)
{
if(!CD_INDRIVE(cd_stat=SDL_CDStatus(cd_id)) ||(!cd_id->numtracks)) return;
cdValid = true;
}
if((track < 1) || (track >= cd_id->numtracks))
{
Com_DPrintf("CDAudio: Bad track number: %d\n",track);
return;
}
track--; /* Convert track from person to SDL value */
if(cd_stat == CD_PLAYING)
{
if(cd_id->cur_track == track) return;
CDAudio_Stop();
}
if(SDL_CDPlay(cd_id,cd_id->track[track].offset,
cd_id->track[track].length))
{
Com_DPrintf("CDAudio_Play: Unable to play track: %d\n",track+1);
return;
}
playLooping = looping;
}
void CDAudio_Stop()
{
int cdstate;
if(!cd_id || !enabled) return;
cdstate = SDL_CDStatus(cd_id);
if((cdstate != CD_PLAYING) && (cdstate != CD_PAUSED)) return;
if(SDL_CDStop(cd_id))
Com_DPrintf("CDAudio_Stop: Failed to stop track.\n");
}
void CDAudio_Pause()
{
if(!cd_id || !enabled) return;
if(SDL_CDStatus(cd_id) != CD_PLAYING) return;
if(SDL_CDPause(cd_id))
Com_DPrintf("CDAudio_Pause: Failed to pause track.\n");
}
void CDAudio_Resume()
{
if(!cd_id || !enabled) return;
if(SDL_CDStatus(cd_id) != CD_PAUSED) return;
if(SDL_CDResume(cd_id))
Com_DPrintf("CDAudio_Resume: Failed tp resume track.\n");
}
void CDAudio_Update()
{
if(!cd_id || !enabled) return;
if(cd_volume && cd_volume->value != cdvolume)
{
if(cdvolume)
{
Cvar_SetValue("cd_volume",0.0);
CDAudio_Pause();
}
else
{
Cvar_SetValue("cd_volume",1.0);
CDAudio_Resume();
}
cdvolume = cd_volume->value;
return;
}
if(playLooping && (SDL_CDStatus(cd_id) != CD_PLAYING)
&& (SDL_CDStatus(cd_id) != CD_PAUSED))
CDAudio_Play(cd_id->cur_track+1,true);
}
int CDAudio_Init()
{
cvar_t *cv;
cv = Cvar_Get ("nocdaudio", "0", CVAR_NOSET);
if (cv->value)
return -1;
cd_nocd = Cvar_Get ("cd_nocd", "0", CVAR_ARCHIVE );
if ( cd_nocd->value)
return -1;
cd_volume = Cvar_Get ("cd_volume", "1", CVAR_ARCHIVE);
if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
if (SDL_Init(SDL_INIT_CDROM) < 0) {
Com_Printf ("Couldn't init SDL cdrom: %s\n", SDL_GetError ());
return -1;
}
} else if (SDL_WasInit(SDL_INIT_CDROM) == 0) {
if (SDL_InitSubSystem(SDL_INIT_CDROM) < 0) {
Com_Printf ("Couldn't init SDL cdrom: %s\n", SDL_GetError ());
return -1;
}
}
cd_id = SDL_CDOpen(0);
if(!cd_id)
{
Com_Printf("CDAudio_Init: Unable to open default CD-ROM drive: %s\n",
SDL_GetError());
return -1;
}
initialized = true;
enabled = true;
cdValid = true;
if(!CD_INDRIVE(SDL_CDStatus(cd_id)))
{
Com_Printf("CDAudio_Init: No CD in drive.\n");
cdValid = false;
}
if(!cd_id->numtracks)
{
Com_Printf("CDAudio_Init: CD contains no audio tracks.\n");
cdValid = false;
}
Cmd_AddCommand("cd",CD_f);
Com_Printf("CD Audio Initialized.\n");
return 0;
}
void CDAudio_Shutdown()
{
if(!cd_id) return;
CDAudio_Stop();
SDL_CDClose(cd_id);
cd_id = NULL;
if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_CDROM)
SDL_Quit();
else
SDL_QuitSubSystem(SDL_INIT_CDROM);
}
static void CD_f()
{
char *command;
int cdstate;
if(Cmd_Argc() < 2) return;
command = Cmd_Argv(1);
if(!Q_strcasecmp(command,"on"))
{
enabled = true;
}
if(!Q_strcasecmp(command,"off"))
{
if(!cd_id) return;
cdstate = SDL_CDStatus(cd_id);
if((cdstate == CD_PLAYING) || (cdstate == CD_PAUSED))
CDAudio_Stop();
enabled = false;
return;
}
if(!Q_strcasecmp(command,"play"))
{
CDAudio_Play((byte)atoi(Cmd_Argv(2)),false);
return;
}
if(!Q_strcasecmp(command,"loop"))
{
CDAudio_Play((byte)atoi(Cmd_Argv(2)),true);
return;
}
if(!Q_strcasecmp(command,"stop"))
{
CDAudio_Stop();
return;
}
if(!Q_strcasecmp(command,"pause"))
{
CDAudio_Pause();
return;
}
if(!Q_strcasecmp(command,"resume"))
{
CDAudio_Resume();
return;
}
if(!Q_strcasecmp(command,"eject"))
{
CDAudio_Eject();
return;
}
if(!Q_strcasecmp(command,"info"))
{
if(!cd_id) return;
cdstate = SDL_CDStatus(cd_id);
Com_Printf("%d tracks\n",cd_id->numtracks);
if(cdstate == CD_PLAYING)
Com_Printf("Currently %s track %d\n",
playLooping ? "looping" : "playing",
cd_id->cur_track+1);
else
if(cdstate == CD_PAUSED)
Com_Printf("Paused %s track %d\n",
playLooping ? "looping" : "playing",
cd_id->cur_track+1);
return;
}
}
void CDAudio_Activate (qboolean active)
{
if (active)
CDAudio_Resume ();
else
CDAudio_Pause ();
}

View file

@ -233,7 +233,13 @@ void RW_IN_Init(in_state_t *in_state_p)
void RW_IN_Shutdown(void)
{
mouse_avail = false;
if (mouse_avail) {
mouse_avail = false;
ri.Cmd_RemoveCommand ("+mlook");
ri.Cmd_RemoveCommand ("-mlook");
ri.Cmd_RemoveCommand ("force_centerview");
}
}
/*
@ -450,6 +456,8 @@ static int XLateKey(XKeyEvent *ev)
key = *(unsigned char*)buf;
if (key >= 'A' && key <= 'Z')
key = key - 'A' + 'a';
if (key >= 1 && key <= 26) /* ctrl+alpha */
key = key + 'a' - 1;
break;
}
@ -601,6 +609,7 @@ int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
Window root;
XVisualInfo *visinfo;
XSetWindowAttributes attr;
XSizeHints *sizehints;
unsigned long mask;
int MajorVersion, MinorVersion;
int actualWidth, actualHeight;
@ -626,11 +635,13 @@ int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
// destroy the existing window
GLimp_Shutdown ();
#if 0 // this breaks getenv()? - sbf
// Mesa VooDoo hacks
if (fullscreen)
putenv("MESA_GLX_FX=fullscreen");
else
putenv("MESA_GLX_FX=window");
#endif
if (!(dpy = XOpenDisplay(NULL))) {
fprintf(stderr, "Error couldn't open the X display\n");
@ -712,6 +723,24 @@ int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
win = XCreateWindow(dpy, root, 0, 0, width, height,
0, visinfo->depth, InputOutput,
visinfo->visual, mask, &attr);
sizehints = XAllocSizeHints();
if (sizehints) {
sizehints->min_width = width;
sizehints->min_height = height;
sizehints->max_width = width;
sizehints->max_height = height;
sizehints->base_width = width;
sizehints->base_height = vid.height;
sizehints->flags = PMinSize | PMaxSize | PBaseSize;
}
XSetWMProperties(dpy, win, NULL, NULL, NULL, 0,
sizehints, None, None);
if (sizehints)
XFree(sizehints);
XMapWindow(dpy, win);
if (vidmode_active) {
@ -762,6 +791,7 @@ void GLimp_Shutdown( void )
qglXDestroyContext(dpy, ctx);
if (vidmode_active)
XF86VidModeSwitchToMode(dpy, scrnum, vidmodes[0]);
XUngrabKeyboard(dpy, CurrentTime);
XCloseDisplay(dpy);
}
ctx = NULL;

View file

@ -37,8 +37,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <dlfcn.h>
const char so_file[] = "/etc/quake2.conf";
/*
//FX Mesa Functions
fxMesaContext (*qfxMesaCreateContext)(GLuint win, GrScreenResolution_t, GrScreenRefresh_t, const GLint attribList[]);
@ -3034,12 +3032,13 @@ qboolean QGL_Init( const char *dllname )
if ( ( glw_state.OpenGLLib = dlopen( dllname, RTLD_LAZY | RTLD_GLOBAL ) ) == 0 )
{
char fn[MAX_OSPATH];
char *path;
FILE *fp;
// ri.Con_Printf(PRINT_ALL, "QGL_Init: Can't load %s from /etc/ld.so.conf: %s\n",
// dllname, dlerror());
// try path in /etc/quake2.conf
#if 0
if ((fp = fopen(so_file, "r")) == NULL) {
ri.Con_Printf(PRINT_ALL, "QGL_Init(\"%s\") failed: can't open %s\n", dllname, so_file);
return false;
@ -3048,9 +3047,11 @@ qboolean QGL_Init( const char *dllname )
fclose(fp);
while (*fn && isspace(fn[strlen(fn) - 1]))
fn[strlen(fn) - 1] = 0;
strcat(fn, "/");
strcat(fn, dllname);
#endif
// try basedir next
path = ri.Cvar_Get ("basedir", ".", CVAR_NOSET)->string;
snprintf (fn, MAX_OSPATH, "%s/%s", path, dllname );
if ( ( glw_state.OpenGLLib = dlopen( fn, RTLD_LAZY ) ) == 0 ) {
ri.Con_Printf( PRINT_ALL, "%s\n", dlerror() );

View file

@ -199,6 +199,7 @@ static int mouse_oldbuttonstate;
static float mouse_x, mouse_y;
static float old_mouse_x, old_mouse_y;
static int mx, my;
static int mwheel;
static cvar_t *m_filter;
static cvar_t *in_mouse;
@ -235,12 +236,23 @@ static void RW_IN_MLookUp (void)
in_state->IN_CenterView_fp ();
}
#if 0 /* old definition */
static void mousehandler(int buttonstate, int dx, int dy)
{
mouse_buttonstate = buttonstate;
mx += dx;
my += dy;
}
#else /* drx is assumed to be the mouse wheel */
static void mousehandler(int buttonstate, int dx, int dy, int dz, int drx, int dry, int drz)
{
mouse_buttonstate = buttonstate;
mx += dx;
my += dy;
mwheel = drx;
}
#endif
void RW_IN_Init(in_state_t *in_state_p)
{
@ -318,12 +330,22 @@ void RW_IN_Commands (void)
if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
!(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
Key_Event_fp (K_MOUSE3, true);
in_state->Key_Event_fp (K_MOUSE3, true);
else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
in_state->Key_Event_fp (K_MOUSE3, false);
mouse_oldbuttonstate = mouse_buttonstate;
if (mwheel < 0) {
in_state->Key_Event_fp (K_MWHEELUP, true);
in_state->Key_Event_fp (K_MWHEELUP, false);
}
if (mwheel > 0) {
in_state->Key_Event_fp (K_MWHEELDOWN, true);
in_state->Key_Event_fp (K_MWHEELDOWN, false);
}
mwheel = 0;
}
/*

878
linux/rw_sdl.c Normal file
View file

@ -0,0 +1,878 @@
/*
** RW_SDL.C
**
** This file contains ALL Linux specific stuff having to do with the
** software refresh. When a port is being made the following functions
** must be implemented by the port:
**
** SWimp_EndFrame
** SWimp_Init
** SWimp_InitGraphics
** SWimp_SetPalette
** SWimp_Shutdown
** SWimp_SwitchFullscreen
*/
#include <ctype.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "SDL.h"
#ifdef OPENGL
#include <GL/gl.h>
#endif
#ifdef OPENGL
#include "../ref_gl/gl_local.h"
#include "../linux/glw_linux.h"
#else
#include "../ref_soft/r_local.h"
#endif
#include "../client/keys.h"
#include "../linux/rw_linux.h"
/*****************************************************************************/
static qboolean X11_active = false;
static SDL_Surface *surface;
static int sdl_palettemode;
struct
{
int key;
int down;
} keyq[64];
int keyq_head=0;
int keyq_tail=0;
int config_notify=0;
int config_notify_width;
int config_notify_height;
#ifdef OPENGL
glwstate_t glw_state;
#endif
// Console variables that we need to access from this module
/*****************************************************************************/
/* MOUSE */
/*****************************************************************************/
// this is inside the renderer shared lib, so these are called from vid_so
static qboolean mouse_avail;
static int mouse_buttonstate;
static int mouse_oldbuttonstate;
static int mouse_x, mouse_y;
static int old_mouse_x, old_mouse_y;
static int mx, my;
static float old_windowed_mouse;
static int p_mouse_x, p_mouse_y;
static cvar_t *_windowed_mouse;
static cvar_t *m_filter;
static cvar_t *in_mouse;
static int blah1[65536*8];
static qboolean mlooking;
static int blah2[65536*8];
// state struct passed in Init
static in_state_t *in_state;
static cvar_t *sensitivity;
static cvar_t *my_lookstrafe;
static cvar_t *m_side;
static cvar_t *m_yaw;
static cvar_t *m_pitch;
static cvar_t *m_forward;
static cvar_t *my_freelook;
static void Force_CenterView_f (void)
{
in_state->viewangles[PITCH] = 0;
}
static void RW_IN_MLookDown (void)
{
mlooking = true;
}
static void RW_IN_MLookUp (void)
{
mlooking = false;
in_state->IN_CenterView_fp ();
}
void RW_IN_Init(in_state_t *in_state_p)
{
int mtype;
int i;
in_state = in_state_p;
// mouse variables
_windowed_mouse = ri.Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE);
m_filter = ri.Cvar_Get ("m_filter", "0", 0);
in_mouse = ri.Cvar_Get ("in_mouse", "1", CVAR_ARCHIVE);
my_freelook = ri.Cvar_Get( "freelook", "0", 0);
my_lookstrafe = ri.Cvar_Get ("lookstrafe", "0", 0);
sensitivity = ri.Cvar_Get ("sensitivity", "3", 0);
m_pitch = ri.Cvar_Get ("m_pitch", "0.022", 0);
m_yaw = ri.Cvar_Get ("m_yaw", "0.022", 0);
m_forward = ri.Cvar_Get ("m_forward", "1", 0);
m_side = ri.Cvar_Get ("m_side", "0.8", 0);
ri.Cmd_AddCommand ("+mlook", RW_IN_MLookDown);
ri.Cmd_AddCommand ("-mlook", RW_IN_MLookUp);
ri.Cmd_AddCommand ("force_centerview", Force_CenterView_f);
mouse_x = mouse_y = 0.0;
mouse_avail = true;
}
void RW_IN_Shutdown(void)
{
if (mouse_avail) {
mouse_avail = false;
ri.Cmd_RemoveCommand ("+mlook");
ri.Cmd_RemoveCommand ("-mlook");
ri.Cmd_RemoveCommand ("force_centerview");
}
}
/*
===========
IN_Commands
===========
*/
void RW_IN_Commands (void)
{
int i;
if (!mouse_avail)
return;
for (i=0 ; i<3 ; i++) {
if ( (mouse_buttonstate & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) )
in_state->Key_Event_fp (K_MOUSE1 + i, true);
if ( !(mouse_buttonstate & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) )
in_state->Key_Event_fp (K_MOUSE1 + i, false);
}
mouse_oldbuttonstate = mouse_buttonstate;
}
/*
===========
IN_Move
===========
*/
void RW_IN_Move (usercmd_t *cmd)
{
if (!mouse_avail)
return;
if (m_filter->value)
{
mouse_x = (mx + old_mouse_x) * 0.5;
mouse_y = (my + old_mouse_y) * 0.5;
} else {
mouse_x = mx;
mouse_y = my;
}
old_mouse_x = mx;
old_mouse_y = my;
if (!mouse_x && !mouse_y)
return;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
// add mouse X/Y movement to cmd
if ( (*in_state->in_strafe_state & 1) ||
(my_lookstrafe->value && mlooking ))
cmd->sidemove += m_side->value * mouse_x;
else
in_state->viewangles[YAW] -= m_yaw->value * mouse_x;
if ( (mlooking || my_freelook->value) &&
!(*in_state->in_strafe_state & 1))
{
in_state->viewangles[PITCH] += m_pitch->value * mouse_y;
}
else
{
cmd->forwardmove -= m_forward->value * mouse_y;
}
mx = my = 0;
}
#if 0
static void IN_DeactivateMouse( void )
{
if (!mouse_avail)
return;
if (mouse_active) {
/* uninstall_grabs(); */
mouse_active = false;
}
}
static void IN_ActivateMouse( void )
{
if (!mouse_avail)
return;
if (!mouse_active) {
mx = my = 0; // don't spazz
/* install_grabs(); */
mouse_active = true;
}
}
#endif
void RW_IN_Frame (void)
{
}
void RW_IN_Activate(qboolean active)
{
#if 0
if (active || vidmode_active)
IN_ActivateMouse();
else
IN_DeactivateMouse();
#endif
}
/*****************************************************************************/
#if 0 /* SDL parachute should catch everything... */
// ========================================================================
// Tragic death handler
// ========================================================================
void TragicDeath(int signal_num)
{
/* SDL_Quit(); */
Sys_Error("This death brought to you by the number %d\n", signal_num);
}
#endif
int XLateKey(unsigned int keysym)
{
int key;
key = 0;
switch(keysym) {
case SDLK_KP9: key = K_KP_PGUP; break;
case SDLK_PAGEUP: key = K_PGUP; break;
case SDLK_KP3: key = K_KP_PGDN; break;
case SDLK_PAGEDOWN: key = K_PGDN; break;
case SDLK_KP7: key = K_KP_HOME; break;
case SDLK_HOME: key = K_HOME; break;
case SDLK_KP1: key = K_KP_END; break;
case SDLK_END: key = K_END; break;
case SDLK_KP4: key = K_KP_LEFTARROW; break;
case SDLK_LEFT: key = K_LEFTARROW; break;
case SDLK_KP6: key = K_KP_RIGHTARROW; break;
case SDLK_RIGHT: key = K_RIGHTARROW; break;
case SDLK_KP2: key = K_KP_DOWNARROW; break;
case SDLK_DOWN: key = K_DOWNARROW; break;
case SDLK_KP8: key = K_KP_UPARROW; break;
case SDLK_UP: key = K_UPARROW; break;
case SDLK_ESCAPE: key = K_ESCAPE; break;
case SDLK_KP_ENTER: key = K_KP_ENTER; break;
case SDLK_RETURN: key = K_ENTER; break;
case SDLK_TAB: key = K_TAB; break;
case SDLK_F1: key = K_F1; break;
case SDLK_F2: key = K_F2; break;
case SDLK_F3: key = K_F3; break;
case SDLK_F4: key = K_F4; break;
case SDLK_F5: key = K_F5; break;
case SDLK_F6: key = K_F6; break;
case SDLK_F7: key = K_F7; break;
case SDLK_F8: key = K_F8; break;
case SDLK_F9: key = K_F9; break;
case SDLK_F10: key = K_F10; break;
case SDLK_F11: key = K_F11; break;
case SDLK_F12: key = K_F12; break;
case SDLK_BACKSPACE: key = K_BACKSPACE; break;
case SDLK_KP_PERIOD: key = K_KP_DEL; break;
case SDLK_DELETE: key = K_DEL; break;
case SDLK_PAUSE: key = K_PAUSE; break;
case SDLK_LSHIFT:
case SDLK_RSHIFT: key = K_SHIFT; break;
case SDLK_LCTRL:
case SDLK_RCTRL: key = K_CTRL; break;
case SDLK_LMETA:
case SDLK_RMETA:
case SDLK_LALT:
case SDLK_RALT: key = K_ALT; break;
case SDLK_KP5: key = K_KP_5; break;
case SDLK_INSERT: key = K_INS; break;
case SDLK_KP0: key = K_KP_INS; break;
case SDLK_KP_MULTIPLY: key = '*'; break;
case SDLK_KP_PLUS: key = K_KP_PLUS; break;
case SDLK_KP_MINUS: key = K_KP_MINUS; break;
case SDLK_KP_DIVIDE: key = K_KP_SLASH; break;
/* suggestions on how to handle this better would be appreciated */
case SDLK_WORLD_7: key = '`'; break;
default: /* assuming that the other sdl keys are mapped to ascii */
if (keysym < 128)
key = keysym;
break;
}
return key;
}
static unsigned char KeyStates[SDLK_LAST];
void GetEvent(SDL_Event *event)
{
unsigned int bstate;
unsigned int key;
switch(event->type) {
case SDL_MOUSEBUTTONDOWN:
if (event->button.button == 4) {
keyq[keyq_head].key = K_MWHEELUP;
keyq[keyq_head].down = true;
keyq_head = (keyq_head + 1) & 63;
keyq[keyq_head].key = K_MWHEELUP;
keyq[keyq_head].down = false;
keyq_head = (keyq_head + 1) & 63;
} else if (event->button.button == 5) {
keyq[keyq_head].key = K_MWHEELDOWN;
keyq[keyq_head].down = true;
keyq_head = (keyq_head + 1) & 63;
keyq[keyq_head].key = K_MWHEELDOWN;
keyq[keyq_head].down = false;
keyq_head = (keyq_head + 1) & 63;
}
break;
case SDL_MOUSEBUTTONUP:
break;
case SDL_KEYDOWN:
#if 0
if ( (KeyStates[SDLK_LALT] || KeyStates[SDLK_RALT]) &&
(event->key.keysym.sym == SDLK_RETURN) ) {
/* SDL_WM_ToggleFullScreen(surface); */
if (surface->flags & SDL_FULLSCREEN) {
ri.Cvar_SetValue( "vid_fullscreen", /*1*/ 0 );
} else {
ri.Cvar_SetValue( "vid_fullscreen", /*0*/ 1 );
}
break; /* ignore this key */
}
if ( (KeyStates[SDLK_LCTRL] || KeyStates[SDLK_RCTRL]) &&
(event->key.keysym.sym == SDLK_g) ) {
SDL_GrabMode gm = SDL_WM_GrabInput(SDL_GRAB_QUERY);
/*
SDL_WM_GrabInput((gm == SDL_GRAB_ON) ? SDL_GRAB_OFF : SDL_GRAB_ON);
gm = SDL_WM_GrabInput(SDL_GRAB_QUERY);
*/
ri.Cvar_SetValue( "_windowed_mouse", (gm == SDL_GRAB_ON) ? /*1*/ 0 : /*0*/ 1 );
break; /* ignore this key */
}
#endif
KeyStates[event->key.keysym.sym] = 1;
key = XLateKey(event->key.keysym.sym);
if (key) {
keyq[keyq_head].key = key;
keyq[keyq_head].down = true;
keyq_head = (keyq_head + 1) & 63;
}
break;
case SDL_KEYUP:
if (KeyStates[event->key.keysym.sym]) {
KeyStates[event->key.keysym.sym] = 0;
key = XLateKey(event->key.keysym.sym);
if (key) {
keyq[keyq_head].key = key;
keyq[keyq_head].down = false;
keyq_head = (keyq_head + 1) & 63;
}
}
break;
case SDL_QUIT:
ri.Cmd_ExecuteText(EXEC_NOW, "quit");
break;
}
}
/*****************************************************************************/
/*
** SWimp_Init
**
** This routine is responsible for initializing the implementation
** specific stuff in a software rendering subsystem.
*/
int SWimp_Init( void *hInstance, void *wndProc )
{
if (SDL_WasInit(SDL_INIT_AUDIO|SDL_INIT_CDROM|SDL_INIT_VIDEO) == 0) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
Sys_Error("SDL Init failed: %s\n", SDL_GetError());
return false;
}
} else if (SDL_WasInit(SDL_INIT_VIDEO) == 0) {
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
Sys_Error("SDL Init failed: %s\n", SDL_GetError());
return false;
}
}
// SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
// catch signals so i can turn on auto-repeat
#if 0
{
struct sigaction sa;
sigaction(SIGINT, 0, &sa);
sa.sa_handler = TragicDeath;
sigaction(SIGINT, &sa, 0);
sigaction(SIGTERM, &sa, 0);
}
#endif
return true;
}
#ifdef OPENGL
void *GLimp_GetProcAddress(const char *func)
{
return SDL_GL_GetProcAddress(func);
}
int GLimp_Init( void *hInstance, void *wndProc )
{
return SWimp_Init(hInstance, wndProc);
}
#endif
/*
** SWimp_InitGraphics
**
** This initializes the software refresh's implementation specific
** graphics subsystem. In the case of Windows it creates DIB or
** DDRAW surfaces.
**
** The necessary width and height parameters are grabbed from
** vid.width and vid.height.
*/
#ifndef OPENGL
static qboolean SWimp_InitGraphics( qboolean fullscreen )
{
const SDL_VideoInfo *vinfo;
int flags;
/* Just toggle fullscreen if that's all that has been changed */
if (surface && (surface->w == vid.width) && (surface->h == vid.height)) {
int isfullscreen = (surface->flags & SDL_FULLSCREEN) ? 1 : 0;
if (fullscreen != isfullscreen)
SDL_WM_ToggleFullScreen(surface);
isfullscreen = (surface->flags & SDL_FULLSCREEN) ? 1 : 0;
if (fullscreen == isfullscreen)
return true;
}
srandom(getpid());
// free resources in use
if (surface)
SDL_FreeSurface(surface);
// let the sound and input subsystems know about the new window
ri.Vid_NewWindow (vid.width, vid.height);
/*
Okay, I am going to query SDL for the "best" pixel format.
If the depth is not 8, use SetPalette with logical pal,
else use SetColors.
Hopefully this works all the time.
*/
vinfo = SDL_GetVideoInfo();
sdl_palettemode = (vinfo->vfmt->BitsPerPixel == 8) ? (SDL_PHYSPAL|SDL_LOGPAL) : SDL_LOGPAL;
flags = /*SDL_DOUBLEBUF|*/SDL_SWSURFACE|SDL_HWPALETTE;
if (fullscreen)
flags |= SDL_FULLSCREEN;
if ((surface = SDL_SetVideoMode(vid.width, vid.height, 8, flags)) == NULL) {
Sys_Error("(SOFTSDL) SDL SetVideoMode failed: %s\n", SDL_GetError());
return false;
}
SDL_WM_SetCaption("Quake II", "Quake II");
SDL_ShowCursor(0);
vid.rowbytes = surface->pitch;
vid.buffer = surface->pixels;
X11_active = true;
return true;
}
#else
static qboolean GLimp_InitGraphics( qboolean fullscreen )
{
int flags;
/* Just toggle fullscreen if that's all that has been changed */
if (surface && (surface->w == vid.width) && (surface->h == vid.height)) {
int isfullscreen = (surface->flags & SDL_FULLSCREEN) ? 1 : 0;
if (fullscreen != isfullscreen)
SDL_WM_ToggleFullScreen(surface);
isfullscreen = (surface->flags & SDL_FULLSCREEN) ? 1 : 0;
if (fullscreen == isfullscreen)
return true;
}
srandom(getpid());
// free resources in use
if (surface)
SDL_FreeSurface(surface);
// let the sound and input subsystems know about the new window
ri.Vid_NewWindow (vid.width, vid.height);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
flags = SDL_OPENGL;
if (fullscreen)
flags |= SDL_FULLSCREEN;
if ((surface = SDL_SetVideoMode(vid.width, vid.height, 0, flags)) == NULL) {
Sys_Error("(SDLGL) SDL SetVideoMode failed: %s\n", SDL_GetError());
return false;
}
SDL_WM_SetCaption("Quake II", "Quake II");
SDL_ShowCursor(0);
X11_active = true;
return true;
}
#endif
#ifdef OPENGL
void GLimp_BeginFrame( float camera_seperation )
{
}
#endif
/*
** SWimp_EndFrame
**
** This does an implementation specific copy from the backbuffer to the
** front buffer. In the Win32 case it uses BitBlt or BltFast depending
** on whether we're using DIB sections/GDI or DDRAW.
*/
#ifndef OPENGL
void SWimp_EndFrame (void)
{
/* SDL_Flip(surface); */
SDL_UpdateRect(surface, 0, 0, 0, 0);
}
#else
void GLimp_EndFrame (void)
{
SDL_GL_SwapBuffers();
}
#endif
/*
** SWimp_SetMode
*/
#ifndef OPENGL
rserr_t SWimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
{
rserr_t retval = rserr_ok;
ri.Con_Printf (PRINT_ALL, "setting mode %d:", mode );
if ( !ri.Vid_GetModeInfo( pwidth, pheight, mode ) )
{
ri.Con_Printf( PRINT_ALL, " invalid mode\n" );
return rserr_invalid_mode;
}
ri.Con_Printf( PRINT_ALL, " %d %d\n", *pwidth, *pheight);
if ( !SWimp_InitGraphics( fullscreen ) ) {
// failed to set a valid mode in windowed mode
return rserr_invalid_mode;
}
R_GammaCorrectAndSetPalette( ( const unsigned char * ) d_8to24table );
return retval;
}
#else
int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
{
ri.Con_Printf (PRINT_ALL, "setting mode %d:", mode );
if ( !ri.Vid_GetModeInfo( pwidth, pheight, mode ) )
{
ri.Con_Printf( PRINT_ALL, " invalid mode\n" );
return rserr_invalid_mode;
}
ri.Con_Printf( PRINT_ALL, " %d %d\n", *pwidth, *pheight);
if ( !GLimp_InitGraphics( fullscreen ) ) {
// failed to set a valid mode in windowed mode
return rserr_invalid_mode;
}
return rserr_ok;
}
#endif
/*
** SWimp_SetPalette
**
** System specific palette setting routine. A NULL palette means
** to use the existing palette. The palette is expected to be in
** a padded 4-byte xRGB format.
*/
#ifndef OPENGL
void SWimp_SetPalette( const unsigned char *palette )
{
SDL_Color colors[256];
int i;
if (!X11_active)
return;
if ( !palette )
palette = ( const unsigned char * ) sw_state.currentpalette;
for (i = 0; i < 256; i++) {
colors[i].r = palette[i*4+0];
colors[i].g = palette[i*4+1];
colors[i].b = palette[i*4+2];
}
SDL_SetPalette(surface, sdl_palettemode, colors, 0, 256);
}
#endif
/*
** SWimp_Shutdown
**
** System specific graphics subsystem shutdown routine. Destroys
** DIBs or DDRAW surfaces as appropriate.
*/
void SWimp_Shutdown( void )
{
if (surface)
SDL_FreeSurface(surface);
surface = NULL;
if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_VIDEO)
SDL_Quit();
else
SDL_QuitSubSystem(SDL_INIT_VIDEO);
X11_active = false;
}
#ifdef OPENGL
void GLimp_Shutdown( void )
{
SWimp_Shutdown();
}
#endif
/*
** SWimp_AppActivate
*/
#ifndef OPENGL
void SWimp_AppActivate( qboolean active )
{
}
#else
void GLimp_AppActivate( qboolean active )
{
}
#endif
//===============================================================================
/*
================
Sys_MakeCodeWriteable
================
*/
void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
{
int r;
unsigned long addr;
int psize = getpagesize();
addr = (startaddr & ~(psize-1)) - psize;
// fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr,
// addr, startaddr+length, length);
r = mprotect((char*)addr, length + startaddr - addr + psize, 7);
if (r < 0)
Sys_Error("Protection change failed\n");
}
/*****************************************************************************/
/* KEYBOARD */
/*****************************************************************************/
Key_Event_fp_t Key_Event_fp;
void KBD_Init(Key_Event_fp_t fp)
{
Key_Event_fp = fp;
}
void KBD_Update(void)
{
SDL_Event event;
static int KBD_Update_Flag;
if (KBD_Update_Flag == 1)
return;
KBD_Update_Flag = 1;
// get events from x server
if (X11_active)
{
int bstate;
while (SDL_PollEvent(&event))
GetEvent(&event);
if (!mx && !my)
SDL_GetRelativeMouseState(&mx, &my);
mouse_buttonstate = 0;
bstate = SDL_GetMouseState(NULL, NULL);
if (SDL_BUTTON(1) & bstate)
mouse_buttonstate |= (1 << 0);
if (SDL_BUTTON(2) & bstate)
mouse_buttonstate |= (1 << 1);
if (SDL_BUTTON(3) & bstate)
mouse_buttonstate |= (1 << 2);
if (old_windowed_mouse != _windowed_mouse->value) {
old_windowed_mouse = _windowed_mouse->value;
if (!_windowed_mouse->value) {
/* ungrab the pointer */
SDL_WM_GrabInput(SDL_GRAB_OFF);
} else {
/* grab the pointer */
SDL_WM_GrabInput(SDL_GRAB_ON);
}
}
while (keyq_head != keyq_tail)
{
Key_Event_fp(keyq[keyq_tail].key, keyq[keyq_tail].down);
keyq_tail = (keyq_tail + 1) & 63;
}
}
KBD_Update_Flag = 0;
}
void KBD_Close(void)
{
keyq_head = 0;
keyq_tail = 0;
memset(keyq, 0, sizeof(keyq));
}
#ifdef OPENGL
void Fake_glColorTableEXT( GLenum target, GLenum internalformat,
GLsizei width, GLenum format, GLenum type,
const GLvoid *table )
{
byte temptable[256][4];
byte *intbl;
int i;
for (intbl = (byte *)table, i = 0; i < 256; i++) {
temptable[i][2] = *intbl++;
temptable[i][1] = *intbl++;
temptable[i][0] = *intbl++;
temptable[i][3] = 255;
}
qgl3DfxSetPaletteEXT((GLuint *)temptable);
}
#endif

View file

@ -318,7 +318,13 @@ void RW_IN_Init(in_state_t *in_state_p)
void RW_IN_Shutdown(void)
{
mouse_avail = false;
if (mouse_avail) {
mouse_avail = false;
ri.Cmd_RemoveCommand ("+mlook");
ri.Cmd_RemoveCommand ("-mlook");
ri.Cmd_RemoveCommand ("force_centerview");
}
}
/*
@ -732,6 +738,8 @@ int XLateKey(XKeyEvent *ev)
key = *(unsigned char*)buf;
if (key >= 'A' && key <= 'Z')
key = key - 'A' + 'a';
if (key >= 1 && key <= 26) /* ctrl+alpha */
key = key + 'a' - 1;
break;
}
@ -972,6 +980,7 @@ static qboolean SWimp_InitGraphics( qboolean fullscreen )
{
int attribmask = CWEventMask | CWColormap | CWBorderPixel;
XSetWindowAttributes attribs;
XSizeHints *sizehints;
Colormap tmpcmap;
tmpcmap = XCreateColormap(dpy, root, x_vis, AllocNone);
@ -984,6 +993,24 @@ static qboolean SWimp_InitGraphics( qboolean fullscreen )
win = XCreateWindow(dpy, root, (int)vid_xpos->value, (int)vid_ypos->value,
vid.width, vid.height, 0, x_visinfo->depth, InputOutput, x_vis,
attribmask, &attribs );
sizehints = XAllocSizeHints();
if (sizehints) {
sizehints->min_width = vid.width;
sizehints->min_height = vid.height;
sizehints->max_width = vid.width;
sizehints->max_height = vid.height;
sizehints->base_width = vid.width;
sizehints->base_height = vid.height;
sizehints->flags = PMinSize | PMaxSize | PBaseSize;
}
XSetWMProperties(dpy, win, NULL, NULL, NULL, 0,
sizehints, None, None);
if (sizehints)
XFree(sizehints);
XStoreName(dpy, win, "Quake II");
if (x_visinfo->class != TrueColor)
@ -1030,11 +1057,16 @@ static qboolean SWimp_InitGraphics( qboolean fullscreen )
displayname = (char *) getenv("DISPLAY");
if (displayname)
{
char *d = displayname;
char *dptr = strdup(displayname);
char *d;
d = dptr;
while (*d && (*d != ':')) d++;
if (*d) *d = 0;
if (!(!strcasecmp(displayname, "unix") || !*displayname))
doShm = false;
free(dptr);
}
}

182
linux/snd_sdl.c Normal file
View file

@ -0,0 +1,182 @@
/*
snd_sdl.c
Sound code taken from SDLQuake and modified to work with Quake2
Robert Bäuml 2001-12-25
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.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#include "SDL.h"
#include "../client/client.h"
#include "../client/snd_loc.h"
static int snd_inited;
static dma_t *shm;
static void
paint_audio (void *unused, Uint8 * stream, int len)
{
if (shm) {
shm->buffer = stream;
shm->samplepos += len / (shm->samplebits / 4);
// Check for samplepos overflow?
S_PaintChannels (shm->samplepos);
}
}
qboolean
SNDDMA_Init (void)
{
SDL_AudioSpec desired, obtained;
int desired_bits, freq;
if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
Com_Printf ("Couldn't init SDL audio: %s\n", SDL_GetError ());
return 0;
}
} else if (SDL_WasInit(SDL_INIT_AUDIO) == 0) {
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
Com_Printf ("Couldn't init SDL audio: %s\n", SDL_GetError ());
return 0;
}
}
snd_inited = 0;
desired_bits = (Cvar_Get("sndbits", "16", CVAR_ARCHIVE))->value;
/* Set up the desired format */
freq = (Cvar_Get("s_khz", "0", CVAR_ARCHIVE))->value;
if (freq == 44)
desired.freq = 44100;
else if (freq == 22)
desired.freq = 22050;
else
desired.freq = 11025;
switch (desired_bits) {
case 8:
desired.format = AUDIO_U8;
break;
case 16:
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
desired.format = AUDIO_S16MSB;
else
desired.format = AUDIO_S16LSB;
break;
default:
Com_Printf ("Unknown number of audio bits: %d\n", desired_bits);
return 0;
}
desired.channels = (Cvar_Get("sndchannels", "2", CVAR_ARCHIVE))->value;
if (desired.freq == 44100)
desired.samples = 1024;
else
desired.samples = 512;
desired.callback = paint_audio;
/* Open the audio device */
if (SDL_OpenAudio (&desired, &obtained) < 0) {
Com_Printf ("Couldn't open SDL audio: %s\n", SDL_GetError ());
return 0;
}
/* Make sure we can support the audio format */
switch (obtained.format) {
case AUDIO_U8:
/* Supported */
break;
case AUDIO_S16LSB:
case AUDIO_S16MSB:
if (((obtained.format == AUDIO_S16LSB) &&
(SDL_BYTEORDER == SDL_LIL_ENDIAN)) ||
((obtained.format == AUDIO_S16MSB) &&
(SDL_BYTEORDER == SDL_BIG_ENDIAN))) {
/* Supported */
break;
}
/* Unsupported, fall through */ ;
default:
/* Not supported -- force SDL to do our bidding */
SDL_CloseAudio ();
if (SDL_OpenAudio (&desired, NULL) < 0) {
Com_Printf ("Couldn't open SDL audio: %s\n", SDL_GetError ());
return 0;
}
memcpy (&obtained, &desired, sizeof (desired));
break;
}
SDL_PauseAudio (0);
/* Fill the audio DMA information block */
shm = &dma;
shm->samplebits = (obtained.format & 0xFF);
shm->speed = obtained.freq;
shm->channels = obtained.channels;
shm->samples = obtained.samples * shm->channels;
shm->samplepos = 0;
shm->submission_chunk = 1;
shm->buffer = NULL;
snd_inited = 1;
return 1;
}
int
SNDDMA_GetDMAPos (void)
{
return shm->samplepos;
}
void
SNDDMA_Shutdown (void)
{
if (snd_inited) {
SDL_CloseAudio ();
snd_inited = 0;
}
if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_AUDIO)
SDL_Quit();
else
SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
/*
SNDDMA_Submit
Send sound to device if buffer isn't really the dma buffer
*/
void
SNDDMA_Submit (void)
{
}
void SNDDMA_BeginPainting(void)
{
}

View file

@ -69,7 +69,7 @@ void Sys_Printf (char *fmt, ...)
unsigned char *p;
va_start (argptr,fmt);
vsprintf (text,fmt,argptr);
vsnprintf (text,1024,fmt,argptr);
va_end (argptr);
if (strlen(text) > sizeof(text))
@ -114,7 +114,7 @@ void Sys_Error (char *error, ...)
Qcommon_Shutdown ();
va_start (argptr,error);
vsprintf (string,error,argptr);
vsnprintf (string,1024,error,argptr);
va_end (argptr);
fprintf(stderr, "Error: %s\n", string);
@ -128,7 +128,7 @@ void Sys_Warn (char *warning, ...)
char string[1024];
va_start (argptr,warning);
vsprintf (string,warning,argptr);
vsnprintf (string,1024,warning,argptr);
va_end (argptr);
fprintf(stderr, "Warning: %s", string);
}
@ -217,12 +217,13 @@ void *Sys_GetGameAPI (void *parms)
void *(*GetGameAPI) (void *);
char name[MAX_OSPATH];
char curpath[MAX_OSPATH];
char *path;
#ifdef __i386__
#if defined __i386__
const char *gamename = "gamei386.so";
#elif defined __alpha__
const char *gamename = "gameaxp.so";
#elif defined __powerpc__
const char *gamename = "gameppc.so";
#else
#error Unknown arch
#endif
@ -233,8 +234,6 @@ void *Sys_GetGameAPI (void *parms)
if (game_library)
Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame");
getcwd(curpath, sizeof(curpath));
Com_Printf("------- Loading %s -------\n", gamename);
// now run through the search paths
@ -244,16 +243,19 @@ void *Sys_GetGameAPI (void *parms)
path = FS_NextPath (path);
if (!path)
return NULL; // couldn't find one anywhere
sprintf (name, "%s/%s/%s", curpath, path, gamename);
game_library = dlopen (name, RTLD_LAZY );
snprintf (name, MAX_OSPATH, "%s/%s", path, gamename);
game_library = dlopen (name, RTLD_NOW );
if (game_library)
{
Com_Printf ("LoadLibrary (%s)\n",name);
Com_DPrintf ("LoadLibrary (%s)\n",name);
break;
} else {
Com_DPrintf ("LoadLibrary (%s) failed\n", name, dlerror());
}
}
GetGameAPI = (void *)dlsym (game_library, "GetGameAPI");
if (!GetGameAPI)
{
Sys_UnloadGame ();
@ -319,6 +321,7 @@ int main (int argc, char **argv)
}
#if 0
void Sys_CopyProtect(void)
{
FILE *mnt;
@ -369,6 +372,7 @@ void Sys_CopyProtect(void)
Com_Error (ERR_FATAL, "Unable to find a mounted iso9660 file system.\n"
"You must mount the Quake2 CD in a cdrom drive in order to play.");
}
#endif
#if 0
/*

View file

@ -22,10 +22,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define REF_SOFT 0
#define REF_SOFTX11 1
#define REF_MESA3D 2
#define REF_3DFXGL 3
#define REF_OPENGLX 4
#define REF_MESA3DGLX 5
#define REF_SOFTSDL 2
#define REF_GLX 3
#define REF_SDLGL 4
#define REF_FXGL 5
#define GL_REF_START REF_GLX
extern cvar_t *vid_ref;
extern cvar_t *vid_fullscreen;
@ -75,7 +77,7 @@ static void DriverCallback( void *unused )
{
s_ref_list[!s_current_menu_index].curvalue = s_ref_list[s_current_menu_index].curvalue;
if ( s_ref_list[s_current_menu_index].curvalue < 2 )
if ( s_ref_list[s_current_menu_index].curvalue < GL_REF_START )
{
s_current_menu = &s_software_menu;
s_current_menu_index = 0;
@ -105,7 +107,8 @@ static void BrightnessCallback( void *s )
s_brightness_slider[0].curvalue = s_brightness_slider[1].curvalue;
if ( stricmp( vid_ref->string, "soft" ) == 0 ||
stricmp( vid_ref->string, "softx" ) == 0 )
stricmp( vid_ref->string, "softx" ) == 0 ||
stricmp( vid_ref->string, "softsdl" ) == 0 )
{
float gamma = ( 0.8 - ( slider->curvalue/10.0 - 0.5 ) ) + 0.5;
@ -151,31 +154,18 @@ static void ApplyChanges( void *unused )
case REF_SOFTX11:
Cvar_Set( "vid_ref", "softx" );
break;
case REF_MESA3D :
Cvar_Set( "vid_ref", "gl" );
Cvar_Set( "gl_driver", "libMesaGL.so.2" );
if (gl_driver->modified)
vid_ref->modified = true;
case REF_SOFTSDL:
Cvar_Set( "vid_ref", "softsdl" );
break;
case REF_OPENGLX :
case REF_GLX:
Cvar_Set( "vid_ref", "glx" );
Cvar_Set( "gl_driver", "libGL.so" );
if (gl_driver->modified)
vid_ref->modified = true;
break;
case REF_MESA3DGLX :
Cvar_Set( "vid_ref", "glx" );
Cvar_Set( "gl_driver", "libMesaGL.so.2" );
if (gl_driver->modified)
vid_ref->modified = true;
break;
case REF_3DFXGL :
Cvar_Set( "vid_ref", "gl" );
Cvar_Set( "gl_driver", "lib3dfxgl.so" );
case REF_SDLGL:
Cvar_Set( "vid_ref", "sdlgl" );
Cvar_Set( "gl_driver", "libGL.so" );
if (gl_driver->modified)
vid_ref->modified = true;
break;
@ -228,17 +218,15 @@ void VID_MenuInit( void )
"[1152 864 ]",
"[1280 1024]",
"[1600 1200]",
"[2048 1536]",
0
};
static const char *refs[] =
{
"[software ]",
"[software X11 ]",
"[Mesa 3-D 3DFX ]",
"[3DFXGL Miniport]",
"[OpenGL glX ]",
"[Mesa 3-D glX ]",
"[software ]",
"[software X11 ]",
"[software SDL ]",
"[OpenGL GLX ]",
"[SDL OpenGL ]",
0
};
static const char *yesno_names[] =
@ -250,7 +238,7 @@ void VID_MenuInit( void )
int i;
if ( !gl_driver )
gl_driver = Cvar_Get( "gl_driver", "libMesaGL.so.2", 0 );
gl_driver = Cvar_Get( "gl_driver", "libGL.so", 0 );
if ( !gl_picmip )
gl_picmip = Cvar_Get( "gl_picmip", "0", 0 );
if ( !gl_mode )
@ -264,7 +252,7 @@ void VID_MenuInit( void )
sw_stipplealpha = Cvar_Get( "sw_stipplealpha", "0", CVAR_ARCHIVE );
if ( !_windowed_mouse)
_windowed_mouse = Cvar_Get( "_windowed_mouse", "0", CVAR_ARCHIVE );
_windowed_mouse = Cvar_Get( "_windowed_mouse", "0", CVAR_ARCHIVE );
s_mode_list[SOFTWARE_MENU].curvalue = sw_mode->value;
s_mode_list[OPENGL_MENU].curvalue = gl_mode->value;
@ -285,21 +273,40 @@ void VID_MenuInit( void )
s_current_menu_index = SOFTWARE_MENU;
s_ref_list[0].curvalue = s_ref_list[1].curvalue = REF_SOFTX11;
}
else if ( strcmp( vid_ref->string, "gl" ) == 0 )
else if (strcmp( vid_ref->string, "softsdl" ) == 0 )
{
s_current_menu_index = OPENGL_MENU;
if ( strcmp( gl_driver->string, "lib3dfxgl.so" ) == 0 )
s_ref_list[s_current_menu_index].curvalue = REF_3DFXGL;
else
s_ref_list[s_current_menu_index].curvalue = REF_MESA3D;
s_current_menu_index = SOFTWARE_MENU;
s_ref_list[0].curvalue = s_ref_list[1].curvalue = REF_SOFTSDL;
}
else if ( strcmp( vid_ref->string, "glx" ) == 0 )
{
s_current_menu_index = OPENGL_MENU;
if ( strcmp( gl_driver->string, "libMesaGL.so.2" ) == 0 )
s_ref_list[s_current_menu_index].curvalue = REF_MESA3DGLX;
s_ref_list[s_current_menu_index].curvalue = REF_GLX;
#if 0
if ( strcmp( gl_driver->string, "3dfxgl" ) == 0 )
s_ref_list[s_current_menu_index].curvalue = REF_3DFX;
else if ( strcmp( gl_driver->string, "pvrgl" ) == 0 )
s_ref_list[s_current_menu_index].curvalue = REF_POWERVR;
else if ( strcmp( gl_driver->string, "opengl32" ) == 0 )
s_ref_list[s_current_menu_index].curvalue = REF_OPENGL;
else
s_ref_list[s_current_menu_index].curvalue = REF_OPENGLX;
s_ref_list[s_current_menu_index].curvalue = REF_VERITE;
#endif
}
else if ( strcmp( vid_ref->string, "sdlgl" ) == 0 )
{
s_current_menu_index = OPENGL_MENU;
s_ref_list[s_current_menu_index].curvalue = REF_SDLGL;
#if 0
if ( strcmp( gl_driver->string, "3dfxgl" ) == 0 )
s_ref_list[s_current_menu_index].curvalue = REF_3DFX;
else if ( strcmp( gl_driver->string, "pvrgl" ) == 0 )
s_ref_list[s_current_menu_index].curvalue = REF_POWERVR;
else if ( strcmp( gl_driver->string, "opengl32" ) == 0 )
s_ref_list[s_current_menu_index].curvalue = REF_OPENGL;
else
s_ref_list[s_current_menu_index].curvalue = REF_VERITE;
#endif
}
s_software_menu.x = viddef.width * 0.50;
@ -484,5 +491,3 @@ const char *VID_MenuKey( int key )
return sound;
}

View file

@ -49,8 +49,6 @@ qboolean reflib_active = 0;
#define VID_NUM_MODES ( sizeof( vid_modes ) / sizeof( vid_modes[0] ) )
const char so_file[] = "/etc/quake2.conf";
/** KEYBOARD **************************************************************/
void Do_Key_Event(int key, qboolean down);
@ -87,7 +85,7 @@ void VID_Printf (int print_level, char *fmt, ...)
char msg[MAXPRINTMSG];
va_start (argptr,fmt);
vsprintf (msg,fmt,argptr);
vsnprintf (msg,MAXPRINTMSG,fmt,argptr);
va_end (argptr);
if (print_level == PRINT_ALL)
@ -102,7 +100,7 @@ void __attribute__((noreturn)) VID_Error (int err_level, char *fmt, ...)
char msg[MAXPRINTMSG];
va_start (argptr,fmt);
vsprintf (msg,fmt,argptr);
vsnprintf (msg,MAXPRINTMSG,fmt,argptr);
va_end (argptr);
Com_Error (err_level,"%s", msg);
@ -204,6 +202,7 @@ qboolean VID_LoadRefresh( char *name )
refimport_t ri;
GetRefAPI_t GetRefAPI;
char fn[MAX_OSPATH];
char *path;
struct stat st;
extern uid_t saved_euid;
FILE *fp;
@ -225,6 +224,7 @@ qboolean VID_LoadRefresh( char *name )
//regain root
seteuid(saved_euid);
#if 0
if ((fp = fopen(so_file, "r")) == NULL) {
Com_Printf( "LoadLibrary(\"%s\") failed: can't open %s (required for location of ref libraries)\n", name, so_file);
return false;
@ -236,13 +236,22 @@ qboolean VID_LoadRefresh( char *name )
strcat(fn, "/");
strcat(fn, name);
#endif
path = Cvar_Get ("basedir", ".", CVAR_NOSET)->string;
snprintf (fn, MAX_OSPATH, "%s/%s", path, name );
if (stat(fn, &st) == -1) {
Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name, strerror(errno));
return false;
}
// permission checking
if (strstr(fn, "softx") == NULL) { // softx doesn't require root
if (stat(fn, &st) == -1) {
Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name, strerror(errno));
return false;
}
if (strstr(fn, "softx") == NULL &&
strstr(fn, "glx") == NULL &&
strstr(fn, "softsdl") == NULL &&
strstr(fn, "sdlgl") == NULL) { // softx doesn't require root
#if 0
if (st.st_uid != 0) {
Com_Printf( "LoadLibrary(\"%s\") failed: ref is not owned by root\n", name);
@ -337,6 +346,8 @@ qboolean VID_LoadRefresh( char *name )
#endif
KBD_Init_fp(Do_Key_Event);
Key_ClearStates();
// give up root now
setreuid(getuid(), getuid());
setegid(getgid());
@ -391,7 +402,11 @@ Com_Printf("Trying mode 0\n");
Com_Error (ERR_FATAL, "Couldn't fall back to software refresh!");
}
Cvar_Set( "vid_ref", "soft" );
/* prefer to fall back on X if active */
if (getenv("DISPLAY"))
Cvar_Set( "vid_ref", "softx" );
else
Cvar_Set( "vid_ref", "soft" );
/*
** drop the console if we fail to load a refresh

View file

@ -104,7 +104,7 @@ void Com_Printf (char *fmt, ...)
char msg[MAXPRINTMSG];
va_start (argptr,fmt);
vsprintf (msg,fmt,argptr);
vsnprintf (msg,MAXPRINTMSG,fmt,argptr);
va_end (argptr);
if (rd_target)
@ -160,7 +160,7 @@ void Com_DPrintf (char *fmt, ...)
return; // don't confuse non-developers with techie stuff...
va_start (argptr,fmt);
vsprintf (msg,fmt,argptr);
vsnprintf (msg,MAXPRINTMSG,fmt,argptr);
va_end (argptr);
Com_Printf ("%s", msg);
@ -186,7 +186,7 @@ void Com_Error (int code, char *fmt, ...)
recursive = true;
va_start (argptr,fmt);
vsprintf (msg,fmt,argptr);
vsnprintf (msg,MAXPRINTMSG,fmt,argptr);
va_end (argptr);
if (code == ERR_DISCONNECT)

View file

@ -506,7 +506,7 @@ pack_t *FS_LoadPackFile (char *packfile)
================
FS_AddGameDirectory
Sets fs_gamedir, adds the directory to the head of the path,
Adds the directory to the head of the path,
then loads and adds pak1.pak pak2.pak ...
================
*/
@ -517,10 +517,8 @@ void FS_AddGameDirectory (char *dir)
pack_t *pak;
char pakfile[MAX_OSPATH];
strcpy (fs_gamedir, dir);
//
// add the directory to the search path
// add the base directory to the search path
//
search = Z_Malloc (sizeof(searchpath_t));
strcpy (search->filename, dir);
@ -541,8 +539,6 @@ void FS_AddGameDirectory (char *dir)
search->next = fs_searchpaths;
fs_searchpaths = search;
}
}
/*
@ -554,10 +550,7 @@ Called to find where to write a file (demos, savegames, etc)
*/
char *FS_Gamedir (void)
{
if (*fs_gamedir)
return fs_gamedir;
else
return BASEDIRNAME;
return fs_gamedir;
}
/*
@ -569,15 +562,45 @@ void FS_ExecAutoexec (void)
{
char *dir;
char name [MAX_QPATH];
char command [MAX_QPATH];
char newpath [MAX_QPATH];
searchpath_t *s;
dir = Cvar_VariableString("gamedir");
if (*dir)
Com_sprintf(name, sizeof(name), "%s/%s/autoexec.cfg", fs_basedir->string, dir);
else
Com_sprintf(name, sizeof(name), "%s/%s/autoexec.cfg", fs_basedir->string, BASEDIRNAME);
if (Sys_FindFirst(name, 0, SFF_SUBDIR | SFF_HIDDEN | SFF_SYSTEM))
Cbuf_AddText ("exec autoexec.cfg\n");
Sys_FindClose();
// search through all the paths for an autoexec.cfg file
for (s = fs_searchpaths ; s ; s = s->next)
{
if (s->pack)
continue;
strcpy (newpath, s->filename);
// eat the last '/'
if (newpath[strlen(newpath) - 1] == '/')
newpath[strlen(newpath) - 1] = '\0';
if (*dir)
{
// skip when current search path and gamedir are equal
if(!strncmp(dir, newpath + 2, strlen(dir)))
Com_sprintf(name, sizeof(name), "%s/autoexec.cfg", newpath);
else
Com_sprintf(name, sizeof(name), "%s/%s/autoexec.cfg", newpath, dir);
}
else
Com_sprintf(name, sizeof(name), "%s/autoexec.cfg", newpath);
if (Sys_FindFirst(name, 0, SFF_SUBDIR | SFF_HIDDEN | SFF_SYSTEM))
{
strcpy (command, "exec ");
strcat (command, name);
Cbuf_AddText (command);
Sys_FindClose();
break;
}
Sys_FindClose();
}
}
@ -586,6 +609,7 @@ void FS_ExecAutoexec (void)
FS_SetGamedir
Sets the gamedir and path to a different directory.
================
*/
void FS_SetGamedir (char *dir)
@ -623,6 +647,7 @@ void FS_SetGamedir (char *dir)
Com_sprintf (fs_gamedir, sizeof(fs_gamedir), "%s/%s", fs_basedir->string, dir);
// now add new entries for
if (!strcmp(dir,BASEDIRNAME) || (*dir == 0))
{
Cvar_FullSet ("gamedir", "", CVAR_SERVERINFO|CVAR_NOSET);
@ -863,10 +888,18 @@ void FS_InitFilesystem (void)
FS_AddGameDirectory (va("%s/"BASEDIRNAME, fs_cddir->string) );
//
// start up with baseq2 by default
// add baseq2 to search path
//
FS_AddGameDirectory (va("%s/"BASEDIRNAME, fs_basedir->string) );
//
// then add a '.quake2/baseq2' directory in home directory by default
//
strcpy (fs_gamedir, getenv("HOME"));
strcat (fs_gamedir, "/.quake2/baseq2/");
FS_CreatePath (fs_gamedir);
FS_AddGameDirectory (fs_gamedir);
// any set gamedirs will be freed up to here
fs_base_searchpaths = fs_searchpaths;
@ -875,6 +908,3 @@ void FS_InitFilesystem (void)
if (fs_gamedirvar->string[0])
FS_SetGamedir (fs_gamedirvar->string);
}

View file

@ -135,7 +135,7 @@ void Netchan_OutOfBandPrint (int net_socket, netadr_t adr, char *format, ...)
static char string[MAX_MSGLEN - 4];
va_start (argptr, format);
vsprintf (string, format,argptr);
vsnprintf (string, MAX_MSGLEN - 4, format, argptr);
va_end (argptr);
Netchan_OutOfBand (net_socket, adr, strlen(string), (byte *)string);

View file

@ -25,14 +25,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#include <math.h>
/*
#ifndef __linux__
#ifndef GL_COLOR_INDEX8_EXT
#define GL_COLOR_INDEX8_EXT GL_COLOR_INDEX
#endif
#endif
*/
#include "../client/ref.h"

View file

@ -1017,7 +1017,11 @@ void R_Register( void )
gl_flashblend = ri.Cvar_Get ("gl_flashblend", "0", 0);
gl_playermip = ri.Cvar_Get ("gl_playermip", "0", 0);
gl_monolightmap = ri.Cvar_Get( "gl_monolightmap", "0", 0 );
#ifdef _WIN32
gl_driver = ri.Cvar_Get( "gl_driver", "opengl32", CVAR_ARCHIVE );
#else
gl_driver = ri.Cvar_Get( "gl_driver", "libGL.so", CVAR_ARCHIVE );
#endif
gl_texturemode = ri.Cvar_Get( "gl_texturemode", "GL_LINEAR_MIPMAP_NEAREST", CVAR_ARCHIVE );
gl_texturealphamode = ri.Cvar_Get( "gl_texturealphamode", "default", CVAR_ARCHIVE );
gl_texturesolidmode = ri.Cvar_Get( "gl_texturesolidmode", "default", CVAR_ARCHIVE );
@ -1058,13 +1062,14 @@ qboolean R_SetMode (void)
rserr_t err;
qboolean fullscreen;
#ifdef _WIN32
if ( vid_fullscreen->modified && !gl_config.allow_cds )
{
ri.Con_Printf( PRINT_ALL, "R_SetMode() - CDS not allowed with this driver\n" );
ri.Cvar_SetValue( "vid_fullscreen", !vid_fullscreen->value );
vid_fullscreen->modified = false;
}
#endif
fullscreen = vid_fullscreen->value;
vid_fullscreen->modified = false;
@ -1245,11 +1250,12 @@ qboolean R_Init( void *hinstance, void *hWnd )
gl_config.allow_cds = true;
}
#ifdef _WIN32
if ( gl_config.allow_cds )
ri.Con_Printf( PRINT_ALL, "...allowing CDS\n" );
else
ri.Con_Printf( PRINT_ALL, "...disabling CDS\n" );
#endif
/*
** grab extensions
*/