From f18b3bcf0277b3833c99a9f254a2d1c76ce19f24 Mon Sep 17 00:00:00 2001 From: "Zephaniah E. Hull" Date: Thu, 27 Jan 2000 17:06:02 +0000 Subject: [PATCH] HUGE changes.. Basicly, sound_lib.a is built, and is compiled into the clients.. Note, uquake is SERIOUSLY FSCKED.. --- Makefile.in | 8 +- acconfig.h | 8 + common/Makefile.in | 186 +++ common/bspfile.h | 284 ++++ common/cd_linux.c | 8 + {qw_common => common}/cmd.c | 6 + {qw_common => common}/cmd.h | 0 common/common.c | 2470 ---------------------------------- common/common.h | 247 ---- common/common_quakedef.h | 31 +- {qw_common => common}/cvar.c | 7 + {uquake => common}/cvar.h | 18 +- common/cvars.h | 20 + common/d_init.c | 1 + common/d_polyse.c | 1 + common/d_sky.c | 1 + common/d_sprite.c | 1 + common/draw.c | 6 +- common/draw.h | 3 + common/gl_draw.c | 5 + common/gl_mesh.c | 6 +- common/gl_refrag.c | 4 + common/gl_rmain.c | 5 + common/gl_rmisc.c | 3 + common/gl_rsurf.c | 2 + common/gl_vidglx.c | 6 + common/gl_vidlinux_3dfx.c | 6 + common/gl_view.c | 4 +- common/gl_warp.c | 4 +- common/glquake.h | 1 + common/glquake2.h | 209 --- common/in_svgalib.c | 6 + common/keys.c | 10 + common/lib_replace.c | 324 +++++ common/lib_replace.h | 55 + common/mathlib.c | 6 +- common/mathlib.h | 59 +- common/model.h | 4 + common/modelgen.h | 6 +- common/net_ser.h | 5 + common/pr_comp.h | 3 - common/qargs.c | 111 ++ common/qargs.h | 38 + common/qdefs.h | 37 + common/qendian.c | 95 ++ common/qendian.h | 62 + common/qstructs.h | 180 +++ common/qtypes.h | 61 + common/quakefs.c | 771 +++++++++++ common/quakefs.h | 48 + common/r_alias.c | 3 +- common/r_bsp.c | 1 + common/r_draw.c | 2 +- common/r_light.c | 1 + common/r_local.h | 18 - common/r_main.c | 5 + common/r_shared.h | 3 + common/r_sky.c | 1 + common/r_surf.c | 2 + common/register_check.c | 5 +- common/render.h | 17 +- common/sbar.c | 7 + common/skin.c | 4 + common/snd_dma.c | 14 +- common/snd_mem.c | 8 +- common/snd_mix.c | 5 +- common/snd_null.c | 5 +- common/snd_oss.c | 5 +- common/sound.h | 5 + common/sw_rpart.c | 2 + common/sw_view.c | 2 + common/sys_linux.c | 3 + common/vid.h | 2 - common/vid_ggi.c | 4 + common/vid_svgalib.c | 2 + common/vid_x.c | 4 + common/wad.c | 5 + common/wad.h | 5 + common/zone.c | 6 + configure.in | 48 +- qw_client/Makefile.in | 129 +- qw_client/cl_cam.c | 6 + qw_client/cl_demo.c | 3 + qw_client/cl_ents.c | 7 + qw_client/cl_input.c | 6 + qw_client/cl_main.c | 13 + qw_client/cl_parse.c | 9 +- qw_client/cl_pred.c | 5 + qw_client/cl_tent.c | 5 + qw_client/d_edge.c | 1 + qw_client/gl_model.c | 10 + qw_client/gl_ngraph.c | 4 + qw_client/gl_rlight.c | 4 + qw_client/gl_rpart.c | 1 + qw_client/gl_screen.c | 11 + qw_client/menu.c | 11 + qw_client/menu.h | 3 + qw_client/model.c | 3 + qw_client/r_edge.c | 2 + qw_client/r_efrag.c | 1 + qw_client/r_misc.c | 6 + qw_client/r_part.c | 4 + qw_client/r_sprite.c | 2 + qw_client/screen.c | 13 +- qw_client/view.c | 5 + qw_common/client.h | 20 +- qw_common/common.c | 1061 +-------------- qw_common/common.h | 62 +- qw_common/console.c | 8 + qw_common/cvar.h | 102 -- qw_common/net.h | 7 +- qw_common/net_chan.c | 5 + qw_common/net_udp.c | 4 + qw_common/pmove.c | 2 + qw_common/pmove.h | 2 + qw_common/pmovetst.c | 4 + qw_common/protocol.h | 17 - qw_server/Makefile.in | 2 +- qw_server/qwsvdef.h | 19 - qw_server/server.h | 4 +- uquake/cmd.c | 705 ---------- uquake/cmd.h | 121 -- uquake/common.c | 1203 +---------------- uquake/cvar.c | 225 ---- uquake/lib_replace.c | 319 +++++ uquake/quakefs.c | 840 ++++++++++++ 126 files changed, 3957 insertions(+), 6675 deletions(-) create mode 100644 common/Makefile.in create mode 100644 common/bspfile.h rename {qw_common => common}/cmd.c (99%) rename {qw_common => common}/cmd.h (100%) delete mode 100644 common/common.c delete mode 100644 common/common.h rename {qw_common => common}/cvar.c (97%) rename {uquake => common}/cvar.h (93%) delete mode 100644 common/glquake2.h create mode 100644 common/lib_replace.c create mode 100644 common/lib_replace.h create mode 100644 common/qargs.c create mode 100644 common/qargs.h create mode 100644 common/qdefs.h create mode 100644 common/qendian.c create mode 100644 common/qendian.h create mode 100644 common/qstructs.h create mode 100644 common/qtypes.h create mode 100644 common/quakefs.c create mode 100644 common/quakefs.h delete mode 100644 qw_common/cvar.h delete mode 100644 uquake/cmd.c delete mode 100644 uquake/cmd.h delete mode 100644 uquake/cvar.c create mode 100644 uquake/lib_replace.c create mode 100644 uquake/quakefs.c diff --git a/Makefile.in b/Makefile.in index d326840..0ec1542 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2,9 +2,9 @@ SRC_DIR = @srcdir@ HAVE_UDP = @HAVE_UDP@ ifeq ($(HAVE_UDP),yes) -SUBDIRS = qw_client qw_server uquake +SUBDIRS = common qw_client qw_server uquake else -SUBDIRS = uquake +SUBDIRS = common uquake endif DESTDIR = @@ -67,4 +67,8 @@ qw_server/Makefile: qw_server/Makefile.in configure uquake/Makefile: uquake/Makefile.in configure $(SHELL) ./config.status --recheck $(SHELL) ./config.status + +common/Makefile: common/Makefile.in configure + $(SHELL) ./config.status --recheck + $(SHELL) ./config.status endif diff --git a/acconfig.h b/acconfig.h index c709e0c..9ac55e5 100644 --- a/acconfig.h +++ b/acconfig.h @@ -40,3 +40,11 @@ /* Define this to use experimental code */ #undef _EXPERIMENTAL_ + +@BOTTOM@ + +#ifdef __i386__ +#define id386 1 +#else +#define id386 0 +#endif diff --git a/common/Makefile.in b/common/Makefile.in new file mode 100644 index 0000000..13ec84b --- /dev/null +++ b/common/Makefile.in @@ -0,0 +1,186 @@ +######################################################################## +# +# Quake general stuff +# + +PROJECT_DIR := @top_srcdir@ +PROJECT_ODIR := .. +SRC_DIR := @srcdir@ +COMMON_DIR := $(PROJECT_DIR)/common +COMMON_ODIR := $(PROJECT_ODIR)/common +BIN_PREFIX := common + +DESTDIR := + +prefix := @prefix@ +exec_prefix := @exec_prefix@ +bindir := @bindir@ +mandir := @mandir@ + +TARGET_DIR := $(PROJECT_ODIR)/targets +BUILD_DIR := $(TARGET_DIR)/common +OBJ_PATTERN := $(shell echo $(BUILD_DIR)/{sound,common}_lib/%.o) + +SOUND_LIB := sound_lib.a + +LDFLAGS = @LDFLAGS@ -lm +LIBS = @LIBS@ +CC = @CC@ +INTEL_ARCH = @INTEL_ARCH@ + +ifneq ($(SRC_DIR),.) +SRC_DIR_INC = -I$(SRC_DIR) +endif + +HAS_MGL = @HAS_MGL@ +HAS_GGI = @HAS_GGI@ +HAS_SVGA = @HAS_SVGA@ +HAS_GLIDE = @HAS_GLIDE@ +HAS_TDFXGL = @HAS_TDFXGL@ +HAS_OGL = @HAS_OGL@ +HAS_XIL = @HAS_XIL@ +HAS_X11 = @HAS_X11@ +HAS_SDL = @HAS_SDL@ + +MAKE_SURE_DIR = if test -d "$(BUILD_DIR)/$$DIR"; \ + then \ + true; \ + else \ + echo "Creating directory $(BUILD_DIR)/$$DIR"; \ + mkdir -p $(BUILD_DIR)/$$DIR; \ + fi + + + +RELEASE = @RELEASE@ +ifeq ($(RELEASE),yes) +OPTFLAGS = @RELEASE_CFLAGS@ +else +OPTFLAGS = -g +endif + +lib_targets = $(SOUND_LIB) $(CD_LIB) $(COMMON_LIB) +targets = $(lib_targets) +CLEAN_TARGETS = $(patsubst %,clean-%, $(targets)) +.PHONY: $(targets) $(CLEAN_TARGETS) + +all: $(targets) +######################################################################## +# +# Source files +# + +ifeq ($(INTEL_ARCH),yes) + +# Source file the Intel archictecture only + +SOUND_SRC += snd_mixa.s +else + +# Source files for non-Intel platforms +endif + +# System specific source files + +CD_AUDIO_SRC = cd_wrapper.c + +# Sound source + +SOUND_STYLE = @SOUND_STYLE@ + +ifeq ($(SOUND_STYLE),ALSA) +SOUND_SRC += snd_dma.c snd_alsa.c +endif +ifeq ($(SOUND_STYLE),OSS) +SOUND_SRC += snd_dma.c snd_oss.c +endif +ifeq ($(SOUND_STYLE),Solaris) +SOUND_SRC += snd_dma.c snd_sun.c +endif +ifeq ($(SOUND_STYLE),MME) +SOUND_SRC += snd_dma.c snd_mme.c +endif +ifeq ($(SOUND_STYLE),Windows) +SOUND_SRC += snd_dma.c snd_win.c +endif +ifeq ($(SOUND_STYLE),NULL) +SOUND_SRC += snd_null.c +endif + +SOUND_SRC += snd_mem.c snd_mix.c + +# Networking source files +# +# Uncomment the second line to add IPv6 support + +QW_NET_SRC = net_udp.c net_com.c mdfour.c +#QW_NET_SRC = net_udp6.c net_com.c mdfour.c + + +######################################################################## +# +# Directory specific stuff +# +DEFS = @DEFS@ +CFLAGS = @CFLAGS@ $(OPTFLAGS) $(DEFS) -I. \ +$(SRC_DIR_INC) -I$(COMMON_ODIR) -I$(COMMON_DIR) + + +########################################################################### +# +# Compilation rules +# + +$(OBJ_PATTERN): $(SRC_DIR)/%.c + $(CC) $(CFLAGS) -o $@ -c $< + +$(OBJ_PATTERN): $(SRC_DIR)/%.s + $(CC) $(CFLAGS) -x assembler-with-cpp -o $@ -c $< + +########################################################################### +# +# Specific target rules +# + +# Lib Software targets + +SOUND_LIB_OBJS = $(patsubst %,$(BUILD_DIR)/sound_lib/%,$(addsuffix \ + .@OBJEXT@, $(basename $(SOUND_SRC) .c .s))) + +sound_lib_DIR: + @DIR=sound_lib; $(MAKE_SURE_DIR) + +$(SOUND_LIB): sound_lib_DIR $(TARGET_DIR)/sound_lib.a + +$(TARGET_DIR)/sound_lib.a: $(SOUND_LIB_OBJS) + #gcc -Wall -shared -o $@ $(SOUND_LIB_OBJS) + ar cru $@ $(SOUND_LIB_OBJS) + ranlib $@ + + +########################################################################### +# +# Misc targets +# + +distclean: clean + rm -f Makefile + +$(CLEAN_TARGETS): + rm -f $(BUILD_DIR)/../$(subst clean-,,$@) + +clean-sound_lib: + rm -rf $(BUILD_DIR)/$(subst clean-,,$@) + +clean: clean-sound_lib $(CLEAN_TARGETS) + -rmdir $(BUILD_DIR) + +install: $(targets) + $(PROJECT_DIR)/mkinstalldirs $(DESTDIR)/$(bindir) + for i in $(targets); do \ + $(PROJECT_DIR)/install-sh -m 755 $(BUILD_DIR)/../$$i \ + $(DESTDIR)/$(bindir)/$$i; \ + done + +check: + @echo check not implemented diff --git a/common/bspfile.h b/common/bspfile.h new file mode 100644 index 0000000..577877f --- /dev/null +++ b/common/bspfile.h @@ -0,0 +1,284 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. +Copyright (C) 1999,2000 contributors of the QuakeForge project +Please see the file "AUTHORS" for a list of contributors + +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. + +*/ + +#ifndef _BSPFILE_H +#define _BSPFILE_H + +// upper design bounds + +#define MAX_MAP_HULLS 4 + +#define MAX_MAP_MODELS 256 +#define MAX_MAP_BRUSHES 4096 +#define MAX_MAP_ENTITIES 1024 +#define MAX_MAP_ENTSTRING 65536 + +#define MAX_MAP_PLANES 8192 +#define MAX_MAP_NODES 32767 // because negative shorts are contents +#define MAX_MAP_CLIPNODES 32767 // +#define MAX_MAP_LEAFS 32767 // +#define MAX_MAP_VERTS 65535 +#define MAX_MAP_FACES 65535 +#define MAX_MAP_MARKSURFACES 65535 +#define MAX_MAP_TEXINFO 4096 +#define MAX_MAP_EDGES 256000 +#define MAX_MAP_SURFEDGES 512000 +#define MAX_MAP_MIPTEX 0x200000 +#define MAX_MAP_LIGHTING 0x100000 +#define MAX_MAP_VISIBILITY 0x100000 + +// key / value pair sizes + +#define MAX_KEY 32 +#define MAX_VALUE 1024 + + +//============================================================================= + + +#define BSPVERSION 29 + +typedef struct +{ + int fileofs, filelen; +} lump_t; + +#define LUMP_ENTITIES 0 +#define LUMP_PLANES 1 +#define LUMP_TEXTURES 2 +#define LUMP_VERTEXES 3 +#define LUMP_VISIBILITY 4 +#define LUMP_NODES 5 +#define LUMP_TEXINFO 6 +#define LUMP_FACES 7 +#define LUMP_LIGHTING 8 +#define LUMP_CLIPNODES 9 +#define LUMP_LEAFS 10 +#define LUMP_MARKSURFACES 11 +#define LUMP_EDGES 12 +#define LUMP_SURFEDGES 13 +#define LUMP_MODELS 14 + +#define HEADER_LUMPS 15 + +typedef struct +{ + float mins[3], maxs[3]; + float origin[3]; + int headnode[MAX_MAP_HULLS]; + int visleafs; // not including the solid leaf 0 + int firstface, numfaces; +} dmodel_t; + +typedef struct +{ + int version; + lump_t lumps[HEADER_LUMPS]; +} dheader_t; + +typedef struct +{ + int nummiptex; + int dataofs[4]; // [nummiptex] +} dmiptexlump_t; + +#define MIPLEVELS 4 +typedef struct miptex_s +{ + char name[16]; + unsigned width, height; + unsigned offsets[MIPLEVELS]; // four mip maps stored +} miptex_t; + + +typedef struct +{ + float point[3]; +} dvertex_t; + + +// 0-2 are axial planes +#define PLANE_X 0 +#define PLANE_Y 1 +#define PLANE_Z 2 + +// 3-5 are non-axial planes snapped to the nearest +#define PLANE_ANYX 3 +#define PLANE_ANYY 4 +#define PLANE_ANYZ 5 + +typedef struct +{ + float normal[3]; + float dist; + int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate +} dplane_t; + + + +#define CONTENTS_EMPTY -1 +#define CONTENTS_SOLID -2 +#define CONTENTS_WATER -3 +#define CONTENTS_SLIME -4 +#define CONTENTS_LAVA -5 +#define CONTENTS_SKY -6 +#define CONTENTS_CURRENT_0 -9 +#define CONTENTS_CURRENT_90 -10 +#define CONTENTS_CURRENT_180 -11 +#define CONTENTS_CURRENT_270 -12 +#define CONTENTS_CURRENT_UP -13 +#define CONTENTS_CURRENT_DOWN -14 + + +// !!! if this is changed, it must be changed in asm_i386.h too !!! +typedef struct +{ + int planenum; + short children[2]; // negative numbers are -(leafs+1), not nodes + short mins[3]; // for sphere culling + short maxs[3]; + unsigned short firstface; + unsigned short numfaces; // counting both sides +} dnode_t; + +typedef struct +{ + int planenum; + short children[2]; // negative numbers are contents +} dclipnode_t; + + +typedef struct texinfo_s +{ + float vecs[2][4]; // [s/t][xyz offset] + int miptex; + int flags; +} texinfo_t; +#define TEX_SPECIAL 1 // sky or slime, no lightmap or 256 subdivision + +// note that edge 0 is never used, because negative edge nums are used for +// counterclockwise use of the edge in a face +typedef struct +{ + unsigned short v[2]; // vertex numbers +} dedge_t; + +#define MAXLIGHTMAPS 4 +typedef struct +{ + short planenum; + short side; + + int firstedge; // we must support > 64k edges + short numedges; + short texinfo; + +// lighting info + byte styles[MAXLIGHTMAPS]; + int lightofs; // start of [numstyles*surfsize] samples +} dface_t; + + + +#define AMBIENT_WATER 0 +#define AMBIENT_SKY 1 +#define AMBIENT_SLIME 2 +#define AMBIENT_LAVA 3 + +#define NUM_AMBIENTS 4 // automatic ambient sounds + +// leaf 0 is the generic CONTENTS_SOLID leaf, used for all solid areas +// all other leafs need visibility info +typedef struct +{ + int contents; + int visofs; // -1 = no visibility info + + short mins[3]; // for frustum culling + short maxs[3]; + + unsigned short firstmarksurface; + unsigned short nummarksurfaces; + + byte ambient_level[NUM_AMBIENTS]; +} dleaf_t; + +//============================================================================ + +#ifndef QUAKE_GAME + +// the utilities get to be lazy and just use large static arrays + +extern int nummodels; +extern dmodel_t dmodels[MAX_MAP_MODELS]; + +extern int visdatasize; +extern byte dvisdata[MAX_MAP_VISIBILITY]; + +extern int lightdatasize; +extern byte dlightdata[MAX_MAP_LIGHTING]; + +extern int texdatasize; +extern byte dtexdata[MAX_MAP_MIPTEX]; // (dmiptexlump_t) + +extern int entdatasize; +extern char dentdata[MAX_MAP_ENTSTRING]; + +extern int numleafs; +extern dleaf_t dleafs[MAX_MAP_LEAFS]; + +extern int numplanes; +extern dplane_t dplanes[MAX_MAP_PLANES]; + +extern int numvertexes; +extern dvertex_t dvertexes[MAX_MAP_VERTS]; + +extern int numnodes; +extern dnode_t dnodes[MAX_MAP_NODES]; + +extern int numtexinfo; +extern texinfo_t texinfo[MAX_MAP_TEXINFO]; + +extern int numfaces; +extern dface_t dfaces[MAX_MAP_FACES]; + +extern int numclipnodes; +extern dclipnode_t dclipnodes[MAX_MAP_CLIPNODES]; + +extern int numedges; +extern dedge_t dedges[MAX_MAP_EDGES]; + +extern int nummarksurfaces; +extern unsigned short dmarksurfaces[MAX_MAP_MARKSURFACES]; + +extern int numsurfedges; +extern int dsurfedges[MAX_MAP_SURFEDGES]; + + + +void LoadBSPFile (char *filename); +void WriteBSPFile (char *filename); +void PrintBSPFileSizes (void); + +#endif + +#endif // _BSPFILE_H diff --git a/common/cd_linux.c b/common/cd_linux.c index e6c200d..6b1942e 100644 --- a/common/cd_linux.c +++ b/common/cd_linux.c @@ -22,7 +22,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Quake is a trademark of Id Software, Inc., (c) 1996 Id Software, Inc. All // rights reserved. +#include "qtypes.h" #include "quakedef.h" +#include "console.h" +#include "cdaudio.h" +#include "common.h" +#include "sound.h" +#include "cmd.h" +#include "cvar.h" #include #ifdef HAVE_UNISTD_H @@ -44,6 +51,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # include #endif + static qboolean cdValid = false; static qboolean playing = false; static qboolean wasPlaying = false; diff --git a/qw_common/cmd.c b/common/cmd.c similarity index 99% rename from qw_common/cmd.c rename to common/cmd.c index 2805a4c..2762c1e 100644 --- a/qw_common/cmd.c +++ b/common/cmd.c @@ -22,6 +22,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // cmd.c -- Quake script command processing module #include "quakedef.h" +#include "common.h" +#include "cmd.h" +#include "console.h" +#include "cvar.h" +#include "sys.h" +#include "client.h" void Cmd_ForwardToServer (void); diff --git a/qw_common/cmd.h b/common/cmd.h similarity index 100% rename from qw_common/cmd.h rename to common/cmd.h diff --git a/common/common.c b/common/common.c deleted file mode 100644 index 42d1970..0000000 --- a/common/common.c +++ /dev/null @@ -1,2470 +0,0 @@ -/* -Copyright (C) 1996-1997 Id Software, Inc. -Portions Copyright (C) 1999,2000 Nelson Rush. -Copyright (C) 1999,2000 contributors of the QuakeForge project -Please see the file "AUTHORS" for a list of contributors - -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. - -*/ -// common.c -- misc functions used in client and server - -#include - -#ifdef SERVERONLY -#include "qwsvdef.h" -#else -#include "quakedef.h" -#endif -#include - - -/* Begin Generations */ -#ifdef _EXPERIMENTAL_ -#include "unzip.h" -#endif - -typedef unsigned char byte_t; - -#ifndef _AIX -typedef unsigned int uint_t; -typedef unsigned short ushort_t; -#endif -/* End Generations */ - -#define MAX_NUM_ARGVS 50 -#define NUM_SAFE_ARGVS 7 - -usercmd_t nullcmd; // guarenteed to be zero -static char *largv[MAX_NUM_ARGVS + NUM_SAFE_ARGVS + 1]; -static char *argvdummy = " "; - -static char *safeargvs[NUM_SAFE_ARGVS] = - {"-stdvid", "-nolan", "-nosound", "-nocdaudio", "-nojoy", "-nomouse", "-dibonly"}; - -cvar_t cmdline = {"cmdline","0", false, true}; - -qboolean com_modified; // set true if using non-id files - -qboolean proghack; - -qboolean msg_suppress_1 = 0; - -void COM_InitFilesystem (void); -void COM_Path_f (void); - - -// if a packfile directory differs from this, it is assumed to be hacked -#ifdef QUAKEWORLD -#define PAK0_COUNT 339 -#define PAK0_CRC 52883 -#else -#define PAK0_COUNT 339 -#define PAK0_CRC 32981 -#endif - -char com_token[1024]; -int com_argc; -char **com_argv; - -char gamedirfile[MAX_OSPATH]; -#define CMDLINE_LENGTH 256 -char com_cmdline[CMDLINE_LENGTH]; - -qboolean standard_quake = true, rogue, hipnotic; - -extern cvar_t developer; - -/* - - -All of Quake's data access is through a hierchal file system, but the contents of the file system can be transparently merged from several sources. - -The "base directory" is the path to the directory holding the quake.exe and all game directories. The sys_* files pass this to host_init in quakeparms_t->basedir. This can be overridden with the "-basedir" command line parm to allow code debugging in a different directory. The base directory is -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. - -*/ - -//============================================================================ - - -// ClearLink is used for new headnodes -void ClearLink (link_t *l) -{ - l->prev = l->next = l; -} - -void RemoveLink (link_t *l) -{ - l->next->prev = l->prev; - l->prev->next = l->next; -} - -void InsertLinkBefore (link_t *l, link_t *before) -{ - l->next = before; - l->prev = before->prev; - l->prev->next = l; - l->next->prev = l; -} -void InsertLinkAfter (link_t *l, link_t *after) -{ - l->next = after->next; - l->prev = after; - l->prev->next = l; - l->next->prev = l; -} - -/* -============================================================================ - - LIBRARY REPLACEMENT FUNCTIONS - -============================================================================ -*/ - -#if 0 -void Q_memset (void *dest, int fill, int count) -{ - int i; - - if ( (((long)dest | count) & 3) == 0) - { - count >>= 2; - fill = fill | (fill<<8) | (fill<<16) | (fill<<24); - for (i=0 ; i>=2; - for (i=0 ; i= 'a' && c1 <= 'z') - c1 -= ('a' - 'A'); - if (c2 >= 'a' && c2 <= 'z') - c2 -= ('a' - 'A'); - if (c1 != c2) - return -1; // strings not equal - } - if (!c1) - return 0; // strings are equal -// s1++; -// s2++; - } - - return -1; -} - -int Q_strcasecmp (char *s1, char *s2) -{ - return Q_strncasecmp (s1, s2, 99999); -} - -#endif - -int Q_atoi (char *str) -{ - int val; - int sign; - int c; - - if (*str == '-') - { - sign = -1; - str++; - } - else - sign = 1; - - val = 0; - -// -// check for hex -// - if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') ) - { - str += 2; - while (1) - { - c = *str++; - if (c >= '0' && c <= '9') - val = (val<<4) + c - '0'; - else if (c >= 'a' && c <= 'f') - val = (val<<4) + c - 'a' + 10; - else if (c >= 'A' && c <= 'F') - val = (val<<4) + c - 'A' + 10; - else - return val*sign; - } - } - -// -// check for character -// - if (str[0] == '\'') - { - return sign * str[1]; - } - -// -// assume decimal -// - while (1) - { - c = *str++; - if (c <'0' || c > '9') - return val*sign; - val = val*10 + c - '0'; - } - - return 0; -} - - -float Q_atof (char *str) -{ - double val; - int sign; - int c; - int decimal, total; - - if (*str == '-') - { - sign = -1; - str++; - } - else - sign = 1; - - val = 0; - -// -// check for hex -// - if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') ) - { - str += 2; - while (1) - { - c = *str++; - if (c >= '0' && c <= '9') - val = (val*16) + c - '0'; - else if (c >= 'a' && c <= 'f') - val = (val*16) + c - 'a' + 10; - else if (c >= 'A' && c <= 'F') - val = (val*16) + c - 'A' + 10; - else - return val*sign; - } - } - -// -// check for character -// - if (str[0] == '\'') - { - return sign * str[1]; - } - -// -// assume decimal -// - decimal = -1; - total = 0; - while (1) - { - c = *str++; - if (c == '.') - { - decimal = total; - continue; - } - if (c <'0' || c > '9') - break; - val = val*10 + c - '0'; - total++; - } - - if (decimal == -1) - return val*sign; - while (total > decimal) - { - val /= 10; - total--; - } - - return val*sign; -} - -/* -============================================================================ - - BYTE ORDER FUNCTIONS - -============================================================================ -*/ - -short (*BigShort) (short l); -short (*LittleShort) (short l); -int (*BigLong) (int l); -int (*LittleLong) (int l); -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; -} - -/* -============================================================================== - - MESSAGE IO FUNCTIONS - -Handles byte ordering and avoids alignment errors -============================================================================== -*/ - -// -// writing functions -// - -void MSG_WriteChar (sizebuf_t *sb, int c) -{ - byte *buf; - -#ifdef PARANOID - if (c < -128 || c > 127) - Sys_Error ("MSG_WriteChar: range error"); -#endif - - buf = SZ_GetSpace (sb, 1); - buf[0] = c; -} - -void MSG_WriteByte (sizebuf_t *sb, int c) -{ - byte *buf; - -#ifdef PARANOID - if (c < 0 || c > 255) - Sys_Error ("MSG_WriteByte: range error"); -#endif - - buf = SZ_GetSpace (sb, 1); - buf[0] = c; -} - -void MSG_WriteShort (sizebuf_t *sb, int c) -{ - byte *buf; - -#ifdef PARANOID - if (c < ((short)0x8000) || c > (short)0x7fff) - Sys_Error ("MSG_WriteShort: range error"); -#endif - - buf = SZ_GetSpace (sb, 2); - buf[0] = c&0xff; - buf[1] = c>>8; -} - -void MSG_WriteLong (sizebuf_t *sb, int c) -{ - byte *buf; - - buf = SZ_GetSpace (sb, 4); - buf[0] = c&0xff; - buf[1] = (c>>8)&0xff; - buf[2] = (c>>16)&0xff; - buf[3] = c>>24; -} - -void MSG_WriteFloat (sizebuf_t *sb, float f) -{ - union - { - float f; - int l; - } dat; - - - dat.f = f; - dat.l = LittleLong (dat.l); - - SZ_Write (sb, &dat.l, 4); -} - -void MSG_WriteString (sizebuf_t *sb, char *s) -{ - if (!s) - SZ_Write (sb, "", 1); - else - SZ_Write (sb, s, Q_strlen(s)+1); -} - -void MSG_WriteCoord (sizebuf_t *sb, float f) -{ - MSG_WriteShort (sb, (int)(f*8)); -} - -void MSG_WriteAngle (sizebuf_t *sb, float f) -{ - MSG_WriteByte (sb, (int)(f*256/360) & 255); -} - -void MSG_WriteAngle16 (sizebuf_t *sb, float f) -{ - MSG_WriteShort (sb, (int)(f*65536/360) & 65535); -} - -void MSG_WriteDeltaUsercmd (sizebuf_t *buf, usercmd_t *from, usercmd_t *cmd) -{ - int bits; - -// -// send the movement message -// - bits = 0; - if (cmd->angles[0] != from->angles[0]) - bits |= CM_ANGLE1; - if (cmd->angles[1] != from->angles[1]) - bits |= CM_ANGLE2; - if (cmd->angles[2] != from->angles[2]) - bits |= CM_ANGLE3; - if (cmd->forwardmove != from->forwardmove) - bits |= CM_FORWARD; - if (cmd->sidemove != from->sidemove) - bits |= CM_SIDE; - if (cmd->upmove != from->upmove) - bits |= CM_UP; - if (cmd->buttons != from->buttons) - bits |= CM_BUTTONS; - if (cmd->impulse != from->impulse) - bits |= CM_IMPULSE; - - MSG_WriteByte (buf, bits); - - if (bits & CM_ANGLE1) - MSG_WriteAngle16 (buf, cmd->angles[0]); - if (bits & CM_ANGLE2) - MSG_WriteAngle16 (buf, cmd->angles[1]); - if (bits & CM_ANGLE3) - MSG_WriteAngle16 (buf, cmd->angles[2]); - - if (bits & CM_FORWARD) - MSG_WriteShort (buf, cmd->forwardmove); - if (bits & CM_SIDE) - MSG_WriteShort (buf, cmd->sidemove); - if (bits & CM_UP) - MSG_WriteShort (buf, cmd->upmove); - - if (bits & CM_BUTTONS) - MSG_WriteByte (buf, cmd->buttons); - if (bits & CM_IMPULSE) - MSG_WriteByte (buf, cmd->impulse); - MSG_WriteByte (buf, cmd->msec); -} - -// -// reading functions -// -int msg_readcount; -qboolean msg_badread; - -void MSG_BeginReading (void) -{ - msg_readcount = 0; - msg_badread = false; -} - -int MSG_GetReadCount(void) -{ - return msg_readcount; -} - -// returns -1 and sets msg_badread if no more characters are available -int MSG_ReadChar (void) -{ - int c; - - if (msg_readcount+1 > net_message.cursize) - { - msg_badread = true; - return -1; - } - - c = (signed char)net_message.data[msg_readcount]; - msg_readcount++; - - return c; -} - -int MSG_ReadByte (void) -{ - int c; - - if (msg_readcount+1 > net_message.cursize) - { - msg_badread = true; - return -1; - } - - c = (unsigned char)net_message.data[msg_readcount]; - msg_readcount++; - - return c; -} - -int MSG_ReadShort (void) -{ - int c; - - if (msg_readcount+2 > net_message.cursize) - { - msg_badread = true; - return -1; - } - - c = (short)(net_message.data[msg_readcount] - + (net_message.data[msg_readcount+1]<<8)); - - msg_readcount += 2; - - return c; -} - -int MSG_ReadLong (void) -{ - int c; - - if (msg_readcount+4 > net_message.cursize) - { - msg_badread = true; - return -1; - } - - c = net_message.data[msg_readcount] - + (net_message.data[msg_readcount+1]<<8) - + (net_message.data[msg_readcount+2]<<16) - + (net_message.data[msg_readcount+3]<<24); - - msg_readcount += 4; - - return c; -} - -float MSG_ReadFloat (void) -{ - union - { - byte b[4]; - float f; - int l; - } dat; - - dat.b[0] = net_message.data[msg_readcount]; - dat.b[1] = net_message.data[msg_readcount+1]; - dat.b[2] = net_message.data[msg_readcount+2]; - dat.b[3] = net_message.data[msg_readcount+3]; - msg_readcount += 4; - - dat.l = LittleLong (dat.l); - - return dat.f; -} - -char *MSG_ReadString (void) -{ - static char string[2048]; - int l,c; - - l = 0; - do - { - c = MSG_ReadChar (); - if (c == -1 || c == 0) - break; - string[l] = c; - l++; - } while (l < sizeof(string)-1); - - string[l] = 0; - - return string; -} - -char *MSG_ReadStringLine (void) -{ - static char string[2048]; - int l,c; - - l = 0; - do - { - c = MSG_ReadChar (); - if (c == -1 || c == 0 || c == '\n') - break; - string[l] = c; - l++; - } while (l < sizeof(string)-1); - - string[l] = 0; - - return string; -} - -float MSG_ReadCoord (void) -{ - return MSG_ReadShort() * (1.0/8); -} - -float MSG_ReadAngle (void) -{ - return MSG_ReadChar() * (360.0/256); -} - -float MSG_ReadAngle16 (void) -{ - return MSG_ReadShort() * (360.0/65536); -} - -void MSG_ReadDeltaUsercmd (usercmd_t *from, usercmd_t *move) -{ - int bits; - - memcpy (move, from, sizeof(*move)); - - bits = MSG_ReadByte (); - -// read current angles - if (bits & CM_ANGLE1) - move->angles[0] = MSG_ReadAngle16 (); - if (bits & CM_ANGLE2) - move->angles[1] = MSG_ReadAngle16 (); - if (bits & CM_ANGLE3) - move->angles[2] = MSG_ReadAngle16 (); - -// read movement - if (bits & CM_FORWARD) - move->forwardmove = MSG_ReadShort (); - if (bits & CM_SIDE) - move->sidemove = MSG_ReadShort (); - if (bits & CM_UP) - move->upmove = MSG_ReadShort (); - -// read buttons - if (bits & CM_BUTTONS) - move->buttons = MSG_ReadByte (); - - if (bits & CM_IMPULSE) - move->impulse = MSG_ReadByte (); - -// read time to run command - move->msec = MSG_ReadByte (); -} - - -//=========================================================================== - -void SZ_Alloc (sizebuf_t *buf, int startsize) -{ - if (startsize < 256) - startsize = 256; - buf->data = Hunk_AllocName (startsize, "sizebuf"); - buf->maxsize = startsize; - buf->cursize = 0; -} - - -void SZ_Free (sizebuf_t *buf) -{ -// Z_Free (buf->data); -// buf->data = NULL; -// buf->maxsize = 0; - buf->cursize = 0; -} - -void SZ_Clear (sizebuf_t *buf) -{ - buf->cursize = 0; - buf->overflowed = false; -} - -void *SZ_GetSpace (sizebuf_t *buf, int length) -{ - void *data; - - if (buf->cursize + length > buf->maxsize) - { - if (!buf->allowoverflow) - Sys_Error ("SZ_GetSpace: overflow without allowoverflow set (%d)", buf->maxsize); - - if (length > buf->maxsize) - Sys_Error ("SZ_GetSpace: %i is > full buffer size", length); - - Sys_Printf ("SZ_GetSpace: overflow\n"); // because Con_Printf may be redirected - SZ_Clear (buf); - buf->overflowed = true; - } - - data = buf->data + buf->cursize; - buf->cursize += length; - - return data; -} - -void SZ_Write (sizebuf_t *buf, void *data, int length) -{ - Q_memcpy (SZ_GetSpace(buf,length),data,length); -} - -void SZ_Print (sizebuf_t *buf, char *data) -{ - int len; - - len = Q_strlen(data)+1; - - if (!buf->cursize || buf->data[buf->cursize-1]) - Q_memcpy ((byte *)SZ_GetSpace(buf, len),data,len); // no trailing 0 - else - Q_memcpy ((byte *)SZ_GetSpace(buf, len-1)-1,data,len); // write over trailing 0 -} - - -//============================================================================ - - -/* -============ -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); -} - -//============================================================================ - -char com_token[1024]; -int com_argc; -char **com_argv; - - -/* -============== -COM_Parse - -Parse a token out of a string -============== -*/ -char *COM_Parse (char *data) -{ - int c; - int len; - - len = 0; - com_token[0] = 0; - - if (!data) - return NULL; - -// skip whitespace -skipwhite: - while ( (c = *data) <= ' ') - { - if (c == 0) - return NULL; // end of file; - data++; - } - -// skip // comments - if (c=='/' && data[1] == '/') - { - while (*data && *data != '\n') - data++; - goto skipwhite; - } - - -// handle quoted strings specially - if (c == '\"') - { - data++; - while (1) - { - c = *data++; - if (c=='\"' || !c) - { - com_token[len] = 0; - return data; - } - com_token[len] = c; - len++; - } - } - -// parse single characters - if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':') - { - com_token[len] = c; - len++; - com_token[len] = 0; - return data+1; - } - -// parse a regular word - do - { - com_token[len] = c; - data++; - len++; - c = *data; - if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':') - break; - } while (c>32); - - com_token[len] = 0; - return data; -} - - -/* -================ -COM_CheckParm - -Returns the position (1 to argc-1) in the program's argument list -where the given parameter apears, or 0 if not present -================ -*/ -int COM_CheckParm (char *parm) -{ - int i; - - for (i=1 ; inext) - { - if (s == com_base_searchpaths) - Con_Printf ("----------\n"); - if (s->pack) - Con_Printf ("%s (%i files)\n", s->pack->filename, s->pack->numfiles); - else - Con_Printf ("%s\n", s->filename); - } -} - -/* -============ -COM_WriteFile - -The filename will be prefixed by the current game directory -============ -*/ -void COM_WriteFile (char *filename, void *data, int len) -{ - FILE *f; - char name[MAX_OSPATH]; - - snprintf(name, sizeof(name), "%s/%s", com_gamedir, filename); - - f = fopen (name, "wb"); - if (!f) { - Sys_mkdir(com_gamedir); - f = fopen (name, "wb"); - if (!f) - Sys_Error ("Error opening %s", filename); - } - - Sys_Printf ("COM_WriteFile: %s\n", name); - fwrite (data, 1, len, f); - fclose (f); -} - - -/* -============ -COM_CreatePath - -Only used for CopyFile and download -============ -*/ -void COM_CreatePath (char *path) -{ - char *ofs; - - for (ofs = path+1 ; *ofs ; ofs++) - { - if (*ofs == '/') - { // create the directory - *ofs = 0; - Sys_mkdir (path); - *ofs = '/'; - } - } -} - - -/* -=========== -COM_CopyFile - -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) -{ - FILE *in, *out; - int remaining, count; - char buf[4096]; - - remaining = COM_FileOpenRead (netpath, &in); - COM_CreatePath (cachepath); // create directories up to the cache file - out = fopen(cachepath, "wb"); - if (!out) - Sys_Error ("Error opening %s", cachepath); - - while (remaining) - { - if (remaining < sizeof(buf)) - count = remaining; - else - count = sizeof(buf); - fread (buf, 1, count, in); - fwrite (buf, 1, count, out); - remaining -= count; - } - - fclose (in); - fclose (out); -} - -/* -=========== -COM_FindFile - -Finds the file in the search path. -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, FILE **file) -{ - searchpath_t *search; - char netpath[MAX_OSPATH]; - pack_t *pak; - int i; - int findtime; - - file_from_pak = 0; - -// -// 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")) - search = search->next; - } - - for (search = com_searchpaths ; 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 ; inumfiles ; i++) - if (!strcmp (pak->files[i].name, filename)) - { // found it! - if(developer.value) - Sys_Printf ("PackFile: %s : %s\n",pak->filename, filename); - // open a new file on the pakfile - *file = fopen (pak->filename, "rb"); - if (!*file) - Sys_Error ("Couldn't reopen %s", pak->filename); - fseek (*file, pak->files[i].filepos, SEEK_SET); - com_filesize = pak->files[i].filelen; - file_from_pak = 1; - return com_filesize; - } - } - else - { - // check a file in the directory tree - snprintf(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 - { -#if defined(_WIN32) - if ((strlen(netpath) < 2) || (netpath[1] != ':')) - snprintf(cachepath, sizeof(cachepath),"%s%s", com_cachedir, netpath); - else - snprintf(cachepath, sizeof(cachepath),"%s%s", com_cachedir, netpath+2); -#else - snprintf(cachepath, sizeof(cachepath),"%s%s", com_cachedir, netpath); -#endif - - cachetime = Sys_FileTime (cachepath); - - if (cachetime < findtime) - COM_CopyFile (netpath, cachepath); - strcpy (netpath, cachepath); - } - - if(developer.value) - Sys_Printf ("FindFile: %s\n",netpath); - - *file = fopen (netpath, "rb"); - return COM_filelength (*file); - } - - } - - Sys_Printf ("FindFile: can't find %s\n", filename); - - *file = NULL; - com_filesize = -1; - return -1; -} - -/* -============ -COM_LoadFile - -Filename are reletive to the quake directory. -Allways appends a 0 byte to the loaded data. -============ -*/ -cache_user_t *loadcache; -byte *loadbuf; -int loadsize; -byte *COM_LoadFile (char *path, int usehunk) -{ - FILE *h; - byte *buf; - char base[32]; - int len; - - buf = NULL; // quiet compiler warning - -// look for it in the filesystem or pack files - len = com_filesize = COM_FOpenFile (path, &h); - if (!h) - return NULL; - -// 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; -#ifndef SERVERONLY - Draw_BeginDisc (); -#endif - fread (buf, 1, len, h); - fclose (h); -#ifndef SERVERONLY - Draw_EndDisc (); -#endif - - 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; - FILE *packhandle; - dpackfile_t info[MAX_FILES_IN_PACK]; - unsigned short crc; - - if (COM_FileOpenRead (packfile, &packhandle) == -1) - return NULL; - - fread (&header, 1, sizeof(header), packhandle); - 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 %i files", packfile, numpackfiles); - - if (numpackfiles != PAK0_COUNT) - com_modified = true; // not the original file - -<<<<<<<<<<<<<< variant A - newfiles = Z_Malloc (numpackfiles * sizeof(packfile_t)); ->>>>>>>>>>>>>> variant B - newfiles = Hunk_AllocName (numpackfiles * sizeof(packfile_t), "packfile"); -======= end of combination - - fseek (packhandle, header.dirofs, SEEK_SET); - fread (info, 1, header.dirlen, packhandle); - -// crc the directory to check for modifications - crc = CRC_Block((byte *)info, header.dirlen); - - if (crc != PAK0_CRC) - com_modified = true; - -// parse the directory - for (i=0 ; i>>>>>>>>>>>>> variant B - pack = Hunk_Alloc (sizeof (pack_t)); -======= end of combination - strcpy (pack->filename, packfile); - pack->handle = packhandle; - pack->numfiles = numpackfiles; - pack->files = newfiles; - - Con_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles); - return pack; -} - -// Todo: Make This work! :) -#if defined _EXPERIMENTAL_ && GENERATIONS -int -COM_pak3_checkfile(unzFile *pak, const char *path) -{ - int status; - - status = unzLocateFile(pak, path, 2); - return (status == UNZ_OK); -} - -void -COM_pak3_closepak(unzFile *pak) -{ - if (pak) - unzClose(pak); - pak = NULL; -} - -void -COM_pak3_close(unzFile *pak) -{ - unzCloseCurrentFile(pak); -} - - - -int -COM_pak3_read(unzFile *pak, void *buf, uint_t size, uint_t nmemb) -{ - int len; - - len = unzReadCurrentFile(pak, buf, size * nmemb); - return len / size; -} - -int -COM_pak3_open(unzFile *pak, const char *path) -{ - if (unzLocateFile(pak, path, 2) != UNZ_OK) - return 0; - if (unzOpenCurrentFile(pak) != UNZ_OK) - return 0; - return 1; -} - -uint_t -COM_pak3_getlen(unzFile *pak) -{ - unz_file_info info; - - if (unzGetCurrentFileInfo(pak, &info, NULL, 0, NULL, 0, NULL, 0) - != UNZ_OK) - return 0; - return info.uncompressed_size; -} - -uint_t -COM_pak3_readfile(unzFile *pak, const char *path, uint_t bufsize, byte_t *buf) -{ - uint_t len; - - if (!COM_pak3_open(pak,path)) - return 0; - - if ((len = COM_pak3_getlen(pak)) != 0) - { - if (COM_pak3_read(pak, (void*)buf, 1, len) != len) - len = 0; - } - COM_pak3_close(pak); - return len; -} - - -pack_t *COM_LoadQ3PackFile (char *packfile) -{ - - int i; - packfile_t *newfiles; - float numpackfiles; - unzFile *pak; - pack_t *pack_old; - int status; -// int packhandle; - dpackfile_t info[MAX_FILES_IN_PACK]; -// unz_file_info fileInfo; - char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; -// int err; - - pak = unzOpen(packfile); - -// numpackfiles = header.dirlen / sizeof(dpackfile_t); -// numpackfiles = COM_pak3_getlen(*pak)/sizeof(unzFile); - numpackfiles = 0; -//= COM_pak3_getlen(pak)/sizeof(unzFile); - Con_Printf ("Assigned Numpackfiles\n"); - - if (!pak) - return NULL; - - newfiles = Hunk_AllocName (numpackfiles * sizeof(unzFile), "packfile"); - - status=unzGoToFirstFile(pak); - - while(status == UNZ_OK) { -// for (i=0 ; ifilename, packfile); - //pack_old->handle = unzGetLocalExtrafield(packfile, NULL, NULL); - pack_old->numfiles = numpackfiles; - pack_old->files = newfiles; - - Con_Printf ("Added packfile %s (%.0f files)\n", packfile, numpackfiles); - - COM_pak3_close(pak); - return pack_old; -} -#endif - - - -/* -================ -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]; - char *p; - - if ((p = strrchr(dir, '/')) != NULL) - strcpy(gamedirfile, ++p); - else - strcpy(gamedirfile, dir); - strcpy (com_gamedir, dir); - -// -// add the directory to the search path -// - search = Hunk_Alloc (sizeof(searchpath_t)); - 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++) - { -#if defined _EXPERIMENTAL_ && GENERATIONS - if (COM_CheckParm ("-aftershock")) - { - snprintf(pakfile, sizeof(pakfile), "%s/pak%i.pk3", dir, i); - pak = COM_LoadQ3PackFile (pakfile); - } else { -#endif - snprintf(pakfile, sizeof(pakfile), "%s/pak%i.pak", dir, i); - pak = COM_LoadPackFile (pakfile); - -#if defined _EXPERIMENTAL_ && GENERATIONS - } -#endif - if (!pak) - break; - search = Hunk_Alloc (sizeof(searchpath_t)); - search->pack = pak; - search->next = com_searchpaths; - com_searchpaths = search; - } - -} - -/* -================ -COM_Gamedir - -Sets the gamedir and path to a different directory. -================ -*/ -void COM_Gamedir (char *dir) -{ - searchpath_t *search, *next; - int i; - pack_t *pak; - char pakfile[MAX_OSPATH]; - - if (strstr(dir, "..") || strstr(dir, "/") - || strstr(dir, "\\") || strstr(dir, ":") ) - { - Con_Printf ("Gamedir should be a single filename, not a path\n"); - return; - } - - if (!strcmp(gamedirfile, dir)) - return; // still the same - strcpy (gamedirfile, dir); - - // - // free up any current game dir info - // - while (com_searchpaths != com_base_searchpaths) - { - if (com_searchpaths->pack) - { - fclose (com_searchpaths->pack->handle); - Z_Free (com_searchpaths->pack->files); - Z_Free (com_searchpaths->pack); - } - next = com_searchpaths->next; - Z_Free (com_searchpaths); - com_searchpaths = next; - } - - // - // flush all data, so it will be forced to reload - // - Cache_Flush (); - - if (!strcmp(dir, GAMENAME) || !strcmp(dir, "qw")) - return; - - snprintf(com_gamedir, sizeof(com_gamedir), "%s/%s", com_basedir, dir); - - // - // add the directory to the search path - // - search = Z_Malloc (sizeof(searchpath_t)); - strcpy (search->filename, com_gamedir); - search->next = com_searchpaths; - com_searchpaths = search; - - // - // add any pak files in the format pak0.pak pak1.pak, ... - // - for (i=0 ; ; i++) - { - snprintf(pakfile, sizeof(pakfile), "%s/pak%i.pak", com_gamedir, i); - pak = COM_LoadPackFile (pakfile); - if (!pak) - break; - search = Z_Malloc (sizeof(searchpath_t)); - search->pack = pak; - search->next = com_searchpaths; - com_searchpaths = search; - } -} - -/* -================ -COM_InitFilesystem -================ -*/ -void COM_InitFilesystem (void) -{ -<<<<<<<<<<<<<< variant A - int i; ->>>>>>>>>>>>>> variant B - int i, j, len; - char basedir[MAX_OSPATH]; - searchpath_t *search; - char * p; - char * games; -======= end of combination - -// -// -basedir -// Overrides the system supplied base directory (under GAMENAME) -// - i = COM_CheckParm ("-basedir"); - if (i && i < com_argc-1) - strcpy (com_basedir, com_argv[i+1]); - else - strcpy (com_basedir, host_parms.basedir); - -// -// start up with GAMENAME by default -// - COM_AddGameDirectory (va("%s/" GAMENAME, com_basedir) ); - COM_AddGameDirectory (va("%s/qw", com_basedir) ); - - // any set gamedirs will be freed up to here - com_base_searchpaths = com_searchpaths; -} - - - -/* -===================================================================== - - INFO STRINGS - -===================================================================== -*/ - -/* -=============== -Info_ValueForKey - -Searches the string for the given -key and returns the associated value, or an empty string. -=============== -*/ -char *Info_ValueForKey (char *s, char *key) -{ - char pkey[512]; - static char value[4][512]; // use two buffers so compares - // work without stomping on each other - static int valueindex; - char *o; - - valueindex = (valueindex + 1) % 4; - if (*s == '\\') - s++; - while (1) - { - o = pkey; - while (*s != '\\') - { - if (!*s) - return ""; - *o++ = *s++; - } - *o = 0; - s++; - - o = value[valueindex]; - - while (*s != '\\' && *s) - { - if (!*s) - return ""; - *o++ = *s++; - } - *o = 0; - - if (!strcmp (key, pkey) ) - return value[valueindex]; - - if (!*s) - return ""; - s++; - } -} - -void Info_RemoveKey (char *s, char *key) -{ - char *start; - char pkey[512]; - char value[512]; - char *o; - - if (strstr (key, "\\")) - { - Con_Printf ("Can't use a key with a \\\n"); - return; - } - - while (1) - { - start = s; - if (*s == '\\') - s++; - o = pkey; - while (*s != '\\') - { - if (!*s) - return; - *o++ = *s++; - } - *o = 0; - s++; - - o = value; - while (*s != '\\' && *s) - { - if (!*s) - return; - *o++ = *s++; - } - *o = 0; - - if (!strcmp (key, pkey) ) - { - strcpy (start, s); // remove this part - return; - } - - if (!*s) - return; - } - -} - -void Info_RemovePrefixedKeys (char *start, char prefix) -{ - char *s; - char pkey[512]; - char value[512]; - char *o; - - s = start; - - while (1) - { - if (*s == '\\') - s++; - o = pkey; - while (*s != '\\') - { - if (!*s) - return; - *o++ = *s++; - } - *o = 0; - s++; - - o = value; - while (*s != '\\' && *s) - { - if (!*s) - return; - *o++ = *s++; - } - *o = 0; - - if (pkey[0] == prefix) - { - Info_RemoveKey (start, pkey); - s = start; - } - - if (!*s) - return; - } - -} - - -void Info_SetValueForStarKey (char *s, char *key, char *value, int maxsize) -{ - char new[1024], *v; - int c; -#ifdef SERVERONLY - extern cvar_t sv_highchars; -#endif - - if (strstr (key, "\\") || strstr (value, "\\") ) - { - Con_Printf ("Can't use keys or values with a \\\n"); - return; - } - - if (strstr (key, "\"") || strstr (value, "\"") ) - { - Con_Printf ("Can't use keys or values with a \"\n"); - return; - } - - if (strlen(key) > 63 || strlen(value) > 63) - { - Con_Printf ("Keys and values must be < 64 characters.\n"); - return; - } - - // this next line is kinda trippy - if (*(v = Info_ValueForKey(s, key))) { - // key exists, make sure we have enough room for new value, - // if we don't, don't change it! - if (strlen(value) - strlen(v) + strlen(s) > maxsize) { - Con_Printf ("Info 1 string length exceeded\n"); - return; - } - } - Info_RemoveKey (s, key); - if (!value || !strlen(value)) - return; - - snprintf(new, sizeof(new), "\\%s\\%s", key, value); - - if ((int)(strlen(new) + strlen(s)) > maxsize) - { - Con_Printf ("Info 2 string length exceeded\n"); - return; - } - - // only copy ascii values - s += strlen(s); - v = new; - while (*v) - { - c = (unsigned char)*v++; -#ifndef SERVERONLY - // client only allows highbits on name - if (stricmp(key, "name") != 0) { - c &= 127; - if (c < 32 || c > 127) - continue; - // auto lowercase team - if (stricmp(key, "team") == 0) - c = tolower(c); - } -#else - if (!sv_highchars.value) { - c &= 127; - if (c < 32 || c > 127) - continue; - } -#endif -// c &= 127; // strip high bits - if (c > 13) // && c < 127) - *s++ = c; - } - *s = 0; -} - -void Info_SetValueForKey (char *s, char *key, char *value, int maxsize) -{ - if (key[0] == '*') - { - Con_Printf ("Can't set * keys\n"); - return; - } - - Info_SetValueForStarKey (s, key, value, maxsize); -} - -void Info_Print (char *s) -{ - char key[512]; - char value[512]; - char *o; - int l; - - if (*s == '\\') - s++; - while (*s) - { - o = key; - while (*s && *s != '\\') - *o++ = *s++; - - l = o - key; - if (l < 20) - { - memset (o, ' ', 20-l); - key[20] = 0; - } - else - *o = 0; - Con_Printf ("%s", key); - - if (!*s) - { - Con_Printf ("MISSING VALUE\n"); - return; - } - - o = value; - s++; - while (*s && *s != '\\') - *o++ = *s++; - *o = 0; - - if (*s) - s++; - Con_Printf ("%s\n", value); - } -} - -static byte chktbl[1024 + 4] = { -0x78,0xd2,0x94,0xe3,0x41,0xec,0xd6,0xd5,0xcb,0xfc,0xdb,0x8a,0x4b,0xcc,0x85,0x01, -0x23,0xd2,0xe5,0xf2,0x29,0xa7,0x45,0x94,0x4a,0x62,0xe3,0xa5,0x6f,0x3f,0xe1,0x7a, -0x64,0xed,0x5c,0x99,0x29,0x87,0xa8,0x78,0x59,0x0d,0xaa,0x0f,0x25,0x0a,0x5c,0x58, -0xfb,0x00,0xa7,0xa8,0x8a,0x1d,0x86,0x80,0xc5,0x1f,0xd2,0x28,0x69,0x71,0x58,0xc3, -0x51,0x90,0xe1,0xf8,0x6a,0xf3,0x8f,0xb0,0x68,0xdf,0x95,0x40,0x5c,0xe4,0x24,0x6b, -0x29,0x19,0x71,0x3f,0x42,0x63,0x6c,0x48,0xe7,0xad,0xa8,0x4b,0x91,0x8f,0x42,0x36, -0x34,0xe7,0x32,0x55,0x59,0x2d,0x36,0x38,0x38,0x59,0x9b,0x08,0x16,0x4d,0x8d,0xf8, -0x0a,0xa4,0x52,0x01,0xbb,0x52,0xa9,0xfd,0x40,0x18,0x97,0x37,0xff,0xc9,0x82,0x27, -0xb2,0x64,0x60,0xce,0x00,0xd9,0x04,0xf0,0x9e,0x99,0xbd,0xce,0x8f,0x90,0x4a,0xdd, -0xe1,0xec,0x19,0x14,0xb1,0xfb,0xca,0x1e,0x98,0x0f,0xd4,0xcb,0x80,0xd6,0x05,0x63, -0xfd,0xa0,0x74,0xa6,0x86,0xf6,0x19,0x98,0x76,0x27,0x68,0xf7,0xe9,0x09,0x9a,0xf2, -0x2e,0x42,0xe1,0xbe,0x64,0x48,0x2a,0x74,0x30,0xbb,0x07,0xcc,0x1f,0xd4,0x91,0x9d, -0xac,0x55,0x53,0x25,0xb9,0x64,0xf7,0x58,0x4c,0x34,0x16,0xbc,0xf6,0x12,0x2b,0x65, -0x68,0x25,0x2e,0x29,0x1f,0xbb,0xb9,0xee,0x6d,0x0c,0x8e,0xbb,0xd2,0x5f,0x1d,0x8f, -0xc1,0x39,0xf9,0x8d,0xc0,0x39,0x75,0xcf,0x25,0x17,0xbe,0x96,0xaf,0x98,0x9f,0x5f, -0x65,0x15,0xc4,0x62,0xf8,0x55,0xfc,0xab,0x54,0xcf,0xdc,0x14,0x06,0xc8,0xfc,0x42, -0xd3,0xf0,0xad,0x10,0x08,0xcd,0xd4,0x11,0xbb,0xca,0x67,0xc6,0x48,0x5f,0x9d,0x59, -0xe3,0xe8,0x53,0x67,0x27,0x2d,0x34,0x9e,0x9e,0x24,0x29,0xdb,0x69,0x99,0x86,0xf9, -0x20,0xb5,0xbb,0x5b,0xb0,0xf9,0xc3,0x67,0xad,0x1c,0x9c,0xf7,0xcc,0xef,0xce,0x69, -0xe0,0x26,0x8f,0x79,0xbd,0xca,0x10,0x17,0xda,0xa9,0x88,0x57,0x9b,0x15,0x24,0xba, -0x84,0xd0,0xeb,0x4d,0x14,0xf5,0xfc,0xe6,0x51,0x6c,0x6f,0x64,0x6b,0x73,0xec,0x85, -0xf1,0x6f,0xe1,0x67,0x25,0x10,0x77,0x32,0x9e,0x85,0x6e,0x69,0xb1,0x83,0x00,0xe4, -0x13,0xa4,0x45,0x34,0x3b,0x40,0xff,0x41,0x82,0x89,0x79,0x57,0xfd,0xd2,0x8e,0xe8, -0xfc,0x1d,0x19,0x21,0x12,0x00,0xd7,0x66,0xe5,0xc7,0x10,0x1d,0xcb,0x75,0xe8,0xfa, -0xb6,0xee,0x7b,0x2f,0x1a,0x25,0x24,0xb9,0x9f,0x1d,0x78,0xfb,0x84,0xd0,0x17,0x05, -0x71,0xb3,0xc8,0x18,0xff,0x62,0xee,0xed,0x53,0xab,0x78,0xd3,0x65,0x2d,0xbb,0xc7, -0xc1,0xe7,0x70,0xa2,0x43,0x2c,0x7c,0xc7,0x16,0x04,0xd2,0x45,0xd5,0x6b,0x6c,0x7a, -0x5e,0xa1,0x50,0x2e,0x31,0x5b,0xcc,0xe8,0x65,0x8b,0x16,0x85,0xbf,0x82,0x83,0xfb, -0xde,0x9f,0x36,0x48,0x32,0x79,0xd6,0x9b,0xfb,0x52,0x45,0xbf,0x43,0xf7,0x0b,0x0b, -0x19,0x19,0x31,0xc3,0x85,0xec,0x1d,0x8c,0x20,0xf0,0x3a,0xfa,0x80,0x4d,0x2c,0x7d, -0xac,0x60,0x09,0xc0,0x40,0xee,0xb9,0xeb,0x13,0x5b,0xe8,0x2b,0xb1,0x20,0xf0,0xce, -0x4c,0xbd,0xc6,0x04,0x86,0x70,0xc6,0x33,0xc3,0x15,0x0f,0x65,0x19,0xfd,0xc2,0xd3, - -// map checksum goes here -0x00,0x00,0x00,0x00 -}; - -#if 0 -static byte chkbuf[16 + 60 + 4]; - -static unsigned last_mapchecksum = 0; - -/* -==================== -COM_BlockSequenceCheckByte - -For proxy protecting -==================== -*/ -byte COM_BlockSequenceCheckByte (byte *base, int length, int sequence, unsigned mapchecksum) -{ - int checksum; - byte *p; - - if (last_mapchecksum != mapchecksum) { - last_mapchecksum = mapchecksum; - chktbl[1024] = (mapchecksum & 0xff000000) >> 24; - chktbl[1025] = (mapchecksum & 0x00ff0000) >> 16; - chktbl[1026] = (mapchecksum & 0x0000ff00) >> 8; - chktbl[1027] = (mapchecksum & 0x000000ff); - - Com_BlockFullChecksum (chktbl, sizeof(chktbl), chkbuf); - } - - p = chktbl + (sequence % (sizeof(chktbl) - 8)); - - if (length > 60) - length = 60; - memcpy (chkbuf + 16, base, length); - - length += 16; - - chkbuf[length] = (sequence & 0xff) ^ p[0]; - chkbuf[length+1] = p[1]; - chkbuf[length+2] = ((sequence>>8) & 0xff) ^ p[2]; - chkbuf[length+3] = p[3]; - - length += 4; - - checksum = LittleLong(Com_BlockChecksum (chkbuf, length)); - - checksum &= 0xff; - - return checksum; -} -#endif - -/* -==================== -COM_BlockSequenceCRCByte - -For proxy protecting -==================== -*/ -byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence) -{ - unsigned short crc; - byte *p; - byte chkb[60 + 4]; - - p = chktbl + (sequence % (sizeof(chktbl) - 8)); - - if (length > 60) - length = 60; - memcpy (chkb, base, length); - - chkb[length] = (sequence & 0xff) ^ p[0]; - chkb[length+1] = p[1]; - chkb[length+2] = ((sequence>>8) & 0xff) ^ p[2]; - chkb[length+3] = p[3]; - - length += 4; - - crc = CRC_Block(chkb, length); - - crc &= 0xff; - - return crc; -} diff --git a/common/common.h b/common/common.h deleted file mode 100644 index 6f8704f..0000000 --- a/common/common.h +++ /dev/null @@ -1,247 +0,0 @@ -/* -Copyright (C) 1996-1997 Id Software, Inc. -Copyright (C) 1999,2000 contributors of the QuakeForge project -Please see the file "AUTHORS" for a list of contributors - -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. - -*/ -// comndef.h -- general definitions - -#ifndef _COMMON_H -#define _COMMON_H - -#include -#include - -typedef unsigned char byte; - -// KJB Undefined true and false defined in SciTech's DEBUG.H header -#undef true -#undef false - -typedef enum {false, true} qboolean; - -#define MAX_INFO_STRING 196 -#define MAX_SERVERINFO_STRING 512 -#define MAX_LOCALINFO_STRING 32768 - -//============================================================================ - -typedef struct sizebuf_s -{ - qboolean allowoverflow; // if false, do a Sys_Error - qboolean overflowed; // set to true if the buffer size failed - byte *data; - int maxsize; - int cursize; -} sizebuf_t; - -void SZ_Alloc (sizebuf_t *buf, int startsize); -void SZ_Free (sizebuf_t *buf); -void SZ_Clear (sizebuf_t *buf); -void *SZ_GetSpace (sizebuf_t *buf, int length); -void SZ_Write (sizebuf_t *buf, void *data, int length); -void SZ_Print (sizebuf_t *buf, char *data); // strcats onto the sizebuf - -//============================================================================ - -typedef struct link_s -{ - struct link_s *prev, *next; -} link_t; - - -void ClearLink (link_t *l); -void RemoveLink (link_t *l); -void InsertLinkBefore (link_t *l, link_t *before); -void InsertLinkAfter (link_t *l, link_t *after); - -// (type *)STRUCT_FROM_LINK(link_t *link, type, member) -// ent = STRUCT_FROM_LINK(link,entity_t,order) -// FIXME: remove this mess! -#define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m))) - -//============================================================================ -// Pak 3 loading support: -/* -pack_t *COM_LoadQ3PackFile (char *packfile); -uint_t COM_pak3_getlen(unzFile *pak); -int COM_pak3_open(unzFile *pak, const char *path); -uint_t COM_pak3_readfile(unzFile *pak, const char *path, uint_t bufsize, byte_t *buf); -int COM_pak3_read(unzFile *pak, void *buf, uint_t size, uint_t nmemb); -int COM_pak3_checkfile(unzFile *pak, const char *path); -*/ - - -// End Pak3 support. -//============================================================================ - -#ifndef NULL -#define NULL ((void *)0) -#endif - -#define Q_MAXCHAR ((char)0x7f) -#define Q_MAXSHORT ((short)0x7fff) -#define Q_MAXINT ((int)0x7fffffff) -#define Q_MAXLONG ((int)0x7fffffff) -#define Q_MAXFLOAT ((int)0x7fffffff) - -#define Q_MINCHAR ((char)0x80) -#define Q_MINSHORT ((short)0x8000) -#define Q_MININT ((int)0x80000000) -#define Q_MINLONG ((int)0x80000000) -#define Q_MINFLOAT ((int)0x7fffffff) - -//============================================================================ - -extern short (*BigShort) (short l); -extern short (*LittleShort) (short l); -extern int (*BigLong) (int l); -extern int (*LittleLong) (int l); -extern float (*BigFloat) (float l); -extern float (*LittleFloat) (float l); - -//============================================================================ - -struct usercmd_s; - -extern struct usercmd_s nullcmd; - -void MSG_WriteChar (sizebuf_t *sb, int c); -void MSG_WriteByte (sizebuf_t *sb, int c); -void MSG_WriteShort (sizebuf_t *sb, int c); -void MSG_WriteLong (sizebuf_t *sb, int c); -void MSG_WriteFloat (sizebuf_t *sb, float f); -void MSG_WriteString (sizebuf_t *sb, char *s); -void MSG_WriteCoord (sizebuf_t *sb, float f); -void MSG_WriteAngle (sizebuf_t *sb, float f); -void MSG_WriteAngle16 (sizebuf_t *sb, float f); -void MSG_WriteDeltaUsercmd (sizebuf_t *sb, struct usercmd_s *from, struct usercmd_s *cmd); - -extern int msg_readcount; -extern qboolean msg_badread; // set if a read goes beyond end of message - -void MSG_BeginReading (void); -int MSG_GetReadCount(void); -int MSG_ReadChar (void); -int MSG_ReadByte (void); -int MSG_ReadShort (void); -int MSG_ReadLong (void); -float MSG_ReadFloat (void); -char *MSG_ReadString (void); -char *MSG_ReadStringLine (void); - -float MSG_ReadCoord (void); -float MSG_ReadAngle (void); -float MSG_ReadAngle16 (void); -void MSG_ReadDeltaUsercmd (struct usercmd_s *from, struct usercmd_s *cmd); - -//============================================================================ - -#define Q_memset(d, f, c) memset((d), (f), (c)) -#define Q_memcpy(d, s, c) memcpy((d), (s), (c)) -#define Q_memcmp(m1, m2, c) memcmp((m1), (m2), (c)) -#define Q_strcpy(d, s) strcpy((d), (s)) -#define Q_strncpy(d, s, n) strncpy((d), (s), (n)) -#define Q_strlen(s) ((int)strlen(s)) -#define Q_strrchr(s, c) strrchr((s), (c)) -#define Q_strcat(d, s) strcat((d), (s)) -#define Q_strcmp(s1, s2) strcmp((s1), (s2)) -#define Q_strncmp(s1, s2, n) strncmp((s1), (s2), (n)) - -#ifdef _WIN32 - -#define Q_strcasecmp(s1, s2) _stricmp((s1), (s2)) -#define Q_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n)) - -#else - -#define Q_strcasecmp(s1, s2) strcasecmp((s1), (s2)) -#define Q_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n)) - -#endif - -int Q_atoi (char *str); -float Q_atof (char *str); - -//============================================================================ - -extern char com_token[1024]; -extern qboolean com_eof; - -char *COM_Parse (char *data); - - -extern int com_argc; -extern char **com_argv; - -int COM_CheckParm (char *parm); -#ifdef QUAKEWORLD -void COM_AddParm (char *parm); -void COM_Init (void); -#else -void COM_Init (char *path); -#endif -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 - - -//============================================================================ - -extern int com_filesize; -struct cache_user_s; - -extern char com_gamedir[MAX_OSPATH]; - -void COM_WriteFile (char *filename, void *data, int len); -int COM_OpenFile (char *filename, int *hndl); -int COM_FOpenFile (char *filename, FILE **file); -#ifdef QUAKEWORLD -void COM_CloseFile (FILE *h); -#else -void COM_CloseFile (int h); -#endif - -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); -void COM_CreatePath (char *path); -void COM_Gamedir (char *dir); - -extern qboolean standard_quake, rogue, hipnotic; - -char *Info_ValueForKey (char *s, char *key); -void Info_RemoveKey (char *s, char *key); -void Info_RemovePrefixedKeys (char *start, char prefix); -void Info_SetValueForKey (char *s, char *key, char *value, int maxsize); -void Info_SetValueForStarKey (char *s, char *key, char *value, int maxsize); -void Info_Print (char *s); - -unsigned Com_BlockChecksum (void *buffer, int length); -void Com_BlockFullChecksum (void *buffer, int len, unsigned char *outbuf); -byte COM_BlockSequenceCheckByte (byte *base, int length, int sequence, unsigned mapchecksum); -byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence); - -#endif // _COMMON_H diff --git a/common/common_quakedef.h b/common/common_quakedef.h index 92f76fa..600eee3 100644 --- a/common/common_quakedef.h +++ b/common/common_quakedef.h @@ -44,6 +44,10 @@ void VID_UnlockBuffer (void); #define VID_UnlockBuffer() #endif +#include "qtypes.h" +#include "qstructs.h" + +/* #include "common.h" #include "bspfile.h" #include "vid.h" @@ -76,6 +80,7 @@ void VID_UnlockBuffer (void); #include "cdaudio.h" #include "cvars.h" +*/ #ifndef max #define max(a,b) ((a) > (b) ? (a) : (b)) @@ -94,32 +99,6 @@ void VID_UnlockBuffer (void); #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF) # define vsnprintf _vsnprintf #endif -#if !defined(HAVE_SNPRINTF) && !defined(HAVE__SNPRINTF) -#ifdef HAVE_VSNPRINTF -# define snprintf vsnprintf -#elif defined(HAVE__VSNPRINTF) -# define snprintf _vsnprintf -#endif -#endif - -//============================================================================= - -// the host system specifies the base of the directory tree, the -// command line parms passed to the program, and the amount of memory -// available for the program to use - -typedef struct -{ - char *basedir; - char *cachedir; // for development over ISDN lines - int argc; - char **argv; - void *membase; - int memsize; -} quakeparms_t; - - -//============================================================================= #define MAX_NUM_ARGVS 50 diff --git a/qw_common/cvar.c b/common/cvar.c similarity index 97% rename from qw_common/cvar.c rename to common/cvar.c index 4a801ae..9462c68 100644 --- a/qw_common/cvar.c +++ b/common/cvar.c @@ -22,6 +22,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // cvar.c -- dynamic variable tracking +#include "qtypes.h" +#include "lib_replace.h" +#include "console.h" +#include "common.h" +#include "cmd.h" +#include "client.h" + #ifdef SERVERONLY #include "qwsvdef.h" #else diff --git a/uquake/cvar.h b/common/cvar.h similarity index 93% rename from uquake/cvar.h rename to common/cvar.h index 3c03a84..2b68260 100644 --- a/uquake/cvar.h +++ b/common/cvar.h @@ -1,5 +1,7 @@ /* Copyright (C) 1996-1997 Id Software, Inc. +Copyright (C) 1999,2000 contributors of the QuakeForge project +Please see the file "AUTHORS" for a list of contributors This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -19,6 +21,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // cvar.h +#ifndef _CVAR_H +#define _CVAR_H + +#include "qtypes.h" +#include "qstructs.h" /* 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 @@ -52,16 +59,6 @@ Cvars are restricted from having the same names as commands to keep this interface from being ambiguous. */ -typedef struct cvar_s -{ - char *name; - char *string; - qboolean archive; // set to true to cause it to be saved to vars.rc - qboolean server; // notifies players when changed - float value; - struct cvar_s *next; -} cvar_t; - void Cvar_RegisterVariable (cvar_t *variable); // registers a cvar that allready has the name, string, and optionally the // archive elements set. @@ -94,3 +91,4 @@ void Cvar_WriteVariables (FILE *f); cvar_t *Cvar_FindVar (char *var_name); extern cvar_t *cvar_vars; +#endif // _CVAR_H diff --git a/common/cvars.h b/common/cvars.h index a551f69..406ce85 100644 --- a/common/cvars.h +++ b/common/cvars.h @@ -25,4 +25,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern cvar_t gl_flashblend; +// From r_local.h +extern cvar_t r_draworder; +extern cvar_t r_speeds; +extern cvar_t r_timegraph; +extern cvar_t r_graphheight; +extern cvar_t r_clearcolor; +extern cvar_t r_waterwarp; +extern cvar_t r_fullbright; +extern cvar_t r_drawentities; +extern cvar_t r_aliasstats; +extern cvar_t r_dspeeds; +extern cvar_t r_drawflat; +extern cvar_t r_ambient; +extern cvar_t r_reportsurfout; +extern cvar_t r_maxsurfs; +extern cvar_t r_numsurfs; +extern cvar_t r_reportedgeout; +extern cvar_t r_maxedges; +extern cvar_t r_numedges; + #endif _CVARS_H diff --git a/common/d_init.c b/common/d_init.c index 2a30435..7978c49 100644 --- a/common/d_init.c +++ b/common/d_init.c @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "d_local.h" +#include #define NUM_MIPS 4 diff --git a/common/d_polyse.c b/common/d_polyse.c index 2b79a8b..21bbfb8 100644 --- a/common/d_polyse.c +++ b/common/d_polyse.c @@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" #include "d_local.h" +#include // TODO: put in span spilling to shrink list size // !!! if this is changed, it must be changed in d_polysa.s too !!! diff --git a/common/d_sky.c b/common/d_sky.c index f5b77a7..669318d 100644 --- a/common/d_sky.c +++ b/common/d_sky.c @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" #include "d_local.h" +#include #define SKY_SPAN_SHIFT 5 #define SKY_SPAN_MAX (1 << SKY_SPAN_SHIFT) diff --git a/common/d_sprite.c b/common/d_sprite.c index 296be94..f64df49 100644 --- a/common/d_sprite.c +++ b/common/d_sprite.c @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "d_local.h" +#include static int sprite_height; static int minindex, maxindex; diff --git a/common/draw.c b/common/draw.c index 573d8c0..8c20251 100644 --- a/common/draw.c +++ b/common/draw.c @@ -23,7 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // draw.c -- this is the only file outside the refresh that touches the // vid buffer -#include "quakedef.h" +#include +#include +#include +#include +#include typedef struct { vrect_t rect; diff --git a/common/draw.h b/common/draw.h index 8792548..4c1abc5 100644 --- a/common/draw.h +++ b/common/draw.h @@ -23,6 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // draw.h -- these are the only functions outside the refresh allowed // to touch the vid buffer +#include "qtypes.h" +#include "wad.h" + extern qpic_t *draw_disc; // also used on sbar void Draw_Init (void); diff --git a/common/gl_draw.c b/common/gl_draw.c index 8e2c0bb..3883be6 100644 --- a/common/gl_draw.c +++ b/common/gl_draw.c @@ -23,8 +23,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // draw.c -- this is the only file outside the refresh that touches the // vid buffer +#include "qtypes.h" #include "quakedef.h" +#include "cvar.h" +#include "wad.h" #include "glquake.h" +#include "console.h" +#include "sbar.h" extern unsigned char d_15to8table[65536]; extern cvar_t crosshair, cl_crossx, cl_crossy, crosshaircolor; diff --git a/common/gl_mesh.c b/common/gl_mesh.c index 99d7c66..9cf8afa 100644 --- a/common/gl_mesh.c +++ b/common/gl_mesh.c @@ -22,8 +22,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // gl_mesh.c: triangle model functions +#include "qtypes.h" #include "quakedef.h" -#include "glquake.h" +#include "model.h" +#include "console.h" +#include "common.h" +#include "sys.h" /* ================================================================= diff --git a/common/gl_refrag.c b/common/gl_refrag.c index 02a860b..27a377c 100644 --- a/common/gl_refrag.c +++ b/common/gl_refrag.c @@ -21,8 +21,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // r_efrag.c +#include "qtypes.h" #include "quakedef.h" #include "glquake.h" +#include "model.h" +#include "console.h" +#include "mathlib.h" mnode_t *r_pefragtopnode; diff --git a/common/gl_rmain.c b/common/gl_rmain.c index 0a058c6..f407bbf 100644 --- a/common/gl_rmain.c +++ b/common/gl_rmain.c @@ -27,8 +27,13 @@ Boston, MA 02111-1307, USA. */ +#include "qtypes.h" #include "quakedef.h" #include "glquake.h" +#include "mathlib.h" +#include "console.h" +#include "view.h" +#include "sound.h" entity_t r_worldentity; diff --git a/common/gl_rmisc.c b/common/gl_rmisc.c index beab749..d9484d2 100644 --- a/common/gl_rmisc.c +++ b/common/gl_rmisc.c @@ -21,8 +21,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // r_misc.c +#include "qtypes.h" #include "quakedef.h" #include "glquake.h" +#include "cvar.h" +#include "console.h" extern void R_InitBubble(); diff --git a/common/gl_rsurf.c b/common/gl_rsurf.c index 294c120..c8930ce 100644 --- a/common/gl_rsurf.c +++ b/common/gl_rsurf.c @@ -21,8 +21,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // r_surf.c: surrface-related refresh code +#include "qtypes.h" #include "quakedef.h" #include "glquake.h" +#include "mathlib.h" int skytexturenum; diff --git a/common/gl_vidglx.c b/common/gl_vidglx.c index 4f193e0..b65061b 100644 --- a/common/gl_vidglx.c +++ b/common/gl_vidglx.c @@ -21,8 +21,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "qtypes.h" #include "quakedef.h" #include "glquake.h" +#include "cvar.h" +#include "console.h" +#include "sound.h" +#include "keys.h" +#include "menu.h" #ifndef _EXPERIMENTAL_ # undef HAS_DGA diff --git a/common/gl_vidlinux_3dfx.c b/common/gl_vidlinux_3dfx.c index 760a3c9..f02ed17 100644 --- a/common/gl_vidlinux_3dfx.c +++ b/common/gl_vidlinux_3dfx.c @@ -22,7 +22,13 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "qtypes.h" #include "quakedef.h" +#include "glquake.h" +#include "sys.h" +#include "console.h" +#include "cvar.h" +#include "sound.h" #include #include diff --git a/common/gl_view.c b/common/gl_view.c index c3bcd8d..34cf362 100644 --- a/common/gl_view.c +++ b/common/gl_view.c @@ -21,9 +21,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // view.c -- player eye positioning +#include "qtypes.h" #include "quakedef.h" -#include "glquake.h" #include "r_local.h" +#include "glquake.h" +#include "view.h" extern int onground; diff --git a/common/gl_warp.c b/common/gl_warp.c index 65d949b..f6536b8 100644 --- a/common/gl_warp.c +++ b/common/gl_warp.c @@ -6,7 +6,7 @@ Copyright (C) 1996-1997 Id Software, Inc. Copyright (C) 1999,2000 contributors of the QuakeForge project Please see the file "AUTHORS" for a list of contributors -Portions Copyright (C) 1999,2000 Nelson Rush. + 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 @@ -27,8 +27,10 @@ Portions Copyright (C) 1999,2000 Nelson Rush. Boston, MA 02111-1307, USA */ +#include "qtypes.h" #include "quakedef.h" #include "glquake.h" +#include "mathlib.h" extern model_t *loadmodel; diff --git a/common/glquake.h b/common/glquake.h index 4089f81..cf9de10 100644 --- a/common/glquake.h +++ b/common/glquake.h @@ -38,6 +38,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include "model.h" #include "client.h" +#include "wad.h" void GL_BeginRendering (int *x, int *y, int *width, int *height); void GL_EndRendering (void); diff --git a/common/glquake2.h b/common/glquake2.h deleted file mode 100644 index 7942722..0000000 --- a/common/glquake2.h +++ /dev/null @@ -1,209 +0,0 @@ -/* -Copyright (C) 1996-1997 Id Software, Inc. -Copyright (C) 1999,2000 contributors of the QuakeForge project -Please see the file "AUTHORS" for a list of contributors - -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. - -*/ -// disable data conversion warnings - -#pragma warning(disable : 4244) // MIPS -#pragma warning(disable : 4136) // X86 -#pragma warning(disable : 4051) // ALPHA - -#include - -#include -#include - -void GL_BeginRendering (int *x, int *y, int *width, int *height); -void GL_EndRendering (void); - - -// Function prototypes for the Texture Object Extension routines -typedef GLboolean (GLAPIENTRY *ARETEXRESFUNCPTR)(GLsizei, const GLuint *, - const GLboolean *); -typedef void (GLAPIENTRY *BINDTEXFUNCPTR)(GLenum, GLuint); -typedef void (GLAPIENTRY *DELTEXFUNCPTR)(GLsizei, const GLuint *); -typedef void (GLAPIENTRY *GENTEXFUNCPTR)(GLsizei, GLuint *); -typedef GLboolean (GLAPIENTRY *ISTEXFUNCPTR)(GLuint); -typedef void (GLAPIENTRY *PRIORTEXFUNCPTR)(GLsizei, const GLuint *, - const GLclampf *); -typedef void (GLAPIENTRY *TEXSUBIMAGEPTR)(int, int, int, int, int, int, int, int, void *); - -extern BINDTEXFUNCPTR bindTexFunc; -extern DELTEXFUNCPTR delTexFunc; -extern TEXSUBIMAGEPTR TexSubImage2DFunc; - -extern int texture_extension_number; -extern int texture_mode; - -extern float gldepthmin, gldepthmax; - -void GL_Upload32 (unsigned *data, int width, int height, qboolean mipmap, qboolean alpha, qboolean modulate); -void GL_Upload8 (byte *data, int width, int height, qboolean mipmap, qboolean alpha, qboolean modulate); -int GL_LoadTexture (char *identifier, int width, int height, byte *data, int mipmap, int alpha, int modulate); -int GL_FindTexture (char *identifier); - -typedef struct -{ - float x, y, z; - float s, t; - float r, g, b; -} glvert_t; - -extern glvert_t glv; - -extern int glx, gly, glwidth, glheight; - -extern PROC glArrayElementEXT; -extern PROC glColorPointerEXT; -extern PROC glTexturePointerEXT; -extern PROC glVertexPointerEXT; - - -// r_local.h -- private refresh defs - -#define MAXALIASVERTS 2000 // TODO: tune this - -#define ALIAS_BASE_SIZE_RATIO (1.0 / 11.0) - // normalizing factor so player model works out to about - // 1 pixel per triangle -#define MAX_LBM_HEIGHT 480 - -#define TILE_SIZE 128 // size of textures generated by R_GenTiledSurf - -#define SKYSHIFT 7 -#define SKYSIZE (1 << SKYSHIFT) -#define SKYMASK (SKYSIZE - 1) - -#define BACKFACE_EPSILON 0.01 - - -void R_TimeRefresh_f (void); -void R_ReadPointFile_f (void); -texture_t *R_TextureAnimation (texture_t *base); - -typedef struct surfcache_s -{ - struct surfcache_s *next; - struct surfcache_s **owner; // NULL is an empty chunk of memory - int lightadj[MAXLIGHTMAPS]; // checked for strobe flush - int dlight; - int size; // including header - unsigned width; - unsigned height; // DEBUG only needed for debug - float mipscale; - struct texture_s *texture; // checked for animating textures - byte data[4]; // width*height elements -} surfcache_t; - - -typedef struct -{ - pixel_t *surfdat; // destination for generated surface - int rowbytes; // destination logical width in bytes - msurface_t *surf; // description for surface to generate - fixed8_t lightadj[MAXLIGHTMAPS]; - // adjust for lightmap levels for dynamic lighting - texture_t *texture; // corrected for animating textures - int surfmip; // mipmapped ratio of surface texels / world pixels - int surfwidth; // in mipmapped texels - int surfheight; // in mipmapped texels -} drawsurf_t; - - -typedef enum { - pt_static, pt_grav, pt_slowgrav, pt_fire, pt_explode, pt_explode2, pt_blob, pt_blob2 -} ptype_t; - -// !!! if this is changed, it must be changed in d_ifacea.h too !!! -typedef struct particle_s -{ -// driver-usable fields - vec3_t org; - float color; -// drivers never touch the following fields - struct particle_s *next; - vec3_t vel; - float ramp; - float die; - ptype_t type; -} particle_t; - - -//==================================================== - - -extern entity_t r_worldentity; -extern qboolean r_cache_thrash; // compatability -extern vec3_t modelorg, r_entorigin; -extern entity_t *currententity; -extern int r_visframecount; // ??? what difs? -extern int r_framecount; -extern mplane_t frustum[4]; -extern int c_brush_polys, c_alias_polys; - - -// -// view origin -// -extern vec3_t vup; -extern vec3_t vpn; -extern vec3_t vright; -extern vec3_t r_origin; - -// -// screen size info -// -extern refdef_t r_refdef; -extern mleaf_t *r_viewleaf, *r_oldviewleaf; -extern int d_lightstylevalue[256]; // 8.8 fraction of base light value - -extern qboolean envmap; -extern int currenttexture; -extern int particletexture; -extern int playertextures; - -extern int skytexturenum; // index in cl.loadmodel, not gl texture object - -extern cvar_t r_drawentities; -extern cvar_t r_drawworld; -extern cvar_t r_drawviewmodel; -extern cvar_t r_speeds; -extern cvar_t r_waterwarp; -extern cvar_t r_fullbright; -extern cvar_t r_lightmap; -extern cvar_t r_shadows; -extern cvar_t r_dynamic; - -extern cvar_t gl_clear; -extern cvar_t gl_cull; -extern cvar_t gl_poly; -extern cvar_t gl_texsort; -extern cvar_t gl_smoothmodels; -extern cvar_t gl_affinemodels; -extern cvar_t gl_fogblend; -extern cvar_t gl_polyblend; -extern cvar_t gl_keeptjunctions; - -extern int gl_lightmap_format; -extern int gl_solid_format; -extern int gl_alpha_format; - -void R_TranslatePlayerSkin (int playernum); -void GL_Bind (int texnum); diff --git a/common/in_svgalib.c b/common/in_svgalib.c index 3d8f4f6..f7c10d0 100644 --- a/common/in_svgalib.c +++ b/common/in_svgalib.c @@ -21,7 +21,13 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "qtypes.h" #include "quakedef.h" +#include "keys.h" +#include "client.h" +#include "sys.h" +#include "console.h" +#include "cvar.h" #include #include diff --git a/common/keys.c b/common/keys.c index d548271..2d6e233 100644 --- a/common/keys.c +++ b/common/keys.c @@ -21,6 +21,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "quakedef.h" +#include "qtypes.h" +#include "keys.h" +#include "cmd.h" +#include "cvar.h" +#include "client.h" +#include "lib_replace.h" +#include "console.h" +#include "menu.h" +#include "screen.h" + #ifdef _WIN32 #include #endif diff --git a/common/lib_replace.c b/common/lib_replace.c new file mode 100644 index 0000000..57ed964 --- /dev/null +++ b/common/lib_replace.c @@ -0,0 +1,324 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. +Portions Copyright (C) 1999,2000 Nelson Rush. +Copyright (C) 1999,2000 contributors of the QuakeForge project +Please see the file "AUTHORS" for a list of contributors + +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. + +*/ +// common.c -- misc functions used in client and server + +#include + +/* +============================================================================ + + LIBRARY REPLACEMENT FUNCTIONS + +============================================================================ +*/ + +#if 0 +void Q_memset (void *dest, int fill, int count) +{ + int i; + + if ( (((long)dest | count) & 3) == 0) + { + count >>= 2; + fill = fill | (fill<<8) | (fill<<16) | (fill<<24); + for (i=0 ; i>=2; + for (i=0 ; i= 'a' && c1 <= 'z') + c1 -= ('a' - 'A'); + if (c2 >= 'a' && c2 <= 'z') + c2 -= ('a' - 'A'); + if (c1 != c2) + return -1; // strings not equal + } + if (!c1) + return 0; // strings are equal +// s1++; +// s2++; + } + + return -1; +} + +int Q_strcasecmp (char *s1, char *s2) +{ + return Q_strncasecmp (s1, s2, 99999); +} + +#endif + +int Q_atoi (char *str) +{ + int val; + int sign; + int c; + + if (*str == '-') + { + sign = -1; + str++; + } + else + sign = 1; + + val = 0; + +// +// check for hex +// + if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') ) + { + str += 2; + while (1) + { + c = *str++; + if (c >= '0' && c <= '9') + val = (val<<4) + c - '0'; + else if (c >= 'a' && c <= 'f') + val = (val<<4) + c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val = (val<<4) + c - 'A' + 10; + else + return val*sign; + } + } + +// +// check for character +// + if (str[0] == '\'') + { + return sign * str[1]; + } + +// +// assume decimal +// + while (1) + { + c = *str++; + if (c <'0' || c > '9') + return val*sign; + val = val*10 + c - '0'; + } + + return 0; +} + + +float Q_atof (char *str) +{ + double val; + int sign; + int c; + int decimal, total; + + if (*str == '-') + { + sign = -1; + str++; + } + else + sign = 1; + + val = 0; + +// +// check for hex +// + if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') ) + { + str += 2; + while (1) + { + c = *str++; + if (c >= '0' && c <= '9') + val = (val*16) + c - '0'; + else if (c >= 'a' && c <= 'f') + val = (val*16) + c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val = (val*16) + c - 'A' + 10; + else + return val*sign; + } + } + +// +// check for character +// + if (str[0] == '\'') + { + return sign * str[1]; + } + +// +// assume decimal +// + decimal = -1; + total = 0; + while (1) + { + c = *str++; + if (c == '.') + { + decimal = total; + continue; + } + if (c <'0' || c > '9') + break; + val = val*10 + c - '0'; + total++; + } + + if (decimal == -1) + return val*sign; + while (total > decimal) + { + val /= 10; + total--; + } + + return val*sign; +} diff --git a/common/lib_replace.h b/common/lib_replace.h new file mode 100644 index 0000000..460a370 --- /dev/null +++ b/common/lib_replace.h @@ -0,0 +1,55 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. +Copyright (C) 1999,2000 contributors of the QuakeForge project +Please see the file "AUTHORS" for a list of contributors + +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. + +*/ +// comndef.h -- general definitions + +#ifndef _LIB_REPLACE_H +#define _LIB_REPLACE_H + +//============================================================================ + +#define Q_memset(d, f, c) memset((d), (f), (c)) +#define Q_memcpy(d, s, c) memcpy((d), (s), (c)) +#define Q_memcmp(m1, m2, c) memcmp((m1), (m2), (c)) +#define Q_strcpy(d, s) strcpy((d), (s)) +#define Q_strncpy(d, s, n) strncpy((d), (s), (n)) +#define Q_strlen(s) ((int)strlen(s)) +#define Q_strrchr(s, c) strrchr((s), (c)) +#define Q_strcat(d, s) strcat((d), (s)) +#define Q_strcmp(s1, s2) strcmp((s1), (s2)) +#define Q_strncmp(s1, s2, n) strncmp((s1), (s2), (n)) + +#ifdef _WIN32 + +#define Q_strcasecmp(s1, s2) _stricmp((s1), (s2)) +#define Q_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n)) + +#else + +#define Q_strcasecmp(s1, s2) strcasecmp((s1), (s2)) +#define Q_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n)) + +#endif + +int Q_atoi (char *str); +float Q_atof (char *str); + +#endif // _LIB_REPLACE_H diff --git a/common/mathlib.c b/common/mathlib.c index 779e43a..b30e8b2 100644 --- a/common/mathlib.c +++ b/common/mathlib.c @@ -23,7 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // mathlib.c -- math primitives #include +#include "qtypes.h" #include "quakedef.h" +#include "mathlib.h" void Sys_Error (char *error, ...); @@ -34,7 +36,7 @@ int nanmask = 255<<23; #define DEG2RAD( a ) ( a * M_PI ) / 180.0F -void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal ) +static void ProjectPointOnPlane(vec3_t dst, const vec3_t p, const vec3_t normal) { float d; vec3_t n; @@ -56,7 +58,7 @@ void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal ) /* ** assumes "src" is normalized */ -void PerpendicularVector( vec3_t dst, const vec3_t src ) +static void PerpendicularVector( vec3_t dst, const vec3_t src ) { int pos; int i; diff --git a/common/mathlib.h b/common/mathlib.h index 304b958..57e5e41 100644 --- a/common/mathlib.h +++ b/common/mathlib.h @@ -23,13 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _MATHLIB_H #define _MATHLIB_H -typedef float vec_t; -typedef vec_t vec3_t[3]; -typedef vec_t vec5_t[5]; +#include -typedef int fixed4_t; -typedef int fixed8_t; -typedef int fixed16_t; #ifndef M_PI #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h @@ -38,7 +33,7 @@ typedef int fixed16_t; struct mplane_s; extern vec3_t vec3_origin; -extern int nanmask; +extern int nanmask; #define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask) @@ -47,36 +42,28 @@ extern int nanmask; #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 _DotProduct (vec3_t v1, vec3_t v2); -void _VectorSubtract (vec3_t veca, vec3_t vecb, vec3_t out); -void _VectorAdd (vec3_t veca, vec3_t vecb, vec3_t out); -void _VectorCopy (vec3_t in, vec3_t out); - -int VectorCompare (vec3_t v1, vec3_t v2); -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); -int Q_log2(int val); - -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); -fixed16_t Invert24To16(fixed16_t val); -fixed16_t Mul16_30(fixed16_t multiplier, fixed16_t multiplicand); -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); +void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees ); float anglemod(float a); - -void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees ); - +void BOPS_Error (void); +int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct mplane_s *plane); +void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up); +int VectorCompare (vec3_t v1, vec3_t v2); +void VectorMA (vec3_t veca, float scale, vec3_t vecb, vec3_t vecc); +vec_t _DotProduct (vec3_t v1, vec3_t v2); +void _VectorSubtract (vec3_t veca, vec3_t vecb, vec3_t out); +void _VectorAdd (vec3_t veca, vec3_t vecb, vec3_t out); +void _VectorCopy (vec3_t in, vec3_t out); +void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross); +vec_t Length (vec3_t v); +float VectorNormalize (vec3_t v); // returns vector length +void VectorInverse (vec3_t v); +void VectorScale (vec3_t in, vec_t scale, vec3_t out); +int Q_log2(int val); +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); +fixed16_t Invert24To16(fixed16_t val); #define BOX_ON_PLANE_SIDE(emins, emaxs, p) \ (((p)->type < 3)? \ diff --git a/common/model.h b/common/model.h index 16378e2..b50f058 100644 --- a/common/model.h +++ b/common/model.h @@ -23,9 +23,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef __MODEL__ #define __MODEL__ +#include "qdefs.h" +#include "qtypes.h" +#include "bspfile.h" #include "render.h" #include "modelgen.h" #include "spritegn.h" +#include "zone.h" /* diff --git a/common/modelgen.h b/common/modelgen.h index 56e6759..c475356 100644 --- a/common/modelgen.h +++ b/common/modelgen.h @@ -29,6 +29,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // * pass data from one to the other via model files. * // ********************************************************* +#ifndef _MODELGEN_H +#define _MODELGEN_H + #ifdef INCLUDELIBS #include @@ -52,7 +55,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef SYNCTYPE_T #define SYNCTYPE_T typedef enum {ST_SYNC=0, ST_RAND } synctype_t; -#endif +#endif // SYNCTYPE_T typedef enum { ALIAS_SINGLE=0, ALIAS_GROUP } aliasframetype_t; @@ -134,3 +137,4 @@ typedef struct { #define IDPOLYHEADER (('O'<<24)+('P'<<16)+('D'<<8)+'I') // little-endian "IDPO" +#endif // _MODELGEN_H diff --git a/common/net_ser.h b/common/net_ser.h index 5885ab9..d2ea0f3 100644 --- a/common/net_ser.h +++ b/common/net_ser.h @@ -19,6 +19,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // net_ser.h +#ifndef _NET_SER_H +#define _NET_SER_H + int Serial_Init (void); void Serial_Listen (qboolean state); void Serial_SearchForHosts (qboolean xmit); @@ -31,3 +34,5 @@ qboolean Serial_CanSendMessage (qsocket_t *sock); qboolean Serial_CanSendUnreliableMessage (qsocket_t *sock); void Serial_Close (qsocket_t *sock); void Serial_Shutdown (void); + +#endif // _NET_SER_H diff --git a/common/pr_comp.h b/common/pr_comp.h index 3a54df5..478d469 100644 --- a/common/pr_comp.h +++ b/common/pr_comp.h @@ -22,9 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // this file is shared by quake and qcc -typedef int func_t; -typedef int string_t; - typedef enum {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_function, ev_pointer} etype_t; diff --git a/common/qargs.c b/common/qargs.c new file mode 100644 index 0000000..69837ea --- /dev/null +++ b/common/qargs.c @@ -0,0 +1,111 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. +Portions Copyright (C) 1999,2000 Nelson Rush. +Copyright (C) 1999,2000 contributors of the QuakeForge project +Please see the file "AUTHORS" for a list of contributors + +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. + +*/ +// common.c -- misc functions used in client and server + +#include +#include +#include "common.h" +#include "crc.h" +#include "sys.h" +#include "cmd.h" +#include "console.h" + +usercmd_t nullcmd; // guarenteed to be zero + +static char *largv[MAX_NUM_ARGVS + NUM_SAFE_ARGVS + 1]; +static char *argvdummy = " "; + +static char *safeargvs[NUM_SAFE_ARGVS] = + {"-stdvid", "-nolan", "-nosound", "-nocdaudio", "-nojoy", "-nomouse"}; +int com_argc; +char **com_argv; + +/* +================ +COM_CheckParm + +Returns the position (1 to argc-1) in the program's argument list +where the given parameter apears, or 0 if not present +================ +*/ +int COM_CheckParm (char *parm) +{ + int i; + + for (i=1 ; i +#include + +#define MAX_QPATH 64 +#define MAX_CL_STATS 32 +#define NUM_CSHIFTS 4 +#define MAX_MODELS 256 +#define MAX_SOUNDS 256 +#define MAX_SCOREBOARDNAME 32 +#define MAX_NUM_ARGVS 50 +#define NUM_SAFE_ARGVS 7 + +#endif // _QDEFS_H diff --git a/common/qendian.c b/common/qendian.c new file mode 100644 index 0000000..326c3db --- /dev/null +++ b/common/qendian.c @@ -0,0 +1,95 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. +Portions Copyright (C) 1999,2000 Nelson Rush. +Copyright (C) 1999,2000 contributors of the QuakeForge project +Please see the file "AUTHORS" for a list of contributors + +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. + +*/ +// common.c -- misc functions used in client and server + +#include +#include "qtypes.h" + +/* +============================================================================ + + BYTE ORDER FUNCTIONS + +============================================================================ +*/ + +short (*BigShort) (short l); +short (*LittleShort) (short l); +int (*BigLong) (int l); +int (*LittleLong) (int l); +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; +} diff --git a/common/qendian.h b/common/qendian.h new file mode 100644 index 0000000..59f3fe8 --- /dev/null +++ b/common/qendian.h @@ -0,0 +1,62 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. +Copyright (C) 1999,2000 contributors of the QuakeForge project +Please see the file "AUTHORS" for a list of contributors + +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. + +*/ +// comndef.h -- general definitions + +#ifndef _QENDIAN_H +#define _QENDIAN_H + + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#define Q_MAXCHAR ((char)0x7f) +#define Q_MAXSHORT ((short)0x7fff) +#define Q_MAXINT ((int)0x7fffffff) +#define Q_MAXLONG ((int)0x7fffffff) +#define Q_MAXFLOAT ((int)0x7fffffff) + +#define Q_MINCHAR ((char)0x80) +#define Q_MINSHORT ((short)0x8000) +#define Q_MININT ((int)0x80000000) +#define Q_MINLONG ((int)0x80000000) +#define Q_MINFLOAT ((int)0x7fffffff) + +//============================================================================ + +extern short (*BigShort) (short l); +extern short (*LittleShort) (short l); +extern int (*BigLong) (int l); +extern int (*LittleLong) (int l); +extern float (*BigFloat) (float l); +extern float (*LittleFloat) (float l); + +short ShortSwap (short l); +short ShortNoSwap (short l); +int LongSwap (int l); +int LongNoSwap (int l); +float FloatSwap (float f); +float FloatNoSwap (float f); + +//============================================================================ + +#endif // _QENDIAN_H diff --git a/common/qstructs.h b/common/qstructs.h new file mode 100644 index 0000000..caefe6f --- /dev/null +++ b/common/qstructs.h @@ -0,0 +1,180 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. +Copyright (C) 1999,2000 contributors of the QuakeForge project +Please see the file "AUTHORS" for a list of contributors + +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. + +*/ +#ifndef _QSTRUCTS_H +#define _QSTRUCTS_H + +#include +#include +#include +#include + +//============================================================================= + +// the host system specifies the base of the directory tree, the +// command line parms passed to the program, and the amount of memory +// available for the program to use + +typedef struct +{ + char *basedir; + char *cachedir; // for development over ISDN lines + int argc; + char **argv; + void *membase; + int memsize; +} quakeparms_t; + +//============================================================================= + +typedef struct cvar_s +{ + char *name; + char *string; + qboolean archive; // set to true to cause it to be saved to vars.rc + qboolean info; // added to serverinfo or userinfo when changed + float value; + struct cvar_s *next; +} cvar_t; + +typedef struct +{ + int destcolor[3]; + int percent; // 0-256 +} cshift_t; + +#if defined(QUAKEWORLD) || defined(UQUAKE) +#include "client.h" +#endif + +// +// the client_state_t structure is wiped completely at every +// server signon +// +typedef struct +{ + int movemessages; // since connecting to this server + // throw out the first couple, so the player + // doesn't accidentally do something the + // first frame + +// information for local display + int stats[MAX_CL_STATS]; // health, etc + float item_gettime[32]; //cl.time of aquiring item, for blinking + float faceanimtime; // use anim frame if cl.time < this + + cshift_t cshifts[NUM_CSHIFTS]; // color shifts for damage, powerups + cshift_t prev_cshifts[NUM_CSHIFTS]; // and content types + +// the client maintains its own idea of view angles, which are +// sent to the server each frame. And only reset at level change +// and teleport times + vec3_t viewangles; + +// the client simulates or interpolates movement to get these values + double time; // this is the time value that the client + // is rendering at. allways <= realtime + +// pitch drifting vars + float pitchvel; + qboolean nodrift; + float driftmove; + double laststop; + + + qboolean paused; // send over by server + + int completed_time; // latched at intermission start + float punchangle; // temporar yview kick from weapon firing + int intermission; // don't change view angle, full screen, etc + +// +// information that is static for the entire time connected to a server +// + struct model_s *model_precache[MAX_MODELS]; + struct sfx_s *sound_precache[MAX_SOUNDS]; + + char levelname[40]; // for display on solo scoreboard + +// refresh related state + struct model_s *worldmodel; // cl_entitites[0].model + struct efrag_s *free_efrags; + int num_statics; // held in cl_staticentities array + + int cdtrack; // cd audio + + entity_t viewent; // weapon model + int playernum; + +#ifdef QUAKEWORLD +// QW specific! +// all player information + player_info_t players[MAX_CLIENTS]; + int servercount; // server identification for prespawns + + char serverinfo[MAX_SERVERINFO_STRING]; + + int parsecount; // server message counter + int validsequence; // this is the sequence number of the last good + // packetentity_t we got. If this is 0, we can't + // render a frame yet + int spectator; + + double last_ping_request; // while showing scoreboard + + frame_t frames[UPDATE_BACKUP]; + + vec3_t simorg; + vec3_t simvel; + vec3_t simangles; +// +// information that is static for the entire time connected to a server +// + char model_name[MAX_MODELS][MAX_QPATH]; + char sound_name[MAX_SOUNDS][MAX_QPATH]; +#elif defined(UQUAKE) +// UQ specific. + int num_entities; // held in cl_entities array + float last_received_message; // (realtime) for net trouble icon + double mtime[2]; // the timestamp of last two messages + double oldtime; // previous cl.time, time-oldtime is used + // to decay light values and smooth step ups + + qboolean onground; + float viewheight; + float idealpitch; + int maxclients; + int gametype; +// frag scoreboard + scoreboard_t *scores; // [cl.maxclients] + + usercmd_t cmd; // last command sent to the server + int items; // inventory bit flags + vec3_t mviewangles[2]; // during demo playback viewangles is lerped + // between these + vec3_t mvelocity[2]; // update by server, used for lean+bob + // (0 is newest) + vec3_t velocity; // lerped between mvelocity[0] and [1] +#endif +} client_state_t; + +extern client_state_t cl; +#endif // _QSTRUCTS_H diff --git a/common/qtypes.h b/common/qtypes.h new file mode 100644 index 0000000..2d867af --- /dev/null +++ b/common/qtypes.h @@ -0,0 +1,61 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. +Copyright (C) 1999,2000 contributors of the QuakeForge project +Please see the file "AUTHORS" for a list of contributors + +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. + +*/ +#ifndef _QTYPES_H +#define _QTYPES_H + +#include +#include +#include + +#define MAX_QPATH 64 + +typedef unsigned char byte; + +typedef enum {false, true} qboolean; + +// From mathlib... +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; + + +typedef int func_t; +typedef int string_t; +typedef byte pixel_t; + +/* +typedef enum {key_game, key_console, key_message, key_menu} keydest_t; +typedef enum { ALIAS_SINGLE=0, ALIAS_GROUP } aliasframetype_t; +typedef enum { ALIAS_SKIN_SINGLE=0, ALIAS_SKIN_GROUP } aliasskintype_t; +typedef enum {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_function, ev_pointer} etype_t; +typedef void (*builtin_t) (void); +typedef enum {touchessolid, drawnode, nodrawnode} solidstate_t; +typedef enum { ST_SYNC=0, ST_RAND } synctype_t; +typedef enum { SPR_SINGLE=0, SPR_GROUP } spriteframetype_t; +typedef enum {MS_WINDOWED, MS_FULLSCREEN, MS_FULLDIB, MS_UNINIT} modestate_t; +typedef enum {mod_brush, mod_sprite, mod_alias} modtype_t; +*/ + +#endif // _QTYPES_H diff --git a/common/quakefs.c b/common/quakefs.c new file mode 100644 index 0000000..f0d3a97 --- /dev/null +++ b/common/quakefs.c @@ -0,0 +1,771 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. +Portions Copyright (C) 1999,2000 Nelson Rush. +Copyright (C) 1999,2000 contributors of the QuakeForge project +Please see the file "AUTHORS" for a list of contributors + +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. + +*/ +// common.c -- misc functions used in client and server + +#include +#include "qtypes.h" +#include "quakefs.h" +#include "sys.h" +#include "console.h" +#include "common_quakedef.h" +#include "zone.h" +#include "common.h" +#include "draw.h" + +/* +All of Quake's data access is through a hierchal file system, but the contents of the file system can be transparently merged from several sources. + +The "base directory" is the path to the directory holding the quake.exe and all game directories. The sys_* files pass this to host_init in quakeparms_t->basedir. This can be overridden with the "-basedir" command line parm to allow code debugging in a different directory. The base directory is +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. +*/ + +/* +============================================================================= + +QUAKE FILESYSTEM + +============================================================================= +*/ + +/* Begin Generations */ +#ifdef _EXPERIMENTAL_ +#include "unzip.h" +#endif + +typedef unsigned char byte_t; +char gamedirfile[MAX_OSPATH]; + +#ifndef _AIX +typedef unsigned int uint_t; +typedef unsigned short ushort_t; +#endif +/* End Generations */ + +int com_filesize; + + +// +// in memory +// + +typedef struct +{ + char name[MAX_QPATH]; + int filepos, filelen; +} packfile_t; + +typedef struct pack_s +{ + char filename[MAX_OSPATH]; + FILE *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_gamedir[MAX_OSPATH]; +char com_basedir[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; +searchpath_t *com_base_searchpaths; // without gamedirs + +/* +================ +COM_filelength +================ +*/ +int COM_filelength (FILE *f) +{ + int pos; + int end; + + pos = ftell (f); + fseek (f, 0, SEEK_END); + end = ftell (f); + fseek (f, pos, SEEK_SET); + + return end; +} + +int COM_FileOpenRead (char *path, FILE **hndl) +{ + FILE *f; + + f = fopen(path, "rb"); + if (!f) + { + *hndl = NULL; + return -1; + } + *hndl = f; + + return COM_filelength(f); +} + +/* +============ +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 == com_base_searchpaths) + Con_Printf ("----------\n"); + if (s->pack) + Con_Printf ("%s (%i files)\n", s->pack->filename, s->pack->numfiles); + else + Con_Printf ("%s\n", s->filename); + } +} + +/* +============ +COM_WriteFile + +The filename will be prefixed by the current game directory +============ +*/ +void COM_WriteFile (char *filename, void *data, int len) +{ + FILE *f; + char name[MAX_OSPATH]; + + snprintf(name, sizeof(name), "%s/%s", com_gamedir, filename); + + f = fopen (name, "wb"); + if (!f) { + Sys_mkdir(com_gamedir); + f = fopen (name, "wb"); + if (!f) + Sys_Error ("Error opening %s", filename); + } + + Sys_Printf ("COM_WriteFile: %s\n", name); + fwrite (data, 1, len, f); + fclose (f); +} + + +/* +============ +COM_CreatePath + +Only used for CopyFile and download +============ +*/ +void COM_CreatePath (char *path) +{ + char *ofs; + + for (ofs = path+1 ; *ofs ; ofs++) + { + if (*ofs == '/') + { // create the directory + *ofs = 0; + Sys_mkdir (path); + *ofs = '/'; + } + } +} + + +/* +=========== +COM_CopyFile + +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) +{ + FILE *in, *out; + int remaining, count; + char buf[4096]; + + remaining = COM_FileOpenRead (netpath, &in); + COM_CreatePath (cachepath); // create directories up to the cache file + out = fopen(cachepath, "wb"); + if (!out) + Sys_Error ("Error opening %s", cachepath); + + while (remaining) + { + if (remaining < sizeof(buf)) + count = remaining; + else + count = sizeof(buf); + fread (buf, 1, count, in); + fwrite (buf, 1, count, out); + remaining -= count; + } + + fclose (in); + fclose (out); +} + +/* +=========== +COM_FindFile + +Finds the file in the search path. +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, FILE **file) +{ + searchpath_t *search; + char netpath[MAX_OSPATH]; + pack_t *pak; + int i; + int findtime; + + file_from_pak = 0; + +// +// search through the path, one element at a time +// + for (search = com_searchpaths ; 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 ; inumfiles ; i++) + if (!strcmp (pak->files[i].name, filename)) + { // found it! + if(developer.value) + Sys_Printf ("PackFile: %s : %s\n",pak->filename, filename); + // open a new file on the pakfile + *file = fopen (pak->filename, "rb"); + if (!*file) + Sys_Error ("Couldn't reopen %s", pak->filename); + fseek (*file, pak->files[i].filepos, SEEK_SET); + com_filesize = pak->files[i].filelen; + file_from_pak = 1; + return com_filesize; + } + } + else + { + // check a file in the directory tree + snprintf(netpath, sizeof(netpath), "%s/%s",search->filename, filename); + + findtime = Sys_FileTime (netpath); + if (findtime == -1) + continue; + + if(developer.value) + Sys_Printf ("FindFile: %s\n",netpath); + + *file = fopen (netpath, "rb"); + return COM_filelength (*file); + } + + } + + Sys_Printf ("FindFile: can't find %s\n", filename); + + *file = NULL; + com_filesize = -1; + return -1; +} + +/* +============ +COM_LoadFile + +Filename are reletive to the quake directory. +Allways appends a 0 byte to the loaded data. +============ +*/ +cache_user_t *loadcache; +byte *loadbuf; +int loadsize; +byte *COM_LoadFile (char *path, int usehunk) +{ + FILE *h; + byte *buf; + char base[32]; + int len; + + buf = NULL; // quiet compiler warning + +// look for it in the filesystem or pack files + len = com_filesize = COM_FOpenFile (path, &h); + if (!h) + return NULL; + +// 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; +#ifndef SERVERONLY + Draw_BeginDisc (); +#endif + fread (buf, 1, len, h); + fclose (h); +#ifndef SERVERONLY + Draw_EndDisc (); +#endif + + 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; + FILE *packhandle; + dpackfile_t info[MAX_FILES_IN_PACK]; + + if (COM_FileOpenRead (packfile, &packhandle) == -1) + return NULL; + + fread (&header, 1, sizeof(header), packhandle); + 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 %i files", packfile, numpackfiles); + + newfiles = Z_Malloc (numpackfiles * sizeof(packfile_t)); + + fseek (packhandle, header.dirofs, SEEK_SET); + fread (info, 1, header.dirlen, packhandle); + + +// parse the directory + for (i=0 ; ifilename, packfile); + pack->handle = packhandle; + pack->numfiles = numpackfiles; + pack->files = newfiles; + + Con_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles); + return pack; +} + +#ifdef _EXPERIMENTAL_ +int +COM_pak3_checkfile(unzFile *pak, const char *path) +{ + int status; + + status = unzLocateFile(pak, path, 2); + return (status == UNZ_OK); +} + +void +COM_pak3_closepak(unzFile *pak) +{ + if (pak) + unzClose(pak); + pak = NULL; +} + +void +COM_pak3_close(unzFile *pak) +{ + unzCloseCurrentFile(pak); +} + + + +int +COM_pak3_read(unzFile *pak, void *buf, uint_t size, uint_t nmemb) +{ + int len; + + len = unzReadCurrentFile(pak, buf, size * nmemb); + return len / size; +} + +int +COM_pak3_open(unzFile *pak, const char *path) +{ + if (unzLocateFile(pak, path, 2) != UNZ_OK) + return 0; + if (unzOpenCurrentFile(pak) != UNZ_OK) + return 0; + return 1; +} + +uint_t +COM_pak3_getlen(unzFile *pak) +{ + unz_file_info info; + + if (unzGetCurrentFileInfo(pak, &info, NULL, 0, NULL, 0, NULL, 0) + != UNZ_OK) + return 0; + return info.uncompressed_size; +} + +uint_t +COM_pak3_readfile(unzFile *pak, const char *path, uint_t bufsize, byte_t *buf) +{ + uint_t len; + + if (!COM_pak3_open(pak,path)) + return 0; + + if ((len = COM_pak3_getlen(pak)) != 0) + { + if (COM_pak3_read(pak, (void*)buf, 1, len) != len) + len = 0; + } + COM_pak3_close(pak); + return len; +} + +#endif + +// Todo: Make This work! :) +#if defined _EXPERIMENTAL_ && GENERATIONS +pack_t *COM_LoadQ3PackFile (char *packfile) +{ + + int i; + packfile_t *newfiles; + float numpackfiles; + unzFile *pak; + pack_t *pack_old; + int status; +// int packhandle; + dpackfile_t info[MAX_FILES_IN_PACK]; +// unz_file_info fileInfo; + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; +// int err; + + pak = unzOpen(packfile); + +// numpackfiles = header.dirlen / sizeof(dpackfile_t); +// numpackfiles = COM_pak3_getlen(*pak)/sizeof(unzFile); + numpackfiles = 0; +//= COM_pak3_getlen(pak)/sizeof(unzFile); + Con_Printf ("Assigned Numpackfiles\n"); + + if (!pak) + return NULL; + + newfiles = Hunk_AllocName (numpackfiles * sizeof(unzFile), "packfile"); + + status=unzGoToFirstFile(pak); + + while(status == UNZ_OK) { + unzGetCurrentFileInfo(pak,NULL,&szCurrentFileName,64,NULL,0,NULL,0); + + if(strcmp(newfiles[i].name, szCurrentFileName)==0) + break; + + strcpy (newfiles[i].name, szCurrentFileName); + Con_Printf ("strcpy'ed %s into newfiles[%i].name Ok\n",szCurrentFileName, i); + + newfiles[i].filepos = LittleLong(unztell(pak)); +// newfiles[i].filelen = LittleLong(COM_pak3_readfile(pak,packfile,64,64)); + + Con_Printf ("Added File\n"); + status=unzGoToNextFile(pak); + ++numpackfiles; + ++i; + } + + Con_Printf ("Added files in %s to game data Ok\n", packfile); + + pack_old = Hunk_Alloc (sizeof (pack_t)); + strcpy (pack_old->filename, packfile); + //pack_old->handle = unzGetLocalExtrafield(packfile, NULL, NULL); + pack_old->numfiles = numpackfiles; + pack_old->files = newfiles; + + Con_Printf ("Added packfile %s (%.0f files)\n", packfile, numpackfiles); + + COM_pak3_close(pak); + return pack_old; +} +#endif + +/* +================ +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]; + char *p; + + if ((p = strrchr(dir, '/')) != NULL) + strcpy(gamedirfile, ++p); + else + strcpy(gamedirfile, dir); + strcpy (com_gamedir, dir); + +// +// add the directory to the search path +// + search = Hunk_Alloc (sizeof(searchpath_t)); + 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++) + { + snprintf(pakfile, sizeof(pakfile), "%s/pak%i.pak", dir, i); + pak = COM_LoadPackFile (pakfile); + if (!pak) + break; + search = Hunk_Alloc (sizeof(searchpath_t)); + search->pack = pak; + search->next = com_searchpaths; + com_searchpaths = search; + } + +} + +/* +================ +COM_Gamedir + +Sets the gamedir and path to a different directory. +================ +*/ +void COM_Gamedir (char *dir) +{ + searchpath_t *search, *next; + int i; + pack_t *pak; + char pakfile[MAX_OSPATH]; + + if (strstr(dir, "..") || strstr(dir, "/") + || strstr(dir, "\\") || strstr(dir, ":") ) + { + Con_Printf ("Gamedir should be a single filename, not a path\n"); + return; + } + + if (!strcmp(gamedirfile, dir)) + return; // still the same + strcpy (gamedirfile, dir); + + // + // free up any current game dir info + // + while (com_searchpaths != com_base_searchpaths) + { + if (com_searchpaths->pack) + { + fclose (com_searchpaths->pack->handle); + Z_Free (com_searchpaths->pack->files); + Z_Free (com_searchpaths->pack); + } + next = com_searchpaths->next; + Z_Free (com_searchpaths); + com_searchpaths = next; + } + + // + // flush all data, so it will be forced to reload + // + Cache_Flush (); + + if (!strcmp(dir, GAMENAME) || !strcmp(dir, "qw")) + return; + + snprintf(com_gamedir, sizeof(com_gamedir), "%s/%s", com_basedir, dir); + + // + // add the directory to the search path + // + search = Z_Malloc (sizeof(searchpath_t)); + strcpy (search->filename, com_gamedir); + search->next = com_searchpaths; + com_searchpaths = search; + + // + // add any pak files in the format pak0.pak pak1.pak, ... + // + for (i=0 ; ; i++) + { + snprintf(pakfile, sizeof(pakfile), "%s/pak%i.pak", com_gamedir, i); + pak = COM_LoadPackFile (pakfile); + if (!pak) + break; + search = Z_Malloc (sizeof(searchpath_t)); + search->pack = pak; + search->next = com_searchpaths; + com_searchpaths = search; + } +} + +/* +================ +COM_InitFilesystem +================ +*/ +void COM_InitFilesystem (void) +{ + int i; + +// +// -basedir +// Overrides the system supplied base directory +// + i = COM_CheckParm ("-basedir"); + if (i && i < com_argc-1) + strcpy (com_basedir, com_argv[i+1]); + else + strcpy (com_basedir, host_parms.basedir); + +// +// start up with GAMENAME by default +// + COM_AddGameDirectory (va("%s/" GAMENAME, com_basedir) ); + COM_AddGameDirectory (va("%s/qw", com_basedir) ); + + // any set gamedirs will be freed up to here + com_base_searchpaths = com_searchpaths; +} diff --git a/common/quakefs.h b/common/quakefs.h new file mode 100644 index 0000000..cc8685b --- /dev/null +++ b/common/quakefs.h @@ -0,0 +1,48 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. +Copyright (C) 1999,2000 contributors of the QuakeForge project +Please see the file "AUTHORS" for a list of contributors + +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. + +*/ +// comndef.h -- general definitions + +#ifndef _QUAKEFS_H +#define _QUAKEFS_H + + +//============================================================================ + +#define MAX_OSPATH 128 // max length of a filesystem pathname + +extern int com_filesize; +struct cache_user_s; + +extern char com_gamedir[MAX_OSPATH]; + +void COM_WriteFile (char *filename, void *data, int len); +int COM_FOpenFile (char *filename, FILE **file); +void COM_CloseFile (FILE *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); +void COM_CreatePath (char *path); +void COM_Gamedir (char *dir); + +#endif // _QUAKEFS_H diff --git a/common/r_alias.c b/common/r_alias.c index 3aa4753..2973412 100644 --- a/common/r_alias.c +++ b/common/r_alias.c @@ -23,8 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" -#include "d_local.h" // FIXME: shouldn't be needed (is needed for patch - // right now, but that should move) +#include #define LIGHT_MIN 5 // lowest light value we'll allow, to avoid the // need for inner-loop light clamping diff --git a/common/r_bsp.c b/common/r_bsp.c index 0cb3838..5067d3a 100644 --- a/common/r_bsp.c +++ b/common/r_bsp.c @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" +#include // // current entity info diff --git a/common/r_draw.c b/common/r_draw.c index 487206b..a63b50a 100644 --- a/common/r_draw.c +++ b/common/r_draw.c @@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" -#include "d_local.h" // FIXME: shouldn't need to include this +#include #define MAXLEFTCLIPEDGES 100 diff --git a/common/r_light.c b/common/r_light.c index 8ac9429..554d924 100644 --- a/common/r_light.c +++ b/common/r_light.c @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" +#include int r_dlightframecount; diff --git a/common/r_local.h b/common/r_local.h index 28a1661..e2452b2 100644 --- a/common/r_local.h +++ b/common/r_local.h @@ -55,24 +55,6 @@ typedef struct { //=========================================================================== -extern cvar_t r_draworder; -extern cvar_t r_speeds; -extern cvar_t r_timegraph; -extern cvar_t r_graphheight; -extern cvar_t r_clearcolor; -extern cvar_t r_waterwarp; -extern cvar_t r_fullbright; -extern cvar_t r_drawentities; -extern cvar_t r_aliasstats; -extern cvar_t r_dspeeds; -extern cvar_t r_drawflat; -extern cvar_t r_ambient; -extern cvar_t r_reportsurfout; -extern cvar_t r_maxsurfs; -extern cvar_t r_numsurfs; -extern cvar_t r_reportedgeout; -extern cvar_t r_maxedges; -extern cvar_t r_numedges; #define XCENTERING (1.0 / 2.0) #define YCENTERING (1.0 / 2.0) diff --git a/common/r_main.c b/common/r_main.c index 3fb5267..d340c9c 100644 --- a/common/r_main.c +++ b/common/r_main.c @@ -23,6 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" +#include +#include +#include +#include +#include //#define PASSAGES diff --git a/common/r_shared.h b/common/r_shared.h index 9efe15b..16c756a 100644 --- a/common/r_shared.h +++ b/common/r_shared.h @@ -27,6 +27,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _R_SHARED_H_ #define _R_SHARED_H_ +#include "qtypes.h" +#include "d_iface.h" + #define MAXVERTS 16 // max points in a surface polygon #define MAXWORKINGVERTS (MAXVERTS+4) // max points in an intermediate // polygon (while processing) diff --git a/common/r_sky.c b/common/r_sky.c index 41f2097..e5b2cb7 100644 --- a/common/r_sky.c +++ b/common/r_sky.c @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" #include "d_local.h" +#include int iskyspeed = 8; diff --git a/common/r_surf.c b/common/r_surf.c index d9a90dc..4fa03eb 100644 --- a/common/r_surf.c +++ b/common/r_surf.c @@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" +#include +#include drawsurf_t r_drawsurf; diff --git a/common/register_check.c b/common/register_check.c index dae68db..a5d91db 100644 --- a/common/register_check.c +++ b/common/register_check.c @@ -29,6 +29,8 @@ Boston, MA 02111-1307, USA */ +#include "cvar.h" +#include "quakefs.h" #include "quakedef.h" cvar_t registered = {"registered", "0"}; @@ -50,7 +52,6 @@ register_check ( void ) { if (h) { Cvar_Set ("registered", "1"); - Con_Printf ("Playing registered version.\n"); - fclose (h); + fclose (h); } } diff --git a/common/render.h b/common/render.h index ccaa86f..32e1e9b 100644 --- a/common/render.h +++ b/common/render.h @@ -23,8 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _RENDER_H #define _RENDER_H +#include "qtypes.h" #include "vid.h" -#include "model.h" // refresh.h -- public interface to refresh functions @@ -43,6 +43,21 @@ typedef struct efrag_s struct efrag_s *entnext; } efrag_t; +// entity_state_t is the information conveyed from the server +// in an update message +typedef struct +{ + int number; // edict index + int flags; // nolerp, etc + vec3_t origin; + vec3_t angles; + int modelindex; + int frame; + int colormap; + int skinnum; + int effects; +} entity_state_t; + typedef struct entity_s { diff --git a/common/sbar.c b/common/sbar.c index ed00d72..b878e3a 100644 --- a/common/sbar.c +++ b/common/sbar.c @@ -23,6 +23,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // sbar.c -- status bar code #include "quakedef.h" +#include "qtypes.h" +#include "wad.h" +#include "common.h" +#include "client.h" +#include "draw.h" +#include "sbar.h" +#include "screen.h" int sb_updates; // if >= vid.numpages, no update needed diff --git a/common/skin.c b/common/skin.c index 1d40c82..86ff2de 100644 --- a/common/skin.c +++ b/common/skin.c @@ -21,7 +21,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "qtypes.h" #include "quakedef.h" +#include "cvar.h" +#include "client.h" +#include "console.h" cvar_t baseskin = {"baseskin", "base"}; cvar_t noskins = {"noskins", "0"}; diff --git a/common/snd_dma.c b/common/snd_dma.c index bb1b63d..cee5deb 100644 --- a/common/snd_dma.c +++ b/common/snd_dma.c @@ -21,8 +21,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // snd_dma.c -- main control for any streaming sound output device -#include "quakedef.h" +#include +#include +#include "qtypes.h" +#include "sound.h" +#include "mathlib.h" #include "model.h" +#include "lib_replace.h" +#include "cvar.h" +#include "cmd.h" +#include "sys.h" +#include "common_quakedef.h" +#include "qargs.h" #ifdef _WIN32 #include "winquake.h" @@ -36,9 +46,7 @@ void S_StopAllSounds(qboolean clear); void S_StopAllSoundsC(void); // QuakeWorld hack -#ifdef QUAKEWORLD #define viewentity playernum+1 -#endif // QUAKEWORLD // ======================================================================= // Internal sound data & structures diff --git a/common/snd_mem.c b/common/snd_mem.c index 97d29a8..71c248e 100644 --- a/common/snd_mem.c +++ b/common/snd_mem.c @@ -21,7 +21,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // snd_mem.c: sound caching -#include "quakedef.h" +#include "qtypes.h" +#include "sound.h" +#include "qendian.h" +#include "lib_replace.h" +#include "string.h" +#include "quakefs.h" +#include "sys.h" int cache_full_cycle; diff --git a/common/snd_mix.c b/common/snd_mix.c index f42ff31..3604c78 100644 --- a/common/snd_mix.c +++ b/common/snd_mix.c @@ -21,7 +21,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // snd_mix.c -- portable code to mix sounds for snd_dma.c -#include "quakedef.h" +#include "config.h" +#include "qtypes.h" +#include "sound.h" +#include "lib_replace.h" #ifdef _WIN32 #include "winquake.h" diff --git a/common/snd_null.c b/common/snd_null.c index a3e9f85..90ffc65 100644 --- a/common/snd_null.c +++ b/common/snd_null.c @@ -22,7 +22,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // snd_null.c -- include this instead of all the other snd_* files to have // no sound code whatsoever -#include "quakedef.h" +//#include "config.h" +//#include "common_quakedef.h" +#include "qtypes.h" +#include "sound.h" // ======================================================================= // Various variables also defined in snd_dma.c diff --git a/common/snd_oss.c b/common/snd_oss.c index 1e74585..8b63a59 100644 --- a/common/snd_oss.c +++ b/common/snd_oss.c @@ -19,7 +19,10 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "quakedef.h" +#include "config.h" +#include "qtypes.h" +#include "sound.h" +#include "qargs.h" #include #include diff --git a/common/sound.h b/common/sound.h index 4937410..279b395 100644 --- a/common/sound.h +++ b/common/sound.h @@ -24,6 +24,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef __SOUND__ #define __SOUND__ +#include +#include +#include +#include + #define DEFAULT_SOUND_PACKET_VOLUME 255 #define DEFAULT_SOUND_PACKET_ATTENUATION 1.0 diff --git a/common/sw_rpart.c b/common/sw_rpart.c index 6ef8177..ef23641 100644 --- a/common/sw_rpart.c +++ b/common/sw_rpart.c @@ -25,6 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "r_local.h" #include "d_iface.h" +#include "glquake.h" +#include extern particle_t *active_particles, *free_particles; extern int ramp1[8], ramp2[8], ramp3[8]; diff --git a/common/sw_view.c b/common/sw_view.c index 74da474..391931a 100644 --- a/common/sw_view.c +++ b/common/sw_view.c @@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" +#include +#include extern int onground; diff --git a/common/sys_linux.c b/common/sys_linux.c index 4cbbe69..9ef4349 100644 --- a/common/sys_linux.c +++ b/common/sys_linux.c @@ -43,6 +43,9 @@ #include #include +#include "qtypes.h" +#include "sys.h" +#include "common.h" #ifndef QUAKEWORLD qboolean isDedicated; diff --git a/common/vid.h b/common/vid.h index 731982a..ecd5393 100644 --- a/common/vid.h +++ b/common/vid.h @@ -28,8 +28,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define VID_GRADES (1 << VID_CBITS) // a pixel can be one, two, or four bytes -typedef byte pixel_t; - typedef struct vrect_s { int x,y,width,height; diff --git a/common/vid_ggi.c b/common/vid_ggi.c index ce572f2..0f37cc1 100644 --- a/common/vid_ggi.c +++ b/common/vid_ggi.c @@ -31,6 +31,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "d_local.h" +#include +#include +#include +#include viddef_t vid; // global video state unsigned short d_8to16table[256]; diff --git a/common/vid_svgalib.c b/common/vid_svgalib.c index 2ce0828..111ea0c 100644 --- a/common/vid_svgalib.c +++ b/common/vid_svgalib.c @@ -25,6 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "d_local.h" +#include +#include #include #ifdef HAVE_UNISTD_H diff --git a/common/vid_x.c b/common/vid_x.c index c7f8e22..a9e3228 100644 --- a/common/vid_x.c +++ b/common/vid_x.c @@ -45,6 +45,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "d_local.h" +#include +#include +#include +#include cvar_t _windowed_mouse = {"_windowed_mouse","0", true}; cvar_t m_filter = {"m_filter","0", true}; diff --git a/common/wad.c b/common/wad.c index 9c51b74..73735df 100644 --- a/common/wad.c +++ b/common/wad.c @@ -21,7 +21,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // wad.c +#include "qtypes.h" #include "quakedef.h" +#include "wad.h" +#include "quakefs.h" +#include "qendian.h" +#include "sys.h" int wad_numlumps; lumpinfo_t *wad_lumps; diff --git a/common/wad.h b/common/wad.h index f356b76..7a5bc9c 100644 --- a/common/wad.h +++ b/common/wad.h @@ -21,6 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // wad.h +#ifndef _WAD_H +#define _WAD_H + //=============== // TYPES //=============== @@ -75,3 +78,5 @@ void *W_GetLumpName (char *name); void *W_GetLumpNum (int num); void SwapPic (qpic_t *pic); + +#endif // _WAD_H diff --git a/common/zone.c b/common/zone.c index 8bbb2c0..2c1f9d0 100644 --- a/common/zone.c +++ b/common/zone.c @@ -21,7 +21,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Z_zone.c +#include "qtypes.h" #include "quakedef.h" +#include "sys.h" +#include "lib_replace.h" +#include "common.h" +#include "console.h" +#include "cmd.h" //#define DYNAMIC_SIZE 0xc000 #define DYNAMIC_SIZE 0x20000 diff --git a/configure.in b/configure.in index fb51ed4..2000cf2 100644 --- a/configure.in +++ b/configure.in @@ -3,7 +3,7 @@ AC_PREREQ(2.13) AC_INIT(common/crc.h) dnl Version of this release -QF_VERSION=0.1-pre +QF_VERSION=0.1.1-devel VERSION=2.40 AC_DEFINE_UNQUOTED(QF_VERSION,"$QF_VERSION") AC_DEFINE_UNQUOTED(VERSION,"$VERSION") @@ -495,11 +495,11 @@ esac dnl Check for sound libraries AC_CHECK_LIB(mme,waveOutOpen,HAVE_LIBMME=yes) -SND_LIBS="" -SND_STYLE="" +SOUND_LIBS="" +SOUND_STYLE="" AC_MSG_CHECKING(for sound support) if test "x$enable_alsa" = "xyes"; then - if test -z "$SND_STYLE" -a "x$ac_cv_header_sys_asoundlib_h" = "xyes"; then + if test -z "$SOUND_STYLE" -a "x$ac_cv_header_sys_asoundlib_h" = "xyes"; then AC_EGREP_CPP([QF_maGiC_VALUE],[ #include #if defined(SND_LIB_MAJOR) && defined(SND_LIB_MINOR) @@ -507,55 +507,55 @@ if test "x$enable_alsa" = "xyes"; then QF_maGiC_VALUE #endif #endif - ],[ SND_STYLE="ALSA" SND_LIBS="-lasound"]) + ],[ SOUND_STYLE="ALSA" SOUND_LIBS="-lasound"]) fi fi -if test -z "$SND_STYLE" -a "x$ac_cv_header_sys_soundcard_h" = "xyes"; then +if test -z "$SOUND_STYLE" -a "x$ac_cv_header_sys_soundcard_h" = "xyes"; then AC_EGREP_CPP([QF_maGiC_VALUE],[ #include #ifdef SNDCTL_DSP_SETTRIGGER QF_maGiC_VALUE #endif - ], SND_STYLE="OSS") + ], SOUND_STYLE="OSS") fi -if test -z "$SND_STYLE" -a "x$ac_cv_header_linux_soundcard_h" = "xyes"; then +if test -z "$SOUND_STYLE" -a "x$ac_cv_header_linux_soundcard_h" = "xyes"; then AC_EGREP_CPP([QF_maGiC_VALUE],[ #include #ifdef SNDCTL_DSP_SETTRIGGER QF_maGiC_VALUE #endif - ], SND_STYLE="OSS") + ], SOUND_STYLE="OSS") fi -if test -z "$SND_STYLE" -a "x$ac_cv_header_machine_soundcard_h" = "xyes"; then +if test -z "$SOUND_STYLE" -a "x$ac_cv_header_machine_soundcard_h" = "xyes"; then AC_EGREP_CPP([QF_maGiC_VALUE],[ #include #ifdef SNDCTL_DSP_SETTRIGGER QF_maGiC_VALUE #endif - ], SND_STYLE="OSS") + ], SOUND_STYLE="OSS") fi -if test -z "$SND_STYLE" -a "x$ac_cv_header_sys_audioio_h" = "xyes"; then +if test -z "$SOUND_STYLE" -a "x$ac_cv_header_sys_audioio_h" = "xyes"; then AC_EGREP_CPP([QF_maGiC_VALUE],[ #include #ifdef AUDIO_SETINFO QF_maGiC_VALUE #endif - ], SND_STYLE="Solaris") + ], SOUND_STYLE="Solaris") fi -if test -z "$SND_STYLE" -a "x$ac_cv_header_mme_mmsystem_h" = "xyes" -a \ +if test -z "$SOUND_STYLE" -a "x$ac_cv_header_mme_mmsystem_h" = "xyes" -a \ "x$HAVE_LIBMME" = "xyes"; then AC_EGREP_CPP([QF_maGiC_VALUE],[ #include #ifdef WAVE_OPEN_SHAREABLE QF_maGiC_VALUE #endif - ], SND_STYLE="MME" - SND_LIBS="-lmme") + ], SOUND_STYLE="MME" + SOUND_LIBS="-lmme") fi -if test -z "$SND_STYLE" -a "x$ac_cv_header_windows_h" = "xyes" -a \ +if test -z "$SOUND_STYLE" -a "x$ac_cv_header_windows_h" = "xyes" -a \ "x$ac_cv_header_mmsystem_h" = "xyes"; then AC_EGREP_CPP([QF_maGiC_VALUE],[ #include @@ -565,14 +565,15 @@ if test -z "$SND_STYLE" -a "x$ac_cv_header_windows_h" = "xyes" -a \ QF_maGiC_VALUE #endif #endif - ], SND_STYLE="Windows" - SND_LIBS="-lwinmm") + ], SOUND_STYLE="Windows" + SOUND_LIBS="-lwinmm") fi -if test "x$SND_STYLE" = "x"; then +if test "x$SOUND_STYLE" = "x"; then AC_MSG_RESULT(no) + SOUND_STYLE="NULL" else - AC_MSG_RESULT(yes ($SND_STYLE style)) + AC_MSG_RESULT(yes ($SOUND_STYLE style)) fi @@ -730,8 +731,8 @@ AC_SUBST(TDFXGL_LIBS) AC_SUBST(HAS_SDL) AC_SUBST(SDL_CFLAGS) AC_SUBST(SDL_LIBS) -AC_SUBST(SND_STYLE) -AC_SUBST(SND_LIBS) +AC_SUBST(SOUND_STYLE) +AC_SUBST(SOUND_LIBS) AC_SUBST(DYN_LIBS) AC_SUBST(INTEL_ARCH) AC_SUBST(NET_LIBS) @@ -750,6 +751,7 @@ AC_OUTPUT( qw_client/Makefile qw_server/Makefile uquake/Makefile + common/Makefile Makefile rpm/quakeforge.spec rpm/build_rpm diff --git a/qw_client/Makefile.in b/qw_client/Makefile.in index 96aac11..149554c 100644 --- a/qw_client/Makefile.in +++ b/qw_client/Makefile.in @@ -3,24 +3,26 @@ # Quake general stuff # -PROJECT_DIR = @top_srcdir@ -PROJECT_ODIR = .. -SRC_DIR = @srcdir@ -QW_COMMON_DIR = $(PROJECT_DIR)/qw_common -COMMON_DIR = $(PROJECT_DIR)/common -COMMON_ODIR = $(PROJECT_ODIR)/common -BIN_PREFIX = qw-client +PROJECT_DIR := @top_srcdir@ +PROJECT_ODIR := .. +SRC_DIR := @srcdir@ +QW_COMMON_DIR := $(PROJECT_DIR)/qw_common +COMMON_DIR := $(PROJECT_DIR)/common +COMMON_ODIR := $(PROJECT_ODIR)/common +BIN_PREFIX := qw-client -DESTDIR = +DESTDIR := -prefix = @prefix@ -exec_prefix = @exec_prefix@ -bindir = @bindir@ -mandir = @mandir@ +prefix := @prefix@ +exec_prefix := @exec_prefix@ +bindir := @bindir@ +mandir := @mandir@ -BUILD_DIR = $(PROJECT_ODIR)/targets/qw_client +TARGET_DIR := $(PROJECT_ODIR)/targets +BUILD_DIR := $(TARGET_DIR)/qw_client +OBJ_PATTERN := $(shell echo $(BUILD_DIR)/{gl,soft,common_lib}/%.o) -LDFLAGS = @LDFLAGS@ @SND_LIBS@ @NET_LIBS@ -lm +LDFLAGS = @LDFLAGS@ @NET_LIBS@ -lm LIBS = @LIBS@ CC = @CC@ INTEL_ARCH = @INTEL_ARCH@ @@ -113,7 +115,6 @@ CL_ADDITIONAL_GENERAL_SRC = sys_dosa.s math.s SWREND_SRC_PLAT = d_draw.s d_draw16.s d_parta.s d_polysa.s d_scana.s \ d_spr8.s d_varsa.s r_aclipa.s r_aliasa.s \ r_drawa.s r_edgea.s r_varsa.s surf16.s surf8.s -XTRA_SND_SRC = snd_mixa.s else # Source files for non-Intel platforms @@ -125,29 +126,6 @@ endif CD_AUDIO_SRC = cd_wrapper.c -# Sound source - -SND_STYLE = @SND_STYLE@ -SND_SRC = snd_null.c - -ifeq ($(SND_STYLE),ALSA) -SND_SRC = snd_dma.c snd_alsa.c -endif -ifeq ($(SND_STYLE),OSS) -SND_SRC = snd_dma.c snd_oss.c -endif -ifeq ($(SND_STYLE),Solaris) -SND_SRC = snd_dma.c snd_sun.c -endif -ifeq ($(SND_STYLE),MME) -SND_SRC = snd_dma.c snd_mme.c -endif -ifeq ($(SND_STYLE),Windows) -SND_SRC = snd_dma.c snd_win.c -endif - -SND_SRC += snd_mem.c snd_mix.c $(XTRA_SND_SRC) - SYS_SRC = sys_common.c @QW_CL_SYS_SRC@ # Networking source files @@ -160,7 +138,7 @@ 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 + wad.c zone.c cvars.c qendian.c lib_replace.c quakefs.c qargs.c # GL renderer source @@ -194,7 +172,7 @@ QW_GENERAL_SRC = pmove.c pmovetst.c # Source common to QW/UQuake CL_COMMON_SRC = $(MISC_SRC) $(CL_GUI_SRC) $(CL_SRC) \ - $(CL_ADDITIONAL_GENERAL_SRC) $(SND_SRC) r_part.c + $(CL_ADDITIONAL_GENERAL_SRC) $(CD_AUDIO_SRC) r_part.c ######################################################################## @@ -216,62 +194,31 @@ GENERAL_SRC = $(CL_COMMON_SRC) \ # Compilation rules # -# Common lib targets. - -$(BUILD_DIR)/common_lib/%.@OBJEXT@: $(SRC_DIR)/%.c +$(OBJ_PATTERN): $(SRC_DIR)/%.c $(CC) $(CFLAGS) -o $@ -c $< -$(BUILD_DIR)/common_lib/%.@OBJEXT@: $(SRC_DIR)/%.s +$(OBJ_PATTERN): $(SRC_DIR)/%.s $(CC) $(CFLAGS) -x assembler-with-cpp -o $@ -c $< -$(BUILD_DIR)/common_lib/%.@OBJEXT@: $(COMMON_DIR)/%.c +$(OBJ_PATTERN): $(COMMON_DIR)/%.c $(CC) $(CFLAGS) -o $@ -c $< -$(BUILD_DIR)/common_lib/%.@OBJEXT@: $(COMMON_DIR)/%.s +$(OBJ_PATTERN): $(COMMON_DIR)/%.s $(CC) $(CFLAGS) -x assembler-with-cpp -o $@ -c $< -$(BUILD_DIR)/common_lib/%.o: $(QW_COMMON_DIR)/%.c +$(OBJ_PATTERN): $(QW_COMMON_DIR)/%.c $(CC) $(CFLAGS) -o $@ -c $< # Software targets soft_DIR: @DIR=soft; $(MAKE_SURE_DIR) -$(BUILD_DIR)/soft/%.@OBJEXT@: $(SRC_DIR)/%.c - $(CC) $(CFLAGS) -o $@ -c $< - -$(BUILD_DIR)/soft/%.@OBJEXT@: $(SRC_DIR)/%.s - $(CC) $(CFLAGS) -x assembler-with-cpp -o $@ -c $< - -$(BUILD_DIR)/soft/%.@OBJEXT@: $(COMMON_DIR)/%.c - $(CC) $(CFLAGS) -o $@ -c $< - -$(BUILD_DIR)/soft/%.@OBJEXT@: $(COMMON_DIR)/%.s - $(CC) $(CFLAGS) -x assembler-with-cpp -o $@ -c $< - -$(BUILD_DIR)/soft/%.o: $(QW_COMMON_DIR)/%.c - $(CC) $(CFLAGS) -o $@ -c $< # GL targets gl_DIR: @DIR=gl; $(MAKE_SURE_DIR) -$(BUILD_DIR)/gl/%.@OBJEXT@: $(SRC_DIR)/%.c - $(CC) $(CFLAGS) $(GL_CFLAGS) -o $@ -c $< - -$(BUILD_DIR)/gl/%.@OBJEXT@: $(SRC_DIR)/%.s - $(CC) $(CFLAGS) -x assembler-with-cpp -o $@ -c $< - -$(BUILD_DIR)/gl/%.@OBJEXT@: $(COMMON_DIR)/%.c - $(CC) $(CFLAGS) $(GL_CFLAGS) -o $@ -c $< - -$(BUILD_DIR)/gl/%.@OBJEXT@: $(COMMON_DIR)/%.s - $(CC) $(CFLAGS) -x assembler-with-cpp -o $@ -c $< - -$(BUILD_DIR)/gl/%.o: $(QW_COMMON_DIR)/%.c - $(CC) $(CFLAGS) -o $@ -c $< - ########################################################################### # # Specific target rules @@ -286,7 +233,7 @@ common_lib_DIR: $(COMMON_LIB): common_lib_DIR $(BUILD_DIR)/common_lib.a -$(BUILD_DIR)/common_lib.a: $(ALL_COMMON_LIB_OBJS) +$(BUILD_DIR)/common_lib.a: common_lib_DIR $(ALL_COMMON_LIB_OBJS) ar cru $@ $(ALL_COMMON_LIB_OBJS) ranlib $@ @@ -294,11 +241,11 @@ $(BUILD_DIR)/common_lib.a: $(ALL_COMMON_LIB_OBJS) ifneq ($(X11QUAKE),) -ALL_X11_SRC = $(CD_AUDIO_SRC) $(SW_REND_SRC) @X11_VID_SRC@\ +ALL_X11_SRC = $(SW_REND_SRC) @X11_VID_SRC@\ model.c ALL_X11_OBJS = $(patsubst %,$(BUILD_DIR)/soft/%,$(addsuffix .@OBJEXT@,\ $(basename $(ALL_X11_SRC) .c .s))) \ - $(BUILD_DIR)/common_lib.a + $(BUILD_DIR)/common_lib.a $(TARGET_DIR)/sound_lib.a X11_CFLAGS = -DX11 @X_CFLAGS@ X11_LDFLAGS = @X_LIBS@ -lX11 @X11_SHM_LIB@ @X_EXTRA_LIBS@ @@ -322,11 +269,11 @@ endif # SVGALib software target ifneq ($(SVGAQUAKE),) -ALL_SVGA_SRC = $(CD_AUDIO_SRC) $(SW_REND_SRC) \ +ALL_SVGA_SRC = $(SW_REND_SRC) \ vid_svgalib.c in_svgalib.c d_copy.s model.c ALL_SVGA_OBJS = $(patsubst %,$(BUILD_DIR)/soft/%,$(addsuffix .@OBJEXT@,\ $(basename $(ALL_SVGA_SRC) .c .s))) \ - $(BUILD_DIR)/common_lib.a + $(BUILD_DIR)/common_lib.a $(TARGET_DIR)/sound_lib.a SVGA_CFLAGS = @SVGA_CFLAGS@ SVGA_LDFLAGS = @SVGA_LIBS@ @@ -351,11 +298,11 @@ endif ifneq ($(GGIQUAKE),) # Map the list of source files into a list of object files -ALL_GGI_SRC = $(CD_AUDIO_SRC) $(SW_REND_SRC) vid_ggi.c\ +ALL_GGI_SRC = $(SW_REND_SRC) vid_ggi.c\ model.c ALL_GGI_OBJS = $(patsubst %,$(BUILD_DIR)/soft/%,$(addsuffix .@OBJEXT@,\ $(basename $(ALL_GGI_SRC) .c .s))) \ - $(BUILD_DIR)/common_lib.a + $(BUILD_DIR)/common_lib.a $(TARGET_DIR)/sound_lib.a GGI_SRC = vid_ggi.c GGI_CFLAGS = -DGGI @GGI_CFLAGS@ @@ -379,7 +326,7 @@ ALL_SDL_SRC = $(SW_REND_SRC) $(SDL_SRC) vid_sdl.c cd_sdl.c\ model.c ALL_SDL_OBJS = $(patsubst %,$(BUILD_DIR)/soft/%,$(addsuffix .@OBJEXT@,\ $(basename $(ALL_SDL_SRC) .c .s))) \ - $(BUILD_DIR)/common_lib.a + $(BUILD_DIR)/common_lib.a $(TARGET_DIR)/sound_lib.a SDL_CFLAGS = @SDL_CFLAGS@ -DSDL SDL_LDFLAGS = @SDL_LIBS@ @@ -403,11 +350,11 @@ endif ifneq ($(MGLQUAKE),) # Map the list of source files into a list of object files -ALL_MGL_SRC = $(CD_AUDIO_SRC) $(SW_REND_SRC) \ +ALL_MGL_SRC = $(SW_REND_SRC) \ vid_win.c in_win.c model.c ALL_MGL_OBJS = $(patsubst %,$(BUILD_DIR)/soft/%,$(addsuffix .@OBJEXT@,\ $(basename $(ALL_MGL_SRC) .c .s))) \ - $(BUILD_DIR)/common_lib.a + $(BUILD_DIR)/common_lib.a $(TARGET_DIR)/sound_lib.a MGL_CFLAGS = -DMGL @MGL_CFLAGS@ MGL_LDFLAGS = @MGL_LIBS@ -lm @@ -426,11 +373,11 @@ endif # X11 GL target ifneq ($(GLQUAKE),) -ALL_GL_SRC = $(CD_AUDIO_SRC) $(GL_REND_SRC) \ +ALL_GL_SRC = $(GL_REND_SRC) \ gl_vidglx.c dga_check.c ALL_GL_OBJS = $(patsubst %,$(BUILD_DIR)/gl/%,$(addsuffix .@OBJEXT@,\ $(basename $(ALL_GL_SRC) .c .s))) \ - $(BUILD_DIR)/common_lib.a + $(BUILD_DIR)/common_lib.a $(TARGET_DIR)/sound_lib.a GL_CFLAGS = @OGL_CFLAGS@ GL_LDFLAGS = $(X11_LDFLAGS) @OGL_LIBS@ @DGA_LIBS@ @DYN_LIBS@ @@ -453,11 +400,11 @@ endif # 3Dfx GL MCD target ifneq ($(TDFXQUAKE),) -ALL_TDFX_SRC = $(CD_AUDIO_SRC) $(GL_REND_SRC) \ +ALL_TDFX_SRC = $(GL_REND_SRC) \ gl_vidlinux_3dfx.c in_svgalib.c ALL_TDFX_OBJS = $(patsubst %,$(BUILD_DIR)/gl/%,$(addsuffix .@OBJEXT@,\ $(basename $(ALL_TDFX_SRC) .c .s))) \ - $(BUILD_DIR)/common_lib.a + $(BUILD_DIR)/common_lib.a $(TARGET_DIR)/sound_lib.a TDFX_CFLAGS = @OGL_CFLAGS@ @GLIDE_CFLAGS@ TDFX_LDFLAGS = @SVGA_LIBS@ @TDFXGL_LIBS@ @@ -494,7 +441,7 @@ clean: clean-soft clean-gl clean-common_lib $(CLEAN_TARGETS) install: $(targets) $(PROJECT_DIR)/mkinstalldirs $(DESTDIR)/$(bindir) for i in $(targets); do \ - $(PROJECT_DIR)/install-sh -m 755 $(BUILD_DIR)/../$$i \ + $(PROJECT_DIR)/install-sh -m 755 $(TARGET_DIR)/$$i \ $(DESTDIR)/$(bindir)/$$i; \ done diff --git a/qw_client/cl_cam.c b/qw_client/cl_cam.c index 3d542ca..8ed7d97 100644 --- a/qw_client/cl_cam.c +++ b/qw_client/cl_cam.c @@ -28,8 +28,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Player moves as a spectator, but the camera tracks and enemy player */ +#include "qtypes.h" #include "quakedef.h" #include "winquake.h" +#include "mathlib.h" +#include "client.h" +#include "sbar.h" +#include "cvar.h" +#include "console.h" #define PM_SPECTATORMAXSPEED 500 #define PM_STOPSPEED 100 diff --git a/qw_client/cl_demo.c b/qw_client/cl_demo.c index db20af0..02fb80f 100644 --- a/qw_client/cl_demo.c +++ b/qw_client/cl_demo.c @@ -23,6 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "pmove_simple.h" +#include "qtypes.h" +#include "client.h" +#include "console.h" void CL_FinishTimeDemo (void); diff --git a/qw_client/cl_ents.c b/qw_client/cl_ents.c index 7c43e68..812e11b 100644 --- a/qw_client/cl_ents.c +++ b/qw_client/cl_ents.c @@ -21,7 +21,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // cl_ents.c -- entity parsing and management +#include "qtypes.h" #include "quakedef.h" +#include "cvar.h" +#include "client.h" +#include "console.h" +#include "mathlib.h" +#include "view.h" +#include "cvars.h" extern cvar_t cl_predict_players; extern cvar_t cl_predict_players2; diff --git a/qw_client/cl_input.c b/qw_client/cl_input.c index 400788a..965c0a9 100644 --- a/qw_client/cl_input.c +++ b/qw_client/cl_input.c @@ -22,6 +22,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // cl.input.c -- builds an intended movement command to send to the server #include "quakedef.h" +#include "qtypes.h" +#include "client.h" +#include "console.h" +#include "mathlib.h" +#include "cvar.h" +#include "input.h" cvar_t cl_nodelta = {"cl_nodelta","0"}; diff --git a/qw_client/cl_main.c b/qw_client/cl_main.c index 23a490c..52d8717 100644 --- a/qw_client/cl_main.c +++ b/qw_client/cl_main.c @@ -27,6 +27,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "winquake.h" #include "pmove_simple.h" +#include "qtypes.h" +#include "client.h" +#include "menu.h" +#include "console.h" +#include "cvar.h" +#include "mathlib.h" +#include "keys.h" +#include "sound.h" +#include "input.h" +#include "screen.h" +#include "view.h" +#include "sbar.h" +#include "cdaudio.h" #ifdef __sun /* Sun's model_t in sys/model.h conflicts w/ Quake's model_t */ diff --git a/qw_client/cl_parse.c b/qw_client/cl_parse.c index e29eb3a..8a48e25 100644 --- a/qw_client/cl_parse.c +++ b/qw_client/cl_parse.c @@ -22,9 +22,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // cl_parse.c -- parse a message received from the server +#include "qtypes.h" #include "quakedef.h" #include "model.h" #include "pmove.h" +#include "glquake.h" +#include "console.h" +#include "mathlib.h" +#include "sound.h" +#include "cdaudio.h" +#include "sbar.h" +#include "screen.h" char *svc_strings[] = { @@ -1036,7 +1044,6 @@ void CL_ParseServerMessage (void) int i, j; received_framecount = host_framecount; - cl.last_servermessage = realtime; CL_ClearProjectiles (); // diff --git a/qw_client/cl_pred.c b/qw_client/cl_pred.c index 6bc676a..297b6ce 100644 --- a/qw_client/cl_pred.c +++ b/qw_client/cl_pred.c @@ -20,8 +20,13 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "qtypes.h" #include "quakedef.h" #include "winquake.h" +#include "cvar.h" +#include "client.h" +#include "console.h" +#include "mathlib.h" cvar_t cl_nopred = {"cl_nopred","0"}; cvar_t cl_pushlatency = {"pushlatency","-999"}; diff --git a/qw_client/cl_tent.c b/qw_client/cl_tent.c index 0d6a44c..9b2436c 100644 --- a/qw_client/cl_tent.c +++ b/qw_client/cl_tent.c @@ -21,8 +21,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // cl_tent.c -- client side temporary entities +#include "qtypes.h" #include "quakedef.h" #include "model.h" +#include "sound.h" +#include "client.h" +#include "mathlib.h" +#include "console.h" #define MAX_BEAMS 8 diff --git a/qw_client/d_edge.c b/qw_client/d_edge.c index a986ec4..f54f7b8 100644 --- a/qw_client/d_edge.c +++ b/qw_client/d_edge.c @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "d_local.h" +#include static int miplevel; diff --git a/qw_client/gl_model.c b/qw_client/gl_model.c index d180516..4e16d2d 100644 --- a/qw_client/gl_model.c +++ b/qw_client/gl_model.c @@ -25,8 +25,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // models are the only shared resource between a client and server running // on the same machine. +#include "qtypes.h" #include "quakedef.h" +#include "cvar.h" +#include "sys.h" +#include "mathlib.h" #include "glquake.h" +#include "qendian.h" +#include "lib_replace.h" +#include "d_iface.h" +#include "common.h" +#include "crc.h" +#include "console.h" model_t *loadmodel; char loadname[32]; // for hunk tags diff --git a/qw_client/gl_ngraph.c b/qw_client/gl_ngraph.c index 7014e4b..9f30fcd 100644 --- a/qw_client/gl_ngraph.c +++ b/qw_client/gl_ngraph.c @@ -22,8 +22,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // gl_ngraph.c +#include "qtypes.h" #include "quakedef.h" #include "glquake.h" +#include "sbar.h" +#include "menu.h" +#include "draw.h" extern byte *draw_chars; // 8*8 graphic characters diff --git a/qw_client/gl_rlight.c b/qw_client/gl_rlight.c index 4d4da2e..adcc9a8 100644 --- a/qw_client/gl_rlight.c +++ b/qw_client/gl_rlight.c @@ -21,8 +21,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // r_light.c +#include "qtypes.h" #include "quakedef.h" #include "glquake.h" +#include "client.h" +#include "mathlib.h" +#include "view.h" int r_dlightframecount; diff --git a/qw_client/gl_rpart.c b/qw_client/gl_rpart.c index e5d4524..e87603e 100644 --- a/qw_client/gl_rpart.c +++ b/qw_client/gl_rpart.c @@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "d_iface.h" #include "glquake.h" +#include "mathlib.h" extern particle_t *active_particles, *free_particles; extern int ramp1[8], ramp2[8], ramp3[8]; diff --git a/qw_client/gl_screen.c b/qw_client/gl_screen.c index 4cf9186..999314d 100644 --- a/qw_client/gl_screen.c +++ b/qw_client/gl_screen.c @@ -23,8 +23,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // screen.c -- master for refresh, status bar, console, chat, notify, etc +#include "qtypes.h" #include "quakedef.h" +#include "client.h" +#include "draw.h" +#include "keys.h" +#include "cvar.h" #include "glquake.h" +#include "console.h" +#include "screen.h" +#include "sbar.h" +#include "menu.h" +#include "sound.h" + #include /* diff --git a/qw_client/menu.c b/qw_client/menu.c index ea2b8ba..801c886 100644 --- a/qw_client/menu.c +++ b/qw_client/menu.c @@ -23,6 +23,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "quakedef.h" #include "winquake.h" +#include "qtypes.h" +#include "draw.h" +#include "keys.h" +#include "console.h" +#include "common.h" +#include "client.h" +#include "screen.h" +#include "cvar.h" +#include "menu.h" +#include "view.h" +#include "sound.h" enum {m_none, m_main, m_singleplayer, m_load, m_save, m_multiplayer, m_setup, m_net, m_options, m_video, m_keys, m_help, m_quit, m_serialconfig, m_modemconfig, m_lanconfig, m_gameoptions, m_search, m_slist} m_state; diff --git a/qw_client/menu.h b/qw_client/menu.h index 6eee367..0eb48a8 100644 --- a/qw_client/menu.h +++ b/qw_client/menu.h @@ -20,6 +20,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "qtypes.h" +#include "draw.h" + // // the net drivers should just set the apropriate bits in m_activenet, // instead of having the menu code look through their internal tables diff --git a/qw_client/model.c b/qw_client/model.c index 4eda595..80abfa6 100644 --- a/qw_client/model.c +++ b/qw_client/model.c @@ -27,6 +27,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" +#include +#include +#include model_t *loadmodel; char loadname[32]; // for hunk tags diff --git a/qw_client/r_edge.c b/qw_client/r_edge.c index 1de3d76..fc0df08 100644 --- a/qw_client/r_edge.c +++ b/qw_client/r_edge.c @@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" +#include +#include #if 0 // FIXME diff --git a/qw_client/r_efrag.c b/qw_client/r_efrag.c index 3d77b86..38a52e2 100644 --- a/qw_client/r_efrag.c +++ b/qw_client/r_efrag.c @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" +#include mnode_t *r_pefragtopnode; diff --git a/qw_client/r_misc.c b/qw_client/r_misc.c index f0b1412..438412a 100644 --- a/qw_client/r_misc.c +++ b/qw_client/r_misc.c @@ -24,6 +24,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" +#include +#include +#include +#include +#include +#include /* diff --git a/qw_client/r_part.c b/qw_client/r_part.c index 8c3eb42..f7c49c5 100644 --- a/qw_client/r_part.c +++ b/qw_client/r_part.c @@ -21,10 +21,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "qtypes.h" #include "quakedef.h" #include "r_local.h" #include "d_iface.h" +#include "glquake.h" +#include "mathlib.h" +#include "console.h" #define MAX_PARTICLES 2048 // default max # of particles at one // time diff --git a/qw_client/r_sprite.c b/qw_client/r_sprite.c index e846e7c..049e226 100644 --- a/qw_client/r_sprite.c +++ b/qw_client/r_sprite.c @@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "r_local.h" +#include +#include static int clip_current; static vec5_t clip_verts[2][MAXWORKINGVERTS]; diff --git a/qw_client/screen.c b/qw_client/screen.c index 8689e30..20a0fdc 100644 --- a/qw_client/screen.c +++ b/qw_client/screen.c @@ -22,8 +22,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // screen.c -- master for refresh, status bar, console, chat, notify, etc -#include "quakedef.h" -#include "r_local.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include diff --git a/qw_client/view.c b/qw_client/view.c index 865100d..ea5c830 100644 --- a/qw_client/view.c +++ b/qw_client/view.c @@ -21,8 +21,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // view.c -- player eye positioning +#include "qtypes.h" #include "quakedef.h" #include "r_local.h" +#include "mathlib.h" +#include "draw.h" +#include "cvar.h" +#include "screen.h" extern int onground; diff --git a/qw_common/client.h b/qw_common/client.h index 7e6fd2f..e8bb80b 100644 --- a/qw_common/client.h +++ b/qw_common/client.h @@ -24,6 +24,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _CLIENT_H #define _CLIENT_H +#include "qtypes.h" +#include "zone.h" +#include "protocol.h" +#include "vid.h" +#include "render.h" +#include "common.h" +#include "sys.h" +#include "cmd.h" + typedef struct { char name[16]; @@ -59,7 +68,6 @@ typedef struct } player_state_t; -#define MAX_SCOREBOARDNAME 16 typedef struct player_info_s { int userid; @@ -101,12 +109,6 @@ typedef struct } frame_t; -typedef struct -{ - int destcolor[3]; - int percent; // 0-256 -} cshift_t; - #define CSHIFT_CONTENTS 0 #define CSHIFT_DAMAGE 1 #define CSHIFT_BONUS 2 @@ -209,6 +211,7 @@ extern client_static_t cls; // the client_state_t structure is wiped completely at every // server signon // +/* typedef struct { int servercount; // server identification for prespawns @@ -293,6 +296,8 @@ typedef struct // all player information player_info_t players[MAX_CLIENTS]; } client_state_t; +extern client_state_t cl; +*/ // @@ -332,7 +337,6 @@ extern cvar_t name; #define MAX_STATIC_ENTITIES 128 // torches, etc -extern client_state_t cl; // FIXME, allocate dynamically extern entity_state_t cl_baselines[MAX_EDICTS]; diff --git a/qw_common/common.c b/qw_common/common.c index 5d2d6e4..abb19ed 100644 --- a/qw_common/common.c +++ b/qw_common/common.c @@ -23,6 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // common.c -- misc functions used in client and server #include +#include "common.h" +#include "crc.h" +#include "sys.h" +#include "cmd.h" +#include "console.h" #ifdef SERVERONLY #include "qwsvdef.h" @@ -33,13 +38,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MAX_NUM_ARGVS 50 #define NUM_SAFE_ARGVS 6 -usercmd_t nullcmd; // guarenteed to be zero - -static char *largv[MAX_NUM_ARGVS + NUM_SAFE_ARGVS + 1]; -static char *argvdummy = " "; - -static char *safeargvs[NUM_SAFE_ARGVS] = - {"-stdvid", "-nolan", "-nosound", "-nocdaudio", "-nojoy", "-nomouse"}; qboolean com_modified; // set true if using non-id files @@ -49,31 +47,10 @@ void COM_InitFilesystem (void); void COM_Path_f (void); -// if a packfile directory differs from this, it is assumed to be hacked -#define PAK0_COUNT 339 -#define PAK0_CRC 52883 - qboolean standard_quake = true, rogue, hipnotic; -char gamedirfile[MAX_OSPATH]; extern cvar_t developer; -/* - - -All of Quake's data access is through a hierchal file system, but the contents of the file system can be transparently merged from several sources. - -The "base directory" is the path to the directory holding the quake.exe and all game directories. The sys_* files pass this to host_init in quakeparms_t->basedir. This can be overridden with the "-basedir" command line parm to allow code debugging in a different directory. The base directory is -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. - -*/ - //============================================================================ @@ -104,374 +81,6 @@ void InsertLinkAfter (link_t *l, link_t *after) l->next->prev = l; } -/* -============================================================================ - - LIBRARY REPLACEMENT FUNCTIONS - -============================================================================ -*/ - -#if 0 -void Q_memset (void *dest, int fill, int count) -{ - int i; - - if ( (((long)dest | count) & 3) == 0) - { - count >>= 2; - fill = fill | (fill<<8) | (fill<<16) | (fill<<24); - for (i=0 ; i>=2; - for (i=0 ; i= 'a' && c1 <= 'z') - c1 -= ('a' - 'A'); - if (c2 >= 'a' && c2 <= 'z') - c2 -= ('a' - 'A'); - if (c1 != c2) - return -1; // strings not equal - } - if (!c1) - return 0; // strings are equal -// s1++; -// s2++; - } - - return -1; -} - -int Q_strcasecmp (char *s1, char *s2) -{ - return Q_strncasecmp (s1, s2, 99999); -} - -#endif - -int Q_atoi (char *str) -{ - int val; - int sign; - int c; - - if (*str == '-') - { - sign = -1; - str++; - } - else - sign = 1; - - val = 0; - -// -// check for hex -// - if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') ) - { - str += 2; - while (1) - { - c = *str++; - if (c >= '0' && c <= '9') - val = (val<<4) + c - '0'; - else if (c >= 'a' && c <= 'f') - val = (val<<4) + c - 'a' + 10; - else if (c >= 'A' && c <= 'F') - val = (val<<4) + c - 'A' + 10; - else - return val*sign; - } - } - -// -// check for character -// - if (str[0] == '\'') - { - return sign * str[1]; - } - -// -// assume decimal -// - while (1) - { - c = *str++; - if (c <'0' || c > '9') - return val*sign; - val = val*10 + c - '0'; - } - - return 0; -} - - -float Q_atof (char *str) -{ - double val; - int sign; - int c; - int decimal, total; - - if (*str == '-') - { - sign = -1; - str++; - } - else - sign = 1; - - val = 0; - -// -// check for hex -// - if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') ) - { - str += 2; - while (1) - { - c = *str++; - if (c >= '0' && c <= '9') - val = (val*16) + c - '0'; - else if (c >= 'a' && c <= 'f') - val = (val*16) + c - 'a' + 10; - else if (c >= 'A' && c <= 'F') - val = (val*16) + c - 'A' + 10; - else - return val*sign; - } - } - -// -// check for character -// - if (str[0] == '\'') - { - return sign * str[1]; - } - -// -// assume decimal -// - decimal = -1; - total = 0; - while (1) - { - c = *str++; - if (c == '.') - { - decimal = total; - continue; - } - if (c <'0' || c > '9') - break; - val = val*10 + c - '0'; - total++; - } - - if (decimal == -1) - return val*sign; - while (total > decimal) - { - val /= 10; - total--; - } - - return val*sign; -} - -/* -============================================================================ - - BYTE ORDER FUNCTIONS - -============================================================================ -*/ - -short (*BigShort) (short l); -short (*LittleShort) (short l); -int (*BigLong) (int l); -int (*LittleLong) (int l); -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; -} - /* ============================================================================== @@ -981,8 +590,6 @@ void COM_DefaultExtension (char *path, char *extension) //============================================================================ char com_token[1024]; -int com_argc; -char **com_argv; /* @@ -1051,78 +658,6 @@ skipwhite: return data; } - -/* -================ -COM_CheckParm - -Returns the position (1 to argc-1) in the program's argument list -where the given parameter apears, or 0 if not present -================ -*/ -int COM_CheckParm (char *parm) -{ - int i; - - for (i=1 ; inext) - { - if (s == com_base_searchpaths) - Con_Printf ("----------\n"); - if (s->pack) - Con_Printf ("%s (%i files)\n", s->pack->filename, s->pack->numfiles); - else - Con_Printf ("%s\n", s->filename); - } -} - -/* -============ -COM_WriteFile - -The filename will be prefixed by the current game directory -============ -*/ -void COM_WriteFile (char *filename, void *data, int len) -{ - FILE *f; - char name[MAX_OSPATH]; - - snprintf(name, sizeof(name), "%s/%s", com_gamedir, filename); - - f = fopen (name, "wb"); - if (!f) { - Sys_mkdir(com_gamedir); - f = fopen (name, "wb"); - if (!f) - Sys_Error ("Error opening %s", filename); - } - - Sys_Printf ("COM_WriteFile: %s\n", name); - fwrite (data, 1, len, f); - fclose (f); -} - - -/* -============ -COM_CreatePath - -Only used for CopyFile and download -============ -*/ -void COM_CreatePath (char *path) -{ - char *ofs; - - for (ofs = path+1 ; *ofs ; ofs++) - { - if (*ofs == '/') - { // create the directory - *ofs = 0; - Sys_mkdir (path); - *ofs = '/'; - } - } -} - - -/* -=========== -COM_CopyFile - -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) -{ - FILE *in, *out; - int remaining, count; - char buf[4096]; - - remaining = COM_FileOpenRead (netpath, &in); - COM_CreatePath (cachepath); // create directories up to the cache file - out = fopen(cachepath, "wb"); - if (!out) - Sys_Error ("Error opening %s", cachepath); - - while (remaining) - { - if (remaining < sizeof(buf)) - count = remaining; - else - count = sizeof(buf); - fread (buf, 1, count, in); - fwrite (buf, 1, count, out); - remaining -= count; - } - - fclose (in); - fclose (out); -} - -/* -=========== -COM_FindFile - -Finds the file in the search path. -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, FILE **file) -{ - searchpath_t *search; - char netpath[MAX_OSPATH]; - pack_t *pak; - int i; - int findtime; - - file_from_pak = 0; - -// -// search through the path, one element at a time -// - for (search = com_searchpaths ; 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 ; inumfiles ; i++) - if (!strcmp (pak->files[i].name, filename)) - { // found it! - if(developer.value) - Sys_Printf ("PackFile: %s : %s\n",pak->filename, filename); - // open a new file on the pakfile - *file = fopen (pak->filename, "rb"); - if (!*file) - Sys_Error ("Couldn't reopen %s", pak->filename); - fseek (*file, pak->files[i].filepos, SEEK_SET); - com_filesize = pak->files[i].filelen; - file_from_pak = 1; - return com_filesize; - } - } - else - { - // check a file in the directory tree - snprintf(netpath, sizeof(netpath), "%s/%s",search->filename, filename); - - findtime = Sys_FileTime (netpath); - if (findtime == -1) - continue; - - if(developer.value) - Sys_Printf ("FindFile: %s\n",netpath); - - *file = fopen (netpath, "rb"); - return COM_filelength (*file); - } - - } - - Sys_Printf ("FindFile: can't find %s\n", filename); - - *file = NULL; - com_filesize = -1; - return -1; -} - -/* -============ -COM_LoadFile - -Filename are reletive to the quake directory. -Allways appends a 0 byte to the loaded data. -============ -*/ -cache_user_t *loadcache; -byte *loadbuf; -int loadsize; -byte *COM_LoadFile (char *path, int usehunk) -{ - FILE *h; - byte *buf; - char base[32]; - int len; - - buf = NULL; // quiet compiler warning - -// look for it in the filesystem or pack files - len = com_filesize = COM_FOpenFile (path, &h); - if (!h) - return NULL; - -// 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; -#ifndef SERVERONLY - Draw_BeginDisc (); -#endif - fread (buf, 1, len, h); - fclose (h); -#ifndef SERVERONLY - Draw_EndDisc (); -#endif - - 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; - FILE *packhandle; - dpackfile_t info[MAX_FILES_IN_PACK]; - unsigned short crc; - - if (COM_FileOpenRead (packfile, &packhandle) == -1) - return NULL; - - fread (&header, 1, sizeof(header), packhandle); - 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 %i files", packfile, numpackfiles); - - if (numpackfiles != PAK0_COUNT) - com_modified = true; // not the original file - - newfiles = Z_Malloc (numpackfiles * sizeof(packfile_t)); - - fseek (packhandle, header.dirofs, SEEK_SET); - fread (info, 1, header.dirlen, packhandle); - -// crc the directory to check for modifications - crc = CRC_Block((byte *)info, header.dirlen); - -// CRC_Init (&crc); -// for (i=0 ; ifilename, packfile); - pack->handle = packhandle; - pack->numfiles = numpackfiles; - pack->files = newfiles; - - Con_Printf ("Added packfile %s (%i 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]; - char *p; - - if ((p = strrchr(dir, '/')) != NULL) - strcpy(gamedirfile, ++p); - else - strcpy(gamedirfile, dir); - strcpy (com_gamedir, dir); - -// -// add the directory to the search path -// - search = Hunk_Alloc (sizeof(searchpath_t)); - 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++) - { - snprintf(pakfile, sizeof(pakfile), "%s/pak%i.pak", dir, i); - pak = COM_LoadPackFile (pakfile); - if (!pak) - break; - search = Hunk_Alloc (sizeof(searchpath_t)); - search->pack = pak; - search->next = com_searchpaths; - com_searchpaths = search; - } - -} - -/* -================ -COM_Gamedir - -Sets the gamedir and path to a different directory. -================ -*/ -void COM_Gamedir (char *dir) -{ - searchpath_t *search, *next; - int i; - pack_t *pak; - char pakfile[MAX_OSPATH]; - - if (strstr(dir, "..") || strstr(dir, "/") - || strstr(dir, "\\") || strstr(dir, ":") ) - { - Con_Printf ("Gamedir should be a single filename, not a path\n"); - return; - } - - if (!strcmp(gamedirfile, dir)) - return; // still the same - strcpy (gamedirfile, dir); - - // - // free up any current game dir info - // - while (com_searchpaths != com_base_searchpaths) - { - if (com_searchpaths->pack) - { - fclose (com_searchpaths->pack->handle); - Z_Free (com_searchpaths->pack->files); - Z_Free (com_searchpaths->pack); - } - next = com_searchpaths->next; - Z_Free (com_searchpaths); - com_searchpaths = next; - } - - // - // flush all data, so it will be forced to reload - // - Cache_Flush (); - - if (!strcmp(dir, GAMENAME) || !strcmp(dir, "qw")) - return; - - snprintf(com_gamedir, sizeof(com_gamedir), "%s/%s", com_basedir, dir); - - // - // add the directory to the search path - // - search = Z_Malloc (sizeof(searchpath_t)); - strcpy (search->filename, com_gamedir); - search->next = com_searchpaths; - com_searchpaths = search; - - // - // add any pak files in the format pak0.pak pak1.pak, ... - // - for (i=0 ; ; i++) - { - snprintf(pakfile, sizeof(pakfile), "%s/pak%i.pak", com_gamedir, i); - pak = COM_LoadPackFile (pakfile); - if (!pak) - break; - search = Z_Malloc (sizeof(searchpath_t)); - search->pack = pak; - search->next = com_searchpaths; - com_searchpaths = search; - } -} - -/* -================ -COM_InitFilesystem -================ -*/ -void COM_InitFilesystem (void) -{ - int i; - -// -// -basedir -// Overrides the system supplied base directory -// - i = COM_CheckParm ("-basedir"); - if (i && i < com_argc-1) - strcpy (com_basedir, com_argv[i+1]); - else - strcpy (com_basedir, host_parms.basedir); - -// -// start up with GAMENAME by default -// - COM_AddGameDirectory (va("%s/" GAMENAME, com_basedir) ); - COM_AddGameDirectory (va("%s/qw", com_basedir) ); - - // any set gamedirs will be freed up to here - com_base_searchpaths = com_searchpaths; -} - - - /* ===================================================================== diff --git a/qw_common/common.h b/qw_common/common.h index fc0df16..a65bcff 100644 --- a/qw_common/common.h +++ b/qw_common/common.h @@ -26,15 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include - -typedef unsigned char byte; -#define _DEF_BYTE_ - -// KJB Undefined true and false defined in SciTech's DEBUG.H header -#undef true -#undef false - -typedef enum {false, true} qboolean; +#include "qtypes.h" #define MAX_INFO_STRING 196 #define MAX_SERVERINFO_STRING 512 @@ -51,6 +43,7 @@ typedef struct sizebuf_s int cursize; } sizebuf_t; +#include "net.h" void SZ_Clear (sizebuf_t *buf); void *SZ_GetSpace (sizebuf_t *buf, int length); void SZ_Write (sizebuf_t *buf, void *data, int length); @@ -94,12 +87,7 @@ void InsertLinkAfter (link_t *l, link_t *after); //============================================================================ -extern short (*BigShort) (short l); -extern short (*LittleShort) (short l); -extern int (*BigLong) (int l); -extern int (*LittleLong) (int l); -extern float (*BigFloat) (float l); -extern float (*LittleFloat) (float l); +#include "qendian.h" //============================================================================ @@ -138,33 +126,7 @@ void MSG_ReadDeltaUsercmd (struct usercmd_s *from, struct usercmd_s *cmd); //============================================================================ -#define Q_memset(d, f, c) memset((d), (f), (c)) -#define Q_memcpy(d, s, c) memcpy((d), (s), (c)) -#define Q_memcmp(m1, m2, c) memcmp((m1), (m2), (c)) -#define Q_strcpy(d, s) strcpy((d), (s)) -#define Q_strncpy(d, s, n) strncpy((d), (s), (n)) -#define Q_strlen(s) ((int)strlen(s)) -#define Q_strrchr(s, c) strrchr((s), (c)) -#define Q_strcat(d, s) strcat((d), (s)) -#define Q_strcmp(s1, s2) strcmp((s1), (s2)) -#define Q_strncmp(s1, s2, n) strncmp((s1), (s2), (n)) - -#ifdef _WIN32 - -#define Q_strcasecmp(s1, s2) _stricmp((s1), (s2)) -#define Q_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n)) - -#else - -#define Q_strcasecmp(s1, s2) strcasecmp((s1), (s2)) -#define Q_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n)) - -#endif - -int Q_atoi (char *str); -float Q_atof (char *str); - - +#include "lib_replace.h" //============================================================================ @@ -194,21 +156,7 @@ char *va(char *format, ...); //============================================================================ -extern int com_filesize; -struct cache_user_s; - -extern char com_gamedir[MAX_OSPATH]; - -void COM_WriteFile (char *filename, void *data, int len); -int COM_FOpenFile (char *filename, FILE **file); -void COM_CloseFile (FILE *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); -void COM_CreatePath (char *path); -void COM_Gamedir (char *dir); +#include "quakefs.h" extern qboolean standard_quake, rogue, hipnotic; diff --git a/qw_common/console.c b/qw_common/console.c index ecf41c8..141cdc9 100644 --- a/qw_common/console.c +++ b/qw_common/console.c @@ -22,7 +22,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // console.c +#include "qtypes.h" #include "quakedef.h" +#include "console.h" +#include "keys.h" +#include "lib_replace.h" +#include "client.h" +#include "cvar.h" +#include "screen.h" +#include "draw.h" int con_ormask; console_t con_main; diff --git a/qw_common/cvar.h b/qw_common/cvar.h deleted file mode 100644 index de52b10..0000000 --- a/qw_common/cvar.h +++ /dev/null @@ -1,102 +0,0 @@ -/* -Copyright (C) 1996-1997 Id Software, Inc. -Copyright (C) 1999,2000 contributors of the QuakeForge project -Please see the file "AUTHORS" for a list of contributors - -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. - -*/ -// cvar.h - -#ifndef _CVAR_H -#define _CVAR_H - -/* - -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 -in C code. - -it is sufficient to initialize a cvar_t with just the first two fields, or -you can add a ,true flag for variables that you want saved to the configuration -file when the game is quit: - -cvar_t r_draworder = {"r_draworder","1"}; -cvar_t scr_screensize = {"screensize","1",true}; - -Cvars must be registered before use, or they will have a 0 value instead of the float interpretation of the string. Generally, all cvar_t declarations should be registered in the apropriate init function before any console commands are executed: -Cvar_RegisterVariable (&host_framerate); - - -C code usually just references a cvar in place: -if ( r_draworder.value ) - -It could optionally ask for the value to be looked up for a string name: -if (Cvar_VariableValue ("r_draworder")) - -Interpreted prog code can access cvars with the cvar(name) or -cvar_set (name, value) internal functions: -teamplay = cvar("teamplay"); - -The user can access cvars from the console in two ways: -r_draworder prints the current value -r_draworder 0 sets the current value to 0 -Cvars are restricted from having the same names as commands to keep this -interface from being ambiguous. -*/ - -typedef struct cvar_s -{ - char *name; - char *string; - qboolean archive; // set to true to cause it to be saved to vars.rc - qboolean info; // added to serverinfo or userinfo when changed - float value; - struct cvar_s *next; -} cvar_t; - -void Cvar_RegisterVariable (cvar_t *variable); -// 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 " " 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 - -char *Cvar_VariableString (char *var_name); -// returns an empty string if not defined - -char *Cvar_CompleteVariable (char *partial); -// attempts to match a partial variable name for command line completion -// returns NULL if nothing fits - -qboolean Cvar_Command (void); -// called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known -// command. Returns true if the command was a variable reference that -// was handled. (print or change) - -void Cvar_WriteVariables (FILE *f); -// Writes lines containing "set variable value" for all variables -// with the archive flag set to true. - -cvar_t *Cvar_FindVar (char *var_name); - -extern cvar_t *cvar_vars; -#endif // _CVAR_H diff --git a/qw_common/net.h b/qw_common/net.h index 58b06ce..353342e 100644 --- a/qw_common/net.h +++ b/qw_common/net.h @@ -25,6 +25,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // net.h -- quake's interface to the networking layer +#include "qtypes.h" +#include "common.h" + #define PORT_ANY -1 // Uncomment this line for IPv6 support @@ -45,7 +48,6 @@ extern netadr_t net_local_adr; extern netadr_t net_from; // address of who sent the packet extern sizebuf_t net_message; -extern cvar_t hostname; extern int net_socket; @@ -123,4 +125,7 @@ void Netchan_Setup (netchan_t *chan, netadr_t adr, int qport); qboolean Netchan_CanPacket (netchan_t *chan); qboolean Netchan_CanReliable (netchan_t *chan); +#include "qstructs.h" +extern cvar_t hostname; + #endif // _NET_H diff --git a/qw_common/net_chan.c b/qw_common/net_chan.c index 3ff0046..56d0b08 100644 --- a/qw_common/net_chan.c +++ b/qw_common/net_chan.c @@ -19,7 +19,12 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "qtypes.h" #include "quakedef.h" +#include "cvar.h" +#include "common.h" +#include "client.h" +#include "console.h" #ifdef HAVE_UNISTD_H #include diff --git a/qw_common/net_udp.c b/qw_common/net_udp.c index e991b31..02a7edd 100644 --- a/qw_common/net_udp.c +++ b/qw_common/net_udp.c @@ -23,7 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // net_udp.c +#include "qtypes.h" #include "quakedef.h" +#include "net.h" +#include "sys.h" +#include "console.h" #include #include diff --git a/qw_common/pmove.c b/qw_common/pmove.c index ca697db..ff4d36b 100644 --- a/qw_common/pmove.c +++ b/qw_common/pmove.c @@ -20,7 +20,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "qtypes.h" #include "quakedef.h" +#include "mathlib.h" movevars_t movevars; diff --git a/qw_common/pmove.h b/qw_common/pmove.h index 60a4126..a5754ae 100644 --- a/qw_common/pmove.h +++ b/qw_common/pmove.h @@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define __PMOVE_H #include "pmove_simple.h" +#include "model.h" +#include "protocol.h" typedef struct { diff --git a/qw_common/pmovetst.c b/qw_common/pmovetst.c index b7e4929..b1d105b 100644 --- a/qw_common/pmovetst.c +++ b/qw_common/pmovetst.c @@ -19,7 +19,11 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "qtypes.h" #include "quakedef.h" +#include "sys.h" +#include "mathlib.h" +#include "console.h" static hull_t box_hull; static dclipnode_t box_clipnodes[6]; diff --git a/qw_common/protocol.h b/qw_common/protocol.h index 7da172e..60ba277 100644 --- a/qw_common/protocol.h +++ b/qw_common/protocol.h @@ -253,23 +253,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // must be power of two #define UPDATE_MASK (UPDATE_BACKUP-1) -// entity_state_t is the information conveyed from the server -// in an update message -typedef struct -{ - int number; // edict index - - int flags; // nolerp, etc - vec3_t origin; - vec3_t angles; - int modelindex; - int frame; - int colormap; - int skinnum; - int effects; -} entity_state_t; - - #define MAX_PACKET_ENTITIES 64 // doesn't count nails typedef struct { diff --git a/qw_server/Makefile.in b/qw_server/Makefile.in index 094a9ec..a6e546b 100644 --- a/qw_server/Makefile.in +++ b/qw_server/Makefile.in @@ -70,7 +70,7 @@ 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 + register_check.c qendian.c qargs.c quakefs.c lib_replace.c ALL_QW_SRV_SRC = $(GENERAL_SRC) model.c # FIXME: add dos/win specifc source diff --git a/qw_server/qwsvdef.h b/qw_server/qwsvdef.h index 6db3917..921267c 100644 --- a/qw_server/qwsvdef.h +++ b/qw_server/qwsvdef.h @@ -71,25 +71,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # define vsnprintf _vsnprintf #endif -//============================================================================= - -// the host system specifies the base of the directory tree, the -// command line parms passed to the program, and the amount of memory -// available for the program to use - -typedef struct -{ - char *basedir; - char *cachedir; // for development over ISDN lines - int argc; - char **argv; - void *membase; - int memsize; -} quakeparms_t; - - -//============================================================================= - // // host // diff --git a/qw_server/server.h b/qw_server/server.h index 281afb6..a0ece87 100644 --- a/qw_server/server.h +++ b/qw_server/server.h @@ -103,7 +103,7 @@ typedef enum // connection for a couple seconds cs_connected, // has been assigned to a client_t, but not in game yet cs_spawned // client is fully in game -} client_state_t; +} sv_client_state_t; typedef struct { @@ -119,7 +119,7 @@ typedef struct typedef struct client_s { - client_state_t state; + sv_client_state_t state; int spectator; // non-interactive diff --git a/uquake/cmd.c b/uquake/cmd.c deleted file mode 100644 index 0778c5e..0000000 --- a/uquake/cmd.c +++ /dev/null @@ -1,705 +0,0 @@ -/* -Copyright (C) 1996-1997 Id Software, Inc. - -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. - -*/ -// cmd.c -- Quake script command processing module - -#include "quakedef.h" - -void Cmd_ForwardToServer (void); - -#define MAX_ALIAS_NAME 32 - -typedef struct cmdalias_s -{ - struct cmdalias_s *next; - char name[MAX_ALIAS_NAME]; - char *value; -} cmdalias_t; - -cmdalias_t *cmd_alias; - -int trashtest; -int *trashspot; - -qboolean cmd_wait; - -//============================================================================= - -/* -============ -Cmd_Wait_f - -Causes execution of the remainder of the command buffer to be delayed until -next frame. This allows commands like: -bind g "impulse 5 ; +attack ; wait ; -attack ; impulse 2" -============ -*/ -void Cmd_Wait_f (void) -{ - cmd_wait = true; -} - -/* -============================================================================= - - COMMAND BUFFER - -============================================================================= -*/ - -sizebuf_t cmd_text; - -/* -============ -Cbuf_Init -============ -*/ -void Cbuf_Init (void) -{ - SZ_Alloc (&cmd_text, 8192); // space for commands and script files -} - - -/* -============ -Cbuf_AddText - -Adds command text at the end of the buffer -============ -*/ -void Cbuf_AddText (char *text) -{ - int l; - - l = Q_strlen (text); - - if (cmd_text.cursize + l >= cmd_text.maxsize) - { - Con_Printf ("Cbuf_AddText: overflow\n"); - return; - } - - SZ_Write (&cmd_text, text, Q_strlen (text)); -} - - -/* -============ -Cbuf_InsertText - -Adds command text immediately after the current command -Adds a \n to the text -FIXME: actually change the command buffer to do less copying -============ -*/ -void Cbuf_InsertText (char *text) -{ - char *temp; - int templen; - -// copy off any commands still remaining in the exec buffer - templen = cmd_text.cursize; - if (templen) - { - temp = Z_Malloc (templen); - Q_memcpy (temp, cmd_text.data, templen); - SZ_Clear (&cmd_text); - } - else - temp = NULL; // shut up compiler - -// add the entire text of the file - Cbuf_AddText (text); - -// add the copied off data - if (templen) - { - SZ_Write (&cmd_text, temp, templen); - Z_Free (temp); - } -} - -/* -============ -Cbuf_Execute -============ -*/ -void Cbuf_Execute (void) -{ - int i; - char *text; - char line[1024]; - int quotes; - - while (cmd_text.cursize) - { -// find a \n or ; line break - text = (char *)cmd_text.data; - - quotes = 0; - for (i=0 ; i< cmd_text.cursize ; i++) - { - if (text[i] == '"') - quotes++; - if ( !(quotes&1) && text[i] == ';') - break; // don't break if inside a quoted string - if (text[i] == '\n') - break; - } - - - memcpy (line, text, i); - line[i] = 0; - -// delete the text from the command buffer and move remaining commands down -// this is necessary because commands (exec, alias) can insert data at the -// beginning of the text buffer - - if (i == cmd_text.cursize) - cmd_text.cursize = 0; - else - { - i++; - cmd_text.cursize -= i; - Q_memcpy (text, text+i, cmd_text.cursize); - } - -// execute the command line - Cmd_ExecuteString (line, src_command); - - if (cmd_wait) - { // skip out while text still remains in buffer, leaving it - // for next frame - cmd_wait = false; - break; - } - } -} - -/* -============================================================================== - - SCRIPT COMMANDS - -============================================================================== -*/ - -/* -=============== -Cmd_StuffCmds_f - -Adds command line parameters as script statements -Commands lead with a +, and continue until a - or another + -quake +prog jctest.qp +cmd amlev1 -quake -nosound +cmd amlev1 -=============== -*/ -void Cmd_StuffCmds_f (void) -{ - int i, j; - int s; - char *text, *build, c; - - if (Cmd_Argc () != 1) - { - Con_Printf ("stuffcmds : execute command line parameters\n"); - return; - } - -// build the combined string to parse from - s = 0; - for (i=1 ; i : execute a script file\n"); - return; - } - - mark = Hunk_LowMark (); - f = (char *)COM_LoadHunkFile (Cmd_Argv(1)); - if (!f) - { - Con_Printf ("couldn't exec %s\n",Cmd_Argv(1)); - return; - } - Con_Printf ("execing %s\n",Cmd_Argv(1)); - - Cbuf_InsertText (f); - Hunk_FreeToLowMark (mark); -} - - -/* -=============== -Cmd_Echo_f - -Just prints the rest of the line to the console -=============== -*/ -void Cmd_Echo_f (void) -{ - int i; - - for (i=1 ; inext) - Con_Printf ("%s : %s\n", a->name, a->value); - return; - } - - s = Cmd_Argv(1); - if (strlen(s) >= MAX_ALIAS_NAME) - { - Con_Printf ("Alias name is too long\n"); - return; - } - - // if the alias allready exists, reuse it - for (a = cmd_alias ; a ; a=a->next) - { - if (!strcmp(s, a->name)) - { - Z_Free (a->value); - break; - } - } - - if (!a) - { - a = Z_Malloc (sizeof(cmdalias_t)); - a->next = cmd_alias; - cmd_alias = a; - } - strcpy (a->name, s); - -// copy the rest of the command line - cmd[0] = 0; // start out with a null string - c = Cmd_Argc(); - for (i=2 ; i< c ; i++) - { - strcat (cmd, Cmd_Argv(i)); - if (i != c) - strcat (cmd, " "); - } - strcat (cmd, "\n"); - - a->value = CopyString (cmd); -} - -/* -============================================================================= - - COMMAND EXECUTION - -============================================================================= -*/ - -typedef struct cmd_function_s -{ - struct cmd_function_s *next; - char *name; - xcommand_t function; -} cmd_function_t; - - -#define MAX_ARGS 80 - -static int cmd_argc; -static char *cmd_argv[MAX_ARGS]; -static char *cmd_null_string = ""; -static char *cmd_args = NULL; - -cmd_source_t cmd_source; - - -static cmd_function_t *cmd_functions; // possible commands to execute - -/* -============ -Cmd_Init -============ -*/ -void Cmd_Init (void) -{ -// -// register our commands -// - Cmd_AddCommand ("stuffcmds",Cmd_StuffCmds_f); - Cmd_AddCommand ("exec",Cmd_Exec_f); - Cmd_AddCommand ("echo",Cmd_Echo_f); - Cmd_AddCommand ("alias",Cmd_Alias_f); - Cmd_AddCommand ("cmd", Cmd_ForwardToServer); - Cmd_AddCommand ("wait", Cmd_Wait_f); -} - -/* -============ -Cmd_Argc -============ -*/ -int Cmd_Argc (void) -{ - return cmd_argc; -} - -/* -============ -Cmd_Argv -============ -*/ -char *Cmd_Argv (int arg) -{ - if ( (unsigned)arg >= cmd_argc ) - return cmd_null_string; - return cmd_argv[arg]; -} - -/* -============ -Cmd_Args -============ -*/ -char *Cmd_Args (void) -{ - return cmd_args; -} - - -/* -============ -Cmd_TokenizeString - -Parses the given string into command line tokens. -============ -*/ -void Cmd_TokenizeString (char *text) -{ - int i; - -// clear the args from the last string - for (i=0 ; inext) - { - if (!Q_strcmp (cmd_name, cmd->name)) - { - Con_Printf ("Cmd_AddCommand: %s already defined\n", cmd_name); - return; - } - } - - cmd = Hunk_Alloc (sizeof(cmd_function_t)); - cmd->name = cmd_name; - cmd->function = function; - cmd->next = cmd_functions; - cmd_functions = cmd; -} - -/* -============ -Cmd_Exists -============ -*/ -qboolean Cmd_Exists (char *cmd_name) -{ - cmd_function_t *cmd; - - for (cmd=cmd_functions ; cmd ; cmd=cmd->next) - { - if (!Q_strcmp (cmd_name,cmd->name)) - return true; - } - - return false; -} - - - -/* -============ -Cmd_CompleteCommand -============ -*/ -char *Cmd_CompleteCommand (char *partial) -{ - cmd_function_t *cmd; - int len; - - len = Q_strlen(partial); - - if (!len) - return NULL; - -// check functions - for (cmd=cmd_functions ; cmd ; cmd=cmd->next) - if (!Q_strncmp (partial,cmd->name, len)) - return cmd->name; - - return NULL; -} - -/* -============ -Cmd_ExecuteString - -A complete command line has been parsed, so try to execute it -FIXME: lookupnoadd the token to speed search? -============ -*/ -void Cmd_ExecuteString (char *text, cmd_source_t src) -{ - cmd_function_t *cmd; - cmdalias_t *a; - - cmd_source = src; - Cmd_TokenizeString (text); - -// execute the command line - if (!Cmd_Argc()) - return; // no tokens - -// check functions - for (cmd=cmd_functions ; cmd ; cmd=cmd->next) - { - if (!Q_strcasecmp (cmd_argv[0],cmd->name)) - { - cmd->function (); - return; - } - } - -// check alias - for (a=cmd_alias ; a ; a=a->next) - { - if (!Q_strcasecmp (cmd_argv[0], a->name)) - { - Cbuf_InsertText (a->value); - return; - } - } - -// check cvars - if (!Cvar_Command ()) - Con_Printf ("Unknown command \"%s\"\n", Cmd_Argv(0)); - -} - - -/* -=================== -Cmd_ForwardToServer - -Sends the entire command line over to the server -=================== -*/ -void Cmd_ForwardToServer (void) -{ - if (cls.state != ca_connected) - { - Con_Printf ("Can't \"%s\", not connected\n", Cmd_Argv(0)); - return; - } - - if (cls.demoplayback) - return; // not really connected - - MSG_WriteByte (&cls.message, clc_stringcmd); - if (Q_strcasecmp(Cmd_Argv(0), "cmd") != 0) - { - SZ_Print (&cls.message, Cmd_Argv(0)); - SZ_Print (&cls.message, " "); - } - if (Cmd_Argc() > 1) - SZ_Print (&cls.message, Cmd_Args()); - else - SZ_Print (&cls.message, "\n"); -} - - -/* -================ -Cmd_CheckParm - -Returns the position (1 to argc-1) in the command's argument list -where the given parameter apears, or 0 if not present -================ -*/ - -int Cmd_CheckParm (char *parm) -{ - int i; - - if (!parm) - Sys_Error ("Cmd_CheckParm: NULL"); - - for (i = 1; i < Cmd_Argc (); i++) - if (! Q_strcasecmp (parm, Cmd_Argv (i))) - return i; - - return 0; -} diff --git a/uquake/cmd.h b/uquake/cmd.h deleted file mode 100644 index f9eab24..0000000 --- a/uquake/cmd.h +++ /dev/null @@ -1,121 +0,0 @@ -/* -Copyright (C) 1996-1997 Id Software, Inc. - -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. - -*/ - -// cmd.h -- Command buffer and command execution - -//=========================================================================== - -/* - -Any number of commands can be added in a frame, from several different sources. -Most commands come from either keybindings or console line input, but remote -servers can also send across commands and entire text files can be execed. - -The + command line options are also added to the command buffer. - -The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute (); - -*/ - - -void Cbuf_Init (void); -// allocates an initial text buffer that will grow as needed - -void Cbuf_AddText (char *text); -// as new commands are generated from the console or keybindings, -// the text is added to the end of the command buffer. - -void Cbuf_InsertText (char *text); -// when a command wants to issue other commands immediately, the text is -// inserted at the beginning of the buffer, before any remaining unexecuted -// commands. - -void Cbuf_Execute (void); -// Pulls off \n terminated lines of text from the command buffer and sends -// them through Cmd_ExecuteString. Stops when the buffer is empty. -// Normally called once per frame, but may be explicitly invoked. -// Do not call inside a command function! - -//=========================================================================== - -/* - -Command execution takes a null terminated string, breaks it into tokens, -then searches for a command or variable that matches the first token. - -Commands can come from three sources, but the handler functions may choose -to dissallow the action or forward it to a remote server if the source is -not apropriate. - -*/ - -typedef void (*xcommand_t) (void); - -typedef enum -{ - src_client, // came in over a net connection as a clc_stringcmd - // host_client will be valid during this state. - src_command // from the command buffer -} cmd_source_t; - -extern cmd_source_t cmd_source; - -void Cmd_Init (void); - -void Cmd_AddCommand (char *cmd_name, xcommand_t function); -// called by the init functions of other parts of the program to -// register commands and functions to call for them. -// The cmd_name is referenced later, so it should not be in temp memory - -qboolean Cmd_Exists (char *cmd_name); -// used by the cvar code to check for cvar / command name overlap - -char *Cmd_CompleteCommand (char *partial); -// attempts to match a partial command for automatic command line completion -// returns NULL if nothing fits - -int Cmd_Argc (void); -char *Cmd_Argv (int arg); -char *Cmd_Args (void); -// The functions that execute commands get their parameters with these -// functions. Cmd_Argv () will return an empty string, not a NULL -// if arg > argc, so string operations are allways safe. - -int Cmd_CheckParm (char *parm); -// Returns the position (1 to argc-1) in the command's argument list -// where the given parameter apears, or 0 if not present - -void Cmd_TokenizeString (char *text); -// Takes a null terminated string. Does not need to be /n terminated. -// breaks the string up into arg tokens. - -void Cmd_ExecuteString (char *text, cmd_source_t src); -// Parses a single line of text into arguments and tries to execute it. -// The text can come from the command buffer, a remote client, or stdin. - -void Cmd_ForwardToServer (void); -// adds the current command line as a clc_stringcmd to the client message. -// things like godmode, noclip, etc, are commands directed to the server, -// so when they are typed in at the console, they will need to be forwarded. - -void Cmd_Print (char *text); -// used by command functions to send output to either the graphics console or -// passed as a print message to the client - diff --git a/uquake/common.c b/uquake/common.c index d5e2872..f9984f0 100644 --- a/uquake/common.c +++ b/uquake/common.c @@ -1,6 +1,8 @@ /* Copyright (C) 1996-1997 Id Software, Inc. Portions Copyright (C) 1999,2000 Nelson Rush. +Copyright (C) 1999,2000 contributors of the QuakeForge project +Please see the file "AUTHORS" for a list of contributors This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -23,20 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include - -/* Begin Generations */ -#ifdef _EXPERIMENTAL_ -#include "unzip.h" -#endif - -typedef unsigned char byte_t; - -#ifndef _AIX -typedef unsigned int uint_t; -typedef unsigned short ushort_t; -#endif -/* End Generations */ - #define NUM_SAFE_ARGVS 7 static char *largv[MAX_NUM_ARGVS + NUM_SAFE_ARGVS + 1]; @@ -70,27 +58,6 @@ qboolean standard_quake = true, rogue, hipnotic; extern cvar_t developer; -/* - - -All of Quake's data access is through a hierchal file system, but the contents of the file system can be transparently merged from several sources. - -The "base directory" is the path to the directory holding the quake.exe and all game directories. The sys_* files pass this to host_init in quakeparms_t->basedir. This can be overridden with the "-basedir" command line parm to allow code debugging in a different directory. The base directory is -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. - -*/ - //============================================================================ @@ -121,371 +88,6 @@ void InsertLinkAfter (link_t *l, link_t *after) l->next->prev = l; } -/* -============================================================================ - - LIBRARY REPLACEMENT FUNCTIONS - -============================================================================ -*/ - -void Q_memset (void *dest, int fill, int count) -{ - int i; - - if ( (((long)dest | count) & 3) == 0) - { - count >>= 2; - fill = fill | (fill<<8) | (fill<<16) | (fill<<24); - for (i=0 ; i>=2; - for (i=0 ; i= 'a' && c1 <= 'z') - c1 -= ('a' - 'A'); - if (c2 >= 'a' && c2 <= 'z') - c2 -= ('a' - 'A'); - if (c1 != c2) - return -1; // strings not equal - } - if (!c1) - return 0; // strings are equal -// s1++; -// s2++; - } - - return -1; -} - -int Q_strcasecmp (char *s1, char *s2) -{ - return Q_strncasecmp (s1, s2, 99999); -} - -int Q_atoi (char *str) -{ - int val; - int sign; - int c; - - if (*str == '-') - { - sign = -1; - str++; - } - else - sign = 1; - - val = 0; - -// -// check for hex -// - if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') ) - { - str += 2; - while (1) - { - c = *str++; - if (c >= '0' && c <= '9') - val = (val<<4) + c - '0'; - else if (c >= 'a' && c <= 'f') - val = (val<<4) + c - 'a' + 10; - else if (c >= 'A' && c <= 'F') - val = (val<<4) + c - 'A' + 10; - else - return val*sign; - } - } - -// -// check for character -// - if (str[0] == '\'') - { - return sign * str[1]; - } - -// -// assume decimal -// - while (1) - { - c = *str++; - if (c <'0' || c > '9') - return val*sign; - val = val*10 + c - '0'; - } - - return 0; -} - - -float Q_atof (char *str) -{ - double val; - int sign; - int c; - int decimal, total; - - if (*str == '-') - { - sign = -1; - str++; - } - else - sign = 1; - - val = 0; - -// -// check for hex -// - if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') ) - { - str += 2; - while (1) - { - c = *str++; - if (c >= '0' && c <= '9') - val = (val*16) + c - '0'; - else if (c >= 'a' && c <= 'f') - val = (val*16) + c - 'a' + 10; - else if (c >= 'A' && c <= 'F') - val = (val*16) + c - 'A' + 10; - else - return val*sign; - } - } - -// -// check for character -// - if (str[0] == '\'') - { - return sign * str[1]; - } - -// -// assume decimal -// - decimal = -1; - total = 0; - while (1) - { - c = *str++; - if (c == '.') - { - decimal = total; - continue; - } - if (c <'0' || c > '9') - break; - val = val*10 + c - '0'; - total++; - } - - if (decimal == -1) - return val*sign; - while (total > decimal) - { - val /= 10; - total--; - } - - return val*sign; -} - -/* -============================================================================ - - BYTE ORDER FUNCTIONS - -============================================================================ -*/ - -short (*BigShort) (short l); -short (*LittleShort) (short l); -int (*BigLong) (int l); -int (*LittleLong) (int l); -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; -} - /* ============================================================================== @@ -1128,804 +730,3 @@ int memsearch (byte *start, int count, int search) return i; return -1; } - -/* -============================================================================= - -QUAKE FILESYSTEM - -============================================================================= -*/ - -int 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 (%i files)\n", s->pack->filename, s->pack->numfiles); - } - else - Con_Printf ("%s\n", s->filename); - } -} - -/* -============ -COM_WriteFile - -The filename will be prefixed by the current game directory -============ -*/ -void COM_WriteFile (char *filename, void *data, int len) -{ - int handle; - char name[MAX_OSPATH]; - - snprintf(name, sizeof(name), "%s/%s", com_gamedir, filename); - - handle = Sys_FileOpenWrite (name); - if (handle == -1) - { - Sys_Printf ("COM_WriteFile: failed on %s\n", name); - return; - } - - Sys_Printf ("COM_WriteFile: %s\n", name); - Sys_FileWrite (handle, data, len); - Sys_FileClose (handle); -} - - -/* -============ -COM_CreatePath - -Only used for CopyFile -============ -*/ -void COM_CreatePath (char *path) -{ - char *ofs; - - for (ofs = path+1 ; *ofs ; ofs++) - { - if (*ofs == '/') - { // create the directory - *ofs = 0; - Sys_mkdir (path); - *ofs = '/'; - } - } -} - - -/* -=========== -COM_CopyFile - -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 remaining, count; - char buf[4096]; - - remaining = Sys_FileOpenRead (netpath, &in); - COM_CreatePath (cachepath); // create directories up to the cache file - out = Sys_FileOpenWrite (cachepath); - - while (remaining) - { - if (remaining < sizeof(buf)) - count = remaining; - else - count = sizeof(buf); - Sys_FileRead (in, buf, count); - Sys_FileWrite (out, buf, count); - remaining -= count; - } - - Sys_FileClose (in); - Sys_FileClose (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")) - 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 ; inumfiles ; i++) - if (!strcmp (pak->files[i].name, filename)) - { // found it! - if(developer.value) - Sys_Printf ("PackFile: %s : %s\n",pak->filename, filename); - if (handle) - { - *handle = pak->handle; - Sys_FileSeek (pak->handle, pak->files[i].filepos); - } - 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 - snprintf(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 - { -#if defined(_WIN32) - if ((strlen(netpath) < 2) || (netpath[1] != ':')) - snprintf(cachepath, sizeof(cachepath),"%s%s", com_cachedir, netpath); - else - snprintf(cachepath, sizeof(cachepath),"%s%s", com_cachedir, netpath+2); -#else - snprintf(cachepath, sizeof(cachepath),"%s%s", com_cachedir, netpath); -#endif - - cachetime = Sys_FileTime (cachepath); - - if (cachetime < findtime) - COM_CopyFile (netpath, cachepath); - strcpy (netpath, cachepath); - } - - if(developer.value) - Sys_Printf ("FindFile: %s\n",netpath); - com_filesize = Sys_FileOpenRead (netpath, &i); - if (handle) - *handle = i; - else - { - Sys_FileClose (i); - *file = fopen (netpath, "rb"); - } - return com_filesize; - } - - } - - Sys_Printf ("FindFile: can't find %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, NULL, 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; - - Sys_FileClose (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 = NULL; // quiet compiler warning - -// look for it in the filesystem or pack files - len = COM_OpenFile (path, &h); - if (h == -1) - return NULL; - -// 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 (); - Sys_FileRead (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 (Sys_FileOpenRead (packfile, &packhandle) == -1) - { -// Con_Printf ("Couldn't open %s\n", packfile); - return NULL; - } - - Sys_FileRead (packhandle, (void *)&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 %i files", packfile, numpackfiles); - - if (numpackfiles != PAK0_COUNT) - com_modified = true; // not the original file - - newfiles = Hunk_AllocName (numpackfiles * sizeof(packfile_t), "packfile"); - - Sys_FileSeek (packhandle, header.dirofs); - Sys_FileRead (packhandle, (void *)info, header.dirlen); - -// crc the directory to check for modifications - CRC_Init (&crc); - for (i=0 ; ifilename, packfile); - pack->handle = packhandle; - pack->numfiles = numpackfiles; - pack->files = newfiles; - - Con_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles); - return pack; -} - -// Todo: Make This work! :) -#if defined _EXPERIMENTAL_ && GENERATIONS -int -COM_pak3_checkfile(unzFile *pak, const char *path) -{ - int status; - - status = unzLocateFile(pak, path, 2); - return (status == UNZ_OK); -} - -void -COM_pak3_closepak(unzFile *pak) -{ - if (pak) - unzClose(pak); - pak = NULL; -} - -void -COM_pak3_close(unzFile *pak) -{ - unzCloseCurrentFile(pak); -} - - - -int -COM_pak3_read(unzFile *pak, void *buf, uint_t size, uint_t nmemb) -{ - int len; - - len = unzReadCurrentFile(pak, buf, size * nmemb); - return len / size; -} - -int -COM_pak3_open(unzFile *pak, const char *path) -{ - if (unzLocateFile(pak, path, 2) != UNZ_OK) - return 0; - if (unzOpenCurrentFile(pak) != UNZ_OK) - return 0; - return 1; -} - -uint_t -COM_pak3_getlen(unzFile *pak) -{ - unz_file_info info; - - if (unzGetCurrentFileInfo(pak, &info, NULL, 0, NULL, 0, NULL, 0) - != UNZ_OK) - return 0; - return info.uncompressed_size; -} - -uint_t -COM_pak3_readfile(unzFile *pak, const char *path, uint_t bufsize, byte_t *buf) -{ - uint_t len; - - if (!COM_pak3_open(pak,path)) - return 0; - - if ((len = COM_pak3_getlen(pak)) != 0) - { - if (COM_pak3_read(pak, (void*)buf, 1, len) != len) - len = 0; - } - COM_pak3_close(pak); - return len; -} - - -pack_t *COM_LoadQ3PackFile (char *packfile) -{ - - int i; - packfile_t *newfiles; - float numpackfiles; - unzFile *pak; - pack_t *pack_old; - int status; -// int packhandle; - dpackfile_t info[MAX_FILES_IN_PACK]; -// unz_file_info fileInfo; - char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; -// int err; - - pak = unzOpen(packfile); - -// numpackfiles = header.dirlen / sizeof(dpackfile_t); -// numpackfiles = COM_pak3_getlen(*pak)/sizeof(unzFile); - numpackfiles = 0; -//= COM_pak3_getlen(pak)/sizeof(unzFile); - Con_Printf ("Assigned Numpackfiles\n"); - - if (!pak) - return NULL; - - newfiles = Hunk_AllocName (numpackfiles * sizeof(unzFile), "packfile"); - - status=unzGoToFirstFile(pak); - - while(status == UNZ_OK) { -// for (i=0 ; ifilename, packfile); - //pack_old->handle = unzGetLocalExtrafield(packfile, NULL, NULL); - pack_old->numfiles = numpackfiles; - pack_old->files = newfiles; - - Con_Printf ("Added packfile %s (%.0f files)\n", packfile, numpackfiles); - - COM_pak3_close(pak); - return pack_old; -} -#endif - - - -/* -================ -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(searchpath_t)); - 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++) - { -#if defined _EXPERIMENTAL_ && GENERATIONS - if (COM_CheckParm ("-aftershock")) - { - snprintf(pakfile, sizeof(pakfile), "%s/pak%i.pk3", dir, i); - pak = COM_LoadQ3PackFile (pakfile); - } else { -#endif - snprintf(pakfile, sizeof(pakfile), "%s/pak%i.pak", dir, i); - pak = COM_LoadPackFile (pakfile); - -#if defined _EXPERIMENTAL_ && GENERATIONS - } -#endif - - if (!pak) - break; - search = Hunk_Alloc (sizeof(searchpath_t)); - 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, len; - char basedir[MAX_OSPATH]; - searchpath_t *search; - char * p; - char * games; - -// -// -basedir -// 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 -// 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 -// - 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 -// Adds basedir/gamedir as an override game -// - i = COM_CheckParm ("-game"); - if (i && i < com_argc-1) - { - com_modified = true; - - len = strlen(com_argv[i+1]) + 1; - games = (char *)malloc(len); - strcpy(games, com_argv[i+1]); - - for (p = strtok(games, ","); - p != NULL; - p = strtok(NULL, ",")) { - COM_AddGameDirectory (va("%s/%s", basedir, p)); - } - - free(games); - -// COM_AddGameDirectory (va("%s/%s", basedir, com_argv[i+1])); - } - -// -// -path [] ... -// Fully specifies the exact serach path, overriding the generated one -// - i = COM_CheckParm ("-path"); - if (i) - { - com_modified = true; - com_searchpaths = NULL; - while (++i < com_argc) - { - if (!com_argv[i] || com_argv[i][0] == '+' || com_argv[i][0] == '-') - break; - - search = Hunk_Alloc (sizeof(searchpath_t)); - if ( !strcmp(COM_FileExtension(com_argv[i]), "pak") ) - { - 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; -} - - diff --git a/uquake/cvar.c b/uquake/cvar.c deleted file mode 100644 index 615d67c..0000000 --- a/uquake/cvar.c +++ /dev/null @@ -1,225 +0,0 @@ -/* -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. - -*/ -// cvar.c -- dynamic variable tracking - -#include "quakedef.h" - -cvar_t *cvar_vars; -char *cvar_null_string = ""; - -/* -============ -Cvar_FindVar -============ -*/ -cvar_t *Cvar_FindVar (char *var_name) -{ - cvar_t *var; - - for (var=cvar_vars ; var ; var=var->next) - if (!Q_strcmp (var_name, var->name)) - return var; - - return NULL; -} - -/* -============ -Cvar_VariableValue -============ -*/ -float Cvar_VariableValue (char *var_name) -{ - cvar_t *var; - - var = Cvar_FindVar (var_name); - if (!var) - return 0; - return Q_atof (var->string); -} - - -/* -============ -Cvar_VariableString -============ -*/ -char *Cvar_VariableString (char *var_name) -{ - cvar_t *var; - - var = Cvar_FindVar (var_name); - if (!var) - return cvar_null_string; - return var->string; -} - - -/* -============ -Cvar_CompleteVariable -============ -*/ -char *Cvar_CompleteVariable (char *partial) -{ - cvar_t *cvar; - int len; - - len = Q_strlen(partial); - - if (!len) - return NULL; - -// check functions - for (cvar=cvar_vars ; cvar ; cvar=cvar->next) - if (!Q_strncmp (partial,cvar->name, len)) - return cvar->name; - - 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 = Q_strcmp(var->string, value); - - Z_Free (var->string); // free the old value string - - var->string = Z_Malloc (Q_strlen(value)+1); - Q_strcpy (var->string, value); - var->value = Q_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]; - - snprintf(val, sizeof(val), "%f",value); - Cvar_Set (var_name, val); -} - - -/* -============ -Cvar_RegisterVariable - -Adds a freestanding variable to the variable list. -============ -*/ -void Cvar_RegisterVariable (cvar_t *variable) -{ - char *oldstr; - -// first check to see if it has allready been defined - if (Cvar_FindVar (variable->name)) - { - Con_Printf ("Can't register variable %s, allready defined\n", variable->name); - return; - } - -// check for overlap with a command - if (Cmd_Exists (variable->name)) - { - Con_Printf ("Cvar_RegisterVariable: %s is a command\n", variable->name); - return; - } - -// copy the value off, because future sets will Z_Free it - oldstr = variable->string; - variable->string = Z_Malloc (Q_strlen(variable->string)+1); - Q_strcpy (variable->string, oldstr); - variable->value = Q_atof (variable->string); - -// link the variable in - variable->next = cvar_vars; - cvar_vars = variable; -} - -/* -============ -Cvar_Command - -Handles variable inspection and changing from the console -============ -*/ -qboolean Cvar_Command (void) -{ - cvar_t *v; - -// check variables - v = Cvar_FindVar (Cmd_Argv(0)); - if (!v) - return false; - -// perform a variable print or set - if (Cmd_Argc() == 1) - { - Con_Printf ("\"%s\" is \"%s\"\n", v->name, v->string); - return true; - } - - Cvar_Set (v->name, Cmd_Argv(1)); - return true; -} - - -/* -============ -Cvar_WriteVariables - -Writes lines containing "set variable value" for all variables -with the archive flag set to true. -============ -*/ -void Cvar_WriteVariables (FILE *f) -{ - cvar_t *var; - - for (var = cvar_vars ; var ; var = var->next) - if (var->archive) - fprintf (f, "%s \"%s\"\n", var->name, var->string); -} - diff --git a/uquake/lib_replace.c b/uquake/lib_replace.c new file mode 100644 index 0000000..3e5dc0d --- /dev/null +++ b/uquake/lib_replace.c @@ -0,0 +1,319 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. +Portions Copyright (C) 1999,2000 Nelson Rush. +Copyright (C) 1999,2000 contributors of the QuakeForge project +Please see the file "AUTHORS" for a list of contributors + +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. + +*/ +// common.c -- misc functions used in client and server + +/* +============================================================================ + + LIBRARY REPLACEMENT FUNCTIONS + +============================================================================ +*/ + +void Q_memset (void *dest, int fill, int count) +{ + int i; + + if ( (((long)dest | count) & 3) == 0) + { + count >>= 2; + fill = fill | (fill<<8) | (fill<<16) | (fill<<24); + for (i=0 ; i>=2; + for (i=0 ; i= 'a' && c1 <= 'z') + c1 -= ('a' - 'A'); + if (c2 >= 'a' && c2 <= 'z') + c2 -= ('a' - 'A'); + if (c1 != c2) + return -1; // strings not equal + } + if (!c1) + return 0; // strings are equal +// s1++; +// s2++; + } + + return -1; +} + +int Q_strcasecmp (char *s1, char *s2) +{ + return Q_strncasecmp (s1, s2, 99999); +} + +int Q_atoi (char *str) +{ + int val; + int sign; + int c; + + if (*str == '-') + { + sign = -1; + str++; + } + else + sign = 1; + + val = 0; + +// +// check for hex +// + if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') ) + { + str += 2; + while (1) + { + c = *str++; + if (c >= '0' && c <= '9') + val = (val<<4) + c - '0'; + else if (c >= 'a' && c <= 'f') + val = (val<<4) + c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val = (val<<4) + c - 'A' + 10; + else + return val*sign; + } + } + +// +// check for character +// + if (str[0] == '\'') + { + return sign * str[1]; + } + +// +// assume decimal +// + while (1) + { + c = *str++; + if (c <'0' || c > '9') + return val*sign; + val = val*10 + c - '0'; + } + + return 0; +} + + +float Q_atof (char *str) +{ + double val; + int sign; + int c; + int decimal, total; + + if (*str == '-') + { + sign = -1; + str++; + } + else + sign = 1; + + val = 0; + +// +// check for hex +// + if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') ) + { + str += 2; + while (1) + { + c = *str++; + if (c >= '0' && c <= '9') + val = (val*16) + c - '0'; + else if (c >= 'a' && c <= 'f') + val = (val*16) + c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + val = (val*16) + c - 'A' + 10; + else + return val*sign; + } + } + +// +// check for character +// + if (str[0] == '\'') + { + return sign * str[1]; + } + +// +// assume decimal +// + decimal = -1; + total = 0; + while (1) + { + c = *str++; + if (c == '.') + { + decimal = total; + continue; + } + if (c <'0' || c > '9') + break; + val = val*10 + c - '0'; + total++; + } + + if (decimal == -1) + return val*sign; + while (total > decimal) + { + val /= 10; + total--; + } + + return val*sign; +} diff --git a/uquake/quakefs.c b/uquake/quakefs.c new file mode 100644 index 0000000..d854500 --- /dev/null +++ b/uquake/quakefs.c @@ -0,0 +1,840 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. +Portions Copyright (C) 1999,2000 Nelson Rush. +Copyright (C) 1999,2000 contributors of the QuakeForge project +Please see the file "AUTHORS" for a list of contributors + +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. + +*/ +// common.c -- misc functions used in client and server + +/* +All of Quake's data access is through a hierchal file system, but the contents of the file system can be transparently merged from several sources. + +The "base directory" is the path to the directory holding the quake.exe and all game directories. The sys_* files pass this to host_init in quakeparms_t->basedir. This can be overridden with the "-basedir" command line parm to allow code debugging in a different directory. The base directory is +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. + +*/ + +/* +============================================================================= + +QUAKE FILESYSTEM + +============================================================================= +*/ + +/* Begin Generations */ +#ifdef _EXPERIMENTAL_ +#include "unzip.h" +#endif + +typedef unsigned char byte_t; + +#ifndef _AIX +typedef unsigned int uint_t; +typedef unsigned short ushort_t; +#endif +/* End Generations */ + +int 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 (%i files)\n", s->pack->filename, s->pack->numfiles); + } + else + Con_Printf ("%s\n", s->filename); + } +} + +/* +============ +COM_WriteFile + +The filename will be prefixed by the current game directory +============ +*/ +void COM_WriteFile (char *filename, void *data, int len) +{ + int handle; + char name[MAX_OSPATH]; + + snprintf(name, sizeof(name), "%s/%s", com_gamedir, filename); + + handle = Sys_FileOpenWrite (name); + if (handle == -1) + { + Sys_Printf ("COM_WriteFile: failed on %s\n", name); + return; + } + + Sys_Printf ("COM_WriteFile: %s\n", name); + Sys_FileWrite (handle, data, len); + Sys_FileClose (handle); +} + + +/* +============ +COM_CreatePath + +Only used for CopyFile +============ +*/ +void COM_CreatePath (char *path) +{ + char *ofs; + + for (ofs = path+1 ; *ofs ; ofs++) + { + if (*ofs == '/') + { // create the directory + *ofs = 0; + Sys_mkdir (path); + *ofs = '/'; + } + } +} + + +/* +=========== +COM_CopyFile + +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 remaining, count; + char buf[4096]; + + remaining = Sys_FileOpenRead (netpath, &in); + COM_CreatePath (cachepath); // create directories up to the cache file + out = Sys_FileOpenWrite (cachepath); + + while (remaining) + { + if (remaining < sizeof(buf)) + count = remaining; + else + count = sizeof(buf); + Sys_FileRead (in, buf, count); + Sys_FileWrite (out, buf, count); + remaining -= count; + } + + Sys_FileClose (in); + Sys_FileClose (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")) + 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 ; inumfiles ; i++) + if (!strcmp (pak->files[i].name, filename)) + { // found it! + if(developer.value) + Sys_Printf ("PackFile: %s : %s\n",pak->filename, filename); + if (handle) + { + *handle = pak->handle; + Sys_FileSeek (pak->handle, pak->files[i].filepos); + } + 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 + snprintf(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 + { +#if defined(_WIN32) + if ((strlen(netpath) < 2) || (netpath[1] != ':')) + snprintf(cachepath, sizeof(cachepath),"%s%s", com_cachedir, netpath); + else + snprintf(cachepath, sizeof(cachepath),"%s%s", com_cachedir, netpath+2); +#else + snprintf(cachepath, sizeof(cachepath),"%s%s", com_cachedir, netpath); +#endif + + cachetime = Sys_FileTime (cachepath); + + if (cachetime < findtime) + COM_CopyFile (netpath, cachepath); + strcpy (netpath, cachepath); + } + + if(developer.value) + Sys_Printf ("FindFile: %s\n",netpath); + com_filesize = Sys_FileOpenRead (netpath, &i); + if (handle) + *handle = i; + else + { + Sys_FileClose (i); + *file = fopen (netpath, "rb"); + } + return com_filesize; + } + + } + + Sys_Printf ("FindFile: can't find %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, NULL, 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; + + Sys_FileClose (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 = NULL; // quiet compiler warning + +// look for it in the filesystem or pack files + len = COM_OpenFile (path, &h); + if (h == -1) + return NULL; + +// 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 (); + Sys_FileRead (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 (Sys_FileOpenRead (packfile, &packhandle) == -1) + { +// Con_Printf ("Couldn't open %s\n", packfile); + return NULL; + } + Sys_FileRead (packhandle, (void *)&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 %i files", packfile, numpackfiles); + + if (numpackfiles != PAK0_COUNT) + com_modified = true; // not the original file + + newfiles = Hunk_AllocName (numpackfiles * sizeof(packfile_t), "packfile"); + + Sys_FileSeek (packhandle, header.dirofs); + Sys_FileRead (packhandle, (void *)info, header.dirlen); + +// crc the directory to check for modifications + CRC_Init (&crc); + for (i=0 ; ifilename, packfile); + pack->handle = packhandle; + pack->numfiles = numpackfiles; + pack->files = newfiles; + + Con_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles); + return pack; +} + +int +COM_pak3_checkfile(unzFile *pak, const char *path) +{ + int status; + + status = unzLocateFile(pak, path, 2); + return (status == UNZ_OK); +} + +void +COM_pak3_closepak(unzFile *pak) +{ + if (pak) + unzClose(pak); + pak = NULL; +} + +void +COM_pak3_close(unzFile *pak) +{ + unzCloseCurrentFile(pak); +} + + + +int +COM_pak3_read(unzFile *pak, void *buf, uint_t size, uint_t nmemb) +{ + int len; + + len = unzReadCurrentFile(pak, buf, size * nmemb); + return len / size; +} + +int +COM_pak3_open(unzFile *pak, const char *path) +{ + if (unzLocateFile(pak, path, 2) != UNZ_OK) + return 0; + if (unzOpenCurrentFile(pak) != UNZ_OK) + return 0; + return 1; +} + +uint_t +COM_pak3_getlen(unzFile *pak) +{ + unz_file_info info; + + if (unzGetCurrentFileInfo(pak, &info, NULL, 0, NULL, 0, NULL, 0) + != UNZ_OK) + return 0; + return info.uncompressed_size; +} + +uint_t +COM_pak3_readfile(unzFile *pak, const char *path, uint_t bufsize, byte_t *buf) +{ + uint_t len; + + if (!COM_pak3_open(pak,path)) + return 0; + + if ((len = COM_pak3_getlen(pak)) != 0) + { + if (COM_pak3_read(pak, (void*)buf, 1, len) != len) + len = 0; + } + COM_pak3_close(pak); + return len; +} + + +// Todo: Make This work! :) +#if defined _EXPERIMENTAL_ && GENERATIONS +pack_t *COM_LoadQ3PackFile (char *packfile) +{ + + int i; + packfile_t *newfiles; + float numpackfiles; + unzFile *pak; + pack_t *pack_old; + int status; +// int packhandle; + dpackfile_t info[MAX_FILES_IN_PACK]; +// unz_file_info fileInfo; + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; +// int err; + + pak = unzOpen(packfile); + +// numpackfiles = header.dirlen / sizeof(dpackfile_t); +// numpackfiles = COM_pak3_getlen(*pak)/sizeof(unzFile); + numpackfiles = 0; +//= COM_pak3_getlen(pak)/sizeof(unzFile); + Con_Printf ("Assigned Numpackfiles\n"); + + if (!pak) + return NULL; + + newfiles = Hunk_AllocName (numpackfiles * sizeof(unzFile), "packfile"); + + status=unzGoToFirstFile(pak); + + while(status == UNZ_OK) { + unzGetCurrentFileInfo(pak,NULL,&szCurrentFileName,64,NULL,0,NULL,0); + + if(strcmp(newfiles[i].name, szCurrentFileName)==0) + break; + + strcpy (newfiles[i].name, szCurrentFileName); + Con_Printf ("strcpy'ed %s into newfiles[%i].name Ok\n",szCurrentFileName, i); + + newfiles[i].filepos = LittleLong(unztell(pak)); +// newfiles[i].filelen = LittleLong(COM_pak3_readfile(pak,packfile,64,64)); + + Con_Printf ("Added File\n"); + status=unzGoToNextFile(pak); + ++numpackfiles; + ++i; + } + + Con_Printf ("Added files in %s to game data Ok\n", packfile); + + pack_old = Hunk_Alloc (sizeof (pack_t)); + strcpy (pack_old->filename, packfile); + //pack_old->handle = unzGetLocalExtrafield(packfile, NULL, NULL); + pack_old->numfiles = numpackfiles; + pack_old->files = newfiles; + + Con_Printf ("Added packfile %s (%.0f files)\n", packfile, numpackfiles); + + COM_pak3_close(pak); + return pack_old; +} +#endif + + +/* +================ +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(searchpath_t)); + 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++) + { + snprintf(pakfile, sizeof(pakfile), "%s/pak%i.pak", dir, i); + pak = COM_LoadPackFile (pakfile); + if (!pak) + break; + search = Hunk_Alloc (sizeof(searchpath_t)); + 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, len; + char basedir[MAX_OSPATH]; + searchpath_t *search; + char * p; + char * games; + +// +// -basedir +// 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 +// 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 +// + 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 +// Adds basedir/gamedir as an override game +// + i = COM_CheckParm ("-game"); + if (i && i < com_argc-1) + { + com_modified = true; + + len = strlen(com_argv[i+1]) + 1; + games = (char *)malloc(len); + strcpy(games, com_argv[i+1]); + + for (p = strtok(games, ","); + p != NULL; + p = strtok(NULL, ",")) { + COM_AddGameDirectory (va("%s/%s", basedir, p)); + } + + free(games); + +// COM_AddGameDirectory (va("%s/%s", basedir, com_argv[i+1])); + } + +// +// -path [] ... +// Fully specifies the exact serach path, overriding the generated one +// + i = COM_CheckParm ("-path"); + if (i) + { + com_modified = true; + com_searchpaths = NULL; + while (++i < com_argc) + { + if (!com_argv[i] || com_argv[i][0] == '+' || com_argv[i][0] == '-') + break; + + search = Hunk_Alloc (sizeof(searchpath_t)); + if ( !strcmp(COM_FileExtension(com_argv[i]), "pak") ) + { + 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; +} + +