diff --git a/include/common.h b/include/common.h new file mode 100644 index 0000000..5692815 --- /dev/null +++ b/include/common.h @@ -0,0 +1,211 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ +// common.h -- general definitions + +#ifndef _COMMON_H +#define _COMMON_H + +//#include "protocol.h" // for struct usercmd_s + +#ifndef _DEF_BYTE_ +# define _DEF_BYTE_ +typedef unsigned char byte; +#endif + +// KJB Undefined true and false defined in SciTech's DEBUG.H header +#undef true +#undef false + +typedef enum {false, true} qboolean; + +#define MAX_INFO_STRING 196 +#define MAX_SERVERINFO_STRING 512 +#define MAX_LOCALINFO_STRING 32768 + +//============================================================================ + +typedef struct sizebuf_s +{ + qboolean allowoverflow; // if false, do a Sys_Error + qboolean overflowed; // set to true if the buffer size failed + byte *data; + int maxsize; + int cursize; +} sizebuf_t; + +void SZ_Clear (sizebuf_t *buf); +void *SZ_GetSpace (sizebuf_t *buf, int length); +void SZ_Write (sizebuf_t *buf, void *data, int length); +void SZ_Print (sizebuf_t *buf, char *data); // strcats onto the sizebuf + +//============================================================================ + +typedef struct link_s +{ + struct link_s *prev, *next; +} link_t; + +void ClearLink (link_t *l); +void RemoveLink (link_t *l); +void InsertLinkBefore (link_t *l, link_t *before); +void InsertLinkAfter (link_t *l, link_t *after); + +// (type *)STRUCT_FROM_LINK(link_t *link, type, member) +// ent = STRUCT_FROM_LINK(link,entity_t,order) +// FIXME: remove this mess! +#define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m))) + +//============================================================================ + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#define Q_MAXCHAR ((char)0x7f) +#define Q_MAXSHORT ((short)0x7fff) +#define Q_MAXINT ((int)0x7fffffff) +#define Q_MAXLONG ((int)0x7fffffff) +#define Q_MAXFLOAT ((int)0x7fffffff) + +#define Q_MINCHAR ((char)0x80) +#define Q_MINSHORT ((short)0x8000) +#define Q_MININT ((int)0x80000000) +#define Q_MINLONG ((int)0x80000000) +#define Q_MINFLOAT ((int)0x7fffffff) + +//============================================================================ + +extern qboolean bigendien; + +extern short (*BigShort) (short l); +extern short (*LittleShort) (short l); +extern int (*BigLong) (int l); +extern int (*LittleLong) (int l); +extern float (*BigFloat) (float l); +extern float (*LittleFloat) (float l); + +//============================================================================ + +extern struct usercmd_s nullcmd; + +void MSG_WriteChar (sizebuf_t *sb, int c); +void MSG_WriteByte (sizebuf_t *sb, int c); +void MSG_WriteShort (sizebuf_t *sb, int c); +void MSG_WriteLong (sizebuf_t *sb, int c); +void MSG_WriteFloat (sizebuf_t *sb, float f); +void MSG_WriteString (sizebuf_t *sb, char *s); +void MSG_WriteCoord (sizebuf_t *sb, float f); +void MSG_WriteAngle (sizebuf_t *sb, float f); +void MSG_WriteAngle16 (sizebuf_t *sb, float f); +void MSG_WriteDeltaUsercmd (sizebuf_t *sb, struct usercmd_s *from, struct usercmd_s *cmd); + +extern int msg_readcount; +extern qboolean msg_badread; // set if a read goes beyond end of message + +void MSG_BeginReading (void); +int MSG_GetReadCount(void); +int MSG_ReadChar (void); +int MSG_ReadByte (void); +int MSG_ReadShort (void); +int MSG_ReadLong (void); +float MSG_ReadFloat (void); +char *MSG_ReadString (void); +char *MSG_ReadStringLine (void); + +float MSG_ReadCoord (void); +float MSG_ReadAngle (void); +float MSG_ReadAngle16 (void); +void MSG_ReadDeltaUsercmd (struct usercmd_s *from, struct usercmd_s *cmd); + + +#ifdef _WIN32 + +#ifdef __BORLANDC__ +#define strcasecmp(s1, s2) stricmp((s1), (s2)) +#define strncasecmp(s1, s2, n) strnicmp((s1), (s2), (n)) + +#else +#define strcasecmp(s1, s2) _stricmp((s1), (s2)) +#define strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n)) +#endif + +#endif + +//============================================================================ + +extern char com_token[1024]; +extern qboolean com_eof; + +char *COM_Parse (char *data); + + +extern int com_argc; +extern char **com_argv; + +int COM_CheckParm (char *parm); +void COM_AddParm (char *parm); + +void COM_Init (void); +void COM_InitArgv (int argc, char **argv); + +char *COM_SkipPath (char *pathname); +void COM_StripExtension (char *in, char *out); +void COM_FileBase (char *in, char *out); +void COM_DefaultExtension (char *path, char *extension); + +char *va(char *format, ...); +// does a varargs printf into a temp buffer + +//============================================================================ + +extern int com_filesize; +struct cache_user_s; + +extern char com_gamedir[MAX_OSPATH]; + +void COM_WriteFile (char *filename, void *data, int len); +int COM_FOpenFile (char *filename, FILE **file); +void COM_CloseFile (FILE *h); + +byte *COM_LoadStackFile (char *path, void *buffer, int bufsize); +byte *COM_LoadTempFile (char *path); +byte *COM_LoadHunkFile (char *path); +void COM_LoadCacheFile (char *path, struct cache_user_s *cu); +void COM_CreatePath (char *path); +void COM_Gamedir (char *dir); + +extern struct cvar_s *registered; +extern qboolean standard_quake, rogue, hipnotic; + +char *Info_ValueForKey (char *s, char *key); +void Info_RemoveKey (char *s, char *key); +void Info_RemovePrefixedKeys (char *start, char prefix); +void Info_SetValueForKey (char *s, char *key, char *value, int maxsize); +void Info_SetValueForStarKey (char *s, char *key, char *value, int maxsize); +void Info_Print (char *s); + +unsigned Com_BlockChecksum (void *buffer, int length); +void Com_BlockFullChecksum (void *buffer, int len, unsigned char *outbuf); +byte COM_BlockSequenceCheckByte (byte *base, int length, int sequence, unsigned mapchecksum); +byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence); + +int build_number( void ); + +#endif // _COMMON_H diff --git a/source/cd_audio.c b/source/cd_audio.c index 04f2ced..69f1112 100644 --- a/source/cd_audio.c +++ b/source/cd_audio.c @@ -33,7 +33,9 @@ #include "quakedef.h" #include "dosisms.h" -extern cvar_t *bgmvolume; +/* extern cvar_t bgmvolume; + CVAR_FIXME */ +extern cvar_t *bgmvolume; #define ADDRESS_MODE_HSG 0 #define ADDRESS_MODE_RED_BOOK 1 @@ -626,13 +628,13 @@ static void CD_f (void) command = Cmd_Argv (1); - if (Q_strcasecmp(command, "on") == 0) + if (strcasecmp(command, "on") == 0) { enabled = true; return; } - if (Q_strcasecmp(command, "off") == 0) + if (strcasecmp(command, "off") == 0) { if (playing) CDAudio_Stop(); @@ -640,7 +642,7 @@ static void CD_f (void) return; } - if (Q_strcasecmp(command, "reset") == 0) + if (strcasecmp(command, "reset") == 0) { enabled = true; if (playing) @@ -652,7 +654,7 @@ static void CD_f (void) return; } - if (Q_strcasecmp(command, "remap") == 0) + if (strcasecmp(command, "remap") == 0) { ret = Cmd_Argc() - 2; if (ret <= 0) @@ -663,7 +665,7 @@ static void CD_f (void) return; } for (n = 1; n <= ret; n++) - remap[n] = Q_atoi(Cmd_Argv (n+1)); + remap[n] = atoi(Cmd_Argv (n+1)); return; } @@ -673,31 +675,31 @@ static void CD_f (void) return; } - if (Q_strcasecmp(command, "play") == 0) + if (strcasecmp(command, "play") == 0) { - CDAudio_Play(Q_atoi(Cmd_Argv (2)), false); + CDAudio_Play(atoi(Cmd_Argv (2)), false); return; } - if (Q_strcasecmp(command, "loop") == 0) + if (strcasecmp(command, "loop") == 0) { - CDAudio_Play(Q_atoi(Cmd_Argv (2)), true); + CDAudio_Play(atoi(Cmd_Argv (2)), true); return; } - if (Q_strcasecmp(command, "stop") == 0) + if (strcasecmp(command, "stop") == 0) { CDAudio_Stop(); return; } - if (Q_strcasecmp(command, "resume") == 0) + if (strcasecmp(command, "resume") == 0) { CDAudio_Resume(); return; } - if (Q_strcasecmp(command, "eject") == 0) + if (strcasecmp(command, "eject") == 0) { if (playing) CDAudio_Stop(); @@ -706,7 +708,7 @@ static void CD_f (void) return; } - if (Q_strcasecmp(command, "info") == 0) + if (strcasecmp(command, "info") == 0) { Con_Printf("%u tracks\n", cd.highTrack - cd.lowTrack + 1); for (n = cd.lowTrack; n <= cd.highTrack; n++) @@ -757,6 +759,8 @@ void CDAudio_Update(void) } } +/* newVolume = (int)(bgmvolume.value * 255.0); + CVAR_FIXME */ newVolume = (int)(bgmvolume->value * 255.0); if (newVolume < 0) { diff --git a/source/cd_linux.c b/source/cd_linux.c index 1102359..39a9fa3 100644 --- a/source/cd_linux.c +++ b/source/cd_linux.c @@ -42,11 +42,7 @@ #include -#include "qargs.h" -#include "cmd.h" -#include "cdaudio.h" -#include "console.h" -#include "sound.h" +#include "quakedef.h" static qboolean cdValid = false; static qboolean playing = false; @@ -346,17 +342,23 @@ void CDAudio_Update(void) if (!enabled) return; +/* if (bgmvolume.value != cdvolume) + CVAR_FIXME */ if (bgmvolume->value != cdvolume) { if (cdvolume) { - Cvar_SetValue (bgmvolume, 0.0); + bgmvolume->value = 0.0; +/* cdvolume = bgmvolume.value; + CVAR_FIXME */ cdvolume = bgmvolume->value; CDAudio_Pause (); } else { bgmvolume->value = 1.0; +/* cdvolume = bgmvolume.value; + CVAR_FIXME */ cdvolume = bgmvolume->value; CDAudio_Resume (); } diff --git a/source/cd_win.c b/source/cd_win.c index c413969..b877acf 100644 --- a/source/cd_win.c +++ b/source/cd_win.c @@ -31,12 +31,10 @@ #endif #include #include "quakedef.h" -#include "qargs.h" -#include "console.h" -#include "cdaudio.h" -#include "cmd.h" extern HWND mainwindow; +/* extern cvar_t bgmvolume; + CVAR_FIXME */ extern cvar_t *bgmvolume; static qboolean cdValid = false; @@ -421,17 +419,23 @@ void CDAudio_Update(void) if (!enabled) return; +/* if (bgmvolume.value != cdvolume) + CVAR_FIXME */ if (bgmvolume->value != cdvolume) { if (cdvolume) { Cvar_SetValue (bgmvolume, 0.0); +/* cdvolume = bgmvolume.value; + CVAR_FIXME */ cdvolume = bgmvolume->value; CDAudio_Pause (); } else { Cvar_SetValue (bgmvolume, 1.0); +/* cdvolume = bgmvolume.value; + CVAR_FIXME */ cdvolume = bgmvolume->value; CDAudio_Resume (); } diff --git a/source/cl_cmd.c b/source/cl_cmd.c index 855b539..2021bae 100644 --- a/source/cl_cmd.c +++ b/source/cl_cmd.c @@ -1,7 +1,7 @@ /* cl_cmd.c - Client-side script command processing module + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -26,15 +26,12 @@ $Id$ */ +// cmd.c -- Quake script command processing module + #ifdef HAVE_CONFIG_H # include #endif -#include "client.h" -#include "console.h" -#include "cmd.h" -#include "msg.h" - -#include +#include "quakedef.h" /* =================== diff --git a/source/cl_input.c b/source/cl_input.c index 1ea58d8..740ef9b 100644 --- a/source/cl_input.c +++ b/source/cl_input.c @@ -1,7 +1,7 @@ /* cl_input.c - builds an intended movement command to send to the server + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,28 +25,16 @@ $Id$ */ +// cl.input.c -- builds an intended movement command to send to the server #ifdef HAVE_CONFIG_H # include #endif -#include "in_win.h" -#include "sys.h" -#include "sys.h" -#include "cvar.h" -#include "sizebuf.h" -#include "msg.h" -#include "client.h" -#include "commdef.h" -#include "cmd.h" -#include "console.h" -#include "qendian.h" -#include "quakefs.h" #include "quakedef.h" -#include "pmove.h" -#include "view.h" -#include "checksum.h" -#include "keys.h" +#include "in_win.h" +/* cvar_t cl_nodelta = {"cl_nodelta","0"}; + CVAR_FIXME */ cvar_t *cl_nodelta; /* @@ -144,7 +132,9 @@ void IN_KLookUp (void) {KeyUp(&in_klook);} void IN_MLookDown (void) {KeyDown(&in_mlook);} void IN_MLookUp (void) { KeyUp(&in_mlook); -if ( !(in_mlook.state&1 || cl_freelook->value) && lookspring->value) +/* if ( !(in_mlook.state&1) && lookspring.value) + CVAR_FIXME */ +if ( !(in_mlook.state&1) && lookspring->value) V_StartPitchDrift(); } void IN_UpDown(void) {KeyDown(&in_up);} @@ -238,16 +228,32 @@ float CL_KeyState (kbutton_t *key) //========================================================================== +/* cvar_t cl_upspeed = {"cl_upspeed","200"}; + CVAR_FIXME */ cvar_t *cl_upspeed; +/* cvar_t cl_forwardspeed = {"cl_forwardspeed","200", true}; + CVAR_FIXME */ cvar_t *cl_forwardspeed; +/* cvar_t cl_backspeed = {"cl_backspeed","200", true}; + CVAR_FIXME */ cvar_t *cl_backspeed; +/* cvar_t cl_sidespeed = {"cl_sidespeed","350"}; + CVAR_FIXME */ cvar_t *cl_sidespeed; +/* cvar_t cl_movespeedkey = {"cl_movespeedkey","2.0"}; + CVAR_FIXME */ cvar_t *cl_movespeedkey; +/* cvar_t cl_yawspeed = {"cl_yawspeed","140"}; + CVAR_FIXME */ cvar_t *cl_yawspeed; +/* cvar_t cl_pitchspeed = {"cl_pitchspeed","150"}; + CVAR_FIXME */ cvar_t *cl_pitchspeed; +/* cvar_t cl_anglespeedkey = {"cl_anglespeedkey","1.5"}; + CVAR_FIXME */ cvar_t *cl_anglespeedkey; @@ -264,27 +270,41 @@ void CL_AdjustAngles (void) float up, down; if (in_speed.state & 1) +/* speed = host_frametime * cl_anglespeedkey.value; + CVAR_FIXME */ speed = host_frametime * cl_anglespeedkey->value; else speed = host_frametime; if (!(in_strafe.state & 1)) { +/* cl.viewangles[YAW] -= speed*cl_yawspeed.value*CL_KeyState (&in_right); + CVAR_FIXME */ cl.viewangles[YAW] -= speed*cl_yawspeed->value*CL_KeyState (&in_right); +/* cl.viewangles[YAW] += speed*cl_yawspeed.value*CL_KeyState (&in_left); + CVAR_FIXME */ cl.viewangles[YAW] += speed*cl_yawspeed->value*CL_KeyState (&in_left); cl.viewangles[YAW] = anglemod(cl.viewangles[YAW]); } if (in_klook.state & 1) { V_StopPitchDrift (); +/* cl.viewangles[PITCH] -= speed*cl_pitchspeed.value * CL_KeyState (&in_forward); + CVAR_FIXME */ cl.viewangles[PITCH] -= speed*cl_pitchspeed->value * CL_KeyState (&in_forward); +/* cl.viewangles[PITCH] += speed*cl_pitchspeed.value * CL_KeyState (&in_back); + CVAR_FIXME */ cl.viewangles[PITCH] += speed*cl_pitchspeed->value * CL_KeyState (&in_back); } up = CL_KeyState (&in_lookup); down = CL_KeyState(&in_lookdown); +/* cl.viewangles[PITCH] -= speed*cl_pitchspeed.value * up; + CVAR_FIXME */ cl.viewangles[PITCH] -= speed*cl_pitchspeed->value * up; +/* cl.viewangles[PITCH] += speed*cl_pitchspeed.value * down; + CVAR_FIXME */ cl.viewangles[PITCH] += speed*cl_pitchspeed->value * down; if (up || down) @@ -318,19 +338,35 @@ void CL_BaseMove (usercmd_t *cmd) VectorCopy (cl.viewangles, cmd->angles); if (in_strafe.state & 1) { +/* cmd->sidemove += cl_sidespeed.value * CL_KeyState (&in_right); + CVAR_FIXME */ cmd->sidemove += cl_sidespeed->value * CL_KeyState (&in_right); +/* cmd->sidemove -= cl_sidespeed.value * CL_KeyState (&in_left); + CVAR_FIXME */ cmd->sidemove -= cl_sidespeed->value * CL_KeyState (&in_left); } +/* cmd->sidemove += cl_sidespeed.value * CL_KeyState (&in_moveright); + CVAR_FIXME */ cmd->sidemove += cl_sidespeed->value * CL_KeyState (&in_moveright); +/* cmd->sidemove -= cl_sidespeed.value * CL_KeyState (&in_moveleft); + CVAR_FIXME */ cmd->sidemove -= cl_sidespeed->value * CL_KeyState (&in_moveleft); +/* cmd->upmove += cl_upspeed.value * CL_KeyState (&in_up); + CVAR_FIXME */ cmd->upmove += cl_upspeed->value * CL_KeyState (&in_up); +/* cmd->upmove -= cl_upspeed.value * CL_KeyState (&in_down); + CVAR_FIXME */ cmd->upmove -= cl_upspeed->value * CL_KeyState (&in_down); if (! (in_klook.state & 1) ) { +/* cmd->forwardmove += cl_forwardspeed.value * CL_KeyState (&in_forward); + CVAR_FIXME */ cmd->forwardmove += cl_forwardspeed->value * CL_KeyState (&in_forward); +/* cmd->forwardmove -= cl_backspeed.value * CL_KeyState (&in_back); + CVAR_FIXME */ cmd->forwardmove -= cl_backspeed->value * CL_KeyState (&in_back); } @@ -339,8 +375,14 @@ void CL_BaseMove (usercmd_t *cmd) // if (in_speed.state & 1) { +/* cmd->forwardmove *= cl_movespeedkey.value; + CVAR_FIXME */ cmd->forwardmove *= cl_movespeedkey->value; +/* cmd->sidemove *= cl_movespeedkey.value; + CVAR_FIXME */ cmd->sidemove *= cl_movespeedkey->value; +/* cmd->upmove *= cl_movespeedkey.value; + CVAR_FIXME */ cmd->upmove *= cl_movespeedkey->value; } } @@ -485,6 +527,8 @@ void CL_SendCmd (void) if (cls.netchan.outgoing_sequence - cl.validsequence >= UPDATE_BACKUP-1) cl.validsequence = 0; +/* if (cl.validsequence && !cl_nodelta.value && cls.state == ca_active && + CVAR_FIXME */ if (cl.validsequence && !cl_nodelta->value && cls.state == ca_active && !cls.demorecording) { @@ -549,26 +593,17 @@ void CL_InitInput (void) Cmd_AddCommand ("+mlook", IN_MLookDown); Cmd_AddCommand ("-mlook", IN_MLookUp); +/* Cvar_RegisterVariable (&cl_nodelta); + CVAR_FIXME */ cl_nodelta = Cvar_Get("cl_nodelta", "0", CVAR_NONE, "None"); } - -extern qboolean keydown[256]; - /* ============ CL_ClearStates ============ -Generate key up event for each key that is down */ void CL_ClearStates (void) { - int i; - -// send an up event for each key, to make sure the server clears them all - for (i=0 ; i<256 ; i++) - { - if (keydown[i]) - Key_Event (i, false); - } } + diff --git a/source/cl_model.c b/source/cl_model.c index cc7df45..c659836 100644 --- a/source/cl_model.c +++ b/source/cl_model.c @@ -1,7 +1,7 @@ /* - cl_model.c + model.c - model loading and caching + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,6 +25,7 @@ $Id$ */ +// models.c -- model loading and caching // models are the only shared resource between a client and server running // on the same machine. @@ -32,11 +33,7 @@ #ifdef HAVE_CONFIG_H # include #endif -#include "model.h" -#include "crc.h" -#include "msg.h" -#include "console.h" -#include "qendian.h" +#include "quakedef.h" #include "r_local.h" void SV_Error (char *error, ...); diff --git a/source/cl_parse.c b/source/cl_parse.c index cb7ee12..cd6302f 100644 --- a/source/cl_parse.c +++ b/source/cl_parse.c @@ -1,7 +1,7 @@ /* cl_parse.c - parse a message received from the server + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,24 +25,17 @@ $Id$ */ +// cl_parse.c -- parse a message received from the server #ifdef HAVE_CONFIG_H # include #endif #include "sys.h" -#include "client.h" -#include "cmd.h" -#include "screen.h" -#include "cdaudio.h" #include "quakedef.h" -#include "bothdefs.h" -#include "console.h" -#include "msg.h" -#include "pmove.h" -#include "sbar.h" +/* extern cvar_t gl_flashblend; + CVAR_FIXME */ extern cvar_t *gl_flashblend; -extern cvar_t *cl_autoexec; char *svc_strings[] = { @@ -389,7 +382,7 @@ void CL_ParseDownload (void) if (strncmp(cls.downloadtempname,"skins/",6)) snprintf (name, sizeof(name), "%s/%s", com_gamedir, cls.downloadtempname); else - snprintf (name, sizeof(name), "%s/qw/%s", fs_userpath->string, cls.downloadtempname); + snprintf (name, sizeof(name), "qw/%s", cls.downloadtempname); COM_CreatePath (name); @@ -440,8 +433,8 @@ void CL_ParseDownload (void) snprintf (oldn, sizeof(oldn), "%s/%s", com_gamedir, cls.downloadtempname); snprintf (newn, sizeof(newn), "%s/%s", com_gamedir, cls.downloadname); } else { - snprintf (oldn, sizeof(oldn), "%s/qw/%s", fs_userpath->string, cls.downloadtempname); - snprintf (newn, sizeof(newn), "%s/qw/%s", fs_userpath->string, cls.downloadname); + snprintf (oldn, sizeof(oldn), "qw/%s", cls.downloadtempname); + snprintf (newn, sizeof(newn), "qw/%s", cls.downloadname); } r = rename (oldn, newn); if (r) @@ -582,29 +575,15 @@ void CL_ParseServerData (void) //ZOID--run the autoexec.cfg in the gamedir //if it exists if (cflag) { - int cl_warncmd_val = cl_warncmd->value; - snprintf(fn, sizeof(fn), "%s/%s", com_gamedir, "config.cfg"); + snprintf (fn, sizeof(fn), "%s/%s", com_gamedir, "config.cfg"); if ((f = fopen(fn, "r")) != NULL) { fclose(f); Cbuf_AddText ("cl_warncmd 0\n"); - Cbuf_AddText ("exec config.cfg\n"); + Cbuf_AddText("exec config.cfg\n"); + Cbuf_AddText("exec frontend.cfg\n"); + Cbuf_AddText("exec autoexec.cfg\n"); + Cbuf_AddText ("cl_warncmd 1\n"); } - snprintf(fn, sizeof(fn), "%s/%s", com_gamedir, "frontend.cfg"); - if ((f = fopen(fn, "r")) != NULL) { - fclose(f); - Cbuf_AddText ("cl_warncmd 0\n"); - Cbuf_AddText ("exec frontend.cfg\n"); - } - if (cl_autoexec->value) { - snprintf(fn, sizeof(fn), "%s/%s", com_gamedir, "autoexec.cfg"); - if ((f = fopen(fn, "r")) != NULL) { - fclose(f); - Cbuf_AddText ("cl_warncmd 0\n"); - Cbuf_AddText ("exec autoexec.cfg\n"); - } - } - snprintf(fn,sizeof(fn), "cl_warncmd %d\n", cl_warncmd_val); - Cbuf_AddText(fn); } // parse player slot, high bit means spectator @@ -1035,6 +1014,8 @@ void CL_MuzzleFlash (void) return; // don't draw our own muzzle flash in gl if flashblending +/* if (i-1 == cl.playernum && gl_flashblend.value) + CVAR_FIXME */ if (i-1 == cl.playernum && gl_flashblend->value) return; @@ -1055,6 +1036,8 @@ void CL_MuzzleFlash (void) } +/* #define SHOWNET(x) if(cl_shownet.value==2)Con_Printf ("%3i:%s\n", msg_readcount-1, x); + CVAR_FIXME */ #define SHOWNET(x) if(cl_shownet->value==2)Con_Printf ("%3i:%s\n", msg_readcount-1, x); /* ===================== @@ -1075,8 +1058,12 @@ void CL_ParseServerMessage (void) // // if recording demos, copy the message out // +/* if (cl_shownet.value == 1) + CVAR_FIXME */ if (cl_shownet->value == 1) Con_Printf ("%i ",net_message.cursize); +/* else if (cl_shownet.value == 2) + CVAR_FIXME */ else if (cl_shownet->value == 2) Con_Printf ("------------------\n"); diff --git a/source/cl_sys_unix.c b/source/cl_sys_unix.c index 8ee79bb..3d920db 100644 --- a/source/cl_sys_unix.c +++ b/source/cl_sys_unix.c @@ -45,7 +45,6 @@ #include #include "sys.h" -#include "qargs.h" #include "quakedef.h" int noconinput = 0; @@ -53,6 +52,8 @@ qboolean is_server = false; #define BASEDIR "." +/* cvar_t sys_linerefresh = {"sys_linerefresh","0"};// set for entity display + CVAR_FIXME */ cvar_t *sys_linerefresh;// set for entity display @@ -235,7 +236,7 @@ int main (int c, char **v) parms.memsize = (int) (atof(com_argv[j+1]) * 1024 * 1024); parms.membase = malloc (parms.memsize); if (!parms.membase) { - printf("Can't allocate memory for zone.\n"); + printf("Can't allocate memroy for zone.\n"); return 1; } diff --git a/source/cl_sys_win.c b/source/cl_sys_win.c index 5dde053..a02667f 100644 --- a/source/cl_sys_win.c +++ b/source/cl_sys_win.c @@ -1,5 +1,5 @@ /* - sys_win.c + sys_win.c.client (description) @@ -26,25 +26,40 @@ $Id$ */ +/* +Copyright (C) 1996-1997 Id Software, Inc. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ +// sys_win.h + #ifdef HAVE_CONFIG_H # include #endif -#include +#include "quakedef.h" +#include "winquake.h" +#include "resource.h" +#include "sys.h" #include #include #include #include #include -#include "quakedef.h" -#include "winquake.h" -#include "resource.h" -#include "sys.h" -#include "screen.h" -#include "qargs.h" -#include "client.h" -#include "console.h" - qboolean is_server = false; #define MINIMUM_WIN_MEMORY 0x0c00000 @@ -365,7 +380,7 @@ void Sys_Sleep (void) } -void IN_SendKeyEvents (void) +void Sys_SendKeyEvents (void) { MSG msg; @@ -466,7 +481,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin *lpCmdLine = 0; lpCmdLine++; } - + } } diff --git a/source/cmd.c b/source/cmd.c index 95decd6..0e93d28 100644 --- a/source/cmd.c +++ b/source/cmd.c @@ -1,7 +1,7 @@ /* cmd.c - script command processing module + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,22 +25,13 @@ $Id$ */ +// cmd.c -- Quake script command processing module #ifdef HAVE_CONFIG_H # include #endif #include "sys.h" -#include "cmd.h" -#include "cvar.h" -#include "sizebuf.h" -#include "zone.h" -#include "console.h" -#include "qargs.h" -#include "quakefs.h" -#include "commdef.h" - -#include -#include +#include "quakedef.h" void Cmd_ForwardToServer (void); @@ -57,7 +48,10 @@ cmdalias_t *cmd_alias; qboolean cmd_wait; -cvar_t *cl_warncmd; +/* cvar_t cl_warncmd = {"cl_warncmd", "0"}; + CVAR_FIXME */ +cvar_t *cl_warncmd; + //============================================================================= /* @@ -106,7 +100,7 @@ Adds command text at the end of the buffer void Cbuf_AddText (char *text) { int l; - + l = strlen (text); if (cmd_text.cursize + l >= cmd_text.maxsize) @@ -142,7 +136,7 @@ void Cbuf_InsertText (char *text) } else temp = NULL; // shut up compiler - + // add the entire text of the file Cbuf_AddText (text); SZ_Write (&cmd_text, "\n", 1); @@ -154,56 +148,54 @@ void Cbuf_InsertText (char *text) } } -static void -extract_line(char *line) +/* +============ +Cbuf_Execute +============ +*/ +void Cbuf_Execute (void) { int i; char *text; - int quotes; + char line[1024]; + int quotes; + + while (cmd_text.cursize) + { +// find a \n or ; line break + text = (char *)cmd_text.data; - // find a \n or ; line break - text = (char *)cmd_text.data; - quotes = 0; - for (i=0 ; i< cmd_text.cursize ; i++) { - if (text[i] == '"') - quotes++; - if ( !(quotes&1) && text[i] == ';') - break; // don't break if inside a quoted string - if (text[i] == '\n' || text[i] == '\r') - break; - } + quotes = 0; + for (i=0 ; i< cmd_text.cursize ; i++) + { + if (text[i] == '"') + quotes++; + if ( !(quotes&1) && text[i] == ';') + break; // don't break if inside a quoted string + if (text[i] == '\n') + break; + } + + + memcpy (line, text, i); + line[i] = 0; + +// delete the text from the command buffer and move remaining commands down +// this is necessary because commands (exec, alias) can insert data at the +// beginning of the text buffer - memcpy (line, text, i); - line[i] = '\0'; - // delete the text from the command buffer and move remaining commands down - // this is necessary because commands (exec, alias) can insert data at the - // beginning of the text buffer + if (i == cmd_text.cursize) + cmd_text.cursize = 0; + else + { + i++; + cmd_text.cursize -= i; + memcpy (text, text+i, cmd_text.cursize); + } - if (i == cmd_text.cursize) - cmd_text.cursize = 0; - else { - i++; - cmd_text.cursize -= i; - memcpy (text, text+i, cmd_text.cursize); - } -} - -/* - - Cbuf_Execute - -*/ -void -Cbuf_Execute (void) -{ - char line[1024] = {0}; - - while (cmd_text.cursize) { - extract_line (line); - // execute the command line - //Con_DPrintf("+%s\n",line), +// execute the command line Cmd_ExecuteString (line); - + if (cmd_wait) { // skip out while text still remains in buffer, leaving it // for next frame @@ -212,25 +204,6 @@ Cbuf_Execute (void) } } } -/* - - Cbuf_Execute - -*/ -void -Cbuf_Execute_Sets (void) -{ - char line[1024] = {0}; - - while (cmd_text.cursize) { - extract_line (line); - // execute the command line - if (strncmp(line,"set",3)==0 - && isspace((int) line[3])) - //Con_DPrintf("+%s\n",line), - Cmd_ExecuteString (line); - } -} /* ============================================================================== @@ -254,74 +227,60 @@ void Cmd_StuffCmds_f (void) { int i, j; int s; - char *build, c; - - s = strlen (com_cmdline); + char *text, *build, c; + +// build the combined string to parse from + s = 0; + for (i=1 ; ivalue || developer->value)) Con_Printf ("execing %s\n",Cmd_Argv(1)); - + Cbuf_InsertText (f); Hunk_FreeToLowMark (mark); } @@ -365,7 +326,7 @@ Just prints the rest of the line to the console void Cmd_Echo_f (void) { int i; - + for (i=1 ; inext = cmd_alias; cmd_alias = a; } - strcpy (a->name, s); + strcpy (a->name, s); // copy the rest of the command line cmd[0] = 0; // start out with a null string @@ -438,45 +399,10 @@ void Cmd_Alias_f (void) strcat (cmd, " "); } strcat (cmd, "\n"); - + a->value = CopyString (cmd); } -void Cmd_UnAlias_f (void) -{ - cmdalias_t *a, *prev; - char *s; - - if (Cmd_Argc() != 2) - { - Con_Printf ("unalias : erase an existing alias\n"); - return; - } - - s = Cmd_Argv(1); - if (strlen(s) >= MAX_ALIAS_NAME) - { - Con_Printf ("Alias name is too long\n"); - return; - } - - prev = cmd_alias; - for (a = cmd_alias ; a ; a = a->next) - { - if (!strcmp(s, a->name)) - { - Z_Free (a->value); - prev->next = a->next; - if (a == cmd_alias) - cmd_alias = a->next; - Z_Free (a); - return; - } - prev = a; - } - Con_Printf ("Unknown alias \"%s\"\n", s); -} - /* ============================================================================= @@ -523,7 +449,7 @@ char *Cmd_Argv (int arg) { if ( arg >= cmd_argc ) return cmd_null_string; - return cmd_argv[arg]; + return cmd_argv[arg]; } /* @@ -551,14 +477,14 @@ Parses the given string into command line tokens. void Cmd_TokenizeString (char *text) { int i; - + // clear the args from the last string for (i=0 ; inext) { @@ -660,12 +586,12 @@ char *Cmd_CompleteCommand (char *partial) cmd_function_t *cmd; int len; cmdalias_t *a; - + len = strlen(partial); - + if (!len) return NULL; - + // check for exact match for (cmd=cmd_functions ; cmd ; cmd=cmd->next) if (!strcmp (partial,cmd->name)) @@ -693,13 +619,13 @@ A complete command line has been parsed, so try to execute it FIXME: lookupnoadd the token to speed search? ============ */ -void Cmd_ExecuteString (char *text) -{ +void Cmd_ExecuteString (char *text) +{ cmd_function_t *cmd; cmdalias_t *a; Cmd_TokenizeString (text); - + // execute the command line if (!Cmd_Argc()) return; // no tokens @@ -717,10 +643,6 @@ void Cmd_ExecuteString (char *text) } } -// Tonik: check cvars - if (Cvar_Command()) - return; - // check alias for (a=cmd_alias ; a ; a=a->next) { @@ -731,9 +653,12 @@ void Cmd_ExecuteString (char *text) } } - if (cl_warncmd->value || developer->value) +// check cvars +/* if (!Cvar_Command () && (cl_warncmd.value || developer.value)) + CVAR_FIXME */ + if (!Cvar_Command () && (cl_warncmd->value || developer->value)) Con_Printf ("Unknown command \"%s\"\n", Cmd_Argv(0)); - + } @@ -749,14 +674,14 @@ where the given parameter apears, or 0 if not present int Cmd_CheckParm (char *parm) { int i; - + if (!parm) Sys_Error ("Cmd_CheckParm: NULL"); for (i = 1; i < Cmd_Argc (); i++) if (! strcasecmp (parm, Cmd_Argv (i))) return i; - + return 0; } @@ -787,76 +712,7 @@ void Cmd_Init (void) Cmd_AddCommand ("exec",Cmd_Exec_f); Cmd_AddCommand ("echo",Cmd_Echo_f); Cmd_AddCommand ("alias",Cmd_Alias_f); - Cmd_AddCommand ("unalias",Cmd_UnAlias_f); Cmd_AddCommand ("wait", Cmd_Wait_f); Cmd_AddCommand ("cmdlist", Cmd_CmdList_f); } - -char com_token[1024]; - -/* -============== -COM_Parse - -Parse a token out of a string -============== -*/ -char *COM_Parse (char *data) -{ - int c; - int len; - - len = 0; - com_token[0] = 0; - - if (!data) - return NULL; - -// skip whitespace -skipwhite: - while ( (c = *data) <= ' ') - { - if (c == 0) - return NULL; // end of file; - data++; - } - -// skip // comments - if (c=='/' && data[1] == '/') - { - while (*data && *data != '\n') - data++; - goto skipwhite; - } - - -// handle quoted strings specially - if (c == '\"') - { - data++; - while (1) - { - c = *data++; - if (c=='\"' || !c) - { - com_token[len] = 0; - return data; - } - com_token[len] = c; - len++; - } - } - -// parse a regular word - do - { - com_token[len] = c; - data++; - len++; - c = *data; - } while (c>32); - - com_token[len] = 0; - return data; -} diff --git a/source/common.c b/source/common.c new file mode 100644 index 0000000..62aed52 --- /dev/null +++ b/source/common.c @@ -0,0 +1,1958 @@ +/* + common.c + + (description) + + Copyright (C) 1996-1997 Id Software, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + + $Id$ +*/ +// common.c -- misc functions used in client and server + +#ifdef HAVE_CONFIG_H +# include +#endif +#include + +#include "sys.h" +#include "quakedef.h" + +#define MAX_NUM_ARGVS 50 +#define NUM_SAFE_ARGVS 6 + +usercmd_t nullcmd; // guarenteed to be zero + +static char *largv[MAX_NUM_ARGVS + NUM_SAFE_ARGVS + 1]; +static char *argvdummy = " "; + +static char *safeargvs[NUM_SAFE_ARGVS] = + {"-stdvid", "-nolan", "-nosound", "-nocdaudio", "-nojoy", "-nomouse"}; + +/* cvar_t registered = {"registered","0"}; + CVAR_FIXME */ +cvar_t *registered; + +qboolean com_modified; // set true if using non-id files + +int static_registered = 1; // only for startup check, then set + +qboolean msg_suppress_1 = 0; + +void COM_InitFilesystem (void); +void COM_Path_f (void); + + +// if a packfile directory differs from this, it is assumed to be hacked +#define PAK0_COUNT 339 +#define PAK0_CRC 52883 + +qboolean standard_quake = true, rogue, hipnotic; + +char gamedirfile[MAX_OSPATH]; + +/* + + +All of Quake's data access is through a hierchal file system, but the contents of the file system can be transparently merged from several sources. + +The "base directory" is the path to the directory holding the quake.exe and all game directories. The sys_* files pass this to host_init in quakeparms_t->basedir. This can be overridden with the "-basedir" command line parm to allow code debugging in a different directory. The base directory is +only used during filesystem initialization. + +The "game directory" is the first tree on the search path and directory that all generated files (savegames, screenshots, demos, config files) will be saved to. This can be overridden with the "-game" command line parameter. The game directory can never be changed while quake is executing. This is a precacution against having a malicious server instruct clients to write files over areas they shouldn't. + +The "cache directory" is only used during development to save network bandwidth, especially over ISDN / T1 lines. If there is a cache directory +specified, when a file is found by the normal search path, it will be mirrored +into the cache directory, then opened there. + +*/ + +//============================================================================ + + +// ClearLink is used for new headnodes +void ClearLink (link_t *l) +{ + l->prev = l->next = l; +} + +void RemoveLink (link_t *l) +{ + l->next->prev = l->prev; + l->prev->next = l->next; +} + +void InsertLinkBefore (link_t *l, link_t *before) +{ + l->next = before; + l->prev = before->prev; + l->prev->next = l; + l->next->prev = l; +} +void InsertLinkAfter (link_t *l, link_t *after) +{ + l->next = after->next; + l->prev = after; + l->prev->next = l; + l->next->prev = l; +} + +/* +============================================================================ + + BYTE ORDER FUNCTIONS + +============================================================================ +*/ + +qboolean bigendien; + +short (*BigShort) (short l); +short (*LittleShort) (short l); +int (*BigLong) (int l); +int (*LittleLong) (int l); +float (*BigFloat) (float l); +float (*LittleFloat) (float l); + +short ShortSwap (short l) +{ + byte b1,b2; + + b1 = l&255; + b2 = (l>>8)&255; + + return (b1<<8) + b2; +} + +short ShortNoSwap (short l) +{ + return l; +} + +int LongSwap (int l) +{ + byte b1,b2,b3,b4; + + b1 = l&255; + b2 = (l>>8)&255; + b3 = (l>>16)&255; + b4 = (l>>24)&255; + + return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4; +} + +int LongNoSwap (int l) +{ + return l; +} + +float FloatSwap (float f) +{ + union + { + float f; + byte b[4]; + } dat1, dat2; + + + dat1.f = f; + dat2.b[0] = dat1.b[3]; + dat2.b[1] = dat1.b[2]; + dat2.b[2] = dat1.b[1]; + dat2.b[3] = dat1.b[0]; + return dat2.f; +} + +float FloatNoSwap (float f) +{ + return f; +} + +/* +============================================================================== + + MESSAGE IO FUNCTIONS + +Handles byte ordering and avoids alignment errors +============================================================================== +*/ + +// +// writing functions +// + +void MSG_WriteChar (sizebuf_t *sb, int c) +{ + byte *buf; + +#ifdef PARANOID + if (c < -128 || c > 127) + Sys_Error ("MSG_WriteChar: range error"); +#endif + + buf = SZ_GetSpace (sb, 1); + buf[0] = c; +} + +void MSG_WriteByte (sizebuf_t *sb, int c) +{ + byte *buf; + +#ifdef PARANOID + if (c < 0 || c > 255) + Sys_Error ("MSG_WriteByte: range error"); +#endif + + buf = SZ_GetSpace (sb, 1); + buf[0] = c; +} + +void MSG_WriteShort (sizebuf_t *sb, int c) +{ + byte *buf; + +#ifdef PARANOID + if (c < ((short)0x8000) || c > (short)0x7fff) + Sys_Error ("MSG_WriteShort: range error"); +#endif + + buf = SZ_GetSpace (sb, 2); + buf[0] = c&0xff; + buf[1] = c>>8; +} + +void MSG_WriteLong (sizebuf_t *sb, int c) +{ + byte *buf; + + buf = SZ_GetSpace (sb, 4); + buf[0] = c&0xff; + buf[1] = (c>>8)&0xff; + buf[2] = (c>>16)&0xff; + buf[3] = c>>24; +} + +void MSG_WriteFloat (sizebuf_t *sb, float f) +{ + union + { + float f; + int l; + } dat; + + + dat.f = f; + dat.l = LittleLong (dat.l); + + SZ_Write (sb, &dat.l, 4); +} + +void MSG_WriteString (sizebuf_t *sb, char *s) +{ + if (!s) + SZ_Write (sb, "", 1); + else + SZ_Write (sb, s, strlen(s)+1); +} + +void MSG_WriteCoord (sizebuf_t *sb, float f) +{ + MSG_WriteShort (sb, (int)(f*8)); +} + +void MSG_WriteAngle (sizebuf_t *sb, float f) +{ + MSG_WriteByte (sb, (int)(f*256/360) & 255); +} + +void MSG_WriteAngle16 (sizebuf_t *sb, float f) +{ + MSG_WriteShort (sb, (int)(f*65536/360) & 65535); +} + +void MSG_WriteDeltaUsercmd (sizebuf_t *buf, usercmd_t *from, usercmd_t *cmd) +{ + int bits; + +// +// send the movement message +// + bits = 0; + if (cmd->angles[0] != from->angles[0]) + bits |= CM_ANGLE1; + if (cmd->angles[1] != from->angles[1]) + bits |= CM_ANGLE2; + if (cmd->angles[2] != from->angles[2]) + bits |= CM_ANGLE3; + if (cmd->forwardmove != from->forwardmove) + bits |= CM_FORWARD; + if (cmd->sidemove != from->sidemove) + bits |= CM_SIDE; + if (cmd->upmove != from->upmove) + bits |= CM_UP; + if (cmd->buttons != from->buttons) + bits |= CM_BUTTONS; + if (cmd->impulse != from->impulse) + bits |= CM_IMPULSE; + + MSG_WriteByte (buf, bits); + + if (bits & CM_ANGLE1) + MSG_WriteAngle16 (buf, cmd->angles[0]); + if (bits & CM_ANGLE2) + MSG_WriteAngle16 (buf, cmd->angles[1]); + if (bits & CM_ANGLE3) + MSG_WriteAngle16 (buf, cmd->angles[2]); + + if (bits & CM_FORWARD) + MSG_WriteShort (buf, cmd->forwardmove); + if (bits & CM_SIDE) + MSG_WriteShort (buf, cmd->sidemove); + if (bits & CM_UP) + MSG_WriteShort (buf, cmd->upmove); + + if (bits & CM_BUTTONS) + MSG_WriteByte (buf, cmd->buttons); + if (bits & CM_IMPULSE) + MSG_WriteByte (buf, cmd->impulse); + MSG_WriteByte (buf, cmd->msec); +} + + +// +// reading functions +// +int msg_readcount; +qboolean msg_badread; + +void MSG_BeginReading (void) +{ + msg_readcount = 0; + msg_badread = false; +} + +int MSG_GetReadCount(void) +{ + return msg_readcount; +} + +// returns -1 and sets msg_badread if no more characters are available +int MSG_ReadChar (void) +{ + int c; + + if (msg_readcount+1 > net_message.cursize) + { + msg_badread = true; + return -1; + } + + c = (signed char)net_message.data[msg_readcount]; + msg_readcount++; + + return c; +} + +int MSG_ReadByte (void) +{ + int c; + + if (msg_readcount+1 > net_message.cursize) + { + msg_badread = true; + return -1; + } + + c = (unsigned char)net_message.data[msg_readcount]; + msg_readcount++; + + return c; +} + +int MSG_ReadShort (void) +{ + int c; + + if (msg_readcount+2 > net_message.cursize) + { + msg_badread = true; + return -1; + } + + c = (short)(net_message.data[msg_readcount] + + (net_message.data[msg_readcount+1]<<8)); + + msg_readcount += 2; + + return c; +} + +int MSG_ReadLong (void) +{ + int c; + + if (msg_readcount+4 > net_message.cursize) + { + msg_badread = true; + return -1; + } + + c = net_message.data[msg_readcount] + + (net_message.data[msg_readcount+1]<<8) + + (net_message.data[msg_readcount+2]<<16) + + (net_message.data[msg_readcount+3]<<24); + + msg_readcount += 4; + + return c; +} + +float MSG_ReadFloat (void) +{ + union + { + byte b[4]; + float f; + int l; + } dat; + + dat.b[0] = net_message.data[msg_readcount]; + dat.b[1] = net_message.data[msg_readcount+1]; + dat.b[2] = net_message.data[msg_readcount+2]; + dat.b[3] = net_message.data[msg_readcount+3]; + msg_readcount += 4; + + dat.l = LittleLong (dat.l); + + return dat.f; +} + +char *MSG_ReadString (void) +{ + static char string[2048]; + int l,c; + + l = 0; + do + { + c = MSG_ReadChar (); + if (c == -1 || c == 0) + break; + string[l] = c; + l++; + } while (l < sizeof(string)-1); + + string[l] = 0; + + return string; +} + +char *MSG_ReadStringLine (void) +{ + static char string[2048]; + int l,c; + + l = 0; + do + { + c = MSG_ReadChar (); + if (c == -1 || c == 0 || c == '\n') + break; + string[l] = c; + l++; + } while (l < sizeof(string)-1); + + string[l] = 0; + + return string; +} + +float MSG_ReadCoord (void) +{ + return MSG_ReadShort() * (1.0/8); +} + +float MSG_ReadAngle (void) +{ + return MSG_ReadChar() * (360.0/256); +} + +float MSG_ReadAngle16 (void) +{ + return MSG_ReadShort() * (360.0/65536); +} + +void MSG_ReadDeltaUsercmd (usercmd_t *from, usercmd_t *move) +{ + int bits; + + memcpy (move, from, sizeof(*move)); + + bits = MSG_ReadByte (); + +// read current angles + if (bits & CM_ANGLE1) + move->angles[0] = MSG_ReadAngle16 (); + if (bits & CM_ANGLE2) + move->angles[1] = MSG_ReadAngle16 (); + if (bits & CM_ANGLE3) + move->angles[2] = MSG_ReadAngle16 (); + +// read movement + if (bits & CM_FORWARD) + move->forwardmove = MSG_ReadShort (); + if (bits & CM_SIDE) + move->sidemove = MSG_ReadShort (); + if (bits & CM_UP) + move->upmove = MSG_ReadShort (); + +// read buttons + if (bits & CM_BUTTONS) + move->buttons = MSG_ReadByte (); + + if (bits & CM_IMPULSE) + move->impulse = MSG_ReadByte (); + +// read time to run command + move->msec = MSG_ReadByte (); +} + + +//=========================================================================== + +void SZ_Clear (sizebuf_t *buf) +{ + buf->cursize = 0; + buf->overflowed = false; +} + +void *SZ_GetSpace (sizebuf_t *buf, int length) +{ + void *data; + + if (buf->cursize + length > buf->maxsize) + { + if (!buf->allowoverflow) + Sys_Error ("SZ_GetSpace: overflow without allowoverflow set (%d)", buf->maxsize); + + if (length > buf->maxsize) + Sys_Error ("SZ_GetSpace: %i is > full buffer size", length); + + Sys_Printf ("SZ_GetSpace: overflow\n"); // because Con_Printf may be redirected + SZ_Clear (buf); + buf->overflowed = true; + } + + data = buf->data + buf->cursize; + buf->cursize += length; + + return data; +} + +void SZ_Write (sizebuf_t *buf, void *data, int length) +{ + memcpy (SZ_GetSpace(buf,length),data,length); +} + +void SZ_Print (sizebuf_t *buf, char *data) +{ + int len; + + len = strlen(data)+1; + + if (!buf->cursize || buf->data[buf->cursize-1]) + memcpy ((byte *)SZ_GetSpace(buf, len),data,len); // no trailing 0 + else + memcpy ((byte *)SZ_GetSpace(buf, len-1)-1,data,len); // write over trailing 0 +} + + +//============================================================================ + + +/* +============ +COM_SkipPath +============ +*/ +char *COM_SkipPath (char *pathname) +{ + char *last; + + last = pathname; + while (*pathname) + { + if (*pathname=='/') + last = pathname+1; + pathname++; + } + return last; +} + +/* +============ +COM_StripExtension +============ +*/ +void COM_StripExtension (char *in, char *out) +{ + while (*in && *in != '.') + *out++ = *in++; + *out = 0; +} + +/* +============ +COM_FileExtension +============ +*/ +char *COM_FileExtension (char *in) +{ + static char exten[8]; + int i; + + while (*in && *in != '.') + in++; + if (!*in) + return ""; + in++; + for (i=0 ; i<7 && *in ; i++,in++) + exten[i] = *in; + exten[i] = 0; + return exten; +} + +/* +============ +COM_FileBase +============ +*/ +void COM_FileBase (char *in, char *out) +{ + char *s, *s2; + + s = in + strlen(in) - 1; + + while (s != in && *s != '.') + s--; + + for (s2 = s ; *s2 && *s2 != '/' ; s2--) + ; + + if (s-s2 < 2) + strcpy (out,"?model?"); + else + { + s--; + strncpy (out,s2+1, s-s2); + out[s-s2] = 0; + } +} + + +/* +================== +COM_DefaultExtension +================== +*/ +void COM_DefaultExtension (char *path, char *extension) +{ + char *src; +// +// if path doesn't have a .EXT, append extension +// (extension should include the .) +// + src = path + strlen(path) - 1; + + while (*src != '/' && src != path) + { + if (*src == '.') + return; // it has an extension + src--; + } + + strcat (path, extension); +} + +//============================================================================ + +char com_token[1024]; +int com_argc; +char **com_argv; + + +/* +============== +COM_Parse + +Parse a token out of a string +============== +*/ +char *COM_Parse (char *data) +{ + int c; + int len; + + len = 0; + com_token[0] = 0; + + if (!data) + return NULL; + +// skip whitespace +skipwhite: + while ( (c = *data) <= ' ') + { + if (c == 0) + return NULL; // end of file; + data++; + } + +// skip // comments + if (c=='/' && data[1] == '/') + { + while (*data && *data != '\n') + data++; + goto skipwhite; + } + + +// handle quoted strings specially + if (c == '\"') + { + data++; + while (1) + { + c = *data++; + if (c=='\"' || !c) + { + com_token[len] = 0; + return data; + } + com_token[len] = c; + len++; + } + } + +// parse a regular word + do + { + com_token[len] = c; + data++; + len++; + c = *data; + } while (c>32); + + com_token[len] = 0; + return data; +} + + +/* +================ +COM_CheckParm + +Returns the position (1 to argc-1) in the program's argument list +where the given parameter apears, or 0 if not present +================ +*/ +int COM_CheckParm (char *parm) +{ + int i; + + for (i=1 ; inext) + { + if (s == com_base_searchpaths) + Con_Printf ("----------\n"); + if (s->pack) + Con_Printf ("%s (%i files)\n", s->pack->filename, s->pack->numfiles); + else + Con_Printf ("%s\n", s->filename); + } +} + +/* +============ +COM_WriteFile + +The filename will be prefixed by the current game directory +============ +*/ +void COM_WriteFile (char *filename, void *data, int len) +{ + FILE *f; + char name[MAX_OSPATH]; + + snprintf (name, sizeof(name), "%s/%s", com_gamedir, filename); + + f = fopen (name, "wb"); + if (!f) { + Sys_mkdir(com_gamedir); + f = fopen (name, "wb"); + if (!f) + Sys_Error ("Error opening %s", filename); + } + + Sys_Printf ("COM_WriteFile: %s\n", name); + fwrite (data, 1, len, f); + fclose (f); +} + + +/* +============ +COM_CreatePath + +Only used for CopyFile and download +============ +*/ +void COM_CreatePath (char *path) +{ + char *ofs; + + for (ofs = path+1 ; *ofs ; ofs++) + { + if (*ofs == '/') + { // create the directory + *ofs = 0; + Sys_mkdir (path); + *ofs = '/'; + } + } +} + + +/* +=========== +COM_CopyFile + +Copies a file over from the net to the local cache, creating any directories +needed. This is for the convenience of developers using ISDN from home. +=========== +*/ +void COM_CopyFile (char *netpath, char *cachepath) +{ + FILE *in, *out; + int remaining, count; + char buf[4096]; + + remaining = COM_FileOpenRead (netpath, &in); + COM_CreatePath (cachepath); // create directories up to the cache file + out = fopen(cachepath, "wb"); + if (!out) + Sys_Error ("Error opening %s", cachepath); + + while (remaining) + { + if (remaining < sizeof(buf)) + count = remaining; + else + count = sizeof(buf); + fread (buf, 1, count, in); + fwrite (buf, 1, count, out); + remaining -= count; + } + + fclose (in); + fclose (out); +} + +/* +=========== +COM_FindFile + +Finds the file in the search path. +Sets com_filesize and one of handle or file +=========== +*/ +int file_from_pak; // global indicating file came from pack file ZOID + +int COM_FOpenFile (char *filename, FILE **file) +{ + searchpath_t *search; + char netpath[MAX_OSPATH]; + pack_t *pak; + int i; + int findtime; + + file_from_pak = 0; + +// +// search through the path, one element at a time +// + for (search = com_searchpaths ; search ; search = search->next) + { + // is the element a pak file? + if (search->pack) + { + // look through all the pak file elements + pak = search->pack; + for (i=0 ; inumfiles ; i++) + if (!strcmp (pak->files[i].name, filename)) + { // found it! +/* if(developer.value) + CVAR_FIXME */ + if(developer->value) + Sys_Printf ("PackFile: %s : %s\n",pak->filename, filename); + // open a new file on the pakfile + *file = fopen (pak->filename, "rb"); + if (!*file) + Sys_Error ("Couldn't reopen %s", pak->filename); + fseek (*file, pak->files[i].filepos, SEEK_SET); + com_filesize = pak->files[i].filelen; + file_from_pak = 1; + return com_filesize; + } + } + else + { + // check a file in the directory tree + if (!static_registered) + { // if not a registered version, don't ever go beyond base + if ( strchr (filename, '/') || strchr (filename,'\\')) + continue; + } + + snprintf (netpath, sizeof(netpath), "%s/%s", search->filename, filename); + + findtime = Sys_FileTime (netpath); + if (findtime == -1) + continue; + + Con_DPrintf ("FindFile: %s\n",netpath); + + *file = fopen (netpath, "rb"); + return COM_filelength (*file); + } + + } + + Sys_Printf ("FindFile: can't find %s\n", filename); + + *file = NULL; + com_filesize = -1; + return -1; +} + +/* +============ +COM_LoadFile + +Filename are reletive to the quake directory. +Allways appends a 0 byte to the loaded data. +============ +*/ +cache_user_t *loadcache; +byte *loadbuf; +int loadsize; +byte *COM_LoadFile (char *path, int usehunk) +{ + FILE *h; + byte *buf; + char base[32]; + int len; + + buf = NULL; // quiet compiler warning + +// look for it in the filesystem or pack files + len = com_filesize = COM_FOpenFile (path, &h); + if (!h) + return NULL; + +// extract the filename base name for hunk tag + COM_FileBase (path, base); + + if (usehunk == 1) + buf = Hunk_AllocName (len+1, base); + else if (usehunk == 2) + buf = Hunk_TempAlloc (len+1); + else if (usehunk == 0) + buf = Z_Malloc (len+1); + else if (usehunk == 3) + buf = Cache_Alloc (loadcache, len+1, base); + else if (usehunk == 4) + { + if (len+1 > loadsize) + buf = Hunk_TempAlloc (len+1); + else + buf = loadbuf; + } + else + Sys_Error ("COM_LoadFile: bad usehunk"); + + if (!buf) + Sys_Error ("COM_LoadFile: not enough space for %s", path); + + ((byte *)buf)[len] = 0; + Draw_BeginDisc (); + fread (buf, 1, len, h); + fclose (h); + Draw_EndDisc (); + + return buf; +} + +byte *COM_LoadHunkFile (char *path) +{ + return COM_LoadFile (path, 1); +} + +byte *COM_LoadTempFile (char *path) +{ + return COM_LoadFile (path, 2); +} + +void COM_LoadCacheFile (char *path, struct cache_user_s *cu) +{ + loadcache = cu; + COM_LoadFile (path, 3); +} + +// uses temp hunk if larger than bufsize +byte *COM_LoadStackFile (char *path, void *buffer, int bufsize) +{ + byte *buf; + + loadbuf = (byte *)buffer; + loadsize = bufsize; + buf = COM_LoadFile (path, 4); + + return buf; +} + +/* +================= +COM_LoadPackFile + +Takes an explicit (not game tree related) path to a pak file. + +Loads the header and directory, adding the files at the beginning +of the list so they override previous pack files. +================= +*/ +pack_t *COM_LoadPackFile (char *packfile) +{ + dpackheader_t header; + int i; + packfile_t *newfiles; + int numpackfiles; + pack_t *pack; + FILE *packhandle; + dpackfile_t info[MAX_FILES_IN_PACK]; + unsigned short crc; + + if (COM_FileOpenRead (packfile, &packhandle) == -1) + return NULL; + + fread (&header, 1, sizeof(header), packhandle); + if (header.id[0] != 'P' || header.id[1] != 'A' + || header.id[2] != 'C' || header.id[3] != 'K') + Sys_Error ("%s is not a packfile", packfile); + header.dirofs = LittleLong (header.dirofs); + header.dirlen = LittleLong (header.dirlen); + + numpackfiles = header.dirlen / sizeof(dpackfile_t); + + if (numpackfiles > MAX_FILES_IN_PACK) + Sys_Error ("%s has %i files", packfile, numpackfiles); + + if (numpackfiles != PAK0_COUNT) + com_modified = true; // not the original file + + newfiles = Z_Malloc (numpackfiles * sizeof(packfile_t)); + + fseek (packhandle, header.dirofs, SEEK_SET); + fread (&info, 1, header.dirlen, packhandle); + +// crc the directory to check for modifications + crc = CRC_Block((byte *)info, header.dirlen); + +// CRC_Init (&crc); +// for (i=0 ; ifilename, packfile); + pack->handle = packhandle; + pack->numfiles = numpackfiles; + pack->files = newfiles; + + Con_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles); + return pack; +} + + +/* +================ +COM_AddGameDirectory + +Sets com_gamedir, adds the directory to the head of the path, +then loads and adds pak1.pak pak2.pak ... +================ +*/ +void COM_AddGameDirectory (char *dir) +{ + int i; + searchpath_t *search; + pack_t *pak; + char pakfile[MAX_OSPATH]; + char *p; + + if ((p = strrchr(dir, '/')) != NULL) + strcpy(gamedirfile, ++p); + else + strcpy(gamedirfile, p); + strcpy (com_gamedir, dir); + +// +// add the directory to the search path +// + search = Hunk_Alloc (sizeof(searchpath_t)); + strcpy (search->filename, dir); + search->next = com_searchpaths; + com_searchpaths = search; + +// +// add any pak files in the format pak0.pak pak1.pak, ... +// + for (i=0 ; ; i++) + { + snprintf (pakfile, sizeof(pakfile), "%s/pak%i.pak", dir, i); + pak = COM_LoadPackFile (pakfile); + if (!pak) + break; + search = Hunk_Alloc (sizeof(searchpath_t)); + search->pack = pak; + search->next = com_searchpaths; + com_searchpaths = search; + } + +} + +/* +================ +COM_Gamedir + +Sets the gamedir and path to a different directory. +================ +*/ +void COM_Gamedir (char *dir) +{ + searchpath_t *search, *next; + int i; + pack_t *pak; + char pakfile[MAX_OSPATH]; + + if (strstr(dir, "..") || strstr(dir, "/") + || strstr(dir, "\\") || strstr(dir, ":") ) + { + Con_Printf ("Gamedir should be a single filename, not a path\n"); + return; + } + + if (!strcmp(gamedirfile, dir)) + return; // still the same + strcpy (gamedirfile, dir); + + // + // free up any current game dir info + // + while (com_searchpaths != com_base_searchpaths) + { + if (com_searchpaths->pack) + { + fclose (com_searchpaths->pack->handle); + Z_Free (com_searchpaths->pack->files); + Z_Free (com_searchpaths->pack); + } + next = com_searchpaths->next; + Z_Free (com_searchpaths); + com_searchpaths = next; + } + + // + // flush all data, so it will be forced to reload + // + Cache_Flush (); + + if (!strcmp(dir,"id1") || !strcmp(dir, "qw")) + return; + + snprintf (com_gamedir, sizeof(com_gamedir), "%s/%s", com_basedir, dir); + + // + // add the directory to the search path + // + search = Z_Malloc (sizeof(searchpath_t)); + strcpy (search->filename, com_gamedir); + search->next = com_searchpaths; + com_searchpaths = search; + + // + // add any pak files in the format pak0.pak pak1.pak, ... + // + for (i=0 ; ; i++) + { + snprintf (pakfile, sizeof(pakfile), "%s/pak%i.pak", com_gamedir, i); + pak = COM_LoadPackFile (pakfile); + if (!pak) + break; + search = Z_Malloc (sizeof(searchpath_t)); + search->pack = pak; + search->next = com_searchpaths; + com_searchpaths = search; + } +} + +/* +================ +COM_InitFilesystem +================ +*/ +void COM_InitFilesystem (void) +{ + int i; + +// +// -basedir +// Overrides the system supplied base directory (under id1) +// + i = COM_CheckParm ("-basedir"); + if (i && i < com_argc-1) + strcpy (com_basedir, com_argv[i+1]); + else + strcpy (com_basedir, host_parms.basedir); + +// +// start up with id1 by default +// + COM_AddGameDirectory (va("%s/id1", com_basedir) ); + COM_AddGameDirectory (va("%s/qw", com_basedir) ); + + // any set gamedirs will be freed up to here + com_base_searchpaths = com_searchpaths; +} + + + +/* +===================================================================== + + INFO STRINGS + +===================================================================== +*/ + +/* +=============== +Info_ValueForKey + +Searches the string for the given +key and returns the associated value, or an empty string. +=============== +*/ +char *Info_ValueForKey (char *s, char *key) +{ + char pkey[512]; + static char value[4][512]; // use two buffers so compares + // work without stomping on each other + static int valueindex; + char *o; + + valueindex = (valueindex + 1) % 4; + if (*s == '\\') + s++; + while (1) + { + o = pkey; + while (*s != '\\') + { + if (!*s) + return ""; + *o++ = *s++; + } + *o = 0; + s++; + + o = value[valueindex]; + + while (*s != '\\' && *s) + { + if (!*s) + return ""; + *o++ = *s++; + } + *o = 0; + + if (!strcmp (key, pkey) ) + return value[valueindex]; + + if (!*s) + return ""; + s++; + } +} + +void Info_RemoveKey (char *s, char *key) +{ + char *start; + char pkey[512]; + char value[512]; + char *o; + + if (strstr (key, "\\")) + { + Con_Printf ("Can't use a key with a \\\n"); + return; + } + + while (1) + { + start = s; + if (*s == '\\') + s++; + o = pkey; + while (*s != '\\') + { + if (!*s) + return; + *o++ = *s++; + } + *o = 0; + s++; + + o = value; + while (*s != '\\' && *s) + { + if (!*s) + return; + *o++ = *s++; + } + *o = 0; + + if (!strcmp (key, pkey) ) + { + strcpy (start, s); // remove this part + return; + } + + if (!*s) + return; + } + +} + +void Info_RemovePrefixedKeys (char *start, char prefix) +{ + char *s; + char pkey[512]; + char value[512]; + char *o; + + s = start; + + while (1) + { + if (*s == '\\') + s++; + o = pkey; + while (*s != '\\') + { + if (!*s) + return; + *o++ = *s++; + } + *o = 0; + s++; + + o = value; + while (*s != '\\' && *s) + { + if (!*s) + return; + *o++ = *s++; + } + *o = 0; + + if (pkey[0] == prefix) + { + Info_RemoveKey (start, pkey); + s = start; + } + + if (!*s) + return; + } + +} + + +void Info_SetValueForStarKey (char *s, char *key, char *value, int maxsize) +{ + char newstr[1024], *v; + int c, is_name, is_team; + + if (strstr (key, "\\") || strstr (value, "\\") ) + { + Con_Printf ("Can't use keys or values with a \\\n"); + return; + } + + if (strstr (key, "\"") || strstr (value, "\"") ) + { + Con_Printf ("Can't use keys or values with a \"\n"); + return; + } + + if (strlen(key) > 63 || strlen(value) > 63) + { + Con_Printf ("Keys and values must be < 64 characters.\n"); + return; + } + + // this next line is kinda trippy + if (*(v = Info_ValueForKey(s, key))) { + // key exists, make sure we have enough room for new value, if we don't, + // don't change it! + if (strlen(value) - strlen(v) + strlen(s) > maxsize) { + Con_Printf ("Info string length exceeded\n"); + return; + } + } + Info_RemoveKey (s, key); + if (!value || !strlen(value)) + return; + + snprintf (newstr, sizeof(newstr), "\\%s\\%s", key, value); + + if ((int)(strlen(newstr) + strlen(s)) > maxsize) + { + Con_Printf ("Info string length exceeded\n"); + return; + } + + // only copy ascii values + s += strlen(s); + v = newstr; + is_name = stricmp(key, "name") == 0; + is_team = stricmp(key, "team") == 0; + while (*v) + { + c = (unsigned char)*v++; + // client only allows highbits on name + if (!is_name) { + c &= 127; + if (c < 32 || c > 127) + continue; + // auto lowercase team + if (is_team) + c = tolower(c); + } + if (c > 13) + *s++ = c; + } + *s = 0; +} + +void Info_SetValueForKey (char *s, char *key, char *value, int maxsize) +{ + if (key[0] == '*') + { + Con_Printf ("Can't set * keys\n"); + return; + } + + Info_SetValueForStarKey (s, key, value, maxsize); +} + +void Info_Print (char *s) +{ + char key[512]; + char value[512]; + char *o; + int l; + + if (*s == '\\') + s++; + while (*s) + { + o = key; + while (*s && *s != '\\') + *o++ = *s++; + + l = o - key; + if (l < 20) + { + memset (o, ' ', 20-l); + key[20] = 0; + } + else + *o = 0; + Con_Printf ("%s", key); + + if (!*s) + { + Con_Printf ("MISSING VALUE\n"); + return; + } + + o = value; + s++; + while (*s && *s != '\\') + *o++ = *s++; + *o = 0; + + if (*s) + s++; + Con_Printf ("%s\n", value); + } +} + +static byte chktbl[1024 + 4] = { +0x78,0xd2,0x94,0xe3,0x41,0xec,0xd6,0xd5,0xcb,0xfc,0xdb,0x8a,0x4b,0xcc,0x85,0x01, +0x23,0xd2,0xe5,0xf2,0x29,0xa7,0x45,0x94,0x4a,0x62,0xe3,0xa5,0x6f,0x3f,0xe1,0x7a, +0x64,0xed,0x5c,0x99,0x29,0x87,0xa8,0x78,0x59,0x0d,0xaa,0x0f,0x25,0x0a,0x5c,0x58, +0xfb,0x00,0xa7,0xa8,0x8a,0x1d,0x86,0x80,0xc5,0x1f,0xd2,0x28,0x69,0x71,0x58,0xc3, +0x51,0x90,0xe1,0xf8,0x6a,0xf3,0x8f,0xb0,0x68,0xdf,0x95,0x40,0x5c,0xe4,0x24,0x6b, +0x29,0x19,0x71,0x3f,0x42,0x63,0x6c,0x48,0xe7,0xad,0xa8,0x4b,0x91,0x8f,0x42,0x36, +0x34,0xe7,0x32,0x55,0x59,0x2d,0x36,0x38,0x38,0x59,0x9b,0x08,0x16,0x4d,0x8d,0xf8, +0x0a,0xa4,0x52,0x01,0xbb,0x52,0xa9,0xfd,0x40,0x18,0x97,0x37,0xff,0xc9,0x82,0x27, +0xb2,0x64,0x60,0xce,0x00,0xd9,0x04,0xf0,0x9e,0x99,0xbd,0xce,0x8f,0x90,0x4a,0xdd, +0xe1,0xec,0x19,0x14,0xb1,0xfb,0xca,0x1e,0x98,0x0f,0xd4,0xcb,0x80,0xd6,0x05,0x63, +0xfd,0xa0,0x74,0xa6,0x86,0xf6,0x19,0x98,0x76,0x27,0x68,0xf7,0xe9,0x09,0x9a,0xf2, +0x2e,0x42,0xe1,0xbe,0x64,0x48,0x2a,0x74,0x30,0xbb,0x07,0xcc,0x1f,0xd4,0x91,0x9d, +0xac,0x55,0x53,0x25,0xb9,0x64,0xf7,0x58,0x4c,0x34,0x16,0xbc,0xf6,0x12,0x2b,0x65, +0x68,0x25,0x2e,0x29,0x1f,0xbb,0xb9,0xee,0x6d,0x0c,0x8e,0xbb,0xd2,0x5f,0x1d,0x8f, +0xc1,0x39,0xf9,0x8d,0xc0,0x39,0x75,0xcf,0x25,0x17,0xbe,0x96,0xaf,0x98,0x9f,0x5f, +0x65,0x15,0xc4,0x62,0xf8,0x55,0xfc,0xab,0x54,0xcf,0xdc,0x14,0x06,0xc8,0xfc,0x42, +0xd3,0xf0,0xad,0x10,0x08,0xcd,0xd4,0x11,0xbb,0xca,0x67,0xc6,0x48,0x5f,0x9d,0x59, +0xe3,0xe8,0x53,0x67,0x27,0x2d,0x34,0x9e,0x9e,0x24,0x29,0xdb,0x69,0x99,0x86,0xf9, +0x20,0xb5,0xbb,0x5b,0xb0,0xf9,0xc3,0x67,0xad,0x1c,0x9c,0xf7,0xcc,0xef,0xce,0x69, +0xe0,0x26,0x8f,0x79,0xbd,0xca,0x10,0x17,0xda,0xa9,0x88,0x57,0x9b,0x15,0x24,0xba, +0x84,0xd0,0xeb,0x4d,0x14,0xf5,0xfc,0xe6,0x51,0x6c,0x6f,0x64,0x6b,0x73,0xec,0x85, +0xf1,0x6f,0xe1,0x67,0x25,0x10,0x77,0x32,0x9e,0x85,0x6e,0x69,0xb1,0x83,0x00,0xe4, +0x13,0xa4,0x45,0x34,0x3b,0x40,0xff,0x41,0x82,0x89,0x79,0x57,0xfd,0xd2,0x8e,0xe8, +0xfc,0x1d,0x19,0x21,0x12,0x00,0xd7,0x66,0xe5,0xc7,0x10,0x1d,0xcb,0x75,0xe8,0xfa, +0xb6,0xee,0x7b,0x2f,0x1a,0x25,0x24,0xb9,0x9f,0x1d,0x78,0xfb,0x84,0xd0,0x17,0x05, +0x71,0xb3,0xc8,0x18,0xff,0x62,0xee,0xed,0x53,0xab,0x78,0xd3,0x65,0x2d,0xbb,0xc7, +0xc1,0xe7,0x70,0xa2,0x43,0x2c,0x7c,0xc7,0x16,0x04,0xd2,0x45,0xd5,0x6b,0x6c,0x7a, +0x5e,0xa1,0x50,0x2e,0x31,0x5b,0xcc,0xe8,0x65,0x8b,0x16,0x85,0xbf,0x82,0x83,0xfb, +0xde,0x9f,0x36,0x48,0x32,0x79,0xd6,0x9b,0xfb,0x52,0x45,0xbf,0x43,0xf7,0x0b,0x0b, +0x19,0x19,0x31,0xc3,0x85,0xec,0x1d,0x8c,0x20,0xf0,0x3a,0xfa,0x80,0x4d,0x2c,0x7d, +0xac,0x60,0x09,0xc0,0x40,0xee,0xb9,0xeb,0x13,0x5b,0xe8,0x2b,0xb1,0x20,0xf0,0xce, +0x4c,0xbd,0xc6,0x04,0x86,0x70,0xc6,0x33,0xc3,0x15,0x0f,0x65,0x19,0xfd,0xc2,0xd3, + +// map checksum goes here +0x00,0x00,0x00,0x00 +}; + +#if 0 +/* +==================== +COM_BlockSequenceCheckByte + +For proxy protecting +==================== +*/ +byte COM_BlockSequenceCheckByte (byte *base, int length, int sequence, unsigned mapchecksum) +{ + int checksum; + byte *p; + + if (last_mapchecksum != mapchecksum) { + last_mapchecksum = mapchecksum; + chktbl[1024] = (mapchecksum & 0xff000000) >> 24; + chktbl[1025] = (mapchecksum & 0x00ff0000) >> 16; + chktbl[1026] = (mapchecksum & 0x0000ff00) >> 8; + chktbl[1027] = (mapchecksum & 0x000000ff); + + Com_BlockFullChecksum (chktbl, sizeof(chktbl), chkbuf); + } + + p = chktbl + (sequence % (sizeof(chktbl) - 8)); + + if (length > 60) + length = 60; + memcpy (chkbuf + 16, base, length); + + length += 16; + + chkbuf[length] = (sequence & 0xff) ^ p[0]; + chkbuf[length+1] = p[1]; + chkbuf[length+2] = ((sequence>>8) & 0xff) ^ p[2]; + chkbuf[length+3] = p[3]; + + length += 4; + + checksum = LittleLong(Com_BlockChecksum (chkbuf, length)); + + checksum &= 0xff; + + return checksum; +} +#endif + +/* +==================== +COM_BlockSequenceCRCByte + +For proxy protecting +==================== +*/ +byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence) +{ + unsigned short crc; + byte *p; + byte chkb[60 + 4]; + + p = chktbl + (sequence % (sizeof(chktbl) - 8)); + + if (length > 60) + length = 60; + memcpy (chkb, base, length); + + chkb[length] = (sequence & 0xff) ^ p[0]; + chkb[length+1] = p[1]; + chkb[length+2] = ((sequence>>8) & 0xff) ^ p[2]; + chkb[length+3] = p[3]; + + length += 4; + + crc = CRC_Block(chkb, length); + + crc &= 0xff; + + return crc; +} + +// char *date = "Oct 24 1996"; +static char *date = __DATE__ ; +static char *mon[12] = +{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; +static char mond[12] = +{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + +// returns days since Oct 24 1996 +int build_number( void ) +{ + int m = 0; + int d = 0; + int y = 0; + static int b = 0; + + if (b != 0) + return b; + + for (m = 0; m < 11; m++) + { + if (strncasecmp( &date[0], mon[m], 3 ) == 0) + break; + d += mond[m]; + } + + d += atoi( &date[4] ) - 1; + + y = atoi( &date[7] ) - 1900; + + b = d + (int)((y - 1) * 365.25); + + if (((y % 4) == 0) && m > 1) + { + b += 1; + } + + b -= 35778; // Dec 16 1998 + + return b; +} + diff --git a/source/console.c b/source/console.c index cc2aa49..04d07a0 100644 --- a/source/console.c +++ b/source/console.c @@ -29,19 +29,8 @@ #ifdef HAVE_CONFIG_H # include #endif -#include "input.h" #include "sys.h" -#include "console.h" -#include "keys.h" -#include "client.h" -#include "draw.h" -#include "commdef.h" -#include "qargs.h" -#include "cmd.h" -#include "screen.h" - -#include -#include +#include "quakedef.h" int con_ormask; console_t con_main; @@ -54,6 +43,8 @@ int con_totallines; // total lines in console scrollback float con_cursorspeed = 4; +/* cvar_t con_notifytime = {"con_notifytime","3"}; //seconds + CVAR_FIXME */ cvar_t *con_notifytime; //seconds #define NUM_CON_TIMES 4 @@ -127,8 +118,6 @@ Con_Clear_f */ void Con_Clear_f (void) { - con_main.numlines = 0; - con_chat.numlines = 0; memset (con_main.text, ' ', CON_TEXTSIZE); memset (con_chat.text, ' ', CON_TEXTSIZE); } @@ -155,8 +144,6 @@ Con_MessageMode_f */ void Con_MessageMode_f (void) { - if (cls.state != ca_active) - return; chat_team = false; key_dest = key_message; } @@ -168,8 +155,6 @@ Con_MessageMode2_f */ void Con_MessageMode2_f (void) { - if (cls.state != ca_active) - return; chat_team = true; key_dest = key_message; } @@ -266,6 +251,8 @@ void Con_Init (void) // // register our commands // +/* Cvar_RegisterVariable (&con_notifytime); + CVAR_FIXME */ con_notifytime = Cvar_Get("con_notifytime", "3", CVAR_NONE, "None"); Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f); @@ -288,8 +275,6 @@ void Con_Linefeed (void) if (con->display == con->current) con->display++; con->current++; - if (con->numlines < con_totallines) - con->numlines++; memset (&con->text[(con->current%con_totallines)*con_linewidth] , ' ', con_linewidth); } @@ -429,6 +414,8 @@ void Con_DPrintf (char *fmt, ...) va_list argptr; char msg[MAXPRINTMSG]; +/* if (!developer.value) + CVAR_FIXME */ if (!developer->value) return; // don't confuse non-developers with techie stuff... @@ -460,30 +447,31 @@ void Con_DrawInput (void) int y; int i; char *text; - char temp[MAXCMDLINE]; if (key_dest != key_console && cls.state == ca_active) return; // don't draw anything (allways draw if not active) - text = strcpy (temp, key_lines[edit_line]); - -// fill out remainder with spaces - for (i=strlen(text) ; i < MAXCMDLINE ; i++) - text[i] = ' '; - + text = key_lines[edit_line]; + // add the cursor frame - if ( (int)(realtime*con_cursorspeed) & 1 ) - text[key_linepos] = 11; - + text[key_linepos] = 10+((int)(realtime*con_cursorspeed)&1); + +// fill out remainder with spaces + for (i=key_linepos+1 ; i< con_linewidth ; i++) + text[i] = ' '; + // prestep if horizontally scrolling if (key_linepos >= con_linewidth) text += 1 + key_linepos - con_linewidth; - + // draw it y = con_vislines-22; for (i=0 ; i con_notifytime.value) + CVAR_FIXME */ if (time > con_notifytime->value) continue; text = con->text + (i % con_totallines)*con_linewidth; @@ -686,7 +676,7 @@ void Con_NotifyBox (char *text) { t1 = Sys_DoubleTime (); SCR_UpdateScreen (); - IN_SendKeyEvents (); + Sys_SendKeyEvents (); t2 = Sys_DoubleTime (); realtime += t2-t1; // make the cursor blink } while (key_count < 0); diff --git a/source/cvar.c b/source/cvar.c index 13ebead..ca912ad 100644 --- a/source/cvar.c +++ b/source/cvar.c @@ -32,18 +32,7 @@ #ifdef HAVE_CONFIG_H # include #endif - -#include "commdef.h" -#include "cvar.h" -#include "zone.h" -#include "console.h" -#include "qargs.h" -#include "cmd.h" -#include "commdef.h" - -#include -#include -#include +#include "quakedef.h" cvar_t *cvar_vars; char *cvar_null_string = ""; @@ -187,38 +176,16 @@ Cvar_Set */ void Cvar_Set (cvar_t *var, char *value) { - if (!var) - return; - if(var->flags&CVAR_ROM) - return; + if (!var) + return; - Z_Free (var->string); // free the old value string + Z_Free (var->string); // free the old value string - var->string = Z_Malloc (strlen(value)+1); - strcpy (var->string, value); - var->value = atof (var->string); + var->string = Z_Malloc (strlen(value)+1); + strcpy (var->string, value); + var->value = atof (var->string); - Cvar_Info(var); -} -/* - - Cvar_SetROM - - doesn't check for CVAR_ROM flag - -*/ -void Cvar_SetROM (cvar_t *var, char *value) -{ - if (!var) - return; - - Z_Free (var->string); // free the old value string - - var->string = Z_Malloc (strlen(value)+1); - strcpy (var->string, value); - var->value = atof (var->string); - - Cvar_Info(var); + Cvar_Info(var); } /* @@ -228,7 +195,10 @@ Cvar_SetValue */ void Cvar_SetValue (cvar_t *var_name, float value) { - Cvar_Set (var_name, va("%f", value)); + char val[32]; + + sprintf (val, "%f",value); + Cvar_Set (var_name, val); } /* @@ -305,32 +275,6 @@ void Cvar_Set_f(void) } } -void Cvar_Setrom_f(void) -{ - cvar_t *var; - char *value; - char *var_name; - - if (Cmd_Argc() != 2) - { - Con_Printf ("usage: setrom \n"); - return; - } - var_name = Cmd_Argv (1); - value = Cmd_Argv (2); - var = Cvar_FindVar (var_name); - if (!var) - var = Cvar_FindAlias (var_name); - if (var) - { - var->flags |= CVAR_ROM; - } - else - { - Con_Printf ("cvar %s not found\n", var_name); - } -} - void Cvar_Toggle_f (void) { cvar_t *var; @@ -393,7 +337,6 @@ void Cvar_Init() developer = Cvar_Get ("developer","0",0,"None"); Cmd_AddCommand ("set", Cvar_Set_f); - Cmd_AddCommand ("setrom", Cvar_Setrom_f); Cmd_AddCommand ("toggle", Cvar_Toggle_f); Cmd_AddCommand ("help",Cvar_Help_f); Cmd_AddCommand ("cvarlist",Cvar_CvarList_f); diff --git a/source/d_surf.c b/source/d_surf.c index 1bc69b3..9faa0cb 100644 --- a/source/d_surf.c +++ b/source/d_surf.c @@ -1,7 +1,7 @@ /* d_surf.c - rasterization driver surface heap manager + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,17 +25,16 @@ $Id$ */ +// d_surf.c: rasterization driver surface heap manager #ifdef HAVE_CONFIG_H # include #endif #include "sys.h" -#include "qargs.h" +#include "quakedef.h" #include "d_local.h" #include "r_local.h" -#include - float surfscale; qboolean r_cache_thrash; // set if surface cache is thrashing diff --git a/source/draw.c b/source/draw.c index cbba3df..2dcd176 100644 --- a/source/draw.c +++ b/source/draw.c @@ -1,7 +1,7 @@ /* draw.c - this is the only file outside the refresh that touches the vid buffer + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,17 +25,14 @@ $Id$ */ +// draw.c -- this is the only file outside the refresh that touches the +// vid buffer #ifdef HAVE_CONFIG_H # include #endif #include "sys.h" -#include "draw.h" -#include "vid.h" -#include "d_iface.h" -#include "console.h" -#include "quakefs.h" -#include "sound.h" +#include "quakedef.h" typedef struct { vrect_t rect; @@ -51,6 +48,8 @@ byte *draw_chars; // 8*8 graphic characters qpic_t *draw_disc; qpic_t *draw_backtile; +/* cvar_t cl_verstring = {"cl_verstring", "QuakeForge " QF_VERSION}; + CVAR_FIXME */ cvar_t *cl_verstring; //============================================================================= @@ -134,6 +133,8 @@ void Draw_Init (void) r_rectdesc.ptexbytes = draw_backtile->data; r_rectdesc.rowbytes = draw_backtile->width; +/* Cvar_RegisterVariable (&cl_verstring); + CVAR_FIXME */ cl_verstring = Cvar_Get("cl_verstring", PROGRAM " " VERSION, CVAR_NONE, "None"); } @@ -289,12 +290,22 @@ void Draw_Pixel(int x, int y, byte color) void Draw_Crosshair(void) { int x, y; +/* extern cvar_t crosshair, cl_crossx, cl_crossy, crosshaircolor; + CVAR_FIXME */ extern cvar_t *crosshair, *cl_crossx, *cl_crossy, *crosshaircolor; extern vrect_t scr_vrect; +/* byte c = (byte)crosshaircolor.value; + CVAR_FIXME */ byte c = (byte)crosshaircolor->value; +/* if (crosshair.value == 2) { + CVAR_FIXME */ if (crosshair->value == 2) { +/* x = scr_vrect.x + scr_vrect.width/2 + cl_crossx.value; + CVAR_FIXME */ x = scr_vrect.x + scr_vrect.width/2 + cl_crossx->value; +/* y = scr_vrect.y + scr_vrect.height/2 + cl_crossy.value; + CVAR_FIXME */ y = scr_vrect.y + scr_vrect.height/2 + cl_crossy->value; Draw_Pixel(x - 1, y, c); Draw_Pixel(x - 3, y, c); @@ -304,9 +315,15 @@ void Draw_Crosshair(void) Draw_Pixel(x, y - 3, c); Draw_Pixel(x, y + 1, c); Draw_Pixel(x, y + 3, c); +/* } else if (crosshair.value) + CVAR_FIXME */ } else if (crosshair->value) Draw_Character ( +/* scr_vrect.x + scr_vrect.width/2-4 + cl_crossx.value, + CVAR_FIXME */ scr_vrect.x + scr_vrect.width/2-4 + cl_crossx->value, +/* scr_vrect.y + scr_vrect.height/2-4 + cl_crossy.value, + CVAR_FIXME */ scr_vrect.y + scr_vrect.height/2-4 + cl_crossy->value, '+'); } diff --git a/source/gl_draw.c b/source/gl_draw.c index 821b595..6ca920b 100644 --- a/source/gl_draw.c +++ b/source/gl_draw.c @@ -27,14 +27,14 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +# include #endif - #include #include #include "bothdefs.h" // needed by: common.h, net.h, client.h +#include "common.h" #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" @@ -60,6 +60,8 @@ extern unsigned char d_15to8table[65536]; CVAR_FIXME */ extern cvar_t *crosshair, *cl_crossx, *cl_crossy, *crosshaircolor; +/* cvar_t gl_nobind = {"gl_nobind", "0"}; + CVAR_FIXME */ cvar_t *gl_nobind; /* cvar_t gl_max_size = {"gl_max_size", "1024"}; CVAR_FIXME */ @@ -125,6 +127,8 @@ int numgltextures; void GL_Bind (int texnum) { +/* if (gl_nobind.value) + CVAR_FIXME */ if (gl_nobind->value) texnum = char_texture; if (currenttexture == texnum) @@ -384,7 +388,7 @@ void Draw_TextureMode_f (void) for (i=0 ; i< 6 ; i++) { - if (!stricmp (modes[i].name, Cmd_Argv(1) ) ) + if (!strcasecmp (modes[i].name, Cmd_Argv(1) ) ) break; } if (i == 6) @@ -431,7 +435,10 @@ void Draw_Init (void) CVAR_FIXME */ gl_picmip = Cvar_Get("gl_picmip", "0", CVAR_NONE, "None"); - cl_verstring = Cvar_Get("cl_verstring", PROGRAM " " VERSION, CVAR_NONE, "Client version string"); +/* Cvar_RegisterVariable (&cl_verstring); + CVAR_FIXME */ +/* Oddone: Why did you remove this? */ + cl_verstring = Cvar_Get("cl_verstring", PROGRAM " " VERSION, CVAR_NONE, "None"); // 3dfx can only handle 256 wide textures if (!strncasecmp ((char *)gl_renderer, "3dfx",4) || @@ -606,11 +613,19 @@ void Draw_Crosshair(void) extern vrect_t scr_vrect; unsigned char *pColor; +/* if (crosshair.value == 2) { + CVAR_FIXME */ if (crosshair->value == 2) { +/* x = scr_vrect.x + scr_vrect.width/2 - 3 + cl_crossx.value; + CVAR_FIXME */ x = scr_vrect.x + scr_vrect.width/2 - 3 + cl_crossx->value; +/* y = scr_vrect.y + scr_vrect.height/2 - 3 + cl_crossy.value; + CVAR_FIXME */ y = scr_vrect.y + scr_vrect.height/2 - 3 + cl_crossy->value; glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); +/* pColor = (unsigned char *) &d_8to24table[(byte) crosshaircolor.value]; + CVAR_FIXME */ pColor = (unsigned char *) &d_8to24table[(byte) crosshaircolor->value]; glColor4ubv ( pColor ); GL_Bind (cs_texture); @@ -627,9 +642,16 @@ void Draw_Crosshair(void) glEnd (); glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); +/* } else if (crosshair.value) + CVAR_FIXME */ } else if (crosshair->value) +/* Draw_Character (scr_vrect.x + scr_vrect.width/2-4 + cl_crossx.value, + CVAR_FIXME */ Draw_Character (scr_vrect.x + scr_vrect.width/2-4 + cl_crossx->value, - scr_vrect.y + scr_vrect.height/2-4 + cl_crossy->value, '+'); +/* scr_vrect.y + scr_vrect.height/2-4 + cl_crossy.value, + CVAR_FIXME */ + scr_vrect.y + scr_vrect.height/2-4 + cl_crossy->value, + '+'); } @@ -686,9 +708,9 @@ void Draw_AlphaPic (int x, int y, qpic_t *pic, float alpha) gl = (glpic_t *)pic->data; glDisable(GL_ALPHA_TEST); glEnable (GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glCullFace(GL_FRONT); -// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // FIXME deek: these cause problems with text. Looking for the real problem + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glColor4f (1,1,1,alpha); GL_Bind (gl->texnum); glBegin (GL_QUADS); @@ -702,7 +724,7 @@ void Draw_AlphaPic (int x, int y, qpic_t *pic, float alpha) glVertex2f (x, y+pic->height); glEnd (); glColor4f (1,1,1,1); -// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // FIXME + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glEnable(GL_ALPHA_TEST); glDisable (GL_BLEND); } @@ -1123,11 +1145,25 @@ static unsigned scaled[1024*512]; // [512*256]; for (scaled_height = 1 ; scaled_height < height ; scaled_height<<=1) ; +/* scaled_width >>= (int)gl_picmip.value; + CVAR_FIXME */ scaled_width >>= (int)gl_picmip->value; +/* scaled_height >>= (int)gl_picmip.value; + CVAR_FIXME */ scaled_height >>= (int)gl_picmip->value; - scaled_width = min(scaled_width, gl_max_size->value); - scaled_height = min(scaled_height, gl_max_size->value); +/* if (scaled_width > gl_max_size.value) + CVAR_FIXME */ + if (scaled_width > gl_max_size->value) +/* scaled_width = gl_max_size.value; + CVAR_FIXME */ + scaled_width = gl_max_size->value; +/* if (scaled_height > gl_max_size.value) + CVAR_FIXME */ + if (scaled_height > gl_max_size->value) +/* scaled_height = gl_max_size.value; + CVAR_FIXME */ + scaled_height = gl_max_size->value; if (scaled_width * scaled_height > sizeof(scaled)/4) Sys_Error ("GL_LoadTexture: too big"); @@ -1223,11 +1259,25 @@ void GL_Upload8_EXT (byte *data, int width, int height, qboolean mipmap, qboole for (scaled_height = 1 ; scaled_height < height ; scaled_height<<=1) ; +/* scaled_width >>= (int)gl_picmip.value; + CVAR_FIXME */ scaled_width >>= (int)gl_picmip->value; +/* scaled_height >>= (int)gl_picmip.value; + CVAR_FIXME */ scaled_height >>= (int)gl_picmip->value; - scaled_width = min(scaled_width, gl_max_size->value); - scaled_height = min(scaled_height, gl_max_size->value); +/* if (scaled_width > gl_max_size.value) + CVAR_FIXME */ + if (scaled_width > gl_max_size->value) +/* scaled_width = gl_max_size.value; + CVAR_FIXME */ + scaled_width = gl_max_size->value; +/* if (scaled_height > gl_max_size.value) + CVAR_FIXME */ + if (scaled_height > gl_max_size->value) +/* scaled_height = gl_max_size.value; + CVAR_FIXME */ + scaled_height = gl_max_size->value; if (scaled_width * scaled_height > sizeof(scaled)) Sys_Error ("GL_LoadTexture: too big"); diff --git a/source/gl_model.c b/source/gl_model.c index 0d0c4b1..d2e120a 100644 --- a/source/gl_model.c +++ b/source/gl_model.c @@ -1,7 +1,7 @@ /* gl_model.c - model loading and caching + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,10 +25,10 @@ $Id$ */ +// models.c -- model loading and caching // models are the only shared resource between a client and server running // on the same machine. - #ifdef HAVE_CONFIG_H # include #endif @@ -37,8 +37,8 @@ #include #include "bothdefs.h" // needed by: common.h, net.h, client.h -#include "qendian.h" -#include "msg.h" + +#include "common.h" #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" diff --git a/source/gl_part.c b/source/gl_part.c index c7b5b19..1330617 100644 --- a/source/gl_part.c +++ b/source/gl_part.c @@ -29,32 +29,8 @@ #ifdef HAVE_CONFIG_H # include #endif -#include "qargs.h" -#include "bothdefs.h" // needed by: common.h, net.h, client.h -#include "d_iface.h" -#include "bspfile.h" // needed by: glquake.h -#include "vid.h" -#include "sys.h" -#include "zone.h" // needed by: client.h, gl_model.h -#include "mathlib.h" // needed by: protocol.h, render.h, client.h, - // modelgen.h, glmodel.h -#include "wad.h" -#include "draw.h" -#include "cvar.h" -#include "menu.h" -#include "net.h" // needed by: client.h -#include "protocol.h" // needed by: client.h -#include "cmd.h" -#include "sbar.h" -#include "render.h" // needed by: client.h, gl_model.h, glquake.h -#include "client.h" // need cls in this file -#include "model.h" // needed by: glquake.h -#include "console.h" -#include "glquake.h" -#include "quakefs.h" #include "quakedef.h" - -#include +#include "glquake.h" #define MAX_PARTICLES 2048 // default max # of particles at one // time @@ -126,7 +102,7 @@ void R_ReadPointFile_f (void) int c; particle_t *p; char name[MAX_OSPATH]; - + // FIXME sprintf (name,"maps/%s.pts", sv.name); COM_FOpenFile (name, &f); diff --git a/source/gl_rmisc.c b/source/gl_rmisc.c index 1873a38..db49402 100644 --- a/source/gl_rmisc.c +++ b/source/gl_rmisc.c @@ -25,7 +25,6 @@ $Id$ */ - #ifdef HAVE_CONFIG_H # include #endif @@ -34,6 +33,7 @@ #include "bothdefs.h" // needed by: common.h, net.h, client.h +#include "common.h" #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" @@ -227,35 +227,83 @@ void R_Init (void) Cmd_AddCommand ("pointfile", R_ReadPointFile_f); Cmd_AddCommand ("loadsky", R_LoadSky_f); +/* Cvar_RegisterVariable (&r_norefresh); + CVAR_FIXME */ r_norefresh = Cvar_Get("r_norefresh", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&r_lightmap); + CVAR_FIXME */ r_lightmap = Cvar_Get("r_lightmap", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&r_fullbright); + CVAR_FIXME */ r_fullbright = Cvar_Get("r_fullbright", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&r_drawentities); + CVAR_FIXME */ r_drawentities = Cvar_Get("r_drawentities", "1", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&r_drawviewmodel); + CVAR_FIXME */ r_drawviewmodel = Cvar_Get("r_drawviewmodel", "1", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&r_shadows); + CVAR_FIXME */ r_shadows = Cvar_Get("r_shadows", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&r_mirroralpha); + CVAR_FIXME */ r_mirroralpha = Cvar_Get("r_mirroralpha", "1", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&r_wateralpha); + CVAR_FIXME */ r_wateralpha = Cvar_Get("r_wateralpha", "1", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&r_dynamic); + CVAR_FIXME */ r_dynamic = Cvar_Get("r_dynamic", "1", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&r_novis); + CVAR_FIXME */ r_novis = Cvar_Get("r_novis", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&r_speeds); + CVAR_FIXME */ r_speeds = Cvar_Get("r_speeds", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&r_netgraph); + CVAR_FIXME */ r_netgraph = Cvar_Get("r_netgraph", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&gl_clear); + CVAR_FIXME */ gl_clear = Cvar_Get("gl_clear", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&gl_texsort); + CVAR_FIXME */ gl_texsort = Cvar_Get("gl_texsort", "1", CVAR_NONE, "None"); if (gl_mtexable) gl_texsort->value = 0.0; +/* Cvar_RegisterVariable (&gl_cull); + CVAR_FIXME */ gl_cull = Cvar_Get("gl_cull", "1", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&gl_smoothmodels); + CVAR_FIXME */ gl_smoothmodels = Cvar_Get("gl_smoothmodels", "1", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&gl_affinemodels); + CVAR_FIXME */ gl_affinemodels = Cvar_Get("gl_affinemodels", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&gl_polyblend); + CVAR_FIXME */ gl_polyblend = Cvar_Get("gl_polyblend", "1", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&gl_flashblend); + CVAR_FIXME */ gl_flashblend = Cvar_Get("gl_flashblend", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&gl_playermip); + CVAR_FIXME */ gl_playermip = Cvar_Get("gl_playermip", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&gl_nocolors); + CVAR_FIXME */ gl_nocolors = Cvar_Get("gl_nocolors", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&gl_finish); + CVAR_FIXME */ gl_finish = Cvar_Get("gl_finish", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&gl_keeptjunctions); + CVAR_FIXME */ gl_keeptjunctions = Cvar_Get("gl_keeptjunctions", "1", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&gl_reporttjunctions); + CVAR_FIXME */ gl_reporttjunctions = Cvar_Get("gl_reporttjunctions", "0", CVAR_NONE, "None"); r_skyname = Cvar_Get("r_skyname", "none", CVAR_NONE, @@ -266,6 +314,10 @@ void R_Init (void) R_InitParticles (); R_InitParticleTexture (); +#ifdef GLTEST + Test_Init (); +#endif + netgraphtexture = texture_extension_number; texture_extension_number++; @@ -378,12 +430,18 @@ void R_TranslatePlayerSkin (int playernum) false, false, true); #endif - // FIXME deek: This 512x256 limit sucks! - scaled_width = min(gl_max_size->value, 512); - scaled_height = min(gl_max_size->value, 256); - +/* scaled_width = gl_max_size.value < 512 ? gl_max_size.value : 512; + CVAR_FIXME */ + scaled_width = gl_max_size->value < 512 ? gl_max_size->value : 512; +/* scaled_height = gl_max_size->value < 256 ? gl_max_size.value : 256; + CVAR_FIXME */ + scaled_height = gl_max_size->value < 256 ? gl_max_size->value : 256; // allow users to crunch sizes down even more if they want +/* scaled_width >>= (int)gl_playermip.value; + CVAR_FIXME */ scaled_width >>= (int)gl_playermip->value; +/* scaled_height >>= (int)gl_playermip.value; + CVAR_FIXME */ scaled_height >>= (int)gl_playermip->value; if (VID_Is8bit()) { // 8bit texture upload diff --git a/source/gl_screen.c b/source/gl_screen.c index f4a9b53..f306bd8 100644 --- a/source/gl_screen.c +++ b/source/gl_screen.c @@ -1,7 +1,7 @@ /* gl_screen.c - master for refresh, status bar, console, chat, notify, etc + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,20 +25,19 @@ $Id$ */ - +// screen.c -- master for refresh, status bar, console, chat, notify, etc #ifdef HAVE_CONFIG_H -# include "config.h" +# include #endif - #include #include #include #include #include -#include "input.h" #include "bothdefs.h" // needed by: common.h, net.h, client.h -#include "qendian.h" + +#include "common.h" #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" @@ -122,16 +121,38 @@ float scr_con_current; float scr_conlines; // lines of console to display float oldscreensize, oldfov; +/* cvar_t scr_viewsize = {"viewsize","100", true}; + CVAR_FIXME */ cvar_t *scr_viewsize; +/* cvar_t scr_fov = {"fov","90"}; // 10 - 170 + CVAR_FIXME */ cvar_t *scr_fov; // 10 - 170 +/* cvar_t scr_conspeed = {"scr_conspeed","300"}; + CVAR_FIXME */ cvar_t *scr_conspeed; +/* cvar_t scr_centertime = {"scr_centertime","2"}; + CVAR_FIXME */ cvar_t *scr_centertime; +/* cvar_t scr_showram = {"showram","1"}; + CVAR_FIXME */ cvar_t *scr_showram; +/* cvar_t scr_showturtle = {"showturtle","0"}; + CVAR_FIXME */ cvar_t *scr_showturtle; +/* cvar_t scr_showpause = {"showpause","1"}; + CVAR_FIXME */ cvar_t *scr_showpause; +/* cvar_t scr_printspeed = {"scr_printspeed","8"}; + CVAR_FIXME */ cvar_t *scr_printspeed; +/* cvar_t scr_allowsnap = {"scr_allowsnap", "1"}; + CVAR_FIXME */ cvar_t *scr_allowsnap; +/* cvar_t gl_triplebuffer = {"gl_triplebuffer", "1", true }; + CVAR_FIXME */ cvar_t *gl_triplebuffer; +/* extern cvar_t crosshair; + CVAR_FIXME */ extern cvar_t *crosshair; qboolean scr_initialized; // ready to draw @@ -186,6 +207,8 @@ for a few moments void SCR_CenterPrint (char *str) { strncpy (scr_centerstring, str, sizeof(scr_centerstring)-1); +/* scr_centertime_off = scr_centertime.value; + CVAR_FIXME */ scr_centertime_off = scr_centertime->value; scr_centertime_start = cl.time; @@ -210,6 +233,8 @@ void SCR_DrawCenterString (void) // the finale prints the characters one at a time if (cl.intermission) +/* remaining = scr_printspeed.value * (cl.time - scr_centertime_start); + CVAR_FIXME */ remaining = scr_printspeed->value * (cl.time - scr_centertime_start); else remaining = 9999; @@ -311,14 +336,22 @@ static void SCR_CalcRefdef (void) //======================================== // bound viewsize +/* if (scr_viewsize.value < 30) + CVAR_FIXME */ if (scr_viewsize->value < 30) Cvar_Set (scr_viewsize,"30"); +/* if (scr_viewsize.value > 120) + CVAR_FIXME */ if (scr_viewsize->value > 120) Cvar_Set (scr_viewsize,"120"); // bound field of view +/* if (scr_fov.value < 10) + CVAR_FIXME */ if (scr_fov->value < 10) Cvar_Set (scr_fov,"10"); +/* if (scr_fov.value > 170) + CVAR_FIXME */ if (scr_fov->value > 170) Cvar_Set (scr_fov,"170"); @@ -326,6 +359,8 @@ static void SCR_CalcRefdef (void) if (cl.intermission) size = 120; else +/* size = scr_viewsize.value; + CVAR_FIXME */ size = scr_viewsize->value; if (size >= 120) @@ -335,10 +370,14 @@ static void SCR_CalcRefdef (void) else sb_lines = 24+16+8; +/* if (scr_viewsize.value >= 100.0) { + CVAR_FIXME */ if (scr_viewsize->value >= 100.0) { full = true; size = 100.0; } else +/* size = scr_viewsize.value; + CVAR_FIXME */ size = scr_viewsize->value; if (cl.intermission) { @@ -348,6 +387,8 @@ static void SCR_CalcRefdef (void) } size /= 100.0; +/* if (!cl_sbar.value && full) + CVAR_FIXME */ if (!cl_sbar->value && full) h = vid.height; else @@ -361,6 +402,8 @@ static void SCR_CalcRefdef (void) } r_refdef.vrect.height = vid.height * size; +/* if (cl_sbar.value || !full) { + CVAR_FIXME */ if (cl_sbar->value || !full) { if (r_refdef.vrect.height > vid.height - sb_lines) r_refdef.vrect.height = vid.height - sb_lines; @@ -372,6 +415,8 @@ static void SCR_CalcRefdef (void) else r_refdef.vrect.y = (h - r_refdef.vrect.height)/2; +/* r_refdef.fov_x = scr_fov.value; + CVAR_FIXME */ r_refdef.fov_x = scr_fov->value; r_refdef.fov_y = CalcFov (r_refdef.fov_x, r_refdef.vrect.width, r_refdef.vrect.height); @@ -388,6 +433,8 @@ Keybinding command */ void SCR_SizeUp_f (void) { +/* Cvar_SetValue ("viewsize",scr_viewsize.value+10); + CVAR_FIXME */ Cvar_SetValue (scr_viewsize, scr_viewsize->value+10); vid.recalc_refdef = 1; @@ -403,6 +450,8 @@ Keybinding command */ void SCR_SizeDown_f (void) { +/* Cvar_SetValue ("viewsize",scr_viewsize.value-10); + CVAR_FIXME */ Cvar_SetValue (scr_viewsize, scr_viewsize->value-10); vid.recalc_refdef = 1; } @@ -455,6 +504,8 @@ SCR_DrawRam */ void SCR_DrawRam (void) { +/* if (!scr_showram.value) + CVAR_FIXME */ if (!scr_showram->value) return; @@ -473,6 +524,8 @@ void SCR_DrawTurtle (void) { static int count; +/* if (!scr_showturtle.value) + CVAR_FIXME */ if (!scr_showturtle->value) return; @@ -506,6 +559,8 @@ void SCR_DrawNet (void) void SCR_DrawFPS (void) { +/* extern cvar_t show_fps; + CVAR_FIXME */ extern cvar_t *show_fps; static double lastframetime; double t; @@ -514,6 +569,8 @@ void SCR_DrawFPS (void) int x, y; char st[80]; +/* if (!show_fps.value) + CVAR_FIXME */ if (!show_fps->value) return; @@ -541,6 +598,8 @@ void SCR_DrawPause (void) { qpic_t *pic; +/* if (!scr_showpause.value) // turn off for screenshots + CVAR_FIXME */ if (!scr_showpause->value) // turn off for screenshots return; @@ -601,6 +660,8 @@ void SCR_SetUpToDrawConsole (void) if (scr_conlines < scr_con_current) { +/* scr_con_current -= scr_conspeed.value*host_frametime; + CVAR_FIXME */ scr_con_current -= scr_conspeed->value*host_frametime; if (scr_conlines > scr_con_current) scr_con_current = scr_conlines; @@ -608,6 +669,8 @@ void SCR_SetUpToDrawConsole (void) } else if (scr_conlines > scr_con_current) { +/* scr_con_current += scr_conspeed.value*host_frametime; + CVAR_FIXME */ scr_con_current += scr_conspeed->value*host_frametime; if (scr_conlines < scr_con_current) scr_con_current = scr_conlines; @@ -1058,7 +1121,7 @@ int SCR_ModalMessage (char *text) do { key_count = -1; // wait for a key down and up - IN_SendKeyEvents (); + Sys_SendKeyEvents (); } while (key_lastpress != 'y' && key_lastpress != 'n' && key_lastpress != K_ESCAPE); scr_fullupdate = 0; @@ -1132,7 +1195,9 @@ void SCR_UpdateScreen (void) if (block_drawing) return; - vid.numpages = 2 + (int) gl_triplebuffer->value; +/* vid.numpages = 2 + gl_triplebuffer.value; + CVAR_FIXME */ + vid.numpages = 2 + gl_triplebuffer->value; scr_copytop = 0; scr_copyeverything = 0; @@ -1152,7 +1217,11 @@ void SCR_UpdateScreen (void) return; // not initialized yet +/* if (oldsbar != cl_sbar.value) { + CVAR_FIXME */ if (oldsbar != cl_sbar->value) { +/* oldsbar = cl_sbar.value; + CVAR_FIXME */ oldsbar = cl_sbar->value; vid.recalc_refdef = true; } @@ -1162,8 +1231,12 @@ void SCR_UpdateScreen (void) // // determine size of refresh window // +/* if (oldfov != scr_fov.value) + CVAR_FIXME */ if (oldfov != scr_fov->value) { +/* oldfov = scr_fov.value; + CVAR_FIXME */ oldfov = scr_fov->value; vid.recalc_refdef = true; } @@ -1185,6 +1258,8 @@ void SCR_UpdateScreen (void) // SCR_TileClear (); +/* if (r_netgraph.value) + CVAR_FIXME */ if (r_netgraph->value) R_NetGraph (); @@ -1211,6 +1286,8 @@ void SCR_UpdateScreen (void) } else { +/* if (crosshair.value) + CVAR_FIXME */ if (crosshair->value) Draw_Crosshair(); diff --git a/source/gl_vidlinux.c b/source/gl_vidlinux.c new file mode 100644 index 0000000..63b9e01 --- /dev/null +++ b/source/gl_vidlinux.c @@ -0,0 +1,868 @@ +/* + gl_vidlinux.c + + (description) + + Copyright (C) 1996-1997 Id Software, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + + $Id$ +*/ + +#ifdef HAVE_CONFIG_H +# include +#endif +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "vga.h" +#include "vgakeyboard.h" +#include "vgamouse.h" + +#include "quakedef.h" +#include "GL/fxmesa.h" + +#define WARP_WIDTH 320 +#define WARP_HEIGHT 200 + +static fxMesaContext fc = NULL; +#define stringify(m) { #m, m } + +unsigned short d_8to16table[256]; +unsigned d_8to24table[256]; +unsigned char d_15to8table[65536]; + +int num_shades=32; + +struct +{ + char *name; + int num; +} mice[] = +{ + stringify(MOUSE_MICROSOFT), + stringify(MOUSE_MOUSESYSTEMS), + stringify(MOUSE_MMSERIES), + stringify(MOUSE_LOGITECH), + stringify(MOUSE_BUSMOUSE), + stringify(MOUSE_PS2), +}; + +static unsigned char scantokey[128]; + +int num_mice = sizeof (mice) / sizeof(mice[0]); + +int d_con_indirect = 0; + +int svgalib_inited=0; +int UseMouse = 1; +int UseKeyboard = 1; + +int mouserate = MOUSE_DEFAULTSAMPLERATE; + +/* cvar_t _windowed_mouse = {"_windowed_mouse","0", true}; + CVAR_FIXME */ +cvar_t *_windowed_mouse; + +/* cvar_t vid_mode = {"vid_mode","5",false}; + CVAR_FIXME */ +cvar_t *vid_mode; +/* cvar_t vid_redrawfull = {"vid_redrawfull","0",false}; + CVAR_FIXME */ +cvar_t *vid_redrawfull; +/* cvar_t vid_waitforrefresh = {"vid_waitforrefresh","0",true}; + CVAR_FIXME */ +cvar_t *vid_waitforrefresh; + +char *framebuffer_ptr; + +cvar_t mouse_button_commands[3] = +{ + {"mouse1","+attack"}, + {"mouse2","+strafe"}, + {"mouse3","+forward"}, +}; + +int mouse_buttons; +int mouse_buttonstate; +int mouse_oldbuttonstate; +float mouse_x, mouse_y; +float old_mouse_x, old_mouse_y; +int mx, my; + +/* cvar_t m_filter = {"m_filter","1"}; + CVAR_FIXME */ +cvar_t *m_filter; + +int scr_width, scr_height; + +/*-----------------------------------------------------------------------*/ + +//int texture_mode = GL_NEAREST; +//int texture_mode = GL_NEAREST_MIPMAP_NEAREST; +//int texture_mode = GL_NEAREST_MIPMAP_LINEAR; +int texture_mode = GL_LINEAR; +//int texture_mode = GL_LINEAR_MIPMAP_NEAREST; +//int texture_mode = GL_LINEAR_MIPMAP_LINEAR; + +int texture_extension_number = 1; + +float gldepthmin, gldepthmax; + +/* cvar_t gl_ztrick = {"gl_ztrick","1"}; + CVAR_FIXME */ +cvar_t *gl_ztrick; + +const char *gl_vendor; +const char *gl_renderer; +const char *gl_version; +const char *gl_extensions; + +qboolean is8bit = false; +qboolean isPermedia = false; +qboolean gl_mtexable = false; + +/*-----------------------------------------------------------------------*/ +void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height) +{ +} + +void D_EndDirectRect (int x, int y, int width, int height) +{ +} + +int matchmouse(int mouse, char *name) +{ + int i; + for (i=0 ; i> 2)+4; + b = ((i & 0x7C00) >> 7)+4; + pal = (unsigned char *)d_8to24table; + for (v=0,k=0,bestdist=10000.0; v<256; v++,pal+=4) { + r1 = (int)r - (int)pal[0]; + g1 = (int)g - (int)pal[1]; + b1 = (int)b - (int)pal[2]; + dist = sqrt(((r1*r1)+(g1*g1)+(b1*b1))); + if (dist < bestdist) { + k=v; + bestdist = dist; + } + } + d_15to8table[i]=k; + } + snprintf (s, sizeof(s), "%s/glquake", com_gamedir); + Sys_mkdir (s); + snprintf (s, sizeof(s), "%s/glquake/15to8.pal", com_gamedir); + if ((f = fopen(s, "wb")) != NULL) { + fwrite(d_15to8table, 1<<15, 1, f); + fclose(f); + } + } +} + +/* +=============== +GL_Init +=============== +*/ +void GL_Init (void) +{ + gl_vendor = glGetString (GL_VENDOR); + Con_Printf ("GL_VENDOR: %s\n", gl_vendor); + gl_renderer = glGetString (GL_RENDERER); + Con_Printf ("GL_RENDERER: %s\n", gl_renderer); + + gl_version = glGetString (GL_VERSION); + Con_Printf ("GL_VERSION: %s\n", gl_version); + gl_extensions = glGetString (GL_EXTENSIONS); + Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions); + +// Con_Printf ("%s %s\n", gl_renderer, gl_version); + + glClearColor (1,0,0,0); + glCullFace(GL_FRONT); + glEnable(GL_TEXTURE_2D); + + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.666); + + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + glShadeModel (GL_FLAT); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + +// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); +} + +/* +================= +GL_BeginRendering + +================= +*/ +void GL_BeginRendering (int *x, int *y, int *width, int *height) +{ +/* extern cvar_t gl_clear; + CVAR_FIXME */ + extern cvar_t *gl_clear; + + *x = *y = 0; + *width = scr_width; + *height = scr_height; + +// if (!wglMakeCurrent( maindc, baseRC )) +// Sys_Error ("wglMakeCurrent failed"); + +// glViewport (*x, *y, *width, *height); +} + + +void GL_EndRendering (void) +{ + glFlush(); + fxMesaSwapBuffers(); +} + +void Init_KBD(void) +{ + int i; + + if (COM_CheckParm("-nokbd")) UseKeyboard = 0; + + if (UseKeyboard) + { + for (i=0 ; i<128 ; i++) + scantokey[i] = ' '; + + scantokey[42] = K_SHIFT; + scantokey[54] = K_SHIFT; + scantokey[72] = K_UPARROW; + scantokey[103] = K_UPARROW; + scantokey[80] = K_DOWNARROW; + scantokey[108] = K_DOWNARROW; + scantokey[75] = K_LEFTARROW; + scantokey[105] = K_LEFTARROW; + scantokey[77] = K_RIGHTARROW; + scantokey[106] = K_RIGHTARROW; + scantokey[29] = K_CTRL; + scantokey[97] = K_CTRL; + scantokey[56] = K_ALT; + scantokey[100] = K_ALT; +// scantokey[58] = JK_CAPS; +// scantokey[69] = JK_NUM_LOCK; + scantokey[71] = K_HOME; + scantokey[73] = K_PGUP; + scantokey[79] = K_END; + scantokey[81] = K_PGDN; + scantokey[82] = K_INS; + scantokey[83] = K_DEL; + scantokey[1 ] = K_ESCAPE; + scantokey[28] = K_ENTER; + scantokey[15] = K_TAB; + scantokey[14] = K_BACKSPACE; + scantokey[119] = K_PAUSE; + scantokey[57] = ' '; + + scantokey[102] = K_HOME; + scantokey[104] = K_PGUP; + scantokey[107] = K_END; + scantokey[109] = K_PGDN; + scantokey[110] = K_INS; + scantokey[111] = K_DEL; + + scantokey[2] = '1'; + scantokey[3] = '2'; + scantokey[4] = '3'; + scantokey[5] = '4'; + scantokey[6] = '5'; + scantokey[7] = '6'; + scantokey[8] = '7'; + scantokey[9] = '8'; + scantokey[10] = '9'; + scantokey[11] = '0'; + scantokey[12] = '-'; + scantokey[13] = '='; + scantokey[41] = '`'; + scantokey[26] = '['; + scantokey[27] = ']'; + scantokey[39] = ';'; + scantokey[40] = '\''; + scantokey[51] = ','; + scantokey[52] = '.'; + scantokey[53] = '/'; + scantokey[43] = '\\'; + + scantokey[59] = K_F1; + scantokey[60] = K_F2; + scantokey[61] = K_F3; + scantokey[62] = K_F4; + scantokey[63] = K_F5; + scantokey[64] = K_F6; + scantokey[65] = K_F7; + scantokey[66] = K_F8; + scantokey[67] = K_F9; + scantokey[68] = K_F10; + scantokey[87] = K_F11; + scantokey[88] = K_F12; + scantokey[30] = 'a'; + scantokey[48] = 'b'; + scantokey[46] = 'c'; + scantokey[32] = 'd'; + scantokey[18] = 'e'; + scantokey[33] = 'f'; + scantokey[34] = 'g'; + scantokey[35] = 'h'; + scantokey[23] = 'i'; + scantokey[36] = 'j'; + scantokey[37] = 'k'; + scantokey[38] = 'l'; + scantokey[50] = 'm'; + scantokey[49] = 'n'; + scantokey[24] = 'o'; + scantokey[25] = 'p'; + scantokey[16] = 'q'; + scantokey[19] = 'r'; + scantokey[31] = 's'; + scantokey[20] = 't'; + scantokey[22] = 'u'; + scantokey[47] = 'v'; + scantokey[17] = 'w'; + scantokey[45] = 'x'; + scantokey[21] = 'y'; + scantokey[44] = 'z'; + + scantokey[78] = '+'; + scantokey[74] = '-'; + + if (keyboard_init()) + Sys_Error("keyboard_init() failed"); + keyboard_seteventhandler(keyhandler); + } +} + +#define NUM_RESOLUTIONS 3 + +static resolutions[NUM_RESOLUTIONS][3]={ + { 512, 384, GR_RESOLUTION_512x384 }, + { 640, 400, GR_RESOLUTION_640x400 }, + { 640, 480, GR_RESOLUTION_640x480 } +}; + +int findres(int *width, int *height) +{ + int i; + + for(i=0;i height) + vid.conheight = height; + if (vid.conwidth > width) + vid.conwidth = width; + vid.width = vid.conwidth; + vid.height = vid.conheight; + + vid.aspect = ((float)vid.height / (float)vid.width) * + (320.0 / 240.0); + vid.numpages = 2; + + InitSig(); // trap evil signals + + GL_Init(); + + snprintf (gldir, sizeof(gldir), "%s/glquake", com_gamedir); + Sys_mkdir (gldir); + + VID_SetPalette(palette); + + // Check for 3DFX Extensions and initialize them. + VID_Init8bitPalette(); + + Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height); + + vid.recalc_refdef = 1; // force a surface cache flush +} + +void Sys_SendKeyEvents(void) +{ + if (UseKeyboard) + while (keyboard_update()); +} + +void Force_CenterView_f (void) +{ + cl.viewangles[PITCH] = 0; +} + + +void mousehandler(int buttonstate, int dx, int dy) +{ + mouse_buttonstate = buttonstate; + mx += dx; + my += dy; +} + +void IN_Init(void) +{ + + int mtype; + char *mousedev; + int mouserate; + + if (UseMouse) + { + + Cvar_RegisterVariable (&mouse_button_commands[0]); + Cvar_RegisterVariable (&mouse_button_commands[1]); + Cvar_RegisterVariable (&mouse_button_commands[2]); + Cmd_AddCommand ("force_centerview", Force_CenterView_f); + + mouse_buttons = 3; + + mtype = vga_getmousetype(); + + mousedev = "/dev/mouse"; + if (getenv("MOUSEDEV")) mousedev = getenv("MOUSEDEV"); + if (COM_CheckParm("-mdev")) + mousedev = com_argv[COM_CheckParm("-mdev")+1]; + + mouserate = 1200; + if (getenv("MOUSERATE")) mouserate = atoi(getenv("MOUSERATE")); + if (COM_CheckParm("-mrate")) + mouserate = atoi(com_argv[COM_CheckParm("-mrate")+1]); + + if (mouse_init(mousedev, mtype, mouserate)) + { + Con_Printf("No mouse found\n"); + UseMouse = 0; + } + else + mouse_seteventhandler(mousehandler); + + } + +} + +void IN_Shutdown(void) +{ + if (UseMouse) + mouse_close(); +} + +/* +=========== +IN_Commands +=========== +*/ +void IN_Commands (void) +{ + if (UseMouse) + { + // poll mouse values + while (mouse_update()) + ; + + // perform button actions + if ((mouse_buttonstate & MOUSE_LEFTBUTTON) && + !(mouse_oldbuttonstate & MOUSE_LEFTBUTTON)) + Key_Event (K_MOUSE1, true); + else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) && + (mouse_oldbuttonstate & MOUSE_LEFTBUTTON)) + Key_Event (K_MOUSE1, false); + + if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) && + !(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON)) + Key_Event (K_MOUSE2, true); + else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) && + (mouse_oldbuttonstate & MOUSE_RIGHTBUTTON)) + Key_Event (K_MOUSE2, false); + + if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) && + !(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON)) + Key_Event (K_MOUSE3, true); + else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) && + (mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON)) + Key_Event (K_MOUSE3, false); + + mouse_oldbuttonstate = mouse_buttonstate; + } +} + +/* +=========== +IN_Move +=========== +*/ +void IN_MouseMove (usercmd_t *cmd) +{ + if (!UseMouse) + return; + + // poll mouse values + while (mouse_update()) + ; + +/* if (m_filter.value) + CVAR_FIXME */ + if (m_filter->value) + { + mouse_x = (mx + old_mouse_x) * 0.5; + mouse_y = (my + old_mouse_y) * 0.5; + } + else + { + mouse_x = mx; + mouse_y = my; + } + old_mouse_x = mx; + old_mouse_y = my; + mx = my = 0; // clear for next update + +/* mouse_x *= sensitivity.value; + CVAR_FIXME */ + mouse_x *= sensitivity->value; +/* mouse_y *= sensitivity.value; + CVAR_FIXME */ + mouse_y *= sensitivity->value; + +// add mouse X/Y movement to cmd +/* if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) )) + CVAR_FIXME */ + if ( (in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1) )) +/* cmd->sidemove += m_side.value * mouse_x; + CVAR_FIXME */ + cmd->sidemove += m_side->value * mouse_x; + else +/* cl.viewangles[YAW] -= m_yaw.value * mouse_x; + CVAR_FIXME */ + cl.viewangles[YAW] -= m_yaw->value * mouse_x; + + if (in_mlook.state & 1) + V_StopPitchDrift (); + + if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) + { +/* cl.viewangles[PITCH] += m_pitch.value * mouse_y; + CVAR_FIXME */ + cl.viewangles[PITCH] += m_pitch->value * mouse_y; + if (cl.viewangles[PITCH] > 80) + cl.viewangles[PITCH] = 80; + if (cl.viewangles[PITCH] < -70) + cl.viewangles[PITCH] = -70; + } + else + { + if ((in_strafe.state & 1) && noclip_anglehack) +/* cmd->upmove -= m_forward.value * mouse_y; + CVAR_FIXME */ + cmd->upmove -= m_forward->value * mouse_y; + else +/* cmd->forwardmove -= m_forward.value * mouse_y; + CVAR_FIXME */ + cmd->forwardmove -= m_forward->value * mouse_y; + } +} + +void IN_Move (usercmd_t *cmd) +{ + IN_MouseMove(cmd); +} + +void VID_UnlockBuffer() {} +void VID_LockBuffer() {} + diff --git a/source/gl_vidlinux_svga.c b/source/gl_vidlinux_svga.c new file mode 100644 index 0000000..4d4ad53 --- /dev/null +++ b/source/gl_vidlinux_svga.c @@ -0,0 +1,907 @@ +/* + gl_vidlinux_svga.c + + (description) + + Copyright (C) 1996-1997 Id Software, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + + $Id$ +*/ + +#ifdef HAVE_CONFIG_H +# include +#endif +#include +#include +#include +#include +#include +#include +#include + +#include + +/*#include "vga.h" */ +#include "vgakeyboard.h" +#include "vgamouse.h" + +#include "quakedef.h" +#include "GL/fxmesa.h" + +#define WARP_WIDTH 320 +#define WARP_HEIGHT 200 + +static fxMesaContext fc = NULL; +#define stringify(m) { #m, m } + +unsigned short d_8to16table[256]; +unsigned d_8to24table[256]; +unsigned char d_15to8table[65536]; + +int num_shades=32; + +struct +{ + char *name; + int num; +} mice[] = +{ + stringify(MOUSE_MICROSOFT), + stringify(MOUSE_MOUSESYSTEMS), + stringify(MOUSE_MMSERIES), + stringify(MOUSE_LOGITECH), + stringify(MOUSE_BUSMOUSE), + stringify(MOUSE_PS2), +}; + +static unsigned char scantokey[128]; + +int num_mice = sizeof (mice) / sizeof(mice[0]); + +int d_con_indirect = 0; + +int svgalib_inited=0; +int UseMouse = 1; +int UseKeyboard = 1; + +int mouserate = MOUSE_DEFAULTSAMPLERATE; + +/* cvar_t vid_mode = {"vid_mode","5",false}; + CVAR_FIXME */ +cvar_t *vid_mode; +/* cvar_t vid_redrawfull = {"vid_redrawfull","0",false}; + CVAR_FIXME */ +cvar_t *vid_redrawfull; +/* cvar_t vid_waitforrefresh = {"vid_waitforrefresh","0",true}; + CVAR_FIXME */ +cvar_t *vid_waitforrefresh; + +char *framebuffer_ptr; + +cvar_t mouse_button_commands[3] = +{ + {"mouse1","+attack"}, + {"mouse2","+strafe"}, + {"mouse3","+forward"}, +}; + +int mouse_buttons; +int mouse_buttonstate; +int mouse_oldbuttonstate; +float mouse_x, mouse_y; +float old_mouse_x, old_mouse_y; +int mx, my; + +/* cvar_t _windowed_mouse = {"_windowed_mouse", "1", true}; + CVAR_FIXME */ +cvar_t *_windowed_mouse; +/* cvar_t m_filter = {"m_filter","0"}; + CVAR_FIXME */ +cvar_t *m_filter; + +int scr_width, scr_height; + +/*-----------------------------------------------------------------------*/ + +//int texture_mode = GL_NEAREST; +//int texture_mode = GL_NEAREST_MIPMAP_NEAREST; +//int texture_mode = GL_NEAREST_MIPMAP_LINEAR; +int texture_mode = GL_LINEAR; +//int texture_mode = GL_LINEAR_MIPMAP_NEAREST; +//int texture_mode = GL_LINEAR_MIPMAP_LINEAR; + +int texture_extension_number = 1; + +float gldepthmin, gldepthmax; + +/* cvar_t gl_ztrick = {"gl_ztrick","1"}; + CVAR_FIXME */ +cvar_t *gl_ztrick; + +const char *gl_vendor; +const char *gl_renderer; +const char *gl_version; +const char *gl_extensions; + +qboolean is8bit = false; +qboolean isPermedia = false; +qboolean gl_mtexable = false; + +/*-----------------------------------------------------------------------*/ +void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height) +{ +} + +void D_EndDirectRect (int x, int y, int width, int height) +{ +} + +/* +================= +VID_Gamma_f + +Keybinding command +================= +*/ +void VID_Gamma_f (void) +{ + float gamma, f, inf; + unsigned char palette[768]; + int i; + + if (Cmd_Argc () == 2) + { + gamma = atof (Cmd_Argv(1)); + + for (i=0 ; i<768 ; i++) + { + f = pow ( (host_basepal[i]+1)/256.0 , gamma ); + inf = f*255 + 0.5; + if (inf < 0) + inf = 0; + if (inf > 255) + inf = 255; + palette[i] = inf; + } + + VID_SetPalette (palette); + + vid.recalc_refdef = 1; // force a surface cache flush + } +} + +int matchmouse(int mouse, char *name) +{ + int i; + for (i=0 ; i> 2)+4; + b = ((i & 0x7C00) >> 7)+4; + pal = (unsigned char *)d_8to24table; + for (v=0,k=0,bestdist=10000.0; v<256; v++,pal+=4) { + r1 = (int)r - (int)pal[0]; + g1 = (int)g - (int)pal[1]; + b1 = (int)b - (int)pal[2]; + dist = sqrt(((r1*r1)+(g1*g1)+(b1*b1))); + if (dist < bestdist) { + k=v; + bestdist = dist; + } + } + d_15to8table[i]=k; + } + snprintf (s, sizeof(s), "%s/glquake", com_gamedir); + Sys_mkdir (s); + snprintf (s, sizeof(s), "%s/glquake/15to8.pal", com_gamedir); + if ((f = fopen(s, "wb")) != NULL) { + fwrite(d_15to8table, 1<<15, 1, f); + fclose(f); + } + } +} + +/* +=============== +GL_Init +=============== +*/ +void GL_Init (void) +{ + gl_vendor = glGetString (GL_VENDOR); + Con_Printf ("GL_VENDOR: %s\n", gl_vendor); + gl_renderer = glGetString (GL_RENDERER); + Con_Printf ("GL_RENDERER: %s\n", gl_renderer); + + gl_version = glGetString (GL_VERSION); + Con_Printf ("GL_VERSION: %s\n", gl_version); + gl_extensions = glGetString (GL_EXTENSIONS); + Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions); + +// Con_Printf ("%s %s\n", gl_renderer, gl_version); + + glClearColor (1,0,0,0); + glCullFace(GL_FRONT); + glEnable(GL_TEXTURE_2D); + + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.666); + + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + glShadeModel (GL_FLAT); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + +// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); +} + +/* +================= +GL_BeginRendering + +================= +*/ +void GL_BeginRendering (int *x, int *y, int *width, int *height) +{ +/* extern cvar_t gl_clear; + CVAR_FIXME */ + extern cvar_t *gl_clear; + + *x = *y = 0; + *width = scr_width; + *height = scr_height; + +// if (!wglMakeCurrent( maindc, baseRC )) +// Sys_Error ("wglMakeCurrent failed"); + +// glViewport (*x, *y, *width, *height); +} + + +void GL_EndRendering (void) +{ + glFlush(); + fxMesaSwapBuffers(); +} + +void Init_KBD(void) +{ + int i; + + if (COM_CheckParm("-nokbd")) UseKeyboard = 0; + + if (UseKeyboard) + { + for (i=0 ; i<128 ; i++) + scantokey[i] = ' '; + + scantokey[ 1] = K_ESCAPE; + scantokey[ 2] = '1'; + scantokey[ 3] = '2'; + scantokey[ 4] = '3'; + scantokey[ 5] = '4'; + scantokey[ 6] = '5'; + scantokey[ 7] = '6'; + scantokey[ 8] = '7'; + scantokey[ 9] = '8'; + scantokey[ 10] = '9'; + scantokey[ 11] = '0'; + scantokey[ 12] = '-'; + scantokey[ 13] = '='; + scantokey[ 14] = K_BACKSPACE; + scantokey[ 15] = K_TAB; + scantokey[ 16] = 'q'; + scantokey[ 17] = 'w'; + scantokey[ 18] = 'e'; + scantokey[ 19] = 'r'; + scantokey[ 20] = 't'; + scantokey[ 21] = 'y'; + scantokey[ 22] = 'u'; + scantokey[ 23] = 'i'; + scantokey[ 24] = 'o'; + scantokey[ 25] = 'p'; + scantokey[ 26] = '['; + scantokey[ 27] = ']'; + scantokey[ 28] = K_ENTER; + scantokey[ 29] = K_CTRL; //left + scantokey[ 30] = 'a'; + scantokey[ 31] = 's'; + scantokey[ 32] = 'd'; + scantokey[ 33] = 'f'; + scantokey[ 34] = 'g'; + scantokey[ 35] = 'h'; + scantokey[ 36] = 'j'; + scantokey[ 37] = 'k'; + scantokey[ 38] = 'l'; + scantokey[ 39] = ';'; + scantokey[ 40] = '\''; + scantokey[ 41] = '`'; + scantokey[ 42] = K_SHIFT; //left + scantokey[ 43] = '\\'; + scantokey[ 44] = 'z'; + scantokey[ 45] = 'x'; + scantokey[ 46] = 'c'; + scantokey[ 47] = 'v'; + scantokey[ 48] = 'b'; + scantokey[ 49] = 'n'; + scantokey[ 50] = 'm'; + scantokey[ 51] = ','; + scantokey[ 52] = '.'; + scantokey[ 53] = '/'; + scantokey[ 54] = K_SHIFT; //right + scantokey[ 55] = '*'; //keypad + scantokey[ 56] = K_ALT; //left + scantokey[ 57] = ' '; + // 58 caps lock + scantokey[ 59] = K_F1; + scantokey[ 60] = K_F2; + scantokey[ 61] = K_F3; + scantokey[ 62] = K_F4; + scantokey[ 63] = K_F5; + scantokey[ 64] = K_F6; + scantokey[ 65] = K_F7; + scantokey[ 66] = K_F8; + scantokey[ 67] = K_F9; + scantokey[ 68] = K_F10; + // 69 numlock + // 70 scrollock + scantokey[ 71] = K_HOME; + scantokey[ 72] = K_UPARROW; + scantokey[ 73] = K_PGUP; + scantokey[ 74] = '-'; + scantokey[ 75] = K_LEFTARROW; + scantokey[ 76] = '5'; + scantokey[ 77] = K_RIGHTARROW; + scantokey[ 79] = K_END; + scantokey[ 78] = '+'; + scantokey[ 80] = K_DOWNARROW; + scantokey[ 81] = K_PGDN; + scantokey[ 82] = K_INS; + scantokey[ 83] = K_DEL; + // 84 to 86 not used + scantokey[ 87] = K_F11; + scantokey[ 88] = K_F12; + // 89 to 95 not used + scantokey[ 96] = K_ENTER; //keypad enter + scantokey[ 97] = K_CTRL; //right + scantokey[ 98] = '/'; + scantokey[ 99] = K_F12; // print screen, bind to screenshot by default + scantokey[100] = K_ALT; // right + + + scantokey[101] = K_PAUSE; // break + scantokey[102] = K_HOME; + scantokey[103] = K_UPARROW; + scantokey[104] = K_PGUP; + scantokey[105] = K_LEFTARROW; + scantokey[106] = K_RIGHTARROW; + scantokey[107] = K_END; + scantokey[108] = K_DOWNARROW; + scantokey[109] = K_PGDN; + scantokey[110] = K_INS; + scantokey[111] = K_DEL; + + scantokey[119] = K_PAUSE; + + if (keyboard_init()) + Sys_Error("keyboard_init() failed"); + keyboard_seteventhandler(keyhandler); + } +} + +#define NUM_RESOLUTIONS 3 + +static resolutions[NUM_RESOLUTIONS][3]={ + { 512, 384, GR_RESOLUTION_512x384 }, + { 640, 400, GR_RESOLUTION_640x400 }, + { 640, 480, GR_RESOLUTION_640x480 } +}; + +int findres(int *width, int *height) +{ + int i; + + for(i=0;i height) + vid.conheight = height; + if (vid.conwidth > width) + vid.conwidth = width; + vid.width = vid.conwidth; + vid.height = vid.conheight; + + vid.aspect = ((float)vid.height / (float)vid.width) * + (320.0 / 240.0); + vid.numpages = 2; + + InitSig(); // trap evil signals + + GL_Init(); + + snprintf (gldir, sizeof(gldir), "%s/glquake", com_gamedir); + Sys_mkdir (gldir); + + VID_SetPalette(palette); + + // Check for 3DFX Extensions and initialize them. + VID_Init8bitPalette(); + + Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height); + + vid.recalc_refdef = 1; // force a surface cache flush +} + +void Sys_SendKeyEvents(void) +{ + if (UseKeyboard) + while (keyboard_update()); +} + +void Force_CenterView_f (void) +{ + cl.viewangles[PITCH] = 0; +} + + +void mousehandler(int buttonstate, int dx, int dy) +{ + mouse_buttonstate = buttonstate; + mx += dx; + my += dy; +} + +void IN_Init(void) +{ + + int mtype; + char *mousedev; + int mouserate; + + if (UseMouse) + { + + Cvar_RegisterVariable (&mouse_button_commands[0]); + Cvar_RegisterVariable (&mouse_button_commands[1]); + Cvar_RegisterVariable (&mouse_button_commands[2]); + Cmd_AddCommand ("force_centerview", Force_CenterView_f); + + mouse_buttons = 3; + + mtype = vga_getmousetype(); + + mousedev = "/dev/mouse"; + if (getenv("MOUSEDEV")) mousedev = getenv("MOUSEDEV"); + if (COM_CheckParm("-mdev")) + mousedev = com_argv[COM_CheckParm("-mdev")+1]; + + mouserate = 1200; + if (getenv("MOUSERATE")) mouserate = atoi(getenv("MOUSERATE")); + if (COM_CheckParm("-mrate")) + mouserate = atoi(com_argv[COM_CheckParm("-mrate")+1]); + + if (mouse_init(mousedev, mtype, mouserate)) + { + Con_Printf("No mouse found\n"); + UseMouse = 0; + } + else + mouse_seteventhandler(mousehandler); + + } + +} + +void IN_Shutdown(void) +{ + if (UseMouse) + mouse_close(); +} + +/* +=========== +IN_Commands +=========== +*/ +void IN_Commands (void) +{ + if (UseMouse) + { + // poll mouse values + while (mouse_update()) + ; + + // perform button actions + if ((mouse_buttonstate & MOUSE_LEFTBUTTON) && + !(mouse_oldbuttonstate & MOUSE_LEFTBUTTON)) + Key_Event (K_MOUSE1, true); + else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) && + (mouse_oldbuttonstate & MOUSE_LEFTBUTTON)) + Key_Event (K_MOUSE1, false); + + if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) && + !(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON)) + Key_Event (K_MOUSE2, true); + else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) && + (mouse_oldbuttonstate & MOUSE_RIGHTBUTTON)) + Key_Event (K_MOUSE2, false); + + if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) && + !(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON)) + Key_Event (K_MOUSE3, true); + else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) && + (mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON)) + Key_Event (K_MOUSE3, false); + + mouse_oldbuttonstate = mouse_buttonstate; + } +} + +/* +=========== +IN_Move +=========== +*/ +void IN_MouseMove (usercmd_t *cmd) +{ + if (!UseMouse) + return; + + // poll mouse values + while (mouse_update()) + ; + +/* if (m_filter.value) + CVAR_FIXME */ + if (m_filter->value) + { + mouse_x = (mx + old_mouse_x) * 0.5; + mouse_y = (my + old_mouse_y) * 0.5; + } + else + { + mouse_x = mx; + mouse_y = my; + } + old_mouse_x = mx; + old_mouse_y = my; + mx = my = 0; // clear for next update + +/* mouse_x *= sensitivity.value; + CVAR_FIXME */ + mouse_x *= sensitivity->value; +/* mouse_y *= sensitivity.value; + CVAR_FIXME */ + mouse_y *= sensitivity->value; + +// add mouse X/Y movement to cmd +/* if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) )) + CVAR_FIXME */ + if ( (in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1) )) +/* cmd->sidemove += m_side.value * mouse_x; + CVAR_FIXME */ + cmd->sidemove += m_side->value * mouse_x; + else +/* cl.viewangles[YAW] -= m_yaw.value * mouse_x; + CVAR_FIXME */ + cl.viewangles[YAW] -= m_yaw->value * mouse_x; + + if (in_mlook.state & 1) + V_StopPitchDrift (); + + if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) + { +/* cl.viewangles[PITCH] += m_pitch.value * mouse_y; + CVAR_FIXME */ + cl.viewangles[PITCH] += m_pitch->value * mouse_y; + if (cl.viewangles[PITCH] > 80) + cl.viewangles[PITCH] = 80; + if (cl.viewangles[PITCH] < -70) + cl.viewangles[PITCH] = -70; + } + else + { + if ((in_strafe.state & 1) && noclip_anglehack) +/* cmd->upmove -= m_forward.value * mouse_y; + CVAR_FIXME */ + cmd->upmove -= m_forward->value * mouse_y; + else +/* cmd->forwardmove -= m_forward.value * mouse_y; + CVAR_FIXME */ + cmd->forwardmove -= m_forward->value * mouse_y; + } +} + +void IN_Move (usercmd_t *cmd) +{ + IN_MouseMove(cmd); +} + + +void VID_LockBuffer (void) {} +void VID_UnlockBuffer (void) {} + diff --git a/source/gl_vidlinux_x11.c b/source/gl_vidlinux_x11.c new file mode 100644 index 0000000..0c52645 --- /dev/null +++ b/source/gl_vidlinux_x11.c @@ -0,0 +1,926 @@ +/* + gl_vidlinux_x11.c + + (description) + + Copyright (C) 1996-1997 Id Software, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + + $Id$ +*/ + +#ifdef HAVE_CONFIG_H +# include +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +//#include +#include +#include +#include +#include + +#include "GL/gl.h" +#include "GL/glx.h" + +#include "quakedef.h" + +#define WARP_WIDTH 320 +#define WARP_HEIGHT 200 + +static Display *dpy = NULL; +static Window win; +static GLXContext ctx = NULL; + +unsigned short d_8to16table[256]; +unsigned int d_8to24table[256]; +unsigned char d_15to8table[65536]; + +static qboolean usedga = false; + +#define stringify(m) { #m, m } + +/* cvar_t vid_mode = {"vid_mode","0",false}; + CVAR_FIXME */ +cvar_t *vid_mode; + +cvar_t mouse_button_commands[3] = +{ + {"mouse1","+attack"}, + {"mouse2","+strafe"}, + {"mouse3","+forward"}, +}; + +static int mouse_buttons=3; +static int mouse_buttonstate; +static int mouse_oldbuttonstate; +static float mouse_x, mouse_y; +static float p_mouse_x, p_mouse_y; +static float old_mouse_x, old_mouse_y; + +/* cvar_t _windowed_mouse = {"_windowed_mouse", "1", true}; + CVAR_FIXME */ +cvar_t *_windowed_mouse; +/* cvar_t m_filter = {"m_filter","0"}; + CVAR_FIXME */ +cvar_t *m_filter; +static float old_windowed_mouse; + +static int scr_width, scr_height; + +#define KEY_MASK (KeyPressMask | KeyReleaseMask) +#define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | \ + PointerMotionMask | ButtonMotionMask) + +/*-----------------------------------------------------------------------*/ + +//int texture_mode = GL_NEAREST; +//int texture_mode = GL_NEAREST_MIPMAP_NEAREST; +//int texture_mode = GL_NEAREST_MIPMAP_LINEAR; +int texture_mode = GL_LINEAR; +//int texture_mode = GL_LINEAR_MIPMAP_NEAREST; +//int texture_mode = GL_LINEAR_MIPMAP_LINEAR; + +int texture_extension_number = 1; + +float gldepthmin, gldepthmax; + +/* cvar_t gl_ztrick = {"gl_ztrick","1"}; + CVAR_FIXME */ +cvar_t *gl_ztrick; + +const char *gl_vendor; +const char *gl_renderer; +const char *gl_version; +const char *gl_extensions; + +qboolean is8bit = false; +qboolean isPermedia = false; +qboolean gl_mtexable = false; + +/*-----------------------------------------------------------------------*/ +void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height) +{ +} + +void D_EndDirectRect (int x, int y, int width, int height) +{ +} + +/* +================= +VID_Gamma_f + +Keybinding command +================= +*/ +void VID_Gamma_f (void) +{ + float gamma, f, inf; + unsigned char palette[768]; + int i; + + if (Cmd_Argc () == 2) + { + gamma = atof (Cmd_Argv(1)); + + for (i=0 ; i<768 ; i++) + { + f = pow ( (host_basepal[i]+1)/256.0 , gamma ); + inf = f*255 + 0.5; + if (inf < 0) + inf = 0; + if (inf > 255) + inf = 255; + palette[i] = inf; + } + + VID_SetPalette (palette); + + vid.recalc_refdef = 1; // force a surface cache flush + } +} + +void VID_Shutdown(void) +{ + if (!ctx) + return; + + XUngrabPointer(dpy,CurrentTime); + XUngrabKeyboard(dpy,CurrentTime); + + glXDestroyContext(dpy,ctx); + +#ifdef USE_DGA + if (usedga) + XF86DGADirectVideo(dpy,DefaultScreen(dpy),0); +#endif +} + +int XLateKey(XKeyEvent *ev) +{ + + int key; + char buf[64]; + KeySym keysym; + + key = 0; + + XLookupString(ev, buf, sizeof buf, &keysym, 0); + + switch(keysym) + { + case XK_KP_Page_Up: + case XK_Page_Up: key = K_PGUP; break; + + case XK_KP_Page_Down: + case XK_Page_Down: key = K_PGDN; break; + + case XK_KP_Home: + case XK_Home: key = K_HOME; break; + + case XK_KP_End: + case XK_End: key = K_END; break; + + case XK_KP_Left: + case XK_Left: key = K_LEFTARROW; break; + + case XK_KP_Right: + case XK_Right: key = K_RIGHTARROW; break; + + case XK_KP_Down: + case XK_Down: key = K_DOWNARROW; break; + + case XK_KP_Up: + case XK_Up: key = K_UPARROW; break; + + case XK_Escape: key = K_ESCAPE; break; + + case XK_KP_Enter: + case XK_Return: key = K_ENTER; break; + + case XK_Tab: key = K_TAB; break; + + case XK_F1: key = K_F1; break; + + case XK_F2: key = K_F2; break; + + case XK_F3: key = K_F3; break; + + case XK_F4: key = K_F4; break; + + case XK_F5: key = K_F5; break; + + case XK_F6: key = K_F6; break; + + case XK_F7: key = K_F7; break; + + case XK_F8: key = K_F8; break; + + case XK_F9: key = K_F9; break; + + case XK_F10: key = K_F10; break; + + case XK_F11: key = K_F11; break; + + case XK_F12: key = K_F12; break; + + case XK_BackSpace: key = K_BACKSPACE; break; + + case XK_KP_Delete: + case XK_Delete: key = K_DEL; break; + + case XK_Pause: key = K_PAUSE; break; + + case XK_Shift_L: + case XK_Shift_R: key = K_SHIFT; break; + + case XK_Execute: + case XK_Control_L: + case XK_Control_R: key = K_CTRL; break; + + case XK_Alt_L: + case XK_Meta_L: + case XK_Alt_R: + case XK_Meta_R: key = K_ALT; break; + + case XK_KP_Begin: key = K_AUX30; break; + + case XK_Insert: + case XK_KP_Insert: key = K_INS; break; + + case XK_KP_Multiply: key = '*'; break; + case XK_KP_Add: key = '+'; break; + case XK_KP_Subtract: key = '-'; break; + case XK_KP_Divide: key = '/'; break; + +#if 0 + case 0x021: key = '1';break;/* [!] */ + case 0x040: key = '2';break;/* [@] */ + case 0x023: key = '3';break;/* [#] */ + case 0x024: key = '4';break;/* [$] */ + case 0x025: key = '5';break;/* [%] */ + case 0x05e: key = '6';break;/* [^] */ + case 0x026: key = '7';break;/* [&] */ + case 0x02a: key = '8';break;/* [*] */ + case 0x028: key = '9';;break;/* [(] */ + case 0x029: key = '0';break;/* [)] */ + case 0x05f: key = '-';break;/* [_] */ + case 0x02b: key = '=';break;/* [+] */ + case 0x07c: key = '\'';break;/* [|] */ + case 0x07d: key = '[';break;/* [}] */ + case 0x07b: key = ']';break;/* [{] */ + case 0x022: key = '\'';break;/* ["] */ + case 0x03a: key = ';';break;/* [:] */ + case 0x03f: key = '/';break;/* [?] */ + case 0x03e: key = '.';break;/* [>] */ + case 0x03c: key = ',';break;/* [<] */ +#endif + + default: + key = *(unsigned char*)buf; + if (key >= 'A' && key <= 'Z') + key = key - 'A' + 'a'; +// fprintf(stdout, "case 0x0%x: key = ___;break;/* [%c] */\n", keysym); + break; + } + + return key; +} + +struct +{ + int key; + int down; +} keyq[64]; +int keyq_head=0; +int keyq_tail=0; + +int config_notify=0; +int config_notify_width; +int config_notify_height; + +qboolean Keyboard_Update(void) +{ + XEvent x_event; + + if(!XCheckMaskEvent(dpy,KEY_MASK,&x_event)) + return false; + + switch(x_event.type) { + case KeyPress: + keyq[keyq_head].key = XLateKey(&x_event.xkey); + keyq[keyq_head].down = true; + keyq_head = (keyq_head + 1) & 63; + break; + case KeyRelease: + keyq[keyq_head].key = XLateKey(&x_event.xkey); + keyq[keyq_head].down = false; + keyq_head = (keyq_head + 1) & 63; + break; + } + + return true; +} + +qboolean Mouse_Update(void) +{ + XEvent x_event; + int b; + + if(!XCheckMaskEvent(dpy,MOUSE_MASK,&x_event)) + return false; + + switch(x_event.type) { + case MotionNotify: + if (usedga) { + mouse_x += x_event.xmotion.x_root; + mouse_y += x_event.xmotion.y_root; +/* } else if (_windowed_mouse.value) { + CVAR_FIXME */ + } else if (_windowed_mouse->value) { + mouse_x += (float) ((int)x_event.xmotion.x - (int)(scr_width/2)); + mouse_y += (float) ((int)x_event.xmotion.y - (int)(scr_height/2)); + + /* move the mouse to the window center again */ + XSelectInput(dpy,win, (KEY_MASK | MOUSE_MASK) & ~PointerMotionMask); + XWarpPointer(dpy,None,win,0,0,0,0, (scr_width/2),(scr_height/2)); + XSelectInput(dpy,win, KEY_MASK | MOUSE_MASK); + } else { + mouse_x = (float) (x_event.xmotion.x-p_mouse_x); + mouse_y = (float) (x_event.xmotion.y-p_mouse_y); + p_mouse_x=x_event.xmotion.x; + p_mouse_y=x_event.xmotion.y; + } + break; + + case ButtonPress: + b=-1; + if (x_event.xbutton.button == 1) + b = 0; + else if (x_event.xbutton.button == 2) + b = 2; + else if (x_event.xbutton.button == 3) + b = 1; + if (b>=0) + mouse_buttonstate |= 1<=0) + mouse_buttonstate &= ~(1<value) { +/* old_windowed_mouse = _windowed_mouse.value; + CVAR_FIXME */ + old_windowed_mouse = _windowed_mouse->value; + +/* if (!_windowed_mouse.value) { + CVAR_FIXME */ + if (!_windowed_mouse->value) { + /* ungrab the pointer */ + Con_Printf("Releasing mouse.\n"); + + XUngrabPointer(dpy,CurrentTime); + XUngrabKeyboard(dpy,CurrentTime); + } else { + /* grab the pointer */ + Con_Printf("Grabbing mouse.\n"); + + XGrabPointer(dpy,win,False,MOUSE_MASK,GrabModeAsync, + GrabModeAsync,win,None,CurrentTime); + XWarpPointer(dpy,None,win, 0,0,0,0, scr_width/2, scr_height/2); + XGrabKeyboard(dpy,win, + False, + GrabModeAsync,GrabModeAsync, + CurrentTime); + + //XSync(dpy,True); + } + } + return true; +} + +void signal_handler(int sig) +{ + printf("Received signal %d, exiting...\n", sig); + VID_Shutdown(); + exit(0); +} + +void InitSig(void) +{ + signal(SIGHUP, signal_handler); + signal(SIGQUIT, signal_handler); + signal(SIGILL, signal_handler); + signal(SIGTRAP, signal_handler); + signal(SIGIOT, signal_handler); + signal(SIGBUS, signal_handler); + signal(SIGFPE, signal_handler); + signal(SIGSEGV, signal_handler); + signal(SIGTERM, signal_handler); +} + +void VID_ShiftPalette(unsigned char *p) +{ + VID_SetPalette(p); +} + +void VID_SetPalette (unsigned char *palette) +{ + byte *pal; + unsigned short r,g,b; + int v; + int r1,g1,b1; + int k; + unsigned short i; + unsigned *table; + FILE *f; + char s[255]; + float dist, bestdist; + static qboolean palflag = false; + +// +// 8 8 8 encoding +// + pal = palette; + table = d_8to24table; + for (i=0 ; i<256 ; i++) + { + r = pal[0]; + g = pal[1]; + b = pal[2]; + pal += 3; + +// v = (255<<24) + (r<<16) + (g<<8) + (b<<0); +// v = (255<<0) + (r<<8) + (g<<16) + (b<<24); + v = (255<<24) + (r<<0) + (g<<8) + (b<<16); + *table++ = v; + } + d_8to24table[255] &= 0xffffff; // 255 is transparent + + // JACK: 3D distance calcs - k is last closest, l is the distance. + // FIXME: Precalculate this and cache to disk. + if (palflag) + return; + palflag = true; + + COM_FOpenFile("glquake/15to8.pal", &f); + if (f) { + fread(d_15to8table, 1<<15, 1, f); + fclose(f); + } else { + for (i=0; i < (1<<15); i++) { + /* Maps + 000000000000000 + 000000000011111 = Red = 0x1F + 000001111100000 = Blue = 0x03E0 + 111110000000000 = Grn = 0x7C00 + */ + r = ((i & 0x1F) << 3)+4; + g = ((i & 0x03E0) >> 2)+4; + b = ((i & 0x7C00) >> 7)+4; + pal = (unsigned char *)d_8to24table; + for (v=0,k=0,bestdist=10000.0; v<256; v++,pal+=4) { + r1 = (int)r - (int)pal[0]; + g1 = (int)g - (int)pal[1]; + b1 = (int)b - (int)pal[2]; + dist = sqrt(((r1*r1)+(g1*g1)+(b1*b1))); + if (dist < bestdist) { + k=v; + bestdist = dist; + } + } + d_15to8table[i]=k; + } + snprintf (s, sizeof(s), "%s/glquake", com_gamedir); + Sys_mkdir (s); + snprintf(s, sizeof(s), "%s/glquake/15to8.pal", com_gamedir); + if ((f = fopen(s, "wb")) != NULL) { + fwrite(d_15to8table, 1<<15, 1, f); + fclose(f); + } + } +} + +/* +=============== +GL_Init +=============== +*/ +void GL_Init (void) +{ + gl_vendor = glGetString (GL_VENDOR); + Con_Printf ("GL_VENDOR: %s\n", gl_vendor); + gl_renderer = glGetString (GL_RENDERER); + Con_Printf ("GL_RENDERER: %s\n", gl_renderer); + + gl_version = glGetString (GL_VERSION); + Con_Printf ("GL_VERSION: %s\n", gl_version); + gl_extensions = glGetString (GL_EXTENSIONS); + Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions); + +// Con_Printf ("%s %s\n", gl_renderer, gl_version); + + glClearColor (1,0,0,0); + glCullFace(GL_FRONT); + glEnable(GL_TEXTURE_2D); + + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.666); + + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + glShadeModel (GL_FLAT); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + +// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); +} + +/* +================= +GL_BeginRendering + +================= +*/ +void GL_BeginRendering (int *x, int *y, int *width, int *height) +{ +/* extern cvar_t gl_clear; + CVAR_FIXME */ + extern cvar_t *gl_clear; + + *x = *y = 0; + *width = scr_width; + *height = scr_height; + +// if (!wglMakeCurrent( maindc, baseRC )) +// Sys_Error ("wglMakeCurrent failed"); + +// glViewport (*x, *y, *width, *height); +} + + +void GL_EndRendering (void) +{ + glFlush(); + glXSwapBuffers(dpy,win); +} + +qboolean VID_Is8bit(void) +{ + return is8bit; +} + +#ifdef GL_EXT_SHARED +void VID_Init8bitPalette() +{ + // Check for 8bit Extensions and initialize them. + int i; + char thePalette[256*3]; + char *oldPalette, *newPalette; + + if (strstr(gl_extensions, "GL_EXT_shared_texture_palette") == NULL) + return; + + Con_SafePrintf("8-bit GL extensions enabled.\n"); + glEnable( GL_SHARED_TEXTURE_PALETTE_EXT ); + oldPalette = (char *) d_8to24table; //d_8to24table3dfx; + newPalette = thePalette; + for (i=0;i<256;i++) { + *newPalette++ = *oldPalette++; + *newPalette++ = *oldPalette++; + *newPalette++ = *oldPalette++; + oldPalette++; + } + glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, (void *) thePalette); + is8bit = true; +} + +#else +extern void gl3DfxSetPaletteEXT(GLuint *pal); + +void VID_Init8bitPalette(void) +{ + // Check for 8bit Extensions and initialize them. + int i; + GLubyte table[256][4]; + char *oldpal; + + if (strstr(gl_extensions, "3DFX_set_global_palette") == NULL) + return; + + Con_SafePrintf("8-bit GL extensions enabled.\n"); + glEnable( GL_SHARED_TEXTURE_PALETTE_EXT ); + oldpal = (char *) d_8to24table; //d_8to24table3dfx; + for (i=0;i<256;i++) { + table[i][2] = *oldpal++; + table[i][1] = *oldpal++; + table[i][0] = *oldpal++; + table[i][3] = 255; + oldpal++; + } + gl3DfxSetPaletteEXT((GLuint *)table); + is8bit = true; +} +#endif + +void VID_Init(unsigned char *palette) +{ + int i; + char gldir[MAX_OSPATH]; + int width = 640, height = 480; + int attrib[] = { + GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 1, + None }; + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + XVisualInfo *visinfo; + +// S_Init(); + +/* Cvar_RegisterVariable (&vid_mode); + CVAR_FIXME */ + vid_mode = Cvar_Get("vid_mode", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&gl_ztrick); + CVAR_FIXME */ + gl_ztrick = Cvar_Get("gl_ztrick", "1", CVAR_NONE, "None"); + + vid.maxwarpwidth = WARP_WIDTH; + vid.maxwarpheight = WARP_HEIGHT; + vid.colormap = host_colormap; + vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048)); + +// interpret command-line params + +// set vid parameters + + if ((i = COM_CheckParm("-width")) != 0) + width = atoi(com_argv[i+1]); + if ((i = COM_CheckParm("-height")) != 0) + height = atoi(com_argv[i+1]); + + if ((i = COM_CheckParm("-conwidth")) != 0) + vid.conwidth = atoi(com_argv[i+1]); + else + vid.conwidth = 640; + + vid.conwidth &= 0xfff8; // make it a multiple of eight + + if (vid.conwidth < 320) + vid.conwidth = 320; + + // pick a conheight that matches with correct aspect + vid.conheight = vid.conwidth*3 / 4; + + if ((i = COM_CheckParm("-conheight")) != 0) + vid.conheight = atoi(com_argv[i+1]); + if (vid.conheight < 200) + vid.conheight = 200; + + if (!(dpy = XOpenDisplay(NULL))) { + fprintf(stderr, "Error couldn't open the X display\n"); + exit(1); + } + + scrnum = DefaultScreen(dpy); + root = RootWindow(dpy, scrnum); + + visinfo=glXChooseVisual(dpy,scrnum,attrib); + if (!visinfo) { + fprintf(stderr, "Error couldn't get an RGB, Double-buffered, Depth visual\n"); + exit(1); + } + + /* window attributes */ + attr.background_pixel=0; + attr.border_pixel=0; + attr.colormap=XCreateColormap(dpy,root,visinfo->visual,AllocNone); + attr.event_mask=KEY_MASK|MOUSE_MASK|VisibilityChangeMask; + mask=CWBackPixel|CWBorderPixel|CWColormap|CWEventMask; + + win=XCreateWindow(dpy,root,0,0,width,height, + 0,visinfo->depth,InputOutput, + visinfo->visual,mask,&attr); + XMapWindow(dpy,win); + + XMoveWindow(dpy,win,0,0); + + XFlush(dpy); + + if (COM_CheckParm("-window")) + putenv("MESA_GLX_FX=window"); + else + putenv("MESA_GLX_FX=fullscreen"); + + ctx = glXCreateContext(dpy,visinfo,NULL,True); + + if (!ctx) { + fprintf(stderr, "Unable to create glX context.\n"); + exit(1); + } + + glXMakeCurrent(dpy,win,ctx); + + scr_width = width; + scr_height = height; + + if (vid.conheight > height) + vid.conheight = height; + if (vid.conwidth > width) + vid.conwidth = width; + vid.width = vid.conwidth; + vid.height = vid.conheight; + + vid.aspect = ((float)vid.height / (float)vid.width) * + (320.0 / 240.0); + vid.numpages = 2; + + InitSig(); // trap evil signals + + GL_Init(); + + snprintf (gldir, sizeof(gldir), "%s/glquake", com_gamedir); + Sys_mkdir (gldir); + + VID_SetPalette(palette); + + // Check for 3DFX Extensions and initialize them. + VID_Init8bitPalette(); + + Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height); + + vid.recalc_refdef = 1; // force a surface cache flush +} + +void Sys_SendKeyEvents(void) +{ + if (dpy) + { + while (Keyboard_Update()) + ; + + while (keyq_head != keyq_tail) + { + Key_Event(keyq[keyq_tail].key, keyq[keyq_tail].down); + keyq_tail = (keyq_tail + 1) & 63; + } + } +} + +void Force_CenterView_f (void) +{ + cl.viewangles[PITCH] = 0; +} + + +void IN_Init(void) +{ +/* Cvar_RegisterVariable (&_windowed_mouse); + CVAR_FIXME */ + _windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None"); +/* Cvar_RegisterVariable (&m_filter); + CVAR_FIXME */ + m_filter = Cvar_Get("m_filter", "0", CVAR_NONE, "None"); + Cvar_RegisterVariable (&mouse_button_commands[0]); + Cvar_RegisterVariable (&mouse_button_commands[1]); + Cvar_RegisterVariable (&mouse_button_commands[2]); + Cmd_AddCommand ("force_centerview", Force_CenterView_f); +} + +void IN_Shutdown(void) +{ +} + +/* +=========== +IN_Commands +=========== +*/ +void IN_Commands (void) +{ + int i; + + for (i=0 ; ivalue) { + mouse_x = (mouse_x + old_mouse_x) * 0.5; + mouse_y = (mouse_y + old_mouse_y) * 0.5; + } + + old_mouse_x = mouse_x; + old_mouse_y = mouse_y; + +/* mouse_x *= sensitivity.value; + CVAR_FIXME */ + mouse_x *= sensitivity->value; +/* mouse_y *= sensitivity.value; + CVAR_FIXME */ + mouse_y *= sensitivity->value; + +/* if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) )) + CVAR_FIXME */ + if ( (in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1) )) +/* cmd->sidemove += m_side.value * mouse_x; + CVAR_FIXME */ + cmd->sidemove += m_side->value * mouse_x; + else +/* cl.viewangles[YAW] -= m_yaw.value * mouse_x; + CVAR_FIXME */ + cl.viewangles[YAW] -= m_yaw->value * mouse_x; + if (in_mlook.state & 1) + V_StopPitchDrift (); + + if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) { +/* cl.viewangles[PITCH] += m_pitch.value * mouse_y; + CVAR_FIXME */ + cl.viewangles[PITCH] += m_pitch->value * mouse_y; + if (cl.viewangles[PITCH] > 80) + cl.viewangles[PITCH] = 80; + if (cl.viewangles[PITCH] < -70) + cl.viewangles[PITCH] = -70; + } else { + if ((in_strafe.state & 1) && noclip_anglehack) +/* cmd->upmove -= m_forward.value * mouse_y; + CVAR_FIXME */ + cmd->upmove -= m_forward->value * mouse_y; + else +/* cmd->forwardmove -= m_forward.value * mouse_y; + CVAR_FIXME */ + cmd->forwardmove -= m_forward->value * mouse_y; + } + mouse_x = mouse_y = 0.0; +} + + +void VID_LockBuffer (void) {} +void VID_UnlockBuffer (void) {} + diff --git a/source/in_win.c b/source/in_win.c index 18969ec..7980f63 100644 --- a/source/in_win.c +++ b/source/in_win.c @@ -1,7 +1,7 @@ /* in_win.c - windows 95 mouse and joystick code + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,7 +25,7 @@ $Id$ */ - +// in_win.c -- windows 95 mouse and joystick code // 02/21/97 JCB Added extended DirectInput code to support external controllers. #ifdef HAVE_CONFIG_H @@ -37,12 +37,7 @@ #include "quakedef.h" #include "winquake.h" #include -#include "client.h" -#include "keys.h" -#include "console.h" -#include "qargs.h" -#include "cmd.h" -#include "input.h" + //#include "dosisms.h" #define DINPUT_BUFFERSIZE 16 @@ -805,7 +800,7 @@ void IN_MouseMove (usercmd_t *cmd) // add mouse X/Y movement to cmd /* if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) )) CVAR_FIXME */ - if ( (in_strafe.state & 1) || (lookstrafe->value && freelook )) + if ( (in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1) )) /* cmd->sidemove += m_side.value * mouse_x; CVAR_FIXME */ cmd->sidemove += m_side->value * mouse_x; @@ -814,10 +809,10 @@ void IN_MouseMove (usercmd_t *cmd) CVAR_FIXME */ cl.viewangles[YAW] -= m_yaw->value * mouse_x; - if (freelook) + if (in_mlook.state & 1) V_StopPitchDrift (); - if ( freelook && !(in_strafe.state & 1)) + if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) { /* cl.viewangles[PITCH] += m_pitch.value * mouse_y; CVAR_FIXME */ @@ -918,7 +913,7 @@ static void IN_StartupJoystick (void) joy_avail = false; // abort startup if user requests no joystick - if ( COM_CheckParm ("-nojoy") ) + if ( COM_CheckParm ("-nojoy") ) return; // verify joystick driver is present @@ -951,7 +946,7 @@ static void IN_StartupJoystick (void) memset (&jc, 0, sizeof(jc)); if ((mmr = joyGetDevCaps (joy_id, &jc, sizeof(jc))) != JOYERR_NOERROR) { - Con_Printf ("\njoystick not found -- invalid joystick capabilities (%x)\n\n", mmr); + Con_Printf ("\njoystick not found -- invalid joystick capabilities (%x)\n\n", mmr); return; } @@ -968,7 +963,7 @@ static void IN_StartupJoystick (void) joy_avail = true; joy_advancedinit = false; - Con_Printf ("\njoystick detected\n\n"); + Con_Printf ("\njoystick detected\n\n"); } @@ -1265,7 +1260,7 @@ static void IN_JoyMove (usercmd_t *cmd) case AxisForward: /* if ((joy_advanced.value == 0.0) && (in_mlook.state & 1)) CVAR_FIXME */ - if ((joy_advanced->value == 0.0) && freelook) + if ((joy_advanced->value == 0.0) && (in_mlook.state & 1)) { // user wants forward control to become look control /* if (fabs(fAxisValue) > joy_pitchthreshold.value) @@ -1330,7 +1325,7 @@ static void IN_JoyMove (usercmd_t *cmd) case AxisTurn: /* if ((in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1))) CVAR_FIXME */ - if ((in_strafe.state & 1) || (lookstrafe->value && freelook)) + if ((in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1))) { // user wants turn control to become side control /* if (fabs(fAxisValue) > joy_sidethreshold.value) @@ -1367,7 +1362,7 @@ static void IN_JoyMove (usercmd_t *cmd) break; case AxisLook: - if (freelook) + if (in_mlook.state & 1) { /* if (fabs(fAxisValue) > joy_pitchthreshold.value) CVAR_FIXME */ diff --git a/source/keys.c b/source/keys.c index b9e1ddb..7cdefd9 100644 --- a/source/keys.c +++ b/source/keys.c @@ -26,26 +26,15 @@ $Id$ */ +#ifdef _WIN32 #ifdef HAVE_CONFIG_H # include #endif -#ifdef _WIN32 #include #endif -#include -#include - -#include "qtypes.h" #include "sys.h" -#include "keys.h" -#include "menu.h" -#include "cmd.h" -#include "zone.h" -#include "console.h" -#include "cvar.h" -#include "screen.h" -#include "client.h" +#include "quakedef.h" /* @@ -53,7 +42,6 @@ key up events are sent even if in console mode */ -cvar_t *cl_chatmode; #define MAXCMDLINE 256 char key_lines[32][MAXCMDLINE]; @@ -265,133 +253,113 @@ Interactive line editing and console scrollback */ void Key_Console (int key) { - int i; #ifdef _WIN32 +// char *cmd, *s; + int i; HANDLE th; char *clipText, *textCopied; #endif - - switch (key) - { - case K_ENTER: - // backslash text are commands - if (key_lines[edit_line][1] == '/' && key_lines[edit_line][2] == '/') - goto no_lf; - else if (key_lines[edit_line][1] == '\\' || key_lines[edit_line][1] == '/') - Cbuf_AddText (key_lines[edit_line]+2); // skip the ]/ - else if (cl_chatmode->value != 2 && CheckForCommand()) - Cbuf_AddText (key_lines[edit_line]+1); // valid command - else if ((cls.state >= ca_connected && cl_chatmode->value == 1) || cl_chatmode->value == 2) - { - if (cls.state < ca_connected) // can happen if cl_constyle == 2 - goto no_lf; // drop the whole line - - // convert to a chat message + + if (key == K_ENTER) + { // backslash text are commands, else chat + if (key_lines[edit_line][1] == '\\' || key_lines[edit_line][1] == '/') + Cbuf_AddText (key_lines[edit_line]+2); // skip the > + else if (CheckForCommand()) + Cbuf_AddText (key_lines[edit_line]+1); // valid command + else + { // convert to a chat message + if (cls.state >= ca_connected) Cbuf_AddText ("say "); - Cbuf_AddText (key_lines[edit_line]+1); - } - else - Cbuf_AddText (key_lines[edit_line]+1); // skip the ] + Cbuf_AddText (key_lines[edit_line]+1); // skip the > + } - Cbuf_AddText ("\n"); -no_lf: - Con_Printf ("%s\n",key_lines[edit_line]); - edit_line = (edit_line + 1) & 31; - history_line = edit_line; + Cbuf_AddText ("\n"); + Con_Printf ("%s\n",key_lines[edit_line]); + edit_line = (edit_line + 1) & 31; + history_line = edit_line; + key_lines[edit_line][0] = ']'; + key_linepos = 1; + if (cls.state == ca_disconnected) + SCR_UpdateScreen (); // force an update, because the command + // may take some time + return; + } + + if (key == K_TAB) + { // command completion + CompleteCommand (); + return; + } + + if (key == K_BACKSPACE || key == K_LEFTARROW) + { + if (key_linepos > 1) + key_linepos--; + return; + } + + if (key == K_UPARROW) + { + do + { + history_line = (history_line - 1) & 31; + } while (history_line != edit_line + && !key_lines[history_line][1]); + if (history_line == edit_line) + history_line = (edit_line+1)&31; + strcpy(key_lines[edit_line], key_lines[history_line]); + key_linepos = strlen(key_lines[edit_line]); + return; + } + + if (key == K_DOWNARROW) + { + if (history_line == edit_line) return; + do + { + history_line = (history_line + 1) & 31; + } + while (history_line != edit_line + && !key_lines[history_line][1]); + if (history_line == edit_line) + { key_lines[edit_line][0] = ']'; - key_lines[edit_line][1] = 0; key_linepos = 1; - if (cls.state == ca_disconnected) - SCR_UpdateScreen (); // force an update, because the command - // may take some time - return; - - case K_TAB: - // command completion - CompleteCommand (); - return; - - case K_BACKSPACE: - if (key_linepos > 1) - { - strcpy(key_lines[edit_line] + key_linepos - 1, key_lines[edit_line] + key_linepos); - key_linepos--; - } - return; - - case K_DEL: - if (key_linepos < strlen(key_lines[edit_line])) - strcpy(key_lines[edit_line] + key_linepos, key_lines[edit_line] + key_linepos + 1); - return; - - case K_RIGHTARROW: - if (key_linepos < strlen(key_lines[edit_line])) - key_linepos++; - return; - - case K_LEFTARROW: - if (key_linepos > 1) - key_linepos--; - return; - - case K_UPARROW: - do { - history_line = (history_line - 1) & 31; - } while (history_line != edit_line - && !key_lines[history_line][1]); - if (history_line == edit_line) - history_line = (edit_line+1)&31; + } + else + { strcpy(key_lines[edit_line], key_lines[history_line]); key_linepos = strlen(key_lines[edit_line]); - return; - - case K_DOWNARROW: - if (history_line == edit_line) return; - do { - history_line = (history_line + 1) & 31; - } while (history_line != edit_line - && !key_lines[history_line][1]); - - if (history_line == edit_line) { - key_lines[edit_line][0] = ']'; - key_lines[edit_line][1] = 0; - key_linepos = 1; - } else { - strcpy(key_lines[edit_line], key_lines[history_line]); - key_linepos = strlen(key_lines[edit_line]); - } - return; - - case K_MWHEELUP: - case K_PGUP: - if (con->display - con->current + con->numlines > 2) - con->display -= 2; - return; - - case K_MWHEELDOWN: - case K_PGDN: - con->display += 2; - if (con->display > con->current) - con->display = con->current; - return; - - case K_HOME: - if (keydown[K_CTRL]) - { - if (con->numlines > 10) - con->display = con->current - con->numlines + 10; - } - else - key_linepos = 1; - return; - - case K_END: - if (keydown[K_CTRL]) - con->display = con->current; - else - key_linepos = strlen(key_lines[edit_line]); - return; + } + return; } + + if (key == K_PGUP || key==K_MWHEELUP) + { + con->display -= 2; + return; + } + + if (key == K_PGDN || key==K_MWHEELDOWN) + { + con->display += 2; + if (con->display > con->current) + con->display = con->current; + return; + } + + if (key == K_HOME) + { + con->display = con->current - con_totallines + 10; + return; + } + + if (key == K_END) + { + con->display = con->current; + return; + } + #ifdef _WIN32 if ((key=='V' || key=='v') && GetKeyState(VK_CONTROL)<0) { if (OpenClipboard(NULL)) { @@ -403,14 +371,12 @@ no_lf: strcpy(textCopied, clipText); /* Substitutes a NULL for every token */strtok(textCopied, "\n\r\b"); i = strlen(textCopied); - if (i + strlen(key_lines[edit_line]) >= MAXCMDLINE-1) - i = MAXCMDLINE-1 - strlen(key_lines[edit_line]); - if (i > 0) - { // insert the string - memcpy (key_lines[edit_line] + key_linepos + i, - key_lines[edit_line] + key_linepos, strlen(key_lines[edit_line]) - key_linepos + 1); - memcpy (key_lines[edit_line] + key_linepos, textCopied, i); - key_linepos += i; + if (i+key_linepos>=MAXCMDLINE) + i=MAXCMDLINE-key_linepos; + if (i>0) { + textCopied[i]=0; + strcat(key_lines[edit_line], textCopied); + key_linepos+=i;; } free(textCopied); } @@ -424,18 +390,12 @@ no_lf: if (key < 32 || key > 127) return; // non printable - + if (key_linepos < MAXCMDLINE-1) { - i = strlen(key_lines[edit_line]) - 1; - if (i == MAXCMDLINE-2) i--; - for (; i >= key_linepos; i--) - key_lines[edit_line][i + 1] = key_lines[edit_line][i]; - i = key_lines[edit_line][key_linepos]; key_lines[edit_line][key_linepos] = key; key_linepos++; - if (!i) // // only null terminate if at the end - key_lines[edit_line][key_linepos] = 0; + key_lines[edit_line][key_linepos] = 0; } } @@ -705,7 +665,6 @@ void Key_Init (void) consolekeys[K_UPARROW] = true; consolekeys[K_DOWNARROW] = true; consolekeys[K_BACKSPACE] = true; - consolekeys[K_DEL] = true; consolekeys[K_HOME] = true; consolekeys[K_END] = true; consolekeys[K_PGUP] = true; @@ -753,9 +712,7 @@ void Key_Init (void) Cmd_AddCommand ("unbind",Key_Unbind_f); Cmd_AddCommand ("unbindall",Key_Unbindall_f); - cl_chatmode = Cvar_Get ("cl_chatmode", "1", 0, - "Controls when console text will be treated as a chat message" - "0 - never, 1 - smart, 2 - always"); + } /* @@ -789,22 +746,17 @@ void Key_Event (int key, qboolean down) if (down) { key_repeats[key]++; - if (key_repeats[key] > 1) - { - if ((key != K_BACKSPACE && key != K_DEL - && key != K_LEFTARROW && key != K_RIGHTARROW - && key != K_PGUP && key != K_PGDN) - || (key_dest == key_game && cls.state == ca_active)) - return; // ignore most autorepeats - } + if (key != K_BACKSPACE + && key != K_PAUSE + && key != K_PGUP + && key != K_PGDN + && key_repeats[key] > 1) + return; // ignore most autorepeats if (key >= 200 && !keybindings[key]) Con_Printf ("%s is unbound, hit F4 to set.\n", Key_KeynumToString (key) ); } -// Exit message mode is disconnected - if (key_dest == key_message && cls.state != ca_active) - key_dest = key_console; // // handle escape specialy, so the user can never unbind it @@ -843,7 +795,7 @@ void Key_Event (int key, qboolean down) kb = keybindings[key]; if (kb && kb[0] == '+') { - snprintf (cmd, sizeof(cmd), "-%s %i\n", kb+1, key); + snprintf (cmd, sizeof(cmd), "-%s %i\n", kb+1, key); Cbuf_AddText (cmd); } if (keyshift[key] != key) @@ -851,7 +803,7 @@ void Key_Event (int key, qboolean down) kb = keybindings[keyshift[key]]; if (kb && kb[0] == '+') { - snprintf (cmd, sizeof(cmd), "-%s %i\n", kb+1, key); + snprintf (cmd, sizeof(cmd), "-%s %i\n", kb+1, key); Cbuf_AddText (cmd); } } @@ -861,8 +813,7 @@ void Key_Event (int key, qboolean down) // // during demo playback, most keys bring up the main menu // - if (cls.demoplayback && down && consolekeys[key] && key_dest == key_game - && key != K_CTRL && key != K_DEL && key != K_HOME && key != K_END && key != K_TAB) + if (cls.demoplayback && down && consolekeys[key] && key_dest == key_game) { M_ToggleMenu_f (); return; diff --git a/source/model.c b/source/model.c index c4708a0..ea0cce1 100644 --- a/source/model.c +++ b/source/model.c @@ -1,7 +1,7 @@ /* model.c - model loading and caching + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,6 +25,7 @@ $Id$ */ +// models.c -- model loading and caching // models are the only shared resource between a client and server running // on the same machine. @@ -32,15 +33,7 @@ #ifdef HAVE_CONFIG_H # include #endif -#include "model.h" -#include "quakefs.h" -#include "qendian.h" -#include "checksum.h" - -#include -#include - -void SV_Error (char *error, ...); +#include "qwsvdef.h" extern int texture_mode; diff --git a/source/pr_edict.c b/source/pr_edict.c index 2f07bcb..dfcf6b7 100644 --- a/source/pr_edict.c +++ b/source/pr_edict.c @@ -1,7 +1,7 @@ /* pr_edict.c - entity dictionary + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,27 +25,12 @@ $Id$ */ +// sv_edict.c -- entity dictionary #ifdef HAVE_CONFIG_H # include #endif -#include "pr_comp.h" -#include "progs.h" -#include "console.h" -#include "server.h" -#include "world.h" -#include "msg.h" -#include "cmd.h" -#include "commdef.h" -#include "crc.h" -#include "qendian.h" -#include "quakefs.h" - -#include -#include -#include - -void SV_Error (char *error, ...); +#include "qwsvdef.h" dprograms_t *progs; dfunction_t *pr_functions; diff --git a/source/r_part.c b/source/r_part.c index 8eb2511..8c829b0 100644 --- a/source/r_part.c +++ b/source/r_part.c @@ -29,13 +29,8 @@ #ifdef HAVE_CONFIG_H # include #endif -#include "qargs.h" -#include "r_local.h" -#include "console.h" -#include "quakefs.h" #include "quakedef.h" - -#include +#include "r_local.h" #define MAX_PARTICLES 2048 // default max # of particles at one // time diff --git a/source/r_sprite.c b/source/r_sprite.c index 3c689b7..5b1cda1 100644 --- a/source/r_sprite.c +++ b/source/r_sprite.c @@ -30,11 +30,9 @@ # include #endif #include "sys.h" -#include "console.h" +#include "quakedef.h" #include "r_local.h" -#include - static int clip_current; static vec5_t clip_verts[2][MAXWORKINGVERTS]; static int sprite_width, sprite_height; diff --git a/source/screen.c b/source/screen.c index 07dc3d2..a83b9e1 100644 --- a/source/screen.c +++ b/source/screen.c @@ -1,7 +1,7 @@ /* screen.c - master for refresh, status bar, console, chat, notify, etc + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,28 +25,16 @@ $Id$ */ +// screen.c -- master for refresh, status bar, console, chat, notify, etc #ifdef HAVE_CONFIG_H # include #endif -#include "input.h" #include "sys.h" -#include "screen.h" -#include "r_local.h" -#include "wad.h" -#include "compat.h" -#include "draw.h" #include "quakedef.h" -#include "keys.h" -#include "console.h" -#include "msg.h" -#include "sbar.h" -#include "menu.h" -#include "qendian.h" -#include "cmd.h" +#include "r_local.h" #include -#include /* @@ -1061,7 +1049,7 @@ int SCR_ModalMessage (char *text) do { key_count = -1; // wait for a key down and up - IN_SendKeyEvents (); + Sys_SendKeyEvents (); } while (key_lastpress != 'y' && key_lastpress != 'n' && key_lastpress != K_ESCAPE); scr_fullupdate = 0; diff --git a/source/snd_dma.c b/source/snd_dma.c index cab2207..2206e90 100644 --- a/source/snd_dma.c +++ b/source/snd_dma.c @@ -1,7 +1,7 @@ /* snd_dma.c - main control for any streaming sound output device + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,16 +25,12 @@ $Id$ */ +// snd_dma.c -- main control for any streaming sound output device #ifdef HAVE_CONFIG_H # include #endif #include "sys.h" -#include "sound.h" -#include "cmd.h" -#include "console.h" -#include "client.h" -#include "qargs.h" #include "quakedef.h" #ifdef _WIN32 @@ -42,9 +38,6 @@ #include "in_win.h" #endif -#include -#include - void S_Play(void); void S_PlayVol(void); void S_SoundList(void); @@ -168,7 +161,7 @@ void S_SoundInfo_f(void) Con_Printf("%5d samplebits\n", shm->samplebits); Con_Printf("%5d submission_chunk\n", shm->submission_chunk); Con_Printf("%5d speed\n", shm->speed); - Con_Printf("0x%x dma buffer\n", (unsigned)shm->buffer); + Con_Printf("0x%x dma buffer\n", shm->buffer); Con_Printf("%5d total_channels\n", total_channels); } diff --git a/source/snd_mem.c b/source/snd_mem.c index 7ee69b2..6da02c2 100644 --- a/source/snd_mem.c +++ b/source/snd_mem.c @@ -1,7 +1,7 @@ /* snd_mem.c - sound caching + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,17 +25,13 @@ $Id$ */ +// snd_mem.c: sound caching #ifdef HAVE_CONFIG_H # include #endif #include "sys.h" -#include "sound.h" -#include "qendian.h" -#include "quakefs.h" -#include "console.h" - -#include +#include "quakedef.h" int cache_full_cycle; diff --git a/source/snd_mix.c b/source/snd_mix.c index 4dc3dac..fe87f0f 100644 --- a/source/snd_mix.c +++ b/source/snd_mix.c @@ -1,7 +1,7 @@ /* snd_mix.c - portable code to mix sounds for snd_dma.c + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,12 +25,12 @@ $Id$ */ +// snd_mix.c -- portable code to mix sounds for snd_dma.c #ifdef HAVE_CONFIG_H # include #endif -#include "sound.h" -#include "console.h" +#include "quakedef.h" #ifdef _WIN32 #include "winquake.h" diff --git a/source/sv_ccmds.c b/source/sv_ccmds.c index fef8f46..62fd4ab 100644 --- a/source/sv_ccmds.c +++ b/source/sv_ccmds.c @@ -29,22 +29,7 @@ #ifdef HAVE_CONFIG_H # include #endif -#include "server.h" -#include "crc.h" -#include "msg.h" -#include "world.h" -#include "commdef.h" -#include "cmd.h" -#include "sys.h" -#include "pmove.h" -#include "compat.h" -#include "quakefs.h" -#include "bothdefs.h" -#include "qendian.h" -#include "qargs.h" - -#include -#include +#include "qwsvdef.h" qboolean sv_allow_cheats; @@ -753,6 +738,43 @@ void SV_Floodprotmsg_f (void) } snprintf (fp_msg, sizeof(fp_msg), "%s", Cmd_Argv(1)); } + +/* +================ +SV_Gamedir_f + +Sets the gamedir and path to a different directory. +================ +*/ +char gamedirfile[MAX_OSPATH]; +void SV_Gamedir_f (void) +{ + char *dir; + + if (Cmd_Argc() == 1) + { + Con_Printf ("Current gamedir: %s\n", com_gamedir); + return; + } + + if (Cmd_Argc() != 2) + { + Con_Printf ("Usage: gamedir \n"); + return; + } + + dir = Cmd_Argv(1); + + if (strstr(dir, "..") || strstr(dir, "/") + || strstr(dir, "\\") || strstr(dir, ":") ) + { + Con_Printf ("Gamedir should be a single filename, not a path\n"); + return; + } + + COM_Gamedir (dir); + Info_SetValueForStarKey (svs.info, "*gamedir", dir, MAX_SERVERINFO_STRING); +} /* ================ @@ -780,15 +802,15 @@ void SV_Snap (int uid) sprintf(pcxname, "%d-00.pcx", uid); - snprintf (checkname, sizeof(checkname), "%s/snap", com_gamedir); - Sys_mkdir(com_gamedir); + snprintf (checkname, sizeof(checkname), "%s/snap", gamedirfile); + Sys_mkdir(gamedirfile); Sys_mkdir(checkname); for (i=0 ; i<=99 ; i++) { pcxname[strlen(pcxname) - 6] = i/10 + '0'; pcxname[strlen(pcxname) - 5] = i%10 + '0'; - snprintf (checkname, sizeof(checkname), "%s/snap/%s", com_gamedir, pcxname); + snprintf (checkname, sizeof(checkname), "%s/snap/%s", gamedirfile, pcxname); if (Sys_FileTime(checkname) == -1) break; // file doesn't exist } @@ -881,6 +903,7 @@ void SV_InitOperatorCommands (void) Cmd_AddCommand ("serverinfo", SV_Serverinfo_f); Cmd_AddCommand ("localinfo", SV_Localinfo_f); Cmd_AddCommand ("user", SV_User_f); + Cmd_AddCommand ("gamedir", SV_Gamedir_f); Cmd_AddCommand ("sv_gamedir", SV_Gamedir); Cmd_AddCommand ("floodprot", SV_Floodprot_f); Cmd_AddCommand ("floodprotmsg", SV_Floodprotmsg_f); diff --git a/source/sv_ents.c b/source/sv_ents.c index 241af6c..a346633 100644 --- a/source/sv_ents.c +++ b/source/sv_ents.c @@ -29,14 +29,7 @@ #ifdef HAVE_CONFIG_H # include #endif -#include "server.h" -#include "crc.h" -#include "msg.h" -#include "world.h" -#include "commdef.h" -#include "cmd.h" -#include "sys.h" -#include "pmove.h" +#include "qwsvdef.h" /* ============================================================================= diff --git a/source/sv_sys_unix.c b/source/sv_sys_unix.c index 33514dd..9b8ef28 100644 --- a/source/sv_sys_unix.c +++ b/source/sv_sys_unix.c @@ -31,16 +31,12 @@ # include #endif #include -#include "qargs.h" -#include "cvar.h" -#include "server.h" -#include "sys.h" +#include "qwsvdef.h" #ifdef NeXT #include #endif -#include #include #include #include @@ -171,7 +167,7 @@ int main(int argc, char *argv[]) if (j) parms.memsize = (int) (atof(com_argv[j+1]) * 1024 * 1024); if ((parms.membase = malloc (parms.memsize)) == NULL) - Sys_Error("Can't allocate %d\n", parms.memsize); + Sys_Error("Can't allocate %ld\n", parms.memsize); parms.basedir = BASEDIR; diff --git a/source/sv_sys_win.c b/source/sv_sys_win.c index abd8c86..bd03a4c 100644 --- a/source/sv_sys_win.c +++ b/source/sv_sys_win.c @@ -27,24 +27,21 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +# include #endif - -#include -#include +#include "qwsvdef.h" #include #include -#include "qargs.h" -#include "cvar.h" -#include "server.h" -#include "sys.h" - qboolean is_server = true; qboolean WinNT; +/* cvar_t sys_nostdout = {"sys_nostdout","0"}; + CVAR_FIXME */ cvar_t *sys_nostdout; +/* cvar_t sys_sleep = {"sys_sleep","1"}; + CVAR_FIXME */ cvar_t *sys_sleep; /* @@ -100,7 +97,7 @@ char *Sys_ConsoleInput (void) int c; // read a line out - while (kbhit()) + while (kbhit()) { c = _getch(); putch (c); @@ -142,6 +139,8 @@ void Sys_Printf (char *fmt, ...) { va_list argptr; +/* if (sys_nostdout.value) + CVAR_FIXME */ if (sys_nostdout->value) return; @@ -173,8 +172,12 @@ void Sys_Init (void) { OSVERSIONINFO vinfo; +/* Cvar_RegisterVariable (&sys_nostdout); + CVAR_FIXME */ sys_nostdout = Cvar_Get("sys_nostdout", "0", CVAR_NONE, "None"); - sys_sleep = Cvar_Get("sys_sleep", "8", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&sys_sleep); + CVAR_FIXME */ + sys_sleep = Cvar_Get("sys_sleep", "1", CVAR_NONE, "None"); // make sure the timer is high precision, otherwise // NT gets 18ms resolution diff --git a/source/sv_user.c b/source/sv_user.c index 45bad6f..49441e7 100644 --- a/source/sv_user.c +++ b/source/sv_user.c @@ -1,7 +1,7 @@ /* sv_user.c - server code for moving users + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,29 +25,12 @@ $Id$ */ - +// sv_user.c -- server code for moving users #ifdef HAVE_CONFIG_H # include #endif -#include "server.h" -#include "crc.h" -#include "console.h" -#include "msg.h" -#include "world.h" -#include "commdef.h" -#include "cmd.h" -#include "sys.h" -#include "pmove.h" -#include "compat.h" -#include "bothdefs.h" -#include "quakefs.h" -#include "checksum.h" - #include -#include -#include -#include -#include +#include "qwsvdef.h" edict_t *sv_player; diff --git a/source/vid_ggi.c b/source/vid_ggi.c index 03236f1..abd87b9 100644 --- a/source/vid_ggi.c +++ b/source/vid_ggi.c @@ -5,6 +5,8 @@ Copyright (C) 1996-1997 Id Software, Inc. Copyright (C) 1999 Marcus Sundberg [mackan@stacken.kth.se] + Copyright (C) 1999,2000 contributors of the QuakeForge project + Please see the file "AUTHORS" for a list of contributors This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -39,34 +41,9 @@ #include #include -#include "bothdefs.h" // needed by: common.h, net.h, client.h - -#include "quakedef.h" - -#include "bspfile.h" // needed by: glquake.h -#include "vid.h" #include "sys.h" -#include "zone.h" // needed by: client.h, gl_model.h -#include "mathlib.h" // needed by: protocol.h, render.h, client.h, - // modelgen.h, glmodel.h -#include "wad.h" -#include "draw.h" -#include "cvar.h" -#include "net.h" // needed by: client.h -#include "protocol.h" // needed by: client.h -#include "cmd.h" -#include "keys.h" -#include "sbar.h" -#include "sound.h" -#include "render.h" // needed by: client.h, gl_model.h, glquake.h -#include "client.h" // need cls in this file -#include "model.h" // needed by: glquake.h -#include "console.h" -#include "qendian.h" -#include "qargs.h" -#include "compat.h" +#include "quakedef.h" #include "d_local.h" -#include "input.h" extern viddef_t vid; // global video state unsigned short d_8to16table[256]; @@ -894,7 +871,7 @@ static void GetEvent(void) } -void IN_SendKeyEvents(void) +void Sys_SendKeyEvents(void) { /* Get events from LibGGI */ if (ggivis) { @@ -966,14 +943,14 @@ IN_Move(usercmd_t *cmd) mouse_x *= sensitivity->value; mouse_y *= sensitivity->value; - if ( (in_strafe.state & 1) || (lookstrafe->value && freelook )) + if ( (in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1) )) cmd->sidemove += m_side->value * mouse_x; else cl.viewangles[YAW] -= m_yaw->value * mouse_x; - if (freelook) + if (in_mlook.state & 1) V_StopPitchDrift (); - if ( freelook && !(in_strafe.state & 1)) { + if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) { cl.viewangles[PITCH] += m_pitch->value * mouse_y; if (cl.viewangles[PITCH] > 80) cl.viewangles[PITCH] = 80; diff --git a/source/vid_glx.c b/source/vid_glx.c index c4cdf51..576900d 100644 --- a/source/vid_glx.c +++ b/source/vid_glx.c @@ -4,7 +4,6 @@ OpenGL GLX video driver Copyright (C) 1996-1997 Id Software, Inc. - Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se] This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -27,96 +26,83 @@ $Id$ */ -#include -#include "qtypes.h" -#include "quakedef.h" -#include "qendian.h" -#include "glquake.h" -#include "cvar.h" -#include "qargs.h" -#include "console.h" -#include "keys.h" -#include "menu.h" -#include "sys.h" -#include "draw.h" -#include "context_x11.h" - -#include +#ifdef HAVE_CONFIG_H +# include +#endif +#include #include -#include +#include +#include #include +#include -#ifdef HAVE_DLFCN_H -# include -#endif -#ifndef RTLD_LAZY -# ifdef DL_LAZY -# define RTLD_LAZY DL_LAZY -# else -# define RTLD_LAZY 0 -# endif -#endif +#include "bothdefs.h" // needed by: common.h, net.h, client.h + +#include + +#include "common.h" +#include "bspfile.h" // needed by: glquake.h +#include "vid.h" +#include "sys.h" +#include "zone.h" // needed by: client.h, gl_model.h +#include "mathlib.h" // needed by: protocol.h, render.h, client.h, + // modelgen.h, glmodel.h +#include "wad.h" +#include "draw.h" +#include "cvar.h" +#include "net.h" // needed by: client.h +#include "protocol.h" // needed by: client.h +#include "cmd.h" +#include "keys.h" +#include "sbar.h" +#include "sound.h" +#include "render.h" // needed by: client.h, gl_model.h, glquake.h +#include "client.h" // need cls in this file +#include "model.h" // needed by: glquake.h +#include "console.h" +#include "glquake.h" #include #include #include -#ifdef HAVE_DGA -# include +#ifdef USE_DGA +#include #endif -#ifdef HAVE_VIDMODE -# include -#endif -#include "dga_check.h" -#ifdef XMESA -# include -#endif #define WARP_WIDTH 320 #define WARP_HEIGHT 200 -static qboolean vid_initialized = false; +extern byte *host_colormap; +extern qboolean noclip_anglehack; -static int screen; -Window x_win; -static GLXContext ctx = NULL; +static Display *x_disp = NULL; +static Window x_win; +static GLXContext ctx = NULL; -#define X_MASK (VisibilityChangeMask | StructureNotifyMask) +static float old_windowed_mouse = 0; + +#define KEY_MASK (KeyPressMask | KeyReleaseMask) +#define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | \ + PointerMotionMask) + +#define X_MASK (KEY_MASK | MOUSE_MASK | VisibilityChangeMask) unsigned short d_8to16table[256]; -unsigned d_8to24table[256]; +unsigned d_8to24table[256]; unsigned char d_15to8table[65536]; +cvar_t *_windowed_mouse; cvar_t *vid_mode; -cvar_t *vid_fullscreen; -extern cvar_t *gl_triplebuffer; -extern cvar_t *vid_dga_mouseaccel; + +static float mouse_x, mouse_y; +static float old_mouse_x, old_mouse_y; -#ifdef HAVE_VIDMODE -static XF86VidModeModeInfo **vidmodes; -static int nummodes, hasvidmode = 0; -#endif -#ifdef HAVE_DGA -static int hasdgavideo = 0; -static int hasdga = 0; -#endif +cvar_t *m_filter; - -#ifdef HAVE_DLOPEN -static void *dlhand = NULL; -#endif -static GLboolean (*QF_XMesaSetFXmode)(GLint mode) = NULL; - - -int scr_width, scr_height; - -#if defined(XMESA) || defined(HAVE_DGA) -int VID_options_items = 2; -#else -int VID_options_items = 1; -#endif +static int scr_width, scr_height; /*-----------------------------------------------------------------------*/ @@ -129,8 +115,10 @@ int texture_mode = GL_LINEAR; int texture_extension_number = 1; -float gldepthmin, gldepthmax; +float gldepthmin, gldepthmax; +/* cvar_t gl_ztrick = {"gl_ztrick","1"}; + CVAR_FIXME */ cvar_t *gl_ztrick; const char *gl_vendor; @@ -150,48 +138,318 @@ void D_EndDirectRect (int x, int y, int width, int height) { } -void -VID_Shutdown(void) +/* +======================================================================== +Create an empty cursor +======================================================================== +*/ + +static Cursor nullcursor = None; + +static Cursor +CreateNullCursor(Display *display, Window root) { - if (!vid_initialized) - return; + Pixmap cursormask; + XGCValues xgc; + GC gc; + XColor dummycolour; - Con_Printf("VID_Shutdown\n"); + if (nullcursor != None) return nullcursor; - glXDestroyContext(x_disp, ctx); + cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/); + xgc.function = GXclear; + gc = XCreateGC(display, cursormask, GCFunction, &xgc); + XFillRectangle(display, cursormask, gc, 0, 0, 1, 1); + dummycolour.pixel = 0; + dummycolour.red = 0; + dummycolour.flags = 04; + nullcursor = XCreatePixmapCursor(display, cursormask, cursormask, + &dummycolour,&dummycolour, 0,0); + XFreePixmap(display,cursormask); + XFreeGC(display,gc); -#ifdef HAVE_VIDMODE - if (hasvidmode) { - int i; - - XF86VidModeSwitchToMode (x_disp, DefaultScreen (x_disp), - vidmodes[0]); - for (i = 0; i < nummodes; i++) { - if (vidmodes[i]->private) XFree(vidmodes[i]->private); - } - XFree(vidmodes); - } -#endif -#ifdef HAVE_DLOPEN - if (dlhand) { - dlclose(dlhand); - dlhand = NULL; - } -#endif - x11_close_display(); + return nullcursor; } -static void -signal_handler(int sig) +static int XLateKey(XKeyEvent *ev) +{ + + int key; + char buf[64]; + KeySym keysym; + + key = 0; + + XLookupString(ev, buf, sizeof buf, &keysym, 0); + + switch(keysym) + { + case XK_KP_Page_Up: + case XK_Page_Up: key = K_PGUP; break; + + case XK_KP_Page_Down: + case XK_Page_Down: key = K_PGDN; break; + + case XK_KP_Home: + case XK_Home: key = K_HOME; break; + + case XK_KP_End: + case XK_End: key = K_END; break; + + case XK_KP_Left: + case XK_Left: key = K_LEFTARROW; break; + + case XK_KP_Right: + case XK_Right: key = K_RIGHTARROW; break; + + case XK_KP_Down: + case XK_Down: key = K_DOWNARROW; break; + + case XK_KP_Up: + case XK_Up: key = K_UPARROW; break; + + case XK_Escape: key = K_ESCAPE; break; + + case XK_KP_Enter: + case XK_Return: key = K_ENTER; break; + + case XK_Tab: key = K_TAB; break; + + case XK_F1: key = K_F1; break; + + case XK_F2: key = K_F2; break; + + case XK_F3: key = K_F3; break; + + case XK_F4: key = K_F4; break; + + case XK_F5: key = K_F5; break; + + case XK_F6: key = K_F6; break; + + case XK_F7: key = K_F7; break; + + case XK_F8: key = K_F8; break; + + case XK_F9: key = K_F9; break; + + case XK_F10: key = K_F10; break; + + case XK_F11: key = K_F11; break; + + case XK_F12: key = K_F12; break; + + case XK_BackSpace: key = K_BACKSPACE; break; + + case XK_KP_Delete: + case XK_Delete: key = K_DEL; break; + + case XK_Pause: key = K_PAUSE; break; + + case XK_Shift_L: + case XK_Shift_R: key = K_SHIFT; break; + + case XK_Execute: + case XK_Control_L: + case XK_Control_R: key = K_CTRL; break; + + case XK_Alt_L: + case XK_Meta_L: + case XK_Alt_R: + case XK_Meta_R: key = K_ALT; break; + + case XK_KP_Begin: key = '5'; break; + + case XK_KP_Insert: + case XK_Insert:key = K_INS; break; + + case XK_KP_Multiply: key = '*'; break; + case XK_KP_Add: key = '+'; break; + case XK_KP_Subtract: key = '-'; break; + case XK_KP_Divide: key = '/'; break; + +#if 0 + case 0x021: key = '1';break;/* [!] */ + case 0x040: key = '2';break;/* [@] */ + case 0x023: key = '3';break;/* [#] */ + case 0x024: key = '4';break;/* [$] */ + case 0x025: key = '5';break;/* [%] */ + case 0x05e: key = '6';break;/* [^] */ + case 0x026: key = '7';break;/* [&] */ + case 0x02a: key = '8';break;/* [*] */ + case 0x028: key = '9';;break;/* [(] */ + case 0x029: key = '0';break;/* [)] */ + case 0x05f: key = '-';break;/* [_] */ + case 0x02b: key = '=';break;/* [+] */ + case 0x07c: key = '\'';break;/* [|] */ + case 0x07d: key = '[';break;/* [}] */ + case 0x07b: key = ']';break;/* [{] */ + case 0x022: key = '\'';break;/* ["] */ + case 0x03a: key = ';';break;/* [:] */ + case 0x03f: key = '/';break;/* [?] */ + case 0x03e: key = '.';break;/* [>] */ + case 0x03c: key = ',';break;/* [<] */ +#endif + + default: + key = *(unsigned char*)buf; + if (key >= 'A' && key <= 'Z') + key = key - 'A' + 'a'; + break; + } + + return key; +} + +static void install_grabs(void) +{ + XGrabPointer(x_disp, x_win, + True, + 0, + GrabModeAsync, GrabModeAsync, + x_win, + None, + CurrentTime); + +#ifdef USE_DGA + XF86DGADirectVideo(x_disp, DefaultScreen(x_disp), XF86DGADirectMouse); + dgamouse = 1; +#else + XWarpPointer(x_disp, None, x_win, + 0, 0, 0, 0, + vid.width / 2, vid.height / 2); +#endif + + XGrabKeyboard(x_disp, x_win, + False, + GrabModeAsync, GrabModeAsync, + CurrentTime); + +// XSync(x_disp, True); +} + +static void uninstall_grabs(void) +{ +#ifdef USE_DGA + XF86DGADirectVideo(x_disp, DefaultScreen(x_disp), 0); + dgamouse = 0; +#endif + + XUngrabPointer(x_disp, CurrentTime); + XUngrabKeyboard(x_disp, CurrentTime); + +// XSync(x_disp, True); +} + +static void GetEvent(void) +{ + XEvent event; + int b; + + if (!x_disp) + return; + + XNextEvent(x_disp, &event); + + switch (event.type) { + case KeyPress: + case KeyRelease: + Key_Event(XLateKey(&event.xkey), event.type == KeyPress); + break; + + case MotionNotify: +#ifdef USE_DGA +/* if (dgamouse && _windowed_mouse.value) { + CVAR_FIXME */ + if (dgamouse && _windowed_mouse->value) { + mouse_x = event.xmotion.x_root; + mouse_y = event.xmotion.y_root; + } else +#endif + { +/* if (_windowed_mouse.value) { + CVAR_FIXME */ + if (_windowed_mouse->value) { + mouse_x = (float) ((int)event.xmotion.x - (int)(vid.width/2)); + mouse_y = (float) ((int)event.xmotion.y - (int)(vid.height/2)); + + /* move the mouse to the window center again */ + XSelectInput(x_disp, x_win, X_MASK & ~PointerMotionMask); + XWarpPointer(x_disp, None, x_win, 0, 0, 0, 0, + (vid.width/2), (vid.height/2)); + XSelectInput(x_disp, x_win, X_MASK); + } + } + break; + + case ButtonPress: + b=-1; + if (event.xbutton.button == 1) + b = 0; + else if (event.xbutton.button == 2) + b = 2; + else if (event.xbutton.button == 3) + b = 1; + if (b>=0) + Key_Event(K_MOUSE1 + b, true); + break; + + case ButtonRelease: + b=-1; + if (event.xbutton.button == 1) + b = 0; + else if (event.xbutton.button == 2) + b = 2; + else if (event.xbutton.button == 3) + b = 1; + if (b>=0) + Key_Event(K_MOUSE1 + b, false); + break; + } + +/* if (old_windowed_mouse != _windowed_mouse.value) { + CVAR_FIXME */ + if (old_windowed_mouse != _windowed_mouse->value) { +/* old_windowed_mouse = _windowed_mouse.value; + CVAR_FIXME */ + old_windowed_mouse = _windowed_mouse->value; + +/* if (!_windowed_mouse.value) { + CVAR_FIXME */ + if (!_windowed_mouse->value) { + /* ungrab the pointer */ + uninstall_grabs(); + } else { + /* grab the pointer */ + install_grabs(); + } + } +} + + +void VID_Shutdown(void) +{ + Con_Printf("VID_Shutdown\n"); + if (ctx) { + glXDestroyContext(x_disp, ctx); + } + if (nullcursor != None) { + XFreeCursor(x_disp, nullcursor); + nullcursor = None; + } + XCloseDisplay(x_disp); +} + +void signal_handler(int sig) { printf("Received signal %d, exiting...\n", sig); Sys_Quit(); - exit(sig); + exit(0); } -static void -InitSig(void) +void InitSig(void) { +#if 0 signal(SIGHUP, signal_handler); signal(SIGINT, signal_handler); signal(SIGQUIT, signal_handler); @@ -199,9 +457,10 @@ InitSig(void) signal(SIGTRAP, signal_handler); signal(SIGIOT, signal_handler); signal(SIGBUS, signal_handler); -/* signal(SIGFPE, signal_handler); */ + signal(SIGFPE, signal_handler); signal(SIGSEGV, signal_handler); signal(SIGTERM, signal_handler); +#endif } void VID_ShiftPalette(unsigned char *p) @@ -226,7 +485,7 @@ void VID_SetPalette (unsigned char *palette) // // 8 8 8 encoding // -// Con_Printf("Converting 8to24\n"); +// Con_DPrintf("Converting 8to24\n"); pal = palette; table = d_8to24table; @@ -236,7 +495,7 @@ void VID_SetPalette (unsigned char *palette) g = pal[1]; b = pal[2]; pal += 3; - + // v = (255<<24) + (r<<16) + (g<<8) + (b<<0); // v = (255<<0) + (r<<8) + (g<<16) + (b<<24); v = (255<<24) + (r<<0) + (g<<8) + (b<<16); @@ -278,9 +537,9 @@ void VID_SetPalette (unsigned char *palette) } d_15to8table[i]=k; } - snprintf(s, sizeof(s), "%s/glquake", com_gamedir); + snprintf (s, sizeof(s), "%s/glquake", com_gamedir); Sys_mkdir (s); - snprintf(s, sizeof(s), "%s/glquake/15to8.pal", com_gamedir); + snprintf (s, sizeof(s), "%s/glquake/15to8.pal", com_gamedir); if ((f = fopen(s, "wb")) != NULL) { fwrite(d_15to8table, 1<<15, 1, f); fclose(f); @@ -288,7 +547,6 @@ void VID_SetPalette (unsigned char *palette) } } - /* =============== GL_Init @@ -308,7 +566,7 @@ void GL_Init (void) // Con_Printf ("%s %s\n", gl_renderer, gl_version); - glClearColor (0,0,0,0); + glClearColor (1,0,0,0); glCullFace(GL_FRONT); glEnable(GL_TEXTURE_2D); @@ -364,8 +622,8 @@ qboolean VID_Is8bit(void) return is8bit; } -#ifdef GL_EXT_SHARED -void VID_Init8bitPalette() +#ifdef GLX_EXT_SHARED +void VID_Init8bitPalette() { // Check for 8bit Extensions and initialize them. int i; @@ -395,6 +653,34 @@ void VID_Init8bitPalette(void) { } +#if 0 +extern void gl3DfxSetPaletteEXT(GLuint *pal); + +void VID_Init8bitPalette(void) +{ + // Check for 8bit Extensions and initialize them. + int i; + GLubyte table[256][4]; + char *oldpal; + + if (strstr(gl_extensions, "3DFX_set_global_palette") == NULL) + return; + + Con_SafePrintf("8-bit GL extensions enabled.\n"); + glEnable( GL_SHARED_TEXTURE_PALETTE_EXT ); + oldpal = (char *) d_8to24table; //d_8to24table3dfx; + for (i=0;i<256;i++) { + table[i][2] = *oldpal++; + table[i][1] = *oldpal++; + table[i][0] = *oldpal++; + table[i][3] = 255; + oldpal++; + } + gl3DfxSetPaletteEXT((GLuint *)table); + is8bit = true; +} +#endif + #endif void VID_Init(unsigned char *palette) @@ -411,27 +697,25 @@ void VID_Init(unsigned char *palette) }; char gldir[MAX_OSPATH]; int width = 640, height = 480; + int scrnum; XSetWindowAttributes attr; unsigned long mask; Window root; XVisualInfo *visinfo; - vid_mode = Cvar_Get ("vid_mode","0",0,"None"); - gl_ztrick = Cvar_Get ("gl_ztrick","0",CVAR_ARCHIVE,"None"); - vid_fullscreen = Cvar_Get ("vid_fullscreen","0",0,"None"); -#ifdef HAVE_DGA - vid_dga_mouseaccel = Cvar_Get("vid_dga_mouseaccel","1",CVAR_ARCHIVE, - "None"); -#endif + + vid_mode = Cvar_Get("vid_mode", "0", CVAR_NONE, "None"); + gl_ztrick = Cvar_Get("gl_ztrick", "0", CVAR_NONE, "None"); + _windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None"); + vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpheight = WARP_HEIGHT; vid.colormap = host_colormap; vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048)); - /* Interpret command-line params - */ + // interpret command-line params - /* Set vid parameters */ + // set vid parameters if ((i = COM_CheckParm("-width")) != 0) width = atoi(com_argv[i+1]); if ((i = COM_CheckParm("-height")) != 0) @@ -443,82 +727,28 @@ void VID_Init(unsigned char *palette) vid.conwidth = width; vid.conwidth &= 0xfff8; // make it a multiple of eight - if (vid.conwidth < 320) - vid.conwidth = 320; + + vid.conwidth = max(vid.conwidth, 320); // pick a conheight that matches with correct aspect - vid.conheight = vid.conwidth * 3 / 4; + vid.conheight = vid.conwidth*3 / 4; - i = COM_CheckParm ("-conheight"); - if ( i != 0 ) // Set console height, but no smaller than 200 px - vid.conheight = atoi(com_argv[i+1]); - if (vid.conheight < 200) - vid.conheight = 200; + if ((i = COM_CheckParm("-conheight")) != 0) + vid.conheight = max(atoi(com_argv[i+1]), 200); - x11_open_display(); - - screen = DefaultScreen(x_disp); - root = RootWindow(x_disp, screen); - - visinfo = glXChooseVisual(x_disp, screen, attrib); - if (!visinfo) { - fprintf(stderr, "Error couldn't get an RGB, Double-buffered, Depth visual\n"); + if (!(x_disp = XOpenDisplay(NULL))) { + fprintf(stderr, "Error couldn't open the X display\n"); exit(1); } -#ifdef HAVE_DGA - { - int maj_ver; + scrnum = DefaultScreen(x_disp); + root = RootWindow(x_disp, scrnum); - hasdga = VID_CheckDGA(x_disp, &maj_ver, NULL, &hasdgavideo); - if (!hasdga || maj_ver < 1) { - hasdga = hasdgavideo = 0; - } + visinfo = glXChooseVisual(x_disp, scrnum, attrib); + if (!visinfo) { + fprintf(stderr, "qkHack: Error couldn't get an RGB, Double-buffered, Depth visual\n"); + exit(1); } - Con_SafePrintf ("hasdga = %i\nhasdgavideo = %i\n", hasdga, hasdgavideo); -#endif -#ifdef HAVE_VIDMODE - hasvidmode = VID_CheckVMode(x_disp, NULL, NULL); - if (hasvidmode) { - if (! XF86VidModeGetAllModeLines(x_disp, DefaultScreen(x_disp), - &nummodes, &vidmodes) - || nummodes <= 0) { - hasvidmode = 0; - } - } - Con_SafePrintf ("hasvidmode = %i\nnummodes = %i\n", hasvidmode, nummodes); -#endif -#ifdef HAVE_DLOPEN - dlhand = dlopen(NULL, RTLD_LAZY); - if (dlhand) { - QF_XMesaSetFXmode = dlsym(dlhand, "XMesaSetFXmode"); - if (!QF_XMesaSetFXmode) { - QF_XMesaSetFXmode = dlsym(dlhand, "_XMesaSetFXmode"); - } - } else { - QF_XMesaSetFXmode = NULL; - } -#else -#ifdef XMESA - QF_XMesaSetFXmode = XMesaSetFXmode; -#endif -#endif - if (QF_XMesaSetFXmode) { -#ifdef XMESA - const char *str = getenv("MESA_GLX_FX"); - if (str != NULL && *str != 'd') { - if (tolower(*str) == 'w') { - Cvar_Set (vid_fullscreen, "0"); - } else { - Cvar_Set (vid_fullscreen, "1"); - } - } -#endif - /* Glide uses DGA internally, so we don't want to - mess with it. */ -// hasdga = 0; - } - /* window attributes */ attr.background_pixel = 0; attr.border_pixel = 0; @@ -526,52 +756,18 @@ void VID_Init(unsigned char *palette) attr.event_mask = X_MASK; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; -#ifdef HAVE_VIDMODE - if (hasvidmode && vid_fullscreen->value) { - int smallest_mode=0, x=MAXINT, y=MAXINT; - - attr.override_redirect=1; - mask|=CWOverrideRedirect; - - // FIXME: does this depend on mode line order in XF86Config? - for (i=0; ividmodes[i]->hdisplay || y>vidmodes[i]->vdisplay) { - smallest_mode=i; - x=vidmodes[i]->hdisplay; - y=vidmodes[i]->vdisplay; - } - printf("%dx%d\n",vidmodes[i]->hdisplay,vidmodes[i]->vdisplay); - } - // chose the smallest mode that our window fits into; - for (i=smallest_mode; - i!=(smallest_mode+1)%nummodes; - i=(i?i-1:nummodes-1)) { - if (vidmodes[i]->hdisplay>=width - && vidmodes[i]->vdisplay>=height) { - XF86VidModeSwitchToMode (x_disp, DefaultScreen (x_disp), - vidmodes[i]); - break; - } - } - XF86VidModeSetViewPort(x_disp, DefaultScreen (x_disp), 0, 0); - _windowed_mouse = Cvar_Get ("_windowed_mouse","1",CVAR_ARCHIVE|CVAR_ROM,"None"); - } else -#endif - _windowed_mouse = Cvar_Get ("_windowed_mouse","0",CVAR_ARCHIVE,"None"); - x_win = XCreateWindow(x_disp, root, 0, 0, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr); - XMapWindow(x_disp, x_win); -#ifdef HAVE_VIDMODE - if (hasvidmode && vid_fullscreen->value) { - XRaiseWindow(x_disp, x_win); - XGrabKeyboard(x_disp, x_win, 1, GrabModeAsync, GrabModeAsync, - CurrentTime); - } -#endif + /* Invisible Cursor */ + XDefineCursor(x_disp, x_win, CreateNullCursor(x_disp, x_win)); - XSync(x_disp, 0); + /* Map the window */ + XMapWindow(x_disp, x_win); + + XMoveWindow(x_disp, x_win, 0, 0); + + XFlush(x_disp); ctx = glXCreateContext(x_disp, visinfo, NULL, True); @@ -580,12 +776,8 @@ void VID_Init(unsigned char *palette) scr_width = width; scr_height = height; - if (vid.conheight > height) - vid.conheight = height; - if (vid.conwidth > width) - vid.conwidth = width; - vid.width = vid.conwidth; - vid.height = vid.conheight; + vid.height = vid.conheight = min(height, vid.conheight); + vid.width = vid.conwidth = min(width, vid.conwidth); vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0); vid.numpages = 2; @@ -594,7 +786,7 @@ void VID_Init(unsigned char *palette) GL_Init(); - snprintf(gldir, sizeof(gldir), "%s/glquake", com_gamedir); + snprintf (gldir, sizeof(gldir), "%s/glquake", com_gamedir); Sys_mkdir (gldir); VID_SetPalette(palette); @@ -602,26 +794,96 @@ void VID_Init(unsigned char *palette) // Check for 3DFX Extensions and initialize them. VID_Init8bitPalette(); - Con_SafePrintf ("Video mode %dx%d initialized.\n", - width, height); + Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height); - vid_initialized = true; - - vid.recalc_refdef = 1; // force a surface cache flush + vid.recalc_refdef = 1; // force a surface cache flush } -void VID_InitCvars() +void Sys_SendKeyEvents(void) { - gl_triplebuffer = Cvar_Get("gl_triplebuffer","1",CVAR_ARCHIVE,"None"); + if (x_disp) { + while (XPending(x_disp)) + GetEvent(); + } } -void -VID_LockBuffer ( void ) +void Force_CenterView_f (void) +{ + cl.viewangles[PITCH] = 0; +} + +void IN_Init(void) { } -void -VID_UnlockBuffer ( void ) +void IN_Shutdown(void) { } +/* +=========== +IN_Commands +=========== +*/ +void IN_Commands (void) +{ +} + +/* +=========== +IN_Move +=========== +*/ +void IN_MouseMove (usercmd_t *cmd) +{ + if (m_filter->value) + { + mouse_x = (mouse_x + old_mouse_x) * 0.5; + mouse_y = (mouse_y + old_mouse_y) * 0.5; + } + old_mouse_x = mouse_x; + old_mouse_y = mouse_y; + + mouse_x *= sensitivity->value; + mouse_y *= sensitivity->value; + +// add mouse X/Y movement to cmd + if ( (in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1) )) + cmd->sidemove += m_side->value * mouse_x; + else + cl.viewangles[YAW] -= m_yaw->value * mouse_x; + + if (in_mlook.state & 1) + V_StopPitchDrift (); + + if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) + { + cl.viewangles[PITCH] += m_pitch->value * mouse_y; + if (cl.viewangles[PITCH] > 80) + cl.viewangles[PITCH] = 80; + if (cl.viewangles[PITCH] < -70) + cl.viewangles[PITCH] = -70; + } + else + { + if ((in_strafe.state & 1) && noclip_anglehack) + cmd->upmove -= m_forward->value * mouse_y; + else + cmd->forwardmove -= m_forward->value * mouse_y; + } + mouse_x = mouse_y = 0.0; +} + +void IN_Move (usercmd_t *cmd) +{ + IN_MouseMove(cmd); +} + +void VID_InitCvars () +{ + m_filter = Cvar_Get("m_filter", "0", CVAR_NONE, "None"); +} + +void VID_UnlockBuffer() {} +void VID_LockBuffer() {} + diff --git a/source/vid_mgl.c b/source/vid_mgl.c index 664ac38..71a5b77 100644 --- a/source/vid_mgl.c +++ b/source/vid_mgl.c @@ -1,7 +1,7 @@ /* - vid_mgl.c + vid_win.c - Win32 Scitech MGL video driver + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,28 +25,17 @@ $Id$ */ +// vid_win.c -- Win32 video driver #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include - #include "quakedef.h" #include "winquake.h" #include "sys.h" #include "d_local.h" #include "resource.h" #include "in_win.h" -#include "keys.h" -#include "screen.h" -#include "wad.h" -#include "cmd.h" -#include "qendian.h" -#include "draw.h" -#include "console.h" -#include "sound.h" -#include "cdaudio.h" -#include "qargs.h" #define MINIMUM_MEMORY 0x550000 @@ -285,7 +274,7 @@ void VID_UpdateWindowStatus (void) } -extern void CL_ClearStates (); +extern qboolean keydown[256]; /* ================ @@ -294,7 +283,15 @@ ClearAllStates */ void ClearAllStates (void) { - CL_ClearStates (); + int i; + +// send an up event for each key, to make sure the server clears them all + for (i=0 ; i<256 ; i++) + { + if (keydown[i]) + Key_Event (i, false); + } + Key_ClearStates (); IN_ClearStates (); } @@ -1398,7 +1395,7 @@ qboolean VID_SetWindowedMode (int modenum) mainwindow = CreateWindowEx ( ExWindowStyle, "WinQuake", - PROGRAM, + "WinQuake", WindowStyle, 0, 0, WindowRect.right - WindowRect.left, @@ -2776,51 +2773,27 @@ void D_EndDirectRect (int x, int y, int width, int height) //========================================================================== -byte scantokey[128] = -{ -// 0 1 2 3 4 5 6 7 -// 8 9 A B C D E F - 0 , 27, '1', '2', '3', '4', '5', '6', - '7', '8', '9', '0', '-', '=', K_BACKSPACE, 9, // 0 - 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', - 'o', 'p', '[', ']', 13, K_CTRL, 'a', 's', // 1 - 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', - '\'', '`', K_SHIFT,'\\', 'z', 'x', 'c', 'v', // 2 - 'b', 'n', 'm', ',', '.', '/', K_SHIFT,KP_MULTIPLY, - K_ALT, ' ', K_CAPSLOCK,K_F1, K_F2, K_F3, K_F4, K_F5, // 3 - K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE,K_SCRLCK,KP_HOME, - KP_UPARROW,KP_PGUP,KP_MINUS,KP_LEFTARROW,KP_5,KP_RIGHTARROW,KP_PLUS,KP_END, // 4 - KP_DOWNARROW,KP_PGDN,KP_INS,KP_DEL,0, 0, 0, K_F11, - K_F12, 0, 0, 0, 0, 0, 0, 0, // 5 - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; - -byte extscantokey[128] = -{ -// 0 1 2 3 4 5 6 7 -// 8 9 A B C D E F - 0 , 27, '1', '2', '3', '4', '5', '6', - '7', '8', '9', '0', '-', '=', K_BACKSPACE, 9, // 0 - 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', - 'o', 'p', '[', ']', KP_ENTER,K_CTRL,'a', 's', // 1 - 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', - '\'', '`', K_SHIFT,'\\', 'z', 'x', 'c', 'v', // 2 - 'b', 'n', 'm', ',', '.', KP_DIVIDE,K_SHIFT,'*', - K_ALT, ' ', K_CAPSLOCK,K_F1,K_F2, K_F3, K_F4, K_F5, // 3 - K_F6, K_F7, K_F8, K_F9, K_F10, KP_NUMLCK,0, K_HOME, - K_UPARROW,K_PGUP,'-',K_LEFTARROW,'5',K_RIGHTARROW,'+', K_END, // 4 - K_DOWNARROW,K_PGDN,K_INS,K_DEL, 0, 0, 0, K_F11, - K_F12, 0, 0, 0, 0, 0, 0, 0, // 5 - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; - - +byte scantokey[128] = + { +// 0 1 2 3 4 5 6 7 +// 8 9 A B C D E F + 0 , 27, '1', '2', '3', '4', '5', '6', + '7', '8', '9', '0', '-', '=', K_BACKSPACE, 9, // 0 + 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', + 'o', 'p', '[', ']', 13 , K_CTRL,'a', 's', // 1 + 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', + '\'' , '`', K_SHIFT,'\\', 'z', 'x', 'c', 'v', // 2 + 'b', 'n', 'm', ',', '.', '/', K_SHIFT,'*', + K_ALT,' ', 0 , K_F1, K_F2, K_F3, K_F4, K_F5, // 3 + K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE, 0 , K_HOME, + K_UPARROW,K_PGUP,'-',K_LEFTARROW,'5',K_RIGHTARROW,'+',K_END, //4 + K_DOWNARROW,K_PGDN,K_INS,K_DEL,0,0, 0, K_F11, + K_F12,0 , 0 , 0 , 0 , 0 , 0 , 0, // 5 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0, + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0, // 6 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0, + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 // 7 +}; /* ======= @@ -2831,21 +2804,13 @@ Map from windows to quake keynums */ int MapKey (int key) { - int extended; - - extended = (key >> 24) & 1; - key = (key>>16)&255; if (key > 127) return 0; - if (extended) - return extscantokey[key]; - else - return scantokey[key]; + return scantokey[key]; } - void AppActivate(BOOL fActive, BOOL minimize) /**************************************************************************** * diff --git a/source/vid_svgalib.c b/source/vid_svgalib.c index 0704428..95ce11e 100644 --- a/source/vid_svgalib.c +++ b/source/vid_svgalib.c @@ -1,14 +1,9 @@ /* vid_svgalib.c - Linux SVGALib video routines + (description) Copyright (C) 1996-1997 Id Software, Inc. - Copyright (C) 1999-2000 Nelson Rush. - Copyright (C) 1999-2000 Marcus Sundberg [mackan@stacken.kth.se] - Copyright (C) 1999-2000 David Symonds [xoxus@usa.net] - Copyright (C) 1999,2000 contributors of the QuakeForge project - Please see the file "AUTHORS" for a list of contributors This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -34,67 +29,116 @@ #ifdef HAVE_CONFIG_H # include #endif +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "sys.h" +#include "vga.h" +#include "vgakeyboard.h" +#include "vgamouse.h" + #include "quakedef.h" #include "d_local.h" -#include "cvar.h" -#include "cmd.h" -#include "sys.h" -#include "console.h" -#include "input.h" -#include "qargs.h" -#include "qendian.h" -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#if defined(HAVE_SYS_IO_H) -# include -#elif defined(HAVE_ASM_IO_H) -# include -#endif +#define stringify(m) { #m, m } -#include +extern viddef_t vid; +unsigned short d_8to16table[256]; +static byte *vid_surfcache; +static int VID_highhunkmark; +int num_modes; +vga_modeinfo *modes; +int current_mode; -void VGA_UpdatePlanarScreen (void *srcbuffer); +int num_shades=32; +struct +{ + char *name; + int num; +} mice[] = +{ + stringify(MOUSE_MICROSOFT), + stringify(MOUSE_MOUSESYSTEMS), + stringify(MOUSE_MMSERIES), + stringify(MOUSE_LOGITECH), + stringify(MOUSE_BUSMOUSE), + stringify(MOUSE_PS2), +}; -unsigned short d_8to16table[256]; -static byte *vid_surfcache; -static int VID_highhunkmark; - -static int num_modes, current_mode; -static vga_modeinfo *modes; - +static unsigned char scantokey[128]; static byte vid_current_palette[768]; -static int svgalib_inited=0; -static int UseDisplay = 1; +int num_mice = sizeof (mice) / sizeof(mice[0]); -static cvar_t *vid_mode; -static cvar_t *vid_redrawfull; -static cvar_t *vid_waitforrefresh; +int d_con_indirect = 0; -static char *framebuffer_ptr; +int svgalib_inited=0; +int UseMouse = 1; +int UseDisplay = 1; +int UseKeyboard = 1; +int mouserate = MOUSE_DEFAULTSAMPLERATE; + +/* cvar_t vid_mode = {"vid_mode","5",false}; + CVAR_FIXME */ +cvar_t *vid_mode; +/* cvar_t vid_redrawfull = {"vid_redrawfull","0",false}; + CVAR_FIXME */ +cvar_t *vid_redrawfull; +/* cvar_t vid_waitforrefresh = {"vid_waitforrefresh","0",true}; + CVAR_FIXME */ +cvar_t *vid_waitforrefresh; + +char *framebuffer_ptr; + +/* +cvar_t mouse_button_commands[3] = +{ + {"mouse1","+attack"}, + {"mouse2","+strafe"}, + {"mouse3","+forward"}, +}; +CVAR_FIXME */ +cvar_t *mouse_button_commands[3]; + +int mouse_buttons; +int mouse_buttonstate; +int mouse_oldbuttonstate; +float mouse_x, mouse_y; +float old_mouse_x, old_mouse_y; +int mx, my; + +/* cvar_t _windowed_mouse = {"_windowed_mouse", "1", true}; + CVAR_FIXME */ +cvar_t *_windowed_mouse; +/* cvar_t m_filter = {"m_filter","0"}; + CVAR_FIXME */ +cvar_t *m_filter; static byte backingbuf[48*24]; -int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes, VGA_planar; +int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes, VGA_planar; byte *VGA_pagebase; -int VID_options_items = 0; +void VGA_UpdatePlanarScreen (void *srcbuffer); - -void -D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height) +void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height) { int i, j, k, plane, reps, repshift, offset, vidpage, off; if (!svgalib_inited || !vid.direct || !vga_oktowrite()) return; - if (vid.aspect > 1.5) { + if (vid.aspect > 1.5) + { reps = 2; repshift = 1; } else { @@ -105,56 +149,60 @@ D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height) vidpage = 0; vga_setpage(0); - if (VGA_planar) { - for (plane=0 ; plane<4 ; plane++) { - /* Select the correct plane for reading and writing */ + if (VGA_planar) + { + for (plane=0 ; plane<4 ; plane++) + { + // select the correct plane for reading and writing outb(0x02, 0x3C4); outb(1 << plane, 0x3C5); outb(4, 0x3CE); outb(plane, 0x3CF); - for (i=0 ; i<(height << repshift) ; i += reps) { - for (k=0 ; k> 2) ; j++) { + for (i=0 ; i<(height << repshift) ; i += reps) + { + for (k=0 ; k> 2) ; j++) + { backingbuf[(i + k) * 24 + (j << 2) + plane] = - vid.direct[(y + i + k) * VGA_rowbytes + + vid.direct[(y + i + k) * VGA_rowbytes + (x >> 2) + j]; vid.direct[(y + i + k) * VGA_rowbytes + (x>>2) + j] = - pbitmap[(i >> repshift) * 24 + - (j << 2) + plane]; + pbitmap[(i >> repshift) * 24 + + (j << 2) + plane]; } } } } } else { - for (i=0 ; i<(height << repshift) ; i += reps) { - for (j=0 ; j> repshift)*width], - width); + &pbitmap[(i >> repshift)*width], width); } } } } - -void -D_EndDirectRect (int x, int y, int width, int height) +void D_EndDirectRect (int x, int y, int width, int height) { int i, j, k, plane, reps, repshift, offset, vidpage, off; if (!svgalib_inited || !vid.direct || !vga_oktowrite()) return; - if (vid.aspect > 1.5) { + if (vid.aspect > 1.5) + { reps = 2; repshift = 1; } else { @@ -165,95 +213,100 @@ D_EndDirectRect (int x, int y, int width, int height) vidpage = 0; vga_setpage(0); - if (VGA_planar) { - for (plane=0 ; plane<4 ; plane++) { - /* Select the correct plane for writing */ + if (VGA_planar) + { + for (plane=0 ; plane<4 ; plane++) + { + // select the correct plane for writing outb(2, 0x3C4); outb(1 << plane, 0x3C5); outb(4, 0x3CE); outb(plane, 0x3CF); - for (i=0 ; i<(height << repshift) ; i += reps) { - for (k=0 ; k> 2) ; j++) { + for (i=0 ; i<(height << repshift) ; i += reps) + { + for (k=0 ; k> 2) ; j++) + { vid.direct[(y + i + k) * VGA_rowbytes + (x>>2) + j] = - backingbuf[(i + k) * 24 + (j << 2) + plane]; + backingbuf[(i + k) * 24 + (j << 2) + plane]; } } } } } else { - for (i=0 ; i<(height << repshift) ; i += reps) { - for (j=0 ; j 255) inf = 255; + if (inf < 0) + inf = 0; + if (inf > 255) + inf = 255; palette[i] = inf; } VID_SetPalette (palette); - /* Force a surface cache flush */ - vid.recalc_refdef = 1; + vid.recalc_refdef = 1; // force a surface cache flush } } -#endif - -static void -VID_DescribeMode_f(void) +void VID_DescribeMode_f (void) { int modenum; - + modenum = atoi (Cmd_Argv(1)); - if ((modenum >= num_modes) || (modenum < 0 ) || - !modes[modenum].width) { - Con_Printf("Invalid video mode: %d!\n", modenum); - } - Con_Printf("%d: %d x %d - ", modenum, - modes[modenum].width, modes[modenum].height); - if (modes[modenum].bytesperpixel == 0) { + if ((modenum >= num_modes) || (modenum < 0 ) || !modes[modenum].width) + Con_Printf("Invalid video mode: %d!\n",modenum); + Con_Printf("%d: %d x %d - ",modenum,modes[modenum].width,modes[modenum].height); + if (modes[modenum].bytesperpixel == 0) Con_Printf("ModeX\n"); - } else { + else Con_Printf("%d bpp\n", modes[modenum].bytesperpixel<<3); - } } - -static void -VID_DescribeModes_f(void) +void VID_DescribeModes_f (void) { int i; - - for (i=0;i> 2; - } + if (vga_getcolors() == 256) + { - if (UseDisplay && vga_oktowrite()) { + tp = tmppal; + for (i=256*3 ; i ; i--) + *(tp++) = *(palette++) >> 2; + + if (UseDisplay && vga_oktowrite()) vga_setpalvec(0, 256, tmppal); - } + } } - -int -VID_SetMode(int modenum, unsigned char *palette) +int VID_SetMode (int modenum, unsigned char *palette) { int bsize, zsize, tsize; - int err; - if ((modenum >= num_modes) || (modenum < 0) || !modes[modenum].width){ + if ((modenum >= num_modes) || (modenum < 0) || !modes[modenum].width) + { vid_mode->value = (float)current_mode; - + Con_Printf("No such video mode: %d\n",modenum); - + return 0; } vid_mode->value = (float)modenum; - + current_mode=modenum; vid.width = modes[current_mode].width; @@ -442,11 +534,11 @@ VID_SetMode(int modenum, unsigned char *palette) vid.conwidth = vid.width; vid.conheight = vid.height; vid.numpages = 1; - + vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpheight = WARP_HEIGHT; - /* alloc zbuffer and surface cache */ + // alloc zbuffer and surface cache if (d_pzbuffer) { D_FlushCaches(); Hunk_FreeToHighMark (VID_highhunkmark); @@ -468,126 +560,243 @@ VID_SetMode(int modenum, unsigned char *palette) D_InitCaches (vid_surfcache, tsize); - /* get goin' */ - err = vga_setmode(current_mode); - if (err) { - Sys_Error("Video mode failed: %d\n",modenum); - } +// get goin' + + vga_setmode(current_mode); VID_SetPalette(palette); VGA_pagebase = vid.direct = framebuffer_ptr = (char *) vga_getgraphmem(); -#if 0 - if (vga_setlinearaddressing() > 0) { - framebuffer_ptr = (char *) vga_getgraphmem(); - } -#endif - if (!framebuffer_ptr) { +// if (vga_setlinearaddressing()>0) +// framebuffer_ptr = (char *) vga_getgraphmem(); + if (!framebuffer_ptr) Sys_Error("This mode isn't hapnin'\n"); - } vga_setpage(0); - svgalib_inited = 1; + svgalib_inited=1; - /* Force a surface cache flush */ - vid.recalc_refdef = 1; + vid.recalc_refdef = 1; // force a surface cache flush - return 1; + return 0; } - -void -VID_Init(unsigned char *palette) +void VID_InitCvars () { + // It may not look like it, but this is important +} + +void VID_Init(unsigned char *palette) +{ + + int i; int w, h, d; - int err; - //plugin_load("in_svgalib.so"); +// S_Init(); // sound gets initialized here - if (svgalib_inited) return; + if (svgalib_inited) + return; -#if 0 - Cmd_AddCommand ("gamma", VID_Gamma_f); -#endif +// Cmd_AddCommand ("gamma", VID_Gamma_f); - if (UseDisplay) { - err = vga_init(); - if (err) - Sys_Error("SVGALib failed to allocate a new VC\n"); + if (UseDisplay) + { + vga_init(); VID_InitModes(); - vid_mode = Cvar_Get ("vid_mode","5",0,"None"); - vid_redrawfull = Cvar_Get ("vid_redrawfull","0",0,"None"); - vid_waitforrefresh = Cvar_Get ("vid_waitforrefresh","0", - CVAR_ARCHIVE,"None"); - +/* Cvar_RegisterVariable (&vid_mode); + CVAR_FIXME */ + vid_mode = Cvar_Get("vid_mode", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&vid_redrawfull); + CVAR_FIXME */ + vid_redrawfull = Cvar_Get("vid_redrawfull", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&vid_waitforrefresh); + CVAR_FIXME */ + vid_waitforrefresh = Cvar_Get("vid_waitforrefresh", "0", CVAR_NONE|CVAR_ARCHIVE, "None"); + Cmd_AddCommand("vid_nummodes", VID_NumModes_f); Cmd_AddCommand("vid_describemode", VID_DescribeMode_f); Cmd_AddCommand("vid_describemodes", VID_DescribeModes_f); Cmd_AddCommand("vid_debug", VID_Debug_f); - /* Interpret command-line params */ - w = h = d = 0; - if (getenv("GSVGAMODE")) { - current_mode = get_mode(getenv("GSVGAMODE"), w, h, d); - } else if (COM_CheckParm("-mode")) { - current_mode = get_mode(com_argv[COM_CheckParm("-mode")+1], w, h, d); - } else if (COM_CheckParm("-w") || COM_CheckParm("-h") - || COM_CheckParm("-d")) { - if (COM_CheckParm("-w")) { - w = atoi(com_argv[COM_CheckParm("-w")+1]); - } - if (COM_CheckParm("-h")) { - h = atoi(com_argv[COM_CheckParm("-h")+1]); - } - if (COM_CheckParm("-d")) { - d = atoi(com_argv[COM_CheckParm("-d")+1]); - } - current_mode = get_mode(0, w, h, d); - } else { - current_mode = G320x200x256; - } + // interpret command-line params - /* Set vid parameters */ + w = h = d = 0; + if (getenv("GSVGAMODE")) + current_mode = get_mode(getenv("GSVGAMODE"), w, h, d); + else if (COM_CheckParm("-mode")) + current_mode = get_mode(com_argv[COM_CheckParm("-mode")+1], w, h, d); + else if (COM_CheckParm("-w") || COM_CheckParm("-h") + || COM_CheckParm("-d")) + { + if (COM_CheckParm("-w")) + w = atoi(com_argv[COM_CheckParm("-w")+1]); + if (COM_CheckParm("-h")) + h = atoi(com_argv[COM_CheckParm("-h")+1]); + if (COM_CheckParm("-d")) + d = atoi(com_argv[COM_CheckParm("-d")+1]); + current_mode = get_mode(0, w, h, d); + } + else + current_mode = G320x200x256; + + // set vid parameters VID_SetMode(current_mode, palette); VID_SetPalette(palette); - /* XoXus: Running in background is just plain bad... */ - vga_runinbackground(0); + // we do want to run in the background when switched away + vga_runinbackground(1); + } + + if (COM_CheckParm("-nokbd")) UseKeyboard = 0; + + if (UseKeyboard) + { + for (i=0 ; i<128 ; i++) + scantokey[i] = ' '; + + scantokey[ 1] = K_ESCAPE; + scantokey[ 2] = '1'; + scantokey[ 3] = '2'; + scantokey[ 4] = '3'; + scantokey[ 5] = '4'; + scantokey[ 6] = '5'; + scantokey[ 7] = '6'; + scantokey[ 8] = '7'; + scantokey[ 9] = '8'; + scantokey[ 10] = '9'; + scantokey[ 11] = '0'; + scantokey[ 12] = '-'; + scantokey[ 13] = '='; + scantokey[ 14] = K_BACKSPACE; + scantokey[ 15] = K_TAB; + scantokey[ 16] = 'q'; + scantokey[ 17] = 'w'; + scantokey[ 18] = 'e'; + scantokey[ 19] = 'r'; + scantokey[ 20] = 't'; + scantokey[ 21] = 'y'; + scantokey[ 22] = 'u'; + scantokey[ 23] = 'i'; + scantokey[ 24] = 'o'; + scantokey[ 25] = 'p'; + scantokey[ 26] = '['; + scantokey[ 27] = ']'; + scantokey[ 28] = K_ENTER; + scantokey[ 29] = K_CTRL; //left + scantokey[ 30] = 'a'; + scantokey[ 31] = 's'; + scantokey[ 32] = 'd'; + scantokey[ 33] = 'f'; + scantokey[ 34] = 'g'; + scantokey[ 35] = 'h'; + scantokey[ 36] = 'j'; + scantokey[ 37] = 'k'; + scantokey[ 38] = 'l'; + scantokey[ 39] = ';'; + scantokey[ 40] = '\''; + scantokey[ 41] = '`'; + scantokey[ 42] = K_SHIFT; //left + scantokey[ 43] = '\\'; + scantokey[ 44] = 'z'; + scantokey[ 45] = 'x'; + scantokey[ 46] = 'c'; + scantokey[ 47] = 'v'; + scantokey[ 48] = 'b'; + scantokey[ 49] = 'n'; + scantokey[ 50] = 'm'; + scantokey[ 51] = ','; + scantokey[ 52] = '.'; + scantokey[ 53] = '/'; + scantokey[ 54] = K_SHIFT; //right + scantokey[ 55] = '*'; //keypad + scantokey[ 56] = K_ALT; //left + scantokey[ 57] = ' '; + // 58 caps lock + scantokey[ 59] = K_F1; + scantokey[ 60] = K_F2; + scantokey[ 61] = K_F3; + scantokey[ 62] = K_F4; + scantokey[ 63] = K_F5; + scantokey[ 64] = K_F6; + scantokey[ 65] = K_F7; + scantokey[ 66] = K_F8; + scantokey[ 67] = K_F9; + scantokey[ 68] = K_F10; + // 69 numlock + // 70 scrollock + scantokey[ 71] = K_HOME; + scantokey[ 72] = K_UPARROW; + scantokey[ 73] = K_PGUP; + scantokey[ 74] = '-'; + scantokey[ 75] = K_LEFTARROW; + scantokey[ 76] = '5'; + scantokey[ 77] = K_RIGHTARROW; + scantokey[ 79] = K_END; + scantokey[ 78] = '+'; + scantokey[ 80] = K_DOWNARROW; + scantokey[ 81] = K_PGDN; + scantokey[ 82] = K_INS; + scantokey[ 83] = K_DEL; + // 84 to 86 not used + scantokey[ 87] = K_F11; + scantokey[ 88] = K_F12; + // 89 to 95 not used + scantokey[ 96] = K_ENTER; //keypad enter + scantokey[ 97] = K_CTRL; //right + scantokey[ 98] = '/'; + scantokey[ 99] = K_F12; // print screen, bind to screenshot by default + scantokey[100] = K_ALT; // right + + scantokey[101] = K_PAUSE; // break + scantokey[102] = K_HOME; + scantokey[103] = K_UPARROW; + scantokey[104] = K_PGUP; + scantokey[105] = K_LEFTARROW; + scantokey[106] = K_RIGHTARROW; + scantokey[107] = K_END; + scantokey[108] = K_DOWNARROW; + scantokey[109] = K_PGDN; + scantokey[110] = K_INS; + scantokey[111] = K_DEL; + + scantokey[119] = K_PAUSE; + + if (keyboard_init()) + Sys_Error("keyboard_init() failed"); + keyboard_seteventhandler(keyhandler); } - /* XoXus: Why was input initialised here?!? */ - /* IN_Init(); */ } - -void -VID_Update(vrect_t *rects) +void VID_Update(vrect_t *rects) { - if (!svgalib_inited) return; - - if (!vga_oktowrite()) { - /* Can't update screen if it's not active */ + if (!svgalib_inited) return; - } - if (vid_waitforrefresh->value) { + if (!vga_oktowrite()) + return; // can't update screen if it's not active + +/* if (vid_waitforrefresh.value) + CVAR_FIXME */ + if (vid_waitforrefresh->value) vga_waitretrace(); - } - if (VGA_planar) { - VGA_UpdatePlanarScreen(vid.buffer); - } else if (vid_redrawfull->value) { + if (VGA_planar) + VGA_UpdatePlanarScreen (vid.buffer); + +/* else if (vid_redrawfull.value) { + CVAR_FIXME */ + else if (vid_redrawfull->value) { int total = vid.rowbytes * vid.height; int offset; for (offset=0;offset0x10000) - ? 0x10000 : (total-offset))); + memcpy(framebuffer_ptr, + vid.buffer + offset, + ((total-offset>0x10000)?0x10000:(total-offset))); } } else { int ycount; @@ -596,64 +805,262 @@ VID_Update(vrect_t *rects) vga_setpage(0); - while (rects) { + while (rects) + { ycount = rects->height; offset = rects->y * vid.rowbytes + rects->x; - while (ycount--) { + while (ycount--) + { register int i = offset % 0x10000; - + if ((offset / 0x10000) != vidpage) { vidpage=offset / 0x10000; vga_setpage(vidpage); } if (rects->width + i > 0x10000) { - memcpy(framebuffer_ptr + i, - vid.buffer + offset, + memcpy(framebuffer_ptr + i, + vid.buffer + offset, 0x10000 - i); vga_setpage(++vidpage); memcpy(framebuffer_ptr, - vid.buffer + offset + 0x10000 - i, + vid.buffer + offset + 0x10000 - i, rects->width - 0x10000 + i); - } else { - memcpy(framebuffer_ptr + i, - vid.buffer + offset, - rects->width); - } + } else + memcpy(framebuffer_ptr + i, + vid.buffer + offset, + rects->width); offset += vid.rowbytes; } + rects = rects->pnext; } } - - if (vid_mode->value != current_mode) { + +/* if (vid_mode.value != current_mode) + CVAR_FIXME */ + if (vid_mode->value != current_mode) +/* VID_SetMode ((int)vid_mode.value, vid_current_palette); + CVAR_FIXME */ VID_SetMode ((int)vid_mode->value, vid_current_palette); - } +} + +static int dither; + +void VID_DitherOn(void) +{ + if (dither == 0) + { +// R_ViewChanged (&vrect, sb_lines, vid.aspect); + dither = 1; + } +} + +void VID_DitherOff(void) +{ + if (dither) + { +// R_ViewChanged (&vrect, sb_lines, vid.aspect); + dither = 0; + } +} + +void Sys_SendKeyEvents(void) +{ + if (!svgalib_inited) + return; + + if (UseKeyboard) + while (keyboard_update()); +} + +void Force_CenterView_f (void) +{ + cl.viewangles[PITCH] = 0; } -static int dither = 0; - -void -VID_DitherOn(void) +void mousehandler(int buttonstate, int dx, int dy) { - if (dither == 0) { -#if 0 - R_ViewChanged (&vrect, sb_lines, vid.aspect); -#endif - dither = 1; + mouse_buttonstate = buttonstate; + mx += dx; + my += dy; +} + +void IN_Init(void) +{ + + int mtype; + char *mousedev; + int mouserate; + +/* Cvar_RegisterVariable (&m_filter); + CVAR_FIXME */ + m_filter = Cvar_Get("m_filter", "0", CVAR_NONE, "None"); + + if (UseMouse) + { +// Cvar_RegisterVariable (&mouse_button_commands[0]); +// Cvar_RegisterVariable (&mouse_button_commands[1]); +// Cvar_RegisterVariable (&mouse_button_commands[2]); + mouse_button_commands[0] = Cvar_Get ("mouse1","+attack", + CVAR_NONE, "None"); + mouse_button_commands[1] = Cvar_Get ("mouse2","+strafe", + CVAR_NONE, "None"); + mouse_button_commands[2] = Cvar_Get ("mouse3","+forward", + CVAR_NONE, "None"); + Cmd_AddCommand ("force_centerview", Force_CenterView_f); + + mouse_buttons = 3; + + mtype = vga_getmousetype(); + + mousedev = "/dev/mouse"; + if (getenv("MOUSEDEV")) mousedev = getenv("MOUSEDEV"); + if (COM_CheckParm("-mdev")) + mousedev = com_argv[COM_CheckParm("-mdev")+1]; + + mouserate = 1200; + if (getenv("MOUSERATE")) mouserate = atoi(getenv("MOUSERATE")); + if (COM_CheckParm("-mrate")) + mouserate = atoi(com_argv[COM_CheckParm("-mrate")+1]); + +// printf("Mouse: dev=%s,type=%s,speed=%d\n", +// mousedev, mice[mtype].name, mouserate); + if (mouse_init(mousedev, mtype, mouserate)) + { + Con_Printf("No mouse found\n"); + UseMouse = 0; + } + else + mouse_seteventhandler(mousehandler); + + } + +} + +void IN_Shutdown(void) +{ + if (UseMouse) + mouse_close(); +} + +/* +=========== +IN_Commands +=========== +*/ +void IN_Commands (void) +{ + if (UseMouse /*&& cls.state != ca_dedicated*/) + { + // poll mouse values + while (mouse_update()) + ; + + // perform button actions + if ((mouse_buttonstate & MOUSE_LEFTBUTTON) && + !(mouse_oldbuttonstate & MOUSE_LEFTBUTTON)) + Key_Event (K_MOUSE1, true); + else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) && + (mouse_oldbuttonstate & MOUSE_LEFTBUTTON)) + Key_Event (K_MOUSE1, false); + + if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) && + !(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON)) + Key_Event (K_MOUSE2, true); + else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) && + (mouse_oldbuttonstate & MOUSE_RIGHTBUTTON)) + Key_Event (K_MOUSE2, false); + + if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) && + !(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON)) + Key_Event (K_MOUSE3, true); + else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) && + (mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON)) + Key_Event (K_MOUSE3, false); + + mouse_oldbuttonstate = mouse_buttonstate; } } - -void -VID_DitherOff(void) +/* +=========== +IN_Move +=========== +*/ +void IN_MouseMove (usercmd_t *cmd) { - if (dither) { -#if 0 - R_ViewChanged (&vrect, sb_lines, vid.aspect); -#endif - dither = 0; + if (!UseMouse) + return; + + // poll mouse values + while (mouse_update()) + ; + +/* if (m_filter.value) + CVAR_FIXME */ + if (m_filter->value) + { + mouse_x = (mx + old_mouse_x) * 0.5; + mouse_y = (my + old_mouse_y) * 0.5; } + else + { + mouse_x = mx; + mouse_y = my; + } + old_mouse_x = mx; + old_mouse_y = my; + mx = my = 0; // clear for next update + +/* mouse_x *= sensitivity.value; + CVAR_FIXME */ + mouse_x *= sensitivity->value; +/* mouse_y *= sensitivity.value; + CVAR_FIXME */ + mouse_y *= sensitivity->value; + +// add mouse X/Y movement to cmd +/* if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) )) + CVAR_FIXME */ + if ( (in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1) )) +/* cmd->sidemove += m_side.value * mouse_x; + CVAR_FIXME */ + cmd->sidemove += m_side->value * mouse_x; + else +/* cl.viewangles[YAW] -= m_yaw.value * mouse_x; + CVAR_FIXME */ + cl.viewangles[YAW] -= m_yaw->value * mouse_x; + + if (in_mlook.state & 1) + V_StopPitchDrift (); + + if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) + { +/* cl.viewangles[PITCH] += m_pitch.value * mouse_y; + CVAR_FIXME */ + cl.viewangles[PITCH] += m_pitch->value * mouse_y; + if (cl.viewangles[PITCH] > 80) + cl.viewangles[PITCH] = 80; + if (cl.viewangles[PITCH] < -70) + cl.viewangles[PITCH] = -70; + } + else + { + if ((in_strafe.state & 1) && noclip_anglehack) +/* cmd->upmove -= m_forward.value * mouse_y; + CVAR_FIXME */ + cmd->upmove -= m_forward->value * mouse_y; + else +/* cmd->forwardmove -= m_forward.value * mouse_y; + CVAR_FIXME */ + cmd->forwardmove -= m_forward->value * mouse_y; + } +} + +void IN_Move (usercmd_t *cmd) +{ + IN_MouseMove(cmd); } @@ -662,52 +1069,29 @@ VID_DitherOff(void) VID_ModeInfo ================ */ -char * -VID_ModeInfo (int modenum) +char *VID_ModeInfo (int modenum) { - static char *badmodestr = "Bad mode number"; - static char modestr[40]; + static char *badmodestr = "Bad mode number"; + static char modestr[40]; - if (modenum == 0) { - snprintf(modestr, sizeof(modestr), "%d x %d, %d bpp", - vid.width, vid.height, modes[current_mode].bytesperpixel*8); + if (modenum == 0) + { + sprintf (modestr, "%d x %d, %d bpp", + vid.width, vid.height, modes[current_mode].bytesperpixel*8); return (modestr); - } else { + } + else + { return (badmodestr); } } - -void -VID_ExtraOptionDraw(unsigned int options_draw_cursor) +void VID_LockBuffer (void) +{ +} + +void VID_UnlockBuffer (void) { - /* No extra option menu items yet */ } -void -VID_ExtraOptionCmd(int option_cursor) -{ -#if 0 - switch(option_cursor) { - case 1: // Always start with 1 - break; - } -#endif -} - -void VID_InitCvars () -{ - // It may not look like it, but this is important -} - -void -VID_LockBuffer ( void ) -{ -} - -void -VID_UnlockBuffer ( void ) -{ -} - diff --git a/source/vid_wgl.c b/source/vid_wgl.c index f126bb3..de09b9b 100644 --- a/source/vid_wgl.c +++ b/source/vid_wgl.c @@ -1,7 +1,7 @@ /* - vid_wgl.c + gl_vidnt.c - Win32 WGL vid component + (description) Copyright (C) 1996-1997 Id Software, Inc. @@ -25,6 +25,7 @@ $Id$ */ +// gl_vidnt.c -- NT GL vid component #ifdef HAVE_CONFIG_H # include "config.h" @@ -36,12 +37,6 @@ #include "glquake.h" #include "in_win.h" #include -#include "screen.h" -#include "keys.h" -#include "qargs.h" -#include "cmd.h" -#include "qendian.h" -#include "draw.h" #define MAX_MODE_LIST 30 #define VID_ROW_SIZE 3 @@ -121,6 +116,8 @@ HDC maindc; glvert_t glv; +/* cvar_t gl_ztrick = {"gl_ztrick","1"}; + CVAR_FIXME */ cvar_t *gl_ztrick; HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow); @@ -158,15 +155,37 @@ qboolean gl_mtexable = false; //==================================== +/* cvar_t vid_mode = {"vid_mode","0", false}; + CVAR_FIXME */ cvar_t *vid_mode; +// Note that 0 is MODE_WINDOWED +/* cvar_t _vid_default_mode = {"_vid_default_mode","0", true}; + CVAR_FIXME */ cvar_t *_vid_default_mode; +// Note that 3 is MODE_FULLSCREEN_DEFAULT +/* cvar_t _vid_default_mode_win = {"_vid_default_mode_win","3", true}; + CVAR_FIXME */ cvar_t *_vid_default_mode_win; +/* cvar_t vid_wait = {"vid_wait","0"}; + CVAR_FIXME */ cvar_t *vid_wait; +/* cvar_t vid_nopageflip = {"vid_nopageflip","0", true}; + CVAR_FIXME */ cvar_t *vid_nopageflip; +/* cvar_t _vid_wait_override = {"_vid_wait_override", "0", true}; + CVAR_FIXME */ cvar_t *_vid_wait_override; +/* cvar_t vid_config_x = {"vid_config_x","800", true}; + CVAR_FIXME */ cvar_t *vid_config_x; +/* cvar_t vid_config_y = {"vid_config_y","600", true}; + CVAR_FIXME */ cvar_t *vid_config_y; +/* cvar_t vid_stretch_by_2 = {"vid_stretch_by_2","1", true}; + CVAR_FIXME */ cvar_t *vid_stretch_by_2; +/* cvar_t _windowed_mouse = {"_windowed_mouse","1", true}; + CVAR_FIXME */ cvar_t *_windowed_mouse; int window_center_x, window_center_y, window_x, window_y, window_width, window_height; @@ -425,6 +444,8 @@ int VID_SetMode (int modenum, unsigned char *palette) // Set either the fullscreen or windowed mode if (modelist[modenum].type == MS_WINDOWED) { +/* if (_windowed_mouse.value && key_dest == key_game) + CVAR_FIXME */ if (_windowed_mouse->value && key_dest == key_game) { stat = VID_SetWindowedMode(modenum); @@ -685,6 +706,8 @@ GL_BeginRendering */ void GL_BeginRendering (int *x, int *y, int *width, int *height) { +/* extern cvar_t gl_clear; + CVAR_FIXME */ extern cvar_t *gl_clear; *x = *y = 0; @@ -706,6 +729,8 @@ void GL_EndRendering (void) // handle the mouse state when windowed if that's changed if (modestate == MS_WINDOWED) { +/* if (!_windowed_mouse.value) { + CVAR_FIXME */ if (!_windowed_mouse->value) { if (windowed_mouse) { IN_DeactivateMouse (); @@ -878,52 +903,50 @@ BOOL bSetupPixelFormat(HDC hDC) } -//========================================================================== -byte scantokey[128] = -{ -// 0 1 2 3 4 5 6 7 -// 8 9 A B C D E F - 0 , 27, '1', '2', '3', '4', '5', '6', - '7', '8', '9', '0', '-', '=', K_BACKSPACE, 9, // 0 - 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', - 'o', 'p', '[', ']', 13, K_CTRL, 'a', 's', // 1 - 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', - '\'', '`', K_SHIFT,'\\', 'z', 'x', 'c', 'v', // 2 - 'b', 'n', 'm', ',', '.', '/', K_SHIFT,KP_MULTIPLY, - K_ALT, ' ', K_CAPSLOCK,K_F1, K_F2, K_F3, K_F4, K_F5, // 3 - K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE,K_SCRLCK,KP_HOME, - KP_UPARROW,KP_PGUP,KP_MINUS,KP_LEFTARROW,KP_5,KP_RIGHTARROW,KP_PLUS,KP_END, // 4 - KP_DOWNARROW,KP_PGDN,KP_INS,KP_DEL,0, 0, 0, K_F11, - K_F12, 0, 0, 0, 0, 0, 0, 0, // 5 - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; - -byte extscantokey[128] = -{ -// 0 1 2 3 4 5 6 7 -// 8 9 A B C D E F - 0 , 27, '1', '2', '3', '4', '5', '6', - '7', '8', '9', '0', '-', '=', K_BACKSPACE, 9, // 0 - 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', - 'o', 'p', '[', ']', KP_ENTER,K_CTRL,'a', 's', // 1 - 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', - '\'', '`', K_SHIFT,'\\', 'z', 'x', 'c', 'v', // 2 - 'b', 'n', 'm', ',', '.', KP_DIVIDE,K_SHIFT,'*', - K_ALT, ' ', K_CAPSLOCK,K_F1,K_F2, K_F3, K_F4, K_F5, // 3 - K_F6, K_F7, K_F8, K_F9, K_F10, KP_NUMLCK,0, K_HOME, - K_UPARROW,K_PGUP,'-',K_LEFTARROW,'5',K_RIGHTARROW,'+', K_END, // 4 - K_DOWNARROW,K_PGDN,K_INS,K_DEL, 0, 0, 0, K_F11, - K_F12, 0, 0, 0, 0, 0, 0, 0, // 5 - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; +byte scantokey[128] = + { +// 0 1 2 3 4 5 6 7 +// 8 9 A B C D E F + 0 , 27, '1', '2', '3', '4', '5', '6', + '7', '8', '9', '0', '-', '=', K_BACKSPACE, 9, // 0 + 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', + 'o', 'p', '[', ']', 13 , K_CTRL,'a', 's', // 1 + 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', + '\'' , '`', K_SHIFT,'\\', 'z', 'x', 'c', 'v', // 2 + 'b', 'n', 'm', ',', '.', '/', K_SHIFT,'*', + K_ALT,' ', 0 , K_F1, K_F2, K_F3, K_F4, K_F5, // 3 + K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE , 0 , K_HOME, + K_UPARROW,K_PGUP,'-',K_LEFTARROW,'5',K_RIGHTARROW,'+',K_END, //4 + K_DOWNARROW,K_PGDN,K_INS,K_DEL,0,0, 0, K_F11, + K_F12,0 , 0 , 0 , 0 , 0 , 0 , 0, // 5 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0, + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0, // 6 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0, + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 // 7 + }; +byte shiftscantokey[128] = + { +// 0 1 2 3 4 5 6 7 +// 8 9 A B C D E F + 0 , 27, '!', '@', '#', '$', '%', '^', + '&', '*', '(', ')', '_', '+', K_BACKSPACE, 9, // 0 + 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', + 'O', 'P', '{', '}', 13 , K_CTRL,'A', 'S', // 1 + 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', + '"' , '~', K_SHIFT,'|', 'Z', 'X', 'C', 'V', // 2 + 'B', 'N', 'M', '<', '>', '?', K_SHIFT,'*', + K_ALT,' ', 0 , K_F1, K_F2, K_F3, K_F4, K_F5, // 3 + K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE , 0 , K_HOME, + K_UPARROW,K_PGUP,'_',K_LEFTARROW,'%',K_RIGHTARROW,'+',K_END, //4 + K_DOWNARROW,K_PGDN,K_INS,K_DEL,0,0, 0, K_F11, + K_F12,0 , 0 , 0 , 0 , 0 , 0 , 0, // 5 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0, + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0, // 6 + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0, + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 // 7 + }; /* @@ -935,21 +958,14 @@ Map from windows to quake keynums */ int MapKey (int key) { - int extended; - - extended = (key >> 24) & 1; - key = (key>>16)&255; if (key > 127) return 0; - - if (extended) - return extscantokey[key]; - else - return scantokey[key]; + if (scantokey[key] == 0) + Con_DPrintf("key 0x%02x has no translation\n", key); + return scantokey[key]; } - /* =================================================================== @@ -958,7 +974,7 @@ MAIN WINDOW =================================================================== */ -extern void CL_ClearStates (); +extern qboolean keydown[256]; /* ================ @@ -967,7 +983,15 @@ ClearAllStates */ void ClearAllStates (void) { - CL_ClearStates (); + int i; + +// send an up event for each key, to make sure the server clears them all + for (i=0 ; i<256 ; i++) + { + if (keydown[i]) + Key_Event (i, false); + } + Key_ClearStates (); IN_ClearStates (); } @@ -1016,6 +1040,8 @@ void AppActivate(BOOL fActive, BOOL minimize) ShowWindow(mainwindow, SW_SHOWNORMAL); } } +/* else if ((modestate == MS_WINDOWED) && _windowed_mouse.value && key_dest == key_game) + CVAR_FIXME */ else if ((modestate == MS_WINDOWED) && _windowed_mouse->value && key_dest == key_game) { IN_ActivateMouse (); @@ -1034,6 +1060,8 @@ void AppActivate(BOOL fActive, BOOL minimize) vid_wassuspended = true; } } +/* else if ((modestate == MS_WINDOWED) && _windowed_mouse.value) + CVAR_FIXME */ else if ((modestate == MS_WINDOWED) && _windowed_mouse->value) { IN_DeactivateMouse (); @@ -1612,19 +1640,38 @@ void VID_Init (unsigned char *palette) memset(&devmode, 0, sizeof(devmode)); -// Note that 0 is MODE_WINDOWED +/* Cvar_RegisterVariable (&vid_mode); + CVAR_FIXME */ vid_mode = Cvar_Get("vid_mode", "0", CVAR_NONE, "None"); - _vid_default_mode = Cvar_Get("_vid_default_mode", "0", CVAR_ARCHIVE, "None"); -// Note that 3 is MODE_FULLSCREEN_DEFAULT - _vid_default_mode_win = Cvar_Get("_vid_default_mode_win", "3", CVAR_ARCHIVE, "None"); - +/* Cvar_RegisterVariable (&vid_wait); + CVAR_FIXME */ vid_wait = Cvar_Get("vid_wait", "0", CVAR_NONE, "None"); +/* Cvar_RegisterVariable (&vid_nopageflip); + CVAR_FIXME */ vid_nopageflip = Cvar_Get("vid_nopageflip", "0", CVAR_ARCHIVE, "None"); +/* Cvar_RegisterVariable (&_vid_wait_override); + CVAR_FIXME */ _vid_wait_override = Cvar_Get("_vid_wait_override", "0", CVAR_ARCHIVE, "None"); +/* Cvar_RegisterVariable (&_vid_default_mode); + CVAR_FIXME */ + _vid_default_mode = Cvar_Get("_vid_default_mode", "0", CVAR_ARCHIVE, "None"); +/* Cvar_RegisterVariable (&_vid_default_mode_win); + CVAR_FIXME */ + _vid_default_mode_win = Cvar_Get("_vid_default_mode_win", "3", CVAR_ARCHIVE, "None"); +/* Cvar_RegisterVariable (&vid_config_x); + CVAR_FIXME */ vid_config_x = Cvar_Get("vid_config_x", "800", CVAR_ARCHIVE, "None"); +/* Cvar_RegisterVariable (&vid_config_y); + CVAR_FIXME */ vid_config_y = Cvar_Get("vid_config_y", "600", CVAR_ARCHIVE, "None"); +/* Cvar_RegisterVariable (&vid_stretch_by_2); + CVAR_FIXME */ vid_stretch_by_2 = Cvar_Get("vid_stretch_by_2", "1", CVAR_ARCHIVE, "None"); +/* Cvar_RegisterVariable (&_windowed_mouse); + CVAR_FIXME */ _windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None"); +/* Cvar_RegisterVariable (&gl_ztrick); + CVAR_FIXME */ gl_ztrick = Cvar_Get("gl_ztrick", "1", CVAR_NONE, "None"); Cmd_AddCommand ("vid_nummodes", VID_NumModes_f); diff --git a/source/vid_x11.c b/source/vid_x11.c index 670a5e9..61d0cf5 100644 --- a/source/vid_x11.c +++ b/source/vid_x11.c @@ -1,13 +1,9 @@ /* vid_x11.c - general x11 video driver + General X11 video driver Copyright (C) 1996-1997 Id Software, Inc. - Copyright (C) 1999-2000 contributors of the QuakeForge project - Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se] - Copyright (C) 1999,2000 contributors of the QuakeForge project - Please see the file "AUTHORS" for a list of contributors This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -31,19 +27,24 @@ */ #define _BSD -#include -#include +typedef unsigned short PIXEL; + +#ifdef HAVE_CONFIG_H +# include +#endif +#include "sys.h" +#include "quakedef.h" +#include "d_local.h" + #include #include #include -#include #include #include #include -#ifdef HAVE_UNISTD_H #include -#endif +#include #include #include #include @@ -52,163 +53,135 @@ #include #include -#include "qendian.h" -#include "qargs.h" -#include "quakedef.h" -#include "d_local.h" -#include "keys.h" -#include "cvar.h" -#include "menu.h" -#include "sys.h" -#include "cmd.h" -#include "input.h" -#include "draw.h" -#include "console.h" -#include "client.h" -#include "input.h" -#include "context_x11.h" -#ifdef HAVE_VIDMODE -# include -#endif -#include "dga_check.h" +/* cvar_t _windowed_mouse = {"_windowed_mouse","0", true}; + CVAR_FIXME */ +cvar_t *_windowed_mouse; +/* cvar_t m_filter = {"m_filter","0", true}; + CVAR_FIXME */ +cvar_t *m_filter; +float old_windowed_mouse; -#ifdef HAVE_STRINGS_H -#include -#endif +// not used +int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes, VGA_planar; +byte *VGA_pagebase; -extern viddef_t vid; // global video state -unsigned short d_8to16table[256]; -Window x_win; -static Colormap x_cmap; -static GC x_gc; -static Visual *x_vis; -static XVisualInfo *x_visinfo; -static Atom aWMDelete = 0; +qboolean mouse_avail; +int mouse_buttons=3; +int mouse_oldbuttonstate; +int mouse_buttonstate; +float mouse_x, mouse_y; +float old_mouse_x, old_mouse_y; +int p_mouse_x; +int p_mouse_y; +int ignorenext; +int bits_per_pixel; -#ifdef HAVE_VIDMODE -static XF86VidModeModeInfo **vidmodes; -static int nummodes, hasvidmode = 0; -#endif +typedef struct +{ + int input; + int output; +} keymap_t; -int XShmQueryExtension(Display *); -int XShmGetEventBase(Display *); +extern viddef_t vid; // global video state +unsigned short d_8to16table[256]; -qboolean doShm; +int num_shades=32; + +int d_con_indirect = 0; + +int vid_buffersize; + +static qboolean doShm; +static Display *x_disp; +static Colormap x_cmap; +static Window x_win; +static GC x_gc; +static Visual *x_vis; +static XVisualInfo *x_visinfo; +//static XImage *x_image; + +static int x_shmeventtype; +//static XShmSegmentInfo x_shminfo; + +static qboolean oktodraw = false; + +int XShmQueryExtension(Display *); +int XShmGetEventBase(Display *); + +int current_framebuffer; +static XImage *x_framebuffer[2] = { 0, 0 }; static XShmSegmentInfo x_shminfo[2]; -static int current_framebuffer; -static XImage *x_framebuffer[2] = { 0, 0 }; - -static int verbose = 0; - -int VID_options_items = 1; +static int verbose=0; static byte current_palette[768]; -cvar_t *vid_fullscreen; +static long X11_highhunkmark; +static long X11_buffersize; -typedef unsigned short PIXEL16; -typedef unsigned long PIXEL24; -static PIXEL16 st2d_8to16table[256]; -static PIXEL24 st2d_8to24table[256]; +int vid_surfcachesize; +void *vid_surfcache; + +void (*vid_menudrawfn)(void); +void (*vid_menukeyfn)(int key); +void VID_MenuKey (int key); + +static PIXEL st2d_8to16table[256]; static int shiftmask_fl=0; static long r_shift,g_shift,b_shift; static unsigned long r_mask,g_mask,b_mask; -static long X11_highhunkmark; - -int scr_width, scr_height; - -#define STD_EVENT_MASK \ - ( VisibilityChangeMask | ExposureMask | StructureNotifyMask) - - -static void -shiftmask_init( void ) +void shiftmask_init() { - unsigned int x; - - r_mask=x_vis->red_mask; - g_mask=x_vis->green_mask; - b_mask=x_vis->blue_mask; - for (r_shift=-8,x=1; xred_mask; + g_mask=x_vis->green_mask; + b_mask=x_vis->blue_mask; + for(r_shift=-8,x=1;x0) { + p=(r<<(r_shift))&r_mask; + } else if(r_shift<0) { + p=(r>>(-r_shift))&r_mask; + } else p|=(r&r_mask); - if (r_shift>0) { - p=(r<<(r_shift))&r_mask; - } else if (r_shift<0) { - p=(r>>(-r_shift))&r_mask; - } else p|=(r&r_mask); + if(g_shift>0) { + p|=(g<<(g_shift))&g_mask; + } else if(g_shift<0) { + p|=(g>>(-g_shift))&g_mask; + } else p|=(g&g_mask); - if (g_shift>0) { - p|=(g<<(g_shift))&g_mask; - } else if (g_shift<0) { - p|=(g>>(-g_shift))&g_mask; - } else p|=(g&g_mask); + if(b_shift>0) { + p|=(b<<(b_shift))&b_mask; + } else if(b_shift<0) { + p|=(b>>(-b_shift))&b_mask; + } else p|=(b&b_mask); - if (b_shift>0) { - p|=(b<<(b_shift))&b_mask; - } else if (b_shift<0) { - p|=(b>>(-b_shift))&b_mask; - } else p|=(b&b_mask); - - return p; + return p; } - -static PIXEL24 -xlib_rgb24(int r,int g,int b) -{ - PIXEL24 p = 0; - - if (shiftmask_fl==0) shiftmask_init(); - - if (r_shift>0) { - p=(r<<(r_shift))&r_mask; - } else if (r_shift<0) { - p=(r>>(-r_shift))&r_mask; - } else p|=(r&r_mask); - - if (g_shift>0) { - p|=(g<<(g_shift))&g_mask; - } else if (g_shift<0) { - p|=(g>>(-g_shift))&g_mask; - } else p|=(g&g_mask); - - if (b_shift>0) { - p|=(b<<(b_shift))&b_mask; - } else if (b_shift<0) { - p|=(b>>(-b_shift))&b_mask; - } else p|=(b&b_mask); - - return p; -} - - -static void -st2_fixup(XImage *framebuf, int x, int y, int width, int height) +void st2_fixup( XImage *framebuf, int x, int y, int width, int height) { int xi,yi; unsigned char *src; - PIXEL16 *dest; + PIXEL *dest; - if (x < 0 || y < 0) return; + if( (x<0)||(y<0) )return; for (yi = y; yi < (y+height); yi++) { src = &framebuf->data [yi * framebuf->bytes_per_line]; - dest = (PIXEL16*)src; + dest = (PIXEL*)src; for(xi = (x+width-1); xi >= x; xi--) { dest[xi] = st2d_8to16table[src[xi]]; } @@ -216,132 +189,83 @@ st2_fixup(XImage *framebuf, int x, int y, int width, int height) } -static void -st3_fixup(XImage *framebuf, int x, int y, int width, int height) +// ======================================================================== +// Tragic death handler +// ======================================================================== + +void TragicDeath(int signal_num) { - int yi; - unsigned char *src; - PIXEL24 *dest; - register int count, n; - - if (x < 0 || y < 0) return; - - for (yi = y; yi < (y+height); yi++) { - src = &framebuf->data [yi * framebuf->bytes_per_line]; - - // Duff's Device - count = width; - n = (count + 7) / 8; - dest = ((PIXEL24 *)src) + x+width - 1; - src += x+width - 1; - - switch (count % 8) { - case 0: do { *dest-- = st2d_8to24table[*src--]; - case 7: *dest-- = st2d_8to24table[*src--]; - case 6: *dest-- = st2d_8to24table[*src--]; - case 5: *dest-- = st2d_8to24table[*src--]; - case 4: *dest-- = st2d_8to24table[*src--]; - case 3: *dest-- = st2d_8to24table[*src--]; - case 2: *dest-- = st2d_8to24table[*src--]; - case 1: *dest-- = st2d_8to24table[*src--]; - } while (--n > 0); - } - -// for(xi = (x+width-1); xi >= x; xi--) { -// dest[xi] = st2d_8to16table[src[xi]]; -// } - } -} - -/* -================ -D_BeginDirectRect -================ -*/ -void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height) -{ -// direct drawing of the "accessing disk" icon isn't supported + XAutoRepeatOn(x_disp); + XCloseDisplay(x_disp); + Sys_Error("This death brought to you by signal number %d\n", signal_num); } /* -================ -D_EndDirectRect -================ -*/ -void D_EndDirectRect (int x, int y, int width, int height) -{ -// direct drawing of the "accessing disk" icon isn't supported -} - - -/* -================= -VID_Gamma_f - -Keybinding command -================= +======================================================================== +Create an empty cursor +======================================================================== */ -byte vid_gamma[256]; +static Cursor nullcursor = None; -void VID_Gamma_f (void) +static Cursor +CreateNullCursor(Display *display, Window root) { + Pixmap cursormask; + XGCValues xgc; + GC gc; + XColor dummycolour; - float g, f, inf; - int i; + if (nullcursor != None) return nullcursor; - if (Cmd_Argc () == 2) { - g = atof (Cmd_Argv(1)); + cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/); + xgc.function = GXclear; + gc = XCreateGC(display, cursormask, GCFunction, &xgc); + XFillRectangle(display, cursormask, gc, 0, 0, 1, 1); + dummycolour.pixel = 0; + dummycolour.red = 0; + dummycolour.flags = 04; + nullcursor = XCreatePixmapCursor(display, cursormask, cursormask, + &dummycolour,&dummycolour, 0,0); + XFreePixmap(display,cursormask); + XFreeGC(display,gc); - for (i=0 ; i<255 ; i++) { - f = pow ((i+1)/256.0, g); - inf = f*255 + 0.5; - if (inf < 0) inf = 0; - if (inf > 255) inf = 255; - vid_gamma[i] = inf; - } - - VID_SetPalette(current_palette); - - vid.recalc_refdef = 1; // force a surface cache flush - } + return nullcursor; } - -static void -ResetFrameBuffer(void) +void ResetFrameBuffer(void) { - int vid_surfcachesize, buffersize; - void *vid_surfcache; - int mem, pwidth; + int mem; + int pwidth; - if (x_framebuffer[0]) { - XDestroyImage(x_framebuffer[0]); + if (x_framebuffer[0]) + { + free(x_framebuffer[0]->data); + free(x_framebuffer[0]); } - if (d_pzbuffer) { + if (d_pzbuffer) + { D_FlushCaches (); - Hunk_FreeToHighMark(X11_highhunkmark); + Hunk_FreeToHighMark (X11_highhunkmark); d_pzbuffer = NULL; } X11_highhunkmark = Hunk_HighMark (); - /* Alloc an extra line in case we want to wrap, and allocate - the z-buffer */ - buffersize = vid.width * vid.height * sizeof(*d_pzbuffer); +// alloc an extra line in case we want to wrap, and allocate the z-buffer + X11_buffersize = vid.width * vid.height * sizeof (*d_pzbuffer); - vid_surfcachesize = D_SurfaceCacheForRes(vid.width, vid.height); + vid_surfcachesize = D_SurfaceCacheForRes (vid.width, vid.height); - buffersize += vid_surfcachesize; + X11_buffersize += vid_surfcachesize; - d_pzbuffer = Hunk_HighAllocName(buffersize, "video"); - if (d_pzbuffer == NULL) { + d_pzbuffer = Hunk_HighAllocName (X11_buffersize, "video"); + if (d_pzbuffer == NULL) Sys_Error ("Not enough memory for video mode\n"); - } vid_surfcache = (byte *) d_pzbuffer - + vid.width * vid.height * sizeof(*d_pzbuffer); + + vid.width * vid.height * sizeof (*d_pzbuffer); D_InitCaches(vid_surfcache, vid_surfcachesize); @@ -349,47 +273,51 @@ ResetFrameBuffer(void) if (pwidth == 3) pwidth = 4; mem = ((vid.width*pwidth+7)&~7) * vid.height; - x_framebuffer[0] = XCreateImage(x_disp, x_vis, x_visinfo->depth, - ZPixmap, 0, - malloc(mem), - vid.width, vid.height, - 32, 0); + x_framebuffer[0] = XCreateImage( x_disp, + x_vis, + x_visinfo->depth, + ZPixmap, + 0, + malloc(mem), + vid.width, vid.height, + 32, + 0); - if (!x_framebuffer[0]) { + if (!x_framebuffer[0]) Sys_Error("VID: XCreateImage failed\n"); - } + + vid.buffer = (byte*) (x_framebuffer[0]); + vid.conbuffer = vid.buffer; + } - -static void -ResetSharedFrameBuffers(void) +void ResetSharedFrameBuffers(void) { - int vid_surfcachesize, buffersize; - void *vid_surfcache; + int size; int key; int minsize = getpagesize(); int frm; - if (d_pzbuffer) { + if (d_pzbuffer) + { D_FlushCaches (); - Hunk_FreeToHighMark(X11_highhunkmark); + Hunk_FreeToHighMark (X11_highhunkmark); d_pzbuffer = NULL; } X11_highhunkmark = Hunk_HighMark (); // alloc an extra line in case we want to wrap, and allocate the z-buffer - buffersize = vid.width * vid.height * sizeof (*d_pzbuffer); + X11_buffersize = vid.width * vid.height * sizeof (*d_pzbuffer); vid_surfcachesize = D_SurfaceCacheForRes (vid.width, vid.height); - buffersize += vid_surfcachesize; + X11_buffersize += vid_surfcachesize; - d_pzbuffer = Hunk_HighAllocName(buffersize, "video"); - if (d_pzbuffer == NULL) { + d_pzbuffer = Hunk_HighAllocName (X11_buffersize, "video"); + if (d_pzbuffer == NULL) Sys_Error ("Not enough memory for video mode\n"); - } vid_surfcache = (byte *) d_pzbuffer + vid.width * vid.height * sizeof (*d_pzbuffer); @@ -451,57 +379,65 @@ ResetSharedFrameBuffers(void) } -static void event_shm(XEvent *event) -{ - if (doShm) - oktodraw = true; -} - // Called at startup to set up translation tables, takes 256 8 bit RGB values // the palette data will go away after the call, so it must be copied off if // the video driver will need it again -void VID_Init (unsigned char *palette) +void VID_InitCvars () { - int pnum, i; - XVisualInfo template; - int num_visuals; - int template_mask; + // It may not look like it, but this is important +} - //plugin_load("in_x11.so"); - vid_fullscreen = Cvar_Get ("vid_fullscreen","0",CVAR_NONE, - "Toggles fullscreen game mode"); -// Cmd_AddCommand("gamma", VID_Gamma_f); - for (i=0; i < 256; i++) vid_gamma[i] = i; +void VID_Init (unsigned char *palette) +{ - vid.width = 320; - vid.height = 200; - vid.maxwarpwidth = WARP_WIDTH; - vid.maxwarpheight = WARP_HEIGHT; - vid.numpages = 2; - vid.colormap = host_colormap; - vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048)); - //vid.cbits = VID_CBITS; - //vid.grades = VID_GRADES; + int pnum, i; + XVisualInfo template; + int num_visuals; + int template_mask; +// S_Init(); + + ignorenext=0; + vid.width = 320; + vid.height = 200; + vid.maxwarpwidth = WARP_WIDTH; + vid.maxwarpheight = WARP_HEIGHT; + vid.numpages = 2; + vid.colormap = host_colormap; + // vid.cbits = VID_CBITS; + // vid.grades = VID_GRADES; + vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048)); + srandom(getpid()); verbose=COM_CheckParm("-verbose"); // open the display - x11_open_display(); - -#ifdef HAVE_VIDMODE - hasvidmode = VID_CheckVMode(x_disp, NULL, NULL); - if (hasvidmode) { - if (! XF86VidModeGetAllModeLines(x_disp, DefaultScreen(x_disp), - &nummodes, &vidmodes) - || nummodes <= 0) { - hasvidmode = 0; - } + x_disp = XOpenDisplay(0); + if (!x_disp) + { + if (getenv("DISPLAY")) + Sys_Error("VID: Could not open display [%s]\n", + getenv("DISPLAY")); + else + Sys_Error("VID: Could not open local display\n"); } - Con_SafePrintf ("hasvidmode = %i\nnummodes = %i\n", hasvidmode, nummodes); -#endif + +// catch signals so i can turn on auto-repeat + + { + struct sigaction sa; + sigaction(SIGINT, 0, &sa); + sa.sa_handler = TragicDeath; + sigaction(SIGINT, &sa, 0); + sigaction(SIGTERM, &sa, 0); + } + + XAutoRepeatOff(x_disp); + +// for debugging only + XSynchronize(x_disp, True); // check for command-line window size if ((pnum=COM_CheckParm("-winsize"))) @@ -551,25 +487,24 @@ void VID_Init (unsigned char *palette) // pick a visual- warn if more than one was available x_visinfo = XGetVisualInfo(x_disp, template_mask, &template, &num_visuals); - if (num_visuals > 1) { + if (num_visuals > 1) + { printf("Found more than one visual id at depth %d:\n", template.depth); for (i=0 ; ivisualid)); - printf(" class %d\n", x_visinfo->class); printf(" screen %d\n", x_visinfo->screen); - printf(" depth %d\n", x_visinfo->depth); printf(" red_mask 0x%x\n", (int)(x_visinfo->red_mask)); printf(" green_mask 0x%x\n", (int)(x_visinfo->green_mask)); printf(" blue_mask 0x%x\n", (int)(x_visinfo->blue_mask)); @@ -579,76 +514,56 @@ void VID_Init (unsigned char *palette) x_vis = x_visinfo->visual; - /* Setup attributes for main window */ +// setup attributes for main window { - int attribmask = CWEventMask | CWBorderPixel; - XSetWindowAttributes attribs; + int attribmask = CWEventMask | CWColormap | CWBorderPixel; + XSetWindowAttributes attribs; + Colormap tmpcmap; + + tmpcmap = XCreateColormap(x_disp, XRootWindow(x_disp, + x_visinfo->screen), x_vis, AllocNone); + + attribs.event_mask = StructureNotifyMask | KeyPressMask + | KeyReleaseMask | ExposureMask | PointerMotionMask | + ButtonPressMask | ButtonReleaseMask; + attribs.border_pixel = 0; + attribs.colormap = tmpcmap; - attribs.event_mask = STD_EVENT_MASK; - attribs.border_pixel = 0; +// create the main window + x_win = XCreateWindow( x_disp, + XRootWindow(x_disp, x_visinfo->screen), + 0, 0, // x, y + vid.width, vid.height, + 0, // borderwidth + x_visinfo->depth, + InputOutput, + x_vis, + attribmask, + &attribs ); + XStoreName( x_disp,x_win,"xquake"); -#ifdef HAVE_VIDMODE - if (hasvidmode && vid_fullscreen->value) { - int smallest_mode=0, x=INT_MAX, y=INT_MAX; - attribs.override_redirect=1; - attribmask|=CWOverrideRedirect; + if (x_visinfo->class != TrueColor) + XFreeColormap(x_disp, tmpcmap); - // FIXME: does this depend on mode line order in XF86Config? - for (i=0; ividmodes[i]->hdisplay || y>vidmodes[i]->vdisplay) { - smallest_mode=i; - x=vidmodes[i]->hdisplay; - y=vidmodes[i]->vdisplay; - } - printf("%dx%d\n",vidmodes[i]->hdisplay,vidmodes[i]->vdisplay); - } - // chose the smallest mode that our window fits into; - for (i=smallest_mode; - i!=(smallest_mode+1)%nummodes; - i=(i?i-1:nummodes-1)) { - if (vidmodes[i]->hdisplay>=vid.width - && vidmodes[i]->vdisplay>=vid.height) { - XF86VidModeSwitchToMode (x_disp, DefaultScreen (x_disp), - vidmodes[i]); - break; - } - } - XF86VidModeSetViewPort(x_disp, DefaultScreen (x_disp), 0, 0); - _windowed_mouse = Cvar_Get ("_windowed_mouse","1",CVAR_ARCHIVE|CVAR_ROM,"None"); - } else -#endif - _windowed_mouse = Cvar_Get ("_windowed_mouse","0",CVAR_ARCHIVE,"None"); - - /* Create the main window */ - x_win = XCreateWindow(x_disp, - XRootWindow(x_disp, x_visinfo->screen), - 0, 0, vid.width, vid.height, - 0, /* borderwidth */ - x_visinfo->depth, InputOutput, x_vis, - attribmask, &attribs); - - scr_width = vid.width; - scr_height = vid.height; - - /* Give it a title */ - XStoreName(x_disp, x_win, "XQuake"); - - /* Make window respond to Delete events */ - aWMDelete = XInternAtom(x_disp, "WM_DELETE_WINDOW", False); - XSetWMProtocols(x_disp, x_win, &aWMDelete, 1); } - if (x_visinfo->depth == 8) { - /* Create and upload the palette */ - if (x_visinfo->class == PseudoColor) { - x_cmap = XCreateColormap(x_disp, x_win, - x_vis, AllocAll); + if (x_visinfo->depth == 8) + { + + // create and upload the palette + if (x_visinfo->class == PseudoColor) + { + x_cmap = XCreateColormap(x_disp, x_win, x_vis, AllocAll); VID_SetPalette(palette); XSetWindowColormap(x_disp, x_win, x_cmap); } + } + /* Invisible Cursor */ + XDefineCursor(x_disp, x_win, CreateNullCursor(x_disp, x_win)); + // create the GC { XGCValues xgcvalues; @@ -657,15 +572,8 @@ void VID_Init (unsigned char *palette) x_gc = XCreateGC(x_disp, x_win, valuemask, &xgcvalues ); } -// map the window + /* Map the window */ XMapWindow(x_disp, x_win); -#ifdef HAVE_VIDMODE - if (hasvidmode && vid_fullscreen->value) { - XRaiseWindow(x_disp, x_win); - XGrabKeyboard(x_disp, x_win, 1, GrabModeAsync, GrabModeAsync, - CurrentTime); - } -#endif // wait for first exposure event { @@ -681,7 +589,6 @@ void VID_Init (unsigned char *palette) // even if MITSHM is available, make sure it's a local connection if (XShmQueryExtension(x_disp)) - //if (0) { char *displayname; doShm = true; @@ -715,84 +622,310 @@ void VID_Init (unsigned char *palette) vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0); // XSynchronize(x_disp, False); - x11_add_event(x_shmeventtype, event_shm); + } - -void -VID_ShiftPalette(unsigned char *p) +void VID_ShiftPalette(unsigned char *p) { VID_SetPalette(p); } -void -VID_SetPalette(unsigned char *palette) + +void VID_SetPalette(unsigned char *palette) { + int i; XColor colors[256]; - for (i=0;i<256;i++) { - st2d_8to16table[i] = xlib_rgb16(palette[i*3], palette[i*3+1], - palette[i*3+2]); - st2d_8to24table[i] = xlib_rgb24(palette[i*3], palette[i*3+1], - palette[i*3+2]); - } + for(i=0;i<256;i++) + st2d_8to16table[i]= xlib_rgb(palette[i*3], + palette[i*3+1],palette[i*3+2]); - if (x_visinfo->class == PseudoColor && x_visinfo->depth == 8) { - if (palette != current_palette) { + if (x_visinfo->class == PseudoColor && x_visinfo->depth == 8) + { + if (palette != current_palette) memcpy(current_palette, palette, 768); - } - for (i=0 ; i<256 ; i++) { - colors[i].pixel = i; - colors[i].flags = DoRed|DoGreen|DoBlue; - colors[i].red = vid_gamma[palette[i*3]] * 256; - colors[i].green = vid_gamma[palette[i*3+1]] * 256; - colors[i].blue = vid_gamma[palette[i*3+2]] * 256; + for (i=0 ; i<256 ; i++) + { + colors[i].pixel = i; + colors[i].flags = DoRed|DoGreen|DoBlue; + colors[i].red = palette[i*3] * 257; + colors[i].green = palette[i*3+1] * 257; + colors[i].blue = palette[i*3+2] * 257; } XStoreColors(x_disp, x_cmap, colors, 256); } + } +// Called at shutdown -/* - Called at shutdown -*/ -void -VID_Shutdown(void) +void VID_Shutdown (void) { - Sys_Printf("VID_Shutdown\n"); - if (x_disp) { -#ifdef HAVE_VIDMODE - if (hasvidmode) { - int i; + Con_Printf("VID_Shutdown\n"); + XAutoRepeatOn(x_disp); + if (nullcursor != None) { + XFreeCursor(x_disp, nullcursor); + nullcursor = None; + } + XCloseDisplay(x_disp); +} - XF86VidModeSwitchToMode (x_disp, DefaultScreen (x_disp), - vidmodes[0]); - for (i = 0; i < nummodes; i++) { - if (vidmodes[i]->private) XFree(vidmodes[i]->private); - } - XFree(vidmodes); - } +int XLateKey(XKeyEvent *ev) +{ + + int key; + char buf[64]; + KeySym keysym; + + key = 0; + + XLookupString(ev, buf, sizeof buf, &keysym, 0); + + switch(keysym) + { + case XK_KP_Page_Up: + case XK_Page_Up: key = K_PGUP; break; + + case XK_KP_Page_Down: + case XK_Page_Down: key = K_PGDN; break; + + case XK_KP_Home: + case XK_Home: key = K_HOME; break; + + case XK_KP_End: + case XK_End: key = K_END; break; + + case XK_KP_Left: + case XK_Left: key = K_LEFTARROW; break; + + case XK_KP_Right: + case XK_Right: key = K_RIGHTARROW; break; + + case XK_KP_Down: + case XK_Down: key = K_DOWNARROW; break; + + case XK_KP_Up: + case XK_Up: key = K_UPARROW; break; + + case XK_Escape: key = K_ESCAPE; break; + + case XK_KP_Enter: + case XK_Return: key = K_ENTER; break; + + case XK_Tab: key = K_TAB; break; + + case XK_F1: key = K_F1; break; + + case XK_F2: key = K_F2; break; + + case XK_F3: key = K_F3; break; + + case XK_F4: key = K_F4; break; + + case XK_F5: key = K_F5; break; + + case XK_F6: key = K_F6; break; + + case XK_F7: key = K_F7; break; + + case XK_F8: key = K_F8; break; + + case XK_F9: key = K_F9; break; + + case XK_F10: key = K_F10; break; + + case XK_F11: key = K_F11; break; + + case XK_F12: key = K_F12; break; + + case XK_BackSpace: key = K_BACKSPACE; break; + + case XK_KP_Delete: + case XK_Delete: key = K_DEL; break; + + case XK_Pause: key = K_PAUSE; break; + + case XK_Shift_L: + case XK_Shift_R: key = K_SHIFT; break; + + case XK_Execute: + case XK_Control_L: + case XK_Control_R: key = K_CTRL; break; + + case XK_Alt_L: + case XK_Meta_L: + case XK_Alt_R: + case XK_Meta_R: key = K_ALT; break; + + case XK_KP_Begin: key = K_AUX30; break; + + case XK_Insert: + case XK_KP_Insert: key = K_INS; break; + + case XK_KP_Multiply: key = '*'; break; + case XK_KP_Add: key = '+'; break; + case XK_KP_Subtract: key = '-'; break; + case XK_KP_Divide: key = '/'; break; + +#if 0 + case 0x021: key = '1';break;/* [!] */ + case 0x040: key = '2';break;/* [@] */ + case 0x023: key = '3';break;/* [#] */ + case 0x024: key = '4';break;/* [$] */ + case 0x025: key = '5';break;/* [%] */ + case 0x05e: key = '6';break;/* [^] */ + case 0x026: key = '7';break;/* [&] */ + case 0x02a: key = '8';break;/* [*] */ + case 0x028: key = '9';;break;/* [(] */ + case 0x029: key = '0';break;/* [)] */ + case 0x05f: key = '-';break;/* [_] */ + case 0x02b: key = '=';break;/* [+] */ + case 0x07c: key = '\'';break;/* [|] */ + case 0x07d: key = '[';break;/* [}] */ + case 0x07b: key = ']';break;/* [{] */ + case 0x022: key = '\'';break;/* ["] */ + case 0x03a: key = ';';break;/* [:] */ + case 0x03f: key = '/';break;/* [?] */ + case 0x03e: key = '.';break;/* [>] */ + case 0x03c: key = ',';break;/* [<] */ #endif - XAutoRepeatOn(x_disp); - x11_close_display(); - x_disp = 0; + + default: + key = *(unsigned char*)buf; + if (key >= 'A' && key <= 'Z') + key = key - 'A' + 'a'; +// fprintf(stdout, "case 0x0%x: key = ___;break;/* [%c] */\n", keysym); + break; + } + + return key; +} + +struct +{ + int key; + int down; +} keyq[64]; +int keyq_head=0; +int keyq_tail=0; + +int config_notify=0; +int config_notify_width; +int config_notify_height; + +void GetEvent(void) +{ + XEvent x_event; + int b; + + XNextEvent(x_disp, &x_event); + switch(x_event.type) { + case KeyPress: + keyq[keyq_head].key = XLateKey(&x_event.xkey); + keyq[keyq_head].down = true; + keyq_head = (keyq_head + 1) & 63; + break; + case KeyRelease: + keyq[keyq_head].key = XLateKey(&x_event.xkey); + keyq[keyq_head].down = false; + keyq_head = (keyq_head + 1) & 63; + break; + + case MotionNotify: +/* if (_windowed_mouse.value) { + CVAR_FIXME */ + if (_windowed_mouse->value) { + mouse_x = (float) ((int)x_event.xmotion.x - (int)(vid.width/2)); + mouse_y = (float) ((int)x_event.xmotion.y - (int)(vid.height/2)); +//printf("m: x=%d,y=%d, mx=%3.2f,my=%3.2f\n", +// x_event.xmotion.x, x_event.xmotion.y, mouse_x, mouse_y); + + /* move the mouse to the window center again */ + XSelectInput(x_disp,x_win,StructureNotifyMask|KeyPressMask + |KeyReleaseMask|ExposureMask + |ButtonPressMask + |ButtonReleaseMask); + XWarpPointer(x_disp,None,x_win,0,0,0,0, + (vid.width/2),(vid.height/2)); + XSelectInput(x_disp,x_win,StructureNotifyMask|KeyPressMask + |KeyReleaseMask|ExposureMask + |PointerMotionMask|ButtonPressMask + |ButtonReleaseMask); + } else { + mouse_x = (float) (x_event.xmotion.x-p_mouse_x); + mouse_y = (float) (x_event.xmotion.y-p_mouse_y); + p_mouse_x=x_event.xmotion.x; + p_mouse_y=x_event.xmotion.y; + } + break; + + case ButtonPress: + b=-1; + if (x_event.xbutton.button == 1) + b = 0; + else if (x_event.xbutton.button == 2) + b = 2; + else if (x_event.xbutton.button == 3) + b = 1; + if (b>=0) + mouse_buttonstate |= 1<=0) + mouse_buttonstate &= ~(1<value) { +/* old_windowed_mouse = _windowed_mouse.value; + CVAR_FIXME */ + old_windowed_mouse = _windowed_mouse->value; + +/* if (!_windowed_mouse.value) { + CVAR_FIXME */ + if (!_windowed_mouse->value) { + /* ungrab the pointer */ + XUngrabPointer(x_disp,CurrentTime); + } else { + /* grab the pointer */ + XGrabPointer(x_disp,x_win,True,0,GrabModeAsync, + GrabModeAsync,x_win,None,CurrentTime); + } } } -static int config_notify=0; -static int config_notify_width; -static int config_notify_height; +// flushes the given rectangles from the view buffer to the screen -/* - Flushes the given rectangles from the view buffer to the screen. -*/ -void -VID_Update(vrect_t *rects) +void VID_Update (vrect_t *rects) { - /* If the window changes dimension, skip this frame. */ - if (config_notify) { + +// if the window changes dimension, skip this frame + + if (config_notify) + { fprintf(stderr, "config notify\n"); config_notify = 0; vid.width = config_notify_width & ~7; @@ -807,91 +940,239 @@ VID_Update(vrect_t *rects) vid.conwidth = vid.width; vid.conheight = vid.height; vid.conrowbytes = vid.rowbytes; - vid.recalc_refdef = 1; /* force a surface cache flush */ + vid.recalc_refdef = 1; // force a surface cache flush Con_CheckResize(); Con_Clear_f(); return; } - if (doShm) { - while (rects) { - if (x_visinfo->depth == 16) { - st2_fixup(x_framebuffer[current_framebuffer], - rects->x, rects->y, rects->width, - rects->height); - } else if (x_visinfo->depth == 24) { - st3_fixup(x_framebuffer[current_framebuffer], - rects->x, rects->y, rects->width, - rects->height); - } + if (doShm) + { + + while (rects) + { + if (x_visinfo->depth != 8) + st2_fixup( x_framebuffer[current_framebuffer], + rects->x, rects->y, rects->width, + rects->height); if (!XShmPutImage(x_disp, x_win, x_gc, - x_framebuffer[current_framebuffer], - rects->x, rects->y, - rects->x, rects->y, - rects->width, rects->height, True)) { - Sys_Error("VID_Update: XShmPutImage failed\n"); - } + x_framebuffer[current_framebuffer], rects->x, rects->y, + rects->x, rects->y, rects->width, rects->height, True)) + Sys_Error("VID_Update: XShmPutImage failed\n"); oktodraw = false; - while (!oktodraw) x11_process_event(); + while (!oktodraw) GetEvent(); rects = rects->pnext; } current_framebuffer = !current_framebuffer; vid.buffer = x_framebuffer[current_framebuffer]->data; vid.conbuffer = vid.buffer; XSync(x_disp, False); - } else { - while (rects) { - if (x_visinfo->depth == 16) { - st2_fixup(x_framebuffer[current_framebuffer], - rects->x, rects->y, rects->width, - rects->height); - } else if (x_visinfo->depth == 24) { - st3_fixup(x_framebuffer[current_framebuffer], - rects->x, rects->y, rects->width, - rects->height); - } - XPutImage(x_disp, x_win, x_gc, x_framebuffer[0], - rects->x, rects->y, rects->x, rects->y, - rects->width, rects->height); + } + else + { + while (rects) + { + if (x_visinfo->depth != 8) + st2_fixup( x_framebuffer[current_framebuffer], + rects->x, rects->y, rects->width, + rects->height); + XPutImage(x_disp, x_win, x_gc, x_framebuffer[0], rects->x, + rects->y, rects->x, rects->y, rects->width, rects->height); rects = rects->pnext; } XSync(x_disp, False); } + } static int dither; -void -VID_DitherOn( void ) +void VID_DitherOn(void) { - if (dither == 0) { + if (dither == 0) + { vid.recalc_refdef = 1; - dither = 1; + dither = 1; + } +} + +void VID_DitherOff(void) +{ + if (dither) + { + vid.recalc_refdef = 1; + dither = 0; + } +} + +int Sys_OpenWindow(void) +{ + return 0; +} + +void Sys_EraseWindow(int window) +{ +} + +void Sys_DrawCircle(int window, int x, int y, int r) +{ +} + +void Sys_DisplayWindow(int window) +{ +} + +void Sys_SendKeyEvents(void) +{ +// get events from x server + if (x_disp) + { + while (XPending(x_disp)) GetEvent(); + while (keyq_head != keyq_tail) + { + Key_Event(keyq[keyq_tail].key, keyq[keyq_tail].down); + keyq_tail = (keyq_tail + 1) & 63; + } } } - -void -VID_DitherOff( void ) +#if 0 +char *Sys_ConsoleInput (void) { - if (dither) { - vid.recalc_refdef = 1; - dither = 0; + + static char text[256]; + int len; + fd_set readfds; + int ready; + struct timeval timeout; + + timeout.tv_sec = 0; + timeout.tv_usec = 0; + FD_ZERO(&readfds); + FD_SET(0, &readfds); + ready = select(1, &readfds, 0, 0, &timeout); + + if (ready>0) + { + len = read (0, text, sizeof(text)); + if (len >= 1) + { + text[len-1] = 0; // rip off the /n and terminate + return text; + } } -} -void VID_InitCvars () + return 0; + +} +#endif + +void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height) { - // It may not look like it, but this is important +// direct drawing of the "accessing disk" icon isn't supported under Linux } -void -VID_LockBuffer ( void ) -{ -} +void D_EndDirectRect (int x, int y, int width, int height) +{ +// direct drawing of the "accessing disk" icon isn't supported under Linux +} -void -VID_UnlockBuffer ( void ) -{ -} +void IN_Init (void) +{ +/* Cvar_RegisterVariable (&_windowed_mouse); + CVAR_FIXME */ + _windowed_mouse = Cvar_Get("_windowed_mouse", "0", CVAR_ARCHIVE, "None"); +/* Cvar_RegisterVariable (&m_filter); + CVAR_FIXME */ + m_filter = Cvar_Get("m_filter", "0", CVAR_ARCHIVE, "None"); + if ( COM_CheckParm ("-nomouse") ) + return; + mouse_x = mouse_y = 0.0; + mouse_avail = 1; +} + +void IN_Shutdown (void) +{ + mouse_avail = 0; +} + +void IN_Commands (void) +{ + int i; + + if (!mouse_avail) return; + + for (i=0 ; ivalue) { + mouse_x = (mouse_x + old_mouse_x) * 0.5; + mouse_y = (mouse_y + old_mouse_y) * 0.5; + } + + old_mouse_x = mouse_x; + old_mouse_y = mouse_y; + +/* mouse_x *= sensitivity.value; + CVAR_FIXME */ + mouse_x *= sensitivity->value; +/* mouse_y *= sensitivity.value; + CVAR_FIXME */ + mouse_y *= sensitivity->value; + +/* if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) )) + CVAR_FIXME */ + if ( (in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1) )) +/* cmd->sidemove += m_side.value * mouse_x; + CVAR_FIXME */ + cmd->sidemove += m_side->value * mouse_x; + else +/* cl.viewangles[YAW] -= m_yaw.value * mouse_x; + CVAR_FIXME */ + cl.viewangles[YAW] -= m_yaw->value * mouse_x; + if (in_mlook.state & 1) + V_StopPitchDrift (); + + if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) { +/* cl.viewangles[PITCH] += m_pitch.value * mouse_y; + CVAR_FIXME */ + cl.viewangles[PITCH] += m_pitch->value * mouse_y; + if (cl.viewangles[PITCH] > 80) + cl.viewangles[PITCH] = 80; + if (cl.viewangles[PITCH] < -70) + cl.viewangles[PITCH] = -70; + } else { + if ((in_strafe.state & 1) && noclip_anglehack) +/* cmd->upmove -= m_forward.value * mouse_y; + CVAR_FIXME */ + cmd->upmove -= m_forward->value * mouse_y; + else +/* cmd->forwardmove -= m_forward.value * mouse_y; + CVAR_FIXME */ + cmd->forwardmove -= m_forward->value * mouse_y; + } + mouse_x = mouse_y = 0.0; +} + +void VID_LockBuffer (void) +{ +} + +void VID_UnlockBuffer (void) +{ +} diff --git a/source/zone.c b/source/zone.c index d699dfe..943ee38 100644 --- a/source/zone.c +++ b/source/zone.c @@ -30,14 +30,7 @@ # include #endif #include "sys.h" -#include "qtypes.h" -#include "zone.h" -#include "console.h" -#include "cmd.h" -#include "qargs.h" - -#include -#include +#include "quakedef.h" #define DYNAMIC_SIZE 0x20000