summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2008-05-05 21:18:52 +0000
committerAndrey Nazarov <skuller@skuller.net>2008-05-05 21:18:52 +0000
commit0bd55fbf794d11385bcc64b01b81e8e478295bad (patch)
treeab548c3ad37fc13c555a5cca9da4348f3e35d84c
parent49e6170b49fbb933eddec6d0e3f946320c68832f (diff)
Brought SDL window resizing policy in compliance to ICCCM.
Renamed `vid_placement' cvar to `vid_geometry'. Load *.pkz files by default. Do not allow backed-up quake paths at all. Apply `--enable-dsound' and `--enable-dinput' options to Unix too. Replaced `s_driver' and `in_driver' cvars with `s_direct' and `in_direct'. Renamed `s_initsound' cva to `s_enable'. Improved SDL input grabs handling in windowed mode. Allow `cl_noskins' to be dynamically changed. Run client at 10 fps if minimuzed, at 60 fps if not active (client is disconnected or in background). Fixed Sys_ExecDefault. Use absolute mouse positioning for UI. Hide custom UI cursor in windowed mode.
-rw-r--r--build/q2pro.mk10
-rwxr-xr-xconfigure144
-rw-r--r--debian/control9
-rwxr-xr-xdebian/rules2
-rw-r--r--source/cl_ents.c4
-rw-r--r--source/cl_fx.c16
-rw-r--r--source/cl_input.c1384
-rw-r--r--source/cl_keys.c20
-rw-r--r--source/cl_local.h23
-rw-r--r--source/cl_main.c73
-rw-r--r--source/cl_null.c2
-rw-r--r--source/cl_parse.c50
-rw-r--r--source/cl_ref.c56
-rw-r--r--source/cl_scrn.c6
-rw-r--r--source/cl_ui.c6
-rw-r--r--source/com_local.h15
-rw-r--r--source/common.c2
-rw-r--r--source/files.c32
-rw-r--r--source/gl_main.c4
-rw-r--r--source/gl_models.c2
-rw-r--r--source/in_dx.c78
-rw-r--r--source/in_evdev.c102
-rw-r--r--source/in_public.h17
-rw-r--r--source/q_files.h546
-rw-r--r--source/q_list.h2
-rw-r--r--source/ref_public.h7
-rw-r--r--source/snd_main.c127
-rw-r--r--source/snd_oss.c4
-rw-r--r--source/snd_public.h2
-rw-r--r--source/snd_sdl.c2
-rw-r--r--source/sv_main.c8
-rw-r--r--source/sw_edge.c2
-rw-r--r--source/sw_model.c2
-rw-r--r--source/sw_surf.c2
-rw-r--r--source/sys_unix.c72
-rw-r--r--source/ui_atoms.c43
-rw-r--r--source/ui_public.h4
-rw-r--r--source/vid_local.h28
-rw-r--r--source/vid_public.h13
-rw-r--r--source/vid_sdl.c677
-rw-r--r--source/vid_win.c128
-rw-r--r--source/win_glimp.c4
-rw-r--r--source/win_local.h2
-rw-r--r--source/win_swimp.c4
44 files changed, 1835 insertions, 1901 deletions
diff --git a/build/q2pro.mk b/build/q2pro.mk
index 1a3fc6e..3a5737a 100644
--- a/build/q2pro.mk
+++ b/build/q2pro.mk
@@ -93,16 +93,12 @@ endif
ifdef MINGW
-SRCFILES+=sys_win.c vid_win.c win_glimp.c win_wgl.c
+SRCFILES+=sys_win.c snd_wave.c vid_win.c win_glimp.c win_wgl.c
ifndef REF_HARD_LINKED
SRCFILES+=win_swimp.c
endif
-ifdef USE_WAVE
-SRCFILES+=snd_wave.c
-endif
-
ifdef USE_DSOUND
SRCFILES+=snd_dx.c
endif
@@ -119,11 +115,11 @@ else # MINGW
SRCFILES+=sys_unix.c
-ifdef USE_OSS
+ifdef USE_DSOUND
SRCFILES+=snd_oss.c
endif
-ifdef USE_EVDEV
+ifdef USE_DINPUT
SRCFILES+=in_evdev.c
endif
diff --git a/configure b/configure
index ad24495..b3c778d 100755
--- a/configure
+++ b/configure
@@ -35,10 +35,7 @@ sdlconfig="sdl-config"
exesuffix=""
libsuffix=".so"
dsound="no"
-wave="???"
dinput="no"
-oss="no"
-evdev="no"
zlib="yes"
png="no"
jpeg="no"
@@ -56,13 +53,14 @@ targets=""
executables=""
libraries=""
hardlink="no"
-asm="no"
+asm="???"
+cpu=""
anticheat="no"
singleuser="no"
gldriver="libGL.so.1"
indriver=""
homedir="~/.q2pro"
-defcfg="/etc/default/q2pro"
+sitecfg="/etc/default/q2pro"
asmflags=""
logfile="console.log"
cfgfile="config.cfg"
@@ -82,49 +80,6 @@ if [ -z "$CFLAGS" ]; then
CFLAGS="-O2 -Wall -Wstrict-prototypes"
fi
-# detect host CPU
-cpu=`uname -m`
-case $cpu in
-i386|i486|i586|i686)
-cpu="i386"
-asm="yes"
-CFLAGS="-ffloat-store -ffast-math $CFLAGS"
-;;
-ia64)
-cpu="ia64"
-;;
-x86_64|amd64)
-cpu="x86_64"
-;;
-arm*)
-cpu="arm"
-;;
-*)
-cpu="unknown"
-;;
-esac
-
-# detect host OS
-targetos=`uname -s`
-case $targetos in
-CYGWIN*)
-mingw="yes"
-CFLAGS="-mno-cygwin $CFLAGS"
-;;
-MINGW*)
-mingw="yes"
-;;
-*BSD)
-make="gmake"
-oss="yes"
-;;
-Linux)
-oss="yes"
-evdev="yes"
-dl="yes"
-;;
-esac
-
#parse options
for opt do
case $opt in
@@ -138,6 +93,8 @@ for opt do
;;
--enable-mingw) mingw="yes" ; sdl="no"
;;
+ --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
+ ;;
--cc=*) cc=`echo $opt | cut -d '=' -f 2`
;;
--make=*) make=`echo $opt | cut -d '=' -f 2`
@@ -158,10 +115,6 @@ for opt do
;;
--enable-dinput) dinput="yes"
;;
- --disable-wave) wave="no"
- ;;
- --disable-oss) oss="no"
- ;;
--disable-zlib) zlib="no"
;;
--enable-png) png="yes"
@@ -205,11 +158,8 @@ echo " --disable-client do not build client"
echo " --enable-server build dedicated server"
echo " --enable-openffa build OpenFFA deathmatch mod"
echo " --enable-mingw enable Windows build"
-echo " --enable-dsound enable DirectSound driver"
-echo " --enable-dinput enable DirectInput driver"
-echo " --disable-wave disable WAVE sound driver"
-echo " --disable-oss disable OSS driver"
-echo " --disable-evdev disable Evdev driver"
+echo " --enable-dsound enable direct sound driver"
+echo " --enable-dinput enable direct input driver"
echo " --disable-zlib disable linking with zlib"
echo " --enable-png enable linking with PNG library"
echo " --enable-jpeg enable linking with JPEG library"
@@ -228,6 +178,50 @@ echo "Object files are built in the directory from which configure is run."
exit 1
fi
+# detect host CPU
+if [ -z "$cpu" ] ; then
+ cpu=`uname -m`
+fi
+case $cpu in
+i386|i486|i586|i686)
+cpu="i386"
+if [ "$asm" != "no" ] ; then
+ asm="yes"
+fi
+CFLAGS="-ffloat-store -ffast-math $CFLAGS"
+;;
+ia64)
+cpu="ia64"
+;;
+x86_64|amd64)
+cpu="x86_64"
+;;
+arm*)
+cpu="arm"
+;;
+*)
+cpu="unknown"
+;;
+esac
+
+# detect host OS
+targetos=`uname -s`
+case $targetos in
+CYGWIN*)
+mingw="yes"
+CFLAGS="-mno-cygwin $CFLAGS"
+;;
+MINGW*)
+mingw="yes"
+;;
+*BSD)
+make="gmake"
+;;
+Linux)
+dl="yes"
+;;
+esac
+
if [ "$mingw" = "yes" ]; then
if [ "$cpu" = "i386" ]; then
cpu="x86"
@@ -238,17 +232,12 @@ if [ "$mingw" = "yes" ]; then
pathsep='\\'
exesuffix=".exe"
libsuffix=".dll"
- oss="no"
- evdev="no"
sdl="no"
gldriver="opengl32"
exported="__attribute__((dllexport))"
homedir=""
asmflags="-DUNDERSCORES"
cfgfile="q2config.cfg"
- if [ "$wave" != "no" ]; then
- wave="yes"
- fi
else
pathsep="/"
exported="__attribute__((visibility(\"default\")))"
@@ -324,16 +313,10 @@ if [ "$mingw" = "no" ]; then
fi
echo "zlib support $zlib"
if [ "$client" = "yes" ]; then
+ echo "Direct input $dinput"
+ echo "Direct sound $dsound"
echo "PNG support $png"
echo "JPEG support $jpeg"
- if [ "$mingw" = "yes" ]; then
- echo "DInput support $dinput"
- echo "DSound support $dsound"
- echo "WAVE sound support $wave"
- else
- echo "OSS support $oss"
- echo "Evdev support $evdev"
- fi
fi
test "$cpu" = "i386" && echo "i386 assembly $asm"
@@ -441,7 +424,7 @@ echo "#define COM_DEMOCACHE_NAME \"$democache\"" >> $config_h
echo "#define SCREENSHOTS_DIRECTORY \"$screenshots\"" >> $config_h
echo "#define SCORESHOTS_DIRECTORY \"$scoreshots\"" >> $config_h
-test "$mingw" = "no" && echo "#define DEFCFG \"$defcfg\"" >> $config_h
+test "$mingw" = "no" && echo "#define SYS_SITECFG_NAME \"$sitecfg\"" >> $config_h
echo "#define CPUSTRING \"$cpu\"" >> $config_h
echo "#define BUILDSTRING \"$targetos\"" >> $config_h
@@ -451,8 +434,6 @@ echo "#define PATH_SEP_STRING \"$pathsep\"" >> $config_h
echo "#define DEFAULT_OPENGL_DRIVER \"$gldriver\"" >> $config_h
-echo "#define DEFAULT_INPUT_DRIVER \"$indriver\"" >> $config_h
-
if [ "$dl" = "yes" ]; then
echo "USE_DL=yes" >> $config_mk
fi
@@ -462,6 +443,8 @@ if [ "$zlib" = "yes" ]; then
echo "ZLIB_LDFLAGS=-lz" >> $config_mk
echo "ZLIB_CFLAGS=" >> $config_mk
echo "#define USE_ZLIB 1" >> $config_h
+else
+ echo "#define USE_ZLIB 0" >> $config_h
fi
if [ "$png" = "yes" ]; then
@@ -491,21 +474,6 @@ if [ "$sdl" = "yes" ]; then
fi
fi
-if [ "$oss" = "yes" ]; then
- echo "USE_OSS=yes" >> $config_mk
- echo "#define USE_OSS 1" >> $config_h
-fi
-
-if [ "$evdev" = "yes" ]; then
- echo "USE_EVDEV=yes" >> $config_mk
- echo "#define USE_EVDEV 1" >> $config_h
-fi
-
-if [ "$wave" = "yes" ]; then
- echo "USE_WAVE=yes" >> $config_mk
- echo "#define USE_WAVE 1" >> $config_h
-fi
-
if [ "$dsound" = "yes" ]; then
echo "USE_DSOUND=yes" >> $config_mk
echo "#define USE_DSOUND 1" >> $config_h
diff --git a/debian/control b/debian/control
index 27fa70f..b3df994 100644
--- a/debian/control
+++ b/debian/control
@@ -7,8 +7,9 @@ Build-Depends: cdbs, debhelper (>= 5), libx11-dev, libsdl1.2-dev,
Standards-Version: 3.7.2
Package: q2pro-client
-Architecture: i386 amd64 armel
-Depends: ${shlibs:Depends}, quake2-data, q2pro-common
+Architecture: any
+Depends: ${shlibs:Depends}, q2pro-common
+Recommends: quake2-data
Description: Enhanced Quake 2 client for multiplayer
Q2PRO is a Quake 2 engine modification designed for online play,
fully compatible with original Quake 2 clients and servers.
@@ -25,7 +26,7 @@ Description: Enhanced Quake 2 client for multiplayer
Homepage: http://q2pro.sf.net/
Package: q2pro-server
-Architecture: i386 amd64 armel
+Architecture: any
Depends: ${shlibs:Depends}, q2pro-common
Recommends: quake2-data
Description: Dedicated Quake 2 server
@@ -42,7 +43,7 @@ Description: Dedicated Quake 2 server
Homepage: http://q2pro.sf.net/
Package: q2pro-common
-Architecture: i386 amd64 armel
+Architecture: any
Depends: ${shlibs:Depends}
Description: Common files for Q2PRO
This package contains common files between Q2PRO server and client.
diff --git a/debian/rules b/debian/rules
index 0aa0a08..ff21d66 100755
--- a/debian/rules
+++ b/debian/rules
@@ -6,5 +6,5 @@ include /usr/share/cdbs/1/class/autotools.mk
DEB_DH_INSTALL_SOURCEDIR := debian/tmp
DEB_CONFIGURE_NORMAL_ARGS := --prefix=$(DEB_CONFIGURE_PREFIX) \
- --enable-png --enable-jpeg --enable-server --enable-anticheat --enable-openffa
+ --enable-png --enable-jpeg --enable-dsound --enable-server --enable-anticheat --enable-openffa
diff --git a/source/cl_ents.c b/source/cl_ents.c
index bd49da9..1a84c98 100644
--- a/source/cl_ents.c
+++ b/source/cl_ents.c
@@ -128,6 +128,10 @@ void CL_DeltaFrame( void ) {
if( cl.oldframe.ps.stats[STAT_LAYOUTS] != cl.frame.ps.stats[STAT_LAYOUTS] ) {
cl.putaway = qfalse;
}
+
+ if( cl.oldframe.ps.pmove.pm_type != cl.frame.ps.pmove.pm_type ) {
+ IN_Activate();
+ }
}
diff --git a/source/cl_fx.c b/source/cl_fx.c
index 5336ba2..7994055 100644
--- a/source/cl_fx.c
+++ b/source/cl_fx.c
@@ -80,24 +80,15 @@ void CL_RunLightStyles( void ) {
}
-void CL_SetLightstyle( int index ) {
- char *s;
- size_t length;
+void CL_SetLightstyle( int index, const char *string, size_t length ) {
int i;
clightstyle_t *dest;
- s = cl.configstrings[index + CS_LIGHTS];
-
- length = strlen( s );
- if( length >= MAX_QPATH )
- Com_Error( ERR_DROP, "CL_SetLightstyle: bad length" );
-
dest = &cl_lightstyles[index];
dest->length = length;
- dest->map[0] = 1.0f;
for( i = 0; i < length; i++ ) {
- dest->map[i] = ( float )( s[i] - 'a' ) / ( float )( 'm' - 'a' );
+ dest->map[i] = ( float )( string[i] - 'a' ) / ( float )( 'm' - 'a' );
}
if( dest->entry.prev ) {
@@ -109,8 +100,7 @@ void CL_SetLightstyle( int index ) {
return;
}
- dest->value[0] = dest->value[1] = dest->value[2] = dest->value[3] = dest->map[0];
-
+ dest->value[0] = dest->value[1] = dest->value[2] = dest->value[3] = dest->map[0] = 1;
}
/*
diff --git a/source/cl_input.c b/source/cl_input.c
index 77184f6..9204241 100644
--- a/source/cl_input.c
+++ b/source/cl_input.c
@@ -20,197 +20,216 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// cl.input.c -- builds an intended movement command to send to the server
#include "cl_local.h"
+#include "in_public.h"
+#include "vid_public.h"
#include "vid_local.h"
-static cvar_t *cl_nodelta;
-static cvar_t *cl_maxpackets;
-static cvar_t *cl_packetdup;
-static cvar_t *cl_fuzzhack;
-static cvar_t *cl_showpackets;
-static cvar_t *cl_instantpacket;
-
-static cvar_t *m_filter;
-static cvar_t *m_accel;
-
-static cvar_t *cl_upspeed;
-static cvar_t *cl_forwardspeed;
-static cvar_t *cl_sidespeed;
-static cvar_t *cl_yawspeed;
-static cvar_t *cl_pitchspeed;
-static cvar_t *cl_run;
-static cvar_t *cl_anglespeedkey;
-
-static cvar_t *freelook;
-static cvar_t *lookspring;
-static cvar_t *lookstrafe;
-static cvar_t *sensitivity;
-
-static cvar_t *m_pitch;
-static cvar_t *m_yaw;
-static cvar_t *m_forward;
-static cvar_t *m_side;
-
-inputAPI_t input;
+static cvar_t *cl_nodelta;
+static cvar_t *cl_maxpackets;
+static cvar_t *cl_packetdup;
+static cvar_t *cl_fuzzhack;
+static cvar_t *cl_showpackets;
+static cvar_t *cl_instantpacket;
+
+static cvar_t *m_filter;
+static cvar_t *m_accel;
+
+static cvar_t *cl_upspeed;
+static cvar_t *cl_forwardspeed;
+static cvar_t *cl_sidespeed;
+static cvar_t *cl_yawspeed;
+static cvar_t *cl_pitchspeed;
+static cvar_t *cl_run;
+static cvar_t *cl_anglespeedkey;
+
+static cvar_t *freelook;
+static cvar_t *lookspring;
+static cvar_t *lookstrafe;
+static cvar_t *sensitivity;
+
+static cvar_t *m_pitch;
+static cvar_t *m_yaw;
+static cvar_t *m_forward;
+static cvar_t *m_side;
/*
===============================================================================
-INPUT LIBRARY
+INPUT SUBSYSTEM
===============================================================================
*/
-static cvar_t *in_driver;
-static cvar_t *in_enable;
+typedef struct {
+ qboolean initialized;
+ inputAPI_t api;
+ qboolean modified;
+ unsigned lastMotion;
+ int hideCursor;
+} in_state_t;
-typedef struct inputDriver_s {
- char *name;
- void (*FillAPI)( inputAPI_t *api );
-} inputDriver_t;
+static in_state_t input;
+static cvar_t *in_enable;
#if USE_DINPUT
-void DI_FillAPI( inputAPI_t *api );
-#endif
-
-#if USE_EVDEV
-void Evdev_FillAPI( inputAPI_t *api );
+static cvar_t *in_direct;
#endif
-static inputDriver_t in_driverTable[] = {
- // fallback driver should be present on all systems
- { "video", Video_FillInputAPI },
-
- /* DirectInput driver */
#if USE_DINPUT
- { "dinput", DI_FillAPI },
-#endif
-#if USE_EVDEV
- { "evdev", Evdev_FillAPI },
+void DI_FillAPI( inputAPI_t *api );
#endif
-};
-
-static int in_numDrivers = sizeof( in_driverTable ) / sizeof( in_driverTable[0] );
/*
============
-CL_InitInput
+IN_Activate
============
*/
-void CL_InputActivate( void ) {
- qboolean active = cls.appactive;
+void IN_Activate( void ) {
+ grab_t grab;
- if( !cls.input_initialized ) {
- return;
- }
+ if( !input.initialized ) {
+ return;
+ }
- if( ( ( cls.key_dest & KEY_CONSOLE ) || ( !( cls.key_dest & KEY_MENU ) && sv_paused->integer ) ) && !( scr_glconfig.flags & QVF_FULLSCREEN ) ) {
- // deactivate in windowed mode if console is open or game is paused
- active = qfalse;
+ input.hideCursor = 0;
+ if( cls.active != ACT_ACTIVATED ) {
+ grab = IN_SHOW;
+ } else if( scr_glconfig.flags & QVF_FULLSCREEN ) {
+ grab = IN_GRAB;
+ } else if( cls.key_dest & KEY_MENU ) {
+ grab = IN_SHOW;
+ } else if( ( cls.key_dest & KEY_CONSOLE ) || sv_paused->integer || cls.demoplayback || cl.frame.ps.pmove.pm_type == PM_FREEZE ) {
+ grab = IN_HIDE;
+ if( !input.hideCursor ) {
+ input.hideCursor = 1;
+ input.lastMotion = com_localTime - 1000;
+ }
+ } else {
+ grab = IN_GRAB;
}
- input.ClearStates();
- input.Activate( active );
+ input.api.Grab( grab );
}
/*
============
-CL_InitInput
+IN_Frame
============
*/
-void CL_InputFrame( void ) {
- if( cls.input_initialized ) {
- input.Frame();
+void IN_Frame( void ) {
+ if( input.modified ) {
+ Cbuf_AddText( "in_restart\n" );
+ input.modified = qfalse;
+ } else if( input.initialized ) {
+ if( input.api.GetEvents ) {
+ input.api.GetEvents();
+ }
+ if( input.hideCursor == 2 && com_localTime - input.lastMotion >= 1000 ) {
+ input.api.Grab( IN_HIDE );
+ input.hideCursor = 1;
+ }
}
}
/*
-============
-CL_RestartInput_f
-============
+================
+IN_MouseEvent
+================
*/
-static void CL_RestartInput_f( void ) {
- CL_ShutdownInput();
- CL_InitInput();
+void IN_MouseEvent( int x, int y ) {
+ input.lastMotion = com_localTime;
+ if( input.hideCursor == 1 ) {
+ input.api.Grab( IN_SHOW );
+ input.hideCursor = 2;
+ }
+ if( cls.key_dest & KEY_MENU ) {
+ UI_MouseEvent( x, y );
+ return;
+ }
}
-static void CL_ReleaseInput_f( void ) {
- if( cls.input_initialized ) {
- input.ClearStates();
- input.Activate( qfalse );
+/*
+================
+IN_WarpMouse
+================
+*/
+void IN_WarpMouse( int x, int y ) {
+ if( input.initialized && input.api.Warp ) {
+ input.api.Warp( x, y );
}
}
+
/*
============
-CL_ShutdownInput
+IN_Restart_f
============
*/
-void CL_ShutdownInput( void ) {
- if( !cls.input_initialized ) {
- return;
- }
+static void IN_Restart_f( void ) {
+ IN_Shutdown();
+ IN_Init();
+}
- Cmd_RemoveCommand( "in_restart" );
- Cmd_RemoveCommand( "in_release" );
+/*
+============
+IN_Shutdown
+============
+*/
+void IN_Shutdown( void ) {
+ if( input.initialized ) {
+#if USE_DINPUT
+ in_direct->changed = NULL;
+#endif
+ input.api.Shutdown();
+ memset( &input, 0, sizeof( input ) );
+ }
+}
- input.Shutdown();
- cls.input_initialized = qfalse;
+static void in_param_changed( cvar_t *self ) {
+ input.modified = qtrue;
}
/*
============
-CL_InitInput
+IN_Init
============
*/
-void CL_InitInput( void ) {
- inputDriver_t *driver;
- int i;
-
- in_driver = Cvar_Get( "in_driver", DEFAULT_INPUT_DRIVER, CVAR_LATCHED );
- in_enable = Cvar_Get( "in_enable", "1", CVAR_LATCHED );
-
- if( !in_enable->integer ) {
- Com_Printf( "Non-keyboard input disabled\n" );
- return;
- }
-
- while( 1 ) {
- if( in_driver->string[0] ) {
- for( i = 0, driver = in_driverTable; i < in_numDrivers; i++, driver++ ) {
- if( !strcmp( in_driver->string, driver->name ) ) {
- break;
- }
- }
- if( i == in_numDrivers ) {
- Com_Printf( "Input driver '%s' not found, falling back to default...\n", in_driver->string );
- Cvar_Set( "in_driver", "" );
- driver = &in_driverTable[0];
- }
- } else {
- driver = &in_driverTable[0];
- }
-
- driver->FillAPI( &input );
-
- if( input.Init() ) {
- break;
- }
- if( !in_driver->string[0] ) {
- Com_WPrintf( "Couldn't fall back to default input driver!\n"
- "Non-keyboard input disabled\n" );
- return;
- }
-
- Com_Printf( "Failed to load input driver, falling back to default...\n" );
- Cvar_Set( "in_driver", "" );
- }
-
- Cmd_AddCommand( "in_restart", CL_RestartInput_f );
- Cmd_AddCommand( "in_release", CL_ReleaseInput_f );
-
- cls.input_initialized = qtrue;
-
- CL_InputActivate();
+void IN_Init( void ) {
+ qboolean ret = qfalse;
+
+ in_enable = Cvar_Get( "in_enable", "1", 0 );
+ in_enable->changed = in_param_changed;
+ if( !in_enable->integer ) {
+ Com_Printf( "Mouse input disabled.\n" );
+ return;
+ }
+
+#if USE_DINPUT
+ in_direct = Cvar_Get( "in_direct", "1", 0 );
+ if( in_direct->integer ) {
+ DI_FillAPI( &input.api );
+ ret = input.api.Init();
+ if( !ret ) {
+ Cvar_Set( "in_direct", "0" );
+ }
+ }
+#endif
+ if( !ret ) {
+ VID_FillInputAPI( &input.api );
+ ret = input.api.Init();
+ if( !ret ) {
+ Cvar_Set( "in_enable", "0" );
+ return;
+ }
+ }
+
+#if USE_DINPUT
+ in_direct->changed = in_param_changed;
+#endif
+
+ input.initialized = qtrue;
+
+ IN_Activate();
}
@@ -241,104 +260,101 @@ Key_Event (int key, qboolean down, unsigned time);
*/
typedef struct kbutton_s {
- int down[2]; // key nums holding it down
- unsigned downtime; // msec timestamp
- unsigned msec; // msec down this frame
- int state;
+ int down[2]; // key nums holding it down
+ unsigned downtime; // msec timestamp
+ unsigned msec; // msec down this frame
+ int state;
} kbutton_t;
-static kbutton_t in_klook;
-static kbutton_t in_left, in_right, in_forward, in_back;
-static kbutton_t in_lookup, in_lookdown, in_moveleft, in_moveright;
-static kbutton_t in_strafe, in_speed, in_use, in_attack;
-static kbutton_t in_up, in_down;
+static kbutton_t in_klook;
+static kbutton_t in_left, in_right, in_forward, in_back;
+static kbutton_t in_lookup, in_lookdown, in_moveleft, in_moveright;
+static kbutton_t in_strafe, in_speed, in_use, in_attack;
+static kbutton_t in_up, in_down;
-static int in_impulse;
+static int in_impulse;
static qboolean in_mlooking;
-static void KeyDown (kbutton_t *b)
-{
- int k;
- char *c;
-
- c = Cmd_Argv(1);
- if (c[0])
- k = atoi(c);
- else
- k = -1; // typed manually at the console for continuous down
-
- if (k == b->down[0] || k == b->down[1])
- return; // repeating key
-
- if (!b->down[0])
- b->down[0] = k;
- else if (!b->down[1])
- b->down[1] = k;
- else
- {
- Com_WPrintf ("Three keys down for a button!\n");
- return;
- }
-
- if (b->state & 1)
- return; // still down
-
- // save timestamp
- c = Cmd_Argv(2);
- b->downtime = atoi(c);
- if (!b->downtime) {
- b->downtime = com_eventTime - 100;
- }
-
- b->state |= 1 + 2; // down + impulse down
+static void KeyDown (kbutton_t *b) {
+ int k;
+ char *c;
+
+ c = Cmd_Argv(1);
+ if (c[0])
+ k = atoi(c);
+ else
+ k = -1; // typed manually at the console for continuous down
+
+ if (k == b->down[0] || k == b->down[1])
+ return; // repeating key
+
+ if (!b->down[0])
+ b->down[0] = k;
+ else if (!b->down[1])
+ b->down[1] = k;
+ else {
+ Com_WPrintf ("Three keys down for a button!\n");
+ return;
+ }
+
+ if (b->state & 1)
+ return; // still down
+
+ // save timestamp
+ c = Cmd_Argv(2);
+ b->downtime = atoi(c);
+ if (!b->downtime) {
+ b->downtime = com_eventTime - 100;
+ }
+
+ b->state |= 1 + 2; // down + impulse down
}
-static void KeyUp (kbutton_t *b)
-{
- int k;
- char *c;
- unsigned uptime;
-
- c = Cmd_Argv(1);
- if (c[0])
- k = atoi(c);
- else
- { // typed manually at the console, assume for unsticking, so clear all
- b->down[0] = b->down[1] = 0;
- b->state = 0; // impulse up
- return;
- }
-
- if (b->down[0] == k)
- b->down[0] = 0;
- else if (b->down[1] == k)
- b->down[1] = 0;
- else
- return; // key up without coresponding down (menu pass through)
- if (b->down[0] || b->down[1])
- return; // some other key is still holding it down
-
- if (!(b->state & 1))
- return; // still up (this should not happen)
-
- // save timestamp
- c = Cmd_Argv(2);
- uptime = atoi(c);
- if( !uptime ) {
- b->msec += 10;
- } else if( uptime > b->downtime ) {
- b->msec += uptime - b->downtime;
- }
-
- b->state &= ~1; // now up
+static void KeyUp (kbutton_t *b) {
+ int k;
+ char *c;
+ unsigned uptime;
+
+ c = Cmd_Argv(1);
+ if (c[0])
+ k = atoi(c);
+ else {
+ // typed manually at the console, assume for unsticking, so clear all
+ b->down[0] = b->down[1] = 0;
+ b->state = 0; // impulse up
+ return;
+ }
+
+ if (b->down[0] == k)
+ b->down[0] = 0;
+ else if (b->down[1] == k)
+ b->down[1] = 0;
+ else
+ return; // key up without coresponding down (menu pass through)
+ if (b->down[0] || b->down[1])
+ return; // some other key is still holding it down
+
+ if (!(b->state & 1))
+ return; // still up (this should not happen)
+
+ // save timestamp
+ c = Cmd_Argv(2);
+ uptime = atoi(c);
+ if( !uptime ) {
+ b->msec += 10;
+ } else if( uptime > b->downtime ) {
+ b->msec += uptime - b->downtime;
+ }
+
+ b->state &= ~1; // now up
}
static void KeyClear( kbutton_t *b ) {
b->msec = 0;
- b->state &= ~2; // clear impulses
- if( b->state & 1 ) {
- b->downtime = com_eventTime; // still down
- }
+ b->state &= ~2; // clear impulses
+ if( b->state & 1 ) {
+ b->downtime = com_eventTime; // still down
+ }
}
static void IN_KLookDown( void ) { KeyDown( &in_klook ); }
@@ -383,22 +399,22 @@ static void IN_UseDown ( void ) {
static void IN_UseUp ( void ) { KeyUp( &in_use ); }
static void IN_Impulse ( void ) {
- in_impulse = atoi( Cmd_Argv( 1 ) );
+ in_impulse = atoi( Cmd_Argv( 1 ) );
}
static void IN_CenterView( void ) {
- cl.viewangles[PITCH] = -SHORT2ANGLE( cl.frame.ps.pmove.delta_angles[PITCH] );
+ cl.viewangles[PITCH] = -SHORT2ANGLE( cl.frame.ps.pmove.delta_angles[PITCH] );
}
static void IN_MLookDown( void ) {
- in_mlooking = qtrue;
+ in_mlooking = qtrue;
}
static void IN_MLookUp( void ) {
- in_mlooking = qfalse;
+ in_mlooking = qfalse;
- if( !freelook->integer && lookspring->integer )
- IN_CenterView();
+ if( !freelook->integer && lookspring->integer )
+ IN_CenterView();
}
/*
@@ -409,47 +425,28 @@ Returns the fraction of the frame that the key was down
===============
*/
static float CL_KeyState( kbutton_t *key ) {
- float val;
- unsigned msec = key->msec;
-
- if( key->state & 1 ) {
- // still down
- if( com_eventTime > key->downtime ) {
- msec += com_eventTime - key->downtime;
- }
- }
-
- if( !cl.cmd.msec ) {
- return 0;
- }
- val = ( float )msec / cl.cmd.msec;
-
- clamp( val, 0, 1 );
+ float val;
+ unsigned msec = key->msec;
+
+ if( key->state & 1 ) {
+ // still down
+ if( com_eventTime > key->downtime ) {
+ msec += com_eventTime - key->downtime;
+ }
+ }
+
+ if( !cl.cmd.msec ) {
+ return 0;
+ }
+ val = ( float )msec / cl.cmd.msec;
+
+ clamp( val, 0, 1 );
- return val;
+ return val;
}
//==========================================================================
-static int mouse_x;
-static int mouse_y;
-static int old_mouse_x;
-static int old_mouse_y;
-
-/*
-================
-CL_MouseEvent
-================
-*/
-void CL_MouseEvent( int dx, int dy ) {
- if( cls.key_dest & KEY_MENU ) {
- UI_MouseMove( dx, dy );
- return;
- }
-
- mouse_x += dx;
- mouse_y += dy;
-}
/*
================
@@ -457,46 +454,56 @@ CL_MouseMove
================
*/
static void CL_MouseMove( void ) {
- float mx, my;
- float speed;
+ static int old_dx, old_dy;
+ int dx, dy;
+ float mx, my;
+ float speed;
+
+ if( !input.initialized ) {
+ return;
+ }
+ if( cls.key_dest & (KEY_MENU|KEY_CONSOLE) ) {
+ return;
+ }
+ if( !input.api.GetMotion( &dx, &dy ) ) {
+ return;
+ }
- if( m_filter->integer ) {
- mx = ( mouse_x + old_mouse_x ) * 0.5f;
- my = ( mouse_y + old_mouse_y ) * 0.5f;
- } else {
- mx = mouse_x;
- my = mouse_y;
- }
+ if( m_filter->integer ) {
+ mx = ( dx + old_dx ) * 0.5f;
+ my = ( dy + old_dy ) * 0.5f;
+ } else {
+ mx = dx;
+ my = dy;
+ }
- old_mouse_x = mouse_x;
- old_mouse_y = mouse_y;
- mouse_x = 0;
- mouse_y = 0;
+ old_dx = dx;
+ old_dy = dy;
- if( !mx && !my ) {
- return;
- }
+ if( !mx && !my ) {
+ return;
+ }
- Cvar_ClampValue( m_accel, 0, 1 );
+ Cvar_ClampValue( m_accel, 0, 1 );
- speed = sqrt( mx * mx + my * my );
- speed = sensitivity->value + speed * m_accel->value;
+ speed = sqrt( mx * mx + my * my );
+ speed = sensitivity->value + speed * m_accel->value;
- mx *= speed;
- my *= speed;
+ mx *= speed;
+ my *= speed;
// add mouse X/Y movement to cmd
- if( ( in_strafe.state & 1 ) || ( lookstrafe->integer && !in_mlooking ) ) {
- cl.cmd.sidemove += m_side->value * mx;
- } else {
- cl.viewangles[YAW] -= m_yaw->value * mx;
- }
-
- if( ( in_mlooking || freelook->integer ) && !( in_strafe.state & 1 ) ) {
- cl.viewangles[PITCH] += m_pitch->value * my;
- } else {
- cl.cmd.forwardmove -= m_forward->value * my;
- }
+ if( ( in_strafe.state & 1 ) || ( lookstrafe->integer && !in_mlooking ) ) {
+ cl.cmd.sidemove += m_side->value * mx;
+ } else {
+ cl.viewangles[YAW] -= m_yaw->value * mx;
+ }
+
+ if( ( in_mlooking || freelook->integer ) && !( in_strafe.state & 1 ) ) {
+ cl.viewangles[PITCH] += m_pitch->value * my;
+ } else {
+ cl.cmd.forwardmove -= m_forward->value * my;
+ }
}
@@ -508,24 +515,24 @@ Moves the local angle positions
================
*/
static void CL_AdjustAngles( int msec ) {
- float speed;
-
- if( in_speed.state & 1 )
- speed = msec * cl_anglespeedkey->value * 0.001f;
- else
- speed = msec * 0.001f;
-
- if( !( in_strafe.state & 1 ) ) {
- cl.viewangles[YAW] -= speed*cl_yawspeed->value*CL_KeyState(&in_right);
- cl.viewangles[YAW] += speed*cl_yawspeed->value*CL_KeyState(&in_left);
- }
- if( in_klook.state & 1 ) {
- cl.viewangles[PITCH] -= speed*cl_pitchspeed->value*CL_KeyState(&in_forward);
- cl.viewangles[PITCH] += speed*cl_pitchspeed->value*CL_KeyState(&in_back);
- }
-
- cl.viewangles[PITCH] -= speed*cl_pitchspeed->value*CL_KeyState(&in_lookup);
- cl.viewangles[PITCH] += speed*cl_pitchspeed->value*CL_KeyState(&in_lookdown);
+ float speed;
+
+ if( in_speed.state & 1 )
+ speed = msec * cl_anglespeedkey->value * 0.001f;
+ else
+ speed = msec * 0.001f;
+
+ if( !( in_strafe.state & 1 ) ) {
+ cl.viewangles[YAW] -= speed*cl_yawspeed->value*CL_KeyState(&in_right);
+ cl.viewangles[YAW] += speed*cl_yawspeed->value*CL_KeyState(&in_left);
+ }
+ if( in_klook.state & 1 ) {
+ cl.viewangles[PITCH] -= speed*cl_pitchspeed->value*CL_KeyState(&in_forward);
+ cl.viewangles[PITCH] += speed*cl_pitchspeed->value*CL_KeyState(&in_back);
+ }
+
+ cl.viewangles[PITCH] -= speed*cl_pitchspeed->value*CL_KeyState(&in_lookup);
+ cl.viewangles[PITCH] += speed*cl_pitchspeed->value*CL_KeyState(&in_lookdown);
}
/*
@@ -538,26 +545,26 @@ Build the intended movement vector
static void CL_BaseMove( vec3_t move ) {
float speed;
- if( in_strafe.state & 1 ) {
- move[1] += cl_sidespeed->value * CL_KeyState( &in_right );
- move[1] -= cl_sidespeed->value * CL_KeyState( &in_left );
+ if( in_strafe.state & 1 ) {
+ move[1] += cl_sidespeed->value * CL_KeyState( &in_right );
+ move[1] -= cl_sidespeed->value * CL_KeyState( &in_left );
}
- move[1] += cl_sidespeed->value * CL_KeyState( &in_moveright );
- move[1] -= cl_sidespeed->value * CL_KeyState( &in_moveleft );
+ move[1] += cl_sidespeed->value * CL_KeyState( &in_moveright );
+ move[1] -= cl_sidespeed->value * CL_KeyState( &in_moveleft );
- move[2] += cl_upspeed->value * CL_KeyState( &in_up );
- move[2] -= cl_upspeed->value * CL_KeyState( &in_down );
+ move[2] += cl_upspeed->value * CL_KeyState( &in_up );
+ move[2] -= cl_upspeed->value * CL_KeyState( &in_down );
- if( !( in_klook.state & 1 ) ) {
- move[0] += cl_forwardspeed->value * CL_KeyState( &in_forward );
- move[0] -= cl_forwardspeed->value * CL_KeyState( &in_back );
+ if( !( in_klook.state & 1 ) ) {
+ move[0] += cl_forwardspeed->value * CL_KeyState( &in_forward );
+ move[0] -= cl_forwardspeed->value * CL_KeyState( &in_back );
}
// adjust for speed key / running
- if( ( in_speed.state & 1 ) ^ cl_run->integer ) {
- VectorScale( move, 2, move );
- }
+ if( ( in_speed.state & 1 ) ^ cl_run->integer ) {
+ VectorScale( move, 2, move );
+ }
// clamp to server defined max speed
speed = cl.pmp.maxspeed;
@@ -567,21 +574,21 @@ static void CL_BaseMove( vec3_t move ) {
}
static void CL_ClampPitch( void ) {
- float pitch;
+ float pitch;
- pitch = SHORT2ANGLE( cl.frame.ps.pmove.delta_angles[PITCH] );
- if (pitch > 180)
- pitch -= 360;
+ pitch = SHORT2ANGLE( cl.frame.ps.pmove.delta_angles[PITCH] );
+ if (pitch > 180)
+ pitch -= 360;
- if (cl.viewangles[PITCH] + pitch < -360)
- cl.viewangles[PITCH] += 360; // wrapped
- if (cl.viewangles[PITCH] + pitch > 360)
- cl.viewangles[PITCH] -= 360; // wrapped
+ if (cl.viewangles[PITCH] + pitch < -360)
+ cl.viewangles[PITCH] += 360; // wrapped
+ if (cl.viewangles[PITCH] + pitch > 360)
+ cl.viewangles[PITCH] -= 360; // wrapped
- if (cl.viewangles[PITCH] + pitch > 89)
- cl.viewangles[PITCH] = 89 - pitch;
- if (cl.viewangles[PITCH] + pitch < -89)
- cl.viewangles[PITCH] = -89 - pitch;
+ if (cl.viewangles[PITCH] + pitch > 89)
+ cl.viewangles[PITCH] = 89 - pitch;
+ if (cl.viewangles[PITCH] + pitch < -89)
+ cl.viewangles[PITCH] = -89 - pitch;
}
/*
@@ -592,29 +599,27 @@ CL_UpdateCmd
void CL_UpdateCmd( int msec ) {
VectorClear( cl.move );
- if( sv_paused->integer ) {
- mouse_x = old_mouse_x;
- mouse_y = old_mouse_y;
+ if( sv_paused->integer ) {
return;
}
- // add to milliseconds of time to apply the move
- cl.cmd.msec += msec;
+ // add to milliseconds of time to apply the move
+ cl.cmd.msec += msec;
- // adjust viewangles
- CL_AdjustAngles( msec );
-
- // get basic movement from keyboard
- CL_BaseMove( cl.move );
+ // adjust viewangles
+ CL_AdjustAngles( msec );
+
+ // get basic movement from keyboard
+ CL_BaseMove( cl.move );
- // allow mice or other external controllers to add to the move
- CL_MouseMove();
+ // allow mice or other external controllers to add to the move
+ CL_MouseMove();
- CL_ClampPitch();
-
- cl.cmd.angles[0] = ANGLE2SHORT( cl.viewangles[0] );
- cl.cmd.angles[1] = ANGLE2SHORT( cl.viewangles[1] );
- cl.cmd.angles[2] = ANGLE2SHORT( cl.viewangles[2] );
+ CL_ClampPitch();
+
+ cl.cmd.angles[0] = ANGLE2SHORT( cl.viewangles[0] );
+ cl.cmd.angles[1] = ANGLE2SHORT( cl.viewangles[1] );
+ cl.cmd.angles[2] = ANGLE2SHORT( cl.viewangles[2] );
}
@@ -624,48 +629,50 @@ CL_RegisterInput
============
*/
void CL_RegisterInput( void ) {
- Cmd_AddCommand ("centerview",IN_CenterView);
-
- Cmd_AddCommand ("+moveup",IN_UpDown);
- Cmd_AddCommand ("-moveup",IN_UpUp);
- Cmd_AddCommand ("+movedown",IN_DownDown);
- Cmd_AddCommand ("-movedown",IN_DownUp);
- Cmd_AddCommand ("+left",IN_LeftDown);
- Cmd_AddCommand ("-left",IN_LeftUp);
- Cmd_AddCommand ("+right",IN_RightDown);
- Cmd_AddCommand ("-right",IN_RightUp);
- Cmd_AddCommand ("+forward",IN_ForwardDown);
- Cmd_AddCommand ("-forward",IN_ForwardUp);
- Cmd_AddCommand ("+back",IN_BackDown);
- Cmd_AddCommand ("-back",IN_BackUp);
- Cmd_AddCommand ("+lookup", IN_LookupDown);
- Cmd_AddCommand ("-lookup", IN_LookupUp);
- Cmd_AddCommand ("+lookdown", IN_LookdownDown);
- Cmd_AddCommand ("-lookdown", IN_LookdownUp);
- Cmd_AddCommand ("+strafe", IN_StrafeDown);
- Cmd_AddCommand ("-strafe", IN_StrafeUp);
- Cmd_AddCommand ("+moveleft", IN_MoveleftDown);
- Cmd_AddCommand ("-moveleft", IN_MoveleftUp);
- Cmd_AddCommand ("+moveright", IN_MoverightDown);
- Cmd_AddCommand ("-moveright", IN_MoverightUp);
- Cmd_AddCommand ("+speed", IN_SpeedDown);
- Cmd_AddCommand ("-speed", IN_SpeedUp);
- Cmd_AddCommand ("+attack", IN_AttackDown);
- Cmd_AddCommand ("-attack", IN_AttackUp);
- Cmd_AddCommand ("+use", IN_UseDown);
- Cmd_AddCommand ("-use", IN_UseUp);
- Cmd_AddCommand ("impulse", IN_Impulse);
- Cmd_AddCommand ("+klook", IN_KLookDown);
- Cmd_AddCommand ("-klook", IN_KLookUp);
- Cmd_AddCommand( "+mlook", IN_MLookDown );
- Cmd_AddCommand( "-mlook", IN_MLookUp );
-
- cl_nodelta = Cvar_Get ("cl_nodelta", "0", 0);
- cl_maxpackets = Cvar_Get( "cl_maxpackets", "30", 0 );
- cl_fuzzhack = Cvar_Get( "cl_fuzzhack", "0", 0 );
- cl_packetdup = Cvar_Get( "cl_packetdup", "1", 0 );
- cl_showpackets = Cvar_Get( "cl_showpackets", "0", 0 );
- cl_instantpacket = Cvar_Get( "cl_instantpacket", "1", 0 );
+ Cmd_AddCommand ("centerview",IN_CenterView);
+
+ Cmd_AddCommand ("+moveup",IN_UpDown);
+ Cmd_AddCommand ("-moveup",IN_UpUp);
+ Cmd_AddCommand ("+movedown",IN_DownDown);
+ Cmd_AddCommand ("-movedown",IN_DownUp);
+ Cmd_AddCommand ("+left",IN_LeftDown);
+ Cmd_AddCommand ("-left",IN_LeftUp);
+ Cmd_AddCommand ("+right",IN_RightDown);
+ Cmd_AddCommand ("-right",IN_RightUp);
+ Cmd_AddCommand ("+forward",IN_ForwardDown);
+ Cmd_AddCommand ("-forward",IN_ForwardUp);
+ Cmd_AddCommand ("+back",IN_BackDown);
+ Cmd_AddCommand ("-back",IN_BackUp);
+ Cmd_AddCommand ("+lookup", IN_LookupDown);
+ Cmd_AddCommand ("-lookup", IN_LookupUp);
+ Cmd_AddCommand ("+lookdown", IN_LookdownDown);
+ Cmd_AddCommand ("-lookdown", IN_LookdownUp);
+ Cmd_AddCommand ("+strafe", IN_StrafeDown);
+ Cmd_AddCommand ("-strafe", IN_StrafeUp);
+ Cmd_AddCommand ("+moveleft", IN_MoveleftDown);
+ Cmd_AddCommand ("-moveleft", IN_MoveleftUp);
+ Cmd_AddCommand ("+moveright", IN_MoverightDown);
+ Cmd_AddCommand ("-moveright", IN_MoverightUp);
+ Cmd_AddCommand ("+speed", IN_SpeedDown);
+ Cmd_AddCommand ("-speed", IN_SpeedUp);
+ Cmd_AddCommand ("+attack", IN_AttackDown);
+ Cmd_AddCommand ("-attack", IN_AttackUp);
+ Cmd_AddCommand ("+use", IN_UseDown);
+ Cmd_AddCommand ("-use", IN_UseUp);
+ Cmd_AddCommand ("impulse", IN_Impulse);
+ Cmd_AddCommand ("+klook", IN_KLookDown);
+ Cmd_AddCommand ("-klook", IN_KLookUp);
+ Cmd_AddCommand( "+mlook", IN_MLookDown );
+ Cmd_AddCommand( "-mlook", IN_MLookUp );
+
+ Cmd_AddCommand( "in_restart", IN_Restart_f );
+
+ cl_nodelta = Cvar_Get ("cl_nodelta", "0", 0);
+ cl_maxpackets = Cvar_Get( "cl_maxpackets", "30", 0 );
+ cl_fuzzhack = Cvar_Get( "cl_fuzzhack", "0", 0 );
+ cl_packetdup = Cvar_Get( "cl_packetdup", "1", 0 );
+ cl_showpackets = Cvar_Get( "cl_showpackets", "0", 0 );
+ cl_instantpacket = Cvar_Get( "cl_instantpacket", "1", 0 );
cl_upspeed = Cvar_Get ( "cl_upspeed", "200", 0 );
cl_forwardspeed = Cvar_Get ( "cl_forwardspeed", "200", 0 );
@@ -684,54 +691,54 @@ void CL_RegisterInput( void ) {
m_yaw = Cvar_Get ( "m_yaw", "0.022", 0 );
m_forward = Cvar_Get ( "m_forward", "1", 0 );
m_side = Cvar_Get ( "m_side", "1", 0 );
- m_filter = Cvar_Get( "m_filter", "0", 0 );
- m_accel = Cvar_Get( "m_accel", "0", 0 );
+ m_filter = Cvar_Get( "m_filter", "0", 0 );
+ m_accel = Cvar_Get( "m_accel", "0", 0 );
}
void CL_FinalizeCmd( void ) {
- vec3_t move;
+ vec3_t move;
// command buffer ticks in sync with cl_maxfps
if( cmd_buffer.waitCount > 0 ) {
cmd_buffer.waitCount--;
}
- if( cls.state < ca_active ) {
- return; // not talking to a server
- }
+ if( cls.state < ca_active ) {
+ return; // not talking to a server
+ }
- if( sv_paused->integer ) {
- return;
- }
+ if( sv_paused->integer ) {
+ return;
+ }
//
// figure button bits
-//
- if( in_attack.state & 3 )
- cl.cmd.buttons |= BUTTON_ATTACK;
- if( in_use.state & 3 )
- cl.cmd.buttons |= BUTTON_USE;
+//
+ if( in_attack.state & 3 )
+ cl.cmd.buttons |= BUTTON_ATTACK;
+ if( in_use.state & 3 )
+ cl.cmd.buttons |= BUTTON_USE;
- in_attack.state &= ~2;
- in_use.state &= ~2;
+ in_attack.state &= ~2;
+ in_use.state &= ~2;
- if( !( cls.key_dest & (KEY_CONSOLE|KEY_MENU|KEY_MESSAGE) ) &&
- Key_AnyKeyDown() )
- cl.cmd.buttons |= BUTTON_ANY;
+ if( cls.key_dest == KEY_GAME && Key_AnyKeyDown() ) {
+ cl.cmd.buttons |= BUTTON_ANY;
+ }
- if( cl.cmd.msec > 250 ) {
- cl.cmd.msec = 100; // time was unreasonable
- }
+ if( cl.cmd.msec > 250 ) {
+ cl.cmd.msec = 100; // time was unreasonable
+ }
- move[0] = cl.cmd.forwardmove;
- move[1] = cl.cmd.sidemove;
- move[2] = cl.cmd.upmove;
+ move[0] = cl.cmd.forwardmove;
+ move[1] = cl.cmd.sidemove;
+ move[2] = cl.cmd.upmove;
- CL_BaseMove( move );
+ CL_BaseMove( move );
- cl.cmd.forwardmove = move[0];
- cl.cmd.sidemove = move[1];
- cl.cmd.upmove = move[2];
+ cl.cmd.forwardmove = move[0];
+ cl.cmd.sidemove = move[1];
+ cl.cmd.upmove = move[2];
KeyClear( &in_right );
KeyClear( &in_left );
@@ -748,15 +755,15 @@ void CL_FinalizeCmd( void ) {
KeyClear( &in_lookup );
KeyClear( &in_lookdown );
- cl.cmd.impulse = in_impulse;
- in_impulse = 0;
+ cl.cmd.impulse = in_impulse;
+ in_impulse = 0;
- // save this command off for prediction
- cl.cmdNumber++;
- cl.cmds[cl.cmdNumber & CMD_MASK] = cl.cmd;
+ // save this command off for prediction
+ cl.cmdNumber++;
+ cl.cmds[cl.cmdNumber & CMD_MASK] = cl.cmd;
- // clear pending cmd
- memset( &cl.cmd, 0, sizeof( cl.cmd ) );
+ // clear pending cmd
+ memset( &cl.cmd, 0, sizeof( cl.cmd ) );
}
/*
@@ -765,36 +772,35 @@ CL_ReadyToSend
=================
*/
static inline qboolean CL_ReadyToSend( void ) {
- unsigned msec;
-
- if( cl.sendPacketNow ) {
- return qtrue;
- }
- if( cls.netchan->message.cursize || cls.netchan->reliable_ack_pending ) {
- return qtrue;
- }
- if( cls.serverProtocol != PROTOCOL_VERSION_Q2PRO && !cl_fuzzhack->integer )
+ unsigned msec;
+
+ if( cl.sendPacketNow ) {
+ return qtrue;
+ }
+ if( cls.netchan->message.cursize || cls.netchan->reliable_ack_pending ) {
+ return qtrue;
+ }
+ if( cls.serverProtocol != PROTOCOL_VERSION_Q2PRO && !cl_fuzzhack->integer )
{
- return qtrue;
- }
- if( !cl_maxpackets->integer ) {
- return qtrue;
- }
-
- if( cl_maxpackets->integer < 10 ) {
- Cvar_SetInteger( "cl_maxpackets", 10 );
- }
-
- msec = 1000 / cl_maxpackets->integer;
- if( msec ) {
- msec = 100 / ( 100 / msec );
- }
- //Com_Printf( "%d\n", msec );
- if( cls.realtime - cl.lastTransmitTime < msec ) {
- return qfalse;
- }
-
- return qtrue;
+ return qtrue;
+ }
+ if( !cl_maxpackets->integer ) {
+ return qtrue;
+ }
+
+ if( cl_maxpackets->integer < 10 ) {
+ Cvar_SetInteger( "cl_maxpackets", 10 );
+ }
+
+ msec = 1000 / cl_maxpackets->integer;
+ if( msec ) {
+ msec = 100 / ( 100 / msec );
+ }
+ if( cls.realtime - cl.lastTransmitTime < msec ) {
+ return qfalse;
+ }
+
+ return qtrue;
}
/*
@@ -803,79 +809,79 @@ CL_SendDefaultCmd
=================
*/
static void CL_SendDefaultCmd( void ) {
- size_t cursize, checksumIndex;
- usercmd_t *cmd, *oldcmd;
- client_history_t *history;
-
- // archive this packet
- history = &cl.history[cls.netchan->outgoing_sequence & CMD_MASK];
- history->cmdNumber = cl.cmdNumber;
- history->sent = cls.realtime; // for ping calculation
- history->rcvd = 0;
-
- cl.lastTransmitCmdNumber = cl.cmdNumber;
-
- // see if we are ready to send this packet
- if( !CL_ReadyToSend() ) {
- if( cl.cmdNumber - cl.lastTransmitCmdNumber < 3 ) {
- cls.netchan->outgoing_sequence++; // HACK: just drop the packet
- return;
- }
- }
-
- cl.lastTransmitTime = cls.realtime;
-
- // begin a client move command
- MSG_WriteByte( clc_move );
-
- // save the position for a checksum byte
- checksumIndex = 0;
- if( cls.serverProtocol <= PROTOCOL_VERSION_DEFAULT ) {
- checksumIndex = msg_write.cursize;
- SZ_GetSpace( &msg_write, 1 );
- }
-
- // let the server know what the last frame we
- // got was, so the next message can be delta compressed
- if( cl_nodelta->integer || !cl.frame.valid /*|| cls.demowaiting*/ ) {
- MSG_WriteLong( -1 ); // no compression
- } else {
- MSG_WriteLong( cl.frame.number );
- }
-
- // send this and the previous cmds in the message, so
- // if the last packet was dropped, it can be recovered
- cmd = &cl.cmds[( cl.cmdNumber - 2 ) & CMD_MASK];
- MSG_WriteDeltaUsercmd( NULL, cmd, cls.protocolVersion );
- MSG_WriteByte( cl.lightlevel );
- oldcmd = cmd;
-
- cmd = &cl.cmds[( cl.cmdNumber - 1 ) & CMD_MASK];
- MSG_WriteDeltaUsercmd( oldcmd, cmd, cls.protocolVersion );
- MSG_WriteByte( cl.lightlevel );
- oldcmd = cmd;
-
- cmd = &cl.cmds[cl.cmdNumber & CMD_MASK];
- MSG_WriteDeltaUsercmd( oldcmd, cmd, cls.protocolVersion );
- MSG_WriteByte( cl.lightlevel );
-
- if( cls.serverProtocol <= PROTOCOL_VERSION_DEFAULT ) {
- // calculate a checksum over the move commands
- msg_write.data[checksumIndex] = COM_BlockSequenceCRCByte(
- msg_write.data + checksumIndex + 1,
+ size_t cursize, checksumIndex;
+ usercmd_t *cmd, *oldcmd;
+ client_history_t *history;
+
+ // archive this packet
+ history = &cl.history[cls.netchan->outgoing_sequence & CMD_MASK];
+ history->cmdNumber = cl.cmdNumber;
+ history->sent = cls.realtime; // for ping calculation
+ history->rcvd = 0;
+
+ cl.lastTransmitCmdNumber = cl.cmdNumber;
+
+ // see if we are ready to send this packet
+ if( !CL_ReadyToSend() ) {
+ if( cl.cmdNumber - cl.lastTransmitCmdNumber < 3 ) {
+ cls.netchan->outgoing_sequence++; // HACK: just drop the packet
+ return;
+ }
+ }
+
+ cl.lastTransmitTime = cls.realtime;
+
+ // begin a client move command
+ MSG_WriteByte( clc_move );
+
+ // save the position for a checksum byte
+ checksumIndex = 0;
+ if( cls.serverProtocol <= PROTOCOL_VERSION_DEFAULT ) {
+ checksumIndex = msg_write.cursize;
+ SZ_GetSpace( &msg_write, 1 );
+ }
+
+ // let the server know what the last frame we
+ // got was, so the next message can be delta compressed
+ if( cl_nodelta->integer || !cl.frame.valid /*|| cls.demowaiting*/ ) {
+ MSG_WriteLong( -1 ); // no compression
+ } else {
+ MSG_WriteLong( cl.frame.number );
+ }
+
+ // send this and the previous cmds in the message, so
+ // if the last packet was dropped, it can be recovered
+ cmd = &cl.cmds[( cl.cmdNumber - 2 ) & CMD_MASK];
+ MSG_WriteDeltaUsercmd( NULL, cmd, cls.protocolVersion );
+ MSG_WriteByte( cl.lightlevel );
+ oldcmd = cmd;
+
+ cmd = &cl.cmds[( cl.cmdNumber - 1 ) & CMD_MASK];
+ MSG_WriteDeltaUsercmd( oldcmd, cmd, cls.protocolVersion );
+ MSG_WriteByte( cl.lightlevel );
+ oldcmd = cmd;
+
+ cmd = &cl.cmds[cl.cmdNumber & CMD_MASK];
+ MSG_WriteDeltaUsercmd( oldcmd, cmd, cls.protocolVersion );
+ MSG_WriteByte( cl.lightlevel );
+
+ if( cls.serverProtocol <= PROTOCOL_VERSION_DEFAULT ) {
+ // calculate a checksum over the move commands
+ msg_write.data[checksumIndex] = COM_BlockSequenceCRCByte(
+ msg_write.data + checksumIndex + 1,
msg_write.cursize - checksumIndex - 1,
- cls.netchan->outgoing_sequence );
- }
-
- //
- // deliver the message
- //
- cursize = cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data );
- if( cl_showpackets->integer ) {
- Com_Printf( "%"PRIz" ", cursize );
- }
-
- SZ_Clear( &msg_write );
+ cls.netchan->outgoing_sequence );
+ }
+
+ //
+ // deliver the message
+ //
+ cursize = cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data );
+ if( cl_showpackets->integer ) {
+ Com_Printf( "%"PRIz" ", cursize );
+ }
+
+ SZ_Clear( &msg_write );
}
/*
@@ -884,169 +890,169 @@ CL_SendBatchedCmd
=================
*/
static void CL_SendBatchedCmd( void ) {
- int i, j, seq, bits;
- int numCmds, numDups;
- int totalCmds, totalMsec;
- size_t cursize;
- usercmd_t *cmd, *oldcmd;
- client_history_t *history, *oldest;
- byte *patch;
-
- // see if we are ready to send this packet
- if( !CL_ReadyToSend() ) {
- return;
- }
-
- // archive this packet
- seq = cls.netchan->outgoing_sequence;
- history = &cl.history[seq & CMD_MASK];
- history->cmdNumber = cl.cmdNumber;
- history->sent = cls.realtime; // for ping calculation
- history->rcvd = 0;
-
- cl.lastTransmitTime = cls.realtime;
- cl.lastTransmitCmdNumber = cl.cmdNumber;
-
- // begin a client move command
- patch = SZ_GetSpace( &msg_write, 1 );
-
- // let the server know what the last frame we
- // got was, so the next message can be delta compressed
- if( cl_nodelta->integer || !cl.frame.valid /*|| cls.demowaiting*/ ) {
- *patch = clc_move_nodelta; // no compression
- } else {
- *patch = clc_move_batched;
- MSG_WriteLong( cl.frame.number );
- }
-
- Cvar_ClampInteger( cl_packetdup, 0, MAX_PACKET_FRAMES - 1 );
- numDups = cl_packetdup->integer;
-
- *patch |= numDups << SVCMD_BITS;
-
- // send lightlevel
- MSG_WriteByte( cl.lightlevel );
-
- // send this and the previous cmds in the message, so
- // if the last packet was dropped, it can be recovered
- oldcmd = NULL;
- totalCmds = 0;
- totalMsec = 0;
- for( i = seq - numDups; i <= seq; i++ ) {
- oldest = &cl.history[( i - 1 ) & CMD_MASK];
- history = &cl.history[i & CMD_MASK];
-
- numCmds = history->cmdNumber - oldest->cmdNumber;
- if( numCmds >= MAX_PACKET_USERCMDS ) {
- Com_WPrintf( "%s: MAX_PACKET_USERCMDS exceeded\n", __func__ );
- SZ_Clear( &msg_write );
- break;
- }
- totalCmds += numCmds;
- MSG_WriteBits( numCmds, 5 );
- for( j = oldest->cmdNumber + 1; j <= history->cmdNumber; j++ ) {
- cmd = &cl.cmds[j & CMD_MASK];
- totalMsec += cmd->msec;
- bits = MSG_WriteDeltaUsercmd_Enhanced( oldcmd, cmd, cls.protocolVersion );
- if( cl_showpackets->integer == 3 ) {
- MSG_ShowDeltaUsercmdBits_Enhanced( bits );
- }
- oldcmd = cmd;
- }
- }
-
- //
- // deliver the message
- //
- cursize = cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data );
- if( cl_showpackets->integer == 1 ) {
- Com_Printf( "%"PRIz"(%i) ", cursize, totalCmds );
- } else if( cl_showpackets->integer == 2 ) {
- Com_Printf( "%"PRIz"(%i) ", cursize, totalMsec );
- } else if( cl_showpackets->integer == 3 ) {
- Com_Printf( " | " );
- }
-
- SZ_Clear( &msg_write );
+ int i, j, seq, bits;
+ int numCmds, numDups;
+ int totalCmds, totalMsec;
+ size_t cursize;
+ usercmd_t *cmd, *oldcmd;
+ client_history_t *history, *oldest;
+ byte *patch;
+
+ // see if we are ready to send this packet
+ if( !CL_ReadyToSend() ) {
+ return;
+ }
+
+ // archive this packet
+ seq = cls.netchan->outgoing_sequence;
+ history = &cl.history[seq & CMD_MASK];
+ history->cmdNumber = cl.cmdNumber;
+ history->sent = cls.realtime; // for ping calculation
+ history->rcvd = 0;
+
+ cl.lastTransmitTime = cls.realtime;
+ cl.lastTransmitCmdNumber = cl.cmdNumber;
+
+ // begin a client move command
+ patch = SZ_GetSpace( &msg_write, 1 );
+
+ // let the server know what the last frame we
+ // got was, so the next message can be delta compressed
+ if( cl_nodelta->integer || !cl.frame.valid /*|| cls.demowaiting*/ ) {
+ *patch = clc_move_nodelta; // no compression
+ } else {
+ *patch = clc_move_batched;
+ MSG_WriteLong( cl.frame.number );
+ }
+
+ Cvar_ClampInteger( cl_packetdup, 0, MAX_PACKET_FRAMES - 1 );
+ numDups = cl_packetdup->integer;
+
+ *patch |= numDups << SVCMD_BITS;
+
+ // send lightlevel
+ MSG_WriteByte( cl.lightlevel );
+
+ // send this and the previous cmds in the message, so
+ // if the last packet was dropped, it can be recovered
+ oldcmd = NULL;
+ totalCmds = 0;
+ totalMsec = 0;
+ for( i = seq - numDups; i <= seq; i++ ) {
+ oldest = &cl.history[( i - 1 ) & CMD_MASK];
+ history = &cl.history[i & CMD_MASK];
+
+ numCmds = history->cmdNumber - oldest->cmdNumber;
+ if( numCmds >= MAX_PACKET_USERCMDS ) {
+ Com_WPrintf( "%s: MAX_PACKET_USERCMDS exceeded\n", __func__ );
+ SZ_Clear( &msg_write );
+ break;
+ }
+ totalCmds += numCmds;
+ MSG_WriteBits( numCmds, 5 );
+ for( j = oldest->cmdNumber + 1; j <= history->cmdNumber; j++ ) {
+ cmd = &cl.cmds[j & CMD_MASK];
+ totalMsec += cmd->msec;
+ bits = MSG_WriteDeltaUsercmd_Enhanced( oldcmd, cmd, cls.protocolVersion );
+ if( cl_showpackets->integer == 3 ) {
+ MSG_ShowDeltaUsercmdBits_Enhanced( bits );
+ }
+ oldcmd = cmd;
+ }
+ }
+
+ //
+ // deliver the message
+ //
+ cursize = cls.netchan->Transmit( cls.netchan, msg_write.cursize, msg_write.data );
+ if( cl_showpackets->integer == 1 ) {
+ Com_Printf( "%"PRIz"(%i) ", cursize, totalCmds );
+ } else if( cl_showpackets->integer == 2 ) {
+ Com_Printf( "%"PRIz"(%i) ", cursize, totalMsec );
+ } else if( cl_showpackets->integer == 3 ) {
+ Com_Printf( " | " );
+ }
+
+ SZ_Clear( &msg_write );
}
static void CL_SendUserinfo( void ) {
char userinfo[MAX_INFO_STRING];
- cvar_t *var;
- int i;
+ cvar_t *var;
+ int i;
- if( !cls.userinfo_modified ) {
- return;
- }
+ if( !cls.userinfo_modified ) {
+ return;
+ }
- if( cls.userinfo_modified == MAX_PACKET_USERINFOS ) {
+ if( cls.userinfo_modified == MAX_PACKET_USERINFOS ) {
size_t len = Cvar_BitInfo( userinfo, CVAR_USERINFO );
- MSG_WriteByte( clc_userinfo );
- MSG_WriteData( userinfo, len + 1 );
- MSG_FlushTo( &cls.netchan->message );
- } else if( cls.serverProtocol == PROTOCOL_VERSION_Q2PRO ) {
- Com_DPrintf( "Sending %d userinfo updates at frame %u\n",
- cls.userinfo_modified, com_framenum );
- for( i = 0; i < cls.userinfo_modified; i++ ) {
- var = cls.userinfo_updates[i];
- MSG_WriteByte( clc_userinfo_delta );
- MSG_WriteString( var->name );
- if( var->flags & CVAR_USERINFO ) {
- MSG_WriteString( var->string );
- } else {
- // no longer in userinfo
- MSG_WriteString( NULL );
- }
- }
- MSG_FlushTo( &cls.netchan->message );
- } else {
- Com_WPrintf( "Userinfo update count is %d, should not happen.\n",
- cls.userinfo_modified );
- }
- cls.userinfo_modified = 0;
-
+ MSG_WriteByte( clc_userinfo );
+ MSG_WriteData( userinfo, len + 1 );
+ MSG_FlushTo( &cls.netchan->message );
+ } else if( cls.serverProtocol == PROTOCOL_VERSION_Q2PRO ) {
+ Com_DPrintf( "Sending %d userinfo updates at frame %u\n",
+ cls.userinfo_modified, com_framenum );
+ for( i = 0; i < cls.userinfo_modified; i++ ) {
+ var = cls.userinfo_updates[i];
+ MSG_WriteByte( clc_userinfo_delta );
+ MSG_WriteString( var->name );
+ if( var->flags & CVAR_USERINFO ) {
+ MSG_WriteString( var->string );
+ } else {
+ // no longer in userinfo
+ MSG_WriteString( NULL );
+ }
+ }
+ MSG_FlushTo( &cls.netchan->message );
+ } else {
+ Com_WPrintf( "Userinfo update count is %d, should not happen.\n",
+ cls.userinfo_modified );
+ }
+ cls.userinfo_modified = 0;
+
}
void CL_SendCmd( void ) {
- if( cls.state < ca_connected ) {
- return; // not talking to a server
- }
-
- if( sv_paused->integer ) {
- return;
- }
-
- // generate usercmds while playing a demo,
- // but do not send them
- if( !cls.netchan ) {
- return;
- }
-
- if( cls.state < ca_active ) {
- CL_SendUserinfo();
-
- // just keepalive or update reliable
- if( cls.netchan->ShouldUpdate( cls.netchan ) ) {
- cls.netchan->Transmit( cls.netchan, 0, NULL );
- }
- cl.lastframe = -1;
- cl.lastTransmitCmdNumber = cl.cmdNumber;
- return;
- }
-
- if( cl.lastTransmitCmdNumber == cl.cmdNumber ) {
- return; // nothing to send
- }
-
- // send a userinfo update if needed
- CL_SendUserinfo();
-
- if( cls.serverProtocol == PROTOCOL_VERSION_Q2PRO ) {
- CL_SendBatchedCmd();
- } else {
- CL_SendDefaultCmd();
- }
+ if( cls.state < ca_connected ) {
+ return; // not talking to a server
+ }
+
+ if( sv_paused->integer ) {
+ return;
+ }
+
+ // generate usercmds while playing a demo,
+ // but do not send them
+ if( !cls.netchan ) {
+ return;
+ }
+
+ if( cls.state < ca_active ) {
+ CL_SendUserinfo();
+
+ // just keepalive or update reliable
+ if( cls.netchan->ShouldUpdate( cls.netchan ) ) {
+ cls.netchan->Transmit( cls.netchan, 0, NULL );
+ }
+ cl.lastframe = -1;
+ cl.lastTransmitCmdNumber = cl.cmdNumber;
+ return;
+ }
+
+ if( cl.lastTransmitCmdNumber == cl.cmdNumber ) {
+ return; // nothing to send
+ }
+
+ // send a userinfo update if needed
+ CL_SendUserinfo();
+
+ if( cls.serverProtocol == PROTOCOL_VERSION_Q2PRO ) {
+ CL_SendBatchedCmd();
+ } else {
+ CL_SendDefaultCmd();
+ }
cl.sendPacketNow = qfalse;
}
diff --git a/source/cl_keys.c b/source/cl_keys.c
index 4539bb6..82d920a 100644
--- a/source/cl_keys.c
+++ b/source/cl_keys.c
@@ -213,8 +213,14 @@ Key_SetDest
===================
*/
void Key_SetDest( keydest_t dest ) {
- int diff = cls.key_dest ^ dest;
+ int diff;
+// make sure at least fullscreen console or main menu is up
+ if( cls.state == ca_disconnected && !( dest & (KEY_MENU|KEY_CONSOLE) ) ) {
+ dest |= KEY_CONSOLE;
+ }
+
+ diff = cls.key_dest ^ dest;
if( diff & KEY_CONSOLE ) {
if( dest & KEY_CONSOLE ) {
// release all keys, to keep the character from continuing an
@@ -237,7 +243,7 @@ void Key_SetDest( keydest_t dest ) {
// activate or deactivate mouse
if( diff & (KEY_CONSOLE|KEY_MENU) ) {
- CL_InputActivate();
+ IN_Activate();
}
}
@@ -662,6 +668,8 @@ void Key_Event( unsigned key, qboolean down, unsigned time ) {
Com_Error( ERR_FATAL, "%s: bad key", __func__ );
}
+ //Com_Printf("%s: %d\n",Key_KeynumToString(key),down);
+
// hack for modal presses
if( key_waiting == -1 ) {
if( down )
@@ -681,7 +689,7 @@ void Key_Event( unsigned key, qboolean down, unsigned time ) {
&& key != K_KP_PGDN
&& key_repeats[key] > 1 )
{
- return; // ignore most autorepeats
+ return; // ignore most autorepeats
}
if( key >= 200 && !keybindings[key] && !consolekeys[key] ) {
@@ -703,9 +711,9 @@ void Key_Event( unsigned key, qboolean down, unsigned time ) {
// Alt+Enter is hardcoded for all systems
if( keydown[K_ALT] && key == K_ENTER ) {
if( down ) {
- extern void Video_ToggleFullscreen( void );
+ extern void VID_ToggleFullscreen( void );
- Video_ToggleFullscreen();
+ VID_ToggleFullscreen();
}
return;
}
@@ -840,7 +848,7 @@ void Key_Event( unsigned key, qboolean down, unsigned time ) {
#ifndef USE_CHAR_EVENTS
if( keydown[K_CTRL] || keydown[K_ALT] ) {
- return;
+ // return;
}
switch( key ) {
diff --git a/source/cl_local.h b/source/cl_local.h
index 9b57cef..6026368 100644
--- a/source/cl_local.h
+++ b/source/cl_local.h
@@ -23,11 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "q_list.h"
#include "q_field.h"
#include "q_uis.h"
-#include "vid_public.h"
#include "ref_public.h"
#include "key_public.h"
#include "snd_public.h"
-#include "in_public.h"
#include "cl_public.h"
#include "ui_public.h"
#if USE_ZLIB
@@ -52,10 +50,10 @@ typedef struct centity_s {
typedef struct clientinfo_s {
char name[MAX_QPATH];
- char cinfo[MAX_QPATH];
qhandle_t skin;
qhandle_t icon;
char model_name[MAX_QPATH];
+ char skin_name[MAX_QPATH];
qhandle_t model;
qhandle_t weaponmodel[MAX_CLIENTWEAPONMODELS];
} clientinfo_t;
@@ -224,12 +222,11 @@ typedef struct client_static_s {
connstate_t state;
keydest_t key_dest;
- qboolean appactive;
+ active_t active;
qboolean ref_initialized;
- qboolean input_initialized;
+ qboolean _unused;
qboolean ui_initialized;
- //qboolean cgame_initialized;
int userinfo_modified;
cvar_t *userinfo_updates[MAX_PACKET_USERINFOS];
@@ -471,7 +468,7 @@ void CL_ParseMuzzleFlash (void);
void CL_ParseMuzzleFlash2 (void);
void SmokeAndFlash(vec3_t origin);
-void CL_SetLightstyle (int i);
+void CL_SetLightstyle( int index, const char *string, size_t length );
void CL_RunParticles (void);
void CL_RunDLights (void);
@@ -509,11 +506,12 @@ void CL_GetEntitySoundOrigin( int ent, vec3_t org );
//
// cl_input
//
+void IN_Init( void );
+void IN_Shutdown( void );
+void IN_Frame( void );
+void IN_Activate( void );
+
void CL_RegisterInput( void );
-void CL_InitInput( void );
-void CL_ShutdownInput( void );
-void CL_InputFrame( void );
-void CL_InputActivate( void );
void CL_UpdateCmd( int msec );
void CL_FinalizeCmd( void );
void CL_SendCmd( void );
@@ -523,8 +521,7 @@ void CL_SendCmd( void );
//
qboolean CL_CheckOrDownloadFile( const char *filename );
void CL_ParseServerMessage (void);
-void CL_LoadClientinfo (clientinfo_t *ci, char *s);
-void CL_ParseClientinfo( int index );
+void CL_LoadClientinfo (clientinfo_t *ci, const char *s);
void CL_Download_f (void);
void CL_DeltaFrame( void );
diff --git a/source/cl_main.c b/source/cl_main.c
index 6ddf6f2..763165b 100644
--- a/source/cl_main.c
+++ b/source/cl_main.c
@@ -1145,17 +1145,34 @@ CL_Skins_f
Load or download any custom player skins and models
=================
*/
-static void CL_Skins_f ( void ) {
+static void CL_Skins_f( void ) {
int i;
char *s;
+ clientinfo_t *ci;
- for ( i = 0 ; i < MAX_CLIENTS ; i++ ) {
+ for( i = 0 ; i < MAX_CLIENTS; i++ ) {
s = cl.configstrings[ CS_PLAYERSKINS + i ];
if( !s[0] )
continue;
- Com_Printf ( "client %i: %s\n", i, s );
- SCR_UpdateScreen ();
- CL_ParseClientinfo ( i );
+ ci = &cl.clientinfo[i];
+ CL_LoadClientinfo( ci, s );
+ Com_Printf( "client %d: %s --> %s/%s\n", i, s,
+ ci->model_name, ci->skin_name );
+ SCR_UpdateScreen();
+ }
+}
+
+static void cl_noskins_changed( cvar_t *self ) {
+ int i;
+ char *s;
+ clientinfo_t *ci;
+
+ for( i = 0 ; i < MAX_CLIENTS; i++ ) {
+ s = cl.configstrings[ CS_PLAYERSKINS + i ];
+ if( !s[0] )
+ continue;
+ ci = &cl.clientinfo[i];
+ CL_LoadClientinfo( ci, s );
}
}
@@ -2241,11 +2258,11 @@ static void CL_RestartRefresh_f( void ) {
S_StopAllSounds();
- CL_ShutdownInput();
+ IN_Shutdown();
CL_ShutdownRefresh();
CL_InitRefresh();
- CL_InitInput();
+ IN_Init();
if ( cls_state == ca_disconnected ) {
UI_OpenMenu( UIMENU_MAIN );
@@ -2396,6 +2413,7 @@ static void CL_InitLocal ( void ) {
cl_footsteps = Cvar_Get( "cl_footsteps", "1", 0 );
cl_footsteps->changed = cl_footsteps_changed;
cl_noskins = Cvar_Get ( "cl_noskins", "0", 0 );
+ cl_noskins->changed = cl_noskins_changed;
cl_predict = Cvar_Get ( "cl_predict", "1", 0 );
cl_predict->changed = cl_predict_changed;
cl_kickangles = Cvar_Get( "cl_kickangles", "1", CVAR_CHEAT );
@@ -2499,11 +2517,18 @@ qboolean CL_CheatsOK( void ) {
//============================================================================
-void CL_AppActivate( qboolean active ) {
- cls.appactive = active;
- Key_ClearStates();
- CL_InputActivate();
- S_Activate( active );
+/*
+==================
+CL_Activate
+==================
+*/
+void CL_Activate( active_t active ) {
+ if( cls.active != active ) {
+ cls.active = active;
+ Key_ClearStates();
+ IN_Activate();
+ S_Activate();
+ }
}
/*
@@ -2668,13 +2693,14 @@ void CL_Frame( int msec ) {
ref_frame = qtrue;
if( !com_timedemo->integer ) {
if( !sv_running->integer ) {
- if( !cls.appactive ) {
- // run at 10 fps if background app
+ if( cls.active == ACT_MINIMIZED ) {
+ // run at 10 fps if minimized
if( main_extra < 100 ) {
NET_Sleep( 100 - main_extra );
return;
}
- } else if( cls.state < ca_active ) {
+ ref_frame = qfalse;
+ } else if( cls.active == ACT_RESTORED || cls.state < ca_active ) {
// run at 60 fps if not active
if( main_extra < 16 ) {
NET_Sleep( 16 - main_extra );
@@ -2694,12 +2720,12 @@ void CL_Frame( int msec ) {
if( cl_paused->integer ) {
if( !sv_paused->integer ) {
Cvar_Set( "sv_paused", "1" );
- CL_InputActivate();
+ IN_Activate();
}
} else {
if( sv_paused->integer ) {
Cvar_Set( "sv_paused", "0" );
- CL_InputActivate();
+ IN_Activate();
}
}
}
@@ -2770,12 +2796,12 @@ void CL_Frame( int msec ) {
if ( host_speeds->integer )
time_after_ref = Sys_Milliseconds();
- // update audio after the 3D view was drawn
- S_Update();
-
ref_extra = 0;
}
+ // update audio after the 3D view was drawn
+ S_Update();
+
// advance local effects for next frame
CL_RunDLights();
CL_RunLightStyles();
@@ -2813,6 +2839,9 @@ void CL_Init( void ) {
// all archived variables will now be loaded
+ // start with full screen console
+ cls.key_dest = KEY_CONSOLE;
+
#ifdef _WIN32
CL_InitRefresh();
S_Init(); // sound must be initialized after window is created
@@ -2822,7 +2851,7 @@ void CL_Init( void ) {
#endif
CL_InitLocal();
- CL_InitInput();
+ IN_Init();
#if USE_ZLIB
if( inflateInit2( &cls.z, -15 ) != Z_OK ) {
@@ -2889,7 +2918,7 @@ void CL_Shutdown( void ) {
CL_ShutdownUI();
S_Shutdown();
- CL_ShutdownInput();
+ IN_Shutdown();
Con_Shutdown();
CL_ShutdownRefresh();
CL_WriteConfig();
diff --git a/source/cl_null.c b/source/cl_null.c
index 83ffe92..d49b42f 100644
--- a/source/cl_null.c
+++ b/source/cl_null.c
@@ -101,7 +101,7 @@ void Key_Event( unsigned key, qboolean down, unsigned time ) {
void Key_CharEvent( int key ) {
}
-void CL_MouseEvent( int dx, int dy ) {
+void CL_MouseEvent( int x, int y ) {
}
void CL_InputFrame( void ) {
diff --git a/source/cl_parse.c b/source/cl_parse.c
index 32a01b0..f215a29 100644
--- a/source/cl_parse.c
+++ b/source/cl_parse.c
@@ -680,39 +680,16 @@ static void CL_ParseFrame( int extrabits ) {
=====================================================================
*/
-/*
-================
-CL_ParseClientinfo
-
-Load the skin, icon, and model for a client
-================
-*/
-void CL_ParseClientinfo( int player ) {
- char *s;
- clientinfo_t *ci;
-
- s = cl.configstrings[player+CS_PLAYERSKINS];
-
- ci = &cl.clientinfo[player];
-
- if( strcmp( ci->cinfo, s ) ) {
- CL_LoadClientinfo( ci, s );
- }
-}
-
-
-static void CL_ConfigString( int index, const char *string ) {
- size_t length, maxlength;
+static void CL_ConfigString( int index, const char *string, size_t length ) {
+ size_t maxlength;
if( index >= CS_STATUSBAR && index < CS_AIRACCEL ) {
maxlength = MAX_QPATH * ( CS_AIRACCEL - index );
} else {
maxlength = MAX_QPATH;
}
- length = strlen( string );
if( length >= maxlength ) {
- Com_Error( ERR_DROP, "%s: index %d overflowed",
- __func__, index );
+ Com_Error( ERR_DROP, "%s: index %d overflowed", __func__, index );
}
memcpy( cl.configstrings[index], string, length + 1 );
@@ -732,7 +709,7 @@ static void CL_ConfigString( int index, const char *string ) {
return;
}
if (index >= CS_LIGHTS && index < CS_LIGHTS+MAX_LIGHTSTYLES) {
- CL_SetLightstyle (index - CS_LIGHTS);
+ CL_SetLightstyle( index - CS_LIGHTS, string, length );
return;
}
@@ -751,7 +728,7 @@ static void CL_ConfigString( int index, const char *string ) {
} else if (index >= CS_IMAGES && index < CS_IMAGES+MAX_MODELS) {
cl.image_precache[index-CS_IMAGES] = ref.RegisterPic (string);
} else if (index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS+MAX_CLIENTS) {
- CL_ParseClientinfo (index-CS_PLAYERSKINS);
+ CL_LoadClientinfo( &cl.clientinfo[index - CS_PLAYERSKINS], string );
} else if( index == CS_AIRACCEL && !cl.pmp.qwmod ) {
cl.pmp.airaccelerate = atoi( string ) ? qtrue : qfalse;
}
@@ -760,6 +737,7 @@ static void CL_ConfigString( int index, const char *string ) {
static void CL_ParseGamestate( void ) {
int index, bits;
char *string;
+ size_t length;
while( 1 ) {
index = MSG_ReadShort();
@@ -771,9 +749,9 @@ static void CL_ParseGamestate( void ) {
__func__, index );
}
- string = MSG_ReadString();
+ string = MSG_ReadStringLength( &length );
- CL_ConfigString( index, string );
+ CL_ConfigString( index, string, length );
}
while( 1 ) {
@@ -952,7 +930,7 @@ CL_LoadClientinfo
================
*/
-void CL_LoadClientinfo( clientinfo_t *ci, char *s ) {
+void CL_LoadClientinfo( clientinfo_t *ci, const char *s ) {
int i;
char *t;
char model_name[MAX_QPATH];
@@ -962,8 +940,6 @@ void CL_LoadClientinfo( clientinfo_t *ci, char *s ) {
char weapon_filename[MAX_QPATH];
char icon_filename[MAX_QPATH];
- strcpy( ci->cinfo, s );
-
// isolate the player's name
strcpy( ci->name, s );
t = strchr( s, '\\' );
@@ -1040,6 +1016,7 @@ void CL_LoadClientinfo( clientinfo_t *ci, char *s ) {
// didn't have it, so default to grunt
if( !ci->skin ) {
// see if the skin exists for the male model
+ strcpy( skin_name, "grunt" );
strcpy( skin_filename, "players/male/grunt.pcx" );
ci->skin = ref.RegisterSkin( skin_filename );
}
@@ -1063,6 +1040,7 @@ void CL_LoadClientinfo( clientinfo_t *ci, char *s ) {
ci->icon = ref.RegisterPic( icon_filename );
strcpy( ci->model_name, model_name );
+ strcpy( ci->skin_name, skin_name );
// must have loaded all data types to be valid
if( !ci->skin || !ci->icon || !ci->model || !ci->weaponmodel[0] ) {
@@ -1071,6 +1049,7 @@ void CL_LoadClientinfo( clientinfo_t *ci, char *s ) {
ci->model = 0;
ci->weaponmodel[0] = 0;
ci->model_name[0] = 0;
+ ci->skin_name[0] = 0;
}
}
@@ -1083,12 +1062,13 @@ CL_ParseConfigString
static void CL_ParseConfigString (void) {
int i;
char *s;
+ size_t length;
i = MSG_ReadShort ();
if (i < 0 || i >= MAX_CONFIGSTRINGS)
Com_Error( ERR_DROP, "%s: bad index: %d", __func__, i );
- s = MSG_ReadString();
+ s = MSG_ReadStringLength( &length );
if( cl_shownet->integer > 2 ) {
Com_Printf( " %i \"%s\"\n", i, Q_FormatString( s ) );
@@ -1098,7 +1078,7 @@ static void CL_ParseConfigString (void) {
Q_SetBit( cl.dcs, i );
}
- CL_ConfigString( i, s );
+ CL_ConfigString( i, s, length );
}
diff --git a/source/cl_ref.c b/source/cl_ref.c
index bcce301..6bd9fd7 100644
--- a/source/cl_ref.c
+++ b/source/cl_ref.c
@@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "cl_local.h"
+#include "vid_public.h"
+#include "in_public.h"
#include "vid_local.h"
// Structure containing functions exported from refresh DLL
@@ -31,12 +33,12 @@ refAPI_t ref;
// Console variables that we need to access from this module
cvar_t *vid_ref; // Name of Refresh DLL loaded
-cvar_t *vid_placement;
+cvar_t *vid_geometry;
cvar_t *vid_modelist;
cvar_t *vid_fullscreen;
cvar_t *_vid_fullscreen;
-#define MODE_PLACEMENT 1
+#define MODE_GEOMETRY 1
#define MODE_FULLSCREEN 2
#define MODE_MODELIST 4
#define MODE_REFRESH 8
@@ -63,7 +65,7 @@ HELPER FUNCTIONS
// 640x480@75
// 640x480@75:32
// 640x480:32@75
-void Video_GetModeFS( vrect_t *rc, int *freq, int *depth ) {
+void VID_GetModeFS( vrect_t *rc, int *freq, int *depth ) {
char *s = vid_modelist->string;
int mode = 1;
int w = 640, h = 480, hz = 0, bpp = 0;
@@ -109,8 +111,8 @@ malformed:
rc->x = 0;
rc->y = 0;
- rc->width = w & ~7;
- rc->height = h & ~1;
+ rc->width = w;
+ rc->height = h;
if( freq ) {
*freq = hz;
@@ -123,13 +125,13 @@ malformed:
// 640x480
// 640x480+0
// 640x480+0+0
-void Video_GetPlacement( vrect_t *rc ) {
- char *s = vid_placement->string;
+void VID_GetGeometry( vrect_t *rc ) {
+ char *s = vid_geometry->string;
int w = 640, h = 480, x = 0, y = 0;
w = strtoul( s, &s, 10 );
if( *s != 'x' ) {
- Com_DPrintf( "Placement string is malformed\n" );
+ Com_DPrintf( "Geometry string is malformed\n" );
goto malformed;
}
h = strtoul( s + 1, &s, 10 );
@@ -153,20 +155,20 @@ malformed:
rc->x = x;
rc->y = y;
- rc->width = w & ~7;
- rc->height = h & ~1;
+ rc->width = w;
+ rc->height = h;
}
-void Video_SetPlacement( vrect_t *rc ) {
+void VID_SetGeometry( vrect_t *rc ) {
char buffer[MAX_QPATH];
Com_sprintf( buffer, sizeof( buffer ), "%dx%d+%d+%d",
rc->width, rc->height, rc->x, rc->y );
- Cvar_Set( "vid_placement", buffer );
+ Cvar_SetByVar( vid_geometry, buffer, CVAR_SET_DIRECT );
}
-void Video_ToggleFullscreen( void ) {
+void VID_ToggleFullscreen( void ) {
if( !vid_fullscreen->integer ) {
if( !_vid_fullscreen->integer ) {
Cvar_Set( "_vid_fullscreen", "1" );
@@ -224,10 +226,10 @@ static qboolean CL_RefSetupCallback( api_type_t type, void *api ) {
Sys_FillAPI( ( sysAPI_t * )api );
break;
case API_VIDEO_SOFTWARE:
- Video_FillSWAPI( ( videoAPI_t * )api );
+ VID_FillSWAPI( ( videoAPI_t * )api );
break;
case API_VIDEO_OPENGL:
- Video_FillGLAPI( ( videoAPI_t * )api );
+ VID_FillGLAPI( ( videoAPI_t * )api );
break;
default:
Com_Error( ERR_FATAL, "CL_RefSetupCallback: bad api type" );
@@ -261,9 +263,9 @@ static qboolean CL_LoadRefresh( const char *name ) {
#ifdef REF_HARD_LINKED
#ifdef SOFTWARE_RENDERER
- Video_FillSWAPI( &video );
+ VID_FillSWAPI( &video );
#else
- Video_FillGLAPI( &video );
+ VID_FillGLAPI( &video );
#endif
Ref_APISetupCallback( API_REFRESH, &ref );
@@ -325,7 +327,7 @@ void CL_PumpEvents( void ) {
return;
}
- Video_PumpEvents();
+ VID_PumpEvents();
if( mode_changed ) {
#ifndef REF_HARD_LINKED
@@ -337,15 +339,15 @@ void CL_PumpEvents( void ) {
if( vid_fullscreen->integer ) {
Cbuf_AddText( "set _vid_fullscreen $vid_fullscreen\n" );
}
- Video_ModeChanged();
+ VID_ModeChanged();
} else {
if( vid_fullscreen->integer ) {
if( mode_changed & MODE_MODELIST ) {
- Video_ModeChanged();
+ VID_ModeChanged();
}
} else {
- if( mode_changed & MODE_PLACEMENT ) {
- Video_ModeChanged();
+ if( mode_changed & MODE_GEOMETRY ) {
+ VID_ModeChanged();
}
}
}
@@ -353,8 +355,8 @@ void CL_PumpEvents( void ) {
}
}
-static void vid_placement_changed( cvar_t *self ) {
- mode_changed |= MODE_PLACEMENT;
+static void vid_geometry_changed( cvar_t *self ) {
+ mode_changed |= MODE_GEOMETRY;
}
static void vid_fullscreen_changed( cvar_t *self ) {
@@ -382,7 +384,7 @@ void CL_InitRefresh( void ) {
}
// Create the video variables so we know how to start the graphics drivers
- vid_placement = Cvar_Get( "vid_placement", "640x480", CVAR_ARCHIVE );
+ vid_geometry = Cvar_Get( "vid_geometry", "640x480", CVAR_ARCHIVE );
vid_fullscreen = Cvar_Get( "vid_fullscreen", "0", CVAR_ARCHIVE );
_vid_fullscreen = Cvar_Get( "_vid_fullscreen", "1", CVAR_ARCHIVE );
vid_modelist = Cvar_Get( "vid_modelist", "640x480 800x600 1024x768", CVAR_ARCHIVE );
@@ -420,7 +422,7 @@ void CL_InitRefresh( void ) {
vid_ref->changed = vid_ref_changed;
#endif
- vid_placement->changed = vid_placement_changed;
+ vid_geometry->changed = vid_geometry_changed;
vid_fullscreen->changed = vid_fullscreen_changed;
vid_modelist->changed = vid_modelist_changed;
@@ -450,7 +452,7 @@ void CL_ShutdownRefresh( void ) {
SCR_Shutdown();
CL_ShutdownUI();
- vid_placement->changed = NULL;
+ vid_geometry->changed = NULL;
vid_fullscreen->changed = NULL;
vid_modelist->changed = NULL;
#if !REF_HARD_LINKED
diff --git a/source/cl_scrn.c b/source/cl_scrn.c
index c36f2b0..fefd8dd 100644
--- a/source/cl_scrn.c
+++ b/source/cl_scrn.c
@@ -454,7 +454,7 @@ void SCR_TouchPics( void ) {
void SCR_ModeChanged( void ) {
ref.GetConfig( &scr_glconfig );
- CL_AppActivate( cls.appactive );
+ IN_Activate();
UI_ModeChanged();
}
@@ -1083,7 +1083,7 @@ void SCR_UpdateScreen( void ) {
return; // not initialized yet
if( recursive > 1 ) {
- Com_Error( ERR_FATAL, "SCR_UpdateScreen: recursively called" );
+ Com_Error( ERR_FATAL, "%s: recursively called", __func__ );
}
recursive++;
@@ -1127,7 +1127,7 @@ void SCR_UpdateScreen( void ) {
break;
default:
- Com_Error( ERR_FATAL, "SCR_DrawScreenFrame: bad cls.state" );
+ Com_Error( ERR_FATAL, "%s: bad cls.state", __func__ );
break;
}
diff --git a/source/cl_ui.c b/source/cl_ui.c
index c8d1601..e4cc1e5 100644
--- a/source/cl_ui.c
+++ b/source/cl_ui.c
@@ -252,12 +252,12 @@ void UI_AddToServerList( const serverStatus_t *status ) {
/*
===================
-UI_MouseMove
+UI_MouseEvent
===================
*/
-void UI_MouseMove( int dx, int dy ) {
+void UI_MouseEvent( int dx, int dy ) {
if( cls.ui_initialized ) {
- ui.MouseMove( dx, dy );
+ ui.MouseEvent( dx, dy );
}
}
diff --git a/source/com_local.h b/source/com_local.h
index bcc6903..a6e5492 100644
--- a/source/com_local.h
+++ b/source/com_local.h
@@ -1091,9 +1091,14 @@ extern cvar_t *allow_download_maps;
extern cvar_t *allow_download_demos;
extern cvar_t *allow_download_other;
+typedef enum {
+ ACT_MINIMIZED,
+ ACT_RESTORED,
+ ACT_ACTIVATED
+} active_t;
+
void CL_PumpEvents( void );
void CL_PacketEvent( neterr_t ret );
-void CL_MouseEvent( int dx, int dy );
void CL_Init (void);
void CL_Disconnect( comErrorType_t type, const char *text );
void CL_Shutdown (void);
@@ -1105,11 +1110,13 @@ void SCR_BeginLoadingPlaque (void);
void SCR_ModeChanged( void );
void CL_LocalConnect( void );
void CL_RestartFilesystem( void );
-void CL_InputFrame( void );
-void CL_InputActivate( void );
-void CL_AppActivate( qboolean active );
+void CL_Activate( active_t active );
void CL_UpdateUserinfo( cvar_t *var, cvarSetSource_t source );
+void IN_Frame( void );
+void IN_Activate( void );
+void IN_MouseEvent( int x, int y );
+
void Key_Init( void );
void Key_Event( unsigned key, qboolean down, unsigned time );
void Key_CharEvent( int key );
diff --git a/source/common.c b/source/common.c
index 1510696..cdfc1dc 100644
--- a/source/common.c
+++ b/source/common.c
@@ -1415,7 +1415,7 @@ void Com_ProcessEvents( void ) {
} while( ret == NET_OK );
CL_PumpEvents();
- CL_InputFrame();
+ IN_Frame();
#endif
}
diff --git a/source/files.c b/source/files.c
index 34a07d5..4f9974a 100644
--- a/source/files.c
+++ b/source/files.c
@@ -224,7 +224,6 @@ static fsFile_t *FS_FileForHandle( fileHandle_t f ) {
qboolean FS_ValidatePath( const char *s ) {
const char *start;
- int back;
// check for leading slash
// check for empty path
@@ -237,10 +236,7 @@ qboolean FS_ValidatePath( const char *s ) {
while( *s ) {
// check for ".."
if( *s == '.' && s[1] == '.' ) {
- if( back > 1 ) {
- return qfalse;
- }
- back++; // allow one level back
+ return qfalse;
}
if( *s == '/' || *s == '\\' ) {
// check for two slashes in a row
@@ -1569,10 +1565,10 @@ static void q_printf( 2, 3 ) FS_AddGameDirectory( int mode, const char *fmt, ...
#if USE_ZLIB
//
- // add any zip files in the format *.pk2
+ // add any zip files in the format *.pkz
//
if( !( fs_restrict_mask->integer & 4 ) ) {
- FS_LoadPackFiles( mode, ".pk2", FS_LoadZipFile );
+ FS_LoadPackFiles( mode, ".pkz", FS_LoadZipFile );
}
#endif
}
@@ -1754,6 +1750,12 @@ void **FS_ListFiles( const char *path,
}
}
+ count = 0;
+
+ if( numFiles ) {
+ *numFiles = 0;
+ }
+
if( !path ) {
path = "";
pathlen = 0;
@@ -1761,15 +1763,13 @@ void **FS_ListFiles( const char *path,
if( *path == '/' ) {
path++;
}
+ if( !FS_ValidatePath( path ) ) {
+ FS_DPrintf( "%s: refusing invalid path: %s\n", __func__, path );
+ return NULL;
+ }
pathlen = strlen( path );
}
- count = 0;
-
- if( numFiles ) {
- *numFiles = 0;
- }
-
for( search = fs_searchpaths; search; search = search->next ) {
if( flags & FS_PATH_MASK ) {
if( ( flags & search->mode & FS_PATH_MASK ) == 0 ) {
@@ -2165,7 +2165,7 @@ void FS_Path_f( void ) {
#if USE_ZLIB
if( !( fs_restrict_mask->integer & 4 ) ) {
- Com_Printf( "%i files in PK2 files\n", numFilesInPK2 );
+ Com_Printf( "%i files in PKZ files\n", numFilesInPK2 );
}
#endif
}
@@ -2613,13 +2613,13 @@ void FS_Init( void ) {
Cmd_Register( c_fs );
fs_debug = Cvar_Get( "fs_debug", "0", 0 );
- fs_restrict_mask = Cvar_Get( "fs_restrict_mask", "4", CVAR_NOSET );
+ fs_restrict_mask = Cvar_Get( "fs_restrict_mask", "0", CVAR_NOSET );
if( ( fs_restrict_mask->integer & 7 ) == 7 ) {
Com_WPrintf( "Invalid fs_restrict_mask value %d. "
"Falling back to default.\n",
fs_restrict_mask->integer );
- Cvar_SetInteger( "fs_restrict_mask", 4 );
+ Cvar_Set( "fs_restrict_mask", "0" );
}
// start up with baseq2 by default
diff --git a/source/gl_main.c b/source/gl_main.c
index 5c1e7fc..b2a5d98 100644
--- a/source/gl_main.c
+++ b/source/gl_main.c
@@ -672,8 +672,8 @@ static void GL_Strings_f( void ) {
static void GL_ModeChanged( int width, int height, int flags,
int rowbytes, void *pixels )
{
- gl_config.vidWidth = width;
- gl_config.vidHeight = height;
+ gl_config.vidWidth = width & ~7;
+ gl_config.vidHeight = height & ~1;
gl_config.flags = flags;
}
diff --git a/source/gl_models.c b/source/gl_models.c
index e1a6848..fa63470 100644
--- a/source/gl_models.c
+++ b/source/gl_models.c
@@ -107,7 +107,7 @@ static void Model_List_f( void ) {
continue;
}
- Com_Printf( "%8i : %s\n", model->pool.cursize, model->name );
+ Com_Printf( "%8"PRIz" : %s\n", model->pool.cursize, model->name );
bytes += model->pool.cursize;
}
Com_Printf( "Total resident: %i\n", bytes );
diff --git a/source/in_dx.c b/source/in_dx.c
index 684853a..3d7e508 100644
--- a/source/in_dx.c
+++ b/source/in_dx.c
@@ -37,12 +37,12 @@ typedef HRESULT (WINAPI *LPDIRECTINPUTCREATE)( HINSTANCE, DWORD, LPDIRECTINPUT *
static LPDIRECTINPUTCREATE pDirectInputCreate;
-static qboolean di_active; // qfalse when not focus app
+static grab_t di_grabbed; // qfalse when not focus app
static qboolean di_initialized;
static LPDIRECTINPUT di;
static LPDIRECTINPUTDEVICE di_mouse;
-static DIOBJECTDATAFORMAT mouseObjectDataFormat[] = {
+static const DIOBJECTDATAFORMAT mouseObjectDataFormat[] = {
{ &GUID_XAxis, DIMOFS_X, DIDFT_RELAXIS|DIDFT_ANYINSTANCE, 0 },
{ &GUID_YAxis, DIMOFS_Y, DIDFT_RELAXIS|DIDFT_ANYINSTANCE, 0 },
{ &GUID_ZAxis, DIMOFS_Z, DIDFT_RELAXIS|DIDFT_ANYINSTANCE|DIDFT_OPTIONAL, 0 },
@@ -56,7 +56,7 @@ static DIOBJECTDATAFORMAT mouseObjectDataFormat[] = {
{ NULL, DIMOFS_BUTTON7, DIDFT_BUTTON|DIDFT_ANYINSTANCE|DIDFT_OPTIONAL, 0 }
};
-static DIDATAFORMAT mouseDataFormat = {
+static const DIDATAFORMAT mouseDataFormat = {
sizeof( DIDATAFORMAT ),
sizeof( DIOBJECTDATAFORMAT ),
DIDF_RELAXIS,
@@ -65,7 +65,7 @@ static DIDATAFORMAT mouseDataFormat = {
mouseObjectDataFormat
};
-static DIPROPDWORD mouseBufferSize = {
+static const DIPROPDWORD mouseBufferSize = {
{
sizeof( DIPROPDWORD ),
sizeof( DIPROPHEADER ),
@@ -80,7 +80,7 @@ static DIPROPDWORD mouseBufferSize = {
#endif
#define DEFINE_GUID( name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8 ) \
- const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
+ static const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
DEFINE_GUID( GUID_SysMouse, 0x6F1D2B60, 0xD5A0, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 );
DEFINE_GUID( GUID_XAxis, 0xA36D02E0, 0xC9F3, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 );
@@ -89,22 +89,17 @@ DEFINE_GUID( GUID_ZAxis, 0xA36D02E2, 0xC9F3, 0x11CF, 0xBF, 0xC7, 0x44, 0x45, 0x5
/*
===========
-DI_SendMouseMoveEvents
+DI_GetMouseEvents
===========
*/
-void DI_SendMouseMoveEvents( void ) {
+static void DI_GetMouseEvents( void ) {
DIDEVICEOBJECTDATA data[16];
LPDIDEVICEOBJECTDATA p, last;
- DIMOUSESTATE2 state;
DWORD numElements, button;
int value;
HRESULT hr;
- if( !di_initialized ) {
- return;
- }
-
- if( !di_active ) {
+ if( !di_initialized || !di_grabbed ) {
return;
}
@@ -120,7 +115,7 @@ void DI_SendMouseMoveEvents( void ) {
return;
}
last = data + numElements;
- for( p = data; p != last; p++ ) {
+ for( p = data; p < last; p++ ) {
switch( p->dwOfs ) {
case DIMOFS_BUTTON0:
case DIMOFS_BUTTON1:
@@ -155,17 +150,30 @@ void DI_SendMouseMoveEvents( void ) {
}
}
} while( hr == DI_BUFFEROVERFLOW );
+}
+
+/*
+===========
+DI_GetMouseMotion
+===========
+*/
+static qboolean DI_GetMouseMotion( int *dx, int *dy ) {
+ DIMOUSESTATE2 state;
+ HRESULT hr;
+
+ if( !di_initialized || !di_grabbed ) {
+ return qfalse;
+ }
hr = IDirectInputDevice_GetDeviceState( di_mouse, sizeof( state ), &state );
if( FAILED( hr ) ) {
Com_EPrintf( "GetDeviceState failed with error 0x%lX\n", hr );
- return;
- }
-
- if( state.lX || state.lY ) {
- CL_MouseEvent( state.lX, state.lY );
+ return qfalse;
}
+ *dx = state.lX;
+ *dy = state.lY;
+ return qtrue;
}
/*
@@ -177,7 +185,7 @@ static void DI_ShutdownMouse( void ) {
Com_Printf( "Shutting down DirectInput\n" );
if( di_mouse ) {
- if( di_active ) {
+ if( di_grabbed ) {
IDirectInputDevice_Unacquire( di_mouse );
}
IDirectInputDevice_Release( di_mouse );
@@ -187,7 +195,7 @@ static void DI_ShutdownMouse( void ) {
IDirectInput_Release( di );
di = NULL;
}
- di_active = qfalse;
+ di_grabbed = qfalse;
di_initialized = qfalse;
}
@@ -269,25 +277,21 @@ fail:
/*
===========
-DI_ActivateMouse
-
-Called when the main window gains or loses focus.
-The window may have been destroyed and recreated
-between a deactivate and an activate.
+DI_GrabMouse
===========
*/
-static void DI_ActivateMouse( qboolean active ) {
+static void DI_GrabMouse( grab_t grab ) {
HRESULT hr;
if( !di_initialized ) {
return;
}
- if( di_active == active ) {
+ if( di_grabbed == grab ) {
return;
}
- if( active ) {
+ if( grab ) {
Com_DPrintf( "IDirectInputDevice_Acquire\n" );
hr = IDirectInputDevice_Acquire( di_mouse );
if( FAILED( hr ) ) {
@@ -301,16 +305,8 @@ static void DI_ActivateMouse( qboolean active ) {
}
}
- di_active = active;
-
-}
+ di_grabbed = grab;
-/*
-===================
-DI_ClearMouseStates
-===================
-*/
-static void DI_ClearMouseStates( void ) {
}
/*
@@ -321,8 +317,8 @@ DI_FillAPI
void DI_FillAPI( inputAPI_t *api ) {
api->Init = DI_InitMouse;
api->Shutdown = DI_ShutdownMouse;
- api->Activate = DI_ActivateMouse;
- api->Frame = DI_SendMouseMoveEvents;
- api->ClearStates = DI_ClearMouseStates;
+ api->Grab = DI_GrabMouse;
+ api->GetEvents = DI_GetMouseEvents;
+ api->GetMotion = DI_GetMouseMotion;
}
diff --git a/source/in_evdev.c b/source/in_evdev.c
index 932b3fa..8eb1c1d 100644
--- a/source/in_evdev.c
+++ b/source/in_evdev.c
@@ -34,19 +34,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static cvar_t *in_device;
-static qboolean mouseinitialized;
-static qboolean mouseactive;
-static int evdev_fd;
+static struct {
+ qboolean initialized;
+ qboolean grabbed;
+ int fd;
+ int dx, dy;
+} evdev;
#define MAX_EVENTS 64
#define EVENT_SIZE sizeof( struct input_event )
/*
===========
-Evdev_SendMouseMoveEvents
+Evdev_RunMouse
===========
*/
-static void Evdev_SendMouseMoveEvents( void ) {
+static void Evdev_RunMouse( void ) {
struct input_event ev[MAX_EVENTS];
fd_set fdset;
struct timeval timeout;
@@ -55,27 +58,23 @@ static void Evdev_SendMouseMoveEvents( void ) {
int i, button;
unsigned time;
- if( !mouseinitialized ) {
- return;
- }
-
- if( !mouseactive ) {
+ if( !evdev.initialized || !evdev.grabbed ) {
return;
}
FD_ZERO( &fdset );
- FD_SET( evdev_fd, &fdset );
+ FD_SET( evdev.fd, &fdset );
timeout.tv_sec = 0;
timeout.tv_usec = 0;
if( select( FD_SETSIZE, &fdset, NULL, NULL, &timeout ) == -1 ) {
return;
}
- if( !FD_ISSET( evdev_fd, &fdset ) ) {
+ if( !FD_ISSET( evdev.fd, &fdset ) ) {
return;
}
- bytes = read( evdev_fd, ev, EVENT_SIZE * MAX_EVENTS );
+ bytes = read( evdev.fd, ev, EVENT_SIZE * MAX_EVENTS );
if( bytes < EVENT_SIZE ) {
return;
}
@@ -98,10 +97,10 @@ static void Evdev_SendMouseMoveEvents( void ) {
case EV_REL:
switch( ev[i].code ) {
case REL_X:
- dx += ( int )ev[i].value;
+ evdev.dx += ( int )ev[i].value;
break;
case REL_Y:
- dy += ( int )ev[i].value;
+ evdev.dy += ( int )ev[i].value;
break;
case REL_WHEEL:
if( ( int )ev[i].value == 1 ) {
@@ -119,12 +118,17 @@ static void Evdev_SendMouseMoveEvents( void ) {
break;
}
}
+}
-
- if( dx || dy ) {
- CL_MouseEvent( dx, dy );
- }
-
+static qboolean Evdev_GetMouseMotion( int *dx, int *dy ) {
+ if( !evdev.initialized || !evdev.grabbed ) {
+ return qfalse;
+ }
+ *dx = evdev.dx;
+ *dy = evdev.dy;
+ evdev.dx = 0;
+ evdev.dy = 0;
+ return qtrue;
}
/*
@@ -133,12 +137,11 @@ Evdev_ShutdownMouse
===========
*/
static void Evdev_ShutdownMouse( void ) {
- if( !mouseinitialized ) {
+ if( !evdev.initialized ) {
return;
}
- close( evdev_fd );
- mouseinitialized = qfalse;
- mouseactive = qfalse;
+ close( evdev.fd );
+ memset( &evdev, 0, sizeof( evdev ) );
}
/*
@@ -149,79 +152,68 @@ Evdev_StartupMouse
static qboolean Evdev_InitMouse( void ) {
in_device = Cvar_Get( "in_device", "/dev/input/event2", CVAR_LATCH );
- evdev_fd = open( in_device->string, O_RDONLY );
-
- if( evdev_fd == -1 ) {
+ evdev.fd = open( in_device->string, O_RDONLY );
+ if( evdev.fd == -1 ) {
Com_EPrintf( "Couldn't open %s: %s\n", in_device->string,
- strerror( errno ) );
+ strerror( errno ) );
return qfalse;
}
- fcntl( evdev_fd, F_SETFL, fcntl( evdev_fd, F_GETFL, 0 ) | FNDELAY );
+ fcntl( evdev.fd, F_SETFL, fcntl( evdev.fd, F_GETFL, 0 ) | FNDELAY );
Com_Printf( "Event interface initialized.\n" );
- mouseinitialized = qtrue;
+ evdev.initialized = qtrue;
return qtrue;
}
/*
===========
-Evdev_ActivateMouse
-
-Called when the main window gains or loses focus.
-The window may have been destroyed and recreated
-between a deactivate and an activate.
+Evdev_GrabMouse
===========
*/
-static void Evdev_ActivateMouse( qboolean active ) {
- if( !mouseinitialized ) {
+static void Evdev_GrabMouse( grab_t grab ) {
+ if( !evdev.initialized ) {
return;
}
- if( mouseactive == active ) {
+ if( evdev.grabbed == grab ) {
return;
}
#ifdef EVIOCGRAB
- if( ioctl( evdev_fd, EVIOCGRAB, active ) == -1 ) {
+ if( ioctl( evdev.fd, EVIOCGRAB, active ) == -1 ) {
Com_EPrintf( "Grab/Release failed: %s\n", strerror( errno ) );
}
#endif // EVIOCGRAB
- if( active ) {
+ if( grab ) {
struct input_event ev;
SDL_ShowCursor( SDL_DISABLE );
- while( read( evdev_fd, &ev, EVENT_SIZE ) == EVENT_SIZE )
+ while( read( evdev.fd, &ev, EVENT_SIZE ) == EVENT_SIZE )
;
} else {
SDL_ShowCursor( SDL_ENABLE );
}
- mouseactive = active;
-}
-
-/*
-===================
-Evdev_ClearMouseStates
-===================
-*/
-static void Evdev_ClearMouseStates( void ) {
+ evdev.dx = 0;
+ evdev.dy = 0;
+ evdev.grabbed = grab;
}
/*
@@@@@@@@@@@@@@@@@@@
-Evdev_FillAPI
+DI_FillAPI
@@@@@@@@@@@@@@@@@@@
*/
-void Evdev_FillAPI( inputAPI_t *api ) {
+void DI_FillAPI( inputAPI_t *api ) {
api->Init = Evdev_InitMouse;
api->Shutdown = Evdev_ShutdownMouse;
- api->Activate = Evdev_ActivateMouse;
- api->Frame = Evdev_SendMouseMoveEvents;
- api->ClearStates = Evdev_ClearMouseStates;
+ api->Grab = Evdev_GrabMouse;
+ api->GetEvents = Evdev_GetMouseEvents;
+ api->GetMotion = Evdev_GetMouseMotion;
}
diff --git a/source/in_public.h b/source/in_public.h
index 82c4a47..47a3ff9 100644
--- a/source/in_public.h
+++ b/source/in_public.h
@@ -22,13 +22,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// in_public.h -- external (non-keyboard) input devices
//
+typedef enum {
+ IN_SHOW,
+ IN_HIDE,
+ IN_GRAB
+} grab_t;
+
typedef struct inputAPI_s {
qboolean (*Init)( void );
- void (*Shutdown)( void );
- void (*Activate)( qboolean active );
- void (*Frame)( void );
- void (*ClearStates)( void );
+ void (*Shutdown)( void );
+ void (*Grab)( grab_t grab );
+ void (*Warp)( int x, int y );
+ void (*GetEvents)( void );
+ qboolean (*GetMotion)( int *dx, int *dy );
} inputAPI_t;
-extern inputAPI_t input;
-
diff --git a/source/q_files.h b/source/q_files.h
index 9d66f8d..6cc84d5 100644
--- a/source/q_files.h
+++ b/source/q_files.h
@@ -31,20 +31,20 @@ The .pak files are just a linear collapse of a directory tree
========================================================================
*/
-#define IDPAKHEADER (('K'<<24)+('C'<<16)+('A'<<8)+'P')
+#define IDPAKHEADER (('K'<<24)+('C'<<16)+('A'<<8)+'P')
typedef struct {
- char name[56];
- uint32_t filepos, filelen;
+ char name[56];
+ uint32_t filepos, filelen;
} dpackfile_t;
typedef struct {
- uint32_t ident; // == IDPAKHEADER
- uint32_t dirofs;
- uint32_t dirlen;
+ uint32_t ident; // == IDPAKHEADER
+ uint32_t dirofs;
+ uint32_t dirlen;
} dpackheader_t;
-#define MAX_FILES_IN_PACK 4096
+#define MAX_FILES_IN_PACK 4096
/*
@@ -56,19 +56,19 @@ PCX files are used for as many images as possible
*/
typedef struct {
- uint8_t manufacturer;
- uint8_t version;
- uint8_t encoding;
- uint8_t bits_per_pixel;
- uint16_t xmin,ymin,xmax,ymax;
- uint16_t hres,vres;
- uint8_t palette[48];
- uint8_t reserved;
- uint8_t color_planes;
- uint16_t bytes_per_line;
- uint16_t palette_type;
- uint8_t filler[58];
- uint8_t data[1]; // unbounded
+ uint8_t manufacturer;
+ uint8_t version;
+ uint8_t encoding;
+ uint8_t bits_per_pixel;
+ uint16_t xmin,ymin,xmax,ymax;
+ uint16_t hres,vres;
+ uint8_t palette[48];
+ uint8_t reserved;
+ uint8_t color_planes;
+ uint16_t bytes_per_line;
+ uint16_t palette_type;
+ uint8_t filler[58];
+ uint8_t data[1]; // unbounded
} pcx_t;
@@ -80,28 +80,28 @@ typedef struct {
========================================================================
*/
-#define IDALIASHEADER (('2'<<24)+('P'<<16)+('D'<<8)+'I')
-#define ALIAS_VERSION 8
+#define IDALIASHEADER (('2'<<24)+('P'<<16)+('D'<<8)+'I')
+#define ALIAS_VERSION 8
-#define MAX_TRIANGLES 4096
-#define MAX_VERTS 2048
-#define MAX_FRAMES 512
-#define MAX_MD2SKINS 32
-#define MAX_SKINNAME 64
+#define MAX_TRIANGLES 4096
+#define MAX_VERTS 2048
+#define MAX_FRAMES 512
+#define MAX_MD2SKINS 32
+#define MAX_SKINNAME 64
typedef struct {
- int16_t s;
- int16_t t;
+ int16_t s;
+ int16_t t;
} dstvert_t;
typedef struct {
- uint16_t index_xyz[3];
- uint16_t index_st[3];
+ uint16_t index_xyz[3];
+ uint16_t index_st[3];
} dtriangle_t;
typedef struct {
- uint8_t v[3]; // scaled byte to fit in frame mins/maxs
- uint8_t lightnormalindex;
+ uint8_t v[3]; // scaled byte to fit in frame mins/maxs
+ uint8_t lightnormalindex;
} dtrivertx_t;
#define DTRIVERTX_V0 0
@@ -111,10 +111,10 @@ typedef struct {
#define DTRIVERTX_SIZE 4
typedef struct {
- float scale[3]; // multiply byte verts by this
- float translate[3]; // then add this
- char name[16]; // frame name from grabbing
- dtrivertx_t verts[1]; // variable sized
+ float scale[3]; // multiply byte verts by this
+ float translate[3]; // then add this
+ char name[16]; // frame name from grabbing
+ dtrivertx_t verts[1]; // variable sized
} daliasframe_t;
#define MAX_FRAMESIZE ( sizeof( daliasframe_t ) + sizeof( dtrivertx_t ) * ( MAX_VERTS - 1 ) )
@@ -130,260 +130,260 @@ typedef struct {
typedef struct {
- uint32_t ident;
- uint32_t version;
+ uint32_t ident;
+ uint32_t version;
- uint32_t skinwidth;
- uint32_t skinheight;
- uint32_t framesize; // byte size of each frame
+ uint32_t skinwidth;
+ uint32_t skinheight;
+ uint32_t framesize; // byte size of each frame
- uint32_t num_skins;
- uint32_t num_xyz;
- uint32_t num_st; // greater than num_xyz for seams
- uint32_t num_tris;
- uint32_t num_glcmds; // dwords in strip/fan command list
- uint32_t num_frames;
+ uint32_t num_skins;
+ uint32_t num_xyz;
+ uint32_t num_st; // greater than num_xyz for seams
+ uint32_t num_tris;
+ uint32_t num_glcmds; // dwords in strip/fan command list
+ uint32_t num_frames;
- uint32_t ofs_skins; // each skin is a MAX_SKINNAME string
- uint32_t ofs_st; // byte offset from start for stverts
- uint32_t ofs_tris; // offset for dtriangles
- uint32_t ofs_frames; // offset for first frame
- uint32_t ofs_glcmds;
- uint32_t ofs_end; // end of file
+ uint32_t ofs_skins; // each skin is a MAX_SKINNAME string
+ uint32_t ofs_st; // byte offset from start for stverts
+ uint32_t ofs_tris; // offset for dtriangles
+ uint32_t ofs_frames; // offset for first frame
+ uint32_t ofs_glcmds;
+ uint32_t ofs_end; // end of file
} dmdl_t;
/*
- =======================================================================
+ =======================================================================
- .MD3 triangle model file format
+ .MD3 triangle model file format
- =======================================================================
-*/
+ =======================================================================
+ */
-#define MD3_IDENT (('3'<<24)+('P'<<16)+('D'<<8)+'I')
-#define MD3_VERSION 15
+#define MD3_IDENT (('3'<<24)+('P'<<16)+('D'<<8)+'I')
+#define MD3_VERSION 15
// limits
-#define MD3_MAX_LODS 3
-#define MD3_MAX_TRIANGLES 8192 // per surface
-#define MD3_MAX_VERTS 4096 // per surface
-#define MD3_MAX_SHADERS 256 // per surface
-#define MD3_MAX_FRAMES 1024 // per model
-#define MD3_MAX_SURFACES 32 // per model
-#define MD3_MAX_TAGS 16 // per frame
-#define MD3_MAX_PATH 64
+#define MD3_MAX_LODS 3
+#define MD3_MAX_TRIANGLES 8192 // per surface
+#define MD3_MAX_VERTS 4096 // per surface
+#define MD3_MAX_SHADERS 256 // per surface
+#define MD3_MAX_FRAMES 1024 // per model
+#define MD3_MAX_SURFACES 32 // per model
+#define MD3_MAX_TAGS 16 // per frame
+#define MD3_MAX_PATH 64
// vertex scales
-#define MD3_XYZ_SCALE (1.0f/64.0f)
+#define MD3_XYZ_SCALE (1.0f/64.0f)
typedef struct {
- float st[2];
+ float st[2];
} dmd3coord_t;
typedef struct {
- int16_t point[3];
- uint8_t norm[2];
+ int16_t point[3];
+ uint8_t norm[2];
} dmd3vertex_t;
typedef struct {
- float mins[3];
- float maxs[3];
- float translate[3];
- float radius;
- char creator[16];
+ float mins[3];
+ float maxs[3];
+ float translate[3];
+ float radius;
+ char creator[16];
} dmd3frame_t;
typedef struct {
- char name[MD3_MAX_PATH]; // tag name
- float origin[3];
- float axis[3][3];
+ char name[MD3_MAX_PATH]; // tag name
+ float origin[3];
+ float axis[3][3];
} dmd3tag_t;
typedef struct {
- char name[MD3_MAX_PATH];
- uint32_t unused; // shader
+ char name[MD3_MAX_PATH];
+ uint32_t unused; // shader
} dmd3skin_t;
typedef struct {
- uint32_t ident;
+ uint32_t ident;
- char name[MD3_MAX_PATH];
- uint32_t flags;
+ char name[MD3_MAX_PATH];
+ uint32_t flags;
- uint32_t num_frames;
- uint32_t num_skins;
- uint32_t num_verts;
- uint32_t num_tris;
+ uint32_t num_frames;
+ uint32_t num_skins;
+ uint32_t num_verts;
+ uint32_t num_tris;
- uint32_t ofs_indexes;
- uint32_t ofs_skins;
- uint32_t ofs_tcs;
- uint32_t ofs_verts;
+ uint32_t ofs_indexes;
+ uint32_t ofs_skins;
+ uint32_t ofs_tcs;
+ uint32_t ofs_verts;
- uint32_t meshsize;
+ uint32_t meshsize;
} dmd3mesh_t;
typedef struct {
- uint32_t ident;
- uint32_t version;
+ uint32_t ident;
+ uint32_t version;
- char filename[MD3_MAX_PATH];
+ char filename[MD3_MAX_PATH];
- uint32_t flags;
+ uint32_t flags;
- uint32_t num_frames;
- uint32_t num_tags;
- uint32_t num_meshes;
- uint32_t num_skins;
+ uint32_t num_frames;
+ uint32_t num_tags;
+ uint32_t num_meshes;
+ uint32_t num_skins;
- uint32_t ofs_frames;
- uint32_t ofs_tags;
- uint32_t ofs_meshes;
- uint32_t ofs_end;
+ uint32_t ofs_frames;
+ uint32_t ofs_tags;
+ uint32_t ofs_meshes;
+ uint32_t ofs_end;
} dmd3header_t;
/*
-========================================================================
+ ========================================================================
-.SP2 sprite file format
+ .SP2 sprite file format
-========================================================================
-*/
+ ========================================================================
+ */
-#define IDSPRITEHEADER (('2'<<24)+('S'<<16)+('D'<<8)+'I')
- // little-endian "IDS2"
-#define SPRITE_VERSION 2
+#define IDSPRITEHEADER (('2'<<24)+('S'<<16)+('D'<<8)+'I')
+// little-endian "IDS2"
+#define SPRITE_VERSION 2
typedef struct {
- uint32_t width, height;
- uint32_t origin_x, origin_y; // raster coordinates inside pic
- char name[MAX_SKINNAME]; // name of pcx file
+ uint32_t width, height;
+ uint32_t origin_x, origin_y; // raster coordinates inside pic
+ char name[MAX_SKINNAME]; // name of pcx file
} dsprframe_t;
typedef struct {
- uint32_t ident;
- uint32_t version;
- uint32_t numframes;
- dsprframe_t frames[1]; // variable sized
+ uint32_t ident;
+ uint32_t version;
+ uint32_t numframes;
+ dsprframe_t frames[1]; // variable sized
} dsprite_t;
/*
-==============================================================================
+ ==============================================================================
- .WAL texture file format
+ .WAL texture file format
-==============================================================================
-*/
+ ==============================================================================
+ */
-#define MIPLEVELS 4
+#define MIPLEVELS 4
typedef struct {
- char name[32];
- uint32_t width, height;
- uint32_t offsets[MIPLEVELS]; // four mip maps stored
- char animname[32]; // next frame in animation chain
- uint32_t flags;
- uint32_t contents;
- uint32_t value;
+ char name[32];
+ uint32_t width, height;
+ uint32_t offsets[MIPLEVELS]; // four mip maps stored
+ char animname[32]; // next frame in animation chain
+ uint32_t flags;
+ uint32_t contents;
+ uint32_t value;
} miptex_t;
/*
-==============================================================================
+ ==============================================================================
- .BSP file format
+ .BSP file format
-==============================================================================
-*/
+ ==============================================================================
+ */
-#define IDBSPHEADER (('P'<<24)+('S'<<16)+('B'<<8)+'I')
- // little-endian "IBSP"
+#define IDBSPHEADER (('P'<<24)+('S'<<16)+('B'<<8)+'I')
+// little-endian "IBSP"
-#define BSPVERSION 38
+#define BSPVERSION 38
// upper design bounds
// leaffaces, leafbrushes, planes, and verts are still bounded by
// 16 bit short limits
-#define MAX_MAP_MODELS 1024
-#define MAX_MAP_BRUSHES 8192
-#define MAX_MAP_ENTITIES 2048
-#define MAX_MAP_ENTSTRING 0x40000
-#define MAX_MAP_TEXINFO 8192
-
-#define MAX_MAP_AREAS 256
-#define MAX_MAP_AREAPORTALS 1024
-#define MAX_MAP_PLANES 65536
-#define MAX_MAP_NODES 65536
-#define MAX_MAP_BRUSHSIDES 65536
-#define MAX_MAP_LEAFS 65536
-#define MAX_MAP_VERTS 65536
-#define MAX_MAP_FACES 65536
-#define MAX_MAP_LEAFFACES 65536
-#define MAX_MAP_LEAFBRUSHES 65536
-#define MAX_MAP_PORTALS 65536
-#define MAX_MAP_EDGES 128000
-#define MAX_MAP_SURFEDGES 256000
-#define MAX_MAP_LIGHTING 0x200000
-#define MAX_MAP_VISIBILITY 0x100000
+#define MAX_MAP_MODELS 1024
+#define MAX_MAP_BRUSHES 8192
+#define MAX_MAP_ENTITIES 2048
+#define MAX_MAP_ENTSTRING 0x40000
+#define MAX_MAP_TEXINFO 8192
+
+#define MAX_MAP_AREAS 256
+#define MAX_MAP_AREAPORTALS 1024
+#define MAX_MAP_PLANES 65536
+#define MAX_MAP_NODES 65536
+#define MAX_MAP_BRUSHSIDES 65536
+#define MAX_MAP_LEAFS 65536
+#define MAX_MAP_VERTS 65536
+#define MAX_MAP_FACES 65536
+#define MAX_MAP_LEAFFACES 65536
+#define MAX_MAP_LEAFBRUSHES 65536
+#define MAX_MAP_PORTALS 65536
+#define MAX_MAP_EDGES 128000
+#define MAX_MAP_SURFEDGES 256000
+#define MAX_MAP_LIGHTING 0x200000
+#define MAX_MAP_VISIBILITY 0x100000
// key / value pair sizes
-#define MAX_KEY 32
-#define MAX_VALUE 1024
+#define MAX_KEY 32
+#define MAX_VALUE 1024
//=============================================================================
typedef struct {
- uint32_t fileofs, filelen;
+ uint32_t fileofs, filelen;
} lump_t;
-#define LUMP_ENTITIES 0
-#define LUMP_PLANES 1
-#define LUMP_VERTEXES 2
-#define LUMP_VISIBILITY 3
-#define LUMP_NODES 4
-#define LUMP_TEXINFO 5
-#define LUMP_FACES 6
-#define LUMP_LIGHTING 7
-#define LUMP_LEAFS 8
-#define LUMP_LEAFFACES 9
-#define LUMP_LEAFBRUSHES 10
-#define LUMP_EDGES 11
-#define LUMP_SURFEDGES 12
-#define LUMP_MODELS 13
-#define LUMP_BRUSHES 14
-#define LUMP_BRUSHSIDES 15
-#define LUMP_POP 16
-#define LUMP_AREAS 17
-#define LUMP_AREAPORTALS 18
-#define HEADER_LUMPS 19
-
-typedef struct {
- uint32_t ident;
- uint32_t version;
- lump_t lumps[HEADER_LUMPS];
+#define LUMP_ENTITIES 0
+#define LUMP_PLANES 1
+#define LUMP_VERTEXES 2
+#define LUMP_VISIBILITY 3
+#define LUMP_NODES 4
+#define LUMP_TEXINFO 5
+#define LUMP_FACES 6
+#define LUMP_LIGHTING 7
+#define LUMP_LEAFS 8
+#define LUMP_LEAFFACES 9
+#define LUMP_LEAFBRUSHES 10
+#define LUMP_EDGES 11
+#define LUMP_SURFEDGES 12
+#define LUMP_MODELS 13
+#define LUMP_BRUSHES 14
+#define LUMP_BRUSHSIDES 15
+#define LUMP_POP 16
+#define LUMP_AREAS 17
+#define LUMP_AREAPORTALS 18
+#define HEADER_LUMPS 19
+
+typedef struct {
+ uint32_t ident;
+ uint32_t version;
+ lump_t lumps[HEADER_LUMPS];
} dheader_t;
typedef struct {
- float mins[3], maxs[3];
- float origin[3]; // for sounds or lights
- uint32_t headnode;
- uint32_t firstface, numfaces; // submodels just draw faces
- // without walking the bsp tree
+ float mins[3], maxs[3];
+ float origin[3]; // for sounds or lights
+ uint32_t headnode;
+ uint32_t firstface, numfaces; // submodels just draw faces
+ // without walking the bsp tree
} dmodel_t;
typedef struct {
- float point[3];
+ float point[3];
} dvertex_t;
typedef struct {
- float normal[3];
- float dist;
- uint32_t type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
+ float normal[3];
+ float dist;
+ uint32_t type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
} dplane_t;
@@ -394,146 +394,146 @@ typedef struct {
// these definitions also need to be in q_shared.h!
// lower bits are stronger, and will eat weaker brushes completely
-#define CONTENTS_SOLID 1 // an eye is never valid in a solid
-#define CONTENTS_WINDOW 2 // translucent, but not watery
-#define CONTENTS_AUX 4
-#define CONTENTS_LAVA 8
-#define CONTENTS_SLIME 16
-#define CONTENTS_WATER 32
-#define CONTENTS_MIST 64
-#define LAST_VISIBLE_CONTENTS 64
+#define CONTENTS_SOLID 1 // an eye is never valid in a solid
+#define CONTENTS_WINDOW 2 // translucent, but not watery
+#define CONTENTS_AUX 4
+#define CONTENTS_LAVA 8
+#define CONTENTS_SLIME 16
+#define CONTENTS_WATER 32
+#define CONTENTS_MIST 64
+#define LAST_VISIBLE_CONTENTS 64
// remaining contents are non-visible, and don't eat brushes
-#define CONTENTS_AREAPORTAL 0x8000
+#define CONTENTS_AREAPORTAL 0x8000
-#define CONTENTS_PLAYERCLIP 0x10000
-#define CONTENTS_MONSTERCLIP 0x20000
+#define CONTENTS_PLAYERCLIP 0x10000
+#define CONTENTS_MONSTERCLIP 0x20000
// currents can be added to any other contents, and may be mixed
-#define CONTENTS_CURRENT_0 0x40000
-#define CONTENTS_CURRENT_90 0x80000
-#define CONTENTS_CURRENT_180 0x100000
-#define CONTENTS_CURRENT_270 0x200000
-#define CONTENTS_CURRENT_UP 0x400000
-#define CONTENTS_CURRENT_DOWN 0x800000
+#define CONTENTS_CURRENT_0 0x40000
+#define CONTENTS_CURRENT_90 0x80000
+#define CONTENTS_CURRENT_180 0x100000
+#define CONTENTS_CURRENT_270 0x200000
+#define CONTENTS_CURRENT_UP 0x400000
+#define CONTENTS_CURRENT_DOWN 0x800000
-#define CONTENTS_ORIGIN 0x1000000 // removed before bsping an entity
+#define CONTENTS_ORIGIN 0x1000000 // removed before bsping an entity
-#define CONTENTS_MONSTER 0x2000000 // should never be on a brush, only in game
-#define CONTENTS_DEADMONSTER 0x4000000
-#define CONTENTS_DETAIL 0x8000000 // brushes to be added after vis leafs
-#define CONTENTS_TRANSLUCENT 0x10000000 // auto set if any surface has trans
-#define CONTENTS_LADDER 0x20000000
+#define CONTENTS_MONSTER 0x2000000 // should never be on a brush, only in game
+#define CONTENTS_DEADMONSTER 0x4000000
+#define CONTENTS_DETAIL 0x8000000 // brushes to be added after vis leafs
+#define CONTENTS_TRANSLUCENT 0x10000000 // auto set if any surface has trans
+#define CONTENTS_LADDER 0x20000000
-#define SURF_LIGHT 0x1 // value will hold the light strength
+#define SURF_LIGHT 0x1 // value will hold the light strength
-#define SURF_SLICK 0x2 // effects game physics
+#define SURF_SLICK 0x2 // effects game physics
-#define SURF_SKY 0x4 // don't draw, but add to skybox
-#define SURF_WARP 0x8 // turbulent water warp
-#define SURF_TRANS33 0x10
-#define SURF_TRANS66 0x20
-#define SURF_FLOWING 0x40 // scroll towards angle
-#define SURF_NODRAW 0x80 // don't bother referencing the texture
+#define SURF_SKY 0x4 // don't draw, but add to skybox
+#define SURF_WARP 0x8 // turbulent water warp
+#define SURF_TRANS33 0x10
+#define SURF_TRANS66 0x20
+#define SURF_FLOWING 0x40 // scroll towards angle
+#define SURF_NODRAW 0x80 // don't bother referencing the texture
typedef struct {
- uint32_t planenum;
- uint32_t children[2]; // negative numbers are -(leafs+1), not nodes
- int16_t mins[3]; // for frustom culling
- int16_t maxs[3];
- uint16_t firstface;
- uint16_t numfaces; // counting both sides
+ uint32_t planenum;
+ uint32_t children[2]; // negative numbers are -(leafs+1), not nodes
+ int16_t mins[3]; // for frustom culling
+ int16_t maxs[3];
+ uint16_t firstface;
+ uint16_t numfaces; // counting both sides
} dnode_t;
typedef struct texinfo_s {
- float vecs[2][4]; // [s/t][xyz offset]
- uint32_t flags; // miptex flags + overrides
- int32_t value; // light emission, etc
- char texture[32]; // texture name (textures/*.wal)
- uint32_t nexttexinfo; // for animations, -1 = end of chain
+ float vecs[2][4]; // [s/t][xyz offset]
+ uint32_t flags; // miptex flags + overrides
+ int32_t value; // light emission, etc
+ char texture[32]; // texture name (textures/*.wal)
+ uint32_t nexttexinfo; // for animations, -1 = end of chain
} texinfo_t;
// note that edge 0 is never used, because negative edge nums are used for
// counterclockwise use of the edge in a face
typedef struct {
- uint16_t v[2]; // vertex numbers
+ uint16_t v[2]; // vertex numbers
} dedge_t;
-#define MAXLIGHTMAPS 4
+#define MAXLIGHTMAPS 4
typedef struct {
- uint16_t planenum;
- uint16_t side;
+ uint16_t planenum;
+ uint16_t side;
- uint32_t firstedge; // we must support > 64k edges
- uint16_t numedges;
- uint16_t texinfo;
+ uint32_t firstedge; // we must support > 64k edges
+ uint16_t numedges;
+ uint16_t texinfo;
// lighting info
- uint8_t styles[MAXLIGHTMAPS];
- uint32_t lightofs; // start of [numstyles*surfsize] samples
+ uint8_t styles[MAXLIGHTMAPS];
+ uint32_t lightofs; // start of [numstyles*surfsize] samples
} dface_t;
typedef struct {
- uint32_t contents; // OR of all brushes (not needed?)
+ uint32_t contents; // OR of all brushes (not needed?)
- uint16_t cluster;
- uint16_t area;
+ uint16_t cluster;
+ uint16_t area;
- int16_t mins[3]; // for frustum culling
- int16_t maxs[3];
+ int16_t mins[3]; // for frustum culling
+ int16_t maxs[3];
- uint16_t firstleafface;
- uint16_t numleaffaces;
+ uint16_t firstleafface;
+ uint16_t numleaffaces;
- uint16_t firstleafbrush;
- uint16_t numleafbrushes;
+ uint16_t firstleafbrush;
+ uint16_t numleafbrushes;
} dleaf_t;
typedef struct {
- uint16_t planenum; // facing out of the leaf
- uint16_t texinfo;
+ uint16_t planenum; // facing out of the leaf
+ uint16_t texinfo;
} dbrushside_t;
typedef struct {
- uint32_t firstside;
- uint32_t numsides;
- uint32_t contents;
+ uint32_t firstside;
+ uint32_t numsides;
+ uint32_t contents;
} dbrush_t;
-#define ANGLE_UP -1
-#define ANGLE_DOWN -2
+#define ANGLE_UP -1
+#define ANGLE_DOWN -2
// the visibility lump consists of a header with a count, then
// byte offsets for the PVS and PHS of each cluster, then the raw
// compressed bit vectors
-#define DVIS_PVS 0
-#define DVIS_PHS 1
+#define DVIS_PVS 0
+#define DVIS_PHS 1
-#define DVIS_CLUSTERS 8
+#define DVIS_CLUSTERS 8
typedef struct {
- uint32_t numclusters;
- uint32_t bitofs[DVIS_CLUSTERS][2]; // bitofs[numclusters][2]
+ uint32_t numclusters;
+ uint32_t bitofs[DVIS_CLUSTERS][2]; // bitofs[numclusters][2]
} dvis_t;
// each area has a list of portals that lead into other areas
// when portals are closed, other areas may not be visible or
// hearable even if the vis info says that it should be
typedef struct {
- uint32_t portalnum;
- uint32_t otherarea;
+ uint32_t portalnum;
+ uint32_t otherarea;
} dareaportal_t;
typedef struct {
- uint32_t numareaportals;
- uint32_t firstareaportal;
+ uint32_t numareaportals;
+ uint32_t firstareaportal;
} darea_t;
diff --git a/source/q_list.h b/source/q_list.h
index 6a06af7..5bfae8d 100644
--- a/source/q_list.h
+++ b/source/q_list.h
@@ -79,7 +79,7 @@ static inline void List_Remove( list_t *elem ) {
}
#define LIST_ENTRY( type, elem, member ) \
- ( type * )( ( unsigned char * )elem - q_offsetof( type, member ) )
+ (( type * )( ( unsigned char * )elem - q_offsetof( type, member ) ))
#define LIST_EMPTY( list ) \
( (list)->next == list ) \
diff --git a/source/ref_public.h b/source/ref_public.h
index 2484a92..71d47c8 100644
--- a/source/ref_public.h
+++ b/source/ref_public.h
@@ -137,6 +137,13 @@ typedef enum glHardware_e {
GL_RENDERER_MESADRI
} glHardware_t;
+typedef enum {
+ QVF_MINIDRIVER = ( 1 << 0 ),
+ QVF_ACCELERATED = ( 1 << 1 ),
+ QVF_GAMMARAMP = ( 1 << 2 ),
+ QVF_FULLSCREEN = ( 1 << 3 )
+} vidFlags_t;
+
typedef struct glconfig_s {
glHardware_t renderer;
const char *rendererString;
diff --git a/source/snd_main.c b/source/snd_main.c
index 48317f5..7163c55 100644
--- a/source/snd_main.c
+++ b/source/snd_main.c
@@ -36,6 +36,7 @@ int s_registration_sequence;
channel_t channels[MAX_CHANNELS];
qboolean sound_started;
+qboolean sound_modified;
dma_t dma;
@@ -68,53 +69,21 @@ cvar_t *s_khz;
cvar_t *s_volume;
cvar_t *s_testsound;
-static cvar_t *s_loadas8bit;
+static cvar_t *s_enable;
+#if USE_DSOUND
+static cvar_t *s_direct;
+#endif
static cvar_t *s_show;
static cvar_t *s_mixahead;
-static cvar_t *s_driver;
static cvar_t *s_ambient;
-
-snddmaAPI_t snddma;
-
-#if USE_WAVE
void WAVE_FillAPI( snddmaAPI_t *api );
-#endif
#if USE_DSOUND
void DS_FillAPI( snddmaAPI_t *api );
#endif
-#if USE_OSS
-void OSS_FillAPI( snddmaAPI_t *api );
-#endif
-
-#if USE_SDL
-void QSDL_FillSoundAPI( snddmaAPI_t *api );
-#endif
-
-
-// the first driver is the default one
-static struct {
- char name[16];
- void (*FillAPI)( snddmaAPI_t *api );
-} s_driverTable[] = {
-#if USE_DSOUND
- { "dsound", DS_FillAPI },
-#endif
-#if USE_WAVE
- { "wave", WAVE_FillAPI },
-#endif
-#if USE_OSS
- { "oss", OSS_FillAPI },
-#endif
-#if USE_SDL
- { "sdl", QSDL_FillSoundAPI },
-#endif
-};
-
-static const int s_numDrivers =
- sizeof( s_driverTable ) / sizeof( s_driverTable[0] );
+snddmaAPI_t snddma;
/*
==========================================================================
@@ -187,6 +156,9 @@ static void S_SoundList_f( void ) {
Com_Printf( "Total resident: %i\n", total );
}
+static void s_param_changed( cvar_t *self ) {
+ sound_modified = qtrue;
+}
static const cmdreg_t c_sound[] = {
{ "play", S_Play_f, S_Play_c },
@@ -203,56 +175,43 @@ S_Init
================
*/
void S_Init( void ) {
- cvar_t *cv;
- int i, j = 0;
- sndinitstat_t ret;
+ sndinitstat_t ret = SIS_FAILURE;
- cv = Cvar_Get( "s_initsound", "1", 0 );
- if( !cv->integer ) {
+ s_enable = Cvar_Get( "s_enable", "1", 0 );
+ s_enable->changed = s_param_changed;
+ if( !s_enable->integer ) {
Com_Printf( "Sound initialization disabled.\n" );
return;
}
Com_Printf( "------- S_Init -------\n" );
- s_volume = Cvar_Get( "s_volume", "0.7", CVAR_ARCHIVE );
s_khz = Cvar_Get( "s_khz", "22", CVAR_ARCHIVE );
- s_loadas8bit = Cvar_Get( "s_loadas8bit", "1", CVAR_ARCHIVE );
- s_mixahead = Cvar_Get( "s_mixahead", "0.2", CVAR_ARCHIVE );
- s_show = Cvar_Get( "s_show", "0", 0 );
- s_testsound = Cvar_Get( "s_testsound", "0", 0 );
- s_driver = Cvar_Get( "s_driver", "", CVAR_LATCHED );
- s_ambient = Cvar_Get( "s_ambient", "1", 0 );
- // determine the first driver to try
- if( s_driver->string[0] ) {
- for( i = 0; i < s_numDrivers; i++ ) {
- if( !strcmp( s_driver->string, s_driverTable[i].name ) ) {
- j = i;
- break;
- }
+#if USE_DSOUND
+ s_direct = Cvar_Get( "s_direct", "1", 0 );
+ if( s_direct->integer ) {
+ DS_FillAPI( &snddma );
+ ret = snddma.Init();
+ if( ret != SIS_SUCCESS ) {
+ Cvar_Set( "s_direct", "0" );
}
}
-
- // cycle until usable driver is found
- i = j;
- while( 1 ) {
- s_driverTable[i].FillAPI( &snddma );
-
- ret = snddma.Init();
- if( ret == SIS_SUCCESS ) {
- break;
- }
- if( ret == SIS_NOTAVAIL ) {
- Com_WPrintf( "Sound hardware already in use\n" );
- return;
- }
- i = ( i + 1 ) % s_numDrivers;
- if( i == j ) {
- Com_WPrintf( "No usable sound driver found\n" );
+#endif
+ if( ret != SIS_SUCCESS ) {
+ WAVE_FillAPI( &snddma );
+ ret = snddma.Init();
+ if( ret != SIS_SUCCESS ) {
+ Cvar_Set( "s_enable", "0" );
return;
}
- }
+ }
+
+ s_volume = Cvar_Get( "s_volume", "0.7", CVAR_ARCHIVE );
+ s_mixahead = Cvar_Get( "s_mixahead", "0.2", CVAR_ARCHIVE );
+ s_show = Cvar_Get( "s_show", "0", 0 );
+ s_testsound = Cvar_Get( "s_testsound", "0", 0 );
+ s_ambient = Cvar_Get( "s_ambient", "1", 0 );
Cmd_Register( c_sound );
@@ -265,6 +224,11 @@ void S_Init( void ) {
s_registration_sequence = 1;
+#if USE_DSOUND
+ s_direct->changed = s_param_changed;
+#endif
+ s_khz->changed = s_param_changed;
+
Com_Printf( "sound sampling rate: %i\n", dma.speed );
S_StopAllSounds();
@@ -303,6 +267,11 @@ void S_Shutdown( void ) {
sound_started = qfalse;
+#if USE_DSOUND
+ s_direct->changed = NULL;
+#endif
+ s_khz->changed = NULL;
+
Cmd_Deregister( c_sound );
S_FreeAllSounds();
@@ -310,12 +279,12 @@ void S_Shutdown( void ) {
Z_LeakTest( TAG_SOUND );
}
-void S_Activate( qboolean active ) {
+void S_Activate( void ) {
if( sound_started ) {
#ifdef _WIN32
S_StopAllSounds(); // FIXME
#endif
- snddma.Activate( active );
+ snddma.Activate( cls.active == ACT_ACTIVATED ? qtrue : qfalse );
}
}
@@ -1061,6 +1030,12 @@ void S_Update( void )
int total;
channel_t *ch;
+ if( sound_modified ) {
+ Cbuf_AddText( "snd_restart\n" );
+ sound_modified = qfalse;
+ return;
+ }
+
if (!sound_started)
return;
diff --git a/source/snd_oss.c b/source/snd_oss.c
index 10b092f..2753326 100644
--- a/source/snd_oss.c
+++ b/source/snd_oss.c
@@ -45,7 +45,7 @@ static cvar_t *sndspeed;
static cvar_t *sndchannels;
static cvar_t *snddevice;
-static int tryrates[] = { 22050, 11025, 44100, 48000, 8000 };
+static const int tryrates[] = { 22050, 11025, 44100, 48000, 8000 };
static sndinitstat_t OSS_Init ( void ) {
int rc;
@@ -235,7 +235,7 @@ static void OSS_Submit ( void ) {
static void OSS_Activate ( qboolean active ) {
}
-void OSS_FillAPI ( snddmaAPI_t *api ) {
+void DS_FillAPI ( snddmaAPI_t *api ) {
api->Init = OSS_Init;
api->Shutdown = OSS_Shutdown;
api->BeginPainting = OSS_BeginPainting;
diff --git a/source/snd_public.h b/source/snd_public.h
index 9354743..0c2d79e 100644
--- a/source/snd_public.h
+++ b/source/snd_public.h
@@ -30,7 +30,7 @@ void S_FreeAllSounds( void );
void S_StopAllSounds(void);
void S_Update (void);
-void S_Activate (qboolean active);
+void S_Activate (void);
void S_BeginRegistration (void);
qhandle_t S_RegisterSound (const char *sample);
diff --git a/source/snd_sdl.c b/source/snd_sdl.c
index f727718..c78a663 100644
--- a/source/snd_sdl.c
+++ b/source/snd_sdl.c
@@ -137,7 +137,7 @@ static void QSDL_ActivateSound( qboolean active ) {
}
}
-void QSDL_FillSoundAPI ( snddmaAPI_t *api ) {
+void WAVE_FillAPI ( snddmaAPI_t *api ) {
api->Init = QSDL_InitSound;
api->Shutdown = QSDL_ShutdownSound;
api->BeginPainting = QSDL_BeginPainting;
diff --git a/source/sv_main.c b/source/sv_main.c
index 425d14c..7a89ad8 100644
--- a/source/sv_main.c
+++ b/source/sv_main.c
@@ -1505,19 +1505,21 @@ void SV_Frame( int msec ) {
}
#ifndef DEDICATED_ONLY
+ // pause if there is only local client on the server
if( !dedicated->integer && cl_paused->integer &&
- List_Count( &svs.udp_client_list ) == 1 && mvdconns == 0 )
+ List_Count( &svs.udp_client_list ) == 1 && mvdconns == 0 &&
+ LIST_FIRST( client_t, &svs.udp_client_list, entry )->state == cs_spawned )
{
if( !sv_paused->integer ) {
Cvar_Set( "sv_paused", "1" );
- CL_InputActivate();
+ IN_Activate();
}
return; // don't run if paused
}
if( sv_paused->integer ) {
Cvar_Set( "sv_paused", "0" );
- CL_InputActivate();
+ IN_Activate();
}
#endif
diff --git a/source/sw_edge.c b/source/sw_edge.c
index c53df44..cdb31b7 100644
--- a/source/sw_edge.c
+++ b/source/sw_edge.c
@@ -1046,7 +1046,7 @@ void D_DrawflatSurfaces (void)
// make a stable color for each surface by taking the low
// bits of the msurface pointer
- D_FlatFillSurface (s, (uint32_t)s->msurf);
+ D_FlatFillSurface (s, (uint32_t)((intptr_t)s->msurf));
D_DrawZSpans (s->spans);
}
}
diff --git a/source/sw_model.c b/source/sw_model.c
index e21c52b..28678b5 100644
--- a/source/sw_model.c
+++ b/source/sw_model.c
@@ -91,7 +91,7 @@ void Mod_Modellist_f (void)
{
if (!mod->name[0])
continue;
- Com_Printf( "%8i : %s\n",mod->pool.cursize, mod->name);
+ Com_Printf( "%8"PRIz" : %s\n",mod->pool.cursize, mod->name);
total += mod->pool.cursize;
}
Com_Printf( "Total resident: %i\n", total);
diff --git a/source/sw_surf.c b/source/sw_surf.c
index f8633bc..d77e33c 100644
--- a/source/sw_surf.c
+++ b/source/sw_surf.c
@@ -264,7 +264,7 @@ surfcache_t *D_SCAlloc (int width, int size)
if ((size <= 0) || (size > 0x10000))
Com_Error (ERR_FATAL,"D_SCAlloc: bad cache size %d\n", size);
- size = (int)&((surfcache_t *)0)->data[size];
+ size += sizeof( surfcache_t ) - 4;
size = (size + 3) & ~3;
if (size > sc_size)
Com_Error (ERR_FATAL,"D_SCAlloc: %i > cache size of %i",size, sc_size);
diff --git a/source/sys_unix.c b/source/sys_unix.c
index 293f2ca..bb9bbf7 100644
--- a/source/sys_unix.c
+++ b/source/sys_unix.c
@@ -414,7 +414,7 @@ void Hunk_Begin( mempool_t *pool, size_t maxsize ) {
buf = mmap( NULL, pool->maxsize, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANON, -1, 0 );
if( buf == NULL || buf == ( void * )-1 ) {
- Com_Error( ERR_FATAL, "%s: unable to virtual allocate %d bytes",
+ Com_Error( ERR_FATAL, "%s: unable to virtual allocate %"PRIz" bytes",
__func__, pool->maxsize );
}
pool->base = buf;
@@ -471,72 +471,6 @@ void Hunk_Free( mempool_t *pool ) {
/*
===============================================================================
-FIFO
-
-===============================================================================
-*/
-
-#if 0
-qboolean FIFO_Alloc( fifo_t *fifo, int size ) {
- byte *mem, *ret;
- char temp[32];
- int fd;
-
- strcpy( temp, "/dev/shm/" APPLICATION "-XXXXXX" );
- fd = mkstemp( temp );
- if( fd < 0 ) {
- return qfalse;
- }
-
- unlink( temp );
-
- size = ( size + 4095 ) & ~4095;
-
- if( ftruncate( fd, size << 1 ) == -1 ) {
- goto fail2;
- }
-
- mem = mmap( NULL, size << 1, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0 );
- if( mem == MAP_FAILED ) {
- goto fail2;
- }
-
- ret = mmap( mem, size, PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, fd, 0 );
- if( ret != mem ) {
- goto fail1;
- }
-
- ret = mmap( mem + size, size, PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, fd, 0 );
- if( ret != mem + size ) {
- goto fail1;
- }
-
- fifo->data = mem;
- fifo->size = size;
- fifo->tail = fifo->head = 0;
- return qtrue;
-
-fail1:
- munmap( mem, size << 1 );
-fail2:
- close( fd );
- return qfalse;
-}
-
-void FIFO_Free( fifo_t *fifo ) {
- if( fifo->data ) {
- if( munmap( fifo->data, fifo->size << 1 ) ) {
- Com_Error( ERR_FATAL, "%s: munmap failed: %s",
- __func__, strerror( errno ) );
- }
- }
- memset( fifo, 0, sizeof( *fifo ) );
-}
-#endif
-
-/*
-===============================================================================
-
GENERAL ROUTINES
===============================================================================
@@ -727,7 +661,7 @@ void Sys_AddDefaultConfig( void ) {
struct stat st;
char *text;
- fp = fopen( DEFCFG, "r" );
+ fp = fopen( SYS_SITECFG_NAME, "r" );
if( !fp ) {
return;
}
@@ -735,7 +669,7 @@ void Sys_AddDefaultConfig( void ) {
if( fstat( fileno( fp ), &st ) == 0 ) {
text = Cbuf_Alloc( &cmd_buffer, st.st_size );
if( text ) {
- Com_Printf( "Execing " DEFCFG "\n" );
+ Com_Printf( "Execing " SYS_SITECFG_NAME "\n" );
fread( text, st.st_size, 1, fp );
}
}
diff --git a/source/ui_atoms.c b/source/ui_atoms.c
index 45976ca..128daa6 100644
--- a/source/ui_atoms.c
+++ b/source/ui_atoms.c
@@ -83,18 +83,16 @@ void UI_PushMenu( menuFrameWork_t *menu ) {
Menu_Init( menu );
+ keydest = keys.GetDest();
+ keys.SetDest( ( keydest & ~KEY_CONSOLE ) | KEY_MENU );
+
if( !uis.activeMenu ) {
uis.entersound = qtrue;
+ //CL_WarpMouse( 0, 0 );
}
uis.activeMenu = menu;
- keydest = keys.GetDest();
- if( keydest & KEY_CONSOLE ) {
- keydest &= ~KEY_CONSOLE;
- }
- keys.SetDest( keydest | KEY_MENU );
-
UI_DoHitTest();
}
@@ -125,6 +123,8 @@ void UI_Resize( void ) {
Menu_Init( uis.layers[i] );
}
}
+
+ //CL_WarpMouse( 0, 0 );
}
@@ -395,31 +395,23 @@ qboolean UI_DoHitTest( void ) {
/*
=================
-UI_MouseMove
+UI_MouseEvent
=================
*/
-void UI_MouseMove( int mx, int my ) {
+void UI_MouseEvent( int x, int y ) {
if( !uis.activeMenu ) {
return;
}
- if( !mx && !my ) {
- return;
- }
-
- uis.mouseCoords[0] += mx;
- uis.mouseCoords[1] += my;
+ clamp( x, 0, uis.glconfig.vidWidth );
+ clamp( y, 0, uis.glconfig.vidHeight );
- clamp( uis.mouseCoords[0], 0, uis.width );
- clamp( uis.mouseCoords[1], 0, uis.height );
+ uis.mouseCoords[0] = x * uis.scale;
+ uis.mouseCoords[1] = y * uis.scale;
- if( UI_DoHitTest() ) {
- // TODO: add new mousemove sound
- // cl.StartLocalSound( "misc/menu2.wav" );
- }
+ UI_DoHitTest();
}
-
/*
=================
UI_Draw
@@ -479,8 +471,11 @@ void UI_Draw( int realtime ) {
}
}
- ref.DrawPic( uis.mouseCoords[0] - uis.cursorWidth / 2,
- uis.mouseCoords[1] - uis.cursorHeight / 2, uis.cursorHandle );
+ // draw custom cursor in fullscreen mode
+ if( uis.glconfig.flags & QVF_FULLSCREEN ) {
+ ref.DrawPic( uis.mouseCoords[0] - uis.cursorWidth / 2,
+ uis.mouseCoords[1] - uis.cursorHeight / 2, uis.cursorHandle );
+ }
if( ui_debug->integer ) {
Menu_HitTest( uis.activeMenu );
@@ -854,7 +849,7 @@ static void UI_FillAPI( uiAPI_t *api ) {
api->ModeChanged = UI_ModeChanged;
api->Draw = UI_Draw;
api->DrawLoading = UI_DrawLoading;
- api->MouseMove = UI_MouseMove;
+ api->MouseEvent = UI_MouseEvent;
api->Keydown = UI_Keydown;
api->CharEvent = UI_CharEvent;
api->OpenMenu = UI_OpenMenu;
diff --git a/source/ui_public.h b/source/ui_public.h
index 2a6f00c..3deb45e 100644
--- a/source/ui_public.h
+++ b/source/ui_public.h
@@ -34,7 +34,7 @@ typedef struct uiAPI_s {
void (*Draw)( int realtime );
void (*DrawLoading)( int realtime );
- void (*MouseMove)( int dx, int dy );
+ void (*MouseEvent)( int x, int y );
void (*Keydown)( int key );
void (*CharEvent)( int key );
void (*OpenMenu)( uiMenu_t menu );
@@ -54,7 +54,7 @@ void UI_Draw( int realtime );
void UI_OpenMenu( uiMenu_t menu );
void UI_ErrorMenu( comErrorType_t type, const char *text );
void UI_AddToServerList( const serverStatus_t *status );
-void UI_MouseMove( int dx, int dy );
+void UI_MouseEvent( int x, int y );
qboolean UI_IsTransparent( void );
void UI_DrawLoading( int realtime );
diff --git a/source/vid_local.h b/source/vid_local.h
index ff9c4c9..780635d 100644
--- a/source/vid_local.h
+++ b/source/vid_local.h
@@ -19,18 +19,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
extern cvar_t *vid_ref;
-extern cvar_t *vid_placement;
+extern cvar_t *vid_geometry;
extern cvar_t *vid_modelist;
extern cvar_t *vid_fullscreen;
extern cvar_t *_vid_fullscreen;
-void Video_PumpEvents( void );
-void Video_ModeChanged( void );
-void Video_FillInputAPI( inputAPI_t *api );
-void Video_FillGLAPI( videoAPI_t *api );
-void Video_FillSWAPI( videoAPI_t *api );
-
-void Video_GetModeFS( vrect_t *rc, int *freq, int *depth );
-void Video_GetPlacement( vrect_t *rc );
-void Video_SetPlacement( vrect_t *rc );
-void Video_ToggleFullscreen( void );
+//
+// vid_*.c
+//
+void VID_PumpEvents( void );
+void VID_ModeChanged( void );
+void VID_FillInputAPI( inputAPI_t *api );
+void VID_FillGLAPI( videoAPI_t *api );
+void VID_FillSWAPI( videoAPI_t *api );
+
+//
+// cl_ref.c
+//
+void VID_GetModeFS( vrect_t *rc, int *freq, int *depth );
+void VID_GetGeometry( vrect_t *rc );
+void VID_SetGeometry( vrect_t *rc );
+void VID_ToggleFullscreen( void );
diff --git a/source/vid_public.h b/source/vid_public.h
index 6faf746..bd31116 100644
--- a/source/vid_public.h
+++ b/source/vid_public.h
@@ -18,19 +18,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-typedef enum {
- QVF_MINIDRIVER = ( 1 << 0 ),
- QVF_ACCELERATED = ( 1 << 1 ),
- QVF_GAMMARAMP = ( 1 << 2 ),
- QVF_FULLSCREEN = ( 1 << 3 )
-} vidFlags_t;
-
-typedef struct vidmode_s {
- int width, height;
- int bpp;
- int frequency;
-} vidmode_t;
-
typedef struct {
qboolean (*Init)( void );
void (*Shutdown)( void );
diff --git a/source/vid_sdl.c b/source/vid_sdl.c
index 7e48223..883973c 100644
--- a/source/vid_sdl.c
+++ b/source/vid_sdl.c
@@ -30,6 +30,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "key_public.h"
#include "q2pro.xbm"
#include <SDL.h>
+#if USE_X11
+#include <SDL_syswm.h>
+#endif
#ifdef __unix__
#include <GL/glx.h>
#include <GL/glxext.h>
@@ -38,10 +41,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
typedef struct {
SDL_Surface *surface;
SDL_Surface *icon;
- Uint16 gamma[3][256];
- vidFlags_t flags;
- qboolean mouseactive; // false when not focus app
- qboolean mouseinitialized;
+ Uint16 gamma[3][256];
+ vidFlags_t flags;
+ struct {
+ qboolean initialized;
+ grab_t grabbed;
+ } mouse;
#ifdef __unix__
//PFNGLXGETVIDEOSYNCSGIPROC glXGetVideoSyncSGI;
#endif
@@ -49,8 +54,6 @@ typedef struct {
static sdl_state_t sdl;
-void QSDL_AcquireMouse( void );
-
/*
===============================================================================
@@ -59,16 +62,45 @@ COMMON SDL VIDEO RELATED ROUTINES
===============================================================================
*/
-static qboolean QSDL_SetMode( int flags, int forcedepth ) {
+static void SetHints( void ) {
+#if USE_X11
+ SDL_SysWMinfo info;
+ Display *dpy;
+ Window win;
+ XSizeHints hints;
+
+ SDL_VERSION( &info.version );
+ if( !SDL_GetWMInfo( &info ) ) {
+ return;
+ }
+ if( info.subsystem != SDL_SYSWM_X11 ) {
+ return;
+ }
+
+ dpy = info.info.x11.display;
+ win = info.info.x11.window;
+
+ memset( &hints, 0, sizeof( hints ) );
+ hints.flags = PMinSize|PResizeInc;
+ hints.min_width = 64;
+ hints.min_height = 64;
+ hints.width_inc = 8;
+ hints.height_inc = 2;
+
+ XSetWMSizeHints( dpy, win, &hints, XA_WM_SIZE_HINTS );
+#endif
+}
+
+static qboolean SetMode( int flags, int forcedepth ) {
SDL_Surface *surf;
vrect_t rc;
int depth;
flags &= ~(SDL_FULLSCREEN|SDL_RESIZABLE);
- sdl.flags &= ~QVF_FULLSCREEN;
+ sdl.flags &= ~QVF_FULLSCREEN;
if( vid_fullscreen->integer > 0 ) {
- Video_GetModeFS( &rc, NULL, &depth );
+ VID_GetModeFS( &rc, NULL, &depth );
if( forcedepth ) {
depth = forcedepth;
}
@@ -76,76 +108,61 @@ static qboolean QSDL_SetMode( int flags, int forcedepth ) {
rc.width, rc.height, depth );
surf = SDL_SetVideoMode( rc.width, rc.height, depth,
flags | SDL_FULLSCREEN );
- if( surf ) {
- sdl.flags |= QVF_FULLSCREEN;
+ if( surf ) {
+ sdl.flags |= QVF_FULLSCREEN;
goto success;
}
- Com_EPrintf( "Fullscreen video mode failed: %s\n", SDL_GetError() );
+ Com_EPrintf( "Fullscreen video mode failed: %s\n", SDL_GetError() );
Cvar_Set( "vid_fullscreen", "0" );
}
flags |= SDL_RESIZABLE;
- Video_GetPlacement( &rc );
+ VID_GetGeometry( &rc );
Com_DPrintf( "...setting windowed mode: %dx%d\n", rc.width, rc.height );
surf = SDL_SetVideoMode( rc.width, rc.height, forcedepth, flags );
if( !surf ) {
return qfalse;
}
-
+
success:
+ SetHints();
sdl.surface = surf;
ref.ModeChanged( rc.width, rc.height, sdl.flags, surf->pitch, surf->pixels );
SCR_ModeChanged();
return qtrue;
}
-static void QSDL_Activate( SDL_Event *event ) {
- // state is actually a bitmask!
- if( event->active.state & SDL_APPACTIVE ) {
- CL_AppActivate( event->active.gain ? qtrue : qfalse );
+/*
+============
+VID_ModeChanged
+============
+*/
+void VID_ModeChanged( void ) {
+ if( !SetMode( sdl.surface->flags, sdl.surface->format->BitsPerPixel ) ) {
+ Com_Error( ERR_FATAL, "Couldn't change video mode: %s", SDL_GetError() );
}
}
-void Video_ModeChanged( void ) {
- SDL_Event event;
+static qboolean InitVideo( void ) {
+ SDL_Color color;
+ byte *dst;
+ char buffer[MAX_QPATH];
+ int i, ret;
- if( !QSDL_SetMode( sdl.surface->flags, sdl.surface->format->BitsPerPixel ) ) {
- Com_Error( ERR_FATAL, "Couldn't change video mode: %s", SDL_GetError() );
+ if( SDL_WasInit( SDL_INIT_EVERYTHING ) == 0 ) {
+ ret = SDL_Init( SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE );
+ } else {
+ ret = SDL_InitSubSystem( SDL_INIT_VIDEO );
}
- // ignore any pending resize events
- while( SDL_PollEvent( &event ) ) {
- switch( event.type ) {
- case SDL_ACTIVEEVENT:
- QSDL_Activate( &event );
- break;
- case SDL_QUIT:
- Com_Quit();
- break;
- }
+ if( ret == -1 ) {
+ Com_EPrintf( "Couldn't initialize SDL video: %s\n", SDL_GetError() );
+ return qfalse;
}
-}
-
-static qboolean QSDL_InitVideo( void ) {
- SDL_Color color;
- byte *dst;
- char buffer[MAX_QPATH];
- int i, ret;
-
- if( SDL_WasInit( SDL_INIT_EVERYTHING ) == 0 ) {
- ret = SDL_Init( SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE );
- } else {
- ret = SDL_InitSubSystem( SDL_INIT_VIDEO );
- }
- if( ret == -1 ) {
- Com_EPrintf( "Couldn't initialize SDL video: %s\n", SDL_GetError() );
- return qfalse;
- }
-
- if( SDL_VideoDriverName( buffer, sizeof( buffer ) ) != NULL ) {
- Com_Printf( "Using SDL video driver: %s\n", buffer );
- }
+ if( SDL_VideoDriverName( buffer, sizeof( buffer ) ) != NULL ) {
+ Com_Printf( "Using SDL video driver: %s\n", buffer );
+ }
sdl.icon = SDL_CreateRGBSurface( SDL_SWSURFACE, q2icon_width,
q2icon_height, 8, 0, 0, 0, 0 );
@@ -169,41 +186,39 @@ static qboolean QSDL_InitVideo( void ) {
SDL_WM_SetIcon( sdl.icon, NULL );
}
- if( SDL_GetGammaRamp( sdl.gamma[0], sdl.gamma[1], sdl.gamma[2] ) != -1 ) {
- Com_DPrintf( "...enabling gamma control\n" );
- sdl.flags |= QVF_GAMMARAMP;
- }
+ if( SDL_GetGammaRamp( sdl.gamma[0], sdl.gamma[1], sdl.gamma[2] ) != -1 ) {
+ Com_DPrintf( "...enabling gamma control\n" );
+ sdl.flags |= QVF_GAMMARAMP;
+ }
- SDL_WM_SetCaption( APPLICATION, APPLICATION );
+ SDL_WM_SetCaption( APPLICATION, APPLICATION );
- SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
+ SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
- return qtrue;
+ return qtrue;
}
-static void QSDL_ShutdownVideo( void ) {
- if( sdl.flags & QVF_GAMMARAMP ) {
- SDL_SetGammaRamp( sdl.gamma[0], sdl.gamma[1], sdl.gamma[2] );
- }
-
- if( sdl.icon ) {
- SDL_FreeSurface( sdl.icon );
- }
-
+static void ShutdownVideo( void ) {
+ if( sdl.flags & QVF_GAMMARAMP ) {
+ SDL_SetGammaRamp( sdl.gamma[0], sdl.gamma[1], sdl.gamma[2] );
+ }
+ if( sdl.icon ) {
+ SDL_FreeSurface( sdl.icon );
+ }
memset( &sdl, 0, sizeof( sdl ) );
- if( SDL_WasInit( SDL_INIT_EVERYTHING ) == SDL_INIT_VIDEO ) {
- SDL_Quit();
- } else {
- SDL_QuitSubSystem( SDL_INIT_VIDEO );
- }
+ if( SDL_WasInit( SDL_INIT_EVERYTHING ) == SDL_INIT_VIDEO ) {
+ SDL_Quit();
+ } else {
+ SDL_QuitSubSystem( SDL_INIT_VIDEO );
+ }
}
-static void QSDL_UpdateGamma( const byte *table ) {
- Uint16 ramp[256];
- int i;
+static void UpdateGamma( const byte *table ) {
+ Uint16 ramp[256];
+ int i;
- if( sdl.flags & QVF_GAMMARAMP ) {
+ if( sdl.flags & QVF_GAMMARAMP ) {
for( i = 0; i < 256; i++ ) {
ramp[i] = table[i] << 8;
}
@@ -211,113 +226,124 @@ static void QSDL_UpdateGamma( const byte *table ) {
}
}
-static void QSDL_KeyEvent( SDL_keysym *keysym, qboolean down ) {
- unsigned key1, key2 = 0;
+static void Activate( void ) {
+ int state = SDL_GetAppState();
+ active_t active;
+
+ if( state & SDL_APPACTIVE ) {
+ if( state & (SDL_APPMOUSEFOCUS|SDL_APPINPUTFOCUS) ) {
+ active = ACT_ACTIVATED;
+ } else {
+ active = ACT_RESTORED;
+ }
+ } else {
+ active = ACT_MINIMIZED;
+ }
+
+ CL_Activate( active );
+}
+
+static void KeyEvent( SDL_keysym *keysym, qboolean down ) {
+ unsigned key1, key2 = 0;
if( keysym->sym <= 127 ) {
// ASCII chars are mapped directly
- Key_Event( keysym->sym, down, com_eventTime );
+ Key_Event( keysym->sym, down, com_eventTime );
return;
}
-#define K( s, d ) case SDLK_ ## s: key1 = K_ ## d; break;
-#define KK( s, d1, d2 ) case SDLK_ ## s: key1 = K_ ## d1; key2 = K_ ## d2; break;
-
- switch( keysym->sym ) {
- K( KP0, KP_INS )
- K( KP1, KP_END )
- K( KP2, KP_DOWNARROW )
- K( KP3, KP_PGDN )
- K( KP4, KP_LEFTARROW )
- K( KP5, KP_5 )
- K( KP6, KP_RIGHTARROW )
- K( KP7, KP_HOME )
- K( KP8, KP_UPARROW )
- K( KP9, KP_PGUP )
- K( KP_PERIOD, KP_DEL )
- K( KP_DIVIDE, KP_SLASH )
- K( KP_MULTIPLY, KP_MULTIPLY )
- K( KP_MINUS, KP_MINUS )
- K( KP_PLUS, KP_PLUS )
- K( KP_ENTER, KP_ENTER )
-
- K( UP, UPARROW )
- K( DOWN, DOWNARROW )
- K( RIGHT, RIGHTARROW )
- K( LEFT, LEFTARROW )
- K( INSERT, INS )
- K( HOME, HOME )
- K( END, END )
- K( PAGEUP, PGUP )
- K( PAGEDOWN, PGDN )
-
- K( F1, F1 )
- K( F2, F2 )
- K( F3, F3 )
- K( F4, F4 )
- K( F5, F5 )
- K( F6, F6 )
- K( F7, F7 )
- K( F8, F8 )
- K( F9, F9 )
- K( F10, F10 )
- K( F11, F11 )
- K( F12, F12 )
-
- K( NUMLOCK, NUMLOCK )
- K( CAPSLOCK, CAPSLOCK )
- K( SCROLLOCK, SCROLLOCK )
- K( LSUPER, LWINKEY )
- K( RSUPER, RWINKEY )
- K( MENU, MENU )
-
- KK( RSHIFT, SHIFT, RSHIFT )
- KK( LSHIFT, SHIFT, LSHIFT )
- KK( RCTRL, CTRL, RCTRL )
- KK( LCTRL, CTRL, LCTRL )
- KK( RALT, ALT, RALT )
- KK( LALT, ALT, LALT )
+#define K( s, d ) case SDLK_ ## s: key1 = K_ ## d; break;
+#define KK( s, d1, d2 ) case SDLK_ ## s: key1 = K_ ## d1; key2 = K_ ## d2; break;
+
+ switch( keysym->sym ) {
+ K( KP0, KP_INS )
+ K( KP1, KP_END )
+ K( KP2, KP_DOWNARROW )
+ K( KP3, KP_PGDN )
+ K( KP4, KP_LEFTARROW )
+ K( KP5, KP_5 )
+ K( KP6, KP_RIGHTARROW )
+ K( KP7, KP_HOME )
+ K( KP8, KP_UPARROW )
+ K( KP9, KP_PGUP )
+ K( KP_PERIOD, KP_DEL )
+ K( KP_DIVIDE, KP_SLASH )
+ K( KP_MULTIPLY, KP_MULTIPLY )
+ K( KP_MINUS, KP_MINUS )
+ K( KP_PLUS, KP_PLUS )
+ K( KP_ENTER, KP_ENTER )
+
+ K( UP, UPARROW )
+ K( DOWN, DOWNARROW )
+ K( RIGHT, RIGHTARROW )
+ K( LEFT, LEFTARROW )
+ K( INSERT, INS )
+ K( HOME, HOME )
+ K( END, END )
+ K( PAGEUP, PGUP )
+ K( PAGEDOWN, PGDN )
+
+ K( F1, F1 )
+ K( F2, F2 )
+ K( F3, F3 )
+ K( F4, F4 )
+ K( F5, F5 )
+ K( F6, F6 )
+ K( F7, F7 )
+ K( F8, F8 )
+ K( F9, F9 )
+ K( F10, F10 )
+ K( F11, F11 )
+ K( F12, F12 )
+
+ K( NUMLOCK, NUMLOCK )
+ K( CAPSLOCK, CAPSLOCK )
+ K( SCROLLOCK, SCROLLOCK )
+ K( LSUPER, LWINKEY )
+ K( RSUPER, RWINKEY )
+ K( MENU, MENU )
+
+ KK( RSHIFT, SHIFT, RSHIFT )
+ KK( LSHIFT, SHIFT, LSHIFT )
+ KK( RCTRL, CTRL, RCTRL )
+ KK( LCTRL, CTRL, LCTRL )
+ KK( RALT, ALT, RALT )
+ KK( LALT, ALT, LALT )
#undef K
#undef KK
- default:
- Com_DPrintf( "%s: unknown keysym %d\n", __func__, keysym->sym );
+ default:
+ Com_DPrintf( "%s: unknown keysym %d\n", __func__, keysym->sym );
return;
- }
+ }
- Key_Event( key1, down, com_eventTime );
+ Key_Event( key1, down, com_eventTime );
if( key2 ) {
- Key_Event( key2, down, com_eventTime );
+ Key_Event( key2, down, com_eventTime );
}
}
-static void QSDL_MouseButtonEvent( int button, qboolean down ) {
+static void ButtonEvent( int button, qboolean down ) {
unsigned key;
- if( !sdl.mouseinitialized ) {
+ if( !sdl.mouse.initialized ) {
return;
}
- if( !sdl.mouseactive ) {
- QSDL_AcquireMouse();
- sdl.mouseactive = qtrue;
- return;
- }
-
-#define K( s, d ) case SDL_BUTTON_ ## s: key = K_ ## d; break;
+#define K( s, d ) case SDL_BUTTON_ ## s: key = K_ ## d; break;
switch( button ) {
- K( LEFT, MOUSE1 )
- K( RIGHT, MOUSE2 )
- K( MIDDLE, MOUSE3 )
- K( WHEELUP, MWHEELUP )
- K( WHEELDOWN, MWHEELDOWN )
+ K( LEFT, MOUSE1 )
+ K( RIGHT, MOUSE2 )
+ K( MIDDLE, MOUSE3 )
+ K( WHEELUP, MWHEELUP )
+ K( WHEELDOWN, MWHEELDOWN )
#undef K
default:
- Com_DPrintf( "%s: unknown button %d\n", __func__, button );
+ Com_DPrintf( "%s: unknown button %d\n", __func__, button );
return;
}
@@ -326,44 +352,45 @@ static void QSDL_MouseButtonEvent( int button, qboolean down ) {
/*
============
-Video_PumpEvents
+VID_PumpEvents
============
*/
-void Video_PumpEvents( void ) {
- SDL_Event event;
-
- while( SDL_PollEvent( &event ) ) {
- switch( event.type ) {
- case SDL_ACTIVEEVENT:
- QSDL_Activate( &event );
- break;
- case SDL_QUIT:
- Com_Quit();
- break;
+void VID_PumpEvents( void ) {
+ SDL_Event event;
+
+ while( SDL_PollEvent( &event ) ) {
+ switch( event.type ) {
+ case SDL_ACTIVEEVENT:
+ Activate();
+ break;
+ case SDL_QUIT:
+ Com_Quit();
+ break;
case SDL_VIDEORESIZE:
if( sdl.surface->flags & SDL_RESIZABLE ) {
- event.resize.w &= ~7;
- event.resize.h &= ~1;
- Cvar_Set( "vid_placement", va( "%dx%d",
+ Cvar_Set( "vid_geometry", va( "%dx%d",
event.resize.w, event.resize.h ) );
- Video_ModeChanged();
+ VID_ModeChanged();
return;
}
break;
- case SDL_KEYDOWN:
- QSDL_KeyEvent( &event.key.keysym, qtrue );
- break;
- case SDL_KEYUP:
- QSDL_KeyEvent( &event.key.keysym, qfalse );
- break;
- case SDL_MOUSEBUTTONDOWN:
- QSDL_MouseButtonEvent( event.button.button, qtrue );
+ case SDL_KEYDOWN:
+ KeyEvent( &event.key.keysym, qtrue );
break;
- case SDL_MOUSEBUTTONUP:
- QSDL_MouseButtonEvent( event.button.button, qfalse );
+ case SDL_KEYUP:
+ KeyEvent( &event.key.keysym, qfalse );
break;
- }
- }
+ case SDL_MOUSEBUTTONDOWN:
+ ButtonEvent( event.button.button, qtrue );
+ break;
+ case SDL_MOUSEBUTTONUP:
+ ButtonEvent( event.button.button, qfalse );
+ break;
+ case SDL_MOUSEMOTION:
+ IN_MouseEvent( event.motion.x, event.motion.y );
+ break;
+ }
+ }
}
@@ -375,44 +402,44 @@ OPENGL SPECIFIC
===============================================================================
*/
-static qboolean QSDL_InitGL( void ) {
- cvar_t *gl_driver;
+static qboolean InitGL( void ) {
+ cvar_t *gl_driver;
- if( !QSDL_InitVideo() ) {
- return qfalse;
- }
+ if( !InitVideo() ) {
+ return qfalse;
+ }
- gl_driver = Cvar_Get( "gl_driver", DEFAULT_OPENGL_DRIVER, CVAR_LATCH );
+ gl_driver = Cvar_Get( "gl_driver", DEFAULT_OPENGL_DRIVER, CVAR_LATCH );
- if( SDL_GL_LoadLibrary( gl_driver->string ) == -1 ) {
- Com_EPrintf( "Couldn't load OpenGL library: %s\n", SDL_GetError() );
+ if( SDL_GL_LoadLibrary( gl_driver->string ) == -1 ) {
+ Com_EPrintf( "Couldn't load OpenGL library: %s\n", SDL_GetError() );
goto fail;
- }
+ }
- 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 );
+ 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 );
- sdl.flags |= QVF_ACCELERATED;
+ sdl.flags |= QVF_ACCELERATED;
- if( !QSDL_SetMode( SDL_OPENGL|SDL_RESIZABLE, 0 ) ) {
+ if( !SetMode( SDL_OPENGL|SDL_RESIZABLE, 0 ) ) {
Com_EPrintf( "Couldn't set video mode: %s\n", SDL_GetError() );
goto fail;
}
// sdl.glXGetVideoSyncSGI = SDL_GL_GetProcAddress( "glXGetVideoSyncSGI" );
- CL_AppActivate( qtrue );
- return qtrue;
+ Activate();
+ return qtrue;
fail:
- QSDL_ShutdownVideo();
- return qfalse;
+ ShutdownVideo();
+ return qfalse;
}
#if 0
-qboolean QSDL_VideoSync( void ) {
+qboolean VideoSync( void ) {
GLuint count;
static GLuint oldcount;
@@ -420,7 +447,7 @@ qboolean QSDL_VideoSync( void ) {
if( count != oldcount ) {
oldcount = count;
- SDL_GL_SwapBuffers();
+ SDL_GL_SwapBuffers();
// Com_Printf( "%u ", count );
return qtrue;
}
@@ -428,21 +455,26 @@ qboolean QSDL_VideoSync( void ) {
}
#endif
-static void QSDL_BeginFrameGL( void ) {
+static void BeginFrameGL( void ) {
}
-static void QSDL_EndFrameGL( void ) {
- SDL_GL_SwapBuffers();
+static void EndFrameGL( void ) {
+ SDL_GL_SwapBuffers();
}
-void Video_FillGLAPI( videoAPI_t *api ) {
- api->Init = QSDL_InitGL;
- api->Shutdown = QSDL_ShutdownVideo;
- api->UpdateGamma = QSDL_UpdateGamma;
+/*
+============
+VID_FillGLAPI
+============
+*/
+void VID_FillGLAPI( videoAPI_t *api ) {
+ api->Init = InitGL;
+ api->Shutdown = ShutdownVideo;
+ api->UpdateGamma = UpdateGamma;
api->UpdatePalette = NULL;
- api->GetProcAddr = SDL_GL_GetProcAddress;
- api->BeginFrame = QSDL_BeginFrameGL;
- api->EndFrame = QSDL_EndFrameGL;
+ api->GetProcAddr = SDL_GL_GetProcAddress;
+ api->BeginFrame = BeginFrameGL;
+ api->EndFrame = EndFrameGL;
}
/*
@@ -455,52 +487,57 @@ SOFTWARE SPECIFIC
#ifndef REF_HARD_LINKED
-static qboolean QSDL_InitSoft( void ) {
- if( !QSDL_InitVideo() ) {
- return qfalse;
- }
+static qboolean InitSoft( void ) {
+ if( !InitVideo() ) {
+ return qfalse;
+ }
- if( !QSDL_SetMode( SDL_SWSURFACE|SDL_HWPALETTE|SDL_RESIZABLE, 8 ) ) {
+ if( !SetMode( SDL_SWSURFACE|SDL_HWPALETTE|SDL_RESIZABLE, 8 ) ) {
Com_EPrintf( "Couldn't set video mode: %s\n", SDL_GetError() );
- QSDL_ShutdownVideo();
+ ShutdownVideo();
return qfalse;
}
- CL_AppActivate( qtrue );
- return qtrue;
+ Activate();
+ return qtrue;
}
-static void QSDL_UpdatePalette( const byte *palette ) {
- SDL_Color colors[256];
- SDL_Color *c;
+static void UpdatePalette( const byte *palette ) {
+ SDL_Color colors[256];
+ SDL_Color *c;
- for( c = colors; c < colors + 256; c++ ) {
- c->r = palette[0];
- c->g = palette[1];
- c->b = palette[2];
- palette += 4;
- }
+ for( c = colors; c < colors + 256; c++ ) {
+ c->r = palette[0];
+ c->g = palette[1];
+ c->b = palette[2];
+ palette += 4;
+ }
- SDL_SetPalette( sdl.surface, SDL_LOGPAL, colors, 0, 256 );
+ SDL_SetPalette( sdl.surface, SDL_LOGPAL, colors, 0, 256 );
}
-static void QSDL_BeginFrameSoft( void ) {
- SDL_LockSurface( sdl.surface );
+static void BeginFrameSoft( void ) {
+ SDL_LockSurface( sdl.surface );
}
-static void QSDL_EndFrameSoft( void ) {
- SDL_UnlockSurface( sdl.surface );
- SDL_Flip( sdl.surface );
+static void EndFrameSoft( void ) {
+ SDL_UnlockSurface( sdl.surface );
+ SDL_Flip( sdl.surface );
}
-void Video_FillSWAPI( videoAPI_t *api ) {
- api->Init = QSDL_InitSoft;
- api->Shutdown = QSDL_ShutdownVideo;
- api->UpdateGamma = QSDL_UpdateGamma;
- api->UpdatePalette = QSDL_UpdatePalette;
- api->GetProcAddr = NULL;
- api->BeginFrame = QSDL_BeginFrameSoft;
- api->EndFrame = QSDL_EndFrameSoft;
+/*
+============
+VID_FillSWAPI
+============
+*/
+void VID_FillSWAPI( videoAPI_t *api ) {
+ api->Init = InitSoft;
+ api->Shutdown = ShutdownVideo;
+ api->UpdateGamma = UpdateGamma;
+ api->UpdatePalette = UpdatePalette;
+ api->GetProcAddr = NULL;
+ api->BeginFrame = BeginFrameSoft;
+ api->EndFrame = EndFrameSoft;
}
#endif // !REF_HARD_LINKED
@@ -515,99 +552,103 @@ SDL MOUSE DRIVER
#define SDL_FULLFOCUS (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS)
-void QSDL_AcquireMouse( void ) {
+static void AcquireMouse( void ) {
int state;
- // move cursor to center of the main window before we grab the mouse
- if( sdl.surface ) {
- SDL_WarpMouse( sdl.surface->w / 2, sdl.surface->h / 2 );
- }
+ // move cursor to center of the main window before we grab the mouse
+ if( sdl.surface ) {
+ SDL_WarpMouse( sdl.surface->w / 2, sdl.surface->h / 2 );
+ }
- // pump mouse motion events generated by SDL_WarpMouse
- SDL_PollEvent( NULL );
+ // pump mouse motion events generated by SDL_WarpMouse
+ SDL_PollEvent( NULL );
- // grab the mouse, so SDL enters relative mouse mode
- SDL_WM_GrabInput( SDL_GRAB_ON );
+ // grab the mouse, so SDL enters relative mouse mode
+ SDL_WM_GrabInput( SDL_GRAB_ON );
state = SDL_GetAppState();
if( ( state & SDL_FULLFOCUS ) != SDL_FULLFOCUS ) {
- Com_DPrintf( "QSDL_AcquireMouse: don't have full focus\n" );
+ Com_DPrintf( "AcquireMouse: don't have full focus\n" );
}
- SDL_ShowCursor( SDL_DISABLE );
-
- // pump mouse motion events still pending
- SDL_PollEvent( NULL );
+ SDL_ShowCursor( SDL_DISABLE );
+
+ // pump mouse motion events still pending
+ SDL_PollEvent( NULL );
- // clear any deltas generated
- SDL_GetRelativeMouseState( NULL, NULL );
+ // clear any deltas generated
+ SDL_GetRelativeMouseState( NULL, NULL );
}
-static void QSDL_DeAcquireMouse( void ) {
- // release the mouse
- SDL_ShowCursor( SDL_ENABLE );
- SDL_WM_GrabInput( SDL_GRAB_OFF );
+static qboolean GetMouseMotion( int *dx, int *dy ) {
+ if( !sdl.mouse.grabbed ) {
+ return qfalse;
+ }
+ SDL_GetRelativeMouseState( dx, dy );
+ return qtrue;
}
-static void QSDL_SendMouseMoveEvents( void ) {
- int dx, dy;
-
- if( !sdl.mouseinitialized ) {
- return;
- }
-
- if( !sdl.mouseactive ) {
- return;
- }
-
- SDL_GetRelativeMouseState( &dx, &dy );
-
- if( dx || dy ) {
- CL_MouseEvent( dx, dy );
- }
+static void WarpMouse( int x, int y ) {
+ SDL_WarpMouse( x, y );
+ SDL_PollEvent( NULL );
+ SDL_GetRelativeMouseState( NULL, NULL );
}
-static void QSDL_ShutdownMouse( void ) {
- QSDL_DeAcquireMouse();
- sdl.mouseactive = qfalse;
- sdl.mouseinitialized = qfalse;
+static void ShutdownMouse( void ) {
+ // release the mouse
+ SDL_ShowCursor( SDL_ENABLE );
+ SDL_WM_GrabInput( SDL_GRAB_OFF );
+ SDL_WM_SetCaption( APPLICATION, APPLICATION );
+ memset( &sdl.mouse, 0, sizeof( sdl.mouse ) );
}
-static qboolean QSDL_InitMouse( void ) {
- if( SDL_WasInit( SDL_INIT_VIDEO ) != SDL_INIT_VIDEO ) {
- return qfalse;
- }
+static qboolean InitMouse( void ) {
+ if( SDL_WasInit( SDL_INIT_VIDEO ) != SDL_INIT_VIDEO ) {
+ return qfalse;
+ }
- sdl.mouseinitialized = qtrue;
+ Com_Printf( "SDL mouse initialized.\n" );
+ sdl.mouse.initialized = qtrue;
- return qtrue;
+ return qtrue;
}
-static void QSDL_ActivateMouse( qboolean active ) {
- if( !sdl.mouseinitialized ) {
- return;
- }
-
- if( sdl.mouseactive == active ) {
- // return;
- }
+static void GrabMouse( grab_t grab ) {
+ if( !sdl.mouse.initialized ) {
+ return;
+ }
- if( active ) {
- QSDL_AcquireMouse();
- } else {
- QSDL_DeAcquireMouse();
- }
+ if( sdl.mouse.grabbed == grab ) {
+ return;
+ }
- sdl.mouseactive = active;
-}
+ if( grab == IN_GRAB ) {
+ AcquireMouse();
+ SDL_WM_SetCaption( "[" APPLICATION "]", APPLICATION );
+ } else {
+ if( sdl.mouse.grabbed == IN_GRAB ) {
+ SDL_WM_GrabInput( SDL_GRAB_OFF );
+ SDL_WM_SetCaption( APPLICATION, APPLICATION );
+ }
+ if( grab == IN_HIDE ) {
+ SDL_ShowCursor( SDL_DISABLE );
+ } else {
+ SDL_ShowCursor( SDL_ENABLE );
+ }
+ }
-static void QSDL_ClearMouseStates( void ) {
- // no work here
+ sdl.mouse.grabbed = grab;
}
-void Video_FillInputAPI( inputAPI_t *api ) {
- api->Init = QSDL_InitMouse;
- api->Shutdown = QSDL_ShutdownMouse;
- api->Activate = QSDL_ActivateMouse;
- api->Frame = QSDL_SendMouseMoveEvents;
- api->ClearStates = QSDL_ClearMouseStates;
+/*
+============
+VID_FillInputAPI
+============
+*/
+void VID_FillInputAPI( inputAPI_t *api ) {
+ api->Init = InitMouse;
+ api->Shutdown = ShutdownMouse;
+ api->Grab = GrabMouse;
+ api->Warp = WarpMouse;
+ api->GetEvents = NULL;
+ api->GetMotion = GetMouseMotion;
}
diff --git a/source/vid_win.c b/source/vid_win.c
index 8683e64..dc83a1a 100644
--- a/source/vid_win.c
+++ b/source/vid_win.c
@@ -188,7 +188,7 @@ void Win_SetMode( void ) {
Com_DPrintf( "failed\n" );
}
- Video_GetPlacement( &rc );
+ VID_GetGeometry( &rc );
Com_DPrintf( "...setting windowed mode: %dx%d+%d+%d\n",
rc.width, rc.height, rc.x, rc.y );
@@ -262,24 +262,27 @@ static void win_noalttab_changed( cvar_t *self ) {
/*
=================
-Win_AppActivate
+Win_Activate
=================
*/
-static void Win_AppActivate( WPARAM wParam ) {
- qboolean active, minimized;
+static void Win_Activate( WPARAM wParam ) {
+ active_t active;
- minimized = active = qfalse;
if( HIWORD( wParam ) ) {
// we don't want to act like we're active if we're minimized
- minimized = qtrue;
- } else if( LOWORD( wParam ) ) {
- active = qtrue;
+ active = ACT_MINIMIZED;
+ } else {
+ if( LOWORD( wParam ) ) {
+ active = ACT_ACTIVATED;
+ } else {
+ active = ACT_RESTORED;
+ }
}
- CL_AppActivate( active );
+ CL_Activate( active );
if( win_noalttab->integer ) {
- if( !active ) {
+ if( active == ACT_ACTIVATED ) {
Win_EnableAltTab();
} else {
Win_DisableAltTab();
@@ -287,7 +290,7 @@ static void Win_AppActivate( WPARAM wParam ) {
}
if( win.flags & QVF_GAMMARAMP ) {
- if( active ) {
+ if( active == ACT_ACTIVATED ) {
SetDeviceGammaRamp( win.dc, win.gamma_cust );
} else {
SetDeviceGammaRamp( win.dc, win.gamma_orig );
@@ -295,14 +298,14 @@ static void Win_AppActivate( WPARAM wParam ) {
}
if( win.flags & QVF_FULLSCREEN ) {
- if( active ) {
+ if( active == ACT_ACTIVATED ) {
ShowWindow( win.wnd, SW_RESTORE );
} else {
ShowWindow( win.wnd, SW_MINIMIZE );
}
if( vid_flip_on_switch->integer ) {
- if( active ) {
+ if( active == ACT_ACTIVATED ) {
ChangeDisplaySettings( &win.dm, CDS_FULLSCREEN );
} else {
ChangeDisplaySettings( NULL, 0 );
@@ -310,7 +313,7 @@ static void Win_AppActivate( WPARAM wParam ) {
}
}
- if( active ) {
+ if( active == ACT_ACTIVATED ) {
SetForegroundWindow( win.wnd );
}
}
@@ -369,7 +372,7 @@ static void win_disablewinkey_changed( cvar_t *self ) {
}
}
-static byte scantokey[128] = {
+static const byte scantokey[128] = {
// 0 1 2 3 4 5 6 7
// 8 9 A B C D E F
0, K_ESCAPE, '1', '2', '3', '4', '5', '6',
@@ -408,7 +411,7 @@ static void Win_KeyEvent( WPARAM wParam, LPARAM lParam, qboolean down ) {
result = scantokey[scancode];
if( !result ) {
- Com_DPrintf( "Win_KeyEvent: unknown scancode %u\n", scancode );
+ Com_DPrintf( "%s: unknown scancode: %u\n", __func__, scancode );
return;
}
@@ -586,7 +589,7 @@ LONG WINAPI Win_MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
return FALSE;
case WM_ACTIVATE:
- Win_AppActivate( wParam );
+ Win_Activate( wParam );
break;
case WM_SIZING:
@@ -634,8 +637,6 @@ LONG WINAPI Win_MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
if( wParam == SIZE_RESTORED && !vid_fullscreen->integer ) {
int w = ( short )LOWORD( lParam );
int h = ( short )HIWORD( lParam );
- win.rc.width = w & ~7;
- win.rc.height = h & ~1;
win.mode_changed |= 1;
}
break;
@@ -668,7 +669,7 @@ LONG WINAPI Win_MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
return FALSE;
case SC_MAXIMIZE:
if( !vid_fullscreen->integer ) {
- Video_ToggleFullscreen();
+ VID_ToggleFullscreen();
}
return FALSE;
}
@@ -723,7 +724,7 @@ void Video_PumpEvents( void ) {
}
if( win.mode_changed ) {
- Video_SetPlacement( &win.rc );
+ VID_SetGeometry( &win.rc );
if( win.mode_changed & 1 ) {
Win_ModeChanged();
}
@@ -837,6 +838,16 @@ MOUSE
// mouse variables
static cvar_t *win_xpfix;
+static void Win_HideCursor( void ) {
+ while( ShowCursor( FALSE ) >= 0 )
+ ;
+}
+
+static void Win_ShowCursor( void ) {
+ while( ShowCursor ( TRUE ) < 0 )
+ ;
+}
+
/*
===========
Win_AcquireMouse
@@ -868,8 +879,8 @@ static void Win_AcquireMouse( void ) {
SetCapture( win.wnd );
ClipCursor( &rc );
- while( ShowCursor( FALSE ) >= 0 )
- ;
+
+ SetWindowTitle( win.wnd, "[" APPLICATION "]" );
}
@@ -881,13 +892,13 @@ Called when the window loses focus
===========
*/
static void Win_DeAcquireMouse( void ) {
- if( win.mouse.restoreparms )
- SystemParametersInfo( SPI_SETMOUSE, 0, win.mouse.originalparms, 0 );
+ if( win.mouse.restoreparms )
+ SystemParametersInfo( SPI_SETMOUSE, 0, win.mouse.originalparms, 0 );
- ClipCursor( NULL );
- ReleaseCapture();
- while( ShowCursor ( TRUE ) < 0 )
- ;
+ ClipCursor( NULL );
+ ReleaseCapture();
+
+ SetWindowTitle( win.wnd, APPLICATION );
}
static void win_xpfix_changed( cvar_t *self ) {
@@ -898,33 +909,27 @@ static void win_xpfix_changed( cvar_t *self ) {
/*
===========
-Win_SendMouseMoveEvents
+Win_GetMouseMotion
===========
*/
-static void Win_SendMouseMoveEvents( void ) {
+static qboolean Win_GetMouseMotion( int *dx, int *dy ) {
POINT pt;
- int dx, dy;
if( !win.mouse.active ) {
- return;
+ return qfalse;
}
// find mouse movement
if( !GetCursorPos( &pt ) ) {
- return;
+ return qfalse;
}
- dx = pt.x - win.center_x;
- dy = pt.y - win.center_y;
-
- if( !dx && !dy ) {
- return;
- }
+ *dx = pt.x - win.center_x;
+ *dy = pt.y - win.center_y;
// force the mouse to the center, so there's room to move
SetCursorPos( win.center_x, win.center_y );
-
- CL_MouseEvent( dx, dy );
+ return qtrue;
}
/*
@@ -934,6 +939,7 @@ Win_ShutdownMouse
*/
static void Win_ShutdownMouse( void ) {
Win_DeAcquireMouse();
+ Win_ShowCursor();
memset( &win.mouse, 0, sizeof( win.mouse ) );
}
@@ -966,42 +972,42 @@ The window may have been destroyed and recreated
between a deactivate and an activate.
===========
*/
-static void Win_ActivateMouse( qboolean active ) {
+static void Win_ActivateMouse( grab_t grab ) {
if( !win.mouse.initialized ) {
return;
}
- if( win.mouse.active == active ) {
-// return;
+ if( win.mouse.grabbed == grab ) {
+ return;
}
- if( active ) {
+ if( grab == IN_GRAB ) {
Win_AcquireMouse();
+ Win_HideCursor();
} else {
- Win_DeAcquireMouse();
+ if( win.mouse.grabbed == IN_GRAB ) {
+ Win_DeAcquireMouse();
+ }
+ if( grab == IN_HIDE ) {
+ Win_HideCursor();
+ } else {
+ Win_ShowCursor();
+ }
}
- win.mouse.active = active;
-}
-
-/*
-===================
-Win_ClearMouseStates
-===================
-*/
-static void Win_ClearMouseStates( void ) {
win.mouse.state = 0;
+ win.mouse.grabbed = grab;
}
/*
@@@@@@@@@@@@@@@@@@@
-Win_FillInputAPI
+VID_FillInputAPI
@@@@@@@@@@@@@@@@@@@
*/
-void Video_FillInputAPI( inputAPI_t *api ) {
+void VID_FillInputAPI( inputAPI_t *api ) {
api->Init = Win_InitMouse;
api->Shutdown = Win_ShutdownMouse;
- api->Activate = Win_ActivateMouse;
- api->Frame = Win_SendMouseMoveEvents;
- api->ClearStates = Win_ClearMouseStates;
+ api->Grab = Win_GrabMouse;
+ api->GetEvents = NULL;
+ api->GetMotion = Win_GetMouseMotion;
}
diff --git a/source/win_glimp.c b/source/win_glimp.c
index caffca5..3393d0b 100644
--- a/source/win_glimp.c
+++ b/source/win_glimp.c
@@ -249,10 +249,10 @@ static void GLimp_EndFrame( void ) {
/*
@@@@@@@@@@@@
-GLimp_FillAPI
+VID_FillGLAPI
@@@@@@@@@@@@
*/
-void Video_FillGLAPI( videoAPI_t *api ) {
+void VID_FillGLAPI( videoAPI_t *api ) {
api->Init = GLimp_Init;
api->Shutdown = GLimp_Shutdown;
api->UpdateGamma = Win_UpdateGamma;
diff --git a/source/win_local.h b/source/win_local.h
index e16cb86..251e23b 100644
--- a/source/win_local.h
+++ b/source/win_local.h
@@ -86,7 +86,7 @@ typedef struct {
struct {
qboolean initialized;
- qboolean active; // qfalse when not focus app
+ grab_t grabbed;
int state;
qboolean parmsvalid;
qboolean restoreparms;
diff --git a/source/win_swimp.c b/source/win_swimp.c
index 383e8c6..0aaf245 100644
--- a/source/win_swimp.c
+++ b/source/win_swimp.c
@@ -333,10 +333,10 @@ static void SWimp_UpdatePalette( const byte *_pal ) {
/*
@@@@@@@@@@@@
-SWimp_FillAPI
+VID_FillSWAPI
@@@@@@@@@@@@
*/
-void Video_FillSWAPI( videoAPI_t *api ) {
+void VID_FillSWAPI( videoAPI_t *api ) {
api->Init = SWimp_Init;
api->Shutdown = SWimp_Shutdown;
api->UpdateGamma = Win_UpdateGamma;