From edbb5890457a3e51664a81a47c7c15c953675e71 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 8 Feb 2000 05:06:58 +0000 Subject: [PATCH] merge qw_client/cl_main.c and uquake/cl_main.c into common/cl_main.c For the rest, convert all refs to FILE and gzFile to QFile, and similar for file functions (eg fprintf, fgets, fread, etc) --- {qw_client => common}/cl_main.c | 1943 ++++++++++++++++++++----------- common/client.h | 15 +- common/cvar.c | 4 +- common/cvar.h | 3 +- common/keys.c | 4 +- common/keys.h | 3 +- common/pr_edict.c | 22 +- common/progs.h | 4 +- common/quakefs.c | 15 +- common/quakefs.h | 10 +- common/r_efrag.c | 4 - common/r_main.c | 9 +- common/register_check.c | 4 +- qw_client/Makefile.in | 3 +- qw_client/cl_demo.c | 74 +- qw_client/cl_parse.c | 12 +- qw_client/r_part.c | 6 +- qw_server/Makefile.in | 3 +- qw_server/server.h | 8 +- qw_server/sv_ccmds.c | 2 +- uquake/Makefile.in | 3 +- uquake/cl_main.c | 783 ------------- uquake/host.c | 6 +- uquake/host_cmd.c | 24 +- uquake/r_part.c | 6 +- uquake/sw_cl_parse.c | 1 + 26 files changed, 1404 insertions(+), 1567 deletions(-) rename {qw_client => common}/cl_main.c (69%) delete mode 100644 uquake/cl_main.c diff --git a/qw_client/cl_main.c b/common/cl_main.c similarity index 69% rename from qw_client/cl_main.c rename to common/cl_main.c index 4fd21f3..dbcade1 100644 --- a/qw_client/cl_main.c +++ b/common/cl_main.c @@ -36,17 +36,31 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include +#ifdef QUAKEWORLD #include +#endif #include +#include #include #include +#include +#include +#include #include -#include +#include #include #include #include +#include +#include +#include #include #include +#include +#include +#ifdef UQUAKE +#include +#endif #include #include #include @@ -83,10 +97,15 @@ cvar_t rcon_address = {"rcon_address", ""}; cvar_t cl_timeout = {"cl_timeout", "60"}; -cvar_t cl_shownet = {"cl_shownet","0"}; // can be 0, 1, or 2 +// these two are not intended to be set directly +cvar_t cl_name = {"_cl_name", "player", true}; +cvar_t cl_color = {"_cl_color", "0", true}; -cvar_t cl_sbar = {"cl_sbar", "0", true}; -cvar_t cl_hudswap = {"cl_hudswap", "0", true}; +cvar_t cl_shownet = {"cl_shownet","0"}; // can be 0, 1, or 2 +cvar_t cl_nolerp = {"cl_nolerp","0"}; + +cvar_t cl_sbar = {"cl_sbar", "1", true}; +cvar_t cl_hudswap = {"cl_hudswap", "1", true}; cvar_t cl_maxfps = {"cl_maxfps", "0", true}; cvar_t lookspring = {"lookspring","0", true}; @@ -94,9 +113,9 @@ cvar_t lookstrafe = {"lookstrafe","0", true}; cvar_t sensitivity = {"sensitivity","3", true}; cvar_t m_pitch = {"m_pitch","0.022", true}; -cvar_t m_yaw = {"m_yaw","0.022"}; -cvar_t m_forward = {"m_forward","1"}; -cvar_t m_side = {"m_side","0.8"}; +cvar_t m_yaw = {"m_yaw","0.022", true}; +cvar_t m_forward = {"m_forward","1", true}; +cvar_t m_side = {"m_side","0.8", true}; cvar_t entlatency = {"entlatency", "20"}; cvar_t cl_predict_players = {"cl_predict_players", "1"}; @@ -105,7 +124,9 @@ cvar_t cl_solid_players = {"cl_solid_players", "1"}; cvar_t localid = {"localid", ""}; +#ifdef QUAKEWORLD static qboolean allowremotecmd = true; +#endif // // info mirrors @@ -126,8 +147,8 @@ extern cvar_t cl_hightrack; client_static_t cls; client_state_t cl; - entity_state_t cl_baselines[MAX_EDICTS]; +// FIXME: put these on hunk? efrag_t cl_efrags[MAX_EFRAGS]; entity_t cl_static_entities[MAX_STATIC_ENTITIES]; lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES]; @@ -171,101 +192,88 @@ void Master_Connect_f (void); char *server_version = NULL; // version of server we connected to -char emodel_name[] = - { 'e' ^ 0xff, 'm' ^ 0xff, 'o' ^ 0xff, 'd' ^ 0xff, 'e' ^ 0xff, 'l' ^ 0xff, 0 }; -char pmodel_name[] = - { 'p' ^ 0xff, 'm' ^ 0xff, 'o' ^ 0xff, 'd' ^ 0xff, 'e' ^ 0xff, 'l' ^ 0xff, 0 }; -char prespawn_name[] = - { 'p'^0xff, 'r'^0xff, 'e'^0xff, 's'^0xff, 'p'^0xff, 'a'^0xff, 'w'^0xff, 'n'^0xff, - ' '^0xff, '%'^0xff, 'i'^0xff, ' '^0xff, '0'^0xff, ' '^0xff, '%'^0xff, 'i'^0xff, 0 }; -char modellist_name[] = - { 'm'^0xff, 'o'^0xff, 'd'^0xff, 'e'^0xff, 'l'^0xff, 'l'^0xff, 'i'^0xff, 's'^0xff, 't'^0xff, - ' '^0xff, '%'^0xff, 'i'^0xff, ' '^0xff, '%'^0xff, 'i'^0xff, 0 }; -char soundlist_name[] = - { 's'^0xff, 'o'^0xff, 'u'^0xff, 'n'^0xff, 'd'^0xff, 'l'^0xff, 'i'^0xff, 's'^0xff, 't'^0xff, - ' '^0xff, '%'^0xff, 'i'^0xff, ' '^0xff, '%'^0xff, 'i'^0xff, 0 }; +char emodel_name[] = "emodel"; +char pmodel_name[] = "pmodel"; +char prespawn_name[] = "prespawn %i 0 %i"; +char modellist_name[] = "modellist %i %i"; +char soundlist_name[] = "soundlist %i %i"; +void CL_CheckForResend (void); +void CL_SendConnectPacket (void); +void SetPal (int i); +void CL_RelinkEntities (void); + +#ifdef UQUAKE /* -================== -CL_Quit_f -================== +=============== +CL_AllocDlight + +=============== */ -void CL_Quit_f (void) +dlight_t *CL_AllocDlight (int key) { - if (1 /* key_dest != key_console */ /* && cls.state != ca_dedicated */) + int i; + dlight_t *dl; + +// first look for an exact key match + if (key) { - M_Menu_Quit_f (); - return; + dl = cl_dlights; + for (i=0 ; ikey == key) + { + memset (dl, 0, sizeof(*dl)); + dl->key = key; + return dl; + } + } } - CL_Disconnect (); - Sys_Quit (); + +// then look for anything else + dl = cl_dlights; + for (i=0 ; idie < cl.time) + { + memset (dl, 0, sizeof(*dl)); + dl->key = key; + return dl; + } + } + + dl = &cl_dlights[0]; + memset (dl, 0, sizeof(*dl)); + dl->key = key; + return dl; +} +#endif + +void CL_BeginServerConnect(void) +{ + connect_time = 0; + CL_CheckForResend(); } /* -======================= -CL_Version_f -====================== +================= +CL_Changing_f + +Just sent as a hint to the client that they should +drop to full console +================= */ -void CL_Version_f (void) +void CL_Changing_f (void) { - Con_Printf ("Version %s\n", QF_VERSION); - Con_Printf ("Exe: "__TIME__" "__DATE__"\n"); -} - - -/* -======================= -CL_SendConnectPacket - -called by CL_Connect_f and CL_CheckResend -====================== -*/ -void CL_SendConnectPacket (void) -{ - netadr_t adr; - char data[2048]; - double t1, t2; -// JACK: Fixed bug where DNS lookups would cause two connects real fast -// Now, adds lookup time to the connect time. -// Should I add it to realtime instead?!?! - - if (cls.state != ca_disconnected) +#ifdef QUAKEWORLD + if (cls.download) // don't change when downloading return; +#endif - t1 = Sys_DoubleTime (); - - if (!NET_StringToAdr (cls.servername, &adr)) - { - Con_Printf ("Bad server address\n"); - connect_time = -1; - return; - } - - if (!NET_IsClientLegal(&adr)) - { - Con_Printf ("Illegal server address\n"); - connect_time = -1; - return; - } - - if (adr.port == 0) - adr.port = BigShort (27500); - t2 = Sys_DoubleTime (); - - connect_time = realtime+t2-t1; // for retransmit requests - - cls.qport = Cvar_VariableValue("qport"); - - // Arrgh, this was not in the old binary only release, and eats up - // far too much of the 196 chars in the userinfo space, leaving nothing - // for player use, thus, its commented out for the moment.. - // - //Info_SetValueForStarKey (cls.userinfo, "*ip", NET_AdrToString(adr), MAX_INFO_STRING); - -// Con_Printf ("Connecting to %s...\n", cls.servername); - snprintf(data, sizeof(data), "%c%c%c%cconnect %i %i %i \"%s\"\n", - 255, 255, 255, 255, PROTOCOL_VERSION, cls.qport, cls.challenge, cls.userinfo); - NET_SendPacket (strlen(data), data, adr); + S_StopAllSounds (true); + cl.intermission = 0; + cls.state = ca_connected; // not active anymore, but not disconnected + Con_Printf ("\nChanging map...\n"); } /* @@ -290,12 +298,14 @@ void CL_CheckForResend (void) return; t1 = Sys_DoubleTime (); +#ifdef QUAKEWORLD if (!NET_StringToAdr (cls.servername, &adr)) { Con_Printf ("Bad server address\n"); connect_time = -1; return; } +#endif if (!NET_IsClientLegal(&adr)) { Con_Printf ("Illegal server address\n"); @@ -309,100 +319,13 @@ void CL_CheckForResend (void) connect_time = realtime+t2-t1; // for retransmit requests +#ifdef QUAKEWORLD Con_Printf ("Connecting to %s...\n", cls.servername); +#endif snprintf(data, sizeof(data), "%c%c%c%cgetchallenge\n", 255, 255, 255, 255); NET_SendPacket (strlen(data), data, adr); } -void CL_BeginServerConnect(void) -{ - connect_time = 0; - CL_CheckForResend(); -} - -/* -================ -CL_Connect_f - -================ -*/ -void CL_Connect_f (void) -{ - char *server; - - if (Cmd_Argc() != 2) - { - Con_Printf ("usage: connect \n"); - return; - } - - server = Cmd_Argv (1); - - CL_Disconnect (); - - strncpy (cls.servername, server, sizeof(cls.servername)-1); - CL_BeginServerConnect(); -} - - -/* -===================== -CL_Rcon_f - - Send the rest of the command line over as - an unconnected command. -===================== -*/ -void CL_Rcon_f (void) -{ - char message[1024]; - int i; - netadr_t to; - - if (!rcon_password.string) - { - Con_Printf ("You must set 'rcon_password' before\n" - "issuing an rcon command.\n"); - return; - } - - message[0] = 255; - message[1] = 255; - message[2] = 255; - message[3] = 255; - message[4] = 0; - - strcat (message, "rcon "); - - strcat (message, rcon_password.string); - strcat (message, " "); - - for (i=1 ; i= ca_connected) - to = cls.netchan.remote_address; - else - { - if (!strlen(rcon_address.string)) - { - Con_Printf ("You must either be connected,\n" - "or set the 'rcon_address' cvar\n" - "to issue rcon commands\n"); - - return; - } - NET_StringToAdr (rcon_address.string, &to); - } - - NET_SendPacket (strlen(message)+1, message - , to); -} - - /* ===================== CL_ClearState @@ -423,6 +346,11 @@ void CL_ClearState (void) CL_ClearTEnts (); +#ifdef UQUAKE + if (!sv.active) + Host_ClearMemory (); +#endif + // wipe the entire cl structure memset (&cl, 0, sizeof(cl)); @@ -430,8 +358,13 @@ void CL_ClearState (void) // clear other arrays memset (cl_efrags, 0, sizeof(cl_efrags)); +#ifdef UQUAKE + memset (cl_entities, 0, sizeof(cl_entities)); + memset (cl_temp_entities, 0, sizeof(cl_temp_entities)); +#endif memset (cl_dlights, 0, sizeof(cl_dlights)); memset (cl_lightstyle, 0, sizeof(cl_lightstyle)); + CL_ClearTEnts (); // // allocate the efrags and chain together into a free list @@ -442,124 +375,7 @@ void CL_ClearState (void) cl.free_efrags[i].entnext = NULL; } -/* -===================== -CL_Disconnect - -Sends a disconnect message to the server -This is also called on Host_Error, so it shouldn't cause any errors -===================== -*/ -void CL_Disconnect (void) -{ - byte final[10]; - - connect_time = -1; - -#ifdef _WIN32 - SetWindowText (mainwindow, "QuakeWorld: disconnected"); -#endif - -// stop sounds (especially looping!) - S_StopAllSounds (true); - -// if running a local server, shut it down - if (cls.demoplayback) - CL_StopPlayback (); - else if (cls.state != ca_disconnected) - { - if (cls.demorecording) - CL_Stop_f (); - - final[0] = clc_stringcmd; - strcpy (final+1, "drop"); - Netchan_Transmit (&cls.netchan, 6, final); - Netchan_Transmit (&cls.netchan, 6, final); - Netchan_Transmit (&cls.netchan, 6, final); - - cls.state = ca_disconnected; - - cls.demoplayback = cls.demorecording = cls.timedemo = false; - } - Cam_Reset(); - - if (cls.download) { - fclose(cls.download); - cls.download = NULL; - } - - CL_StopUpload(); - -} - -void CL_Disconnect_f (void) -{ - CL_Disconnect (); -} - -/* -==================== -CL_User_f - -user - -Dump userdata / masterdata for a user -==================== -*/ -void CL_User_f (void) -{ - int uid; - int i; - - if (Cmd_Argc() != 2) - { - Con_Printf ("Usage: user \n"); - return; - } - - uid = atoi(Cmd_Argv(1)); - - for (i=0 ; i\n"); - return; + Con_Printf ("usage: connect \n"); + return; } + + server = Cmd_Argv (1); - strcpy (cl.serverinfo, Cmd_Argv(1)); + CL_Disconnect (); - if ((p = Info_ValueForKey(cl.serverinfo, "*qf_version")) && *p) { - if (!server_version) - Con_Printf("QuakeForge Version %s Server\n", p); - server_version = strdup(p); - } else if ((p = Info_ValueForKey(cl.serverinfo, "*version")) && *p) { - if (!server_version) - Con_Printf("Version %s Server\n", p); - server_version = strdup(p); - } -} - -/* -================== -CL_FullInfo_f - -Allow clients to change userinfo -================== -Casey was here :) -*/ -void CL_FullInfo_f (void) -{ - char key[512]; - char value[512]; - char *o; - char *s; - - if (Cmd_Argc() != 2) - { - Con_Printf ("fullinfo \n"); - return; - } - - s = Cmd_Argv(1); - if (*s == '\\') - s++; - while (*s) - { - o = key; - while (*s && *s != '\\') - *o++ = *s++; - *o = 0; - - if (!*s) - { - Con_Printf ("MISSING VALUE\n"); - return; - } - - o = value; - s++; - while (*s && *s != '\\') - *o++ = *s++; - *o = 0; - - if (*s) - s++; - - if (!stricmp(key, pmodel_name) || !stricmp(key, emodel_name)) - continue; - - Info_SetValueForKey (cls.userinfo, key, value, MAX_INFO_STRING); - } -} - -/* -================== -CL_SetInfo_f - -Allow clients to change userinfo -================== -*/ -void CL_SetInfo_f (void) -{ - if (Cmd_Argc() == 1) - { - Info_Print (cls.userinfo); - return; - } - if (Cmd_Argc() != 3) - { - Con_Printf ("usage: setinfo [ ]\n"); - return; - } - if (!stricmp(Cmd_Argv(1), pmodel_name) || !strcmp(Cmd_Argv(1), emodel_name)) - return; - - Info_SetValueForKey (cls.userinfo, Cmd_Argv(1), Cmd_Argv(2), MAX_INFO_STRING); - if (cls.state >= ca_connected) - Cmd_ForwardToServer (); -} - -/* -==================== -CL_Packet_f - -packet - -Contents allows \n escape character -==================== -*/ -void CL_Packet_f (void) -{ - char send[2048]; - int i, l; - char *in, *out; - netadr_t adr; - - if (Cmd_Argc() != 3) - { - Con_Printf ("packet \n"); - return; - } - - if (!NET_StringToAdr (Cmd_Argv(1), &adr)) - { - Con_Printf ("Bad address\n"); - return; - } - - in = Cmd_Argv(2); - out = send+4; - send[0] = send[1] = send[2] = send[3] = 0xff; - - l = strlen (in); - for (i=0 ; idie < cl.time || !dl->radius) + continue; + + dl->radius -= time*dl->decay; + if (dl->radius < 0) + dl->radius = 0; + } +} +#endif + +/* +===================== +CL_Disconnect + +Sends a disconnect message to the server +This is also called on Host_Error, so it shouldn't cause any errors +===================== +*/ +void CL_Disconnect (void) +{ +#ifdef QUAKEWORLD + byte final[10]; +#endif + + connect_time = -1; + +#ifdef _WIN32 + SetWindowText (mainwindow, "QuakeWorld: disconnected"); +#endif + +// stop sounds (especially looping!) + S_StopAllSounds (true); + +// bring the console down and fade the colors back to normal +// SCR_BringDownConsole (); + +// if running a local server, shut it down + if (cls.demoplayback) + CL_StopPlayback (); + else if (cls.state != ca_disconnected) +// else if (cls.state >= ca_connected) + { + if (cls.demorecording) + CL_Stop_f (); + +#ifdef QUAKEWORLD + final[0] = clc_stringcmd; + strcpy (final+1, "drop"); + Netchan_Transmit (&cls.netchan, 6, final); + Netchan_Transmit (&cls.netchan, 6, final); + Netchan_Transmit (&cls.netchan, 6, final); +#else + Con_DPrintf ("Sending clc_disconnect\n"); + SZ_Clear (&cls.netchan.message); + MSG_WriteByte (&cls.netchan.message, clc_disconnect); + NET_SendUnreliableMessage (cls.netcon, &cls.netchan.message); + SZ_Clear (&cls.netchan.message); + NET_Close (cls.netcon); +#endif + + cls.state = ca_disconnected; + + cls.demoplayback = cls.demorecording = cls.timedemo = false; +#ifdef UQUQKE + if (sv.active) + Host_ShutdownServer(false); +#endif + } +#ifdef QUAKEWORLD + Cam_Reset(); + + if (cls.download) { + Qclose(cls.download); + cls.download = NULL; + } + + CL_StopUpload(); +#endif +#ifdef UQUQKE + cls.demoplayback = cls.timedemo = false; + cls.signon = 0; +#endif +} + +void CL_Disconnect_f (void) +{ + CL_Disconnect (); +#ifdef UQUQKE + if (sv.active) + Host_ShutdownServer (false); +#endif +} + +#ifdef QUAKEWORLD +/* +===================== +CL_Download_f +===================== +*/ +void CL_Download_f (void) +{ + char *p, *q; + + if (cls.state == ca_disconnected) + { + Con_Printf ("Must be connected.\n"); + return; + } + + if (Cmd_Argc() != 2) + { + Con_Printf ("Usage: download \n"); + return; + } + + snprintf(cls.downloadname, sizeof(cls.downloadname), "%s/%s", com_gamedir, Cmd_Argv(1)); + + p = cls.downloadname; + for (;;) { + if ((q = strchr(p, '/')) != NULL) { + *q = 0; + Sys_mkdir(cls.downloadname); + *q = '/'; + p = q + 1; + } else + break; + } + + strcpy(cls.downloadtempname, cls.downloadname); + cls.download = Qopen (cls.downloadname, "wb"); + cls.downloadtype = dl_single; + + MSG_WriteByte (&cls.netchan.message, clc_stringcmd); + SZ_Print (&cls.netchan.message, va("download %s\n",Cmd_Argv(1))); +} +#endif + +/* +===================== +CL_EstablishConnection + +Host should be either "local" or a net address to be passed on +===================== +*/ +void CL_EstablishConnection (char *host) +{ + if (cls.state == ca_dedicated) + return; + + if (cls.demoplayback) + return; + + CL_Disconnect (); + +#ifdef UQUAKE + cls.netcon = NET_Connect (host); + if (!cls.netcon) + Host_Error ("CL_Connect: connect failed\n"); +#endif + Con_DPrintf ("CL_EstablishConnection: connected to %s\n", host); + + cls.demonum = -1; // not in the demo loop now + cls.state = ca_connected; +#ifdef UQUAKE + cls.signon = 0; // need all the signon messages before playing +#endif +} + +/* +================== +CL_FullInfo_f + +Allow clients to change userinfo +================== +Casey was here :) +*/ +void CL_FullInfo_f (void) +{ + char key[512]; + char value[512]; + char *o; + char *s; + + if (Cmd_Argc() != 2) + { + Con_Printf ("fullinfo \n"); + return; + } + + s = Cmd_Argv(1); + if (*s == '\\') + s++; + while (*s) + { + o = key; + while (*s && *s != '\\') + *o++ = *s++; + *o = 0; + + if (!*s) + { + Con_Printf ("MISSING VALUE\n"); + return; + } + + o = value; + s++; + while (*s && *s != '\\') + *o++ = *s++; + *o = 0; + + if (*s) + s++; + + if (!stricmp(key, pmodel_name) || !stricmp(key, emodel_name)) + continue; + +#ifdef QUAKEWORLD + Info_SetValueForKey (cls.userinfo, key, value, MAX_INFO_STRING); +#endif + } +} + +#ifdef QUAKEWORLD +/* +================== +CL_FullServerinfo_f + +Sent by server when serverinfo changes +================== +*/ +void CL_FullServerinfo_f (void) +{ + char *p; + + if (Cmd_Argc() != 2) + { + Con_Printf ("usage: fullserverinfo \n"); + return; + } + + strcpy (cl.serverinfo, Cmd_Argv(1)); + + if ((p = Info_ValueForKey(cl.serverinfo, "*qf_version")) && *p) { + if (!server_version) + Con_Printf("QuakeForge Version %s Server\n", p); + server_version = strdup(p); + } else if ((p = Info_ValueForKey(cl.serverinfo, "*version")) && *p) { + if (!server_version) + Con_Printf("Version %s Server\n", p); + server_version = strdup(p); + } +} +#endif + +#ifdef UQUAKE +/* +=============== +CL_LerpPoint + +Determines the fraction between the last two messages that the objects +should be put at. +=============== +*/ +float CL_LerpPoint (void) +{ + float f, frac; + + f = cl.mtime[0] - cl.mtime[1]; + + if (!f || cl_nolerp.value || cls.timedemo || sv.active) + { + cl.time = cl.mtime[0]; + return 1; + } + if (f > 0.1) + { // dropped packet, or start of demo + cl.mtime[1] = cl.mtime[0] - 0.1; + f = 0.1; + } + frac = (cl.time - cl.mtime[1]) / f; +//Con_Printf ("frac: %f\n",frac); + if (frac < 0) + { + if (frac < -0.01) + { +SetPal(1); + cl.time = cl.mtime[1]; +// Con_Printf ("low frac\n"); + } + frac = 0; + } + else if (frac > 1) + { + if (frac > 1.01) + { +SetPal(2); + cl.time = cl.mtime[0]; +// Con_Printf ("high frac\n"); + } + frac = 1; + } + else + SetPal(0); + + return frac; +} +#endif + +/* +===================== +CL_NextDemo + +Called to play the next demo in the demo loop +===================== +*/ +void CL_NextDemo (void) +{ + char str[1024]; + + if (cls.demonum == -1) + return; // don't play demos + +#ifdef UQUAKE + SCR_BeginLoadingPlaque (); +#endif + + if (!cls.demos[cls.demonum][0] || cls.demonum == MAX_DEMOS) + { + cls.demonum = 0; + if (!cls.demos[cls.demonum][0]) + { + Con_Printf ("No demos listed with startdemos\n"); + cls.demonum = -1; + return; + } + } + + snprintf(str, sizeof(str),"playdemo %s\n", cls.demos[cls.demonum]); + Cbuf_InsertText (str); + cls.demonum++; +} + +/* +==================== +CL_Packet_f + +packet + +Contents allows \n escape character +==================== +*/ +void CL_Packet_f (void) +{ + char send[2048]; + int i, l; + char *in, *out; + netadr_t adr; + + if (Cmd_Argc() != 3) + { + Con_Printf ("packet \n"); + return; + } + + if (!NET_StringToAdr (Cmd_Argv(1), &adr)) + { + Con_Printf ("Bad address\n"); + return; + } + + in = Cmd_Argv(2); + out = send+4; + send[0] = send[1] = send[2] = send[3] = 0xff; + + l = strlen (in); + for (i=0 ; imodel) + { + Con_Printf ("EMPTY\n"); + continue; + } + Con_Printf ("%s:%2i (%5.1f,%5.1f,%5.1f) [%5.1f %5.1f %5.1f]\n" + ,ent->model->name,ent->frame, ent->origin[0], ent->origin[1], ent->origin[2], ent->angles[0], ent->angles[1], ent->angles[2]); + } +} +#endif + +/* +================== +CL_Quit_f +================== +*/ +void CL_Quit_f (void) +{ +#ifdef QUAKEWORLD + if (1 /* key_dest != key_console */ /* && cls.state != ca_dedicated */) + { + M_Menu_Quit_f (); + return; + } +#endif + CL_Disconnect (); + Sys_Quit (); +} + +/* +===================== +CL_Rcon_f + + Send the rest of the command line over as + an unconnected command. +===================== +*/ +void CL_Rcon_f (void) +{ + char message[1024]; + int i; + netadr_t to; + + if (!rcon_password.string) + { + Con_Printf ("You must set 'rcon_password' before\n" + "issuing an rcon command.\n"); + return; + } + + message[0] = 255; + message[1] = 255; + message[2] = 255; + message[3] = 255; + message[4] = 0; + + strcat (message, "rcon "); + + strcat (message, rcon_password.string); + strcat (message, " "); + + for (i=1 ; i= ca_connected) + to = cls.netchan.remote_address; + else + { + if (!strlen(rcon_address.string)) + { + Con_Printf ("You must either be connected,\n" + "or set the 'rcon_address' cvar\n" + "to issue rcon commands\n"); + + return; + } + NET_StringToAdr (rcon_address.string, &to); + } + + NET_SendPacket (strlen(message)+1, message + , to); +} + +#ifdef UQUAKE +/* +=============== +CL_ReadFromServer + +Read all incoming data from the server +=============== +*/ +int CL_ReadFromServer (void) +{ + int ret; + + cl.oldtime = cl.time; + cl.time += host_frametime; + + do + { + ret = CL_GetMessage (); + if (ret == -1) + Host_Error ("CL_ReadFromServer: lost server connection"); + if (!ret) + break; + + cl.last_received_message = realtime; + CL_ParseServerMessage (); + } while (ret && cls.state >= ca_connected); + + if (cl_shownet.value) + Con_Printf ("\n"); + + CL_RelinkEntities (); + CL_UpdateTEnts (); + +// +// bring the links up to date +// + return 0; +} +#endif + +#ifdef QUAKEWORLD /* ================= CL_ReadPackets @@ -1029,49 +1179,489 @@ void CL_ReadPackets (void) } } - -//============================================================================= +#endif /* -===================== -CL_Download_f -===================== -*/ -void CL_Download_f (void) -{ - char *p, *q; +================= +CL_Reconnect_f - if (cls.state == ca_disconnected) - { - Con_Printf ("Must be connected.\n"); +The server is changing levels +================= +*/ +void CL_Reconnect_f (void) +{ +#ifdef QUAKEWORLD + if (cls.download) // don't change when downloading + return; +#endif + + S_StopAllSounds (true); + + if (cls.state == ca_connected) { + Con_Printf ("reconnecting...\n"); + MSG_WriteChar (&cls.netchan.message, clc_stringcmd); + MSG_WriteString (&cls.netchan.message, "new"); return; } +#ifdef QUAKEWORLD + if (!*cls.servername) { + Con_Printf("No server to reconnect to...\n"); + return; + } +#endif + + CL_Disconnect(); + CL_BeginServerConnect(); +} + +#ifdef UQUAKE +/* +=============== +CL_RelinkEntities +=============== +*/ +void CL_RelinkEntities (void) +{ + entity_t *ent; + int i, j; + float frac, f, d; + vec3_t delta; + float bobjrotate; + vec3_t oldorg; + dlight_t *dl; + +// determine partial update time + frac = CL_LerpPoint (); + + cl_numvisedicts = 0; + +// +// interpolate player info +// + for (i=0 ; i<3 ; i++) + cl.velocity[i] = cl.mvelocity[1][i] + + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]); + + if (cls.demoplayback) + { + // interpolate the angles + for (j=0 ; j<3 ; j++) + { + d = cl.mviewangles[0][j] - cl.mviewangles[1][j]; + if (d > 180) + d -= 360; + else if (d < -180) + d += 360; + cl.viewangles[j] = cl.mviewangles[1][j] + frac*d; + } + } + + bobjrotate = anglemod(100*cl.time); + +// start on the entity after the world + for (i=1,ent=cl_entities+1 ; imodel) + { // empty slot + if (ent->forcelink) + R_RemoveEfrags (ent); // just became empty + continue; + } + +// if the object wasn't included in the last packet, remove it + if (ent->msgtime != cl.mtime[0]) + { + ent->model = NULL; + continue; + } + + VectorCopy (ent->origin, oldorg); + + if (ent->forcelink) + { // the entity was not updated in the last message + // so move to the final spot + VectorCopy (ent->msg_origins[0], ent->origin); + VectorCopy (ent->msg_angles[0], ent->angles); + } + else + { // if the delta is large, assume a teleport and don't lerp + f = frac; + for (j=0 ; j<3 ; j++) + { + delta[j] = ent->msg_origins[0][j] - ent->msg_origins[1][j]; + if (delta[j] > 100 || delta[j] < -100) + f = 1; // assume a teleportation, not a motion + } + + // interpolate the origin and angles + for (j=0 ; j<3 ; j++) + { + ent->origin[j] = ent->msg_origins[1][j] + f*delta[j]; + + d = ent->msg_angles[0][j] - ent->msg_angles[1][j]; + if (d > 180) + d -= 360; + else if (d < -180) + d += 360; + ent->angles[j] = ent->msg_angles[1][j] + f*d; + } + + } + +// rotate binary objects locally + if (ent->model->flags & EF_ROTATE) + ent->angles[1] = bobjrotate; + + if (ent->effects & EF_BRIGHTFIELD) + R_EntityParticles (ent); +#ifdef QUAKE2 + if (ent->effects & EF_DARKFIELD) + R_DarkFieldParticles (ent); +#endif + if (ent->effects & EF_MUZZLEFLASH) + { + vec3_t fv, rv, uv; + + dl = CL_AllocDlight (i); + VectorCopy (ent->origin, dl->origin); + dl->origin[2] += 16; + AngleVectors (ent->angles, fv, rv, uv); + + VectorMA (dl->origin, 18, fv, dl->origin); + dl->radius = 200 + (rand()&31); + dl->minlight = 32; + dl->die = cl.time + 0.1; + } + if (ent->effects & EF_BRIGHTLIGHT) + { + dl = CL_AllocDlight (i); + VectorCopy (ent->origin, dl->origin); + dl->origin[2] += 16; + dl->radius = 400 + (rand()&31); + dl->die = cl.time + 0.001; + } + if (ent->effects & EF_DIMLIGHT) + { + dl = CL_AllocDlight (i); + VectorCopy (ent->origin, dl->origin); + dl->radius = 200 + (rand()&31); + dl->die = cl.time + 0.001; + } +#ifdef QUAKE2 + if (ent->effects & EF_DARKLIGHT) + { + dl = CL_AllocDlight (i); + VectorCopy (ent->origin, dl->origin); + dl->radius = 200.0 + (rand()&31); + dl->die = cl.time + 0.001; + dl->dark = true; + } + if (ent->effects & EF_LIGHT) + { + dl = CL_AllocDlight (i); + VectorCopy (ent->origin, dl->origin); + dl->radius = 200; + dl->die = cl.time + 0.001; + } +#endif + + if (ent->model->flags & EF_GIB) + R_RocketTrail (oldorg, ent->origin, 2); + else if (ent->model->flags & EF_ZOMGIB) + R_RocketTrail (oldorg, ent->origin, 4); + else if (ent->model->flags & EF_TRACER) + R_RocketTrail (oldorg, ent->origin, 3); + else if (ent->model->flags & EF_TRACER2) + R_RocketTrail (oldorg, ent->origin, 5); + else if (ent->model->flags & EF_ROCKET) + { + R_RocketTrail (oldorg, ent->origin, 0); + dl = CL_AllocDlight (i); + VectorCopy (ent->origin, dl->origin); + dl->radius = 200; + dl->die = cl.time + 0.01; + } + else if (ent->model->flags & EF_GRENADE) + R_RocketTrail (oldorg, ent->origin, 1); + else if (ent->model->flags & EF_TRACER3) + R_RocketTrail (oldorg, ent->origin, 6); + + ent->forcelink = false; + + if (i == cl.playernum + 1 && !cl_chasecam.value) + continue; + +#ifdef QUAKE2 + if ( ent->effects & EF_NODRAW ) + continue; +#endif + if (cl_numvisedicts < MAX_VISEDICTS) + { + cl_visedicts[cl_numvisedicts] = *ent; + cl_numvisedicts++; + } + } + +} +#endif + +/* +======================= +CL_SendConnectPacket + +called by CL_Connect_f and CL_CheckResend +====================== +*/ +void CL_SendConnectPacket (void) +{ + netadr_t adr; + char data[2048]; + double t1, t2; +// JACK: Fixed bug where DNS lookups would cause two connects real fast +// Now, adds lookup time to the connect time. +// Should I add it to realtime instead?!?! + + if (cls.state != ca_disconnected) + return; + + t1 = Sys_DoubleTime (); +#ifdef QUAKEWORLD + if (!NET_StringToAdr (cls.servername, &adr)) + { + Con_Printf ("Bad server address\n"); + connect_time = -1; + return; + } +#endif + if (!NET_IsClientLegal(&adr)) + { + Con_Printf ("Illegal server address\n"); + connect_time = -1; + return; + } + + if (adr.port == 0) + adr.port = BigShort (27500); + t2 = Sys_DoubleTime (); + + connect_time = realtime+t2-t1; // for retransmit requests +#ifdef QUAKEWORLD + cls.qport = Cvar_VariableValue("qport"); + + // Arrgh, this was not in the old binary only release, and eats up + // far too much of the 196 chars in the userinfo space, leaving nothing + // for player use, thus, its commented out for the moment.. + // + //Info_SetValueForStarKey (cls.userinfo, "*ip", NET_AdrToString(adr), MAX_INFO_STRING); + +// Con_Printf ("Connecting to %s...\n", cls.servername); + snprintf(data, sizeof(data), "%c%c%c%cconnect %i %i %i \"%s\"\n", + 255, 255, 255, 255, PROTOCOL_VERSION, cls.qport, cls.challenge, cls.userinfo); +#endif + NET_SendPacket (strlen(data), data, adr); +} + +#ifdef UQUAKE +/* +================= +CL_SendCmd +================= +*/ +void CL_SendCmd (void) +{ + usercmd_t cmd; + + if (cls.state < ca_connected) + return; + + if (cls.signon == SIGNONS) + { + // get basic movement from keyboard + CL_BaseMove (&cmd); + + // allow mice or other external controllers to add to the move + IN_Move (&cmd); + + // send the unreliable message + CL_SendMove (&cmd); + + } + + if (cls.demoplayback) + { + SZ_Clear (&cls.netchan.message); + return; + } + +// send the reliable message + if (!cls.netchan.message.cursize) + return; // no message at all + + if (!NET_CanSendMessage (cls.netcon)) + { + Con_DPrintf ("CL_WriteToServer: can't send\n"); + return; + } + + if (NET_SendMessage (cls.netcon, &cls.netchan.message) == -1) + Host_Error ("CL_WriteToServer: lost server connection"); + + SZ_Clear (&cls.netchan.message); +} +#endif + +#ifdef QUAKEWORLD +/* +================== +CL_SetInfo_f + +Allow clients to change userinfo +================== +*/ +void CL_SetInfo_f (void) +{ + if (Cmd_Argc() == 1) + { + Info_Print (cls.userinfo); + return; + } + if (Cmd_Argc() != 3) + { + Con_Printf ("usage: setinfo [ ]\n"); + return; + } + if (!stricmp(Cmd_Argv(1), pmodel_name) || !strcmp(Cmd_Argv(1), emodel_name)) + return; + + Info_SetValueForKey (cls.userinfo, Cmd_Argv(1), Cmd_Argv(2), MAX_INFO_STRING); + if (cls.state >= ca_connected) + Cmd_ForwardToServer (); +} +#endif + +#ifdef UQUAKE +/* +===================== +CL_SignonReply + +An svc_signonnum has been received, perform a client side setup +===================== +*/ +void CL_SignonReply (void) +{ + char str[8192]; + +Con_DPrintf ("CL_SignonReply: %i\n", cls.signon); + + switch (cls.signon) + { + case 1: + MSG_WriteByte (&cls.netchan.message, clc_stringcmd); + MSG_WriteString (&cls.netchan.message, "prespawn"); + cls.state = ca_onserver; + break; + + case 2: + MSG_WriteByte (&cls.netchan.message, clc_stringcmd); + MSG_WriteString (&cls.netchan.message, va("name \"%s\"\n", cl_name.string)); + + MSG_WriteByte (&cls.netchan.message, clc_stringcmd); + MSG_WriteString (&cls.netchan.message, va("color %i %i\n", ((int)cl_color.value)>>4, ((int)cl_color.value)&15)); + + MSG_WriteByte (&cls.netchan.message, clc_stringcmd); + snprintf(str, sizeof(str), "spawn %s", cls.spawnparms); + MSG_WriteString (&cls.netchan.message, str); + break; + + case 3: + MSG_WriteByte (&cls.netchan.message, clc_stringcmd); + MSG_WriteString (&cls.netchan.message, "begin"); + Cache_Report (); // print remaining memory + break; + + case 4: + SCR_EndLoadingPlaque (); // allow normal screen updates + cls.state = ca_active; + break; + } +} +#endif + +#ifdef QUAKEWORLD +/* +==================== +CL_User_f + +user + +Dump userdata / masterdata for a user +==================== +*/ +void CL_User_f (void) +{ + int uid; + int i; + if (Cmd_Argc() != 2) { - Con_Printf ("Usage: download \n"); + Con_Printf ("Usage: user \n"); return; } - snprintf(cls.downloadname, sizeof(cls.downloadname), "%s/%s", com_gamedir, Cmd_Argv(1)); + uid = atoi(Cmd_Argv(1)); - p = cls.downloadname; - for (;;) { - if ((q = strchr(p, '/')) != NULL) { - *q = 0; - Sys_mkdir(cls.downloadname); - *q = '/'; - p = q + 1; - } else - break; + for (i=0 ; i realtime) - oldrealtime = 0; - - if (cl_maxfps.value) - fps = max(30.0, min(cl_maxfps.value, 72.0)); - else - fps = max(30.0, min(rate.value/80.0, 72.0)); - - if (!cls.timedemo && (realtime + time) - oldrealtime < 1.0/fps) - return false; // framerate is too high - return true; -} -#endif - - /* ================== Host_Frame @@ -1438,22 +2037,88 @@ void Host_Frame (float time) fps_count++; } -static void simple_crypt(char *buf, int len) +/* +=============== +Host_Shutdown + +FIXME: this is a callback from Sys_Quit and Sys_Error. It would be better +to run quit through here before the final handoff to the sys code. +=============== +*/ +void Host_Shutdown(void) { - while (len--) - *buf++ ^= 0xff; + static qboolean isdown = false; + + if (isdown) + { + printf ("recursive shutdown\n"); + return; + } + isdown = true; + + Host_WriteConfiguration (); + + CDAudio_Shutdown (); + NET_Shutdown (); + S_Shutdown(); + IN_Shutdown (); + if (host_basepal) + VID_Shutdown(); } -void Host_FixupModelNames(void) +#if 0 +/* +================== +Host_SimulationTime + +This determines if enough time has passed to run a simulation frame +================== +*/ +qboolean Host_SimulationTime(float time) { - simple_crypt(emodel_name, sizeof(emodel_name) - 1); - simple_crypt(pmodel_name, sizeof(pmodel_name) - 1); - simple_crypt(prespawn_name, sizeof(prespawn_name) - 1); - simple_crypt(modellist_name, sizeof(modellist_name) - 1); - simple_crypt(soundlist_name, sizeof(soundlist_name) - 1); + float fps; + + if (oldrealtime > realtime) + oldrealtime = 0; + + if (cl_maxfps.value) + fps = max(30.0, min(cl_maxfps.value, 72.0)); + else + fps = max(30.0, min(rate.value/80.0, 72.0)); + + if (!cls.timedemo && (realtime + time) - oldrealtime < 1.0/fps) + return false; // framerate is too high + return true; +} +#endif + +/* +=============== +Host_WriteConfiguration + +Writes key bindings and archived cvars to config.cfg +=============== +*/ +void Host_WriteConfiguration (void) +{ + QFile *f; + + if (host_initialized) + { + f = Qopen (va("%s/config.cfg",com_gamedir), "w"); + if (!f) + { + Con_Printf ("Couldn't write config.cfg.\n"); + return; + } + + Key_WriteBindings (f); + Cvar_WriteVariables (f); + + Qclose (f); + } } -//============================================================================ /* ==================== @@ -1483,8 +2148,6 @@ void Host_Init (quakeparms_t *parms) COM_Init (); - Host_FixupModelNames(); - NET_Init (PORT_CLIENT); Netchan_Init (); @@ -1532,34 +2195,4 @@ void Host_Init (quakeparms_t *parms) Con_Printf ("€ QuakeWorld Initialized ‚\n"); } - - -/* -=============== -Host_Shutdown - -FIXME: this is a callback from Sys_Quit and Sys_Error. It would be better -to run quit through here before the final handoff to the sys code. -=============== -*/ -void Host_Shutdown(void) -{ - static qboolean isdown = false; - - if (isdown) - { - printf ("recursive shutdown\n"); - return; - } - isdown = true; - - Host_WriteConfiguration (); - - CDAudio_Shutdown (); - NET_Shutdown (); - S_Shutdown(); - IN_Shutdown (); - if (host_basepal) - VID_Shutdown(); -} - +#endif diff --git a/common/client.h b/common/client.h index 608afd3..a7488d9 100644 --- a/common/client.h +++ b/common/client.h @@ -205,7 +205,7 @@ typedef struct int qport; // download stuff - FILE *download; // file transfer from server + QFile *download; // file transfer from server char downloadtempname[MAX_OSPATH]; char downloadname[MAX_OSPATH]; int downloadnumber; @@ -229,7 +229,7 @@ typedef struct qboolean demoplayback; qboolean timedemo; int forcetrack; - gzFile *demofile; + QFile *demofile; float td_lastframe; int td_startframe; float td_starttime; @@ -446,14 +446,14 @@ void CL_BeginServerConnect(void); #define MAX_VISEDICTS 256 extern int cl_numvisedicts, cl_oldnumvisedicts; -#ifdef QUAKEWORLD +//#ifdef QUAKEWORLD extern entity_t *cl_visedicts, *cl_oldvisedicts; extern entity_t cl_visedicts_list[2][MAX_VISEDICTS]; extern char emodel_name[], pmodel_name[], prespawn_name[], modellist_name[], soundlist_name[]; -#elif UQUAKE -extern entity_t *cl_visedicts[MAX_VISEDICTS]; -#endif // QUAKEWORLD else UQUAKE +//#elif UQUAKE +//extern entity_t *cl_visedicts[MAX_VISEDICTS]; +//#endif // QUAKEWORLD else UQUAKE // @@ -497,8 +497,9 @@ void CL_StopPlayback (void); #ifdef QUAKEWORLD qboolean CL_GetMessage (void); void CL_WriteDemoCmd (usercmd_t *pcmd); -#elif UQUAKE +#elif defined(UQUAKE) int CL_GetMessage (void); +void CL_SignonReply (void); #endif // QUAKEWORLD else UQUAKE void CL_Stop_f (void); diff --git a/common/cvar.c b/common/cvar.c index 69f8152..5967abc 100644 --- a/common/cvar.c +++ b/common/cvar.c @@ -278,12 +278,12 @@ Writes lines containing "set variable value" for all variables with the archive flag set to true. ============ */ -void Cvar_WriteVariables (FILE *f) +void Cvar_WriteVariables (QFile *f) { cvar_t *var; for (var = cvar_vars ; var ; var = var->next) if (var->archive) - fprintf (f, "%s \"%s\"\n", var->name, var->string); + Qprintf (f, "%s \"%s\"\n", var->name, var->string); } diff --git a/common/cvar.h b/common/cvar.h index c371146..361209e 100644 --- a/common/cvar.h +++ b/common/cvar.h @@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define _CVAR_H #include +#include /* cvar_t variables are used to hold scalar or string variables that can be changed or displayed at the console or prog code as well as accessed directly @@ -95,7 +96,7 @@ qboolean Cvar_Command (void); // command. Returns true if the command was a variable reference that // was handled. (print or change) -void Cvar_WriteVariables (FILE *f); +void Cvar_WriteVariables (QFile *f); // Writes lines containing "set variable value" for all variables // with the archive flag set to true. diff --git a/common/keys.c b/common/keys.c index 78df937..e52b001 100644 --- a/common/keys.c +++ b/common/keys.c @@ -628,13 +628,13 @@ Key_WriteBindings Writes lines containing "bind key value" ============ */ -void Key_WriteBindings (FILE *f) +void Key_WriteBindings (QFile *f) { int i; for (i=0 ; i<256 ; i++) if (keybindings[i]) - fprintf (f, "bind %s \"%s\"\n", Key_KeynumToString(i), keybindings[i]); + Qprintf (f, "bind %s \"%s\"\n", Key_KeynumToString(i), keybindings[i]); } diff --git a/common/keys.h b/common/keys.h index 5b406cb..af21af6 100644 --- a/common/keys.h +++ b/common/keys.h @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define KEYS_H #include "qtypes.h" +#include "quakeio.h" // // these are the key numbers that should be passed to Key_Event @@ -166,7 +167,7 @@ extern qboolean chat_team; void Key_Event (int key, qboolean down); void Key_Init (void); -void Key_WriteBindings (FILE *f); +void Key_WriteBindings (QFile *f); void Key_SetBinding (int keynum, char *binding); void Key_ClearStates (void); diff --git a/common/pr_edict.c b/common/pr_edict.c index 7c16a7e..a0cacf2 100644 --- a/common/pr_edict.c +++ b/common/pr_edict.c @@ -527,7 +527,7 @@ ED_Write For savegames ============= */ -void ED_Write (FILE *f, edict_t *ed) +void ED_Write (QFile *f, edict_t *ed) { ddef_t *d; int *v; @@ -535,11 +535,11 @@ void ED_Write (FILE *f, edict_t *ed) char *name; int type; - fprintf (f, "{\n"); + Qprintf (f, "{\n"); if (ed->free) { - fprintf (f, "}\n"); + Qprintf (f, "}\n"); return; } @@ -560,11 +560,11 @@ void ED_Write (FILE *f, edict_t *ed) if (j == type_size[type]) continue; - fprintf (f,"\"%s\" ",name); - fprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v)); + Qprintf (f,"\"%s\" ",name); + Qprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v)); } - fprintf (f, "}\n"); + Qprintf (f, "}\n"); } void ED_PrintNum (int ent) @@ -665,14 +665,14 @@ FIXME: need to tag constants, doesn't really work ED_WriteGlobals ============= */ -void ED_WriteGlobals (FILE *f) +void ED_WriteGlobals (QFile *f) { ddef_t *def; int i; char *name; int type; - fprintf (f,"{\n"); + Qprintf (f,"{\n"); for (i=0 ; inumglobaldefs ; i++) { def = &pr_globaldefs[i]; @@ -687,10 +687,10 @@ void ED_WriteGlobals (FILE *f) continue; name = PR_GetString(def->s_name); - fprintf (f,"\"%s\" ", name); - fprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs])); + Qprintf (f,"\"%s\" ", name); + Qprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs])); } - fprintf (f,"}\n"); + Qprintf (f,"}\n"); } /* diff --git a/common/progs.h b/common/progs.h index 97bae8f..0c505db 100644 --- a/common/progs.h +++ b/common/progs.h @@ -82,10 +82,10 @@ char *ED_NewString (char *string); // returns a copy of the string allocated from the server's string heap void ED_Print (edict_t *ed); -void ED_Write (FILE *f, edict_t *ed); +void ED_Write (QFile *f, edict_t *ed); char *ED_ParseEdict (char *data, edict_t *ent); -void ED_WriteGlobals (FILE *f); +void ED_WriteGlobals (QFile *f); void ED_ParseGlobals (char *data); void ED_LoadFromFile (char *data); diff --git a/common/quakefs.c b/common/quakefs.c index 45d2678..42f5c22 100644 --- a/common/quakefs.c +++ b/common/quakefs.c @@ -264,9 +264,9 @@ void COM_CopyFile (char *netpath, char *cachepath) } -gzFile *COM_gzOpenRead(const char *path, int offs, int len) +QFile *COM_gzOpenRead(const char *path, int offs, int len) { - int fd=open(path,O_RDONLY); +/* int fd=open(path,O_RDONLY); unsigned char id[2]; unsigned char len_bytes[4]; if (fd==-1) { @@ -290,7 +290,8 @@ gzFile *COM_gzOpenRead(const char *path, int offs, int len) } lseek(fd,offs,SEEK_SET); com_filesize=len; - return gzdopen(fd,"rb"); + return gzdopen(fd,"rb");*/ + return 0; } /* @@ -303,7 +304,7 @@ Sets com_filesize and one of handle or file */ int file_from_pak; // global indicating file came from pack file ZOID -int COM_FOpenFile (char *filename, gzFile **gzfile) +int COM_FOpenFile (char *filename, QFile **gzfile) { searchpath_t *search; char netpath[MAX_OSPATH]; @@ -402,7 +403,7 @@ byte *loadbuf; int loadsize; byte *COM_LoadFile (char *path, int usehunk) { - gzFile *h; + QFile *h; byte *buf; char base[32]; int len; @@ -442,8 +443,8 @@ byte *COM_LoadFile (char *path, int usehunk) #ifndef SERVERONLY Draw_BeginDisc (); #endif - gzread (h, buf, len); - gzclose (h); + Qread (h, buf, len); + Qclose (h); #ifndef SERVERONLY Draw_EndDisc (); #endif diff --git a/common/quakefs.h b/common/quakefs.h index d0dadeb..344df98 100644 --- a/common/quakefs.h +++ b/common/quakefs.h @@ -25,11 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define _QUAKEFS_H #include "config.h" -#ifdef HAS_ZLIB -#include -#else -#include "nozip.h" -#endif +#include "quakeio.h" //============================================================================ @@ -41,8 +37,8 @@ struct cache_user_s; extern char com_gamedir[MAX_OSPATH]; void COM_WriteFile (char *filename, void *data, int len); -int COM_FOpenFile (char *filename, gzFile **file); -void COM_CloseFile (FILE *h); +int COM_FOpenFile (char *filename, QFile **file); +void COM_CloseFile (QFile *h); byte *COM_LoadStackFile (char *path, void *buffer, int bufsize); byte *COM_LoadTempFile (char *path); diff --git a/common/r_efrag.c b/common/r_efrag.c index 54af88f..e5e4288 100644 --- a/common/r_efrag.c +++ b/common/r_efrag.c @@ -267,11 +267,7 @@ void R_StoreEfrags (efrag_t **ppefrag) if ((pent->visframe != r_framecount) && (cl_numvisedicts < MAX_VISEDICTS)) { -#ifdef QUAKEWORLD cl_visedicts[cl_numvisedicts++] = *pent; -#else - cl_visedicts[cl_numvisedicts++] = pent; -#endif // mark that we've recorded this entity for this frame pent->visframe = r_framecount; diff --git a/common/r_main.c b/common/r_main.c index fd9cc64..65bd750 100644 --- a/common/r_main.c +++ b/common/r_main.c @@ -597,11 +597,8 @@ void R_DrawEntitiesOnList (void) for (i=0 ; imodel->type) { diff --git a/common/register_check.c b/common/register_check.c index c3808a7..bd6d98d 100644 --- a/common/register_check.c +++ b/common/register_check.c @@ -44,7 +44,7 @@ cvar_t registered = {"registered", "0"}; void register_check ( void ) { - gzFile *h; + QFile *h; Cvar_RegisterVariable (®istered); @@ -52,6 +52,6 @@ register_check ( void ) { if (h) { Cvar_Set ("registered", "1"); - gzclose (h); + Qclose (h); } } diff --git a/qw_client/Makefile.in b/qw_client/Makefile.in index 7a55221..feb3eb6 100644 --- a/qw_client/Makefile.in +++ b/qw_client/Makefile.in @@ -146,7 +146,8 @@ QW_NET_SRC = net_udp.c net_com.c mdfour.c # Common source files MISC_SRC = common.c crc.c cvar.c cmd.c mathlib.c register_check.c \ - wad.c zone.c cvars.c qendian.c lib_replace.c quakefs.c qargs.c + wad.c zone.c cvars.c qendian.c lib_replace.c quakefs.c \ + quakeio.c qargs.c # GL renderer source diff --git a/qw_client/cl_demo.c b/qw_client/cl_demo.c index 8d79dff..24b077d 100644 --- a/qw_client/cl_demo.c +++ b/qw_client/cl_demo.c @@ -54,7 +54,7 @@ void CL_StopPlayback (void) if (!cls.demoplayback) return; - gzclose (cls.demofile); + Qclose (cls.demofile); cls.demofile = NULL; cls.state = ca_disconnected; cls.demoplayback = 0; @@ -84,10 +84,10 @@ void CL_WriteDemoCmd (usercmd_t *pcmd) //Con_Printf("write: %ld bytes, %4.4f\n", msg->cursize, realtime); fl = LittleFloat((float)realtime); - gzwrite (cls.demofile, &fl, sizeof(fl)); + Qwrite (cls.demofile, &fl, sizeof(fl)); c = dem_cmd; - gzwrite (cls.demofile, &c, sizeof(c)); + Qwrite (cls.demofile, &c, sizeof(c)); // correct for byte order, bytes don't matter cmd = *pcmd; @@ -98,15 +98,15 @@ void CL_WriteDemoCmd (usercmd_t *pcmd) cmd.sidemove = LittleShort(cmd.sidemove); cmd.upmove = LittleShort(cmd.upmove); - gzwrite(cls.demofile, &cmd, sizeof(cmd)); + Qwrite(cls.demofile, &cmd, sizeof(cmd)); for (i=0 ; i<3 ; i++) { fl = LittleFloat (cl.viewangles[i]); - gzwrite (cls.demofile, &fl, 4); + Qwrite (cls.demofile, &fl, 4); } - gzflush (cls.demofile, Z_SYNC_FLUSH); + Qflush (cls.demofile); } /* @@ -128,16 +128,16 @@ void CL_WriteDemoMessage (sizebuf_t *msg) return; fl = LittleFloat((float)realtime); - gzwrite (cls.demofile, &fl, sizeof(fl)); + Qwrite (cls.demofile, &fl, sizeof(fl)); c = dem_read; - gzwrite (cls.demofile, &c, sizeof(c)); + Qwrite (cls.demofile, &c, sizeof(c)); len = LittleLong (msg->cursize); - gzwrite (cls.demofile, &len, 4); - gzwrite (cls.demofile, msg->data, msg->cursize); + Qwrite (cls.demofile, &len, 4); + Qwrite (cls.demofile, msg->data, msg->cursize); - gzflush (cls.demofile, Z_SYNC_FLUSH); + Qflush (cls.demofile); } /* @@ -156,7 +156,7 @@ qboolean CL_GetDemoMessage (void) usercmd_t *pcmd; // read the time from the packet - gzread(cls.demofile, &demotime, sizeof(demotime)); + Qread(cls.demofile, &demotime, sizeof(demotime)); demotime = LittleFloat(demotime); // decide if it is time to grab the next message @@ -166,7 +166,7 @@ qboolean CL_GetDemoMessage (void) else if (demotime > cls.td_lastframe) { cls.td_lastframe = demotime; // rewind back to time - gzseek(cls.demofile, gztell(cls.demofile) - sizeof(demotime), + Qseek(cls.demofile, Qtell(cls.demofile) - sizeof(demotime), SEEK_SET); return 0; // allready read this frame's message } @@ -180,12 +180,12 @@ qboolean CL_GetDemoMessage (void) // too far back realtime = demotime - 1.0; // rewind back to time - gzseek(cls.demofile, gztell(cls.demofile) - sizeof(demotime), + Qseek(cls.demofile, Qtell(cls.demofile) - sizeof(demotime), SEEK_SET); return 0; } else if (realtime < demotime) { // rewind back to time - gzseek(cls.demofile, gztell(cls.demofile) - sizeof(demotime), + Qseek(cls.demofile, Qtell(cls.demofile) - sizeof(demotime), SEEK_SET); return 0; // don't need another message yet } @@ -196,14 +196,14 @@ qboolean CL_GetDemoMessage (void) Host_Error ("CL_GetDemoMessage: cls.state != ca_active"); // get the msg type - gzread (cls.demofile, &c, sizeof(c)); + Qread (cls.demofile, &c, sizeof(c)); switch (c) { case dem_cmd : // user sent input i = cls.netchan.outgoing_sequence & UPDATE_MASK; pcmd = &cl.frames[i].cmd; - r = gzread (cls.demofile, pcmd, sizeof(*pcmd)); + r = Qread (cls.demofile, pcmd, sizeof(*pcmd)); if (r != sizeof(*pcmd)) { CL_StopPlayback (); @@ -220,19 +220,19 @@ qboolean CL_GetDemoMessage (void) cls.netchan.outgoing_sequence++; for (i=0 ; i<3 ; i++) { - r = gzread (cls.demofile, &f, 4); + r = Qread (cls.demofile, &f, 4); cl.viewangles[i] = LittleFloat (f); } break; case dem_read: // get the next message - gzread (cls.demofile, &net_message.cursize, 4); + Qread (cls.demofile, &net_message.cursize, 4); net_message.cursize = LittleLong (net_message.cursize); //Con_Printf("read: %ld bytes\n", net_message.cursize); if (net_message.cursize > MAX_MSGLEN) Sys_Error ("Demo message > MAX_MSGLEN"); - r = gzread (cls.demofile, net_message.data, net_message.cursize); + r = Qread (cls.demofile, net_message.data, net_message.cursize); if (r != net_message.cursize) { CL_StopPlayback (); @@ -241,9 +241,9 @@ qboolean CL_GetDemoMessage (void) break; case dem_set : - gzread (cls.demofile, &i, 4); + Qread (cls.demofile, &i, 4); cls.netchan.outgoing_sequence = LittleLong(i); - gzread (cls.demofile, &i, 4); + Qread (cls.demofile, &i, 4); cls.netchan.incoming_sequence = LittleLong(i); break; @@ -300,7 +300,7 @@ void CL_Stop_f (void) CL_WriteDemoMessage (&net_message); // finish up - gzclose (cls.demofile); + Qclose (cls.demofile); cls.demofile = NULL; cls.demorecording = false; Con_Printf ("Completed demo\n"); @@ -327,21 +327,21 @@ void CL_WriteRecordDemoMessage (sizebuf_t *msg, int seq) return; fl = LittleFloat((float)realtime); - gzwrite (cls.demofile, &fl, sizeof(fl)); + Qwrite (cls.demofile, &fl, sizeof(fl)); c = dem_read; - gzwrite (cls.demofile, &c, sizeof(c)); + Qwrite (cls.demofile, &c, sizeof(c)); len = LittleLong (msg->cursize + 8); - gzwrite (cls.demofile, &len, 4); + Qwrite (cls.demofile, &len, 4); i = LittleLong(seq); - gzwrite (cls.demofile, &i, 4); - gzwrite (cls.demofile, &i, 4); + Qwrite (cls.demofile, &i, 4); + Qwrite (cls.demofile, &i, 4); - gzwrite (cls.demofile, msg->data, msg->cursize); + Qwrite (cls.demofile, msg->data, msg->cursize); - gzflush (cls.demofile, Z_SYNC_FLUSH); + Qflush (cls.demofile); } @@ -357,17 +357,17 @@ void CL_WriteSetDemoMessage (void) return; fl = LittleFloat((float)realtime); - gzwrite (cls.demofile, &fl, sizeof(fl)); + Qwrite (cls.demofile, &fl, sizeof(fl)); c = dem_set; - gzwrite (cls.demofile, &c, sizeof(c)); + Qwrite (cls.demofile, &c, sizeof(c)); len = LittleLong(cls.netchan.outgoing_sequence); - gzwrite (cls.demofile, &len, 4); + Qwrite (cls.demofile, &len, 4); len = LittleLong(cls.netchan.incoming_sequence); - gzwrite (cls.demofile, &len, 4); + Qwrite (cls.demofile, &len, 4); - gzflush (cls.demofile, Z_SYNC_FLUSH); + Qflush (cls.demofile); } @@ -416,7 +416,7 @@ void CL_Record_f (void) // COM_DefaultExtension (name, ".qwd"); - cls.demofile = gzopen (name, "wb"); + cls.demofile = Qopen (name, "wb"); if (!cls.demofile) { Con_Printf ("ERROR: couldn't open.\n"); @@ -702,7 +702,7 @@ void CL_ReRecord_f (void) // COM_DefaultExtension (name, ".qwd"); - cls.demofile = gzopen (name, "wb"); + cls.demofile = Qopen (name, "wb"); if (!cls.demofile) { Con_Printf ("ERROR: couldn't open.\n"); diff --git a/qw_client/cl_parse.c b/qw_client/cl_parse.c index 138e90d..159d579 100644 --- a/qw_client/cl_parse.c +++ b/qw_client/cl_parse.c @@ -168,7 +168,7 @@ to start a download from the server. */ qboolean CL_CheckOrDownloadFile (char *filename) { - gzFile *f; + QFile *f; if (strstr (filename, "..")) { @@ -179,7 +179,7 @@ qboolean CL_CheckOrDownloadFile (char *filename) COM_FOpenFile (filename, &f); if (f) { // it exists, no need to download - gzclose (f); + Qclose (f); return true; } @@ -367,7 +367,7 @@ void CL_ParseDownload (void) if (cls.download) { Con_Printf ("cls.download shouldn't have been set\n"); - fclose (cls.download); + Qclose (cls.download); cls.download = NULL; } CL_RequestNextDownload (); @@ -384,7 +384,7 @@ void CL_ParseDownload (void) COM_CreatePath (name); - cls.download = fopen (name, "wb"); + cls.download = Qopen (name, "wb"); if (!cls.download) { msg_readcount += size; @@ -394,7 +394,7 @@ void CL_ParseDownload (void) } } - fwrite (net_message.data + msg_readcount, 1, size, cls.download); + Qwrite (cls.download, net_message.data + msg_readcount, size); msg_readcount += size; if (percent != 100) @@ -423,7 +423,7 @@ void CL_ParseDownload (void) Con_Printf ("100%%\n"); #endif - fclose (cls.download); + Qclose (cls.download); // rename the temp file to it's final name if (strcmp(cls.downloadtempname, cls.downloadname)) { diff --git a/qw_client/r_part.c b/qw_client/r_part.c index fe615eb..d3469b3 100644 --- a/qw_client/r_part.c +++ b/qw_client/r_part.c @@ -93,7 +93,7 @@ void R_ClearParticles (void) void R_ReadPointFile_f (void) { - gzFile *f; + QFile *f; vec3_t org; int r; int c; @@ -114,7 +114,7 @@ void R_ReadPointFile_f (void) c = 0; for ( ;; ) { - if (!gzgets(f,buf,sizeof(buf))) + if (!Qgets(f,buf,sizeof(buf))) break; r = sscanf (buf,"%f %f %f\n", &org[0], &org[1], &org[2]); if (r != 3) @@ -138,7 +138,7 @@ void R_ReadPointFile_f (void) VectorCopy (org, p->org); } - gzclose (f); + Qclose (f); Con_Printf ("%i points read\n", c); } diff --git a/qw_server/Makefile.in b/qw_server/Makefile.in index a6e546b..b4a25f9 100644 --- a/qw_server/Makefile.in +++ b/qw_server/Makefile.in @@ -70,7 +70,8 @@ targets = $(SRVQUAKE) GENERAL_SRC = common.c crc.c cvar.c cmd.c mathlib.c wad.c zone.c \ $(QW_NET_SRC) net_chan.c $(SRV_SRC) $(QW_SRV_SRC) \ $(SRV_PR_SRC) $(QW_SRV_SYS_SRC) $(QW_GENERAL_SRC) \ - register_check.c qendian.c qargs.c quakefs.c lib_replace.c + register_check.c qendian.c qargs.c quakefs.c quakeio.c \ + lib_replace.c ALL_QW_SRV_SRC = $(GENERAL_SRC) model.c # FIXME: add dos/win specifc source diff --git a/qw_server/server.h b/qw_server/server.h index bd89ffa..76c1e54 100644 --- a/qw_server/server.h +++ b/qw_server/server.h @@ -26,12 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "config.h" -#ifdef HAS_ZLIB -#include -#else -#include "nozip.h" -#endif - #include #define QW_SERVER @@ -183,7 +177,7 @@ typedef struct client_s client_frame_t frames[UPDATE_BACKUP]; // updates can be deltad from here - gzFile *download; // file being downloaded + QFile *download; // file being downloaded int downloadsize; // total bytes int downloadcount; // bytes sent diff --git a/qw_server/sv_ccmds.c b/qw_server/sv_ccmds.c index 414c635..ae4eb3e 100644 --- a/qw_server/sv_ccmds.c +++ b/qw_server/sv_ccmds.c @@ -306,7 +306,7 @@ void SV_Map_f (void) { char level[MAX_QPATH]; char expanded[MAX_QPATH]; - gzFile *f; + QFile *f; if (Cmd_Argc() != 2) { diff --git a/uquake/Makefile.in b/uquake/Makefile.in index 0e027b3..5efa85b 100644 --- a/uquake/Makefile.in +++ b/uquake/Makefile.in @@ -156,7 +156,8 @@ UQ_NET_SRC = net_dgrm.c net_loop.c net_main.c net_vcr.c $(NET_SRC) # Common source files MISC_SRC = common.c crc.c cvar.c cmd.c mathlib.c register_check.c \ - wad.c zone.c cvars.c lib_replace.c qendian.c quakefs.c + wad.c zone.c cvars.c lib_replace.c qendian.c quakefs.c \ + quakeio.c # GL renderer source diff --git a/uquake/cl_main.c b/uquake/cl_main.c deleted file mode 100644 index de592cb..0000000 --- a/uquake/cl_main.c +++ /dev/null @@ -1,783 +0,0 @@ -/* -cl_main.c - client main loop -Copyright (C) 1996-1997 Id Software, Inc. -Portions Copyright (C) 1999,2000 Nelson Rush. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// we need to declare some mouse variables here, because the menu system -// references them even when on a unix system. - -// these two are not intended to be set directly -cvar_t cl_name = {"_cl_name", "player", true}; -cvar_t cl_color = {"_cl_color", "0", true}; - -cvar_t cl_shownet = {"cl_shownet","0"}; // can be 0, 1, or 2 -cvar_t cl_nolerp = {"cl_nolerp","0"}; - -cvar_t cl_sbar = {"cl_sbar", "1", true}; -cvar_t cl_hudswap = {"cl_hudswap", "1", true}; - -cvar_t lookspring = {"lookspring","0", true}; -cvar_t lookstrafe = {"lookstrafe","0", true}; -cvar_t sensitivity = {"sensitivity","3", true}; - -cvar_t m_pitch = {"m_pitch","0.022", true}; -cvar_t m_yaw = {"m_yaw","0.022", true}; -cvar_t m_forward = {"m_forward","1", true}; -cvar_t m_side = {"m_side","0.8", true}; - - -client_static_t cls; -client_state_t cl; -// FIXME: put these on hunk? -efrag_t cl_efrags[MAX_EFRAGS]; -entity_t cl_entities[MAX_EDICTS]; -entity_t cl_static_entities[MAX_STATIC_ENTITIES]; -lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES]; -dlight_t cl_dlights[MAX_DLIGHTS]; - -int cl_numvisedicts; -entity_t *cl_visedicts[MAX_VISEDICTS]; - -/* -===================== -CL_ClearState - -===================== -*/ -void CL_ClearState (void) -{ - int i; - - if (!sv.active) - Host_ClearMemory (); - -// wipe the entire cl structure - memset (&cl, 0, sizeof(cl)); - - SZ_Clear (&cls.netchan.message); - -// clear other arrays - memset (cl_efrags, 0, sizeof(cl_efrags)); - memset (cl_entities, 0, sizeof(cl_entities)); - memset (cl_dlights, 0, sizeof(cl_dlights)); - memset (cl_lightstyle, 0, sizeof(cl_lightstyle)); - memset (cl_temp_entities, 0, sizeof(cl_temp_entities)); - CL_ClearTEnts (); - -// -// allocate the efrags and chain together into a free list -// - cl.free_efrags = cl_efrags; - for (i=0 ; i= ca_connected) - { - if (cls.demorecording) - CL_Stop_f (); - - Con_DPrintf ("Sending clc_disconnect\n"); - SZ_Clear (&cls.netchan.message); - MSG_WriteByte (&cls.netchan.message, clc_disconnect); - NET_SendUnreliableMessage (cls.netcon, &cls.netchan.message); - SZ_Clear (&cls.netchan.message); - NET_Close (cls.netcon); - - cls.state = ca_disconnected; - if (sv.active) - Host_ShutdownServer(false); - } - - cls.demoplayback = cls.timedemo = false; - cls.signon = 0; -} - -void CL_Disconnect_f (void) -{ - CL_Disconnect (); - if (sv.active) - Host_ShutdownServer (false); -} - - - - -/* -===================== -CL_EstablishConnection - -Host should be either "local" or a net address to be passed on -===================== -*/ -void CL_EstablishConnection (char *host) -{ - if (cls.state == ca_dedicated) - return; - - if (cls.demoplayback) - return; - - CL_Disconnect (); - - cls.netcon = NET_Connect (host); - if (!cls.netcon) - Host_Error ("CL_Connect: connect failed\n"); - Con_DPrintf ("CL_EstablishConnection: connected to %s\n", host); - - cls.demonum = -1; // not in the demo loop now - cls.state = ca_connected; - cls.signon = 0; // need all the signon messages before playing -} - -/* -===================== -CL_SignonReply - -An svc_signonnum has been received, perform a client side setup -===================== -*/ -void CL_SignonReply (void) -{ - char str[8192]; - -Con_DPrintf ("CL_SignonReply: %i\n", cls.signon); - - switch (cls.signon) - { - case 1: - MSG_WriteByte (&cls.netchan.message, clc_stringcmd); - MSG_WriteString (&cls.netchan.message, "prespawn"); - cls.state = ca_onserver; - break; - - case 2: - MSG_WriteByte (&cls.netchan.message, clc_stringcmd); - MSG_WriteString (&cls.netchan.message, va("name \"%s\"\n", cl_name.string)); - - MSG_WriteByte (&cls.netchan.message, clc_stringcmd); - MSG_WriteString (&cls.netchan.message, va("color %i %i\n", ((int)cl_color.value)>>4, ((int)cl_color.value)&15)); - - MSG_WriteByte (&cls.netchan.message, clc_stringcmd); - snprintf(str, sizeof(str), "spawn %s", cls.spawnparms); - MSG_WriteString (&cls.netchan.message, str); - break; - - case 3: - MSG_WriteByte (&cls.netchan.message, clc_stringcmd); - MSG_WriteString (&cls.netchan.message, "begin"); - Cache_Report (); // print remaining memory - break; - - case 4: - SCR_EndLoadingPlaque (); // allow normal screen updates - cls.state = ca_active; - break; - } -} - -/* -===================== -CL_NextDemo - -Called to play the next demo in the demo loop -===================== -*/ -void CL_NextDemo (void) -{ - char str[1024]; - - if (cls.demonum == -1) - return; // don't play demos - - SCR_BeginLoadingPlaque (); - - if (!cls.demos[cls.demonum][0] || cls.demonum == MAX_DEMOS) - { - cls.demonum = 0; - if (!cls.demos[cls.demonum][0]) - { - Con_Printf ("No demos listed with startdemos\n"); - cls.demonum = -1; - return; - } - } - - snprintf(str, sizeof(str),"playdemo %s\n", cls.demos[cls.demonum]); - Cbuf_InsertText (str); - cls.demonum++; -} - -/* -============== -CL_PrintEntities_f -============== -*/ -void CL_PrintEntities_f (void) -{ - entity_t *ent; - int i; - - for (i=0,ent=cl_entities ; imodel) - { - Con_Printf ("EMPTY\n"); - continue; - } - Con_Printf ("%s:%2i (%5.1f,%5.1f,%5.1f) [%5.1f %5.1f %5.1f]\n" - ,ent->model->name,ent->frame, ent->origin[0], ent->origin[1], ent->origin[2], ent->angles[0], ent->angles[1], ent->angles[2]); - } -} - - -/* -=============== -SetPal - -Debugging tool, just flashes the screen -=============== -*/ -void SetPal (int i) -{ -#if 0 - static int old; - byte pal[768]; - int c; - - if (i == old) - return; - old = i; - - if (i==0) - VID_SetPalette (host_basepal); - else if (i==1) - { - for (c=0 ; c<768 ; c+=3) - { - pal[c] = 0; - pal[c+1] = 255; - pal[c+2] = 0; - } - VID_SetPalette (pal); - } - else - { - for (c=0 ; c<768 ; c+=3) - { - pal[c] = 0; - pal[c+1] = 0; - pal[c+2] = 255; - } - VID_SetPalette (pal); - } -#endif -} - -/* -=============== -CL_AllocDlight - -=============== -*/ -dlight_t *CL_AllocDlight (int key) -{ - int i; - dlight_t *dl; - -// first look for an exact key match - if (key) - { - dl = cl_dlights; - for (i=0 ; ikey == key) - { - memset (dl, 0, sizeof(*dl)); - dl->key = key; - return dl; - } - } - } - -// then look for anything else - dl = cl_dlights; - for (i=0 ; idie < cl.time) - { - memset (dl, 0, sizeof(*dl)); - dl->key = key; - return dl; - } - } - - dl = &cl_dlights[0]; - memset (dl, 0, sizeof(*dl)); - dl->key = key; - return dl; -} - - -/* -=============== -CL_DecayLights - -=============== -*/ -void CL_DecayLights (void) -{ - int i; - dlight_t *dl; - float time; - - time = cl.time - cl.oldtime; - - dl = cl_dlights; - for (i=0 ; idie < cl.time || !dl->radius) - continue; - - dl->radius -= time*dl->decay; - if (dl->radius < 0) - dl->radius = 0; - } -} - - -/* -=============== -CL_LerpPoint - -Determines the fraction between the last two messages that the objects -should be put at. -=============== -*/ -float CL_LerpPoint (void) -{ - float f, frac; - - f = cl.mtime[0] - cl.mtime[1]; - - if (!f || cl_nolerp.value || cls.timedemo || sv.active) - { - cl.time = cl.mtime[0]; - return 1; - } - - if (f > 0.1) - { // dropped packet, or start of demo - cl.mtime[1] = cl.mtime[0] - 0.1; - f = 0.1; - } - frac = (cl.time - cl.mtime[1]) / f; -//Con_Printf ("frac: %f\n",frac); - if (frac < 0) - { - if (frac < -0.01) - { -SetPal(1); - cl.time = cl.mtime[1]; -// Con_Printf ("low frac\n"); - } - frac = 0; - } - else if (frac > 1) - { - if (frac > 1.01) - { -SetPal(2); - cl.time = cl.mtime[0]; -// Con_Printf ("high frac\n"); - } - frac = 1; - } - else - SetPal(0); - - return frac; -} - - -/* -=============== -CL_RelinkEntities -=============== -*/ -void CL_RelinkEntities (void) -{ - entity_t *ent; - int i, j; - float frac, f, d; - vec3_t delta; - float bobjrotate; - vec3_t oldorg; - dlight_t *dl; - -// determine partial update time - frac = CL_LerpPoint (); - - cl_numvisedicts = 0; - -// -// interpolate player info -// - for (i=0 ; i<3 ; i++) - cl.velocity[i] = cl.mvelocity[1][i] + - frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]); - - if (cls.demoplayback) - { - // interpolate the angles - for (j=0 ; j<3 ; j++) - { - d = cl.mviewangles[0][j] - cl.mviewangles[1][j]; - if (d > 180) - d -= 360; - else if (d < -180) - d += 360; - cl.viewangles[j] = cl.mviewangles[1][j] + frac*d; - } - } - - bobjrotate = anglemod(100*cl.time); - -// start on the entity after the world - for (i=1,ent=cl_entities+1 ; imodel) - { // empty slot - if (ent->forcelink) - R_RemoveEfrags (ent); // just became empty - continue; - } - -// if the object wasn't included in the last packet, remove it - if (ent->msgtime != cl.mtime[0]) - { - ent->model = NULL; - continue; - } - - VectorCopy (ent->origin, oldorg); - - if (ent->forcelink) - { // the entity was not updated in the last message - // so move to the final spot - VectorCopy (ent->msg_origins[0], ent->origin); - VectorCopy (ent->msg_angles[0], ent->angles); - } - else - { // if the delta is large, assume a teleport and don't lerp - f = frac; - for (j=0 ; j<3 ; j++) - { - delta[j] = ent->msg_origins[0][j] - ent->msg_origins[1][j]; - if (delta[j] > 100 || delta[j] < -100) - f = 1; // assume a teleportation, not a motion - } - - // interpolate the origin and angles - for (j=0 ; j<3 ; j++) - { - ent->origin[j] = ent->msg_origins[1][j] + f*delta[j]; - - d = ent->msg_angles[0][j] - ent->msg_angles[1][j]; - if (d > 180) - d -= 360; - else if (d < -180) - d += 360; - ent->angles[j] = ent->msg_angles[1][j] + f*d; - } - - } - -// rotate binary objects locally - if (ent->model->flags & EF_ROTATE) - ent->angles[1] = bobjrotate; - - if (ent->effects & EF_BRIGHTFIELD) - R_EntityParticles (ent); -#ifdef QUAKE2 - if (ent->effects & EF_DARKFIELD) - R_DarkFieldParticles (ent); -#endif - if (ent->effects & EF_MUZZLEFLASH) - { - vec3_t fv, rv, uv; - - dl = CL_AllocDlight (i); - VectorCopy (ent->origin, dl->origin); - dl->origin[2] += 16; - AngleVectors (ent->angles, fv, rv, uv); - - VectorMA (dl->origin, 18, fv, dl->origin); - dl->radius = 200 + (rand()&31); - dl->minlight = 32; - dl->die = cl.time + 0.1; - } - if (ent->effects & EF_BRIGHTLIGHT) - { - dl = CL_AllocDlight (i); - VectorCopy (ent->origin, dl->origin); - dl->origin[2] += 16; - dl->radius = 400 + (rand()&31); - dl->die = cl.time + 0.001; - } - if (ent->effects & EF_DIMLIGHT) - { - dl = CL_AllocDlight (i); - VectorCopy (ent->origin, dl->origin); - dl->radius = 200 + (rand()&31); - dl->die = cl.time + 0.001; - } -#ifdef QUAKE2 - if (ent->effects & EF_DARKLIGHT) - { - dl = CL_AllocDlight (i); - VectorCopy (ent->origin, dl->origin); - dl->radius = 200.0 + (rand()&31); - dl->die = cl.time + 0.001; - dl->dark = true; - } - if (ent->effects & EF_LIGHT) - { - dl = CL_AllocDlight (i); - VectorCopy (ent->origin, dl->origin); - dl->radius = 200; - dl->die = cl.time + 0.001; - } -#endif - - if (ent->model->flags & EF_GIB) - R_RocketTrail (oldorg, ent->origin, 2); - else if (ent->model->flags & EF_ZOMGIB) - R_RocketTrail (oldorg, ent->origin, 4); - else if (ent->model->flags & EF_TRACER) - R_RocketTrail (oldorg, ent->origin, 3); - else if (ent->model->flags & EF_TRACER2) - R_RocketTrail (oldorg, ent->origin, 5); - else if (ent->model->flags & EF_ROCKET) - { - R_RocketTrail (oldorg, ent->origin, 0); - dl = CL_AllocDlight (i); - VectorCopy (ent->origin, dl->origin); - dl->radius = 200; - dl->die = cl.time + 0.01; - } - else if (ent->model->flags & EF_GRENADE) - R_RocketTrail (oldorg, ent->origin, 1); - else if (ent->model->flags & EF_TRACER3) - R_RocketTrail (oldorg, ent->origin, 6); - - ent->forcelink = false; - - if (i == cl.playernum + 1 && !cl_chasecam.value) - continue; - -#ifdef QUAKE2 - if ( ent->effects & EF_NODRAW ) - continue; -#endif - if (cl_numvisedicts < MAX_VISEDICTS) - { - cl_visedicts[cl_numvisedicts] = ent; - cl_numvisedicts++; - } - } - -} - - -/* -=============== -CL_ReadFromServer - -Read all incoming data from the server -=============== -*/ -int CL_ReadFromServer (void) -{ - int ret; - - cl.oldtime = cl.time; - cl.time += host_frametime; - - do - { - ret = CL_GetMessage (); - if (ret == -1) - Host_Error ("CL_ReadFromServer: lost server connection"); - if (!ret) - break; - - cl.last_received_message = realtime; - CL_ParseServerMessage (); - } while (ret && cls.state >= ca_connected); - - if (cl_shownet.value) - Con_Printf ("\n"); - - CL_RelinkEntities (); - CL_UpdateTEnts (); - -// -// bring the links up to date -// - return 0; -} - -/* -================= -CL_SendCmd -================= -*/ -void CL_SendCmd (void) -{ - usercmd_t cmd; - - if (cls.state < ca_connected) - return; - - if (cls.signon == SIGNONS) - { - // get basic movement from keyboard - CL_BaseMove (&cmd); - - // allow mice or other external controllers to add to the move - IN_Move (&cmd); - - // send the unreliable message - CL_SendMove (&cmd); - - } - - if (cls.demoplayback) - { - SZ_Clear (&cls.netchan.message); - return; - } - -// send the reliable message - if (!cls.netchan.message.cursize) - return; // no message at all - - if (!NET_CanSendMessage (cls.netcon)) - { - Con_DPrintf ("CL_WriteToServer: can't send\n"); - return; - } - - if (NET_SendMessage (cls.netcon, &cls.netchan.message) == -1) - Host_Error ("CL_WriteToServer: lost server connection"); - - SZ_Clear (&cls.netchan.message); -} - -/* -================= -CL_Init -================= -*/ -void CL_Init (void) -{ - SZ_Alloc (&cls.netchan.message, 1024); - - CL_InitInput (); - CL_InitTEnts (); - -// -// register our commands -// - Cvar_RegisterVariable (&cl_name); - Cvar_RegisterVariable (&cl_color); - Cvar_RegisterVariable (&cl_upspeed); - Cvar_RegisterVariable (&cl_forwardspeed); - Cvar_RegisterVariable (&cl_backspeed); - Cvar_RegisterVariable (&cl_sidespeed); - Cvar_RegisterVariable (&cl_movespeedkey); - Cvar_RegisterVariable (&cl_yawspeed); - Cvar_RegisterVariable (&cl_pitchspeed); - Cvar_RegisterVariable (&cl_anglespeedkey); - Cvar_RegisterVariable (&cl_shownet); - Cvar_RegisterVariable (&cl_nolerp); - - Cvar_RegisterVariable (&cl_sbar); - Cvar_RegisterVariable (&cl_hudswap); - - Cvar_RegisterVariable (&lookspring); - Cvar_RegisterVariable (&lookstrafe); - Cvar_RegisterVariable (&sensitivity); - - Cvar_RegisterVariable (&m_pitch); - 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); -} - diff --git a/uquake/host.c b/uquake/host.c index 1d8ef2f..02a05b5 100644 --- a/uquake/host.c +++ b/uquake/host.c @@ -277,13 +277,13 @@ Writes key bindings and archived cvars to config.cfg */ void Host_WriteConfiguration (void) { - FILE *f; + QFile *f; // dedicated servers initialize the host but don't parse and set the // config.cfg cvars if (host_initialized & !isDedicated) { - f = fopen (va("%s/config.cfg",com_gamedir), "w"); + f = Qopen (va("%s/config.cfg",com_gamedir), "w"); if (!f) { Con_Printf ("Couldn't write config.cfg.\n"); @@ -293,7 +293,7 @@ void Host_WriteConfiguration (void) Key_WriteBindings (f); Cvar_WriteVariables (f); - fclose (f); + Qclose (f); } } diff --git a/uquake/host_cmd.c b/uquake/host_cmd.c index be77ba6..f94e087 100644 --- a/uquake/host_cmd.c +++ b/uquake/host_cmd.c @@ -483,7 +483,7 @@ Host_Savegame_f void Host_Savegame_f (void) { char name[256]; - FILE *f; + QFile *f; int i; char comment[SAVEGAME_COMMENT_LENGTH+1]; @@ -533,30 +533,30 @@ void Host_Savegame_f (void) COM_DefaultExtension (name, ".sav"); Con_Printf ("Saving game to %s...\n", name); - f = fopen (name, "w"); + f = Qopen (name, "w"); if (!f) { Con_Printf ("ERROR: couldn't open.\n"); return; } - fprintf (f, "%i\n", SAVEGAME_VERSION); + Qprintf (f, "%i\n", SAVEGAME_VERSION); Host_SavegameComment (comment); - fprintf (f, "%s\n", comment); + Qprintf (f, "%s\n", comment); for (i=0 ; ispawn_parms[i]); - fprintf (f, "%d\n", current_skill); - fprintf (f, "%s\n", sv.name); - fprintf (f, "%f\n",sv.time); + Qprintf (f, "%f\n", svs.clients->spawn_parms[i]); + Qprintf (f, "%d\n", current_skill); + Qprintf (f, "%s\n", sv.name); + Qprintf (f, "%f\n",sv.time); // write the light styles for (i=0 ; iorg); } - gzclose (f); + Qclose (f); Con_Printf ("%i points read\n", c); } diff --git a/uquake/sw_cl_parse.c b/uquake/sw_cl_parse.c index f92f16e..cc352d0 100644 --- a/uquake/sw_cl_parse.c +++ b/uquake/sw_cl_parse.c @@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include entity_t *CL_EntityNum (int num);