ref: e7c5e21800899bc725cf85d5c1e766ddc3efc187
parent: 57bae65b26afd0c01b4c65b3d7538cc96ef80ae8
author: qwx <qwx@sciops.net>
date: Fri Jul 19 03:16:54 EDT 2024
fix qw build; use nq PF_Random, nanosec, flen; call srand in both sv and cl
--- a/qw/cl_main.c
+++ b/qw/cl_main.c
@@ -123,7 +123,8 @@
CL_Quit_f
==================
*/
-void CL_Quit_f (void)
+static void
+CL_Quit_f(void)
{
if (1 /* key_dest != key_console */ /* && cls.state != ca_dedicated */)
{
@@ -139,7 +140,8 @@
CL_Version_f
======================
*/
-void CL_Version_f (void)
+static void
+CL_Version_f(void)
{
Con_Printf ("Version %4.2f\n", VERSION);
Con_Printf ("Exe: 00:00:00 Dec 17 1996\n");
@@ -153,7 +155,8 @@
called by CL_Connect_f and CL_CheckResend
======================
*/
-void CL_SendConnectPacket (void)
+static void
+CL_SendConnectPacket(void)
{
netadr_t adr;
char data[2048];
@@ -195,7 +198,8 @@
=================
*/
-void CL_CheckForResend (void)
+static void
+CL_CheckForResend(void)
{
netadr_t adr;
char data[2048];
@@ -224,7 +228,8 @@
NET_SendPacket (strlen(data), data, &adr);
}
-void CL_BeginServerConnect(void)
+void
+CL_BeginServerConnect(void)
{
connect_time = 0;
CL_CheckForResend();
@@ -236,7 +241,8 @@
================
*/
-void CL_Connect_f (void)
+static void
+CL_Connect_f(void)
{
char *server;
@@ -263,7 +269,8 @@
an unconnected command.
=====================
*/
-void CL_Rcon_f (void)
+static void
+CL_Rcon_f(void)
{
char message[1024];
int i;
@@ -318,7 +325,8 @@
=====================
*/
-void CL_ClearState (void)
+void
+CL_ClearState(void)
{
int i;
@@ -359,7 +367,8 @@
This is also called on Host_Error, so it shouldn't cause any errors
=====================
*/
-void CL_Disconnect (void)
+void
+CL_Disconnect(void)
{
byte final[10];
@@ -398,7 +407,8 @@
}
-void CL_Disconnect_f (void)
+static void
+CL_Disconnect_f(void)
{
CL_Disconnect ();
}
@@ -412,7 +422,8 @@
Dump userdata / masterdata for a user
====================
*/
-void CL_User_f (void)
+static void
+CL_User_f(void)
{
int uid;
int i;
@@ -446,7 +457,8 @@
Dump userids for all current players
====================
*/
-void CL_Users_f (void)
+static void
+CL_Users_f(void)
{
int i;
int c;
@@ -466,7 +478,8 @@
Con_Printf ("%d total users\n", c);
}
-void CL_Color_f (void)
+static void
+CL_Color_f(void)
{
// just for quake compatability...
int top, bottom;
@@ -509,7 +522,8 @@
Sent by server when serverinfo changes
==================
*/
-void CL_FullServerinfo_f (void)
+static void
+CL_FullServerinfo_f(void)
{
char *p;
float v;
@@ -540,7 +554,8 @@
==================
Casey was here :)
*/
-void CL_FullInfo_f (void)
+static void
+CL_FullInfo_f(void)
{
char key[512];
char value[512];
@@ -592,7 +607,8 @@
Allow clients to change userinfo
==================
*/
-void CL_SetInfo_f (void)
+static void
+CL_SetInfo_f(void)
{
if (Cmd_Argc() == 1)
{
@@ -621,7 +637,8 @@
Contents allows \n escape character
====================
*/
-void CL_Packet_f (void)
+static void
+CL_Packet_f(void)
{
char send[2048];
int i, l;
@@ -668,7 +685,8 @@
Called to play the next demo in the demo loop
=====================
*/
-void CL_NextDemo (void)
+void
+CL_NextDemo(void)
{
char str[1024];
@@ -700,7 +718,8 @@
drop to full console
=================
*/
-void CL_Changing_f (void)
+static void
+CL_Changing_f(void)
{
if (cls.download) // don't change when downloading
return;
@@ -719,7 +738,8 @@
The server is changing levels
=================
*/
-void CL_Reconnect_f (void)
+static void
+CL_Reconnect_f(void)
{
if (cls.download) // don't change when downloading
return;
@@ -749,7 +769,8 @@
Responses to broadcasts, etc
=================
*/
-void CL_ConnectionlessPacket (void)
+static void
+CL_ConnectionlessPacket(void)
{
char *s;
int c;
@@ -874,7 +895,8 @@
CL_ReadPackets
=================
*/
-void CL_ReadPackets (void)
+static void
+CL_ReadPackets(void)
{
// while (NET_GetPacket ())
while (CL_GetMessage())
@@ -932,7 +954,8 @@
CL_Download_f
=====================
*/
-void CL_Download_f (void)
+static void
+CL_Download_f(void)
{
char *p, *q;
--- a/qw/client.h
+++ b/qw/client.h
@@ -333,7 +333,6 @@
void CL_EstablishConnection (char *host);
void CL_Disconnect (void);
-void CL_Disconnect_f (void);
void CL_NextDemo (void);
bool CL_DemoBehind(void);
@@ -367,8 +366,6 @@
void CL_UpdateTEnts (void);
void CL_ClearState (void);
-
-void CL_ReadPackets (void);
int CL_ReadFromServer (void);
void CL_WriteToServer (usercmd_t *cmd);
--- a/qw/cmd.c
+++ b/qw/cmd.c
@@ -254,7 +254,8 @@
Cmd_Exec_f
===============
*/
-void Cmd_Exec_f (void)
+static void
+Cmd_Exec_f(void)
{
char *f;
int mark;
@@ -288,7 +289,8 @@
Just prints the rest of the line to the console
===============
*/
-void Cmd_Echo_f (void)
+static void
+Cmd_Echo_f(void)
{
int i;
@@ -305,7 +307,8 @@
===============
*/
-char *CopyString (char *in)
+char *
+CopyString(char *in)
{
char *out;
@@ -314,7 +317,8 @@
return out;
}
-void Cmd_Alias_f (void)
+static void
+Cmd_Alias_f(void)
{
cmdalias_t *a;
char cmd[1024];
@@ -439,7 +443,8 @@
Parses the given string into command line tokens.
============
*/
-void Cmd_TokenizeString (char *text)
+void
+Cmd_TokenizeString(char *text)
{
int i;
--- a/qw/cmd.h
+++ b/qw/cmd.h
@@ -85,3 +85,5 @@
// so when they are typed in at the console, they will need to be forwarded.
void Cmd_StuffCmds_f (void);
+
+char *CopyString(char *);
--- a/qw/console.c
+++ b/qw/console.c
@@ -110,7 +110,8 @@
Con_MessageMode_f
================
*/
-void Con_MessageMode_f (void)
+static void
+Con_MessageMode_f(void)
{
chat_team = false;
key_dest = key_message;
@@ -121,7 +122,8 @@
Con_MessageMode2_f
================
*/
-void Con_MessageMode2_f (void)
+static void
+Con_MessageMode2_f(void)
{
chat_team = true;
key_dest = key_message;
@@ -233,7 +235,8 @@
Con_Linefeed
===============
*/
-void Con_Linefeed (void)
+static void
+Con_Linefeed(void)
{
con->x = 0;
if (con->display == con->current)
@@ -400,7 +403,8 @@
The input line scrolls horizontally if typing goes beyond the right edge
================
*/
-void Con_DrawInput (void)
+static void
+Con_DrawInput(void)
{
int i;
char *text;
--- a/qw/d_sky.c
+++ b/qw/d_sky.c
@@ -9,7 +9,8 @@
D_Sky_uv_To_st
=================
*/
-void D_Sky_uv_To_st (int u, int v, fixed16_t *s, fixed16_t *t)
+static void
+D_Sky_uv_To_st(int u, int v, fixed16_t *s, fixed16_t *t)
{
float wu, wv, temp;
vec3_t end;
--- a/qw/d_surf.c
+++ b/qw/d_surf.c
@@ -31,7 +31,8 @@
return size;
}
-void D_CheckCacheGuard (void)
+static void
+D_CheckCacheGuard(void)
{
byte *s;
int i;
@@ -42,7 +43,8 @@
Sys_Error ("D_CheckCacheGuard: failed");
}
-void D_ClearCacheGuard (void)
+static void
+D_ClearCacheGuard(void)
{
byte *s;
int i;
--- a/qw/draw.c
+++ b/qw/draw.c
@@ -471,7 +471,7 @@
sprintf (ver, "%4.2f", VERSION);
dest = conback->data + 320 + 320*186 - 11 - 8*strlen(ver);
} else {
- sprint(ver, "(9) %4.2f QuakeWorld %4.2f", PLAN9_VERSION, VERSION);
+ sprint(ver, "qk1w %4.2f QuakeWorld %4.2f", PLAN9_VERSION, VERSION);
dest = conback->data + 320 - (strlen(ver)*8 + 11) + 320*186;
}
@@ -507,8 +507,8 @@
R_DrawRect8
==============
*/
-void R_DrawRect8 (vrect_t *prect, int rowbytes, byte *psrc,
- int transparent)
+static void
+R_DrawRect8(vrect_t *prect, int rowbytes, byte *psrc, int transparent)
{
byte t;
int i, j, srcdelta, destdelta;
--- a/qw/keys.c
+++ b/qw/keys.c
@@ -178,7 +178,8 @@
Interactive line editing and console scrollback
====================
*/
-void Key_Console (int key)
+static void
+Key_Console(int key)
{
if (key == K_ENTER)
{ // backslash text are commands, else chat
@@ -297,7 +298,8 @@
char chat_buffer[MAXCMDLINE];
int chat_bufferlen = 0;
-void Key_Message (int key)
+static void
+Key_Message(int key)
{
if (key == K_ENTER)
@@ -355,7 +357,8 @@
the K_* names are matched up.
===================
*/
-int Key_StringToKeynum (char *str)
+static int
+Key_StringToKeynum(char *str)
{
keyname_t *kn;
@@ -436,7 +439,8 @@
Key_Unbind_f
===================
*/
-void Key_Unbind_f (void)
+static void
+Key_Unbind_f(void)
{
int b;
@@ -456,7 +460,8 @@
Key_SetBinding (b, "");
}
-void Key_Unbindall_f (void)
+static void
+Key_Unbindall_f(void)
{
int i;
@@ -471,7 +476,8 @@
Key_Bind_f
===================
*/
-void Key_Bind_f (void)
+static void
+Key_Bind_f(void)
{
int i, c, b;
char cmd[1024];
--- /dev/null
+++ b/qw/mathlib.h
@@ -1,0 +1,63 @@
+// mathlib.h
+
+typedef float vec_t;
+typedef vec_t vec3_t[3];
+typedef vec_t vec5_t[5];
+
+typedef int fixed4_t;
+typedef int fixed8_t;
+typedef int fixed16_t;
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846264338327950288
+#endif
+
+int isnanf(float f);
+
+struct mplane_s;
+
+extern vec3_t vec3_origin;
+
+#define Qrint(f) (int)((f) + ((f) >= 0 ? 0.5 : -0.5))
+
+#define DotProduct_(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
+#define DotProductDouble(x,y) ((double)x[0]*y[0]+(double)x[1]*y[1]+(double)x[2]*y[2])
+#define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
+#define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
+#define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
+
+void VectorMA (vec3_t veca, float scale, vec3_t vecb, vec3_t vecc);
+
+vec_t Length (vec3_t v);
+void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross);
+float VectorNormalize (vec3_t v); // returns vector length
+void VectorInverse (vec3_t v);
+void VectorScale (vec3_t in, vec_t scale, vec3_t out);
+
+void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]);
+void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]);
+
+void FloorDivMod (double numer, double denom, int *quotient, int *rem);
+int GreatestCommonDivisor (int i1, int i2);
+
+void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
+int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct mplane_s *plane);
+float anglemod(float a);
+
+
+
+#define BOX_ON_PLANE_SIDE(emins, emaxs, p) \
+ (((p)->type < 3)? \
+ ( \
+ ((p)->dist <= (emins)[(p)->type])? \
+ 1 \
+ : \
+ ( \
+ ((p)->dist >= (emaxs)[(p)->type])?\
+ 2 \
+ : \
+ 3 \
+ ) \
+ ) \
+ : \
+ BoxOnPlaneSide( (emins), (emaxs), (p)))
--- a/qw/mkfile
+++ b/qw/mkfile
@@ -37,12 +37,14 @@
draw.$O\
in.$O\
keys.$O\
- ../m_dotproduct`{test -f span_$objtype.s && echo -n _$objtype}.$O\
+ ../m_dotproduct`{test -f m_dotproduct_$objtype.s && echo -n _$objtype}.$O\
+ ../m_random.$O\
mathlib.$O\
md4.$O\
menu.$O\
model.$O\
- nanosec.$O\
+ ../mt19937-64.$O\
+ ../nanosec.$O\
net_chan.$O\
net_udp.$O\
nonintel.$O\
@@ -79,10 +81,12 @@
crc.$O\
cvar.$O\
../isnanf.$O\
- ../m_dotproduct`{test -f span_$objtype.s && echo -n _$objtype}.$O\
+ ../m_dotproduct`{test -f m_dotproduct_$objtype.s && echo -n _$objtype}.$O\
+ ../m_random.$O\
mathlib.$O\
md4.$O\
- nanosec.$O\
+ ../mt19937-64.$O\
+ ../nanosec.$O\
net_chan.$O\
net_udp.$O\
pmove.$O\
@@ -121,6 +125,7 @@
draw.h\
input.h\
keys.h\
+ ../m_random.h\
../mathlib.h\
menu.h\
model.h\
--- a/qw/nanosec.c
+++ /dev/null
@@ -1,35 +1,0 @@
-#include "quakedef.h"
-#include <tos.h>
-
-/*
- * nsec() is wallclock and can be adjusted by timesync
- * so need to use cycles() instead, but fall back to
- * nsec() in case we can't
- */
-uvlong
-nanosec(void)
-{
- static uvlong fasthz, xstart;
- uvlong x, div;
-
- if(fasthz == ~0ULL)
- return nsec() - xstart;
-
- if(fasthz == 0){
- if(_tos->cyclefreq){
- fasthz = _tos->cyclefreq;
- cycles(&xstart);
- } else {
- fasthz = ~0ULL;
- xstart = nsec();
- }
- return 0;
- }
- cycles(&x);
- x -= xstart;
-
- /* this is ugly */
- for(div = 1000000000ULL; x < 0x1999999999999999ULL && div > 1 ; div /= 10ULL, x *= 10ULL);
-
- return x / (fasthz / div);
-}
--- a/qw/pr_cmds.c
+++ b/qw/pr_cmds.c
@@ -386,11 +386,7 @@
*/
void PF_random (void)
{
- float num;
-
- num = (rand ()&0x7fff) / ((float)0x7fff);
-
- G_FLOAT(OFS_RETURN) = num;
+ G_FLOAT(OFS_RETURN) = m_random_i0e1();
}
--- a/qw/quakedef.h
+++ b/qw/quakedef.h
@@ -139,6 +139,7 @@
#include "sys.h"
#include "zone.h"
#include "mathlib.h"
+#include "m_random.h"
#include "wad.h"
#include "draw.h"
#include "cvar.h"
--- a/qw/server.h
+++ b/qw/server.h
@@ -399,11 +399,6 @@
void SV_EndRedirect (void);
//
-// sv_ccmds.c
-//
-void SV_Status_f (void);
-
-//
// sv_ents.c
//
void SV_WriteEntitiesToClient (client_t *client, sizebuf_t *msg);
--- a/qw/sv_ccmds.c
+++ b/qw/sv_ccmds.c
@@ -24,7 +24,8 @@
Make a master server current
====================
*/
-void SV_SetMaster_f (void)
+static void
+SV_SetMaster_f(void)
{
char data[2];
int i;
@@ -56,7 +57,8 @@
SV_Quit_f
==================
*/
-void SV_Quit_f (void)
+void
+SV_Quit_f(void)
{
SV_FinalMessage ("server shutdown\n");
Con_Printf ("Shutting down.\n");
@@ -69,7 +71,8 @@
SV_Logfile_f
============
*/
-void SV_Logfile_f (void)
+static void
+SV_Logfile_f(void)
{
char name[MAX_OSPATH];
@@ -94,7 +97,8 @@
SV_Fraglogfile_f
============
*/
-void SV_Fraglogfile_f (void)
+static void
+SV_Fraglogfile_f(void)
{
char name[MAX_OSPATH];
int i;
@@ -139,7 +143,8 @@
Sets host_client and sv_player to the player with idnum Cmd_Argv(1)
==================
*/
-bool SV_SetPlayer (void)
+static bool
+SV_SetPlayer(void)
{
client_t *cl;
int i;
@@ -170,7 +175,8 @@
Sets client to godmode
==================
*/
-void SV_God_f (void)
+static void
+SV_God_f(void)
{
if (!sv_allow_cheats)
{
@@ -189,7 +195,8 @@
}
-void SV_Noclip_f (void)
+static void
+SV_Noclip_f(void)
{
if (!sv_allow_cheats)
{
@@ -218,7 +225,8 @@
SV_Give_f
==================
*/
-void SV_Give_f (void)
+static void
+SV_Give_f(void)
{
char *t;
int v;
@@ -276,7 +284,8 @@
command from the console or progs.
======================
*/
-void SV_Map_f (void)
+static void
+SV_Map_f(void)
{
char level[MAX_QPATH];
char expanded[MAX_QPATH];
@@ -323,7 +332,8 @@
Kick a user off of the server
==================
*/
-void SV_Kick_f (void)
+static void
+SV_Kick_f(void)
{
int i;
client_t *cl;
@@ -355,7 +365,8 @@
SV_Status_f
================
*/
-void SV_Status_f (void)
+static void
+SV_Status_f(void)
{
int i, j, l;
client_t *cl;
@@ -460,7 +471,8 @@
SV_ConSay_f
==================
*/
-void SV_ConSay_f(void)
+static void
+SV_ConSay_f(void)
{
client_t *client;
int j;
@@ -495,7 +507,8 @@
SV_Heartbeat_f
==================
*/
-void SV_Heartbeat_f (void)
+static void
+SV_Heartbeat_f(void)
{
svs.last_heartbeat = -9999;
}
@@ -517,8 +530,8 @@
Examine or change the serverinfo string
===========
*/
-char *CopyString(char *s);
-void SV_Serverinfo_f (void)
+static void
+SV_Serverinfo_f(void)
{
cvar_t *var;
@@ -562,8 +575,8 @@
Examine or change the serverinfo string
===========
*/
-char *CopyString(char *s);
-void SV_Localinfo_f (void)
+static void
+SV_Localinfo_f(void)
{
if (Cmd_Argc() == 1)
{
@@ -594,7 +607,8 @@
Examine a users info strings
===========
*/
-void SV_User_f (void)
+static void
+SV_User_f(void)
{
if (Cmd_Argc() != 2)
{
@@ -615,7 +629,8 @@
Sets the fake *gamedir to a different directory.
================
*/
-void SV_Gamedir (void)
+static void
+SV_Gamedir(void)
{
char *dir;
@@ -651,7 +666,8 @@
================
*/
-void SV_Floodprot_f (void)
+static void
+SV_Floodprot_f(void)
{
int arg1, arg2, arg3;
@@ -711,7 +727,8 @@
================
*/
char gamedirfile[MAX_OSPATH];
-void SV_Gamedir_f (void)
+static void
+SV_Gamedir_f(void)
{
char *dir;
@@ -745,7 +762,8 @@
SV_Snap
================
*/
-void SV_Snap (int uid)
+static void
+SV_Snap(int uid)
{
client_t *cl;
char pcxname[80];
@@ -803,7 +821,8 @@
SV_Snap_f
================
*/
-void SV_Snap_f (void)
+static void
+SV_Snap_f(void)
{
int uid;
@@ -823,7 +842,8 @@
SV_Snap
================
*/
-void SV_SnapAll_f (void)
+static void
+SV_SnapAll_f(void)
{
client_t *cl;
int i;
--- a/qw/sv_main.c
+++ b/qw/sv_main.c
@@ -848,7 +848,8 @@
SV_AddIP_f
=================
*/
-void SV_AddIP_f (void)
+static void
+SV_AddIP_f(void)
{
int i;
@@ -866,7 +867,8 @@
SV_RemoveIP_f
=================
*/
-void SV_RemoveIP_f (void)
+static void
+SV_RemoveIP_f(void)
{
netadr_t a;
int i, j;
@@ -889,7 +891,8 @@
SV_ListIP_f
=================
*/
-void SV_ListIP_f (void)
+static void
+SV_ListIP_f(void)
{
int i;
@@ -903,7 +906,8 @@
SV_WriteIP_f
=================
*/
-void SV_WriteIP_f (void)
+static void
+SV_WriteIP_f(void)
{
FILE *f;
char name[MAX_OSPATH];
--- a/qw/sys.c
+++ b/qw/sys.c
@@ -63,17 +63,17 @@
return 0;
}
-vlong
+s64int
flen(int fd)
{
+ s64int l;
Dir *d;
- vlong sz;
- sz = -1;
- if((d = dirfstat(fd)) != nil)
- sz = d->length;
+ if((d = dirfstat(fd)) == nil) /* file assumed extant and readable */
+ sysfatal("flen: %r");
+ l = d->length;
free(d);
- return sz;
+ return l;
}
double
@@ -120,4 +120,6 @@
void
Sys_Init(void)
{
+ m_random_init(time(nil));
+ srand(time(nil));
}
--- a/qw/vid.c
+++ b/qw/vid.c
@@ -136,14 +136,11 @@
void
VID_Init(uchar *)
{
- int n;
-
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
vid.numpages = 2;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong(*((int *)vid.colormap + 2048));
- srand(getpid());
if(initdraw(nil, nil, "quake") < 0)
sysfatal("initdraw: %r\n");
resetfb();