05 Nov 2007

This commit is contained in:
g-cont 2007-11-05 00:00:00 +03:00 committed by Alibek Omarov
parent 6c904b82c5
commit 0bed22f0be
61 changed files with 4548 additions and 3761 deletions

View File

@ -8,6 +8,7 @@
1. Перенести сетевой протокол из ку3 (huffman compressed)
2. подключить roqlib
3. переписать cvar-систему и cmd систему
Quake1 Quake2
SV_MoveBounds SV_TraceBounds

View File

@ -1630,7 +1630,7 @@ rgbdata_t *FS_LoadImage(const char *filename, char *buffer, int buffsize )
FS_StripExtension( loadname ); //remove extension if needed
// developer warning
if(!anyformat) MsgWarn( "Warning: %s will be loading only with ext .%s\n", loadname, ext );
if(!anyformat) MsgWarn( "%s will be loading only with ext .%s\n", loadname, ext );
// now try all the formats in the selected list
for (format = load_formats; format->formatstring; format++)

View File

@ -643,6 +643,138 @@ char *SC_Token( void )
return token;
}
/*
============
SC_StringContains
============
*/
char *SC_StringContains(char *str1, char *str2, int casecmp)
{
int len, i, j;
len = strlen(str1) - strlen(str2);
for (i = 0; i <= len; i++, str1++)
{
for (j = 0; str2[j]; j++)
{
if (casecmp)
{
if (str1[j] != str2[j]) break;
}
else
{
if(toupper(str1[j]) != toupper(str2[j]))
break;
}
}
if (!str2[j]) return str1;
}
return NULL;
}
/*
============
SC_FilterToken
============
*/
bool SC_FilterToken(char *filter, char *name, int casecmp)
{
char buf[MAX_INPUTLINE];
char *ptr;
int i, found;
while(*filter)
{
if(*filter == '*')
{
filter++;
for (i = 0; *filter; i++)
{
if (*filter == '*' || *filter == '?')
break;
buf[i] = *filter;
filter++;
}
buf[i] = '\0';
if (strlen(buf))
{
ptr = SC_StringContains(name, buf, casecmp);
if (!ptr) return false;
name = ptr + strlen(buf);
}
}
else if (*filter == '?')
{
filter++;
name++;
}
else if (*filter == '[' && *(filter+1) == '[')
{
filter++;
}
else if (*filter == '[')
{
filter++;
found = false;
while(*filter && !found)
{
if (*filter == ']' && *(filter+1) != ']') break;
if (*(filter+1) == '-' && *(filter+2) && (*(filter+2) != ']' || *(filter+3) == ']'))
{
if (casecmp)
{
if (*name >= *filter && *name <= *(filter+2)) found = true;
}
else
{
if (toupper(*name) >= toupper(*filter) && toupper(*name) <= toupper(*(filter+2)))
found = true;
}
filter += 3;
}
else
{
if (casecmp)
{
if (*filter == *name) found = true;
}
else
{
if (toupper(*filter) == toupper(*name)) found = true;
}
filter++;
}
}
if (!found) return false;
while(*filter)
{
if (*filter == ']' && *(filter+1) != ']')
break;
filter++;
}
filter++;
name++;
}
else
{
if (casecmp)
{
if (*filter != *name)
return false;
}
else
{
if (toupper(*filter) != toupper(*name))
return false;
}
filter++;
name++;
}
}
return true;
}
/*
=============================================================================
@ -664,6 +796,7 @@ scriptsystem_api_t Sc_GetAPI( void )
sc.MatchToken = SC_MatchToken;
sc.ParseToken = SC_ParseToken;
sc.ParseWord = SC_ParseWord;
sc.FilterToken = SC_FilterToken;
sc.Token = token;
return sc;

View File

@ -61,5 +61,5 @@ if exist vprogs\progdefs.h move vprogs\progdefs.h engine\progdefs.h
echo Build succeeded!
echo Please wait. Xash is now loading
cd D:\Xash3D\
xash.exe +demomap idlogo.roq -log -debug -dev 4
xash.exe +map qctest -log -debug -dev 4
:done

View File

@ -19,33 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "client.h"
typedef struct
{
byte *data;
int count;
} cblock_t;
typedef struct
{
bool restart_sound;
int s_rate;
int s_width;
int s_channels;
int width;
int height;
byte *pic;
byte *pic_pending;
// order 1 huffman stuff
int *hnodes1; // [256][256][2];
int numhnodes1[256];
int h_used[512];
int h_count[512];
} cinematics_t;
cinematics_t cin;
roq_dec_t *cin;
/*
==================
SCR_StopCinematic
@ -54,39 +28,17 @@ SCR_StopCinematic
void SCR_StopCinematic (void)
{
cl.cinematictime = 0; // done
if (cin.pic)
{
Z_Free (cin.pic);
cin.pic = NULL;
}
if (cin.pic_pending)
{
Z_Free (cin.pic_pending);
cin.pic_pending = NULL;
}
if (cl.cinematicpalette_active)
{
re->CinematicSetPalette(NULL);
cl.cinematicpalette_active = false;
}
if (cl.cinematic_file)
{
FS_Close (cl.cinematic_file);
cl.cinematic_file = NULL;
}
if (cin.hnodes1)
{
Z_Free (cin.hnodes1);
cin.hnodes1 = NULL;
}
if(!cin) return;
// switch back down to 11 khz sound if necessary
if (cin.restart_sound)
if(cin->restart_sound)
{
cin.restart_sound = false;
CL_Snd_Restart_f ();
// switch back down to 11 khz sound if necessary
cin->restart_sound = false;
CL_Snd_Restart_f();
}
Msg("total [%d] frames played\n", cin->frameNum );
Com->Roq.FreeVideo( cin );
cin = NULL;
}
/*
@ -103,281 +55,30 @@ void SCR_FinishCinematic (void)
SZ_Print (&cls.netchan.message, va("nextserver %i\n", cl.servercount));
}
//==========================================================================
/*
==================
SmallestNode1
==================
*/
int SmallestNode1 (int numhnodes)
{
int i;
int best, bestnode;
best = 99999999;
bestnode = -1;
for (i=0 ; i<numhnodes ; i++)
{
if (cin.h_used[i])
continue;
if (!cin.h_count[i])
continue;
if (cin.h_count[i] < best)
{
best = cin.h_count[i];
bestnode = i;
}
}
if (bestnode == -1)
return -1;
cin.h_used[bestnode] = true;
return bestnode;
}
/*
==================
Huff1TableInit
Reads the 64k counts table and initializes the node trees
==================
*/
void Huff1TableInit (void)
{
int prev;
int j;
int *node, *nodebase;
byte counts[256];
int numhnodes;
cin.hnodes1 = Z_Malloc (256*256*2*4);
memset (cin.hnodes1, 0, 256*256*2*4);
for (prev=0 ; prev<256 ; prev++)
{
memset (cin.h_count,0,sizeof(cin.h_count));
memset (cin.h_used,0,sizeof(cin.h_used));
// read a row of counts
FS_Read (cl.cinematic_file, counts, sizeof(counts));
for (j=0 ; j<256 ; j++)
cin.h_count[j] = counts[j];
// build the nodes
numhnodes = 256;
nodebase = cin.hnodes1 + prev*256*2;
while (numhnodes != 511)
{
node = nodebase + (numhnodes-256)*2;
// pick two lowest counts
node[0] = SmallestNode1 (numhnodes);
if (node[0] == -1)
break; // no more
node[1] = SmallestNode1 (numhnodes);
if (node[1] == -1)
break;
cin.h_count[numhnodes] = cin.h_count[node[0]] + cin.h_count[node[1]];
numhnodes++;
}
cin.numhnodes1[prev] = numhnodes-1;
}
}
/*
==================
Huff1Decompress
==================
*/
cblock_t Huff1Decompress (cblock_t in)
{
byte *input;
byte *out_p;
int nodenum;
int count;
cblock_t out;
int inbyte;
int *hnodes, *hnodesbase;
//int i;
// get decompressed count
count = in.data[0] + (in.data[1]<<8) + (in.data[2]<<16) + (in.data[3]<<24);
input = in.data + 4;
out_p = out.data = Z_Malloc (count);
// read bits
hnodesbase = cin.hnodes1 - 256*2; // nodes 0-255 aren't stored
hnodes = hnodesbase;
nodenum = cin.numhnodes1[0];
while (count)
{
inbyte = *input++;
//-----------
if (nodenum < 256)
{
hnodes = hnodesbase + (nodenum<<9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum*2 + (inbyte&1)];
inbyte >>=1;
//-----------
if (nodenum < 256)
{
hnodes = hnodesbase + (nodenum<<9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum*2 + (inbyte&1)];
inbyte >>=1;
//-----------
if (nodenum < 256)
{
hnodes = hnodesbase + (nodenum<<9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum*2 + (inbyte&1)];
inbyte >>=1;
//-----------
if (nodenum < 256)
{
hnodes = hnodesbase + (nodenum<<9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum*2 + (inbyte&1)];
inbyte >>=1;
//-----------
if (nodenum < 256)
{
hnodes = hnodesbase + (nodenum<<9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum*2 + (inbyte&1)];
inbyte >>=1;
//-----------
if (nodenum < 256)
{
hnodes = hnodesbase + (nodenum<<9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum*2 + (inbyte&1)];
inbyte >>=1;
//-----------
if (nodenum < 256)
{
hnodes = hnodesbase + (nodenum<<9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum*2 + (inbyte&1)];
inbyte >>=1;
//-----------
if (nodenum < 256)
{
hnodes = hnodesbase + (nodenum<<9);
*out_p++ = nodenum;
if (!--count)
break;
nodenum = cin.numhnodes1[nodenum];
}
nodenum = hnodes[nodenum*2 + (inbyte&1)];
inbyte >>=1;
}
if (input - in.data != in.count && input - in.data != in.count+1)
{
Msg ("Decompression overread by %i", (input - in.data) - in.count);
}
out.count = out_p - out.data;
return out;
}
/*
==================
SCR_ReadNextFrame
==================
*/
byte *SCR_ReadNextFrame (void)
bool SCR_ReadNextFrame (void)
{
int r;
int command;
byte samples[22050/14*4];
byte compressed[0x20000];
int size;
byte *pic;
cblock_t in, huf1;
int start, end, count;
// read the next frame
r = FS_Read (cl.cinematic_file, &command, 4 );
if (r == 0) // we'll give it one more chance
r = FS_Read (cl.cinematic_file, &command, 4);
if (!r) return NULL;
command = LittleLong(command);
if (command == 2)
return NULL; // last frame marker
if (command == 1)
{ // read palette
FS_Read (cl.cinematic_file, cl.cinematicpalette, sizeof(cl.cinematicpalette));
cl.cinematicpalette_active=0; // dubious.... exposes an edge case
switch(Com->Roq.ReadFrame( cin ))
{
case ROQ_MARKER_INFO:
break;
case ROQ_MARKER_VIDEO:
//re->DrawStretchRaw(0, 0, viddef.width, viddef.height, cin->width, cin->height, cin->rgb );
break;
case ROQ_MARKER_EOF:
return false;
case ROQ_MARKER_SND_MONO:
S_RawSamples (cin->audioSize, 22050, 2, 1, (byte *)cin->audioSamples, 1.0f );
break;
case ROQ_MARKER_SND_STEREO:
S_RawSamples (cin->audioSize, 22050, 2, 2, (byte *)cin->audioSamples, 1.0f );
break;
}
// decompress the next frame
FS_Read (cl.cinematic_file, &size, 4);
size = LittleLong(size);
if (size > sizeof(compressed) || size < 1)
Host_Error("Bad compressed frame size\n");
FS_Read (cl.cinematic_file, compressed, size);
// read sound
start = cl.cinematicframe*cin.s_rate/14;
end = (cl.cinematicframe+1)*cin.s_rate/14;
count = end - start;
FS_Read (cl.cinematic_file, samples, count*cin.s_width*cin.s_channels);
S_RawSamples (count, cin.s_rate, cin.s_width, cin.s_channels, samples);
in.data = compressed;
in.count = size;
huf1 = Huff1Decompress (in);
pic = huf1.data;
cl.cinematicframe++;
return pic;
return true;
}
@ -397,36 +98,28 @@ void SCR_RunCinematic (void)
return;
}
if (cl.cinematicframe == -1)
return; // static image
if (cls.key_dest != key_game)
{ // pause if menu or console is up
cl.cinematictime = cls.realtime - cl.cinematicframe/14;
/*if (cls.key_dest != key_game)
{
// pause if menu or console is up
cl.cinematictime = cls.realtime - cin->frameNum / 30;
return;
}*/
frame = (cls.realtime - cl.cinematictime) * 30.0;
if (frame + 1 < cin->frameNum) return; //too early
if (frame > cin->frameNum + 1)
{
MsgWarn("SCR_RunCinematic: dropped frame: %i > %i\n", frame, cin->frameNum + 1);
cl.cinematictime = cls.realtime - cin->frameNum / 30;
}
frame = (cls.realtime - cl.cinematictime)*14.0;
if (frame <= cl.cinematicframe)
return;
if (frame > cl.cinematicframe+1)
if(!SCR_ReadNextFrame())
{
Msg ("Dropped frame: %i > %i\n", frame, cl.cinematicframe+1);
cl.cinematictime = cls.realtime - cl.cinematicframe/14;
}
if (cin.pic)
Z_Free (cin.pic);
cin.pic = cin.pic_pending;
cin.pic_pending = NULL;
cin.pic_pending = SCR_ReadNextFrame ();
if (!cin.pic_pending)
{
SCR_StopCinematic ();
SCR_FinishCinematic ();
cl.cinematictime = 1; // hack to get the black screen behind loading
SCR_BeginLoadingPlaque ();
SCR_StopCinematic();
SCR_FinishCinematic();
cl.cinematictime = 1; // hack to get the black screen behind loading
SCR_BeginLoadingPlaque();
cl.cinematictime = 0;
return;
}
}
@ -440,29 +133,10 @@ should be skipped
*/
bool SCR_DrawCinematic (void)
{
if (cl.cinematictime <= 0)
{
return false;
}
if (cl.cinematictime <= 0) return false;
if (!cin || !cin->rgb) return true;
if (cls.key_dest == key_menu)
{
// blank screen and pause if menu is up
re->CinematicSetPalette( NULL );
cl.cinematicpalette_active = false;
return true;
}
if (!cl.cinematicpalette_active)
{
re->CinematicSetPalette(cl.cinematicpalette);
cl.cinematicpalette_active = true;
}
if (!cin.pic)
return true;
re->DrawStretchRaw (0, 0, viddef.width, viddef.height, cin.width, cin.height, cin.pic);
re->DrawStretchRaw(0, 0, viddef.width, viddef.height, cin->width, cin->height, cin->rgb );
return true;
}
@ -475,76 +149,28 @@ SCR_PlayCinematic
*/
void SCR_PlayCinematic (char *arg)
{
int width, height;
byte *palette;
char name[MAX_OSPATH];
int old_khz;
rgbdata_t *pic = NULL;
const char *ext = FS_FileExtension( arg );
cl.cinematicframe = 0;
if (!strcmp (ext, "pcx"))
{
pic = FS_LoadImage( va("textures/base_menu/%s", arg), NULL, 0 );
if(pic)
{
cin.pic = pic->buffer;
palette = pic->palette;
cin.width = pic->width;
cin.height = pic->height;
cl.cinematicframe = -1;
cl.cinematictime = 1;
SCR_EndLoadingPlaque ();
cls.state = ca_active;
Mem_Copy (cl.cinematicpalette, palette, sizeof(cl.cinematicpalette));
}
else Host_Error("%s not found.\n", arg );
return;
}
sprintf (name, "video/%s", arg);
cl.cinematic_file = FS_Open(name, "rb" );
if (!cl.cinematic_file)
cin = Com->Roq.LoadVideo( arg );
if (!cin)
{
SCR_FinishCinematic ();
cl.cinematictime = 0; // done
return;
}
SCR_EndLoadingPlaque ();
SCR_EndLoadingPlaque();
cls.state = ca_active;
FS_Read (cl.cinematic_file, &width, 4);
FS_Read (cl.cinematic_file, &height, 4);
cin.width = LittleLong(width);
cin.height = LittleLong(height);
FS_Read (cl.cinematic_file, &cin.s_rate, 4);
cin.s_rate = LittleLong(cin.s_rate);
FS_Read (cl.cinematic_file, &cin.s_width, 4);
cin.s_width = LittleLong(cin.s_width);
FS_Read (cl.cinematic_file, &cin.s_channels, 4);
cin.s_channels = LittleLong(cin.s_channels);
Huff1TableInit ();
// switch up to 22 khz sound if necessary
old_khz = Cvar_VariableValue ("s_khz");
if (old_khz != cin.s_rate/1000)
if (old_khz != 22)
{
cin.restart_sound = true;
Cvar_SetValue ("s_khz", cin.s_rate/1000);
CL_Snd_Restart_f ();
Cvar_SetValue ("s_khz", old_khz);
cin->restart_sound = true;
Cvar_SetValue ("s_khz", 22 );
CL_Snd_Restart_f();
Cvar_SetValue ("s_khz", old_khz );
}
cl.cinematicframe = 0;
cin.pic = SCR_ReadNextFrame ();
cl.cinematictime = Sys_DoubleTime ();
SCR_ReadNextFrame(); //first frame
cl.cinematictime = Sys_DoubleTime();
}

View File

@ -1,176 +0,0 @@
/*
Copyright (C) 1997-2001 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.
*/
#include "client.h"
roq_dec_t *cin;
/*
==================
SCR_StopCinematic
==================
*/
void SCR_StopCinematic (void)
{
cl.cinematictime = 0; // done
if(!cin) return;
if(cin->restart_sound)
{
// switch back down to 11 khz sound if necessary
cin->restart_sound = false;
CL_Snd_Restart_f();
}
Msg("total [%d] frames played\n", cin->frameNum );
Com->Roq.FreeVideo( cin );
cin = NULL;
}
/*
====================
SCR_FinishCinematic
Called when either the cinematic completes, or it is aborted
====================
*/
void SCR_FinishCinematic (void)
{
// tell the server to advance to the next map / cinematic
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
SZ_Print (&cls.netchan.message, va("nextserver %i\n", cl.servercount));
}
/*
==================
SCR_ReadNextFrame
==================
*/
bool SCR_ReadNextFrame (void)
{
switch(Com->Roq.ReadFrame( cin ))
{
case ROQ_MARKER_INFO:
break;
case ROQ_MARKER_VIDEO:
//re->DrawStretchRaw(0, 0, viddef.width, viddef.height, cin->width, cin->height, cin->rgb );
break;
case ROQ_MARKER_EOF:
return false;
case ROQ_MARKER_SND_MONO:
S_RawSamples (cin->audioSize, 22050, 2, 1, (byte *)cin->audioSamples, 1.0f );
break;
case ROQ_MARKER_SND_STEREO:
S_RawSamples (cin->audioSize, 22050, 2, 2, (byte *)cin->audioSamples, 1.0f );
break;
}
return true;
}
/*
==================
SCR_RunCinematic
==================
*/
void SCR_RunCinematic (void)
{
int frame;
if (cl.cinematictime <= 0)
{
SCR_StopCinematic ();
return;
}
/*if (cls.key_dest != key_game)
{
// pause if menu or console is up
cl.cinematictime = cls.realtime - cin->frameNum / 30;
return;
}*/
frame = (cls.realtime - cl.cinematictime) * 30.0;
if (frame + 1 < cin->frameNum) return; //too early
if (frame > cin->frameNum + 1)
{
MsgWarn("SCR_RunCinematic: dropped frame: %i > %i\n", frame, cin->frameNum + 1);
cl.cinematictime = cls.realtime - cin->frameNum / 30;
}
if(!SCR_ReadNextFrame())
{
SCR_StopCinematic();
SCR_FinishCinematic();
cl.cinematictime = 1; // hack to get the black screen behind loading
SCR_BeginLoadingPlaque();
cl.cinematictime = 0;
}
}
/*
==================
SCR_DrawCinematic
Returns true if a cinematic is active, meaning the view rendering
should be skipped
==================
*/
bool SCR_DrawCinematic (void)
{
if (cl.cinematictime <= 0) return false;
if (!cin || !cin->rgb) return true;
re->DrawStretchRaw(0, 0, viddef.width, viddef.height, cin->width, cin->height, cin->rgb );
return true;
}
/*
==================
SCR_PlayCinematic
==================
*/
void SCR_PlayCinematic (char *arg)
{
int old_khz;
cin = Com->Roq.LoadVideo( arg );
if (!cin)
{
SCR_FinishCinematic ();
return;
}
SCR_EndLoadingPlaque();
cls.state = ca_active;
// switch up to 22 khz sound if necessary
old_khz = Cvar_VariableValue ("s_khz");
if (old_khz != 22)
{
cin->restart_sound = true;
Cvar_SetValue ("s_khz", 22 );
CL_Snd_Restart_f();
Cvar_SetValue ("s_khz", old_khz );
}
SCR_ReadNextFrame(); //first frame
cl.cinematictime = Sys_DoubleTime();
}

741
engine/client/cl_console.c Normal file
View File

@ -0,0 +1,741 @@
/*
Copyright (C) 1997-2001 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.
*/
// console.c
#include "client.h"
cvar_t *con_notifytime;
vec4_t console_color = {1.0, 1.0, 1.0, 1.0};
extern cvar_t *scr_conspeed;
int g_console_field_width = 78;
#define NUM_CON_TIMES 4
#define CON_TEXTSIZE MAX_INPUTLINE * 32 // 512 kb buffer
typedef struct
{
bool initialized;
short text[CON_TEXTSIZE];
int current; // line where next message will be printed
int x; // offset in current line for next print
int display; // bottom of console displays this line
int linewidth; // characters across screen
int totallines; // total lines in console scrollback
float xadjust; // for wide aspect screens
float displayFrac; // aproaches finalFrac at scr_conspeed
float finalFrac; // 0.0 to 1.0 lines of console to display
int vislines; // in scanlines
float times[NUM_CON_TIMES]; // cls.realtime time the line was generated for transparent notify lines
vec4_t color;
} console_t;
static console_t con;
void DrawString (int x, int y, char *s)
{
while (*s)
{
re->DrawChar (x, y, *s);
x+=8;
s++;
}
}
void DrawAltString (int x, int y, char *s)
{
while (*s)
{
re->DrawChar (x, y, *s ^ 0x80);
x+=8;
s++;
}
}
// strlen that discounts color sequences
int Con_PrintStrlen( const char *string )
{
int len;
const char *p;
if( !string ) return 0;
len = 0;
p = string;
while( *p )
{
if(IsColorString( p ))
{
p += 2;
continue;
}
p++;
len++;
}
return len;
}
/*
================
Con_ToggleConsole_f
================
*/
void Con_ToggleConsole_f (void)
{
SCR_EndLoadingPlaque(); // get rid of loading plaque
Field_Clear( &g_consoleField );
g_consoleField.widthInChars = g_console_field_width;
Con_ClearNotify ();
if (cls.key_dest == key_console)
{
M_ForceMenuOff();
Cvar_Set ("paused", "0");
}
else
{
M_ForceMenuOff();
cls.key_dest = key_console;
if(Cvar_VariableValue ("maxclients") == 1 && Com_ServerState())
Cvar_Set ("paused", "1");
}
}
/*
================
Con_ToggleChat_f
================
*/
void Con_ToggleChat_f (void)
{
Field_Clear( &g_consoleField );
g_consoleField.widthInChars = g_console_field_width;
if (cls.key_dest == key_console)
{
if (cls.state == ca_active)
{
M_ForceMenuOff ();
cls.key_dest = key_game;
}
}
else
cls.key_dest = key_console;
Con_ClearNotify ();
}
/*
================
Con_Clear_f
================
*/
void Con_Clear_f (void)
{
int i;
for ( i = 0; i < CON_TEXTSIZE; i++ )
con.text[i] = (ColorIndex(COLOR_WHITE)<<8) | ' ';
Con_Bottom(); // go to end
}
/*
================
Con_Dump_f
Save the console contents out to a file
================
*/
void Con_Dump_f (void)
{
int l, x, i;
short *line;
file_t *f;
char buffer[1024];
char name[MAX_OSPATH];
if (Cmd_Argc() != 2)
{
Msg ("usage: condump <filename>\n");
return;
}
sprintf (name, "%s.txt", Cmd_Argv(1));
Msg ("Dumped console text to %s.\n", name);
f = FS_Open (name, "w");
if (!f)
{
Msg ("ERROR: couldn't open.\n");
return;
}
// skip empty lines
for (l = con.current - con.totallines + 1; l <= con.current; l++)
{
line = con.text + (l%con.totallines)*con.linewidth;
for (x = 0; x < con.linewidth; x++)
{
if ((line[x] & 0xff) != ' ')
break;
}
if (x != con.linewidth) break;
}
// write the remaining lines
buffer[con.linewidth] = 0;
for ( ; l <= con.current; l++)
{
line = con.text + (l%con.totallines)*con.linewidth;
for(i = 0; i < con.linewidth; i++)
buffer[i] = line[i] & 0xff;
for (x = con.linewidth - 1; x >= 0; x--)
{
if (buffer[x] == ' ') buffer[x] = 0;
else break;
}
strcat( buffer, "\n" );
FS_Printf (f, "%s\n", buffer);
}
FS_Close (f);
}
/*
================
Con_ClearNotify
================
*/
void Con_ClearNotify (void)
{
int i;
for (i=0 ; i<NUM_CON_TIMES ; i++)
con.times[i] = 0;
}
/*
================
Con_MessageMode_f
================
*/
void Con_MessageMode_f (void)
{
chat_team = false;
cls.key_dest = key_message;
}
/*
================
Con_MessageMode2_f
================
*/
void Con_MessageMode2_f (void)
{
chat_team = true;
cls.key_dest = key_message;
}
/*
================
Con_CheckResize
If the line width has changed, reformat the buffer.
================
*/
void Con_CheckResize (void)
{
int i, j, width, oldwidth, oldtotallines, numlines, numchars;
char tbuf[CON_TEXTSIZE];
width = (viddef.width >> 3) - 2;
if (width == con.linewidth)
return;
if (width < 1) // video hasn't been initialized yet
{
width = 38;
con.linewidth = width;
con.totallines = CON_TEXTSIZE / con.linewidth;
memset (con.text, ' ', CON_TEXTSIZE);
}
else
{
oldwidth = con.linewidth;
con.linewidth = width;
oldtotallines = con.totallines;
con.totallines = CON_TEXTSIZE / con.linewidth;
numlines = oldtotallines;
if (con.totallines < numlines)
numlines = con.totallines;
numchars = oldwidth;
if (con.linewidth < numchars)
numchars = con.linewidth;
memcpy (tbuf, con.text, CON_TEXTSIZE);
memset (con.text, ' ', CON_TEXTSIZE);
for (i=0 ; i<numlines ; i++)
{
for (j=0 ; j<numchars ; j++)
{
con.text[(con.totallines - 1 - i) * con.linewidth + j] =
tbuf[((con.current - i + oldtotallines) %
oldtotallines) * oldwidth + j];
}
}
Con_ClearNotify ();
}
con.current = con.totallines - 1;
con.display = con.current;
}
/*
================
Con_Init
================
*/
void Con_Init (void)
{
con.linewidth = -1;
Con_CheckResize ();
MsgDev(D_INFO, "Console initialized.\n");
// register our commands
con_notifytime = Cvar_Get ("con_notifytime", "3", 0);
Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f);
Cmd_AddCommand ("togglechat", Con_ToggleChat_f);
Cmd_AddCommand ("messagemode", Con_MessageMode_f);
Cmd_AddCommand ("messagemode2", Con_MessageMode2_f);
Cmd_AddCommand ("clear", Con_Clear_f);
Cmd_AddCommand ("condump", Con_Dump_f);
con.initialized = true;
}
/*
===============
Con_Linefeed
===============
*/
void Con_Linefeed (bool skipnotify)
{
int i;
// mark time for transparent overlay
if (con.current >= 0)
{
if(skipnotify) con.times[con.current % NUM_CON_TIMES] = 0.0f;
else con.times[con.current % NUM_CON_TIMES] = cls.realtime;
}
con.x = 0;
if (con.display == con.current) con.display++;
con.current++;
for(i = 0; i < con.linewidth; i++)
con.text[(con.current%con.totallines)*con.linewidth+i] = (ColorIndex(COLOR_WHITE)<<8)|' ';
}
/*
================
CL_ConsolePrint
Handles cursor positioning, line wrapping, etc
All console printing must go through this in order to be logged to disk
If no console is visible, the text will appear at the top of the game window
================
*/
void Con_Print( char *txt )
{
int y, c, l, color;
bool skipnotify = false;
int prev;
// client not running
if(host.type == HOST_DEDICATED) return;
if(!con.initialized) return;
if(!strncmp( txt, "[skipnotify]", 12 ))
{
skipnotify = true;
txt += 12;
}
color = ColorIndex(COLOR_WHITE);
while((c = *txt) != 0 )
{
if(IsColorString( txt ))
{
color = ColorIndex(*(txt+1));
txt += 2;
continue;
}
// count word length
for (l = 0; l < con.linewidth; l++)
{
if ( txt[l] <= ' ') break;
}
// word wrap
if (l != con.linewidth && (con.x + l >= con.linewidth))
Con_Linefeed( skipnotify);
txt++;
switch(c)
{
case '\n':
Con_Linefeed( skipnotify );
break;
case '\r':
con.x = 0;
break;
default: // display character and advance
y = con.current % con.totallines;
con.text[y*con.linewidth+con.x] = (color << 8) | c;
con.x++;
if (con.x >= con.linewidth)
{
Con_Linefeed(skipnotify);
con.x = 0;
}
break;
}
}
// mark time for transparent overlay
if (con.current >= 0)
{
if ( skipnotify )
{
prev = con.current % NUM_CON_TIMES - 1;
if ( prev < 0 ) prev = NUM_CON_TIMES - 1;
con.times[prev] = 0.0f;
}
else con.times[con.current % NUM_CON_TIMES] = cls.realtime;
}
}
/*
==============================================================================
DRAWING
==============================================================================
*/
/*
================
Con_DrawInput
The input line scrolls horizontally if typing goes beyond the right edge
================
*/
void Con_DrawInput (void)
{
int y;
if (cls.key_dest == key_menu) return;
if (cls.key_dest != key_console && cls.state == ca_active)
return; // don't draw anything (always draw if not active)
y = con.vislines - ( SMALLCHAR_HEIGHT * 2 );
re->SetColor( con.color );
SCR_DrawSmallChar( con.xadjust + 1 * SMALLCHAR_WIDTH, y, '>' );
Field_Draw( &g_consoleField, con.xadjust + 2 * SMALLCHAR_WIDTH, y, SCREEN_WIDTH - 3 * SMALLCHAR_WIDTH, true );
}
/*
================
Con_DrawNotify
Draws the last few lines of output transparently over the game top
================
*/
void Con_DrawNotify (void)
{
int x, v;
short *text;
int i;
float time;
int skip;
int currentColor;
currentColor = 7;
re->SetColor( g_color_table[currentColor] );
v = 0;
for (i = con.current-NUM_CON_TIMES + 1; i <= con.current; i++)
{
if (i < 0) continue;
time = con.times[i % NUM_CON_TIMES];
if (time == 0) continue;
time = cls.realtime - time;
if (time > con_notifytime->value) continue;
text = con.text + (i % con.totallines)*con.linewidth;
for (x = 0 ; x < con.linewidth ; x++)
{
if ( ( text[x] & 0xff ) == ' ' ) continue;
if ( ( (text[x]>>8)&7 ) != currentColor )
{
currentColor = (text[x]>>8)&7;
re->SetColor( g_color_table[currentColor] );
}
SCR_DrawSmallChar( con.xadjust + (x+1)*SMALLCHAR_WIDTH, v, text[x] & 0xff );
}
v += SMALLCHAR_HEIGHT;
}
re->SetColor( NULL );
// draw the chat line
if ( cls.key_dest == key_message )
{
if (chat_team)
{
SCR_DrawBigString (8, v, "say_team:", 1.0f );
skip = 11;
}
else
{
SCR_DrawBigString (8, v, "say:", 1.0f );
skip = 5;
}
Field_BigDraw( &chatField, skip * BIGCHAR_WIDTH, v, SCREEN_WIDTH - ( skip + 1 ) * BIGCHAR_WIDTH, true );
v += BIGCHAR_HEIGHT;
}
}
/*
================
Con_DrawConsole
Draws the console with the solid background
================
*/
void Con_DrawSolidConsole (float frac)
{
int i, x, y;
int rows;
short *text;
int row;
int lines;
int currentColor;
vec4_t color;
lines = viddef.height * frac;
if (lines <= 0) return;
if (lines > viddef.height) lines = viddef.height;
con.xadjust = 0; // on wide screens, we will center the text
SCR_AdjustSize( &con.xadjust, NULL, NULL, NULL );
// draw the background
y = frac * SCREEN_HEIGHT - 2;
if ( y < 1 ) y = 0;
else SCR_DrawPic( 0, -SCREEN_HEIGHT + lines, SCREEN_WIDTH, SCREEN_HEIGHT, "conback" );
Vector4Set( color, 1, 0, 0, 1 );
SCR_FillRect( 0, y, SCREEN_WIDTH, 2, color );
// draw the version number
re->SetColor(g_color_table[ColorIndex(COLOR_RED)]);
i = strlen( VERSION );
for (x = 0; x < i; x++)
SCR_DrawSmallChar( viddef.width - ( i - x ) * SMALLCHAR_WIDTH, (lines - (SMALLCHAR_HEIGHT+SMALLCHAR_HEIGHT/2)), VERSION[x]);
// draw the text
con.vislines = lines;
rows = (lines - SMALLCHAR_WIDTH)/SMALLCHAR_WIDTH; // rows of text to draw
y = lines - (SMALLCHAR_HEIGHT * 3);
// draw from the bottom up
if (con.display != con.current)
{
// draw arrows to show the buffer is backscrolled
re->SetColor(g_color_table[ColorIndex(COLOR_RED)]);
for (x = 0; x < con.linewidth; x += 4)
SCR_DrawSmallChar( con.xadjust + (x+1) * SMALLCHAR_WIDTH, y, '^' );
y -= SMALLCHAR_HEIGHT;
rows--;
}
row = con.display;
if( con.x == 0 ) row--;
currentColor = 7;
re->SetColor( g_color_table[currentColor] );
for (i = 0; i < rows; i++, y -= SMALLCHAR_HEIGHT, row--)
{
if (row < 0) break;
if (con.current - row >= con.totallines)
{
// past scrollback wrap point
continue;
}
text = con.text + (row % con.totallines)*con.linewidth;
for (x = 0; x < con.linewidth; x++)
{
if((text[x] & 0xff ) == ' ')continue;
if(((text[x]>>8)&7 ) != currentColor )
{
currentColor = (text[x]>>8)&7;
re->SetColor(g_color_table[currentColor]);
}
SCR_DrawSmallChar( con.xadjust + (x+1) * SMALLCHAR_WIDTH, y, text[x] & 0xff );
}
}
// draw the input prompt, user text, and cursor if desired
Con_DrawInput();
re->SetColor( NULL );
}
/*
==================
Con_DrawConsole
==================
*/
void Con_DrawConsole( void )
{
// check for console width changes from a vid mode change
Con_CheckResize ();
// if disconnected, render console full screen
if ( cls.state == ca_disconnected || cls.state == ca_connecting)
{
Con_DrawSolidConsole( 1.0 );
}
if (cls.state != ca_active || !cl.refresh_prepped)
{
// connected, but can't render
if(cl.cinematictime > 0) SCR_DrawCinematic();
else SCR_FillRect( 0, SCREEN_HEIGHT/2, SCREEN_WIDTH, SCREEN_HEIGHT/2, COLOR_0 );
Con_DrawSolidConsole (0.5);
return;
}
if ( con.displayFrac )
{
Con_DrawSolidConsole( con.displayFrac );
}
else
{
// draw notify lines
if ( cls.state == ca_active )
{
Con_DrawNotify ();
}
}
}
/*
==================
Con_RunConsole
Scroll it up or down
==================
*/
void Con_RunConsole( void )
{
// decide on the destination height of the console
if (cls.key_dest == key_console)
con.finalFrac = 0.5; // half screen
else con.finalFrac = 0; // none visible
if (con.finalFrac < con.displayFrac)
{
con.displayFrac -= scr_conspeed->value*cls.frametime;
if (con.finalFrac > con.displayFrac)
con.displayFrac = con.finalFrac;
}
else if (con.finalFrac > con.displayFrac)
{
con.displayFrac += scr_conspeed->value*cls.frametime;
if (con.finalFrac < con.displayFrac)
con.displayFrac = con.finalFrac;
}
}
void Con_PageUp( void )
{
con.display -= 2;
if( con.current - con.display >= con.totallines )
con.display = con.current - con.totallines + 1;
}
void Con_PageDown( void )
{
con.display += 2;
if (con.display > con.current) con.display = con.current;
}
void Con_Top( void )
{
con.display = con.totallines;
if ( con.current - con.display >= con.totallines )
con.display = con.current - con.totallines + 1;
}
void Con_Bottom( void )
{
con.display = con.current;
}
void Con_Close( void )
{
Field_Clear( &g_consoleField );
Con_ClearNotify ();
con.finalFrac = 0; // none visible
con.displayFrac = 0;
}
bool Con_Active( void )
{
return con.initialized;
}

View File

@ -964,13 +964,15 @@ void CL_CalcViewValues (void)
for (i=0 ; i<3 ; i++)
cl.refdef.viewangles[i] += LerpAngle (ops->kick_angles[i], ps->kick_angles[i], lerp);
AngleVectors (cl.refdef.viewangles, cl.v_forward, cl.v_right, cl.v_up);
// sound engine requiried left-side hand
AngleVectorsFLU(cl.refdef.viewangles, NULL, cl.v_left, NULL );
AngleVectors(cl.refdef.viewangles, cl.v_forward, cl.v_right, cl.v_up);
// interpolate field of view
cl.refdef.fov_x = ops->fov + lerp * (ps->fov - ops->fov);
// don't interpolate blend color
for (i=0 ; i<4 ; i++)
for (i = 0; i < 4; i++)
cl.refdef.blend[i] = ps->blend[i];
// add the weapon

View File

@ -30,7 +30,7 @@ void CL_ParseInventory (void)
{
int i;
for (i=0 ; i<MAX_ITEMS ; i++)
for (i = 0; i < MAX_ITEMS; i++)
cl.inventory[i] = MSG_ReadShort (&net_message);
}
@ -52,8 +52,7 @@ void Inv_DrawString (int x, int y, char *string)
void SetStringHighBit (char *s)
{
while (*s)
*s++ |= 128;
while (*s) *s++ |= 128;
}
/*
@ -68,10 +67,10 @@ void CL_DrawInventory (void)
int i, j;
int num, selected_num, item;
int index[MAX_ITEMS];
char string[1024];
char string[1024];
int x, y;
char binding[1024];
char *bind;
char binding[1024];
char *bind;
int selected;
int top;
@ -79,10 +78,9 @@ void CL_DrawInventory (void)
num = 0;
selected_num = 0;
for (i=0 ; i<MAX_ITEMS ; i++)
for ( i = 0; i < MAX_ITEMS; i++)
{
if (i==selected)
selected_num = num;
if (i == selected) selected_num = num;
if (cl.inventory[i])
{
index[num] = i;
@ -92,10 +90,8 @@ void CL_DrawInventory (void)
// determine scroll point
top = selected_num - DISPLAY_ITEMS/2;
if (num - top < DISPLAY_ITEMS)
top = num - DISPLAY_ITEMS;
if (top < 0)
top = 0;
if (num - top < DISPLAY_ITEMS) top = num - DISPLAY_ITEMS;
if (top < 0) top = 0;
x = (viddef.width-256)/2;
y = (viddef.height-240)/2;
@ -110,28 +106,29 @@ void CL_DrawInventory (void)
Inv_DrawString (x, y, "hotkey ### item");
Inv_DrawString (x, y+8, "------ --- ----");
y += 16;
for (i=top ; i<num && i < top+DISPLAY_ITEMS ; i++)
for (i = top; i < num && i < top + DISPLAY_ITEMS; i++)
{
item = index[i];
// search for a binding
sprintf (binding, "use %s", cl.configstrings[CS_ITEMS+item]);
bind = "";
for (j=0 ; j<256 ; j++)
if (keybindings[j] && !strcasecmp (keybindings[j], binding))
for (j = 0; j < 256; j++)
{
if(keys[j].binding && !strcasecmp(keys[j].binding, binding))
{
bind = Key_KeynumToString(j);
break;
}
sprintf (string, "%6s %3i %s", bind, cl.inventory[item],
cl.configstrings[CS_ITEMS+item] );
}
sprintf (string, "%6s %3i %s", bind, cl.inventory[item], cl.configstrings[CS_ITEMS+item] );
if (item != selected)
{
SetStringHighBit (string);
}
else // draw a blinky cursor by the selected item
{
if ( (int)(cls.realtime * 5.0f) & 1)
if((int)(cls.realtime * 5.0f) & 1)
re->DrawChar (x-8, y, 15);
}
Inv_DrawString (x, y, string);

1342
engine/client/cl_keys.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -89,7 +89,7 @@ cvar_t *gender_auto;
cvar_t *cl_vwep;
client_static_t cls;
client_state_t cl;
client_t cl;
centity_t cl_entities[MAX_EDICTS];
@ -811,7 +811,7 @@ void CL_PingServers_f (void)
// send a broadcast packet
Msg ("pinging broadcast...\n");
noudp = Cvar_Get ("noudp", "0", CVAR_NOSET);
noudp = Cvar_Get ("noudp", "0", CVAR_INIT);
if (!noudp->value)
{
adr.type = NA_BROADCAST;
@ -819,7 +819,7 @@ void CL_PingServers_f (void)
Netchan_OutOfBandPrint (NS_CLIENT, adr, va("info %i", PROTOCOL_VERSION));
}
noipx = Cvar_Get ("noipx", "0", CVAR_NOSET);
noipx = Cvar_Get ("noipx", "0", CVAR_INIT);
if (!noipx->value)
{
adr.type = NA_BROADCAST_IPX;
@ -884,11 +884,11 @@ void CL_ConnectionlessPacket (void)
char *c;
MSG_BeginReading (&net_message);
MSG_ReadLong (&net_message); // skip the -1
MSG_ReadLong (&net_message); // skip the -1
s = MSG_ReadStringLine (&net_message);
Cmd_TokenizeString (s, false);
Cmd_TokenizeString(s);
c = Cmd_Argv(0);
@ -1534,21 +1534,31 @@ void CL_WriteConfiguration (void)
{
file_t *f;
if (cls.state == ca_uninitialized)
return;
if (cls.state == ca_uninitialized) return;
f = FS_Open ("config.cfg", "w");
if (!f)
f = FS_Open("scripts/config/keys.rc", "w");
if(f)
{
Msg ("Couldn't write config.cfg.\n");
return;
FS_Printf (f, "//=======================================================================\n");
FS_Printf (f, "//\t\t\tCopyright XashXT Group 2007 ©\n");
FS_Printf (f, "//\t\t\tkeys.rc - current key bindings\n");
FS_Printf (f, "//=======================================================================\n");
Key_WriteBindings(f);
FS_Close (f);
}
else Msg("Couldn't write keys.rc.\n");
FS_Printf (f, "// generated by system, do not modify\n");
Key_WriteBindings (f);
FS_Close (f);
Cvar_WriteVariables ("config.cfg");
f = FS_Open("scripts/config/vars.rc", "w");
if(f)
{
FS_Printf (f, "//=======================================================================\n");
FS_Printf (f, "//\t\t\tCopyright XashXT Group 2007 ©\n");
FS_Printf (f, "//\t\t\tvars.rc - archive of cvars\n");
FS_Printf (f, "//=======================================================================\n");
Cvar_WriteVariables(f);
FS_Close (f);
}
else Msg("Couldn't write vars.rc.\n");
}
@ -1700,13 +1710,13 @@ void CL_Frame (float time)
// update audio
S_Update();
S_Respatialize( cl.playernum + 1, cl.refdef.vieworg, cl.v_forward, cl.v_right, cl.v_up );
S_Respatialize( cl.playernum + 1, cl.refdef.vieworg, cl.v_forward, cl.v_left, cl.v_up );
// advance local effects for next frame
CL_RunDLights ();
CL_RunLightStyles ();
SCR_RunCinematic ();
SCR_RunConsole ();
Con_RunConsole ();
cls.framecount++;
}

View File

@ -298,7 +298,7 @@ void CL_ParseServerData (void)
//Sys_Error("Serverdata packet received.\n");
MsgDev (D_INFO, "Serverdata packet received.\n");
// wipe the client_state_t struct
// wipe the client_t struct
CL_ClearState ();
cls.state = ca_connected;
@ -663,13 +663,8 @@ void CL_ParseServerMessage (void)
case svc_print:
i = MSG_ReadByte (&net_message);
if (i == PRINT_CHAT)
{
S_StartLocalSound ("misc/talk.wav");
con.ormask = 128;
}
Msg ("%s", MSG_ReadString (&net_message));
con.ormask = 0;
if (i == PRINT_CHAT) S_StartLocalSound ("misc/talk.wav");
Msg ("^6%s", MSG_ReadString (&net_message));
break;
case svc_centerprint:

View File

@ -239,7 +239,7 @@ void CL_PredictMovement (void)
pm.s = cl.frame.playerstate.pmove;
// SCR_DebugGraph (current - ack - 1, 0);
// SCR_DebugGraph (current - ack - 1, COLOR_0);
frame = 0;

View File

@ -98,29 +98,28 @@ void CL_AddNetgraph (void)
if (scr_debuggraph->value || scr_timegraph->value)
return;
for (i=0 ; i<cls.netchan.dropped ; i++)
SCR_DebugGraph (30, 0x40);
for (i = 0; i < cls.netchan.dropped; i++)
SCR_DebugGraph (30, COLOR_64);
for (i=0 ; i<cl.surpressCount ; i++)
SCR_DebugGraph (30, 0xdf);
for (i = 0; i < cl.surpressCount; i++)
SCR_DebugGraph (30, COLOR_223);
// see what the latency was on this packet
in = cls.netchan.incoming_acknowledged & (CMD_BACKUP-1);
ping = cls.realtime - cl.cmd_time[in];
ping /= 30;
if (ping > 30)
ping = 30;
SCR_DebugGraph (ping, 0xd0);
if (ping > 30) ping = 30;
SCR_DebugGraph (ping, COLOR_208);
}
typedef struct
{
float value;
int color;
float value;
vec4_t color;
} graphsamp_t;
static int current;
static int current;
static graphsamp_t values[1024];
/*
@ -128,10 +127,10 @@ static graphsamp_t values[1024];
SCR_DebugGraph
==============
*/
void SCR_DebugGraph (float value, int color)
void SCR_DebugGraph (float value, vec4_t color)
{
values[current&1023].value = value;
values[current&1023].color = color;
values[current & 1023].value = value;
Vector4Copy(color, values[current & 1023].color);
current++;
}
@ -143,30 +142,25 @@ SCR_DrawDebugGraph
void SCR_DrawDebugGraph (void)
{
int a, x, y, w, i, h;
float v;
int color;
float v;
//
// draw the graph
//
w = scr_vrect.width;
x = scr_vrect.x;
y = scr_vrect.y+scr_vrect.height;
re->DrawFill (x, y-scr_graphheight->value,
w, scr_graphheight->value, 8);
for (a=0 ; a<w ; a++)
SCR_FillRect( x, y-scr_graphheight->value, w, scr_graphheight->value, COLOR_8);
for (a = 0; a < w; a++)
{
i = (current-1-a+1024) & 1023;
i = (current - 1 - a + 1024) & 1023;
v = values[i].value;
color = values[i].color;
v = v*scr_graphscale->value + scr_graphshift->value;
v = v * scr_graphscale->value + scr_graphshift->value;
if (v < 0)
v += scr_graphheight->value * (1+(int)(-v/scr_graphheight->value));
if (v < 0) v += scr_graphheight->value * (1+(int)(-v/scr_graphheight->value));
h = (int)v % (int)scr_graphheight->value;
re->DrawFill (x+w-1-a, y - h, 1, h, color);
SCR_FillRect( x+w-1-a, y - h, 1, h, values[i].color );
}
}
@ -255,7 +249,7 @@ void SCR_DrawCenterString (void)
int x, y;
int remaining;
// the finale prints the characters one at a time
// the finale prints the characters one at a time
remaining = 9999;
scr_erase_center = 0;
@ -419,9 +413,7 @@ void SCR_Init (void)
scr_graphscale = Cvar_Get ("graphscale", "1", 0);
scr_graphshift = Cvar_Get ("graphshift", "0", 0);
//
// register our commands
//
// register our commands
Cmd_AddCommand ("timerefresh",SCR_TimeRefresh_f);
Cmd_AddCommand ("loading",SCR_Loading_f);
Cmd_AddCommand ("sizeup",SCR_SizeUp_f);
@ -496,73 +488,6 @@ void SCR_DrawLoading (void)
//=============================================================================
/*
==================
SCR_RunConsole
Scroll it up or down
==================
*/
void SCR_RunConsole (void)
{
// decide on the height of the console
if (cls.key_dest == key_console)
scr_conlines = 0.5; // half screen
else scr_conlines = 0; // none visible
if (scr_conlines < scr_con_current)
{
scr_con_current -= scr_conspeed->value*cls.frametime;
if (scr_conlines > scr_con_current)
scr_con_current = scr_conlines;
}
else if (scr_conlines > scr_con_current)
{
scr_con_current += scr_conspeed->value*cls.frametime;
if (scr_conlines < scr_con_current)
scr_con_current = scr_conlines;
}
}
/*
==================
SCR_DrawConsole
==================
*/
void SCR_DrawConsole (void)
{
Con_CheckResize ();
if (cls.state == ca_disconnected || cls.state == ca_connecting)
{ // forced full screen console
Con_DrawConsole (1.0);
return;
}
if (cls.state != ca_active || !cl.refresh_prepped)
{
// connected, but can't render
if(cl.cinematictime > 0) SCR_DrawCinematic();
else re->DrawFill (0, viddef.height/2, viddef.width, viddef.height/2, 0);
Con_DrawConsole (0.5);
return;
}
if (scr_con_current)
{
Con_DrawConsole (scr_con_current);
}
else
{
if (cls.key_dest == key_game || cls.key_dest == key_message)
Con_DrawNotify(); // only draw notify in game
}
}
//=============================================================================
/*
================
SCR_BeginLoadingPlaque
@ -663,6 +588,233 @@ void SCR_TimeRefresh_f (void)
Msg ("%f seconds (%f fps)\n", time, 128/time);
}
/*
================
SCR_AdjustFrom640
Adjusted for resolution and screen aspect ratio
================
*/
void SCR_AdjustSize( float *x, float *y, float *w, float *h )
{
float xscale;
float yscale;
// scale for screen sizes
xscale = viddef.width / SCREEN_WIDTH;
yscale = viddef.height / SCREEN_HEIGHT;
if(x) *x *= xscale;
if(y) *y *= yscale;
if(w) *w *= xscale;
if(h) *h *= yscale;
}
/*
================
SCR_DrawPic
Coordinates are 640*480 virtual values
================
*/
void SCR_DrawPic( float x, float y, float width, float height, char *picname )
{
SCR_AdjustSize( &x, &y, &width, &height );
re->DrawStretchPic (x, y, width, height, 0, 0, 1, 1, picname );
}
/*
================
SCR_DrawChar
chars are drawn at 640*480 virtual screen size
================
*/
static void SCR_DrawChar( int x, int y, float size, int ch )
{
int row, col;
float frow, fcol;
float ax, ay, aw, ah;
ch &= 255;
if( ch == ' ' )return;
if(y < -size) return;
ax = x;
ay = y;
aw = size;
ah = size;
SCR_AdjustSize( &ax, &ay, &aw, &ah );
row = ch>>4;
col = ch&15;
frow = row*0.0625;
fcol = col*0.0625;
size = 0.0625;
re->DrawStretchPic( ax, ay, aw, ah, fcol, frow, fcol + size, frow + size, "conchars" );
}
/*
====================
SCR_DrawSmallChar
small chars are drawn at native screen resolution
====================
*/
void SCR_DrawSmallChar( int x, int y, int ch )
{
int row, col;
float frow, fcol;
float size;
ch &= 255;
if( ch == ' ' )return;
if(y < -SMALLCHAR_HEIGHT) return;
row = ch>>4;
col = ch&15;
frow = row*0.0625;
fcol = col*0.0625;
size = 0.0625;
re->DrawStretchPic( x, y, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT, fcol, frow, fcol + size, frow + size, "conchars" );
}
/*
==================
SCR_DrawSmallString[Color]
Draws a multi-colored string with a drop shadow, optionally forcing
to a fixed color.
Coordinates are at 640 by 480 virtual resolution
==================
*/
void SCR_DrawSmallStringExt( int x, int y, const char *string, float *setColor, bool forceColor )
{
vec4_t color;
const char *s;
int xx;
// draw the colored text
s = string;
xx = x;
re->SetColor( setColor );
while ( *s )
{
if(IsColorString( s ))
{
if( !forceColor )
{
Mem_Copy( color, g_color_table[ColorIndex(*(s+1))], sizeof( color ));
color[3] = setColor[3];
re->SetColor( color );
}
s += 2;
continue;
}
SCR_DrawSmallChar( xx, y, *s );
xx += SMALLCHAR_WIDTH;
s++;
}
re->SetColor( NULL );
}
/*
==================
SCR_DrawBigString[Color]
Draws a multi-colored string with a drop shadow, optionally forcing
to a fixed color.
Coordinates are at 640 by 480 virtual resolution
==================
*/
void SCR_DrawStringExt( int x, int y, float size, const char *string, float *setColor, bool forceColor )
{
vec4_t color;
const char *s;
int xx;
// draw the drop shadow
Vector4Set( color, 0.0f, 0.0f, 0.0f, setColor[3] );
re->SetColor( color );
s = string;
xx = x;
while ( *s )
{
if(IsColorString( s ))
{
s += 2;
continue;
}
SCR_DrawChar( xx + 2, y + 2, size, *s );
xx += size;
s++;
}
// draw the colored text
s = string;
xx = x;
re->SetColor( setColor );
while ( *s )
{
if(IsColorString( s ))
{
if ( !forceColor )
{
Mem_Copy( color, g_color_table[ColorIndex(*(s+1))], sizeof( color ));
color[3] = setColor[3];
re->SetColor( color );
}
s += 2;
continue;
}
SCR_DrawChar( xx, y, size, *s );
xx += size;
s++;
}
re->SetColor( NULL );
}
void SCR_DrawBigString( int x, int y, const char *s, float alpha )
{
float color[4];
Vector4Set( color, 1.0f, 1.0f, 1.0f, alpha );
SCR_DrawStringExt( x, y, BIGCHAR_WIDTH, s, color, false );
}
void SCR_DrawBigStringColor( int x, int y, const char *s, vec4_t color )
{
SCR_DrawStringExt( x, y, BIGCHAR_WIDTH, s, color, true );
}
/*
================
SCR_FillRect
Coordinates are 640*480 virtual values
=================
*/
void SCR_FillRect( float x, float y, float width, float height, const float *color )
{
re->SetColor( color );
SCR_AdjustSize( &x, &y, &width, &height );
re->DrawFill( x, y, width, height );
re->SetColor( NULL );
}
/*
=================
SCR_AddDirtyPoint
@ -1273,8 +1425,7 @@ void SCR_UpdateScreen (void)
return;
}
if (!scr_initialized || !con.initialized)
return; // not initialized yet
if (!scr_initialized) return; // not initialized yet
/*
** range check cl_camera_separation so we don't inadvertently fry someone's
@ -1319,7 +1470,7 @@ void SCR_UpdateScreen (void)
}
else if (cls.key_dest == key_console)
{
SCR_DrawConsole ();
Con_DrawConsole ();
}
else SCR_DrawCinematic();
}
@ -1343,14 +1494,14 @@ void SCR_UpdateScreen (void)
SCR_CheckDrawCenterString ();
if (scr_timegraph->value)
SCR_DebugGraph (cls.frametime*300, 0);
SCR_DebugGraph (cls.frametime*300, COLOR_0);
if (scr_debuggraph->value || scr_timegraph->value || scr_netgraph->value)
SCR_DrawDebugGraph ();
SCR_DrawPause ();
SCR_DrawConsole ();
Con_DrawConsole ();
M_Draw ();

View File

@ -19,7 +19,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// client.h -- primary header for client
//define PARANOID // speed sapping error checking
#ifndef CLIENT_H
#define CLIENT_H
#include "engine.h"
#include "vid.h"
@ -27,7 +28,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sound.h"
#include "input.h"
#include "keys.h"
#include "console.h"
//=============================================================================
typedef struct
@ -75,7 +75,7 @@ extern int num_cl_weaponmodels;
#define CMD_BACKUP 64 // allow a lot of command backups for very fast systems
//
// the client_state_t structure is wiped completely at every
// the client_t structure is wiped completely at every
// server map change
//
typedef struct
@ -121,7 +121,7 @@ typedef struct
refdef_t refdef;
vec3_t v_forward, v_right, v_up; // set when refdef.angles is set
vec3_t v_forward, v_right, v_left, v_up; // set when refdef.angles is set
//
// transient data from server
@ -150,9 +150,9 @@ typedef struct
clientinfo_t clientinfo[MAX_CLIENTS];
clientinfo_t baseclientinfo;
} client_state_t;
} client_t;
extern client_state_t cl;
extern client_t cl;
/*
==================================================================
@ -454,6 +454,7 @@ void CL_BaseMove (usercmd_t *cmd);
void IN_CenterView (void);
float CL_KeyState (kbutton_t *key);
void CL_CharEvent( int key );
char *Key_KeynumToString (int keynum);
//
@ -536,4 +537,28 @@ void CL_DrawInventory (void);
//
// cl_pred.c
//
void CL_PredictMovement (void);
void CL_PredictMovement (void);
//
// cl_con.c
//
int Con_PrintStrlen( const char *string );
bool Con_Active( void );
void Con_CheckResize( void );
void Con_Print( char *txt );
void Con_Init( void );
void Con_Clear_f( void );
void Con_ToggleConsole_f( void );
void Con_DrawNotify( void );
void Con_ClearNotify( void );
void Con_RunConsole( void );
void Con_DrawConsole( void );
void Con_PageUp( void );
void Con_PageDown( void );
void Con_Top( void );
void Con_Bottom( void );
void Con_Close( void );
extern int g_console_field_width;
#endif//CLIENT_H

189
engine/client/keys.h Normal file
View File

@ -0,0 +1,189 @@
/*
Copyright (C) 1997-2001 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.
*/
#define MAX_EDIT_LINE 256
#define COMMAND_HISTORY 32
// these are the key numbers that should be passed to Key_Event
typedef enum
{
K_TAB = 9,
K_ENTER = 13,
K_ESCAPE = 27,
K_SPACE = 32,
K_BACKSPACE = 127,
K_COMMAND = 128,
K_CAPSLOCK,
K_POWER,
K_PAUSE,
K_UPARROW,
K_DOWNARROW,
K_LEFTARROW,
K_RIGHTARROW,
K_ALT,
K_CTRL,
K_SHIFT,
K_INS,
K_DEL,
K_PGDN,
K_PGUP,
K_HOME,
K_END,
K_F1,
K_F2,
K_F3,
K_F4,
K_F5,
K_F6,
K_F7,
K_F8,
K_F9,
K_F10,
K_F11,
K_F12,
K_F13,
K_F14,
K_F15,
K_KP_HOME,
K_KP_UPARROW,
K_KP_PGUP,
K_KP_LEFTARROW,
K_KP_5,
K_KP_RIGHTARROW,
K_KP_END,
K_KP_DOWNARROW,
K_KP_PGDN,
K_KP_ENTER,
K_KP_INS,
K_KP_DEL,
K_KP_SLASH,
K_KP_MINUS,
K_KP_PLUS,
K_KP_NUMLOCK,
K_KP_STAR,
K_KP_EQUALS,
K_MOUSE1,
K_MOUSE2,
K_MOUSE3,
K_MOUSE4,
K_MOUSE5,
K_MWHEELDOWN,
K_MWHEELUP,
K_JOY1,
K_JOY2,
K_JOY3,
K_JOY4,
K_JOY5,
K_JOY6,
K_JOY7,
K_JOY8,
K_JOY9,
K_JOY10,
K_JOY11,
K_JOY12,
K_JOY13,
K_JOY14,
K_JOY15,
K_JOY16,
K_JOY17,
K_JOY18,
K_JOY19,
K_JOY20,
K_JOY21,
K_JOY22,
K_JOY23,
K_JOY24,
K_JOY25,
K_JOY26,
K_JOY27,
K_JOY28,
K_JOY29,
K_JOY30,
K_JOY31,
K_JOY32,
K_AUX1,
K_AUX2,
K_AUX3,
K_AUX4,
K_AUX5,
K_AUX6,
K_AUX7,
K_AUX8,
K_AUX9,
K_AUX10,
K_AUX11,
K_AUX12,
K_AUX13,
K_AUX14,
K_AUX15,
K_AUX16,
K_LAST_KEY // this had better be <256!
} keyNum_t;
typedef struct field_s
{
int cursor;
int scroll;
int widthInChars;
char buffer[MAX_EDIT_LINE];
} field_t;
typedef struct key_s
{
bool down;
int repeats; // if > 1, it is autorepeating
char *binding;
} key_t;
extern char chat_buffer[];
extern int chat_bufferlen;
extern bool chat_team;
extern field_t historyEditLines[COMMAND_HISTORY];
extern field_t g_consoleField;
extern field_t chatField;
extern bool anykeydown;
extern key_t keys[];
void Field_Clear( field_t *edit );
void Field_CharEvent( field_t *edit, int ch );
void Field_Draw( field_t *edit, int x, int y, int width, bool showCursor );
void Field_BigDraw( field_t *edit, int x, int y, int width, bool showCursor );
void Key_Event (int key, bool down, unsigned time);
void Key_Init (void);
void Key_WriteBindings (file_t *f);
void Key_SetBinding (int keynum, char *binding);
void Key_ClearStates (void);
char *Key_KeynumToString (int keynum);
int Key_StringToKeynum (char *str);
int Key_GetKey( char *binding );

View File

@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// common.h -- definitions common between client and server, but not game.dll
#define VERSION 3.21
#define VERSION "Xash 0.48"
#define BASEDIRNAME "xash"
@ -40,6 +40,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define STRING_COLOR_DEFAULT 7
#define STRING_COLOR_DEFAULT_STR "^7"
extern vec4_t g_color_table[8];
// move to mathlib
#define RAD_TO_STUDIO (32768.0/M_PI)
#define STUDIO_TO_RAD (M_PI/32768.0)
@ -137,8 +139,15 @@ int COM_CheckParm (char *parm);
void COM_Init (void);
void COM_InitArgv (int argc, char **argv);
// message functions
void Com_Print(char *txt);
void Com_Printf(char *fmt, ...);
void Com_DPrintf(int level, char *fmt, ...);
void Com_DWarnf(char *fmt, ...);
char *CopyString (const char *in);
//============================================================================
void Info_Print (char *s);
@ -333,45 +342,15 @@ The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute ();
*/
#define EXEC_NOW 0 // don't return until completed
#define EXEC_NOW 0 // don't return until completed
#define EXEC_INSERT 1 // insert at current position, but don't run yet
#define EXEC_APPEND 2 // add to end of the command buffer
void Cbuf_Init (void);
// allocates an initial text buffer that will grow as needed
void Cbuf_AddText (char *text);
// as new commands are generated from the console or keybindings,
// the text is added to the end of the command buffer.
void Cbuf_InsertText (char *text);
// when a command wants to issue other commands immediately, the text is
// inserted at the beginning of the buffer, before any remaining unexecuted
// commands.
void Cbuf_ExecuteText (int exec_when, char *text);
// this can be used in place of either Cbuf_AddText or Cbuf_InsertText
void Cbuf_AddEarlyCommands (bool clear);
// adds all the +set commands from the command line
bool Cbuf_AddLateCommands (void);
// adds all the remaining + commands from the command line
// Returns true if any late commands were added, which
// will keep the demoloop from immediately starting
void Cbuf_AddText (const char *text);
void Cbuf_InsertText (const char *text);
void Cbuf_ExecuteText (int exec_when, const char *text);
void Cbuf_Execute (void);
// Pulls off \n terminated lines of text from the command buffer and sends
// them through Cmd_ExecuteString. Stops when the buffer is empty.
// Normally called once per frame, but may be explicitly invoked.
// Do not call inside a command function!
void Cbuf_CopyToDefer (void);
void Cbuf_InsertFromDefer (void);
// These two functions are used to defer any pending commands while a map
// is being loaded
//===========================================================================
/*
@ -382,9 +361,11 @@ then searches for a command or variable that matches the first token.
typedef void (*xcommand_t) (void);
void Cmd_Init (void);
void Cmd_Init( int argc, char **argv );
bool Cmd_AddStartupCommands( void );
void Cmd_AddCommand (char *cmd_name, xcommand_t function);
#define Cmd_AddCommand(name, func) _Cmd_AddCommand(name, func, "no description" )
void _Cmd_AddCommand(const char *cmd_name, xcommand_t function, const char *cmd_desc);
// called by the init functions of other parts of the program to
// register commands and functions to call for them.
// The cmd_name is referenced later, so it should not be in temp memory
@ -395,18 +376,18 @@ void Cmd_RemoveCommand (char *cmd_name);
bool Cmd_Exists (const char *cmd_name);
// used by the cvar code to check for cvar / command name overlap
char *Cmd_CompleteCommand (char *partial);
void Cmd_CommandCompletion( void(*callback)(const char *s, const char *m));
// attempts to match a partial command for automatic command line completion
// returns NULL if nothing fits
int Cmd_Argc (void);
char *Cmd_Argv (int arg);
char *Cmd_Args (void);
int Cmd_Argc (void);
char *Cmd_Argv (int arg);
char *Cmd_Args (void);
// The functions that execute commands get their parameters with these
// functions. Cmd_Argv () will return an empty string, not a NULL
// if arg > argc, so string operations are always safe.
void Cmd_TokenizeString (const char *text, bool macroExpand);
void Cmd_TokenizeString (const char *text);
// Takes a null terminated string. Does not need to be /n terminated.
// breaks the string up into arg tokens.
@ -665,7 +646,7 @@ extern float time_after_ref;
extern vec3_t bytedirs[NUMVERTEXNORMALS];
// this is in the client code, but can be used for debugging from server
void SCR_DebugGraph (float value, int color);
void SCR_DebugGraph (float value, vec4_t color);
/*

File diff suppressed because it is too large Load Diff

View File

@ -38,6 +38,19 @@ float time_before_game;
float time_after_game;
float time_before_ref;
float time_after_ref;
vec4_t g_color_table[8] =
{
{0.0, 0.0, 0.0, 1.0},
{1.0, 0.0, 0.0, 1.0},
{0.0, 1.0, 0.0, 1.0},
{1.0, 1.0, 0.0, 1.0},
{0.0, 0.0, 1.0, 1.0},
{0.0, 1.0, 1.0, 1.0},
{1.0, 0.0, 1.0, 1.0},
{1.0, 1.0, 1.0, 1.0},
};
/*
==================
Com_ServerState
@ -284,4 +297,113 @@ void Com_PageInMemory (byte *buffer, int size)
for (i = size - 1; i > 0; i -= 4096)
paged_total += buffer[i];
}
/*
================
Com_Print
Handles cursor positioning, line wrapping, etc
All console printing must go through this in order to be logged to disk
If no console is visible, the text will appear at the top of the game window
================
*/
void Com_Print (char *txt)
{
if (host.rd.target)
{
if((strlen (txt) + strlen(host.rd.buffer)) > (host.rd.buffersize - 1))
{
if(host.rd.flush)
{
host.rd.flush(host.rd.target, host.rd.buffer);
*host.rd.buffer = 0;
}
}
strcat (host.rd.buffer, txt);
return;
}
Con_Print( txt ); // echo to client console
Sys_Print( txt ); // echo to system console
// sys print also stored messages into system log
}
/*
=============
Com_Printf
Both client and server can use this, and it will output
to the apropriate place.
=============
*/
void Com_Printf (char *fmt, ...)
{
va_list argptr;
char msg[MAX_INPUTLINE];
va_start (argptr, fmt);
vsprintf (msg, fmt, argptr);
va_end (argptr);
Com_Print (msg);
}
/*
================
Con_DPrintf
A Msg that only shows up in developer mode
================
*/
void Com_DPrintf (int level, char *fmt, ...)
{
va_list argptr;
char msg[MAX_INPUTLINE];
// don't confuse non-developers with techie stuff...
if(host.developer < level) return;
va_start (argptr,fmt);
vsprintf (msg,fmt,argptr);
va_end (argptr);
switch(level)
{
case D_INFO:
Com_Print(va("^6%s", msg));
break;
case D_WARN:
Com_Print(va("^3Warning:^7 %s", msg));
break;
case D_ERROR:
Com_Print(va("^1Error:^7 %s", msg));
break;
case D_LOAD:
Com_Print(msg);
break;
}
}
/*
================
Con_DWarnf
A Warning that only shows up in debug mode
================
*/
void Com_DWarnf (char *fmt, ...)
{
va_list argptr;
char msg[MAX_INPUTLINE];
// don't confuse non-developers with techie stuff...
if (!host.debug) return;
va_start (argptr, fmt);
vsprintf (msg, fmt, argptr);
va_end (argptr);
Com_Print(va("^3Warning:^7 %s", msg));
}

View File

@ -1,742 +0,0 @@
/*
Copyright (C) 1997-2001 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.
*/
// console.c
#include "client.h"
console_t con;
cvar_t *con_notifytime;
#define MAXCMDLINE 256
extern char key_lines[32][MAXCMDLINE];
extern int edit_line;
extern int key_linepos;
void DrawString (int x, int y, char *s)
{
while (*s)
{
re->DrawChar (x, y, *s);
x+=8;
s++;
}
}
void DrawAltString (int x, int y, char *s)
{
while (*s)
{
re->DrawChar (x, y, *s ^ 0x80);
x+=8;
s++;
}
}
void Key_ClearTyping (void)
{
key_lines[edit_line][1] = 0; // clear any typing
key_linepos = 1;
}
/*
================
Con_ToggleConsole_f
================
*/
void Con_ToggleConsole_f (void)
{
SCR_EndLoadingPlaque(); // get rid of loading plaque
Key_ClearTyping ();
Con_ClearNotify ();
if (cls.key_dest == key_console)
{
M_ForceMenuOff ();
Cvar_Set ("paused", "0");
}
else
{
M_ForceMenuOff ();
cls.key_dest = key_console;
if (Cvar_VariableValue ("maxclients") == 1 && Com_ServerState ())
Cvar_Set ("paused", "1");
}
}
/*
================
Con_ToggleChat_f
================
*/
void Con_ToggleChat_f (void)
{
Key_ClearTyping ();
if (cls.key_dest == key_console)
{
if (cls.state == ca_active)
{
M_ForceMenuOff ();
cls.key_dest = key_game;
}
}
else
cls.key_dest = key_console;
Con_ClearNotify ();
}
/*
================
Con_Clear_f
================
*/
void Con_Clear_f (void)
{
memset (con.text, ' ', CON_TEXTSIZE);
}
/*
================
Con_Dump_f
Save the console contents out to a file
================
*/
void Con_Dump_f (void)
{
int l, x;
char *line;
file_t *f;
char buffer[1024];
char name[MAX_OSPATH];
if (Cmd_Argc() != 2)
{
Msg ("usage: condump <filename>\n");
return;
}
sprintf (name, "%s.txt", Cmd_Argv(1));
Msg ("Dumped console text to %s.\n", name);
f = FS_Open (name, "w");
if (!f)
{
Msg ("ERROR: couldn't open.\n");
return;
}
// skip empty lines
for (l = con.current - con.totallines + 1 ; l <= con.current ; l++)
{
line = con.text + (l%con.totallines)*con.linewidth;
for (x=0 ; x<con.linewidth ; x++)
if (line[x] != ' ')
break;
if (x != con.linewidth)
break;
}
// write the remaining lines
buffer[con.linewidth] = 0;
for ( ; l <= con.current ; l++)
{
line = con.text + (l%con.totallines)*con.linewidth;
strncpy (buffer, line, con.linewidth);
for (x=con.linewidth-1 ; x>=0 ; x--)
{
if (buffer[x] == ' ')
buffer[x] = 0;
else
break;
}
for (x=0; buffer[x]; x++)
buffer[x] &= 0x7f;
FS_Printf (f, "%s\n", buffer);
}
FS_Close (f);
}
/*
================
Con_ClearNotify
================
*/
void Con_ClearNotify (void)
{
int i;
for (i=0 ; i<NUM_CON_TIMES ; i++)
con.times[i] = 0;
}
/*
================
Con_MessageMode_f
================
*/
void Con_MessageMode_f (void)
{
chat_team = false;
cls.key_dest = key_message;
}
/*
================
Con_MessageMode2_f
================
*/
void Con_MessageMode2_f (void)
{
chat_team = true;
cls.key_dest = key_message;
}
/*
================
Con_CheckResize
If the line width has changed, reformat the buffer.
================
*/
void Con_CheckResize (void)
{
int i, j, width, oldwidth, oldtotallines, numlines, numchars;
char tbuf[CON_TEXTSIZE];
width = (viddef.width >> 3) - 2;
if (width == con.linewidth)
return;
if (width < 1) // video hasn't been initialized yet
{
width = 38;
con.linewidth = width;
con.totallines = CON_TEXTSIZE / con.linewidth;
memset (con.text, ' ', CON_TEXTSIZE);
}
else
{
oldwidth = con.linewidth;
con.linewidth = width;
oldtotallines = con.totallines;
con.totallines = CON_TEXTSIZE / con.linewidth;
numlines = oldtotallines;
if (con.totallines < numlines)
numlines = con.totallines;
numchars = oldwidth;
if (con.linewidth < numchars)
numchars = con.linewidth;
memcpy (tbuf, con.text, CON_TEXTSIZE);
memset (con.text, ' ', CON_TEXTSIZE);
for (i=0 ; i<numlines ; i++)
{
for (j=0 ; j<numchars ; j++)
{
con.text[(con.totallines - 1 - i) * con.linewidth + j] =
tbuf[((con.current - i + oldtotallines) %
oldtotallines) * oldwidth + j];
}
}
Con_ClearNotify ();
}
con.current = con.totallines - 1;
con.display = con.current;
}
/*
================
Con_Init
================
*/
void Con_Init (void)
{
con.linewidth = -1;
Con_CheckResize ();
MsgDev(D_INFO, "Console initialized.\n");
// register our commands
con_notifytime = Cvar_Get ("con_notifytime", "3", 0);
Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f);
Cmd_AddCommand ("togglechat", Con_ToggleChat_f);
Cmd_AddCommand ("messagemode", Con_MessageMode_f);
Cmd_AddCommand ("messagemode2", Con_MessageMode2_f);
Cmd_AddCommand ("clear", Con_Clear_f);
Cmd_AddCommand ("condump", Con_Dump_f);
con.initialized = true;
}
/*
===============
Con_Linefeed
===============
*/
void Con_Linefeed (void)
{
con.x = 0;
if (con.display == con.current)
con.display++;
con.current++;
memset (&con.text[(con.current%con.totallines)*con.linewidth], ' ', con.linewidth);
}
/*
================
Con_Print
Handles cursor positioning, line wrapping, etc
All console printing must go through this in order to be logged to disk
If no console is visible, the text will appear at the top of the game window
================
*/
void Con_Print (char *txt)
{
int y;
int c, l;
static int cr;
int mask;
Sys_Print( txt ); // make sure what all messages will be stored in log
if (host.rd.target)
{
if((strlen (txt) + strlen(host.rd.buffer)) > (host.rd.buffersize - 1))
{
if(host.rd.flush)
{
host.rd.flush(host.rd.target, host.rd.buffer);
*host.rd.buffer = 0;
}
}
strcat (host.rd.buffer, txt);
return;
}
if (!con.initialized) return;
if (txt[0] == '^' && txt[1] == '3') // default Darkplace color code
{
mask = 128; // go to colored text
txt += 2;
}
else mask = 0;
while ( (c = *txt) )
{
// count word length
for (l=0 ; l< con.linewidth ; l++)
if ( txt[l] <= ' ')
break;
// word wrap
if (l != con.linewidth && (con.x + l > con.linewidth) )
con.x = 0;
txt++;
if (cr)
{
con.current--;
cr = false;
}
if (!con.x)
{
Con_Linefeed ();
// mark time for transparent overlay
if (con.current >= 0)
con.times[con.current % NUM_CON_TIMES] = cls.realtime;
}
switch (c)
{
case '\n':
con.x = 0;
break;
case '\r':
con.x = 0;
cr = 1;
break;
default: // display character and advance
y = con.current % con.totallines;
con.text[y*con.linewidth+con.x] = c | mask | con.ormask;
con.x++;
if (con.x >= con.linewidth)
con.x = 0;
break;
}
}
}
/*
=============
Con_Printf
Both client and server can use this, and it will output
to the apropriate place.
=============
*/
void Con_Printf (char *fmt, ...)
{
va_list argptr;
char msg[MAX_INPUTLINE];
va_start (argptr, fmt);
vsprintf (msg, fmt, argptr);
va_end (argptr);
Con_Print (msg);
}
/*
================
Con_DPrintf
A Msg that only shows up in developer mode
================
*/
void Con_DPrintf (int level, char *fmt, ...)
{
va_list argptr;
char msg[MAX_INPUTLINE];
// don't confuse non-developers with techie stuff...
if(host.developer >= level)
{
va_start (argptr,fmt);
vsprintf (msg,fmt,argptr);
va_end (argptr);
Con_Print (msg);
}
}
/*
================
Con_DWarnf
A Warning that only shows up in debug mode
================
*/
void Con_DWarnf (char *fmt, ...)
{
va_list argptr;
char msg[MAX_INPUTLINE];
// don't confuse non-developers with techie stuff...
if (!host.debug) return;
va_start (argptr,fmt);
vsprintf (msg,fmt,argptr);
va_end (argptr);
Con_Print (msg);
}
/*
==============
Con_CenteredPrint
==============
*/
void Con_CenteredPrint (char *text)
{
int l;
char buffer[1024];
l = strlen(text);
l = (con.linewidth-l)/2;
if (l < 0)
l = 0;
memset (buffer, ' ', l);
strcpy (buffer+l, text);
strcat (buffer, "\n");
Con_Print (buffer);
}
/*
==============================================================================
DRAWING
==============================================================================
*/
/*
================
Con_DrawInput
The input line scrolls horizontally if typing goes beyond the right edge
================
*/
void Con_DrawInput (void)
{
int y;
int i;
char *text;
if (cls.key_dest == key_menu)
return;
if (cls.key_dest != key_console && cls.state == ca_active)
return; // don't draw anything (always draw if not active)
text = key_lines[edit_line];
// add the cursor frame
text[key_linepos] = 10+((int)(cls.realtime * 4.0f)&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-16;
for (i=0 ; i<con.linewidth ; i++)
re->DrawChar ( (i+1)<<3, con.vislines - 22, text[i]);
// remove cursor
key_lines[edit_line][key_linepos] = 0;
}
/*
================
Con_DrawNotify
Draws the last few lines of output transparently over the game top
================
*/
void Con_DrawNotify (void)
{
int x, v;
char *text;
int i;
float time;
char *s;
int skip;
v = 0;
for (i = con.current - NUM_CON_TIMES + 1; i <= con.current; i++)
{
if (i < 0) continue;
time = con.times[i % NUM_CON_TIMES];
if (time == 0)
continue;
time = cls.realtime - time;
if (time > con_notifytime->value)
continue;
text = con.text + (i % con.totallines) * con.linewidth;
for (x = 0 ; x < con.linewidth ; x++)
re->DrawChar ( (x+1)<<3, v, text[x]);
v += 8;
}
if (cls.key_dest == key_message)
{
if (chat_team)
{
DrawString (8, v, "say_team:");
skip = 11;
}
else
{
DrawString (8, v, "say:");
skip = 5;
}
s = chat_buffer;
if (chat_bufferlen > (viddef.width>>3)-(skip+1))
s += chat_bufferlen - ((viddef.width>>3)-(skip+1));
x = 0;
while(s[x])
{
re->DrawChar ( (x+skip)<<3, v, s[x]);
x++;
}
re->DrawChar ( (x+skip)<<3, v, 10 + ((int)(cls.realtime* 4.0f)&1));
v += 8;
}
if (v)
{
SCR_AddDirtyPoint (0,0);
SCR_AddDirtyPoint (viddef.width-1, v);
}
}
/*
================
Con_DrawConsole
Draws the console with the solid background
================
*/
void Con_DrawConsole (float frac)
{
int i, j, x, y, n;
int rows;
char *text;
int row;
int lines;
char version[64];
char dlbar[1024];
lines = viddef.height * frac;
if (lines <= 0)
return;
if (lines > viddef.height)
lines = viddef.height;
// draw the background
re->DrawStretchPic (0, -viddef.height+lines, viddef.width, viddef.height, "conback");
SCR_AddDirtyPoint (0,0);
SCR_AddDirtyPoint (viddef.width-1,lines-1);
sprintf (version, "v%4.2f", VERSION);
for (x=0 ; x<5 ; x++)
re->DrawChar (viddef.width-44+x*8, lines-12, 128 + version[x] );
// draw the text
con.vislines = lines;
#if 0
rows = (lines-8)>>3; // rows of text to draw
y = lines - 24;
#else
rows = (lines-22)>>3; // rows of text to draw
y = lines - 30;
#endif
// draw from the bottom up
if (con.display != con.current)
{
// draw arrows to show the buffer is backscrolled
for (x=0 ; x<con.linewidth ; x+=4)
re->DrawChar ( (x+1)<<3, y, '^');
y -= 8;
rows--;
}
row = con.display;
for (i=0 ; i<rows ; i++, y-=8, row--)
{
if (row < 0)
break;
if (con.current - row >= con.totallines)
break; // past scrollback wrap point
text = con.text + (row % con.totallines)*con.linewidth;
for (x=0 ; x<con.linewidth ; x++)
re->DrawChar ( (x+1)<<3, y, text[x]);
}
//ZOID
// draw the download bar
// figure out width
if (cls.download) {
if ((text = strrchr(cls.downloadname, '/')) != NULL)
text++;
else
text = cls.downloadname;
x = con.linewidth - ((con.linewidth * 7) / 40);
y = x - strlen(text) - 8;
i = con.linewidth/3;
if (strlen(text) > i) {
y = x - i - 11;
strncpy(dlbar, text, i);
dlbar[i] = 0;
strcat(dlbar, "...");
} else
strcpy(dlbar, text);
strcat(dlbar, ": ");
i = strlen(dlbar);
dlbar[i++] = '\x80';
// where's the dot go?
if (cls.downloadpercent == 0)
n = 0;
else
n = y * cls.downloadpercent / 100;
for (j = 0; j < y; j++)
if (j == n)
dlbar[i++] = '\x83';
else
dlbar[i++] = '\x81';
dlbar[i++] = '\x82';
dlbar[i] = 0;
sprintf(dlbar + strlen(dlbar), " %02d%%", cls.downloadpercent);
// draw it
y = con.vislines-12;
for (i = 0; i < strlen(dlbar); i++)
re->DrawChar ( (i+1)<<3, y, dlbar[i]);
}
//ZOID
// draw the input prompt, user text, and cursor if desired
Con_DrawInput ();
}

View File

@ -1,69 +0,0 @@
/*
Copyright (C) 1997-2001 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.
*/
#ifndef CONSOLE_H
#define CONSOLE_H
#define NUM_CON_TIMES 4
#define CON_TEXTSIZE MAX_INPUTLINE*32 //512 kb buffer
typedef struct
{
bool initialized;
char text[CON_TEXTSIZE];
int current; // line where next message will be printed
int x; // offset in current line for next print
int display; // bottom of console displays this line
int ormask; // high bit mask for colored characters
int linewidth; // characters across screen
int totallines; // total lines in console scrollback
float cursorspeed;
int vislines;
float times[NUM_CON_TIMES]; // cls.realtime time the line was generated
int width;
int height;
// for transparent notify lines
} console_t;
extern console_t con;
void Con_DrawCharacter (int cx, int line, int num);
void Con_CheckResize (void);
void Con_Init (void);
void Con_DrawConsole (float frac);
void Con_Print (char *txt);
void Con_Printf (char *fmt, ...);
void Con_DPrintf (int level, char *fmt, ...);
void Con_DWarnf (char *fmt, ...);
void Con_CenteredPrint (char *text);
void Con_Clear_f (void);
void Con_DrawNotify (void);
void Con_ClearNotify (void);
void Con_ToggleConsole_f (void);
#endif//CONSOLE_H

View File

@ -22,20 +22,50 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "engine.h"
cvar_t *cvar_vars;
cvar_t *host_cheats;
#define MAX_CVARS 1024
#define FILE_HASH_SIZE 256
int cvar_numIndexes;
int cvar_modifiedFlags;
bool userinfo_modified;
cvar_t cvar_indexes[MAX_CVARS];
static cvar_t* hashTable[FILE_HASH_SIZE];
/*
================
return a hash value for the filename
================
*/
static long Cvar_GetHashValue( const char *fname )
{
int i = 0;
long hash = 0;
char letter;
while (fname[i] != '\0')
{
letter = tolower(fname[i]);
hash += (long)(letter)*(i + 119);
i++;
}
hash &= (FILE_HASH_SIZE - 1);
return hash;
}
/*
============
Cvar_InfoValidate
============
*/
static bool Cvar_InfoValidate (const char *s)
static bool Cvar_ValidateString(const char *s, bool isvalue )
{
if (strstr (s, "\\"))
return false;
if (strstr (s, "\""))
return false;
if (strstr (s, ";"))
if ( !s ) return false;
if (strstr(s, "\\") && !isvalue)
return false;
if (strstr(s, "\"")) return false;
if (strstr(s, ";")) return false;
return true;
}
@ -47,10 +77,15 @@ Cvar_FindVar
cvar_t *Cvar_FindVar (const char *var_name)
{
cvar_t *var;
long hash;
hash = Cvar_GetHashValue(var_name);
for (var = cvar_vars; var; var = var->next)
if (!strcmp (var_name, var->name))
for (var = hashTable[hash]; var; var = var->hash)
{
if (!stricmp(var_name, var->name))
return var;
}
return NULL;
}
@ -60,15 +95,28 @@ cvar_t *Cvar_FindVar (const char *var_name)
Cvar_VariableValue
============
*/
float Cvar_VariableValue (const char *var_name)
float Cvar_VariableValue(const char *var_name)
{
cvar_t *var;
var = Cvar_FindVar (var_name);
if (!var) return 0;
return atof (var->string);
return var->value;
}
/*
============
Cvar_VariableIntegerValue
============
*/
int Cvar_VariableInteger( const char *var_name )
{
cvar_t *var;
var = Cvar_FindVar(var_name);
if (!var) return 0;
return var->integer;
}
/*
============
@ -84,36 +132,35 @@ char *Cvar_VariableString (const char *var_name)
return var->string;
}
/*
============
Cvar_VariableStringBuffer
place variable into buffer
============
*/
void Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize )
{
cvar_t *var;
var = Cvar_FindVar (var_name);
if (!var) *buffer = 0;
else strncpy( buffer, var->string, bufsize );
}
/*
============
Cvar_CompleteVariable
Cvar_CommandCompletion
============
*/
char *Cvar_CompleteVariable (char *partial)
void Cvar_CommandCompletion( void(*callback)(const char *s, const char *m))
{
cvar_t *cvar;
int len;
len = strlen(partial);
if (!len)
return NULL;
// check exact match
for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
if (!strcmp (partial,cvar->name))
return cvar->name;
// check partial match
for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
if (!strncmp (partial,cvar->name, len))
return cvar->name;
return NULL;
for( cvar = cvar_vars; cvar; cvar = cvar->next )
callback( cvar->name, cvar->description );
}
/*
============
Cvar_Get
@ -122,43 +169,86 @@ If the variable already exists, the value will not be set
The flags will be or'ed in if the variable exists.
============
*/
cvar_t *Cvar_Get (const char *var_name, const char *var_value, int flags)
cvar_t *_Cvar_Get(const char *var_name, const char *var_value, int flags, const char *var_desc )
{
cvar_t *var;
if (flags & (CVAR_USERINFO | CVAR_SERVERINFO))
long hash;
if(!var_name || !var_value)
{
if (!Cvar_InfoValidate (var_name))
{
Msg("invalid info cvar name\n");
return NULL;
}
MsgDev( D_ERROR, "Cvar_Get: NULL parameter" );
return NULL;
}
if (!Cvar_ValidateString(var_name, false))
{
MsgDev(D_WARN, "invalid info cvar name string %s\n", var_name );
var_value = "noname";
}
if(!Cvar_ValidateString( var_value, true ))
{
MsgDev(D_WARN, "invalid cvar value string: %s\n", var_value );
var_value = "default";
}
var = Cvar_FindVar (var_name);
if (var)
if ( var )
{
// if the C code is now specifying a variable that the user already
// set a value for, take the new value as the reset value
if(( var->flags & CVAR_USER_CREATED ) && !( flags & CVAR_USER_CREATED ) && var_value[0])
{
var->flags &= ~CVAR_USER_CREATED;
Z_Free( var->reset_string );
var->reset_string = CopyString( var_value );
cvar_modifiedFlags |= flags;
}
var->flags |= flags;
// only allow one non-empty reset string without a warning
if( !var->reset_string[0] )
{
// we don't have a reset string yet
Z_Free( var->reset_string );
var->reset_string = CopyString( var_value );
}
else if ( var_value[0] && strcmp( var->reset_string, var_value ))
{
MsgDev(D_WARN, "cvar \"%s\" given initial values: \"%s\" and \"%s\"\n", var_name, var->reset_string, var_value );
}
// if we have a latched string, take that value now
if ( var->latched_string )
{
char *s;
s = var->latched_string;
var->latched_string = NULL; // otherwise cvar_set2 would free it
Cvar_Set2( var_name, s, true );
Z_Free( s );
}
return var;
}
if (!var_value)
return NULL;
if (flags & (CVAR_USERINFO | CVAR_SERVERINFO))
// allocate a new cvar
if( cvar_numIndexes >= MAX_CVARS )
{
if (!Cvar_InfoValidate (var_value))
{
Msg("invalid info cvar value\n");
return NULL;
}
MsgWarn("Cvar_Get: MAX_CVARS limit exceeded\n" );
return NULL;
}
var = Z_Malloc (sizeof(*var));
var->name = CopyString (var_name);
var->string = CopyString (var_value);
var = &cvar_indexes[cvar_numIndexes];
cvar_numIndexes++;
var->name = CopyString(var_name);
var->string = CopyString(var_value);
var->description = CopyString(var_desc);
var->modified = true;
var->value = atof (var->string);
var->modificationCount = 1;
var->value = atof(var->string);
var->integer = atoi(var->string);
var->reset_string = CopyString( var_value );
// link the variable in
var->next = cvar_vars;
@ -166,6 +256,10 @@ cvar_t *Cvar_Get (const char *var_name, const char *var_value, int flags)
var->flags = flags;
hash = Cvar_GetHashValue(var_name);
var->hash = hashTable[hash];
hashTable[hash] = var;
return var;
}
@ -178,50 +272,68 @@ cvar_t *Cvar_Set2 (const char *var_name, const char *value, bool force)
{
cvar_t *var;
var = Cvar_FindVar (var_name);
if (!var) return Cvar_Get (var_name, value, 0); // create it
if (var->flags & (CVAR_USERINFO | CVAR_SERVERINFO))
if( !Cvar_ValidateString( var_name, false ))
{
if (!Cvar_InfoValidate (value))
{
Msg("invalid info cvar value\n");
return var;
}
MsgDev(D_WARN, "invalid cvar name string: %s\n", var_name );
var_name = "unknown";
}
if ( value && !Cvar_ValidateString( value, true ))
{
MsgDev(D_WARN, "invalid cvar value string: %s\n", value );
value = "default";
}
var = Cvar_FindVar (var_name);
if (!var)
{
if( !value ) return NULL;
// create it
if ( !force ) return Cvar_Get( var_name, value, CVAR_USER_CREATED );
else return Cvar_Get (var_name, value, 0 );
}
if(!value ) value = var->reset_string;
if(!strcmp(value, var->string)) return var;
// note what types of cvars have been modified (userinfo, archive, serverinfo, systeminfo)
cvar_modifiedFlags |= var->flags;
if (!force)
{
if (var->flags & CVAR_NOSET)
if (var->flags & CVAR_READ_ONLY)
{
Msg ("%s is write protected.\n", var_name);
MsgDev(D_INFO, "%s is read only.\n", var_name);
return var;
}
if (var->flags & CVAR_INIT)
{
MsgDev(D_INFO, "%s is write protected.\n", var_name);
return var;
}
if (var->flags & CVAR_LATCH)
{
if (var->latched_string)
{
if (strcmp(value, var->latched_string) == 0)
if (!strcmp(value, var->latched_string))
return var;
Z_Free (var->latched_string);
}
else
{
if (strcmp(value, var->string) == 0)
if (!strcmp(value, var->string))
return var;
}
if (Com_ServerState())
{
Msg ("%s will be changed for next game.\n", var_name);
var->latched_string = CopyString(value);
}
else
{
var->string = CopyString(value);
var->value = atof (var->string);
}
MsgDev(D_INFO, "%s will be changed after restarting.\n", var_name);
var->latched_string = CopyString(value);
var->modified = true;
var->modificationCount++;
return var;
}
if ( (var->flags & CVAR_CHEAT) && !host_cheats->integer )
{
MsgDev(D_INFO, "%s is cheat protected.\n", var_name);
return var;
}
}
@ -229,45 +341,44 @@ cvar_t *Cvar_Set2 (const char *var_name, const char *value, bool force)
{
if (var->latched_string)
{
Z_Free (var->latched_string);
Z_Free(var->latched_string);
var->latched_string = NULL;
}
}
if (!strcmp(value, var->string))
return var; // not changed
return var; // not changed
var->modified = true;
// transmit at next oportunity
if (var->flags & CVAR_USERINFO) userinfo_modified = true;
var->modificationCount++;
Z_Free (var->string); // free the old value string
var->string = CopyString(value);
var->value = atof(var->string);
var->value = atof (var->string);
var->integer = atoi (var->string);
return var;
}
/*
============
Cvar_ForceSet
============
*/
cvar_t *Cvar_ForceSet (const char *var_name, const char *value)
{
return Cvar_Set2 (var_name, value, true);
}
/*
============
Cvar_Set
============
*/
cvar_t *Cvar_Set (const char *var_name, const char *value)
void Cvar_Set( const char *var_name, const char *value)
{
return Cvar_Set2 (var_name, value, false);
Cvar_Set2 (var_name, value, true);
}
/*
============
Cvar_SetLatched
============
*/
void Cvar_SetLatched( const char *var_name, const char *value)
{
Cvar_Set2 (var_name, value, false);
}
/*
@ -275,28 +386,28 @@ cvar_t *Cvar_Set (const char *var_name, const char *value)
Cvar_FullSet
============
*/
cvar_t *Cvar_FullSet (char *var_name, char *value, int flags)
void Cvar_FullSet (char *var_name, char *value, int flags)
{
cvar_t *var;
var = Cvar_FindVar (var_name);
if (!var)
{ // create it
return Cvar_Get (var_name, value, flags);
if (!var)
{
// create it
Cvar_Get (var_name, value, flags);
return;
}
var->modified = true;
if (var->flags & CVAR_USERINFO)
userinfo_modified = true; // transmit at next oportunity
userinfo_modified = true; // transmit at next oportunity
Z_Free (var->string); // free the old value string
Z_Free (var->string); // free the old value string
var->string = CopyString(value);
var->value = atof (var->string);
var->value = atof(var->string);
var->integer = atoi(var->string);
var->flags = flags;
return var;
}
/*
@ -304,37 +415,53 @@ cvar_t *Cvar_FullSet (char *var_name, char *value, int flags)
Cvar_SetValue
============
*/
void Cvar_SetValue (char *var_name, float value)
void Cvar_SetValue( const char *var_name, float value)
{
char val[32];
if (value == (int)value)
sprintf (val, "%i",(int)value);
else
sprintf (val, "%f",value);
if( value == (int)value ) sprintf (val, "%i", (int)value);
else sprintf (val, "%f", value);
Cvar_Set (var_name, val);
}
/*
============
Cvar_Reset
============
*/
void Cvar_Reset( const char *var_name )
{
Cvar_Set2( var_name, NULL, false );
}
/*
============
Cvar_GetLatchedVars
Cvar_SetCheatState
Any variables with latched values will now be updated
Any testing variables will be reset to the safe values
============
*/
void Cvar_GetLatchedVars (void)
void Cvar_SetCheatState( void )
{
cvar_t *var;
for (var = cvar_vars ; var ; var = var->next)
// set all default vars to the safe value
for ( var = cvar_vars ; var ; var = var->next )
{
if (!var->latched_string)
continue;
Z_Free (var->string);
var->string = var->latched_string;
var->latched_string = NULL;
var->value = atof(var->string);
if( var->flags & CVAR_CHEAT )
{
// the CVAR_LATCHED|CVAR_CHEAT vars might escape the reset here
// because of a different var->latched_string
if (var->latched_string)
{
Z_Free(var->latched_string);
var->latched_string = NULL;
}
if (strcmp(var->reset_string, var->string))
{
Cvar_Set( var->name, var->reset_string );
}
}
}
}
@ -345,59 +472,168 @@ Cvar_Command
Handles variable inspection and changing from the console
============
*/
bool Cvar_Command (void)
bool Cvar_Command( void )
{
cvar_t *v;
// check variables
v = Cvar_FindVar (Cmd_Argv(0));
if (!v) return false;
// perform a variable print or set
if (Cmd_Argc() == 1)
if ( Cmd_Argc() == 1 )
{
Msg ("\"%s\" is \"%s\"\n", v->name, v->string);
Msg("\"%s\" is:\"%s" "\" default:\"%s" "\"\n", v->name, v->string, v->reset_string );
if ( v->latched_string ) Msg( "latched: \"%s\"\n", v->latched_string );
return true;
}
Cvar_Set (v->name, Cmd_Argv(1));
// set the value if forcing isn't required
Cvar_Set2 (v->name, Cmd_Argv(1), false);
return true;
}
/*
============
Cvar_Toggle_f
Toggles a cvar for easy single key binding
============
*/
void Cvar_Toggle_f( void )
{
int v;
if( Cmd_Argc() != 2 )
{
Msg("usage: toggle <variable>\n");
return;
}
v = Cvar_VariableValue( Cmd_Argv( 1 ));
v = !v;
Cvar_Set2 (Cmd_Argv(1), va("%i", v), false);
}
/*
============
Cvar_Set_f
Allows setting and defining of arbitrary cvars from console
Allows setting and defining of arbitrary cvars from console, even if they
weren't declared in C code.
============
*/
void Cvar_Set_f (void)
void Cvar_Set_f( void )
{
int c;
int flags;
int i, c, l = 0, len;
char combined[MAX_STRING_TOKENS];
c = Cmd_Argc();
if (c != 3 && c != 4)
if ( c < 3 )
{
Msg ("usage: set <variable> <value> [u / s]\n");
Msg("usage: set <variable> <value>\n");
return;
}
if (c == 4)
combined[0] = 0;
for ( i = 2; i < c; i++ )
{
if (!strcmp(Cmd_Argv(3), "u")) flags = CVAR_USERINFO;
else if (!strcmp(Cmd_Argv(3), "s")) flags = CVAR_SERVERINFO;
else
{
Msg ("flags can only be 'u' or 's'\n");
return;
}
Cvar_FullSet (Cmd_Argv(1), Cmd_Argv(2), flags);
len = strlen( Cmd_Argv(i) + 1 );
if ( l + len >= MAX_STRING_TOKENS - 2 )
break;
strcat( combined, Cmd_Argv(i));
if ( i != c-1 ) strcat( combined, " " );
l += len;
}
else Cvar_Set (Cmd_Argv(1), Cmd_Argv(2));
Cvar_Set2 (Cmd_Argv(1), combined, false);
}
/*
============
Cvar_SetU_f
As Cvar_Set, but also flags it as userinfo
============
*/
void Cvar_SetU_f( void )
{
cvar_t *v;
if ( Cmd_Argc() != 3 )
{
Msg("usage: setu <variable> <value>\n");
return;
}
Cvar_Set_f();
v = Cvar_FindVar( Cmd_Argv(1));
if( !v ) return;
v->flags |= CVAR_USERINFO;
}
/*
============
Cvar_SetS_f
As Cvar_Set, but also flags it as userinfo
============
*/
void Cvar_SetS_f( void )
{
cvar_t *v;
if ( Cmd_Argc() != 3 )
{
Msg("usage: sets <variable> <value>\n");
return;
}
Cvar_Set_f();
v = Cvar_FindVar( Cmd_Argv(1));
if ( !v ) return;
v->flags |= CVAR_SERVERINFO;
}
/*
============
Cvar_SetA_f
As Cvar_Set, but also flags it as archived
============
*/
void Cvar_SetA_f( void )
{
cvar_t *v;
if ( Cmd_Argc() != 3 )
{
Msg("usage: seta <variable> <value>\n");
return;
}
Cvar_Set_f();
v = Cvar_FindVar( Cmd_Argv( 1 ) );
if ( !v ) return;
v->flags |= CVAR_ARCHIVE;
}
/*
============
Cvar_Reset_f
============
*/
void Cvar_Reset_f( void )
{
if ( Cmd_Argc() != 2 )
{
Msg("usage: reset <variable>\n");
return;
}
Cvar_Reset( Cmd_Argv( 1 ));
}
/*
============
@ -407,64 +643,115 @@ Appends lines containing "set variable value" for all variables
with the archive flag set to true.
============
*/
void Cvar_WriteVariables (char *path)
void Cvar_WriteVariables( file_t *f )
{
cvar_t *var;
char buffer[1024];
file_t *f;
f = FS_Open (path, "a");
for (var = cvar_vars ; var ; var = var->next)
for(var = cvar_vars; var; var = var->next)
{
if (var->flags & CVAR_ARCHIVE)
if( var->flags & CVAR_ARCHIVE )
{
sprintf (buffer, "set %s \"%s\"\n", var->name, var->string);
FS_Printf(f, "%s", buffer);
// write the latched value, even if it hasn't taken effect yet
if (!var->latched_string ) sprintf(buffer, "seta %s \"%s\"\n", var->name, var->string);
else sprintf(buffer, "seta %s \"%s\"\n", var->name, var->latched_string);
FS_Printf (f, "%s", buffer);
}
}
FS_Close (f);
}
/*
============
Cvar_List_f
============
*/
void Cvar_List_f (void)
void Cvar_List_f( void )
{
cvar_t *var;
int i;
char *match;
int i = 0;
i = 0;
for (var = cvar_vars ; var ; var = var->next, i++)
if ( Cmd_Argc() > 1 ) match = Cmd_Argv(1);
else match = NULL;
for (var = cvar_vars; var; var = var->next, i++)
{
if (var->flags & CVAR_ARCHIVE)
Msg ("*");
else
Msg (" ");
if (var->flags & CVAR_USERINFO)
Msg ("U");
else
Msg (" ");
if (var->flags & CVAR_SERVERINFO)
Msg ("S");
else
Msg (" ");
if (var->flags & CVAR_NOSET)
Msg ("-");
else if (var->flags & CVAR_LATCH)
Msg ("L");
else
Msg (" ");
if (match && !COM_Filter(match, var->name, false))
continue;
if (var->flags & CVAR_SERVERINFO) Msg("S");
else Msg(" ");
if (var->flags & CVAR_USERINFO) Msg("U");
else Msg(" ");
if (var->flags & CVAR_READ_ONLY) Msg("R");
else Msg(" ");
if (var->flags & CVAR_INIT) Msg("I");
else Msg(" ");
if (var->flags & CVAR_ARCHIVE) Msg("A");
else Msg(" ");
if (var->flags & CVAR_LATCH) Msg("L");
else Msg(" ");
if (var->flags & CVAR_CHEAT) Msg("C");
else Msg(" ");
Msg (" %s \"%s\"\n", var->name, var->string);
}
Msg ("%i cvars\n", i);
Msg ("\n%i total cvars\n", i);
Msg ("%i cvar indexes\n", cvar_numIndexes);
}
/*
============
Cvar_Restart_f
bool userinfo_modified;
Resets all cvars to their hardcoded values
============
*/
void Cvar_Restart_f( void )
{
cvar_t *var;
cvar_t **prev;
prev = &cvar_vars;
while ( 1 )
{
var = *prev;
if ( !var ) break;
// don't mess with rom values, or some inter-module
// communication will get broken (com_cl_running, etc)
if ( var->flags & ( CVAR_READ_ONLY | CVAR_INIT ))
{
prev = &var->next;
continue;
}
// throw out any variables the user created
if ( var->flags & CVAR_USER_CREATED )
{
*prev = var->next;
if( var->name ) Z_Free( var->name );
if ( var->string ) Z_Free( var->string );
if ( var->latched_string ) Z_Free( var->latched_string );
if ( var->reset_string ) Z_Free( var->reset_string );
if ( var->description ) Z_Free( var->description );
// clear the var completely, since we
// can't remove the index from the list
memset( var, 0, sizeof( var ));
continue;
}
Cvar_Set( var->name, var->reset_string );
prev = &var->next;
}
}
char *Cvar_BitInfo (int bit)
{
@ -502,7 +789,15 @@ Reads in all archived cvars
*/
void Cvar_Init (void)
{
host_cheats = Cvar_Get("host_cheats", "1", CVAR_READ_ONLY | CVAR_SYSTEMINFO );
Cmd_AddCommand ("toggle", Cvar_Toggle_f);
Cmd_AddCommand ("set", Cvar_Set_f);
Cmd_AddCommand ("sets", Cvar_SetS_f);
Cmd_AddCommand ("setu", Cvar_SetU_f);
Cmd_AddCommand ("seta", Cvar_SetA_f);
Cmd_AddCommand ("reset", Cvar_Reset_f);
Cmd_AddCommand ("cvarlist", Cvar_List_f);
Cmd_AddCommand ("cvar_restart", Cvar_Restart_f);
}

View File

@ -5,57 +5,23 @@
#ifndef CVAR_H
#define CVAR_H
extern cvar_t *cvar_vars;
extern cvar_t *cvar_vars;
cvar_t *Cvar_FindVar (const char *var_name);
cvar_t *Cvar_Get (const char *var_name, const char *value, int flags);
// creates the variable if it doesn't exist, or returns the existing one
// if it exists, the value will not be changed, but flags will be ORed in
// that allows variables to be unarchived without needing bitflags
cvar_t *Cvar_Set (const char *var_name, const char *value);
// will create the variable if it doesn't exist
cvar_t *Cvar_ForceSet (const char *var_name, const char *value);
// will set the variable even if NOSET or LATCH
cvar_t *Cvar_FullSet (char *var_name, char *value, int flags);
void Cvar_SetValue (char *var_name, float value);
// expands value to a string and calls Cvar_Set
float Cvar_VariableValue (const char *var_name);
// returns 0 if not defined or non numeric
char *Cvar_VariableString (const char *var_name);
// returns an empty string if not defined
char *Cvar_CompleteVariable (char *partial);
// attempts to match a partial variable name for command line completion
// returns NULL if nothing fits
void Cvar_GetLatchedVars (void);
// any CVAR_LATCHED variables that have been set will now take effect
#define Cvar_Get(name, value, flags) _Cvar_Get( name, value, flags, "no description" )
cvar_t *_Cvar_Get (const char *var_name, const char *value, int flags, const char *description);
void Cvar_Set( const char *var_name, const char *value);
cvar_t *Cvar_Set2 (const char *var_name, const char *value, bool force);
void Cvar_CommandCompletion( void(*callback)(const char *s, const char *m));
void Cvar_FullSet (char *var_name, char *value, int flags);
void Cvar_SetLatched( const char *var_name, const char *value);
void Cvar_SetValue( const char *var_name, float value);
float Cvar_VariableValue (const char *var_name);
char *Cvar_VariableString (const char *var_name);
bool Cvar_Command (void);
// called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
// command. Returns true if the command was a variable reference that
// was handled. (print or change)
void Cvar_WriteVariables (char *path);
// appends lines containing "set variable value" for all variables
// with the archive flag set to true.
void Cvar_Init (void);
char *Cvar_Userinfo (void);
// returns an info string containing all the CVAR_USERINFO cvars
char *Cvar_Serverinfo (void);
// returns an info string containing all the CVAR_SERVERINFO cvars
extern bool userinfo_modified;
// this is set each time a CVAR_USERINFO variable is changed
// so that the client knows to send it to the server
void Cvar_WriteVariables( file_t *f );
void Cvar_Init (void);
char *Cvar_Userinfo (void);
char *Cvar_Serverinfo (void);
extern bool userinfo_modified;
#endif//CVAR_H

View File

@ -1,930 +0,0 @@
/*
Copyright (C) 1997-2001 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.
*/
#include "client.h"
/*
key up events are sent even if in console mode
*/
#define MAXCMDLINE 256
char key_lines[32][MAXCMDLINE];
int key_linepos;
int shift_down=false;
int anykeydown;
int edit_line=0;
int history_line=0;
int key_waiting;
char *keybindings[256];
bool consolekeys[256]; // if true, can't be rebound while in console
bool menubound[256]; // if true, can't be rebound while in menu
int keyshift[256]; // key to map to if shift held down in console
int key_repeats[256]; // if > 1, it is autorepeating
bool keydown[256];
typedef struct
{
char *name;
int keynum;
} keyname_t;
keyname_t keynames[] =
{
{"TAB", K_TAB},
{"ENTER", K_ENTER},
{"ESCAPE", K_ESCAPE},
{"SPACE", K_SPACE},
{"BACKSPACE", K_BACKSPACE},
{"UPARROW", K_UPARROW},
{"DOWNARROW", K_DOWNARROW},
{"LEFTARROW", K_LEFTARROW},
{"RIGHTARROW", K_RIGHTARROW},
{"ALT", K_ALT},
{"CTRL", K_CTRL},
{"SHIFT", K_SHIFT},
{"F1", K_F1},
{"F2", K_F2},
{"F3", K_F3},
{"F4", K_F4},
{"F5", K_F5},
{"F6", K_F6},
{"F7", K_F7},
{"F8", K_F8},
{"F9", K_F9},
{"F10", K_F10},
{"F11", K_F11},
{"F12", K_F12},
{"INS", K_INS},
{"DEL", K_DEL},
{"PGDN", K_PGDN},
{"PGUP", K_PGUP},
{"HOME", K_HOME},
{"END", K_END},
{"MOUSE1", K_MOUSE1},
{"MOUSE2", K_MOUSE2},
{"MOUSE3", K_MOUSE3},
{"JOY1", K_JOY1},
{"JOY2", K_JOY2},
{"JOY3", K_JOY3},
{"JOY4", K_JOY4},
{"AUX1", K_AUX1},
{"AUX2", K_AUX2},
{"AUX3", K_AUX3},
{"AUX4", K_AUX4},
{"AUX5", K_AUX5},
{"AUX6", K_AUX6},
{"AUX7", K_AUX7},
{"AUX8", K_AUX8},
{"AUX9", K_AUX9},
{"AUX10", K_AUX10},
{"AUX11", K_AUX11},
{"AUX12", K_AUX12},
{"AUX13", K_AUX13},
{"AUX14", K_AUX14},
{"AUX15", K_AUX15},
{"AUX16", K_AUX16},
{"AUX17", K_AUX17},
{"AUX18", K_AUX18},
{"AUX19", K_AUX19},
{"AUX20", K_AUX20},
{"AUX21", K_AUX21},
{"AUX22", K_AUX22},
{"AUX23", K_AUX23},
{"AUX24", K_AUX24},
{"AUX25", K_AUX25},
{"AUX26", K_AUX26},
{"AUX27", K_AUX27},
{"AUX28", K_AUX28},
{"AUX29", K_AUX29},
{"AUX30", K_AUX30},
{"AUX31", K_AUX31},
{"AUX32", K_AUX32},
{"KP_HOME", K_KP_HOME },
{"KP_UPARROW", K_KP_UPARROW },
{"KP_PGUP", K_KP_PGUP },
{"KP_LEFTARROW", K_KP_LEFTARROW },
{"KP_5", K_KP_5 },
{"KP_RIGHTARROW", K_KP_RIGHTARROW },
{"KP_END", K_KP_END },
{"KP_DOWNARROW", K_KP_DOWNARROW },
{"KP_PGDN", K_KP_PGDN },
{"KP_ENTER", K_KP_ENTER },
{"KP_INS", K_KP_INS },
{"KP_DEL", K_KP_DEL },
{"KP_SLASH", K_KP_SLASH },
{"KP_MINUS", K_KP_MINUS },
{"KP_PLUS", K_KP_PLUS },
{"MWHEELUP", K_MWHEELUP },
{"MWHEELDOWN", K_MWHEELDOWN },
{"PAUSE", K_PAUSE},
{"SEMICOLON", ';'}, // because a raw semicolon seperates commands
{NULL,0}
};
/*
==============================================================================
LINE TYPING INTO THE CONSOLE
==============================================================================
*/
void CompleteCommand (void)
{
char *cmd, *s;
s = key_lines[edit_line]+1;
if (*s == '\\' || *s == '/')
s++;
cmd = Cmd_CompleteCommand (s);
if (!cmd)
cmd = Cvar_CompleteVariable (s);
if (cmd)
{
key_lines[edit_line][1] = '/';
strcpy (key_lines[edit_line]+2, cmd);
key_linepos = strlen(cmd)+2;
key_lines[edit_line][key_linepos] = ' ';
key_linepos++;
key_lines[edit_line][key_linepos] = 0;
return;
}
}
/*
====================
Key_Console
Interactive line editing and console scrollback
====================
*/
void Key_Console (int key)
{
switch ( key )
{
case K_KP_SLASH:
key = '/';
break;
case K_KP_MINUS:
key = '-';
break;
case K_KP_PLUS:
key = '+';
break;
case K_KP_HOME:
key = '7';
break;
case K_KP_UPARROW:
key = '8';
break;
case K_KP_PGUP:
key = '9';
break;
case K_KP_LEFTARROW:
key = '4';
break;
case K_KP_5:
key = '5';
break;
case K_KP_RIGHTARROW:
key = '6';
break;
case K_KP_END:
key = '1';
break;
case K_KP_DOWNARROW:
key = '2';
break;
case K_KP_PGDN:
key = '3';
break;
case K_KP_INS:
key = '0';
break;
case K_KP_DEL:
key = '.';
break;
}
if (( toupper( key ) == 'V' && keydown[K_CTRL]) || ((( key == K_INS ) || ( key == K_KP_INS )) && keydown[K_SHIFT] ))
{
char *cbd;
if (( cbd = Sys_GetClipboardData()) != 0 )
{
int i;
strtok( cbd, "\n\r\b" );
i = strlen( cbd );
if ( i + key_linepos >= MAXCMDLINE)
i= MAXCMDLINE - key_linepos;
if ( i > 0 )
{
cbd[i]=0;
strcat( key_lines[edit_line], cbd );
key_linepos += i;
}
Z_Free( cbd );
}
return;
}
if ( key == 'l' )
{
if ( keydown[K_CTRL] )
{
Cbuf_AddText ("clear\n");
return;
}
}
if ( key == K_ENTER || key == K_KP_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
Cbuf_AddText (key_lines[edit_line]+1); // valid command
Cbuf_AddText ("\n");
Msg ("%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 ) || ( key == K_KP_LEFTARROW ) || ( ( key == 'h' ) && ( keydown[K_CTRL] ) ) )
{
if (key_linepos > 1)
key_linepos--;
return;
}
if ( ( key == K_UPARROW ) || ( key == K_KP_UPARROW ) ||
( ( key == 'p' ) && keydown[K_CTRL] ) )
{
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 ) || ( key == K_KP_DOWNARROW ) ||
( ( key == 'n' ) && keydown[K_CTRL] ) )
{
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_linepos = 1;
}
else
{
strcpy(key_lines[edit_line], key_lines[history_line]);
key_linepos = strlen(key_lines[edit_line]);
}
return;
}
if (key == K_PGUP || key == K_KP_PGUP )
{
con.display -= 2;
return;
}
if (key == K_PGDN || key == K_KP_PGDN )
{
con.display += 2;
if (con.display > con.current)
con.display = con.current;
return;
}
if (key == K_HOME || key == K_KP_HOME )
{
con.display = con.current - con.totallines + 10;
return;
}
if (key == K_END || key == K_KP_END )
{
con.display = con.current;
return;
}
if (key < 32 || key > 127)
return; // non printable
if (key_linepos < MAXCMDLINE-1)
{
key_lines[edit_line][key_linepos] = key;
key_linepos++;
key_lines[edit_line][key_linepos] = 0;
}
}
//============================================================================
bool chat_team;
char chat_buffer[MAXCMDLINE];
int chat_bufferlen = 0;
void Key_Message (int key)
{
if ( key == K_ENTER || key == K_KP_ENTER )
{
if (chat_team)
Cbuf_AddText ("say_team \"");
else
Cbuf_AddText ("say \"");
Cbuf_AddText(chat_buffer);
Cbuf_AddText("\"\n");
cls.key_dest = key_game;
chat_bufferlen = 0;
chat_buffer[0] = 0;
return;
}
if (key == K_ESCAPE)
{
cls.key_dest = key_game;
chat_bufferlen = 0;
chat_buffer[0] = 0;
return;
}
if (key < 32 || key > 127)
return; // non printable
if (key == K_BACKSPACE)
{
if (chat_bufferlen)
{
chat_bufferlen--;
chat_buffer[chat_bufferlen] = 0;
}
return;
}
if (chat_bufferlen == sizeof(chat_buffer)-1)
return; // all full
chat_buffer[chat_bufferlen++] = key;
chat_buffer[chat_bufferlen] = 0;
}
//============================================================================
/*
===================
Key_StringToKeynum
Returns a key number to be used to index keybindings[] by looking at
the given string. Single ascii characters return themselves, while
the K_* names are matched up.
===================
*/
int Key_StringToKeynum (char *str)
{
keyname_t *kn;
if (!str || !str[0])
return -1;
if (!str[1])
return str[0];
for (kn = keynames; kn->name; kn++)
{
if (!strcasecmp(str, kn->name))
return kn->keynum;
}
return -1;
}
/*
===================
Key_KeynumToString
Returns a string (either a single ascii char, or a K_* name) for the
given keynum.
FIXME: handle quote special (general escape sequence?)
===================
*/
char *Key_KeynumToString (int keynum)
{
keyname_t *kn;
static char tinystr[2];
if (keynum == -1)
return "<KEY NOT FOUND>";
if (keynum > 32 && keynum < 127)
{ // printable ascii
tinystr[0] = keynum;
tinystr[1] = 0;
return tinystr;
}
for (kn=keynames ; kn->name ; kn++)
if (keynum == kn->keynum)
return kn->name;
return "<UNKNOWN KEYNUM>";
}
/*
===================
Key_SetBinding
===================
*/
void Key_SetBinding (int keynum, char *binding)
{
char *new;
int l;
if (keynum == -1)
return;
// free old bindings
if (keybindings[keynum])
{
Z_Free (keybindings[keynum]);
keybindings[keynum] = NULL;
}
// allocate memory for new binding
l = strlen (binding);
new = Z_Malloc (l+1);
strcpy (new, binding);
new[l] = 0;
keybindings[keynum] = new;
}
/*
===================
Key_Unbind_f
===================
*/
void Key_Unbind_f (void)
{
int b;
if (Cmd_Argc() != 2)
{
Msg ("unbind <key> : remove commands from a key\n");
return;
}
b = Key_StringToKeynum (Cmd_Argv(1));
if (b==-1)
{
Msg ("\"%s\" isn't a valid key\n", Cmd_Argv(1));
return;
}
Key_SetBinding (b, "");
}
void Key_Unbindall_f (void)
{
int i;
for (i=0 ; i<256 ; i++)
if (keybindings[i])
Key_SetBinding (i, "");
}
/*
===================
Key_Bind_f
===================
*/
void Key_Bind_f (void)
{
int i, c, b;
char cmd[1024];
c = Cmd_Argc();
if (c < 2)
{
Msg ("bind <key> [command] : attach a command to a key\n");
return;
}
b = Key_StringToKeynum (Cmd_Argv(1));
if (b==-1)
{
Msg ("\"%s\" isn't a valid key\n", Cmd_Argv(1));
return;
}
if (c == 2)
{
if (keybindings[b])
Msg ("\"%s\" = \"%s\"\n", Cmd_Argv(1), keybindings[b] );
else
Msg ("\"%s\" is not bound\n", Cmd_Argv(1) );
return;
}
// copy the rest of the command line
cmd[0] = 0; // start out with a null string
for (i=2 ; i< c ; i++)
{
strcat (cmd, Cmd_Argv(i));
if (i != (c-1))
strcat (cmd, " ");
}
Key_SetBinding (b, cmd);
}
/*
============
Key_WriteBindings
Writes lines containing "bind key value"
============
*/
void Key_WriteBindings (file_t *f)
{
int i;
for (i=0 ; i<256 ; i++)
if (keybindings[i] && keybindings[i][0])
FS_Printf (f, "bind %s \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
}
/*
============
Key_Bindlist_f
============
*/
void Key_Bindlist_f (void)
{
int i;
for (i=0 ; i<256 ; i++)
if (keybindings[i] && keybindings[i][0])
Msg ("%s \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
}
/*
===================
Key_Init
===================
*/
void Key_Init (void)
{
int i;
for (i=0 ; i<32 ; i++)
{
key_lines[i][0] = ']';
key_lines[i][1] = 0;
}
key_linepos = 1;
//
// init ascii characters in console mode
//
for (i=32 ; i<128 ; i++)
consolekeys[i] = true;
consolekeys[K_ENTER] = true;
consolekeys[K_KP_ENTER] = true;
consolekeys[K_TAB] = true;
consolekeys[K_LEFTARROW] = true;
consolekeys[K_KP_LEFTARROW] = true;
consolekeys[K_RIGHTARROW] = true;
consolekeys[K_KP_RIGHTARROW] = true;
consolekeys[K_UPARROW] = true;
consolekeys[K_KP_UPARROW] = true;
consolekeys[K_DOWNARROW] = true;
consolekeys[K_KP_DOWNARROW] = true;
consolekeys[K_BACKSPACE] = true;
consolekeys[K_HOME] = true;
consolekeys[K_KP_HOME] = true;
consolekeys[K_END] = true;
consolekeys[K_KP_END] = true;
consolekeys[K_PGUP] = true;
consolekeys[K_KP_PGUP] = true;
consolekeys[K_PGDN] = true;
consolekeys[K_KP_PGDN] = true;
consolekeys[K_SHIFT] = true;
consolekeys[K_INS] = true;
consolekeys[K_KP_INS] = true;
consolekeys[K_KP_DEL] = true;
consolekeys[K_KP_SLASH] = true;
consolekeys[K_KP_PLUS] = true;
consolekeys[K_KP_MINUS] = true;
consolekeys[K_KP_5] = true;
consolekeys['`'] = false;
consolekeys['~'] = false;
for (i=0 ; i<256 ; i++)
keyshift[i] = i;
for (i='a' ; i<='z' ; i++)
keyshift[i] = i - 'a' + 'A';
keyshift['1'] = '!';
keyshift['2'] = '@';
keyshift['3'] = '#';
keyshift['4'] = '$';
keyshift['5'] = '%';
keyshift['6'] = '^';
keyshift['7'] = '&';
keyshift['8'] = '*';
keyshift['9'] = '(';
keyshift['0'] = ')';
keyshift['-'] = '_';
keyshift['='] = '+';
keyshift[','] = '<';
keyshift['.'] = '>';
keyshift['/'] = '?';
keyshift[';'] = ':';
keyshift['\''] = '"';
keyshift['['] = '{';
keyshift[']'] = '}';
keyshift['`'] = '~';
keyshift['\\'] = '|';
menubound[K_ESCAPE] = true;
for (i=0 ; i<12 ; i++)
menubound[K_F1+i] = true;
//
// register our functions
//
Cmd_AddCommand ("bind",Key_Bind_f);
Cmd_AddCommand ("unbind",Key_Unbind_f);
Cmd_AddCommand ("unbindall",Key_Unbindall_f);
Cmd_AddCommand ("bindlist",Key_Bindlist_f);
}
/*
===================
Key_Event
Called by the system between frames for both key up and key down events
Should NOT be called during an interrupt!
===================
*/
void Key_Event (int key, bool down, unsigned time)
{
char *kb;
char cmd[1024];
// hack for modal presses
if (key_waiting == -1)
{
if (down)
key_waiting = key;
return;
}
// update auto-repeat status
if (down)
{
key_repeats[key]++;
if (key != K_BACKSPACE && key != K_PAUSE && key != K_PGUP && key != K_KP_PGUP && key != K_PGDN && key != K_KP_PGDN && key_repeats[key] > 1)
return; // ignore most autorepeats
if (key >= 200 && !keybindings[key])
Msg ("%s is unbound, hit F4 to set.\n", Key_KeynumToString (key) );
}
else
{
key_repeats[key] = 0;
}
if (key == K_SHIFT)
shift_down = down;
// console key is hardcoded, so the user can never unbind it
if (key == '`' || key == '~')
{
if (!down) return;
Con_ToggleConsole_f();
return;
}
// any key during the attract mode will bring up the menu
if (cl.attractloop && cls.key_dest != key_menu && !(key >= K_F1 && key <= K_F12))
key = K_ESCAPE;
// menu key is hardcoded, so the user can never unbind it
if (key == K_ESCAPE)
{
if (!down) return;
if (cl.frame.playerstate.stats[STAT_LAYOUTS] && cls.key_dest == key_game)
{
// put away help computer / inventory
Cbuf_AddText ("cmd putaway\n");
return;
}
switch (cls.key_dest)
{
case key_message:
Key_Message (key);
break;
case key_menu:
M_Keydown (key);
break;
case key_game:
case key_console:
M_Menu_Main_f ();
break;
default:
MsgWarn("Key_Event: bad cls.key_dest\n");
break;
}
return;
}
// track if any key is down for BUTTON_ANY
keydown[key] = down;
if (down)
{
if (key_repeats[key] == 1)
anykeydown++;
}
else
{
anykeydown--;
if (anykeydown < 0)
anykeydown = 0;
}
// key up events only generate commands if the game key binding is
// a button command (leading + sign). These will occur even in console mode,
// to keep the character from continuing an action started before a console
// switch. Button commands include the kenum as a parameter, so multiple
// downs can be matched with ups
if (!down)
{
kb = keybindings[key];
if (kb && kb[0] == '+')
{
sprintf (cmd, "-%s %i %i\n", kb+1, key, time);
Cbuf_AddText (cmd);
}
if (keyshift[key] != key)
{
kb = keybindings[keyshift[key]];
if (kb && kb[0] == '+')
{
sprintf (cmd, "-%s %i %i\n", kb+1, key, time);
Cbuf_AddText (cmd);
}
}
return;
}
// if not a consolekey, send to the interpreter no matter what mode is
if ( (cls.key_dest == key_menu && menubound[key]) || (cls.key_dest == key_console && !consolekeys[key]) || (cls.key_dest == key_game && ( cls.state == ca_active || !consolekeys[key] )))
{
kb = keybindings[key];
if (kb)
{
if (kb[0] == '+')
{
// button commands add keynum and time as a parm
sprintf (cmd, "%s %i %i\n", kb, key, time);
Cbuf_AddText (cmd);
}
else
{
Cbuf_AddText (kb);
Cbuf_AddText ("\n");
}
}
return;
}
if (!down) return; // other systems only care about key down events
if (shift_down) key = keyshift[key];
switch (cls.key_dest)
{
case key_message:
Key_Message (key);
break;
case key_menu:
M_Keydown (key);
break;
case key_game:
case key_console:
Key_Console (key);
break;
default:
MsgWarn("Key_Event: bad cls.key_dest\n");
break;
}
}
/*
===================
Key_ClearStates
===================
*/
void Key_ClearStates (void)
{
int i;
anykeydown = false;
for (i=0 ; i<256 ; i++)
{
if ( keydown[i] || key_repeats[i] )
Key_Event( i, false, 0 );
keydown[i] = 0;
key_repeats[i] = 0;
}
}
/*
===================
Key_GetKey
===================
*/
int Key_GetKey (void)
{
key_waiting = -1;
while (key_waiting == -1)
Sys_SendKeyEvents ();
return key_waiting;
}

View File

@ -1,148 +0,0 @@
/*
Copyright (C) 1997-2001 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.
*/
//
// these are the key numbers that should be passed to Key_Event
//
#define K_TAB 9
#define K_ENTER 13
#define K_ESCAPE 27
#define K_SPACE 32
// normal keys should be passed as lowercased ascii
#define K_BACKSPACE 127
#define K_UPARROW 128
#define K_DOWNARROW 129
#define K_LEFTARROW 130
#define K_RIGHTARROW 131
#define K_ALT 132
#define K_CTRL 133
#define K_SHIFT 134
#define K_F1 135
#define K_F2 136
#define K_F3 137
#define K_F4 138
#define K_F5 139
#define K_F6 140
#define K_F7 141
#define K_F8 142
#define K_F9 143
#define K_F10 144
#define K_F11 145
#define K_F12 146
#define K_INS 147
#define K_DEL 148
#define K_PGDN 149
#define K_PGUP 150
#define K_HOME 151
#define K_END 152
#define K_KP_HOME 160
#define K_KP_UPARROW 161
#define K_KP_PGUP 162
#define K_KP_LEFTARROW 163
#define K_KP_5 164
#define K_KP_RIGHTARROW 165
#define K_KP_END 166
#define K_KP_DOWNARROW 167
#define K_KP_PGDN 168
#define K_KP_ENTER 169
#define K_KP_INS 170
#define K_KP_DEL 171
#define K_KP_SLASH 172
#define K_KP_MINUS 173
#define K_KP_PLUS 174
#define K_PAUSE 255
//
// mouse buttons generate virtual keys
//
#define K_MOUSE1 200
#define K_MOUSE2 201
#define K_MOUSE3 202
//
// joystick buttons
//
#define K_JOY1 203
#define K_JOY2 204
#define K_JOY3 205
#define K_JOY4 206
//
// aux keys are for multi-buttoned joysticks to generate so they can use
// the normal binding process
//
#define K_AUX1 207
#define K_AUX2 208
#define K_AUX3 209
#define K_AUX4 210
#define K_AUX5 211
#define K_AUX6 212
#define K_AUX7 213
#define K_AUX8 214
#define K_AUX9 215
#define K_AUX10 216
#define K_AUX11 217
#define K_AUX12 218
#define K_AUX13 219
#define K_AUX14 220
#define K_AUX15 221
#define K_AUX16 222
#define K_AUX17 223
#define K_AUX18 224
#define K_AUX19 225
#define K_AUX20 226
#define K_AUX21 227
#define K_AUX22 228
#define K_AUX23 229
#define K_AUX24 230
#define K_AUX25 231
#define K_AUX26 232
#define K_AUX27 233
#define K_AUX28 234
#define K_AUX29 235
#define K_AUX30 236
#define K_AUX31 237
#define K_AUX32 238
#define K_MWHEELDOWN 239
#define K_MWHEELUP 240
extern char *keybindings[256];
extern int key_repeats[256];
extern int anykeydown;
extern char chat_buffer[];
extern int chat_bufferlen;
extern bool chat_team;
void Key_Event (int key, bool down, unsigned time);
void Key_Init (void);
void Key_WriteBindings (file_t *f);
void Key_SetBinding (int keynum, char *binding);
void Key_ClearStates (void);
char *Key_KeynumToString (int keynum);
int Key_StringToKeynum (char *str);
int Key_GetKey (void);

View File

@ -230,23 +230,6 @@ const char *Default_MenuKey( menuframework_s *m, int key )
case K_AUX14:
case K_AUX15:
case K_AUX16:
case K_AUX17:
case K_AUX18:
case K_AUX19:
case K_AUX20:
case K_AUX21:
case K_AUX22:
case K_AUX23:
case K_AUX24:
case K_AUX25:
case K_AUX26:
case K_AUX27:
case K_AUX28:
case K_AUX29:
case K_AUX30:
case K_AUX31:
case K_AUX32:
case K_KP_ENTER:
case K_ENTER:
if ( m )
@ -644,15 +627,14 @@ static void M_UnbindCommand (char *command)
{
int j;
int l;
char *b;
char *b;
l = strlen(command);
for (j=0 ; j<256 ; j++)
for (j = 0; j < 256; j++)
{
b = keybindings[j];
if (!b)
continue;
b = keys[j].binding;
if (!b) continue;
if (!strncmp (b, command, l) )
Key_SetBinding (j, "");
}
@ -660,26 +642,24 @@ static void M_UnbindCommand (char *command)
static void M_FindKeysForCommand (char *command, int *twokeys)
{
int count;
int j;
int l;
int count;
int j;
int l;
char *b;
twokeys[0] = twokeys[1] = -1;
l = strlen(command);
count = 0;
for (j=0 ; j<256 ; j++)
for (j = 0; j < 256; j++)
{
b = keybindings[j];
if (!b)
continue;
b = keys[j].binding;
if (!b) continue;
if (!strncmp (b, command, l) )
{
twokeys[count] = j;
count++;
if (count == 2)
break;
if (count == 2) break;
}
}
}
@ -1028,9 +1008,9 @@ static menulist_s s_options_lookspring_box;
static menulist_s s_options_lookstrafe_box;
static menulist_s s_options_crosshair_box;
static menuslider_s s_options_sfxvolume_slider;
static menuslider_s s_options_musicvolume_slider;
static menulist_s s_options_joystick_box;
static menulist_s s_options_quality_list;
static menulist_s s_options_compatibility_list;
static menulist_s s_options_console_action;
static void CrosshairFunc( void *unused )
@ -1073,6 +1053,7 @@ static float ClampCvar( float min, float max, float value )
static void ControlsSetMenuItemValues( void )
{
s_options_sfxvolume_slider.curvalue = Cvar_VariableValue( "s_volume" ) * 10;
s_options_musicvolume_slider.curvalue = Cvar_VariableValue( "s_musicvolume" ) * 10;
s_options_quality_list.curvalue = !(Cvar_VariableValue( "s_khz" ) == 22);
s_options_sensitivity_slider.curvalue = ( sensitivity->value ) * 2;
@ -1125,14 +1106,18 @@ static void UpdateVolumeFunc( void *unused )
Cvar_SetValue( "s_volume", s_options_sfxvolume_slider.curvalue / 10 );
}
static void UpdateMusicVolumeFunc( void *unused )
{
Cvar_SetValue( "s_musicvolume", s_options_musicvolume_slider.curvalue / 10 );
}
static void ConsoleFunc( void *unused )
{
/*
** the proper way to do this is probably to have ToggleConsole_f accept a parameter
*/
extern void Key_ClearTyping( void );
Key_ClearTyping ();
Field_Clear( &g_consoleField );
Con_ClearNotify ();
M_ForceMenuOff ();
@ -1141,16 +1126,8 @@ static void ConsoleFunc( void *unused )
static void UpdateSoundQualityFunc( void *unused )
{
if ( s_options_quality_list.curvalue )
{
Cvar_SetValue( "s_khz", 44 );
}
else
{
Cvar_SetValue( "s_khz", 22 );
}
Cvar_SetValue( "s_primary", s_options_compatibility_list.curvalue );
if ( s_options_quality_list.curvalue ) Cvar_SetValue( "s_khz", 44 );
else Cvar_SetValue( "s_khz", 22 );
M_DrawTextBox( 8, 120 - 48, 36, 3 );
M_Print( 16 + 16, 120 - 48 + 8, "Restarting the sound system. This" );
@ -1159,7 +1136,6 @@ static void UpdateSoundQualityFunc( void *unused )
// the text box won't show up unless we do a buffer swap
re->EndFrame();
CL_Snd_Restart_f();
}
@ -1201,28 +1177,29 @@ void Options_MenuInit( void )
s_options_sfxvolume_slider.generic.type = MTYPE_SLIDER;
s_options_sfxvolume_slider.generic.x = 0;
s_options_sfxvolume_slider.generic.y = 0;
s_options_sfxvolume_slider.generic.name = "effects volume";
s_options_sfxvolume_slider.generic.name = "sound volume";
s_options_sfxvolume_slider.generic.callback = UpdateVolumeFunc;
s_options_sfxvolume_slider.minvalue = 0;
s_options_sfxvolume_slider.maxvalue = 10;
s_options_sfxvolume_slider.curvalue = Cvar_VariableValue( "s_volume" ) * 10;
s_options_quality_list.generic.type = MTYPE_SPINCONTROL;
s_options_quality_list.generic.x = 0;
s_options_quality_list.generic.y = 10;
s_options_musicvolume_slider.generic.type = MTYPE_SLIDER;
s_options_musicvolume_slider.generic.x = 0;
s_options_musicvolume_slider.generic.y = 10;
s_options_musicvolume_slider.generic.name = "music volume";
s_options_musicvolume_slider.generic.callback = UpdateMusicVolumeFunc;
s_options_musicvolume_slider.minvalue = 0;
s_options_musicvolume_slider.maxvalue = 10;
s_options_musicvolume_slider.curvalue = Cvar_VariableValue( "s_musicvolume" ) * 10;
s_options_quality_list.generic.type = MTYPE_SPINCONTROL;
s_options_quality_list.generic.x = 0;
s_options_quality_list.generic.y = 20;
s_options_quality_list.generic.name = "sound quality";
s_options_quality_list.generic.callback = UpdateSoundQualityFunc;
s_options_quality_list.itemnames = quality_items;
s_options_quality_list.curvalue = !(Cvar_VariableValue( "s_khz" ) == 22);
s_options_compatibility_list.generic.type = MTYPE_SPINCONTROL;
s_options_compatibility_list.generic.x = 0;
s_options_compatibility_list.generic.y = 20;
s_options_compatibility_list.generic.name = "sound compatibility";
s_options_compatibility_list.generic.callback = UpdateSoundQualityFunc;
s_options_compatibility_list.itemnames = compatibility_items;
s_options_compatibility_list.curvalue = Cvar_VariableValue( "s_primary" );
s_options_sensitivity_slider.generic.type = MTYPE_SLIDER;
s_options_sensitivity_slider.generic.x = 0;
s_options_sensitivity_slider.generic.y = 40;
@ -1301,8 +1278,8 @@ void Options_MenuInit( void )
ControlsSetMenuItemValues();
Menu_AddItem( &s_options_menu, ( void * ) &s_options_sfxvolume_slider );
Menu_AddItem( &s_options_menu, ( void * ) &s_options_musicvolume_slider );
Menu_AddItem( &s_options_menu, ( void * ) &s_options_quality_list );
Menu_AddItem( &s_options_menu, ( void * ) &s_options_compatibility_list );
Menu_AddItem( &s_options_menu, ( void * ) &s_options_sensitivity_slider );
Menu_AddItem( &s_options_menu, ( void * ) &s_options_alwaysrun_box );
Menu_AddItem( &s_options_menu, ( void * ) &s_options_invertmouse_box );
@ -1580,19 +1557,19 @@ static void StartGame( void )
static void EasyGameFunc( void *data )
{
Cvar_ForceSet( "skill", "0" );
Cvar_SetLatched( "skill", "0" );
StartGame();
}
static void MediumGameFunc( void *data )
{
Cvar_ForceSet( "skill", "1" );
Cvar_SetLatched( "skill", "1" );
StartGame();
}
static void HardGameFunc( void *data )
{
Cvar_ForceSet( "skill", "2" );
Cvar_SetLatched( "skill", "2" );
StartGame();
}

View File

@ -98,7 +98,7 @@ void Netchan_Init (void)
Msg("netchan port %d\n", port );
showpackets = Cvar_Get ("showpackets", "0", 0);
showdrop = Cvar_Get ("showdrop", "0", 0);
qport = Cvar_Get ("qport", va("%i", port), CVAR_NOSET);
qport = Cvar_Get ("qport", va("%i", port), CVAR_INIT);
}
/*

View File

@ -581,19 +581,19 @@ void NET_OpenIP (void)
int port;
int dedicated;
ip = Cvar_Get ("ip", "localhost", CVAR_NOSET);
ip = Cvar_Get ("ip", "localhost", CVAR_INIT);
dedicated = Cvar_VariableValue ("dedicated");
if (!ip_sockets[NS_SERVER])
{
port = Cvar_Get("ip_hostport", "0", CVAR_NOSET)->value;
port = Cvar_Get("ip_hostport", "0", CVAR_INIT)->value;
if (!port)
{
port = Cvar_Get("hostport", "0", CVAR_NOSET)->value;
port = Cvar_Get("hostport", "0", CVAR_INIT)->value;
if (!port)
{
port = Cvar_Get("port", va("%i", PORT_SERVER), CVAR_NOSET)->value;
port = Cvar_Get("port", va("%i", PORT_SERVER), CVAR_INIT)->value;
}
}
ip_sockets[NS_SERVER] = NET_IPSocket (ip->string, port);
@ -606,10 +606,10 @@ void NET_OpenIP (void)
if (!ip_sockets[NS_CLIENT])
{
port = Cvar_Get("ip_clientport", "0", CVAR_NOSET)->value;
port = Cvar_Get("ip_clientport", "0", CVAR_INIT)->value;
if (!port)
{
port = Cvar_Get("clientport", va("%i", PORT_CLIENT), CVAR_NOSET)->value;
port = Cvar_Get("clientport", va("%i", PORT_CLIENT), CVAR_INIT)->value;
if (!port)
port = PORT_ANY;
}
@ -687,13 +687,13 @@ void NET_OpenIPX (void)
if (!ipx_sockets[NS_SERVER])
{
port = Cvar_Get("ipx_hostport", "0", CVAR_NOSET)->value;
port = Cvar_Get("ipx_hostport", "0", CVAR_INIT)->value;
if (!port)
{
port = Cvar_Get("hostport", "0", CVAR_NOSET)->value;
port = Cvar_Get("hostport", "0", CVAR_INIT)->value;
if (!port)
{
port = Cvar_Get("port", va("%i", PORT_SERVER), CVAR_NOSET)->value;
port = Cvar_Get("port", va("%i", PORT_SERVER), CVAR_INIT)->value;
}
}
ipx_sockets[NS_SERVER] = NET_IPXSocket (port);
@ -705,10 +705,10 @@ void NET_OpenIPX (void)
if (!ipx_sockets[NS_CLIENT])
{
port = Cvar_Get("ipx_clientport", "0", CVAR_NOSET)->value;
port = Cvar_Get("ipx_clientport", "0", CVAR_INIT)->value;
if (!port)
{
port = Cvar_Get("clientport", va("%i", PORT_CLIENT), CVAR_NOSET)->value;
port = Cvar_Get("clientport", va("%i", PORT_CLIENT), CVAR_INIT)->value;
if (!port)
port = PORT_ANY;
}
@ -810,8 +810,8 @@ void NET_Init (void)
Msg("Winsock Initialized\n");
noudp = Cvar_Get ("noudp", "0", CVAR_NOSET);
noipx = Cvar_Get ("noipx", "0", CVAR_NOSET);
noudp = Cvar_Get ("noudp", "0", CVAR_INIT);
noipx = Cvar_Get ("noipx", "0", CVAR_INIT);
net_shownet = Cvar_Get ("net_shownet", "0", 0);
}

View File

@ -83,7 +83,7 @@ bool Field_DoEnter( menufield_s *f )
return false;
}
void Field_Draw( menufield_s *f )
void QField_Draw( menufield_s *f )
{
int i;
char tempbuffer[128]="";
@ -194,7 +194,7 @@ bool Field_Key( menufield_s *f, int key )
/*
** support pasting from the clipboard
*/
if ( ( toupper( key ) == 'V' && keydown[K_CTRL] ) || ((( key == K_INS ) || ( key == K_KP_INS )) && keydown[K_SHIFT] ))
if ( ( toupper( key ) == 'V' && keys[K_CTRL].down ) || ((( key == K_INS ) || ( key == K_KP_INS )) && keys[K_SHIFT].down ))
{
char *cbd;
@ -205,8 +205,7 @@ bool Field_Key( menufield_s *f, int key )
strncpy( f->buffer, cbd, f->length - 1 );
f->cursor = strlen( f->buffer );
f->visible_offset = f->cursor - f->visible_length;
if ( f->visible_offset < 0 )
f->visible_offset = 0;
if ( f->visible_offset < 0 ) f->visible_offset = 0;
Z_Free( cbd );
}
@ -354,7 +353,7 @@ void Menu_Draw( menuframework_s *menu )
switch ((( menucommon_s * )menu->items[i] )->type )
{
case MTYPE_FIELD:
Field_Draw( ( menufield_s * ) menu->items[i] );
QField_Draw( ( menufield_s * ) menu->items[i] );
break;
case MTYPE_SLIDER:
Slider_Draw( ( menuslider_s * ) menu->items[i] );
@ -421,12 +420,12 @@ void Menu_DrawStatusBar( const char *string )
int maxcol = VID_WIDTH / 8;
int col = maxcol / 2 - l / 2;
Draw_Fill( 0, VID_HEIGHT-8, VID_WIDTH, 8, 4 );
SCR_FillRect( 0, SCREEN_HEIGHT - 8, SCREEN_WIDTH, 8, COLOR_4 );
Menu_DrawString( col*8, VID_HEIGHT - 8, string );
}
else
{
Draw_Fill( 0, VID_HEIGHT-8, VID_WIDTH, 8, 0 );
SCR_FillRect( 0, SCREEN_HEIGHT - 8, SCREEN_WIDTH, 8, COLOR_0 );
}
}
@ -566,14 +565,14 @@ void Menulist_DoEnter( menulist_s *l )
void MenuList_Draw( menulist_s *l )
{
const char **n;
int y = 0;
int y = 0;
Menu_DrawStringR2LDark( l->generic.x + l->generic.parent->x + LCOLUMN_OFFSET, l->generic.y + l->generic.parent->y, l->generic.name );
n = l->itemnames;
Draw_Fill( l->generic.x - 112 + l->generic.parent->x, l->generic.parent->y + l->generic.y + l->curvalue*10 + 10, 128, 10, 16 );
while ( *n )
SCR_FillRect( l->generic.x - 112 + l->generic.parent->x, l->generic.parent->y + l->generic.y + l->curvalue*10 + 10, 128, 10, COLOR_16 );
while ( *n )
{
Menu_DrawStringR2LDark( l->generic.x + l->generic.parent->x + LCOLUMN_OFFSET, l->generic.y + l->generic.parent->y + y + 10, *n );

View File

@ -23,6 +23,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "vid.h"
// all drawing is done to a 640*480 virtual screen size
// and will be automatically scaled to the real resolution
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define TINYCHAR_WIDTH (SMALLCHAR_WIDTH)
#define TINYCHAR_HEIGHT (SMALLCHAR_HEIGHT/2)
#define SMALLCHAR_WIDTH 8
#define SMALLCHAR_HEIGHT 16
#define BIGCHAR_WIDTH 16
#define BIGCHAR_HEIGHT 16
#define GIANTCHAR_WIDTH 32
#define GIANTCHAR_HEIGHT 48
// cinematic states
typedef enum
{
@ -41,6 +55,14 @@ typedef enum
#define CIN_silent 8
#define CIN_shader 16
#define COLOR_0 NULL
#define COLOR_4 GetRGBA(1.0f, 0.5f, 0.0f, 1.0f)
#define COLOR_8 GetRGBA(1.0f, 0.5f, 1.0f, 1.0f)
#define COLOR_16 GetRGBA(0.3f, 0.8f, 1.0f, 1.0f)
#define COLOR_64 GetRGBA(0.7f, 0.5f, 0.0f, 1.0f)
#define COLOR_208 GetRGBA(0.0f, 0.4f, 0.0f, 1.0f)
#define COLOR_223 GetRGBA(0.5f, 0.2f, 1.0f, 1.0f)
void SCR_Init (void);
void SCR_UpdateScreen (void);
@ -51,7 +73,7 @@ void SCR_CenterPrint (char *str);
void SCR_BeginLoadingPlaque (void);
void SCR_EndLoadingPlaque (void);
void SCR_DebugGraph (float value, int color);
void SCR_DebugGraph (float value, vec4_t color);
void SCR_TouchPics (void);
@ -72,6 +94,13 @@ extern int crosshair_width, crosshair_height;
void SCR_AddDirtyPoint (int x, int y);
void SCR_DirtyScreen (void);
void SCR_AdjustSize( float *x, float *y, float *w, float *h );
void SCR_DrawPic( float x, float y, float width, float height, char *picname );
void SCR_FillRect( float x, float y, float width, float height, const float *color );
void SCR_DrawSmallChar( int x, int y, int ch );
void SCR_DrawSmallStringExt( int x, int y, const char *string, float *setColor, bool forceColor );
void SCR_DrawBigString( int x, int y, const char *s, float alpha );
void SCR_DrawBigStringColor( int x, int y, const char *s, vec4_t color );
//
// cl_cin.c

View File

@ -8,7 +8,6 @@
#include "vm_cmds.h"
#include "sound.h"
#include "screen.h"
#include "keys.h"
//============================================================================
// Common
@ -163,7 +162,7 @@ void VM_print (void)
char string[VM_STRINGTEMP_LENGTH];
VM_VarString(0, string, sizeof(string));
Con_Print(string);
Msg(string);
}
/*
@ -183,7 +182,7 @@ void VM_bprint (void)
if(sv.state == ss_loading)
{
Con_Print( string );
Msg( string );
return;
}
SV_BroadcastPrintf(PRINT_HIGH, string);
@ -232,7 +231,7 @@ clientcommand(float client, string s) (for client and menu)
*/
void VM_clientcmd (void)
{
client_t *temp_client;
client_state_t *temp_client;
int i;
VM_SAFEPARMCOUNT(2, VM_clientcmd);
@ -2308,19 +2307,19 @@ float drawfill(vector position, vector size, vector rgb, float alpha, float flag
void VM_drawfill(void)
{
float *size, *pos, *rgb;
int flag, color;
VM_SAFEPARMCOUNT(5,VM_drawfill);
int flag;
vec4_t color;
VM_SAFEPARMCOUNT(5, VM_drawfill);
pos = PRVM_G_VECTOR(OFS_PARM0);
size = PRVM_G_VECTOR(OFS_PARM1);
rgb = PRVM_G_VECTOR(OFS_PARM2);
flag = (int) PRVM_G_FLOAT(OFS_PARM4);
flag = (int)PRVM_G_FLOAT(OFS_PARM4);
color = VectorLength( rgb ); //stupid hack
Vector4Set( color, rgb[0], rgb[1], rgb[2], 1.0f );
re->DrawFill( pos[0], pos[1], size[0], size[1], color );
SCR_FillRect( pos[0], pos[1], size[0], size[1], color );
PRVM_G_FLOAT(OFS_RETURN) = 1;
}

View File

@ -636,11 +636,11 @@ void PRVM_ED_Print(edict_t *ed)
strncat(tempstring, "\n", sizeof(tempstring));
if (strlen(tempstring) >= sizeof(tempstring)/2)
{
Con_Print(tempstring);
Msg(tempstring);
tempstring[0] = 0;
}
}
if (tempstring[0]) Con_Print(tempstring);
if (tempstring[0]) Msg(tempstring);
}
/*
@ -725,7 +725,7 @@ void PRVM_ED_PrintEdicts_f (void)
if(Cmd_Argc() != 2)
{
Con_Print("prvm_edicts <program name>\n");
Msg("prvm_edicts <program name>\n");
return;
}
@ -789,7 +789,7 @@ void PRVM_ED_Count_f (void)
if(Cmd_Argc() != 2)
{
Con_Print("prvm_count <program name>\n");
Msg("prvm_count <program name>\n");
return;
}
@ -1016,7 +1016,7 @@ void PRVM_ED_EdictSet_f(void)
if(Cmd_Argc() != 5)
{
Con_Print("prvm_edictset <program name> <edict number> <field> <value>\n");
Msg("prvm_edictset <program name> <edict number> <field> <value>\n");
return;
}
@ -1703,14 +1703,14 @@ void PRVM_Fields_f (void)
/*
if (!sv.active)
{
Con_Print("no progs loaded\n");
Msg("no progs loaded\n");
return;
}
*/
if(Cmd_Argc() != 2)
{
Con_Print("prvm_fields <program name>\n");
Msg("prvm_fields <program name>\n");
return;
}
@ -1797,7 +1797,7 @@ void PRVM_Fields_f (void)
strncat(tempstring, "\n", sizeof(tempstring));
if (strlen(tempstring) >= sizeof(tempstring)/2)
{
Con_Print(tempstring);
Msg(tempstring);
tempstring[0] = 0;
}
if (counts[i])
@ -1818,12 +1818,12 @@ void PRVM_Globals_f (void)
// TODO
/*if (!sv.active)
{
Con_Print("no progs loaded\n");
Msg("no progs loaded\n");
return;
}*/
if(Cmd_Argc () != 2)
{
Con_Print("prvm_globals <program name>\n");
Msg("prvm_globals <program name>\n");
return;
}
@ -1927,7 +1927,7 @@ void VM_Warning(const char *fmt, ...)
va_end(argptr);
Msg(msg);
// TODO: either add a cvar/cmd to control the state dumping or replace some of the calls with Con_Printf [9/13/2006 Black]
// TODO: either add a cvar/cmd to control the state dumping or replace some of the calls with Msgf [9/13/2006 Black]
//PRVM_PrintState();
}

View File

@ -142,7 +142,7 @@ void PRVM_PrintStatement (dstatement_t *s)
if (prvm_opnames[s->op][0] == STRING_COLOR_TAG)
i -= 2;
for ( ; i<10 ; i++)
Con_Print(" ");
Msg(" ");
}
if (s->op == OP_IF || s->op == OP_IFNOT)
Msg("%s, s%i",PRVM_GlobalString((unsigned short) s->a),(signed short)s->b + opnum);
@ -150,41 +150,41 @@ void PRVM_PrintStatement (dstatement_t *s)
Msg("s%i",(signed short)s->a + opnum);
else if ( (unsigned)(s->op - OP_STORE_F) < 6)
{
Con_Print(PRVM_GlobalString((unsigned short) s->a));
Con_Print(", ");
Con_Print(PRVM_GlobalStringNoContents((unsigned short) s->b));
Msg(PRVM_GlobalString((unsigned short) s->a));
Msg(", ");
Msg(PRVM_GlobalStringNoContents((unsigned short) s->b));
}
else if (s->op == OP_ADDRESS || (unsigned)(s->op - OP_LOAD_F) < 6)
{
if (s->a)
Con_Print(PRVM_GlobalString((unsigned short) s->a));
Msg(PRVM_GlobalString((unsigned short) s->a));
if (s->b)
{
Con_Print(", ");
Con_Print(PRVM_GlobalStringNoContents((unsigned short) s->b));
Msg(", ");
Msg(PRVM_GlobalStringNoContents((unsigned short) s->b));
}
if (s->c)
{
Con_Print(", ");
Con_Print(PRVM_GlobalStringNoContents((unsigned short) s->c));
Msg(", ");
Msg(PRVM_GlobalStringNoContents((unsigned short) s->c));
}
}
else
{
if (s->a)
Con_Print(PRVM_GlobalString((unsigned short) s->a));
Msg(PRVM_GlobalString((unsigned short) s->a));
if (s->b)
{
Con_Print(", ");
Con_Print(PRVM_GlobalString((unsigned short) s->b));
Msg(", ");
Msg(PRVM_GlobalString((unsigned short) s->b));
}
if (s->c)
{
Con_Print(", ");
Con_Print(PRVM_GlobalStringNoContents((unsigned short) s->c));
Msg(", ");
Msg(PRVM_GlobalStringNoContents((unsigned short) s->c));
}
}
Con_Print("\n");
Msg("\n");
}
void PRVM_PrintFunctionStatements (const char *name)
@ -259,7 +259,7 @@ void PRVM_StackTrace (void)
f = prog->stack[i].f;
if (!f)
Con_Print("<NULL FUNCTION>\n");
Msg("<NULL FUNCTION>\n");
else
Msg("%12s : %s : statement %i\n", PRVM_GetString(f->s_file), PRVM_GetString(f->s_name), prog->stack[i].s - f->first_statement);
}
@ -320,7 +320,7 @@ void PRVM_Profile_f (void)
howmany = atoi(Cmd_Argv(2));
else if (Cmd_Argc() != 2)
{
Con_Print("prvm_profile <program name>\n");
Msg("prvm_profile <program name>\n");
return;
}
@ -359,7 +359,7 @@ void PRVM_PrintState(void)
PRVM_PrintStatement (prog->statements + prog->xstatement + i);
}
else
Con_Print("null function executing??\n");
Msg("null function executing??\n");
PRVM_StackTrace ();
}

View File

@ -118,6 +118,10 @@ SOURCE=.\client\cl_cin.c
# End Source File
# Begin Source File
SOURCE=.\client\cl_console.c
# End Source File
# Begin Source File
SOURCE=.\client\cl_ents.c
# End Source File
# Begin Source File
@ -134,6 +138,10 @@ SOURCE=.\client\cl_inv.c
# End Source File
# Begin Source File
SOURCE=.\client\cl_keys.c
# End Source File
# Begin Source File
SOURCE=.\client\cl_main.c
# End Source File
# Begin Source File
@ -174,10 +182,6 @@ SOURCE=.\common\common.c
# End Source File
# Begin Source File
SOURCE=.\common\console.c
# End Source File
# Begin Source File
SOURCE=.\common\cvar.c
# End Source File
# Begin Source File
@ -190,10 +194,6 @@ SOURCE=.\in_win.c
# End Source File
# Begin Source File
SOURCE=.\common\keys.c
# End Source File
# Begin Source File
SOURCE=.\common\md4.c
# End Source File
# Begin Source File

View File

@ -24,7 +24,7 @@
#include "const.h"
#include "common.h"
#include "cvar.h"
#include "console.h"
#include "client.h"
extern stdlib_api_t std;
extern common_exp_t *Com;
@ -141,7 +141,7 @@ scriptsystem manager
*/
#define COM_Parse(data) Com->Script.ParseToken(data)
#define COM_Token Com->Script.Token
#define COM_Filter Com->Script.FilterToken
/*
===========================================
infostring manager
@ -167,9 +167,9 @@ System Events
===========================================
*/
#define Msg Con_Printf
#define MsgDev Con_DPrintf
#define MsgWarn Con_DWarnf
#define Msg Com_Printf
#define MsgDev Com_DPrintf
#define MsgWarn Com_DWarnf
#define Sys_LoadLibrary std.LoadLibrary
#define Sys_FreeLibrary std.FreeLibrary
#define Sys_Sleep std.sleep

View File

@ -34,10 +34,10 @@ stdlib_api_t Host_GetStdio( bool crash_on_error )
io.api_size = sizeof(stdlib_api_t);
io.print = Con_Print;
io.printf = Con_Printf;
io.dprintf = Con_DPrintf;
io.wprintf = Con_DWarnf;
io.print = Com_Print;
io.printf = Com_Printf;
io.dprintf = Com_DPrintf;
io.wprintf = Com_DWarnf;
io.exit = Sys_Quit;
io.input = Sys_ConsoleInput;
io.sleep = Sys_Sleep;
@ -143,23 +143,15 @@ void Host_Init (char *funcname, int argc, char **argv)
COM_InitArgv (argc, argv); // init host.debug & host.developer here
Host_InitCommon( funcname, argc, argv );
Cbuf_Init ();
Cmd_Init ();
Cvar_Init ();
Key_Init ();
Cmd_Init( argc, argv );
Cvar_Init();
Key_Init();
PRVM_Init();
// we need to add the early commands twice, because
// a basedir or cddir needs to be set before execing
// config files, but we want other parms to override
// the settings of the config files
Cbuf_AddEarlyCommands (false);
Cbuf_Execute ();
Cbuf_AddText ("exec default.cfg\n");
Cbuf_AddText ("exec config.cfg\n");
Cbuf_AddEarlyCommands (true);
Cbuf_Execute ();
Cbuf_AddText("exec base.rc\n");
Cbuf_AddText("exec keys.rc\n");
Cbuf_AddText("exec vars.rc\n");
Cbuf_Execute();
// init commands and vars
Cmd_AddCommand ("error", Host_Error_f);
@ -168,11 +160,11 @@ void Host_Init (char *funcname, int argc, char **argv)
host_frametime = Cvar_Get ("host_frametime", "0.01", 0);
timescale = Cvar_Get ("timescale", "1", 0);
fixedtime = Cvar_Get ("fixedtime", "0", 0);
if(host.type == HOST_DEDICATED) dedicated = Cvar_Get ("dedicated", "1", CVAR_NOSET);
else dedicated = Cvar_Get ("dedicated", "0", CVAR_NOSET);
if(host.type == HOST_DEDICATED) dedicated = Cvar_Get ("dedicated", "1", CVAR_INIT);
else dedicated = Cvar_Get ("dedicated", "0", CVAR_INIT);
s = va("%4.2f %s %s %s", VERSION, "x86", __DATE__, BUILDSTRING);
Cvar_Get ("version", s, CVAR_SERVERINFO|CVAR_NOSET);
Cvar_Get ("version", s, CVAR_SERVERINFO|CVAR_INIT);
if (dedicated->value) Cmd_AddCommand ("quit", Sys_Quit);
@ -184,12 +176,12 @@ void Host_Init (char *funcname, int argc, char **argv)
CL_Init();
// add + commands from command line
if (!Cbuf_AddLateCommands ())
if(!Cmd_AddStartupCommands())
{
// if the user didn't give any commands, run default action
if (!dedicated->value) Cbuf_AddText ("d1\n");
else Cbuf_AddText ("dedicated_start\n");
Cbuf_Execute ();
if ( host.type != HOST_DEDICATED )
Cbuf_AddText ("demomap idlogo.roq\n");
else Cbuf_AddText ("map dm_qstyle\n");
}
else
{ // the user asked for something explicit

View File

@ -223,7 +223,7 @@ void IN_StartupMouse (void)
{
cvar_t *cv;
cv = Cvar_Get ("in_initmouse", "1", CVAR_NOSET);
cv = Cvar_Get ("in_initmouse", "1", CVAR_INIT);
if ( !cv->value )
return;
@ -492,7 +492,7 @@ void IN_StartupJoystick (void)
joy_avail = false;
// abort startup if user requests no joystick
cv = Cvar_Get ("in_initjoy", "1", CVAR_NOSET);
cv = Cvar_Get ("in_initjoy", "1", CVAR_INIT);
if ( !cv->value )
return;
@ -702,12 +702,12 @@ void IN_Commands (void)
{
if ( (povstate & (1<<i)) && !(joy_oldpovstate & (1<<i)) )
{
Key_Event (K_AUX29 + i, true, 0);
Key_Event (K_AUX16 + i, true, 0);
}
if ( !(povstate & (1<<i)) && (joy_oldpovstate & (1<<i)) )
{
Key_Event (K_AUX29 + i, false, 0);
Key_Event (K_AUX16 + i, false, 0);
}
}
joy_oldpovstate = povstate;

View File

@ -37,20 +37,20 @@ typedef enum
ss_cinematic,
ss_demo,
} server_state_t;
} sv_state_t;
typedef enum
{
cs_free, // can be reused for a new connection
cs_zombie, // client has been disconnected, but don't reuse connection for a couple seconds
cs_connected, // has been assigned to a client_t, but not in game yet
cs_connected, // has been assigned to a client_state_t, but not in game yet
cs_spawned // client is fully in game
} client_state_t;
} cl_state_t;
typedef struct
{
server_state_t state; // precache commands are only valid during load
sv_state_t state; // precache commands are only valid during load
bool attractloop; // running cinematics and demos for the local system only
bool loadgame; // client begins should reuse existing entity
@ -92,9 +92,9 @@ typedef struct
} client_frame_t;
typedef struct client_s
typedef struct client_state_s
{
client_state_t state;
cl_state_t state;
char userinfo[MAX_INFO_STRING]; // name, etc
@ -132,7 +132,7 @@ typedef struct client_s
int challenge; // challenge of this user, randomly generated
netchan_t netchan;
} client_t;
} client_state_t;
/*
=============================================================================
@ -168,7 +168,7 @@ typedef struct
int spawncount; // incremented each server start
// used to check late spawns
gclient_t *gclients; // [maxclients->value]
client_t *clients; // [maxclients->value]
client_state_t *clients; // [maxclients->value]
int num_client_entities; // maxclients->value*UPDATE_BACKUP*MAX_PACKET_ENTITIES
int next_client_entities; // next client_entity to use
entity_state_t *client_entities; // [num_client_entities]
@ -202,7 +202,7 @@ extern cvar_t *sv_gravity;
// development tool
extern cvar_t *sv_enforcetime;
extern client_t *sv_client;
extern client_state_t *sv_client;
extern edict_t *sv_player;
@ -211,18 +211,18 @@ extern edict_t *sv_player;
// sv_main.c
//
void SV_FinalMessage (char *message, bool reconnect);
void SV_DropClient (client_t *drop);
void SV_DropClient (client_state_t *drop);
int SV_ModelIndex (const char *name);
int SV_SoundIndex (const char *name);
int SV_ImageIndex (const char *name);
int SV_DecalIndex (const char *name);
void SV_WriteClientdataToMessage (client_t *client, sizebuf_t *msg);
void SV_WriteClientdataToMessage (client_state_t *client, sizebuf_t *msg);
void SV_ExecuteUserCommand (char *s);
void SV_InitOperatorCommands (void);
void SV_SendServerinfo (client_t *client);
void SV_UserinfoChanged (client_t *cl);
void SV_SendServerinfo (client_state_t *client);
void SV_UserinfoChanged (client_state_t *cl);
void Master_Heartbeat (void);
void Master_Packet (void);
@ -260,7 +260,7 @@ void SV_FlushRedirect (int sv_redirected, char *outputbuf);
void SV_DemoCompleted (void);
void SV_SendClientMessages (void);
void SV_StartSound (vec3_t origin, edict_t *entity, int channel, int index, float vol, float attn, float timeofs);
void SV_ClientPrintf (client_t *cl, int level, char *fmt, ...);
void SV_ClientPrintf (client_state_t *cl, int level, char *fmt, ...);
void SV_BroadcastPrintf (int level, char *fmt, ...);
void SV_BroadcastCommand (char *fmt, ...);
@ -268,7 +268,7 @@ void SV_BroadcastCommand (char *fmt, ...);
// sv_user.c
//
void SV_Nextserver (void);
void SV_ExecuteClientMessage (client_t *cl);
void SV_ExecuteClientMessage (client_state_t *cl);
//
// sv_ccmds.c
@ -278,9 +278,9 @@ void SV_Status_f (void);
//
// sv_ents.c
//
void SV_WriteFrameToClient (client_t *client, sizebuf_t *msg);
void SV_WriteFrameToClient (client_state_t *client, sizebuf_t *msg);
void SV_RecordDemoMessage (void);
void SV_BuildClientFrame (client_t *client);
void SV_BuildClientFrame (client_state_t *client);
void SV_UpdateEntityState( edict_t *ent);
void SV_FatPVS ( vec3_t org );

View File

@ -92,7 +92,7 @@ Sets sv_client and sv_player to the player with idnum Cmd_Argv(1)
*/
bool SV_SetPlayer (void)
{
client_t *cl;
client_state_t *cl;
int i;
int idnum;
char *s;
@ -179,7 +179,7 @@ void SV_GameMap_f (void)
{
char *map;
int i;
client_t *cl;
client_state_t *cl;
bool *savedFree;
if (Cmd_Argc() != 2)
@ -371,7 +371,7 @@ SV_Status_f
void SV_Status_f (void)
{
int i, j, l;
client_t *cl;
client_state_t *cl;
char *s;
int ping;
if (!svs.clients)
@ -426,7 +426,7 @@ SV_ConSay_f
*/
void SV_ConSay_f(void)
{
client_t *client;
client_state_t *client;
int j;
char *p;
char text[1024];

View File

@ -288,7 +288,7 @@ void SV_WritePlayerstateToClient (client_frame_t *from, client_frame_t *to, size
SV_WriteFrameToClient
==================
*/
void SV_WriteFrameToClient (client_t *client, sizebuf_t *msg)
void SV_WriteFrameToClient (client_state_t *client, sizebuf_t *msg)
{
client_frame_t *frame, *oldframe;
int lastframe;
@ -396,7 +396,7 @@ Decides which entities are going to be visible to the client, and
copies off the playerstat and areabits.
=============
*/
void SV_BuildClientFrame (client_t *client)
void SV_BuildClientFrame (client_state_t *client)
{
int e, i;
vec3_t org;

View File

@ -151,7 +151,7 @@ clients along with it.
================
*/
void SV_SpawnServer (char *server, char *spawnpoint, char *savename, server_state_t serverstate, bool attractloop, bool loadgame)
void SV_SpawnServer (char *server, char *spawnpoint, char *savename, sv_state_t serverstate, bool attractloop, bool loadgame)
{
uint i, checksum;
@ -250,7 +250,7 @@ void SV_SpawnServer (char *server, char *spawnpoint, char *savename, server_stat
SV_CheckForSavegame ( savename );
// set serverinfo variable
Cvar_FullSet ("mapname", sv.name, CVAR_SERVERINFO | CVAR_NOSET);
Cvar_FullSet ("mapname", sv.name, CVAR_SERVERINFO | CVAR_INIT);
Msg ("-------------------------------------\n");
SV_VM_End();
@ -279,9 +279,6 @@ void SV_InitGame (void)
CL_Drop ();
SCR_BeginLoadingPlaque ();
}
// get any latched variable changes (maxclients, etc)
Cvar_GetLatchedVars ();
svs.initialized = true;
@ -318,7 +315,7 @@ void SV_InitGame (void)
}
svs.spawncount = rand();
svs.clients = Z_Malloc (sizeof(client_t)*maxclients->value);
svs.clients = Z_Malloc (sizeof(client_state_t)*maxclients->value);
svs.num_client_entities = maxclients->value*UPDATE_BACKUP*64;
svs.client_entities = Z_Malloc (sizeof(entity_state_t)*svs.num_client_entities);
svs.gclients = Z_Malloc(sizeof(gclient_t)*maxclients->value);
@ -422,7 +419,6 @@ void SV_Map (bool attractloop, char *levelstring, char *savename, bool loadgame)
SV_BroadcastCommand ("changing\n");
SV_SendClientMessages ();
SV_SpawnServer (level, spawnpoint, savename, ss_game, attractloop, loadgame);
Cbuf_CopyToDefer ();
}
SV_BroadcastCommand ("reconnect\n");
}

View File

@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
netadr_t master_adr[MAX_MASTERS]; // address of group servers
client_t *sv_client; // current client
client_state_t *sv_client; // current client
cvar_t *sv_paused;
cvar_t *sv_timedemo;
@ -95,7 +95,7 @@ or unwillingly. This is NOT called if the entire server is quiting
or crashing.
=====================
*/
void SV_DropClient (client_t *drop)
void SV_DropClient (client_state_t *drop)
{
// add the disconnect
MSG_WriteByte (&drop->netchan.message, svc_disconnect);
@ -138,7 +138,7 @@ char *SV_StatusString (void)
char player[1024];
static char status[MAX_MSGLEN - 16];
int i;
client_t *cl;
client_state_t *cl;
int statusLength;
int playerLength;
@ -290,8 +290,8 @@ void SVC_DirectConnect( void )
char userinfo[MAX_INFO_STRING];
netadr_t adr;
int i;
client_t *cl, *newcl;
client_t temp;
client_state_t *cl, *newcl;
client_state_t temp;
edict_t *ent;
int edictnum;
int version;
@ -351,7 +351,7 @@ void SVC_DirectConnect( void )
}
newcl = &temp;
memset (newcl, 0, sizeof(client_t));
memset (newcl, 0, sizeof(client_state_t));
// if there is already a slot for this ip, reuse it
for (i = 0, cl = svs.clients; i < maxclients->value; i++, cl++)
@ -390,7 +390,7 @@ void SVC_DirectConnect( void )
gotnewcl:
// build a new connection
// accept the new client
// this is the only place a client_t is ever initialized
// this is the only place a client_state_t is ever initialized
*newcl = temp;
sv_client = newcl;
edictnum = (newcl - svs.clients) + 1;
@ -491,7 +491,7 @@ void SV_ConnectionlessPacket (void)
s = MSG_ReadStringLine (&net_message);
Cmd_TokenizeString (s, false);
Cmd_TokenizeString(s);
c = Cmd_Argv(0);
MsgWarn("SV_ConnectionlessPacket: %s : %s\n", NET_AdrToString(net_from), c);
@ -519,7 +519,7 @@ Updates the cl->ping variables
void SV_CalcPings (void)
{
int i, j;
client_t *cl;
client_state_t *cl;
int total, count;
for (i=0 ; i<maxclients->value ; i++)
@ -571,7 +571,7 @@ for their command moves. If they exceed it, assume cheating.
void SV_GiveMsec (void)
{
int i;
client_t *cl;
client_state_t *cl;
if (sv.framenum & 15)
return;
@ -595,7 +595,7 @@ SV_ReadPackets
void SV_ReadPackets (void)
{
int i;
client_t *cl;
client_state_t *cl;
int qport;
while (NET_GetPacket (NS_SERVER, &net_from, &net_message))
@ -648,7 +648,7 @@ If a packet has not been received from a client for timeout->value
seconds, drop the conneciton. Server frames are used instead of
realtime to avoid dropping the local client while debugging.
When a client is normally dropped, the client_t goes into a zombie state
When a client is normally dropped, the client_state_t goes into a zombie state
for a few seconds to make sure any final reliable message gets resent
if necessary
==================
@ -656,7 +656,7 @@ if necessary
void SV_CheckTimeouts (void)
{
int i;
client_t *cl;
client_state_t *cl;
float droppoint;
float zombiepoint;
@ -900,7 +900,7 @@ Pull specific info from a newly changed userinfo string
into a more C freindly form.
=================
*/
void SV_UserinfoChanged (client_t *cl)
void SV_UserinfoChanged (client_state_t *cl)
{
char *val;
int i;
@ -959,7 +959,7 @@ void SV_Init (void)
Cvar_Get ("fraglimit", "0", CVAR_SERVERINFO);
Cvar_Get ("timelimit", "0", CVAR_SERVERINFO);
Cvar_Get ("cheats", "0", CVAR_SERVERINFO|CVAR_LATCH);
Cvar_Get ("protocol", va("%i", PROTOCOL_VERSION), CVAR_SERVERINFO|CVAR_NOSET);;
Cvar_Get ("protocol", va("%i", PROTOCOL_VERSION), CVAR_SERVERINFO|CVAR_INIT);
maxclients = Cvar_Get ("maxclients", "1", CVAR_SERVERINFO | CVAR_LATCH);
hostname = Cvar_Get ("hostname", "noname", CVAR_SERVERINFO | CVAR_ARCHIVE);
timeout = Cvar_Get ("timeout", "125", 0);
@ -1000,7 +1000,7 @@ to totally exit after returning from this function.
void SV_FinalMessage (char *message, bool reconnect)
{
int i;
client_t *cl;
client_state_t *cl;
SZ_Clear (&net_message);
MSG_WriteByte (&net_message, svc_print);

View File

@ -448,7 +448,7 @@ int SV_FlyMove (edict_t *ent, float time, float *stepnormal)
if (!trace.ent)
{
Con_Printf ("SV_FlyMove: !trace.ent");
Msg("SV_FlyMove: !trace.ent");
trace.ent = prog->edicts;
}
@ -1285,7 +1285,7 @@ void SV_WalkMove (edict_t *ent)
}
else
{
//Con_Printf("slope\n");
//Msgf("slope\n");
// if the push down didn't end up on good ground, use the move without
// the step up. This happens near wall / slope combinations, and can
// cause the player to hop up higher on a slope too steep to climb

View File

@ -198,7 +198,7 @@ void Sav_LoadCvars( lump_t *l )
{
pos = COM_UnpackString( in, pos, name );
pos = COM_UnpackString( in, pos, string );
Cvar_ForceSet (name, string);
Cvar_SetLatched(name, string);
}
}

View File

@ -63,7 +63,7 @@ SV_ClientPrintf
Sends text across to be displayed if the level passes
=================
*/
void SV_ClientPrintf (client_t *cl, int level, char *fmt, ...)
void SV_ClientPrintf (client_state_t *cl, int level, char *fmt, ...)
{
va_list argptr;
char string[1024];
@ -91,7 +91,7 @@ void SV_BroadcastPrintf (int level, char *fmt, ...)
{
va_list argptr;
char string[2048];
client_t *cl;
client_state_t *cl;
int i;
va_start (argptr,fmt);
@ -164,7 +164,7 @@ void _MSG_Send (msgtype_t to, vec3_t origin, edict_t *ent, const char *filename,
int leafnum = 0, cluster = 0;
int area1 = 0, area2 = 0;
int j, numclients = maxclients->value;
client_t *client, *current = svs.clients;
client_state_t *client, *current = svs.clients;
bool reliable = false;
/*if(origin == NULL || ent == NULL)
@ -393,7 +393,7 @@ FRAME UPDATES
SV_SendClientDatagram
=======================
*/
bool SV_SendClientDatagram (client_t *client)
bool SV_SendClientDatagram (client_state_t *client)
{
byte msg_buf[MAX_MSGLEN];
sizebuf_t msg;
@ -456,7 +456,7 @@ Returns true if the client is over its current
bandwidth estimation and should not be sent another packet
=======================
*/
bool SV_RateDrop (client_t *c)
bool SV_RateDrop (client_state_t *c)
{
int total;
int i;
@ -490,7 +490,7 @@ SV_SendClientMessages
void SV_SendClientMessages (void)
{
int i;
client_t *c;
client_state_t *c;
int msglen;
byte msgbuf[MAX_MSGLEN];

View File

@ -225,7 +225,7 @@ SV_Begin_f
void SV_Begin_f (void)
{
// handle the case of a level changing while a client was connecting
if ( atoi(Cmd_Argv(1)) != svs.spawncount )
if( atoi(Cmd_Argv(1)) != svs.spawncount )
{
Msg ("SV_Begin_f from different level\n");
SV_New_f ();
@ -236,7 +236,6 @@ void SV_Begin_f (void)
// call the game begin function
SV_ClientBegin(sv_player);
Cbuf_InsertFromDefer ();
}
//=============================================================================
@ -443,7 +442,7 @@ void SV_ExecuteUserCommand (char *s)
{
ucmd_t *u;
Cmd_TokenizeString (s, true);
Cmd_TokenizeString(s);
sv_player = sv_client->edict;
for (u = ucmds; u->name; u++)
@ -473,7 +472,7 @@ USER CMD EXECUTION
===========================================================================
*/
void SV_ClientThink (client_t *cl, usercmd_t *cmd)
void SV_ClientThink (client_state_t *cl, usercmd_t *cmd)
{
cl->commandMsec -= cmd->msec;
@ -494,7 +493,7 @@ The current net_message is parsed for the given client
*/
#define MAX_STRINGCMDS 8
void SV_ExecuteClientMessage (client_t *cl)
void SV_ExecuteClientMessage (client_state_t *cl)
{
int c;
char *s;

View File

@ -213,7 +213,7 @@ sprint(clientent, value)
*/
void PF_sprint (void)
{
client_t *client;
client_state_t *client;
int num;
char string[VM_STRINGTEMP_LENGTH];
@ -243,7 +243,7 @@ centerprint(clientent, value)
*/
void PF_centerprint (void)
{
client_t *client;
client_state_t *client;
int num;
char string[VM_STRINGTEMP_LENGTH];

View File

@ -372,7 +372,7 @@ sound_t S_RegisterSound( const char *name )
{
if( sfx->defaultSound )
{
MsgWarn("S_RegisterSound: could not find %s - using default\n", sfx->soundName );
MsgWarn("S_RegisterSound: could not find %s\n", sfx->soundName );
return 0;
}
return sfx - s_knownSfx;
@ -383,7 +383,7 @@ sound_t S_RegisterSound( const char *name )
if ( sfx->defaultSound )
{
MsgWarn("S_RegisterSound: could not find %s - using default\n", sfx->soundName );
MsgWarn("S_RegisterSound: could not find %s\n", sfx->soundName );
return 0;
}
return sfx - s_knownSfx;
@ -1322,7 +1322,8 @@ void S_StartBackgroundTrack( const char *intro, const char *loop )
if ( !loop || !loop[0] ) loop = intro;
MsgDev(D_INFO,"S_StartBackgroundTrack( %s, %s )\n", intro, loop );
strncpy( name, intro, sizeof( name ) - 4 );
FS_StripExtension( (char *)intro );
sprintf (name, "music/%s", intro );
FS_DefaultExtension( name, ".wav" );
if ( !intro[0] ) return;

View File

@ -65,29 +65,30 @@ DLL GLUE
*/
//==========================================================================
byte scantokey[128] =
static byte s_scantokey[128] =
{
// 0 1 2 3 4 5 6 7
// 8 9 A B C D E F
// 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
'7', '8', '9', '0', '-', '=', K_BACKSPACE, 9, // 0
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
'o', 'p', '[', ']', 13 , K_CTRL,'a', 's', // 1
'o', 'p', '[', ']', 13 , K_CTRL,'a', 's', // 1
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
'\'' , '`', K_SHIFT,'\\', 'z', 'x', 'c', 'v', // 2
'\'' , '`', 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_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, 0 , K_HOME,
K_UPARROW,K_PGUP,K_KP_MINUS,K_LEFTARROW,K_KP_5,K_RIGHTARROW, K_KP_PLUS,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
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, // 6
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 // 7
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 // 7
};
/*
=======
MapKey
@ -95,19 +96,29 @@ MapKey
Map from windows to quake keynums
=======
*/
int MapKey (int key)
static int MapKey (int key)
{
int result;
int modified = ( key >> 16 ) & 255;
bool is_extended = false;
int modified;
bool is_extended;
if ( modified > 127)
// Com_Printf( "0x%x\n", key);
modified = ( key >> 16 ) & 255;
if ( modified > 127 )
return 0;
if ( key & ( 1 << 24 ) )
{
is_extended = true;
}
else
{
is_extended = false;
}
result = scantokey[modified];
result = s_scantokey[modified];
if ( !is_extended )
{
@ -141,6 +152,8 @@ int MapKey (int key)
{
switch ( result )
{
case K_PAUSE:
return K_KP_NUMLOCK;
case 0x0D:
return K_KP_ENTER;
case 0x2F:
@ -324,6 +337,9 @@ LONG WINAPI MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_KEYUP:
Key_Event( MapKey( lParam ), false, host.sv_timer);
break;
case WM_CHAR:
CL_CharEvent( wParam );
break;
default: // pass all unhandled messages to DefWindowProc
return DefWindowProc (hWnd, uMsg, wParam, lParam);
}
@ -432,6 +448,16 @@ char *FS_Gamedir( void )
return GI.gamedir;
}
cvar_t *VID_Cvar_Get(const char *var_name, const char *value, int flags)
{
return _Cvar_Get(var_name, value, flags, "render variable" );
}
void VID_Cmd_AddCommand(const char *cmd_name, xcommand_t function)
{
_Cmd_AddCommand(cmd_name, function, "render command" );
}
char *FS_Title( void )
{
return GI.title;
@ -456,7 +482,7 @@ void VID_InitRender( void )
ri.Compile = Com->Compile;
ri.Stdio = Host_GetStdio( false );
ri.Cmd_AddCommand = Cmd_AddCommand;
ri.Cmd_AddCommand = VID_Cmd_AddCommand;
ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
ri.Cmd_Argc = Cmd_Argc;
ri.Cmd_Argv = Cmd_Argv;
@ -464,7 +490,7 @@ void VID_InitRender( void )
ri.gamedir = FS_Gamedir;
ri.title = FS_Title;
ri.Cvar_Get = Cvar_Get;
ri.Cvar_Get = VID_Cvar_Get;
ri.Cvar_Set = Cvar_Set;
ri.Cvar_SetValue = Cvar_SetValue;
ri.Vid_GetModeInfo = VID_GetModeInfo;

View File

@ -42,16 +42,20 @@
#define VectorToServer(v) { v[0] = METER2INCH(v[0]), v[1] = METER2INCH(v[1]), v[2] = METER2INCH(v[2]); }
#define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
#define VectorSubtract(a,b,c){c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
#define Vector4Subtract(a,b,c){c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];c[3]=a[3]-b[3];}
#define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
#define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
#define Vector4Copy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];}
#define VectorScale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale),(out)[2] = (in)[2] * (scale))
#define Vector4Scale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale),(out)[2] = (in)[2] * (scale),(out)[3] = (in)[3] * (scale))
#define VectorMultiply(a,b,c) ((c)[0]=(a)[0]*(b)[0],(c)[1]=(a)[1]*(b)[1],(c)[2]=(a)[2]*(b)[2])
#define VectorLength2(a) (DotProduct(a, a))
#define VectorDistance(a, b) (sqrt(VectorDistance2(a,b)))
#define VectorDistance2(a, b) (((a)[0] - (b)[0]) * ((a)[0] - (b)[0]) + ((a)[1] - (b)[1]) * ((a)[1] - (b)[1]) + ((a)[2] - (b)[2]) * ((a)[2] - (b)[2]))
#define VectorSet(v, x, y, z) {v[0] = x; v[1] = y; v[2] = z;}
#define Vector4Set(v, x, y, z, w) {v[0] = x; v[1] = y; v[2] = z; v[3] = w;}
#define Vector4Set(v, x, y, z, w) {v[0] = x, v[1] = y, v[2] = z, v[3] = w;}
#define VectorClear(x) {x[0] = x[1] = x[2] = 0;}
#define Vector4Clear(x) {x[0] = x[1] = x[2] = x[3] = 0;}
#define VectorNegate(x, y) {y[0] =-x[0]; y[1]=-x[1]; y[2]=-x[2];}
#define VectorM(scale1, b1, c) ((c)[0] = (scale1) * (b1)[0],(c)[1] = (scale1) * (b1)[1],(c)[2] = (scale1) * (b1)[2])
#define VectorMA(a, scale, b, c) ((c)[0] = (a)[0] + (scale) * (b)[0],(c)[1] = (a)[1] + (scale) * (b)[1],(c)[2] = (a)[2] + (scale) * (b)[2])
@ -219,27 +223,47 @@ _inline void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t u
angle = angles[PITCH] * (M_PI*2 / 360);
sp = sin(angle);
cp = cos(angle);
angle = angles[ROLL] * (M_PI*2 / 360);
sr = sin(angle);
cr = cos(angle);
if (forward)
{
forward[0] = cp*cy;
forward[1] = cp*sy;
forward[2] = -sp;
}
if (right)
if (right || up)
{
right[0] = (-1*sr*sp*cy+-1*cr*-sy);
right[1] = (-1*sr*sp*sy+-1*cr*cy);
right[2] = -1*sr*cp;
}
if (up)
{
up[0] = (cr*sp*cy+-sr*-sy);
up[1] = (cr*sp*sy+-sr*cy);
up[2] = cr*cp;
if (angles[ROLL])
{
angle = angles[ROLL] * (M_PI*2 / 360);
sr = sin(angle);
cr = cos(angle);
if (right)
{
right[0] = -1*(sr*sp*cy+cr*-sy);
right[1] = -1*(sr*sp*sy+cr*cy);
right[2] = -1*(sr*cp);
}
if (up)
{
up[0] = (cr*sp*cy+-sr*-sy);
up[1] = (cr*sp*sy+-sr*cy);
up[2] = cr*cp;
}
}
else
{
if (right)
{
right[0] = sy;
right[1] = -cy;
right[2] = 0;
}
if (up)
{
up[0] = (sp*cy);
up[1] = (sp*sy);
up[2] = cp;
}
}
}
}
@ -383,6 +407,14 @@ _inline void ResetRGBA( vec4_t in )
in[3] = 1.0f;
}
_inline float *GetRGBA( float r, float g, float b, float a )
{
static vec4_t color;
Vector4Set( color, r, g, b, a );
return color;
}
_inline vec_t ColorNormalize (vec3_t in, vec3_t out)
{
float max, scale;

View File

@ -26,6 +26,16 @@
#define MAX_INFO_VALUE 64
#define MAX_INFO_STRING 512
#define COLOR_BLACK '0'
#define COLOR_RED '1'
#define COLOR_GREEN '2'
#define COLOR_YELLOW '3'
#define COLOR_BLUE '4'
#define COLOR_CYAN '5'
#define COLOR_MAGENTA '6'
#define COLOR_WHITE '7'
#define ColorIndex(c) (((c) - '0') & 7)
#define STRING_COLOR_TAG '^'
#define IsColorString(p) ( p && *(p) == STRING_COLOR_TAG && *((p)+1) && *((p)+1) != STRING_COLOR_TAG )

View File

@ -520,28 +520,32 @@ typedef struct dll_info_s
#define CVAR_ARCHIVE 1 // set to cause it to be saved to vars.rc
#define CVAR_USERINFO 2 // added to userinfo when changed
#define CVAR_SERVERINFO 4 // added to serverinfo when changed
#define CVAR_NOSET 8 // don't allow change from console at all, but can be set from the command line
#define CVAR_LATCH 16 // save changes until server restart
#define CVAR_CHEAT 32 // marker for cheats
#define CVAR_MAXFLAGSVAL 63 // maximum number of flags
#define CVAR_SYSTEMINFO 8 // these cvars will be duplicated on all clients
#define CVAR_INIT 16 // don't allow change from console at all, but can be set from the command line
#define CVAR_LATCH 32 // save changes until server restart
#define CVAR_READ_ONLY 64 // display only, cannot be set by user at all
#define CVAR_USER_CREATED 128 // created by a set command (prvm used)
#define CVAR_TEMP 256 // can be set even when cheats are disabled, but is not archived
#define CVAR_CHEAT 512 // can not be changed if cheats are disabled
#define CVAR_NORESTART 1024 // do not clear when a cvar_restart is issued
#define CVAR_MAXFLAGSVAL 2047 // maximum number of flags
typedef struct cvar_s
{
int flags;
char *name;
char *reset_string; // cvar_restart will reset to this value
char *latched_string; // for CVAR_LATCH vars
char *description; // variable descrition info
int flags; // state flags
bool modified; // set each time the cvar is changed
int modificationCount; // incremented each time the cvar is changed
char *string;
char *description;
int integer;
float value;
float vector[3];
char *defstring;
char *string; // normal string
float value; // atof( string )
int integer; // atoi( string )
struct cvar_s *next;
struct cvar_s *hash;
char *latched_string; // for CVAR_LATCH vars
bool modified; // set each time the cvar is changed
} cvar_t;
typedef struct dlight_s
@ -869,6 +873,7 @@ typedef struct scriptsystem_api_s
bool (*MatchToken)( const char *match ); // compare current token with user keyword
char *(*ParseToken)(const char **data ); // parse token from char buffer
char *(*ParseWord)( const char **data ); // parse word from char buffer
bool (*FilterToken)(char *filter, char *name, int casecmp); // compare keyword by mask with filter
char *Token; // contains current token
} scriptsystem_api_t;
@ -1029,6 +1034,7 @@ typedef struct render_exp_s
// initialize
bool (*Init)( void *hInstance, void *WndProc ); // init all render systems
void (*Shutdown)( void ); // shutdown all render systems
void (*AppActivate)( bool activate ); // ??
void (*BeginRegistration) (char *map);
model_t *(*RegisterModel) (char *name);
@ -1039,25 +1045,24 @@ typedef struct render_exp_s
void (*RenderFrame) (refdef_t *fd);
void (*SetColor)( const float *rgba );
void (*DrawStretchRaw) (int x, int y, int w, int h, int cols, int rows, byte *data, bool redraw );
void (*DrawStretchPic)(float x, float y, float w, float h, float s1, float t1, float s2, float t2, char *name);
// get rid of this
void (*DrawGetPicSize) (int *w, int *h, char *name); // will return 0 0 if not found
void (*DrawPic) (int x, int y, char *name);
void (*DrawStretchPic) (int x, int y, int w, int h, char *name);
void (*DrawChar) (float x, float y, int c);
void (*DrawPic)(int x, int y, char *name);
void (*DrawChar)(float x, float y, int c);
void (*DrawString) (int x, int y, char *str);
void (*DrawTileClear) (int x, int y, int w, int h, char *name);
void (*DrawFill) (int x, int y, int w, int h, int c);
void (*DrawFill)(float x, float y, float w, float h );
void (*DrawFadeScreen) (void);
// Draw images for cinematic rendering (which can have a different palette). Note that calls
void (*DrawStretchRaw) (int x, int y, int w, int h, int cols, int rows, byte *data, bool dirty);
// video mode and refresh state management entry points
void (*CinematicSetPalette)( const byte *palette); // NULL = game palette
void (*BeginFrame)( float camera_separation );
void (*EndFrame) (void);
void (*AppActivate)( bool activate ); // ??
} render_exp_t;
typedef struct render_imp_s
@ -1086,7 +1091,7 @@ typedef struct render_imp_s
char *(*title) ( void );
cvar_t *(*Cvar_Get) (char *name, char *value, int flags);
cvar_t *(*Cvar_Set)( char *name, char *value );
void (*Cvar_Set)( char *name, char *value );
void (*Cvar_SetValue)( char *name, float value );
bool (*Vid_GetModeInfo)( int *width, int *height, int mode );

View File

@ -138,23 +138,28 @@ void Draw_GetPicSize (int *w, int *h, char *pic)
Draw_StretchPic
=============
*/
void Draw_StretchPic (int x, int y, int w, int h, char *pic)
void Draw_StretchPic (float x, float y, float w, float h, float s1, float t1, float s2, float t2, char *pic)
{
image_t *gl;
gl = Draw_FindPic (pic);
if (!gl) return;
if(!gl) return;
GL_Bind (gl->texnum[0]);
qglColor4fv(gl_state.draw_color);
GL_TexEnv( GL_MODULATE );
qglBegin (GL_QUADS);
qglTexCoord2f (0, 0);
qglTexCoord2f (s1, t1);
qglVertex2f (x, y);
qglTexCoord2f (1, 0);
qglTexCoord2f (s2, t1);
qglVertex2f (x+w, y);
qglTexCoord2f (1, 1);
qglTexCoord2f (s2, t2);
qglVertex2f (x+w, y+h);
qglTexCoord2f (0, 1);
qglTexCoord2f (s1, t2);
qglVertex2f (x, y+h);
qglEnd ();
}
@ -220,34 +225,19 @@ Draw_Fill
Fills a box of pixels with a single color
=============
*/
void Draw_Fill (int x, int y, int w, int h, int c)
void Draw_Fill(float x, float y, float w, float h)
{
union
{
unsigned c;
byte v[4];
} color;
if ((unsigned) c > 255)
{
Msg("Draw_Fill: bad color %i", c );
c = 255;
}
qglDisable (GL_TEXTURE_2D);
color.c = d_8to24table[c];
qglColor3f (color.v[0]/255.0, color.v[1]/255.0, color.v[2]/255.0);
qglColor4fv(gl_state.draw_color);
qglBegin (GL_QUADS);
qglVertex2f (x, y);
qglVertex2f (x + w, y);
qglVertex2f (x + w, y + h);
qglVertex2f (x, y + h);
qglVertex2f(x, y);
qglVertex2f(x + w, y);
qglVertex2f(x + w, y + h);
qglVertex2f(x, y + h);
qglEnd ();
qglColor3f (1,1,1);
qglEnd();
qglEnable (GL_TEXTURE_2D);
}
@ -299,6 +289,7 @@ void Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data
GL_TexFilter( false );
R_SetGL2D();
qglColor4fv(gl_state.draw_color);
qglBegin(GL_QUADS);
qglTexCoord2f( 0.5f / cols, 0.5f / rows );
qglVertex2f (x, y);

View File

@ -116,6 +116,17 @@ typedef struct
extern viddef_t vid;
#define MAX_RADAR_ENTS 1024
typedef struct radar_ent_s
{
vec4_t color;
vec3_t org;
vec3_t ang;
} radar_ent_t;
int numRadarEnts;
extern radar_ent_t RadarEnts[MAX_RADAR_ENTS];
typedef struct rect_s
{
int left;
@ -168,7 +179,6 @@ typedef struct image_s
};
#define TEXNUM_LIGHTMAPS 1024
#define TEXNUM_SCRAPS 1152
#define TEXNUM_IMAGES 1152
#define MAX_GLTEXTURES 1024
@ -210,11 +220,13 @@ typedef struct
//====================================================
extern image_t gltextures[MAX_GLTEXTURES];
extern int numgltextures;
extern int numgltextures;
extern image_t *r_notexture;
extern image_t *r_particletexture;
extern image_t *r_notexture;
extern image_t *r_particletexture;
extern image_t *r_radarmap;
extern image_t *r_around;
extern entity_t *currententity;
extern model_t *currentmodel;
extern int r_visframecount;
@ -267,6 +279,11 @@ extern cvar_t *gl_particle_att_a;
extern cvar_t *gl_particle_att_b;
extern cvar_t *gl_particle_att_c;
extern cvar_t *r_minimap;
extern cvar_t *r_minimap_size;
extern cvar_t *r_minimap_zoom;
extern cvar_t *r_minimap_style;
extern cvar_t *r_bloom;
extern cvar_t *r_bloom_alpha;
extern cvar_t *r_bloom_diamond_size;
@ -333,7 +350,8 @@ void GL_TexEnv( GLenum value );
void GL_EnableMultitexture( bool enable );
void GL_SelectTexture( GLenum );
void GL_TexFilter( GLboolean mipmap );
void GL_SetColor( const void *data );
void R_SetGL2D ( void );
void R_LightPoint (vec3_t p, vec3_t color);
void R_PushDlights (void);
@ -372,6 +390,7 @@ bool R_CullBox (vec3_t mins, vec3_t maxs);
void R_RotateForEntity (entity_t *e);
void R_MarkLeaves (void);
void GL_DrawRadar( void );
void R_BloomBlend ( refdef_t *fd );
void R_Bloom_InitTextures( void );
@ -398,11 +417,11 @@ void COM_FileBase (char *in, char *out);
void Draw_GetPicSize (int *w, int *h, char *name);
void Draw_Pic (int x, int y, char *name);
void Draw_StretchPic (int x, int y, int w, int h, char *name);
void Draw_StretchPic(float x, float y, float w, float h, float s1, float t1, float s2, float t2, char *pic);
void Draw_Char (float x, float y, int c);
void Draw_String (int x, int y, char *str);
void Draw_TileClear (int x, int y, int w, int h, char *name);
void Draw_Fill (int x, int y, int w, int h, int c);
void Draw_Fill(float x, float y, float w, float h );
void Draw_FadeScreen (void);
void Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data, bool dirty );
@ -471,7 +490,7 @@ typedef struct
int lightmap_textures;
int currenttextures[2];
int currenttmu;
int currenttmu;
float camera_separation;
bool stereo_enabled;
@ -493,9 +512,8 @@ typedef struct
bool nv_tex_rectangle;
bool ati_tex_rectangle;
byte originalRedGammaTable[256];
byte originalGreenGammaTable[256];
byte originalBlueGammaTable[256];
vec4_t draw_color; // using with Draw_* functions
} glstate_t;
extern glconfig_t gl_config;

View File

@ -44,9 +44,11 @@ float col_array[MAX_ARRAY][4];
image_t *r_notexture; // use for bad textures
image_t *r_particletexture;// little dot for particles
image_t *r_radarmap; // wall texture for radar texgen
image_t *r_around;
entity_t *currententity;
model_t *currentmodel;
model_t *currentmodel;
cplane_t frustum[4];
@ -105,6 +107,12 @@ cvar_t *gl_particle_att_a;
cvar_t *gl_particle_att_b;
cvar_t *gl_particle_att_c;
// doom1\2 style map, based on GLOOM radar code
cvar_t *r_minimap;
cvar_t *r_minimap_size;
cvar_t *r_minimap_zoom;
cvar_t *r_minimap_style;
cvar_t *gl_ext_swapinterval;
cvar_t *gl_ext_palettedtexture;
cvar_t *gl_ext_multitexture;
@ -537,6 +545,7 @@ void R_SetupFrame (void)
c_brush_polys = 0;
c_studio_polys = 0;
numRadarEnts = 0;
// clear out the portion of the screen that the NOWORLDMODEL defines
if ( r_newrefdef.rdflags & RDF_NOWORLDMODEL )
@ -698,7 +707,10 @@ void R_RenderView (refdef_t *fd)
R_DrawAlphaSurfaces ();
R_Flash();
R_BloomBlend (fd);
ri.ShowCollision();
GL_DrawRadar();
if(!( r_newrefdef.rdflags & RDF_NOWORLDMODEL ))
ri.ShowCollision(); //physic debug
}
void R_DrawPauseScreen( void )
@ -983,6 +995,11 @@ void R_Register( void )
r_bloom_sample_size = ri.Cvar_Get( "r_bloom_sample_size", "128", CVAR_ARCHIVE );
r_bloom_fast_sample = ri.Cvar_Get( "r_bloom_fast_sample", "0", CVAR_ARCHIVE );
r_minimap_size = ri.Cvar_Get ("r_minimap_size", "256", CVAR_ARCHIVE );
r_minimap_zoom = ri.Cvar_Get ("r_minimap_zoom", "1", CVAR_ARCHIVE );
r_minimap_style = ri.Cvar_Get ("r_minimap_style", "1", CVAR_ARCHIVE );
r_minimap = ri.Cvar_Get("r_minimap", "0", CVAR_ARCHIVE );
gl_modulate = ri.Cvar_Get ("gl_modulate", "1", CVAR_ARCHIVE );
gl_log = ri.Cvar_Get( "gl_log", "0", 0 );
gl_bitdepth = ri.Cvar_Get( "gl_bitdepth", "0", 0 );
@ -1554,12 +1571,6 @@ void R_RenderFrame (refdef_t *fd);
image_t *Draw_FindPic (char *name);
void Draw_Pic (int x, int y, char *name);
void Draw_Char (float x, float y, int c);
void Draw_TileClear (int x, int y, int w, int h, char *name);
void Draw_Fill (int x, int y, int w, int h, int c);
void Draw_FadeScreen (void);
/*
@@@@@@@@@@@@@@@@@@@@@
CreateAPI
@ -1597,6 +1608,7 @@ render_exp_t DLLEXPORT *CreateAPI(render_imp_t *rimp )
re.DrawFadeScreen= Draw_FadeScreen;
re.DrawStretchRaw = Draw_StretchRaw;
re.SetColor = GL_SetColor;
re.Init = R_Init;
re.Shutdown = R_Shutdown;

View File

@ -46,9 +46,8 @@ void R_InitParticleTexture (void)
rgbdata_t r_tex;
memset(&r_tex, 0, sizeof(r_tex));
//
// particle texture
//
for (x = 0; x < 8; x++)
{
for (y = 0; y < 8; y++)
@ -61,7 +60,7 @@ void R_InitParticleTexture (void)
}
r_tex.width = 8;
r_tex.height = 8;
r_tex.type = PF_RGBA_GN;
r_tex.type = PF_RGBA_GN; // generated
r_tex.flags = IMAGE_HAS_ALPHA;
r_tex.numMips = 1;
r_tex.palette = NULL;
@ -69,12 +68,10 @@ void R_InitParticleTexture (void)
r_particletexture = R_LoadImage("***particle***", &r_tex, it_sprite );
//
// also use this for bad textures, but without alpha
//
for (x = 0; x < 8; x++)
{
for (y=0 ; y<8 ; y++)
for (y = 0; y < 8; y++)
{
data[y][x][0] = dottexture[x&3][y&3]*255;
data[y][x][1] = 0; // dottexture[x&3][y&3]*255;
@ -85,6 +82,9 @@ void R_InitParticleTexture (void)
r_tex.flags &= ~IMAGE_HAS_ALPHA;// notexture don't have alpha
r_notexture = R_LoadImage("***r_notexture***", &r_tex, it_wall );
r_radarmap = R_FindImage("common/radarmap", NULL, 0, it_pic);
r_around = R_FindImage("common/around", NULL, 0, it_pic);
R_Bloom_InitTextures();
}

View File

@ -1526,3 +1526,296 @@ void GL_EndBuildingLightmaps (void)
GL_EnableMultitexture( false );
}
/*
========================
R_RecursiveRadarNode
========================
*/
void R_RecursiveRadarNode(mnode_t *node)
{
int i, c, side, sidebit;
cplane_t *plane;
msurface_t *surf, **mark;
mleaf_t *pleaf;
float *v, dot, distance;
glpoly_t *p;
if (node->contents == CONTENTS_SOLID) return; // solid
if(r_minimap_zoom->value >= 0.1)
{
distance = 1024.0/r_minimap_zoom->value;
}
else distance = 1024.0;
if( r_origin[0] + distance < node->minmaxs[0] || r_origin[0] - distance > node->minmaxs[3] || r_origin[1] + distance < node->minmaxs[1] || r_origin[1] - distance > node->minmaxs[4] || r_origin[2] + 256 < node->minmaxs[2] || r_origin[2] - 256 > node->minmaxs[5])
return;
// if a leaf node, draw stuff
if (node->contents != -1)
{
pleaf = (mleaf_t *)node;
// check for door connected areas
if (r_newrefdef.areabits)
{
// not visible
if(! (r_newrefdef.areabits[pleaf->area>>3] & (1<<(pleaf->area&7))))
return;
}
mark = pleaf->firstmarksurface;
c = pleaf->nummarksurfaces;
if(c)
{
do{
(*mark)->visframe = r_framecount;
mark++;
}while(--c);
}
return;
}
// node is just a decision point, so go down the apropriate sides
// find which side of the node we are on
plane = node->plane;
switch (plane->type)
{
case PLANE_X:
dot = modelorg[0] - plane->dist;
break;
case PLANE_Y:
dot = modelorg[1] - plane->dist;
break;
case PLANE_Z:
dot = modelorg[2] - plane->dist;
break;
default:
dot = DotProduct (modelorg, plane->normal) - plane->dist;
break;
}
if (dot >= 0)
{
side = 0;
sidebit = 0;
}
else
{
side = 1;
sidebit = SURF_PLANEBACK;
}
// recurse down the children, front side first
R_RecursiveRadarNode (node->children[side]);
if(plane->normal[2])
{
// draw stuff
if(plane->normal[2]>0) for ( c = node->numsurfaces, surf = r_worldmodel->surfaces + node->firstsurface; c;c--, surf++)
{
if (surf->texinfo->flags & SURF_SKY)
continue;
}
}
else
{
qglDisable(GL_TEXTURE_2D);
for ( c = node->numsurfaces, surf = r_worldmodel->surfaces + node->firstsurface; c; c--, surf++)
{
float sColor;
vec4_t C;
if (surf->texinfo->flags & SURF_SKY) continue;
if (surf->texinfo->flags & (SURF_WARP|SURF_FLOWING|SURF_TRANS33|SURF_TRANS66))
{
sColor=0.5;
}
else sColor=0;
for ( p = surf->polys; p; p = p->chain )
{
v = p->verts[0];
qglBegin(GL_LINE_STRIP);
for (i = 0; i < p->numverts; i++, v += VERTEXSIZE)
{
C[3] = (v[2] - r_origin[2]) / 512.0;
if(C[3] > 0)
{
Vector4Set(C, 0.5, 0.5 + sColor, 0.5, 1 - C[3]);
}
else
{
Vector4Set(C, 0.5, sColor, 0, 1 + C[3]);
}
if(C[3] < 0) C[3] = 0;
qglColor4fv(C);
qglVertex3fv (v);
}
qglEnd();
}
}
qglEnable(GL_TEXTURE_2D);
}
// recurse down the back side
R_RecursiveRadarNode (node->children[!side]);
}
int numRadarEnts = 0;
radar_ent_t RadarEnts[MAX_RADAR_ENTS];
void GL_DrawRadar( void )
{
int i;
vec4_t fS;
Vector4Set(fS, 0, 0, -1.0/512.0, 0 );
if(r_newrefdef.rdflags & RDF_NOWORLDMODEL ) return;
if(!r_minimap->value) return;
qglViewport(vid.width - r_minimap_size->value, 0, r_minimap_size->value, r_minimap_size->value );
qglDisable(GL_DEPTH_TEST);
qglMatrixMode(GL_PROJECTION);
qglPushMatrix();
qglLoadIdentity();
if(r_minimap_style->value) qglOrtho(-1024, 1024, -1024, 1024, -256, 256);
else qglOrtho(-1024, 1024, -512, 1536, -256, 256);
qglMatrixMode(GL_MODELVIEW);
qglPushMatrix();
qglLoadIdentity();
qglStencilMask(255);
qglClear(GL_STENCIL_BUFFER_BIT);
qglEnable(GL_STENCIL_TEST);
qglStencilFunc(GL_ALWAYS, 4, 4);
qglStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
GL_EnableAlphaTest();
qglAlphaFunc(GL_LESS, 0.1f);
qglColorMask(0, 0, 0, 0);
qglColor4f(1.0f, 1.0f, 1.0f, 1.0f);
GL_Bind(r_around->texnum[0]);
qglBegin(GL_TRIANGLE_FAN);
if(r_minimap_style->value)
{
qglTexCoord2f(0, 1);
qglVertex3f(1024, -1024, 1);
qglTexCoord2f(1, 1);
qglVertex3f(-1024, -1024, 1);
qglTexCoord2f(1, 0);
qglVertex3f(-1024, 1024, 1);
qglTexCoord2f(0, 0);
qglVertex3f(1024, 1024, 1);
}
else
{
qglTexCoord2f(0, 1);
qglVertex3f(1024, -512, 1);
qglTexCoord2f(1, 1);
qglVertex3f(-1024, -512, 1);
qglTexCoord2f(1, 0);
qglVertex3f(-1024, 1536, 1);
qglTexCoord2f(0, 0);
qglVertex3f(1024, 1536, 1);
}
qglEnd();
qglColorMask(1.0f, 1.0f, 1.0f, 1.0f);
GL_DisableAlphaTest();
qglAlphaFunc(GL_GREATER, 0.5f);
qglStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
qglStencilFunc(GL_NOTEQUAL, 4.0f, 4.0f);
if(r_minimap_zoom->value >= 0.1f)
{
qglScalef(r_minimap_zoom->value, r_minimap_zoom->value, r_minimap_zoom->value);
}
if(r_minimap_style->value)
{
qglPushMatrix();
qglRotatef(90.0f - r_newrefdef.viewangles[1], 0.0f, 0.0f, -1.0f);
qglDisable(GL_TEXTURE_2D);
qglBegin(GL_TRIANGLES);
qglColor4f(1.0f, 1.0f, 1.0f, 0.5f);
qglVertex3f(0.0f, 32.0f, 0.0f);
qglColor4f(1.0f, 1.0f, 0.0f, 0.5f);
qglVertex3f(24.0f, -32.0f, 0.0f);
qglVertex3f(-24.0f, -32.0f, 0.0f);
qglEnd();
qglPopMatrix();
}
else
{
qglDisable(GL_TEXTURE_2D);
qglBegin(GL_TRIANGLES);
qglColor4f(1.0f, 1.0f, 1.0f, 0.5f );
qglVertex3f(0.0f, 32.0f, 0.0f );
qglColor4f(1.0f, 1.0f, 0.0f, 0.5f );
qglVertex3f(24.0f, -32.0f, 0.0f );
qglVertex3f(-24.0f, -32.0f, 0.0f );
qglEnd();
qglRotatef (90.0f - r_newrefdef.viewangles[1], 0.0f, 0.0f, 1.0f);
}
qglTranslatef(-r_newrefdef.vieworg[0], -r_newrefdef.vieworg[1], -r_newrefdef.vieworg[2]);
if(r_minimap->value > 1)
{
qglBegin(GL_QUADS);
for(i = 0; i < numRadarEnts; i++)
{
vec3_t v;
VectorCopy(RadarEnts[i].org, v);
qglColor4fv(RadarEnts[i].color);
qglVertex3f(v[0] + 9, v[1] + 9, v[2]);
qglVertex3f(v[0] + 9, v[1] - 9, v[2]);
qglVertex3f(v[0] - 9, v[1] - 9, v[2]);
qglVertex3f(v[0] - 9, v[1] + 9, v[2]);
}
qglEnd();
}
qglEnable(GL_TEXTURE_2D);
GL_Bind(r_radarmap->texnum[0]);
qglBlendFunc(GL_SRC_ALPHA, GL_ONE);
GL_EnableBlend();
qglColor3f(1,1,1);
fS[3] = 0.5 + r_newrefdef.vieworg[2] / 512.0;
qglTexGenf(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
GL_EnableTexGen();
qglTexGenfv(GL_S, GL_OBJECT_PLANE, fS);
// draw the stuff
R_RecursiveRadarNode (r_worldmodel->nodes);
qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GL_DisableTexGen();
qglPopMatrix();
qglViewport(0.0f, 0.0f, vid.width, vid.height);
qglMatrixMode(GL_PROJECTION);
qglPopMatrix();
qglMatrixMode(GL_MODELVIEW);
qglDisable(GL_STENCIL_TEST);
qglStencilMask(0);
GL_TexEnv( GL_REPLACE );
GL_DisableBlend();
qglEnable(GL_DEPTH_TEST);
qglColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}

View File

@ -392,23 +392,24 @@ bool GLimp_InitGL (void)
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_GENERIC_ACCELERATED | // accelerated
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
int pixelformat;
cvar_t *stereo;

View File

@ -388,6 +388,26 @@ void GL_MBind( GLenum target, int texnum )
GL_Bind( texnum );
}
/*
=============
GL_SetColor
=============
*/
void GL_SetColor( const void *data )
{
float *color = (float *)data;
if(color)
{
Vector4Set(gl_state.draw_color, color[0], color[1], color[2], color[3] );
}
else
{
Vector4Set(gl_state.draw_color, 1.0f, 1.0f, 1.0f, 1.0f );
}
}
/*
===============
GL_SetDefaultState
@ -405,10 +425,12 @@ void GL_SetDefaultState( void )
qglDisable (GL_DEPTH_TEST);
qglDisable (GL_CULL_FACE);
qglDisable (GL_BLEND);
gl_state.blend=false;
gl_state.blend = false;
qglColor4f (1,1,1,1);
Vector4Set(gl_state.draw_color, 1.0f, 1.0f, 1.0f, 1.0f );
qglHint(GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
qglHint (GL_FOG_HINT, GL_FASTEST);
qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL);

View File

@ -1634,17 +1634,43 @@ void R_DrawStudioModel( int passnum )
if (m_pCurrentEntity->flags & RF_DEPTHHACK)
qglDepthRange (gldepthmin, gldepthmax);
if(r_minimap->value > 1)
{
if(numRadarEnts >= MAX_RADAR_ENTS) return;
if(currententity->flags & RF_VIEWERMODEL) return;
if(currententity->flags & RF_WEAPONMODEL) return;
if( currententity->flags & RF_GLOW)
{
RadarEnts[numRadarEnts].color[0]= 0.0;
RadarEnts[numRadarEnts].color[1]= 1.0;
RadarEnts[numRadarEnts].color[2]= 0.0;
RadarEnts[numRadarEnts].color[3]= 0.5;
}
/*else if( currententity->flags & RF2_MONSTER)
{
Vector4Set(RadarEnts[numRadarEnts].color, 1.0f, 0.0f, 2.0f, 1.0f );
}*/
else
{
Vector4Set(RadarEnts[numRadarEnts].color, 0.0f, 1.0f, 1.0f, 0.5f );
}
VectorCopy(currententity->origin, RadarEnts[numRadarEnts].org);
VectorCopy(currententity->angles, RadarEnts[numRadarEnts].ang);
numRadarEnts++;
}
if (gl_shadows->value && !(m_pCurrentEntity->flags & (RF_TRANSLUCENT | RF_WEAPONMODEL)))
{
qglPushMatrix();
R_RotateForEntity(m_pCurrentEntity);
qglDisable (GL_TEXTURE_2D);
qglEnable (GL_BLEND);
qglColor4f (0, 0, 0, 0.5f );
qglColor4f (0.0f, 0.0f, 0.0f, 0.5f );
R_StudioDrawShadow();
qglEnable (GL_TEXTURE_2D);
qglDisable (GL_BLEND);
qglPopMatrix ();
}
qglColor4f (1,1,1,1);
qglColor4f(1.0f, 1.0f, 1.0f, 1.0f );
}

View File

@ -1651,7 +1651,7 @@ image_t *R_LoadImage(char *name, rgbdata_t *pic, imagetype_t type )
byte *buf;
//nothing to load
if (!pic || !pic->buffer) return NULL;
if (!pic || !pic->buffer) return r_notexture;
// find a free image_t
for (i = 0, image = gltextures; i < numgltextures; i++, image++)