ref: facd1d4e9b6a5c1cd9c5faf96f7520c62746144b
parent: aff29f25c0e72554e533162fc4d2ba69a8009fdb
author: Konstantinn Bonnet <[email protected]>
date: Sun Jan 29 21:06:49 EST 2017
reimplement common.c file reading shit using libbio - nuke -path, -proghack, -cachedir: useless - remove static_registered check: eat me - remove exit text: just exit already - #pragma varargck argpos for all va functions
--- a/cl_demo.c
+++ b/cl_demo.c
@@ -3,348 +3,165 @@
#include <stdio.h>
#include "quakedef.h"
-void CL_FinishTimeDemo (void);
-
-/*
-==============================================================================
-
-DEMO CODE
-
-When a demo is playing back, all NET_SendMessages are skipped, and
-NET_GetMessages are read from the demo file.
-
-Whenever cl.time gets past the last received message, another message is
-read from the demo file.
-==============================================================================
-*/
-
-/*
-==============
-CL_StopPlayback
-
-Called when a demo file runs out, or the user starts a game
-==============
-*/
-void CL_StopPlayback (void)
+static void
+dmtimeend(void)
{
- if (!cls.demoplayback)
- return;
+ int f;
+ float t;
- fclose (cls.demofile);
- cls.demoplayback = false;
- cls.demofile = NULL;
- cls.state = ca_disconnected;
-
- if (cls.timedemo)
- CL_FinishTimeDemo ();
+ cls.timedemo = 0;
+ f = host_framecount - cls.td_startframe - 1;
+ t = realtime - cls.td_starttime;
+ if(t == 0.0)
+ t = 1;
+ Con_Printf("%d frames %5.1f seconds %5.1f fps\n", f, t, f/t);
}
-/*
-====================
-CL_WriteDemoMessage
-
-Dumps the current net message, prefixed by the length and view angles
-====================
-*/
-void CL_WriteDemoMessage (void)
+static int
+dmmsg(void)
{
- int len;
- int i;
- float f;
-
- len = LittleLong (net_message.cursize);
- fwrite (&len, 4, 1, cls.demofile);
- for (i=0 ; i<3 ; i++)
- {
- f = LittleFloat (cl.viewangles[i]);
- fwrite (&f, 4, 1, cls.demofile);
+ if(cls.signon == SIGNONS){
+ if(cls.timedemo){
+ if(host_framecount == cls.td_lastframe)
+ return 0;
+ cls.td_lastframe = host_framecount;
+ if(host_framecount == cls.td_startframe + 1)
+ cls.td_starttime = realtime;
+ }else if(cl.time <= cl.mtime[0])
+ return 0;
}
- fwrite (net_message.data, net_message.cursize, 1, cls.demofile);
- fflush (cls.demofile);
+ if(rlmpmsg() < 0){
+ abortdemo();
+ return 0;
+ }
+ return 1;
}
-/*
-====================
-CL_GetMessage
-
-Handles recording and playback of demos, on top of NET_ code
-====================
-*/
-int CL_GetMessage (void)
+int
+clmsg(void)
{
- int r, i;
- float f;
-
- if (cls.demoplayback)
- {
- // decide if it is time to grab the next message
- if (cls.signon == SIGNONS) // allways grab until fully connected
- {
- if (cls.timedemo)
- {
- if (host_framecount == cls.td_lastframe)
- return 0; // allready read this frame's message
- cls.td_lastframe = host_framecount;
- // if this is the second frame, grab the real td_starttime
- // so the bogus time on the first frame doesn't count
- if (host_framecount == cls.td_startframe + 1)
- cls.td_starttime = realtime;
- }
- else if ( /* cl.time > 0 && */ cl.time <= cl.mtime[0])
- {
- return 0; // don't need another message yet
- }
- }
-
- // get the next message
- fread (&net_message.cursize, 4, 1, cls.demofile);
- VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
- for (i=0 ; i<3 ; i++)
- {
- fread (&f, 4, 1, cls.demofile);
- cl.mviewangles[0][i] = LittleFloat (f);
- }
-
- net_message.cursize = LittleLong (net_message.cursize);
- if (net_message.cursize > MAX_MSGLEN)
- Sys_Error ("Demo message > MAX_MSGLEN");
- r = fread (net_message.data, net_message.cursize, 1, cls.demofile);
- if (r != 1)
- {
- CL_StopPlayback ();
- return 0;
- }
-
- return 1;
- }
+ int r;
- while (1)
- {
- r = NET_GetMessage (cls.netcon);
-
- if (r != 1 && r != 2)
+ if(cls.demoplayback)
+ return dmmsg();
+ for(;;){
+ r = NET_GetMessage(cls.netcon);
+ if(r != 1 && r != 2)
return r;
-
- // discard nop keepalive message
- if (net_message.cursize == 1 && net_message.data[0] == svc_nop)
- Con_Printf ("<-- server to client keepalive\n");
+ if(net_message.cursize == 1 && net_message.data[0] == svc_nop)
+ dprint("<-- server to client keepalive");
else
break;
}
-
- if (cls.demorecording)
- CL_WriteDemoMessage ();
-
+ if(cls.demorecording)
+ wlmpmsg();
return r;
}
-
-/*
-====================
-CL_Stop_f
-
-stop recording a demo
-====================
-*/
-void CL_Stop_f (void)
+void
+abortdemo(void)
{
- if (cmd_source != src_command)
+ if(!cls.demoplayback)
return;
+ endlmp();
+ cls.demoplayback = 0;
+ cls.state = ca_disconnected;
+ if(cls.timedemo)
+ dmtimeend();
+}
- if (!cls.demorecording)
- {
- Con_Printf ("Not recording a demo.\n");
+void
+stopdemo(void)
+{
+ if(cmd_source != src_command)
return;
+ if(!cls.demorecording){
+ Con_Printf("stop: no recording in progress\n");
+ return;
}
-
-// write a disconnect message to the demo file
- SZ_Clear (&net_message);
- MSG_WriteByte (&net_message, svc_disconnect);
- CL_WriteDemoMessage ();
-
-// finish up
- fclose (cls.demofile);
- cls.demofile = NULL;
- cls.demorecording = false;
- Con_Printf ("Completed demo\n");
+ SZ_Clear(&net_message);
+ MSG_WriteByte(&net_message, svc_disconnect);
+ wlmpmsg();
+ endlmp();
+ cls.demorecording = 0;
}
-/*
-====================
-CL_Record_f
-
-record <demoname> <map> [cd track]
-====================
-*/
-void CL_Record_f (void)
+void
+recdemo(void)
{
- int c;
- char name[MAX_OSPATH];
- int track;
+ int c, trk;
+ char f[Nfspath];
- if (cmd_source != src_command)
+ if(cmd_source != src_command)
return;
-
c = Cmd_Argc();
- if (c != 2 && c != 3 && c != 4)
- {
- Con_Printf ("record <demoname> [<map> [cd track]]\n");
+ if(c < 2 || c > 4){
+ Con_Printf("record <demoname> [<map> [cd track]]\n");
return;
}
-
- if (strstr(Cmd_Argv(1), ".."))
- {
- Con_Printf ("Relative pathnames are not allowed.\n");
+ trk = -1;
+ if(strstr(Cmd_Argv(1), "..") != nil){
+ Con_Printf("recdemo: invalid path\n");
return;
- }
-
- if (c == 2 && cls.state == ca_connected)
- {
- Con_Printf("Can not record - already connected to server\nClient demo recording must be started before connecting\n");
+ }else if(c == 2 && cls.state == ca_connected){
+ Con_Printf("recdemo: too late, already connected\n");
return;
- }
-
-// write the forced cd track number, or -1
- if (c == 4)
- {
- track = atoi(Cmd_Argv(3));
- Con_Printf ("Forcing CD track to %d\n", cls.forcetrack);
- }
- else
- track = -1;
-
- sprint (name, "%s/%s", com_gamedir, Cmd_Argv(1));
-
-//
-// start the map up
-//
- if (c > 2)
- Cmd_ExecuteString ( va("map %s", Cmd_Argv(2)), src_command);
-
-//
-// open the demo file
-//
- COM_DefaultExtension (name, ".dem");
-
- Con_Printf ("recording to %s.\n", name);
- cls.demofile = fopen (name, "wb");
- if (!cls.demofile)
- {
- Con_Printf ("ERROR: couldn't open.\n");
+ }else if(c == 4)
+ trk = atoi(Cmd_Argv(3));
+ snprint(f, sizeof f, "%s/%s", fsdir, Cmd_Argv(1));
+ ext(f, ".dem");
+ if(c > 2)
+ Cmd_ExecuteString(va("map %s", Cmd_Argv(2)), src_command);
+ if(reclmp(f, trk) < 0){
+ Con_Printf("recdemo: can't open %s: %r\n", f);
return;
}
-
- cls.forcetrack = track;
- fprintf (cls.demofile, "%d\n", cls.forcetrack);
-
- cls.demorecording = true;
+ cls.demorecording = 1;
+ cls.forcetrack = trk;
}
-
-/*
-====================
-CL_PlayDemo_f
-
-play [demoname]
-====================
-*/
-void CL_PlayDemo_f (void)
+/* when a demo is playing back, all NET_SendMessages are skipped, and
+ * NET_GetMessages are read from the demo file. whenever cl.time gets past
+ * the last received message, another message is read from the demo lump. */
+void
+playdemo(void)
{
- char name[256];
- int c;
- qboolean neg = false;
+ char f[Nfspath];
- if (cmd_source != src_command)
+ if(cmd_source != src_command)
return;
-
- if (Cmd_Argc() != 2)
- {
- Con_Printf ("play <demoname> : plays a demo\n");
+ if(Cmd_Argc() != 2){
+ Con_Printf("playdemo <demo> : plays a demo\n");
return;
}
-
-//
-// disconnect from server
-//
- CL_Disconnect ();
-
-//
-// open the demo file
-//
- strcpy (name, Cmd_Argv(1));
- COM_DefaultExtension (name, ".dem");
-
- Con_Printf ("Playing demo from %s.\n", name);
- COM_FOpenFile (name, &cls.demofile);
- if (!cls.demofile)
- {
- Con_Printf ("ERROR: couldn't open.\n");
- cls.demonum = -1; // stop demo loop
+ CL_Disconnect();
+ memset(f, 0, sizeof f);
+ strncpy(f, Cmd_Argv(1), sizeof(f)-5);
+ ext(f, ".dem");
+ if(demolmp(f) < 0){
+ Con_Printf("playdemo: can't open %s: %r\n", f);
+ cls.demonum = -1;
return;
}
-
- cls.demoplayback = true;
+ cls.demoplayback = 1;
cls.state = ca_connected;
- cls.forcetrack = 0;
-
- while ((c = getc(cls.demofile)) != '\n')
- if (c == '-')
- neg = true;
- else
- cls.forcetrack = cls.forcetrack * 10 + (c - '0');
-
- if (neg)
- cls.forcetrack = -cls.forcetrack;
-// ZOID, fscanf is evil
-// fscanf (cls.demofile, "%i\n", &cls.forcetrack);
}
-/*
-====================
-CL_FinishTimeDemo
-
-====================
-*/
-void CL_FinishTimeDemo (void)
+void
+timedemo(void)
{
- int frames;
- float time;
-
- cls.timedemo = false;
-
-// the first frame didn't count
- frames = (host_framecount - cls.td_startframe) - 1;
- time = realtime - cls.td_starttime;
- if (!time)
- time = 1;
- Con_Printf ("%d frames %5.1f seconds %5.1f fps\n", frames, time, frames/time);
-}
-
-/*
-====================
-CL_TimeDemo_f
-
-timedemo [demoname]
-====================
-*/
-void CL_TimeDemo_f (void)
-{
- if (cmd_source != src_command)
+ if(cmd_source != src_command)
return;
-
- if (Cmd_Argc() != 2)
- {
- Con_Printf ("timedemo <demoname> : gets demo speeds\n");
+ if(Cmd_Argc() != 2){
+ Con_Printf("timedemo <demoname> : gets demo speeds\n");
return;
}
-
- CL_PlayDemo_f ();
-
-// cls.td_starttime will be grabbed at the second frame of the demo, so
-// all the loading time doesn't get counted
-
- cls.timedemo = true;
+ playdemo();
+ if(cls.demoplayback != 1)
+ return;
+ /* cls.td_starttime will be grabbed at the second frame of the demo, so
+ * all the loading time doesn't get counted */
+ cls.timedemo = 1;
cls.td_startframe = host_framecount;
- cls.td_lastframe = -1; // get a new message this frame
+ cls.td_lastframe = -1; /* get a new message this frame */
}
-
--- a/cl_main.c
+++ b/cl_main.c
@@ -90,11 +90,11 @@
// if running a local server, shut it down
if (cls.demoplayback)
- CL_StopPlayback ();
+ abortdemo ();
else if (cls.state == ca_connected)
{
if (cls.demorecording)
- CL_Stop_f ();
+ stopdemo();
print("CL_Disconnect: sending clc_disconnect...\n");
SZ_Clear (&cls.message);
@@ -599,7 +599,7 @@
do
{
- ret = CL_GetMessage ();
+ ret = clmsg ();
if (ret == -1)
Host_Error ("CL_ReadFromServer: lost server connection");
if (!ret)
@@ -703,14 +703,11 @@
Cvar_RegisterVariable (&m_yaw);
Cvar_RegisterVariable (&m_forward);
Cvar_RegisterVariable (&m_side);
-
-// Cvar_RegisterVariable (&cl_autofire);
Cmd_AddCommand ("entities", CL_PrintEntities_f);
Cmd_AddCommand ("disconnect", CL_Disconnect_f);
- Cmd_AddCommand ("record", CL_Record_f);
- Cmd_AddCommand ("stop", CL_Stop_f);
- Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
- Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
+ Cmd_AddCommand("stop", stopdemo);
+ Cmd_AddCommand("record", recdemo);
+ Cmd_AddCommand("playdemo", playdemo);
+ Cmd_AddCommand("timedemo", timedemo);
}
-
--- a/cl_parse.c
+++ b/cl_parse.c
@@ -146,11 +146,11 @@
do
{
- ret = CL_GetMessage ();
+ ret = clmsg ();
switch (ret)
{
default:
- Host_Error ("CL_KeepaliveMessage: CL_GetMessage failed");
+ Host_Error ("CL_KeepaliveMessage: clmsg failed");
case 0:
break; // nothing waiting
case 1:
@@ -190,8 +190,8 @@
char *str;
int i;
int nummodels, numsounds;
- char model_precache[MAX_MODELS][MAX_QPATH];
- char sound_precache[MAX_SOUNDS][MAX_QPATH];
+ char model_precache[MAX_MODELS][Npath];
+ char sound_precache[MAX_SOUNDS][Npath];
print("CL_ParseServerInfo: parsing serverinfo pkt...\n");
//
@@ -390,7 +390,7 @@
else
{
if (i > cl.maxclients)
- Sys_Error ("i >= cl.maxclients");
+ fatal ("i >= cl.maxclients");
ent->colormap = cl.scores[i-1].translations;
}
@@ -599,7 +599,7 @@
byte *dest, *source;
if (slot > cl.maxclients)
- Sys_Error ("CL_NewTranslation: slot > cl.maxclients");
+ fatal ("CL_NewTranslation: slot > cl.maxclients");
dest = cl.scores[slot].translations;
source = vid.colormap;
memcpy(dest, vid.colormap, sizeof cl.scores[slot].translations);
@@ -784,7 +784,7 @@
case svc_lightstyle:
i = MSG_ReadByte ();
if (i >= MAX_LIGHTSTYLES)
- Sys_Error ("svc_lightstyle > MAX_LIGHTSTYLES");
+ fatal ("svc_lightstyle > MAX_LIGHTSTYLES");
strcpy(cl_lightstyle[i].map, MSG_ReadString());
cl_lightstyle[i].length = strlen(cl_lightstyle[i].map);
break;
@@ -869,7 +869,7 @@
case svc_updatestat:
i = MSG_ReadByte ();
if (i < 0 || i >= MAX_CL_STATS)
- Sys_Error ("svc_updatestat: %d is invalid", i);
+ fatal ("svc_updatestat: %d is invalid", i);
cl.stats[i] = MSG_ReadLong ();;
break;
@@ -880,7 +880,7 @@
case svc_cdtrack:
cl.cdtrack = MSG_ReadByte ();
cl.looptrack = MSG_ReadByte ();
- if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
+ if((cls.demoplayback || cls.demorecording) && cls.forcetrack > 0)
CDAudio_Play ((byte)cls.forcetrack, true);
else
CDAudio_Play ((byte)cl.cdtrack, true);
--- a/cl_tent.c
+++ b/cl_tent.c
@@ -230,7 +230,7 @@
break;
default:
- Sys_Error ("CL_ParseTEnt: bad type");
+ fatal ("CL_ParseTEnt: bad type");
}
}
--- a/client.h
+++ b/client.h
@@ -86,7 +86,7 @@
cactive_t state;
// personalization data sent to server
- char mapstring[MAX_QPATH];
+ char mapstring[Npath];
char spawnparms[MAX_MAPSTRING]; // to restart a level
// demo loop control
@@ -99,7 +99,6 @@
qboolean demoplayback;
qboolean timedemo;
int forcetrack; // -1 = use normal cd track
- FILE *demofile;
int td_lastframe; // to meter out one message a frame
int td_startframe; // host_framecount at start
float td_starttime; // realtime at second frame of timedemo
@@ -220,8 +219,6 @@
extern cvar_t cl_anglespeedkey;
-extern cvar_t cl_autofire;
-
extern cvar_t cl_shownet;
extern cvar_t cl_nolerp;
@@ -304,17 +301,6 @@
float CL_KeyState (kbutton_t *key);
char *Key_KeynumToString (int keynum);
-
-//
-// cl_demo.c
-//
-void CL_StopPlayback (void);
-int CL_GetMessage (void);
-
-void CL_Stop_f (void);
-void CL_Record_f (void);
-void CL_PlayDemo_f (void);
-void CL_TimeDemo_f (void);
//
// cl_parse.c
--- a/cmd.c
+++ b/cmd.c
@@ -274,10 +274,9 @@
}
mark = Hunk_LowMark ();
- f = (char *)COM_LoadHunkFile (Cmd_Argv(1));
- if (!f)
- {
- Con_Printf ("couldn't exec %s\n",Cmd_Argv(1));
+ f = loadhunklmp(Cmd_Argv(1), nil);
+ if(f == nil){
+ Con_Printf("couldn't exec %s: %r\n", Cmd_Argv(1));
return;
}
Con_Printf ("execing %s\n",Cmd_Argv(1));
@@ -512,7 +511,7 @@
cmd_function_t *cmd;
if (host_initialized) // because hunk allocation would get stomped
- Sys_Error ("Cmd_AddCommand after host_initialized");
+ fatal ("Cmd_AddCommand after host_initialized");
// fail if the command is a variable name
if (Cvar_VariableString(cmd_name)[0])
@@ -673,7 +672,7 @@
int i;
if (parm == nil)
- Sys_Error ("Cmd_CheckParm: nil");
+ fatal ("Cmd_CheckParm: nil");
for (i = 1; i < Cmd_Argc (); i++)
if(cistrcmp(parm, Cmd_Argv(i)) == 0)
--- a/common.c
+++ b/common.c
@@ -1,10 +1,12 @@
-// common.c -- misc functions used in client and server
-
#include <u.h>
#include <libc.h>
#include <stdio.h>
#include "quakedef.h"
+cvar_t registered = {"registered","0"};
+cvar_t cmdline = {"cmdline","0", false, true};
+char com_cmdline[256];
+
#define NUM_SAFE_ARGVS 6
static char *largv[MAX_NUM_ARGVS + NUM_SAFE_ARGVS + 1];
@@ -13,52 +15,15 @@
static char *safeargvs[NUM_SAFE_ARGVS] =
{"-stdvid", "-nolan", "-nosound", "-nojoy", "-nomouse", "-dibonly"};
-cvar_t registered = {"registered","0"};
-cvar_t cmdline = {"cmdline","0", false, true};
-
-qboolean com_modified; // set true if using non-id files
-
-qboolean proghack;
-
-int static_registered = 1; // only for startup check, then set
-
qboolean msg_suppress_1 = 0;
-void COM_InitFilesystem (void);
-
-// if a packfile directory differs from this, it is assumed to be hacked
-#define PAK0_COUNT 339
-#define PAK0_CRC 32981
-
char com_token[1024];
int com_argc;
char **com_argv;
-#define CMDLINE_LENGTH 256
-char com_cmdline[CMDLINE_LENGTH];
qboolean standard_quake = true, rogue, hipnotic;
-// this graphic needs to be in the pak file to use registered features
-unsigned short pop[] =
-{
- 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
-,0x0000,0x0000,0x6600,0x0000,0x0000,0x0000,0x6600,0x0000
-,0x0000,0x0066,0x0000,0x0000,0x0000,0x0000,0x0067,0x0000
-,0x0000,0x6665,0x0000,0x0000,0x0000,0x0000,0x0065,0x6600
-,0x0063,0x6561,0x0000,0x0000,0x0000,0x0000,0x0061,0x6563
-,0x0064,0x6561,0x0000,0x0000,0x0000,0x0000,0x0061,0x6564
-,0x0064,0x6564,0x0000,0x6469,0x6969,0x6400,0x0064,0x6564
-,0x0063,0x6568,0x6200,0x0064,0x6864,0x0000,0x6268,0x6563
-,0x0000,0x6567,0x6963,0x0064,0x6764,0x0063,0x6967,0x6500
-,0x0000,0x6266,0x6769,0x6a68,0x6768,0x6a69,0x6766,0x6200
-,0x0000,0x0062,0x6566,0x6666,0x6666,0x6666,0x6562,0x0000
-,0x0000,0x0000,0x0062,0x6364,0x6664,0x6362,0x0000,0x0000
-,0x0000,0x0000,0x0000,0x0062,0x6662,0x0000,0x0000,0x0000
-,0x0000,0x0000,0x0000,0x0061,0x6661,0x0000,0x0000,0x0000
-,0x0000,0x0000,0x0000,0x0000,0x6500,0x0000,0x0000,0x0000
-,0x0000,0x0000,0x0000,0x0000,0x6400,0x0000,0x0000,0x0000
-};
/*
@@ -69,15 +34,6 @@
only used during filesystem initialization.
The "game directory" is the first tree on the search path and directory that all generated files (savegames, screenshots, demos, config files) will be saved to. This can be overridden with the "-game" command line parameter. The game directory can never be changed while quake is executing. This is a precacution against having a malicious server instruct clients to write files over areas they shouldn't.
-
-The "cache directory" is only used during development to save network bandwidth, especially over ISDN / T1 lines. If there is a cache directory
-specified, when a file is found by the normal search path, it will be mirrored
-into the cache directory, then opened there.
-
-
-
-FIXME:
-The file "parms.txt" will be read out of the game directory and appended to the current command line arguments to allow different games to initialize startup parms differently. This could be used to add a "-sspeed 22050" for the high quality sound edition. Because they are added at the end, they will not override an explicit setting on the original command line.
*/
@@ -119,8 +75,6 @@
============================================================================
*/
-qboolean bigendien;
-
short (*BigShort) (short l);
short (*LittleShort) (short l);
int (*BigLong) (int l);
@@ -128,60 +82,6 @@
float (*BigFloat) (float l);
float (*LittleFloat) (float l);
-short ShortSwap (short l)
-{
- byte b1,b2;
-
- b1 = l&255;
- b2 = (l>>8)&255;
-
- return (b1<<8) + b2;
-}
-
-short ShortNoSwap (short l)
-{
- return l;
-}
-
-int LongSwap (int l)
-{
- byte b1,b2,b3,b4;
-
- b1 = l&255;
- b2 = (l>>8)&255;
- b3 = (l>>16)&255;
- b4 = (l>>24)&255;
-
- return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
-}
-
-int LongNoSwap (int l)
-{
- return l;
-}
-
-float FloatSwap (float f)
-{
- union
- {
- float f;
- byte b[4];
- } dat1, dat2;
-
-
- dat1.f = f;
- dat2.b[0] = dat1.b[3];
- dat2.b[1] = dat1.b[2];
- dat2.b[2] = dat1.b[1];
- dat2.b[3] = dat1.b[0];
- return dat2.f;
-}
-
-float FloatNoSwap (float f)
-{
- return f;
-}
-
/*
==============================================================================
@@ -201,7 +101,7 @@
#ifdef PARANOID
if (c < -128 || c > 127)
- Sys_Error ("MSG_WriteChar: range error");
+ fatal ("MSG_WriteChar: range error");
#endif
buf = SZ_GetSpace (sb, 1);
@@ -214,7 +114,7 @@
#ifdef PARANOID
if (c < 0 || c > 255)
- Sys_Error ("MSG_WriteByte: range error");
+ fatal ("MSG_WriteByte: range error");
#endif
buf = SZ_GetSpace (sb, 1);
@@ -227,7 +127,7 @@
#ifdef PARANOID
if (c < ((short)0x8000) || c > (short)0x7fff)
- Sys_Error ("MSG_WriteShort: range error");
+ fatal ("MSG_WriteShort: range error");
#endif
buf = SZ_GetSpace (sb, 2);
@@ -449,9 +349,9 @@
if(buf->cursize + length > buf->maxsize){
if(!buf->allowoverflow)
- Sys_Error("SZ_GetSpace: overflow without allowoverflow set");
+ fatal("SZ_GetSpace: overflow without allowoverflow set");
if(length > buf->maxsize)
- Sys_Error("SZ_GetSpace: %d is > full buffer size", length);
+ fatal("SZ_GetSpace: %d is > full buffer size", length);
buf->overflowed = true;
Con_Printf("SZ_GetSpace: overflow");
SZ_Clear(buf);
@@ -481,116 +381,7 @@
memcpy((uchar *)SZ_GetSpace(buf, len-1)-1, data, len); // write over trailing 0
}
-
-//============================================================================
-
-
/*
-============
-COM_SkipPath
-============
-*/
-char *COM_SkipPath (char *pathname)
-{
- char *last;
-
- last = pathname;
- while (*pathname)
- {
- if (*pathname=='/')
- last = pathname+1;
- pathname++;
- }
- return last;
-}
-
-/*
-============
-COM_StripExtension
-============
-*/
-void COM_StripExtension (char *in, char *out)
-{
- while (*in && *in != '.')
- *out++ = *in++;
- *out = 0;
-}
-
-/*
-============
-COM_FileExtension
-============
-*/
-char *COM_FileExtension (char *in)
-{
- static char exten[8];
- int i;
-
- while (*in && *in != '.')
- in++;
- if (!*in)
- return "";
- in++;
- for (i=0 ; i<7 && *in ; i++,in++)
- exten[i] = *in;
- exten[i] = 0;
- return exten;
-}
-
-/*
-============
-COM_FileBase
-============
-*/
-void COM_FileBase (char *in, char *out)
-{
- char *s, *s2;
-
- s = in + strlen(in) - 1;
-
- while (s != in && *s != '.')
- s--;
-
- for (s2 = s ; *s2 && *s2 != '/' ; s2--)
- ;
-
- if (s-s2 < 2)
- strcpy (out,"?model?");
- else
- {
- s--;
- strncpy (out,s2+1, s-s2);
- out[s-s2] = 0;
- }
-}
-
-
-/*
-==================
-COM_DefaultExtension
-==================
-*/
-void COM_DefaultExtension (char *path, char *extension)
-{
- char *src;
-//
-// if path doesn't have a .EXT, append extension
-// (extension should include the .)
-//
- src = path + strlen(path) - 1;
-
- while (*src != '/' && src != path)
- {
- if (*src == '.')
- return; // it has an extension
- src--;
- }
-
- strcat (path, extension);
-}
-
-
-/*
==============
COM_Parse
@@ -693,50 +484,6 @@
/*
================
-COM_CheckRegistered
-
-Looks for the pop.txt file and verifies it.
-Sets the "registered" cvar.
-Immediately exits out if an alternate game was attempted to be started without
-being registered.
-================
-*/
-void COM_CheckRegistered (void)
-{
- int h;
- unsigned short check[128];
- int i;
-
- COM_OpenFile("gfx/pop.lmp", &h);
- static_registered = 0;
-
- if (h == -1)
- {
- Con_Printf ("Playing shareware version.\n");
- if (com_modified)
- Sys_Error ("You must have the registered version to use modified games");
- return;
- }
-
- eread(h, check, sizeof check);
- COM_CloseFile (h);
-
- for (i=0 ; i<128 ; i++)
- if (pop[i] != (unsigned short)BigShort (check[i]))
- Sys_Error ("Corrupted data file.");
-
- Cvar_Set ("cmdline", com_cmdline);
- Cvar_Set ("registered", "1");
- static_registered = 1;
- Con_Printf ("Playing registered version.\n");
-}
-
-
-void COM_Path_f (void);
-
-
-/*
-================
COM_InitArgv
================
*/
@@ -752,12 +499,12 @@
{
i = 0;
- while ((n < (CMDLINE_LENGTH - 1)) && argv[j][i])
+ while ((n < (sizeof(com_cmdline) - 1)) && argv[j][i])
{
com_cmdline[n++] = argv[j][i++];
}
- if (n < (CMDLINE_LENGTH - 1))
+ if (n < (sizeof(com_cmdline) - 1))
com_cmdline[n++] = ' ';
else
break;
@@ -802,48 +549,7 @@
}
}
-
/*
-================
-COM_Init
-================
-*/
-void COM_Init (char *) /*basedir*/
-{
- byte swaptest[2] = {1,0};
-
-// set the byte swapping variables in a portable manner
- if ( *(short *)swaptest == 1)
- {
- bigendien = false;
- BigShort = ShortSwap;
- LittleShort = ShortNoSwap;
- BigLong = LongSwap;
- LittleLong = LongNoSwap;
- BigFloat = FloatSwap;
- LittleFloat = FloatNoSwap;
- }
- else
- {
- bigendien = true;
- BigShort = ShortNoSwap;
- LittleShort = ShortSwap;
- BigLong = LongNoSwap;
- LittleLong = LongSwap;
- BigFloat = FloatNoSwap;
- LittleFloat = FloatSwap;
- }
-
- Cvar_RegisterVariable (®istered);
- Cvar_RegisterVariable (&cmdline);
- Cmd_AddCommand ("path", COM_Path_f);
-
- COM_InitFilesystem ();
- COM_CheckRegistered ();
-}
-
-
-/*
============
va
@@ -863,626 +569,4 @@
va_end(arg);
return s;
-}
-
-
-/// just for debugging
-int memsearch (byte *start, int count, int search)
-{
- int i;
-
- for (i=0 ; i<count ; i++)
- if (start[i] == search)
- return i;
- return -1;
-}
-
-/*
-=============================================================================
-
-QUAKE FILESYSTEM
-
-=============================================================================
-*/
-
-vlong com_filesize;
-
-
-//
-// in memory
-//
-
-typedef struct
-{
- char name[MAX_QPATH];
- int filepos, filelen;
-} packfile_t;
-
-typedef struct pack_s
-{
- char filename[MAX_OSPATH];
- int handle;
- int numfiles;
- packfile_t *files;
-} pack_t;
-
-//
-// on disk
-//
-typedef struct
-{
- char name[56];
- int filepos, filelen;
-} dpackfile_t;
-
-typedef struct
-{
- char id[4];
- int dirofs;
- int dirlen;
-} dpackheader_t;
-
-#define MAX_FILES_IN_PACK 2048
-
-char com_cachedir[MAX_OSPATH];
-char com_gamedir[MAX_OSPATH];
-
-typedef struct searchpath_s
-{
- char filename[MAX_OSPATH];
- pack_t *pack; // only one of filename / pack will be used
- struct searchpath_s *next;
-} searchpath_t;
-
-searchpath_t *com_searchpaths;
-
-/*
-============
-COM_Path_f
-
-============
-*/
-void COM_Path_f (void)
-{
- searchpath_t *s;
-
- Con_Printf ("Current search path:\n");
- for (s=com_searchpaths ; s ; s=s->next)
- {
- if (s->pack)
- {
- Con_Printf ("%s (%d files)\n", s->pack->filename, s->pack->numfiles);
- }
- else
- Con_Printf ("%s\n", s->filename);
- }
-}
-
-void
-COM_WriteFile(char *filename, void *data, int len)
-{
- int fd;
- char path[MAX_OSPATH];
-
- snprint(path, sizeof path, "%s/%s", com_gamedir, filename);
- if((fd = create(path, OWRITE, 0666)) < 0)
- sysfatal("COM_WriteFile: %r");
- ewrite(fd, data, len);
- close(fd);
-}
-
-/* create directories needed to resolve a path */
-static void
-mkdirp(char *path)
-{
- int fd;
- char *s;
-
- for(s = path+1; *s; s++){
- if(*s == '/'){
- *s = 0;
- if(access(path, AEXIST) < 0){
- if((fd = create(path, OREAD, DMDIR|0777)) < 0)
- sysfatal("mkdirp: %r");
- close(fd);
- }
- *s = '/';
- }
- }
-}
-
-/* Copies a file over from the net to the local cache, creating any directories
- * needed. This is for the convenience of developers using ISDN from home. */
-void
-COM_CopyFile(char *netpath, char *cachepath)
-{
- int in, out;
- int count;
- vlong remaining;
- char buf[4096];
-
- if((in = open(netpath, OREAD)) < 0)
- sysfatal("COM_CopyFile:open: %r");
- remaining = flen(in);
-
- mkdirp(cachepath);
- if((out = create(cachepath, OWRITE, 0666)) < 0)
- sysfatal("COM_CopyFile: %r");
-
- while(remaining){
- if(remaining < sizeof buf)
- count = remaining;
- else
- count = sizeof buf;
- eread(in, buf, count);
- ewrite(out, buf, count);
- remaining -= count;
- }
-
- close(in);
- close(out);
-}
-
-/*
-===========
-COM_FindFile
-
-Finds the file in the search path.
-Sets com_filesize and one of handle or file
-===========
-*/
-int COM_FindFile (char *filename, int *handle, FILE **file)
-{
- searchpath_t *search;
- char netpath[MAX_OSPATH];
- char cachepath[MAX_OSPATH];
- pack_t *pak;
- int i;
- int findtime, cachetime;
-
- if (file && handle)
- Sys_Error ("COM_FindFile: both handle and file set");
- if (!file && !handle)
- Sys_Error ("COM_FindFile: neither handle or file set");
-
-//
-// search through the path, one element at a time
-//
- search = com_searchpaths;
- if (proghack)
- { // gross hack to use quake 1 progs with quake 2 maps
- if(strcmp(filename, "progs.dat") == 0)
- search = search->next;
- }
-
- for ( ; search ; search = search->next)
- {
- // is the element a pak file?
- if (search->pack)
- {
- // look through all the pak file elements
- pak = search->pack;
- for (i=0 ; i<pak->numfiles ; i++)
- if(strcmp(pak->files[i].name, filename) == 0)
- { // found it!
- if (handle)
- {
- *handle = pak->handle;
- seek(pak->handle, pak->files[i].filepos, 0);
- }
- else
- { // open a new file on the pakfile
- *file = fopen (pak->filename, "rb");
- if (*file)
- fseek (*file, pak->files[i].filepos, SEEK_SET);
- }
- com_filesize = pak->files[i].filelen;
- return com_filesize;
- }
- }
- else
- {
- // check a file in the directory tree
- if (!static_registered)
- { // if not a registered version, don't ever go beyond base
- if ( strchr (filename, '/') || strchr (filename,'\\'))
- continue;
- }
-
- snprint(netpath, sizeof netpath, "%s/%s", search->filename, filename);
-
- findtime = Sys_FileTime (netpath);
- if (findtime == -1)
- continue;
-
- // see if the file needs to be updated in the cache
- if (!com_cachedir[0])
- strcpy (cachepath, netpath);
- else
- {
- sprint (cachepath,"%s%s", com_cachedir, netpath);
-
- cachetime = Sys_FileTime (cachepath);
-
- if (cachetime < findtime)
- COM_CopyFile (netpath, cachepath);
- strcpy (netpath, cachepath);
- }
-
- com_filesize = -1;
- if((i = open(netpath, OREAD)) < 0)
- fprint(2, "COM_FindFile:open: %r\n");
- else
- com_filesize = flen(i);
-
- if(handle != nil)
- *handle = i;
- else
- {
- close(i);
- *file = fopen (netpath, "rb");
- }
- return com_filesize;
- }
- }
-
- fprint(2, "FindFile: no such file %s\n", filename);
-
- if (handle)
- *handle = -1;
- else
- *file = NULL;
- com_filesize = -1;
- return -1;
-}
-
-
-/*
-===========
-COM_OpenFile
-
-filename never has a leading slash, but may contain directory walks
-returns a handle and a length
-it may actually be inside a pak file
-===========
-*/
-int COM_OpenFile (char *filename, int *handle)
-{
- return COM_FindFile (filename, handle, NULL);
-}
-
-/*
-===========
-COM_FOpenFile
-
-If the requested file is inside a packfile, a new FILE * will be opened
-into the file.
-===========
-*/
-int COM_FOpenFile (char *filename, FILE **file)
-{
- return COM_FindFile (filename, nil, file);
-}
-
-/*
-============
-COM_CloseFile
-
-If it is a pak file handle, don't really close it
-============
-*/
-void COM_CloseFile (int h)
-{
- searchpath_t *s;
-
- for (s = com_searchpaths ; s ; s=s->next)
- if (s->pack && s->pack->handle == h)
- return;
-
- close(h);
-}
-
-
-/*
-============
-COM_LoadFile
-
-Filename are reletive to the quake directory.
-Allways appends a 0 byte.
-============
-*/
-cache_user_t *loadcache;
-byte *loadbuf;
-int loadsize;
-byte *COM_LoadFile (char *path, int usehunk)
-{
- int h;
- byte *buf;
- char base[32];
- int len;
-
- buf = nil; // quiet compiler warning
-
-// look for it in the filesystem or pack files
- len = COM_OpenFile (path, &h);
- if (h == -1)
- return nil;
-
-// extract the filename base name for hunk tag
- COM_FileBase (path, base);
-
- if (usehunk == 1)
- buf = Hunk_AllocName (len+1, base);
- else if (usehunk == 2)
- buf = Hunk_TempAlloc (len+1);
- else if (usehunk == 0)
- buf = Z_Malloc (len+1);
- else if (usehunk == 3)
- buf = Cache_Alloc (loadcache, len+1, base);
- else if (usehunk == 4)
- {
- if (len+1 > loadsize)
- buf = Hunk_TempAlloc (len+1);
- else
- buf = loadbuf;
- }
- else
- Sys_Error ("COM_LoadFile: bad usehunk");
-
- if (!buf)
- Sys_Error ("COM_LoadFile: not enough space for %s", path);
-
- ((byte *)buf)[len] = 0;
-
- Draw_BeginDisc ();
- eread(h, buf, len);
- COM_CloseFile (h);
- Draw_EndDisc ();
-
- return buf;
-}
-
-byte *COM_LoadHunkFile (char *path)
-{
- return COM_LoadFile (path, 1);
-}
-
-byte *COM_LoadTempFile (char *path)
-{
- return COM_LoadFile (path, 2);
-}
-
-void COM_LoadCacheFile (char *path, struct cache_user_s *cu)
-{
- loadcache = cu;
- COM_LoadFile (path, 3);
-}
-
-// uses temp hunk if larger than bufsize
-byte *COM_LoadStackFile (char *path, void *buffer, int bufsize)
-{
- byte *buf;
-
- loadbuf = (byte *)buffer;
- loadsize = bufsize;
- buf = COM_LoadFile (path, 4);
-
- return buf;
-}
-
-/*
-=================
-COM_LoadPackFile
-
-Takes an explicit (not game tree related) path to a pak file.
-
-Loads the header and directory, adding the files at the beginning
-of the list so they override previous pack files.
-=================
-*/
-pack_t *COM_LoadPackFile (char *packfile)
-{
- dpackheader_t header;
- int i;
- packfile_t *newfiles;
- int numpackfiles;
- pack_t *pack;
- int packhandle;
- dpackfile_t info[MAX_FILES_IN_PACK];
- unsigned short crc;
-
- if((packhandle = open(packfile, OREAD)) < 0){
- fprint(2, "COM_LoadPackFile: %r\n");
- return nil;
- }
- eread(packhandle, &header, sizeof header);
- if (header.id[0] != 'P' || header.id[1] != 'A'
- || header.id[2] != 'C' || header.id[3] != 'K')
- Sys_Error ("%s is not a packfile", packfile);
- header.dirofs = LittleLong (header.dirofs);
- header.dirlen = LittleLong (header.dirlen);
-
- numpackfiles = header.dirlen / sizeof(dpackfile_t);
-
- if (numpackfiles > MAX_FILES_IN_PACK)
- Sys_Error ("%s has %d files", packfile, numpackfiles);
-
- if (numpackfiles != PAK0_COUNT)
- com_modified = true; // not the original file
-
- newfiles = Hunk_AllocName(numpackfiles * sizeof *newfiles, "packfile");
-
- seek(packhandle, header.dirofs, 0);
- eread(packhandle, info, header.dirlen);
-
-// crc the directory to check for modifications
- CRC_Init (&crc);
- for (i=0 ; i<header.dirlen ; i++)
- CRC_ProcessByte (&crc, ((byte *)info)[i]);
- if (crc != PAK0_CRC)
- com_modified = true;
-
-// parse the directory
- for (i=0 ; i<numpackfiles ; i++)
- {
- strcpy (newfiles[i].name, info[i].name);
- newfiles[i].filepos = LittleLong(info[i].filepos);
- newfiles[i].filelen = LittleLong(info[i].filelen);
- }
-
- pack = Hunk_Alloc(sizeof *pack);
- strcpy (pack->filename, packfile);
- pack->handle = packhandle;
- pack->numfiles = numpackfiles;
- pack->files = newfiles;
-
- Con_Printf ("Added packfile %s (%d files)\n", packfile, numpackfiles);
- return pack;
-}
-
-
-/*
-================
-COM_AddGameDirectory
-
-Sets com_gamedir, adds the directory to the head of the path,
-then loads and adds pak1.pak pak2.pak ...
-================
-*/
-void COM_AddGameDirectory (char *dir)
-{
- int i;
- searchpath_t *search;
- pack_t *pak;
- char pakfile[MAX_OSPATH];
-
- strcpy (com_gamedir, dir);
-
-//
-// add the directory to the search path
-//
- search = Hunk_Alloc(sizeof *search);
- strcpy (search->filename, dir);
- search->next = com_searchpaths;
- com_searchpaths = search;
-
-//
-// add any pak files in the format pak0.pak pak1.pak, ...
-//
- for (i=0 ; ; i++)
- {
- sprint (pakfile, "%s/pak%d.pak", dir, i);
- pak = COM_LoadPackFile (pakfile);
- if (!pak)
- break;
- search = Hunk_Alloc(sizeof *search);
- search->pack = pak;
- search->next = com_searchpaths;
- com_searchpaths = search;
- }
-
-//
-// add the contents of the parms.txt file to the end of the command line
-//
-
-}
-
-/*
-================
-COM_InitFilesystem
-================
-*/
-void COM_InitFilesystem (void)
-{
- int i, j;
- char basedir[MAX_OSPATH];
- searchpath_t *search;
-
-//
-// -basedir <path>
-// Overrides the system supplied base directory (under GAMENAME)
-//
- i = COM_CheckParm ("-basedir");
- if (i && i < com_argc-1)
- strcpy (basedir, com_argv[i+1]);
- else
- strcpy (basedir, host_parms.basedir);
-
- j = strlen (basedir);
-
- if (j > 0)
- {
- if ((basedir[j-1] == '\\') || (basedir[j-1] == '/'))
- basedir[j-1] = 0;
- }
-
-//
-// -cachedir <path>
-// Overrides the system supplied cache directory (NULL or /qcache)
-// -cachedir - will disable caching.
-//
- i = COM_CheckParm ("-cachedir");
- if (i && i < com_argc-1)
- {
- if (com_argv[i+1][0] == '-')
- com_cachedir[0] = 0;
- else
- strcpy (com_cachedir, com_argv[i+1]);
- }
- else if (host_parms.cachedir)
- strcpy (com_cachedir, host_parms.cachedir);
- else
- com_cachedir[0] = 0;
-
-//
-// start up with GAMENAME by default (id1)
-//
- COM_AddGameDirectory (va("%s/"GAMENAME, basedir) );
-
- if (COM_CheckParm ("-rogue"))
- COM_AddGameDirectory (va("%s/rogue", basedir) );
- if (COM_CheckParm ("-hipnotic"))
- COM_AddGameDirectory (va("%s/hipnotic", basedir) );
-
-//
-// -game <gamedir>
-// Adds basedir/gamedir as an override game
-//
- i = COM_CheckParm ("-game");
- if (i && i < com_argc-1)
- {
- com_modified = true;
- COM_AddGameDirectory (va("%s/%s", basedir, com_argv[i+1]));
- }
-
-//
-// -path <dir or packfile> [<dir or packfile>] ...
-// Fully specifies the exact serach path, overriding the generated one
-//
- i = COM_CheckParm ("-path");
- if (i)
- {
- com_modified = true;
- com_searchpaths = nil;
- while (++i < com_argc)
- {
- if (!com_argv[i] || com_argv[i][0] == '+' || com_argv[i][0] == '-')
- break;
-
- search = Hunk_Alloc(sizeof *search);
- if(strcmp(COM_FileExtension(com_argv[i]), "pak") == 0)
- {
- search->pack = COM_LoadPackFile (com_argv[i]);
- if (!search->pack)
- Sys_Error ("Couldn't load packfile: %s", com_argv[i]);
- }
- else
- strcpy (search->filename, com_argv[i]);
- search->next = com_searchpaths;
- com_searchpaths = search;
- }
- }
-
- if (COM_CheckParm ("-proghack"))
- proghack = true;
}
--- a/common.h
+++ b/common.h
@@ -1,20 +1,6 @@
-// comndef.h -- general definitions
-
-#ifndef BYTE_DEFINED
-typedef unsigned char byte;
-#define BYTE_DEFINED 1
-#endif
-
-#undef true
-#undef false
-
-typedef enum {false, true} qboolean;
-
-//============================================================================
-
typedef struct sizebuf_s
{
- qboolean allowoverflow; // if false, do a Sys_Error
+ qboolean allowoverflow; // if false, do a fatal
qboolean overflowed; // set to true if the buffer size failed
byte *data;
int maxsize;
@@ -66,8 +52,6 @@
//============================================================================
-extern qboolean bigendien;
-
extern short (*BigShort) (short l);
extern short (*LittleShort) (short l);
extern int (*BigLong) (int l);
@@ -110,16 +94,11 @@
extern int com_argc;
extern char **com_argv;
+extern char com_cmdline[];
int COM_CheckParm (char *parm);
-void COM_Init (char *path);
void COM_InitArgv (int argc, char **argv);
-char *COM_SkipPath (char *pathname);
-void COM_StripExtension (char *in, char *out);
-void COM_FileBase (char *in, char *out);
-void COM_DefaultExtension (char *path, char *extension);
-
char *va(char *format, ...);
// does a varargs printf into a temp buffer
@@ -126,22 +105,11 @@
//============================================================================
-extern vlong com_filesize;
struct cache_user_s;
-extern char com_gamedir[MAX_OSPATH];
+extern cvar_t registered;
+extern cvar_t cmdline;
-void COM_WriteFile (char *filename, void *data, int len);
-int COM_OpenFile (char *filename, int *hndl);
-int COM_FOpenFile (char *filename, FILE **file);
-void COM_CloseFile (int h);
-
-byte *COM_LoadStackFile (char *path, void *buffer, int bufsize);
-byte *COM_LoadTempFile (char *path);
-byte *COM_LoadHunkFile (char *path);
-void COM_LoadCacheFile (char *path, struct cache_user_s *cu);
-
-
-extern struct cvar_s registered;
-
extern qboolean standard_quake, rogue, hipnotic;
+
+#pragma varargck argpos va 1
--- a/console.h
+++ b/console.h
@@ -18,3 +18,5 @@
void Con_DrawNotify (void);
void Con_ClearNotify (void);
void Con_ToggleConsole_f (void);
+
+#pragma varargck argpos Con_Printf 1
--- a/crc.c
+++ /dev/null
@@ -1,62 +1,0 @@
-#include <u.h>
-#include <libc.h>
-#include <stdio.h>
-#include "quakedef.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
-// CCITT standard CRC used by XMODEM
-
-#define CRC_INIT_VALUE 0xffff
-#define CRC_XOR_VALUE 0x0000
-
-static unsigned short crctable[256] =
-{
- 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
- 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
- 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
- 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
- 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
- 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
- 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
- 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
- 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
- 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
- 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
- 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
- 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
- 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
- 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
- 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
- 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
- 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
- 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
- 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
- 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
- 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
- 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
- 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
- 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
- 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
- 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
- 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
- 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
- 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
- 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
- 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
-};
-
-void CRC_Init(unsigned short *crcvalue)
-{
- *crcvalue = CRC_INIT_VALUE;
-}
-
-void CRC_ProcessByte(unsigned short *crcvalue, byte data)
-{
- *crcvalue = (*crcvalue << 8) ^ crctable[(*crcvalue >> 8) ^ data];
-}
-
-unsigned short CRC_Value(unsigned short crcvalue)
-{
- return crcvalue ^ CRC_XOR_VALUE;
-}
--- a/crc.h
+++ /dev/null
@@ -1,3 +1,0 @@
-void CRC_Init(unsigned short *crcvalue);
-void CRC_ProcessByte(unsigned short *crcvalue, byte data);
-unsigned short CRC_Value(unsigned short crcvalue);
--- a/cvar.c
+++ b/cvar.c
@@ -79,54 +79,8 @@
return NULL;
}
-
/*
============
-Cvar_Set
-============
-*/
-void Cvar_Set (char *var_name, char *value)
-{
- cvar_t *var;
- qboolean changed;
-
- var = Cvar_FindVar (var_name);
- if (!var)
- { // there is an error in C code if this happens
- Con_Printf ("Cvar_Set: variable %s not found\n", var_name);
- return;
- }
-
- changed = strcmp(var->string, value);
-
- Z_Free (var->string); // free the old value string
-
- var->string = Z_Malloc(strlen(value)+1);
- strcpy(var->string, value);
- var->value = atof(var->string);
- if (var->server && changed)
- {
- if (sv.active)
- SV_BroadcastPrintf ("\"%s\" changed to \"%s\"\n", var->name, var->string);
- }
-}
-
-/*
-============
-Cvar_SetValue
-============
-*/
-void Cvar_SetValue (char *var_name, float value)
-{
- char val[32];
-
- sprint (val, "%f",value);
- Cvar_Set (var_name, val);
-}
-
-
-/*
-============
Cvar_RegisterVariable
Adds a freestanding variable to the variable list.
@@ -184,7 +138,7 @@
return true;
}
- Cvar_Set (v->name, Cmd_Argv(1));
+ setcvar (v->name, Cmd_Argv(1));
return true;
}
@@ -206,3 +160,29 @@
fprintf (f, "%s \"%s\"\n", var->name, var->string);
}
+void
+setcvar(char *k, char *v)
+{
+ int n;
+ cvar_t *cv;
+
+ cv = Cvar_FindVar(k);
+ if(cv == nil)
+ fatal("setcvar: no such cvar %s", k);
+ n = strcmp(cv->string, k);
+ Z_Free(cv->string);
+ cv->string = Z_Malloc(strlen(v)+1);
+ strcpy(cv->string, v);
+ cv->value = atof(v);
+ if(n && cv->server && sv.active)
+ SV_BroadcastPrintf("\"%s\" changed to \"%s\"\n", cv->name, cv->string);
+}
+
+void
+setcvarv(char *k, float v)
+{
+ char u[32];
+
+ sprint(u, "%f", v);
+ setcvar(k, u);
+}
--- a/cvar.h
+++ b/cvar.h
@@ -46,12 +46,6 @@
// registers a cvar that allready has the name, string, and optionally the
// archive elements set.
-void Cvar_Set (char *var_name, char *value);
-// equivelant to "<name> <variable>" typed at the console
-
-void Cvar_SetValue (char *var_name, float value);
-// expands value to a string and calls Cvar_Set
-
float Cvar_VariableValue (char *var_name);
// returns 0 if not defined or non numeric
--- a/d_iface.h
+++ b/d_iface.h
@@ -29,6 +29,7 @@
float die;
ptype_t type;
} particle_t;
+extern particle_t *active_particles, *free_particles;
#define PARTICLE_Z_CLIP 8.0
--- a/d_surf.c
+++ b/d_surf.c
@@ -42,7 +42,7 @@
s = (byte *)sc_base + sc_size;
for (i=0 ; i<GUARDSIZE ; i++)
if (s[i] != (byte)i)
- Sys_Error ("D_CheckCacheGuard: failed");
+ fatal ("D_CheckCacheGuard: failed");
}
void D_ClearCacheGuard (void)
@@ -115,15 +115,15 @@
qboolean wrapped_this_time;
if ((width < 0) || (width > 256))
- Sys_Error ("D_SCAlloc: bad cache width %d\n", width);
+ fatal ("D_SCAlloc: bad cache width %d\n", width);
if ((size <= 0) || (size > 0x10000))
- Sys_Error ("D_SCAlloc: bad cache size %d\n", size);
+ fatal ("D_SCAlloc: bad cache size %zud\n", size);
size = (uintptr)&((surfcache_t *)0)->data[size];
size = (size + 3) & ~3;
if (size > sc_size)
- Sys_Error ("D_SCAlloc: %d > cache size",size);
+ fatal ("D_SCAlloc: %zud > cache size",size);
// if there is not size bytes after the rover, reset to the start
wrapped_this_time = false;
@@ -147,7 +147,7 @@
// free another
sc_rover = sc_rover->next;
if (!sc_rover)
- Sys_Error ("D_SCAlloc: hit the end of memory");
+ fatal ("D_SCAlloc: hit the end of memory");
if (sc_rover->owner)
*sc_rover->owner = nil;
--- /dev/null
+++ b/dat.h
@@ -1,0 +1,8 @@
+enum{
+ Npath = 64,
+ Nfspath = 128,
+ Nmsg = 8000
+};
+
+extern char fsdir[];
+extern u16int crcn;
--- a/draw.c
+++ b/draw.c
@@ -25,7 +25,7 @@
typedef struct cachepic_s
{
- char name[MAX_QPATH];
+ char name[Npath];
cache_user_t cache;
} cachepic_t;
@@ -57,7 +57,7 @@
if (i == menu_numcachepics)
{
if (menu_numcachepics == MAX_CACHED_PICS)
- Sys_Error ("menu_numcachepics == MAX_CACHED_PICS");
+ fatal ("menu_numcachepics == MAX_CACHED_PICS");
menu_numcachepics++;
strcpy (pic->name, path);
}
@@ -70,13 +70,9 @@
//
// load the pic from disk
//
- COM_LoadCacheFile (path, &pic->cache);
-
- dat = (qpic_t *)pic->cache.data;
- if (!dat)
- {
- Sys_Error ("Draw_CachePic: failed to load %s", path);
- }
+ dat = loadcachelmp(path, &pic->cache);
+ if(dat == nil)
+ fatal("Draw_CachePic: failed to load %s: %r", path);
SwapPic (dat);
@@ -127,9 +123,9 @@
#ifdef PARANOID
if (y > vid.height - 8 || x < 0 || x > vid.width - 8)
- Sys_Error ("Con_DrawCharacter: (%d, %d)", x, y);
+ fatal ("Con_DrawCharacter: (%d, %d)", x, y);
if (num < 0 || num > 255)
- Sys_Error ("Con_DrawCharacter: char %d", num);
+ fatal ("Con_DrawCharacter: char %d", num);
#endif
row = num>>4;
@@ -277,7 +273,7 @@
(y < 0) ||
(y + pic->height > vid.height))
{
- Sys_Error ("Draw_Pic: bad coordinates");
+ fatal ("Draw_Pic: bad coordinates");
}
source = pic->data;
@@ -326,7 +322,7 @@
if (x < 0 || (unsigned)(x + pic->width) > vid.width || y < 0 ||
(unsigned)(y + pic->height) > vid.height)
{
- Sys_Error ("Draw_TransPic: bad coordinates");
+ fatal ("Draw_TransPic: bad coordinates");
}
source = pic->data;
@@ -413,7 +409,7 @@
if (x < 0 || (unsigned)(x + pic->width) > vid.width || y < 0 ||
(unsigned)(y + pic->height) > vid.height)
{
- Sys_Error ("Draw_TransPic: bad coordinates");
+ fatal ("Draw_TransPic: bad coordinates");
}
source = pic->data;
--- /dev/null
+++ b/fns.h
@@ -1,0 +1,28 @@
+void setcvar(char*, char*);
+void setcvarv(char*, float);
+int clmsg(void);
+void abortdemo(void);
+void stopdemo(void);
+void recdemo(void);
+void playdemo(void);
+void timedemo(void);
+void* loadhunklmp(char *, int *);
+void* loadcachelmp(char *, cache_user_t *);
+void* loadstklmp(char *, void *, int, int *);
+void pointlmp(void);
+void endlmp(void);
+int rlmpmsg(void);
+void wlmpmsg(void);
+int reclmp(char*, int);
+int demolmp(char*);
+void crc(u8int);
+void initcrc(void);
+void ext(char*, char*);
+void radix(char*, char*);
+void unloadfs(void);
+void initfs(void);
+void dprint(char*, ...);
+void fatal(char*, ...);
+
+#pragma varargck argpos dprint 1
+#pragma varargck argpos fatal 1
--- /dev/null
+++ b/fs.c
@@ -1,0 +1,721 @@
+#include <u.h>
+#include <libc.h>
+#include <stdio.h>
+#include <bio.h>
+#include "quakedef.h"
+
+u16int crcn;
+char fsdir[Nfspath];
+
+typedef struct Lump Lump;
+typedef struct Pak Pak;
+typedef struct Paklist Paklist;
+
+enum{
+ Npakhdr = 4+4+4,
+ Npaksz = 56+4+4,
+ Npaklmp = 2048,
+ Npak0lmp = 339,
+ Npak0crc = 0x80d5,
+ Fhunk = 0,
+ Fcache,
+ Fstack
+};
+struct Lump{
+ char f[Npath];
+ int ofs;
+ int len;
+};
+struct Pak{
+ char f[Nfspath];
+ Biobuf *bf;
+ Lump *l;
+ Lump *e;
+};
+struct Paklist{
+ char f[Nfspath];
+ Pak *p;
+ Paklist *pl;
+};
+static Paklist *pkl;
+
+static u16int pop[] = {
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x6600, 0x0000, 0x0000, 0x0000, 0x6600, 0x0000,
+ 0x0000, 0x0066, 0x0000, 0x0000, 0x0000, 0x0000, 0x0067, 0x0000,
+ 0x0000, 0x6665, 0x0000, 0x0000, 0x0000, 0x0000, 0x0065, 0x6600,
+ 0x0063, 0x6561, 0x0000, 0x0000, 0x0000, 0x0000, 0x0061, 0x6563,
+ 0x0064, 0x6561, 0x0000, 0x0000, 0x0000, 0x0000, 0x0061, 0x6564,
+ 0x0064, 0x6564, 0x0000, 0x6469, 0x6969, 0x6400, 0x0064, 0x6564,
+ 0x0063, 0x6568, 0x6200, 0x0064, 0x6864, 0x0000, 0x6268, 0x6563,
+ 0x0000, 0x6567, 0x6963, 0x0064, 0x6764, 0x0063, 0x6967, 0x6500,
+ 0x0000, 0x6266, 0x6769, 0x6a68, 0x6768, 0x6a69, 0x6766, 0x6200,
+ 0x0000, 0x0062, 0x6566, 0x6666, 0x6666, 0x6666, 0x6562, 0x0000,
+ 0x0000, 0x0000, 0x0062, 0x6364, 0x6664, 0x6362, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0062, 0x6662, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0061, 0x6661, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x6500, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x6400, 0x0000, 0x0000, 0x0000
+};
+
+/* 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 CCITT standard
+ * CRC used by XMODEM */
+enum{
+ Ncrc0 = 0xffff,
+ Nxor = 0
+};
+static u16int crct[] ={
+ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
+ 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
+ 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
+ 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
+ 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
+ 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
+ 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
+ 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
+ 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
+ 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
+ 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
+ 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
+ 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
+ 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
+ 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
+ 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
+ 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
+ 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
+ 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
+ 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
+ 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
+ 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+ 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
+ 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
+ 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
+ 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
+ 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
+ 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
+ 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
+ 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
+ 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
+ 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
+};
+static int notid1;
+
+static int loadsize;
+static uchar *loadbuf;
+static cache_user_t *loadcache;
+
+static Biobuf *demobf;
+static vlong demoofs;
+
+#define GBIT32(p) ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
+#define PBIT32(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24
+
+static Biobuf *
+bopen(char *f, int m, int arm)
+{
+ Biobuf *bf;
+
+ bf = Bopen(f, m);
+ if(bf == nil)
+ return nil;
+ if(arm)
+ Blethal(bf, nil);
+ return bf;
+}
+
+static long
+eread(Biobuf *bf, void *u, long n)
+{
+ if(Bread(bf, u, n) != n)
+ fatal("eread: short read: %r");
+ return n;
+}
+
+static u8int
+get8(Biobuf *bf)
+{
+ u8int v;
+
+ eread(bf, &v, 1);
+ return v;
+}
+
+static u16int
+get16(Biobuf *bf)
+{
+ u16int v;
+
+ v = get8(bf);
+ return v | get8(bf) << 8;
+}
+
+static u32int
+get32(Biobuf *bf)
+{
+ u32int v;
+
+ v = get16(bf);
+ return v | get16(bf) << 16;
+}
+
+static float
+getfl(Biobuf *bf)
+{
+ union{
+ float v;
+ u32int u;
+ } u;
+
+ u.u = get32(bf);
+ return u.v;
+}
+
+static u16int
+get16b(Biobuf *bf)
+{
+ u16int v;
+
+ v = get8(bf);
+ return v << 8 | get8(bf);
+}
+
+static u32int
+get32b(Biobuf *bf)
+{
+ u32int v;
+
+ v = get16(bf);
+ return v << 16 | get16(bf);
+}
+
+static void
+ewrite(Biobuf *bf, void *u, long n)
+{
+ if(Bwrite(bf, u, n) != n)
+ fatal("eread: short write: %r");
+}
+
+static void
+put32(Biobuf *bf, u32int v)
+{
+ uchar u[4];
+
+ PBIT32(u, v);
+ ewrite(bf, u, 4);
+}
+
+static void
+putfl(Biobuf *bf, float v)
+{
+ union{
+ float v;
+ u32int u;
+ } w;
+
+ w.v = v;
+ put32(bf, w.u);
+}
+
+static vlong
+bsize(Biobuf *bf)
+{
+ vlong n;
+ Dir *d;
+
+ d = dirfstat(Bfildes(bf));
+ if(d == nil)
+ sysfatal("bstat: %r");
+ n = d->length;
+ free(d);
+ return n;
+}
+
+static Pak *
+pak(char *f)
+{
+ int n, ofs, len, nlmp;
+ uchar u[8];
+ Biobuf *bf;
+ Lump *l;
+ Pak *p;
+
+ bf = bopen(f, OREAD, 1);
+ if(bf == nil)
+ return nil;
+ memset(u, 0, sizeof u);
+ eread(bf, u, 4);
+ if(memcmp(u, "PACK", 4) != 0)
+ fatal("pak %s: invalid pak file", f);
+ ofs = get32(bf);
+ len = get32(bf);
+ nlmp = len / Npaksz;
+ if(nlmp > Npaklmp)
+ fatal("pak %s: invalid lump number %d", f, nlmp);
+ if(nlmp != Npak0lmp)
+ notid1 = 1;
+ l = Hunk_AllocName(nlmp * sizeof *l, "pak");
+ p = Hunk_Alloc(sizeof *p);
+ strncpy(p->f, f, sizeof(p->f)-1);
+ p->bf = bf;
+ p->l = l;
+ p->e = l + nlmp;
+ Bseek(bf, ofs, 0);
+ initcrc();
+ while(l < p->e){
+ eread(bf, l->f, 56);
+ for(n=0; n<56; n++)
+ crc(l->f[n]);
+ eread(bf, u, 8);
+ for(n=0; n<8; n++)
+ crc(u[n]);
+ l->ofs = GBIT32(u);
+ l->len = GBIT32(u+4);
+ l++;
+ }
+ if(crcn != Npak0crc)
+ notid1 = 1;
+ return p;
+}
+
+static void
+pakdir(char *d)
+{
+ int n;
+ char f[Nfspath];
+ Paklist *pl;
+ Pak *p;
+
+ strncpy(fsdir, d, sizeof(fsdir)-1);
+ pl = Hunk_Alloc(sizeof *pl);
+ strncpy(pl->f, d, sizeof(pl->f)-1);
+ pl->pl = pkl;
+ pkl = pl;
+ for(n=0; ; n++){
+ snprint(f, sizeof f, "%s/pak%d.pak", d, n);
+ p = pak(f);
+ if(p == nil){
+ dprint("pakdir: can't open %s: %r", f);
+ break;
+ }
+ pl = Hunk_Alloc(sizeof *pl);
+ pl->p = p;
+ pl->pl = pkl;
+ pkl = pl;
+ }
+}
+
+static void
+initns(void)
+{
+ int i;
+ char d[Nfspath], *e;
+
+ memset(d, 0, sizeof d);
+ i = COM_CheckParm("-basedir");
+ if(i != 0 && i < com_argc - 1)
+ strncpy(d, com_argv[i+1], sizeof(d)-1);
+ else
+ strncpy(d, host_parms.basedir, sizeof(d)-1);
+ e = d + strlen(d) - 1;
+ if(e > d && *e == '/')
+ *e = 0;
+ pakdir(va("%s%s", d, "/id1"));
+ if(COM_CheckParm("-rogue"))
+ pakdir(va("%s%s", d, "/rogue"));
+ if(COM_CheckParm("-hipnotic"))
+ pakdir(va("%s%s", d, "/hipnotic"));
+ i = COM_CheckParm("-game");
+ if(i != 0 && i < com_argc - 1){
+ notid1 = 1;
+ pakdir(va("%s/%s", d, com_argv[i+1]));
+ }
+}
+
+static Biobuf *
+openlmp(char *f, int *len)
+{
+ char d[Nfspath];
+ Biobuf *bf;
+ Paklist *pl;
+ Pak *p;
+ Lump *l;
+
+ for(pl=pkl; pl != nil; pl=pl->pl){
+ if(pl->p != nil){
+ p = pl->p;
+ l = p->l;
+ while(l < p->e){
+ if(strcmp(l->f, f) == 0){
+ Bseek(p->bf, l->ofs, 0);
+ if(len != nil)
+ *len = l->len;
+ return p->bf;
+ }
+ l++;
+ }
+ continue;
+ }
+ snprint(d, sizeof d, "%s/%s", pl->f, f);
+ if(access(d, AREAD) < 0)
+ continue;
+ bf = bopen(d, OREAD, 1);
+ if(bf == nil)
+ return nil;
+ if(len != nil)
+ *len = bsize(bf);
+ return bf;
+ }
+ werrstr("openlmp %s: not found", f);
+ return nil;
+}
+
+static void
+closelmp(Biobuf *bf)
+{
+ Paklist *pl;
+
+ for(pl=pkl; pl!=nil; pl=pl->pl)
+ if(pl->p && pl->p->bf == bf)
+ return;
+ Bterm(bf);
+}
+
+static uchar *
+loadlmp(char *f, int mth, int *n)
+{
+ int m;
+ char r[32];
+ uchar *buf;
+ Biobuf *bf;
+
+ bf = openlmp(f, &m);
+ if(bf == nil)
+ return nil;
+ radix(f, r);
+ buf = nil;
+ switch(mth){
+ case Fhunk: buf = Hunk_AllocName(m + 1, r); break;
+ case Fcache: buf = Cache_Alloc(loadcache, m + 1, r); break;
+ case Fstack: buf = m+1 <= loadsize ? loadbuf : Hunk_TempAlloc(m+1);
+ }
+ if(buf == nil)
+ fatal("loadlmp %s %d: memory allocation failed: %r", f, m+1);
+ buf[m] = 0;
+ Draw_BeginDisc();
+ eread(bf, buf, m);
+ closelmp(bf);
+ Draw_EndDisc();
+ if(n != nil)
+ *n = m;
+ return buf;
+}
+
+static void
+path(void)
+{
+ Paklist *pl;
+
+ for(pl=pkl; pl!=nil; pl=pl->pl)
+ if(pl->p)
+ Con_Printf("%s (%zd files)\n", pl->p->f, pl->p->e - pl->p->l);
+ else
+ Con_Printf("%s\n", pl->f);
+}
+
+static void
+chkreg(void)
+{
+ u16int *p;
+ Biobuf *bf;
+
+ Cvar_RegisterVariable(®istered);
+ bf = openlmp("gfx/pop.lmp", nil);
+ if(bf == nil){
+ dprint("chkreg: shareware version");
+ if(notid1)
+ fatal("chkreg: phase error -- %r");
+ return;
+ }
+ p = pop;
+ while(p < pop + nelem(pop))
+ if(*p++ != get16b(bf))
+ fatal("chkreg: corrupted pop lump");
+ closelmp(bf);
+ setcvar("registered", "1");
+ dprint("chkreg: registered version");
+}
+
+void *
+loadhunklmp(char *f, int *n)
+{
+ return loadlmp(f, Fhunk, n);
+}
+
+void *
+loadcachelmp(char *f, cache_user_t *c)
+{
+ loadcache = c;
+ loadlmp(f, Fcache, nil);
+ return c->data;
+}
+
+void *
+loadstklmp(char *f, void *buf, int nbuf, int *n)
+{
+ loadbuf = buf;
+ loadsize = nbuf;
+ return loadlmp(f, Fstack, n);
+}
+
+void
+pointlmp(void)
+{
+ int i, n, nv;
+ char f[Nfspath];
+ Biobuf *bf;
+ vec3_t v3;
+ vec_t *v;
+ particle_t *p;
+
+ snprint(f, sizeof f, "maps/%s.pts", sv.name);
+ bf = openlmp(f, &n);
+ if(bf == nil){
+ Con_Printf("pointlmp: can't open %s: %r\n", f);
+ return;
+ }
+ nv = 0;
+ for(;;){
+ if(n < 3*4+3)
+ break;
+ for(i=0, v=v3; i<3; i++){
+ *v++ = getfl(bf);
+ Bseek(bf, 1, 1);
+ }
+ n -= 3*4+3;
+ nv++;
+ if(free_particles == nil){
+ Con_Printf("pointlmp: insufficient free particles\n");
+ break;
+ }
+ p = free_particles;
+ free_particles = p->next;
+ p->next = active_particles;
+ active_particles = p;
+ p->die = 99999;
+ p->color = -nv & 15;
+ p->type = pt_static;
+ VectorCopy(vec3_origin, p->vel);
+ VectorCopy(v3, p->org);
+ }
+ closelmp(bf);
+ Con_Printf("pointlmp: %d points read\n", nv);
+}
+
+void
+endlmp(void)
+{
+ closelmp(demobf);
+ demobf = nil;
+}
+
+int
+rlmpmsg(void)
+{
+ int n;
+ vec_t *f;
+
+ Bseek(demobf, demoofs, 0);
+ net_message.cursize = get32(demobf);
+ VectorCopy(cl.mviewangles[0], cl.mviewangles[1]);
+ for(n=0, f=cl.mviewangles[0]; n<3; n++)
+ *f++ = getfl(demobf);
+ if(net_message.cursize > Nmsg)
+ fatal("rlmpmsg: invalid message size %d\n", net_message.cursize);
+ n = Bread(demobf, net_message.data, net_message.cursize);
+ demoofs = Bseek(demobf, 0, 1);
+ if(n < 0)
+ dprint("rlmpmsg: bad read: %r");
+ if(n != net_message.cursize){
+ dprint("rlmpmsg: short read: %r");
+ n = -1;
+ }
+ return n;
+}
+
+void
+wlmpmsg(void)
+{
+ int i;
+
+ put32(demobf, net_message.cursize);
+ for(i=0; i<3; i++)
+ putfl(demobf, cl.viewangles[i]);
+ ewrite(demobf, net_message.data, net_message.cursize);
+}
+
+int
+reclmp(char *f, int trk)
+{
+ char s[16];
+
+ demobf = bopen(f, OWRITE, 0);
+ if(demobf == nil)
+ return -1;
+ sprint(s, "%d\n", trk);
+ ewrite(demobf, s, strlen(s));
+ return 0;
+}
+
+demolmp(char *f)
+{
+ int n;
+ char *s;
+
+ demobf = openlmp(f, &n);
+ if(demobf == nil)
+ return -1;
+ s = Brdline(demobf, '\n');
+ n = Blinelen(demobf) - 1;
+ if(s == nil || n < 0 || n > 11){
+ dprint("demolmp: invalid trk field");
+ closelmp(demobf);
+ return -1;
+ }
+ demoofs = Bseek(demobf, 0, 1);
+ s[n] = 0;
+ cls.forcetrack = strtol(s, nil, 10);
+ return 0;
+}
+
+void
+crc(u8int v)
+{
+ crcn = crcn << 8 ^ crct[crcn >> 8 ^ v];
+}
+
+void
+initcrc(void)
+{
+ crcn = Ncrc0;
+}
+
+void
+ext(char *f, char *e)
+{
+ char *s, *d;
+
+ s = strrchr(f, '/');
+ d = strrchr(f, '.');
+ if(d > s)
+ return;
+ strcat(f, e);
+}
+
+void
+radix(char *f, char *d)
+{
+ char *s, *e;
+
+ s = strrchr(f, '/');
+ e = strrchr(f, '.');
+ if(s == nil)
+ s = f;
+ s++;
+ if(e - s < 1)
+ strcpy(d, "?model?");
+ else{
+ strncpy(d, s, e - s);
+ d[e - s] = 0;
+ }
+}
+
+void
+unloadfs(void)
+{
+ Paklist *pl;
+
+ for(pl=pkl; pl!=nil; pl=pl->pl)
+ if(pl->p != nil)
+ Bterm(pl->p->bf);
+}
+
+/* TODO: nuke these from orbit */
+static short
+ShortSwap(short l)
+{
+ byte b1,b2;
+
+ b1 = l&255;
+ b2 = (l>>8)&255;
+ return (b1<<8) + b2;
+}
+static short
+ShortNoSwap(short l)
+{
+ return l;
+}
+static int
+LongSwap(int l)
+{
+ byte b1,b2,b3,b4;
+
+ b1 = l&255;
+ b2 = (l>>8)&255;
+ b3 = (l>>16)&255;
+ b4 = (l>>24)&255;
+ return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
+}
+static int
+LongNoSwap(int l)
+{
+ return l;
+}
+static float
+FloatSwap(float f)
+{
+ union{
+ float f;
+ byte b[4];
+ } dat1, dat2;
+
+ dat1.f = f;
+ dat2.b[0] = dat1.b[3];
+ dat2.b[1] = dat1.b[2];
+ dat2.b[2] = dat1.b[1];
+ dat2.b[3] = dat1.b[0];
+ return dat2.f;
+}
+static float
+FloatNoSwap(float f)
+{
+ return f;
+}
+
+void
+initfs(void)
+{
+ byte swaptest[2] = {1,0};
+
+ if(*(short *)swaptest == 1)
+ {
+ BigShort = ShortSwap;
+ LittleShort = ShortNoSwap;
+ BigLong = LongSwap;
+ LittleLong = LongNoSwap;
+ BigFloat = FloatSwap;
+ LittleFloat = FloatNoSwap;
+ }else{
+ BigShort = ShortNoSwap;
+ LittleShort = ShortSwap;
+ BigLong = LongNoSwap;
+ LittleLong = LongSwap;
+ BigFloat = FloatNoSwap;
+ LittleFloat = FloatSwap;
+ }
+ initns();
+ chkreg();
+ Cmd_AddCommand("path", path);
+ Cvar_RegisterVariable(&cmdline);
+ setcvar("cmdline", com_cmdline);
+}
--- a/host.c
+++ b/host.c
@@ -78,7 +78,7 @@
if(sv.active)
Host_ShutdownServer(false);
if(cls.state == ca_dedicated)
- Sys_Error("Host_EndGame: %s\n", s); // dedicated servers exit
+ fatal("Host_EndGame: %s\n", s); // dedicated servers exit
if(cls.demonum != -1)
CL_NextDemo();
else
@@ -101,7 +101,7 @@
static qboolean inerror = false;
if(inerror)
- Sys_Error("Host_Error: recursively entered");
+ fatal("Host_Error: recursively entered");
inerror = true;
SCR_EndLoadingPlaque(); // reenable screen updates
@@ -115,7 +115,7 @@
if(sv.active)
Host_ShutdownServer(false);
if(cls.state == ca_dedicated)
- Sys_Error("Host_Error: %s\n", s); // dedicated servers exit
+ fatal("Host_Error: %s\n", s); // dedicated servers exit
CL_Disconnect();
cls.demonum = -1;
@@ -151,7 +151,7 @@
if (i)
{
if (cls.state == ca_dedicated)
- Sys_Error ("Only one of -dedicated or -listen can be specified");
+ fatal ("Only one of -dedicated or -listen can be specified");
if (i != (com_argc - 1))
svs.maxclients = atoi(com_argv[i+1]);
else
@@ -168,9 +168,9 @@
svs.clients = Hunk_AllocName(svs.maxclientslimit * sizeof *svs.clients, "clients");
if (svs.maxclients > 1)
- Cvar_SetValue ("deathmatch", 1.0);
+ setcvarv ("deathmatch", 1.0);
else
- Cvar_SetValue ("deathmatch", 0.0);
+ setcvarv ("deathmatch", 0.0);
}
@@ -223,7 +223,7 @@
// config.cfg cvars
if (host_initialized & !isDedicated)
{
- f = fopen (va("%s/config.cfg",com_gamedir), "w");
+ f = fopen (va("%s/config.cfg",fsdir), "w");
if (!f)
{
Con_Printf ("Couldn't write config.cfg.\n");
@@ -703,7 +703,7 @@
host_parms = *parms;
if (parms->memsize < minimum_memory)
- Sys_Error ("Only %4.1f megs of memory available, can't execute game", parms->memsize / (float)0x100000);
+ fatal ("Only %4.1f megs of memory available, can't execute game", parms->memsize / (float)0x100000);
com_argc = parms->argc;
com_argv = parms->argv;
@@ -713,7 +713,7 @@
Cmd_Init ();
V_Init ();
Chase_Init ();
- COM_Init (parms->basedir);
+ initfs();
Host_InitLocal ();
W_LoadWadFile ("gfx.wad");
Key_Init ();
@@ -731,12 +731,12 @@
if (cls.state != ca_dedicated)
{
- host_basepal = (byte *)COM_LoadHunkFile ("gfx/palette.lmp");
- if (!host_basepal)
- Sys_Error ("Couldn't load gfx/palette.lmp");
- host_colormap = (byte *)COM_LoadHunkFile ("gfx/colormap.lmp");
- if (!host_colormap)
- Sys_Error ("Couldn't load gfx/colormap.lmp");
+ host_basepal = loadhunklmp("gfx/palette.lmp", nil);
+ if(host_basepal == nil)
+ fatal("Host_Init: failed to load gfx/palette.lmp: %r");
+ host_colormap = loadhunklmp("gfx/colormap.lmp", nil);
+ if(host_colormap == nil)
+ fatal("Host_Init: failed to load gfx/colormap.lmp: %r");
VID_Init (host_basepal);
@@ -763,7 +763,7 @@
===============
Host_Shutdown
-FIXME: this is a callback from Sys_Quit and Sys_Error. It would be better
+FIXME: this is a callback from Sys_Quit and fatal. It would be better
to run quit through here before the final handoff to the sys code.
===============
*/
@@ -787,6 +787,7 @@
NET_Shutdown ();
S_Shutdown();
IN_Shutdown ();
+ unloadfs();
if (cls.state != ca_dedicated)
{
--- a/host_cmd.c
+++ b/host_cmd.c
@@ -239,7 +239,7 @@
void Host_Map_f (void)
{
int i;
- char name[MAX_QPATH];
+ char name[Npath];
if (cmd_source != src_command)
return;
@@ -289,7 +289,7 @@
*/
void Host_Changelevel_f (void)
{
- char level[MAX_QPATH];
+ char level[Npath];
if (Cmd_Argc() != 2)
{
@@ -315,7 +315,7 @@
*/
void Host_Restart_f (void)
{
- char mapname[MAX_QPATH];
+ char mapname[Npath];
if (cls.demoplayback || !sv.active)
return;
@@ -350,12 +350,12 @@
*/
void Host_Connect_f (void)
{
- char name[MAX_QPATH];
+ char name[Npath];
cls.demonum = -1; // stop demo loop in case this fails
if (cls.demoplayback)
{
- CL_StopPlayback ();
+ abortdemo ();
CL_Disconnect ();
}
strcpy (name, Cmd_Argv(1));
@@ -453,9 +453,9 @@
}
}
- sprint (name, "%s/%s", com_gamedir, Cmd_Argv(1));
- COM_DefaultExtension (name, ".sav");
-
+ sprint (name, "%s/%s", fsdir, Cmd_Argv(1));
+ ext(name, ".sav");
+
Con_Printf ("Saving game to %s...\n", name);
f = fopen (name, "w");
if (!f)
@@ -502,9 +502,9 @@
*/
void Host_Loadgame_f (void)
{
- char name[MAX_OSPATH];
+ char name[Nfspath];
FILE *f;
- char mapname[MAX_QPATH];
+ char mapname[Npath];
float time, tfloat;
char str[32768], *start;
int i, r;
@@ -524,9 +524,9 @@
cls.demonum = -1; // stop demo loop in case this fails
- sprint (name, "%s/%s", com_gamedir, Cmd_Argv(1));
- COM_DefaultExtension (name, ".sav");
-
+ sprint (name, "%s/%s", fsdir, Cmd_Argv(1));
+ ext(name, ".sav");
+
// we can't call SCR_BeginLoadingPlaque, because too much stack space has
// been used. The menu calls it before stuffing loadgame command
// SCR_BeginLoadingPlaque ();
@@ -552,7 +552,7 @@
// this silliness is so we can load 1.06 save files, which have float skill values
fscanf (f, "%f\n", &tfloat);
current_skill = (int)(tfloat + 0.1);
- Cvar_SetValue ("skill", (float)current_skill);
+ setcvarv ("skill", (float)current_skill);
fscanf (f, "%s\n",mapname);
fscanf (f, "%f\n",&time);
@@ -594,13 +594,13 @@
}
}
if (i == sizeof(str)-1)
- Sys_Error ("Loadgame buffer overflow");
+ fatal ("Loadgame buffer overflow");
str[i] = 0;
start = COM_Parse(str);
if (!com_token[0])
break; // end of file
if(strcmp(com_token, "{") != 0)
- Sys_Error ("First token isn't a brace");
+ fatal ("First token isn't a brace");
if (entnum == -1)
{ // parse the global vars
@@ -664,7 +664,7 @@
{
if(strcmp(cl_name.string, newName) == 0)
return;
- Cvar_Set ("_cl_name", newName);
+ setcvar ("_cl_name", newName);
if (cls.state == ca_connected)
Cmd_ForwardToServer ();
return;
@@ -907,7 +907,7 @@
if (cmd_source == src_command)
{
- Cvar_SetValue ("_cl_color", playercolor);
+ setcvarv ("_cl_color", playercolor);
if (cls.state == ca_connected)
Cmd_ForwardToServer ();
return;
@@ -1604,7 +1604,7 @@
return;
if (!cls.demoplayback)
return;
- CL_StopPlayback ();
+ abortdemo ();
CL_Disconnect ();
}
--- a/keys.c
+++ b/keys.c
@@ -618,7 +618,7 @@
M_ToggleMenu_f ();
break;
default:
- Sys_Error ("Bad key_dest");
+ fatal ("Bad key_dest");
}
return;
}
@@ -705,7 +705,7 @@
Key_Console (key);
break;
default:
- Sys_Error ("Bad key_dest");
+ fatal ("Bad key_dest");
}
}
--- a/mathlib.c
+++ b/mathlib.c
@@ -5,8 +5,6 @@
#include <stdio.h>
#include "quakedef.h"
-void Sys_Error (char *error, ...);
-
vec3_t vec3_origin = {0,0,0};
int nanmask = 255<<23;
@@ -146,7 +144,7 @@
*/
void BOPS_Error (void)
{
- Sys_Error ("BoxOnPlaneSide: Bad signbits");
+ fatal ("BoxOnPlaneSide: Bad signbits");
}
@@ -251,7 +249,7 @@
#ifdef PARANOID
if (sides == 0)
- Sys_Error ("BoxOnPlaneSide: sides==0");
+ fatal ("BoxOnPlaneSide: sides==0");
#endif
return sides;
@@ -464,9 +462,9 @@
#ifdef PARANOID
if (denom <= 0.0)
- Sys_Error ("FloorDivMod: bad denominator %d\n", denom);
+ fatal ("FloorDivMod: bad denominator %d\n", denom);
if (floor(numer) != numer || floor(denom) != denom)
- Sys_Error ("FloorDivMod: non-integer numer or denom %f %f\n", numer, denom);
+ fatal ("FloorDivMod: non-integer numer or denom %f %f\n", numer, denom);
#endif
if (numer >= 0.0)
--- a/menu.c
+++ b/menu.c
@@ -420,7 +420,7 @@
void M_ScanSaves (void)
{
int i, j;
- char name[MAX_OSPATH];
+ char name[Nfspath];
FILE *f;
int version;
@@ -428,7 +428,7 @@
{
strcpy (m_filenames[i], "--- UNUSED SLOT ---");
loadable[i] = false;
- sprint (name, "%s/s%d.sav", com_gamedir, i);
+ sprint (name, "%s/s%d.sav", fsdir, i);
f = fopen (name, "r");
if (!f)
continue;
@@ -771,7 +771,7 @@
if(strcmp(cl_name.string, setup_myname) != 0)
Cbuf_AddText ( va ("name \"%s\"\n", setup_myname) );
if(strcmp(hostname.string, setup_hostname) != 0)
- Cvar_Set("hostname", setup_hostname);
+ setcvar("hostname", setup_hostname);
if(setup_top != setup_oldtop || setup_bottom != setup_oldbottom)
Cbuf_AddText(va("color %d %d\n", setup_top, setup_bottom));
m_entersound = true;
@@ -1020,7 +1020,7 @@
scr_viewsize.value = 30;
if (scr_viewsize.value > 120)
scr_viewsize.value = 120;
- Cvar_SetValue ("viewsize", scr_viewsize.value);
+ setcvarv ("viewsize", scr_viewsize.value);
break;
case 4: // gamma
v_gamma.value -= dir * 0.05;
@@ -1028,7 +1028,7 @@
v_gamma.value = 0.5;
if (v_gamma.value > 1)
v_gamma.value = 1;
- Cvar_SetValue ("gamma", v_gamma.value);
+ setcvarv ("gamma", v_gamma.value);
break;
case 5: // mouse speed
sensitivity.value += dir * 0.5;
@@ -1036,7 +1036,7 @@
sensitivity.value = 1;
if (sensitivity.value > 11)
sensitivity.value = 11;
- Cvar_SetValue ("sensitivity", sensitivity.value);
+ setcvarv ("sensitivity", sensitivity.value);
break;
case 6: // music volume
bgmvolume.value += dir * 0.1;
@@ -1044,7 +1044,7 @@
bgmvolume.value = 0;
if (bgmvolume.value > 1)
bgmvolume.value = 1;
- Cvar_SetValue ("bgmvolume", bgmvolume.value);
+ setcvarv ("bgmvolume", bgmvolume.value);
break;
case 7: // sfx volume
volume.value += dir * 0.1;
@@ -1052,32 +1052,32 @@
volume.value = 0;
if (volume.value > 1)
volume.value = 1;
- Cvar_SetValue ("volume", volume.value);
+ setcvarv ("volume", volume.value);
break;
case 8: // allways run
if (cl_forwardspeed.value > 200)
{
- Cvar_SetValue ("cl_forwardspeed", 200);
- Cvar_SetValue ("cl_backspeed", 200);
+ setcvarv ("cl_forwardspeed", 200);
+ setcvarv ("cl_backspeed", 200);
}
else
{
- Cvar_SetValue ("cl_forwardspeed", 400);
- Cvar_SetValue ("cl_backspeed", 400);
+ setcvarv ("cl_forwardspeed", 400);
+ setcvarv ("cl_backspeed", 400);
}
break;
case 9: // invert mouse
- Cvar_SetValue ("m_pitch", -m_pitch.value);
+ setcvarv ("m_pitch", -m_pitch.value);
break;
case 10: // lookspring
- Cvar_SetValue ("lookspring", !lookspring.value);
+ setcvarv ("lookspring", !lookspring.value);
break;
case 11: // lookstrafe
- Cvar_SetValue ("lookstrafe", !lookstrafe.value);
+ setcvarv ("lookstrafe", !lookstrafe.value);
break;
}
}
@@ -2572,7 +2572,7 @@
break;
case 2:
- Cvar_SetValue ("coop", coop.value ? 0 : 1);
+ setcvarv ("coop", coop.value ? 0 : 1);
break;
case 3:
@@ -2581,35 +2581,35 @@
else
count = 2;
- Cvar_SetValue ("teamplay", teamplay.value + dir);
+ setcvarv ("teamplay", teamplay.value + dir);
if (teamplay.value > count)
- Cvar_SetValue ("teamplay", 0);
+ setcvarv ("teamplay", 0);
else if (teamplay.value < 0)
- Cvar_SetValue ("teamplay", count);
+ setcvarv ("teamplay", count);
break;
case 4:
- Cvar_SetValue ("skill", skill.value + dir);
+ setcvarv ("skill", skill.value + dir);
if (skill.value > 3)
- Cvar_SetValue ("skill", 0);
+ setcvarv ("skill", 0);
if (skill.value < 0)
- Cvar_SetValue ("skill", 3);
+ setcvarv ("skill", 3);
break;
case 5:
- Cvar_SetValue ("fraglimit", fraglimit.value + dir*10);
+ setcvarv ("fraglimit", fraglimit.value + dir*10);
if (fraglimit.value > 100)
- Cvar_SetValue ("fraglimit", 0);
+ setcvarv ("fraglimit", 0);
if (fraglimit.value < 0)
- Cvar_SetValue ("fraglimit", 100);
+ setcvarv ("fraglimit", 100);
break;
case 6:
- Cvar_SetValue ("timelimit", timelimit.value + dir*5);
+ setcvarv ("timelimit", timelimit.value + dir*5);
if (timelimit.value > 60)
- Cvar_SetValue ("timelimit", 0);
+ setcvarv ("timelimit", 0);
if (timelimit.value < 0)
- Cvar_SetValue ("timelimit", 60);
+ setcvarv ("timelimit", 60);
break;
case 7:
--- a/mkfile
+++ b/mkfile
@@ -13,7 +13,6 @@
cmd.$O\
common.$O\
console.$O\
- crc.$O\
cvar.$O\
draw.$O\
d_edge.$O\
@@ -28,6 +27,7 @@
d_surf.$O\
d_vars.$O\
d_zpoint.$O\
+ fs.$O\
host.$O\
host_cmd.$O\
keys.$O\
@@ -42,6 +42,7 @@
pr_cmds.$O\
pr_edict.$O\
pr_exec.$O\
+ qk1.$O\
r_aclip.$O\
r_alias.$O\
r_bsp.$O\
@@ -77,6 +78,8 @@
net_udp.$O\
HFILES=\
+ dat.h\
+ fns.h\
adivtab.h\
anorms.h\
bspfile.h\
@@ -85,7 +88,6 @@
cmd.h\
common.h\
console.h\
- crc.h\
cvar.h\
d_iface.h\
d_local.h\
--- a/model.c
+++ b/model.c
@@ -51,7 +51,7 @@
Mod_LoadModel (mod, true);
if (!mod->cache.data)
- Sys_Error ("Mod_Extradata: caching failed");
+ fatal ("Mod_Extradata: caching failed");
return mod->cache.data;
}
@@ -67,7 +67,7 @@
mplane_t *plane;
if (!model || !model->nodes)
- Sys_Error ("Mod_PointInLeaf: bad model");
+ fatal ("Mod_PointInLeaf: bad model");
node = model->nodes;
while (1)
@@ -167,7 +167,7 @@
model_t *avail = nil;
if (!name[0])
- Sys_Error ("Mod_ForName: nil name");
+ fatal ("Mod_ForName: nil name");
//
// search the currently loaded models
@@ -193,7 +193,7 @@
Cache_Free (&mod->cache);
}
else
- Sys_Error ("mod_numknown == MAX_MOD_KNOWN");
+ fatal ("mod_numknown == MAX_MOD_KNOWN");
}
else
mod_numknown++;
@@ -252,23 +252,18 @@
//
// because the world is so huge, load it one piece at a time
//
-
-//
-// load the file
-//
- buf = (uint *)COM_LoadStackFile(mod->name, stackbuf, sizeof stackbuf);
- if (!buf)
- {
- if (crash)
- Sys_Error ("Mod_NumForName: %s not found", mod->name);
+
+ buf = loadstklmp(mod->name, stackbuf, sizeof stackbuf, nil);
+ if(buf == nil){
+ if(crash)
+ fatal("Mod_LoadModel %s: not found: %r", mod->name);
return nil;
}
-
+
//
// allocate a new model
//
- COM_FileBase (mod->name, loadname);
-
+ radix(mod->name, loadname);
loadmodel = mod;
//
@@ -362,7 +357,7 @@
mt->offsets[j] = LittleLong (mt->offsets[j]);
if ( (mt->width & 15) || (mt->height & 15) )
- Sys_Error ("Texture %s is not 16 aligned", mt->name);
+ fatal ("Texture %s is not 16 aligned", mt->name);
pixels = mt->width*mt->height/64*85;
tx = Hunk_AllocName(pixels + sizeof *tx, loadname);
loadmodel->textures[i] = tx;
@@ -413,7 +408,7 @@
altmax++;
}
else
- Sys_Error ("Bad animating texture %s", tx->name);
+ fatal ("Bad animating texture %s", tx->name);
for (j=i+1 ; j<m->nummiptex ; j++)
{
@@ -441,7 +436,7 @@
altmax = num+1;
}
else
- Sys_Error ("Bad animating texture %s", tx->name);
+ fatal ("Bad animating texture %s", tx->name);
}
#define ANIM_CYCLE 2
@@ -450,7 +445,7 @@
{
tx2 = anims[j];
if (!tx2)
- Sys_Error("Missing frame %d of %s", j, tx->name);
+ fatal("Missing frame %d of %s", j, tx->name);
tx2->anim_total = max * ANIM_CYCLE;
tx2->anim_min = j * ANIM_CYCLE;
tx2->anim_max = (j+1) * ANIM_CYCLE;
@@ -462,7 +457,7 @@
{
tx2 = altanims[j];
if (!tx2)
- Sys_Error("Missing frame %d of %s", j, tx->name);
+ fatal("Missing frame %d of %s", j, tx->name);
tx2->anim_total = altmax * ANIM_CYCLE;
tx2->anim_min = j * ANIM_CYCLE;
tx2->anim_max = (j+1) * ANIM_CYCLE;
@@ -537,7 +532,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- Sys_Error("Mod_LoadVertexes: funny lump size in %s", loadmodel->name);
+ fatal("Mod_LoadVertexes: funny lump size in %s", loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName(count * sizeof *out, loadname);
@@ -565,7 +560,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- Sys_Error("Mod_LoadSubmodels: funny lump size in %s", loadmodel->name);
+ fatal("Mod_LoadSubmodels: funny lump size in %s", loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName(count * sizeof *out, loadname);
@@ -601,7 +596,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- Sys_Error("Mod_LoadEdges: funny lump size in %s", loadmodel->name);
+ fatal("Mod_LoadEdges: funny lump size in %s", loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName((count+1) * sizeof *out, loadname);
@@ -630,7 +625,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- Sys_Error("Mod_LoadTexInfo: funny lump size in %s", loadmodel->name);
+ fatal("Mod_LoadTexInfo: funny lump size in %s", loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName(count * sizeof *out, loadname);
@@ -670,7 +665,7 @@
else
{
if (miptex >= loadmodel->numtextures)
- Sys_Error ("miptex >= loadmodel->numtextures");
+ fatal ("miptex >= loadmodel->numtextures");
out->texture = loadmodel->textures[miptex];
if (!out->texture)
{
@@ -730,7 +725,7 @@
s->texturemins[i] = bmins[i] * 16;
s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 256)
- Sys_Error ("Bad surface extents");
+ fatal ("Bad surface extents");
}
}
@@ -749,7 +744,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- Sys_Error("Mod_LoadFaces: funny lump size in %s", loadmodel->name);
+ fatal("Mod_LoadFaces: funny lump size in %s", loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName(count * sizeof *out, loadname);
@@ -832,7 +827,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- Sys_Error("Mod_LoadNodes: funny lump size in %s", loadmodel->name);
+ fatal("Mod_LoadNodes: funny lump size in %s", loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName(count * sizeof *out, loadname);
@@ -879,7 +874,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- Sys_Error("Mod_LoadLeafs: funny lump size in %s", loadmodel->name);
+ fatal("Mod_LoadLeafs: funny lump size in %s", loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName(count * sizeof *out, loadname);
@@ -926,7 +921,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- Sys_Error("Mod_LoadClipnodes: funny lump size in %s", loadmodel->name);
+ fatal("Mod_LoadClipnodes: funny lump size in %s", loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName(count * sizeof *out, loadname);
@@ -1017,7 +1012,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- Sys_Error("Mod_LoadMarksurfaces: funny lump size in %s", loadmodel->name);
+ fatal("Mod_LoadMarksurfaces: funny lump size in %s", loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName(count * sizeof *out, loadname);
@@ -1028,7 +1023,7 @@
{
j = LittleShort(in[i]);
if (j >= loadmodel->numsurfaces)
- Sys_Error ("Mod_ParseMarksurfaces: bad surface number");
+ fatal ("Mod_ParseMarksurfaces: bad surface number");
out[i] = loadmodel->surfaces + j;
}
}
@@ -1045,7 +1040,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- Sys_Error("Mod_LoadSurfedges: funny lump size in %s", loadmodel->name);
+ fatal("Mod_LoadSurfedges: funny lump size in %s", loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName(count * sizeof *out, loadname);
@@ -1071,7 +1066,7 @@
in = (void *)(mod_base + l->fileofs);
if (l->filelen % sizeof(*in))
- Sys_Error("Mod_LoadPlanes: funny lump size in %s", loadmodel->name);
+ fatal("Mod_LoadPlanes: funny lump size in %s", loadmodel->name);
count = l->filelen / sizeof(*in);
out = Hunk_AllocName(count * 2 * sizeof *out, loadname);
@@ -1129,7 +1124,7 @@
i = LittleLong (header->version);
if (i != BSPVERSION)
- Sys_Error("Mod_LoadBrushModel: %s has wrong version number (%d should be %d)", mod->name, i, BSPVERSION);
+ fatal("Mod_LoadBrushModel: %s has wrong version number (%d should be %d)", mod->name, i, BSPVERSION);
// swap all the lumps
mod_base = (byte *)header;
@@ -1295,7 +1290,7 @@
{
*poutintervals = LittleFloat (pin_intervals->interval);
if (*poutintervals <= 0.0)
- Sys_Error ("Mod_LoadAliasGroup: interval<=0");
+ fatal ("Mod_LoadAliasGroup: interval<=0");
poutintervals++;
pin_intervals++;
@@ -1334,7 +1329,7 @@
for(i=0; i<skinsize; i++)
pusskin[i] = d_8to16table[pinskin[i]];
}else
- Sys_Error("Mod_LoadAliasSkin: invalid r_pixbytes: %d\n", r_pixbytes);
+ fatal("Mod_LoadAliasSkin: invalid r_pixbytes: %d\n", r_pixbytes);
pinskin += skinsize;
@@ -1379,7 +1374,7 @@
{
*poutskinintervals = LittleFloat (pinskinintervals->interval);
if (*poutskinintervals <= 0)
- Sys_Error ("Mod_LoadAliasSkinGroup: interval<=0");
+ fatal ("Mod_LoadAliasSkinGroup: interval<=0");
poutskinintervals++;
pinskinintervals++;
@@ -1424,7 +1419,7 @@
version = LittleLong (pinmodel->version);
if (version != ALIAS_VERSION)
- Sys_Error ("%s has wrong version number (%d should be %d)",
+ fatal ("%s has wrong version number (%d should be %d)",
mod->name, version, ALIAS_VERSION);
//
@@ -1454,21 +1449,21 @@
pmodel->skinheight = LittleLong (pinmodel->skinheight);
if (pmodel->skinheight > MAX_LBM_HEIGHT)
- Sys_Error ("model %s has a skin taller than %d", mod->name,
+ fatal ("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);
+ fatal ("model %s has no vertices", mod->name);
if (pmodel->numverts > MAXALIASVERTS)
- Sys_Error ("model %s has too many vertices", mod->name);
+ fatal ("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);
+ fatal ("model %s has no triangles", mod->name);
pmodel->numframes = LittleLong (pinmodel->numframes);
pmodel->size = LittleFloat (pinmodel->size) * ALIAS_BASE_SIZE_RATIO;
@@ -1486,7 +1481,7 @@
numframes = pmodel->numframes;
if (pmodel->skinwidth & 0x03)
- Sys_Error ("Mod_LoadAliasModel: skinwidth not multiple of 4");
+ fatal ("Mod_LoadAliasModel: skinwidth not multiple of 4");
pheader->model = (byte *)pmodel - (byte *)pheader;
@@ -1496,7 +1491,7 @@
skinsize = pmodel->skinheight * pmodel->skinwidth;
if (numskins < 1)
- Sys_Error ("Mod_LoadAliasModel: Invalid # of skins: %d\n", numskins);
+ fatal ("Mod_LoadAliasModel: Invalid # of skins: %d\n", numskins);
pskintype = (daliasskintype_t *)&pinmodel[1];
@@ -1568,7 +1563,7 @@
// load the frames
//
if (numframes < 1)
- Sys_Error ("Mod_LoadAliasModel: Invalid # of frames: %d\n", numframes);
+ fatal ("Mod_LoadAliasModel: Invalid # of frames: %d\n", numframes);
pframetype = (daliasframetype_t *)&pintriangles[pmodel->numtris];
@@ -1660,7 +1655,7 @@
for(i=0 ; i<size ; i++)
ppixout[i] = d_8to16table[ppixin[i]];
}else
- Sys_Error("Mod_LoadSpriteFrame: invalid r_pixbytes: %d\n", r_pixbytes);
+ fatal("Mod_LoadSpriteFrame: invalid r_pixbytes: %d\n", r_pixbytes);
return (void *)((byte *)pinframe + size + sizeof *pinframe);
}
@@ -1701,7 +1696,7 @@
{
*poutintervals = LittleFloat (pin_intervals->interval);
if (*poutintervals <= 0.0)
- Sys_Error ("Mod_LoadSpriteGroup: interval<=0");
+ fatal ("Mod_LoadSpriteGroup: interval<=0");
poutintervals++;
pin_intervals++;
@@ -1737,7 +1732,7 @@
version = LittleLong (pin->version);
if (version != SPRITE_VERSION)
- Sys_Error ("%s has wrong version number "
+ fatal ("%s has wrong version number "
"(%d should be %d)", mod->name, version, SPRITE_VERSION);
numframes = LittleLong (pin->numframes);
@@ -1764,7 +1759,7 @@
// load the frames
//
if (numframes < 1)
- Sys_Error ("Mod_LoadSpriteModel: Invalid # of frames: %d\n", numframes);
+ fatal ("Mod_LoadSpriteModel: Invalid # of frames: %d\n", numframes);
mod->numframes = numframes;
mod->flags = 0;
--- a/model.h
+++ b/model.h
@@ -278,7 +278,7 @@
typedef struct model_s
{
- char name[MAX_QPATH];
+ char name[Npath];
qboolean needload; // bmodels and sprites don't cache normally
modtype_t type;
--- a/net_dgrm.c
+++ b/net_dgrm.c
@@ -141,13 +141,13 @@
#ifdef DEBUG
if (data->cursize == 0)
- Sys_Error("Datagram_SendMessage: zero length message\n");
+ fatal("Datagram_SendMessage: zero length message\n");
if (data->cursize > NET_MAXMESSAGE)
- Sys_Error("Datagram_SendMessage: message too big %ud\n", data->cursize);
+ fatal("Datagram_SendMessage: message too big %ud\n", data->cursize);
if (sock->canSend == false)
- Sys_Error("SendMessage: called with canSend == false\n");
+ fatal("SendMessage: called with canSend == false\n");
#endif
memcpy(sock->sendMessage, data->data, data->cursize);
@@ -267,10 +267,10 @@
#ifdef DEBUG
if (data->cursize == 0)
- Sys_Error("Datagram_SendUnreliableMessage: zero length message\n");
+ fatal("Datagram_SendUnreliableMessage: zero length message\n");
if (data->cursize > MAX_DATAGRAM)
- Sys_Error("Datagram_SendUnreliableMessage: message too big %ud\n", data->cursize);
+ fatal("Datagram_SendUnreliableMessage: message too big %ud\n", data->cursize);
#endif
packetLen = NET_HEADERSIZE + data->cursize;
@@ -526,7 +526,7 @@
break;
if (MSG_ReadByte() != CCREP_PLAYER_INFO)
- Sys_Error("Unexpected repsonse to Player Info request\n");
+ fatal("Unexpected repsonse to Player Info request\n");
MSG_ReadByte(); /* playerNumber */
strcpy(name, MSG_ReadString());
--- a/net_loop.c
+++ b/net_loop.c
@@ -143,7 +143,7 @@
bufferLength = &((qsocket_t *)sock->driverdata)->receiveMessageLength;
if ((*bufferLength + data->cursize + 4) > NET_MAXMESSAGE)
- Sys_Error("Loop_SendMessage: overflow\n");
+ fatal("Loop_SendMessage: overflow\n");
buffer = ((qsocket_t *)sock->driverdata)->receiveMessage + *bufferLength;
--- a/net_main.c
+++ b/net_main.c
@@ -140,7 +140,7 @@
break;
}
if (!s)
- Sys_Error ("NET_FreeQSocket: not active\n");
+ fatal ("NET_FreeQSocket: not active\n");
}
// add it to free list
@@ -202,9 +202,9 @@
svs.maxclients = n;
if (n == 1)
- Cvar_Set ("deathmatch", "0");
+ setcvar ("deathmatch", "0");
else
- Cvar_Set ("deathmatch", "1");
+ setcvar ("deathmatch", "1");
}
@@ -699,7 +699,7 @@
if (i < com_argc-1)
DEFAULTnet_hostport = atoi(com_argv[i+1]);
else
- Sys_Error ("NET_Init: you must specify a number after -port");
+ fatal ("NET_Init: you must specify a number after -port");
}
net_hostport = DEFAULTnet_hostport;
--- a/net_udp.c
+++ b/net_udp.c
@@ -41,11 +41,11 @@
if(strcmp(hostname.string, "UNNAMED") == 0)
{
buff[15] = 0;
- Cvar_Set ("hostname", buff);
+ setcvar ("hostname", buff);
}
if ((net_controlsocket = UDP_OpenSocket (0)) == -1)
- Sys_Error("UDP_Init: Unable to open control socket\n");
+ fatal("UDP_Init: Unable to open control socket\n");
((struct sockaddr_in *)&broadcastaddr)->sin_family = AF_INET;
((struct sockaddr_in *)&broadcastaddr)->sin_addr.s_addr = INADDR_BROADCAST;
@@ -80,7 +80,7 @@
if (net_acceptsocket != -1)
return;
if ((net_acceptsocket = UDP_OpenSocket (net_hostport)) == -1)
- Sys_Error ("UDP_Listen: Unable to open accept socket\n");
+ fatal ("UDP_Listen: Unable to open accept socket\n");
return;
}
@@ -204,7 +204,7 @@
return -1;
if (ioctl (net_acceptsocket, FIONREAD, &available) == -1)
- Sys_Error ("UDP: ioctlsocket (FIONREAD) failed\n");
+ fatal ("UDP: ioctlsocket (FIONREAD) failed\n");
if (available)
return net_acceptsocket;
return -1;
@@ -249,7 +249,7 @@
if (socket != net_broadcastsocket)
{
if (net_broadcastsocket != 0)
- Sys_Error("Attempted to use multiple broadcasts sockets\n");
+ fatal("Attempted to use multiple broadcasts sockets\n");
ret = UDP_MakeSocketBroadcastCapable (socket);
if (ret == -1)
{
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -553,13 +553,13 @@
attenuation = G_FLOAT(OFS_PARM4);
if (volume < 0 || volume > 255)
- Sys_Error ("SV_StartSound: volume = %d", volume);
+ fatal ("SV_StartSound: volume = %d", volume);
if (attenuation < 0 || attenuation > 4)
- Sys_Error ("SV_StartSound: attenuation = %f", attenuation);
+ fatal ("SV_StartSound: attenuation = %f", attenuation);
if (channel < 0 || channel > 7)
- Sys_Error ("SV_StartSound: channel = %d", channel);
+ fatal ("SV_StartSound: channel = %d", channel);
SV_StartSound (entity, channel, sample, volume, attenuation);
}
@@ -818,7 +818,7 @@
var = G_STRING(OFS_PARM0);
val = G_STRING(OFS_PARM1);
- Cvar_Set (var, val);
+ setcvar (var, val);
}
/*
--- a/pr_edict.c
+++ b/pr_edict.c
@@ -15,8 +15,6 @@
float *pr_globals; // same as pr_global_struct
int pr_edict_size; // in bytes
-unsigned short pr_crc;
-
int type_size[8] = {1,sizeof(string_t)/4,1,3,1,1,sizeof(func_t)/4,sizeof(void *)/4};
ddef_t *ED_FieldAtOfs (int ofs);
@@ -94,7 +92,7 @@
}
if (i == MAX_EDICTS)
- Sys_Error ("ED_Alloc: no free edicts");
+ fatal ("ED_Alloc: no free edicts");
sv.num_edicts++;
e = EDICT_NUM(i);
@@ -650,7 +648,7 @@
if (com_token[0] == '}')
break;
if (!data)
- Sys_Error ("ED_ParseEntity: EOF without closing brace");
+ fatal ("ED_ParseEntity: EOF without closing brace");
strcpy (keyname, com_token);
@@ -657,10 +655,10 @@
// parse value
data = COM_Parse (data);
if (!data)
- Sys_Error ("ED_ParseEntity: EOF without closing brace");
+ fatal ("ED_ParseEntity: EOF without closing brace");
if (com_token[0] == '}')
- Sys_Error ("ED_ParseEntity: closing brace without data");
+ fatal ("ED_ParseEntity: closing brace without data");
key = ED_FindGlobal (keyname);
if (!key)
@@ -813,7 +811,7 @@
if (com_token[0] == '}')
break;
if (!data)
- Sys_Error ("ED_ParseEntity: EOF without closing brace");
+ fatal ("ED_ParseEntity: EOF without closing brace");
// anglehack is to allow QuakeEd to write single scalar angles
// and allow them to be turned into vectors. (FIXME...)
@@ -842,10 +840,10 @@
// parse value
data = COM_Parse (data);
if (!data)
- Sys_Error ("ED_ParseEntity: EOF without closing brace");
+ fatal ("ED_ParseEntity: EOF without closing brace");
if (com_token[0] == '}')
- Sys_Error ("ED_ParseEntity: closing brace without data");
+ fatal ("ED_ParseEntity: closing brace without data");
init = true;
@@ -912,7 +910,7 @@
if (!data)
break;
if (com_token[0] != '{')
- Sys_Error ("ED_LoadFromFile: found %s when expecting {",com_token);
+ fatal ("ED_LoadFromFile: found %s when expecting {",com_token);
if (!ent)
ent = EDICT_NUM(0);
@@ -976,21 +974,21 @@
*/
void PR_LoadProgs (void)
{
- int i;
+ int i, n;
// flush the non-C variable lookup cache
for (i=0 ; i<GEFV_CACHESIZE ; i++)
gefvCache[i].field[0] = 0;
- CRC_Init (&pr_crc);
+ initcrc();
- progs = (dprograms_t *)COM_LoadHunkFile ("progs.dat");
- if (!progs)
- Sys_Error ("PR_LoadProgs: couldn't load progs.dat");
- print("Programs occupy %lldK.\n", com_filesize/1024);
+ progs = loadhunklmp("progs.dat", &n);
+ if(progs == nil)
+ fatal("PR_LoadProgs: failed to load progs.dat: %r");
+ print("Programs occupy %dK.\n", n/1024);
- for (i=0 ; i<com_filesize ; i++)
- CRC_ProcessByte (&pr_crc, ((byte *)progs)[i]);
+ for (i=0 ; i<n ; i++)
+ crc (((byte *)progs)[i]);
// byte swap the header
for (i=0 ; i<sizeof(*progs)/4 ; i++)
@@ -997,9 +995,9 @@
((int *)progs)[i] = LittleLong ( ((int *)progs)[i] );
if (progs->version != PROG_VERSION)
- Sys_Error ("progs.dat has wrong version number (%d should be %d)", progs->version, PROG_VERSION);
+ fatal ("progs.dat has wrong version number (%d should be %d)", progs->version, PROG_VERSION);
if (progs->crc != PROGHEADER_CRC)
- Sys_Error ("progs.dat system vars have been modified, progdefs.h is out of date");
+ fatal ("progs.dat system vars have been modified, progdefs.h is out of date");
pr_functions = (dfunction_t *)((byte *)progs + progs->ofs_functions);
pr_strings = (char *)progs + progs->ofs_strings;
@@ -1042,7 +1040,7 @@
{
pr_fielddefs[i].type = LittleShort (pr_fielddefs[i].type);
if (pr_fielddefs[i].type & DEF_SAVEGLOBAL)
- Sys_Error ("PR_LoadProgs: pr_fielddefs[i].type & DEF_SAVEGLOBAL");
+ fatal ("PR_LoadProgs: pr_fielddefs[i].type & DEF_SAVEGLOBAL");
pr_fielddefs[i].ofs = LittleShort (pr_fielddefs[i].ofs);
pr_fielddefs[i].s_name = LittleLong (pr_fielddefs[i].s_name);
}
@@ -1081,7 +1079,7 @@
edict_t *EDICT_NUM(int n)
{
if (n < 0 || n >= sv.max_edicts)
- Sys_Error ("EDICT_NUM: bad number %d", n);
+ fatal ("EDICT_NUM: bad number %d", n);
return (edict_t *)((byte *)sv.edicts+ (n)*pr_edict_size);
}
@@ -1093,6 +1091,6 @@
b = b / pr_edict_size;
if (b < 0 || b >= sv.num_edicts)
- Sys_Error ("NUM_FOR_EDICT: bad pointer");
+ fatal ("NUM_FOR_EDICT: bad pointer");
return b;
}
--- a/pr_exec.c
+++ b/pr_exec.c
@@ -317,7 +317,7 @@
int i, c;
if (pr_depth <= 0)
- Sys_Error ("prog stack underflow");
+ fatal ("prog stack underflow");
// restore locals from the stack
c = pr_xfunction->locals;
--- a/progs.h
+++ b/progs.h
@@ -105,8 +105,6 @@
extern dfunction_t *pr_xfunction;
extern int pr_xstatement;
-extern unsigned short pr_crc;
-
void PR_RunError (char *error, ...);
void ED_PrintEdicts (void);
@@ -118,3 +116,5 @@
void M_Keydown (int key);
void M_ToggleMenu_f (void);
void M_Draw (void);
+
+#pragma varargck argpos PR_RunError 1
--- /dev/null
+++ b/qk1.c
@@ -1,0 +1,31 @@
+#include <u.h>
+#include <libc.h>
+#include <stdio.h>
+#include "quakedef.h"
+
+static int debug;
+
+void
+dprint(char *fmt, ...)
+{
+ char s[256];
+ va_list arg;
+
+ if(!debug)
+ return;
+ va_start(arg, fmt);
+ vseprint(s, s+sizeof s, fmt, arg);
+ va_end(arg);
+ fprint(2, "%s\n", s);
+}
+
+void
+fatal(char *fmt, ...)
+{
+ va_list arg;
+
+ Host_Shutdown();
+ va_start(arg, fmt);
+ sysfatal(fmt, arg);
+ va_end(arg);
+}
--- a/quakedef.h
+++ b/quakedef.h
@@ -1,5 +1,3 @@
-// quakedef.h -- primary header for client
-
#define QUAKE_GAME // as opposed to utilities
#define VERSION 1.09
//#define PARANOID // speed sapping error checking
@@ -30,13 +28,8 @@
// fall over
#define ROLL 2
-
-#define MAX_QPATH 64 // max length of a quake game pathname
-#define MAX_OSPATH 128 // max length of a filesystem pathname
-
#define ON_EPSILON 0.1 // point on plane side epsilon
-#define MAX_MSGLEN 8000 // max length of a reliable message
#define MAX_DATAGRAM 1024 // max length of unreliable message
//
@@ -147,6 +140,10 @@
// Use for multiplayer testing only - VERY dangerous!!!
// #define IDGODS
+typedef unsigned char byte;
+typedef enum {false, true} qboolean;
+
+#include "cvar.h"
#include "common.h"
#include "bspfile.h"
#include "vid.h"
@@ -165,9 +162,10 @@
int effects;
} entity_state_t;
+#include "dat.h"
+#include "fns.h"
#include "wad.h"
#include "draw.h"
-#include "cvar.h"
#include "screen.h"
#include "net.h"
#include "protocol.h"
@@ -186,7 +184,6 @@
#include "console.h"
#include "view.h"
#include "menu.h"
-#include "crc.h"
#include "cdaudio.h"
/* included here to avoid type incompatibilities errors from 2c(1),2l(1) */
@@ -202,7 +199,6 @@
typedef struct
{
char *basedir;
- char *cachedir; // for development over ISDN lines
int argc;
char **argv;
void *membase;
@@ -262,3 +258,7 @@
void Chase_Init (void);
void Chase_Reset (void);
void Chase_Update (void);
+
+#pragma varargck argpos Host_Error 1
+#pragma varargck argpos Host_EndGame 1
+#pragma varargck argpos Host_ClientCommands 1
--- a/r_alias.c
+++ b/r_alias.c
@@ -698,7 +698,7 @@
R_AliasSetupFrame ();
if (!currententity->colormap)
- Sys_Error ("R_AliasDrawModel: !currententity->colormap");
+ fatal ("R_AliasDrawModel: !currententity->colormap");
r_affinetridesc.drawtype = (currententity->trivial_accept == 3) &&
r_recursiveaffinetriangles;
--- a/r_bsp.c
+++ b/r_bsp.c
@@ -376,7 +376,7 @@
}
else
{
- Sys_Error ("no edges in bmodel");
+ fatal ("no edges in bmodel");
}
}
}
--- a/r_efrag.c
+++ b/r_efrag.c
@@ -249,7 +249,7 @@
break;
default:
- Sys_Error ("R_StoreEfrags: Bad entity type %d\n", clmodel->type);
+ fatal ("R_StoreEfrags: Bad entity type %d\n", clmodel->type);
}
}
}
--- a/r_local.h
+++ b/r_local.h
@@ -221,7 +221,6 @@
void R_DrawParticles (void);
void R_InitParticles (void);
void R_ClearParticles (void);
-void R_ReadPointFile_f (void);
void R_SurfacePatch (void);
extern int r_amodels_drawn;
--- a/r_main.c
+++ b/r_main.c
@@ -171,7 +171,7 @@
R_InitTurb ();
Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);
- Cmd_AddCommand ("pointfile", R_ReadPointFile_f);
+ Cmd_AddCommand("pointfile", pointlmp);
Cvar_RegisterVariable (&r_draworder);
Cvar_RegisterVariable (&r_speeds);
@@ -195,8 +195,8 @@
Cvar_RegisterVariable (&r_aliastransbase);
Cvar_RegisterVariable (&r_aliastransadj);
- Cvar_SetValue ("r_maxedges", (float)NUMSTACKEDGES);
- Cvar_SetValue ("r_maxsurfs", (float)NUMSTACKSURFACES);
+ setcvarv ("r_maxedges", (float)NUMSTACKEDGES);
+ setcvarv ("r_maxsurfs", (float)NUMSTACKSURFACES);
view_clipplanes[0].leftedge = true;
view_clipplanes[1].rightedge = true;
@@ -927,7 +927,7 @@
Sys_LowFPPrecision ();
if (!cl_entities[0].model || !cl.worldmodel)
- Sys_Error ("R_RenderView: NULL worldmodel");
+ fatal ("R_RenderView: NULL worldmodel");
if (!r_dspeeds.value)
{
@@ -1006,16 +1006,16 @@
delta = (byte *)&dummy - r_stack_start;
if (delta < -10000 || delta > 10000)
- Sys_Error ("R_RenderView: called without enough stack");
+ fatal ("R_RenderView: called without enough stack");
if ( Hunk_LowMark() & 3 )
- Sys_Error ("Hunk is missaligned");
+ fatal ("Hunk is missaligned");
if ( (uintptr)(&dummy) & 3 )
- Sys_Error ("Stack is missaligned");
+ fatal ("Stack is missaligned");
if ( (uintptr)(&r_warpbuffer) & 3 )
- Sys_Error ("Globals are missaligned");
+ fatal ("Globals are missaligned");
R_RenderView_ ();
}
--- a/r_misc.c
+++ b/r_misc.c
@@ -349,10 +349,10 @@
// don't allow cheats in multiplayer
if (cl.maxclients > 1)
{
- Cvar_Set ("r_draworder", "0");
- Cvar_Set ("r_fullbright", "0");
- Cvar_Set ("r_ambient", "0");
- Cvar_Set ("r_drawflat", "0");
+ setcvar ("r_draworder", "0");
+ setcvar ("r_fullbright", "0");
+ setcvar ("r_ambient", "0");
+ setcvar ("r_drawflat", "0");
}
if (r_numsurfs.value)
@@ -360,7 +360,7 @@
if ((surface_p - surfaces) > r_maxsurfsseen)
r_maxsurfsseen = surface_p - surfaces;
- Con_Printf ("Used %d of %d surfs; %d max\n", surface_p - surfaces,
+ Con_Printf ("Used %zd of %zd surfs; %d max\n", surface_p - surfaces,
surf_max - surfaces, r_maxsurfsseen);
}
--- a/r_part.c
+++ b/r_part.c
@@ -115,55 +115,6 @@
particles[r_numparticles-1].next = nil;
}
-
-void R_ReadPointFile_f (void)
-{
- FILE *f;
- vec3_t org;
- int r;
- int c;
- particle_t *p;
- char name[MAX_OSPATH];
-
- sprint (name,"maps/%s.pts", sv.name);
-
- COM_FOpenFile (name, &f);
- if (!f)
- {
- Con_Printf ("couldn't open %s\n", name);
- return;
- }
-
- Con_Printf ("Reading %s...\n", name);
- c = 0;
- for ( ;; )
- {
- r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]);
- if (r != 3)
- break;
- c++;
-
- if (!free_particles)
- {
- Con_Printf ("Not enough free particles\n");
- break;
- }
- p = free_particles;
- free_particles = p->next;
- p->next = active_particles;
- active_particles = p;
-
- p->die = 99999;
- p->color = (-c)&15;
- p->type = pt_static;
- VectorCopy (vec3_origin, p->vel);
- VectorCopy (org, p->org);
- }
-
- fclose (f);
- Con_Printf ("%d points read\n", c);
-}
-
/*
===============
R_ParseParticleEffect
--- a/r_sprite.c
+++ b/r_sprite.c
@@ -170,7 +170,7 @@
if (nump < 3)
return;
if (nump >= MAXWORKINGVERTS)
- Sys_Error("R_SetupAndDrawSprite: too many points");
+ fatal("R_SetupAndDrawSprite: too many points");
}
// transform vertices into viewspace and project
@@ -372,7 +372,7 @@
}
else
{
- Sys_Error ("R_DrawSprite: Bad sprite type %d", psprite->type);
+ fatal ("R_DrawSprite: Bad sprite type %d", psprite->type);
}
R_RotateSprite (psprite->beamlength);
--- a/r_surf.c
+++ b/r_surf.c
@@ -197,9 +197,9 @@
{
base = base->anim_next;
if (!base)
- Sys_Error ("R_TextureAnimation: broken cycle");
+ fatal ("R_TextureAnimation: broken cycle");
if (++count > 100)
- Sys_Error ("R_TextureAnimation: infinite cycle");
+ fatal ("R_TextureAnimation: infinite cycle");
}
return base;
@@ -634,7 +634,7 @@
}
else
{
- Sys_Error ("Unknown tile type");
+ fatal ("Unknown tile type");
}
}
--- a/screen.c
+++ b/screen.c
@@ -183,7 +183,7 @@
float x;
if (fov_x < 1 || fov_x > 179)
- Sys_Error ("Bad fov: %f", fov_x);
+ fatal ("Bad fov: %f", fov_x);
x = width/tan(fov_x/360*M_PI);
@@ -217,15 +217,15 @@
// bound viewsize
if (scr_viewsize.value < 30)
- Cvar_Set ("viewsize","30");
+ setcvar ("viewsize","30");
if (scr_viewsize.value > 120)
- Cvar_Set ("viewsize","120");
+ setcvar ("viewsize","120");
// bound field of view
if (scr_fov.value < 10)
- Cvar_Set ("fov","10");
+ setcvar ("fov","10");
if (scr_fov.value > 170)
- Cvar_Set ("fov","170");
+ setcvar ("fov","170");
r_refdef.fov_x = scr_fov.value;
r_refdef.fov_y = CalcFov (r_refdef.fov_x, r_refdef.vrect.width, r_refdef.vrect.height);
@@ -271,7 +271,7 @@
*/
void SCR_SizeUp_f (void)
{
- Cvar_SetValue ("viewsize",scr_viewsize.value+10);
+ setcvarv ("viewsize",scr_viewsize.value+10);
vid.recalc_refdef = 1;
}
@@ -285,7 +285,7 @@
*/
void SCR_SizeDown_f (void)
{
- Cvar_SetValue ("viewsize",scr_viewsize.value-10);
+ setcvarv ("viewsize",scr_viewsize.value-10);
vid.recalc_refdef = 1;
}
@@ -561,7 +561,8 @@
for(i=0; i<3*256; i++)
*p++ = *pal++;
- COM_WriteFile(path, buf, p - buf);
+ USED(path);
+ /*COM_WriteFile(path, buf, p - buf);*/
}
static void
@@ -568,7 +569,7 @@
dopcx(void)
{
int i;
- char pcxname[12], checkname[MAX_OSPATH];
+ char pcxname[12], checkname[Nfspath];
writepcx = 0;
@@ -577,7 +578,7 @@
for(i=0; i<100; i++){
pcxname[5] = i / 10 + '0';
pcxname[6] = i % 10 + '0';
- sprint(checkname, "%s/%s", com_gamedir, pcxname);
+ sprint(checkname, "%s/%s", fsdir, pcxname);
if(access(checkname, AEXIST) == -1)
break;
}
--- a/server.h
+++ b/server.h
@@ -69,7 +69,7 @@
sizebuf_t message; // can be added to at any time,
// copied and clear once per frame
- byte msgbuf[MAX_MSGLEN];
+ byte msgbuf[Nmsg];
edict_t *edict; // EDICT_NUM(clientnum+1)
char name[32]; // for printing to other people
int colors;
@@ -202,3 +202,6 @@
void SV_RunClients (void);
void SV_SaveSpawnparms (void);
void SV_SpawnServer (char *server);
+
+#pragma varargck argpos SV_ClientPrintf 1
+#pragma varargck argpos SV_BroadcastPrintf 1
--- a/snd_dma.c
+++ b/snd_dma.c
@@ -96,7 +96,7 @@
Con_Printf ("sound system not started\n");
return;
}
-
+
Con_Printf("%5d stereo\n", shm->channels - 1);
Con_Printf("%5d samples\n", shm->samples);
Con_Printf("%5d samplepos\n", shm->samplepos);
@@ -103,7 +103,7 @@
Con_Printf("%5d samplebits\n", shm->samplebits);
Con_Printf("%5d submission_chunk\n", shm->submission_chunk);
Con_Printf("%5d speed\n", shm->speed);
- Con_Printf("0x%x dma buffer\n", shm->buffer);
+ Con_Printf("%#p dma buffer\n", shm->buffer);
Con_Printf("%5d total_channels\n", total_channels);
}
@@ -173,7 +173,7 @@
if (host_parms.memsize < 0x800000)
{
- Cvar_Set ("loadas8bit", "1");
+ setcvar("loadas8bit", "1");
Con_Printf ("loading all sounds as 8bit\n");
}
@@ -251,10 +251,10 @@
sfx_t *sfx;
if (name == nil)
- Sys_Error ("S_FindName: NULL\n");
+ fatal ("S_FindName: NULL\n");
- if(strlen(name) >= MAX_QPATH)
- Sys_Error ("Sound name too long: %s", name);
+ if(strlen(name) >= Npath)
+ fatal ("Sound name too long: %s", name);
// see if already loaded
for (i=0 ; i < num_sfx ; i++)
@@ -262,7 +262,7 @@
return &known_sfx[i];
if (num_sfx == MAX_SFX)
- Sys_Error ("S_FindName: out of sfx_t");
+ fatal ("S_FindName: out of sfx_t");
sfx = &known_sfx[i];
strcpy (sfx->name, name);
--- a/snd_mem.c
+++ b/snd_mem.c
@@ -100,15 +100,13 @@
// Con_Printf ("loading %s\n",namebuffer);
- data = COM_LoadStackFile(namebuffer, stackbuf, sizeof stackbuf);
-
- if (!data)
- {
- Con_Printf ("Couldn't load %s\n", namebuffer);
+ data = loadstklmp(namebuffer, stackbuf, sizeof stackbuf, &len);
+ if(data == nil){
+ Con_Printf("Couldn't load %s: %r\n", namebuffer);
return nil;
}
- info = GetWavinfo (s->name, data, com_filesize);
+ info = GetWavinfo (s->name, data, len);
if (info.channels != 1)
{
Con_Printf ("%s is a stereo sample\n",s->name);
@@ -195,7 +193,7 @@
return;
}
// if (iff_chunk_len > 1024*1024)
-// Sys_Error ("FindNextChunk: %d length is past the 1 meg sanity limit", iff_chunk_len);
+// fatal ("FindNextChunk: %d 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(strncmp((char *)data_p, name, 4) == 0)
@@ -221,7 +219,7 @@
memcpy (str, data_p, 4);
data_p += 4;
iff_chunk_len = GetLittleLong();
- Con_Printf ("0x%x : %s (%d)\n", (uintptr)(data_p - 4), str, iff_chunk_len);
+ Con_Printf ("0x%zud : %s (%d)\n", (uintptr)(data_p - 4), str, iff_chunk_len);
data_p += (iff_chunk_len + 1) & ~1;
} while (data_p < iff_end);
}
@@ -315,7 +313,7 @@
if (info.samples)
{
if (samples < info.samples)
- Sys_Error ("Sound %s has a bad loop length", name);
+ fatal ("Sound %s has a bad loop length", name);
}
else
info.samples = samples;
--- a/sound.h
+++ b/sound.h
@@ -20,7 +20,7 @@
typedef struct sfx_s
{
- char name[MAX_QPATH];
+ char name[Npath];
cache_user_t cache;
} sfx_t;
--- a/sv_main.c
+++ b/sv_main.c
@@ -108,13 +108,13 @@
int ent;
if (volume < 0 || volume > 255)
- Sys_Error ("SV_StartSound: volume = %d", volume);
+ fatal ("SV_StartSound: volume = %d", volume);
if (attenuation < 0 || attenuation > 4)
- Sys_Error ("SV_StartSound: attenuation = %f", attenuation);
+ fatal ("SV_StartSound: attenuation = %f", attenuation);
if (channel < 0 || channel > 7)
- Sys_Error ("SV_StartSound: channel = %d", channel);
+ fatal ("SV_StartSound: channel = %d", channel);
if (sv.datagram.cursize > MAX_DATAGRAM-16)
return;
@@ -176,7 +176,7 @@
char message[2048];
MSG_WriteByte (&client->message, svc_print);
- sprint(message, "%c\nVERSION %4.2f SERVER (%ud CRC)\n", 2, VERSION, pr_crc);
+ sprint(message, "%c\nVERSION %4.2f SERVER (%ud CRC)\n", 2, VERSION, crcn);
MSG_WriteString (&client->message,message);
MSG_WriteByte (&client->message, svc_serverinfo);
@@ -303,7 +303,7 @@
if (!svs.clients[i].active)
break;
if (i == svs.maxclients)
- Sys_Error ("Host_CheckForNewClients: no free clients");
+ fatal ("Host_CheckForNewClients: no free clients");
svs.clients[i].netconnection = ret;
SV_ConnectClient (i);
@@ -883,7 +883,7 @@
if (!strcmp(sv.model_precache[i], name))
return i;
if (i==MAX_MODELS || !sv.model_precache[i])
- Sys_Error ("SV_ModelIndex: model %s not precached", name);
+ fatal ("SV_ModelIndex: model %s not precached", name);
return i;
}
@@ -1015,7 +1015,7 @@
// let's not have any servers with no name
if (hostname.string[0] == 0)
- Cvar_Set ("hostname", "UNNAMED");
+ setcvar ("hostname", "UNNAMED");
scr_centertime_off = 0;
print("SV_SpawnServer: %s\n", server);
@@ -1033,7 +1033,7 @@
// make cvars consistant
//
if (coop.value)
- Cvar_SetValue ("deathmatch", 0);
+ setcvarv ("deathmatch", 0);
current_skill = (int)(skill.value + 0.5);
if (current_skill < 0)
current_skill = 0;
@@ -1040,7 +1040,7 @@
if (current_skill > 3)
current_skill = 3;
- Cvar_SetValue ("skill", (float)current_skill);
+ setcvarv ("skill", (float)current_skill);
//
// set up the new server
--- a/sv_phys.c
+++ b/sv_phys.c
@@ -251,7 +251,7 @@
break; // moved the entire distance
if (!trace.ent)
- Sys_Error ("SV_FlyMove: !trace.ent");
+ fatal ("SV_FlyMove: !trace.ent");
if (trace.plane.normal[2] > 0.7)
{
@@ -907,7 +907,7 @@
break;
default:
- Sys_Error ("SV_Physics_client: bad movetype %d", (int)ent->v.movetype);
+ fatal ("SV_Physics_client: bad movetype %d", (int)ent->v.movetype);
}
//
@@ -1161,7 +1161,7 @@
|| ent->v.movetype == MOVETYPE_FLYMISSILE)
SV_Physics_Toss (ent);
else
- Sys_Error ("SV_Physics: bad movetype %d", (int)ent->v.movetype);
+ fatal ("SV_Physics: bad movetype %d", (int)ent->v.movetype);
}
if (pr_global_struct->force_retouch)
--- a/sys.c
+++ b/sys.c
@@ -7,94 +7,13 @@
qboolean isDedicated;
mainstacksize = 512*1024;
-static char end1[] =
- " QUAKE: The Doomed Dimension by id Software\n"
- " ----------------------------------------------------------------------------\n"
- " CALL 1-800-IDGAMES TO ORDER OR FOR TECHNICAL SUPPORT\n"
- " PRICE: $45.00 (PRICES MAY VARY OUTSIDE THE US.)\n"
- "\n"
- " Yes! You only have one fourth of this incredible epic. That is because most\n"
- " of you have paid us nothing or at most, very little. You could steal the\n"
- " game from a friend. But we both know you'll be punished by God if you do.\n"
- " WHY RISK ETERNAL DAMNATION? CALL 1-800-IDGAMES AND BUY NOW!\n"
- " Remember, we love you almost as much as He does.\n"
- "\n"
- " Programming: John Carmack, Michael Abrash, John Cash\n"
- " Design: John Romero, Sandy Petersen, American McGee, Tim Willits\n"
- " Art: Adrian Carmack, Kevin Cloud\n"
- " Biz: Jay Wilbur, Mike Wilson, Donna Jackson\n"
- " Projects: Shawn Green Support: Barrett Alexander\n"
- " Sound Effects: Trent Reznor and Nine Inch Nails\n"
- " For other information or details on ordering outside the US, check out the\n"
- " files accompanying QUAKE or our website at http://www.idsoftware.com.\n"
- " Quake is a trademark of Id Software, inc., (c)1996 Id Software, inc.\n"
- " All rights reserved. NIN logo is a registered trademark licensed to\n"
- " Nothing Interactive, Inc. All rights reserved.\n";
-static char end2[] =
- " QUAKE by id Software\n"
- " -----------------------------------------------------------------------------\n"
- " Why did you quit from the registered version of QUAKE? Did the\n"
- " scary monsters frighten you? Or did Mr. Sandman tug at your\n"
- " little lids? No matter! What is important is you love our\n"
- " game, and gave us your money. Congratulations, you are probably\n"
- " not a thief.\n"
- " Thank You.\n"
- " id Software is:\n"
- " PROGRAMMING: John Carmack, Michael Abrash, John Cash\n"
- " DESIGN: John Romero, Sandy Petersen, American McGee, Tim Willits\n"
- " ART: Adrian Carmack, Kevin Cloud\n"
- " BIZ: Jay Wilbur, Mike Wilson PROJECTS MAN: Shawn Green\n"
- " BIZ ASSIST: Donna Jackson SUPPORT: Barrett Alexander\n"
- " SOUND EFFECTS AND MUSIC: Trent Reznor and Nine Inch Nails\n"
- "\n"
- " If you need help running QUAKE refer to the text files in the\n"
- " QUAKE directory, or our website at http://www.idsoftware.com.\n"
- " If all else fails, call our technical support at 1-800-IDGAMES.\n"
- " Quake is a trademark of Id Software, inc., (c)1996 Id Software, inc.\n"
- " All rights reserved. NIN logo is a registered trademark licensed\n"
- " to Nothing Interactive, Inc. All rights reserved.\n";
-
-
void
Sys_Quit(void)
{
Host_Shutdown();
- print("\n");
- if(registered.value)
- print("%s\n", end2);
- else
- print("%s\n", end1);
threadexitsall(nil);
}
-void
-Sys_Error(char *fmt, ...)
-{
- char buf[1024], *p;
- va_list arg;
-
- va_start(arg, fmt);
- p = vseprint(buf, buf+sizeof buf, fmt, arg);
- va_end(arg);
- p = seprint(p, buf+sizeof buf, "\n");
- ewrite(2, buf, p-buf);
- Host_Shutdown();
- sysfatal("ending.");
-}
-
-ulong
-Sys_FileTime(char *path)
-{
- ulong t;
- Dir *d;
-
- if((d = dirstat(path)) == nil)
- return -1;
- t = d->mtime;
- free(d);
- return t;
-}
-
vlong
flen(int fd)
{
@@ -106,20 +25,6 @@
l = d->length;
free(d);
return l;
-}
-
-void
-eread(int fd, void *buf, long n)
-{
- if(read(fd, buf, n) <= 0)
- sysfatal("eread: %r");
-}
-
-void
-ewrite(int fd, void *buf, long n)
-{
- if(write(fd, buf, n) != n)
- sysfatal("ewrite: %r");
}
double
--- a/sys.h
+++ b/sys.h
@@ -5,15 +5,11 @@
THnet = 3
};
-void Sys_Error(char *, ...);
void Sys_Quit(void);
void Sys_LowFPPrecision(void);
void Sys_HighFPPrecision(void);
void* emalloc(ulong);
-ulong Sys_FileTime(char *);
vlong flen(int);
-void eread(int, void *, long);
-void ewrite(int, void *, long);
double Sys_FloatTime(void);
char* Sys_ConsoleInput(void);
void Sys_SendKeyEvents(void); // call Key_Event() until the input queue is empty
--- a/vid.c
+++ b/vid.c
@@ -186,7 +186,6 @@
void
VID_Shutdown(void)
{
- Con_Printf("VID_Shutdown\n");
free(framebuf);
freeimage(fbim);
}
--- a/view.c
+++ b/view.c
@@ -842,9 +842,9 @@
// don't allow cheats in multiplayer
if (cl.maxclients > 1)
{
- Cvar_Set ("scr_ofsx", "0");
- Cvar_Set ("scr_ofsy", "0");
- Cvar_Set ("scr_ofsz", "0");
+ setcvar ("scr_ofsx", "0");
+ setcvar ("scr_ofsy", "0");
+ setcvar ("scr_ofsz", "0");
}
if (cl.intermission)
--- a/wad.c
+++ b/wad.c
@@ -53,11 +53,11 @@
wadinfo_t *header;
unsigned i;
int infotableofs;
-
- wad_base = COM_LoadHunkFile (filename);
- if (!wad_base)
- Sys_Error ("W_LoadWadFile: couldn't load %s", filename);
+ wad_base = loadhunklmp(filename, nil);
+ if(wad_base == nil)
+ fatal("W_LoadWadFile: failed to load %s: %r", filename);
+
header = (wadinfo_t *)wad_base;
if (header->identification[0] != 'W'
@@ -64,7 +64,7 @@
|| header->identification[1] != 'A'
|| header->identification[2] != 'D'
|| header->identification[3] != '2')
- Sys_Error ("Wad file %s doesn't have WAD2 id\n",filename);
+ fatal ("Wad file %s doesn't have WAD2 id\n",filename);
wad_numlumps = LittleLong(header->numlumps);
infotableofs = LittleLong(header->infotableofs);
@@ -100,7 +100,7 @@
return lump_p;
}
- Sys_Error ("W_GetLumpinfo: %s not found", name);
+ fatal ("W_GetLumpinfo: %s not found", name);
return nil;
}
@@ -118,7 +118,7 @@
lumpinfo_t *lump;
if (num < 0 || num > wad_numlumps)
- Sys_Error ("W_GetLumpNum: bad number: %d", num);
+ fatal ("W_GetLumpNum: bad number: %d", num);
lump = wad_lumps + num;
--- a/world.c
+++ b/world.c
@@ -121,12 +121,12 @@
if (ent->v.solid == SOLID_BSP)
{ // explicit hulls in the BSP model
if (ent->v.movetype != MOVETYPE_PUSH)
- Sys_Error ("SOLID_BSP without MOVETYPE_PUSH");
+ fatal ("SOLID_BSP without MOVETYPE_PUSH");
model = sv.models[ (int)ent->v.modelindex ];
if (!model || model->type != mod_brush)
- Sys_Error ("MOVETYPE_PUSH with a non bsp model");
+ fatal ("MOVETYPE_PUSH with a non bsp model");
VectorSubtract (maxs, mins, size);
if (size[0] < 3)
@@ -451,7 +451,7 @@
while (num >= 0)
{
if (num < hull->firstclipnode || num > hull->lastclipnode)
- Sys_Error ("SV_HullPointContents: bad node number");
+ fatal ("SV_HullPointContents: bad node number");
node = hull->clipnodes + num;
plane = hull->planes + node->planenum;
@@ -558,7 +558,7 @@
}
if (num < hull->firstclipnode || num > hull->lastclipnode)
- Sys_Error ("SV_RecursiveHullCheck: bad node number");
+ fatal ("SV_RecursiveHullCheck: bad node number");
//
// find the point distances
@@ -727,7 +727,7 @@
if (touch == clip->passedict)
continue;
if (touch->v.solid == SOLID_TRIGGER)
- Sys_Error ("Trigger in clipping list");
+ fatal ("Trigger in clipping list");
if (clip->type == MOVE_NOMONSTERS && touch->v.solid != SOLID_BSP)
continue;
--- a/zone.c
+++ b/zone.c
@@ -83,13 +83,13 @@
memblock_t *block, *other;
if (!ptr)
- Sys_Error ("Z_Free: NULL pointer");
+ fatal ("Z_Free: NULL pointer");
block = (memblock_t *)((uchar *)ptr - sizeof(memblock_t));
if (block->id != ZONEID)
- Sys_Error ("Z_Free: freed a pointer without ZONEID");
+ fatal ("Z_Free: freed a pointer without ZONEID");
if (block->tag == 0)
- Sys_Error ("Z_Free: freed a freed pointer");
+ fatal ("Z_Free: freed a freed pointer");
block->tag = 0; // mark as free
@@ -122,7 +122,7 @@
Z_CheckHeap(); // DEBUG
if((buf = Z_TagMalloc(size, 1)) == nil)
- Sys_Error("Z_Malloc: failed on allocation of %d bytes", size);
+ fatal("Z_Malloc: failed on allocation of %d bytes", size);
memset(buf, 0, size);
return buf;
@@ -134,7 +134,7 @@
memblock_t *start, *rover, *new, *base;
if (!tag)
- Sys_Error ("Z_TagMalloc: tried to use a 0 tag");
+ fatal ("Z_TagMalloc: tried to use a 0 tag");
//
// scan through the block list looking for the first free block
@@ -229,11 +229,11 @@
if (block->next == &mainzone->blocklist)
break; // all blocks have been hit
if ( (byte *)block + block->size != (byte *)block->next)
- Sys_Error ("Z_CheckHeap: block size does not touch the next block\n");
+ fatal ("Z_CheckHeap: block size does not touch the next block\n");
if ( block->next->prev != block)
- Sys_Error ("Z_CheckHeap: next block doesn't have proper back link\n");
+ fatal ("Z_CheckHeap: next block doesn't have proper back link\n");
if (!block->tag && !block->next->tag)
- Sys_Error ("Z_CheckHeap: two consecutive free blocks\n");
+ fatal ("Z_CheckHeap: two consecutive free blocks\n");
}
}
@@ -273,9 +273,9 @@
for (h = (hunk_t *)hunk_base ; (byte *)h != hunk_base + hunk_low_used ; )
{
if (h->sentinal != HUNK_SENTINAL)
- Sys_Error ("Hunk_Check: trahsed sentinal");
+ fatal ("Hunk_Check: trahsed sentinal");
if (h->size < 16 || h->size + (byte *)h - hunk_base > hunk_size)
- Sys_Error ("Hunk_Check: bad size");
+ fatal ("Hunk_Check: bad size");
h = (hunk_t *)((byte *)h+h->size);
}
}
@@ -331,9 +331,9 @@
// run consistancy checks
//
if (h->sentinal != HUNK_SENTINAL)
- Sys_Error ("Hunk_Check: trahsed sentinal");
+ fatal ("Hunk_Check: trahsed sentinal");
if (h->size < 16 || h->size + (byte *)h - hunk_base > hunk_size)
- Sys_Error ("Hunk_Check: bad size");
+ fatal ("Hunk_Check: bad size");
next = (hunk_t *)((byte *)h+h->size);
count++;
@@ -381,12 +381,12 @@
#endif
if (size < 0)
- Sys_Error ("Hunk_Alloc: bad size: %d", size);
+ fatal ("Hunk_Alloc: bad size: %d", size);
size = sizeof(hunk_t) + ((size+15)&~15);
if (hunk_size - hunk_low_used - hunk_high_used < size)
- Sys_Error ("Hunk_Alloc: failed on %d bytes",size);
+ fatal ("Hunk_Alloc: failed on %d bytes",size);
h = (hunk_t *)(hunk_base + hunk_low_used);
hunk_low_used += size;
@@ -420,7 +420,7 @@
void Hunk_FreeToLowMark (int mark)
{
if (mark < 0 || mark > hunk_low_used)
- Sys_Error ("Hunk_FreeToLowMark: bad mark %d", mark);
+ fatal ("Hunk_FreeToLowMark: bad mark %d", mark);
memset(hunk_base + mark, 0, hunk_low_used - mark);
hunk_low_used = mark;
}
@@ -444,7 +444,7 @@
Hunk_FreeToHighMark (hunk_tempmark);
}
if (mark < 0 || mark > hunk_high_used)
- Sys_Error ("Hunk_FreeToHighMark: bad mark %d", mark);
+ fatal ("Hunk_FreeToHighMark: bad mark %d", mark);
memset(hunk_base + hunk_size - hunk_high_used, 0, hunk_high_used - mark);
hunk_high_used = mark;
}
@@ -460,7 +460,7 @@
hunk_t *h;
if (size < 0)
- Sys_Error ("Hunk_HighAllocName: bad size: %d", size);
+ fatal ("Hunk_HighAllocName: bad size: %d", size);
if (hunk_tempactive)
{
@@ -626,7 +626,7 @@
void Cache_UnlinkLRU (cache_system_t *cs)
{
if (!cs->lru_next || !cs->lru_prev)
- Sys_Error ("Cache_UnlinkLRU: NULL link");
+ fatal ("Cache_UnlinkLRU: NULL link");
cs->lru_next->lru_prev = cs->lru_prev;
cs->lru_prev->lru_next = cs->lru_next;
@@ -637,7 +637,7 @@
void Cache_MakeLRU (cache_system_t *cs)
{
if (cs->lru_next || cs->lru_prev)
- Sys_Error ("Cache_MakeLRU: active link");
+ fatal ("Cache_MakeLRU: active link");
cache_head.lru_next->lru_prev = cs;
cs->lru_next = cache_head.lru_next;
@@ -662,7 +662,7 @@
if (!nobottom && cache_head.prev == &cache_head)
{
if (hunk_size - hunk_high_used - hunk_low_used < size)
- Sys_Error ("Cache_TryAlloc: %d is greater then free hunk", size);
+ fatal ("Cache_TryAlloc: %d is greater then free hunk", size);
new = (cache_system_t *) (hunk_base + hunk_low_used);
memset(new, 0, sizeof *new);
@@ -772,7 +772,7 @@
cache_system_t *cs;
if (!c->data)
- Sys_Error ("Cache_Free: not allocated");
+ fatal ("Cache_Free: not allocated");
cs = ((cache_system_t *)c->data) - 1;
@@ -819,10 +819,10 @@
cache_system_t *cs;
if (c->data)
- Sys_Error ("Cache_Alloc: allready allocated");
+ fatal ("Cache_Alloc: allready allocated");
if (size <= 0)
- Sys_Error ("Cache_Alloc: size %d", size);
+ fatal ("Cache_Alloc: size %d", size);
size = (size + sizeof(*cs) + 15) & ~15;
@@ -840,7 +840,7 @@
// free the least recently used cahedat
if (cache_head.lru_prev == &cache_head)
- Sys_Error ("Cache_Alloc: out of memory");
+ fatal ("Cache_Alloc: out of memory");
// not enough memory at all
Cache_Free ( cache_head.lru_prev->user );
}
@@ -873,7 +873,7 @@
if (p < com_argc-1)
zonesize = atoi(com_argv[p+1]) * 1024;
else
- Sys_Error ("Memory_Init: you must specify a size in KB after -zone");
+ fatal ("Memory_Init: you must specify a size in KB after -zone");
}
mainzone = Hunk_AllocName (zonesize, "zone" );
Z_ClearZone (mainzone, zonesize);