ref: a4474be05dd2196175875f7333185e7b6c9bd449
parent: 6aaee9a37654f87eb52375d0b2bca5f26cd8139a
author: qwx <>
date: Sat Dec 8 18:47:27 EST 2018
qw: add broken-ass port
--- a/README
+++ b/README
@@ -2,7 +2,6 @@
===============
Port of linux/x11 quake to plan9front.
- Works on amd64 and 386, broken on arm and probably other arches
-- Lacks networking
Installation
@@ -51,7 +50,6 @@
- fix arm graphics issues
- cd: buffer reading from actual cdroms
- do away with PR_Str shit
-- udp/ip, plan9 style
- manpages
- port quakeworld: mkmany, merging common code
- random crashes in d_sprite.c:D_SpriteDrawSpans
--- a/qw/bspfile.h
+++ b/qw/bspfile.h
@@ -29,6 +29,7 @@
//=============================================================================
+#pragma pack on
#define BSPVERSION 29
@@ -189,6 +190,8 @@
byte ambient_level[NUM_AMBIENTS];
} dleaf_t;
+
+#pragma pack off
//============================================================================
--- /dev/null
+++ b/qw/cd.c
@@ -1,0 +1,393 @@
+#include <u.h>
+#include <libc.h>
+#include <stdio.h>
+#include "quakedef.h"
+
+static qboolean cdValid;
+static qboolean playing;
+static qboolean wasPlaying;
+static qboolean initialized;
+static qboolean enabled = true;
+static qboolean playLooping;
+static float cdvolume;
+static byte remap[100];
+static byte playTrack;
+static byte maxTrack;
+static int cdfile = -1;
+static char cd_dev[64] = "/dev/cdrom";
+
+
+static void CDAudio_Eject(void)
+{
+ if (cdfile == -1 || !enabled)
+ return; // no cd init'd
+/*
+ if ( ioctl(cdfile, CDROMEJECT) == -1 )
+ Con_DPrintf("ioctl cdromeject failed\n");
+*/
+}
+
+static void CDAudio_CloseDoor(void)
+{
+ if (cdfile == -1 || !enabled)
+ return; // no cd init'd
+/*
+ if ( ioctl(cdfile, CDROMCLOSETRAY) == -1 )
+ Con_DPrintf("ioctl cdromclosetray failed\n");
+*/
+}
+
+static int CDAudio_GetAudioDiskInfo(void)
+{
+ cdValid = false;
+ return -1;
+
+/*
+ struct cdrom_tochdr tochdr;
+
+ if ( ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1 )
+ {
+ Con_DPrintf("ioctl cdromreadtochdr failed\n");
+ return -1;
+ }
+
+ if (tochdr.cdth_trk0 < 1)
+ {
+ Con_DPrintf("CDAudio: no music tracks\n");
+ return -1;
+ }
+
+ cdValid = true;
+ maxTrack = tochdr.cdth_trk1;
+
+ return 0;
+*/
+}
+
+
+void CDAudio_Play(byte track, qboolean looping)
+{
+ if (cdfile == -1 || !enabled)
+ return;
+
+ if (!cdValid)
+ {
+ CDAudio_GetAudioDiskInfo();
+ if (!cdValid)
+ return;
+ }
+
+ track = remap[track];
+
+ if (track < 1 || track > maxTrack)
+ {
+ Con_DPrintf("CDAudio: Bad track number %u.\n", track);
+ return;
+ }
+
+ USED(looping);
+/*
+ struct cdrom_tocentry entry;
+ struct cdrom_ti ti;
+
+ // don't try to play a non-audio track
+ entry.cdte_track = track;
+ entry.cdte_format = CDROM_MSF;
+ if ( ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1 )
+ {
+ Con_DPrintf("ioctl cdromreadtocentry failed\n");
+ return;
+ }
+ if (entry.cdte_ctrl == CDROM_DATA_TRACK)
+ {
+ Con_Printf("CDAudio: track %i is not audio\n", track);
+ return;
+ }
+
+ if (playing)
+ {
+ if (playTrack == track)
+ return;
+ CDAudio_Stop();
+ }
+
+ ti.cdti_trk0 = track;
+ ti.cdti_trk1 = track;
+ ti.cdti_ind0 = 1;
+ ti.cdti_ind1 = 99;
+
+ if ( ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1 )
+ {
+ Con_DPrintf("ioctl cdromplaytrkind failed\n");
+ return;
+ }
+
+ if ( ioctl(cdfile, CDROMRESUME) == -1 )
+ Con_DPrintf("ioctl cdromresume failed\n");
+
+ playLooping = looping;
+ playTrack = track;
+ playing = true;
+
+ if (cdvolume == 0.0)
+ CDAudio_Pause ();
+*/
+}
+
+
+void CDAudio_Stop(void)
+{
+ if (cdfile == -1 || !enabled)
+ return;
+
+ if (!playing)
+ return;
+
+/*
+ if ( ioctl(cdfile, CDROMSTOP) == -1 )
+ Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
+ wasPlaying = false;
+ playing = false;
+*/
+}
+
+void CDAudio_Pause(void)
+{
+ if (cdfile == -1 || !enabled)
+ return;
+
+ if (!playing)
+ return;
+
+/*
+ if ( ioctl(cdfile, CDROMPAUSE) == -1 )
+ Con_DPrintf("ioctl cdrompause failed\n");
+ wasPlaying = playing;
+ playing = false;
+*/
+}
+
+
+void CDAudio_Resume(void)
+{
+ if (cdfile == -1 || !enabled)
+ return;
+
+ if (!cdValid)
+ return;
+
+ if (!wasPlaying)
+ return;
+/*
+ if ( ioctl(cdfile, CDROMRESUME) == -1 )
+ Con_DPrintf("ioctl cdromresume failed\n");
+ playing = true;
+*/
+}
+
+static void CD_f (void)
+{
+ char *command;
+ int ret;
+ int n;
+
+ if (Cmd_Argc() < 2)
+ return;
+
+ command = Cmd_Argv (1);
+
+ if (cistrcmp(command, "on") == 0)
+ {
+ enabled = true;
+ return;
+ }
+
+ if (cistrcmp(command, "off") == 0)
+ {
+ if (playing)
+ CDAudio_Stop();
+ enabled = false;
+ return;
+ }
+
+ if (cistrcmp(command, "reset") == 0)
+ {
+ enabled = true;
+ if (playing)
+ CDAudio_Stop();
+ for (n = 0; n < 100; n++)
+ remap[n] = n;
+ CDAudio_GetAudioDiskInfo();
+ return;
+ }
+
+ if (cistrcmp(command, "remap") == 0)
+ {
+ ret = Cmd_Argc() - 2;
+ if (ret <= 0)
+ {
+ for (n = 1; n < 100; n++)
+ if (remap[n] != n)
+ Con_Printf(" %u -> %u\n", n, remap[n]);
+ return;
+ }
+ for (n = 1; n <= ret; n++)
+ remap[n] = Q_atoi(Cmd_Argv (n+1));
+ return;
+ }
+
+ if (cistrcmp(command, "close") == 0)
+ {
+ CDAudio_CloseDoor();
+ return;
+ }
+
+ if (!cdValid)
+ {
+ CDAudio_GetAudioDiskInfo();
+ if (!cdValid)
+ {
+ Con_Printf("No CD in player.\n");
+ return;
+ }
+ }
+
+ if (cistrcmp(command, "play") == 0)
+ {
+ CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), false);
+ return;
+ }
+
+ if (cistrcmp(command, "loop") == 0)
+ {
+ CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), true);
+ return;
+ }
+
+ if (cistrcmp(command, "stop") == 0)
+ {
+ CDAudio_Stop();
+ return;
+ }
+
+ if (cistrcmp(command, "pause") == 0)
+ {
+ CDAudio_Pause();
+ return;
+ }
+
+ if (cistrcmp(command, "resume") == 0)
+ {
+ CDAudio_Resume();
+ return;
+ }
+
+ if (cistrcmp(command, "eject") == 0)
+ {
+ if (playing)
+ CDAudio_Stop();
+ CDAudio_Eject();
+ cdValid = false;
+ return;
+ }
+
+ if (cistrcmp(command, "info") == 0)
+ {
+ Con_Printf("%u tracks\n", maxTrack);
+ if (playing)
+ Con_Printf("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack);
+ else if (wasPlaying)
+ Con_Printf("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack);
+ Con_Printf("Volume is %f\n", cdvolume);
+ return;
+ }
+}
+
+void CDAudio_Update(void)
+{
+ if (!enabled)
+ return;
+
+ if (bgmvolume.value != cdvolume)
+ {
+ if (cdvolume)
+ {
+ Cvar_SetValue ("bgmvolume", 0.0);
+ cdvolume = bgmvolume.value;
+ CDAudio_Pause ();
+ }
+ else
+ {
+ Cvar_SetValue ("bgmvolume", 1.0);
+ cdvolume = bgmvolume.value;
+ CDAudio_Resume ();
+ }
+ }
+
+/*
+ struct cdrom_subchnl subchnl;
+ static time_t lastchk;
+ if (playing && lastchk < time(NULL)) {
+ lastchk = time(NULL) + 2; //two seconds between chks
+
+ subchnl.cdsc_format = CDROM_MSF;
+ if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1 ) {
+ Con_DPrintf("ioctl cdromsubchnl failed\n");
+ playing = false;
+ return;
+ }
+ if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
+ subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) {
+ playing = false;
+ if (playLooping)
+ CDAudio_Play(playTrack, true);
+ }
+ }
+*/
+}
+
+int CDAudio_Init(void)
+{
+ int i;
+
+ if (COM_CheckParm("-nocdaudio"))
+ return -1;
+
+ if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1) {
+ strncpy(cd_dev, com_argv[i + 1], sizeof(cd_dev));
+ cd_dev[sizeof(cd_dev) - 1] = 0;
+ }
+
+ if ((cdfile = open(cd_dev, OREAD)) == -1) {
+ fprint(2, "CDAudio_Init:open: %r\n");
+ cdfile = -1;
+ return -1;
+ }
+
+ for (i = 0; i < 100; i++)
+ remap[i] = i;
+ initialized = true;
+ enabled = true;
+
+ if (CDAudio_GetAudioDiskInfo())
+ {
+ Con_Printf("CDAudio_Init: No CD in player.\n");
+ cdValid = false;
+ }
+
+ Cmd_AddCommand ("cd", CD_f);
+
+ Con_Printf("CD Audio Initialized\n");
+
+ return 0;
+}
+
+
+void CDAudio_Shutdown(void)
+{
+ if (!initialized)
+ return;
+ CDAudio_Stop();
+ close(cdfile);
+ cdfile = -1;
+}
--- a/qw/cl_cam.c
+++ b/qw/cl_cam.c
@@ -1,7 +1,5 @@
-/* ZOID
+/* Player camera tracking in Spectator mode
*
- * Player camera tracking in Spectator mode
- *
* This takes over player controls for spectator automatic camera.
* Player moves as a spectator, but the camera tracks and enemy player
*/
@@ -118,13 +116,13 @@
pmtrace_t Cam_DoTrace(vec3_t vec1, vec3_t vec2)
{
-#if 0
+/*
memset(&pmove, 0, sizeof(pmove));
pmove.numphysent = 1;
VectorCopy (vec3_origin, pmove.physents[0].origin);
pmove.physents[0].model = cl.worldmodel;
-#endif
+*/
VectorCopy (vec1, pmove.origin);
return PM_PlayerMove(pmove.origin, vec2);
@@ -342,7 +340,7 @@
VectorCopy(player->viewangles, cl.viewangles);
VectorCopy(player->origin, desired_position);
- if (memcmp(&desired_position, &self->origin, sizeof(desired_position)) != 0) {
+ if (memcmp(desired_position, self->origin, sizeof(desired_position)) != 0) {
MSG_WriteByte (&cls.netchan.message, clc_tmove);
MSG_WriteCoord (&cls.netchan.message, desired_position[0]);
MSG_WriteCoord (&cls.netchan.message, desired_position[1]);
@@ -374,7 +372,7 @@
}
}
-#if 0
+/*
static float adjustang(float current, float ideal, float speed)
{
float move;
@@ -410,9 +408,9 @@
//Con_Printf("c/i: %4.2f/%4.2f move: %4.2f\n", current, ideal, move);
return anglemod (current + move);
}
-#endif
+*/
-#if 0
+/*
void Cam_SetView(void)
{
return;
@@ -443,7 +441,7 @@
VectorCopy(cam_viewangles, cl.viewangles);
VectorCopy(cl.viewangles, cl.simangles);
}
-#endif
+*/
void Cam_FinishMove(usercmd_t *cmd)
{
@@ -457,7 +455,7 @@
if (!cl.spectator) // only in spectator mode
return;
-#if 0
+/*
if (autocam && locked) {
frame = &cl.frames[cls.netchan.incoming_sequence & UPDATE_MASK];
player = frame->playerstate + spec_track;
@@ -477,7 +475,7 @@
}
VectorCopy(cam_viewangles, cl.viewangles);
}
-#endif
+*/
if (cmd->buttons & BUTTON_ATTACK) {
if (!(oldbuttons & BUTTON_ATTACK)) {
--- a/qw/cl_demo.c
+++ b/qw/cl_demo.c
@@ -196,7 +196,7 @@
cls.netchan.outgoing_sequence++;
for (i=0 ; i<3 ; i++)
{
- r = fread (&f, 4, 1, cls.demofile);
+ fread (&f, 4, 1, cls.demofile);
cl.viewangles[i] = LittleFloat (f);
}
break;
@@ -361,7 +361,7 @@
int c;
char name[MAX_OSPATH];
sizebuf_t buf;
- char buf_data[MAX_MSGLEN];
+ uchar buf_data[MAX_MSGLEN];
int n, i, j;
char *s;
entity_t *ent;
@@ -618,7 +618,7 @@
}
}
-#if 0
+/*
MSG_WriteByte (&buf, svc_updatestatlong);
MSG_WriteByte (&buf, STAT_TOTALMONSTERS);
MSG_WriteLong (&buf, cl.stats[STAT_TOTALMONSTERS]);
@@ -630,7 +630,7 @@
MSG_WriteByte (&buf, svc_updatestatlong);
MSG_WriteByte (&buf, STAT_MONSTERS);
MSG_WriteLong (&buf, cl.stats[STAT_MONSTERS]);
-#endif
+*/
// get the client to check and download skins
// when that is completed, a begin command will be issued
@@ -637,11 +637,9 @@
MSG_WriteByte (&buf, svc_stufftext);
MSG_WriteString (&buf, va("skins\n") );
- CL_WriteRecordDemoMessage (&buf, seq++);
+ CL_WriteRecordDemoMessage (&buf, seq);
CL_WriteSetDemoMessage();
-
- // done
}
/*
--- a/qw/cl_ents.c
+++ b/qw/cl_ents.c
@@ -642,7 +642,6 @@
{
int msec;
int flags;
- player_info_t *info;
player_state_t *state;
int num;
int i;
@@ -651,8 +650,6 @@
if (num > MAX_CLIENTS)
Sys_Error ("CL_ParsePlayerinfo: bad num");
- info = &cl.players[num];
-
state = &cl.frames[parsecountmod].playerstate[num];
flags = state->flags = MSG_ReadShort ();
@@ -797,22 +794,16 @@
continue; // not present this frame
// spawn light flashes, even ones coming from invisible objects
-#ifdef GLQUAKE
- if (!gl_flashblend.value || j != cl.playernum) {
-#endif
- if ((state->effects & (EF_BLUE | EF_RED)) == (EF_BLUE | EF_RED))
- CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2], 200 + (rand()&31), 0.1, 3);
- else if (state->effects & EF_BLUE)
- CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2], 200 + (rand()&31), 0.1, 1);
- else if (state->effects & EF_RED)
- CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2], 200 + (rand()&31), 0.1, 2);
- else if (state->effects & EF_BRIGHTLIGHT)
- CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2] + 16, 400 + (rand()&31), 0.1, 0);
- else if (state->effects & EF_DIMLIGHT)
- CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2], 200 + (rand()&31), 0.1, 0);
-#ifdef GLQUAKE
- }
-#endif
+ if ((state->effects & (EF_BLUE | EF_RED)) == (EF_BLUE | EF_RED))
+ CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2], 200 + (rand()&31), 0.1, 3);
+ else if (state->effects & EF_BLUE)
+ CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2], 200 + (rand()&31), 0.1, 1);
+ else if (state->effects & EF_RED)
+ CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2], 200 + (rand()&31), 0.1, 2);
+ else if (state->effects & EF_BRIGHTLIGHT)
+ CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2] + 16, 400 + (rand()&31), 0.1, 0);
+ else if (state->effects & EF_DIMLIGHT)
+ CL_NewDlight (j, state->origin[0], state->origin[1], state->origin[2], 200 + (rand()&31), 0.1, 0);
// the player object never gets added
if (j == cl.playernum)
--- a/qw/cl_main.c
+++ b/qw/cl_main.c
@@ -2,9 +2,13 @@
#include <u.h>
#include <libc.h>
+#include <ctype.h>
#include <stdio.h>
#include "quakedef.h"
+enum{
+ Iploopback = 0x0100007f
+};
// we need to declare some mouse variables here, because the menu system
// references them even when on a unix system.
@@ -92,8 +96,6 @@
byte *host_basepal;
byte *host_colormap;
-netadr_t master_adr; // address of the master server
-
cvar_t host_speeds = {"host_speeds","0"}; // set for running times
cvar_t show_fps = {"show_fps","0"}; // set for running times
cvar_t developer = {"developer","0"};
@@ -144,7 +146,7 @@
void CL_Version_f (void)
{
Con_Printf ("Version %4.2f\n", VERSION);
- Con_Printf ("Exe: "__TIME__" "__DATE__"\n");
+ Con_Printf ("Exe: 00:00:00 Dec 17 1996\n");
}
@@ -176,13 +178,6 @@
return;
}
- if (!NET_IsClientLegal(&adr))
- {
- Con_Printf ("Illegal server address\n");
- connect_time = -1;
- return;
- }
-
if (adr.port == 0)
adr.port = BigShort (27500);
t2 = Sys_DoubleTime ();
@@ -227,12 +222,6 @@
connect_time = -1;
return;
}
- if (!NET_IsClientLegal(&adr))
- {
- Con_Printf ("Illegal server address\n");
- connect_time = -1;
- return;
- }
if (adr.port == 0)
adr.port = BigShort (27500);
@@ -387,10 +376,6 @@
connect_time = -1;
-#ifdef _WIN32
- SetWindowText (mainwindow, "QuakeWorld: disconnected");
-#endif
-
// stop sounds (especially looping!)
S_StopAllSounds (true);
@@ -403,7 +388,7 @@
CL_Stop_f ();
final[0] = clc_stringcmd;
- strcpy (final+1, "drop");
+ strcpy((char *)final+1, "drop");
Netchan_Transmit (&cls.netchan, 6, final);
Netchan_Transmit (&cls.netchan, 6, final);
Netchan_Transmit (&cls.netchan, 6, final);
@@ -603,7 +588,7 @@
if (*s)
s++;
- if (!stricmp(key, pmodel_name) || !stricmp(key, emodel_name))
+ if (!cistrcmp(key, pmodel_name) || !cistrcmp(key, emodel_name))
continue;
Info_SetValueForKey (cls.userinfo, key, value, MAX_INFO_STRING);
@@ -629,7 +614,7 @@
Con_Printf ("usage: setinfo [ <key> <value> ]\n");
return;
}
- if (!stricmp(Cmd_Argv(1), pmodel_name) || !strcmp(Cmd_Argv(1), emodel_name))
+ if (!cistrcmp(Cmd_Argv(1), pmodel_name) || !strcmp(Cmd_Argv(1), emodel_name))
return;
Info_SetValueForKey (cls.userinfo, Cmd_Argv(1), Cmd_Argv(2), MAX_INFO_STRING);
@@ -810,16 +795,12 @@
Con_Printf ("client command\n");
- if ((*(unsigned *)net_from.ip != *(unsigned *)net_local_adr.ip
- && *(unsigned *)net_from.ip != htonl(INADDR_LOOPBACK)) )
+ if ((*(unsigned *)net_from.ip != *(unsigned *)laddr.ip
+ && *(unsigned *)net_from.ip != Iploopback) )
{
Con_Printf ("Command packet from remote host. Ignored.\n");
return;
}
-#ifdef _WIN32
- ShowWindow (mainwindow, SW_RESTORE);
- SetForegroundWindow (mainwindow);
-#endif
s = MSG_ReadString ();
strncpy(cmdtext, s, sizeof(cmdtext) - 1);
@@ -879,7 +860,7 @@
data[4] = A2A_ACK;
data[5] = 0;
- NET_SendPacket (6, &data, net_from);
+ NET_SendPacket (6, data, net_from);
return;
}
@@ -892,7 +873,7 @@
return;
}
-#if 0
+/*
if (c == svc_disconnect) {
Con_Printf ("disconnect\n");
@@ -899,7 +880,7 @@
Host_EndGame ("Server disconnected");
return;
}
-#endif
+*/
Con_Printf ("unknown: %c\n", c);
}
@@ -1005,23 +986,8 @@
SZ_Print (&cls.netchan.message, va("download %s\n",Cmd_Argv(1)));
}
-#ifdef _WINDOWS
-#include <windows.h>
/*
=================
-CL_Minimize_f
-=================
-*/
-void CL_Windows_f (void) {
-// if (modestate == MS_WINDOWED)
-// ShowWindow(mainwindow, SW_MINIMIZE);
-// else
- SendMessage(mainwindow, WM_SYSKEYUP, VK_TAB, 1 | (0x0F << 16) | (1<<29));
-}
-#endif
-
-/*
-=================
CL_Init
=================
*/
@@ -1038,7 +1004,7 @@
Info_SetValueForKey (cls.userinfo, "bottomcolor", "0", MAX_INFO_STRING);
Info_SetValueForKey (cls.userinfo, "rate", "2500", MAX_INFO_STRING);
Info_SetValueForKey (cls.userinfo, "msg", "1", MAX_INFO_STRING);
- sprintf (st, "%4.2f", VERSION);
+ sprint(st, "%4.2f", VERSION);
Info_SetValueForStarKey (cls.userinfo, "*ver", st, MAX_INFO_STRING);
CL_InitInput ();
@@ -1146,13 +1112,6 @@
Cmd_AddCommand ("say", NULL);
Cmd_AddCommand ("say_team", NULL);
Cmd_AddCommand ("serverinfo", NULL);
-
-//
-// Windows commands
-//
-#ifdef _WINDOWS
- Cmd_AddCommand ("windows", CL_Windows_f);
-#endif
}
@@ -1242,7 +1201,6 @@
//============================================================================
-#if 0
/*
==================
Host_SimulationTime
@@ -1250,6 +1208,7 @@
This determines if enough time has passed to run a simulation frame
==================
*/
+/*
qboolean Host_SimulationTime(float time)
{
float fps;
@@ -1258,15 +1217,15 @@
oldrealtime = 0;
if (cl_maxfps.value)
- fps = max(30.0, min(cl_maxfps.value, 72.0));
+ fps = Max(30.0, Min(cl_maxfps.value, 72.0));
else
- fps = max(30.0, min(rate.value/80.0, 72.0));
+ fps = Max(30.0, Min(rate.value/80.0, 72.0));
if (!cls.timedemo && (realtime + time) - oldrealtime < 1.0/fps)
return false; // framerate is too high
return true;
}
-#endif
+*/
/*
@@ -1293,9 +1252,9 @@
oldrealtime = 0;
if (cl_maxfps.value)
- fps = max(30.0, min(cl_maxfps.value, 72.0));
+ fps = Max(30.0, Min(cl_maxfps.value, 72.0));
else
- fps = max(30.0, min(rate.value/80.0, 72.0));
+ fps = Max(30.0, Min(rate.value/80.0, 72.0));
if (!cls.timedemo && realtime - oldrealtime < 1.0/fps)
return; // framerate is too high
@@ -1394,12 +1353,12 @@
*/
void Host_Init (quakeparms_t *parms)
{
+ int p, port;
+
COM_InitArgv (parms->argc, parms->argv);
COM_AddParm ("-game");
COM_AddParm ("qw");
- Sys_mkdir("qw");
-
if (COM_CheckParm ("-minmemory"))
parms->memsize = MINIMUM_MEMORY;
@@ -1416,8 +1375,15 @@
COM_Init ();
Host_FixupModelNames();
-
- NET_Init (PORT_CLIENT);
+
+ port = PORT_CLIENT;
+ p = COM_CheckParm ("-cport");
+ if (p && p < com_argc)
+ {
+ port = atoi(com_argv[p+1]);
+ Con_Printf ("Client port: %i\n", port);
+ }
+ NET_Init (port);
Netchan_Init ();
W_LoadWadFile ("gfx.wad");
@@ -1425,12 +1391,11 @@
Con_Init ();
M_Init ();
Mod_Init ();
-
-// Con_Printf ("Exe: "__TIME__" "__DATE__"\n");
- Con_Printf ("%4.1f megs RAM used.\n",parms->memsize/ (1024*1024.0));
-
+
+ Con_Printf ("%4.1f megs RAM used.\n", parms->memsize/(1024*1024.0));
+
R_InitTextures ();
-
+
host_basepal = (byte *)COM_LoadHunkFile ("gfx/palette.lmp");
if (!host_basepal)
Sys_Error ("Couldn't load gfx/palette.lmp");
@@ -1437,7 +1402,7 @@
host_colormap = (byte *)COM_LoadHunkFile ("gfx/colormap.lmp");
if (!host_colormap)
Sys_Error ("Couldn't load gfx/colormap.lmp");
-#ifdef __linux__
+
IN_Init ();
CDAudio_Init ();
VID_Init (host_basepal);
@@ -1444,28 +1409,10 @@
Draw_Init ();
SCR_Init ();
R_Init ();
-
-// S_Init (); // S_Init is now done as part of VID. Sigh.
-
+ S_Init ();
cls.state = ca_disconnected;
Sbar_Init ();
CL_Init ();
-#else
- VID_Init (host_basepal);
- Draw_Init ();
- SCR_Init ();
- R_Init ();
-// S_Init (); // S_Init is now done as part of VID. Sigh.
-#ifdef GLQUAKE
- S_Init();
-#endif
-
- cls.state = ca_disconnected;
- CDAudio_Init ();
- Sbar_Init ();
- CL_Init ();
- IN_Init ();
-#endif
Cbuf_InsertText ("exec quake.rc\n");
Cbuf_AddText ("echo Type connect <internet address> or use GameSpy to connect to a game.\n");
--- a/qw/cl_parse.c
+++ b/qw/cl_parse.c
@@ -100,7 +100,6 @@
int a, i;
frame_t *frame;
int lost;
- char st[80];
for (i=cls.netchan.outgoing_sequence-UPDATE_BACKUP+1
; i <= cls.netchan.outgoing_sequence
@@ -308,6 +307,22 @@
}
}
+static void
+rename(char *old, char *new)
+{
+ char *p;
+ Dir d;
+
+ if((p = strrchr(new, '/')) == nil)
+ p = new;
+ else
+ p++;
+ nulldir(&d);
+ d.name = p;
+ if(dirwstat(old, &d) < 0)
+ fprint(2, "rename: %r\n");
+}
+
/*
=====================
CL_ParseDownload
@@ -318,10 +333,8 @@
void CL_ParseDownload (void)
{
int size, percent;
- byte name[1024];
- int r;
+ char name[1024];
-
// read the data
size = MSG_ReadShort ();
percent = MSG_ReadByte ();
@@ -348,10 +361,10 @@
// open the file if not opened yet
if (!cls.download)
{
- if (strncmp(cls.downloadtempname,"skins/",6))
- sprintf (name, "%s/%s", com_gamedir, cls.downloadtempname);
+ if(strncmp(cls.downloadtempname, "skins/", 6))
+ sprint(name, "%s/%s", com_gamedir, cls.downloadtempname);
else
- sprintf (name, "qw/%s", cls.downloadtempname);
+ sprint(name, "qw/%s", cls.downloadtempname);
COM_CreatePath (name);
@@ -372,7 +385,7 @@
{
// change display routines by zoid
// request next block
-#if 0
+/*
Con_Printf (".");
if (10*(percent/10) != cls.downloadpercent)
{
@@ -379,7 +392,7 @@
cls.downloadpercent = 10*(percent/10);
Con_Printf ("%i%%", cls.downloadpercent);
}
-#endif
+*/
cls.downloadpercent = percent;
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
@@ -390,9 +403,9 @@
char oldn[MAX_OSPATH];
char newn[MAX_OSPATH];
-#if 0
+/*
Con_Printf ("100%%\n");
-#endif
+*/
fclose (cls.download);
@@ -399,15 +412,13 @@
// rename the temp file to it's final name
if (strcmp(cls.downloadtempname, cls.downloadname)) {
if (strncmp(cls.downloadtempname,"skins/",6)) {
- sprintf (oldn, "%s/%s", com_gamedir, cls.downloadtempname);
- sprintf (newn, "%s/%s", com_gamedir, cls.downloadname);
+ sprint(oldn, "%s/%s", com_gamedir, cls.downloadtempname);
+ sprint(newn, "%s/%s", com_gamedir, cls.downloadname);
} else {
- sprintf (oldn, "qw/%s", cls.downloadtempname);
- sprintf (newn, "qw/%s", cls.downloadname);
+ sprint(oldn, "qw/%s", cls.downloadtempname);
+ sprint(newn, "qw/%s", cls.downloadname);
}
- r = rename (oldn, newn);
- if (r)
- Con_Printf ("failed to rename.\n");
+ rename(oldn, newn);
}
cls.download = NULL;
@@ -533,7 +544,7 @@
// game directory
str = MSG_ReadString ();
- if (stricmp(gamedirfile, str)) {
+ if (cistrcmp(gamedirfile, str)) {
// save current config
Host_WriteConfiguration ();
cflag = true;
@@ -854,13 +865,6 @@
*/
void CL_NewTranslation (int slot)
{
-#ifdef GLQUAKE
- if (slot > MAX_CLIENTS)
- Sys_Error ("CL_NewTranslation: slot > MAX_CLIENTS");
-
- R_TranslatePlayerSkin(slot);
-#else
-
int i, j;
int top, bottom;
byte *dest, *source;
@@ -874,7 +878,7 @@
strcpy(s, Info_ValueForKey(player->userinfo, "skin"));
COM_StripExtension(s, s);
- if (player->skin && !stricmp(s, player->skin->name))
+ if (player->skin && !cistrcmp(s, player->skin->name))
player->skin = NULL;
if (player->_topcolor != player->topcolor ||
@@ -909,7 +913,6 @@
dest[BOTTOM_RANGE+j] = source[bottom+15-j];
}
}
-#endif
}
/*
@@ -992,8 +995,6 @@
*/
void CL_ServerInfo (void)
{
- int slot;
- player_info_t *player;
char key[MAX_MSGLEN];
char value[MAX_MSGLEN];
@@ -1048,12 +1049,6 @@
if ((unsigned)(i-1) >= MAX_CLIENTS)
return;
-#ifdef GLQUAKE
- // don't draw our own muzzle flash in gl if flashblending
- if (i-1 == cl.playernum && gl_flashblend.value)
- return;
-#endif
-
pl = &cl.frames[parsecountmod].playerstate[i-1];
dl = CL_AllocDlight (i);
@@ -1181,8 +1176,8 @@
i = MSG_ReadByte ();
if (i >= MAX_LIGHTSTYLES)
Sys_Error ("svc_lightstyle > MAX_LIGHTSTYLES");
- Q_strcpy (cl_lightstyle[i].map, MSG_ReadString());
- cl_lightstyle[i].length = Q_strlen(cl_lightstyle[i].map);
+ strcpy(cl_lightstyle[i].map, MSG_ReadString());
+ cl_lightstyle[i].length = strlen(cl_lightstyle[i].map);
break;
case svc_sound:
--- a/qw/cl_pred.c
+++ b/qw/cl_pred.c
@@ -130,9 +130,6 @@
cls.state = ca_active;
sprintf (text, "QuakeWorld: %s", cls.servername);
-#ifdef _WIN32
- SetWindowText (mainwindow, text);
-#endif
}
if (cl_nopred.value)
--- a/qw/cl_tent.c
+++ b/qw/cl_tent.c
@@ -59,8 +59,8 @@
*/
void CL_ClearTEnts (void)
{
- memset (&cl_beams, 0, sizeof(cl_beams));
- memset (&cl_explosions, 0, sizeof(cl_explosions));
+ memset (cl_beams, 0, sizeof(cl_beams));
+ memset (cl_explosions, 0, sizeof(cl_explosions));
}
/*
--- a/qw/client.h
+++ b/qw/client.h
@@ -299,7 +299,7 @@
extern cvar_t m_forward;
extern cvar_t m_side;
-extern cvar_t _windowed_mouse;
+extern cvar_t m_windowed;
extern cvar_t name;
--- a/qw/cmd.c
+++ b/qw/cmd.c
@@ -71,7 +71,7 @@
{
int l;
- l = Q_strlen (text);
+ l = strlen (text);
if (cmd_text.cursize + l >= cmd_text.maxsize)
{
@@ -78,7 +78,7 @@
Con_Printf ("Cbuf_AddText: overflow\n");
return;
}
- SZ_Write (&cmd_text, text, Q_strlen (text));
+ SZ_Write (&cmd_text, text, strlen (text));
}
@@ -101,7 +101,7 @@
if (templen)
{
temp = Z_Malloc (templen);
- Q_memcpy (temp, cmd_text.data, templen);
+ memcpy (temp, cmd_text.data, templen);
SZ_Clear (&cmd_text);
}
else
@@ -160,7 +160,7 @@
{
i++;
cmd_text.cursize -= i;
- Q_memcpy (text, text+i, cmd_text.cursize);
+ memcpy (text, text+i, cmd_text.cursize);
}
// execute the command line
@@ -205,7 +205,7 @@
{
if (!com_argv[i])
continue; // NEXTSTEP nulls out -NXHost
- s += Q_strlen (com_argv[i]) + 1;
+ s += strlen (com_argv[i]) + 1;
}
if (!s)
return;
@@ -216,9 +216,9 @@
{
if (!com_argv[i])
continue; // NEXTSTEP nulls out -NXHost
- Q_strcat (text,com_argv[i]);
+ strcat (text,com_argv[i]);
if (i != com_argc-1)
- Q_strcat (text, " ");
+ strcat (text, " ");
}
// pull out the commands
@@ -237,8 +237,8 @@
c = text[j];
text[j] = 0;
- Q_strcat (build, text+i);
- Q_strcat (build, "\n");
+ strcat (build, text+i);
+ strcat (build, "\n");
text[j] = c;
i = j-1;
}
@@ -461,11 +461,8 @@
text++;
}
- if (*text == '\n')
- { // a newline seperates commands in the buffer
- text++;
+ if (*text == '\n') // a newline seperates commands in the buffer
break;
- }
if (!*text)
return;
@@ -479,8 +476,8 @@
if (cmd_argc < MAX_ARGS)
{
- cmd_argv[cmd_argc] = Z_Malloc (Q_strlen(com_token)+1);
- Q_strcpy (cmd_argv[cmd_argc], com_token);
+ cmd_argv[cmd_argc] = Z_Malloc (strlen(com_token)+1);
+ strcpy (cmd_argv[cmd_argc], com_token);
cmd_argc++;
}
}
@@ -510,7 +507,7 @@
// fail if the command already exists
for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
{
- if (!Q_strcmp (cmd_name, cmd->name))
+ if (!strcmp (cmd_name, cmd->name))
{
Con_Printf ("Cmd_AddCommand: %s already defined\n", cmd_name);
return;
@@ -535,7 +532,7 @@
for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
{
- if (!Q_strcmp (cmd_name,cmd->name))
+ if (!strcmp (cmd_name,cmd->name))
return true;
}
@@ -555,7 +552,7 @@
int len;
cmdalias_t *a;
- len = Q_strlen(partial);
+ len = strlen(partial);
if (!len)
return NULL;
@@ -579,7 +576,6 @@
return NULL;
}
-#ifndef SERVERONLY // FIXME
/*
===================
Cmd_ForwardToServer
@@ -591,6 +587,9 @@
*/
void Cmd_ForwardToServer (void)
{
+ if(svonly)
+ return;
+
if (cls.state == ca_disconnected)
{
Con_Printf ("Can't \"%s\", not connected\n", Cmd_Argv(0));
@@ -618,7 +617,7 @@
return;
}
- if (Q_strcasecmp(Cmd_Argv(1), "snap") == 0) {
+ if (cistrcmp(Cmd_Argv(1), "snap") == 0) {
Cbuf_InsertText ("snap\n");
return;
}
@@ -632,11 +631,6 @@
SZ_Print (&cls.netchan.message, Cmd_Args());
}
}
-#else
-void Cmd_ForwardToServer (void)
-{
-}
-#endif
/*
============
@@ -660,7 +654,7 @@
// check functions
for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
{
- if (!Q_strcasecmp (cmd_argv[0],cmd->name))
+ if(!cistrcmp(cmd_argv[0], cmd->name))
{
if (!cmd->function)
Cmd_ForwardToServer ();
@@ -673,7 +667,7 @@
// check alias
for (a=cmd_alias ; a ; a=a->next)
{
- if (!Q_strcasecmp (cmd_argv[0], a->name))
+ if (!cistrcmp (cmd_argv[0], a->name))
{
Cbuf_InsertText (a->value);
return;
@@ -704,7 +698,7 @@
Sys_Error ("Cmd_CheckParm: NULL");
for (i = 1; i < Cmd_Argc (); i++)
- if (! Q_strcasecmp (parm, Cmd_Argv (i)))
+ if (!cistrcmp (parm, Cmd_Argv (i)))
return i;
return 0;
@@ -725,8 +719,8 @@
Cmd_AddCommand ("echo",Cmd_Echo_f);
Cmd_AddCommand ("alias",Cmd_Alias_f);
Cmd_AddCommand ("wait", Cmd_Wait_f);
-#ifndef SERVERONLY
- Cmd_AddCommand ("cmd", Cmd_ForwardToServer_f);
-#endif
+
+ if(!svonly)
+ Cmd_AddCommand ("cmd", Cmd_ForwardToServer_f);
}
--- a/qw/common.c
+++ b/qw/common.c
@@ -3,15 +3,10 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include <ctype.h>
-
-#ifdef SERVERONLY
-#include "qwsvdef.h"
-#else
#include "quakedef.h"
-#endif
-#define MAX_NUM_ARGVS 50
+cvar_t sv_highchars = {"sv_highchars", "1"};
+
#define NUM_SAFE_ARGVS 6
usercmd_t nullcmd; // guarenteed to be zero
@@ -117,163 +112,6 @@
============================================================================
*/
-#if 0
-void Q_memset (void *dest, int fill, int count)
-{
- int i;
-
- if ( (((long)dest | count) & 3) == 0)
- {
- count >>= 2;
- fill = fill | (fill<<8) | (fill<<16) | (fill<<24);
- for (i=0 ; i<count ; i++)
- ((int *)dest)[i] = fill;
- }
- else
- for (i=0 ; i<count ; i++)
- ((byte *)dest)[i] = fill;
-}
-
-void Q_memcpy (void *dest, void *src, int count)
-{
- int i;
-
- if (( ( (long)dest | (long)src | count) & 3) == 0 )
- {
- count>>=2;
- for (i=0 ; i<count ; i++)
- ((int *)dest)[i] = ((int *)src)[i];
- }
- else
- for (i=0 ; i<count ; i++)
- ((byte *)dest)[i] = ((byte *)src)[i];
-}
-
-int Q_memcmp (void *m1, void *m2, int count)
-{
- while(count)
- {
- count--;
- if (((byte *)m1)[count] != ((byte *)m2)[count])
- return -1;
- }
- return 0;
-}
-
-void Q_strcpy (char *dest, char *src)
-{
- while (*src)
- {
- *dest++ = *src++;
- }
- *dest++ = 0;
-}
-
-void Q_strncpy (char *dest, char *src, int count)
-{
- while (*src && count--)
- {
- *dest++ = *src++;
- }
- if (count)
- *dest++ = 0;
-}
-
-int Q_strlen (char *str)
-{
- int count;
-
- count = 0;
- while (str[count])
- count++;
-
- return count;
-}
-
-char *Q_strrchr(char *s, char c)
-{
- int len = Q_strlen(s);
- s += len;
- while (len--)
- if (*--s == c) return s;
- return 0;
-}
-
-void Q_strcat (char *dest, char *src)
-{
- dest += Q_strlen(dest);
- Q_strcpy (dest, src);
-}
-
-int Q_strcmp (char *s1, char *s2)
-{
- while (1)
- {
- if (*s1 != *s2)
- return -1; // strings not equal
- if (!*s1)
- return 0; // strings are equal
- s1++;
- s2++;
- }
-
- return -1;
-}
-
-int Q_strncmp (char *s1, char *s2, int count)
-{
- while (1)
- {
- if (!count--)
- return 0;
- if (*s1 != *s2)
- return -1; // strings not equal
- if (!*s1)
- return 0; // strings are equal
- s1++;
- s2++;
- }
-
- return -1;
-}
-
-int Q_strncasecmp (char *s1, char *s2, int n)
-{
- int c1, c2;
-
- while (1)
- {
- c1 = *s1++;
- c2 = *s2++;
-
- if (!n--)
- return 0; // strings are equal until end point
-
- if (c1 != c2)
- {
- if (c1 >= 'a' && c1 <= 'z')
- c1 -= ('a' - 'A');
- if (c2 >= 'a' && c2 <= 'z')
- c2 -= ('a' - 'A');
- if (c1 != c2)
- return -1; // strings not equal
- }
- if (!c1)
- return 0; // strings are equal
-// s1++;
-// s2++;
- }
-
- return -1;
-}
-
-int Q_strcasecmp (char *s1, char *s2)
-{
- return Q_strncasecmp (s1, s2, 99999);
-}
-
-#endif
-
int Q_atoi (char *str)
{
int val;
@@ -328,8 +166,6 @@
return val*sign;
val = val*10 + c - '0';
}
-
- return 0;
}
@@ -563,7 +399,7 @@
if (!s)
SZ_Write (sb, "", 1);
else
- SZ_Write (sb, s, Q_strlen(s)+1);
+ SZ_Write (sb, s, strlen(s)+1);
}
void MSG_WriteCoord (sizebuf_t *sb, float f)
@@ -862,7 +698,7 @@
void SZ_Write (sizebuf_t *buf, void *data, int length)
{
- Q_memcpy (SZ_GetSpace(buf,length),data,length);
+ memcpy (SZ_GetSpace(buf,length),data,length);
}
void SZ_Print (sizebuf_t *buf, char *data)
@@ -869,12 +705,12 @@
{
int len;
- len = Q_strlen(data)+1;
+ len = strlen(data)+1;
if (!buf->cursize || buf->data[buf->cursize-1])
- Q_memcpy ((byte *)SZ_GetSpace(buf, len),data,len); // no trailing 0
+ memcpy ((byte *)SZ_GetSpace(buf, len),data,len); // no trailing 0
else
- Q_memcpy ((byte *)SZ_GetSpace(buf, len-1)-1,data,len); // write over trailing 0
+ memcpy ((byte *)SZ_GetSpace(buf, len-1)-1,data,len); // write over trailing 0
}
@@ -1075,7 +911,7 @@
{
if (!com_argv[i])
continue; // NEXTSTEP sometimes clears appkit vars.
- if (!Q_strcmp (parm,com_argv[i]))
+ if (!strcmp (parm,com_argv[i]))
return i;
}
@@ -1104,11 +940,10 @@
if (!h)
{
Con_Printf ("Playing shareware version.\n");
-#ifndef SERVERONLY
-// FIXME DEBUG -- only temporary
- if (com_modified)
+ /*
+ if(!svonly && com_modified)
Sys_Error ("You must have the registered version to play QuakeWorld");
-#endif
+ */
return;
}
@@ -1142,7 +977,7 @@
com_argc++)
{
largv[com_argc] = argv[com_argc];
- if (!Q_strcmp ("-safe", argv[com_argc]))
+ if (!strcmp ("-safe", argv[com_argc]))
safe = true;
}
@@ -1294,7 +1129,7 @@
#define MAX_FILES_IN_PACK 2048
char com_gamedir[MAX_OSPATH];
-char com_basedir[MAX_OSPATH];
+char com_basedir[MAX_OSPATH] = "/sys/games/lib/quake";
typedef struct searchpath_s
{
@@ -1571,14 +1406,10 @@
Sys_Error ("COM_LoadFile: not enough space for %s", path);
((byte *)buf)[len] = 0;
-#ifndef SERVERONLY
- Draw_BeginDisc ();
-#endif
+ Draw_BeginDisc();
fread (buf, 1, len, h);
fclose (h);
-#ifndef SERVERONLY
- Draw_EndDisc ();
-#endif
+ Draw_EndDisc();
return buf;
}
@@ -1653,7 +1484,7 @@
newfiles = Z_Malloc (numpackfiles * sizeof(packfile_t));
fseek (packhandle, header.dirofs, SEEK_SET);
- fread (&info, 1, header.dirlen, packhandle);
+ fread (info, 1, header.dirlen, packhandle);
// crc the directory to check for modifications
crc = CRC_Block((byte *)info, header.dirlen);
@@ -1813,6 +1644,7 @@
void COM_InitFilesystem (void)
{
int i;
+ char *p;
//
// -basedir <path>
@@ -1821,14 +1653,17 @@
i = COM_CheckParm ("-basedir");
if (i && i < com_argc-1)
strcpy (com_basedir, com_argv[i+1]);
- else
- strcpy (com_basedir, host_parms.basedir);
//
// start up with id1 by default
//
- COM_AddGameDirectory (va("%s/id1", com_basedir) );
- COM_AddGameDirectory (va("%s/qw", com_basedir) );
+ COM_AddGameDirectory ("/sys/games/lib/quake/id1");
+ COM_AddGameDirectory ("/sys/games/lib/quake/qw");
+ if(p = getenv("home")){
+ COM_AddGameDirectory (va("%s/lib/quake/id1", p) );
+ COM_AddGameDirectory (va("%s/lib/quake/qw", p) );
+ free(p);
+ }
// any set gamedirs will be freed up to here
com_base_searchpaths = com_searchpaths;
@@ -1992,9 +1827,6 @@
{
char new[1024], *v;
int c;
-#ifdef SERVERONLY
- extern cvar_t sv_highchars;
-#endif
if (strstr (key, "\\") || strstr (value, "\\") )
{
@@ -2041,23 +1873,23 @@
while (*v)
{
c = (unsigned char)*v++;
-#ifndef SERVERONLY
- // client only allows highbits on name
- if (stricmp(key, "name") != 0) {
- c &= 127;
- if (c < 32 || c > 127)
- continue;
- // auto lowercase team
- if (stricmp(key, "team") == 0)
- c = tolower(c);
+ if(!svonly){
+ // client only allows highbits on name
+ if(cistrcmp(key, "name") != 0){
+ c &= 127;
+ if(c < 32 || c > 127)
+ continue;
+ // auto lowercase team
+ if(cistrcmp(key, "team") == 0)
+ c = tolower(c);
+ }
+ }else{
+ if(!sv_highchars.value){
+ c &= 127;
+ if(c < 32 || c > 127)
+ continue;
+ }
}
-#else
- if (!sv_highchars.value) {
- c &= 127;
- if (c < 32 || c > 127)
- continue;
- }
-#endif
// c &= 127; // strip high bits
if (c > 13) // && c < 127)
*s++ = c;
@@ -2161,14 +1993,7 @@
static unsigned last_mapchecksum = 0;
-#if 0
-/*
-====================
-COM_BlockSequenceCheckByte
-
-For proxy protecting
-====================
-*/
+/* For proxy protecting
byte COM_BlockSequenceCheckByte (byte *base, int length, int sequence, unsigned mapchecksum)
{
int checksum;
@@ -2205,7 +2030,7 @@
return checksum;
}
-#endif
+*/
/*
====================
--- a/qw/common.h
+++ b/qw/common.h
@@ -3,10 +3,6 @@
typedef unsigned char byte;
#define _DEF_BYTE_
-// KJB Undefined true and false defined in SciTech's DEBUG.H header
-#undef true
-#undef false
-
typedef enum {false, true} qboolean;
#define MAX_INFO_STRING 196
@@ -113,33 +109,8 @@
//============================================================================
-#define Q_memset(d, f, c) memset((d), (f), (c))
-#define Q_memcpy(d, s, c) memcpy((d), (s), (c))
-#define Q_memcmp(m1, m2, c) memcmp((m1), (m2), (c))
-#define Q_strcpy(d, s) strcpy((d), (s))
-#define Q_strncpy(d, s, n) strncpy((d), (s), (n))
-#define Q_strlen(s) ((int)strlen(s))
-#define Q_strrchr(s, c) strrchr((s), (c))
-#define Q_strcat(d, s) strcat((d), (s))
-#define Q_strcmp(s1, s2) strcmp((s1), (s2))
-#define Q_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
-
-#ifdef _WIN32
-
-#define Q_strcasecmp(s1, s2) _stricmp((s1), (s2))
-#define Q_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n))
-
-#else
-
-#define Q_strcasecmp(s1, s2) strcasecmp((s1), (s2))
-#define Q_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n))
-
-#endif
-
int Q_atoi (char *str);
float Q_atof (char *str);
-
-
//============================================================================
--- a/qw/console.c
+++ b/qw/console.c
@@ -23,8 +23,6 @@
int con_vislines;
int con_notifylines; // scan lines to clear for notify lines
-qboolean con_debuglog;
-
#define MAXCMDLINE 256
extern char key_lines[32][MAXCMDLINE];
extern int edit_line;
@@ -87,8 +85,8 @@
*/
void Con_Clear_f (void)
{
- Q_memset (con_main.text, ' ', CON_TEXTSIZE);
- Q_memset (con_chat.text, ' ', CON_TEXTSIZE);
+ memset (con_main.text, ' ', CON_TEXTSIZE);
+ memset (con_chat.text, ' ', CON_TEXTSIZE);
}
@@ -149,7 +147,7 @@
width = 38;
con_linewidth = width;
con_totallines = CON_TEXTSIZE / con_linewidth;
- Q_memset (con->text, ' ', CON_TEXTSIZE);
+ memset (con->text, ' ', CON_TEXTSIZE);
}
else
{
@@ -167,8 +165,8 @@
if (con_linewidth < numchars)
numchars = con_linewidth;
- Q_memcpy (tbuf, con->text, CON_TEXTSIZE);
- Q_memset (con->text, ' ', CON_TEXTSIZE);
+ memcpy (tbuf, con->text, CON_TEXTSIZE);
+ memset (con->text, ' ', CON_TEXTSIZE);
for (i=0 ; i<numlines ; i++)
{
@@ -209,8 +207,6 @@
*/
void Con_Init (void)
{
- con_debuglog = COM_CheckParm("-condebug");
-
con = &con_main;
con_linewidth = -1;
Con_CheckResize ();
@@ -242,7 +238,7 @@
if (con->display == con->current)
con->display++;
con->current++;
- Q_memset (&con->text[(con->current%con_totallines)*con_linewidth]
+ memset (&con->text[(con->current%con_totallines)*con_linewidth]
, ' ', con_linewidth);
}
@@ -344,10 +340,6 @@
// also echo to debugging console
Sys_Printf ("%s", msg); // also echo to debugging console
-
-// log all messages to file
- if (con_debuglog)
- Sys_DebugLog(va("%s/qconsole.log",com_gamedir), "%s", msg);
if (!con_initialized)
return;
@@ -409,7 +401,6 @@
*/
void Con_DrawInput (void)
{
- int y;
int i;
char *text;
@@ -430,7 +421,7 @@
text += 1 + key_linepos - con_linewidth;
// draw it
- y = con_vislines-22;
+ //int y = con_vislines-22;
for (i=0 ; i<con_linewidth ; i++)
Draw_Character ( (i+1)<<3, con_vislines - 22, text[i]);
@@ -586,7 +577,7 @@
strcpy(dlbar, text);
strcat(dlbar, ": ");
i = strlen(dlbar);
- dlbar[i++] = '\x80';
+ dlbar[i++] = 0x80;
// where's the dot go?
if (cls.downloadpercent == 0)
n = 0;
@@ -595,10 +586,10 @@
for (j = 0; j < y; j++)
if (j == n)
- dlbar[i++] = '\x83';
+ dlbar[i++] = 0x83;
else
- dlbar[i++] = '\x81';
- dlbar[i++] = '\x82';
+ dlbar[i++] = 0x81;
+ dlbar[i++] = 0x82;
dlbar[i] = 0;
sprintf(dlbar + strlen(dlbar), " %02d%%", cls.downloadpercent);
--- a/qw/crc.c
+++ b/qw/crc.c
@@ -2,7 +2,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "crc.h"
// this is a 16 bit, non-reflected CRC using the polynomial 0x1021
// and the initial and final xor values shown below... in other words, the
--- a/qw/cvar.c
+++ b/qw/cvar.c
@@ -3,11 +3,7 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#ifdef SERVERONLY
-#include "qwsvdef.h"
-#else
#include "quakedef.h"
-#endif
cvar_t *cvar_vars;
char *cvar_null_string = "";
@@ -22,7 +18,7 @@
cvar_t *var;
for (var=cvar_vars ; var ; var=var->next)
- if (!Q_strcmp (var_name, var->name))
+ if (!strcmp (var_name, var->name))
return var;
return NULL;
@@ -70,7 +66,7 @@
cvar_t *cvar;
int len;
- len = Q_strlen(partial);
+ len = strlen(partial);
if (!len)
return NULL;
@@ -82,7 +78,7 @@
// check partial match
for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
- if (!Q_strncmp (partial,cvar->name, len))
+ if (!strncmp (partial,cvar->name, len))
return cvar->name;
return NULL;
@@ -89,10 +85,6 @@
}
-#ifdef SERVERONLY
-void SV_SendServerInfoChange(char *key, char *value);
-#endif
-
/*
============
Cvar_Set
@@ -109,29 +101,24 @@
return;
}
-#ifdef SERVERONLY
- if (var->info)
- {
- Info_SetValueForKey (svs.info, var_name, value, MAX_SERVERINFO_STRING);
- SV_SendServerInfoChange(var_name, value);
-// SV_BroadcastCommand ("fullserverinfo \"%s\"\n", svs.info);
- }
-#else
- if (var->info)
- {
- Info_SetValueForKey (cls.userinfo, var_name, value, MAX_INFO_STRING);
- if (cls.state >= ca_connected)
- {
- MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
- SZ_Print (&cls.netchan.message, va("setinfo \"%s\" \"%s\"\n", var_name, value));
+ if(var->info){
+ if(svonly){
+ Info_SetValueForKey(svs.info, var_name, value, MAX_SERVERINFO_STRING);
+ SV_SendServerInfoChange(var_name, value);
+// SV_BroadcastCommand("fullserverinfo \"%s\"\n", svs.info);
+ }else{
+ Info_SetValueForKey(cls.userinfo, var_name, value, MAX_INFO_STRING);
+ if(cls.state >= ca_connected){
+ MSG_WriteByte(&cls.netchan.message, clc_stringcmd);
+ SZ_Print(&cls.netchan.message, va("setinfo \"%s\" \"%s\"\n", var_name, value));
+ }
}
}
-#endif
Z_Free (var->string); // free the old value string
- var->string = Z_Malloc (Q_strlen(value)+1);
- Q_strcpy (var->string, value);
+ var->string = Z_Malloc (strlen(value)+1);
+ strcpy (var->string, value);
var->value = Q_atof (var->string);
}
--- a/qw/d_edge.c
+++ b/qw/d_edge.c
@@ -2,7 +2,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "d_local.h"
static int miplevel;
@@ -104,14 +103,11 @@
*/
void D_CalcGradients (msurface_t *pface)
{
- mplane_t *pplane;
float mipscale;
vec3_t p_temp1;
vec3_t p_saxis, p_taxis;
float t;
- pplane = pface->plane;
-
mipscale = 1.0 / (float)(1 << miplevel);
TransformVector (pface->texinfo->vecs[0], p_saxis);
@@ -177,11 +173,7 @@
d_zistepv = s->d_zistepv;
d_ziorigin = s->d_ziorigin;
-#ifdef __alpha__
- D_DrawSolidSurface (s, (int)((long)s->data & 0xFF));
-#else
- D_DrawSolidSurface (s, (int)s->data & 0xFF);
-#endif
+ D_DrawSolidSurface (s, (uintptr)s->data & 0xFF);
D_DrawZSpans (s->spans);
}
}
--- a/qw/d_fill.c
+++ b/qw/d_fill.c
@@ -5,7 +5,6 @@
#include <stdio.h>
#include "quakedef.h"
-
/*
================
D_FillRect
@@ -42,7 +41,7 @@
dest = ((byte *)vid.buffer + ry*vid.rowbytes + rx);
- if (((rwidth & 0x03) == 0) && (((long)dest & 0x03) == 0))
+ if (((rwidth & 0x03) == 0) && (((uintptr)dest & 0x03) == 0))
{
// faster aligned dword clear
ldest = (unsigned *)dest;
--- a/qw/d_iface.h
+++ b/qw/d_iface.h
@@ -115,11 +115,6 @@
extern zpointdesc_t r_zpointdesc;
extern polydesc_t r_polydesc;
-extern int d_con_indirect; // if 0, Quake will draw console directly
- // to vid.buffer; if 1, Quake will
- // draw console via D_DrawRect. Must be
- // defined by driver
-
extern vec3_t r_pright, r_pup, r_ppn;
--- a/qw/d_init.c
+++ b/qw/d_init.c
@@ -4,11 +4,9 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "d_local.h"
#define NUM_MIPS 4
-cvar_t d_subdiv16 = {"d_subdiv16", "1"};
cvar_t d_mipcap = {"d_mipcap", "0"};
cvar_t d_mipscale = {"d_mipscale", "1"};
@@ -31,10 +29,8 @@
*/
void D_Init (void)
{
-
r_skydirect = 1;
- Cvar_RegisterVariable (&d_subdiv16);
Cvar_RegisterVariable (&d_mipcap);
Cvar_RegisterVariable (&d_mipscale);
@@ -51,17 +47,13 @@
D_CopyRects
===============
*/
-void D_CopyRects (vrect_t *prects, int transparent)
+void D_CopyRects (vrect_t */*prects*/, int /*transparent*/)
{
-
// this function is only required if the CPU doesn't have direct access to the
// back buffer, and there's some driver interface function that the driver
// doesn't support and requires Quake to do in software (such as drawing the
// console); Quake will then draw into wherever the driver points vid.buffer
// and will call this function before swapping buffers
-
- USED(prects);
- USED(transparent);
}
@@ -72,7 +64,6 @@
*/
void D_EnableBackBufferAccess (void)
{
-
VID_LockBuffer ();
}
@@ -130,29 +121,16 @@
for (i=0 ; i<(NUM_MIPS-1) ; i++)
d_scalemip[i] = basemip[i] * d_mipscale.value;
-#if id386
- if (d_subdiv16.value)
- d_drawspans = D_DrawSpans16;
- else
- d_drawspans = D_DrawSpans8;
-#else
- d_drawspans = D_DrawSpans8;
-#endif
-
+ d_drawspans = D_DrawSpans8; /* no DrawSpans16 for non-asm heathens */
d_aflatcolor = 0;
}
-
/*
===============
D_UpdateRects
===============
*/
-void D_UpdateRects (vrect_t *prect)
+void D_UpdateRects (vrect_t */*prect*/)
{
-
// the software driver draws these directly to the vid buffer
-
- USED(prect);
}
-
--- a/qw/d_local.h
+++ b/qw/d_local.h
@@ -1,7 +1,5 @@
// d_local.h: private rasterization driver defs
-#include "r_shared.h"
-
//
// TODO: fine-tune this; it's based on providing some overage even if there
// is a 2k-wide scan, with subdivision every 8, for 256 spans of 12 bytes each
@@ -65,11 +63,6 @@
surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel);
extern int D_MipLevelForScale (float scale);
-
-#if id386
-extern void D_PolysetAff8Start (void);
-extern void D_PolysetAff8End (void);
-#endif
extern short *d_pzbuffer;
extern unsigned int d_zrowbytes, d_zwidth;
--- a/qw/d_modech.c
+++ b/qw/d_modech.c
@@ -4,7 +4,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "d_local.h"
int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;
@@ -13,25 +12,9 @@
int d_scantable[MAXHEIGHT];
short *zspantable[MAXHEIGHT];
-/*
-================
-D_Patch
-================
-*/
+
void D_Patch (void)
{
-#if id386
-
- static qboolean protectset8 = false;
-
- if (!protectset8)
- {
- Sys_MakeCodeWriteable ((int)D_PolysetAff8Start,
- (int)D_PolysetAff8End - (int)D_PolysetAff8Start);
- protectset8 = true;
- }
-
-#endif // id386
}
--- a/qw/d_part.c
+++ b/qw/d_part.c
@@ -4,7 +4,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "d_local.h"
/*
@@ -28,9 +27,6 @@
// not used by software driver
}
-
-#if !id386
-
/*
==============
D_DrawParticle
@@ -186,6 +182,3 @@
break;
}
}
-
-#endif // !id386
-
--- a/qw/d_polyse.c
+++ b/qw/d_polyse.c
@@ -5,8 +5,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
-#include "d_local.h"
// TODO: put in span spilling to shrink list size
// !!! if this is changed, it must be changed in d_polysa.s too !!!
@@ -99,7 +97,6 @@
void D_RasterizeAliasPolySmooth (void);
void D_PolysetScanLeftEdge (int height);
-#if !id386
/*
================
@@ -113,7 +110,7 @@
// one extra because of cache line pretouching
a_spans = (spanpackage_t *)
- (((long)&spans[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+ (((uintptr)&spans[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
if (r_affinetridesc.drawtype)
{
@@ -370,9 +367,7 @@
D_PolysetRecursiveTriangle (lp3, new, lp2);
}
-#endif // !id386
-
/*
================
D_PolysetUpdateTables
@@ -394,9 +389,6 @@
}
}
-
-#if !id386
-
/*
===================
D_PolysetScanLeftEdge
@@ -463,9 +455,7 @@
} while (--height);
}
-#endif // !id386
-
/*
===================
D_PolysetSetUpForLineScan
@@ -504,9 +494,6 @@
}
}
-
-#if !id386
-
/*
================
D_PolysetCalcGradients
@@ -557,20 +544,13 @@
r_zistepy = (int)((t1 * p00_minus_p20 - t0 * p10_minus_p20) *
ystepdenominv);
-#if id386
- a_sstepxfrac = r_sstepx << 16;
- a_tstepxfrac = r_tstepx << 16;
-#else
a_sstepxfrac = r_sstepx & 0xFFFF;
a_tstepxfrac = r_tstepx & 0xFFFF;
-#endif
a_ststepxwhole = skinwidth * (r_tstepx >> 16) + (r_sstepx >> 16);
}
-#endif // !id386
-
byte gelmap[256];
void InitGel (byte *palette)
{
@@ -585,9 +565,6 @@
}
}
-
-#if !id386
-
/*
================
D_PolysetDrawSpans8
@@ -656,7 +633,6 @@
pspanpackage++;
} while (pspanpackage->count != -999999);
}
-#endif // !id386
/*
@@ -739,17 +715,12 @@
d_ptex = (byte *)r_affinetridesc.pskin + (plefttop[2] >> 16) +
(plefttop[3] >> 16) * r_affinetridesc.skinwidth;
-#if id386
- d_sfrac = (plefttop[2] & 0xFFFF) << 16;
- d_tfrac = (plefttop[3] & 0xFFFF) << 16;
- d_pzbasestep = (d_zwidth + ubasestep) << 1;
- d_pzextrastep = d_pzbasestep + 2;
-#else
+
d_sfrac = plefttop[2] & 0xFFFF;
d_tfrac = plefttop[3] & 0xFFFF;
d_pzbasestep = d_zwidth + ubasestep;
d_pzextrastep = d_pzbasestep + 1;
-#endif
+
d_light = plefttop[4];
d_zi = plefttop[5];
@@ -773,13 +744,10 @@
d_ptexbasestep = ((r_sstepy + r_sstepx * ubasestep) >> 16) +
((r_tstepy + r_tstepx * ubasestep) >> 16) *
r_affinetridesc.skinwidth;
-#if id386
- d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) << 16;
- d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) << 16;
-#else
+
d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) & 0xFFFF;
d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) & 0xFFFF;
-#endif
+
d_lightbasestep = r_lstepy + working_lstepx * ubasestep;
d_zibasestep = r_zistepy + r_zistepx * ubasestep;
@@ -786,13 +754,10 @@
d_ptexextrastep = ((r_sstepy + r_sstepx * d_countextrastep) >> 16) +
((r_tstepy + r_tstepx * d_countextrastep) >> 16) *
r_affinetridesc.skinwidth;
-#if id386
- d_sfracextrastep = (r_sstepy + r_sstepx*d_countextrastep) << 16;
- d_tfracextrastep = (r_tstepy + r_tstepx*d_countextrastep) << 16;
-#else
+
d_sfracextrastep = (r_sstepy + r_sstepx*d_countextrastep) & 0xFFFF;
d_tfracextrastep = (r_tstepy + r_tstepx*d_countextrastep) & 0xFFFF;
-#endif
+
d_lightextrastep = d_lightbasestep + working_lstepx;
d_ziextrastep = d_zibasestep + r_zistepx;
@@ -827,13 +792,10 @@
d_pdestbasestep = screenwidth + ubasestep;
d_pdestextrastep = d_pdestbasestep + 1;
d_pdest = (byte *)d_viewbuffer + ystart * screenwidth + plefttop[0];
-#if id386
- d_pzbasestep = (d_zwidth + ubasestep) << 1;
- d_pzextrastep = d_pzbasestep + 2;
-#else
+
d_pzbasestep = d_zwidth + ubasestep;
d_pzextrastep = d_pzbasestep + 1;
-#endif
+
d_pz = d_pzbuffer + ystart * d_zwidth + plefttop[0];
if (ubasestep < 0)
@@ -845,13 +807,10 @@
d_ptexbasestep = ((r_sstepy + r_sstepx * ubasestep) >> 16) +
((r_tstepy + r_tstepx * ubasestep) >> 16) *
r_affinetridesc.skinwidth;
-#if id386
- d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) << 16;
- d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) << 16;
-#else
+
d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) & 0xFFFF;
d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) & 0xFFFF;
-#endif
+
d_lightbasestep = r_lstepy + working_lstepx * ubasestep;
d_zibasestep = r_zistepy + r_zistepx * ubasestep;
@@ -858,13 +817,10 @@
d_ptexextrastep = ((r_sstepy + r_sstepx * d_countextrastep) >> 16) +
((r_tstepy + r_tstepx * d_countextrastep) >> 16) *
r_affinetridesc.skinwidth;
-#if id386
- d_sfracextrastep = ((r_sstepy+r_sstepx*d_countextrastep) & 0xFFFF)<<16;
- d_tfracextrastep = ((r_tstepy+r_tstepx*d_countextrastep) & 0xFFFF)<<16;
-#else
+
d_sfracextrastep = (r_sstepy+r_sstepx*d_countextrastep) & 0xFFFF;
d_tfracextrastep = (r_tstepy+r_tstepx*d_countextrastep) & 0xFFFF;
-#endif
+
d_lightextrastep = d_lightbasestep + working_lstepx;
d_ziextrastep = d_zibasestep + r_zistepx;
@@ -971,9 +927,7 @@
pedgetable = &edgetables[edgetableindex];
}
-
-#if 0
-
+/*
void D_PolysetRecursiveDrawLine (int *lp1, int *lp2)
{
int d;
@@ -1043,6 +997,4 @@
D_PolysetRecursiveTriangle (lp1, new, lp3);
D_PolysetRecursiveTriangle (new, lp2, lp3);
}
-
-#endif
-
+*/
--- a/qw/d_scan.c
+++ b/qw/d_scan.c
@@ -4,8 +4,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
-#include "d_local.h"
unsigned char *r_turb_pbase, *r_turb_pdest;
fixed16_t r_turb_s, r_turb_t, r_turb_sstep, r_turb_tstep;
@@ -70,9 +68,6 @@
}
}
-
-#if !id386
-
/*
=============
D_DrawTurbulent8Span
@@ -92,8 +87,6 @@
} while (--r_turb_spancount > 0);
}
-#endif // !id386
-
/*
=============
Turbulent8
@@ -226,9 +219,6 @@
} while ((pspan = pspan->pnext) != NULL);
}
-
-#if !id386
-
/*
=============
D_DrawSpans8
@@ -362,11 +352,6 @@
} while ((pspan = pspan->pnext) != NULL);
}
-#endif
-
-
-#if !id386
-
/*
=============
D_DrawZSpans
@@ -399,7 +384,7 @@
// we count on FP exceptions being turned off to avoid range problems
izi = (int)(zi * 0x8000 * 0x10000);
- if ((long)pdest & 0x02)
+ if ((uintptr)pdest & 0x02)
{
*pdest++ = (short)(izi >> 16);
izi += izistep;
@@ -424,5 +409,3 @@
} while ((pspan = pspan->pnext) != NULL);
}
-
-#endif
--- a/qw/d_sky.c
+++ b/qw/d_sky.c
@@ -2,8 +2,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
-#include "d_local.h"
#define SKY_SPAN_SHIFT 5
#define SKY_SPAN_MAX (1 << SKY_SPAN_SHIFT)
--- a/qw/d_sprite.c
+++ b/qw/d_sprite.c
@@ -1,17 +1,14 @@
-// d_sprite.c: software top-level rasterization driver module for drawing
-// sprites
+// d_sprite.c: software top-level rasterization driver module for drawing sprites
#include <u.h>
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "d_local.h"
static int sprite_height;
static int minindex, maxindex;
static sspan_t *sprite_spans;
-#if !id386
/*
=====================
@@ -172,9 +169,6 @@
} while (pspan->count != DS_SPAN_LIST_END);
}
-#endif
-
-
/*
=====================
D_SpriteScanLeftEdge
@@ -422,5 +416,5 @@
D_SpriteScanLeftEdge ();
D_SpriteScanRightEdge ();
D_SpriteDrawSpans (sprite_spans);
+ print("D_DrawSprite: ok\n");
}
-
--- a/qw/d_surf.c
+++ b/qw/d_surf.c
@@ -4,8 +4,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "d_local.h"
-#include "r_local.h"
float surfscale;
qboolean r_cache_thrash; // set if surface cache is thrashing
@@ -121,11 +119,8 @@
if ((size <= 0) || (size > 0x10000))
Sys_Error ("D_SCAlloc: bad cache size %d\n", size);
-#ifdef __alpha__
- size = (int)((long)&((surfcache_t *)0)->data[size]);
-#else
- size = (int)&((surfcache_t *)0)->data[size];
-#endif
+ size = (uintptr)&((surfcache_t *)0)->data[size];
+
size = (size + 3) & ~3;
if (size > sc_size)
Sys_Error ("D_SCAlloc: %i > cache size",size);
--- a/qw/d_vars.c
+++ b/qw/d_vars.c
@@ -1,11 +1,9 @@
// r_vars.c: global refresh variables
-#if !id386
-
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "quakedef.h"
+#include "quakedef.h"
// all global and static refresh variables are collected in a contiguous block
// to avoid cache conflicts.
@@ -29,6 +27,3 @@
short *d_pzbuffer;
unsigned int d_zrowbytes;
unsigned int d_zwidth;
-
-#endif // !id386
-
--- a/qw/d_zpoint.c
+++ b/qw/d_zpoint.c
@@ -4,7 +4,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "d_local.h"
/*
--- a/qw/draw.c
+++ b/qw/draw.c
@@ -1,5 +1,4 @@
-// draw.c -- this is the only file outside the refresh that touches the
-// vid buffer
+// draw.c -- this is the only file outside the refresh that touches the vid buffer
#include <u.h>
#include <libc.h>
@@ -346,7 +345,7 @@
for (v=0 ; v<pic->height ; v++)
{
- Q_memcpy (dest, source, pic->width);
+ memcpy (dest, source, pic->width);
dest += vid.rowbytes;
source += pic->width;
}
@@ -397,7 +396,7 @@
for (v=0 ; v<height ; v++)
{
- Q_memcpy (dest, source, width);
+ memcpy (dest, source, width);
dest += vid.rowbytes;
source += pic->width;
}
@@ -645,11 +644,7 @@
sprintf (ver, "%4.2f", VERSION);
dest = conback->data + 320 + 320*186 - 11 - 8*strlen(ver);
} else {
-#if defined(__linux__)
- sprintf (ver, "Linux (%4.2f) QuakeWorld %4.2f", LINUX_VERSION, VERSION);
-#else
- sprintf (ver, "QuakeWorld %4.2f", VERSION);
-#endif
+ sprint(ver, "(9) %4.2f QuakeWorld %4.2f", PLAN9_VERSION, VERSION);
dest = conback->data + 320 - (strlen(ver)*8 + 11) + 320*186;
}
--- a/qw/in.c
+++ b/qw/in.c
@@ -1,4 +1,308 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
+#include <draw.h>
+#include <thread.h>
+#include <mouse.h>
+#include <keyboard.h>
#include "quakedef.h"
+
+extern Channel *fuckchan; /* main fuck receptor */
+
+/* vid_9.c */
+extern int resized;
+extern Point center;
+
+cvar_t m_windowed = {"m_windowed", "0", true};
+
+static cvar_t m_filter = {"m_filter", "0", true};
+
+static int mouseon, oldmwin;
+static float mx, my, oldmx, oldmy;
+static int mb, oldmb;
+
+typedef struct Kev Kev;
+struct Kev{
+ int key;
+ int down;
+};
+enum{
+ Nbuf = 64
+};
+static Channel *kchan;
+
+
+void
+IN_Grabm(int on)
+{
+ static char nocurs[2*4+2*2*16];
+ static int fd = -1;
+
+ if(mouseon == on)
+ return;
+ if(mouseon = on && m_windowed.value){
+ if((fd = open("/dev/cursor", ORDWR|OCEXEC)) < 0){
+ fprint(2, "IN_Grabm:open: %r\n");
+ return;
+ }
+ write(fd, nocurs, sizeof nocurs);
+ }else if(fd >= 0){
+ close(fd);
+ fd = -1;
+ }
+}
+
+void
+Sys_SendKeyEvents(void)
+{
+ Kev ev;
+ int r;
+
+ if(kchan == nil)
+ return;
+
+ if(oldmwin != (int)m_windowed.value){
+ oldmwin = (int)m_windowed.value;
+ IN_Grabm(oldmwin);
+ }
+
+ while((r = nbrecv(kchan, &ev)) > 0)
+ Key_Event(ev.key, ev.down);
+ if(r < 0)
+ fprint(2, "Sys_SendKeyEvents:nbrecv: %r\n");
+}
+
+void
+IN_Commands(void)
+{
+ int i;
+
+ if(!mouseon)
+ return;
+
+ /* FIXMEGASHIT */
+ for(i = 0; i < 3; i++){
+ if(mb & 1<<i && ~oldmb & 1<<i)
+ Key_Event(K_MOUSE1+i, true);
+ if (~mb & 1<<i && oldmb & 1<<i)
+ Key_Event(K_MOUSE1+i, false);
+ }
+ oldmb = mb;
+}
+
+void
+IN_Move(usercmd_t *cmd)
+{
+ if(!mouseon)
+ return;
+
+ if(m_filter.value){
+ mx = (mx + oldmx) * 0.5;
+ my = (my + oldmy) * 0.5;
+ }
+ oldmx = mx;
+ oldmy = my;
+ mx *= sensitivity.value;
+ my *= sensitivity.value;
+
+ if(in_strafe.state & 1 || lookstrafe.value && in_mlook.state & 1)
+ cmd->sidemove += m_side.value * mx;
+ else
+ cl.viewangles[YAW] -= m_yaw.value * mx;
+ if(in_mlook.state & 1)
+ V_StopPitchDrift();
+
+ if(in_mlook.state & 1 && ~in_strafe.state & 1){
+ cl.viewangles[PITCH] += m_pitch.value * my;
+ if(cl.viewangles[PITCH] > 80)
+ cl.viewangles[PITCH] = 80;
+ if(cl.viewangles[PITCH] < -70)
+ cl.viewangles[PITCH] = -70;
+ }else{
+ if(in_strafe.state & 1 && noclip_anglehack)
+ cmd->upmove -= m_forward.value * my;
+ else
+ cmd->forwardmove -= m_forward.value * my;
+ }
+ mx = my = 0.0;
+}
+
+static int
+runetokey(Rune r)
+{
+ int k = 0;
+
+ switch(r){
+ case Kpgup: k = K_PGUP; break;
+ case Kpgdown: k = K_PGDN; break;
+ case Khome: k = K_HOME; break;
+ case Kend: k = K_END; break;
+ case Kleft: k = K_LEFTARROW; break;
+ case Kright: k = K_RIGHTARROW; break;
+ case Kdown: k = K_DOWNARROW; break;
+ case Kup: k = K_UPARROW; break;
+ case Kesc: k = K_ESCAPE; break;
+ case '\n': k = K_ENTER; break;
+ case '\t': k = K_TAB; break;
+ case KF|1: k = K_F1; break;
+ case KF|2: k = K_F2; break;
+ case KF|3: k = K_F3; break;
+ case KF|4: k = K_F4; break;
+ case KF|5: k = K_F5; break;
+ case KF|6: k = K_F6; break;
+ case KF|7: k = K_F7; break;
+ case KF|8: k = K_F8; break;
+ case KF|9: k = K_F9; break;
+ case KF|10: k = K_F10; break;
+ case KF|11: k = K_F11; break;
+ case KF|12: k = K_F12; break;
+ case Kbs: k = K_BACKSPACE; break;
+ case Kdel: k = K_DEL; break;
+ case Kbreak: k = K_PAUSE; break;
+ case Kshift: k = K_SHIFT; break;
+ case Kctl: k = K_CTRL; break;
+ case Kalt:
+ case Kaltgr: k = K_ALT; break;
+ case Kins: k = K_INS; break;
+ default:
+ if(r < 0x80)
+ k = r;
+ }
+ return k;
+}
+
+static void
+kproc(void *)
+{
+ int n, k, fd;
+ char buf[128], kdown[128], *s;
+ Rune r;
+ Kev ev;
+
+ threadsetgrp(THin);
+
+ if((fd = open("/dev/kbd", OREAD)) < 0)
+ sysfatal("open /dev/kbd: %r");
+ kdown[0] = kdown[1] = buf[0] = 0;
+ for(;;){
+ if(buf[0] != 0){
+ n = strlen(buf)+1;
+ memmove(buf, buf+n, sizeof(buf)-n);
+ }
+ if(buf[0] == 0){
+ n = read(fd, buf, sizeof(buf)-1);
+ if(n <= 0)
+ break;
+ buf[n-1] = 0;
+ buf[n] = 0;
+ }
+ switch(*buf){
+ case 'c':
+ default:
+ continue;
+ case 'k':
+ s = buf+1;
+ while(*s){
+ s += chartorune(&r, s);
+ if(utfrune(kdown+1, r) == nil){
+ if(k = runetokey(r)){
+ ev.key = k;
+ ev.down = true;
+ if(nbsend(kchan, &ev) < 0)
+ fprint(2, "kproc:nbsend: %r\n");
+ }
+ }
+ }
+ break;
+ case 'K':
+ s = kdown+1;
+ while(*s){
+ s += chartorune(&r, s);
+ if(utfrune(buf+1, r) == nil){
+ if(k = runetokey(r)){
+ ev.key = k;
+ ev.down = false;
+ if(nbsend(kchan, &ev) < 0)
+ fprint(2, "kproc:nbsend: %r\n");
+ }
+ }
+ }
+ break;
+ }
+ strcpy(kdown, buf);
+ }
+ close(fd);
+}
+
+static void
+mproc(void *)
+{
+ int b, n, nerr, fd;
+ char buf[1+5*12];
+ float x, y;
+
+ threadsetgrp(THin);
+
+ if((fd = open("/dev/mouse", ORDWR)) < 0)
+ sysfatal("open /dev/mouse: %r");
+
+ nerr = 0;
+ for(;;){
+ if((n = read(fd, buf, sizeof buf)) != 1+4*12){
+ fprint(2, "mproc:read: bad count %d not 49: %r\n", n);
+ if(n < 0 || ++nerr > 10)
+ break;
+ continue;
+ }
+ nerr = 0;
+ switch(*buf){
+ case 'r':
+ resized = 1;
+ /* fall through */
+ case 'm':
+ if(!mouseon)
+ break;
+
+ x = atoi(buf+1+0*12) - center.x;
+ y = atoi(buf+1+1*12) - center.y;
+ b = atoi(buf+1+2*12);
+
+ mx += x;
+ my += y;
+ if(x != 0.0 || y != 0.0)
+ fprint(fd, "m%d %d", center.x, center.y);
+
+ mb = b&1 | (b&2)<<1 | (b&4)>>1;
+ break;
+ }
+ }
+ close(fd);
+}
+
+void
+IN_Shutdown(void)
+{
+ threadkillgrp(THin);
+ IN_Grabm(0);
+ if(kchan != nil){
+ chanfree(kchan);
+ kchan = nil;
+ }
+}
+
+void
+IN_Init(void)
+{
+ Cvar_RegisterVariable(&m_windowed);
+ Cvar_RegisterVariable(&m_filter);
+ if((kchan = chancreate(sizeof(Kev), Nbuf)) == nil)
+ sysfatal("chancreate kchan: %r");
+ if(proccreate(kproc, nil, 8192) < 0)
+ sysfatal("proccreate kproc: %r");
+ if(COM_CheckParm("-nomouse"))
+ return;
+ if(proccreate(mproc, nil, 8192) < 0)
+ sysfatal("proccreate mproc: %r");
+ mx = my = 0.0;
+ IN_Grabm(0);
+}
--- a/qw/input.h
+++ b/qw/input.h
@@ -1,15 +1,6 @@
-// input.h -- external (non-keyboard) input devices
-
-void IN_Init (void);
-
-void IN_Shutdown (void);
-
-void IN_Commands (void);
-// oportunity for devices to stick commands on the script buffer
-
-void IN_Move (usercmd_t *cmd);
-// add additional movement on top of the keyboard move cmd
-
-void IN_ModeChanged (void);
-// called whenever screen dimensions change
-
+void IN_Init(void);
+void IN_Shutdown(void);
+void IN_Commands(void); // oportunity for devices to stick commands on the script buffer
+void IN_Move(usercmd_t *); // add additional movement on top of the keyboard move cmd
+void IN_ModeChanged(void); // called whenever screen dimensions change
+void IN_Grabm(int);
--- a/qw/keys.c
+++ b/qw/keys.c
@@ -2,13 +2,10 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-/*
-key up events are sent even if in console mode
+/* key up events are sent even if in console mode */
-*/
-
#define MAXCMDLINE 256
char key_lines[32][MAXCMDLINE];
int key_linepos;
@@ -168,8 +165,8 @@
if (cmd)
{
key_lines[edit_line][1] = '/';
- Q_strcpy (key_lines[edit_line]+2, cmd);
- key_linepos = Q_strlen(cmd)+2;
+ 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;
@@ -186,13 +183,6 @@
*/
void Key_Console (int key)
{
-#ifdef _WIN32
- char *cmd, *s;
- int i;
- HANDLE th;
- char *clipText, *textCopied;
-#endif
-
if (key == K_ENTER)
{ // backslash text are commands, else chat
if (key_lines[edit_line][1] == '\\' || key_lines[edit_line][1] == '/')
@@ -240,8 +230,8 @@
&& !key_lines[history_line][1]);
if (history_line == edit_line)
history_line = (edit_line+1)&31;
- Q_strcpy(key_lines[edit_line], key_lines[history_line]);
- key_linepos = Q_strlen(key_lines[edit_line]);
+ strcpy(key_lines[edit_line], key_lines[history_line]);
+ key_linepos = strlen(key_lines[edit_line]);
return;
}
@@ -261,8 +251,8 @@
}
else
{
- Q_strcpy(key_lines[edit_line], key_lines[history_line]);
- key_linepos = Q_strlen(key_lines[edit_line]);
+ strcpy(key_lines[edit_line], key_lines[history_line]);
+ key_linepos = strlen(key_lines[edit_line]);
}
return;
}
@@ -292,38 +282,10 @@
con->display = con->current;
return;
}
-
-#ifdef _WIN32
- if ((key=='V' || key=='v') && GetKeyState(VK_CONTROL)<0) {
- if (OpenClipboard(NULL)) {
- th = GetClipboardData(CF_TEXT);
- if (th) {
- clipText = GlobalLock(th);
- if (clipText) {
- textCopied = malloc(GlobalSize(th)+1);
- strcpy(textCopied, clipText);
- /* Substitutes a NULL for every token */strtok(textCopied, "\n\r\b");
- i = strlen(textCopied);
- if (i+key_linepos>=MAXCMDLINE)
- i=MAXCMDLINE-key_linepos;
- if (i>0) {
- textCopied[i]=0;
- strcat(key_lines[edit_line], textCopied);
- key_linepos+=i;;
- }
- free(textCopied);
- }
- GlobalUnlock(th);
- }
- CloseClipboard();
- return;
- }
- }
-#endif
if (key < 32 || key > 127)
return; // non printable
-
+
if (key_linepos < MAXCMDLINE-1)
{
key_lines[edit_line][key_linepos] = key;
@@ -330,7 +292,6 @@
key_linepos++;
key_lines[edit_line][key_linepos] = 0;
}
-
}
//============================================================================
@@ -408,7 +369,7 @@
for (kn=keynames ; kn->name ; kn++)
{
- if (!Q_strcasecmp(str,kn->name))
+ if (!cistrcmp(str, kn->name))
return kn->keynum;
}
return -1;
@@ -466,9 +427,9 @@
}
// allocate memory for new binding
- l = Q_strlen (binding);
+ l = strlen (binding);
new = Z_Malloc (l+1);
- Q_strcpy (new, binding);
+ strcpy (new, binding);
new[l] = 0;
keybindings[keynum] = new;
}
--- a/qw/mathlib.c
+++ b/qw/mathlib.c
@@ -68,11 +68,6 @@
VectorNormalize( dst );
}
-#ifdef _WIN32
-#pragma optimize( "", off )
-#endif
-
-
void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees )
{
float m[3][3];
@@ -128,20 +123,14 @@
}
}
-#ifdef _WIN32
-#pragma optimize( "", on )
-#endif
-
-/*-----------------------------------------------------------------*/
-
float anglemod(float a)
{
-#if 0
+ /*
if (a >= 0)
a -= 360*(int)(a/360);
else
a += 360*( 1 + (int)(-a/360) );
-#endif
+ */
a = (360.0/65536) * ((int)(a*(65536/360.0)) & 65535);
return a;
}
@@ -158,8 +147,6 @@
Sys_Error ("BoxOnPlaneSide: Bad signbits");
}
-#if !id386
-
/*
==================
BoxOnPlaneSide
@@ -172,10 +159,8 @@
float dist1, dist2;
int sides;
-#if 0 // this is done by the BOX_ON_PLANE_SIDE macro before calling this
- // function
-// fast axial cases
- if (p->type < 3)
+ /* this is done by the BOX_ON_PLANE_SIDE macro before calling this function
+ if (p->type < 3) // fast axial cases
{
if (p->dist <= emins[p->type])
return 1;
@@ -183,7 +168,7 @@
return 2;
return 3;
}
-#endif
+ */
// general case
switch (p->signbits)
@@ -226,7 +211,7 @@
break;
}
-#if 0
+/*
int i;
vec3_t corners[2];
@@ -250,9 +235,8 @@
sides = 1;
if (dist2 < 0)
sides |= 2;
+*/
-#endif
-
sides = 0;
if (dist1 >= p->dist)
sides = 1;
@@ -267,9 +251,6 @@
return sides;
}
-#endif
-
-
void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
{
float angle;
@@ -541,9 +522,6 @@
}
}
-
-#if !id386
-
// TODO: move to nonintel.c
/*
@@ -553,7 +531,6 @@
Inverts an 8.24 value to a 16.16 value
====================
*/
-
fixed16_t Invert24To16(fixed16_t val)
{
if (val < 256)
@@ -562,5 +539,3 @@
return (fixed16_t)
(((double)0x10000 * (double)0x1000000 / (double)val) + 0.5);
}
-
-#endif
--- a/qw/mathlib.h
+++ b/qw/mathlib.h
@@ -1,5 +1,3 @@
-// mathlib.h
-
typedef float vec_t;
typedef vec_t vec3_t[3];
typedef vec_t vec5_t[5];
--- a/qw/md4.c
+++ b/qw/md4.c
@@ -2,21 +2,15 @@
#include <u.h>
#include <libc.h>
-#include <stdio.h>
/* POINTER defines a generic pointer type */
-typedef unsigned char *POINTER;
+typedef uchar *POINTER;
/* UINT2 defines a two byte word */
-typedef unsigned short int UINT2;
+typedef ushort UINT2;
/* UINT4 defines a four byte word */
-#ifdef __alpha__
-typedef unsigned int UINT4;
-#else
-typedef unsigned long int UINT4;
-#endif
-
+typedef ulong UINT4;
/* MD4.H - header file for MD4C.C */
--- a/qw/menu.c
+++ b/qw/menu.c
@@ -17,7 +17,6 @@
void M_Menu_Net_f (void);
void M_Menu_Options_f (void);
void M_Menu_Keys_f (void);
- void M_Menu_Video_f (void);
void M_Menu_Help_f (void);
void M_Menu_Quit_f (void);
void M_Menu_SerialConfig_f (void);
@@ -36,7 +35,6 @@
void M_Net_Draw (void);
void M_Options_Draw (void);
void M_Keys_Draw (void);
- void M_Video_Draw (void);
void M_Help_Draw (void);
void M_Quit_Draw (void);
void M_SerialConfig_Draw (void);
@@ -55,7 +53,6 @@
void M_Net_Key (int key);
void M_Options_Key (int key);
void M_Keys_Key (int key);
- void M_Video_Key (int key);
void M_Help_Key (int key);
void M_Quit_Key (int key);
void M_SerialConfig_Key (int key);
@@ -229,6 +226,7 @@
{
m_entersound = true;
+ IN_Grabm(0);
if (key_dest == key_menu)
{
if (m_state != m_main)
@@ -297,6 +295,7 @@
cls.demonum = m_save_demonum;
if (cls.demonum != -1 && !cls.demoplayback && cls.state == ca_disconnected)
CL_NextDemo ();
+ IN_Grabm(1);
break;
case K_DOWNARROW:
@@ -343,7 +342,7 @@
//=============================================================================
/* OPTIONS MENU */
-#define OPTIONS_ITEMS 16
+#define OPTIONS_ITEMS 15
#define SLIDER_RANGE 10
@@ -388,11 +387,7 @@
Cvar_SetValue ("sensitivity", sensitivity.value);
break;
case 6: // music volume
-#ifdef _WIN32
- bgmvolume.value += dir * 1.0;
-#else
bgmvolume.value += dir * 0.1;
-#endif
if (bgmvolume.value < 0)
bgmvolume.value = 0;
if (bgmvolume.value > 1)
@@ -439,9 +434,10 @@
case 13:
Cvar_SetValue ("cl_hudswap", !cl_hudswap.value);
+ break;
- case 15: // _windowed_mouse
- Cvar_SetValue ("_windowed_mouse", !_windowed_mouse.value);
+ case 14:
+ Cvar_SetValue ("m_windowed", !m_windowed.value);
break;
}
}
@@ -464,12 +460,12 @@
void M_DrawCheckbox (int x, int y, int on)
{
-#if 0
+/*
if (on)
M_DrawCharacter (x, y, 131);
else
M_DrawCharacter (x, y, 129);
-#endif
+*/
if (on)
M_Print (x, y, "on");
else
@@ -476,72 +472,63 @@
M_Print (x, y, "off");
}
-void M_Options_Draw (void)
+void
+M_Options_Draw(void)
{
- float r;
- qpic_t *p;
+ float r;
+ qpic_t *p;
+
+ M_DrawTransPic(16, 4, Draw_CachePic("gfx/qplaque.lmp"));
+ p = Draw_CachePic("gfx/p_option.lmp");
+ M_DrawPic((320-p->width)/2, 4, p);
- M_DrawTransPic (16, 4, Draw_CachePic ("gfx/qplaque.lmp") );
- p = Draw_CachePic ("gfx/p_option.lmp");
- M_DrawPic ( (320-p->width)/2, 4, p);
-
- M_Print (16, 32, " Customize controls");
- M_Print (16, 40, " Go to console");
- M_Print (16, 48, " Reset to defaults");
+ M_Print(16, 32, " Customize controls");
+ M_Print(16, 40, " Go to console");
+ M_Print(16, 48, " Reset to defaults");
- M_Print (16, 56, " Screen size");
+ M_Print(16, 56, " Screen size");
r = (scr_viewsize.value - 30) / (120 - 30);
- M_DrawSlider (220, 56, r);
+ M_DrawSlider(220, 56, r);
- M_Print (16, 64, " Brightness");
+ M_Print(16, 64, " Brightness");
r = (1.0 - v_gamma.value) / 0.5;
- M_DrawSlider (220, 64, r);
+ M_DrawSlider(220, 64, r);
- M_Print (16, 72, " Mouse Speed");
+ M_Print(16, 72, " Mouse Speed");
r = (sensitivity.value - 1)/10;
- M_DrawSlider (220, 72, r);
+ M_DrawSlider(220, 72, r);
- M_Print (16, 80, " CD Music Volume");
+ M_Print(16, 80, " CD Music Volume");
r = bgmvolume.value;
- M_DrawSlider (220, 80, r);
+ M_DrawSlider(220, 80, r);
- M_Print (16, 88, " Sound Volume");
+ M_Print(16, 88, " Sound Volume");
r = volume.value;
- M_DrawSlider (220, 88, r);
+ M_DrawSlider(220, 88, r);
- M_Print (16, 96, " Always Run");
- M_DrawCheckbox (220, 96, cl_forwardspeed.value > 200);
+ M_Print(16, 96, " Always Run");
+ M_DrawCheckbox(220, 96, cl_forwardspeed.value > 200);
- M_Print (16, 104, " Invert Mouse");
- M_DrawCheckbox (220, 104, m_pitch.value < 0);
+ M_Print(16, 104, " Invert Mouse");
+ M_DrawCheckbox(220, 104, m_pitch.value < 0);
- M_Print (16, 112, " Lookspring");
- M_DrawCheckbox (220, 112, lookspring.value);
+ M_Print(16, 112, " Lookspring");
+ M_DrawCheckbox(220, 112, lookspring.value);
- M_Print (16, 120, " Lookstrafe");
- M_DrawCheckbox (220, 120, lookstrafe.value);
+ M_Print(16, 120, " Lookstrafe");
+ M_DrawCheckbox(220, 120, lookstrafe.value);
- M_Print (16, 128, " Use old status bar");
- M_DrawCheckbox (220, 128, cl_sbar.value);
+ M_Print(16, 128, " Use old status bar");
+ M_DrawCheckbox(220, 128, cl_sbar.value);
- M_Print (16, 136, " HUD on left side");
- M_DrawCheckbox (220, 136, cl_hudswap.value);
+ M_Print(16, 136, " HUD on left side");
+ M_DrawCheckbox(220, 136, cl_hudswap.value);
- if (vid_menudrawfn)
- M_Print (16, 144, " Video Options");
+ M_Print(16, 144, " Grab Mouse");
+ M_DrawCheckbox(220, 144, m_windowed.value);
-#ifdef _WIN32
- if (modestate == MS_WINDOWED)
- {
-#endif
- M_Print (16, 152, " Use Mouse");
- M_DrawCheckbox (220, 152, _windowed_mouse.value);
-#ifdef _WIN32
- }
-#endif
-
// cursor
- M_DrawCharacter (200, 32 + options_cursor*8, 12+((int)(realtime*4)&1));
+ M_DrawCharacter(200, 32 + options_cursor*8, 12+((int)(realtime*4)&1));
}
@@ -567,9 +554,6 @@
case 2:
Cbuf_AddText ("exec default.cfg\n");
break;
- case 14:
- M_Menu_Video_f ();
- break;
default:
M_AdjustSliders (1);
break;
@@ -598,26 +582,6 @@
M_AdjustSliders (1);
break;
}
-
- if (options_cursor == 14 && vid_menudrawfn == NULL)
- {
- if (k == K_UPARROW)
- options_cursor = 13;
- else
- options_cursor = 0;
- }
-
- if ((options_cursor == 15)
-#ifdef _WIN32
- && (modestate != MS_WINDOWED)
-#endif
- )
- {
- if (k == K_UPARROW)
- options_cursor = 14;
- else
- options_cursor = 0;
- }
}
@@ -706,7 +670,7 @@
void M_Keys_Draw (void)
{
- int i, l;
+ int i;
int keys[2];
char *name;
int x, y;
@@ -727,7 +691,7 @@
M_Print (16, y, bindnames[i][1]);
- l = strlen (bindnames[i][0]);
+ //int l = strlen (bindnames[i][0]);
M_FindKeysForCommand (bindnames[i][0], keys);
@@ -763,12 +727,8 @@
if (bind_grab)
{ // defining a key
S_LocalSound ("misc/menu1.wav");
- if (k == K_ESCAPE)
+ if (k != '`')
{
- bind_grab = false;
- }
- else if (k != '`')
- {
sprintf (cmd, "bind %s \"%s\"\n", Key_KeynumToString (k), bindnames[keys_cursor][0]);
Cbuf_InsertText (cmd);
}
@@ -816,28 +776,6 @@
}
//=============================================================================
-/* VIDEO MENU */
-
-void M_Menu_Video_f (void)
-{
- key_dest = key_menu;
- m_state = m_video;
- m_entersound = true;
-}
-
-
-void M_Video_Draw (void)
-{
- (*vid_menudrawfn) ();
-}
-
-
-void M_Video_Key (int key)
-{
- (*vid_menukeyfn) (key);
-}
-
-//=============================================================================
/* HELP MENU */
int help_page;
@@ -1000,7 +938,7 @@
}
-void M_SinglePlayer_Key (key) {
+void M_SinglePlayer_Key (int key) {
if (key == K_ESCAPE || key==K_ENTER)
m_state = m_main;
}
@@ -1040,7 +978,7 @@
char *cmsg[] = {
// 0123456789012345678901234567890123456789
"0 QuakeWorld",
- "1 version " VSTR2(VERSION) " by id Software",
+ "1 version 2.40 by id Software",
"0Programming",
"1 John Carmack Michael Abrash",
"1 John Cash Christian Antkow",
@@ -1072,7 +1010,13 @@
M_Draw ();
m_state = m_quit;
}
-#if 1
+/*
+ M_DrawTextBox (56, 76, 24, 4);
+ M_Print (64, 84, quitMessage[msgNumber*4+0]);
+ M_Print (64, 92, quitMessage[msgNumber*4+1]);
+ M_Print (64, 100, quitMessage[msgNumber*4+2]);
+ M_Print (64, 108, quitMessage[msgNumber*4+3]);
+*/
M_DrawTextBox (0, 0, 38, 23);
y = 12;
for (p = cmsg; *p; p++, y += 8) {
@@ -1081,13 +1025,6 @@
else
M_Print (16, y, *p + 1);
}
-#else
- M_DrawTextBox (56, 76, 24, 4);
- M_Print (64, 84, quitMessage[msgNumber*4+0]);
- M_Print (64, 92, quitMessage[msgNumber*4+1]);
- M_Print (64, 100, quitMessage[msgNumber*4+2]);
- M_Print (64, 108, quitMessage[msgNumber*4+3]);
-#endif
}
@@ -1103,7 +1040,6 @@
Cmd_AddCommand ("menu_main", M_Menu_Main_f);
Cmd_AddCommand ("menu_options", M_Menu_Options_f);
Cmd_AddCommand ("menu_keys", M_Menu_Keys_f);
- Cmd_AddCommand ("menu_video", M_Menu_Video_f);
Cmd_AddCommand ("help", M_Menu_Help_f);
Cmd_AddCommand ("menu_quit", M_Menu_Quit_f);
}
@@ -1176,10 +1112,6 @@
M_Keys_Draw ();
break;
- case m_video:
- M_Video_Draw ();
- break;
-
case m_help:
M_Help_Draw ();
break;
@@ -1266,10 +1198,6 @@
case m_keys:
M_Keys_Key (key);
- return;
-
- case m_video:
- M_Video_Key (key);
return;
case m_help:
--- a/qw/menu.h
+++ b/qw/menu.h
@@ -1,3 +1,4 @@
+//
// the net drivers should just set the apropriate bits in m_activenet,
// instead of having the menu code look through their internal tables
//
--- a/qw/mkfile
+++ b/qw/mkfile
@@ -1,4 +1,5 @@
</$objtype/mkfile
+
BIN=$home/bin/$objtype
TARG=\
qwcl\
@@ -5,7 +6,6 @@
qwsv\
CLOBJ=\
- cl_cam.$O\
cl_demo.$O\
cl_ents.$O\
cl_input.$O\
@@ -13,6 +13,7 @@
cl_parse.$O\
cl_pred.$O\
cl_tent.$O\
+ cl_cam.$O\
cmd.$O\
common.$O\
console.$O\
@@ -31,7 +32,6 @@
d_vars.$O\
d_zpoint.$O\
draw.$O\
- in.$O\
keys.$O\
mathlib.$O\
md4.$O\
@@ -38,11 +38,9 @@
menu.$O\
model.$O\
net_chan.$O\
- net_udp.$O\
nonintel.$O\
pmove.$O\
pmovetst.$O\
- qwcl.$O\
r_aclip.$O\
r_alias.$O\
r_bsp.$O\
@@ -60,44 +58,48 @@
sbar.$O\
screen.$O\
skin.$O\
- snd.$O\
snd_dma.$O\
snd_mem.$O\
snd_mix.$O\
- sys.$O\
- vid.$O\
view.$O\
wad.$O\
zone.$O\
+ cd.$O\
+ vid.$O\
+ snd.$O\
+ in.$O\
+ sys.$O\
+ net_udp.$O\
+ qwcl.$O\
SVOBJ=\
- cmd.$O\
- common.$O\
- crc.$O\
- cvar.$O\
- mathlib.$O\
- md4.$O\
- net_chan.$O\
- net_udp.$O\
- pmove.$O\
- pmovetst.$O\
pr_cmds.$O\
pr_edict.$O\
pr_exec.$O\
- qwsv.$O\
- sv_ccmds.$O\
- sv_ents.$O\
sv_init.$O\
sv_main.$O\
- sv_move.$O\
sv_nchan.$O\
- sv_phys.$O\
+ sv_ents.$O\
sv_send.$O\
+ sv_move.$O\
+ sv_phys.$O\
sv_user.$O\
- svmodel.$O\
- sys.$O\
+ sv_ccmds.$O\
world.$O\
+ svmodel.$O\
+ cmd.$O\
+ common.$O\
+ crc.$O\
+ cvar.$O\
+ mathlib.$O\
+ md4.$O\
zone.$O\
+ pmove.$O\
+ pmovetst.$O\
+ net_chan.$O\
+ sys.$O\
+ net_udp.$O\
+ qwsv.$O\
HFILES=\
../adivtab.h\
--- a/qw/model.c
+++ b/qw/model.c
@@ -6,7 +6,7 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "qwsvdef.h"
+#include "quakedef.h"
model_t *loadmodel;
char loadname[32]; // for hunk tags
@@ -22,10 +22,6 @@
model_t mod_known[MAX_MOD_KNOWN];
int mod_numknown;
-texture_t r_notexture_mip;
-
-unsigned *model_checksum;
-
/*
===============
Mod_Init
@@ -38,6 +34,28 @@
/*
===============
+Mod_Init
+
+Caches the data if needed
+===============
+*/
+void *Mod_Extradata (model_t *mod)
+{
+ void *r;
+
+ r = Cache_Check (&mod->cache);
+ if (r)
+ return r;
+
+ Mod_LoadModel (mod, true);
+
+ if (!mod->cache.data)
+ Sys_Error ("Mod_Extradata: caching failed");
+ return mod->cache.data;
+}
+
+/*
+===============
Mod_PointInLeaf
===============
*/
@@ -48,7 +66,7 @@
mplane_t *plane;
if (!model || !model->nodes)
- SV_Error ("Mod_PointInLeaf: bad model");
+ Sys_Error ("Mod_PointInLeaf: bad model");
node = model->nodes;
while (1)
@@ -62,8 +80,6 @@
else
node = node->children[1];
}
-
- return NULL; // never reached
}
@@ -82,9 +98,9 @@
row = (model->numleafs+7)>>3;
out = decompressed;
-#if 0
+/*
memcpy (out, in, row);
-#else
+*/
if (!in)
{ // no vis info, so make all visible
while (row)
@@ -111,7 +127,6 @@
c--;
}
} while (out - decompressed < row);
-#endif
return decompressed;
}
@@ -150,7 +165,7 @@
model_t *mod;
if (!name[0])
- SV_Error ("Mod_ForName: NULL name");
+ Sys_Error ("Mod_ForName: NULL name");
//
// search the currently loaded models
@@ -162,7 +177,7 @@
if (i == mod_numknown)
{
if (mod_numknown == MAX_MOD_KNOWN)
- SV_Error ("mod_numknown == MAX_MOD_KNOWN");
+ Sys_Error ("mod_numknown == MAX_MOD_KNOWN");
strcpy (mod->name, name);
mod->needload = true;
mod_numknown++;
@@ -171,7 +186,25 @@
return mod;
}
+/*
+==================
+Mod_TouchModel
+==================
+*/
+void Mod_TouchModel (char *name)
+{
+ model_t *mod;
+
+ mod = Mod_FindName (name);
+
+ if (!mod->needload)
+ {
+ if (mod->type == mod_alias)
+ Cache_Check (&mod->cache);
+ }
+}
+
/*
==================
Mod_LoadModel
@@ -196,7 +229,15 @@
else
return mod; // not cached at all
}
+
+//
+// because the world is so huge, load it one piece at a time
+//
+ if (!crash)
+ {
+ }
+
//
// load the file
//
@@ -204,7 +245,7 @@
if (!buf)
{
if (crash)
- SV_Error ("Mod_NumForName: %s not found", mod->name);
+ Sys_Error ("Mod_NumForName: %s not found", mod->name);
return NULL;
}
@@ -222,7 +263,20 @@
// call the apropriate loader
mod->needload = false;
- Mod_LoadBrushModel (mod, buf);
+ switch (LittleLong(*(unsigned *)buf))
+ {
+ case IDPOLYHEADER:
+ Mod_LoadAliasModel (mod, buf);
+ break;
+
+ case IDSPRITEHEADER:
+ Mod_LoadSpriteModel (mod, buf);
+ break;
+
+ default:
+ Mod_LoadBrushModel (mod, buf);
+ break;
+ }
return mod;
}
@@ -293,7 +347,7 @@
mt->offsets[j] = LittleLong (mt->offsets[j]);
if ( (mt->width & 15) || (mt->height & 15) )
- SV_Error ("Texture %s is not 16 aligned", mt->name);
+ Sys_Error ("Texture %s is not 16 aligned", mt->name);
pixels = mt->width*mt->height/64*85;
tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );
loadmodel->textures[i] = tx;
@@ -305,6 +359,9 @@
tx->offsets[j] = mt->offsets[j] + sizeof(texture_t) - sizeof(miptex_t);
// the pixels immediately follow the structures
memcpy ( tx+1, mt+1, pixels);
+
+ if (!strncmp(mt->name,"sky",3))
+ R_InitSky (tx);
}
//
@@ -341,7 +398,7 @@
altmax++;
}
else
- SV_Error ("Bad animating texture %s", tx->name);
+ Sys_Error ("Bad animating texture %s", tx->name);
for (j=i+1 ; j<m->nummiptex ; j++)
{
@@ -369,7 +426,7 @@
altmax = num+1;
}
else
- SV_Error ("Bad animating texture %s", tx->name);
+ Sys_Error ("Bad animating texture %s", tx->name);
}
#define ANIM_CYCLE 2
@@ -378,7 +435,7 @@
{
tx2 = anims[j];
if (!tx2)
- SV_Error ("Missing frame %i of %s",j, tx->name);
+ Sys_Error ("Missing frame %i of %s",j, tx->name);
tx2->anim_total = max * ANIM_CYCLE;
tx2->anim_min = j * ANIM_CYCLE;
tx2->anim_max = (j+1) * ANIM_CYCLE;
@@ -390,7 +447,7 @@
{
tx2 = altanims[j];
if (!tx2)
- SV_Error ("Missing frame %i of %s",j, tx->name);
+ Sys_Error ("Missing frame %i of %s",j, tx->name);
tx2->anim_total = altmax * ANIM_CYCLE;
tx2->anim_min = j * ANIM_CYCLE;
tx2->anim_max = (j+1) * ANIM_CYCLE;
@@ -465,7 +522,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName ( count*sizeof(*out), loadname);
@@ -493,7 +550,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName ( count*sizeof(*out), loadname);
@@ -529,7 +586,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName ( (count + 1) * sizeof(*out), loadname);
@@ -558,7 +615,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName ( count*sizeof(*out), loadname);
@@ -567,23 +624,25 @@
for ( i=0 ; i<count ; i++, in++, out++)
{
-#if 0
for (j=0 ; j<8 ; j++)
out->vecs[0][j] = LittleFloat (in->vecs[0][j]);
- len1 = Length (in->vecs[0]);
- len2 = Length (in->vecs[1]);
-#else
- for (j=0 ; j<4 ; j++) {
- out->vecs[0][j] = LittleFloat (in->vecs[0][j]);
- out->vecs[1][j] = LittleFloat (in->vecs[1][j]);
- }
len1 = Length (out->vecs[0]);
len2 = Length (out->vecs[1]);
-#endif
- if (len1 + len2 < 2 /*0.001*/)
+ len1 = (len1 + len2)/2;
+ if (len1 < 0.32)
+ out->mipadjust = 4;
+ else if (len1 < 0.49)
+ out->mipadjust = 3;
+ else if (len1 < 0.99)
+ out->mipadjust = 2;
+ else
out->mipadjust = 1;
+/*
+ if (len1 + len2 < 0.001)
+ out->mipadjust = 1; // don't crash
else
- out->mipadjust = 1 / floor( (len1+len2)/2 );
+ out->mipadjust = 1 / floor( (len1+len2)/2 + 0.1 );
+*/
miptex = LittleLong (in->miptex);
out->flags = LittleLong (in->flags);
@@ -590,17 +649,17 @@
if (!loadmodel->textures)
{
- out->texture = &r_notexture_mip; // checkerboard texture
+ out->texture = r_notexture_mip; // checkerboard texture
out->flags = 0;
}
else
{
if (miptex >= loadmodel->numtextures)
- SV_Error ("miptex >= loadmodel->numtextures");
+ Sys_Error ("miptex >= loadmodel->numtextures");
out->texture = loadmodel->textures[miptex];
if (!out->texture)
{
- out->texture = &r_notexture_mip; // texture not found
+ out->texture = r_notexture_mip; // texture not found
out->flags = 0;
}
}
@@ -656,7 +715,7 @@
s->texturemins[i] = bmins[i] * 16;
s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 256)
- SV_Error ("Bad surface extents");
+ Sys_Error ("Bad surface extents");
}
}
@@ -675,7 +734,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName ( count*sizeof(*out), loadname);
@@ -711,13 +770,13 @@
// set the drawing flags flag
- if (!Q_strncmp(out->texinfo->texture->name,"sky",3)) // sky
+ if (!strncmp(out->texinfo->texture->name,"sky",3)) // sky
{
out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED);
continue;
}
- if (!Q_strncmp(out->texinfo->texture->name,"*",1)) // turbulent
+ if (!strncmp(out->texinfo->texture->name,"*",1)) // turbulent
{
out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
for (i=0 ; i<2 ; i++)
@@ -758,7 +817,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName ( count*sizeof(*out), loadname);
@@ -805,7 +864,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName ( count*sizeof(*out), loadname);
@@ -852,7 +911,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName ( count*sizeof(*out), loadname);
@@ -943,7 +1002,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName ( count*sizeof(*out), loadname);
@@ -954,7 +1013,7 @@
{
j = LittleShort(in[i]);
if (j >= loadmodel->numsurfaces)
- SV_Error ("Mod_ParseMarksurfaces: bad surface number");
+ Sys_Error ("Mod_ParseMarksurfaces: bad surface number");
out[i] = loadmodel->surfaces + j;
}
}
@@ -971,7 +1030,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName ( count*sizeof(*out), loadname);
@@ -997,7 +1056,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName ( count*2*sizeof(*out), loadname);
@@ -1020,7 +1079,24 @@
}
}
+/*
+=================
+RadiusFromBounds
+=================
+*/
+float RadiusFromBounds (vec3_t mins, vec3_t maxs)
+{
+ int i;
+ vec3_t corner;
+ for (i=0 ; i<3 ; i++)
+ {
+ corner[i] = fabs(mins[i]) > fabs(maxs[i]) ? fabs(mins[i]) : fabs(maxs[i]);
+ }
+
+ return Length (corner);
+}
+
/*
=================
Mod_LoadBrushModel
@@ -1038,7 +1114,7 @@
i = LittleLong (header->version);
if (i != BSPVERSION)
- SV_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i)", mod->name, i, BSPVERSION);
+ Sys_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i)", mod->name, i, BSPVERSION);
// swap all the lumps
mod_base = (byte *)header;
@@ -1046,23 +1122,23 @@
for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
((int *)header)[i] = LittleLong ( ((int *)header)[i]);
-// load into heap
-
mod->checksum = 0;
mod->checksum2 = 0;
- // checksum all of the map, except for entities
+// checksum all of the map, except for entities
for (i = 0; i < HEADER_LUMPS; i++) {
if (i == LUMP_ENTITIES)
continue;
- mod->checksum ^= LittleLong(Com_BlockChecksum(mod_base + header->lumps[i].fileofs,
- header->lumps[i].filelen));
+ mod->checksum ^= Com_BlockChecksum(mod_base + header->lumps[i].fileofs,
+ header->lumps[i].filelen);
if (i == LUMP_VISIBILITY || i == LUMP_LEAFS || i == LUMP_NODES)
continue;
- mod->checksum2 ^= LittleLong(Com_BlockChecksum(mod_base + header->lumps[i].fileofs,
- header->lumps[i].filelen));
+ mod->checksum2 ^= Com_BlockChecksum(mod_base + header->lumps[i].fileofs,
+ header->lumps[i].filelen);
}
+
+// load into heap
Mod_LoadVertexes (&header->lumps[LUMP_VERTEXES]);
Mod_LoadEdges (&header->lumps[LUMP_EDGES]);
@@ -1100,6 +1176,7 @@
mod->firstmodelsurface = bm->firstface;
mod->nummodelsurfaces = bm->numfaces;
+ mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
VectorCopy (bm->maxs, mod->maxs);
VectorCopy (bm->mins, mod->mins);
@@ -1118,4 +1195,677 @@
}
}
}
+
+/*
+==============================================================================
+
+ALIAS MODELS
+
+==============================================================================
+*/
+
+/*
+=================
+Mod_LoadAliasFrame
+=================
+*/
+void * Mod_LoadAliasFrame (void * pin, int *pframeindex, int numv,
+ trivertx_t *pbboxmin, trivertx_t *pbboxmax, aliashdr_t *pheader, char *name)
+{
+ trivertx_t *pframe, *pinframe;
+ int i, j;
+ daliasframe_t *pdaliasframe;
+
+ pdaliasframe = (daliasframe_t *)pin;
+
+ strcpy (name, pdaliasframe->name);
+
+ for (i=0 ; i<3 ; i++)
+ {
+ // these are byte values, so we don't have to worry about
+ // endianness
+ pbboxmin->v[i] = pdaliasframe->bboxmin.v[i];
+ pbboxmax->v[i] = pdaliasframe->bboxmax.v[i];
+ }
+
+ pinframe = (trivertx_t *)(pdaliasframe + 1);
+ pframe = Hunk_AllocName (numv * sizeof(*pframe), loadname);
+
+ *pframeindex = (byte *)pframe - (byte *)pheader;
+
+ for (j=0 ; j<numv ; j++)
+ {
+ int k;
+
+ // these are all byte values, so no need to deal with endianness
+ pframe[j].lightnormalindex = pinframe[j].lightnormalindex;
+
+ for (k=0 ; k<3 ; k++)
+ {
+ pframe[j].v[k] = pinframe[j].v[k];
+ }
+ }
+
+ pinframe += numv;
+
+ return (void *)pinframe;
+}
+
+
+/*
+=================
+Mod_LoadAliasGroup
+=================
+*/
+void * Mod_LoadAliasGroup (void * pin, int *pframeindex, int numv,
+ trivertx_t *pbboxmin, trivertx_t *pbboxmax, aliashdr_t *pheader, char *name)
+{
+ daliasgroup_t *pingroup;
+ maliasgroup_t *paliasgroup;
+ int i, numframes;
+ daliasinterval_t *pin_intervals;
+ float *poutintervals;
+ void *ptemp;
+
+ pingroup = (daliasgroup_t *)pin;
+
+ numframes = LittleLong (pingroup->numframes);
+
+ paliasgroup = Hunk_AllocName (sizeof (maliasgroup_t) +
+ (numframes - 1) * sizeof (paliasgroup->frames[0]), loadname);
+
+ paliasgroup->numframes = numframes;
+
+ for (i=0 ; i<3 ; i++)
+ {
+ // these are byte values, so we don't have to worry about endianness
+ pbboxmin->v[i] = pingroup->bboxmin.v[i];
+ pbboxmax->v[i] = pingroup->bboxmax.v[i];
+ }
+
+ *pframeindex = (byte *)paliasgroup - (byte *)pheader;
+
+ pin_intervals = (daliasinterval_t *)(pingroup + 1);
+
+ poutintervals = Hunk_AllocName (numframes * sizeof (float), loadname);
+
+ paliasgroup->intervals = (byte *)poutintervals - (byte *)pheader;
+
+ for (i=0 ; i<numframes ; i++)
+ {
+ *poutintervals = LittleFloat (pin_intervals->interval);
+ if (*poutintervals <= 0.0)
+ Sys_Error ("Mod_LoadAliasGroup: interval<=0");
+
+ poutintervals++;
+ pin_intervals++;
+ }
+
+ ptemp = (void *)pin_intervals;
+
+ for (i=0 ; i<numframes ; i++)
+ {
+ ptemp = Mod_LoadAliasFrame (ptemp,
+ &paliasgroup->frames[i].frame,
+ numv,
+ &paliasgroup->frames[i].bboxmin,
+ &paliasgroup->frames[i].bboxmax,
+ pheader, name);
+ }
+
+ return ptemp;
+}
+
+
+/*
+=================
+Mod_LoadAliasSkin
+=================
+*/
+void * Mod_LoadAliasSkin (void * pin, int *pskinindex, int skinsize,
+ aliashdr_t *pheader)
+{
+ int i;
+ byte *pskin, *pinskin;
+ unsigned short *pusskin;
+
+ pskin = Hunk_AllocName (skinsize * r_pixbytes, loadname);
+ pinskin = (byte *)pin;
+ *pskinindex = (byte *)pskin - (byte *)pheader;
+
+ if (r_pixbytes == 1)
+ {
+ memcpy (pskin, pinskin, skinsize);
+ }
+ else if (r_pixbytes == 2)
+ {
+ pusskin = (unsigned short *)pskin;
+
+ for (i=0 ; i<skinsize ; i++)
+ pusskin[i] = d_8to16table[pinskin[i]];
+ }
+ else
+ {
+ Sys_Error ("Mod_LoadAliasSkin: driver set invalid r_pixbytes: %d\n",
+ r_pixbytes);
+ }
+
+ pinskin += skinsize;
+
+ return ((void *)pinskin);
+}
+
+
+/*
+=================
+Mod_LoadAliasSkinGroup
+=================
+*/
+void * Mod_LoadAliasSkinGroup (void * pin, int *pskinindex, int skinsize,
+ aliashdr_t *pheader)
+{
+ daliasskingroup_t *pinskingroup;
+ maliasskingroup_t *paliasskingroup;
+ int i, numskins;
+ daliasskininterval_t *pinskinintervals;
+ float *poutskinintervals;
+ void *ptemp;
+
+ pinskingroup = (daliasskingroup_t *)pin;
+
+ numskins = LittleLong (pinskingroup->numskins);
+
+ paliasskingroup = Hunk_AllocName (sizeof (maliasskingroup_t) +
+ (numskins - 1) * sizeof (paliasskingroup->skindescs[0]),
+ loadname);
+
+ paliasskingroup->numskins = numskins;
+
+ *pskinindex = (byte *)paliasskingroup - (byte *)pheader;
+
+ pinskinintervals = (daliasskininterval_t *)(pinskingroup + 1);
+
+ poutskinintervals = Hunk_AllocName (numskins * sizeof (float),loadname);
+
+ paliasskingroup->intervals = (byte *)poutskinintervals - (byte *)pheader;
+
+ for (i=0 ; i<numskins ; i++)
+ {
+ *poutskinintervals = LittleFloat (pinskinintervals->interval);
+ if (*poutskinintervals <= 0)
+ Sys_Error ("Mod_LoadAliasSkinGroup: interval<=0");
+
+ poutskinintervals++;
+ pinskinintervals++;
+ }
+
+ ptemp = (void *)pinskinintervals;
+
+ for (i=0 ; i<numskins ; i++)
+ {
+ ptemp = Mod_LoadAliasSkin (ptemp,
+ &paliasskingroup->skindescs[i].skin, skinsize, pheader);
+ }
+
+ return ptemp;
+}
+
+
+/*
+=================
+Mod_LoadAliasModel
+=================
+*/
+void Mod_LoadAliasModel (model_t *mod, void *buffer)
+{
+ int i;
+ mdl_t *pmodel, *pinmodel;
+ stvert_t *pstverts, *pinstverts;
+ aliashdr_t *pheader;
+ mtriangle_t *ptri;
+ dtriangle_t *pintriangles;
+ int version, numframes, numskins;
+ int size;
+ daliasframetype_t *pframetype;
+ daliasskintype_t *pskintype;
+ maliasskindesc_t *pskindesc;
+ int skinsize;
+ int start, end, total;
+
+ if (!strcmp(loadmodel->name, "progs/player.mdl") ||
+ !strcmp(loadmodel->name, "progs/eyes.mdl")) {
+ unsigned short crc;
+ byte *p;
+ int len;
+ char st[40];
+
+ CRC_Init(&crc);
+ for (len = com_filesize, p = buffer; len; len--, p++)
+ CRC_ProcessByte(&crc, *p);
+
+ sprintf(st, "%d", (int) crc);
+ Info_SetValueForKey (cls.userinfo,
+ !strcmp(loadmodel->name, "progs/player.mdl") ? pmodel_name : emodel_name,
+ st, MAX_INFO_STRING);
+
+ if (cls.state >= ca_connected) {
+ MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
+ sprintf(st, "setinfo %s %d",
+ !strcmp(loadmodel->name, "progs/player.mdl") ? pmodel_name : emodel_name,
+ (int)crc);
+ SZ_Print (&cls.netchan.message, st);
+ }
+ }
+
+ start = Hunk_LowMark ();
+
+ pinmodel = (mdl_t *)buffer;
+
+ version = LittleLong (pinmodel->version);
+ if (version != ALIAS_VERSION)
+ Sys_Error ("%s has wrong version number (%i should be %i)",
+ mod->name, version, ALIAS_VERSION);
+
+//
+// allocate space for a working header, plus all the data except the frames,
+// skin and group info
+//
+ size = sizeof (aliashdr_t) + (LittleLong (pinmodel->numframes) - 1) *
+ sizeof (pheader->frames[0]) +
+ sizeof (mdl_t) +
+ LittleLong (pinmodel->numverts) * sizeof (stvert_t) +
+ LittleLong (pinmodel->numtris) * sizeof (mtriangle_t);
+
+ pheader = Hunk_AllocName (size, loadname);
+ pmodel = (mdl_t *) ((byte *)&pheader[1] +
+ (LittleLong (pinmodel->numframes) - 1) *
+ sizeof (pheader->frames[0]));
+
+// mod->cache.data = pheader;
+ mod->flags = LittleLong (pinmodel->flags);
+
+//
+// endian-adjust and copy the data, starting with the alias model header
+//
+ pmodel->boundingradius = LittleFloat (pinmodel->boundingradius);
+ pmodel->numskins = LittleLong (pinmodel->numskins);
+ pmodel->skinwidth = LittleLong (pinmodel->skinwidth);
+ pmodel->skinheight = LittleLong (pinmodel->skinheight);
+
+ if (pmodel->skinheight > MAX_LBM_HEIGHT)
+ Sys_Error ("model %s has a skin taller than %d", mod->name,
+ MAX_LBM_HEIGHT);
+
+ pmodel->numverts = LittleLong (pinmodel->numverts);
+
+ if (pmodel->numverts <= 0)
+ Sys_Error ("model %s has no vertices", mod->name);
+
+ if (pmodel->numverts > MAXALIASVERTS)
+ Sys_Error ("model %s has too many vertices", mod->name);
+
+ pmodel->numtris = LittleLong (pinmodel->numtris);
+
+ if (pmodel->numtris <= 0)
+ Sys_Error ("model %s has no triangles", mod->name);
+
+ pmodel->numframes = LittleLong (pinmodel->numframes);
+ pmodel->size = LittleFloat (pinmodel->size) * ALIAS_BASE_SIZE_RATIO;
+ mod->synctype = LittleLong (pinmodel->synctype);
+ mod->numframes = pmodel->numframes;
+
+ for (i=0 ; i<3 ; i++)
+ {
+ pmodel->scale[i] = LittleFloat (pinmodel->scale[i]);
+ pmodel->scale_origin[i] = LittleFloat (pinmodel->scale_origin[i]);
+ pmodel->eyeposition[i] = LittleFloat (pinmodel->eyeposition[i]);
+ }
+
+ numskins = pmodel->numskins;
+ numframes = pmodel->numframes;
+
+ if (pmodel->skinwidth & 0x03)
+ Sys_Error ("Mod_LoadAliasModel: skinwidth not multiple of 4");
+
+ pheader->model = (byte *)pmodel - (byte *)pheader;
+
+//
+// load the skins
+//
+ skinsize = pmodel->skinheight * pmodel->skinwidth;
+
+ if (numskins < 1)
+ Sys_Error ("Mod_LoadAliasModel: Invalid # of skins: %d\n", numskins);
+
+ pskintype = (daliasskintype_t *)&pinmodel[1];
+
+ pskindesc = Hunk_AllocName (numskins * sizeof (maliasskindesc_t),
+ loadname);
+
+ pheader->skindesc = (byte *)pskindesc - (byte *)pheader;
+
+ for (i=0 ; i<numskins ; i++)
+ {
+ aliasskintype_t skintype;
+
+ skintype = LittleLong (pskintype->type);
+ pskindesc[i].type = skintype;
+
+ if (skintype == ALIAS_SKIN_SINGLE)
+ {
+ pskintype = (daliasskintype_t *)
+ Mod_LoadAliasSkin (pskintype + 1,
+ &pskindesc[i].skin,
+ skinsize, pheader);
+ }
+ else
+ {
+ pskintype = (daliasskintype_t *)
+ Mod_LoadAliasSkinGroup (pskintype + 1,
+ &pskindesc[i].skin,
+ skinsize, pheader);
+ }
+ }
+
+//
+// set base s and t vertices
+//
+ pstverts = (stvert_t *)&pmodel[1];
+ pinstverts = (stvert_t *)pskintype;
+
+ pheader->stverts = (byte *)pstverts - (byte *)pheader;
+
+ for (i=0 ; i<pmodel->numverts ; i++)
+ {
+ pstverts[i].onseam = LittleLong (pinstverts[i].onseam);
+ // put s and t in 16.16 format
+ pstverts[i].s = LittleLong (pinstverts[i].s) << 16;
+ pstverts[i].t = LittleLong (pinstverts[i].t) << 16;
+ }
+
+//
+// set up the triangles
+//
+ ptri = (mtriangle_t *)&pstverts[pmodel->numverts];
+ pintriangles = (dtriangle_t *)&pinstverts[pmodel->numverts];
+
+ pheader->triangles = (byte *)ptri - (byte *)pheader;
+
+ for (i=0 ; i<pmodel->numtris ; i++)
+ {
+ int j;
+
+ ptri[i].facesfront = LittleLong (pintriangles[i].facesfront);
+
+ for (j=0 ; j<3 ; j++)
+ {
+ ptri[i].vertindex[j] =
+ LittleLong (pintriangles[i].vertindex[j]);
+ }
+ }
+
+//
+// load the frames
+//
+ if (numframes < 1)
+ Sys_Error ("Mod_LoadAliasModel: Invalid # of frames: %d\n", numframes);
+
+ pframetype = (daliasframetype_t *)&pintriangles[pmodel->numtris];
+
+ for (i=0 ; i<numframes ; i++)
+ {
+ aliasframetype_t frametype;
+
+ frametype = LittleLong (pframetype->type);
+ pheader->frames[i].type = frametype;
+
+
+ if (frametype == ALIAS_SINGLE)
+ {
+ pframetype = (daliasframetype_t *)
+ Mod_LoadAliasFrame (pframetype + 1,
+ &pheader->frames[i].frame,
+ pmodel->numverts,
+ &pheader->frames[i].bboxmin,
+ &pheader->frames[i].bboxmax,
+ pheader, pheader->frames[i].name);
+ }
+ else
+ {
+ pframetype = (daliasframetype_t *)
+ Mod_LoadAliasGroup (pframetype + 1,
+ &pheader->frames[i].frame,
+ pmodel->numverts,
+ &pheader->frames[i].bboxmin,
+ &pheader->frames[i].bboxmax,
+ pheader, pheader->frames[i].name);
+ }
+ }
+
+ mod->type = mod_alias;
+
+// FIXME: do this right
+ mod->mins[0] = mod->mins[1] = mod->mins[2] = -16;
+ mod->maxs[0] = mod->maxs[1] = mod->maxs[2] = 16;
+
+//
+// move the complete, relocatable alias model to the cache
+//
+ end = Hunk_LowMark ();
+ total = end - start;
+
+ Cache_Alloc (&mod->cache, total, loadname);
+ if (!mod->cache.data)
+ return;
+ memcpy (mod->cache.data, pheader, total);
+
+ Hunk_FreeToLowMark (start);
+}
+
+//=============================================================================
+
+/*
+=================
+Mod_LoadSpriteFrame
+=================
+*/
+void * Mod_LoadSpriteFrame (void * pin, mspriteframe_t **ppframe)
+{
+ dspriteframe_t *pinframe;
+ mspriteframe_t *pspriteframe;
+ int i, width, height, size, origin[2];
+ unsigned short *ppixout;
+ byte *ppixin;
+
+ pinframe = (dspriteframe_t *)pin;
+
+ width = LittleLong (pinframe->width);
+ height = LittleLong (pinframe->height);
+ size = width * height;
+
+ pspriteframe = Hunk_AllocName (sizeof (mspriteframe_t) + size*r_pixbytes,
+ loadname);
+
+ memset (pspriteframe, 0, sizeof (mspriteframe_t) + size);
+ *ppframe = pspriteframe;
+
+ pspriteframe->width = width;
+ pspriteframe->height = height;
+ origin[0] = LittleLong (pinframe->origin[0]);
+ origin[1] = LittleLong (pinframe->origin[1]);
+
+ pspriteframe->up = origin[1];
+ pspriteframe->down = origin[1] - height;
+ pspriteframe->left = origin[0];
+ pspriteframe->right = width + origin[0];
+
+ if (r_pixbytes == 1)
+ {
+ memcpy (&pspriteframe->pixels[0], (byte *)(pinframe + 1), size);
+ }
+ else if (r_pixbytes == 2)
+ {
+ ppixin = (byte *)(pinframe + 1);
+ ppixout = (unsigned short *)&pspriteframe->pixels[0];
+
+ for (i=0 ; i<size ; i++)
+ ppixout[i] = d_8to16table[ppixin[i]];
+ }
+ else
+ {
+ Sys_Error ("Mod_LoadSpriteFrame: driver set invalid r_pixbytes: %d\n",
+ r_pixbytes);
+ }
+
+ return (void *)((byte *)pinframe + sizeof (dspriteframe_t) + size);
+}
+
+
+/*
+=================
+Mod_LoadSpriteGroup
+=================
+*/
+void * Mod_LoadSpriteGroup (void * pin, mspriteframe_t **ppframe)
+{
+ dspritegroup_t *pingroup;
+ mspritegroup_t *pspritegroup;
+ int i, numframes;
+ dspriteinterval_t *pin_intervals;
+ float *poutintervals;
+ void *ptemp;
+
+ pingroup = (dspritegroup_t *)pin;
+
+ numframes = LittleLong (pingroup->numframes);
+
+ pspritegroup = Hunk_AllocName (sizeof (mspritegroup_t) +
+ (numframes - 1) * sizeof (pspritegroup->frames[0]), loadname);
+
+ pspritegroup->numframes = numframes;
+
+ *ppframe = (mspriteframe_t *)pspritegroup;
+
+ pin_intervals = (dspriteinterval_t *)(pingroup + 1);
+
+ poutintervals = Hunk_AllocName (numframes * sizeof (float), loadname);
+
+ pspritegroup->intervals = poutintervals;
+
+ for (i=0 ; i<numframes ; i++)
+ {
+ *poutintervals = LittleFloat (pin_intervals->interval);
+ if (*poutintervals <= 0.0)
+ Sys_Error ("Mod_LoadSpriteGroup: interval<=0");
+
+ poutintervals++;
+ pin_intervals++;
+ }
+
+ ptemp = (void *)pin_intervals;
+
+ for (i=0 ; i<numframes ; i++)
+ {
+ ptemp = Mod_LoadSpriteFrame (ptemp, &pspritegroup->frames[i]);
+ }
+
+ return ptemp;
+}
+
+
+/*
+=================
+Mod_LoadSpriteModel
+=================
+*/
+void Mod_LoadSpriteModel (model_t *mod, void *buffer)
+{
+ int i;
+ int version;
+ dsprite_t *pin;
+ msprite_t *psprite;
+ int numframes;
+ int size;
+ dspriteframetype_t *pframetype;
+
+ pin = (dsprite_t *)buffer;
+
+ version = LittleLong (pin->version);
+ if (version != SPRITE_VERSION)
+ Sys_Error ("%s has wrong version number "
+ "(%i should be %i)", mod->name, version, SPRITE_VERSION);
+
+ numframes = LittleLong (pin->numframes);
+
+ size = sizeof (msprite_t) + (numframes - 1) * sizeof (psprite->frames);
+
+ psprite = Hunk_AllocName (size, loadname);
+
+ mod->cache.data = psprite;
+
+ psprite->type = LittleLong (pin->type);
+ psprite->maxwidth = LittleLong (pin->width);
+ psprite->maxheight = LittleLong (pin->height);
+ psprite->beamlength = LittleFloat (pin->beamlength);
+ mod->synctype = LittleLong (pin->synctype);
+ psprite->numframes = numframes;
+
+ mod->mins[0] = mod->mins[1] = -psprite->maxwidth/2;
+ mod->maxs[0] = mod->maxs[1] = psprite->maxwidth/2;
+ mod->mins[2] = -psprite->maxheight/2;
+ mod->maxs[2] = psprite->maxheight/2;
+
+//
+// load the frames
+//
+ if (numframes < 1)
+ Sys_Error ("Mod_LoadSpriteModel: Invalid # of frames: %d\n", numframes);
+
+ mod->numframes = numframes;
+
+ pframetype = (dspriteframetype_t *)(pin + 1);
+
+ for (i=0 ; i<numframes ; i++)
+ {
+ spriteframetype_t frametype;
+
+ frametype = LittleLong (pframetype->type);
+ psprite->frames[i].type = frametype;
+
+ if (frametype == SPR_SINGLE)
+ {
+ pframetype = (dspriteframetype_t *)
+ Mod_LoadSpriteFrame (pframetype + 1,
+ &psprite->frames[i].frameptr);
+ }
+ else
+ {
+ pframetype = (dspriteframetype_t *)
+ Mod_LoadSpriteGroup (pframetype + 1,
+ &psprite->frames[i].frameptr);
+ }
+ }
+
+ mod->type = mod_sprite;
+}
+
+//=============================================================================
+
+/*
+================
+Mod_Print
+================
+*/
+void Mod_Print (void)
+{
+ int i;
+ model_t *mod;
+
+ Con_Printf ("Cached models:\n");
+ for (i=0, mod=mod_known ; i < mod_numknown ; i++, mod++)
+ {
+ Con_Printf ("%8p : %s\n",mod->cache.data, mod->name);
+ }
+}
+
--- a/qw/model.h
+++ b/qw/model.h
@@ -1,16 +1,8 @@
-#ifndef __MODEL__
-#define __MODEL__
-
-#include "modelgen.h"
-#include "spritegn.h"
-
/*
+ * d*_t structures are on-disk representations
+ * m*_t structures are in-memory
+ */
-d*_t structures are on-disk representations
-m*_t structures are in-memory
-
-*/
-
// entity effects
#define EF_BRIGHTFIELD 1
@@ -378,5 +370,3 @@
mleaf_t *Mod_PointInLeaf (float *p, model_t *model);
byte *Mod_LeafPVS (mleaf_t *leaf, model_t *model);
-
-#endif // __MODEL__
--- a/qw/modelgen.h
+++ b/qw/modelgen.h
@@ -1,31 +1,8 @@
-//
// modelgen.h: header file for model generation program
-//
-// *********************************************************
-// * This file must be identical in the modelgen directory *
-// * and in the Quake directory, because it's used to *
-// * pass data from one to the other via model files. *
-// *********************************************************
-
-#ifdef INCLUDELIBS
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-
-#include "cmdlib.h"
-#include "scriplib.h"
-#include "trilib.h"
-#include "lbmlib.h"
-#include "mathlib.h"
-
-#endif
-
#define ALIAS_VERSION 6
-#define ALIAS_ONSEAM 0x0020
+#pragma pack on
// must match definition in spritegn.h
#ifndef SYNCTYPE_T
@@ -113,3 +90,4 @@
#define IDPOLYHEADER (('O'<<24)+('P'<<16)+('D'<<8)+'I')
// little-endian "IDPO"
+#pragma pack off
--- a/qw/net.h
+++ b/qw/net.h
@@ -9,7 +9,7 @@
unsigned short pad;
} netadr_t;
-extern netadr_t net_local_adr;
+extern netadr_t laddr;
extern netadr_t net_from; // address of who sent the packet
extern sizebuf_t net_message;
@@ -27,7 +27,6 @@
char *NET_AdrToString (netadr_t a);
char *NET_BaseAdrToString (netadr_t a);
qboolean NET_StringToAdr (char *s, netadr_t *a);
-qboolean NET_IsClientLegal(netadr_t *adr);
//============================================================================
--- a/qw/net_chan.c
+++ b/qw/net_chan.c
@@ -70,11 +70,7 @@
int port;
// pick a port value that should be nice and random
-#ifdef _WIN32
- port = ((int)(timeGetTime()*1000) * time(NULL)) & 0xffff;
-#else
- port = ((int)(getpid()+getuid()*1000) * time(NULL)) & 0xffff;
-#endif
+ port = ((int)(getpid()+nrand(4096)*1000) * time(nil)) & 0xffff;
Cvar_RegisterVariable (&showpackets);
Cvar_RegisterVariable (&showdrop);
@@ -104,9 +100,7 @@
// send the datagram
//zoid, no input in demo playback mode
-#ifndef SERVERONLY
- if (!cls.demoplayback)
-#endif
+ if(svonly || !cls.demoplayback)
NET_SendPacket (send.cursize, send.data, adr);
}
@@ -185,10 +179,6 @@
return Netchan_CanPacket (chan);
}
-#ifdef SERVERONLY
-qboolean ServerPaused(void);
-#endif
-
/*
===============
Netchan_Transmit
@@ -247,9 +237,8 @@
MSG_WriteLong (&send, w2);
// send the qport if we are a client
-#ifndef SERVERONLY
- MSG_WriteShort (&send, cls.qport);
-#endif
+ if(!svonly)
+ MSG_WriteShort (&send, cls.qport);
// copy the reliable message to the packet first
if (send_reliable)
@@ -268,9 +257,7 @@
chan->outgoing_time[i] = realtime;
//zoid, no input in demo playback mode
-#ifndef SERVERONLY
- if (!cls.demoplayback)
-#endif
+ if(svonly || !cls.demoplayback)
NET_SendPacket (send.cursize, send.data, chan->remote_address);
if (chan->cleartime < realtime)
@@ -277,10 +264,8 @@
chan->cleartime = realtime + send.cursize*chan->rate;
else
chan->cleartime += send.cursize*chan->rate;
-#ifdef SERVERONLY
- if (ServerPaused())
+ if(ServerPaused())
chan->cleartime = realtime;
-#endif
if (showpackets.value)
Con_Printf ("--> s=%i(%i) a=%i(%i) %i\n"
@@ -304,18 +289,11 @@
{
unsigned sequence, sequence_ack;
unsigned reliable_ack, reliable_message;
-#ifdef SERVERONLY
int qport;
-#endif
- int i;
- if (
-#ifndef SERVERONLY
- !cls.demoplayback &&
-#endif
- !NET_CompareAdr (net_from, chan->remote_address))
+ if((svonly || !cls.demoplayback) && !NET_CompareAdr(net_from, chan->remote_address))
return false;
-
+
// get sequence numbers
MSG_BeginReading ();
sequence = MSG_ReadLong ();
@@ -322,9 +300,10 @@
sequence_ack = MSG_ReadLong ();
// read the qport if we are a server
-#ifdef SERVERONLY
- qport = MSG_ReadShort ();
-#endif
+ if(svonly){
+ qport = MSG_ReadShort ();
+ USED(qport);
+ }
reliable_message = sequence >> 31;
reliable_ack = sequence_ack >> 31;
@@ -340,8 +319,7 @@
, reliable_ack
, net_message.cursize);
-// get a rate estimation
-#if 0
+/* get a rate estimation
if (chan->outgoing_sequence - sequence_ack < MAX_LATENT)
{
int i;
@@ -368,7 +346,7 @@
}
}
}
-#endif
+*/
//
// discard stale or duplicated packets
--- a/qw/net_udp.c
+++ b/qw/net_udp.c
@@ -1,278 +1,390 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
+#include <thread.h>
+#include <bio.h>
+#include <ndb.h>
+#include <ip.h>
#include "quakedef.h"
-netadr_t net_local_adr;
+extern Channel *fuckchan; /* main fuck receptor */
-netadr_t net_from;
-sizebuf_t net_message;
-int net_socket; // non blocking, for receives
-int net_send_socket; // blocking, for sends
+sizebuf_t net_message;
+netadr_t laddr = { .ip{ 192, 168, 1, 138} }; /* 0.0.0.0:0 */
+netadr_t net_from;
-#define MAX_UDP_PACKET 8192
-byte net_message_buffer[MAX_UDP_PACKET];
+typedef struct Conmsg Conmsg;
+typedef struct Conlist Conlist;
-int gethostname (char *, int);
-int close (int);
+enum{
+ Nbuf = 64,
+ Bufsz = 8192,
+ Hdrsz = 16+16+16+2+2, /* sizeof Udphdr w/o padding */
+};
+static int cfd = -1, ufd = -1;
+static char srv[6];
+static uchar netbuf[Bufsz];
+static Channel *udpchan;
+static QLock cnlock;
-//=============================================================================
+struct Conlist{
+ Conlist *p;
+ uchar u[IPaddrlen+2];
+ char addr[IPaddrlen*2+8+6]; /* ipv6 + separators + port in decimal */
+ int dfd;
+ Udphdr h;
+};
+Conlist *cnroot;
-void NetadrToSockadr (netadr_t *a, struct sockaddr_in *s)
-{
- memset (s, 0, sizeof(*s));
- s->sin_family = AF_INET;
+struct Conmsg{
+ Conlist *p;
+ int n;
+ uchar buf[Bufsz];
+};
- *(int *)&s->sin_addr = *(int *)&a->ip;
- s->sin_port = a->port;
-}
+static void uproc(void *);
+static void dproc(void *);
+static void cninit(void);
+static Conlist* cnins(int, char *, uchar *, Udphdr *);
+static Conlist* cnfind(char *);
+static void cndel(Conlist *);
+static void cnnuke(void);
-void SockadrToNetadr (struct sockaddr_in *s, netadr_t *a)
-{
- *(int *)&a->ip = *(int *)&s->sin_addr;
- a->port = s->sin_port;
-}
-qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b)
+netadr_t net_from;
+int net_socket; // non blocking, for receives
+int net_send_socket; // blocking, for sends
+
+
+qboolean
+NET_CompareBaseAdr(netadr_t a, netadr_t b)
{
- if (a.ip[0] == b.ip[0] && a.ip[1] == b.ip[1] && a.ip[2] == b.ip[2] && a.ip[3] == b.ip[3])
- return true;
- return false;
+ return a.ip[0] == b.ip[0] && a.ip[1] == b.ip[1] && a.ip[2] == b.ip[2] && a.ip[3] == b.ip[3];
}
-
-qboolean NET_CompareAdr (netadr_t a, netadr_t b)
+qboolean
+NET_CompareAdr(netadr_t a, netadr_t b)
{
- if (a.ip[0] == b.ip[0] && a.ip[1] == b.ip[1] && a.ip[2] == b.ip[2] && a.ip[3] == b.ip[3] && a.port == b.port)
- return true;
- return false;
+ return a.ip[0] == b.ip[0] && a.ip[1] == b.ip[1] && a.ip[2] == b.ip[2] && a.ip[3] == b.ip[3] && a.port == b.port;
}
-char *NET_AdrToString (netadr_t a)
+char *
+NET_AdrToString(netadr_t a)
{
- static char s[64];
-
- sprintf (s, "%i.%i.%i.%i:%i", a.ip[0], a.ip[1], a.ip[2], a.ip[3], ntohs(a.port));
+ static char s[256];
+ seprint(s, s+sizeof s, "%ud.%ud.%ud.%ud:%hud", a.ip[0], a.ip[1], a.ip[2], a.ip[3], BigShort(a.port));
return s;
}
-char *NET_BaseAdrToString (netadr_t a)
+char *
+NET_BaseAdrToString(netadr_t a)
{
- static char s[64];
-
- sprintf (s, "%i.%i.%i.%i", a.ip[0], a.ip[1], a.ip[2], a.ip[3]);
+ static char s[256];
+ seprint(s, s+sizeof s, "%ud.%ud.%ud.%ud", a.ip[0], a.ip[1], a.ip[2], a.ip[3]);
return s;
}
/*
-=============
-NET_StringToAdr
-
idnewt
idnewt:28000
192.246.40.70
192.246.40.70:28000
-=============
*/
-qboolean NET_StringToAdr (char *s, netadr_t *a)
+qboolean
+NET_StringToAdr(char *addr, netadr_t *a) /* assumes IPv4 */
{
- struct hostent *h;
- struct sockaddr_in sadr;
- char *colon;
- char copy[128];
-
-
- memset (&sadr, 0, sizeof(sadr));
- sadr.sin_family = AF_INET;
-
- sadr.sin_port = 0;
+ int i;
+ char s[256], *p, *pp;
+ Ndbtuple *t, *nt;
- strcpy (copy, s);
- // strip off a trailing :port if present
- for (colon = copy ; *colon ; colon++)
- if (*colon == ':')
- {
- *colon = 0;
- sadr.sin_port = htons(atoi(colon+1));
- }
-
- if (copy[0] >= '0' && copy[0] <= '9')
- {
- *(int *)&sadr.sin_addr = inet_addr(copy);
+ strncpy(s, addr, sizeof s);
+ s[sizeof(s)-1] = 0;
+
+ /* FIXME: arbitrary length strings: ip.h limit? */
+ if((p = strrchr(s, ':')) != nil){
+ *p++ = '\0';
+ a->port = BigShort(atoi(p));
}
- else
- {
- if (! (h = gethostbyname(copy)) )
+
+ /* FIXME: sys */
+ if(strcmp(ipattr(s), "dom") == 0){
+ if((t = dnsquery(nil, s, "ip")) == nil){
+ fprint(2, "NET_StringToAdr:dnsquery %s: %r\n", s);
return 0;
- *(int *)&sadr.sin_addr = *(int *)h->h_addr_list[0];
+ }
+
+ for(nt = t; nt != nil; nt = nt->entry)
+ if(!strcmp(nt->attr, "ip")){
+ strncpy(s, nt->val, sizeof(s)-1);
+ break;
+ }
+ ndbfree(t);
}
-
- SockadrToNetadr (&sadr, a);
+ /* FIXMEGASHIT */
+ for(i = 0, pp = s; i < IPv4addrlen; i++){
+ if((p = strchr(pp, '.')) != nil)
+ *p++ = 0;
+ a->ip[i] = atoi(pp);
+ pp = p;
+ }
return true;
}
-// Returns true if we can't bind the address locally--in other words,
-// the IP is NOT one of our interfaces.
-qboolean NET_IsClientLegal(netadr_t *adr)
+static void
+cninit(void)
{
- struct sockaddr_in sadr;
- int newsocket;
+ if(cnroot != nil)
+ return;
+ if((cnroot = malloc(sizeof *cnroot)) == nil)
+ sysfatal("cninit:malloc: %r");
+ cnroot->p = cnroot;
+ memset(cnroot->u, 0, sizeof cnroot->u);
+ memset(cnroot->addr, 0, sizeof cnroot->addr);
+ cnroot->dfd = -1;
+}
-#if 0
- if (adr->ip[0] == 127)
- return false; // no local connections period
+static Conlist *
+cnins(int fd, char *addr, uchar *u, Udphdr *h)
+{
+ Conlist *p, *l;
- NetadrToSockadr (adr, &sadr);
+ l = cnroot;
+ if((p = malloc(sizeof *p)) == nil)
+ sysfatal("cnins:malloc: %r");
- if ((newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
- Sys_Error ("NET_IsClientLegal: socket:", strerror(errno));
+ strncpy(p->addr, addr, sizeof p->addr);
+ memcpy(p->u, u, sizeof p->u);
+ p->dfd = fd;
+ if(h != nil)
+ memcpy(&p->h, h, sizeof p->h);
+ p->p = l->p;
+ l->p = p;
+ return p;
+}
- sadr.sin_port = 0;
+static Conlist *
+cnfind(char *raddr)
+{
+ Conlist *p = cnroot->p;
- if( bind (newsocket, (void *)&sadr, sizeof(sadr)) == -1)
- {
- // It is not a local address
- close(newsocket);
- return true;
+ while(p != cnroot){
+ if(!strncmp(p->addr, raddr, strlen(p->addr)))
+ return p;
+ p = p->p;
}
- close(newsocket);
- return false;
-#else
- return true;
-#endif
+ return nil;
}
+static void
+cndel(Conlist *p)
+{
+ Conlist *l = cnroot;
-//=============================================================================
+ while(l->p != p){
+ l = l->p;
+ if(l == cnroot)
+ sysfatal("cndel: bad unlink: cnroot 0x%p node 0x%p\n", cnroot, p);
+ }
+ l->p = p->p;
+ if(p->dfd != ufd && p->dfd != -1)
+ close(p->dfd);
+ free(p);
+}
-qboolean NET_GetPacket (void)
+static void
+cnnuke(void)
{
- int ret;
- struct sockaddr_in from;
- int fromlen;
+ Conlist *p, *l = cnroot;
- fromlen = sizeof(from);
- ret = recvfrom (net_socket, net_message_buffer, sizeof(net_message_buffer), 0, (struct sockaddr *)&from, &fromlen);
- if (ret == -1) {
- if (errno == EWOULDBLOCK)
- return false;
- if (errno == ECONNREFUSED)
- return false;
- Sys_Printf ("NET_GetPacket: %s\n", strerror(errno));
+ if(cnroot == nil)
+ return;
+ do{
+ p = l;
+ l = l->p;
+ if(p->dfd != -1)
+ close(p->dfd);
+ free(p);
+ }while(l != cnroot);
+ cnroot = nil;
+}
+
+qboolean
+NET_GetPacket(void)
+{
+ int n;
+ Conmsg m;
+
+ if(cfd == -1)
return false;
- }
- net_message.cursize = ret;
- SockadrToNetadr (&from, &net_from);
+ if((n = nbrecv(udpchan, &m)) < 0)
+ sysfatal("NET_GetPacket:nbrecv: %r");
+ if(n == 0)
+ return false;
+ memcpy(net_from.ip, m.p->u+12, 4);
+ net_from.port = m.p->u[17] << 8 | m.p->u[16];
+ net_message.cursize = m.n;
+ memcpy(netbuf, m.buf, m.n);
- return ret;
+ return true;
}
-//=============================================================================
-
-void NET_SendPacket (int length, void *data, netadr_t to)
+void
+NET_SendPacket(int length, void *data, netadr_t to)
{
- int ret;
- struct sockaddr_in addr;
+ int fd;
+ char *addr, *s, *lport;
+ uchar b[Bufsz+Hdrsz], u[IPaddrlen+2];
+ Conlist *p;
- NetadrToSockadr (&to, &addr);
+ if(cfd == -1)
+ return;
- ret = sendto (net_socket, data, length, 0, (struct sockaddr *)&addr, sizeof(addr) );
- if (ret == -1) {
- if (errno == EWOULDBLOCK)
+ addr = NET_AdrToString(to);
+ qlock(&cnlock);
+ p = cnfind(addr);
+ qunlock(&cnlock);
+ if(p != nil){
+ fd = p->dfd;
+ if(fd == ufd){
+ memcpy(b, &p->h, Hdrsz);
+ memcpy(b+Hdrsz, data, length);
+ write(fd, b, length+Hdrsz);
return;
- if (errno == ECONNREFUSED)
- return;
- Sys_Printf ("NET_SendPacket: %s\n", strerror(errno));
+ }else if(write(fd, data, length) != length)
+ sysfatal("NET_SendPacket:write: %r");
+ }else{
+ lport = strrchr(addr, ':');
+ *lport++ = '\0';
+ s = netmkaddr(addr, "udp", lport);
+ if((fd = dial(s, srv, nil, nil)) < 0)
+ sysfatal("NET_SendPacket:dial: %r");
+
+ memcpy(u, v4prefix, sizeof v4prefix);
+ memcpy(u+IPv4off, to.ip, IPv4addrlen);
+ u[16] = to.port;
+ u[17] = to.port >> 8;
+ *(lport-1) = ':';
+ qlock(&cnlock);
+ p = cnins(fd, addr, u, nil);
+ qunlock(&cnlock);
+
+ if(proccreate(dproc, p, 8196*4) < 0)
+ sysfatal("NET_SendPacket:proccreate: %r");
}
+ if(write(fd, data, length) != length)
+ sysfatal("NET_SendPacket:write: %r");
}
-//=============================================================================
-
-int UDP_OpenSocket (int port)
+static void
+dproc(void *me)
{
- int newsocket;
- struct sockaddr_in address;
- qboolean _true = true;
- int i;
+ int n, fd;
+ Conmsg m;
+ Conlist *p;
- if ((newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
- Sys_Error ("UDP_OpenSocket: socket:", strerror(errno));
- if (ioctl (newsocket, FIONBIO, (char *)&_true) == -1)
- Sys_Error ("UDP_OpenSocket: ioctl FIONBIO:", strerror(errno));
- address.sin_family = AF_INET;
-//ZOID -- check for interface binding option
- if ((i = COM_CheckParm("-ip")) != 0 && i < com_argc) {
- address.sin_addr.s_addr = inet_addr(com_argv[i+1]);
- Con_Printf("Binding to IP Interface Address of %s\n",
- inet_ntoa(address.sin_addr));
- } else
- address.sin_addr.s_addr = INADDR_ANY;
- if (port == PORT_ANY)
- address.sin_port = 0;
- else
- address.sin_port = htons((short)port);
- if( bind (newsocket, (void *)&address, sizeof(address)) == -1)
- Sys_Error ("UDP_OpenSocket: bind: %s", strerror(errno));
+ threadsetgrp(THnet);
- return newsocket;
+ m.p = p = me;
+ fd = p->dfd;
+
+ for(;;){
+ if((n = read(fd, m.buf, sizeof m.buf)) <= 0)
+ break;
+ m.n = n;
+ if(send(udpchan, &m) < 0)
+ sysfatal("uproc:send: %r\n");
+ if(svonly && nbsend(fuckchan, nil) < 0)
+ sysfatal("fuckchan %r\n");
+ }
+ fprint(2, "dproc %d: %r\n", threadpid(threadid()));
+ cndel(me);
}
-void NET_GetLocalAddress (void)
+static void
+uproc(void *)
{
- char buff[MAXHOSTNAMELEN];
- struct sockaddr_in address;
- int namelen;
+ int n;
+ uchar udpbuf[Bufsz+Hdrsz], u[IPaddrlen+2];
+ char a[IPaddrlen*2+8+6];
+ Udphdr h;
+ Conmsg m;
+ Conlist *p;
- gethostname(buff, MAXHOSTNAMELEN);
- buff[MAXHOSTNAMELEN-1] = 0;
+ threadsetgrp(THnet);
- NET_StringToAdr (buff, &net_local_adr);
+ for(;;){
+ if((n = read(ufd, udpbuf, sizeof udpbuf)) <= 0)
+ sysfatal("uproc:read: %r");
- namelen = sizeof(address);
- if (getsockname (net_socket, (struct sockaddr *)&address, &namelen) == -1)
- Sys_Error ("NET_Init: getsockname:", strerror(errno));
- net_local_adr.port = address.sin_port;
+ memcpy(&h, udpbuf, Hdrsz);
+ memcpy(u, h.raddr, IPaddrlen);
+ memcpy(u+IPaddrlen, h.rport, 2);
+ snprint(a, sizeof a, "%ud.%ud.%ud.%ud:%hud", u[12], u[13], u[14], u[15], u[16]<<8 | u[17]);
+ qlock(&cnlock);
+ if((p = cnfind(a)) == nil)
+ p = cnins(ufd, a, u, &h);
+ qunlock(&cnlock);
+ m.p = p;
- Con_Printf("IP address %s\n", NET_AdrToString (net_local_adr) );
+ if(n - Hdrsz < 0){ /* FIXME */
+ m.n = n;
+ memcpy(m.buf, udpbuf, m.n);
+ }else{
+ m.n = n - Hdrsz;
+ memcpy(m.buf, udpbuf+Hdrsz, m.n);
+ }
+ if(send(udpchan, &m) < 0)
+ sysfatal("uproc:send: %r\n");
+ if(svonly && nbsend(fuckchan, nil) < 0)
+ sysfatal("fucking chan refused the fuck: %r\n");
+ }
}
-/*
-====================
-NET_Init
-====================
-*/
-void NET_Init (int port)
+void
+NET_Init(int port)
{
- //
- // open the single socket to be used for all communications
- //
- net_socket = UDP_OpenSocket (port);
+ char data[64], adir[40];
- //
- // init the message buffer
- //
- net_message.maxsize = sizeof(net_message_buffer);
- net_message.data = net_message_buffer;
+ if(cfd != -1)
+ return;
- //
- // determine my name & address
- //
- NET_GetLocalAddress ();
+ cninit();
+ snprint(srv, sizeof srv, "%hud", port);
+ if((cfd = announce(netmkaddr("*", "udp", srv), adir)) < 0)
+ sysfatal("announce udp!*!%s: %r", srv);
+ if(fprint(cfd, "headers") < 0)
+ sysfatal("NET_Init: failed to set header mode: %r");
+ snprint(data, sizeof data, "%s/data", adir);
+ if((ufd = open(data, ORDWR)) < 0)
+ sysfatal("open: %r");
+ if((udpchan = chancreate(sizeof(Conmsg), Nbuf)) == nil)
+ sysfatal("chancreate udpchan: %r");
+ if(proccreate(uproc, udpchan, 8192*4) < 0)
+ sysfatal("proccreate: %r");
- Con_Printf("UDP Initialized\n");
+ net_message.maxsize = sizeof netbuf;
+ net_message.data = netbuf;
}
-/*
-====================
-NET_Shutdown
-====================
-*/
-void NET_Shutdown (void)
+void
+NET_Shutdown(void)
{
- close (net_socket);
+ threadkillgrp(THnet);
+ cnnuke();
+ if(udpchan != nil){
+ chanfree(udpchan);
+ udpchan = nil;
+ }
+ if(cfd != -1){
+ close(cfd);
+ cfd = -1;
+ }
+ if(ufd != -1){
+ close(ufd);
+ ufd = -1;
+ }
}
-
--- a/qw/nonintel.c
+++ b/qw/nonintel.c
@@ -7,14 +7,12 @@
#include <stdio.h>
#include "quakedef.h"
-#if !id386
-
/*
================
R_Surf8Patch
================
*/
-void R_Surf8Patch ()
+void R_Surf8Patch (void)
{
// we only patch code on Intel
}
@@ -25,7 +23,7 @@
R_Surf16Patch
================
*/
-void R_Surf16Patch ()
+void R_Surf16Patch (void)
{
// we only patch code on Intel
}
@@ -40,7 +38,3 @@
{
// we only patch code on Intel
}
-
-
-#endif // !id386
-
--- a/qw/pmove.c
+++ b/qw/pmove.c
@@ -3,7 +3,6 @@
#include <stdio.h>
#include "quakedef.h"
-
movevars_t movevars;
playermove_t pmove;
@@ -758,7 +757,7 @@
*/
void SpectatorMove (void)
{
- float speed, drop, friction, control, newspeed, accel;
+ float speed, drop, friction, control, newspeed;
float currentspeed, addspeed, accelspeed;
int i;
vec3_t wishvel;
@@ -765,9 +764,7 @@
float fmove, smove;
vec3_t wishdir;
float wishspeed;
-#ifndef SERVERONLY
extern float server_version; // version of server we connected to
-#endif
// friction
--- a/qw/pmovetst.c
+++ b/qw/pmovetst.c
@@ -203,18 +203,17 @@
t1 = DotProduct (plane->normal, p1) - plane->dist;
t2 = DotProduct (plane->normal, p2) - plane->dist;
}
-
-#if 1
- if (t1 >= 0 && t2 >= 0)
- return PM_RecursiveHullCheck (hull, node->children[0], p1f, p2f, p1, p2, trace);
- if (t1 < 0 && t2 < 0)
- return PM_RecursiveHullCheck (hull, node->children[1], p1f, p2f, p1, p2, trace);
-#else
+
+/*
if ( (t1 >= DIST_EPSILON && t2 >= DIST_EPSILON) || (t2 > t1 && t1 >= 0) )
return PM_RecursiveHullCheck (hull, node->children[0], p1f, p2f, p1, p2, trace);
if ( (t1 <= -DIST_EPSILON && t2 <= -DIST_EPSILON) || (t2 < t1 && t1 <= 0) )
return PM_RecursiveHullCheck (hull, node->children[1], p1f, p2f, p1, p2, trace);
-#endif
+*/
+ if (t1 >= 0 && t2 >= 0)
+ return PM_RecursiveHullCheck (hull, node->children[0], p1f, p2f, p1, p2, trace);
+ if (t1 < 0 && t2 < 0)
+ return PM_RecursiveHullCheck (hull, node->children[1], p1f, p2f, p1, p2, trace);
// put the crosspoint DIST_EPSILON pixels on the near side
if (t1 < 0)
@@ -237,10 +236,9 @@
return false;
#ifdef PARANOID
- if (PM_HullPointContents (pm_hullmodel, mid, node->children[side])
- == CONTENTS_SOLID)
- {
- Con_Printf ("mid PointInHullSolid\n");
+// if (PM_HullPointContents (pm_hullmodel, mid, node->children[side]) == CONTENTS_SOLID)
+ if(PM_HullPointContents(hull, node->children[side], mid) == CONTENTS_SOLID){
+ Con_Printf("mid PointInHullSolid\n");
return false;
}
#endif
--- a/qw/pr_cmds.c
+++ b/qw/pr_cmds.c
@@ -1,7 +1,7 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "qwsvdef.h"
+#include "quakedef.h"
#define RETURN_EDICT(e) (((int *)pr_globals)[OFS_RETURN] = EDICT_TO_PROG(e))
#define RETURN_STRING(s) (((int *)pr_globals)[OFS_RETURN] = PR_SetString(s))
@@ -1145,11 +1145,10 @@
int i, j;
trace_t tr;
float dist, bestdist;
- float speed;
char *noaim;
ent = G_EDICT(OFS_PARM0);
- speed = G_FLOAT(OFS_PARM1);
+ /*float speed = G_FLOAT(OFS_PARM1);*/
VectorCopy (ent->v.origin, start);
start[2] += 20;
@@ -1283,9 +1282,7 @@
sizebuf_t *WriteDest (void)
{
- int entnum;
int dest;
- edict_t *ent;
dest = G_FLOAT(OFS_PARM0);
switch (dest)
@@ -1295,13 +1292,13 @@
case MSG_ONE:
SV_Error("Shouldn't be at MSG_ONE");
-#if 0
- ent = PROG_TO_EDICT(pr_global_struct->msg_entity);
- entnum = NUM_FOR_EDICT(ent);
+/*
+ edict *ent = PROG_TO_EDICT(pr_global_struct->msg_entity);
+ int entnum = NUM_FOR_EDICT(ent);
if (entnum < 1 || entnum > MAX_CLIENTS)
PR_RunError ("WriteDest: not a client");
return &svs.clients[entnum-1].netchan.message;
-#endif
+*/
case MSG_ALL:
return &sv.reliable_datagram;
--- a/qw/pr_comp.h
+++ b/qw/pr_comp.h
@@ -1,5 +1,3 @@
-// this file is shared by quake and qcc
-
typedef int func_t;
typedef int string_t;
@@ -97,6 +95,7 @@
OP_BITOR
};
+#pragma pack on
typedef struct statement_s
{
@@ -158,3 +157,4 @@
int entityfields;
} dprograms_t;
+#pragma pack off
--- a/qw/pr_edict.c
+++ b/qw/pr_edict.c
@@ -3,7 +3,7 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "qwsvdef.h"
+#include "quakedef.h"
dprograms_t *progs;
dfunction_t *pr_functions;
@@ -219,7 +219,7 @@
eval_t *GetEdictFieldValue(edict_t *ed, char *field)
{
- ddef_t *def = NULL;
+ ddef_t *def;
int i;
static int rep = 0;
--- a/qw/pr_exec.c
+++ b/qw/pr_exec.c
@@ -1,12 +1,7 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "qwsvdef.h"
-
-
-/*
-
-*/
+#include "quakedef.h"
typedef struct
{
--- a/qw/progs.h
+++ b/qw/progs.h
@@ -1,6 +1,3 @@
-#include "pr_comp.h" // defs shared with qcc
-#include "progdefs.h" // generated by program cdefs
-
typedef union eval_s
{
string_t string;
@@ -9,7 +6,7 @@
func_t function;
int _int;
int edict;
-} eval_t;
+} eval_t;
#define MAX_ENT_LEAFS 16
typedef struct edict_s
--- a/qw/protocol.h
+++ b/qw/protocol.h
@@ -190,10 +190,12 @@
#define DEFAULT_SOUND_PACKET_ATTENUATION 1.0
// svc_print messages have an id, so messages can be filtered
-#define PRINT_LOW 0
-#define PRINT_MEDIUM 1
-#define PRINT_HIGH 2
-#define PRINT_CHAT 3 // also go to chat buffer
+enum{
+ PRINT_LOW = 0, /* pickup messages */
+ PRINT_MEDIUM = 1, /* death messages */
+ PRINT_HIGH = 2, /* critical messages */
+ PRINT_CHAT = 3 /* char messages, also go to chat buffer */
+};
//
// temp entity events
--- a/qw/quakedef.h
+++ b/qw/quakedef.h
@@ -1,19 +1,17 @@
+// quakedef.h -- primary header for client
+
#define QUAKE_GAME // as opposed to utilities
+//#define PARANOID // speed sapping error checking
-//define PARANOID // speed sapping error checking
+enum{
+ VERSION = 2.40,
+ PLAN9_VERSION = 0.98
+};
-// defs common to client and server
+#define UNALIGNED_OK 0 // set to 0 if unaligned accesses are not supported (!386)
-#define VERSION 2.40
-#define LINUX_VERSION 0.98
+#define CACHE_SIZE 32 // used to align key data structures
-//#define id386
-
-//#define UNALIGNED_OK
-
-// !!! if this is changed, it must be changed in d_ifacea.h too !!!
-#define CACHE_SIZE 32 // used to align key data structures
-
#define MINIMUM_MEMORY 0x550000
// up / down
@@ -115,14 +113,22 @@
#define IT_SIGIL3 (1<<30)
#define IT_SIGIL4 (1<<31)
-//
-// print flags
-//
-#define PRINT_LOW 0 // pickup messages
-#define PRINT_MEDIUM 1 // death messages
-#define PRINT_HIGH 2 // critical messages
-#define PRINT_CHAT 3 // chat messages
+
+#define Max(a,b) ((a) > (b) ? (a) : (b))
+#define Min(a,b) ((a) < (b) ? (a) : (b))
+
+typedef struct
+{
+ char *basedir; // base of directory tree
+ char *cachedir; // for development over ISDN lines
+ int argc;
+ char **argv;
+ void *membase; // amount of memory available for use
+ int memsize;
+} quakeparms_t;
+
+
#include "common.h"
#include "bspfile.h"
#include "vid.h"
@@ -140,6 +146,8 @@
#include "sound.h"
#include "render.h"
#include "client.h"
+#include "modelgen.h"
+#include "spritegn.h"
#include "model.h"
#include "d_iface.h"
#include "input.h"
@@ -148,31 +156,19 @@
#include "view.h"
#include "menu.h"
#include "crc.h"
+#include "pr_comp.h" // defs shared with qcc
+#include "progdefs.h" // generated by program cdefs
+#include "progs.h"
#include "cdaudio.h"
+#include "server.h"
+#include "world.h"
#include "pmove.h"
+#include "r_shared.h"
+#include "d_local.h"
+#include "r_local.h"
-#define max(a,b) ((a) > (b) ? (a) : (b))
-#define min(a,b) ((a) < (b) ? (a) : (b))
-
//=============================================================================
-// the host system specifies the base of the directory tree, the
-// command line parms passed to the program, and the amount of memory
-// available for the program to use
-
-typedef struct
-{
- char *basedir;
- char *cachedir; // for development over ISDN lines
- int argc;
- char **argv;
- void *membase;
- int memsize;
-} quakeparms_t;
-
-
-//=============================================================================
-
#define MAX_NUM_ARGVS 50
@@ -213,3 +209,5 @@
extern qboolean msg_suppress_1; // suppresses resolution and cache size console output
// an fullscreen DIB focus gain/loss
+void SV_Error (char *error, ...);
+void SV_Init (quakeparms_t *parms);
--- a/qw/qwcl.c
+++ b/qw/qwcl.c
@@ -1,3 +1,50 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
+#include <thread.h>
+#include "quakedef.h"
+
+mainstacksize = 512*1024;
+Channel *fuckchan;
+
+
+/* FIXME: stupid-ass linking kludges */
+server_static_t svs;
+qboolean ServerPaused(void){return 0;}
+void SV_SendServerInfoChange(char *, char *){}
+
+
+static void
+croak(void *, char *note)
+{
+ if(!strncmp(note, "sys:", 4)){
+ IN_Shutdown();
+ SNDDMA_Shutdown();
+ NET_Shutdown();
+ }
+ noted(NDFLT);
+}
+
+void
+threadmain(int argc, char *argv[])
+{
+ double time, oldtime, newtime;
+ quakeparms_t q;
+
+ /* ignore fp exceptions: rendering shit assumes they are */
+ setfcr(getfcr() & ~(FPOVFL|FPUNFL|FPINVAL|FPZDIV));
+ notify(croak);
+
+ COM_InitArgv(argc, argv);
+ initparm(&q);
+ Sys_Init();
+ Host_Init(&q);
+
+ oldtime = Sys_DoubleTime ();
+ for(;;){
+ newtime = Sys_DoubleTime(); /* time spent rendering last frame */
+ time = newtime - oldtime;
+ Host_Frame(time);
+ oldtime = newtime;
+ }
+}
--- a/qw/qwsv.c
+++ b/qw/qwsv.c
@@ -1,3 +1,109 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
+#include <thread.h>
+#include "quakedef.h"
+
+mainstacksize = 512*1024;
+Channel *fuckchan;
+quakeparms_t q;
+
+static cvar_t extrasleep = {"extrasleep", "0"}; /* in ms */
+static int iop = -1, pfd[2];
+
+
+/* FIXME: stupid-ass linking kludges */
+client_static_t cls;
+void Draw_BeginDisc(void){}
+void Draw_EndDisc(void){}
+void Host_Shutdown(void){}
+
+
+char *
+Sys_ConsoleInput(void)
+{
+ static char buf[256];
+
+ if(iop < 0)
+ return nil;
+ if(flen(pfd[1]) < 1) /* only poll for input */
+ return nil;
+ if(read(pfd[1], buf, sizeof buf) < 0)
+ sysfatal("Sys_ConsoleInput:read: %r");
+ return buf;
+}
+
+void
+killiop(void)
+{
+ threadkillgrp(THin);
+ close(pfd[0]);
+ close(pfd[1]);
+ iop = -1;
+}
+
+static void
+iproc(void *)
+{
+ int n;
+ char s[256];
+
+ threadsetgrp(THin);
+
+ if((iop = pipe(pfd)) < 0)
+ sysfatal("iproc:pipe: %r");
+ for(;;){
+ if((n = read(0, s, sizeof s)) <= 0)
+ break;
+ s[n-1] = 0;
+ if((write(pfd[0], s, n)) != n)
+ break;
+ if(nbsend(fuckchan, nil) < 0)
+ sysfatal("chan really wanted to, but it's just too tired. %r");
+ }
+ fprint(2, "iproc %d: %r\n", threadpid(threadid()));
+ iop = -1;
+}
+
+static void
+croak(void *, char *note)
+{
+ if(!strncmp(note, "sys:", 4)){
+ killiop();
+ NET_Shutdown();
+ }
+ noted(NDFLT);
+}
+
+void
+threadmain(int argc, char *argv[])
+{
+ double time, oldtime, newtime;
+
+ svonly = 1;
+ COM_InitArgv (argc, argv);
+ initparm(&q);
+ notify(croak);
+ if((fuckchan = chancreate(sizeof(int), 1)) == nil)
+ sysfatal("chancreate fuckchan: %r");
+ SV_Init(&q);
+ Cvar_RegisterVariable(&extrasleep);
+ if(proccreate(iproc, nil, 8192) < 0)
+ sysfatal("proccreate iproc: %r");
+
+ SV_Frame(0.1); /* run one frame immediately for first heartbeat */
+
+ oldtime = Sys_DoubleTime() - 0.1;
+ for(;;){
+ recv(fuckchan, nil); /* we just don't give any for free */
+
+ newtime = Sys_DoubleTime(); /* time since last docking */
+ time = newtime - oldtime;
+ oldtime = newtime;
+ SV_Frame(time);
+
+ /* just a way to screw up fucking conformation on purpose */
+ if(extrasleep.value)
+ sleep(extrasleep.value);
+ }
+}
--- a/qw/r_aclip.c
+++ b/qw/r_aclip.c
@@ -4,8 +4,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
-#include "d_local.h"
static finalvert_t fv[2][8];
static auxvert_t av[8];
@@ -76,8 +74,6 @@
}
-#if !id386
-
void R_Alias_clip_left (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out)
{
float scale;
@@ -168,8 +164,6 @@
out->v[i] = pfv1->v[i] + (pfv0->v[i] - pfv1->v[i])*scale + 0.5;
}
}
-
-#endif
int R_AliasClip (finalvert_t *in, finalvert_t *out, int flag, int count,
--- a/qw/r_alias.c
+++ b/qw/r_alias.c
@@ -4,9 +4,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
-#include "d_local.h" // FIXME: shouldn't be needed (is needed for patch
- // right now, but that should move)
#define LIGHT_MIN 5 // lowest light value we'll allow, to avoid the
// need for inner-loop light clamping
@@ -433,8 +430,6 @@
}
-#if !id386
-
/*
================
R_AliasTransformAndProjectFinalVerts
@@ -487,9 +482,7 @@
}
}
-#endif
-
/*
================
R_AliasProjectFinalVert
@@ -709,7 +702,7 @@
// cache align
pfinalverts = (finalvert_t *)
- (((long)&finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+ (((uintptr)&finalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
pauxverts = &auxverts[0];
paliashdr = (aliashdr_t *)Mod_Extradata (currententity->model);
@@ -727,15 +720,7 @@
r_recursiveaffinetriangles;
if (r_affinetridesc.drawtype)
- {
D_PolysetUpdateTables (); // FIXME: precalc...
- }
- else
- {
-#if id386
- D_Aff8Patch (currententity->colormap);
-#endif
- }
acolormap = currententity->colormap;
@@ -749,4 +734,3 @@
else
R_AliasPreparePoints ();
}
-
--- a/qw/r_bsp.c
+++ b/qw/r_bsp.c
@@ -2,7 +2,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
//
// current entity info
--- a/qw/r_draw.c
+++ b/qw/r_draw.c
@@ -2,8 +2,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
-#include "d_local.h" // FIXME: shouldn't need to include this
#define MAXLEFTCLIPEDGES 100
@@ -51,8 +49,6 @@
qboolean r_lastvertvalid;
-#if !id386
-
/*
================
R_EmitEdge
@@ -333,9 +329,7 @@
R_EmitEdge (pv0, pv1);
}
-#endif // !id386
-
/*
================
R_EmitCachedEdge
@@ -345,7 +339,7 @@
{
edge_t *pedge_t;
- pedge_t = (edge_t *)((unsigned long)r_edges + r_pedge->cachededgeoffset);
+ pedge_t = (edge_t *)((uintptr)r_edges + r_pedge->cachededgeoffset);
if (!pedge_t->surfs[0])
pedge_t->surfs[0] = surface_p - surfaces;
@@ -432,9 +426,9 @@
}
else
{
- if ((((unsigned long)edge_p - (unsigned long)r_edges) >
+ if ((((uintptr)edge_p - (uintptr)r_edges) >
r_pedge->cachededgeoffset) &&
- (((edge_t *)((unsigned long)r_edges +
+ (((edge_t *)((uintptr)r_edges +
r_pedge->cachededgeoffset))->owner == r_pedge))
{
R_EmitCachedEdge ();
@@ -478,9 +472,9 @@
{
// it's cached if the cached edge is valid and is owned
// by this medge_t
- if ((((unsigned long)edge_p - (unsigned long)r_edges) >
+ if ((((uintptr)edge_p - (uintptr)r_edges) >
r_pedge->cachededgeoffset) &&
- (((edge_t *)((unsigned long)r_edges +
+ (((edge_t *)((uintptr)r_edges +
r_pedge->cachededgeoffset))->owner == r_pedge))
{
R_EmitCachedEdge ();
@@ -886,4 +880,3 @@
}
}
}
-
--- a/qw/r_edge.c
+++ b/qw/r_edge.c
@@ -2,10 +2,8 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
-#if 0
-// FIXME
+/* FIXME
the complex cases add new polys on most lines, so dont optimize for keeping them the same
have multiple free span lists to try to get better coherence?
low depth complexity -- 1 to 3 or so
@@ -13,7 +11,7 @@
this breaks spans at every edge, even hidden ones (bad)
have a sentinal at both ends?
-#endif
+*/
edge_t *auxedges;
@@ -140,8 +138,6 @@
}
-#if !id386
-
/*
==============
R_InsertNewEdges
@@ -183,11 +179,7 @@
} while ((edgestoadd = next_edge) != NULL);
}
-#endif // !id386
-
-#if !id386
-
/*
==============
R_RemoveEdges
@@ -203,11 +195,7 @@
} while ((pedge = pedge->nextremove) != NULL);
}
-#endif // !id386
-
-#if !id386
-
/*
==============
R_StepActiveU
@@ -273,15 +261,13 @@
}
}
-#endif // !id386
-
/*
==============
R_CleanupSpan
==============
*/
-void R_CleanupSpan ()
+void R_CleanupSpan (void)
{
surf_t *surf;
int iu;
@@ -432,8 +418,6 @@
}
-#if !id386
-
/*
==============
R_LeadingEdge
@@ -598,9 +582,7 @@
R_CleanupSpan ();
}
-#endif // !id386
-
/*
==============
R_GenerateSpansBackward
@@ -650,7 +632,7 @@
surf_t *s;
basespan_p = (espan_t *)
- ((long)(basespans + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+ ((uintptr)(basespans + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
max_span_p = &basespan_p[MAXSPANS - r_refdef.vrect.width];
span_p = basespan_p;
@@ -748,5 +730,3 @@
else
D_DrawSurfaces ();
}
-
-
--- a/qw/r_efrag.c
+++ b/qw/r_efrag.c
@@ -2,7 +2,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
mnode_t *r_pefragtopnode;
--- a/qw/r_light.c
+++ b/qw/r_light.c
@@ -2,7 +2,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
int r_dlightframecount;
--- a/qw/r_local.h
+++ b/qw/r_local.h
@@ -1,9 +1,5 @@
// r_local.h -- private refresh defs
-#ifndef GLQUAKE
-
-#include "r_shared.h"
-
#define ALIAS_BASE_SIZE_RATIO (1.0 / 11.0)
// normalizing factor so player model works out to about
// 1 pixel per triangle
@@ -122,15 +118,6 @@
void R_DrawSurfaceBlock8 (void);
texture_t *R_TextureAnimation (texture_t *base);
-#if id386
-
-void R_DrawSurfaceBlock8_mip0 (void);
-void R_DrawSurfaceBlock8_mip1 (void);
-void R_DrawSurfaceBlock8_mip2 (void);
-void R_DrawSurfaceBlock8_mip3 (void);
-
-#endif
-
void R_GenSkyTile (void *pdest);
void R_GenSkyTile16 (void *pdest);
void R_Surf8Patch (void);
@@ -294,5 +281,3 @@
void R_ClipEdge (mvertex_t *pv0, mvertex_t *pv1, clipplane_t *clip);
void R_SplitEntityOnNode2 (mnode_t *node);
void R_MarkLights (dlight_t *light, int bit, mnode_t *node);
-
-#endif //GLQUAKE
\ No newline at end of file
--- a/qw/r_main.c
+++ b/qw/r_main.c
@@ -2,7 +2,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
//define PASSAGES
@@ -216,12 +215,6 @@
R_InitParticles ();
-// TODO: collect 386-specific code in one place
-#if id386
- Sys_MakeCodeWriteable ((long)R_EdgeCodeStart,
- (long)R_EdgeCodeEnd - (long)R_EdgeCodeStart);
-#endif // id386
-
D_Init ();
}
@@ -463,24 +456,6 @@
else
r_fov_greater_than_90 = true;
-// TODO: collect 386-specific code in one place
-#if id386
- if (r_pixbytes == 1)
- {
- Sys_MakeCodeWriteable ((long)R_Surf8Start,
- (long)R_Surf8End - (long)R_Surf8Start);
- colormap = vid.colormap;
- R_Surf8Patch ();
- }
- else
- {
- Sys_MakeCodeWriteable ((long)R_Surf16Start,
- (long)R_Surf16End - (long)R_Surf16Start);
- colormap = vid.colormap16;
- R_Surf16Patch ();
- }
-#endif // id386
-
D_ViewChanged ();
}
@@ -882,13 +857,13 @@
else
{
r_edges = (edge_t *)
- (((long)&ledges[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+ (((uintptr)&ledges[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
}
if (r_surfsonstack)
{
surfaces = (surf_t *)
- (((long)&lsurfs[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+ (((uintptr)&lsurfs[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
surf_max = &surfaces[r_cnumsurfs];
// surface 0 doesn't really exist; it's just a dummy because index 0
// is used to indicate no edge attached to surface
@@ -1059,10 +1034,10 @@
if ( Hunk_LowMark() & 3 )
Sys_Error ("Hunk is missaligned");
- if ( (long)(&dummy) & 3 )
+ if((uintptr)&dummy & 3)
Sys_Error ("Stack is missaligned");
- if ( (long)(&r_warpbuffer) & 3 )
+ if((uintptr)&r_warpbuffer & 3)
Sys_Error ("Globals are missaligned");
R_RenderView_ ();
--- a/qw/r_misc.c
+++ b/qw/r_misc.c
@@ -2,7 +2,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
/*
@@ -12,7 +11,7 @@
*/
void R_CheckVariables (void)
{
-#if 0
+/*
static float oldbright;
if (r_fullbright.value != oldbright)
@@ -20,7 +19,7 @@
oldbright = r_fullbright.value;
D_FlushCaches (); // so all lighting changes
}
-#endif
+*/
}
@@ -123,13 +122,13 @@
dest[0] = color;
// *(dest-vid.rowbytes) = 0x30;
}
-#if 0
+/*
for ( ; i<s ; i++, dest -= vid.rowbytes*2)
{
dest[0] = 0x30;
*(dest-vid.rowbytes) = 0x30;
}
-#endif
+*/
}
/*
@@ -146,13 +145,12 @@
{
static int timex;
int a;
- float r_time2;
static byte r_timings[MAX_TIMINGS];
int x;
- r_time2 = Sys_DoubleTime ();
+ //float r_time2 = Sys_DoubleTime ();
- a = (r_time2-r_time1)/0.01;
+// a = (r_time2-r_time1)/0.01;
//a = fabs(mouse_y * 0.05);
//a = (int)((r_refdef.vieworg[2] + 1024)/1)%(int)r_graphheight.value;
//a = (int)((pmove.velocity[2] + 500)/10);
@@ -192,7 +190,6 @@
void R_NetGraph (void)
{
int a, x, y, y2, w, i;
- frame_t *frame;
int lost;
char st[80];
@@ -350,8 +347,6 @@
}
-#if !id386
-
/*
================
TransformVector
@@ -364,9 +359,7 @@
out[2] = DotProduct(in,vpn);
}
-#endif
-
/*
================
R_TransformPlane
@@ -471,7 +464,7 @@
numbtofpolys = 0;
// debugging
-#if 0
+/*
r_refdef.vieworg[0]= 80;
r_refdef.vieworg[1]= 64;
r_refdef.vieworg[2]= 40;
@@ -478,7 +471,7 @@
r_refdef.viewangles[0]= 0;
r_refdef.viewangles[1]= 46.763641357;
r_refdef.viewangles[2]= 0;
-#endif
+*/
// build the transformation matrix for the given view angles
VectorCopy (r_refdef.vieworg, modelorg);
--- a/qw/r_part.c
+++ b/qw/r_part.c
@@ -2,7 +2,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
#define MAX_PARTICLES 2048 // default max # of particles at one
// time
@@ -436,31 +435,12 @@
float time1;
float dvel;
float frametime;
-#ifdef GLQUAKE
- unsigned char *at;
- unsigned char theAlpha;
- vec3_t up, right;
- float scale;
- qboolean alphaTestEnabled;
-
- GL_Bind(particletexture);
- alphaTestEnabled = glIsEnabled(GL_ALPHA_TEST);
-
- if (alphaTestEnabled)
- glDisable(GL_ALPHA_TEST);
- glEnable (GL_BLEND);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glBegin (GL_TRIANGLES);
- VectorScale (vup, 1.5, up);
- VectorScale (vright, 1.5, right);
-#else
D_StartParticles ();
VectorScale (vright, xscaleshrink, r_pright);
VectorScale (vup, yscaleshrink, r_pup);
VectorCopy (vpn, r_ppn);
-#endif
frametime = host_frametime;
time3 = frametime * 15;
@@ -497,35 +477,7 @@
break;
}
-#ifdef GLQUAKE
- // hack a scale up to keep particles from disapearing
- scale = (p->org[0] - r_origin[0])*vpn[0] + (p->org[1] - r_origin[1])*vpn[1]
- + (p->org[2] - r_origin[2])*vpn[2];
- if (scale < 20)
- scale = 1;
- else
- scale = 1 + scale * 0.004;
- at = (byte *)&d_8to24table[(int)p->color];
- if (p->type==pt_fire)
- theAlpha = 255*(6-p->ramp)/6;
-// theAlpha = 192;
-// else if (p->type==pt_explode || p->type==pt_explode2)
-// theAlpha = 255*(8-p->ramp)/8;
- else
- theAlpha = 255;
- glColor4ub (*at, *(at+1), *(at+2), theAlpha);
-// glColor3ubv (at);
-// glColor3ubv ((byte *)&d_8to24table[(int)p->color]);
- glTexCoord2f (0,0);
- glVertex3fv (p->org);
- glTexCoord2f (1,0);
- glVertex3f (p->org[0] + up[0]*scale, p->org[1] + up[1]*scale, p->org[2] + up[2]*scale);
- glTexCoord2f (0,1);
- glVertex3f (p->org[0] + right[0]*scale, p->org[1] + right[1]*scale, p->org[2] + right[2]*scale);
-
-#else
D_DrawParticle (p);
-#endif
p->org[0] += p->vel[0]*frametime;
p->org[1] += p->vel[1]*frametime;
@@ -585,14 +537,5 @@
}
}
-#ifdef GLQUAKE
- glEnd ();
- glDisable (GL_BLEND);
- if (alphaTestEnabled)
- glEnable(GL_ALPHA_TEST);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-#else
D_EndParticles ();
-#endif
}
-
--- a/qw/r_shared.h
+++ b/qw/r_shared.h
@@ -1,18 +1,13 @@
-#ifndef GLQUAKE
-// r_shared.h: general refresh-related stuff shared between the refresh and the
-// driver
+// r_shared.h: general refresh-related stuff shared between the refresh and the driver
// FIXME: clean up and move into d_iface.h
-#ifndef _R_SHARED_H_
-#define _R_SHARED_H_
-
#define MAXVERTS 16 // max points in a surface polygon
#define MAXWORKINGVERTS (MAXVERTS+4) // max points in an intermediate
// polygon (while processing)
// !!! if this is changed, it must be changed in d_ifacea.h too !!!
-#define MAXHEIGHT 1024
-#define MAXWIDTH 1280
+#define MAXHEIGHT 4096
+#define MAXWIDTH 4096
#define INFINITE_DISTANCE 0x10000 // distance that's always guaranteed to
// be farther away than anything in
@@ -114,8 +109,7 @@
#define ALIAS_BOTTOM_CLIP 0x0008
#define ALIAS_Z_CLIP 0x0010
// !!! if this is changed, it must be changed in d_ifacea.h too !!!
-#define ALIAS_ONSEAM 0x0020 // also defined in modelgen.h;
- // must be kept in sync
+#define ALIAS_ONSEAM 0x0020
#define ALIAS_XY_CLIP_MASK 0x000F
// !!! if this is changed, it must be changed in asm_draw.h too !!!
@@ -129,7 +123,3 @@
float nearzi;
medge_t *owner;
} edge_t;
-
-#endif // _R_SHARED_H_
-
-#endif // GLQUAKE
--- a/qw/r_sky.c
+++ b/qw/r_sky.c
@@ -2,10 +2,7 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
-#include "d_local.h"
-
int iskyspeed = 8;
int iskyspeed2 = 2;
float skyspeed, skyspeed2;
@@ -100,35 +97,29 @@
baseofs = ((y+yshift) & SKYMASK) * 131;
// FIXME: clean this up
-#ifdef UNALIGNED_OK
+ if(UNALIGNED_OK){
+ for (x=0 ; x<SKYSIZE ; x += 4)
+ {
+ ofs = baseofs + ((x+xshift) & SKYMASK);
- for (x=0 ; x<SKYSIZE ; x += 4)
- {
- ofs = baseofs + ((x+xshift) & SKYMASK);
+ // PORT: unaligned dword access to bottommask and bottomsky
- // PORT: unaligned dword access to bottommask and bottomsky
-
- *pnewsky = (*(pnewsky + (128 / sizeof (unsigned))) &
+ *pnewsky = (*(pnewsky + (128 / sizeof (unsigned))) &
*(unsigned *)&bottommask[ofs]) |
*(unsigned *)&bottomsky[ofs];
- pnewsky++;
- }
+ pnewsky++;
+ }
+ }else{
+ for (x=0 ; x<SKYSIZE ; x++)
+ {
+ ofs = baseofs + ((x+xshift) & SKYMASK);
-#endif
-#ifndef UNALIGNED_OK
-
- for (x=0 ; x<SKYSIZE ; x++)
- {
- ofs = baseofs + ((x+xshift) & SKYMASK);
-
- *(byte *)pnewsky = (*((byte *)pnewsky + 128) &
+ *(byte *)pnewsky = (*((byte *)pnewsky + 128) &
*(byte *)&bottommask[ofs]) |
*(byte *)&bottomsky[ofs];
- pnewsky = (unsigned *)((byte *)pnewsky + 1);
+ pnewsky = (unsigned *)((byte *)pnewsky + 1);
+ }
}
-
-#endif
-
pnewsky += 128 / sizeof (unsigned);
}
@@ -160,37 +151,31 @@
baseofs = ((y+yshift) & SKYMASK) * 131;
// FIXME: clean this up
-#ifdef UNALIGNED_OK
+ if(UNALIGNED_OK){
+ for (x=0 ; x<SKYSIZE ; x += 4)
+ {
+ ofs = baseofs + ((x+xshift) & SKYMASK);
- for (x=0 ; x<SKYSIZE ; x += 4)
- {
- ofs = baseofs + ((x+xshift) & SKYMASK);
+ // PORT: unaligned dword access to bottommask and bottomsky
- // PORT: unaligned dword access to bottommask and bottomsky
-
- *pd = (*(pnewsky + (128 / sizeof (unsigned))) &
+ *pd = (*(pnewsky + (128 / sizeof (unsigned))) &
*(unsigned *)&bottommask[ofs]) |
*(unsigned *)&bottomsky[ofs];
- pnewsky++;
- pd++;
- }
+ pnewsky++;
+ pd++;
+ }
+ }else{
+ for (x=0 ; x<SKYSIZE ; x++)
+ {
+ ofs = baseofs + ((x+xshift) & SKYMASK);
-#endif
-#ifndef UNALIGNED_OK
-
- for (x=0 ; x<SKYSIZE ; x++)
- {
- ofs = baseofs + ((x+xshift) & SKYMASK);
-
- *(byte *)pd = (*((byte *)pnewsky + 128) &
+ *(byte *)pd = (*((byte *)pnewsky + 128) &
*(byte *)&bottommask[ofs]) |
*(byte *)&bottomsky[ofs];
- pnewsky = (unsigned *)((byte *)pnewsky + 1);
- pd = (unsigned *)((byte *)pd + 1);
+ pnewsky = (unsigned *)((byte *)pnewsky + 1);
+ pd = (unsigned *)((byte *)pd + 1);
+ }
}
-
-#endif
-
pnewsky += 128 / sizeof (unsigned);
}
}
--- a/qw/r_sprite.c
+++ b/qw/r_sprite.c
@@ -2,7 +2,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
static int clip_current;
static vec5_t clip_verts[2][MAXWORKINGVERTS];
@@ -69,7 +68,7 @@
// handle wraparound case
dists[nump] = dists[0];
- Q_memcpy (instep, in, sizeof (vec5_t));
+ memcpy (instep, in, sizeof (vec5_t));
// clip the winding
@@ -80,7 +79,7 @@
{
if (dists[i] >= 0)
{
- Q_memcpy (outstep, instep, sizeof (vec5_t));
+ memcpy (outstep, instep, sizeof (vec5_t));
outstep += sizeof (vec5_t) / sizeof (float);
outcount++;
}
@@ -115,7 +114,7 @@
R_SetupAndDrawSprite
================
*/
-void R_SetupAndDrawSprite ()
+void R_SetupAndDrawSprite (void)
{
int i, nump;
float dot, scale, *pv;
@@ -200,7 +199,7 @@
scale = yscale * pout->zi;
pout->v = (ycenter - scale * transformed[1]);
- pv += sizeof (vec5_t) / sizeof (pv);
+ pv += sizeof (vec5_t) / sizeof (*pv);
}
// draw it
@@ -380,4 +379,3 @@
R_SetupAndDrawSprite ();
}
-
--- a/qw/r_surf.c
+++ b/qw/r_surf.c
@@ -4,7 +4,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
drawsurf_t r_drawsurf;
@@ -300,7 +299,6 @@
//=============================================================================
-#if !id386
/*
================
@@ -543,13 +541,11 @@
pbasesource += sourcetstep;
lightright += lightrightstep;
lightleft += lightleftstep;
- prowdest = (unsigned short *)((long)prowdest + surfrowbytes);
+ prowdest = (ushort *)((uintptr)prowdest + surfrowbytes);
}
prowdestbase = prowdest;
}
-
-#endif
//============================================================================
--- a/qw/r_vars.c
+++ b/qw/r_vars.c
@@ -3,7 +3,7 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "quakedef.h"
+#include "quakedef.h"
// all global and static refresh variables are collected in a contiguous block
// to avoid cache conflicts.
--- a/qw/sbar.c
+++ b/qw/sbar.c
@@ -5,7 +5,6 @@
#include <stdio.h>
#include "quakedef.h"
-
int sb_updates; // if >= vid.numpages, no update needed
#define STAT_MINUS 10 // num frame for '-' stats digit
@@ -813,26 +812,6 @@
else if (sb_showteamscores)
Sbar_TeamOverlay();
-#ifdef GLQUAKE
- if (sb_showscores || sb_showteamscores ||
- cl.stats[STAT_HEALTH] <= 0)
- sb_updates = 0;
- // clear unused areas in gl
-#if 0
- {
- int x = (vid.width - 320)>>1;
-
- // left
- if (x > 0) {
- Draw_TileClear (0, vid.height - sb_lines, x, sb_lines);
- Draw_TileClear (x+320, vid.height - sb_lines, vid.width - x+320, sb_lines);
- }
- }
-#endif
- if (vid.width > 320 && !headsup)
- Draw_TileClear (320, vid.height - sb_lines, vid.width - 320, sb_lines);
-#endif
-
if (sb_lines > 0)
Sbar_MiniDeathmatchOverlay ();
}
@@ -882,7 +861,7 @@
void Sbar_TeamOverlay (void)
{
qpic_t *pic;
- int i, k, l;
+ int i, k;
int x, y;
char num[12];
int teamplay;
@@ -916,7 +895,7 @@
Sbar_SortTeams();
// draw the text
- l = scoreboardlines;
+ //l = scoreboardlines;
for (i=0 ; i < scoreboardteams && y <= vid.height-10 ; i++)
{
--- a/qw/screen.c
+++ b/qw/screen.c
@@ -4,7 +4,6 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
/*
@@ -155,7 +154,7 @@
y = 48;
scr_copytop = 1;
- Draw_TileClear (0, y, vid.width, min(8*scr_erase_lines, vid.height - y - 1));
+ Draw_TileClear (0, y, vid.width, Min(8*scr_erase_lines, vid.height - y - 1));
}
void SCR_DrawCenterString (void)
@@ -593,11 +592,11 @@
pcx->ymax = LittleShort((short)(height-1));
pcx->hres = LittleShort((short)width);
pcx->vres = LittleShort((short)height);
- Q_memset (pcx->palette,0,sizeof(pcx->palette));
+ memset(pcx->palette, 0, sizeof(pcx->palette));
pcx->color_planes = 1; // chunky image
pcx->bytes_per_line = LittleShort((short)width);
pcx->palette_type = LittleShort(2); // not a grey scale
- Q_memset (pcx->filler,0,sizeof(pcx->filler));
+ memset(pcx->filler, 0, sizeof(pcx->filler));
// pack the image
pack = &pcx->data;
@@ -683,9 +682,8 @@
*/
int MipColor(int r, int g, int b)
{
- int i;
+ int i, best = 0;
float dist;
- int best;
float bestdist;
int r1, g1, b1;
static int lr = -1, lg = -1, lb = -1;
@@ -762,12 +760,10 @@
*/
void SCR_RSShot_f (void)
{
- int i, x, y;
+ int x, y;
unsigned char *src, *dest;
- char pcxname[80];
- char checkname[MAX_OSPATH];
- unsigned char *newbuf, *srcbuf;
- int srcrowbytes;
+ char pcxname[80];
+ unsigned char *newbuf;
int w, h;
int dx, dy, dex, dey, nx;
int r, b, g;
@@ -774,7 +770,6 @@
int count;
float fracw, frach;
char st[80];
- time_t now;
if (CL_IsUploading())
return; // already one pending
@@ -791,7 +786,7 @@
Con_Printf("Remote screen shot requested.\n");
-#if 0
+/*
//
// find a file name to save it to
//
@@ -810,7 +805,7 @@
Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX");
return;
}
-#endif
+*/
//
// save the pcx file
@@ -857,8 +852,7 @@
}
}
- time(&now);
- strcpy(st, ctime(&now));
+ strcpy(st, ctime(time(nil)));
st[strlen(st) - 1] = 0;
SCR_DrawStringToSnap (st, newbuf, w - strlen(st)*8, 0, w);
@@ -996,15 +990,6 @@
if (scr_disabled_for_loading)
return;
-
-#ifdef _WIN32
- { // don't suck up any cpu if minimized
- extern int Minimized;
-
- if (Minimized)
- return;
- }
-#endif
scr_copytop = 0;
scr_copyeverything = 0;
--- a/qw/server.h
+++ b/qw/server.h
@@ -72,14 +72,13 @@
#define NUM_SPAWN_PARMS 16
-typedef enum
-{
+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_spawned // client is fully in game
-} client_state_t;
+}State;
typedef struct
{
@@ -95,7 +94,7 @@
typedef struct client_s
{
- client_state_t state;
+ State state;
int spectator; // non-interactive
@@ -271,14 +270,6 @@
#define FL_PARTIALGROUND 1024 // not all corners are valid
#define FL_WATERJUMP 2048 // player jumping out of water
-// entity effects
-
-//define EF_BRIGHTFIELD 1
-//define EF_MUZZLEFLASH 2
-#define EF_BRIGHTLIGHT 4
-#define EF_DIMLIGHT 8
-
-
#define SPAWNFLAG_NOT_EASY 256
#define SPAWNFLAG_NOT_MEDIUM 512
#define SPAWNFLAG_NOT_HARD 1024
@@ -294,6 +285,8 @@
//============================================================================
+extern cvar_t sv_highchars;
+
extern cvar_t sv_mintic, sv_maxtic;
extern cvar_t sv_maxspeed;
@@ -332,6 +325,7 @@
int SV_CalcPing (client_t *cl);
void SV_FullClientUpdate (client_t *client, sizebuf_t *buf);
+void SV_FullClientUpdateToClient (client_t *, client_t *);
int SV_ModelIndex (char *name);
@@ -352,7 +346,6 @@
void SV_SendServerinfo (client_t *client);
void SV_ExtractFromUserinfo (client_t *cl);
-
void Master_Heartbeat (void);
void Master_Packet (void);
@@ -433,3 +426,5 @@
void ClientReliableWrite_String(client_t *cl, char *s);
void ClientReliableWrite_SZ(client_t *cl, void *data, int len);
+qboolean ServerPaused(void);
+void SV_SendServerInfoChange(char *key, char *value);
--- a/qw/skin.c
+++ b/qw/skin.c
@@ -231,9 +231,6 @@
if (!sc->name[0])
continue;
Skin_Cache (sc->skin);
-#ifdef GLQUAKE
- sc->skin = NULL;
-#endif
}
if (cls.state != ca_active)
--- a/qw/snd.c
+++ b/qw/snd.c
@@ -1,243 +1,113 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
+#include <thread.h>
#include "quakedef.h"
-int audio_fd;
-int snd_inited;
+static int afd, sndon;
+static uint wpos;
+enum{
+ Nbuf = 16
+};
+static Channel *schan;
+static QLock sndlock;
-static int tryrates[] = { 11025, 22051, 44100, 8000 };
-qboolean SNDDMA_Init(void)
+static void
+sproc(void *)
{
+ int n;
- int rc;
- int fmt;
- int tmp;
- int i;
- char *s;
- struct audio_buf_info info;
- int caps;
+ threadsetgrp(THsnd);
- snd_inited = 0;
-
-// open /dev/dsp, confirm capability to mmap, and get size of dma buffer
-
- audio_fd = open("/dev/dsp", O_RDWR);
- if (audio_fd < 0)
- {
- perror("/dev/dsp");
- Con_Printf("Could not open /dev/dsp\n");
- return 0;
+ for(;;){
+ if(recv(schan, nil) < 0)
+ break;
+ if((n = write(afd, shm->buffer, shm->samplebits/8 * shm->samples)) < 0)
+ break;
+ qlock(&sndlock);
+ wpos += n;
+ qunlock(&sndlock);
}
+ fprint(2, "sproc %d: %r\n", threadpid(threadid()));
+}
- rc = ioctl(audio_fd, SNDCTL_DSP_RESET, 0);
- if (rc < 0)
- {
- perror("/dev/dsp");
- Con_Printf("Could not reset /dev/dsp\n");
- close(audio_fd);
- return 0;
- }
+qboolean
+SNDDMA_Init(void)
+{
+ int i;
- if (ioctl(audio_fd, SNDCTL_DSP_GETCAPS, &caps)==-1)
- {
- perror("/dev/dsp");
- Con_Printf("Sound driver too old\n");
- close(audio_fd);
- return 0;
- }
+ sndon = 0;
- if (!(caps & DSP_CAP_TRIGGER) || !(caps & DSP_CAP_MMAP))
- {
- Con_Printf("Sorry but your soundcard can't do this\n");
- close(audio_fd);
+ if((afd = open("/dev/audio", OWRITE)) < 0){
+ fprint(2, "open: %r\n");
return 0;
}
- if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info)==-1)
- {
- perror("GETOSPACE");
- Con_Printf("Um, can't do GETOSPACE?\n");
- close(audio_fd);
- return 0;
- }
-
shm = &sn;
- shm->splitbuffer = 0;
+ shm->splitbuffer = 0;
-// set sample bits & speed
-
- s = getenv("QUAKE_SOUND_SAMPLEBITS");
- if (s) shm->samplebits = atoi(s);
- else if ((i = COM_CheckParm("-sndbits")) != 0)
+ if((i = COM_CheckParm("-sndbits")) != 0)
shm->samplebits = atoi(com_argv[i+1]);
- if (shm->samplebits != 16 && shm->samplebits != 8)
- {
- ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &fmt);
- if (fmt & AFMT_S16_LE) shm->samplebits = 16;
- else if (fmt & AFMT_U8) shm->samplebits = 8;
- }
+ if(shm->samplebits != 16 && shm->samplebits != 8)
+ shm->samplebits = 16;
- s = getenv("QUAKE_SOUND_SPEED");
- if (s) shm->speed = atoi(s);
- else if ((i = COM_CheckParm("-sndspeed")) != 0)
+ if((i = COM_CheckParm("-sndspeed")) != 0)
shm->speed = atoi(com_argv[i+1]);
- else
- {
- for (i=0 ; i<sizeof(tryrates)/4 ; i++)
- if (!ioctl(audio_fd, SNDCTL_DSP_SPEED, &tryrates[i])) break;
- shm->speed = tryrates[i];
- }
+ else
+ shm->speed = 44100;
- s = getenv("QUAKE_SOUND_CHANNELS");
- if (s) shm->channels = atoi(s);
- else if ((i = COM_CheckParm("-sndmono")) != 0)
+ shm->channels = 2;
+ if(COM_CheckParm("-sndmono") != 0)
shm->channels = 1;
- else if ((i = COM_CheckParm("-sndstereo")) != 0)
- shm->channels = 2;
- else shm->channels = 2;
- shm->samples = info.fragstotal * info.fragsize / (shm->samplebits/8);
+ shm->samples = 4096;
shm->submission_chunk = 1;
-// memory map the dma buffer
-
- shm->buffer = (unsigned char *) mmap(NULL, info.fragstotal
- * info.fragsize, PROT_WRITE, MAP_FILE|MAP_SHARED, audio_fd, 0);
- if (!shm->buffer)
- {
- perror("/dev/dsp");
- Con_Printf("Could not mmap /dev/dsp\n");
- close(audio_fd);
- return 0;
- }
-
- tmp = 0;
- if (shm->channels == 2)
- tmp = 1;
- rc = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp);
- if (rc < 0)
- {
- perror("/dev/dsp");
- Con_Printf("Could not set /dev/dsp to stereo=%d", shm->channels);
- close(audio_fd);
- return 0;
- }
- if (tmp)
- shm->channels = 2;
- else
- shm->channels = 1;
-
- rc = ioctl(audio_fd, SNDCTL_DSP_SPEED, &shm->speed);
- if (rc < 0)
- {
- perror("/dev/dsp");
- Con_Printf("Could not set /dev/dsp speed to %d", shm->speed);
- close(audio_fd);
- return 0;
- }
-
- if (shm->samplebits == 16)
- {
- rc = AFMT_S16_LE;
- rc = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &rc);
- if (rc < 0)
- {
- perror("/dev/dsp");
- Con_Printf("Could not support 16-bit data. Try 8-bit.\n");
- close(audio_fd);
- return 0;
- }
- }
- else if (shm->samplebits == 8)
- {
- rc = AFMT_U8;
- rc = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &rc);
- if (rc < 0)
- {
- perror("/dev/dsp");
- Con_Printf("Could not support 8-bit data.\n");
- close(audio_fd);
- return 0;
- }
- }
- else
- {
- perror("/dev/dsp");
- Con_Printf("%d-bit sound not supported.", shm->samplebits);
- close(audio_fd);
- return 0;
- }
-
-// toggle the trigger & start her up
-
- tmp = 0;
- rc = ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
- if (rc < 0)
- {
- perror("/dev/dsp");
- Con_Printf("Could not toggle.\n");
- close(audio_fd);
- return 0;
- }
- tmp = PCM_ENABLE_OUTPUT;
- rc = ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp);
- if (rc < 0)
- {
- perror("/dev/dsp");
- Con_Printf("Could not toggle.\n");
- close(audio_fd);
- return 0;
- }
-
+ if((shm->buffer = mallocz(shm->samplebits/8 * shm->samples, 1)) == nil)
+ sysfatal("SNDDMA_Init:mallocz: %r\n");
shm->samplepos = 0;
-
- snd_inited = 1;
+ sndon = 1;
+ wpos = 0;
+ if((schan = chancreate(sizeof(int), Nbuf)) == nil)
+ sysfatal("SNDDMA_Init:chancreate: %r");
+ if(proccreate(sproc, nil, 8192) < 0)
+ sysfatal("SNDDMA_Init:proccreate: %r");
return 1;
-
}
-int SNDDMA_GetDMAPos(void)
+int
+SNDDMA_GetDMAPos(void)
{
-
- struct count_info count;
-
- if (!snd_inited) return 0;
-
- if (ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &count)==-1)
- {
- perror("/dev/dsp");
- Con_Printf("Uh, sound dead.\n");
- close(audio_fd);
- snd_inited = 0;
+ if(!sndon)
return 0;
- }
-// shm->samplepos = (count.bytes / (shm->samplebits / 8)) & (shm->samples-1);
-// fprintf(stderr, "%d \r", count.ptr);
- shm->samplepos = count.ptr / (shm->samplebits / 8);
-
+ qlock(&sndlock);
+ shm->samplepos = wpos / (shm->samplebits/8);
+ qunlock(&sndlock);
return shm->samplepos;
-
}
-void SNDDMA_Shutdown(void)
+void
+SNDDMA_Shutdown(void)
{
- if (snd_inited)
- {
- close(audio_fd);
- snd_inited = 0;
+ if(!sndon)
+ return;
+
+ threadkillgrp(THsnd);
+ close(afd);
+ free(shm->buffer);
+ if(schan != nil){
+ chanfree(schan);
+ schan = nil;
}
+ sndon = 0;
}
-/*
-==============
-SNDDMA_Submit
-
-Send sound to device if buffer isn't really the dma buffer
-===============
-*/
-void SNDDMA_Submit(void)
+void
+SNDDMA_Submit(void)
{
+ if(nbsend(schan, nil) < 0){
+ fprint(2, "SNDDMA_Submit:nbsend: %r\n");
+ SNDDMA_Shutdown();
+ }
}
-
--- a/qw/snd_dma.c
+++ b/qw/snd_dma.c
@@ -5,13 +5,10 @@
#include <stdio.h>
#include "quakedef.h"
-#ifdef _WIN32
-#endif
-
void S_Play(void);
void S_PlayVol(void);
void S_SoundList(void);
-void S_Update_();
+void S_Update_(void);
void S_StopAllSounds(qboolean clear);
void S_StopAllSoundsC(void);
@@ -133,9 +130,7 @@
if (!rc)
{
-#ifndef _WIN32
Con_Printf("S_Startup: SNDDMA_Init failed.\n");
-#endif
sound_started = 0;
return;
}
@@ -234,19 +229,16 @@
void S_Shutdown(void)
{
- if (!sound_started)
+ if(!sound_started)
return;
- if (shm)
+ if(shm != nil)
shm->gamealive = 0;
+ if(!fakedma)
+ SNDDMA_Shutdown();
shm = 0;
sound_started = 0;
-
- if (!fakedma)
- {
- SNDDMA_Shutdown();
- }
}
@@ -265,18 +257,16 @@
int i;
sfx_t *sfx;
- if (!name)
+ if(name == nil)
Sys_Error ("S_FindName: NULL\n");
- if (Q_strlen(name) >= MAX_QPATH)
+ if(strlen(name) >= MAX_QPATH)
Sys_Error ("Sound name too long: %s", name);
// see if already loaded
for (i=0 ; i < num_sfx ; i++)
- if (!Q_strcmp(known_sfx[i].name, name))
- {
+ if(!strcmp(known_sfx[i].name, name))
return &known_sfx[i];
- }
if (num_sfx == MAX_SFX)
Sys_Error ("S_FindName: out of sfx_t");
@@ -387,7 +377,6 @@
vec_t dist;
vec_t lscale, rscale, scale;
vec3_t source_vec;
- sfx_t *snd;
// anything coming from the view entity will allways be full volume
if (ch->entnum == cl.viewentity)
@@ -399,7 +388,6 @@
// calculate stereo seperation and distance attenuation
- snd = ch->sfx;
VectorSubtract(ch->origin, listener_origin, source_vec);
dist = VectorNormalize(source_vec) * ch->dist_mult;
@@ -531,7 +519,7 @@
if (channels[i].sfx)
channels[i].sfx = NULL;
- Q_memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
+ memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
if (clear)
S_ClearBuffer ();
@@ -546,11 +534,7 @@
{
int clear;
-#ifdef _WIN32
- if (!sound_started || !shm || (!shm->buffer && !pDSBuf))
-#else
if (!sound_started || !shm || !shm->buffer)
-#endif
return;
if (shm->samplebits == 8)
@@ -558,43 +542,7 @@
else
clear = 0;
-#ifdef _WIN32
- if (pDSBuf)
- {
- DWORD dwSize;
- DWORD *pData;
- int reps;
- HRESULT hresult;
-
- reps = 0;
-
- while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, &pData, &dwSize, NULL, NULL, 0)) != DS_OK)
- {
- if (hresult != DSERR_BUFFERLOST)
- {
- Con_Printf ("S_ClearBuffer: DS::Lock Sound Buffer Failed\n");
- S_Shutdown ();
- return;
- }
-
- if (++reps > 10000)
- {
- Con_Printf ("S_ClearBuffer: DS: couldn't restore buffer\n");
- S_Shutdown ();
- return;
- }
- }
-
- Q_memset(pData, clear, shm->samples * shm->samplebits/8);
-
- pDSBuf->lpVtbl->Unlock(pDSBuf, pData, dwSize, NULL, 0);
-
- }
- else
-#endif
- {
- Q_memset(shm->buffer, clear, shm->samples * shm->samplebits/8);
- }
+ memset(shm->buffer, clear, shm->samples * shm->samplebits/8);
}
@@ -824,11 +772,6 @@
void S_ExtraUpdate (void)
{
-
-#ifdef _WIN32
- IN_Accumulate ();
-#endif
-
if (snd_noextraupdate.value)
return; // don't pollute timings
S_Update_();
@@ -860,25 +803,6 @@
if (endtime - soundtime > samps)
endtime = soundtime + samps;
-#ifdef _WIN32
-// if the buffer was lost or stopped, restore it and/or restart it
- {
- DWORD dwStatus;
-
- if (pDSBuf)
- {
- if (pDSBuf->lpVtbl->GetStatus (pDSBuf, &dwStatus) != DD_OK)
- Con_Printf ("Couldn't get sound buffer status\n");
-
- if (dwStatus & DSBSTATUS_BUFFERLOST)
- pDSBuf->lpVtbl->Restore (pDSBuf);
-
- if (!(dwStatus & DSBSTATUS_PLAYING))
- pDSBuf->lpVtbl->Play(pDSBuf, 0, 0, DSBPLAY_LOOPING);
- }
- }
-#endif
-
S_PaintChannels (endtime);
SNDDMA_Submit ();
@@ -902,13 +826,13 @@
i = 1;
while (i<Cmd_Argc())
{
- if (!Q_strrchr(Cmd_Argv(i), '.'))
+ if(strrchr(Cmd_Argv(i), '.') == nil)
{
- Q_strcpy(name, Cmd_Argv(i));
- Q_strcat(name, ".wav");
+ strcpy(name, Cmd_Argv(i));
+ strcat(name, ".wav");
}
else
- Q_strcpy(name, Cmd_Argv(i));
+ strcpy(name, Cmd_Argv(i));
sfx = S_PrecacheSound(name);
S_StartSound(hash++, 0, sfx, listener_origin, 1.0, 1.0);
i++;
@@ -926,13 +850,13 @@
i = 1;
while (i<Cmd_Argc())
{
- if (!Q_strrchr(Cmd_Argv(i), '.'))
+ if(strrchr(Cmd_Argv(i), '.') == nil)
{
- Q_strcpy(name, Cmd_Argv(i));
- Q_strcat(name, ".wav");
+ strcpy(name, Cmd_Argv(i));
+ strcat(name, ".wav");
}
else
- Q_strcpy(name, Cmd_Argv(i));
+ strcpy(name, Cmd_Argv(i));
sfx = S_PrecacheSound(name);
vol = Q_atof(Cmd_Argv(i+1));
S_StartSound(hash++, 0, sfx, listener_origin, vol, 1.0);
--- a/qw/snd_mem.c
+++ b/qw/snd_mem.c
@@ -93,10 +93,10 @@
if (sc)
return sc;
-//Con_Printf ("S_LoadSound: %x\n", (int)stackbuf);
-// load it in
- Q_strcpy(namebuffer, "sound/");
- Q_strcat(namebuffer, s->name);
+// Con_Printf ("S_LoadSound: %x\n", (int)stackbuf);
+ // load it in
+ strcpy(namebuffer, "sound/");
+ strcat(namebuffer, s->name);
// Con_Printf ("loading %s\n",namebuffer);
@@ -155,7 +155,7 @@
short GetLittleShort(void)
{
- short val = 0;
+ short val;
val = *data_p;
val = val + (*(data_p+1)<<8);
data_p += 2;
@@ -164,7 +164,7 @@
int GetLittleLong(void)
{
- int val = 0;
+ int val;
val = *data_p;
val = val + (*(data_p+1)<<8);
val = val + (*(data_p+2)<<16);
@@ -196,7 +196,7 @@
// Sys_Error ("FindNextChunk: %i length is past the 1 meg sanity limit", iff_chunk_len);
data_p -= 8;
last_chunk = data_p + 8 + ( (iff_chunk_len + 1) & ~1 );
- if (!Q_strncmp(data_p, name, 4))
+ if (!strncmp((char *)data_p, name, 4))
return;
}
}
@@ -208,7 +208,7 @@
}
-#if 0
+/*
void DumpChunks(void)
{
char str[5];
@@ -224,7 +224,7 @@
data_p += (iff_chunk_len + 1) & ~1;
} while (data_p < iff_end);
}
-#endif
+*/
/*
============
@@ -248,7 +248,7 @@
// find "RIFF" chunk
FindChunk("RIFF");
- if (!(data_p && !Q_strncmp(data_p+8, "WAVE", 4)))
+ if (!(data_p != nil && !strncmp((char *)data_p+8, "WAVE", 4)))
{
Con_Printf("Missing RIFF/WAVE chunks\n");
return info;
@@ -289,7 +289,7 @@
FindNextChunk ("LIST");
if (data_p)
{
- if (!strncmp (data_p + 28, "mark", 4))
+ if(!strncmp((char *)data_p+28, "mark", 4))
{ // this is not a proper parse, but it works with cooledit...
data_p += 24;
i = GetLittleLong (); // samples in loop
--- a/qw/snd_mix.c
+++ b/qw/snd_mix.c
@@ -5,10 +5,7 @@
#include <stdio.h>
#include "quakedef.h"
-#ifdef _WIN32
-#else
#define DWORD unsigned long
-#endif
#define PAINTBUFFER_SIZE 512
portable_samplepair_t paintbuffer[PAINTBUFFER_SIZE];
@@ -18,7 +15,6 @@
void Snd_WriteLinearBlastStereo16 (void);
-#if !id386
void Snd_WriteLinearBlastStereo16 (void)
{
int i;
@@ -43,7 +39,6 @@
snd_out[i+1] = val;
}
}
-#endif
void S_TransferStereo16 (int endtime)
{
@@ -50,12 +45,6 @@
int lpos;
int lpaintedtime;
DWORD *pbuf;
-#ifdef _WIN32
- int reps;
- DWORD dwSize,dwSize2;
- DWORD *pbuf2;
- HRESULT hresult;
-#endif
snd_vol = volume.value*256;
@@ -62,37 +51,8 @@
snd_p = (int *) paintbuffer;
lpaintedtime = paintedtime;
-#ifdef _WIN32
- if (pDSBuf)
- {
- reps = 0;
+ pbuf = (DWORD *)shm->buffer;
- while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, &pbuf, &dwSize,
- &pbuf2, &dwSize2, 0)) != DS_OK)
- {
- if (hresult != DSERR_BUFFERLOST)
- {
- Con_Printf ("S_TransferStereo16: DS::Lock Sound Buffer Failed\n");
- S_Shutdown ();
- S_Startup ();
- return;
- }
-
- if (++reps > 10000)
- {
- Con_Printf ("S_TransferStereo16: DS: couldn't restore buffer\n");
- S_Shutdown ();
- S_Startup ();
- return;
- }
- }
- }
- else
-#endif
- {
- pbuf = (DWORD *)shm->buffer;
- }
-
while (lpaintedtime < endtime)
{
// handle recirculating buffer issues
@@ -112,11 +72,6 @@
snd_p += snd_linear_count;
lpaintedtime += (snd_linear_count>>1);
}
-
-#ifdef _WIN32
- if (pDSBuf)
- pDSBuf->lpVtbl->Unlock(pDSBuf, pbuf, dwSize, NULL, 0);
-#endif
}
void S_TransferPaintBuffer(int endtime)
@@ -129,12 +84,6 @@
int val;
int snd_vol;
DWORD *pbuf;
-#ifdef _WIN32
- int reps;
- DWORD dwSize,dwSize2;
- DWORD *pbuf2;
- HRESULT hresult;
-#endif
if (shm->samplebits == 16 && shm->channels == 2)
{
@@ -149,37 +98,8 @@
step = 3 - shm->channels;
snd_vol = volume.value*256;
-#ifdef _WIN32
- if (pDSBuf)
- {
- reps = 0;
+ pbuf = (DWORD *)shm->buffer;
- while ((hresult = pDSBuf->lpVtbl->Lock(pDSBuf, 0, gSndBufSize, &pbuf, &dwSize,
- &pbuf2,&dwSize2, 0)) != DS_OK)
- {
- if (hresult != DSERR_BUFFERLOST)
- {
- Con_Printf ("S_TransferPaintBuffer: DS::Lock Sound Buffer Failed\n");
- S_Shutdown ();
- S_Startup ();
- return;
- }
-
- if (++reps > 10000)
- {
- Con_Printf ("S_TransferPaintBuffer: DS: couldn't restore buffer\n");
- S_Shutdown ();
- S_Startup ();
- return;
- }
- }
- }
- else
-#endif
- {
- pbuf = (DWORD *)shm->buffer;
- }
-
if (shm->samplebits == 16)
{
short *out = (short *) pbuf;
@@ -210,23 +130,6 @@
out_idx = (out_idx + 1) & out_mask;
}
}
-
-#ifdef _WIN32
- if (pDSBuf) {
- DWORD dwNewpos, dwWrite;
- int il = paintedtime;
- int ir = endtime - paintedtime;
-
- ir += il;
-
- pDSBuf->lpVtbl->Unlock(pDSBuf, pbuf, dwSize, NULL, 0);
-
- pDSBuf->lpVtbl->GetCurrentPosition(pDSBuf, &dwNewpos, &dwWrite);
-
-// if ((dwNewpos >= il) && (dwNewpos <= ir))
-// Con_Printf("%d-%d p %d c\n", il, ir, dwNewpos);
- }
-#endif
}
@@ -257,7 +160,7 @@
end = paintedtime + PAINTBUFFER_SIZE;
// clear the paint buffer
- Q_memset(paintbuffer, 0, (end - paintedtime) * sizeof(portable_samplepair_t));
+ memset(paintbuffer, 0, (end - paintedtime) * sizeof(portable_samplepair_t));
// paint in the channels.
ch = channels;
@@ -324,8 +227,6 @@
}
-#if !id386
-
void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count)
{
int data;
@@ -340,7 +241,7 @@
lscale = snd_scaletable[ch->leftvol >> 3];
rscale = snd_scaletable[ch->rightvol >> 3];
- sfx = (signed char *)sc->data + ch->pos;
+ sfx = (uchar *)sc->data + ch->pos;
for (i=0 ; i<count ; i++)
{
@@ -352,9 +253,7 @@
ch->pos += count;
}
-#endif // !id386
-
void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int count)
{
int data;
@@ -378,4 +277,3 @@
ch->pos += count;
}
-
--- a/qw/sound.h
+++ b/qw/sound.h
@@ -1,8 +1,5 @@
// sound.h -- client sound i/o functions
-#ifndef __SOUND__
-#define __SOUND__
-
// !!! if this is changed, it much be changed in asm_i386.h too !!!
typedef struct
{
@@ -151,5 +148,3 @@
void S_AmbientOff (void);
void S_AmbientOn (void);
-
-#endif
--- a/qw/spritegn.h
+++ b/qw/spritegn.h
@@ -1,13 +1,5 @@
-//
// spritegn.h: header file for sprite generation program
-//
-// **********************************************************
-// * This file must be identical in the spritegen directory *
-// * and in the Quake directory, because it's used to *
-// * pass data from one to the other via .spr files. *
-// **********************************************************
-
//-------------------------------------------------------
// This program generates .spr sprite package files.
// The format of the files is as follows:
@@ -23,22 +15,6 @@
// <endrepeat>
//-------------------------------------------------------
-#ifdef INCLUDELIBS
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-
-#include "cmdlib.h"
-#include "scriplib.h"
-#include "dictlib.h"
-#include "trilib.h"
-#include "lbmlib.h"
-#include "mathlib.h"
-
-#endif
-
#define SPRITE_VERSION 1
// must match definition in modelgen.h
@@ -47,6 +23,8 @@
typedef enum {ST_SYNC=0, ST_RAND } synctype_t;
#endif
+#pragma pack on
+
// TODO: shorten these?
typedef struct {
int ident;
@@ -89,3 +67,4 @@
#define IDSPRITEHEADER (('P'<<24)+('S'<<16)+('D'<<8)+'I')
// little-endian "IDSP"
+#pragma pack off
--- a/qw/sv_ccmds.c
+++ b/qw/sv_ccmds.c
@@ -1,12 +1,12 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "qwsvdef.h"
+#include "quakedef.h"
qboolean sv_allow_cheats;
int fp_messages=4, fp_persecond=4, fp_secondsdead=10;
-char fp_msg[255] = { 0 };
+char fp_msg[255];
extern cvar_t cl_warncmd;
extern redirect_t sv_redirected;
@@ -32,7 +32,7 @@
char data[2];
int i;
- memset (&master_adr, 0, sizeof(master_adr));
+ memset (master_adr, 0, sizeof(master_adr));
for (i=1 ; i<Cmd_Argc() ; i++)
{
@@ -295,13 +295,13 @@
}
strcpy (level, Cmd_Argv(1));
-#if 0
+ /*
if (!strcmp (level, "e1m8"))
{ // QuakeWorld can't go to e1m8
SV_BroadcastPrintf (PRINT_HIGH, "can't go to low grav level in QuakeWorld...\n");
strcpy (level, "e1m5");
}
-#endif
+ */
// check to make sure the level exists
sprintf (expanded, "maps/%s.bsp", level);
@@ -375,7 +375,7 @@
avg = 1000*svs.stats.latched_active / STATFRAMES;
pak = (float)svs.stats.latched_packets/ STATFRAMES;
- Con_Printf ("net address : %s\n",NET_AdrToString (net_local_adr));
+ Con_Printf ("net address : %s\n",NET_AdrToString (laddr));
Con_Printf ("cpu utilization : %3i%%\n",(int)cpu);
Con_Printf ("avg response time: %i ms\n",(int)avg);
Con_Printf ("packets/frame : %5.2f (%d)\n", pak, num_prstr);
@@ -477,16 +477,16 @@
if (Cmd_Argc () < 2)
return;
- Q_strcpy (text, "console: ");
+ strcpy (text, "console: ");
p = Cmd_Args();
if (*p == '"')
{
p++;
- p[Q_strlen(p)-1] = 0;
+ p[strlen(p)-1] = 0;
}
- Q_strcat(text, p);
+ strcat(text, p);
for (j = 0, client = svs.clients; j < MAX_CLIENTS; j++, client++)
{
--- a/qw/sv_ents.c
+++ b/qw/sv_ents.c
@@ -1,7 +1,7 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "qwsvdef.h"
+#include "quakedef.h"
/*
=============================================================================
@@ -63,7 +63,7 @@
byte *SV_FatPVS (vec3_t org)
{
fatbytes = (sv.worldmodel->numleafs+31)>>3;
- Q_memset (fatpvs, 0, fatbytes);
+ memset (fatpvs, 0, fatbytes);
SV_AddToFatPVS (org, sv.worldmodel->nodes);
return fatpvs;
}
--- a/qw/sv_init.c
+++ b/qw/sv_init.c
@@ -1,7 +1,7 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "qwsvdef.h"
+#include "quakedef.h"
server_static_t svs; // persistant server info
server_t sv; // local server
--- a/qw/sv_main.c
+++ b/qw/sv_main.c
@@ -1,7 +1,7 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "qwsvdef.h"
+#include "quakedef.h"
quakeparms_t host_parms;
@@ -35,8 +35,6 @@
cvar_t allow_download_sounds = {"allow_download_sounds", "1"};
cvar_t allow_download_maps = {"allow_download_maps", "1"};
-cvar_t sv_highchars = {"sv_highchars", "1"};
-
cvar_t sv_phs = {"sv_phs", "1"};
cvar_t pausable = {"pausable", "1"};
@@ -79,6 +77,7 @@
*/
void SV_Shutdown (void)
{
+ killiop();
Master_Shutdown ();
if (sv_logfile)
{
@@ -537,7 +536,7 @@
if (s[0] && strcmp(s, "0"))
{
if (spectator_password.string[0] &&
- stricmp(spectator_password.string, "none") &&
+ cistrcmp(spectator_password.string, "none") &&
strcmp(spectator_password.string, s) )
{ // failed
Con_Printf ("%s:spectator password failed\n", NET_AdrToString (net_from));
@@ -552,7 +551,7 @@
{
s = Info_ValueForKey (userinfo, "password");
if (password.string[0] &&
- stricmp(password.string, "none") &&
+ cistrcmp(password.string, "none") &&
strcmp(password.string, s) )
{
Con_Printf ("%s:password failed\n", NET_AdrToString (net_from));
@@ -1050,10 +1049,8 @@
{
int i;
client_t *cl;
- qboolean good;
int qport;
- good = false;
while (NET_GetPacket ())
{
if (SV_FilterPacket ())
@@ -1093,7 +1090,6 @@
if (Netchan_Process(&cl->netchan))
{ // this is a valid, sequenced packet, so process it
svs.stats.packets++;
- good = true;
cl->send_message = true; // reply at end of frame
if (cl->state != cs_zombie)
SV_ExecuteClientMessage (cl);
@@ -1479,7 +1475,7 @@
val = Info_ValueForKey (cl->userinfo, "name");
}
- if (!val[0] || !stricmp(val, "console")) {
+ if (!val[0] || !cistrcmp(val, "console")) {
Info_SetValueForKey (cl->userinfo, "name", "unnamed", MAX_INFO_STRING);
val = Info_ValueForKey (cl->userinfo, "name");
}
@@ -1489,7 +1485,7 @@
for (i=0, client = svs.clients ; i<MAX_CLIENTS ; i++, client++) {
if (client->state != cs_spawned || client == cl)
continue;
- if (!stricmp(client->name, val))
+ if (!cistrcmp(client->name, val))
break;
}
if (i != MAX_CLIENTS) { // dup name
@@ -1622,7 +1618,7 @@
host_initialized = true;
- Con_Printf ("Exe: "__TIME__" "__DATE__"\n");
+ Con_Printf ("Exe: 00:00:00 Dec 17 1996\n");
Con_Printf ("%4.1f megabyte heap\n",parms->memsize/ (1024*1024.0));
Con_Printf ("\nServer Version %4.2f\n\n", VERSION);
--- a/qw/sv_move.c
+++ b/qw/sv_move.c
@@ -3,7 +3,7 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "qwsvdef.h"
+#include "quakedef.h"
#define STEPSIZE 18
--- a/qw/sv_nchan.c
+++ b/qw/sv_nchan.c
@@ -3,7 +3,7 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "qwsvdef.h"
+#include "quakedef.h"
// check to see if client block will fit, if not, rotate buffers
void ClientReliableCheckBlock(client_t *cl, int maxsize)
--- a/qw/sv_phys.c
+++ b/qw/sv_phys.c
@@ -1,11 +1,9 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "qwsvdef.h"
+#include "quakedef.h"
/*
-
-
pushmove objects do not obey gravity, and do not interact with each other or trigger fields, but block normal movement and push normal objects when they move.
onground is set for toss objects when they come to a complete rest. it is set for steping or walking objects
@@ -18,7 +16,6 @@
flying/floating monsters are SOLID_SLIDEBOX and MOVETYPE_FLY
solid_edge items only clip against bsp models.
-
*/
cvar_t sv_maxvelocity = {"sv_maxvelocity","2000"};
@@ -130,8 +127,6 @@
if (ent->free)
return false;
} while (1);
-
- return true;
}
/*
--- a/qw/sv_send.c
+++ b/qw/sv_send.c
@@ -3,7 +3,7 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "qwsvdef.h"
+#include "quakedef.h"
#define CHAN_AUTO 0
#define CHAN_WEAPON 1
@@ -334,7 +334,6 @@
float attenuation)
{
int sound_num;
- int field_mask;
int i;
int ent;
vec3_t origin;
@@ -379,7 +378,6 @@
channel = (ent<<3) | channel;
- field_mask = 0;
if (volume != DEFAULT_SOUND_PACKET_VOLUME)
channel |= SND_VOLUME;
if (attenuation != DEFAULT_SOUND_PACKET_ATTENUATION)
@@ -670,12 +668,7 @@
SZ_Clear (&sv.datagram);
}
-#ifdef _WIN32
-#pragma optimize( "", off )
-#endif
-
-
/*
=======================
SV_SendClientMessages
@@ -762,11 +755,6 @@
}
}
-
-#ifdef _WIN32
-#pragma optimize( "", on )
-#endif
-
/*
--- a/qw/sv_user.c
+++ b/qw/sv_user.c
@@ -3,7 +3,7 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "qwsvdef.h"
+#include "quakedef.h"
edict_t *sv_player;
@@ -408,8 +408,8 @@
*/
void SV_Begin_f (void)
{
- unsigned pmodel = 0, emodel = 0;
- int i;
+ int i;
+ uint pmodel, emodel;
if (host_client->state == cs_spawned)
return; // don't begin again
@@ -478,8 +478,7 @@
SV_ClientPrintf(host_client, PRINT_HIGH, "Server is paused.\n");
}
-#if 0
-//
+/*
// send a fixangle over the reliable channel to make sure it gets there
// Never send a roll angle, because savegames can catch the server
// in a state where it is expecting the client to correct the angle
@@ -490,7 +489,7 @@
for (i=0 ; i < 2 ; i++)
MSG_WriteAngle (&host_client->netchan.message, ent->v.angles[i] );
MSG_WriteAngle (&host_client->netchan.message, 0 );
-#endif
+*/
}
//=============================================================================
@@ -557,11 +556,8 @@
*/
void SV_NextUpload (void)
{
- byte buffer[1024];
- int r;
int percent;
int size;
- client_t *client;
if (!*host_client->uploadfn) {
SV_ClientPrintf(host_client, PRINT_HIGH, "Upload denied\n");
@@ -762,11 +758,11 @@
if (*p == '"')
{
p++;
- p[Q_strlen(p)-1] = 0;
+ p[strlen(p)-1] = 0;
}
- Q_strcat(text, p);
- Q_strcat(text, "\n");
+ strcat(text, p);
+ strcat(text, "\n");
Sys_Printf ("%s", text);
@@ -898,8 +894,6 @@
*/
void SV_Pause_f (void)
{
- int i;
- client_t *cl;
char st[sizeof(host_client->name) + 32];
if (!pausable.value) {
@@ -1430,26 +1424,16 @@
pmove_mins[i] = pmove.origin[i] - 256;
pmove_maxs[i] = pmove.origin[i] + 256;
}
-#if 1
- AddLinksToPmove ( sv_areanodes );
-#else
- AddAllEntsToPmove ();
-#endif
+ AddLinksToPmove ( sv_areanodes ); /*AddAllEntsToPmove ();*/
-#if 0
-{
- int before, after;
-
-before = PM_TestPlayerPosition (pmove.origin);
+ /*
+ int before = PM_TestPlayerPosition (pmove.origin);
PlayerMove ();
-after = PM_TestPlayerPosition (pmove.origin);
-
-if (sv_player->v.health > 0 && before && !after )
- Con_Printf ("player %s got stuck in playermove!!!!\n", host_client->name);
-}
-#else
+ int after = PM_TestPlayerPosition (pmove.origin);
+ if (sv_player->v.health > 0 && before && !after )
+ Con_Printf ("player %s got stuck in playermove!!!!\n", host_client->name);
+ */
PlayerMove ();
-#endif
host_client->oldbuttons = pmove.oldbuttons;
sv_player->v.teleport_time = pmove.waterjumptime;
@@ -1465,13 +1449,11 @@
for (i=0 ; i<3 ; i++)
sv_player->v.origin[i] = pmove.origin[i] - (sv_player->v.mins[i] - player_mins[i]);
-#if 0
- // truncate velocity the same way the net protocol will
+ /* truncate velocity the same way the net protocol will
for (i=0 ; i<3 ; i++)
sv_player->v.velocity[i] = (int)pmove.velocity[i];
-#else
+ */
VectorCopy (pmove.velocity, sv_player->v.velocity);
-#endif
VectorCopy (pmove.angles, sv_player->v.v_angle);
--- /dev/null
+++ b/qw/svmodel.c
@@ -1,0 +1,1119 @@
+// models.c -- model loading and caching
+
+// models are the only shared resource between a client and server running
+// on the same machine.
+
+#include <u.h>
+#include <libc.h>
+#include <stdio.h>
+#include "quakedef.h"
+
+model_t *loadmodel;
+char loadname[32]; // for hunk tags
+
+void Mod_LoadSpriteModel (model_t *mod, void *buffer);
+void Mod_LoadBrushModel (model_t *mod, void *buffer);
+void Mod_LoadAliasModel (model_t *mod, void *buffer);
+model_t *Mod_LoadModel (model_t *mod, qboolean crash);
+
+byte mod_novis[MAX_MAP_LEAFS/8];
+
+#define MAX_MOD_KNOWN 256
+model_t mod_known[MAX_MOD_KNOWN];
+int mod_numknown;
+
+texture_t rnotexmip;
+
+unsigned *model_checksum;
+
+/*
+===============
+Mod_Init
+===============
+*/
+void Mod_Init (void)
+{
+ memset (mod_novis, 0xff, sizeof(mod_novis));
+}
+
+/*
+===============
+Mod_PointInLeaf
+===============
+*/
+mleaf_t *Mod_PointInLeaf (vec3_t p, model_t *model)
+{
+ mnode_t *node;
+ float d;
+ mplane_t *plane;
+
+ if (!model || !model->nodes)
+ SV_Error ("Mod_PointInLeaf: bad model");
+
+ node = model->nodes;
+ while (1)
+ {
+ if (node->contents < 0)
+ return (mleaf_t *)node;
+ plane = node->plane;
+ d = DotProduct (p,plane->normal) - plane->dist;
+ if (d > 0)
+ node = node->children[0];
+ else
+ node = node->children[1];
+ }
+}
+
+
+/*
+===================
+Mod_DecompressVis
+===================
+*/
+byte *Mod_DecompressVis (byte *in, model_t *model)
+{
+ static byte decompressed[MAX_MAP_LEAFS/8];
+ int c;
+ byte *out;
+ int row;
+
+ row = (model->numleafs+7)>>3;
+ out = decompressed;
+
+ /*
+ memcpy (out, in, row);
+ */
+ if (!in)
+ { // no vis info, so make all visible
+ while (row)
+ {
+ *out++ = 0xff;
+ row--;
+ }
+ return decompressed;
+ }
+
+ do
+ {
+ if (*in)
+ {
+ *out++ = *in++;
+ continue;
+ }
+
+ c = in[1];
+ in += 2;
+ while (c)
+ {
+ *out++ = 0;
+ c--;
+ }
+ } while (out - decompressed < row);
+#endif
+
+ return decompressed;
+}
+
+byte *Mod_LeafPVS (mleaf_t *leaf, model_t *model)
+{
+ if (leaf == model->leafs)
+ return mod_novis;
+ return Mod_DecompressVis (leaf->compressed_vis, model);
+}
+
+/*
+===================
+Mod_ClearAll
+===================
+*/
+void Mod_ClearAll (void)
+{
+ int i;
+ model_t *mod;
+
+ for (i=0 , mod=mod_known ; i<mod_numknown ; i++, mod++)
+ if (mod->type != mod_alias)
+ mod->needload = true;
+}
+
+/*
+==================
+Mod_FindName
+
+==================
+*/
+model_t *Mod_FindName (char *name)
+{
+ int i;
+ model_t *mod;
+
+ if (!name[0])
+ SV_Error ("Mod_ForName: NULL name");
+
+//
+// search the currently loaded models
+//
+ for (i=0 , mod=mod_known ; i<mod_numknown ; i++, mod++)
+ if (!strcmp (mod->name, name) )
+ break;
+
+ if (i == mod_numknown)
+ {
+ if (mod_numknown == MAX_MOD_KNOWN)
+ SV_Error ("mod_numknown == MAX_MOD_KNOWN");
+ strcpy (mod->name, name);
+ mod->needload = true;
+ mod_numknown++;
+ }
+
+ return mod;
+}
+
+
+/*
+==================
+Mod_LoadModel
+
+Loads a model into the cache
+==================
+*/
+model_t *Mod_LoadModel (model_t *mod, qboolean crash)
+{
+ void *d;
+ unsigned *buf;
+ byte stackbuf[1024]; // avoid dirtying the cache heap
+
+ if (!mod->needload)
+ {
+ if (mod->type == mod_alias)
+ {
+ d = Cache_Check (&mod->cache);
+ if (d)
+ return mod;
+ }
+ else
+ return mod; // not cached at all
+ }
+
+//
+// load the file
+//
+ buf = (unsigned *)COM_LoadStackFile (mod->name, stackbuf, sizeof(stackbuf));
+ if (!buf)
+ {
+ if (crash)
+ SV_Error ("Mod_NumForName: %s not found", mod->name);
+ return NULL;
+ }
+
+//
+// allocate a new model
+//
+ COM_FileBase (mod->name, loadname);
+
+ loadmodel = mod;
+
+//
+// fill it in
+//
+
+// call the apropriate loader
+ mod->needload = false;
+
+ Mod_LoadBrushModel (mod, buf);
+
+ return mod;
+}
+
+/*
+==================
+Mod_ForName
+
+Loads in a model for the given name
+==================
+*/
+model_t *Mod_ForName (char *name, qboolean crash)
+{
+ model_t *mod;
+
+ mod = Mod_FindName (name);
+
+ return Mod_LoadModel (mod, crash);
+}
+
+
+/*
+===============================================================================
+
+ BRUSHMODEL LOADING
+
+===============================================================================
+*/
+
+byte *mod_base;
+
+
+/*
+=================
+Mod_LoadTextures
+=================
+*/
+void Mod_LoadTextures (lump_t *l)
+{
+ int i, j, pixels, num, max, altmax;
+ miptex_t *mt;
+ texture_t *tx, *tx2;
+ texture_t *anims[10];
+ texture_t *altanims[10];
+ dmiptexlump_t *m;
+
+ if (!l->filelen)
+ {
+ loadmodel->textures = NULL;
+ return;
+ }
+ m = (dmiptexlump_t *)(mod_base + l->fileofs);
+
+ m->nummiptex = LittleLong (m->nummiptex);
+
+ loadmodel->numtextures = m->nummiptex;
+ loadmodel->textures = Hunk_AllocName (m->nummiptex * sizeof(*loadmodel->textures) , loadname);
+
+ for (i=0 ; i<m->nummiptex ; i++)
+ {
+ m->dataofs[i] = LittleLong(m->dataofs[i]);
+ if (m->dataofs[i] == -1)
+ continue;
+ mt = (miptex_t *)((byte *)m + m->dataofs[i]);
+ mt->width = LittleLong (mt->width);
+ mt->height = LittleLong (mt->height);
+ for (j=0 ; j<MIPLEVELS ; j++)
+ mt->offsets[j] = LittleLong (mt->offsets[j]);
+
+ if ( (mt->width & 15) || (mt->height & 15) )
+ SV_Error ("Texture %s is not 16 aligned", mt->name);
+ pixels = mt->width*mt->height/64*85;
+ tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );
+ loadmodel->textures[i] = tx;
+
+ memcpy (tx->name, mt->name, sizeof(tx->name));
+ tx->width = mt->width;
+ tx->height = mt->height;
+ for (j=0 ; j<MIPLEVELS ; j++)
+ tx->offsets[j] = mt->offsets[j] + sizeof(texture_t) - sizeof(miptex_t);
+ // the pixels immediately follow the structures
+ memcpy ( tx+1, mt+1, pixels);
+ }
+
+//
+// sequence the animations
+//
+ for (i=0 ; i<m->nummiptex ; i++)
+ {
+ tx = loadmodel->textures[i];
+ if (!tx || tx->name[0] != '+')
+ continue;
+ if (tx->anim_next)
+ continue; // allready sequenced
+
+ // find the number of frames in the animation
+ memset (anims, 0, sizeof(anims));
+ memset (altanims, 0, sizeof(altanims));
+
+ max = tx->name[1];
+ altmax = 0;
+ if (max >= 'a' && max <= 'z')
+ max -= 'a' - 'A';
+ if (max >= '0' && max <= '9')
+ {
+ max -= '0';
+ altmax = 0;
+ anims[max] = tx;
+ max++;
+ }
+ else if (max >= 'A' && max <= 'J')
+ {
+ altmax = max - 'A';
+ max = 0;
+ altanims[altmax] = tx;
+ altmax++;
+ }
+ else
+ SV_Error ("Bad animating texture %s", tx->name);
+
+ for (j=i+1 ; j<m->nummiptex ; j++)
+ {
+ tx2 = loadmodel->textures[j];
+ if (!tx2 || tx2->name[0] != '+')
+ continue;
+ if (strcmp (tx2->name+2, tx->name+2))
+ continue;
+
+ num = tx2->name[1];
+ if (num >= 'a' && num <= 'z')
+ num -= 'a' - 'A';
+ if (num >= '0' && num <= '9')
+ {
+ num -= '0';
+ anims[num] = tx2;
+ if (num+1 > max)
+ max = num + 1;
+ }
+ else if (num >= 'A' && num <= 'J')
+ {
+ num = num - 'A';
+ altanims[num] = tx2;
+ if (num+1 > altmax)
+ altmax = num+1;
+ }
+ else
+ SV_Error ("Bad animating texture %s", tx->name);
+ }
+
+#define ANIM_CYCLE 2
+ // link them all together
+ for (j=0 ; j<max ; j++)
+ {
+ tx2 = anims[j];
+ if (!tx2)
+ SV_Error ("Missing frame %i of %s",j, tx->name);
+ tx2->anim_total = max * ANIM_CYCLE;
+ tx2->anim_min = j * ANIM_CYCLE;
+ tx2->anim_max = (j+1) * ANIM_CYCLE;
+ tx2->anim_next = anims[ (j+1)%max ];
+ if (altmax)
+ tx2->alternate_anims = altanims[0];
+ }
+ for (j=0 ; j<altmax ; j++)
+ {
+ tx2 = altanims[j];
+ if (!tx2)
+ SV_Error ("Missing frame %i of %s",j, tx->name);
+ tx2->anim_total = altmax * ANIM_CYCLE;
+ tx2->anim_min = j * ANIM_CYCLE;
+ tx2->anim_max = (j+1) * ANIM_CYCLE;
+ tx2->anim_next = altanims[ (j+1)%altmax ];
+ if (max)
+ tx2->alternate_anims = anims[0];
+ }
+ }
+}
+
+/*
+=================
+Mod_LoadLighting
+=================
+*/
+void Mod_LoadLighting (lump_t *l)
+{
+ if (!l->filelen)
+ {
+ loadmodel->lightdata = NULL;
+ return;
+ }
+ loadmodel->lightdata = Hunk_AllocName ( l->filelen, loadname);
+ memcpy (loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
+}
+
+
+/*
+=================
+Mod_LoadVisibility
+=================
+*/
+void Mod_LoadVisibility (lump_t *l)
+{
+ if (!l->filelen)
+ {
+ loadmodel->visdata = NULL;
+ return;
+ }
+ loadmodel->visdata = Hunk_AllocName ( l->filelen, loadname);
+ memcpy (loadmodel->visdata, mod_base + l->fileofs, l->filelen);
+}
+
+
+/*
+=================
+Mod_LoadEntities
+=================
+*/
+void Mod_LoadEntities (lump_t *l)
+{
+ if (!l->filelen)
+ {
+ loadmodel->entities = NULL;
+ return;
+ }
+ loadmodel->entities = Hunk_AllocName ( l->filelen, loadname);
+ memcpy (loadmodel->entities, mod_base + l->fileofs, l->filelen);
+}
+
+
+/*
+=================
+Mod_LoadVertexes
+=================
+*/
+void Mod_LoadVertexes (lump_t *l)
+{
+ dvertex_t *in;
+ mvertex_t *out;
+ int i, count;
+
+ in = (void *)(mod_base + l->fileofs);
+ if (l->filelen % sizeof(*in))
+ SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ count = l->filelen / sizeof(*in);
+ out = Hunk_AllocName ( count*sizeof(*out), loadname);
+
+ loadmodel->vertexes = out;
+ loadmodel->numvertexes = count;
+
+ for ( i=0 ; i<count ; i++, in++, out++)
+ {
+ out->position[0] = LittleFloat (in->point[0]);
+ out->position[1] = LittleFloat (in->point[1]);
+ out->position[2] = LittleFloat (in->point[2]);
+ }
+}
+
+/*
+=================
+Mod_LoadSubmodels
+=================
+*/
+void Mod_LoadSubmodels (lump_t *l)
+{
+ dmodel_t *in;
+ dmodel_t *out;
+ int i, j, count;
+
+ in = (void *)(mod_base + l->fileofs);
+ if (l->filelen % sizeof(*in))
+ SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ count = l->filelen / sizeof(*in);
+ out = Hunk_AllocName ( count*sizeof(*out), loadname);
+
+ loadmodel->submodels = out;
+ loadmodel->numsubmodels = count;
+
+ for ( i=0 ; i<count ; i++, in++, out++)
+ {
+ for (j=0 ; j<3 ; j++)
+ { // spread the mins / maxs by a pixel
+ out->mins[j] = LittleFloat (in->mins[j]) - 1;
+ out->maxs[j] = LittleFloat (in->maxs[j]) + 1;
+ out->origin[j] = LittleFloat (in->origin[j]);
+ }
+ for (j=0 ; j<MAX_MAP_HULLS ; j++)
+ out->headnode[j] = LittleLong (in->headnode[j]);
+ out->visleafs = LittleLong (in->visleafs);
+ out->firstface = LittleLong (in->firstface);
+ out->numfaces = LittleLong (in->numfaces);
+ }
+}
+
+/*
+=================
+Mod_LoadEdges
+=================
+*/
+void Mod_LoadEdges (lump_t *l)
+{
+ dedge_t *in;
+ medge_t *out;
+ int i, count;
+
+ in = (void *)(mod_base + l->fileofs);
+ if (l->filelen % sizeof(*in))
+ SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ count = l->filelen / sizeof(*in);
+ out = Hunk_AllocName ( (count + 1) * sizeof(*out), loadname);
+
+ loadmodel->edges = out;
+ loadmodel->numedges = count;
+
+ for ( i=0 ; i<count ; i++, in++, out++)
+ {
+ out->v[0] = (unsigned short)LittleShort(in->v[0]);
+ out->v[1] = (unsigned short)LittleShort(in->v[1]);
+ }
+}
+
+/*
+=================
+Mod_LoadTexinfo
+=================
+*/
+void Mod_LoadTexinfo (lump_t *l)
+{
+ texinfo_t *in;
+ mtexinfo_t *out;
+ int i, j, count;
+ int miptex;
+ float len1, len2;
+
+ in = (void *)(mod_base + l->fileofs);
+ if (l->filelen % sizeof(*in))
+ SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ count = l->filelen / sizeof(*in);
+ out = Hunk_AllocName ( count*sizeof(*out), loadname);
+
+ loadmodel->texinfo = out;
+ loadmodel->numtexinfo = count;
+
+ for ( i=0 ; i<count ; i++, in++, out++)
+ {
+ /*
+ for (j=0 ; j<8 ; j++)
+ out->vecs[0][j] = LittleFloat (in->vecs[0][j]);
+ len1 = Length (in->vecs[0]);
+ len2 = Length (in->vecs[1]);
+ */
+ for (j=0 ; j<4 ; j++) {
+ out->vecs[0][j] = LittleFloat (in->vecs[0][j]);
+ out->vecs[1][j] = LittleFloat (in->vecs[1][j]);
+ }
+ len1 = Length (out->vecs[0]);
+ len2 = Length (out->vecs[1]);
+
+ if (len1 + len2 < 2 /*0.001*/)
+ out->mipadjust = 1;
+ else
+ out->mipadjust = 1 / floor( (len1+len2)/2 );
+
+ miptex = LittleLong (in->miptex);
+ out->flags = LittleLong (in->flags);
+
+ if (!loadmodel->textures)
+ {
+ out->texture = &rnotexmip; // checkerboard texture
+ out->flags = 0;
+ }
+ else
+ {
+ if (miptex >= loadmodel->numtextures)
+ SV_Error ("miptex >= loadmodel->numtextures");
+ out->texture = loadmodel->textures[miptex];
+ if (!out->texture)
+ {
+ out->texture = &rnotexmip; // texture not found
+ out->flags = 0;
+ }
+ }
+ }
+}
+
+/*
+================
+CalcSurfaceExtents
+
+Fills in s->texturemins[] and s->extents[]
+================
+*/
+void CalcSurfaceExtents (msurface_t *s)
+{
+ float mins[2], maxs[2], val;
+ int i,j, e;
+ mvertex_t *v;
+ mtexinfo_t *tex;
+ int bmins[2], bmaxs[2];
+
+ mins[0] = mins[1] = 999999;
+ maxs[0] = maxs[1] = -99999;
+
+ tex = s->texinfo;
+
+ for (i=0 ; i<s->numedges ; i++)
+ {
+ e = loadmodel->surfedges[s->firstedge+i];
+ if (e >= 0)
+ v = &loadmodel->vertexes[loadmodel->edges[e].v[0]];
+ else
+ v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]];
+
+ for (j=0 ; j<2 ; j++)
+ {
+ val = v->position[0] * tex->vecs[j][0] +
+ v->position[1] * tex->vecs[j][1] +
+ v->position[2] * tex->vecs[j][2] +
+ tex->vecs[j][3];
+ if (val < mins[j])
+ mins[j] = val;
+ if (val > maxs[j])
+ maxs[j] = val;
+ }
+ }
+
+ for (i=0 ; i<2 ; i++)
+ {
+ bmins[i] = floor(mins[i]/16);
+ bmaxs[i] = ceil(maxs[i]/16);
+
+ s->texturemins[i] = bmins[i] * 16;
+ s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
+ if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 256)
+ SV_Error ("Bad surface extents");
+ }
+}
+
+
+/*
+=================
+Mod_LoadFaces
+=================
+*/
+void Mod_LoadFaces (lump_t *l)
+{
+ dface_t *in;
+ msurface_t *out;
+ int i, count, surfnum;
+ int planenum, side;
+
+ in = (void *)(mod_base + l->fileofs);
+ if (l->filelen % sizeof(*in))
+ SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ count = l->filelen / sizeof(*in);
+ out = Hunk_AllocName ( count*sizeof(*out), loadname);
+
+ loadmodel->surfaces = out;
+ loadmodel->numsurfaces = count;
+
+ for ( surfnum=0 ; surfnum<count ; surfnum++, in++, out++)
+ {
+ out->firstedge = LittleLong(in->firstedge);
+ out->numedges = LittleShort(in->numedges);
+ out->flags = 0;
+
+ planenum = LittleShort(in->planenum);
+ side = LittleShort(in->side);
+ if (side)
+ out->flags |= SURF_PLANEBACK;
+
+ out->plane = loadmodel->planes + planenum;
+
+ out->texinfo = loadmodel->texinfo + LittleShort (in->texinfo);
+
+ CalcSurfaceExtents (out);
+
+ // lighting info
+
+ for (i=0 ; i<MAXLIGHTMAPS ; i++)
+ out->styles[i] = in->styles[i];
+ i = LittleLong(in->lightofs);
+ if (i == -1)
+ out->samples = NULL;
+ else
+ out->samples = loadmodel->lightdata + i;
+
+ // set the drawing flags flag
+
+ if (!strncmp(out->texinfo->texture->name,"sky",3)) // sky
+ {
+ out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED);
+ continue;
+ }
+
+ if (!strncmp(out->texinfo->texture->name,"*",1)) // turbulent
+ {
+ out->flags |= (SURF_DRAWTURB | SURF_DRAWTILED);
+ for (i=0 ; i<2 ; i++)
+ {
+ out->extents[i] = 16384;
+ out->texturemins[i] = -8192;
+ }
+ continue;
+ }
+ }
+}
+
+
+/*
+=================
+Mod_SetParent
+=================
+*/
+void Mod_SetParent (mnode_t *node, mnode_t *parent)
+{
+ node->parent = parent;
+ if (node->contents < 0)
+ return;
+ Mod_SetParent (node->children[0], node);
+ Mod_SetParent (node->children[1], node);
+}
+
+/*
+=================
+Mod_LoadNodes
+=================
+*/
+void Mod_LoadNodes (lump_t *l)
+{
+ int i, j, count, p;
+ dnode_t *in;
+ mnode_t *out;
+
+ in = (void *)(mod_base + l->fileofs);
+ if (l->filelen % sizeof(*in))
+ SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ count = l->filelen / sizeof(*in);
+ out = Hunk_AllocName ( count*sizeof(*out), loadname);
+
+ loadmodel->nodes = out;
+ loadmodel->numnodes = count;
+
+ for ( i=0 ; i<count ; i++, in++, out++)
+ {
+ for (j=0 ; j<3 ; j++)
+ {
+ out->minmaxs[j] = LittleShort (in->mins[j]);
+ out->minmaxs[3+j] = LittleShort (in->maxs[j]);
+ }
+
+ p = LittleLong(in->planenum);
+ out->plane = loadmodel->planes + p;
+
+ out->firstsurface = LittleShort (in->firstface);
+ out->numsurfaces = LittleShort (in->numfaces);
+
+ for (j=0 ; j<2 ; j++)
+ {
+ p = LittleShort (in->children[j]);
+ if (p >= 0)
+ out->children[j] = loadmodel->nodes + p;
+ else
+ out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p));
+ }
+ }
+
+ Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs
+}
+
+/*
+=================
+Mod_LoadLeafs
+=================
+*/
+void Mod_LoadLeafs (lump_t *l)
+{
+ dleaf_t *in;
+ mleaf_t *out;
+ int i, j, count, p;
+
+ in = (void *)(mod_base + l->fileofs);
+ if (l->filelen % sizeof(*in))
+ SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ count = l->filelen / sizeof(*in);
+ out = Hunk_AllocName ( count*sizeof(*out), loadname);
+
+ loadmodel->leafs = out;
+ loadmodel->numleafs = count;
+
+ for ( i=0 ; i<count ; i++, in++, out++)
+ {
+ for (j=0 ; j<3 ; j++)
+ {
+ out->minmaxs[j] = LittleShort (in->mins[j]);
+ out->minmaxs[3+j] = LittleShort (in->maxs[j]);
+ }
+
+ p = LittleLong(in->contents);
+ out->contents = p;
+
+ out->firstmarksurface = loadmodel->marksurfaces +
+ LittleShort(in->firstmarksurface);
+ out->nummarksurfaces = LittleShort(in->nummarksurfaces);
+
+ p = LittleLong(in->visofs);
+ if (p == -1)
+ out->compressed_vis = NULL;
+ else
+ out->compressed_vis = loadmodel->visdata + p;
+ out->efrags = NULL;
+
+ for (j=0 ; j<4 ; j++)
+ out->ambient_sound_level[j] = in->ambient_level[j];
+ }
+}
+
+/*
+=================
+Mod_LoadClipnodes
+=================
+*/
+void Mod_LoadClipnodes (lump_t *l)
+{
+ dclipnode_t *in, *out;
+ int i, count;
+ hull_t *hull;
+
+ in = (void *)(mod_base + l->fileofs);
+ if (l->filelen % sizeof(*in))
+ SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ count = l->filelen / sizeof(*in);
+ out = Hunk_AllocName ( count*sizeof(*out), loadname);
+
+ loadmodel->clipnodes = out;
+ loadmodel->numclipnodes = count;
+
+ hull = &loadmodel->hulls[1];
+ hull->clipnodes = out;
+ hull->firstclipnode = 0;
+ hull->lastclipnode = count-1;
+ hull->planes = loadmodel->planes;
+ hull->clip_mins[0] = -16;
+ hull->clip_mins[1] = -16;
+ hull->clip_mins[2] = -24;
+ hull->clip_maxs[0] = 16;
+ hull->clip_maxs[1] = 16;
+ hull->clip_maxs[2] = 32;
+
+ hull = &loadmodel->hulls[2];
+ hull->clipnodes = out;
+ hull->firstclipnode = 0;
+ hull->lastclipnode = count-1;
+ hull->planes = loadmodel->planes;
+ hull->clip_mins[0] = -32;
+ hull->clip_mins[1] = -32;
+ hull->clip_mins[2] = -24;
+ hull->clip_maxs[0] = 32;
+ hull->clip_maxs[1] = 32;
+ hull->clip_maxs[2] = 64;
+
+ for (i=0 ; i<count ; i++, out++, in++)
+ {
+ out->planenum = LittleLong(in->planenum);
+ out->children[0] = LittleShort(in->children[0]);
+ out->children[1] = LittleShort(in->children[1]);
+ }
+}
+
+/*
+=================
+Mod_MakeHull0
+
+Deplicate the drawing hull structure as a clipping hull
+=================
+*/
+void Mod_MakeHull0 (void)
+{
+ mnode_t *in, *child;
+ dclipnode_t *out;
+ int i, j, count;
+ hull_t *hull;
+
+ hull = &loadmodel->hulls[0];
+
+ in = loadmodel->nodes;
+ count = loadmodel->numnodes;
+ out = Hunk_AllocName ( count*sizeof(*out), loadname);
+
+ hull->clipnodes = out;
+ hull->firstclipnode = 0;
+ hull->lastclipnode = count-1;
+ hull->planes = loadmodel->planes;
+
+ for (i=0 ; i<count ; i++, out++, in++)
+ {
+ out->planenum = in->plane - loadmodel->planes;
+ for (j=0 ; j<2 ; j++)
+ {
+ child = in->children[j];
+ if (child->contents < 0)
+ out->children[j] = child->contents;
+ else
+ out->children[j] = child - loadmodel->nodes;
+ }
+ }
+}
+
+/*
+=================
+Mod_LoadMarksurfaces
+=================
+*/
+void Mod_LoadMarksurfaces (lump_t *l)
+{
+ int i, j, count;
+ short *in;
+ msurface_t **out;
+
+ in = (void *)(mod_base + l->fileofs);
+ if (l->filelen % sizeof(*in))
+ SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ count = l->filelen / sizeof(*in);
+ out = Hunk_AllocName ( count*sizeof(*out), loadname);
+
+ loadmodel->marksurfaces = out;
+ loadmodel->nummarksurfaces = count;
+
+ for ( i=0 ; i<count ; i++)
+ {
+ j = LittleShort(in[i]);
+ if (j >= loadmodel->numsurfaces)
+ SV_Error ("Mod_ParseMarksurfaces: bad surface number");
+ out[i] = loadmodel->surfaces + j;
+ }
+}
+
+/*
+=================
+Mod_LoadSurfedges
+=================
+*/
+void Mod_LoadSurfedges (lump_t *l)
+{
+ int i, count;
+ int *in, *out;
+
+ in = (void *)(mod_base + l->fileofs);
+ if (l->filelen % sizeof(*in))
+ SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ count = l->filelen / sizeof(*in);
+ out = Hunk_AllocName ( count*sizeof(*out), loadname);
+
+ loadmodel->surfedges = out;
+ loadmodel->numsurfedges = count;
+
+ for ( i=0 ; i<count ; i++)
+ out[i] = LittleLong (in[i]);
+}
+
+/*
+=================
+Mod_LoadPlanes
+=================
+*/
+void Mod_LoadPlanes (lump_t *l)
+{
+ int i, j;
+ mplane_t *out;
+ dplane_t *in;
+ int count;
+ int bits;
+
+ in = (void *)(mod_base + l->fileofs);
+ if (l->filelen % sizeof(*in))
+ SV_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+ count = l->filelen / sizeof(*in);
+ out = Hunk_AllocName ( count*2*sizeof(*out), loadname);
+
+ loadmodel->planes = out;
+ loadmodel->numplanes = count;
+
+ for ( i=0 ; i<count ; i++, in++, out++)
+ {
+ bits = 0;
+ for (j=0 ; j<3 ; j++)
+ {
+ out->normal[j] = LittleFloat (in->normal[j]);
+ if (out->normal[j] < 0)
+ bits |= 1<<j;
+ }
+
+ out->dist = LittleFloat (in->dist);
+ out->type = LittleLong (in->type);
+ out->signbits = bits;
+ }
+}
+
+
+/*
+=================
+Mod_LoadBrushModel
+=================
+*/
+void Mod_LoadBrushModel (model_t *mod, void *buffer)
+{
+ int i, j;
+ dheader_t *header;
+ dmodel_t *bm;
+
+ loadmodel->type = mod_brush;
+
+ header = (dheader_t *)buffer;
+
+ i = LittleLong (header->version);
+ if (i != BSPVERSION)
+ SV_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i)", mod->name, i, BSPVERSION);
+
+// swap all the lumps
+ mod_base = (byte *)header;
+
+ for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
+ ((int *)header)[i] = LittleLong ( ((int *)header)[i]);
+
+// load into heap
+
+ mod->checksum = 0;
+ mod->checksum2 = 0;
+
+ // checksum all of the map, except for entities
+ for (i = 0; i < HEADER_LUMPS; i++) {
+ if (i == LUMP_ENTITIES)
+ continue;
+ mod->checksum ^= LittleLong(Com_BlockChecksum(mod_base + header->lumps[i].fileofs,
+ header->lumps[i].filelen));
+
+ if (i == LUMP_VISIBILITY || i == LUMP_LEAFS || i == LUMP_NODES)
+ continue;
+ mod->checksum2 ^= LittleLong(Com_BlockChecksum(mod_base + header->lumps[i].fileofs,
+ header->lumps[i].filelen));
+ }
+
+ Mod_LoadVertexes (&header->lumps[LUMP_VERTEXES]);
+ Mod_LoadEdges (&header->lumps[LUMP_EDGES]);
+ Mod_LoadSurfedges (&header->lumps[LUMP_SURFEDGES]);
+ Mod_LoadTextures (&header->lumps[LUMP_TEXTURES]);
+ Mod_LoadLighting (&header->lumps[LUMP_LIGHTING]);
+ Mod_LoadPlanes (&header->lumps[LUMP_PLANES]);
+ Mod_LoadTexinfo (&header->lumps[LUMP_TEXINFO]);
+ Mod_LoadFaces (&header->lumps[LUMP_FACES]);
+ Mod_LoadMarksurfaces (&header->lumps[LUMP_MARKSURFACES]);
+ Mod_LoadVisibility (&header->lumps[LUMP_VISIBILITY]);
+ Mod_LoadLeafs (&header->lumps[LUMP_LEAFS]);
+ Mod_LoadNodes (&header->lumps[LUMP_NODES]);
+ Mod_LoadClipnodes (&header->lumps[LUMP_CLIPNODES]);
+ Mod_LoadEntities (&header->lumps[LUMP_ENTITIES]);
+ Mod_LoadSubmodels (&header->lumps[LUMP_MODELS]);
+
+ Mod_MakeHull0 ();
+
+ mod->numframes = 2; // regular and alternate animation
+
+//
+// set up the submodels (FIXME: this is confusing)
+//
+ for (i=0 ; i<mod->numsubmodels ; i++)
+ {
+ bm = &mod->submodels[i];
+
+ mod->hulls[0].firstclipnode = bm->headnode[0];
+ for (j=1 ; j<MAX_MAP_HULLS ; j++)
+ {
+ mod->hulls[j].firstclipnode = bm->headnode[j];
+ mod->hulls[j].lastclipnode = mod->numclipnodes-1;
+ }
+
+ mod->firstmodelsurface = bm->firstface;
+ mod->nummodelsurfaces = bm->numfaces;
+
+ VectorCopy (bm->maxs, mod->maxs);
+ VectorCopy (bm->mins, mod->mins);
+
+ mod->numleafs = bm->visleafs;
+
+ if (i < mod->numsubmodels-1)
+ { // duplicate the basic information
+ char name[10];
+
+ sprintf (name, "*%i", i+1);
+ loadmodel = Mod_FindName (name);
+ *loadmodel = *mod;
+ strcpy (loadmodel->name, name);
+ mod = loadmodel;
+ }
+ }
+}
+
--- a/qw/sys.c
+++ b/qw/sys.c
@@ -1,393 +1,142 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
+#include <thread.h>
#include "quakedef.h"
-int noconinput = 0;
-int nostdout = 0;
+int svonly;
-char *basedir = ".";
-char *cachedir = "/tmp";
-cvar_t sys_linerefresh = {"sys_linerefresh","0"};// set for entity display
-
-// =======================================================================
-// General routines
-// =======================================================================
-
-void Sys_DebugNumber(int y, int val)
+void
+Sys_Printf(char *fmt, ...)
{
-}
+ char buf[1024];
+ char *p;
+ va_list arg;
-/*
-void Sys_Printf (char *fmt, ...)
-{
- va_list argptr;
- char text[1024];
-
- va_start (argptr,fmt);
- vsprintf (text,fmt,argptr);
- va_end (argptr);
- fprintf(stderr, "%s", text);
-
- Con_Print (text);
-}
+ va_start(arg, fmt);
+ vseprint(buf, buf+sizeof(buf), fmt, arg);
+ va_end(arg);
-void Sys_Printf (char *fmt, ...)
-{
-
- va_list argptr;
- char text[1024], *t_p;
- int l, r;
-
- if (nostdout)
- return;
-
- va_start (argptr,fmt);
- vsprintf (text,fmt,argptr);
- va_end (argptr);
-
- l = strlen(text);
- t_p = text;
-
-// make sure everything goes through, even though we are non-blocking
- while (l)
- {
- r = write (1, text, l);
- if (r != l)
- sleep (0);
- if (r > 0)
- {
- t_p += r;
- l -= r;
- }
- }
-
-}
-*/
-
-void Sys_Printf (char *fmt, ...)
-{
- va_list argptr;
- char text[2048];
- unsigned char *p;
-
- va_start (argptr,fmt);
- vsprintf (text,fmt,argptr);
- va_end (argptr);
-
- if (strlen(text) > sizeof(text))
- Sys_Error("memory overwrite in Sys_Printf");
-
- if (nostdout)
- return;
-
- for (p = (unsigned char *)text; *p; p++)
- if ((*p > 128 || *p < 32) && *p != 10 && *p != 13 && *p != 9)
- printf("[%02x]", *p);
+ for(p = buf; *p; p++){
+ *p &= 0x7f;
+ if(*p < 32 && *p != 10 && *p != 13 && *p != 9)
+ print("[%02x]", *p);
else
- putc(*p, stdout);
+ print("%c", *p);
+ }
}
-void Sys_Quit (void)
-{
- Host_Shutdown();
- fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
- exit(0);
-}
-
-void Sys_Init(void)
-{
-#if id386
- Sys_SetFPCW();
-#endif
-}
-
-void Sys_Error (char *error, ...)
+void
+Sys_Error(char *error, ...)
{
- va_list argptr;
- char string[1024];
+ char buf[1024], *out;
+ va_list arg;
-// change stdin to non blocking
- fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
-
- va_start (argptr,error);
- vsprintf (string,error,argptr);
- va_end (argptr);
- fprintf(stderr, "Error: %s\n", string);
-
- Host_Shutdown ();
- exit (1);
-
-}
-
-void Sys_Warn (char *warning, ...)
-{
- va_list argptr;
- char string[1024];
-
- va_start (argptr,warning);
- vsprintf (string,warning,argptr);
- va_end (argptr);
- fprintf(stderr, "Warning: %s", string);
-}
-
-/*
-============
-Sys_FileTime
-
-returns -1 if not present
-============
-*/
-int Sys_FileTime (char *path)
-{
- struct stat buf;
-
- if (stat (path,&buf) == -1)
- return -1;
-
- return buf.st_mtime;
+ va_start(arg, error);
+ out = vseprint(buf, buf+sizeof(buf), error, arg);
+ va_end(arg);
+ out = seprint(out, buf+sizeof(buf), "\n");
+ write(2, buf, out-buf);
+ Host_Shutdown();
+ sysfatal("ending.");
}
-
-void Sys_mkdir (char *path)
+int
+Sys_FileTime(char *path)
{
- mkdir (path, 0777);
-}
+ uchar bs[1024];
-int Sys_FileOpenRead (char *path, int *handle)
-{
- int h;
- struct stat fileinfo;
-
-
- h = open (path, O_RDONLY, 0666);
- *handle = h;
- if (h == -1)
+ if(stat(path, bs, sizeof bs) < 0)
return -1;
-
- if (fstat (h,&fileinfo) == -1)
- Sys_Error ("Error fstating %s", path);
-
- return fileinfo.st_size;
+ return *((int *)(bs+2+2+4+1+4+8+4+4)); /* mtime[4] */
}
-int Sys_FileOpenWrite (char *path)
+void
+Sys_mkdir(char *path)
{
- int handle;
+ int d;
- umask (0);
-
- handle = open(path,O_RDWR | O_CREAT | O_TRUNC
- , 0666);
-
- if (handle == -1)
- Sys_Error ("Error opening %s: %s", path,strerror(errno));
-
- return handle;
+ if((d = create(path, OREAD, DMDIR|0777)) < 0)
+ fprint(2, "Sys_mkdir:create: %r\n");
+ else
+ close(d);
}
-int Sys_FileWrite (int handle, void *src, int count)
+vlong
+flen(int fd)
{
- return write (handle, src, count);
-}
+ uchar bs[1024];
-void Sys_FileClose (int handle)
-{
- close (handle);
+ if(fstat(fd, bs, sizeof bs) < 0){
+ fprint(2, "flen:fstat: %r\n");
+ return -1;
+ }
+ return *((vlong *)(bs+2+2+4+1+4+8+4+4+4)); /* length[8] */
}
-void Sys_FileSeek (int handle, int position)
+vlong
+Sys_FileOpenRead(char *path, int *fd)
{
- lseek (handle, position, SEEK_SET);
+ if((*fd = open(path, OREAD)) < 0)
+ return -1;
+ return flen(*fd);
}
-int Sys_FileRead (int handle, void *dest, int count)
+int
+Sys_FileOpenWrite(char *path)
{
- return read (handle, dest, count);
-}
+ int fd;
-void Sys_DebugLog(char *file, char *fmt, ...)
-{
- va_list argptr;
- static char data[1024];
- int fd;
-
- va_start(argptr, fmt);
- vsprintf(data, fmt, argptr);
- va_end(argptr);
-// fd = open(file, O_WRONLY | O_BINARY | O_CREAT | O_APPEND, 0666);
- fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0666);
- write(fd, data, strlen(data));
- close(fd);
+ if((fd = open(path, OREAD|OTRUNC)) < 0)
+ sysfatal("Sys_FileOpenWrite:open: %r");
+ return fd;
}
-void Sys_EditFile(char *filename)
+double
+Sys_DoubleTime(void)
{
+ static long secbase;
- char cmd[256];
- char *term;
- char *editor;
-
- term = getenv("TERM");
- if (term && !strcmp(term, "xterm"))
- {
- editor = getenv("VISUAL");
- if (!editor)
- editor = getenv("EDITOR");
- if (!editor)
- editor = getenv("EDIT");
- if (!editor)
- editor = "vi";
- sprintf(cmd, "xterm -e %s %s", editor, filename);
- system(cmd);
- }
-
+ if(secbase == 0)
+ secbase = time(nil);
+ return nsec()/1000000000.0 - secbase;
}
-double Sys_DoubleTime (void)
+void
+Sys_HighFPPrecision(void)
{
- struct timeval tp;
- struct timezone tzp;
- static int secbase;
-
- gettimeofday(&tp, &tzp);
-
- if (!secbase)
- {
- secbase = tp.tv_sec;
- return tp.tv_usec/1000000.0;
- }
-
- return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0;
}
-// =======================================================================
-// Sleeps for microseconds
-// =======================================================================
-
-static volatile int oktogo;
-
-void alarm_handler(int x)
+void
+Sys_LowFPPrecision(void)
{
- oktogo=1;
}
-void Sys_LineRefresh(void)
+void
+initparm(quakeparms_t *q)
{
-}
+ int i;
-void floating_point_exception_handler(int whatever)
-{
-// Sys_Warn("floating point exception\n");
- signal(SIGFPE, floating_point_exception_handler);
-}
+ memset(q, 0, sizeof *q);
+ q->argc = com_argc;
+ q->argv = com_argv;
+ q->memsize = 16*1024*1024;
-char *Sys_ConsoleInput(void)
-{
-#if 0
- static char text[256];
- int len;
-
- if (cls.state == ca_dedicated) {
- len = read (0, text, sizeof(text));
- if (len < 1)
- return NULL;
- text[len-1] = 0; // rip off the /n and terminate
-
- return text;
- }
-#endif
- return NULL;
+ if(i = COM_CheckParm("-mem"))
+ q->memsize = atoi(com_argv[i+1]) * 1024*1024;
+ if((q->membase = malloc(q->memsize)) == nil)
+ sysfatal("initparm:malloc: %r");
}
-#if !id386
-void Sys_HighFPPrecision (void)
+void
+Sys_Quit(void)
{
+ Host_Shutdown();
+ threadexitsall(nil);
}
-void Sys_LowFPPrecision (void)
+void
+Sys_Init(void)
{
}
-#endif
-
-int skipframes;
-
-int main (int c, char **v)
-{
-
- double time, oldtime, newtime;
- quakeparms_t parms;
- int j;
-
-// static char cwd[1024];
-
-// signal(SIGFPE, floating_point_exception_handler);
- signal(SIGFPE, SIG_IGN);
-
- memset(&parms, 0, sizeof(parms));
-
- COM_InitArgv(c, v);
- parms.argc = com_argc;
- parms.argv = com_argv;
-
- parms.memsize = 16*1024*1024;
-
- j = COM_CheckParm("-mem");
- if (j)
- parms.memsize = (int) (Q_atof(com_argv[j+1]) * 1024 * 1024);
- parms.membase = malloc (parms.memsize);
-
- parms.basedir = basedir;
-// caching is disabled by default, use -cachedir to enable
-// parms.cachedir = cachedir;
-
- noconinput = COM_CheckParm("-noconinput");
- if (!noconinput)
- fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
-
- if (COM_CheckParm("-nostdout"))
- nostdout = 1;
-
- Sys_Init();
-
- Host_Init(&parms);
-
- oldtime = Sys_DoubleTime ();
- while (1)
- {
-// find time spent rendering last frame
- newtime = Sys_DoubleTime ();
- time = newtime - oldtime;
-
- Host_Frame(time);
- oldtime = newtime;
- }
-
-}
-
-
-/*
-================
-Sys_MakeCodeWriteable
-================
-*/
-void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
-{
-
- int r;
- unsigned long addr;
- int psize = getpagesize();
-
- addr = (startaddr & ~(psize-1)) - psize;
-
-// fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr,
-// addr, startaddr+length, length);
-
- r = mprotect((char*)addr, length + startaddr - addr + psize, 7);
-
- if (r < 0)
- Sys_Error("Protection change failed\n");
-
-}
-
--- a/qw/sys.h
+++ b/qw/sys.h
@@ -1,16 +1,29 @@
// sys.h -- non-portable functions
-int Sys_FileTime (char *path);
+enum{
+ THin = 1,
+ THsnd = 2,
+ THnet = 3
+};
+extern int svonly;
-void Sys_mkdir (char *path);
+vlong Sys_FileOpenRead(char *, int *);
+int Sys_FileOpenWrite(char *);
+int Sys_FileTime(char *);
+void Sys_mkdir(char *);
+vlong flen(int);
-void Sys_Error (char *error, ...);
-// an error will cause the entire program to exit
+void Sys_Error(char *, ...);
+void Sys_Printf(char *, ...);
+void Sys_Quit(void);
+double Sys_DoubleTime(void);
+char *Sys_ConsoleInput(void);
+void Sys_Sleep(void);
+void Sys_SendKeyEvents(void); // Perform Key_Event () callbacks until the input que is empty
+void Sys_LowFPPrecision(void);
+void Sys_HighFPPrecision(void);
+void Sys_SetFPCW(void);
+void Sys_Init(void);
+void initparm(quakeparms_t *);
-void Sys_Printf (char *fmt, ...);
-// send text to the console
-
-void Sys_Quit (void);
-double Sys_DoubleTime (void);
-char *Sys_ConsoleInput (void);
-void Sys_Init (void);
+void killiop(void);
--- a/qw/vid.c
+++ b/qw/vid.c
@@ -1,1075 +1,222 @@
#include <u.h>
#include <libc.h>
+#include <draw.h>
#include <stdio.h>
#include "quakedef.h"
-#include "d_local.h"
-typedef unsigned short PIXEL;
+viddef_t vid;
+ushort d_8to16table[256];
+int resized;
+Point center;
-cvar_t _windowed_mouse = {"_windowed_mouse","0", true};
-cvar_t m_filter = {"m_filter","0", true};
-float old_windowed_mouse;
+void (*vid_menudrawfn)(void);
+void (*vid_menukeyfn)(int);
-// not used
-int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes, VGA_planar;
-byte *VGA_pagebase;
+typedef ulong PIXEL;
+enum{
+ Rmask = 0xff0000,
+ Gmask = 0xff00,
+ Bmask = 0xff
+};
+static int shifton, rshift, gshift, bshift;
+static uchar *framebuf; /* draw buffer */
+static Image *fbim; /* framebuf image */
-qboolean mouse_avail;
-int mouse_buttons=3;
-int mouse_oldbuttonstate;
-int mouse_buttonstate;
-float mouse_x, mouse_y;
-float old_mouse_x, old_mouse_y;
-int p_mouse_x;
-int p_mouse_y;
-int ignorenext;
-int bits_per_pixel;
+static PIXEL st2d_8to16table[256];
-typedef struct
-{
- int input;
- int output;
-} keymap_t;
+static void mkmasks(void);
+static PIXEL rgb24(int, int, int);
+static void st2_fixup(uchar *, int, int, int, int);
+static void resetfb(void);
-viddef_t vid; // global video state
-unsigned short d_8to16table[256];
-int num_shades=32;
-
-int d_con_indirect = 0;
-
-int vid_buffersize;
-
-static qboolean doShm;
-static Display *x_disp;
-static Colormap x_cmap;
-static Window x_win;
-static GC x_gc;
-static Visual *x_vis;
-static XVisualInfo *x_visinfo;
-//static XImage *x_image;
-
-static int x_shmeventtype;
-//static XShmSegmentInfo x_shminfo;
-
-static qboolean oktodraw = false;
-
-int XShmQueryExtension(Display *);
-int XShmGetEventBase(Display *);
-
-int current_framebuffer;
-static XImage *x_framebuffer[2] = { 0, 0 };
-static XShmSegmentInfo x_shminfo[2];
-
-static int verbose=0;
-
-static byte current_palette[768];
-
-static long X11_highhunkmark;
-static long X11_buffersize;
-
-int vid_surfcachesize;
-void *vid_surfcache;
-
-void (*vid_menudrawfn)(void);
-void (*vid_menukeyfn)(int key);
-void VID_MenuKey (int key);
-
-static PIXEL st2d_8to16table[256];
-static int shiftmask_fl=0;
-static long r_shift,g_shift,b_shift;
-static unsigned long r_mask,g_mask,b_mask;
-
-void shiftmask_init()
+static void
+mkmasks(void)
{
- unsigned int x;
- r_mask=x_vis->red_mask;
- g_mask=x_vis->green_mask;
- b_mask=x_vis->blue_mask;
- for(r_shift=-8,x=1;x<r_mask;x=x<<1)r_shift++;
- for(g_shift=-8,x=1;x<g_mask;x=x<<1)g_shift++;
- for(b_shift=-8,x=1;x<b_mask;x=x<<1)b_shift++;
- shiftmask_fl=1;
+ uint x;
+
+ for(rshift = -8, x = 1; x < Rmask; x <<= 1)
+ rshift++;
+ for(gshift = -8, x = 1; x < Gmask; x <<= 1)
+ gshift++;
+ for(bshift = -8, x = 1; x < Bmask; x <<= 1)
+ bshift++;
+ shifton = 1;
}
-PIXEL xlib_rgb(int r,int g,int b)
+static PIXEL
+rgb24(int r, int g, int b)
{
- PIXEL p;
- if(shiftmask_fl==0) shiftmask_init();
- p=0;
+ PIXEL p = 0;
- if(r_shift>0) {
- p=(r<<(r_shift))&r_mask;
- } else if(r_shift<0) {
- p=(r>>(-r_shift))&r_mask;
- } else p|=(r&r_mask);
+ if(!shifton)
+ mkmasks();
- if(g_shift>0) {
- p|=(g<<(g_shift))&g_mask;
- } else if(g_shift<0) {
- p|=(g>>(-g_shift))&g_mask;
- } else p|=(g&g_mask);
-
- if(b_shift>0) {
- p|=(b<<(b_shift))&b_mask;
- } else if(b_shift<0) {
- p|=(b>>(-b_shift))&b_mask;
- } else p|=(b&b_mask);
-
- return p;
+ if(rshift > 0)
+ p = r<<rshift & Rmask;
+ else if(rshift < 0)
+ p = r>>-rshift & Rmask;
+ else
+ p |= r & Rmask;
+ if(gshift > 0)
+ p |= g<<gshift & Gmask;
+ else if(gshift < 0)
+ p |= g>>-gshift & Gmask;
+ else
+ p |= g & Gmask;
+ if(bshift > 0)
+ p |= b<<bshift & Bmask;
+ else if(bshift < 0)
+ p |= b>>-bshift & Bmask;
+ else
+ p |= b & Bmask;
+ return p;
}
-void st2_fixup( XImage *framebuf, int x, int y, int width, int height)
+static void
+st2_fixup(uchar *data, int x, int y, int width, int height)
{
- int xi,yi;
- unsigned char *src;
+ int xi, yi;
+ uchar *src;
PIXEL *dest;
- if( (x<0)||(y<0) )return;
+ if(x < 0 || y < 0)
+ return;
- for (yi = y; yi < (y+height); yi++) {
- src = &framebuf->data [yi * framebuf->bytes_per_line];
- dest = (PIXEL*)src;
- for(xi = (x+width-1); xi >= x; xi--) {
+ for (yi = y; yi < y+height; yi++){
+ src = &data[yi*vid.rowbytes];
+ dest = (PIXEL *)src;
+ for(xi = x+width-1; xi >= x; xi--)
dest[xi] = st2d_8to16table[src[xi]];
- }
}
}
-
-// ========================================================================
-// Tragic death handler
-// ========================================================================
-
-void TragicDeath(int signal_num)
+/* vid.height and vid.width must be set correctly before this call */
+static void
+resetfb(void)
{
- XAutoRepeatOn(x_disp);
- XCloseDisplay(x_disp);
- Sys_Error("This death brought to you by the number %d\n", signal_num);
-}
+ static int highhunk;
+ void *surfcache;
+ int hunkvbuf, scachesz;
-// ========================================================================
-// makes a null cursor
-// ========================================================================
-
-static Cursor CreateNullCursor(Display *display, Window root)
-{
- Pixmap cursormask;
- XGCValues xgc;
- GC gc;
- XColor dummycolour;
- Cursor cursor;
-
- cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/);
- xgc.function = GXclear;
- gc = XCreateGC(display, cursormask, GCFunction, &xgc);
- XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
- dummycolour.pixel = 0;
- dummycolour.red = 0;
- dummycolour.flags = 04;
- cursor = XCreatePixmapCursor(display, cursormask, cursormask,
- &dummycolour,&dummycolour, 0,0);
- XFreePixmap(display,cursormask);
- XFreeGC(display,gc);
- return cursor;
-}
-
-void ResetFrameBuffer(void)
-{
- int mem;
- int pwidth;
-
- if (x_framebuffer[0])
- {
- free(x_framebuffer[0]->data);
- free(x_framebuffer[0]);
+ if(framebuf != nil){
+ free(framebuf);
+ framebuf = nil;
}
-
- if (d_pzbuffer)
- {
- D_FlushCaches ();
- Hunk_FreeToHighMark (X11_highhunkmark);
- d_pzbuffer = NULL;
+ if(d_pzbuffer){
+ D_FlushCaches();
+ Hunk_FreeToHighMark(highhunk);
+ d_pzbuffer = nil;
}
- X11_highhunkmark = Hunk_HighMark ();
-// alloc an extra line in case we want to wrap, and allocate the z-buffer
- X11_buffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
+ highhunk = Hunk_HighMark();
+ // alloc an extra line in case we want to wrap, and allocate the z-buffer
+ hunkvbuf = vid.width * vid.height * sizeof(*d_pzbuffer);
+ scachesz = D_SurfaceCacheForRes(vid.width, vid.height);
+ hunkvbuf += scachesz;
+ if((d_pzbuffer = Hunk_HighAllocName(hunkvbuf, "video")) == nil)
+ sysfatal("Not enough memory for video mode\n");
+ surfcache = (byte *)d_pzbuffer + vid.width * vid.height * sizeof(*d_pzbuffer);
+ D_InitCaches(surfcache, scachesz);
- vid_surfcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
-
- X11_buffersize += vid_surfcachesize;
-
- d_pzbuffer = Hunk_HighAllocName (X11_buffersize, "video");
- if (d_pzbuffer == NULL)
- Sys_Error ("Not enough memory for video mode\n");
-
- vid_surfcache = (byte *) d_pzbuffer
- + vid.width * vid.height * sizeof (*d_pzbuffer);
-
- D_InitCaches(vid_surfcache, vid_surfcachesize);
-
- pwidth = x_visinfo->depth / 8;
- if (pwidth == 3) pwidth = 4;
- mem = ((vid.width*pwidth+7)&~7) * vid.height;
-
- x_framebuffer[0] = XCreateImage( x_disp,
- x_vis,
- x_visinfo->depth,
- ZPixmap,
- 0,
- malloc(mem),
- vid.width, vid.height,
- 32,
- 0);
-
- if (!x_framebuffer[0])
- Sys_Error("VID: XCreateImage failed\n");
-
- vid.buffer = (byte*) (x_framebuffer[0]);
+ framebuf = malloc(sizeof *framebuf * Dx(screen->r) * Dy(screen->r) * screen->depth/8);
+ vid.buffer = framebuf;
+ vid.rowbytes = Dx(screen->r) * screen->depth/8;
+ vid.aspect = (float)vid.height / (float)vid.width * (320.0/240.0); /* FIXME */
vid.conbuffer = vid.buffer;
-
+ vid.conrowbytes = vid.rowbytes;
+ vid.conwidth = vid.width;
+ vid.conheight = vid.height;
+ center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2));
+ if(fbim != nil)
+ freeimage(fbim);
+ fbim = allocimage(display, Rect(0, 0, vid.width, vid.height), screen->chan, 1, DNofill);
}
-void ResetSharedFrameBuffers(void)
-{
-
- int size;
- int key;
- int minsize = getpagesize();
- int frm;
-
- if (d_pzbuffer)
- {
- D_FlushCaches ();
- Hunk_FreeToHighMark (X11_highhunkmark);
- d_pzbuffer = NULL;
- }
-
- X11_highhunkmark = Hunk_HighMark ();
-
-// alloc an extra line in case we want to wrap, and allocate the z-buffer
- X11_buffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
-
- vid_surfcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
-
- X11_buffersize += vid_surfcachesize;
-
- d_pzbuffer = Hunk_HighAllocName (X11_buffersize, "video");
- if (d_pzbuffer == NULL)
- Sys_Error ("Not enough memory for video mode\n");
-
- vid_surfcache = (byte *) d_pzbuffer
- + vid.width * vid.height * sizeof (*d_pzbuffer);
-
- D_InitCaches(vid_surfcache, vid_surfcachesize);
-
- for (frm=0 ; frm<2 ; frm++)
- {
-
- // free up old frame buffer memory
-
- if (x_framebuffer[frm])
- {
- XShmDetach(x_disp, &x_shminfo[frm]);
- free(x_framebuffer[frm]);
- shmdt(x_shminfo[frm].shmaddr);
- }
-
- // create the image
-
- x_framebuffer[frm] = XShmCreateImage( x_disp,
- x_vis,
- x_visinfo->depth,
- ZPixmap,
- 0,
- &x_shminfo[frm],
- vid.width,
- vid.height );
-
- // grab shared memory
-
- size = x_framebuffer[frm]->bytes_per_line
- * x_framebuffer[frm]->height;
- if (size < minsize)
- Sys_Error("VID: Window must use at least %d bytes\n", minsize);
-
- key = random();
- x_shminfo[frm].shmid = shmget((key_t)key, size, IPC_CREAT|0777);
- if (x_shminfo[frm].shmid==-1)
- Sys_Error("VID: Could not get any shared memory\n");
-
- // attach to the shared memory segment
- x_shminfo[frm].shmaddr =
- (void *) shmat(x_shminfo[frm].shmid, 0, 0);
-
- printf("VID: shared memory id=%d, addr=0x%lx\n", x_shminfo[frm].shmid,
- (long) x_shminfo[frm].shmaddr);
-
- x_framebuffer[frm]->data = x_shminfo[frm].shmaddr;
-
- // get the X server to attach to it
-
- if (!XShmAttach(x_disp, &x_shminfo[frm]))
- Sys_Error("VID: XShmAttach() failed\n");
- XSync(x_disp, 0);
- shmctl(x_shminfo[frm].shmid, IPC_RMID, 0);
-
- }
-
-}
-
// Called at startup to set up translation tables, takes 256 8 bit RGB values
// the palette data will go away after the call, so it must be copied off if
// the video driver will need it again
-
-void VID_Init (unsigned char *palette)
+void
+VID_Init(uchar */*palette*/)
{
-
- int pnum, i;
- XVisualInfo template;
- int num_visuals;
- int template_mask;
-
- S_Init();
-
- ignorenext=0;
- vid.width = 320;
- vid.height = 200;
- vid.maxwarpwidth = WARP_WIDTH;
- vid.maxwarpheight = WARP_HEIGHT;
- vid.numpages = 2;
- vid.colormap = host_colormap;
- // vid.cbits = VID_CBITS;
- // vid.grades = VID_GRADES;
- vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
-
- srandom(getpid());
-
- verbose=COM_CheckParm("-verbose");
-
-// open the display
- x_disp = XOpenDisplay(0);
- if (!x_disp)
- {
- if (getenv("DISPLAY"))
- Sys_Error("VID: Could not open display [%s]\n",
- getenv("DISPLAY"));
- else
- Sys_Error("VID: Could not open local display\n");
- }
-
-// catch signals so i can turn on auto-repeat
-
- {
- struct sigaction sa;
- sigaction(SIGINT, 0, &sa);
- sa.sa_handler = TragicDeath;
- sigaction(SIGINT, &sa, 0);
- sigaction(SIGTERM, &sa, 0);
- }
-
- XAutoRepeatOff(x_disp);
-
-// for debugging only
- XSynchronize(x_disp, True);
-
-// check for command-line window size
- if ((pnum=COM_CheckParm("-winsize")))
- {
- if (pnum >= com_argc-2)
- Sys_Error("VID: -winsize <width> <height>\n");
- vid.width = Q_atoi(com_argv[pnum+1]);
- vid.height = Q_atoi(com_argv[pnum+2]);
- if (!vid.width || !vid.height)
- Sys_Error("VID: Bad window width/height\n");
- }
- if ((pnum=COM_CheckParm("-width"))) {
- if (pnum >= com_argc-1)
- Sys_Error("VID: -width <width>\n");
- vid.width = Q_atoi(com_argv[pnum+1]);
- if (!vid.width)
- Sys_Error("VID: Bad window width\n");
- }
- if ((pnum=COM_CheckParm("-height"))) {
- if (pnum >= com_argc-1)
- Sys_Error("VID: -height <height>\n");
- vid.height = Q_atoi(com_argv[pnum+1]);
- if (!vid.height)
- Sys_Error("VID: Bad window height\n");
- }
-
- template_mask = 0;
-
-// specify a visual id
- if ((pnum=COM_CheckParm("-visualid")))
- {
- if (pnum >= com_argc-1)
- Sys_Error("VID: -visualid <id#>\n");
- template.visualid = Q_atoi(com_argv[pnum+1]);
- template_mask = VisualIDMask;
- }
-
-// If not specified, use default visual
- else
- {
- int screen;
- screen = XDefaultScreen(x_disp);
- template.visualid =
- XVisualIDFromVisual(XDefaultVisual(x_disp, screen));
- template_mask = VisualIDMask;
- }
-
-// pick a visual- warn if more than one was available
- x_visinfo = XGetVisualInfo(x_disp, template_mask, &template, &num_visuals);
- if (num_visuals > 1)
- {
- printf("Found more than one visual id at depth %d:\n", template.depth);
- for (i=0 ; i<num_visuals ; i++)
- printf(" -visualid %d\n", (int)(x_visinfo[i].visualid));
- }
- else if (num_visuals == 0)
- {
- if (template_mask == VisualIDMask)
- Sys_Error("VID: Bad visual id %d\n", template.visualid);
- else
- Sys_Error("VID: No visuals at depth %d\n", template.depth);
- }
-
- if (verbose)
- {
- printf("Using visualid %d:\n", (int)(x_visinfo->visualid));
- printf(" screen %d\n", x_visinfo->screen);
- printf(" red_mask 0x%x\n", (int)(x_visinfo->red_mask));
- printf(" green_mask 0x%x\n", (int)(x_visinfo->green_mask));
- printf(" blue_mask 0x%x\n", (int)(x_visinfo->blue_mask));
- printf(" colormap_size %d\n", x_visinfo->colormap_size);
- printf(" bits_per_rgb %d\n", x_visinfo->bits_per_rgb);
- }
-
- x_vis = x_visinfo->visual;
-
-// setup attributes for main window
- {
- int attribmask = CWEventMask | CWColormap | CWBorderPixel;
- XSetWindowAttributes attribs;
- Colormap tmpcmap;
-
- tmpcmap = XCreateColormap(x_disp, XRootWindow(x_disp,
- x_visinfo->screen), x_vis, AllocNone);
-
- attribs.event_mask = StructureNotifyMask | KeyPressMask
- | KeyReleaseMask | ExposureMask | PointerMotionMask |
- ButtonPressMask | ButtonReleaseMask;
- attribs.border_pixel = 0;
- attribs.colormap = tmpcmap;
-
-// create the main window
- x_win = XCreateWindow( x_disp,
- XRootWindow(x_disp, x_visinfo->screen),
- 0, 0, // x, y
- vid.width, vid.height,
- 0, // borderwidth
- x_visinfo->depth,
- InputOutput,
- x_vis,
- attribmask,
- &attribs );
- XStoreName( x_disp,x_win,"xquake");
-
-
- if (x_visinfo->class != TrueColor)
- XFreeColormap(x_disp, tmpcmap);
-
- }
-
- if (x_visinfo->depth == 8)
- {
-
- // create and upload the palette
- if (x_visinfo->class == PseudoColor)
- {
- x_cmap = XCreateColormap(x_disp, x_win, x_vis, AllocAll);
- VID_SetPalette(palette);
- XSetWindowColormap(x_disp, x_win, x_cmap);
- }
-
- }
-
-// inviso cursor
- XDefineCursor(x_disp, x_win, CreateNullCursor(x_disp, x_win));
+ vid.maxwarpwidth = WARP_WIDTH;
+ vid.maxwarpheight = WARP_HEIGHT;
+ vid.numpages = 2;
+ vid.colormap = host_colormap;
+ vid.fullbright = 256 - LittleLong(*((int *)vid.colormap + 2048));
-// create the GC
- {
- XGCValues xgcvalues;
- int valuemask = GCGraphicsExposures;
- xgcvalues.graphics_exposures = False;
- x_gc = XCreateGC(x_disp, x_win, valuemask, &xgcvalues );
- }
+ srand(getpid());
-// map the window
- XMapWindow(x_disp, x_win);
-
-// wait for first exposure event
- {
- XEvent event;
- do
- {
- XNextEvent(x_disp, &event);
- if (event.type == Expose && !event.xexpose.count)
- oktodraw = true;
- } while (!oktodraw);
- }
-// now safe to draw
-
-// even if MITSHM is available, make sure it's a local connection
- if (XShmQueryExtension(x_disp))
- {
- char *displayname;
- doShm = true;
- displayname = (char *) getenv("DISPLAY");
- if (displayname)
- {
- char *d = displayname;
- while (*d && (*d != ':')) d++;
- if (*d) *d = 0;
- if (!(!strcasecmp(displayname, "unix") || !*displayname))
- doShm = false;
- }
- }
-
- if (doShm)
- {
- x_shmeventtype = XShmGetEventBase(x_disp) + ShmCompletion;
- ResetSharedFrameBuffers();
- }
- else
- ResetFrameBuffer();
-
- current_framebuffer = 0;
- vid.rowbytes = x_framebuffer[0]->bytes_per_line;
- vid.buffer = x_framebuffer[0]->data;
+ if(initdraw(nil, nil, "quake") < 0)
+ sysfatal("VID_Init:initdraw: %r\n");
+ vid.width = Dx(screen->r);
+ vid.height = Dy(screen->r);
+ resetfb();
vid.direct = 0;
- vid.conbuffer = x_framebuffer[0]->data;
- vid.conrowbytes = vid.rowbytes;
- vid.conwidth = vid.width;
- vid.conheight = vid.height;
- vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
-
-// XSynchronize(x_disp, False);
-
}
-void VID_ShiftPalette(unsigned char *p)
+void
+VID_ShiftPalette(uchar *p)
{
VID_SetPalette(p);
}
-
-
-void VID_SetPalette(unsigned char *palette)
+void
+VID_SetPalette(uchar *palette)
{
-
int i;
- XColor colors[256];
- for(i=0;i<256;i++)
- st2d_8to16table[i]= xlib_rgb(palette[i*3],
- palette[i*3+1],palette[i*3+2]);
-
- if (x_visinfo->class == PseudoColor && x_visinfo->depth == 8)
- {
- if (palette != current_palette)
- memcpy(current_palette, palette, 768);
- for (i=0 ; i<256 ; i++)
- {
- colors[i].pixel = i;
- colors[i].flags = DoRed|DoGreen|DoBlue;
- colors[i].red = palette[i*3] * 257;
- colors[i].green = palette[i*3+1] * 257;
- colors[i].blue = palette[i*3+2] * 257;
- }
- XStoreColors(x_disp, x_cmap, colors, 256);
- }
-
+ for(i = 0; i < 256; i++)
+ st2d_8to16table[i] = rgb24(palette[i*3], palette[i*3+1], palette[i*3+2]);
}
-// Called at shutdown
-
-void VID_Shutdown (void)
+void
+VID_Shutdown(void)
{
Con_Printf("VID_Shutdown\n");
- XAutoRepeatOn(x_disp);
- XCloseDisplay(x_disp);
+ free(framebuf);
+ freeimage(fbim);
}
-int XLateKey(XKeyEvent *ev)
+void
+VID_Update(vrect_t *rects)
{
-
- int key;
- char buf[64];
- KeySym keysym;
-
- key = 0;
-
- XLookupString(ev, buf, sizeof buf, &keysym, 0);
-
- switch(keysym)
- {
- case XK_KP_Page_Up:
- case XK_Page_Up: key = K_PGUP; break;
-
- case XK_KP_Page_Down:
- case XK_Page_Down: key = K_PGDN; break;
-
- case XK_KP_Home:
- case XK_Home: key = K_HOME; break;
-
- case XK_KP_End:
- case XK_End: key = K_END; break;
-
- case XK_KP_Left:
- case XK_Left: key = K_LEFTARROW; break;
-
- case XK_KP_Right:
- case XK_Right: key = K_RIGHTARROW; break;
-
- case XK_KP_Down:
- case XK_Down: key = K_DOWNARROW; break;
-
- case XK_KP_Up:
- case XK_Up: key = K_UPARROW; break;
-
- case XK_Escape: key = K_ESCAPE; break;
-
- case XK_KP_Enter:
- case XK_Return: key = K_ENTER; break;
-
- case XK_Tab: key = K_TAB; break;
-
- case XK_F1: key = K_F1; break;
-
- case XK_F2: key = K_F2; break;
-
- case XK_F3: key = K_F3; break;
-
- case XK_F4: key = K_F4; break;
-
- case XK_F5: key = K_F5; break;
-
- case XK_F6: key = K_F6; break;
-
- case XK_F7: key = K_F7; break;
-
- case XK_F8: key = K_F8; break;
-
- case XK_F9: key = K_F9; break;
-
- case XK_F10: key = K_F10; break;
-
- case XK_F11: key = K_F11; break;
-
- case XK_F12: key = K_F12; break;
-
- case XK_BackSpace: key = K_BACKSPACE; break;
-
- case XK_KP_Delete:
- case XK_Delete: key = K_DEL; break;
-
- case XK_Pause: key = K_PAUSE; break;
-
- case XK_Shift_L:
- case XK_Shift_R: key = K_SHIFT; break;
-
- case XK_Execute:
- case XK_Control_L:
- case XK_Control_R: key = K_CTRL; break;
-
- case XK_Alt_L:
- case XK_Meta_L:
- case XK_Alt_R:
- case XK_Meta_R: key = K_ALT; break;
-
- case XK_KP_Begin: key = K_AUX30; break;
-
- case XK_Insert:
- case XK_KP_Insert: key = K_INS; break;
-
- case XK_KP_Multiply: key = '*'; break;
- case XK_KP_Add: key = '+'; break;
- case XK_KP_Subtract: key = '-'; break;
- case XK_KP_Divide: key = '/'; break;
-
-#if 0
- case 0x021: key = '1';break;/* [!] */
- case 0x040: key = '2';break;/* [@] */
- case 0x023: key = '3';break;/* [#] */
- case 0x024: key = '4';break;/* [$] */
- case 0x025: key = '5';break;/* [%] */
- case 0x05e: key = '6';break;/* [^] */
- case 0x026: key = '7';break;/* [&] */
- case 0x02a: key = '8';break;/* [*] */
- case 0x028: key = '9';;break;/* [(] */
- case 0x029: key = '0';break;/* [)] */
- case 0x05f: key = '-';break;/* [_] */
- case 0x02b: key = '=';break;/* [+] */
- case 0x07c: key = '\'';break;/* [|] */
- case 0x07d: key = '[';break;/* [}] */
- case 0x07b: key = ']';break;/* [{] */
- case 0x022: key = '\'';break;/* ["] */
- case 0x03a: key = ';';break;/* [:] */
- case 0x03f: key = '/';break;/* [?] */
- case 0x03e: key = '.';break;/* [>] */
- case 0x03c: key = ',';break;/* [<] */
-#endif
-
- default:
- key = *(unsigned char*)buf;
- if (key >= 'A' && key <= 'Z')
- key = key - 'A' + 'a';
-// fprintf(stdout, "case 0x0%x: key = ___;break;/* [%c] */\n", keysym);
- break;
- }
-
- return key;
-}
-
-struct
-{
- int key;
- int down;
-} keyq[64];
-int keyq_head=0;
-int keyq_tail=0;
-
-int config_notify=0;
-int config_notify_width;
-int config_notify_height;
-
-void GetEvent(void)
-{
- XEvent x_event;
- int b;
-
- XNextEvent(x_disp, &x_event);
- switch(x_event.type) {
- case KeyPress:
- keyq[keyq_head].key = XLateKey(&x_event.xkey);
- keyq[keyq_head].down = true;
- keyq_head = (keyq_head + 1) & 63;
- break;
- case KeyRelease:
- keyq[keyq_head].key = XLateKey(&x_event.xkey);
- keyq[keyq_head].down = false;
- keyq_head = (keyq_head + 1) & 63;
- break;
-
- case MotionNotify:
- if (_windowed_mouse.value) {
- mouse_x = (float) ((int)x_event.xmotion.x - (int)(vid.width/2));
- mouse_y = (float) ((int)x_event.xmotion.y - (int)(vid.height/2));
-//printf("m: x=%d,y=%d, mx=%3.2f,my=%3.2f\n",
-// x_event.xmotion.x, x_event.xmotion.y, mouse_x, mouse_y);
-
- /* move the mouse to the window center again */
- XSelectInput(x_disp,x_win,StructureNotifyMask|KeyPressMask
- |KeyReleaseMask|ExposureMask
- |ButtonPressMask
- |ButtonReleaseMask);
- XWarpPointer(x_disp,None,x_win,0,0,0,0,
- (vid.width/2),(vid.height/2));
- XSelectInput(x_disp,x_win,StructureNotifyMask|KeyPressMask
- |KeyReleaseMask|ExposureMask
- |PointerMotionMask|ButtonPressMask
- |ButtonReleaseMask);
- } else {
- mouse_x = (float) (x_event.xmotion.x-p_mouse_x);
- mouse_y = (float) (x_event.xmotion.y-p_mouse_y);
- p_mouse_x=x_event.xmotion.x;
- p_mouse_y=x_event.xmotion.y;
- }
- break;
-
- case ButtonPress:
- b=-1;
- if (x_event.xbutton.button == 1)
- b = 0;
- else if (x_event.xbutton.button == 2)
- b = 2;
- else if (x_event.xbutton.button == 3)
- b = 1;
- if (b>=0)
- mouse_buttonstate |= 1<<b;
- break;
-
- case ButtonRelease:
- b=-1;
- if (x_event.xbutton.button == 1)
- b = 0;
- else if (x_event.xbutton.button == 2)
- b = 2;
- else if (x_event.xbutton.button == 3)
- b = 1;
- if (b>=0)
- mouse_buttonstate &= ~(1<<b);
- break;
-
- case ConfigureNotify:
-//printf("config notify\n");
- config_notify_width = x_event.xconfigure.width;
- config_notify_height = x_event.xconfigure.height;
- config_notify = 1;
- break;
-
- default:
- if (doShm && x_event.type == x_shmeventtype)
- oktodraw = true;
- }
-
- if (old_windowed_mouse != _windowed_mouse.value) {
- old_windowed_mouse = _windowed_mouse.value;
-
- if (!_windowed_mouse.value) {
- /* ungrab the pointer */
- XUngrabPointer(x_disp,CurrentTime);
- } else {
- /* grab the pointer */
- XGrabPointer(x_disp,x_win,True,0,GrabModeAsync,
- GrabModeAsync,x_win,None,CurrentTime);
- }
- }
-}
-
-// flushes the given rectangles from the view buffer to the screen
-
-void VID_Update (vrect_t *rects)
-{
-
-// if the window changes dimension, skip this frame
-
- if (config_notify)
- {
- fprintf(stderr, "config notify\n");
- config_notify = 0;
- vid.width = config_notify_width & ~7;
- vid.height = config_notify_height;
- if (doShm)
- ResetSharedFrameBuffers();
- else
- ResetFrameBuffer();
- vid.rowbytes = x_framebuffer[0]->bytes_per_line;
- vid.buffer = x_framebuffer[current_framebuffer]->data;
- vid.conbuffer = vid.buffer;
- vid.conwidth = vid.width;
- vid.conheight = vid.height;
- vid.conrowbytes = vid.rowbytes;
- vid.recalc_refdef = 1; // force a surface cache flush
+ if(resized){ /* skip this frame if window resize */
+ resized = 0;
+ if(getwindow(display, Refnone) < 0)
+ sysfatal("VID_Update:getwindow: %r\n");
+ vid.width = Dx(screen->r);
+ vid.height = Dy(screen->r);
+ resetfb();
+ vid.recalc_refdef = 1; /* force a surface cache flush */
Con_CheckResize();
Con_Clear_f();
return;
}
- if (doShm)
- {
+ scr_fullupdate = 0; /* force full update if not 8bit (cf. screen.h) */
- while (rects)
- {
- if (x_visinfo->depth != 8)
- st2_fixup( x_framebuffer[current_framebuffer],
- rects->x, rects->y, rects->width,
- rects->height);
- if (!XShmPutImage(x_disp, x_win, x_gc,
- x_framebuffer[current_framebuffer], rects->x, rects->y,
- rects->x, rects->y, rects->width, rects->height, True))
- Sys_Error("VID_Update: XShmPutImage failed\n");
- oktodraw = false;
- while (!oktodraw) GetEvent();
- rects = rects->pnext;
- }
- current_framebuffer = !current_framebuffer;
- vid.buffer = x_framebuffer[current_framebuffer]->data;
- vid.conbuffer = vid.buffer;
- XSync(x_disp, False);
+ while(rects){
+ st2_fixup(framebuf, rects->x, rects->y, rects->width, rects->height);
+ rects = rects->pnext;
}
- else
- {
- while (rects)
- {
- if (x_visinfo->depth != 8)
- st2_fixup( x_framebuffer[current_framebuffer],
- rects->x, rects->y, rects->width,
- rects->height);
- XPutImage(x_disp, x_win, x_gc, x_framebuffer[0], rects->x,
- rects->y, rects->x, rects->y, rects->width, rects->height);
- rects = rects->pnext;
- }
- XSync(x_disp, False);
- }
-
+ loadimage(fbim, fbim->r, framebuf, vid.height * vid.rowbytes);
+ draw(screen, screen->r, fbim, nil, ZP);
+ flushimage(display, 1);
}
-static int dither;
-
-void VID_DitherOn(void)
+/* direct drawing of the "accessing disk" icon */
+void
+D_BeginDirectRect(int /*x*/, int /*y*/, byte */*pbitmap*/, int /*width*/, int /*height*/)
{
- if (dither == 0)
- {
- vid.recalc_refdef = 1;
- dither = 1;
- }
}
-void VID_DitherOff(void)
+void
+D_EndDirectRect(int /*x*/, int /*y*/, int /*width*/, int /*height*/)
{
- if (dither)
- {
- vid.recalc_refdef = 1;
- dither = 0;
- }
}
-int Sys_OpenWindow(void)
-{
- return 0;
-}
-
-void Sys_EraseWindow(int window)
-{
-}
-
-void Sys_DrawCircle(int window, int x, int y, int r)
-{
-}
-
-void Sys_DisplayWindow(int window)
-{
-}
-
-void Sys_SendKeyEvents(void)
-{
-// get events from x server
- if (x_disp)
- {
- while (XPending(x_disp)) GetEvent();
- while (keyq_head != keyq_tail)
- {
- Key_Event(keyq[keyq_tail].key, keyq[keyq_tail].down);
- keyq_tail = (keyq_tail + 1) & 63;
- }
- }
-}
-
-#if 0
-char *Sys_ConsoleInput (void)
-{
-
- static char text[256];
- int len;
- fd_set readfds;
- int ready;
- struct timeval timeout;
-
- timeout.tv_sec = 0;
- timeout.tv_usec = 0;
- FD_ZERO(&readfds);
- FD_SET(0, &readfds);
- ready = select(1, &readfds, 0, 0, &timeout);
-
- if (ready>0)
- {
- len = read (0, text, sizeof(text));
- if (len >= 1)
- {
- text[len-1] = 0; // rip off the /n and terminate
- return text;
- }
- }
-
- return 0;
-
-}
-#endif
-
-void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
-{
-// direct drawing of the "accessing disk" icon isn't supported under Linux
-}
-
-void D_EndDirectRect (int x, int y, int width, int height)
-{
-// direct drawing of the "accessing disk" icon isn't supported under Linux
-}
-
-void IN_Init (void)
-{
- Cvar_RegisterVariable (&_windowed_mouse);
- Cvar_RegisterVariable (&m_filter);
- if ( COM_CheckParm ("-nomouse") )
- return;
- mouse_x = mouse_y = 0.0;
- mouse_avail = 1;
-}
-
-void IN_Shutdown (void)
-{
- mouse_avail = 0;
-}
-
-void IN_Commands (void)
-{
- int i;
-
- if (!mouse_avail) return;
-
- for (i=0 ; i<mouse_buttons ; i++) {
- if ( (mouse_buttonstate & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) )
- Key_Event (K_MOUSE1 + i, true);
-
- if ( !(mouse_buttonstate & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) )
- Key_Event (K_MOUSE1 + i, false);
- }
- mouse_oldbuttonstate = mouse_buttonstate;
-}
-
-void IN_Move (usercmd_t *cmd)
-{
- if (!mouse_avail)
- return;
-
- if (m_filter.value) {
- mouse_x = (mouse_x + old_mouse_x) * 0.5;
- mouse_y = (mouse_y + old_mouse_y) * 0.5;
- }
-
- old_mouse_x = mouse_x;
- old_mouse_y = mouse_y;
-
- mouse_x *= sensitivity.value;
- mouse_y *= sensitivity.value;
-
- if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
- cmd->sidemove += m_side.value * mouse_x;
- else
- cl.viewangles[YAW] -= m_yaw.value * mouse_x;
- if (in_mlook.state & 1)
- V_StopPitchDrift ();
-
- if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) {
- cl.viewangles[PITCH] += m_pitch.value * mouse_y;
- if (cl.viewangles[PITCH] > 80)
- cl.viewangles[PITCH] = 80;
- if (cl.viewangles[PITCH] < -70)
- cl.viewangles[PITCH] = -70;
- } else {
- if ((in_strafe.state & 1) && noclip_anglehack)
- cmd->upmove -= m_forward.value * mouse_y;
- else
- cmd->forwardmove -= m_forward.value * mouse_y;
- }
- mouse_x = mouse_y = 0.0;
-}
-
void VID_LockBuffer (void)
{
}
@@ -1077,4 +224,3 @@
void VID_UnlockBuffer (void)
{
}
-
--- a/qw/vid.h
+++ b/qw/vid.h
@@ -1,3 +1,5 @@
+// vid.h -- video driver defs
+
#define VID_CBITS 6
#define VID_GRADES (1 << VID_CBITS)
@@ -35,8 +37,6 @@
extern viddef_t vid; // global video state
extern unsigned short d_8to16table[256];
extern unsigned d_8to24table[256];
-extern void (*vid_menudrawfn)(void);
-extern void (*vid_menukeyfn)(int key);
void VID_SetPalette (unsigned char *palette);
// called at startup and after any gamma correction
@@ -64,8 +64,3 @@
void VID_LockBuffer (void);
void VID_UnlockBuffer (void);
-
-#ifdef GLQUAKE
-qboolean VID_Is8bit(void);
-#endif
-
--- a/qw/view.c
+++ b/qw/view.c
@@ -4,15 +4,12 @@
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
-#include "r_local.h"
/*
-
The view is allowed to move slightly from it's true position for bobbing,
but if it exceeds 8 pixels linear distance (spherical, not box), the list of
entities sent from the server may not include everything in the pvs, especially
when crossing a water boudnary.
-
*/
cvar_t lcd_x = {"lcd_x", "0"}; // FIXME: make this work sometime...
@@ -43,10 +40,6 @@
cvar_t cl_crossx = {"cl_crossx", "0", true};
cvar_t cl_crossy = {"cl_crossy", "0", true};
-#ifdef GLQUAKE
-cvar_t gl_cshiftpercent = {"gl_cshiftpercent", "100", false};
-#endif
-
cvar_t v_contentblend = {"v_contentblend", "1", false};
float v_dmg_time, v_dmg_roll, v_dmg_pitch;
@@ -135,12 +128,8 @@
void V_StartPitchDrift (void)
{
-#if 1
if (cl.laststop == cl.time)
- {
return; // something else is keeping it from drifting
- }
-#endif
if (cl.nodrift || !cl.pitchvel)
{
cl.pitchvel = v_centerspeed.value;
@@ -251,11 +240,6 @@
byte gammatable[256]; // palette is sent through this
-#ifdef GLQUAKE
-byte ramps[3][256];
-float v_blend[4]; // rgba 0.0 - 1.0
-#endif // GLQUAKE
-
void BuildGammaTable (float g)
{
int i, inf;
@@ -469,55 +453,9 @@
/*
=============
-V_CalcBlend
-=============
-*/
-#ifdef GLQUAKE
-void V_CalcBlend (void)
-{
- float r, g, b, a, a2;
- int j;
-
- r = 0;
- g = 0;
- b = 0;
- a = 0;
-
- for (j=0 ; j<NUM_CSHIFTS ; j++)
- {
- if (!gl_cshiftpercent.value)
- continue;
-
- a2 = ((cl.cshifts[j].percent * gl_cshiftpercent.value) / 100.0) / 255.0;
-
-// a2 = (cl.cshifts[j].percent/2)/255.0;
- if (!a2)
- continue;
- a = a + a2*(1-a);
-//Con_Printf ("j:%i a:%f\n", j, a);
- a2 = a2/a;
- r = r*(1-a2) + cl.cshifts[j].destcolor[0]*a2;
- g = g*(1-a2) + cl.cshifts[j].destcolor[1]*a2;
- b = b*(1-a2) + cl.cshifts[j].destcolor[2]*a2;
- }
-
- v_blend[0] = r/255.0;
- v_blend[1] = g/255.0;
- v_blend[2] = b/255.0;
- v_blend[3] = a;
- if (v_blend[3] > 1)
- v_blend[3] = 1;
- if (v_blend[3] < 0)
- v_blend[3] = 0;
-}
-#endif
-
-/*
-=============
V_UpdatePalette
=============
*/
-#ifdef GLQUAKE
void V_UpdatePalette (void)
{
int i, j;
@@ -524,100 +462,6 @@
qboolean new;
byte *basepal, *newpal;
byte pal[768];
- float r,g,b,a;
- int ir, ig, ib;
- qboolean force;
-
- V_CalcPowerupCshift ();
-
- new = false;
-
- for (i=0 ; i<NUM_CSHIFTS ; i++)
- {
- if (cl.cshifts[i].percent != cl.prev_cshifts[i].percent)
- {
- new = true;
- cl.prev_cshifts[i].percent = cl.cshifts[i].percent;
- }
- for (j=0 ; j<3 ; j++)
- if (cl.cshifts[i].destcolor[j] != cl.prev_cshifts[i].destcolor[j])
- {
- new = true;
- cl.prev_cshifts[i].destcolor[j] = cl.cshifts[i].destcolor[j];
- }
- }
-
-// drop the damage value
- cl.cshifts[CSHIFT_DAMAGE].percent -= host_frametime*150;
- if (cl.cshifts[CSHIFT_DAMAGE].percent <= 0)
- cl.cshifts[CSHIFT_DAMAGE].percent = 0;
-
-// drop the bonus value
- cl.cshifts[CSHIFT_BONUS].percent -= host_frametime*100;
- if (cl.cshifts[CSHIFT_BONUS].percent <= 0)
- cl.cshifts[CSHIFT_BONUS].percent = 0;
-
- force = V_CheckGamma ();
- if (!new && !force)
- return;
-
- V_CalcBlend ();
-
-//Con_Printf("b: %4.2f %4.2f %4.2f %4.6f\n", v_blend[0], v_blend[1], v_blend[2], v_blend[3]);
-
- a = v_blend[3];
- r = 255*v_blend[0]*a;
- g = 255*v_blend[1]*a;
- b = 255*v_blend[2]*a;
-
- a = 1-a;
- for (i=0 ; i<256 ; i++)
- {
- ir = i*a + r;
- ig = i*a + g;
- ib = i*a + b;
- if (ir > 255)
- ir = 255;
- if (ig > 255)
- ig = 255;
- if (ib > 255)
- ib = 255;
-
- ramps[0][i] = gammatable[ir];
- ramps[1][i] = gammatable[ig];
- ramps[2][i] = gammatable[ib];
- }
-
- basepal = host_basepal;
- newpal = pal;
-
- for (i=0 ; i<256 ; i++)
- {
- ir = basepal[0];
- ig = basepal[1];
- ib = basepal[2];
- basepal += 3;
-
- newpal[0] = ramps[0][ir];
- newpal[1] = ramps[1][ig];
- newpal[2] = ramps[2][ib];
- newpal += 3;
- }
-
- VID_ShiftPalette (pal);
-}
-#else // !GLQUAKE
-/*
-=============
-V_UpdatePalette
-=============
-*/
-void V_UpdatePalette (void)
-{
- int i, j;
- qboolean new;
- byte *basepal, *newpal;
- byte pal[768];
int r,g,b;
qboolean force;
@@ -680,8 +524,6 @@
VID_ShiftPalette (pal);
}
-#endif // !GLQUAKE
-
/*
==============================================================================
@@ -998,11 +840,8 @@
R_PushDlights ();
R_RenderView ();
-#ifndef GLQUAKE
if (crosshair.value)
- Draw_Crosshair();
-#endif
-
+ Draw_Crosshair();
}
//============================================================================
@@ -1035,9 +874,6 @@
Cvar_RegisterVariable (&crosshair);
Cvar_RegisterVariable (&cl_crossx);
Cvar_RegisterVariable (&cl_crossy);
-#ifdef GLQUAKE
- Cvar_RegisterVariable (&gl_cshiftpercent);
-#endif
Cvar_RegisterVariable (&cl_rollspeed);
Cvar_RegisterVariable (&cl_rollangle);
--- a/qw/view.h
+++ b/qw/view.h
@@ -1,11 +1,7 @@
extern cvar_t v_gamma;
extern cvar_t lcd_x;
-#ifdef GLQUAKE
-extern float v_blend[4];
-#endif
void V_Init (void);
void V_RenderView (void);
float V_CalcRoll (vec3_t angles, vec3_t velocity);
void V_UpdatePalette (void);
-
--- a/qw/world.c
+++ b/qw/world.c
@@ -3,14 +3,12 @@
#include <u.h>
#include <libc.h>
#include <stdio.h>
-#include "qwsvdef.h"
+#include "quakedef.h"
/*
-
entities never clip against themselves, or their owner
line of sight checks trace->crosscontent, but bullets don't
-
*/
@@ -426,8 +424,6 @@
===============================================================================
*/
-#if !id386
-
/*
==================
SV_HullPointContents
@@ -461,9 +457,6 @@
return num;
}
-#endif // !id386
-
-
/*
==================
SV_PointContents
@@ -560,18 +553,17 @@
t1 = DotProduct (plane->normal, p1) - plane->dist;
t2 = DotProduct (plane->normal, p2) - plane->dist;
}
-
-#if 1
- if (t1 >= 0 && t2 >= 0)
- return SV_RecursiveHullCheck (hull, node->children[0], p1f, p2f, p1, p2, trace);
- if (t1 < 0 && t2 < 0)
- return SV_RecursiveHullCheck (hull, node->children[1], p1f, p2f, p1, p2, trace);
-#else
+
+ /*
if ( (t1 >= DIST_EPSILON && t2 >= DIST_EPSILON) || (t2 > t1 && t1 >= 0) )
return SV_RecursiveHullCheck (hull, node->children[0], p1f, p2f, p1, p2, trace);
if ( (t1 <= -DIST_EPSILON && t2 <= -DIST_EPSILON) || (t2 < t1 && t1 <= 0) )
return SV_RecursiveHullCheck (hull, node->children[1], p1f, p2f, p1, p2, trace);
-#endif
+ */
+ if (t1 >= 0 && t2 >= 0)
+ return SV_RecursiveHullCheck (hull, node->children[0], p1f, p2f, p1, p2, trace);
+ if (t1 < 0 && t2 < 0)
+ return SV_RecursiveHullCheck (hull, node->children[1], p1f, p2f, p1, p2, trace);
// put the crosspoint DIST_EPSILON pixels on the near side
if (t1 < 0)
@@ -594,10 +586,9 @@
return false;
#ifdef PARANOID
- if (SV_HullPointContents (sv_hullmodel, mid, node->children[side])
- == CONTENTS_SOLID)
- {
- Con_Printf ("mid PointInHullSolid\n");
+// if (SV_HullPointContents (sv_hullmodel, mid, node->children[side]) == CONTENTS_SOLID)
+ if(SV_HullPointContents(hull, node->children[side], mid) == CONTENTS_SOLID){
+ Con_Printf("mid PointInHullSolid\n");
return false;
}
#endif
@@ -778,11 +769,11 @@
*/
void SV_MoveBounds (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, vec3_t boxmins, vec3_t boxmaxs)
{
-#if 0
-// debug to test against everything
-boxmins[0] = boxmins[1] = boxmins[2] = -9999;
-boxmaxs[0] = boxmaxs[1] = boxmaxs[2] = 9999;
-#else
+ /* debug to test against everything
+ boxmins[0] = boxmins[1] = boxmins[2] = -9999;
+ boxmaxs[0] = boxmaxs[1] = boxmaxs[2] = 9999;
+ */
+
int i;
for (i=0 ; i<3 ; i++)
@@ -798,7 +789,6 @@
boxmaxs[i] = start[i] + maxs[i] + 1;
}
}
-#endif
}
/*
--- a/qw/zone.c
+++ b/qw/zone.c
@@ -115,22 +115,16 @@
}
}
-
-/*
-========================
-Z_Malloc
-========================
-*/
-void *Z_Malloc (int size)
+void *
+Z_Malloc(int size)
{
- void *buf;
+ void *buf;
-Z_CheckHeap (); // DEBUG
- buf = Z_TagMalloc (size, 1);
- if (!buf)
- Sys_Error ("Z_Malloc: failed on allocation of %i bytes",size);
- Q_memset (buf, 0, size);
+ Z_CheckHeap(); // DEBUG
+ if((buf = Z_TagMalloc(size, 1)) == nil)
+ Sys_Error("Z_Malloc: failed on allocation of %d bytes", size);
+ memset(buf, 0, size);
return buf;
}
@@ -392,12 +386,7 @@
size = sizeof(hunk_t) + ((size+15)&~15);
if (hunk_size - hunk_low_used - hunk_high_used < size)
-// Sys_Error ("Hunk_Alloc: failed on %i bytes",size);
-#ifdef _WIN32
- Sys_Error ("Not enough RAM allocated. Try starting using \"-heapsize 16000\" on the QuakeWorld command line.");
-#else
- Sys_Error ("Not enough RAM allocated. Try starting using \"-mem 16\" on the QuakeWorld command line.");
-#endif
+ Sys_Error ("Hunk_Alloc: failed on %i bytes",size);
h = (hunk_t *)(hunk_base + hunk_low_used);
hunk_low_used += size;
@@ -408,7 +397,7 @@
h->size = size;
h->sentinal = HUNK_SENTINAL;
- Q_strncpy (h->name, name, 8);
+ strncpy(h->name, name, 8);
return (void *)(h+1);
}
@@ -499,7 +488,7 @@
memset (h, 0, size);
h->size = size;
h->sentinal = HUNK_SENTINAL;
- Q_strncpy (h->name, name, 8);
+ strncpy(h->name, name, 8);
return (void *)(h+1);
}
@@ -569,9 +558,9 @@
{
// Con_Printf ("cache_move ok\n");
- Q_memcpy ( new+1, c+1, c->size - sizeof(cache_system_t) );
+ memcpy(new+1, c+1, c->size - sizeof(cache_system_t));
new->user = c->user;
- Q_memcpy (new->name, c->name, sizeof(new->name));
+ memcpy(new->name, c->name, sizeof(new->name));
Cache_Free (c->user);
new->user->data = (void *)(new+1);
}
--- a/qw/zone.h
+++ b/qw/zone.h
@@ -1,7 +1,4 @@
-/*
- memory allocation
-
-
+/* memory allocation
H_??? The hunk manages the entire memory block given to quake. It must be
contiguous. Memory can be allocated from either the low or high end in a
stack fashion. The only way memory is released is by resetting one of the
@@ -59,9 +56,6 @@
Zone block
----- Bottom of Memory -----
-
-
-
*/
void Memory_Init (void *buf, int size);
@@ -107,6 +101,3 @@
// wasn't enough room.
void Cache_Report (void);
-
-
-