mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-10 07:21:58 +00:00
console.c, gl_vidsdl.c, host_cmd.c, in_sdl.c, main.c, menu.c, net_sdl.c,
net_sdlnet.c, sys_sdl.c: a lot of space-to-tab whitespace tidy-ups in the files created or touched by the SDL port. no actual code change. git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@43 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
80d77aaaf6
commit
ec3801107d
9 changed files with 876 additions and 879 deletions
|
@ -111,7 +111,7 @@ void Con_ToggleConsole_f (void)
|
|||
{
|
||||
if (cls.state == ca_connected)
|
||||
{
|
||||
IN_Activate();
|
||||
IN_Activate();
|
||||
key_dest = key_game;
|
||||
key_lines[edit_line][1] = 0; // clear any typing
|
||||
key_linepos = 1;
|
||||
|
@ -124,10 +124,10 @@ void Con_ToggleConsole_f (void)
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
{
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_console;
|
||||
}
|
||||
}
|
||||
|
||||
SCR_EndLoadingPlaque ();
|
||||
memset (con_times, 0, sizeof(con_times));
|
||||
|
@ -1104,7 +1104,7 @@ void Con_NotifyBox (char *text)
|
|||
Con_Printf (Con_Quakebar(40)); //johnfitz
|
||||
|
||||
key_count = -2; // wait for a key down and up
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_console;
|
||||
|
||||
do
|
||||
|
@ -1117,7 +1117,7 @@ void Con_NotifyBox (char *text)
|
|||
} while (key_count < 0);
|
||||
|
||||
Con_Printf ("\n");
|
||||
IN_Activate();
|
||||
IN_Activate();
|
||||
key_dest = key_game;
|
||||
realtime = 0; // put the cursor back to invisible
|
||||
}
|
||||
|
|
|
@ -24,15 +24,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "quakedef.h"
|
||||
#include "resource.h"
|
||||
|
||||
#define MAX_MODE_LIST 600 //johnfitz -- was 30
|
||||
#define VID_ROW_SIZE 3
|
||||
#define WARP_WIDTH 320
|
||||
#define WARP_HEIGHT 200
|
||||
#define MAXWIDTH 10000
|
||||
#define MAXHEIGHT 10000
|
||||
#define BASEWIDTH 320
|
||||
#define BASEHEIGHT 200
|
||||
#define SDL_DEFAULT_FLAGS SDL_OPENGL
|
||||
#define MAX_MODE_LIST 600 //johnfitz -- was 30
|
||||
#define VID_ROW_SIZE 3
|
||||
#define WARP_WIDTH 320
|
||||
#define WARP_HEIGHT 200
|
||||
#define MAXWIDTH 10000
|
||||
#define MAXHEIGHT 10000
|
||||
#define BASEWIDTH 320
|
||||
#define BASEHEIGHT 200
|
||||
|
||||
#define SDL_DEFAULT_FLAGS SDL_OPENGL
|
||||
|
||||
typedef struct {
|
||||
modestate_t type;
|
||||
|
@ -75,7 +76,7 @@ static qboolean windowed, leavecurrentmode;
|
|||
static qboolean vid_canalttab = false;
|
||||
extern qboolean mouseactive; // from in_win.c
|
||||
|
||||
SDL_Surface *draw_context;
|
||||
SDL_Surface *draw_context;
|
||||
|
||||
int vid_modenum = NO_MODE;
|
||||
int vid_realmode;
|
||||
|
@ -146,10 +147,6 @@ cvar_t vid_gamma = {"gamma", "1", true}; //johnfitz -- moved here from view.c
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
//typedef int (WINAPI * RAMPFUNC)();
|
||||
//RAMPFUNC wglGetDeviceGammaRamp3DFX;
|
||||
//RAMPFUNC wglSetDeviceGammaRamp3DFX;
|
||||
|
||||
unsigned short vid_gamma_red[256];
|
||||
unsigned short vid_gamma_green[256];
|
||||
unsigned short vid_gamma_blue[256];
|
||||
|
@ -167,9 +164,9 @@ VID_Gamma_SetGamma -- apply gamma correction
|
|||
*/
|
||||
void VID_Gamma_SetGamma (void)
|
||||
{
|
||||
if (draw_context && vid_gammaworks)
|
||||
if (SDL_SetGammaRamp(&vid_gamma_red[0], &vid_gamma_green[0], &vid_gamma_blue[0]) == -1)
|
||||
Con_Printf ("VID_Gamma_SetGamma: failed on SDL_SetGammaRamp\n");
|
||||
if (draw_context && vid_gammaworks)
|
||||
if (SDL_SetGammaRamp(&vid_gamma_red[0], &vid_gamma_green[0], &vid_gamma_blue[0]) == -1)
|
||||
Con_Printf ("VID_Gamma_SetGamma: failed on SDL_SetGammaRamp\n");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -179,9 +176,9 @@ VID_Gamma_Restore -- restore system gamma
|
|||
*/
|
||||
void VID_Gamma_Restore (void)
|
||||
{
|
||||
if (draw_context && vid_gammaworks)
|
||||
if (SDL_SetGammaRamp(&vid_sysgamma_red[0], &vid_sysgamma_green[0], &vid_sysgamma_blue[0]) == -1)
|
||||
Con_Printf ("VID_Gamma_Restore: failed on SDL_SetGammaRamp\n");
|
||||
if (draw_context && vid_gammaworks)
|
||||
if (SDL_SetGammaRamp(&vid_sysgamma_red[0], &vid_sysgamma_green[0], &vid_sysgamma_blue[0]) == -1)
|
||||
Con_Printf ("VID_Gamma_Restore: failed on SDL_SetGammaRamp\n");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -209,11 +206,11 @@ void VID_Gamma_f (void)
|
|||
|
||||
oldgamma = vid_gamma.value;
|
||||
|
||||
for (i=0; i<256; i++)
|
||||
{
|
||||
vid_gamma_red[i] = CLAMP(0, (int) (255 * pow ((i+0.5)/255.5, vid_gamma.value) + 0.5), 255) << 8;
|
||||
vid_gamma_green[i] = vid_gamma_red[i];
|
||||
vid_gamma_blue[i] = vid_gamma_red[i];
|
||||
for (i=0; i<256; i++)
|
||||
{
|
||||
vid_gamma_red[i] = CLAMP(0, (int) (255 * pow ((i+0.5)/255.5, vid_gamma.value) + 0.5), 255) << 8;
|
||||
vid_gamma_green[i] = vid_gamma_red[i];
|
||||
vid_gamma_blue[i] = vid_gamma_red[i];
|
||||
}
|
||||
|
||||
VID_Gamma_SetGamma ();
|
||||
|
@ -246,7 +243,7 @@ int VID_SetMode (int modenum)
|
|||
Uint32 flags = SDL_DEFAULT_FLAGS;
|
||||
char caption[50];
|
||||
|
||||
//TODO: check if video mode is supported using SDL_VideoModeOk
|
||||
// TODO: check if video mode is supported using SDL_VideoModeOk
|
||||
if ((windowed && (modenum != 0)) ||
|
||||
(!windowed && (modenum < 1)) ||
|
||||
(!windowed && (modenum >= nummodes)))
|
||||
|
@ -260,7 +257,7 @@ int VID_SetMode (int modenum)
|
|||
|
||||
CDAudio_Pause ();
|
||||
|
||||
// set vertical sync
|
||||
// set vertical sync
|
||||
if (gl_swap_control)
|
||||
{
|
||||
if (vid_vsync.value)
|
||||
|
@ -275,44 +272,49 @@ int VID_SetMode (int modenum)
|
|||
}
|
||||
}
|
||||
|
||||
if (modelist[modenum].type == MODE_WINDOWED)
|
||||
{
|
||||
if (modelist[modenum].type == MODE_WINDOWED)
|
||||
{
|
||||
if (_windowed_mouse.value && key_dest == key_game)
|
||||
{
|
||||
draw_context = SDL_SetVideoMode(modelist[modenum].width, modelist[modenum].height, modelist[modenum].bpp, flags);
|
||||
stat = true;
|
||||
draw_context = SDL_SetVideoMode(modelist[modenum].width,
|
||||
modelist[modenum].height,
|
||||
modelist[modenum].bpp, flags);
|
||||
stat = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_context = SDL_SetVideoMode(modelist[modenum].width, modelist[modenum].height, modelist[modenum].bpp, flags);
|
||||
stat = true;
|
||||
draw_context = SDL_SetVideoMode(modelist[modenum].width,
|
||||
modelist[modenum].height,
|
||||
modelist[modenum].bpp, flags);
|
||||
stat = true;
|
||||
}
|
||||
modestate = MODE_WINDOWED;
|
||||
// TODO set icon and title
|
||||
}
|
||||
else if (modelist[modenum].type == MODE_FULLSCREEN_DEFAULT)
|
||||
modestate = MODE_WINDOWED;
|
||||
// TODO set icon and title
|
||||
}
|
||||
else if (modelist[modenum].type == MODE_FULLSCREEN_DEFAULT)
|
||||
{
|
||||
flags |= SDL_FULLSCREEN;
|
||||
draw_context = SDL_SetVideoMode(modelist[modenum].width, modelist[modenum].height, modelist[modenum].bpp, flags);
|
||||
|
||||
stat = true;
|
||||
modestate = MODE_FULLSCREEN_DEFAULT;
|
||||
flags |= SDL_FULLSCREEN;
|
||||
draw_context = SDL_SetVideoMode(modelist[modenum].width,
|
||||
modelist[modenum].height,
|
||||
modelist[modenum].bpp, flags);
|
||||
stat = true;
|
||||
modestate = MODE_FULLSCREEN_DEFAULT;
|
||||
}
|
||||
else
|
||||
{
|
||||
Sys_Error ("VID_SetMode: Bad mode type in modelist");
|
||||
}
|
||||
|
||||
//kristian -- set window caption
|
||||
sprintf(caption, "FitzQuake (SDL port) Version %1.2f", FITZQUAKE_VERSION);
|
||||
SDL_WM_SetCaption((const char* )&caption, (const char*)&caption);
|
||||
//kristian -- set window caption
|
||||
sprintf(caption, "FitzQuake (SDL port) Version %1.2f", FITZQUAKE_VERSION);
|
||||
SDL_WM_SetCaption((const char* )&caption, (const char*)&caption);
|
||||
|
||||
vid.width = modelist[modenum].width;
|
||||
vid.height = modelist[modenum].height;
|
||||
vid.conwidth = vid.width & 0xFFFFFFF8;
|
||||
vid.conheight = vid.conwidth * vid.height / vid.width;
|
||||
vid.numpages = 2;
|
||||
vid.type = modelist[modenum].type;
|
||||
vid.conwidth = vid.width & 0xFFFFFFF8;
|
||||
vid.conheight = vid.conwidth * vid.height / vid.width;
|
||||
vid.numpages = 2;
|
||||
vid.type = modelist[modenum].type;
|
||||
|
||||
VID_UpdateWindowStatus ();
|
||||
|
||||
|
@ -326,7 +328,7 @@ int VID_SetMode (int modenum)
|
|||
|
||||
vid_modenum = modenum;
|
||||
|
||||
// fix the leftover Alt from any Alt-Tab or the like that switched us away
|
||||
// fix the leftover Alt from any Alt-Tab or the like that switched us away
|
||||
ClearAllStates ();
|
||||
|
||||
if (!msg_suppress_1)
|
||||
|
@ -334,12 +336,12 @@ int VID_SetMode (int modenum)
|
|||
|
||||
vid.recalc_refdef = 1;
|
||||
|
||||
// with SDL, this needs to be done every time the render context is recreated, so I moved it here
|
||||
// with SDL, this needs to be done every time the render context is recreated, so I moved it here
|
||||
TexMgr_ReloadImages ();
|
||||
GL_SetupState ();
|
||||
|
||||
// no pending changes
|
||||
vid_changed = false;
|
||||
// no pending changes
|
||||
vid_changed = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -351,7 +353,7 @@ VID_Changed_f -- kristian -- notify us that a value has changed that requires a
|
|||
*/
|
||||
void VID_Changed_f (void)
|
||||
{
|
||||
vid_changed = true;
|
||||
vid_changed = true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -370,75 +372,75 @@ void VID_Restart (void)
|
|||
//
|
||||
// decide which mode to set
|
||||
//
|
||||
oldmode = modelist[vid_default];
|
||||
oldmode = modelist[vid_default];
|
||||
|
||||
if (vid_fullscreen.value)
|
||||
{
|
||||
for (i=1; i<nummodes; i++)
|
||||
{
|
||||
if (modelist[i].width == (int)vid_width.value &&
|
||||
modelist[i].height == (int)vid_height.value &&
|
||||
modelist[i].bpp == (int)vid_bpp.value)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (vid_fullscreen.value)
|
||||
{
|
||||
for (i=1; i<nummodes; i++)
|
||||
{
|
||||
if (modelist[i].width == (int)vid_width.value &&
|
||||
modelist[i].height == (int)vid_height.value &&
|
||||
modelist[i].bpp == (int)vid_bpp.value)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == nummodes)
|
||||
{
|
||||
Con_Printf ("%dx%dx%d %dHz is not a valid fullscreen mode\n",
|
||||
(int)vid_width.value,
|
||||
(int)vid_height.value,
|
||||
(int)vid_bpp.value,
|
||||
(int)vid_refreshrate.value);
|
||||
return;
|
||||
}
|
||||
if (i == nummodes)
|
||||
{
|
||||
Con_Printf ("%dx%dx%d %dHz is not a valid fullscreen mode\n",
|
||||
(int)vid_width.value,
|
||||
(int)vid_height.value,
|
||||
(int)vid_bpp.value,
|
||||
(int)vid_refreshrate.value);
|
||||
return;
|
||||
}
|
||||
|
||||
windowed = false;
|
||||
vid_default = i;
|
||||
}
|
||||
else //not fullscreen
|
||||
{
|
||||
if (vid_width.value < 320)
|
||||
{
|
||||
Con_Printf ("Window width can't be less than 320\n");
|
||||
return;
|
||||
}
|
||||
windowed = false;
|
||||
vid_default = i;
|
||||
}
|
||||
else //not fullscreen
|
||||
{
|
||||
if (vid_width.value < 320)
|
||||
{
|
||||
Con_Printf ("Window width can't be less than 320\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (vid_height.value < 200)
|
||||
{
|
||||
Con_Printf ("Window height can't be less than 200\n");
|
||||
return;
|
||||
}
|
||||
if (vid_height.value < 200)
|
||||
{
|
||||
Con_Printf ("Window height can't be less than 200\n");
|
||||
return;
|
||||
}
|
||||
|
||||
modelist[0].width = (int)vid_width.value;
|
||||
modelist[0].height = (int)vid_height.value;
|
||||
sprintf (modelist[0].modedesc, "%dx%dx%d",
|
||||
modelist[0].width,
|
||||
modelist[0].height,
|
||||
modelist[0].bpp);
|
||||
modelist[0].width = (int)vid_width.value;
|
||||
modelist[0].height = (int)vid_height.value;
|
||||
sprintf (modelist[0].modedesc, "%dx%dx%d",
|
||||
modelist[0].width,
|
||||
modelist[0].height,
|
||||
modelist[0].bpp);
|
||||
|
||||
windowed = true;
|
||||
vid_default = 0;
|
||||
}
|
||||
//
|
||||
// set new mode
|
||||
//
|
||||
VID_SetMode (vid_default);
|
||||
windowed = true;
|
||||
vid_default = 0;
|
||||
}
|
||||
//
|
||||
// set new mode
|
||||
//
|
||||
VID_SetMode (vid_default);
|
||||
|
||||
vid_canalttab = true;
|
||||
vid_canalttab = true;
|
||||
|
||||
// Clear menu pic cache
|
||||
Draw_ClearMenuPicCache ();
|
||||
//warpimages needs to be recalculated
|
||||
TexMgr_RecalcWarpImageSize ();
|
||||
// Clear menu pic cache
|
||||
Draw_ClearMenuPicCache ();
|
||||
//warpimages needs to be recalculated
|
||||
TexMgr_RecalcWarpImageSize ();
|
||||
|
||||
//conwidth and conheight need to be recalculated
|
||||
vid.conwidth = (scr_conwidth.value > 0) ? (int)scr_conwidth.value : vid.width;
|
||||
vid.conwidth = CLAMP (320, vid.conwidth, vid.width);
|
||||
vid.conwidth &= 0xFFFFFFF8;
|
||||
vid.conheight = vid.conwidth * vid.height / vid.width;
|
||||
//
|
||||
//conwidth and conheight need to be recalculated
|
||||
vid.conwidth = (scr_conwidth.value > 0) ? (int)scr_conwidth.value : vid.width;
|
||||
vid.conwidth = CLAMP (320, vid.conwidth, vid.width);
|
||||
vid.conwidth &= 0xFFFFFFF8;
|
||||
vid.conheight = vid.conwidth * vid.height / vid.width;
|
||||
//
|
||||
// keep cvars in line with actual mode
|
||||
//
|
||||
Cvar_Set ("vid_width", va("%i", modelist[vid_default].width));
|
||||
|
@ -573,9 +575,9 @@ void CheckArrayExtensions (void)
|
|||
if (strncmp((const char*)tmp, "GL_EXT_vertex_array", strlen("GL_EXT_vertex_array")) == 0)
|
||||
{
|
||||
if (((glArrayElementEXT = SDL_GL_GetProcAddress("glArrayElementEXT")) == NULL) ||
|
||||
((glColorPointerEXT = SDL_GL_GetProcAddress("glColorPointerEXT")) == NULL) ||
|
||||
((glTexCoordPointerEXT = SDL_GL_GetProcAddress("glTexCoordPointerEXT")) == NULL) ||
|
||||
((glVertexPointerEXT = SDL_GL_GetProcAddress("glVertexPointerEXT")) == NULL) )
|
||||
((glColorPointerEXT = SDL_GL_GetProcAddress("glColorPointerEXT")) == NULL) ||
|
||||
((glTexCoordPointerEXT = SDL_GL_GetProcAddress("glTexCoordPointerEXT")) == NULL) ||
|
||||
((glVertexPointerEXT = SDL_GL_GetProcAddress("glVertexPointerEXT")) == NULL) )
|
||||
{
|
||||
Sys_Error ("GetProcAddress for vertex extension failed");
|
||||
return;
|
||||
|
@ -595,7 +597,7 @@ GL_CheckExtensions -- johnfitz
|
|||
*/
|
||||
void GL_CheckExtensions (void)
|
||||
{
|
||||
int swap_control;
|
||||
int swap_control;
|
||||
|
||||
//
|
||||
// multitexture
|
||||
|
@ -677,28 +679,32 @@ void GL_CheckExtensions (void)
|
|||
Con_Warning ("texture_env_add not supported\n");
|
||||
#endif
|
||||
|
||||
//
|
||||
//
|
||||
// swap control
|
||||
//
|
||||
if (strstr(gl_extensions, "GL_EXT_swap_control"))
|
||||
{
|
||||
if (SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0) == -1) {
|
||||
Con_Printf("WARNING: vertical sync not supported (SDL_GL_SetAttribute failed)\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &swap_control) == -1) {
|
||||
Con_Printf("WARNING: vertical sync not supported (SDL_GL_GetAttribute failed). Make sure you don't have vertical sync disabled in your driver settings.\n");
|
||||
} else if (swap_control == -1) {
|
||||
// TODO: check if this is correct - I don't know what SDL returns if vertical sync is disabled
|
||||
Con_Printf("WARNING: vertical sync not supported (swap interval is -1.) Make sure you don't have vertical sync disabled in your driver settings.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Con_Printf("FOUND: WGL_EXT_swap_control\n");
|
||||
gl_swap_control = true;
|
||||
}
|
||||
}
|
||||
if (SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0) == -1)
|
||||
{
|
||||
Con_Printf("WARNING: vertical sync not supported (SDL_GL_SetAttribute failed)\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &swap_control) == -1)
|
||||
{
|
||||
Con_Printf("WARNING: vertical sync not supported (SDL_GL_GetAttribute failed). Make sure you don't have vertical sync disabled in your driver settings.\n");
|
||||
}
|
||||
else if (swap_control == -1)
|
||||
{
|
||||
// TODO: check if this is correct - I don't know what SDL returns if vertical sync is disabled
|
||||
Con_Printf("WARNING: vertical sync not supported (swap interval is -1.) Make sure you don't have vertical sync disabled in your driver settings.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Con_Printf("FOUND: WGL_EXT_swap_control\n");
|
||||
gl_swap_control = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
Con_Printf ("WARNING: vertical sync not supported (extension not found)\n");
|
||||
|
@ -709,7 +715,7 @@ void GL_CheckExtensions (void)
|
|||
if (strstr(gl_extensions, "GL_EXT_texture_filter_anisotropic"))
|
||||
{
|
||||
float test1,test2;
|
||||
GLuint tex;
|
||||
GLuint tex;
|
||||
|
||||
// test to make sure we really have control over it
|
||||
// 1.0 and 2.0 should always be legal values
|
||||
|
@ -783,11 +789,10 @@ void GL_Init (void)
|
|||
|
||||
Cvar_RegisterVariable (&vid_vsync, VID_Changed_f); //johnfitz
|
||||
|
||||
if (SDL_strncasecmp(gl_renderer,"PowerVR",7)==0)
|
||||
fullsbardraw = true;
|
||||
|
||||
if (SDL_strncasecmp(gl_renderer,"Permedia",8)==0)
|
||||
isPermedia = true;
|
||||
if (SDL_strncasecmp(gl_renderer,"PowerVR",7)==0)
|
||||
fullsbardraw = true;
|
||||
if (SDL_strncasecmp(gl_renderer,"Permedia",8)==0)
|
||||
isPermedia = true;
|
||||
#if 1
|
||||
//johnfitz -- intel video workarounds from Baker
|
||||
if (!strcmp(gl_vendor, "Intel"))
|
||||
|
@ -830,7 +835,7 @@ GL_EndRendering
|
|||
void GL_EndRendering (void)
|
||||
{
|
||||
if (!scr_skipupdate || block_drawing)
|
||||
SDL_GL_SwapBuffers();
|
||||
SDL_GL_SwapBuffers();
|
||||
|
||||
if (fullsbardraw)
|
||||
Sbar_Changed();
|
||||
|
@ -848,10 +853,10 @@ void VID_Shutdown (void)
|
|||
vid_canalttab = false;
|
||||
VID_Gamma_Shutdown (); //johnfitz
|
||||
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
draw_context = NULL;
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
draw_context = NULL;
|
||||
|
||||
PL_VID_Shutdown();
|
||||
PL_VID_Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1006,9 +1011,9 @@ VID_DescribeModes_f -- johnfitz -- changed formatting, and added refresh rates a
|
|||
*/
|
||||
void VID_DescribeModes_f (void)
|
||||
{
|
||||
int i, lnummodes, t;
|
||||
int i, lnummodes, t;
|
||||
vmode_t *pv;
|
||||
int lastwidth=0, lastheight=0, lastbpp=0, count=0;
|
||||
int lastwidth=0, lastheight=0, lastbpp=0, count=0;
|
||||
|
||||
lnummodes = VID_NumModes ();
|
||||
|
||||
|
@ -1045,9 +1050,9 @@ void VID_DescribeModes_f (void)
|
|||
VID_InitDIB
|
||||
=================
|
||||
*/
|
||||
void VID_InitDIB ()
|
||||
void VID_InitDIB (void)
|
||||
{
|
||||
const SDL_VideoInfo *info;
|
||||
const SDL_VideoInfo *info;
|
||||
|
||||
modelist[0].type = MODE_WINDOWED;
|
||||
|
||||
|
@ -1067,8 +1072,8 @@ void VID_InitDIB ()
|
|||
if (modelist[0].height < 200) //johnfitz -- was 240
|
||||
modelist[0].height = 200; //johnfitz -- was 240
|
||||
|
||||
info = SDL_GetVideoInfo();
|
||||
modelist[0].bpp = info->vfmt->BitsPerPixel;
|
||||
info = SDL_GetVideoInfo();
|
||||
modelist[0].bpp = info->vfmt->BitsPerPixel;
|
||||
|
||||
sprintf (modelist[0].modedesc, "%dx%dx%d", //johnfitz -- added bpp
|
||||
modelist[0].width,
|
||||
|
@ -1088,83 +1093,83 @@ void VID_InitDIB ()
|
|||
VID_InitFullDIB
|
||||
=================
|
||||
*/
|
||||
void VID_InitFullDIB ()
|
||||
void VID_InitFullDIB (void)
|
||||
{
|
||||
SDL_PixelFormat format;
|
||||
SDL_Rect **modes;
|
||||
Uint32 flags;
|
||||
int i, j, k, modenum, originalnummodes, existingmode;
|
||||
int bpps[3] = {16, 24, 32}; // enumerate >8 bpp modes
|
||||
SDL_PixelFormat format;
|
||||
SDL_Rect **modes;
|
||||
Uint32 flags;
|
||||
int i, j, k, modenum, originalnummodes, existingmode;
|
||||
int bpps[3] = {16, 24, 32}; // enumerate >8 bpp modes
|
||||
|
||||
originalnummodes = nummodes;
|
||||
modenum = 0;
|
||||
format.palette = NULL;
|
||||
format.palette = NULL;
|
||||
|
||||
// enumerate fullscreen modes
|
||||
flags = SDL_DEFAULT_FLAGS | SDL_FULLSCREEN;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if (nummodes >= MAX_MODE_LIST)
|
||||
break;
|
||||
// enumerate fullscreen modes
|
||||
flags = SDL_DEFAULT_FLAGS | SDL_FULLSCREEN;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if (nummodes >= MAX_MODE_LIST)
|
||||
break;
|
||||
|
||||
format.BitsPerPixel = bpps[i];
|
||||
modes = SDL_ListModes(&format, flags);
|
||||
format.BitsPerPixel = bpps[i];
|
||||
modes = SDL_ListModes(&format, flags);
|
||||
|
||||
if (modes == (SDL_Rect **)0 || modes == (SDL_Rect **)-1)
|
||||
continue;
|
||||
if (modes == (SDL_Rect **)0 || modes == (SDL_Rect **)-1)
|
||||
continue;
|
||||
|
||||
for (j = 0; modes[j]; j++)
|
||||
{
|
||||
if (modes[j]->w > MAXWIDTH || modes[j]->h > MAXHEIGHT || nummodes >= MAX_MODE_LIST)
|
||||
continue;
|
||||
for (j = 0; modes[j]; j++)
|
||||
{
|
||||
if (modes[j]->w > MAXWIDTH || modes[j]->h > MAXHEIGHT || nummodes >= MAX_MODE_LIST)
|
||||
continue;
|
||||
|
||||
modelist[nummodes].type = MODE_FULLSCREEN_DEFAULT;
|
||||
modelist[nummodes].width = modes[j]->w;
|
||||
modelist[nummodes].height = modes[j]->h;
|
||||
modelist[nummodes].modenum = 0;
|
||||
modelist[nummodes].halfscreen = 0;
|
||||
modelist[nummodes].dib = 1;
|
||||
modelist[nummodes].fullscreen = 1;
|
||||
modelist[nummodes].bpp = bpps[i];
|
||||
modelist[nummodes].type = MODE_FULLSCREEN_DEFAULT;
|
||||
modelist[nummodes].width = modes[j]->w;
|
||||
modelist[nummodes].height = modes[j]->h;
|
||||
modelist[nummodes].modenum = 0;
|
||||
modelist[nummodes].halfscreen = 0;
|
||||
modelist[nummodes].dib = 1;
|
||||
modelist[nummodes].fullscreen = 1;
|
||||
modelist[nummodes].bpp = bpps[i];
|
||||
|
||||
sprintf (modelist[nummodes].modedesc, "%dx%dx%d",
|
||||
modelist[nummodes].width,
|
||||
modelist[nummodes].height,
|
||||
modelist[nummodes].bpp); //johnfitz -- refreshrate
|
||||
sprintf (modelist[nummodes].modedesc, "%dx%dx%d",
|
||||
modelist[nummodes].width,
|
||||
modelist[nummodes].height,
|
||||
modelist[nummodes].bpp); //johnfitz -- refreshrate
|
||||
|
||||
// if the width is more than twice the height, reduce it by half because this
|
||||
// is probably a dual-screen monitor
|
||||
if (!COM_CheckParm("-noadjustaspect"))
|
||||
{
|
||||
if (modelist[nummodes].width > (modelist[nummodes].height << 1))
|
||||
{
|
||||
modelist[nummodes].width >>= 1;
|
||||
modelist[nummodes].halfscreen = 1;
|
||||
sprintf (modelist[nummodes].modedesc, "%dx%dx%d",
|
||||
modelist[nummodes].width,
|
||||
modelist[nummodes].height,
|
||||
modelist[nummodes].bpp);
|
||||
}
|
||||
}
|
||||
// if the width is more than twice the height, reduce it by half because this
|
||||
// is probably a dual-screen monitor
|
||||
if (!COM_CheckParm("-noadjustaspect"))
|
||||
{
|
||||
if (modelist[nummodes].width > (modelist[nummodes].height << 1))
|
||||
{
|
||||
modelist[nummodes].width >>= 1;
|
||||
modelist[nummodes].halfscreen = 1;
|
||||
sprintf (modelist[nummodes].modedesc, "%dx%dx%d",
|
||||
modelist[nummodes].width,
|
||||
modelist[nummodes].height,
|
||||
modelist[nummodes].bpp);
|
||||
}
|
||||
}
|
||||
|
||||
for (k=originalnummodes, existingmode = 0 ; k < nummodes ; k++)
|
||||
{
|
||||
if ((modelist[nummodes].width == modelist[k].width) &&
|
||||
(modelist[nummodes].height == modelist[k].height) &&
|
||||
(modelist[nummodes].bpp == modelist[k].bpp))
|
||||
{
|
||||
existingmode = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (k=originalnummodes, existingmode = 0 ; k < nummodes ; k++)
|
||||
{
|
||||
if ((modelist[nummodes].width == modelist[k].width) &&
|
||||
(modelist[nummodes].height == modelist[k].height) &&
|
||||
(modelist[nummodes].bpp == modelist[k].bpp))
|
||||
{
|
||||
existingmode = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!existingmode)
|
||||
{
|
||||
nummodes++;
|
||||
}
|
||||
}
|
||||
if (!existingmode)
|
||||
{
|
||||
nummodes++;
|
||||
}
|
||||
}
|
||||
modenum++;
|
||||
}
|
||||
}
|
||||
|
||||
if (nummodes == originalnummodes)
|
||||
Con_SafePrintf ("No fullscreen DIB modes found\n");
|
||||
|
@ -1177,10 +1182,10 @@ VID_Init
|
|||
*/
|
||||
void VID_Init (void)
|
||||
{
|
||||
const SDL_VideoInfo *info;
|
||||
int i, existingmode;
|
||||
int basenummodes, width, height, bpp, findbpp, done;
|
||||
char gldir[MAX_OSPATH];
|
||||
const SDL_VideoInfo *info;
|
||||
int i, existingmode;
|
||||
int basenummodes, width, height, bpp, findbpp, done;
|
||||
char gldir[MAX_OSPATH];
|
||||
|
||||
//johnfitz -- clean up init readouts
|
||||
//Con_Printf("------------- Init Video -------------\n");
|
||||
|
@ -1200,12 +1205,10 @@ void VID_Init (void)
|
|||
Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f);
|
||||
Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f);
|
||||
|
||||
//InitCommonControls();
|
||||
if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
|
||||
Sys_Error("Could not initialize SDL Video");
|
||||
|
||||
if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
|
||||
Sys_Error("Could not initialize SDL Video");
|
||||
|
||||
SDL_putenv("SDL_VIDEO_CENTERED=center");
|
||||
SDL_putenv("SDL_VIDEO_CENTERED=center");
|
||||
|
||||
VID_InitDIB();
|
||||
basenummodes = nummodes = 1;
|
||||
|
@ -1236,7 +1239,7 @@ void VID_Init (void)
|
|||
{
|
||||
if (COM_CheckParm("-current"))
|
||||
{
|
||||
info = SDL_GetVideoInfo();
|
||||
info = SDL_GetVideoInfo();
|
||||
modelist[MODE_FULLSCREEN_DEFAULT].width = info->current_w;
|
||||
modelist[MODE_FULLSCREEN_DEFAULT].height = info->current_h;
|
||||
vid_default = MODE_FULLSCREEN_DEFAULT;
|
||||
|
@ -1375,8 +1378,8 @@ void VID_Init (void)
|
|||
vid.colormap = host_colormap;
|
||||
vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
|
||||
|
||||
// set window icon
|
||||
PL_SetWindowIcon();
|
||||
// set window icon
|
||||
PL_SetWindowIcon();
|
||||
|
||||
VID_SetMode (vid_default);
|
||||
GL_Init ();
|
||||
|
@ -1443,15 +1446,15 @@ VID_SyncCvars -- johnfitz -- set vid cvars to match current video mode
|
|||
*/
|
||||
void VID_SyncCvars (void)
|
||||
{
|
||||
int swap_control;
|
||||
int swap_control;
|
||||
|
||||
Cvar_Set ("vid_width", va("%i", modelist[vid_default].width));
|
||||
Cvar_Set ("vid_height", va("%i", modelist[vid_default].height));
|
||||
Cvar_Set ("vid_bpp", va("%i", modelist[vid_default].bpp));
|
||||
Cvar_Set ("vid_fullscreen", (windowed) ? "0" : "1");
|
||||
|
||||
if (SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &swap_control) == 0)
|
||||
Cvar_Set ("vid_vsync", (swap_control) ? "1" : "0");
|
||||
if (SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &swap_control) == 0)
|
||||
Cvar_Set ("vid_vsync", (swap_control) ? "1" : "0");
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -1732,10 +1735,10 @@ void VID_MenuKey (int key)
|
|||
Cbuf_AddText ("toggle vid_fullscreen\n");
|
||||
break;
|
||||
case 4:
|
||||
Cbuf_AddText ("toggle vid_vsync\n"); // kristian
|
||||
break;
|
||||
Cbuf_AddText ("toggle vid_vsync\n"); // kristian
|
||||
break;
|
||||
case 5:
|
||||
case 6:
|
||||
case 6:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1758,10 +1761,10 @@ void VID_MenuKey (int key)
|
|||
Cbuf_AddText ("toggle vid_fullscreen\n");
|
||||
break;
|
||||
case 4:
|
||||
Cbuf_AddText ("toggle vid_vsync\n");
|
||||
break;
|
||||
Cbuf_AddText ("toggle vid_vsync\n");
|
||||
break;
|
||||
case 5:
|
||||
case 6:
|
||||
case 6:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1791,9 +1794,9 @@ void VID_MenuKey (int key)
|
|||
break;
|
||||
case 6:
|
||||
Cbuf_AddText ("vid_restart\n");
|
||||
key_dest = key_game;
|
||||
m_state = m_none;
|
||||
IN_Activate();
|
||||
key_dest = key_game;
|
||||
m_state = m_none;
|
||||
IN_Activate();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1844,12 +1847,12 @@ void VID_MenuDraw (void)
|
|||
M_DrawCheckbox (216, video_cursor_table[i], (int)vid_fullscreen.value);
|
||||
i++;
|
||||
|
||||
// added vsync to the video menu -- kristian
|
||||
// added vsync to the video menu -- kristian
|
||||
M_Print (16, video_cursor_table[i], " Vertical Sync");
|
||||
if (gl_swap_control)
|
||||
M_DrawCheckbox (216, video_cursor_table[i], (int)vid_vsync.value);
|
||||
else
|
||||
M_Print (216, video_cursor_table[i], "N/A");
|
||||
if (gl_swap_control)
|
||||
M_DrawCheckbox (216, video_cursor_table[i], (int)vid_vsync.value);
|
||||
else
|
||||
M_Print (216, video_cursor_table[i], "N/A");
|
||||
|
||||
i++;
|
||||
|
||||
|
|
129
Quake/host_cmd.c
129
Quake/host_cmd.c
|
@ -252,14 +252,14 @@ void ExtraMaps_Add (char *name)
|
|||
|
||||
void ExtraMaps_Init (void)
|
||||
{
|
||||
DIR *dir_p;
|
||||
struct dirent *dir_t;
|
||||
DIR *dir_p;
|
||||
struct dirent *dir_t;
|
||||
char filestring[MAX_OSPATH];
|
||||
char mapname[32];
|
||||
char ignorepakdir[32];
|
||||
searchpath_t *search;
|
||||
pack_t *pak;
|
||||
int i;
|
||||
searchpath_t *search;
|
||||
pack_t *pak;
|
||||
int i;
|
||||
|
||||
//we don't want to list the maps in id1 pakfiles, becuase these are not "add-on" levels
|
||||
sprintf (ignorepakdir, "/%s/", GAMENAME);
|
||||
|
@ -269,32 +269,34 @@ void ExtraMaps_Init (void)
|
|||
if (*search->filename) //directory
|
||||
{
|
||||
sprintf (filestring,"%s/maps/",search->filename);
|
||||
dir_p = opendir(filestring);
|
||||
|
||||
if (dir_p == NULL)
|
||||
continue;
|
||||
|
||||
while ((dir_t = readdir(dir_p)) != NULL)
|
||||
{
|
||||
if (!strstr(dir_t->d_name, ".bsp") && !strstr(dir_t->d_name, ".BSP"))
|
||||
continue;
|
||||
|
||||
dir_p = opendir(filestring);
|
||||
if (dir_p == NULL)
|
||||
continue;
|
||||
while ((dir_t = readdir(dir_p)) != NULL)
|
||||
{
|
||||
if (!strstr(dir_t->d_name, ".bsp") && !strstr(dir_t->d_name, ".BSP"))
|
||||
continue;
|
||||
COM_StripExtension(dir_t->d_name, mapname);
|
||||
ExtraMaps_Add (mapname);
|
||||
}
|
||||
|
||||
closedir(dir_p);
|
||||
}
|
||||
closedir(dir_p);
|
||||
}
|
||||
else //pakfile
|
||||
{
|
||||
if (!strstr(search->pack->filename, ignorepakdir)) //don't list standard id maps
|
||||
{
|
||||
for (i=0, pak=search->pack; i<pak->numfiles ; i++)
|
||||
{
|
||||
if (strstr(pak->files[i].name, ".bsp"))
|
||||
{
|
||||
if (pak->files[i].filelen > 32*1024) // don't list files under 32k (ammo boxes etc)
|
||||
{
|
||||
COM_StripExtension(pak->files[i].name + 5, mapname);
|
||||
ExtraMaps_Add (mapname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -382,60 +384,51 @@ void Modlist_Add (char *name)
|
|||
|
||||
void Modlist_Init (void)
|
||||
{
|
||||
DIR *dir_p, *mod_dir_p;
|
||||
struct dirent *dir_t, *mod_dir_t;
|
||||
qboolean progs_found, pak_found;
|
||||
DIR *dir_p, *mod_dir_p;
|
||||
struct dirent *dir_t, *mod_dir_t;
|
||||
qboolean progs_found, pak_found;
|
||||
char dir_string[MAX_OSPATH], mod_dir_string[MAX_OSPATH];
|
||||
int i;
|
||||
int i;
|
||||
|
||||
i = COM_CheckParm ("-basedir");
|
||||
if (i && i < com_argc-1)
|
||||
sprintf (dir_string, "%s/", com_argv[i+1]);
|
||||
else
|
||||
sprintf (dir_string, "%s/", host_parms.basedir);
|
||||
|
||||
dir_p = opendir(dir_string);
|
||||
if (dir_p == NULL)
|
||||
return;
|
||||
sprintf (dir_string, "%s/", com_argv[i+1]);
|
||||
else
|
||||
sprintf (dir_string, "%s/", host_parms.basedir);
|
||||
|
||||
while ((dir_t = readdir(dir_p)) != NULL)
|
||||
{
|
||||
if ((strcmp(dir_t->d_name, ".") == 0) || (strcmp(dir_t->d_name, "..") == 0))
|
||||
continue;
|
||||
|
||||
sprintf(mod_dir_string, "%s%s/", dir_string, dir_t->d_name);
|
||||
mod_dir_p = opendir(mod_dir_string);
|
||||
|
||||
if (mod_dir_p == NULL)
|
||||
continue;
|
||||
|
||||
progs_found = false;
|
||||
pak_found = false;
|
||||
|
||||
// find progs.dat and pak file(s)
|
||||
while ((mod_dir_t = readdir(mod_dir_p)) != NULL)
|
||||
{
|
||||
if ((strcmp(mod_dir_t->d_name, ".") == 0) || (strcmp(mod_dir_t->d_name, "..") == 0))
|
||||
continue;
|
||||
|
||||
if (Q_strcasecmp(mod_dir_t->d_name, "progs.dat") != -1)
|
||||
progs_found = true;
|
||||
|
||||
if (strstr(mod_dir_t->d_name, ".pak") || strstr(mod_dir_t->d_name, ".PAK"))
|
||||
pak_found = true;
|
||||
|
||||
if (progs_found || pak_found)
|
||||
break;
|
||||
}
|
||||
closedir(mod_dir_p);
|
||||
|
||||
if (!progs_found && !pak_found)
|
||||
continue;
|
||||
|
||||
Modlist_Add(dir_t->d_name);
|
||||
}
|
||||
|
||||
closedir(dir_p);
|
||||
dir_p = opendir(dir_string);
|
||||
if (dir_p == NULL)
|
||||
return;
|
||||
|
||||
while ((dir_t = readdir(dir_p)) != NULL)
|
||||
{
|
||||
if ((strcmp(dir_t->d_name, ".") == 0) || (strcmp(dir_t->d_name, "..") == 0))
|
||||
continue;
|
||||
sprintf(mod_dir_string, "%s%s/", dir_string, dir_t->d_name);
|
||||
mod_dir_p = opendir(mod_dir_string);
|
||||
if (mod_dir_p == NULL)
|
||||
continue;
|
||||
progs_found = false;
|
||||
pak_found = false;
|
||||
// find progs.dat and pak file(s)
|
||||
while ((mod_dir_t = readdir(mod_dir_p)) != NULL)
|
||||
{
|
||||
if ((strcmp(mod_dir_t->d_name, ".") == 0) || (strcmp(mod_dir_t->d_name, "..") == 0))
|
||||
continue;
|
||||
if (Q_strcasecmp(mod_dir_t->d_name, "progs.dat") != -1)
|
||||
progs_found = true;
|
||||
if (strstr(mod_dir_t->d_name, ".pak") || strstr(mod_dir_t->d_name, ".PAK"))
|
||||
pak_found = true;
|
||||
if (progs_found || pak_found)
|
||||
break;
|
||||
}
|
||||
closedir(mod_dir_p);
|
||||
if (!progs_found && !pak_found)
|
||||
continue;
|
||||
Modlist_Add(dir_t->d_name);
|
||||
}
|
||||
|
||||
closedir(dir_p);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -824,7 +817,7 @@ void Host_Map_f (void)
|
|||
CL_Disconnect ();
|
||||
Host_ShutdownServer(false);
|
||||
|
||||
IN_Activate();
|
||||
IN_Activate();
|
||||
key_dest = key_game; // remove console or menu
|
||||
SCR_BeginLoadingPlaque ();
|
||||
|
||||
|
|
182
Quake/in_sdl.c
182
Quake/in_sdl.c
|
@ -31,81 +31,82 @@ int total_dx, total_dy = 0;
|
|||
|
||||
int FilterMouseEvents (const SDL_Event *event)
|
||||
{
|
||||
switch (event->type) {
|
||||
case SDL_MOUSEMOTION:
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
switch (event->type)
|
||||
{
|
||||
case SDL_MOUSEMOTION:
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void IN_Activate (void)
|
||||
{
|
||||
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_ON)
|
||||
{
|
||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_ON)
|
||||
Con_Printf("WARNING: SDL_WM_GrabInput(SDL_GRAB_ON) failed.\n");
|
||||
}
|
||||
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_ON)
|
||||
{
|
||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_ON)
|
||||
Con_Printf("WARNING: SDL_WM_GrabInput(SDL_GRAB_ON) failed.\n");
|
||||
}
|
||||
|
||||
if (SDL_ShowCursor(SDL_QUERY) != SDL_DISABLE)
|
||||
{
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
if (SDL_ShowCursor(SDL_QUERY) != SDL_DISABLE)
|
||||
Con_Printf("WARNING: SDL_ShowCursor(SDL_DISABLE) failed.\n");
|
||||
}
|
||||
if (SDL_ShowCursor(SDL_QUERY) != SDL_DISABLE)
|
||||
{
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
if (SDL_ShowCursor(SDL_QUERY) != SDL_DISABLE)
|
||||
Con_Printf("WARNING: SDL_ShowCursor(SDL_DISABLE) failed.\n");
|
||||
}
|
||||
|
||||
if (SDL_GetEventFilter() != NULL)
|
||||
SDL_SetEventFilter(NULL);
|
||||
|
||||
total_dx = 0;
|
||||
total_dy = 0;
|
||||
if (SDL_GetEventFilter() != NULL)
|
||||
SDL_SetEventFilter(NULL);
|
||||
|
||||
total_dx = 0;
|
||||
total_dy = 0;
|
||||
}
|
||||
|
||||
void IN_Deactivate (qboolean free_cursor)
|
||||
{
|
||||
if (free_cursor)
|
||||
{
|
||||
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_OFF)
|
||||
{
|
||||
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
||||
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_OFF)
|
||||
Con_Printf("WARNING: SDL_WM_GrabInput(SDL_GRAB_OFF) failed.\n");
|
||||
}
|
||||
if (free_cursor)
|
||||
{
|
||||
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_OFF)
|
||||
{
|
||||
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
||||
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_OFF)
|
||||
Con_Printf("WARNING: SDL_WM_GrabInput(SDL_GRAB_OFF) failed.\n");
|
||||
}
|
||||
|
||||
if (SDL_ShowCursor(SDL_QUERY) != SDL_ENABLE)
|
||||
{
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
if (SDL_ShowCursor(SDL_QUERY) != SDL_ENABLE)
|
||||
Con_Printf("WARNING: SDL_ShowCursor(SDL_ENABLE) failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
// discard all mouse events when input is deactivated
|
||||
if (SDL_GetEventFilter() != FilterMouseEvents)
|
||||
SDL_SetEventFilter(FilterMouseEvents);
|
||||
if (SDL_ShowCursor(SDL_QUERY) != SDL_ENABLE)
|
||||
{
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
if (SDL_ShowCursor(SDL_QUERY) != SDL_ENABLE)
|
||||
Con_Printf("WARNING: SDL_ShowCursor(SDL_ENABLE) failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
// discard all mouse events when input is deactivated
|
||||
if (SDL_GetEventFilter() != FilterMouseEvents)
|
||||
SDL_SetEventFilter(FilterMouseEvents);
|
||||
}
|
||||
|
||||
void IN_Init (void)
|
||||
{
|
||||
BuildKeyMaps();
|
||||
|
||||
if (SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL) == -1)
|
||||
Con_Printf("Warning: SDL_EnableKeyRepeat() failed.\n");
|
||||
|
||||
IN_Activate();
|
||||
BuildKeyMaps();
|
||||
|
||||
if (SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL) == -1)
|
||||
Con_Printf("Warning: SDL_EnableKeyRepeat() failed.\n");
|
||||
|
||||
IN_Activate();
|
||||
}
|
||||
|
||||
void IN_Shutdown (void)
|
||||
{
|
||||
IN_Deactivate(true);
|
||||
IN_Deactivate(true);
|
||||
}
|
||||
|
||||
void IN_Commands (void)
|
||||
{
|
||||
// TODO: implement this for joystick support
|
||||
// TODO: implement this for joystick support
|
||||
}
|
||||
|
||||
extern cvar_t cl_maxpitch; //johnfitz -- variable pitch clamping
|
||||
|
@ -114,55 +115,56 @@ extern cvar_t cl_minpitch; //johnfitz -- variable pitch clamping
|
|||
|
||||
void IN_MouseMove(int dx, int dy)
|
||||
{
|
||||
total_dx += dx;
|
||||
total_dy += dy;
|
||||
total_dx += dx;
|
||||
total_dy += dy;
|
||||
}
|
||||
|
||||
void IN_Move (usercmd_t *cmd)
|
||||
{
|
||||
int dmx, dmy;
|
||||
int dmx, dmy;
|
||||
|
||||
/* TODO: fix this
|
||||
if (m_filter.value)
|
||||
{
|
||||
dmx = (2*mx - dmx) * 0.5;
|
||||
dmy = (2*my - dmy) * 0.5;
|
||||
}
|
||||
*/
|
||||
/* TODO: fix this
|
||||
if (m_filter.value)
|
||||
{
|
||||
dmx = (2*mx - dmx) * 0.5;
|
||||
dmy = (2*my - dmy) * 0.5;
|
||||
}
|
||||
*/
|
||||
|
||||
dmx = total_dx * sensitivity.value;
|
||||
dmy = total_dy * sensitivity.value;
|
||||
|
||||
total_dx = 0;
|
||||
total_dy = 0;
|
||||
dmx = total_dx * sensitivity.value;
|
||||
dmy = total_dy * sensitivity.value;
|
||||
|
||||
if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
|
||||
cmd->sidemove += m_side.value * dmx;
|
||||
else
|
||||
cl.viewangles[YAW] -= m_yaw.value * dmx;
|
||||
total_dx = 0;
|
||||
total_dy = 0;
|
||||
|
||||
if (in_mlook.state & 1)
|
||||
V_StopPitchDrift ();
|
||||
if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
|
||||
cmd->sidemove += m_side.value * dmx;
|
||||
else
|
||||
cl.viewangles[YAW] -= m_yaw.value * dmx;
|
||||
|
||||
if ( (in_mlook.state & 1) && !(in_strafe.state & 1))
|
||||
{
|
||||
cl.viewangles[PITCH] += m_pitch.value * dmy;
|
||||
//johnfitz -- variable pitch clamping
|
||||
if (cl.viewangles[PITCH] > cl_maxpitch.value)
|
||||
cl.viewangles[PITCH] = cl_maxpitch.value;
|
||||
if (cl.viewangles[PITCH] < cl_minpitch.value)
|
||||
cl.viewangles[PITCH] = cl_minpitch.value;
|
||||
//johnfitz
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((in_strafe.state & 1) && noclip_anglehack)
|
||||
cmd->upmove -= m_forward.value * dmy;
|
||||
else
|
||||
cmd->forwardmove -= m_forward.value * dmy;
|
||||
}
|
||||
if (in_mlook.state & 1)
|
||||
V_StopPitchDrift ();
|
||||
|
||||
if ( (in_mlook.state & 1) && !(in_strafe.state & 1))
|
||||
{
|
||||
cl.viewangles[PITCH] += m_pitch.value * dmy;
|
||||
//johnfitz -- variable pitch clamping
|
||||
if (cl.viewangles[PITCH] > cl_maxpitch.value)
|
||||
cl.viewangles[PITCH] = cl_maxpitch.value;
|
||||
if (cl.viewangles[PITCH] < cl_minpitch.value)
|
||||
cl.viewangles[PITCH] = cl_minpitch.value;
|
||||
//johnfitz
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((in_strafe.state & 1) && noclip_anglehack)
|
||||
cmd->upmove -= m_forward.value * dmy;
|
||||
else
|
||||
cmd->forwardmove -= m_forward.value * dmy;
|
||||
}
|
||||
}
|
||||
|
||||
void IN_ClearStates (void)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
220
Quake/main.c
220
Quake/main.c
|
@ -26,133 +26,133 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Event event;
|
||||
quakeparms_t parms;
|
||||
int t;
|
||||
int done = 0;
|
||||
double time, oldtime, newtime;
|
||||
SDL_Event event;
|
||||
quakeparms_t parms;
|
||||
int t;
|
||||
int done = 0;
|
||||
double time, oldtime, newtime;
|
||||
|
||||
parms.basedir = ".";
|
||||
parms.cachedir = NULL;
|
||||
parms.basedir = ".";
|
||||
parms.cachedir = NULL;
|
||||
|
||||
parms.argc = argc;
|
||||
parms.argv = argv;
|
||||
parms.argc = argc;
|
||||
parms.argv = argv;
|
||||
|
||||
COM_InitArgv(parms.argc, parms.argv);
|
||||
COM_InitArgv(parms.argc, parms.argv);
|
||||
|
||||
isDedicated = (COM_CheckParm("-dedicated") != 0);
|
||||
isDedicated = (COM_CheckParm("-dedicated") != 0);
|
||||
|
||||
// default memory size
|
||||
parms.memsize = DEFAULT_MEMORY;
|
||||
// default memory size
|
||||
parms.memsize = DEFAULT_MEMORY;
|
||||
|
||||
if (COM_CheckParm("-heapsize"))
|
||||
{
|
||||
t = COM_CheckParm("-heapsize") + 1;
|
||||
if (t < com_argc)
|
||||
parms.memsize = Q_atoi(com_argv[t]) * 1024;
|
||||
}
|
||||
if (COM_CheckParm("-heapsize"))
|
||||
{
|
||||
t = COM_CheckParm("-heapsize") + 1;
|
||||
if (t < com_argc)
|
||||
parms.memsize = Q_atoi(com_argv[t]) * 1024;
|
||||
}
|
||||
|
||||
parms.membase = malloc (parms.memsize);
|
||||
// TODO: dedicated server setup
|
||||
|
||||
if (!parms.membase)
|
||||
Sys_Error ("Not enough memory free; check disk space\n");
|
||||
parms.membase = malloc (parms.memsize);
|
||||
|
||||
// TODO: dedicated server setup
|
||||
if (!parms.membase)
|
||||
Sys_Error ("Not enough memory free; check disk space\n");
|
||||
|
||||
// S_BlockSound(); do I need this?
|
||||
Con_Printf("\nFitzQuake Version %1.2f (c) John Fitzgibbons\n", FITZQUAKE_VERSION);
|
||||
Con_Printf("SDL port (c) Sleepwalkr, Baker, and OZ\n");
|
||||
Con_Printf("This version hacked by Stevenaaus and OZ\n");
|
||||
|
||||
Con_Printf("\nFitzQuake Version %1.2f (c) John Fitzgibbons\n", FITZQUAKE_VERSION);
|
||||
Con_Printf("SDL port (c) Sleepwalkr, Baker, and OZ\n");
|
||||
Con_Printf("This version hacked by Stevenaaus and OZ\n");
|
||||
Con_Printf("Host_Init\n");
|
||||
Host_Init(&parms);
|
||||
|
||||
Con_Printf("Host_Init\n");
|
||||
Host_Init(&parms);
|
||||
oldtime = Sys_FloatTime();
|
||||
while (!done)
|
||||
{
|
||||
// TODO: dedicated server loop
|
||||
|
||||
oldtime = Sys_FloatTime();
|
||||
while (!done)
|
||||
{
|
||||
// TODO: dedicated server loop
|
||||
|
||||
while (!done && SDL_PollEvent (&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_ACTIVEEVENT:
|
||||
if (event.active.state & SDL_APPACTIVE & SDL_APPINPUTFOCUS)
|
||||
{
|
||||
if (event.active.gain)
|
||||
{
|
||||
IN_Activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: handle sound
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
IN_MouseMove(event.motion.xrel, event.motion.yrel);
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT:
|
||||
Key_Event(K_MOUSE1, event.button.type == SDL_MOUSEBUTTONDOWN);
|
||||
break;
|
||||
case SDL_BUTTON_RIGHT:
|
||||
Key_Event(K_MOUSE2, event.button.type == SDL_MOUSEBUTTONDOWN);
|
||||
break;
|
||||
case SDL_BUTTON_MIDDLE:
|
||||
Key_Event(K_MOUSE3, event.button.type == SDL_MOUSEBUTTONDOWN);
|
||||
break;
|
||||
case SDL_BUTTON_WHEELUP:
|
||||
Key_Event(K_MWHEELUP, event.button.type == SDL_MOUSEBUTTONDOWN);
|
||||
break;
|
||||
case SDL_BUTTON_WHEELDOWN:
|
||||
Key_Event(K_MWHEELDOWN, event.button.type == SDL_MOUSEBUTTONDOWN);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
// SHIFT + ESC and circomflex always opens the console no matter what
|
||||
if ((event.key.keysym.sym == SDLK_ESCAPE && (event.key.keysym.mod & KMOD_SHIFT))
|
||||
|| (event.key.keysym.sym == SDLK_CARET))
|
||||
{
|
||||
if (event.key.type == SDL_KEYDOWN)
|
||||
Con_ToggleConsole_f();
|
||||
}
|
||||
else if ((event.key.keysym.sym == SDLK_RETURN) &&
|
||||
(event.key.keysym.mod & KMOD_ALT))
|
||||
{
|
||||
if (event.key.type == SDL_KEYDOWN)
|
||||
VID_Toggle();
|
||||
}
|
||||
else
|
||||
{
|
||||
Key_Event(Key_Map(&(event.key)), event.key.type == SDL_KEYDOWN);
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
while (!done && SDL_PollEvent (&event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_ACTIVEEVENT:
|
||||
if (event.active.state & SDL_APPACTIVE & SDL_APPINPUTFOCUS)
|
||||
{
|
||||
if (event.active.gain)
|
||||
{
|
||||
IN_Activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: handle sound
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
IN_MouseMove(event.motion.xrel, event.motion.yrel);
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
switch (event.button.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT:
|
||||
Key_Event(K_MOUSE1, event.button.type == SDL_MOUSEBUTTONDOWN);
|
||||
break;
|
||||
case SDL_BUTTON_RIGHT:
|
||||
Key_Event(K_MOUSE2, event.button.type == SDL_MOUSEBUTTONDOWN);
|
||||
break;
|
||||
case SDL_BUTTON_MIDDLE:
|
||||
Key_Event(K_MOUSE3, event.button.type == SDL_MOUSEBUTTONDOWN);
|
||||
break;
|
||||
case SDL_BUTTON_WHEELUP:
|
||||
Key_Event(K_MWHEELUP, event.button.type == SDL_MOUSEBUTTONDOWN);
|
||||
break;
|
||||
case SDL_BUTTON_WHEELDOWN:
|
||||
Key_Event(K_MWHEELDOWN, event.button.type == SDL_MOUSEBUTTONDOWN);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
// SHIFT + ESC and circomflex always opens the console no matter what
|
||||
if ((event.key.keysym.sym == SDLK_ESCAPE && (event.key.keysym.mod & KMOD_SHIFT))
|
||||
|| (event.key.keysym.sym == SDLK_CARET))
|
||||
{
|
||||
if (event.key.type == SDL_KEYDOWN)
|
||||
Con_ToggleConsole_f();
|
||||
}
|
||||
else if ((event.key.keysym.sym == SDLK_RETURN) &&
|
||||
(event.key.keysym.mod & KMOD_ALT))
|
||||
{
|
||||
if (event.key.type == SDL_KEYDOWN)
|
||||
VID_Toggle();
|
||||
}
|
||||
else
|
||||
{
|
||||
Key_Event(Key_Map(&(event.key)), event.key.type == SDL_KEYDOWN);
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
newtime = Sys_FloatTime();
|
||||
time = newtime - oldtime;
|
||||
newtime = Sys_FloatTime();
|
||||
time = newtime - oldtime;
|
||||
Host_Frame(time);
|
||||
|
||||
Host_Frame(time);
|
||||
// throttle the game loop just a little bit - noone needs more than 1000fps, I think
|
||||
if (newtime - oldtime < 1)
|
||||
SDL_Delay(1);
|
||||
|
||||
// throttle the game loop just a little bit - noone needs more than 1000fps, I think
|
||||
if (newtime - oldtime < 1)
|
||||
SDL_Delay(1);
|
||||
oldtime = newtime;
|
||||
}
|
||||
|
||||
oldtime = newtime;
|
||||
}
|
||||
|
||||
Sys_Quit();
|
||||
return 0;
|
||||
Sys_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
58
Quake/menu.c
58
Quake/menu.c
|
@ -243,7 +243,7 @@ void M_ToggleMenu_f (void)
|
|||
return;
|
||||
}
|
||||
|
||||
IN_Activate();
|
||||
IN_Activate();
|
||||
key_dest = key_game;
|
||||
m_state = m_none;
|
||||
return;
|
||||
|
@ -273,7 +273,7 @@ void M_Menu_Main_f (void)
|
|||
m_save_demonum = cls.demonum;
|
||||
cls.demonum = -1;
|
||||
}
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_state = m_main;
|
||||
m_entersound = true;
|
||||
|
@ -301,7 +301,7 @@ void M_Main_Key (int key)
|
|||
switch (key)
|
||||
{
|
||||
case K_ESCAPE:
|
||||
IN_Activate();
|
||||
IN_Activate();
|
||||
key_dest = key_game;
|
||||
m_state = m_none;
|
||||
cls.demonum = m_save_demonum;
|
||||
|
@ -358,7 +358,7 @@ int m_singleplayer_cursor;
|
|||
|
||||
void M_Menu_SinglePlayer_f (void)
|
||||
{
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_state = m_singleplayer;
|
||||
m_entersound = true;
|
||||
|
@ -410,7 +410,7 @@ void M_SinglePlayer_Key (int key)
|
|||
if (sv.active)
|
||||
if (!SCR_ModalMessage("Are you sure you want to\nstart a new game?\n", 0.0f))
|
||||
break;
|
||||
IN_Activate();
|
||||
IN_Activate();
|
||||
key_dest = key_game;
|
||||
if (sv.active)
|
||||
Cbuf_AddText ("disconnect\n");
|
||||
|
@ -473,7 +473,7 @@ void M_Menu_Load_f (void)
|
|||
m_entersound = true;
|
||||
m_state = m_load;
|
||||
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
M_ScanSaves ();
|
||||
}
|
||||
|
@ -490,7 +490,7 @@ void M_Menu_Save_f (void)
|
|||
m_entersound = true;
|
||||
m_state = m_save;
|
||||
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
M_ScanSaves ();
|
||||
}
|
||||
|
@ -541,7 +541,7 @@ void M_Load_Key (int k)
|
|||
if (!loadable[load_cursor])
|
||||
return;
|
||||
m_state = m_none;
|
||||
IN_Activate();
|
||||
IN_Activate();
|
||||
key_dest = key_game;
|
||||
|
||||
// Host_Loadgame_f can't bring up the loading plaque because too much
|
||||
|
@ -581,7 +581,7 @@ void M_Save_Key (int k)
|
|||
|
||||
case K_ENTER:
|
||||
m_state = m_none;
|
||||
IN_Activate();
|
||||
IN_Activate();
|
||||
key_dest = key_game;
|
||||
Cbuf_AddText (va("save s%i\n", load_cursor));
|
||||
return;
|
||||
|
@ -613,7 +613,7 @@ int m_multiplayer_cursor;
|
|||
|
||||
void M_Menu_MultiPlayer_f (void)
|
||||
{
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_state = m_multiplayer;
|
||||
m_entersound = true;
|
||||
|
@ -698,7 +698,7 @@ int setup_bottom;
|
|||
|
||||
void M_Menu_Setup_f (void)
|
||||
{
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_state = m_setup;
|
||||
m_entersound = true;
|
||||
|
@ -888,7 +888,7 @@ char *net_helpMessage [] =
|
|||
|
||||
void M_Menu_Net_f (void)
|
||||
{
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_state = m_net;
|
||||
m_entersound = true;
|
||||
|
@ -1053,7 +1053,7 @@ int options_cursor;
|
|||
|
||||
void M_Menu_Options_f (void)
|
||||
{
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_state = m_options;
|
||||
m_entersound = true;
|
||||
|
@ -1318,7 +1318,7 @@ int bind_grab;
|
|||
|
||||
void M_Menu_Keys_f (void)
|
||||
{
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_state = m_keys;
|
||||
m_entersound = true;
|
||||
|
@ -1436,7 +1436,7 @@ void M_Keys_Key (int k)
|
|||
}
|
||||
|
||||
bind_grab = false;
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED); // deactivate because we're returning to the menu
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED); // deactivate because we're returning to the menu
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1468,7 +1468,7 @@ void M_Keys_Key (int k)
|
|||
if (keys[1] != -1)
|
||||
M_UnbindCommand (bindnames[keys_cursor][0]);
|
||||
bind_grab = true;
|
||||
IN_Activate(); // activate to allow mouse key binding
|
||||
IN_Activate(); // activate to allow mouse key binding
|
||||
break;
|
||||
|
||||
case K_BACKSPACE: // delete bindings
|
||||
|
@ -1508,7 +1508,7 @@ int help_page;
|
|||
|
||||
void M_Menu_Help_f (void)
|
||||
{
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_state = m_help;
|
||||
m_entersound = true;
|
||||
|
@ -1560,7 +1560,7 @@ void M_Menu_Quit_f (void)
|
|||
if (m_state == m_quit)
|
||||
return;
|
||||
wasInMenus = (key_dest == key_menu);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_quit_prevstate = m_state;
|
||||
m_state = m_quit;
|
||||
|
@ -1583,7 +1583,7 @@ void M_Quit_Key (int key)
|
|||
}
|
||||
else
|
||||
{
|
||||
IN_Activate();
|
||||
IN_Activate();
|
||||
key_dest = key_game;
|
||||
m_state = m_none;
|
||||
}
|
||||
|
@ -1591,7 +1591,7 @@ void M_Quit_Key (int key)
|
|||
|
||||
case 'Y':
|
||||
case 'y':
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_console;
|
||||
Host_Quit_f ();
|
||||
break;
|
||||
|
@ -1658,7 +1658,7 @@ void M_Menu_SerialConfig_f (void)
|
|||
int baudrate;
|
||||
qboolean useModem;
|
||||
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_state = m_serialconfig;
|
||||
m_entersound = true;
|
||||
|
@ -1880,7 +1880,7 @@ forward:
|
|||
|
||||
m_return_state = m_state;
|
||||
m_return_onerror = true;
|
||||
IN_Activate();
|
||||
IN_Activate();
|
||||
key_dest = key_game;
|
||||
m_state = m_none;
|
||||
|
||||
|
@ -1943,7 +1943,7 @@ char modemConfig_hangup [16];
|
|||
|
||||
void M_Menu_ModemConfig_f (void)
|
||||
{
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_state = m_modemconfig;
|
||||
m_entersound = true;
|
||||
|
@ -2115,7 +2115,7 @@ char lanConfig_joinname[22];
|
|||
|
||||
void M_Menu_LanConfig_f (void)
|
||||
{
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_state = m_lanconfig;
|
||||
m_entersound = true;
|
||||
|
@ -2242,7 +2242,7 @@ void M_LanConfig_Key (int key)
|
|||
{
|
||||
m_return_state = m_state;
|
||||
m_return_onerror = true;
|
||||
IN_Activate();
|
||||
IN_Activate();
|
||||
key_dest = key_game;
|
||||
m_state = m_none;
|
||||
Cbuf_AddText ( va ("connect \"%s\"\n", lanConfig_joinname) );
|
||||
|
@ -2463,7 +2463,7 @@ double m_serverInfoMessageTime;
|
|||
|
||||
void M_Menu_GameOptions_f (void)
|
||||
{
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_state = m_gameoptions;
|
||||
m_entersound = true;
|
||||
|
@ -2774,7 +2774,7 @@ double searchCompleteTime;
|
|||
|
||||
void M_Menu_Search_f (void)
|
||||
{
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_state = m_search;
|
||||
m_entersound = false;
|
||||
|
@ -2835,7 +2835,7 @@ qboolean slist_sorted;
|
|||
|
||||
void M_Menu_ServerList_f (void)
|
||||
{
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
IN_Deactivate(vid.type == MODE_WINDOWED);
|
||||
key_dest = key_menu;
|
||||
m_state = m_slist;
|
||||
m_entersound = true;
|
||||
|
@ -2920,7 +2920,7 @@ void M_ServerList_Key (int k)
|
|||
m_return_state = m_state;
|
||||
m_return_onerror = true;
|
||||
slist_sorted = false;
|
||||
IN_Activate();
|
||||
IN_Activate();
|
||||
key_dest = key_game;
|
||||
m_state = m_none;
|
||||
Cbuf_AddText ( va ("connect \"%s\"\n", hostcache[slist_cursor].cname) );
|
||||
|
|
|
@ -84,7 +84,7 @@ int net_numdrivers = 2;
|
|||
|
||||
net_landriver_t net_landrivers[MAX_NET_DRIVERS] =
|
||||
{
|
||||
{
|
||||
{
|
||||
"UDP",
|
||||
false,
|
||||
0,
|
||||
|
@ -110,3 +110,4 @@ net_landriver_t net_landrivers[MAX_NET_DRIVERS] =
|
|||
};
|
||||
|
||||
int net_numlandrivers = 1;
|
||||
|
||||
|
|
|
@ -28,89 +28,87 @@ Foundat(&addr->sa_dataion, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-
|
|||
|
||||
#include "net_sdlnet.h"
|
||||
|
||||
#define MAX_SOCKETS 32
|
||||
#define MAXHOSTNAMELEN 255
|
||||
#define AF_INET 2 /* internet */
|
||||
#define MAX_SOCKETS 32
|
||||
#define MAXHOSTNAMELEN 255
|
||||
#define AF_INET 2 /* internet */
|
||||
|
||||
static int net_controlsocket;
|
||||
static int net_broadcastsocket = 0;
|
||||
static int net_acceptsocket = -1;
|
||||
static struct qsockaddr broadcastaddr;
|
||||
|
||||
SDLNet_SocketSet acceptsocket_set;
|
||||
|
||||
IPaddress myaddr;
|
||||
static int net_controlsocket;
|
||||
static int net_broadcastsocket = 0;
|
||||
static int net_acceptsocket = -1;
|
||||
static struct qsockaddr broadcastaddr;
|
||||
|
||||
SDLNet_SocketSet acceptsocket_set;
|
||||
IPaddress myaddr;
|
||||
// contains a map of socket numbers to SDL_net UDP sockets
|
||||
UDPsocket net_sockets[MAX_SOCKETS];
|
||||
UDPsocket net_sockets[MAX_SOCKETS];
|
||||
|
||||
int socket_id(UDPsocket socket)
|
||||
int socket_id (UDPsocket socket)
|
||||
{
|
||||
int i;
|
||||
int index = -1;
|
||||
int i;
|
||||
int idx = -1;
|
||||
|
||||
for (i = 0; i < MAX_SOCKETS; i++)
|
||||
{
|
||||
if (net_sockets[i] == socket)
|
||||
return i;
|
||||
for (i = 0; i < MAX_SOCKETS; i++)
|
||||
{
|
||||
if (net_sockets[i] == socket)
|
||||
return i;
|
||||
|
||||
if (net_sockets[i] == NULL && index == -1)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (net_sockets[i] == NULL && idx == -1)
|
||||
{
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
// todo error
|
||||
}
|
||||
if (idx == -1)
|
||||
{
|
||||
// todo error
|
||||
}
|
||||
|
||||
net_sockets[index] = socket;
|
||||
net_sockets[idx] = socket;
|
||||
|
||||
return index;
|
||||
return idx;
|
||||
}
|
||||
|
||||
char *_AddrToString (int ip, int port)
|
||||
{
|
||||
static char buffer[22];
|
||||
static char buffer[22];
|
||||
|
||||
sprintf(buffer, "%d.%d.%d.%d:%d", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff, port);
|
||||
return buffer;
|
||||
sprintf(buffer, "%d.%d.%d.%d:%d", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff, port);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
char *_IPAddrToString (IPaddress *address)
|
||||
{
|
||||
int ip;
|
||||
int port;
|
||||
int ip;
|
||||
int port;
|
||||
|
||||
ip = SDLNet_Read32(&address->host);
|
||||
port = SDLNet_Read16(&address->port);
|
||||
ip = SDLNet_Read32(&address->host);
|
||||
port = SDLNet_Read16(&address->port);
|
||||
|
||||
return _AddrToString(ip, port);
|
||||
return _AddrToString(ip, port);
|
||||
}
|
||||
|
||||
int SDLN_Init (void)
|
||||
{
|
||||
int i;
|
||||
char buff[MAXHOSTNAMELEN];
|
||||
char *p;
|
||||
IPaddress *ipaddress;
|
||||
int i;
|
||||
char buff[MAXHOSTNAMELEN];
|
||||
char *p;
|
||||
IPaddress *ipaddress;
|
||||
|
||||
// init SDL
|
||||
if (SDLNet_Init() == -1)
|
||||
{
|
||||
Con_SafePrintf ("SDL_net initialization failed.\n");
|
||||
return -1;
|
||||
}
|
||||
// init SDL
|
||||
if (SDLNet_Init() == -1)
|
||||
{
|
||||
Con_SafePrintf ("SDL_net initialization failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// allocate a socket set for the accept socket
|
||||
acceptsocket_set = SDLNet_AllocSocketSet(1);
|
||||
if (acceptsocket_set == NULL)
|
||||
{
|
||||
// allocate a socket set for the accept socket
|
||||
acceptsocket_set = SDLNet_AllocSocketSet(1);
|
||||
if (acceptsocket_set == NULL)
|
||||
{
|
||||
Con_DPrintf ("SDL_net initialization failed: Could not create socket set.\n");
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// determine my name
|
||||
if (gethostname(buff, MAXHOSTNAMELEN) == -1)
|
||||
|
@ -138,13 +136,13 @@ int SDLN_Init (void)
|
|||
Cvar_Set ("hostname", buff);
|
||||
}
|
||||
|
||||
// set my IP address
|
||||
// set my IP address
|
||||
i = COM_CheckParm ("-ip");
|
||||
if (i)
|
||||
{
|
||||
if (i < com_argc-1)
|
||||
{
|
||||
SDLNet_ResolveHost(&myaddr, com_argv[i+1], 0);
|
||||
SDLNet_ResolveHost(&myaddr, com_argv[i+1], 0);
|
||||
if (myaddr.host == INADDR_NONE)
|
||||
Sys_Error ("%s is not a valid IP address", com_argv[i+1]);
|
||||
strcpy(my_tcpip_address, com_argv[i+1]);
|
||||
|
@ -156,21 +154,21 @@ int SDLN_Init (void)
|
|||
}
|
||||
else
|
||||
{
|
||||
SDLNet_ResolveHost(&myaddr, NULL, 0);
|
||||
SDLNet_ResolveHost(&myaddr, NULL, 0);
|
||||
strcpy(my_tcpip_address, "INADDR_ANY");
|
||||
}
|
||||
|
||||
// open the control socket
|
||||
// open the control socket
|
||||
if ((net_controlsocket = SDLN_OpenSocket (0)) == -1)
|
||||
{
|
||||
Con_Printf("SDLN_Init: Unable to open control socket\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
broadcastaddr.sa_family = AF_INET;
|
||||
ipaddress = (IPaddress *)&(broadcastaddr.sa_data);
|
||||
SDLNet_Write32(INADDR_BROADCAST, &ipaddress->host);
|
||||
SDLNet_Write16(net_hostport, &ipaddress->port);
|
||||
broadcastaddr.sa_family = AF_INET;
|
||||
ipaddress = (IPaddress *)&(broadcastaddr.sa_data);
|
||||
SDLNet_Write32(INADDR_BROADCAST, &ipaddress->host);
|
||||
SDLNet_Write16(net_hostport, &ipaddress->port);
|
||||
|
||||
Con_Printf("SDL_net TCP/IP initialized\n");
|
||||
tcpipAvailable = true;
|
||||
|
@ -189,7 +187,7 @@ void SDLN_GetLocalAddress()
|
|||
if (myaddr.host != INADDR_ANY)
|
||||
return;
|
||||
|
||||
SDLNet_ResolveHost(&myaddr, NULL, 0);
|
||||
SDLNet_ResolveHost(&myaddr, NULL, 0);
|
||||
}
|
||||
|
||||
void SDLN_Listen (qboolean state)
|
||||
|
@ -204,39 +202,38 @@ void SDLN_Listen (qboolean state)
|
|||
if ((net_acceptsocket = SDLN_OpenSocket (net_hostport)) == -1)
|
||||
Sys_Error ("SDLN_Listen: Unable to open accept socket\n");
|
||||
|
||||
SDLNet_UDP_AddSocket(acceptsocket_set, net_sockets[net_acceptsocket]);
|
||||
SDLNet_UDP_AddSocket(acceptsocket_set, net_sockets[net_acceptsocket]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// disable listening
|
||||
if (net_acceptsocket == -1)
|
||||
return;
|
||||
else
|
||||
{
|
||||
// disable listening
|
||||
if (net_acceptsocket == -1)
|
||||
return;
|
||||
|
||||
SDLNet_UDP_DelSocket(acceptsocket_set, net_sockets[net_acceptsocket]);
|
||||
SDLN_CloseSocket(net_acceptsocket);
|
||||
SDLNet_UDP_DelSocket(acceptsocket_set, net_sockets[net_acceptsocket]);
|
||||
SDLN_CloseSocket(net_acceptsocket);
|
||||
|
||||
net_acceptsocket = -1;
|
||||
}
|
||||
net_acceptsocket = -1;
|
||||
}
|
||||
}
|
||||
|
||||
int SDLN_OpenSocket (int port)
|
||||
int SDLN_OpenSocket (int port)
|
||||
{
|
||||
UDPsocket newsocket;
|
||||
static IPaddress address;
|
||||
|
||||
UDPsocket newsocket;
|
||||
static IPaddress address;
|
||||
|
||||
if ((newsocket = SDLNet_UDP_Open(port)) == NULL)
|
||||
return -1;
|
||||
if ((newsocket = SDLNet_UDP_Open(port)) == NULL)
|
||||
return -1;
|
||||
|
||||
// todo check what this does
|
||||
// if (pioctlsocket (newsocket, FIONBIO, &_true) == -1)
|
||||
// goto ErrorReturn;
|
||||
|
||||
address.host = myaddr.host;
|
||||
address.port = SDLNet_Read16(&port);
|
||||
address.host = myaddr.host;
|
||||
address.port = SDLNet_Read16(&port);
|
||||
|
||||
if (SDLNet_UDP_Bind(newsocket, 0, &address) != -1)
|
||||
return socket_id(newsocket);
|
||||
if (SDLNet_UDP_Bind(newsocket, 0, &address) != -1)
|
||||
return socket_id(newsocket);
|
||||
|
||||
Sys_Error ("Unable to bind to %s", _IPAddrToString(&address));
|
||||
|
||||
|
@ -244,201 +241,200 @@ int SDLN_OpenSocket (int port)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int SDLN_CloseSocket (int socketid)
|
||||
int SDLN_CloseSocket (int socketid)
|
||||
{
|
||||
UDPsocket socket;
|
||||
UDPsocket socket;
|
||||
|
||||
if (socketid == net_broadcastsocket)
|
||||
net_broadcastsocket = -1;
|
||||
if (socketid == net_broadcastsocket)
|
||||
net_broadcastsocket = -1;
|
||||
|
||||
socket = net_sockets[socketid];
|
||||
socket = net_sockets[socketid];
|
||||
|
||||
if (socket == NULL)
|
||||
return -1;
|
||||
if (socket == NULL)
|
||||
return -1;
|
||||
|
||||
SDLNet_UDP_Close(socket);
|
||||
SDLNet_UDP_Close(socket);
|
||||
|
||||
net_sockets[socketid] = NULL;
|
||||
return 0;
|
||||
net_sockets[socketid] = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDLN_Connect (int socket, struct qsockaddr *addr)
|
||||
int SDLN_Connect (int socket, struct qsockaddr *addr)
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDLN_CheckNewConnections (void)
|
||||
int SDLN_CheckNewConnections (void)
|
||||
{
|
||||
if (net_acceptsocket == -1)
|
||||
return -1;
|
||||
|
||||
if (SDLNet_CheckSockets(acceptsocket_set, 0) > 0)
|
||||
return net_acceptsocket;
|
||||
if (SDLNet_CheckSockets(acceptsocket_set, 0) > 0)
|
||||
return net_acceptsocket;
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
UDPpacket *init_packet(UDPpacket *packet, int len)
|
||||
{
|
||||
if (packet == NULL)
|
||||
return SDLNet_AllocPacket(len);
|
||||
if (packet == NULL)
|
||||
return SDLNet_AllocPacket(len);
|
||||
|
||||
if (packet->maxlen < len)
|
||||
SDLNet_ResizePacket(packet, len);
|
||||
if (packet->maxlen < len)
|
||||
SDLNet_ResizePacket(packet, len);
|
||||
|
||||
return packet;
|
||||
return packet;
|
||||
}
|
||||
|
||||
int SDLN_Read (int socketid, byte *buf, int len, struct qsockaddr *addr)
|
||||
int SDLN_Read (int socketid, byte *buf, int len, struct qsockaddr *addr)
|
||||
{
|
||||
int numrecv;
|
||||
static UDPpacket *packet;
|
||||
IPaddress *ipaddress;
|
||||
int numrecv;
|
||||
static UDPpacket *packet;
|
||||
IPaddress *ipaddress;
|
||||
|
||||
UDPsocket socket = net_sockets[socketid];
|
||||
if (socket == NULL)
|
||||
return -1;
|
||||
UDPsocket socket = net_sockets[socketid];
|
||||
if (socket == NULL)
|
||||
return -1;
|
||||
|
||||
packet = init_packet(packet, len);
|
||||
packet = init_packet(packet, len);
|
||||
|
||||
numrecv = SDLNet_UDP_Recv(socket, packet);
|
||||
if (numrecv == 1)
|
||||
{
|
||||
memcpy(buf, packet->data, packet->len);
|
||||
numrecv = SDLNet_UDP_Recv(socket, packet);
|
||||
if (numrecv == 1)
|
||||
{
|
||||
memcpy(buf, packet->data, packet->len);
|
||||
|
||||
addr->sa_family = AF_INET;
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
ipaddress->host = packet->address.host;
|
||||
ipaddress->port = packet->address.port;
|
||||
addr->sa_family = AF_INET;
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
ipaddress->host = packet->address.host;
|
||||
ipaddress->port = packet->address.port;
|
||||
|
||||
return packet->len;
|
||||
}
|
||||
|
||||
return numrecv;
|
||||
return packet->len;
|
||||
}
|
||||
|
||||
return numrecv;
|
||||
}
|
||||
|
||||
int SDLN_Write (int socketid, byte *buf, int len, struct qsockaddr *addr)
|
||||
int SDLN_Write (int socketid, byte *buf, int len, struct qsockaddr *addr)
|
||||
{
|
||||
int numsent;
|
||||
static UDPpacket *packet;
|
||||
UDPsocket socket;
|
||||
IPaddress *ipaddress;
|
||||
int numsent;
|
||||
static UDPpacket *packet;
|
||||
UDPsocket socket;
|
||||
IPaddress *ipaddress;
|
||||
|
||||
socket = net_sockets[socketid];
|
||||
socket = net_sockets[socketid];
|
||||
|
||||
if (socket == NULL)
|
||||
return -1;
|
||||
if (socket == NULL)
|
||||
return -1;
|
||||
|
||||
packet = init_packet(packet, len);
|
||||
memcpy(packet->data, buf, len);
|
||||
packet->len = len;
|
||||
packet = init_packet(packet, len);
|
||||
memcpy(packet->data, buf, len);
|
||||
packet->len = len;
|
||||
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
packet->address.host = ipaddress->host;
|
||||
packet->address.port = ipaddress->port;
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
packet->address.host = ipaddress->host;
|
||||
packet->address.port = ipaddress->port;
|
||||
|
||||
numsent = SDLNet_UDP_Send(socket, -1, packet);
|
||||
if (numsent == 0)
|
||||
return 0;
|
||||
numsent = SDLNet_UDP_Send(socket, -1, packet);
|
||||
if (numsent == 0)
|
||||
return 0;
|
||||
|
||||
return len;
|
||||
return len;
|
||||
}
|
||||
|
||||
int SDLN_Broadcast (int socketid, byte *buf, int len)
|
||||
int SDLN_Broadcast (int socketid, byte *buf, int len)
|
||||
{
|
||||
if (socketid != net_broadcastsocket)
|
||||
{
|
||||
if (net_broadcastsocket != 0)
|
||||
Sys_Error("Attempted to use multiple broadcast sockets\n");
|
||||
|
||||
if (socketid != net_broadcastsocket)
|
||||
{
|
||||
if (net_broadcastsocket != 0)
|
||||
Sys_Error("Attempted to use multiple broadcast sockets\n");
|
||||
// todo make socket broadcast capable
|
||||
Sys_Error("Unable to make socket broadcast capable\n");
|
||||
}
|
||||
|
||||
// todo make socket broadcast capable
|
||||
Sys_Error("Unable to make socket broadcast capable\n");
|
||||
}
|
||||
|
||||
return SDLN_Write(socketid, buf, len, &broadcastaddr);
|
||||
return SDLN_Write(socketid, buf, len, &broadcastaddr);
|
||||
}
|
||||
|
||||
char *SDLN_AddrToString (struct qsockaddr *addr)
|
||||
{
|
||||
int ip;
|
||||
int port;
|
||||
IPaddress *ipaddress;
|
||||
int ip;
|
||||
int port;
|
||||
IPaddress *ipaddress;
|
||||
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
|
||||
ip = SDLNet_Read32(&ipaddress->host);
|
||||
port = SDLNet_Read16(&ipaddress->port);
|
||||
ip = SDLNet_Read32(&ipaddress->host);
|
||||
port = SDLNet_Read16(&ipaddress->port);
|
||||
|
||||
return _AddrToString(ip, port);
|
||||
return _AddrToString(ip, port);
|
||||
}
|
||||
|
||||
int SDLN_StringToAddr (char *string, struct qsockaddr *addr)
|
||||
{
|
||||
int ha1, ha2, ha3, ha4, hp;
|
||||
int hostaddr;
|
||||
IPaddress *ipaddress;
|
||||
IPaddress *ipaddress;
|
||||
|
||||
sscanf(string, "%d.%d.%d.%d:%d", &ha1, &ha2, &ha3, &ha4, &hp);
|
||||
hostaddr = (ha1 << 24) | (ha2 << 16) | (ha3 << 8) | ha4;
|
||||
|
||||
addr->sa_family = AF_INET;
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
addr->sa_family = AF_INET;
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
|
||||
SDLNet_Write32(hostaddr, &ipaddress->host);
|
||||
SDLNet_Write16(hp, &ipaddress->port);
|
||||
SDLNet_Write32(hostaddr, &ipaddress->host);
|
||||
SDLNet_Write16(hp, &ipaddress->port);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDLN_GetSocketAddr (int socketid, struct qsockaddr *addr)
|
||||
int SDLN_GetSocketAddr (int socketid, struct qsockaddr *addr)
|
||||
{
|
||||
static UDPsocket socket;
|
||||
IPaddress *peeraddress;
|
||||
IPaddress *ipaddress;
|
||||
static UDPsocket socket;
|
||||
IPaddress *peeraddress;
|
||||
IPaddress *ipaddress;
|
||||
|
||||
Q_memset(addr, 0, sizeof(struct qsockaddr));
|
||||
|
||||
socket = net_sockets[socketid];
|
||||
if (socket == NULL)
|
||||
return -1;
|
||||
socket = net_sockets[socketid];
|
||||
if (socket == NULL)
|
||||
return -1;
|
||||
|
||||
peeraddress = SDLNet_UDP_GetPeerAddress(socket, -1);
|
||||
if (peeraddress == NULL)
|
||||
return -1;
|
||||
peeraddress = SDLNet_UDP_GetPeerAddress(socket, -1);
|
||||
if (peeraddress == NULL)
|
||||
return -1;
|
||||
|
||||
addr->sa_family = AF_INET;
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
if (peeraddress->host == 0 || peeraddress->host == inet_addr("127.0.0.1"))
|
||||
{
|
||||
ipaddress->host = myaddr.host;
|
||||
ipaddress->port = myaddr.port;
|
||||
}
|
||||
else
|
||||
{
|
||||
ipaddress->host = peeraddress->host;
|
||||
ipaddress->port = peeraddress->port;
|
||||
}
|
||||
addr->sa_family = AF_INET;
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
if (peeraddress->host == 0 || peeraddress->host == inet_addr("127.0.0.1"))
|
||||
{
|
||||
ipaddress->host = myaddr.host;
|
||||
ipaddress->port = myaddr.port;
|
||||
}
|
||||
else
|
||||
{
|
||||
ipaddress->host = peeraddress->host;
|
||||
ipaddress->port = peeraddress->port;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDLN_GetNameFromAddr (struct qsockaddr *addr, char *name)
|
||||
int SDLN_GetNameFromAddr (struct qsockaddr *addr, char *name)
|
||||
{
|
||||
char *buf;
|
||||
IPaddress *ipaddress;
|
||||
char *buf;
|
||||
IPaddress *ipaddress;
|
||||
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
|
||||
buf = (char *)SDLNet_ResolveIP(ipaddress);
|
||||
if (buf != NULL) {
|
||||
Q_strncpy(name, buf, NET_NAMELEN - 1);
|
||||
return 0;
|
||||
}
|
||||
buf = (char *)SDLNet_ResolveIP(ipaddress);
|
||||
if (buf != NULL)
|
||||
{
|
||||
Q_strncpy(name, buf, NET_NAMELEN - 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Q_strcpy(name, SDLN_AddrToString(addr));
|
||||
return 0;
|
||||
Q_strcpy(name, SDLN_AddrToString(addr));
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
@ -457,7 +453,7 @@ static int PartialIPAddress (char *in, struct qsockaddr *hostaddr)
|
|||
int addr;
|
||||
int num;
|
||||
int mask;
|
||||
int tmp;
|
||||
int tmp;
|
||||
int run;
|
||||
int port;
|
||||
IPaddress *ipaddress;
|
||||
|
@ -477,9 +473,9 @@ static int PartialIPAddress (char *in, struct qsockaddr *hostaddr)
|
|||
run = 0;
|
||||
while (!( *b < '0' || *b > '9'))
|
||||
{
|
||||
num = num*10 + *b++ - '0';
|
||||
if (++run > 3)
|
||||
return -1;
|
||||
num = num*10 + *b++ - '0';
|
||||
if (++run > 3)
|
||||
return -1;
|
||||
}
|
||||
if ((*b < '0' || *b > '9') && *b != '.' && *b != ':' && *b != 0)
|
||||
return -1;
|
||||
|
@ -494,43 +490,43 @@ static int PartialIPAddress (char *in, struct qsockaddr *hostaddr)
|
|||
else
|
||||
port = net_hostport;
|
||||
|
||||
tmp = SDLNet_Read32(&myaddr.host);
|
||||
tmp = (tmp & mask) | addr;
|
||||
tmp = SDLNet_Read32(&myaddr.host);
|
||||
tmp = (tmp & mask) | addr;
|
||||
|
||||
hostaddr->sa_family = AF_INET;
|
||||
ipaddress = (IPaddress *)&(hostaddr->sa_data);
|
||||
hostaddr->sa_family = AF_INET;
|
||||
ipaddress = (IPaddress *)&(hostaddr->sa_data);
|
||||
|
||||
SDLNet_Write32(tmp, &ipaddress->host);
|
||||
SDLNet_Write16(port, &ipaddress->port);
|
||||
SDLNet_Write32(tmp, &ipaddress->host);
|
||||
SDLNet_Write16(port, &ipaddress->port);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDLN_GetAddrFromName (char *name, struct qsockaddr *addr)
|
||||
int SDLN_GetAddrFromName (char *name, struct qsockaddr *addr)
|
||||
{
|
||||
IPaddress *ipaddress;
|
||||
IPaddress *ipaddress;
|
||||
|
||||
if (name[0] >= '0' && name[0] <= '9')
|
||||
return PartialIPAddress (name, addr);
|
||||
return PartialIPAddress (name, addr);
|
||||
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
if (SDLNet_ResolveHost((IPaddress *)(&addr->sa_data), name, 26000) == -1)
|
||||
return -1;
|
||||
|
||||
addr->sa_family = AF_INET;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDLN_AddrCompare (struct qsockaddr *addr1, struct qsockaddr *addr2)
|
||||
{
|
||||
IPaddress *ipaddr1;
|
||||
IPaddress *ipaddr2;
|
||||
|
||||
if (addr1->sa_family != addr2->sa_family)
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
if (SDLNet_ResolveHost((IPaddress *)(&addr->sa_data), name, 26000) == -1)
|
||||
return -1;
|
||||
|
||||
ipaddr1 = (IPaddress *)&(addr1->sa_data);
|
||||
ipaddr2 = (IPaddress *)&(addr2->sa_data);
|
||||
addr->sa_family = AF_INET;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDLN_AddrCompare (struct qsockaddr *addr1, struct qsockaddr *addr2)
|
||||
{
|
||||
IPaddress *ipaddr1;
|
||||
IPaddress *ipaddr2;
|
||||
|
||||
if (addr1->sa_family != addr2->sa_family)
|
||||
return -1;
|
||||
|
||||
ipaddr1 = (IPaddress *)&(addr1->sa_data);
|
||||
ipaddr2 = (IPaddress *)&(addr2->sa_data);
|
||||
|
||||
if (ipaddr1->host != ipaddr2->host)
|
||||
return -1;
|
||||
|
@ -541,21 +537,21 @@ int SDLN_AddrCompare (struct qsockaddr *addr1, struct qsockaddr *addr2)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int SDLN_GetSocketPort (struct qsockaddr *addr)
|
||||
int SDLN_GetSocketPort (struct qsockaddr *addr)
|
||||
{
|
||||
IPaddress *ipaddress;
|
||||
IPaddress *ipaddress;
|
||||
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
return SDLNet_Read16(&ipaddress->port);
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
return SDLNet_Read16(&ipaddress->port);
|
||||
}
|
||||
|
||||
int SDLN_SetSocketPort (struct qsockaddr *addr, int port)
|
||||
int SDLN_SetSocketPort (struct qsockaddr *addr, int port)
|
||||
{
|
||||
IPaddress *ipaddress;
|
||||
IPaddress *ipaddress;
|
||||
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
SDLNet_Write16(port, &ipaddress->port);
|
||||
ipaddress = (IPaddress *)&(addr->sa_data);
|
||||
SDLNet_Write16(port, &ipaddress->port);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
188
Quake/sys_sdl.c
188
Quake/sys_sdl.c
|
@ -23,36 +23,36 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "quakedef.h"
|
||||
#include "errno.h"
|
||||
|
||||
#define CONSOLE_ERROR_TIMEOUT 60.0 // # of seconds to wait on Sys_Error running
|
||||
qboolean isDedicated;
|
||||
#define CONSOLE_ERROR_TIMEOUT 60.0 /* # of seconds to wait on Sys_Error running */
|
||||
qboolean isDedicated;
|
||||
static qboolean sc_return_on_enter = false;
|
||||
|
||||
#define MAX_HANDLES 32 //johnfitz -- was 10
|
||||
FILE *sys_handles[MAX_HANDLES];
|
||||
#define MAX_HANDLES 32 /* johnfitz -- was 10 */
|
||||
FILE *sys_handles[MAX_HANDLES];
|
||||
|
||||
int findhandle (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=1 ; i<MAX_HANDLES ; i++)
|
||||
if (!sys_handles[i])
|
||||
return i;
|
||||
|
||||
Sys_Error ("out of handles");
|
||||
for (i=1 ; i<MAX_HANDLES ; i++)
|
||||
if (!sys_handles[i])
|
||||
return i;
|
||||
|
||||
Sys_Error ("out of handles");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int filelength (FILE *f)
|
||||
{
|
||||
int pos;
|
||||
int end;
|
||||
int pos;
|
||||
int end;
|
||||
|
||||
pos = ftell (f);
|
||||
fseek (f, 0, SEEK_END);
|
||||
end = ftell (f);
|
||||
fseek (f, pos, SEEK_SET);
|
||||
pos = ftell (f);
|
||||
fseek (f, 0, SEEK_END);
|
||||
end = ftell (f);
|
||||
fseek (f, pos, SEEK_SET);
|
||||
|
||||
return end;
|
||||
return end;
|
||||
}
|
||||
|
||||
int Sys_FileOpenRead (char *path, int *hndl)
|
||||
|
@ -88,8 +88,8 @@ int Sys_FileOpenWrite (char *path)
|
|||
|
||||
if (!f)
|
||||
Sys_Error ("Error opening %s: %s", path, strerror(errno));
|
||||
|
||||
sys_handles[i] = f;
|
||||
|
||||
sys_handles[i] = f;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -114,19 +114,19 @@ int Sys_FileWrite (int handle, void *data, int count)
|
|||
return fwrite (data, 1, count, sys_handles[handle]);
|
||||
}
|
||||
|
||||
int Sys_FileTime (char *path)
|
||||
int Sys_FileTime (char *path)
|
||||
{
|
||||
FILE *f;
|
||||
FILE *f;
|
||||
|
||||
f = fopen(path, "rb");
|
||||
f = fopen(path, "rb");
|
||||
|
||||
if (f)
|
||||
{
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
if (f)
|
||||
{
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Sys_mkdir (char *path)
|
||||
|
@ -144,7 +144,7 @@ void Sys_DebugLog(char *file, char *fmt, ...)
|
|||
|
||||
void Sys_Error (char *error, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
va_list argptr;
|
||||
char text[1024], text2[1024];
|
||||
char *text3 = "Press Enter to exit\n";
|
||||
char *text4 = "***********************************\n";
|
||||
|
@ -157,48 +157,50 @@ void Sys_Error (char *error, ...)
|
|||
if (!in_sys_error3)
|
||||
{
|
||||
in_sys_error3 = 1;
|
||||
// VID_ForceUnlockedAndReturnState (); TODO: see what this does
|
||||
}
|
||||
|
||||
//TODO: use OS messagebox here if possible (windows, os x and linux shouldn't be a problem)
|
||||
//implement this in pl_*, which contains all the platform dependent code
|
||||
|
||||
va_start (argptr, error);
|
||||
vsprintf (text, error, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
if (isDedicated) {
|
||||
sprintf (text2, "ERROR: %s\n", text);
|
||||
printf ("%s", text5);
|
||||
printf ("%s", text4);
|
||||
printf ("%s", text2);
|
||||
printf ("%s", text3);
|
||||
printf ("%s", text4);
|
||||
|
||||
starttime = Sys_FloatTime ();
|
||||
sc_return_on_enter = true; // so Enter will get us out of here
|
||||
|
||||
while (!Sys_ConsoleInput () &&
|
||||
((Sys_FloatTime () - starttime) < CONSOLE_ERROR_TIMEOUT))
|
||||
{
|
||||
}
|
||||
|
||||
if (!in_sys_error1)
|
||||
{
|
||||
in_sys_error1 = 1;
|
||||
Host_Shutdown ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PL_ErrorDialog(text);
|
||||
}
|
||||
|
||||
//TODO: use OS messagebox here if possible
|
||||
// (windows, os x and linux shouldn't be a problem)
|
||||
//implement this in pl_*, which contains all the
|
||||
// platform dependent code
|
||||
|
||||
va_start (argptr, error);
|
||||
vsprintf (text, error, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
if (isDedicated)
|
||||
{
|
||||
sprintf (text2, "ERROR: %s\n", text);
|
||||
printf ("%s", text5);
|
||||
printf ("%s", text4);
|
||||
printf ("%s", text2);
|
||||
printf ("%s", text3);
|
||||
printf ("%s", text4);
|
||||
|
||||
starttime = Sys_FloatTime ();
|
||||
sc_return_on_enter = true; // so Enter will get us out of here
|
||||
|
||||
while (!Sys_ConsoleInput () &&
|
||||
((Sys_FloatTime () - starttime) < CONSOLE_ERROR_TIMEOUT))
|
||||
{
|
||||
}
|
||||
|
||||
if (!in_sys_error1)
|
||||
{
|
||||
in_sys_error1 = 1;
|
||||
Host_Shutdown ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PL_ErrorDialog(text);
|
||||
}
|
||||
|
||||
// shut down QHOST hooks if necessary
|
||||
if (!in_sys_error2)
|
||||
{
|
||||
in_sys_error2 = 1;
|
||||
//DeinitConProc (); TODO: check what this does
|
||||
// DeinitConProc ();
|
||||
}
|
||||
|
||||
exit (1);
|
||||
|
@ -206,20 +208,19 @@ void Sys_Error (char *error, ...)
|
|||
|
||||
void Sys_Printf (char *fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
va_list argptr;
|
||||
|
||||
// always print to the console
|
||||
// if (isDedicated)
|
||||
// {
|
||||
va_start(argptr, fmt);
|
||||
vprintf(fmt, argptr);
|
||||
va_end(argptr);
|
||||
// }
|
||||
// always print to the console
|
||||
// if (isDedicated)
|
||||
// {
|
||||
va_start(argptr, fmt);
|
||||
vprintf(fmt, argptr);
|
||||
va_end(argptr);
|
||||
// }
|
||||
}
|
||||
|
||||
void Sys_Quit (void)
|
||||
{
|
||||
|
||||
Host_Shutdown();
|
||||
|
||||
// if (isDedicated)
|
||||
|
@ -233,7 +234,7 @@ void Sys_Quit (void)
|
|||
|
||||
double Sys_FloatTime (void)
|
||||
{
|
||||
return SDL_GetTicks() / 1000.0;
|
||||
return SDL_GetTicks() / 1000.0;
|
||||
}
|
||||
|
||||
char *Sys_ConsoleInput (void)
|
||||
|
@ -241,31 +242,31 @@ char *Sys_ConsoleInput (void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Sys_Sleep (void)
|
||||
{
|
||||
}
|
||||
|
||||
void Sys_SendKeyEvents (void)
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
SDL_PumpEvents();
|
||||
while (SDL_PollEvent (&event))
|
||||
{
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
Key_Event(Key_Map(&(event.key)), event.key.type == SDL_KEYDOWN);
|
||||
return;
|
||||
case SDL_QUIT:
|
||||
Sys_Quit();
|
||||
break;
|
||||
default:
|
||||
SDL_PumpEvents();
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDL_Event event;
|
||||
|
||||
SDL_PumpEvents();
|
||||
while (SDL_PollEvent (&event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
Key_Event(Key_Map(&(event.key)), event.key.type == SDL_KEYDOWN);
|
||||
return;
|
||||
case SDL_QUIT:
|
||||
Sys_Quit();
|
||||
break;
|
||||
default:
|
||||
SDL_PumpEvents();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sys_LowFPPrecision (void)
|
||||
|
@ -279,3 +280,4 @@ void Sys_HighFPPrecision (void)
|
|||
void Sys_SetFPCW (void)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue