diff --git a/Makefile b/Makefile index 9b0de036..95404b59 100644 --- a/Makefile +++ b/Makefile @@ -219,7 +219,7 @@ ifeq ($(OS),Win32) # workaround: OpenGL library for Win32 is called opengl32.dll LIBS_GL = -lopengl32 # workaround: no -ldl on Win32 - LIBS_DL = + LIBS_DL = else ifeq ($(OS),Darwin) @@ -435,6 +435,7 @@ binaries-radiant-core: \ binaries-tools: \ binaries-tools-quake2 \ binaries-tools-quake3 \ + binaries-mbspc \ .PHONY: binaries-tools-quake2 binaries-tools-quake2: \ @@ -472,6 +473,11 @@ binaries-q3map2: \ $(INSTALLDIR)/q3map2.$(EXE) \ $(INSTALLDIR)/q3map2 \ +.PHONY: binaries-mbspc +binaries-mbspc: \ + $(INSTALLDIR)/mbspc.$(EXE) \ + $(INSTALLDIR)/mbspc \ + .PHONY: clean clean: @@ -1103,6 +1109,68 @@ $(INSTALLDIR)/heretic2/h2data.$(EXE): \ libl_net.$(A) \ $(if $(findstring $(OS),Win32),icons/h2data.o,) \ +$(INSTALLDIR)/mbspc.$(EXE): CPPFLAGS_EXTRA := -Wstrict-prototypes -DNDEBUG -DBSPC -DBSPCINCLUDE +$(INSTALLDIR)/mbspc.$(EXE): \ + tools/mbspc/botlib/be_aas_bspq3.o \ + tools/mbspc/botlib/be_aas_cluster.o \ + tools/mbspc/botlib/be_aas_move.o \ + tools/mbspc/botlib/be_aas_optimize.o \ + tools/mbspc/botlib/be_aas_reach.o \ + tools/mbspc/botlib/be_aas_sample.o \ + tools/mbspc/botlib/l_libvar.o \ + tools/mbspc/botlib/l_precomp.o \ + tools/mbspc/botlib/l_script.o \ + tools/mbspc/botlib/l_struct.o \ + tools/mbspc/mbspc/aas_areamerging.o \ + tools/mbspc/mbspc/aas_cfg.o \ + tools/mbspc/mbspc/aas_create.o \ + tools/mbspc/mbspc/aas_edgemelting.o \ + tools/mbspc/mbspc/aas_facemerging.o \ + tools/mbspc/mbspc/aas_file.o \ + tools/mbspc/mbspc/aas_gsubdiv.o \ + tools/mbspc/mbspc/aas_map.o \ + tools/mbspc/mbspc/aas_prunenodes.o \ + tools/mbspc/mbspc/aas_store.o \ + tools/mbspc/mbspc/be_aas_bspc.o \ + tools/mbspc/mbspc/brushbsp.o \ + tools/mbspc/mbspc/bspc.o \ + tools/mbspc/mbspc/csg.o \ + tools/mbspc/mbspc/faces.o \ + tools/mbspc/mbspc/glfile.o \ + tools/mbspc/mbspc/l_bsp_ent.o \ + tools/mbspc/mbspc/l_bsp_hl.o \ + tools/mbspc/mbspc/l_bsp_q1.o \ + tools/mbspc/mbspc/l_bsp_q2.o \ + tools/mbspc/mbspc/l_bsp_q3.o \ + tools/mbspc/mbspc/l_bsp_sin.o \ + tools/mbspc/mbspc/l_cmd.o \ + tools/mbspc/mbspc/l_log.o \ + tools/mbspc/mbspc/l_math.o \ + tools/mbspc/mbspc/l_mem.o \ + tools/mbspc/mbspc/l_poly.o \ + tools/mbspc/mbspc/l_qfiles.o \ + tools/mbspc/mbspc/l_threads.o \ + tools/mbspc/mbspc/l_utils.o \ + tools/mbspc/mbspc/leakfile.o \ + tools/mbspc/mbspc/map.o \ + tools/mbspc/mbspc/map_hl.o \ + tools/mbspc/mbspc/map_q1.o \ + tools/mbspc/mbspc/map_q2.o \ + tools/mbspc/mbspc/map_q3.o \ + tools/mbspc/mbspc/map_sin.o \ + tools/mbspc/mbspc/nodraw.o \ + tools/mbspc/mbspc/portals.o \ + tools/mbspc/mbspc/prtfile.o \ + tools/mbspc/mbspc/textures.o \ + tools/mbspc/mbspc/tree.o \ + tools/mbspc/mbspc/writebsp.o \ + tools/mbspc/qcommon/cm_load.o \ + tools/mbspc/qcommon/cm_patch.o \ + tools/mbspc/qcommon/cm_test.o \ + tools/mbspc/qcommon/cm_trace.o \ + tools/mbspc/qcommon/md4.o \ + tools/mbspc/qcommon/unzip.o \ + .PHONY: install-data install-data: binaries $(MKDIR) $(INSTALLDIR)/games @@ -1119,7 +1187,7 @@ install-data: binaries ifeq ($(OS),Win32) install-dll: binaries ifeq ($(INSTALL_DLLS),yes) - MKDIR="$(MKDIR)" CP="$(CP)" CAT="$(CAT)" GTKDIR="$(GTKDIR)" WHICHDLL="$(WHICHDLL)" INSTALLDIR="$(INSTALLDIR)" $(SH) $(DLLINSTALL) + MKDIR="$(MKDIR)" CP="$(CP)" CAT="$(CAT)" GTKDIR="$(GTKDIR)" WHICHDLL="$(WHICHDLL)" INSTALLDIR="$(INSTALLDIR)" $(SH) $(DLLINSTALL) endif else install-dll: binaries diff --git a/tools/mbspc/Makefile b/tools/mbspc/Makefile new file mode 100644 index 00000000..81b99b2b --- /dev/null +++ b/tools/mbspc/Makefile @@ -0,0 +1,179 @@ +# Makefile for the MBSPC utility +# Copyright (C) 2012 Laszlo Menczel +# Platforms: Linux and Win32/MinGW + +#-------------------------------------------------------------------- +# Detection of platform and architecture +#-------------------------------------------------------------------- + +PLATFORM = $(shell uname|sed -e s/_.*//|tr '[:upper:]' '[:lower:]') + +ifeq ($(PLATFORM),linux) + ARCH = x86_64 + TMP = $(shell uname -a | grep x86_64) +ifeq (x$(TMP),x) + ARCH = x86 +endif +endif + +ifeq ($(PLATFORM),mingw32) + ARCH = x86 +endif + +#-------------------------------------------------------------------- +# MNT_DIR = path to MBSPC source (e.g. "/home/somebody/src/mbspc") +#-------------------------------------------------------------------- + +ifeq ($(PLATFORM),linux) + MNT_DIR = /root/Progdev/mbspc + BLD_DIR = $(MNT_DIR)/build/linux + OS_CFLAGS = -D__linux__ + LIBS = -ldl -lm + BIN_EXT = +endif + +ifeq ($(PLATFORM),mingw32) + MNT_DIR = d:/Msys/home/menczel/mbspc + BLD_DIR = $(MNT_DIR)/build/win32 + OS_CFLAGS = -D_WIN32 + LIBS = -lws2_32 -lwinmm + BIN_EXT = .exe +endif + +#-------------------------------------------------------------------- +# Locations +#-------------------------------------------------------------------- + +BOT_DIR = $(MNT_DIR)/botlib +BSP_DIR = $(MNT_DIR)/mbspc +COM_DIR = $(MNT_DIR)/qcommon +OBJ_DIR = $(BLD_DIR)/obj + +#-------------------------------------------------------------------- +# Flags +#-------------------------------------------------------------------- + +BASE_CFLAGS = -c -O3 -Wall -Wstrict-prototypes -fno-strict-aliasing \ + -MMD -DNDEBUG -DBSPC -DBSPCINCLUDE + +CFLAGS = $(BASE_CFLAGS) $(OS_CFLAGS) + +#-------------------------------------------------------------------- +# Compile commands +#-------------------------------------------------------------------- + +CC = gcc$(BIN_EXT) + +$(OBJ_DIR)/%.o: $(BSP_DIR)/%.c + $(CC) $(CFLAGS) -o $@ -c $< + +$(OBJ_DIR)/%.o: $(BOT_DIR)/%.c + $(CC) $(CFLAGS) -o $@ -c $< + +$(OBJ_DIR)/%.o: $(COM_DIR)/%.c + $(CC) $(CFLAGS) -o $@ -c $< + +#-------------------------------------------------------------------- +# Objects +#-------------------------------------------------------------------- + +BSP_OBJ = \ + $(OBJ_DIR)/aas_areamerging.o \ + $(OBJ_DIR)/aas_cfg.o \ + $(OBJ_DIR)/aas_create.o \ + $(OBJ_DIR)/aas_edgemelting.o \ + $(OBJ_DIR)/aas_facemerging.o \ + $(OBJ_DIR)/aas_file.o \ + $(OBJ_DIR)/aas_gsubdiv.o \ + $(OBJ_DIR)/aas_map.o \ + $(OBJ_DIR)/aas_prunenodes.o \ + $(OBJ_DIR)/aas_store.o \ + $(OBJ_DIR)/be_aas_bspc.o \ + $(OBJ_DIR)/brushbsp.o \ + $(OBJ_DIR)/bsp_ent.o \ + $(OBJ_DIR)/bsp_hl.o \ + $(OBJ_DIR)/bsp_q1.o \ + $(OBJ_DIR)/bsp_q2.o \ + $(OBJ_DIR)/bsp_q3.o \ + $(OBJ_DIR)/bsp_sin.o \ + $(OBJ_DIR)/bspc.o \ + $(OBJ_DIR)/bspcmd.o \ + $(OBJ_DIR)/csg.o \ + $(OBJ_DIR)/faces.o \ + $(OBJ_DIR)/glfile.o \ + $(OBJ_DIR)/leakfile.o \ + $(OBJ_DIR)/log.o \ + $(OBJ_DIR)/map.o \ + $(OBJ_DIR)/map_hl.o \ + $(OBJ_DIR)/map_q1.o \ + $(OBJ_DIR)/map_q2.o \ + $(OBJ_DIR)/map_q3.o \ + $(OBJ_DIR)/map_sin.o \ + $(OBJ_DIR)/math.o \ + $(OBJ_DIR)/mem.o \ + $(OBJ_DIR)/nodraw.o \ + $(OBJ_DIR)/poly.o \ + $(OBJ_DIR)/portals.o \ + $(OBJ_DIR)/prtfile.o \ + $(OBJ_DIR)/qfiles.o \ + $(OBJ_DIR)/textures.o \ + $(OBJ_DIR)/threads.o \ + $(OBJ_DIR)/tree.o \ + $(OBJ_DIR)/utils.o \ + $(OBJ_DIR)/writebsp.o \ + \ + $(OBJ_DIR)/be_aas_bspq3.o \ + $(OBJ_DIR)/be_aas_cluster.o \ + $(OBJ_DIR)/be_aas_move.o \ + $(OBJ_DIR)/be_aas_optimize.o \ + $(OBJ_DIR)/be_aas_reach.o \ + $(OBJ_DIR)/be_aas_sample.o \ + $(OBJ_DIR)/l_libvar.o \ + $(OBJ_DIR)/l_precomp.o \ + $(OBJ_DIR)/l_script.o \ + $(OBJ_DIR)/l_struct.o \ + \ + $(OBJ_DIR)/cm_load.o \ + $(OBJ_DIR)/cm_patch.o \ + $(OBJ_DIR)/cm_test.o \ + $(OBJ_DIR)/cm_trace.o \ + $(OBJ_DIR)/md4.o \ + $(OBJ_DIR)/unzip.o + +#-------------------------------------------------------------------- +# Targets +#-------------------------------------------------------------------- + +BSP_EXE = $(BLD_DIR)/mbspc$(BIN_EXT) + +all: $(BSP_EXE) + +clean: + rm -f $(BSP_OBJ) + rm -f $(BSP_EXE) + + +veryclean: + rm -f $(BSP_OBJ) + rm -f $(BSP_EXE) + rm -f $(DEP_FILES) + +cleandep: + rm -f $(DEP_FILES) + +#------------------------------------------------------------------- +# Build rules +#------------------------------------------------------------------- + +$(BSP_EXE): $(BSP_OBJ) + $(CC) $(BSP_LDFLAGS) -o $@ $(BSP_OBJ) $(LIBS) + +#-------------------------------------------------------------------- +# Dependencies +#-------------------------------------------------------------------- + +DEP_FILES = $(filter %.d,$(BSP_OBJ:%.o=%.d)) + +-include $(DEP_FILES) + +.PHONY: all clean xclean cleandep diff --git a/tools/mbspc/README b/tools/mbspc/README new file mode 100644 index 00000000..64ca60db --- /dev/null +++ b/tools/mbspc/README @@ -0,0 +1,38 @@ +MBSPC - modified BSPC utility +***************************** + +Copyright (C) 2012 Laszlo Menczel (laszlo.menczel@gmail.com) + +Original version: Copyright (C) id Software + +This is an enhanced version of the BSPC utility. It is based on version +2.1h of the source code. + +Restored features: + +1. Restored the capability of decompiling a BSP file to an editable MAP +file + +3. Restored the capability of updating the entity list in a BSP file +using entity definitions from a text file. + +New features: + +1. When MBSPC is used for converting BSP files to MAP files, the correct +texture name is written for every brush side (but see Note 1.). + +2. Added a new switch '-entlist'. This will produce a list of entity +definitions from a BSP file in an editable ASCII text file. + +3. Added a new switch '-texinfo'. If you specify this switch, MBSPC writes +a simple ASCII text file (extension '.txi') containing the list of textures +and models (i.e. all shaders) used by in the BSP file specified. + +Note 1. +------- +This new feature works only with Q3A BSP files (at present). + +Texture alignment info (shift, scale, rotation) is not written to the +MAP file produced. It is not trivial to obtain this info from the BSP, and +I did not need it when I coded this modification, sorry. If you need this +functionality, add the necessary code. diff --git a/tools/mbspc/botlib/be_aas_bsp.h b/tools/mbspc/botlib/be_aas_bsp.h index aa05e4b7..4780f0e1 100644 --- a/tools/mbspc/botlib/be_aas_bsp.h +++ b/tools/mbspc/botlib/be_aas_bsp.h @@ -29,7 +29,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -#ifdef AASINTERN //loads the given BSP file int AAS_LoadBSPFile(void); //dump the loaded BSP data @@ -53,7 +52,6 @@ qboolean AAS_EntityCollision(int entnum, //for debugging void AAS_PrintFreeBSPLinks(char *str); // -#endif //AASINTERN #define MAX_EPAIRKEY 128 diff --git a/tools/mbspc/botlib/be_aas_bspq3.c b/tools/mbspc/botlib/be_aas_bspq3.c index 97c286d6..ae1fbc41 100644 --- a/tools/mbspc/botlib/be_aas_bspq3.c +++ b/tools/mbspc/botlib/be_aas_bspq3.c @@ -29,16 +29,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -#include "../game/q_shared.h" +#include "../qcommon/q_shared.h" #include "l_memory.h" #include "l_script.h" #include "l_precomp.h" #include "l_struct.h" #include "aasfile.h" -#include "../game/botlib.h" -#include "../game/be_aas.h" +#include "botlib.h" +#include "be_aas.h" #include "be_aas_funcs.h" #include "be_aas_def.h" +#include "be_aas_bsp.h" extern botlib_import_t botimport; diff --git a/tools/mbspc/botlib/be_aas_cluster.c b/tools/mbspc/botlib/be_aas_cluster.c index 118dd0a8..dc30b655 100644 --- a/tools/mbspc/botlib/be_aas_cluster.c +++ b/tools/mbspc/botlib/be_aas_cluster.c @@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -#include "../game/q_shared.h" +#include "../qcommon/q_shared.h" #include "l_memory.h" #include "l_script.h" #include "l_precomp.h" @@ -38,12 +38,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "l_memory.h" #include "l_libvar.h" #include "aasfile.h" -#include "../game/botlib.h" -#include "../game/be_aas.h" +#include "botlib.h" +#include "be_aas.h" #include "be_aas_funcs.h" #include "be_aas_def.h" +#include "be_aas_cluster.h" +#include "be_aas_reach.h" + +void AAS_Error(char *fmt, ...); extern botlib_import_t botimport; +extern aas_t aasworld; #define AAS_MAX_PORTALS 65536 #define AAS_MAX_PORTALINDEXSIZE 65536 diff --git a/tools/mbspc/botlib/be_aas_move.c b/tools/mbspc/botlib/be_aas_move.c index 3433153f..c9c03a85 100644 --- a/tools/mbspc/botlib/be_aas_move.c +++ b/tools/mbspc/botlib/be_aas_move.c @@ -29,19 +29,26 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -#include "../game/q_shared.h" +#include "../qcommon/q_shared.h" #include "l_memory.h" #include "l_script.h" #include "l_precomp.h" #include "l_struct.h" #include "l_libvar.h" #include "aasfile.h" -#include "../game/botlib.h" -#include "../game/be_aas.h" +#include "botlib.h" +#include "be_aas.h" #include "be_aas_funcs.h" #include "be_aas_def.h" +#include "be_aas_bsp.h" +#include "be_aas_sample.h" +#include "be_aas_move.h" + +void AAS_DebugLine(vec3_t start, vec3_t end, int color); +void AAS_ClearShownDebugLines(void); extern botlib_import_t botimport; +extern aas_t aasworld; aas_settings_t aassettings; @@ -389,9 +396,6 @@ void AAS_Accelerate(vec3_t velocity, float frametime, vec3_t wishdir, float wish //=========================================================================== void AAS_AirControl(vec3_t start, vec3_t end, vec3_t velocity, vec3_t cmdmove) { - vec3_t dir; - - VectorSubtract(end, start, dir); } //end of the function AAS_AirControl //=========================================================================== // applies ground friction to the given velocity @@ -518,7 +522,7 @@ int AAS_ClientMovementPrediction(struct aas_clientmove_s *move, float phys_maxstep, phys_maxsteepness, phys_jumpvel, friction; float gravity, delta, maxvel, wishspeed, accelerate; //float velchange, newvel; - int n, i, j, pc, step, swimming, ax, crouch, event, jump_frame, areanum; + int n, i, j, pc, step, swimming, crouch, event, jump_frame, areanum; int areas[20], numareas; vec3_t points[20]; vec3_t org, end, feet, start, stepend, lastorg, wishdir; @@ -574,7 +578,6 @@ int AAS_ClientMovementPrediction(struct aas_clientmove_s *move, //apply command movement if (n < cmdframes) { - ax = 0; maxvel = phys_maxwalkvelocity; accelerate = phys_airaccelerate; VectorCopy(cmdmove, wishdir); @@ -598,13 +601,11 @@ int AAS_ClientMovementPrediction(struct aas_clientmove_s *move, { accelerate = phys_walkaccelerate; } //end else - ax = 2; } //end if if (swimming) { maxvel = phys_maxswimvelocity; accelerate = phys_swimaccelerate; - ax = 3; } //end if else { diff --git a/tools/mbspc/botlib/be_aas_optimize.c b/tools/mbspc/botlib/be_aas_optimize.c index 605dc4db..88c7bdd3 100644 --- a/tools/mbspc/botlib/be_aas_optimize.c +++ b/tools/mbspc/botlib/be_aas_optimize.c @@ -30,18 +30,19 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -#include "../game/q_shared.h" +#include "../qcommon/q_shared.h" #include "l_libvar.h" #include "l_memory.h" #include "l_script.h" #include "l_precomp.h" #include "l_struct.h" #include "aasfile.h" -#include "../game/botlib.h" -#include "../game/be_aas.h" +#include "botlib.h" +#include "be_aas.h" #include "be_aas_funcs.h" #include "be_interface.h" #include "be_aas_def.h" +extern aas_t aasworld; typedef struct optimized_s { diff --git a/tools/mbspc/botlib/be_aas_reach.c b/tools/mbspc/botlib/be_aas_reach.c index 4b69d289..3abcf121 100644 --- a/tools/mbspc/botlib/be_aas_reach.c +++ b/tools/mbspc/botlib/be_aas_reach.c @@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -#include "../game/q_shared.h" +#include "../qcommon/q_shared.h" #include "l_log.h" #include "l_memory.h" #include "l_script.h" @@ -37,15 +37,24 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "l_precomp.h" #include "l_struct.h" #include "aasfile.h" -#include "../game/botlib.h" -#include "../game/be_aas.h" +#include "botlib.h" +#include "be_aas.h" #include "be_aas_funcs.h" #include "be_aas_def.h" +#include "be_aas_bsp.h" +#include "be_aas_sample.h" +#include "be_aas_reach.h" +#include "be_aas_move.h" + +void AAS_Error(char *fmt, ...); extern int Sys_MilliSeconds(void); extern botlib_import_t botimport; +extern aas_t aasworld; + +extern aas_settings_t aassettings; //#define REACH_DEBUG @@ -289,7 +298,7 @@ int AAS_GetJumpPadInfo(int ent, vec3_t areastart, vec3_t absmins, vec3_t absmaxs //=========================================================================== int AAS_BestReachableFromJumpPadArea(vec3_t origin, vec3_t mins, vec3_t maxs) { - int area2num, ent, bot_visualizejumppads, bestareanum; + int ent, bot_visualizejumppads, bestareanum; float volume, bestareavolume; vec3_t areastart, cmdmove, bboxmins, bboxmaxs; vec3_t absmins, absmaxs, velocity; @@ -327,7 +336,6 @@ int AAS_BestReachableFromJumpPadArea(vec3_t origin, vec3_t mins, vec3_t maxs) // VectorSet(cmdmove, 0, 0, 0); Com_Memset(&move, 0, sizeof(aas_clientmove_t)); - area2num = 0; AAS_ClientMovementHitBBox(&move, -1, areastart, PRESENCE_NORMAL, qfalse, velocity, cmdmove, 0, 30, 0.1f, bboxmins, bboxmaxs, bot_visualizejumppads); if (move.frames < 30) @@ -837,7 +845,6 @@ int AAS_Reachability_Swim(int area1num, int area2num) { int i, j, face1num, face2num, side1; aas_area_t *area1, *area2; - aas_areasettings_t *areasettings; aas_lreachability_t *lreach; aas_face_t *face1; aas_plane_t *plane; @@ -875,7 +882,6 @@ int AAS_Reachability_Swim(int area1num, int area2num) { // face1 = &aasworld.faces[face1num]; - areasettings = &aasworld.areasettings[area1num]; //create a new reachability link lreach = AAS_AllocReachability(); if (!lreach) return qfalse; @@ -1062,18 +1068,18 @@ int AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge(int area1num, int area2 int ground_bestarea2groundedgenum, ground_foundreach; int water_bestarea2groundedgenum, water_foundreach; int side1, area1swim, faceside1, groundface1num; - float dist, dist1, dist2, diff, invgravitydot, ortdot; + float dist, dist1, dist2, diff, ortdot; float x1, x2, x3, x4, y1, y2, y3, y4, tmp, y; float length, ground_bestlength, water_bestlength, ground_bestdist, water_bestdist; vec3_t v1, v2, v3, v4, tmpv, p1area1, p1area2, p2area1, p2area2; vec3_t normal, ort, edgevec, start, end, dir; - vec3_t ground_beststart, ground_bestend, ground_bestnormal; - vec3_t water_beststart, water_bestend, water_bestnormal; + vec3_t ground_beststart = { 0, 0, 0 }, ground_bestend = { 0, 0, 0 }, ground_bestnormal = { 0, 0, 0 }; + vec3_t water_beststart = { 0, 0, 0 }, water_bestend = { 0, 0, 0 }, water_bestnormal = { 0, 0, 0 }; vec3_t invgravity = {0, 0, 1}; vec3_t testpoint; aas_plane_t *plane; aas_area_t *area1, *area2; - aas_face_t *groundface1, *groundface2, *ground_bestface1, *water_bestface1; + aas_face_t *groundface1, *groundface2; aas_edge_t *edge1, *edge2; aas_lreachability_t *lreach; aas_trace_t trace; @@ -1172,7 +1178,6 @@ int AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge(int area1num, int area2 //edges if they overlap in the direction orthogonal to //the gravity direction CrossProduct(invgravity, normal, ort); - invgravitydot = DotProduct(invgravity, invgravity); ortdot = DotProduct(ort, ort); //projection into the step plane //NOTE: since gravity is vertical this is just the z coordinate @@ -1302,7 +1307,6 @@ int AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge(int area1num, int area2 ground_bestlength = length; ground_foundreach = qtrue; ground_bestarea2groundedgenum = edge1num; - ground_bestface1 = groundface1; //best point towards area1 VectorCopy(start, ground_beststart); //normal is pointing into area2 @@ -1323,7 +1327,6 @@ int AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge(int area1num, int area2 water_bestlength = length; water_foundreach = qtrue; water_bestarea2groundedgenum = edge1num; - water_bestface1 = groundface1; //best point towards area1 VectorCopy(start, water_beststart); //normal is pointing into area2 @@ -2379,15 +2382,15 @@ int AAS_Reachability_Jump(int area1num, int area2num) //=========================================================================== int AAS_Reachability_Ladder(int area1num, int area2num) { - int i, j, k, l, edge1num, edge2num, sharededgenum, lowestedgenum; - int face1num, face2num, ladderface1num, ladderface2num; + int i, j, k, l, edge1num, edge2num, sharededgenum = 0, lowestedgenum = 0; + int face1num, face2num, ladderface1num = 0, ladderface2num = 0; int ladderface1vertical, ladderface2vertical, firstv; - float face1area, face2area, bestface1area, bestface2area; + float face1area, face2area, bestface1area = -9999, bestface2area = -9999; float phys_jumpvel, maxjumpheight; vec3_t area1point, area2point, v1, v2, up = {0, 0, 1}; - vec3_t mid, lowestpoint, start, end, sharededgevec, dir; + vec3_t mid, lowestpoint = { 0, 0 }, start, end, sharededgevec, dir; aas_area_t *area1, *area2; - aas_face_t *face1, *face2, *ladderface1, *ladderface2; + aas_face_t *face1, *face2, *ladderface1 = NULL, *ladderface2 = NULL; aas_plane_t *plane1, *plane2; aas_edge_t *sharededge, *edge1; aas_lreachability_t *lreach; @@ -2401,16 +2404,7 @@ int AAS_Reachability_Ladder(int area1num, int area2num) area1 = &aasworld.areas[area1num]; area2 = &aasworld.areas[area2num]; - // - ladderface1 = NULL; - ladderface2 = NULL; - ladderface1num = 0; //make compiler happy - ladderface2num = 0; //make compiler happy - bestface1area = -9999; - bestface2area = -9999; - sharededgenum = 0; //make compiler happy - lowestedgenum = 0; //make compiler happy - // + for (i = 0; i < area1->numfaces; i++) { face1num = aasworld.faceindex[area1->firstface + i]; @@ -3501,7 +3495,7 @@ void AAS_Reachability_JumpPad(void) int face2num, i, ret, area2num, visualize, ent, bot_visualizejumppads; //int modelnum, ent2; //float dist, time, height, gravity, forward; - float speed, zvel, hordist; + float speed, zvel; aas_face_t *face2; aas_area_t *area2; aas_lreachability_t *lreach; @@ -3723,8 +3717,6 @@ void AAS_Reachability_JumpPad(void) //direction towards the face center VectorSubtract(facecenter, areastart, dir); dir[2] = 0; - hordist = VectorNormalize(dir); - //if (hordist < 1.6 * facecenter[2] - areastart[2]) { //get command movement VectorScale(dir, speed, cmdmove); @@ -4006,7 +3998,7 @@ void AAS_SetWeaponJumpAreaFlags(void) int AAS_Reachability_WeaponJump(int area1num, int area2num) { int face2num, i, n, ret, visualize; - float speed, zvel, hordist; + float speed, zvel; aas_face_t *face2; aas_area_t *area1, *area2; aas_lreachability_t *lreach; @@ -4066,8 +4058,6 @@ int AAS_Reachability_WeaponJump(int area1num, int area2num) //direction towards the face center VectorSubtract(facecenter, areastart, dir); dir[2] = 0; - hordist = VectorNormalize(dir); - //if (hordist < 1.6 * (facecenter[2] - areastart[2])) { //get command movement VectorScale(dir, speed, cmdmove); diff --git a/tools/mbspc/botlib/be_aas_sample.c b/tools/mbspc/botlib/be_aas_sample.c index 68806eb0..8423235c 100644 --- a/tools/mbspc/botlib/be_aas_sample.c +++ b/tools/mbspc/botlib/be_aas_sample.c @@ -29,22 +29,22 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -#include "../game/q_shared.h" +#include "../qcommon/q_shared.h" #include "l_memory.h" #include "l_script.h" #include "l_precomp.h" #include "l_struct.h" -#ifndef BSPC -#include "l_libvar.h" -#endif #include "aasfile.h" -#include "../game/botlib.h" -#include "../game/be_aas.h" +#include "botlib.h" +#include "be_aas.h" #include "be_interface.h" #include "be_aas_funcs.h" #include "be_aas_def.h" +#include "be_aas_bsp.h" +#include "be_aas_sample.h" +#include "be_aas_reach.h" -extern botlib_import_t botimport; +extern aas_t aasworld; //#define AAS_SAMPLE_DEBUG @@ -1388,7 +1388,8 @@ int AAS_AreaInfo( int areanum, aas_areainfo_t *info ) //=========================================================================== aas_plane_t *AAS_PlaneFromNum(int planenum) { - if (!aasworld.loaded) return 0; + if (!aasworld.loaded) + return NULL; return &aasworld.planes[planenum]; } //end of the function AAS_PlaneFromNum diff --git a/tools/mbspc/botlib/l_libvar.c b/tools/mbspc/botlib/l_libvar.c index a8629c81..be7ad3ab 100644 --- a/tools/mbspc/botlib/l_libvar.c +++ b/tools/mbspc/botlib/l_libvar.c @@ -29,12 +29,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -#include "../game/q_shared.h" +#include "../qcommon/q_shared.h" #include "l_memory.h" #include "l_libvar.h" //list with library variables -libvar_t *libvarlist; +libvar_t *libvarlist = NULL; //=========================================================================== // @@ -84,9 +84,9 @@ libvar_t *LibVarAlloc(char *var_name) { libvar_t *v; - v = (libvar_t *) GetMemory(sizeof(libvar_t) + strlen(var_name) + 1); + v = ( libvar_t* ) GetMemory( sizeof( libvar_t ) ); Com_Memset(v, 0, sizeof(libvar_t)); - v->name = (char *) v + sizeof(libvar_t); + v->name = ( char* ) GetMemory( strlen( var_name ) + 1 ); strcpy(v->name, var_name); //add the variable in the list v->next = libvarlist; @@ -101,7 +101,9 @@ libvar_t *LibVarAlloc(char *var_name) //=========================================================================== void LibVarDeAlloc(libvar_t *v) { - if (v->string) FreeMemory(v->string); + if (v->string) + FreeMemory(v->string); + FreeMemory( v->name ); FreeMemory(v); } //end of the function LibVarDeAlloc //=========================================================================== diff --git a/tools/mbspc/botlib/l_log.c b/tools/mbspc/botlib/l_log.c index 7b1a346a..bd622443 100644 --- a/tools/mbspc/botlib/l_log.c +++ b/tools/mbspc/botlib/l_log.c @@ -33,8 +33,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include -#include "../game/q_shared.h" -#include "../game/botlib.h" +#include "../qcommon/q_shared.h" +#include "botlib.h" #include "be_interface.h" //for botimport.Print #include "l_libvar.h" diff --git a/tools/mbspc/botlib/l_precomp.c b/tools/mbspc/botlib/l_precomp.c index ae82981b..d179b577 100644 --- a/tools/mbspc/botlib/l_precomp.c +++ b/tools/mbspc/botlib/l_precomp.c @@ -32,61 +32,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA //Notes: fix: PC_StringizeTokens -//#define SCREWUP -//#define BOTLIB -//#define QUAKE -//#define QUAKEC -//#define MEQCC - -#ifdef SCREWUP -#include -#include -#include -#include -#include -#include -#include "l_memory.h" -#include "l_script.h" -#include "l_precomp.h" - -typedef enum {qfalse, qtrue} qboolean; -#endif //SCREWUP - -#ifdef BOTLIB -#include "../game/q_shared.h" -#include "../game/botlib.h" -#include "be_interface.h" -#include "l_memory.h" -#include "l_script.h" -#include "l_precomp.h" +#include "../mbspc/qbsp.h" #include "l_log.h" -#endif //BOTLIB - -#ifdef MEQCC -#include "qcc.h" -#include "time.h" //time & ctime -#include "math.h" //fabs -#include "l_memory.h" -#include "l_script.h" -#include "l_precomp.h" -#include "l_log.h" - -#define qtrue true -#define qfalse false -#endif //MEQCC - -#ifdef BSPC -//include files for usage in the BSP Converter -#include "../bspc/qbsp.h" -#include "../bspc/l_log.h" -#include "../bspc/l_mem.h" +#include "../mbspc/l_mem.h" #include "l_precomp.h" #define qtrue true #define qfalse false #define Q_stricmp stricmp -#endif //BSPC #if defined(QUAKE) && !defined(BSPC) #include "l_utils.h" @@ -131,7 +85,7 @@ void QDECL SourceError(source_t *source, char *str, ...) va_list ap; va_start(ap, str); - vsprintf(text, str, ap); + Q_vsnprintf(text, sizeof(text), str, ap); va_end(ap); #ifdef BOTLIB botimport.Print(PRT_ERROR, "file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text); @@ -155,7 +109,7 @@ void QDECL SourceWarning(source_t *source, char *str, ...) va_list ap; va_start(ap, str); - vsprintf(text, str, ap); + Q_vsnprintf(text, sizeof(text), str, ap); va_end(ap); #ifdef BOTLIB botimport.Print(PRT_WARNING, "file %s, line %d: %s\n", source->scriptstack->filename, source->scriptstack->line, text); @@ -469,9 +423,9 @@ int PC_StringizeTokens(token_t *tokens, token_t *token) strcat(token->string, "\""); for (t = tokens; t; t = t->next) { - strncat(token->string, t->string, MAX_TOKEN - strlen(token->string)); + strncat(token->string, t->string, MAX_TOKEN - strlen(token->string) - 1); } //end for - strncat(token->string, "\"", MAX_TOKEN - strlen(token->string)); + strncat(token->string, "\"", MAX_TOKEN - strlen(token->string) - 1); return qtrue; } //end of the function PC_StringizeTokens //============================================================================ @@ -653,6 +607,7 @@ void PC_FreeDefine(define_t *define) PC_FreeToken(t); } //end for //free the define + FreeMemory(define->name); FreeMemory(define); } //end of the function PC_FreeDefine //============================================================================ @@ -680,9 +635,9 @@ void PC_AddBuiltinDefines(source_t *source) for (i = 0; builtin[i].string; i++) { - define = (define_t *) GetMemory(sizeof(define_t) + strlen(builtin[i].string) + 1); + define = ( define_t* ) GetMemory( sizeof( define_t ) ); Com_Memset(define, 0, sizeof(define_t)); - define->name = (char *) define + sizeof(define_t); + define->name = ( char* ) GetMemory( strlen( builtin[i].string ) + 1 ); strcpy(define->name, builtin[i].string); define->flags |= DEFINE_FIXED; define->builtin = builtin[i].builtin; @@ -705,7 +660,8 @@ int PC_ExpandBuiltinDefine(source_t *source, token_t *deftoken, define_t *define token_t **firsttoken, token_t **lasttoken) { token_t *token; - unsigned long t; // time_t t; //to prevent LCC warning + time_t t; + char *curtime; token = PC_CopyToken(deftoken); @@ -1009,8 +965,9 @@ int PC_Directive_include(source_t *source) PC_UnreadSourceToken(source, &token); break; } //end if - if (token.type == TT_PUNCTUATION && *token.string == '>') break; - strncat(path, token.string, MAX_PATH); + if( token.type == TT_PUNCTUATION && *token.string == '>' ) + break; + strncat( path, token.string, MAX_PATH - 1 ); } //end while if (*token.string != '>') { @@ -1215,9 +1172,9 @@ int PC_Directive_define(source_t *source) #endif //DEFINEHASHING } //end if //allocate define - define = (define_t *) GetMemory(sizeof(define_t) + strlen(token.string) + 1); + define = ( define_t* ) GetMemory( sizeof( define_t ) ); Com_Memset(define, 0, sizeof(define_t)); - define->name = (char *) define + sizeof(define_t); + define->name = ( char* ) GetMemory( strlen( token.string ) + 1 ); strcpy(define->name, token.string); //add the define to the source #if DEFINEHASHING @@ -1451,9 +1408,9 @@ define_t *PC_CopyDefine(source_t *source, define_t *define) define_t *newdefine; token_t *token, *newtoken, *lasttoken; - newdefine = (define_t *) GetMemory(sizeof(define_t) + strlen(define->name) + 1); + newdefine = ( define_t* ) GetMemory( sizeof( define_t ) ); //copy the define name - newdefine->name = (char *) newdefine + sizeof(define_t); + newdefine->name = ( char* ) GetMemory( strlen( define->name ) + 1 ); strcpy(newdefine->name, define->name); newdefine->flags = define->flags; newdefine->builtin = define->builtin; @@ -1615,7 +1572,7 @@ typedef struct operator_s typedef struct value_s { signed long int intvalue; - double floatvalue; + float floatvalue; int parentheses; struct value_s *prev, *next; } value_t; @@ -1683,7 +1640,7 @@ int PC_OperatorPriority(int op) #define FreeOperator(op) int PC_EvaluateTokens(source_t *source, token_t *tokens, signed long int *intvalue, - double *floatvalue, int integer) + float *floatvalue, int integer) { operator_t *o, *firstoperator, *lastoperator; value_t *v, *firstvalue, *lastvalue, *v1, *v2; @@ -1694,9 +1651,8 @@ int PC_EvaluateTokens(source_t *source, token_t *tokens, signed long int *intval int lastwasvalue = 0; int negativevalue = 0; int questmarkintvalue = 0; - double questmarkfloatvalue = 0; + float questmarkfloatvalue = 0; int gotquestmarkvalue = qfalse; - int lastoperatortype = 0; // operator_t operator_heap[MAX_OPERATORS]; int numoperators = 0; @@ -2084,8 +2040,8 @@ int PC_EvaluateTokens(source_t *source, token_t *tokens, signed long int *intval if (integer) Log_Write("result value = %d", v1->intvalue); else Log_Write("result value = %f", v1->floatvalue); #endif //DEBUG_EVAL - if (error) break; - lastoperatortype = o->operator; + if( error ) + break; //if not an operator with arity 1 if (o->operator != P_LOGIC_NOT && o->operator != P_BIN_NOT) @@ -2137,7 +2093,7 @@ int PC_EvaluateTokens(source_t *source, token_t *tokens, signed long int *intval // Changes Globals: - //============================================================================ int PC_Evaluate(source_t *source, signed long int *intvalue, - double *floatvalue, int integer) + float *floatvalue, int integer) { token_t token, *firsttoken, *lasttoken; token_t *t, *nexttoken; @@ -2236,7 +2192,7 @@ int PC_Evaluate(source_t *source, signed long int *intvalue, // Changes Globals: - //============================================================================ int PC_DollarEvaluate(source_t *source, signed long int *intvalue, - double *floatvalue, int integer) + float *floatvalue, int integer) { int indent, defined = qfalse; token_t token, *firsttoken, *lasttoken; @@ -2466,7 +2422,7 @@ int PC_Directive_eval(source_t *source) //============================================================================ int PC_Directive_evalfloat(source_t *source) { - double value; + float value; token_t token; if (!PC_Evaluate(source, NULL, &value, qfalse)) return qfalse; @@ -2575,7 +2531,7 @@ int PC_DollarDirective_evalint(source_t *source) //============================================================================ int PC_DollarDirective_evalfloat(source_t *source) { - double value; + float value; token_t token; if (!PC_DollarEvaluate(source, NULL, &value, qfalse)) return qfalse; diff --git a/tools/mbspc/botlib/l_script.c b/tools/mbspc/botlib/l_script.c index e782e7fb..cef1b0a0 100644 --- a/tools/mbspc/botlib/l_script.c +++ b/tools/mbspc/botlib/l_script.c @@ -29,56 +29,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//#define SCREWUP -//#define BOTLIB -//#define MEQCC -//#define BSPC +#include "../mbspc/qbsp.h" -#ifdef SCREWUP -#include -#include -#include -#include -#include -#include "l_memory.h" -#include "l_script.h" - -typedef enum {qfalse, qtrue} qboolean; - -#endif //SCREWUP - -#ifdef BOTLIB -//include files for usage in the bot library -#include "../game/q_shared.h" -#include "../game/botlib.h" -#include "be_interface.h" -#include "l_script.h" -#include "l_memory.h" -#include "l_log.h" -#include "l_libvar.h" -#endif //BOTLIB - -#ifdef MEQCC -//include files for usage in MrElusive's QuakeC Compiler -#include "qcc.h" -#include "l_script.h" -#include "l_memory.h" #include "l_log.h" +#include "../mbspc/l_mem.h" #define qtrue true #define qfalse false -#endif //MEQCC - -#ifdef BSPC -//include files for usage in the BSP Converter -#include "../bspc/qbsp.h" -#include "../bspc/l_log.h" -#include "../bspc/l_mem.h" - -#define qtrue true -#define qfalse false -#endif //BSPC - #define PUNCTABLE @@ -160,11 +117,7 @@ punctuation_t default_punctuations[] = {NULL, 0} }; -#ifdef BSPC char basefolder[MAX_PATH]; -#else -char basefolder[MAX_QPATH]; -#endif //=========================================================================== // @@ -236,17 +189,10 @@ void QDECL ScriptError(script_t *script, char *str, ...) if (script->flags & SCFL_NOERRORS) return; va_start(ap, str); - vsprintf(text, str, ap); + Q_vsnprintf(text, sizeof(text), str, ap); va_end(ap); -#ifdef BOTLIB - botimport.Print(PRT_ERROR, "file %s, line %d: %s\n", script->filename, script->line, text); -#endif //BOTLIB -#ifdef MEQCC - printf("error: file %s, line %d: %s\n", script->filename, script->line, text); -#endif //MEQCC -#ifdef BSPC + Log_Print("error: file %s, line %d: %s\n", script->filename, script->line, text); -#endif //BSPC } //end of the function ScriptError //=========================================================================== // @@ -262,17 +208,9 @@ void QDECL ScriptWarning(script_t *script, char *str, ...) if (script->flags & SCFL_NOWARNINGS) return; va_start(ap, str); - vsprintf(text, str, ap); + Q_vsnprintf(text, sizeof(text), str, ap); va_end(ap); -#ifdef BOTLIB - botimport.Print(PRT_WARNING, "file %s, line %d: %s\n", script->filename, script->line, text); -#endif //BOTLIB -#ifdef MEQCC - printf("warning: file %s, line %d: %s\n", script->filename, script->line, text); -#endif //MEQCC -#ifdef BSPC Log_Print("warning: file %s, line %d: %s\n", script->filename, script->line, text); -#endif //BSPC } //end of the function ScriptWarning //=========================================================================== // @@ -554,7 +492,7 @@ int PS_ReadName(script_t *script, token_t *token) // Changes Globals: - //============================================================================ void NumberValue(char *string, int subtype, unsigned long int *intvalue, - long double *floatvalue) + float *floatvalue) { unsigned long int dotfound = 0; @@ -573,13 +511,13 @@ void NumberValue(char *string, int subtype, unsigned long int *intvalue, } //end if if (dotfound) { - *floatvalue = *floatvalue + (long double) (*string - '0') / - (long double) dotfound; + *floatvalue = *floatvalue + (float) (*string - '0') / + (float) dotfound; dotfound *= 10; } //end if else { - *floatvalue = *floatvalue * 10.0 + (long double) (*string - '0'); + *floatvalue = *floatvalue * 10.0 + (float) (*string - '0'); } //end else string++; } //end while @@ -631,7 +569,7 @@ int PS_ReadNumber(script_t *script, token_t *token) int octal, dot; char c; // unsigned long int intvalue = 0; -// long double floatvalue = 0; +// double floatvalue = 0; token->type = TT_NUMBER; //check for a hexadecimal number @@ -1148,10 +1086,10 @@ void StripSingleQuotes(char *string) // Returns: - // Changes Globals: - //============================================================================ -long double ReadSignedFloat(script_t *script) +float ReadSignedFloat(script_t *script) { token_t token; - long double sign = 1; + float sign = 1; PS_ExpectAnyToken(script, &token); if (!strcmp(token.string, "-")) @@ -1319,9 +1257,9 @@ script_t *LoadScriptFile(const char *filename) #ifdef BOTLIB if (strlen(basefolder)) - Com_sprintf(pathname, sizeof(pathname), "%s/%s", basefolder, filename); + sprintf( pathname, "%s/%s", basefolder, filename ); else - Com_sprintf(pathname, sizeof(pathname), "%s", filename); + sprintf( pathname, "%s", filename ); length = botimport.FS_FOpenFile( pathname, &fp, FS_READ ); if (!fp) return NULL; #else @@ -1363,8 +1301,6 @@ script_t *LoadScriptFile(const char *filename) } //end if fclose(fp); #endif - // - script->length = COM_Compress(script->buffer); return script; } //end of the function LoadScriptFile @@ -1425,9 +1361,5 @@ void FreeScript(script_t *script) //============================================================================ void PS_SetBaseFolder(char *path) { -#ifdef BSPC sprintf(basefolder, path); -#else - Com_sprintf(basefolder, sizeof(basefolder), path); -#endif } //end of the function PS_SetBaseFolder diff --git a/tools/mbspc/botlib/l_script.h b/tools/mbspc/botlib/l_script.h index 88696bf7..a79ab5d0 100644 --- a/tools/mbspc/botlib/l_script.h +++ b/tools/mbspc/botlib/l_script.h @@ -161,7 +161,7 @@ typedef struct token_s int subtype; //last read token sub type #ifdef NUMBERVALUE unsigned long int intvalue; //integer value - long double floatvalue; //floating point value + float floatvalue; //floating point value #endif //NUMBERVALUE char *whitespace_p; //start of white space before token char *endwhitespace_p; //start of white space before token @@ -218,7 +218,7 @@ void StripSingleQuotes(char *string); //read a possible signed integer signed long int ReadSignedInt(script_t *script); //read a possible signed floating point number -long double ReadSignedFloat(script_t *script); +float ReadSignedFloat(script_t *script); //set an array with punctuations, NULL restores default C/C++ set void SetScriptPunctuations(script_t *script, punctuation_t *p); //set script flags diff --git a/tools/mbspc/botlib/l_struct.c b/tools/mbspc/botlib/l_struct.c index c628821d..2d6f4c92 100644 --- a/tools/mbspc/botlib/l_struct.c +++ b/tools/mbspc/botlib/l_struct.c @@ -29,27 +29,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -#ifdef BOTLIB -#include "../game/q_shared.h" -#include "../game/botlib.h" //for the include of be_interface.h -#include "l_script.h" -#include "l_precomp.h" -#include "l_struct.h" -#include "l_utils.h" -#include "be_interface.h" -#endif //BOTLIB - -#ifdef BSPC -//include files for usage in the BSP Converter -#include "../bspc/qbsp.h" -#include "../bspc/l_log.h" -#include "../bspc/l_mem.h" +#include "../mbspc/qbsp.h" +#include "l_log.h" +#include "../mbspc/l_mem.h" #include "l_precomp.h" #include "l_struct.h" #define qtrue true #define qfalse false -#endif //BSPC //=========================================================================== // diff --git a/tools/mbspc/mbspc.html b/tools/mbspc/mbspc.html new file mode 100644 index 00000000..b7227996 --- /dev/null +++ b/tools/mbspc/mbspc.html @@ -0,0 +1,255 @@ + + + + + + + + + + + + +
+

MBSPC -- BSP converter and editing utility

+

Copyright (C) 2004-2012 Laszlo Menczel (laszlo.menczel@gmail.com)

+
+ +

+This program is distributed under the terms of the GNU General Public +License version 2 as published by the Free Software Foundation. A copy of +it is in the file GPL.TXT. This program comes with ABSOLUTELY NO WARRANTY. + +

Introduction

+ +

+This program is based on version 2.1 of the BSPC utility (part of the +toolkit created for the Quake series of games). Originally it used to be +a MAP to BSP converter. For Quake 3 it is mainly used for the creation of AAS +file from BSP files. An AAS file is a file containing area information +used by the Quake III Arena bots to navigate and understand a map. + +

+MBSPC is a modified (enhanced) version of this utility. I have (re)added +some functions that were either not present originally or were removed +from this version for some reason. So you can also do the following tricks +with MBSPC: + +

    +
  • + convert BSP files to editable MAP format +
  • +
  • + update the entity list in a BSP file +
  • +
  • + extract the entity list from a BSP file to a text file (new) +
  • +
  • + create a list of the textures used in a BSP file (new, only for Q3A at present) +
  • +
+ +

+When MBSPC is used for converting BSP files to MAP files, the correct +texture name is written for every brush side. However, texture alignment +info (shift, scale, rotation) is not written to the MAP file. It is not +trivial to obtain this info from the BSP, and I did not need it when I +coded this modification, sorry. If you need this functionality, add the +necessary code. + +

+

Usage

+ +
+
+  bspc -option [ -option ... ] input-file
+
+
+ +

+At least one option must be given to specify the desired action. The +rest of the option(s) within the brackets are optional. Examples: + +

+
+  mbspc -bsp2aas d:\quake3\baseq3\maps\mymap?.bsp
+  mbspc -bsp2aas d:\quake3\baseq3\pak0.pk3\maps/q3dm*.bsp
+  mbspc -bsp2map -output d:\tmp d:\quake3\baseq3\maps\q3dm1.bsp
+
+
+ +

Options

+ +The first section in the table contains obligatory options, i.e. one of +them must be specified so that MBSPC knows what to do. The second section +contains optional parameters that modify the way the action is done. The +third section contains options that are useful only if you want to use +MBSPC for compiling a BSP from a MAP. These are kind of obsolete because for +Quake 1/2/3 there are now better compilers (e.g. q3map2), so MBSPC should +not be used for this purpose. + +

+List of options recognized by MBSPC: + +

+
+   option           argument        explanation                          output
+   ---------------------------------------------------------------------------------------
+   entlist          file.bsp        extract entity list                  file.ent
+   onlyents         file.bsp        update entity list from file.ent(*)  file.bsp
+   texinfo          file.bsp        extract texture list                 file.txi
+   bsp2map          file.bsp        create MAP from BSP                  file.map
+   bsp2aas          file.bsp        create AAS from BSP                  file.aas
+   reach            file.bsp        compute reachability and clusters    file.aas
+   cluster          file.aas        compute clusters                     file.aas
+   aasopt           file.aas        optimize aas file                    file.aas
+   ---------------------------------------------------------------------------------------
+   output           output-path     set output path
+   threads          N               set number of threads to N
+   cfg              file            use configuration data in 'file'
+   noverbose                        disable verbose output
+   ---------------------------------------------------------------------------------------
+   optimize                         enable optimization
+   breadthfirst                     breadth first bsp building
+   nobrushmerge                     don't merge brushes
+   freetree                         free the bsp tree
+   nocsg                            disables brush chopping
+   noliquids                        don't write liquids to map
+   forcesidesvisible                force all sides to be visible
+
+
+ +

+(*) The '.ent' file must exist! You can make one using the '-entlist' +option. The '.ent' file can be edited by using a text editor (e.g. you +may change entity types and coordinates) as long as the format of entity +specifications remains valid. + +

+Several metacharacter may be used in the paths of the input file: + +

+
+  *          match any string of zero or more characters
+  ?          match any single character
+  [abc...]   match any of the enclosed characters; a hyphen can
+             be used to specify a range (e.g. a-z, A-Z, 0-9)
+
+
+ +

+.pk3 files are accessed as if they are normal folders. For instance +use "d:\quake3\baseq3\pak0.pk3\maps/q3dm1.bsp" to access the +map q3dm1.bsp from the pak0.pk3 file. + +

+Multiple files may be listed after the switches bsp2map, bsp2aas, reach, +cluster and aasopt. + +

+If a BSP file is being converted to an AAS file and no output path +is entered on the command-line then the AAS file will automatically +be stored in the same folder as the BSP file. However if the BSP file +was stored in a .pk3 file then the AAS file will be stored in a folder +with the name 'maps' outside the .pk3 file. + +

How updating the entity lump affects the AAS file?

+ +

+If an AAS file is already available for a BSP file and you ONLY change +the entities inside this BSP file (using the map editor or MBSPC with the +'-onlyents' option) then you only have to recalculate the reachabilities. +This way you can move items, platforms etc. around without the need to +recalculate the whole AAS file which can save quite some compile time. +You can recalculate the reachabilities as follows: + +

+
+  bspc -reach file.bsp
+
+
+ +

+where 'file.bsp' is the updated BSP file. 'file.aas' must exist and must +be in the same folder as 'file.bsp' or in the output folder specified with +the '-output' option. + +

+Note: the option '-reach' does not work on optimized '.AAS' files. + +

+Keep in mind that as soon as ANY geometry in the map changes the whole +AAS file HAS to be recalculated in order to play with bots. + +

Testing AAS files

+ +

+One of the easiest ways to test the AAS file is to load the map in +Quake3 in teamplay mode (type /set g_gametype 3 on the console before +loading the map). Enter a team and add a bot to your team. Use the +team order menu (by default bound to the key F3) to command the bot +to follow you. Walk around the map and see if the bot is able to +follow you everywhere. + +

+Map bugs can sometimes cause certain places in the map to show up +'solid' in the AAS file. The bots cannot travel through these 'solid' +areas. To test for these 'solid' places set the cvar bot_testsolid +to 1 on the console. (type /set bot_testsolid 1) The map has to be +started with devmap instead of map before the cvar bot_testsolid can +be set. When the cvar is set to 1 then either "empty area" or +"SOLID area" will be printed on the screen while traveling through a map. + +

+Several map bugs can cause these 'solid' places in the AAS file. + +

+
+- Sometimes microscopic brushes are left over after a brush CSG. Search
+  for such brushes in the problem area and delete them.
+
+- Tiny brush faces (not curves) can also cause problems. Due to vertex
+  snapping in the q3map tool those tiny brush faces can be snapped out
+  of existence. Such faces will not show up in Quake3 and you'll see
+  tiny peek holes or slits where you can view through the geometry.
+  Allign vertexes of and edges of adjacent brushes to remove and avoid
+  such tiny faces. Placing a clip brush in front of the face that is
+  snapped out of existence will also remove the 'solid' area but ofcourse
+  it's much better to remove the peek holes and slits.
+
+- Another cause could be a brush with a collapsed side. Check how many
+  sides a brush has and how many sides actually have a surface. Rebuild
+  brushes with collapsed sides.
+
+- All faces contained within liquid brushes using a shader without
+  "surfaceparm trans" set will be removed. Those contained surfaces will
+  not be visible and can cause the lava to appear "solid" in the aas file.
+
+
+ +

+Clusters can be tested with the cvar bot_testclusters. +(type "/set bot_testclusters 1" on the console) + +

+Jumppads can also be tested. Type the following on the Quake3 console +before loading your map: + +

+
+/set bot_maxdebugpolys 1024
+/set bot_visualizejumppads 1
+/set bot_forcereachability 1
+
+
+ +

+Now load the map. A counter will be shown and goes from 0% to 100%. +When the counter has reached 100% type /set r_debugSurface 2 on the +console. For every jumppad the default arch of travel (without using +air control) will be visualized. + + + + diff --git a/tools/mbspc/mbspc/aas_create.c b/tools/mbspc/mbspc/aas_create.c index 17053623..4cf40b50 100644 --- a/tools/mbspc/mbspc/aas_create.c +++ b/tools/mbspc/mbspc/aas_create.c @@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "aas_edgemelting.h" #include "aas_prunenodes.h" #include "aas_cfg.h" -#include "../game/surfaceflags.h" +#include "../qcommon/surfaceflags.h" //#define AW_DEBUG //#define L_DEBUG @@ -342,7 +342,7 @@ void AAS_CheckArea(tmp_area_t *tmparea) Log_Write("AAS_CheckArea: area %d face %d: %s\r\n", tmparea->areanum, face->num, WindingErrorString()); } //end if -#endif L_DEBUG +#endif /* L_DEBUG */ plane = &mapplanes[face->planenum ^ side]; @@ -363,7 +363,7 @@ void AAS_CheckArea(tmp_area_t *tmparea) Log_Write("AAS_CheckArea: area %d face %d winding plane unequal to face plane\r\n", tmparea->areanum, face->num); } //end if -#endif L_DEBUG +#endif /* L_DEBUG */ } //end for } //end of the function AAS_CheckArea //=========================================================================== @@ -643,7 +643,6 @@ tmp_node_t *AAS_CreateArea(node_t *node) tmp_face_t *tmpface; tmp_area_t *tmparea; tmp_node_t *tmpnode; - vec3_t up = {0, 0, 1}; //create an area from this leaf tmparea = AAS_AllocTmpArea(); diff --git a/tools/mbspc/mbspc/aas_facemerging.c b/tools/mbspc/mbspc/aas_facemerging.c index 2fb29039..c921c2da 100644 --- a/tools/mbspc/mbspc/aas_facemerging.c +++ b/tools/mbspc/mbspc/aas_facemerging.c @@ -217,7 +217,7 @@ int AAS_CanMergePlaneFaces(tmp_area_t *tmparea, int planenum) { tmp_area_t *frontarea, *backarea; tmp_face_t *face1; - int side1, merge, faceflags; + int side1, merge, faceflags = 0; frontarea = backarea = NULL; merge = false; diff --git a/tools/mbspc/mbspc/aas_gsubdiv.c b/tools/mbspc/mbspc/aas_gsubdiv.c index 4cfb1941..862bc95a 100644 --- a/tools/mbspc/mbspc/aas_gsubdiv.c +++ b/tools/mbspc/mbspc/aas_gsubdiv.c @@ -528,7 +528,7 @@ tmp_node_t *AAS_LadderSubdivideArea_r(tmp_node_t *tmpnode) tmp_area_t *tmparea, *frontarea, *backarea; tmp_face_t *face1; tmp_node_t *tmpnode1, *tmpnode2; - vec3_t lowestpoint, normal = {0, 0, 1}; + vec3_t lowestpoint = {0, 0, 0}, normal = {0, 0, 1}; plane_t *plane; winding_t *w; diff --git a/tools/mbspc/mbspc/aas_map.c b/tools/mbspc/mbspc/aas_map.c index 10c616a2..7125a927 100644 --- a/tools/mbspc/mbspc/aas_map.c +++ b/tools/mbspc/mbspc/aas_map.c @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "../botlib/aasfile.h" //aas_bbox_t #include "aas_store.h" //AAS_MAX_BBOXES #include "aas_cfg.h" -#include "../game/surfaceflags.h" +#include "../qcommon/surfaceflags.h" #define SPAWNFLAG_NOT_EASY 0x00000100 #define SPAWNFLAG_NOT_MEDIUM 0x00000200 diff --git a/tools/mbspc/mbspc/aas_store.c b/tools/mbspc/mbspc/aas_store.c index d549ab72..3fd8c8ef 100644 --- a/tools/mbspc/mbspc/aas_store.c +++ b/tools/mbspc/mbspc/aas_store.c @@ -654,7 +654,6 @@ qboolean AAS_FindPlane(vec3_t normal, float dist, int *planenum) qboolean AAS_FindHashedPlane(vec3_t normal, float dist, int *planenum) { int i, p; - aas_plane_t *plane; int hash, h; hash = (int)fabs(dist) / 8; @@ -666,7 +665,6 @@ qboolean AAS_FindHashedPlane(vec3_t normal, float dist, int *planenum) h = (hash+i)&(PLANE_HASH_SIZE-1); for (p = aas_hashplanes[h]; p >= 0; p = aas_planechain[p]) { - plane = &aasworld.planes[p]; if (AAS_PlaneEqual(normal, dist, p)) { *planenum = p; @@ -908,7 +906,7 @@ int AAS_StoreArea(tmp_area_t *tmparea) aas_face_t *aasface; aas_faceindex_t aasfacenum; vec3_t facecenter; - winding_t *w; + winding_t *w = NULL; //when the area is merged go to the merged area //FIXME: this isn't necessary anymore because the tree diff --git a/tools/mbspc/mbspc/aas_store.h b/tools/mbspc/mbspc/aas_store.h index 063adbed..4a18ce5b 100644 --- a/tools/mbspc/mbspc/aas_store.h +++ b/tools/mbspc/mbspc/aas_store.h @@ -35,8 +35,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define AAS_MAX_PORTALINDEXSIZE 65536 #define AAS_MAX_CLUSTERS 65536 -#define BSPCINCLUDE -#include "../game/be_aas.h" +#include "../botlib/be_aas.h" #include "../botlib/be_aas_def.h" /* diff --git a/tools/mbspc/mbspc/be_aas_bspc.c b/tools/mbspc/mbspc/be_aas_bspc.c index 9473287b..83cba83e 100644 --- a/tools/mbspc/mbspc/be_aas_bspc.c +++ b/tools/mbspc/mbspc/be_aas_bspc.c @@ -20,23 +20,29 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =========================================================================== */ -#include "../game/q_shared.h" -#include "../bspc/l_log.h" -#include "../bspc/l_qfiles.h" +#include "../qcommon/q_shared.h" +#include "l_log.h" +#include "l_qfiles.h" #include "../botlib/l_memory.h" #include "../botlib/l_script.h" #include "../botlib/l_precomp.h" #include "../botlib/l_struct.h" #include "../botlib/aasfile.h" -#include "../game/botlib.h" -#include "../game/be_aas.h" +#include "../botlib/botlib.h" +#include "../botlib/be_aas.h" #include "../botlib/be_aas_def.h" +#include "../botlib/be_aas_bsp.h" +#include "../botlib/be_aas_move.h" +#include "../botlib/be_aas_sample.h" +#include "../botlib/be_aas_cluster.h" +#include "../botlib/be_aas_reach.h" #include "../qcommon/cm_public.h" //#define BSPC extern botlib_import_t botimport; extern qboolean capsule_collision; +extern aas_t aasworld; botlib_import_t botimport; clipHandle_t worldmodel; @@ -217,6 +223,8 @@ void Com_DPrintf(char *fmt, ...) int COM_Compress( char *data_p ) { return strlen(data_p); } +#if 0 // ML081030 removed ************* + //=========================================================================== // // Parameter: - @@ -235,6 +243,8 @@ void Com_Memset (void* dest, const int val, const size_t count) { void Com_Memcpy (void* dest, const void* src, const size_t count) { memcpy(dest, src, count); } +#endif // ******************************** + //=========================================================================== // // Parameter: - diff --git a/tools/mbspc/mbspc/brushbsp.c b/tools/mbspc/mbspc/brushbsp.c index d8accecd..e793887d 100644 --- a/tools/mbspc/mbspc/brushbsp.c +++ b/tools/mbspc/mbspc/brushbsp.c @@ -972,13 +972,11 @@ side_t *SelectSplitSide (bspbrush_t *brushes, node_t *node) int s; int front, back, both, facing, splits; int bsplits; - int bestsplits; int epsilonbrush; qboolean hintsplit = false; bestside = NULL; bestvalue = -99999; - bestsplits = 0; // the search order goes: visible-structural, visible-detail, // nonvisible-structural, nonvisible-detail. @@ -1066,7 +1064,6 @@ side_t *SelectSplitSide (bspbrush_t *brushes, node_t *node) { bestvalue = value; bestside = side; - bestsplits = splits; for (test = brushes; test ; test = test->next) test->side = test->testside; } //end if diff --git a/tools/mbspc/mbspc/bspc.c b/tools/mbspc/mbspc/bspc.c index e19076ea..898fdf43 100644 --- a/tools/mbspc/mbspc/bspc.c +++ b/tools/mbspc/mbspc/bspc.c @@ -375,12 +375,12 @@ void CreateAASFilesForAllBSPFiles(char *quakepath) WIN32_FIND_DATA filedata; HWND handle; struct _stat statbuf; + int done; #else glob_t globbuf; struct stat statbuf; int j; #endif - int done; char filter[_MAX_PATH], bspfilter[_MAX_PATH], aasfilter[_MAX_PATH]; char aasfile[_MAX_PATH], buf[_MAX_PATH], foldername[_MAX_PATH]; quakefile_t *qf, *qf2, *files, *bspfiles, *aasfiles; @@ -500,14 +500,19 @@ quakefile_t *GetArgumentFiles(int argc, char *argv[], int *i, char *ext) #define COMP_CLUSTER 4 #define COMP_AASOPTIMIZE 5 #define COMP_AASINFO 6 +// ML090131 added +#define COMP_TEXINFO 7 +#define COMP_ENTLIST 8 int main (int argc, char **argv) { int i, comp = 0; char outputpath[MAX_PATH] = ""; char filename[MAX_PATH] = "unknown"; - quakefile_t *qfiles, *qf; + quakefile_t *qfiles = NULL, *qf; double start_time; + char *ent_str; + int ent_str_size; myargc = argc; myargv = argv; @@ -635,11 +640,13 @@ int main (int argc, char **argv) freetree = true; Log_Print("freetree = true\n"); } //end else if +#if 0 else if (!stricmp(argv[i], "-grapplereach")) { calcgrapplereach = true; Log_Print("grapplereach = true\n"); } //end else if +#endif else if (!stricmp(argv[i], "-nobrushmerge")) { nobrushmerge = true; @@ -677,6 +684,28 @@ int main (int argc, char **argv) if (!LoadCfgFile(argv[++i])) exit(0); } //end else if + else if (!stricmp(argv[i], "-texinfo")) + { + if (i + 1 >= argc) + { + i = 0; + break; + } + comp = COMP_TEXINFO; + qfiles = GetArgumentFiles(argc, argv, &i, "bsp"); + } //end else if + + else if (!stricmp(argv[i], "-entlist")) + { + if (i + 1 >= argc) + { + i = 0; + break; + } + comp = COMP_ENTLIST; + qfiles = GetArgumentFiles(argc, argv, &i, "bsp"); + } //end else if + else if (!stricmp(argv[i], "-bsp2map")) { if (i + 1 >= argc) {i = 0; break;} @@ -731,6 +760,95 @@ int main (int argc, char **argv) { switch(comp) { + // ML090131 added: extract BSP texture info + case COMP_TEXINFO: + { + if (!qfiles) + Log_Print("no files found\n"); + + for (qf = qfiles; qf; qf = qf->next) + { + //copy the output path + strcpy(filename, outputpath); + + //append the bsp file base + AppendPathSeperator(filename, MAX_PATH); + ExtractFileBase(qf->origname, &filename[strlen(filename)]); + + //append .txi + strcat(filename, ".txi"); + Log_Print("texinfo: %s to %s\n", qf->origname, filename); + + if (qf->type != QFILETYPE_BSP) + Warning("%s is probably not a BSP file\n", qf->origname); + + if (! LoadMapFromBSP(qf)) + return 1; + + //write the texture info file + WriteTexinfo(filename); + } //end for + break; + } //end case + + case COMP_ENTLIST: + { + if (!qfiles) + Log_Print("no files found\n"); + + for (qf = qfiles; qf; qf = qf->next) + { + //copy the output path + strcpy(filename, outputpath); + + //append the bsp file base + AppendPathSeperator(filename, MAX_PATH); + ExtractFileBase(qf->origname, &filename[strlen(filename)]); + + //append .ent + strcat(filename, ".ent"); + Log_Print("entlist: %s to %s\n", qf->origname, filename); + + if (qf->type != QFILETYPE_BSP) + { + Warning("%s is probably not a BSP file\n", qf->origname); + return 1; + } + + if (! LoadMapFromBSP(qf)) + return 1; + + //write the entity list + switch (loadedmaptype) + { + case MAPTYPE_QUAKE1: + ent_str = Q1_UnparseEntities(&ent_str_size); + break; + + case MAPTYPE_QUAKE2: + ent_str = Q2_UnparseEntities(&ent_str_size); + break; + + case MAPTYPE_QUAKE3: + ent_str = Q3_UnparseEntities(&ent_str_size); + break; + + default: + Error("Entity listing is not implemented for this BSP type\n", qf->origname); + return 1; + } + + if (ent_str == NULL || ent_str_size == 0) + { + Error("Could not parse entity string\n"); + return 1; + } + + WriteEntList(filename, ent_str, ent_str_size); + } + break; + } + case COMP_BSP2MAP: { if (!qfiles) Log_Print("no files found\n"); @@ -745,8 +863,8 @@ int main (int argc, char **argv) strcat(filename, ".map"); // Log_Print("bsp2map: %s to %s\n", qf->origname, filename); - if (qf->type != QFILETYPE_BSP) Warning("%s is probably not a BSP file\n", qf->origname); - // + if (qf->type != QFILETYPE_BSP) + Warning("%s is probably not a BSP file\n", qf->origname); LoadMapFromBSP(qf); //write the map file WriteMapFile(filename); @@ -923,6 +1041,7 @@ int main (int argc, char **argv) } //end if AAS_ShowTotals(); } //end for + break; } //end case default: { @@ -943,7 +1062,7 @@ int main (int argc, char **argv) #endif "\n" "Switches:\n" - //" bsp2map <[pakfilter/]filter.bsp> = convert BSP to MAP\n" + " bsp2map <[pakfilter/]filter.bsp> = convert BSP to MAP\n" //" aasall = create AAS files for all BSPs\n" " bsp2aas <[pakfilter/]filter.bsp> = convert BSP to AAS\n" " reach = compute reachability & clusters\n" diff --git a/tools/mbspc/mbspc/l_bsp_hl.c b/tools/mbspc/mbspc/l_bsp_hl.c index 48cb7e8e..823f00af 100644 --- a/tools/mbspc/mbspc/l_bsp_hl.c +++ b/tools/mbspc/mbspc/l_bsp_hl.c @@ -244,10 +244,15 @@ FastChecksum int FastChecksum(void *buffer, int bytes) { - int checksum = 0; + int checksum = 0, i; + char *buf; - while( bytes-- ) - checksum = (checksum << 4) ^ *((char *)buffer)++; +// while( bytes-- ) +// checksum = (checksum << 4) ^ *((char *)buffer)++; + buf = (char *) buffer; + + for (i = 0; i < bytes; i++, buf++) + checksum = (checksum << 4) ^ *buf; return checksum; } @@ -637,7 +642,7 @@ void HL_WriteBSPFile (char *filename) #define ENTRIES(a) (sizeof(a)/sizeof(*(a))) #define ENTRYSIZE(a) (sizeof(*(a))) -ArrayUsage( char *szItem, int items, int maxitems, int itemsize ) +int ArrayUsage( char *szItem, int items, int maxitems, int itemsize ) { float percentage = maxitems ? items * 100.0 / maxitems : 0.0; @@ -654,7 +659,7 @@ ArrayUsage( char *szItem, int items, int maxitems, int itemsize ) return items * itemsize; } -GlobUsage( char *szItem, int itemstorage, int maxstorage ) +int GlobUsage( char *szItem, int itemstorage, int maxstorage ) { float percentage = maxstorage ? itemstorage * 100.0 / maxstorage : 0.0; @@ -680,7 +685,6 @@ Dumps info about current file */ void HL_PrintBSPFileSizes(void) { - int numtextures = hl_texdatasize ? ((hl_dmiptexlump_t*)hl_dtexdata)->nummiptex : 0; int totalmemory = 0; qprintf("\n"); diff --git a/tools/mbspc/mbspc/l_bsp_q1.c b/tools/mbspc/mbspc/l_bsp_q1.c index 7ac1553c..d5c4990a 100644 --- a/tools/mbspc/mbspc/l_bsp_q1.c +++ b/tools/mbspc/mbspc/l_bsp_q1.c @@ -584,7 +584,7 @@ Q1_UnparseEntities Generates the dentdata string from all the entities ================ */ -void Q1_UnparseEntities (void) +char *Q1_UnparseEntities(int *size) { char *buf, *end; epair_t *ep; @@ -614,7 +614,12 @@ void Q1_UnparseEntities (void) end += 2; if (end > buf + Q1_MAX_MAP_ENTSTRING) + { Error ("Entity text too long"); + return NULL; + } } q1_entdatasize = end - buf + 1; + *size = q1_entdatasize; + return buf; } //end of the function Q1_UnparseEntities diff --git a/tools/mbspc/mbspc/l_bsp_q1.h b/tools/mbspc/mbspc/l_bsp_q1.h index 7cf459ce..07b0b648 100644 --- a/tools/mbspc/mbspc/l_bsp_q1.h +++ b/tools/mbspc/mbspc/l_bsp_q1.h @@ -270,6 +270,6 @@ void Q1_LoadBSPFile(char *filename, int offset, int length); void Q1_WriteBSPFile(char *filename); void Q1_PrintBSPFileSizes(void); void Q1_ParseEntities(void); -void Q1_UnparseEntities(void); +char *Q1_UnparseEntities(int *size); #endif diff --git a/tools/mbspc/mbspc/l_bsp_q2.c b/tools/mbspc/mbspc/l_bsp_q2.c index 2d97579c..c465c183 100644 --- a/tools/mbspc/mbspc/l_bsp_q2.c +++ b/tools/mbspc/mbspc/l_bsp_q2.c @@ -898,7 +898,7 @@ void Q2_LoadBSPFile(char *filename, int offset, int length) Q2_SwapBSPFile (false); Q2_FixTextureReferences(); -} //end of the function Q2_LoadBSPFile +} /* @@ -1091,7 +1091,7 @@ UnparseEntities Generates the dentdata string from all the entities ================ */ -void Q2_UnparseEntities (void) +char *Q2_UnparseEntities(int *size) { char *buf, *end; epair_t *ep; @@ -1127,8 +1127,13 @@ void Q2_UnparseEntities (void) end += 2; if (end > buf + MAX_MAP_ENTSTRING) + { Error ("Entity text too long"); + return NULL; + } } entdatasize = end - buf + 1; + *size = entdatasize; + return buf; } //end of the function Q2_UnparseEntities diff --git a/tools/mbspc/mbspc/l_bsp_q2.h b/tools/mbspc/mbspc/l_bsp_q2.h index f0720df9..1d6ce30b 100644 --- a/tools/mbspc/mbspc/l_bsp_q2.h +++ b/tools/mbspc/mbspc/l_bsp_q2.h @@ -94,5 +94,4 @@ void Q2_LoadBSPFileTexinfo(char *filename); // just for qdata void Q2_WriteBSPFile(char *filename); void Q2_PrintBSPFileSizes(void); void Q2_ParseEntities(void); -void Q2_UnparseEntities(void); - +char *Q2_UnparseEntities(int *size); diff --git a/tools/mbspc/mbspc/l_bsp_q3.c b/tools/mbspc/mbspc/l_bsp_q3.c index 24bb7668..a5c65245 100644 --- a/tools/mbspc/mbspc/l_bsp_q3.c +++ b/tools/mbspc/mbspc/l_bsp_q3.c @@ -259,7 +259,9 @@ void Q3_CreatePlanarSurfacePlanes(void) // Returns: - // Changes Globals: - //=========================================================================== -/* + +#if 0 // ****************** + void Q3_SurfacePlane(q3_dsurface_t *surface, vec3_t normal, float *dist) { //take the plane information from the lightmap vector @@ -269,7 +271,9 @@ void Q3_SurfacePlane(q3_dsurface_t *surface, vec3_t normal, float *dist) Q3_PlaneFromPoints(q3_drawVerts[surface->firstVert].xyz, q3_drawVerts[surface->firstVert+1].xyz, q3_drawVerts[surface->firstVert+2].xyz, normal, dist); -} //end of the function Q3_SurfacePlane*/ +} //end of the function Q3_SurfacePlane + +#endif // ****************** //=========================================================================== // returns the amount the face and the winding overlap // @@ -325,7 +329,7 @@ winding_t *Q3_BrushSideWinding(q3_dbrush_t *brush, q3_dbrushside_t *baseside) q3_dplane_t *baseplane, *plane; winding_t *w; q3_dbrushside_t *side; - + //create a winding for the brush side with the given planenumber baseplane = &q3_dplanes[baseside->planeNum]; w = BaseWindingForPlane(baseplane->normal, baseplane->dist); @@ -473,8 +477,8 @@ Byte swaps all data in a bsp file. */ void Q3_SwapBSPFile( void ) { int i; - - // models + + // models Q3_SwapBlock( (int *)q3_dmodels, q3_nummodels * sizeof( q3_dmodels[0] ) ); // shaders (don't swap the name) @@ -485,7 +489,7 @@ void Q3_SwapBSPFile( void ) { // planes Q3_SwapBlock( (int *)q3_dplanes, q3_numplanes * sizeof( q3_dplanes[0] ) ); - + // nodes Q3_SwapBlock( (int *)q3_dnodes, q3_numnodes * sizeof( q3_dnodes[0] ) ); @@ -546,7 +550,7 @@ int Q3_CopyLump( q3_dheader_t *header, int lump, void **dest, int size ) { length = header->lumps[lump].filelen; ofs = header->lumps[lump].fileofs; - + if ( length % size ) { Error ("Q3_LoadBSPFile: odd lump size"); } @@ -629,13 +633,13 @@ void Q3_LoadBSPFile(struct quakefile_s *qf) CountTriangles(); FreeMemory( header ); // everything has been copied out - + // swap everything Q3_SwapBSPFile(); Q3_FindVisibleBrushSides(); - //Q3_PrintBSPFileSizes(); + Q3_PrintBSPFileSizes(); } @@ -650,7 +654,7 @@ void Q3_AddLump( FILE *bspfile, q3_dheader_t *header, int lumpnum, void *data, i q3_lump_t *lump; lump = &header->lumps[lumpnum]; - + lump->fileofs = LittleLong( ftell(bspfile) ); lump->filelen = LittleLong( len ); SafeWrite( bspfile, data, (len+3)&~3 ); @@ -670,12 +674,12 @@ void Q3_WriteBSPFile( char *filename ) header = &outheader; memset( header, 0, sizeof(q3_dheader_t) ); - + Q3_SwapBSPFile(); header->ident = LittleLong( Q3_BSP_IDENT ); header->version = LittleLong( Q3_BSP_VERSION ); - + bspfile = SafeOpenWrite( filename ); SafeWrite( bspfile, header, sizeof(q3_dheader_t) ); // overwritten later @@ -696,10 +700,10 @@ void Q3_WriteBSPFile( char *filename ) Q3_AddLump( bspfile, header, Q3_LUMP_ENTITIES, q3_dentdata, q3_entdatasize ); Q3_AddLump( bspfile, header, Q3_LUMP_FOGS, q3_dfogs, q3_numFogs * sizeof(q3_dfog_t) ); Q3_AddLump( bspfile, header, Q3_LUMP_DRAWINDEXES, q3_drawIndexes, q3_numDrawIndexes * sizeof(q3_drawIndexes[0]) ); - + fseek (bspfile, 0, SEEK_SET); SafeWrite (bspfile, header, sizeof(q3_dheader_t)); - fclose (bspfile); + fclose (bspfile); } //============================================================================ @@ -786,26 +790,26 @@ Q3_UnparseEntities Generates the q3_dentdata string from all the entities ================ */ -void Q3_UnparseEntities (void) +char *Q3_UnparseEntities(int *size) { char *buf, *end; epair_t *ep; char line[2048]; int i; - + buf = q3_dentdata; end = buf; *end = 0; - + for (i=0 ; inext) { sprintf (line, "\"%s\" \"%s\"\n", ep->key, ep->value); @@ -819,6 +823,9 @@ void Q3_UnparseEntities (void) Error ("Entity text too long"); } q3_entdatasize = end - buf + 1; + q3_entdatasize = end - buf + 1; + *size = q3_entdatasize; + return buf; } //end of the function Q3_UnparseEntities diff --git a/tools/mbspc/mbspc/l_bsp_q3.h b/tools/mbspc/mbspc/l_bsp_q3.h index 3573c87c..a3f2f628 100644 --- a/tools/mbspc/mbspc/l_bsp_q3.h +++ b/tools/mbspc/mbspc/l_bsp_q3.h @@ -79,3 +79,4 @@ extern char q3_dbrushsidetextured[Q3_MAX_MAP_BRUSHSIDES]; void Q3_LoadBSPFile(struct quakefile_s *qf); void Q3_FreeMaxBSP(void); void Q3_ParseEntities (void); +char *Q3_UnparseEntities(int *size); diff --git a/tools/mbspc/mbspc/l_cmd.c b/tools/mbspc/mbspc/l_cmd.c index e35104b2..b5d912a3 100644 --- a/tools/mbspc/mbspc/l_cmd.c +++ b/tools/mbspc/mbspc/l_cmd.c @@ -22,21 +22,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // cmdlib.c +#include +#include +#include #include "l_cmd.h" #include "l_log.h" #include "l_mem.h" -#include -#include #ifndef SIN #define SIN #endif //SIN -#if defined(WIN32) || defined(_WIN32) -#include -#else -#include -#endif #ifdef NeXT #include @@ -320,7 +316,7 @@ char *ExpandArg (char *path) char *ExpandPath (char *path) { static char full[1024]; - if (!qdir) + if (qdir[0] == 0) Error ("ExpandPath called without qdir set"); if (path[0] == '/' || path[0] == '\\' || path[1] == ':') return path; @@ -386,11 +382,11 @@ double I_FloatTime (void) void Q_getwd (char *out) { + getcwd(out, 256); + #if defined(WIN32) || defined(_WIN32) - getcwd (out, 256); strcat (out, "\\"); #else - getwd(out); strcat(out, "/"); #endif } diff --git a/tools/mbspc/mbspc/l_cmd.h b/tools/mbspc/mbspc/l_cmd.h index 613cafaa..40c90a9f 100644 --- a/tools/mbspc/mbspc/l_cmd.h +++ b/tools/mbspc/mbspc/l_cmd.h @@ -28,15 +28,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #ifndef __CMDLIB__ #define __CMDLIB__ -#ifdef _WIN32 -#pragma warning(disable : 4244) // MIPS -#pragma warning(disable : 4136) // X86 -#pragma warning(disable : 4051) // ALPHA - -#pragma warning(disable : 4018) // signed/unsigned mismatch -#pragma warning(disable : 4305) // truncate from double to float -#endif - #include #include #include diff --git a/tools/mbspc/mbspc/l_log.c b/tools/mbspc/mbspc/l_log.c index 6a69c2b6..57797660 100644 --- a/tools/mbspc/mbspc/l_log.c +++ b/tools/mbspc/mbspc/l_log.c @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include "qbsp.h" @@ -212,4 +213,23 @@ void Log_Flush(void) { if (logfile.fp) fflush(logfile.fp); } //end of the function Log_Flush +//================================================================================ + +void logprintf(char *fmt, ...) +{ + FILE *f; + char buf[1024]; + va_list arglist; + + f = fopen("mbspc.log", "at"); + if (f != NULL) + { + va_start(arglist, fmt); + vsprintf(buf, fmt, arglist); + buf[1023] = '\0'; + + fprintf(f, "%s\n", buf); + fclose(f); + } +} diff --git a/tools/mbspc/mbspc/l_log.h b/tools/mbspc/mbspc/l_log.h index b9f1be46..2b1a9b3d 100644 --- a/tools/mbspc/mbspc/l_log.h +++ b/tools/mbspc/mbspc/l_log.h @@ -40,3 +40,5 @@ void Log_Flush(void); #ifdef WINBSPC void WinBSPCPrint(char *str); #endif //WINBSPC + +void logprintf(char *fmt, ...); diff --git a/tools/mbspc/mbspc/l_mem.c b/tools/mbspc/mbspc/l_mem.c index 31e02b28..dba005df 100644 --- a/tools/mbspc/mbspc/l_mem.c +++ b/tools/mbspc/mbspc/l_mem.c @@ -250,7 +250,7 @@ memoryblock_t *BlockFromPointer(void *ptr, char *str) //char *crash = (char *) NULL; //crash[0] = 1; Error("%s: NULL pointer\n", str); -#endif MEMDEBUG +#endif /* MEMDEBUG */ return NULL; } //end if block = (memoryblock_t *) ((char *) ptr - sizeof(memoryblock_t)); diff --git a/tools/mbspc/mbspc/l_qfiles.c b/tools/mbspc/mbspc/l_qfiles.c index e2e8d104..285fcff0 100644 --- a/tools/mbspc/mbspc/l_qfiles.c +++ b/tools/mbspc/mbspc/l_qfiles.c @@ -411,6 +411,7 @@ quakefile_t *FindQuakeFilesWithPakFilter(char *pakfilter, char *filter) WIN32_FIND_DATA filedata; HWND handle; struct _stat statbuf; + int done; #else glob_t globbuf; struct stat statbuf; @@ -418,7 +419,6 @@ quakefile_t *FindQuakeFilesWithPakFilter(char *pakfilter, char *filter) #endif quakefile_t *qfiles, *lastqf, *qf; char pakfile[_MAX_PATH], filename[_MAX_PATH], *str; - int done; qfiles = NULL; lastqf = NULL; diff --git a/tools/mbspc/mbspc/l_threads.c b/tools/mbspc/mbspc/l_threads.c index 94e641a8..6b1f8059 100644 --- a/tools/mbspc/mbspc/l_threads.c +++ b/tools/mbspc/mbspc/l_threads.c @@ -105,13 +105,13 @@ void RunThreadsOnIndividual (int workcnt, qboolean showpacifier, void(*func)(int //=================================================================== // -// WIN32 +// Win32 // //=================================================================== -#if defined(WIN32) || defined(_WIN32) +#if defined _WIN32 // ****************************************************** -#define USED +#define MULTI_THREAD #include @@ -119,7 +119,7 @@ typedef struct thread_s { HANDLE handle; int threadid; - int id; + DWORD id; struct thread_s *next; } thread_t; @@ -261,7 +261,8 @@ void ThreadSemaphoreIncrease(int count) //=========================================================================== void RunThreadsOn(int workcnt, qboolean showpacifier, void(*func)(int)) { - int threadid[MAX_THREADS]; +// int threadid[MAX_THREADS]; + DWORD threadid[MAX_THREADS]; // ML081030 modified HANDLE threadhandle[MAX_THREADS]; int i; int start, end; @@ -436,324 +437,10 @@ int GetNumThreads(void) return currentnumthreads; } //end of the function GetNumThreads -#endif +#endif // _WIN32 *********************************************************** -//=================================================================== -// -// OSF1 -// -//=================================================================== -#if defined(__osf__) - -#define USED - -#include - -typedef struct thread_s -{ - pthread_t thread; - int threadid; - int id; - struct thread_s *next; -} thread_t; - -thread_t *firstthread; -thread_t *lastthread; -int currentnumthreads; -int currentthreadid; - -int numthreads = 1; -pthread_mutex_t my_mutex; -pthread_attr_t attrib; -static int enter; -static int numwaitingthreads = 0; - - -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void ThreadSetDefault(void) -{ - if (numthreads == -1) // not set manually - { - numthreads = 1; - } //end if - qprintf("%i threads\n", numthreads); -} //end of the function ThreadSetDefault -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void ThreadLock(void) -{ - if (!threaded) - { - Error("ThreadLock: !threaded"); - return; - } //end if - if (my_mutex) - { - pthread_mutex_lock(my_mutex); - } //end if - if (enter) - Error("Recursive ThreadLock\n"); - enter = 1; -} //end of the function ThreadLock -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void ThreadUnlock(void) -{ - if (!threaded) - { - Error("ThreadUnlock: !threaded"); - return; - } //end if - if (!enter) - Error("ThreadUnlock without lock\n"); - enter = 0; - if (my_mutex) - { - pthread_mutex_unlock(my_mutex); - } //end if -} //end of the function ThreadUnlock -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void ThreadSetupLock(void) -{ - pthread_mutexattr_t mattrib; - - Log_Print("pthread multi-threading\n"); - - if (!my_mutex) - { - my_mutex = GetMemory(sizeof(*my_mutex)); - if (pthread_mutexattr_create (&mattrib) == -1) - Error ("pthread_mutex_attr_create failed"); - if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1) - Error ("pthread_mutexattr_setkind_np failed"); - if (pthread_mutex_init (my_mutex, mattrib) == -1) - Error ("pthread_mutex_init failed"); - } - - if (pthread_attr_create (&attrib) == -1) - Error ("pthread_attr_create failed"); - if (pthread_attr_setstacksize (&attrib, 0x100000) == -1) - Error ("pthread_attr_setstacksize failed"); - - threaded = true; - currentnumthreads = 0; - currentthreadid = 0; -} //end of the function ThreadInitLock -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void ThreadShutdownLock(void) -{ - threaded = false; -} //end of the function ThreadShutdownLock -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void RunThreadsOn(int workcnt, qboolean showpacifier, void(*func)(int)) -{ - int i; - pthread_t work_threads[MAX_THREADS]; - pthread_addr_t status; - pthread_attr_t attrib; - pthread_mutexattr_t mattrib; - int start, end; - - Log_Print("pthread multi-threading\n"); - - start = I_FloatTime (); - dispatch = 0; - workcount = workcnt; - oldf = -1; - pacifier = showpacifier; - threaded = true; - - if (numthreads < 1 || numthreads > MAX_THREADS) numthreads = 1; - - if (pacifier) - setbuf (stdout, NULL); - - if (!my_mutex) - { - my_mutex = GetMemory(sizeof(*my_mutex)); - if (pthread_mutexattr_create (&mattrib) == -1) - Error ("pthread_mutex_attr_create failed"); - if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1) - Error ("pthread_mutexattr_setkind_np failed"); - if (pthread_mutex_init (my_mutex, mattrib) == -1) - Error ("pthread_mutex_init failed"); - } - - if (pthread_attr_create (&attrib) == -1) - Error ("pthread_attr_create failed"); - if (pthread_attr_setstacksize (&attrib, 0x100000) == -1) - Error ("pthread_attr_setstacksize failed"); - - for (i=0 ; i= numthreads) return; - currentnumthreads++; - func(-1); - currentnumthreads--; - } //end if - else - { - ThreadLock(); - if (currentnumthreads >= numthreads) - { - ThreadUnlock(); - return; - } //end if - //allocate new thread - thread = GetMemory(sizeof(thread_t)); - if (!thread) Error("can't allocate memory for thread\n"); - // - thread->threadid = currentthreadid; - - if (pthread_create(&thread->thread, attrib, (pthread_startroutine_t)func, (pthread_addr_t)thread->threadid) == -1) - Error ("pthread_create failed"); - - //add the thread to the end of the list - thread->next = NULL; - if (lastthread) lastthread->next = thread; - else firstthread = thread; - lastthread = thread; - // -#ifdef THREAD_DEBUG - qprintf("added thread with id %d\n", thread->threadid); -#endif //THREAD_DEBUG - // - currentnumthreads++; - currentthreadid++; - // - ThreadUnlock(); - } //end else -} //end of the function AddThread -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void RemoveThread(int threadid) -{ - thread_t *thread, *last; - - //if a single thread - if (threadid == -1) return; - // - ThreadLock(); - last = NULL; - for (thread = firstthread; thread; thread = thread->next) - { - if (thread->threadid == threadid) - { - if (last) last->next = thread->next; - else firstthread = thread->next; - if (!thread->next) lastthread = last; - // - FreeMemory(thread); - currentnumthreads--; -#ifdef THREAD_DEBUG - qprintf("removed thread with id %d\n", threadid); -#endif //THREAD_DEBUG - break; - } //end if - last = thread; - } //end if - if (!thread) Error("couldn't find thread with id %d", threadid); - ThreadUnlock(); -} //end of the function RemoveThread -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void WaitForAllThreadsFinished(void) -{ - pthread_t *thread; - pthread_addr_t status; - - ThreadLock(); - while(firstthread) - { - thread = &firstthread->thread; - ThreadUnlock(); - - if (pthread_join(*thread, &status) == -1) - Error("pthread_join failed"); - - ThreadLock(); - } //end while - ThreadUnlock(); -} //end of the function WaitForAllThreadsFinished -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -int GetNumThreads(void) -{ - return currentnumthreads; -} //end of the function GetNumThreads - -#endif //=================================================================== // @@ -763,7 +450,7 @@ int GetNumThreads(void) #if defined(LINUX) -#define USED +#define MULTI_THREAD #include #include @@ -1080,269 +767,7 @@ int GetNumThreads(void) #endif //LINUX -//=================================================================== -// -// IRIX -// -//=================================================================== -#ifdef _MIPS_ISA - -#define USED - -#include -#include -#include -#include - -typedef struct thread_s -{ - int threadid; - int id; - struct thread_s *next; -} thread_t; - -thread_t *firstthread; -thread_t *lastthread; -int currentnumthreads; -int currentthreadid; - -int numthreads = 1; -static int enter; -static int numwaitingthreads = 0; - -abilock_t lck; - -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void ThreadSetDefault (void) -{ - if (numthreads == -1) - numthreads = prctl(PR_MAXPPROCS); - printf ("%i threads\n", numthreads); -//@@ - usconfig (CONF_INITUSERS, numthreads); -} //end of the function ThreadSetDefault -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void ThreadLock (void) -{ - spin_lock (&lck); -} //end of the function ThreadLock -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void ThreadUnlock (void) -{ - release_lock(&lck); -} //end of the function ThreadUnlock -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void ThreadSetupLock(void) -{ - init_lock (&lck); - - Log_Print("IRIX multi-threading\n"); - - threaded = true; - currentnumthreads = 0; - currentthreadid = 0; -} //end of the function ThreadInitLock -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void ThreadShutdownLock(void) -{ - threaded = false; -} //end of the function ThreadShutdownLock -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void RunThreadsOn (int workcnt, qboolean showpacifier, void(*func)(int)) -{ - int i; - int pid[MAX_THREADS]; - int start, end; - - start = I_FloatTime (); - dispatch = 0; - workcount = workcnt; - oldf = -1; - pacifier = showpacifier; - threaded = true; - - if (numthreads < 1 || numthreads > MAX_THREADS) numthreads = 1; - - if (pacifier) - setbuf (stdout, NULL); - - init_lock (&lck); - - for (i=0 ; i= numthreads) return; - currentnumthreads++; - func(-1); - currentnumthreads--; - } //end if - else - { - ThreadLock(); - if (currentnumthreads >= numthreads) - { - ThreadUnlock(); - return; - } //end if - //allocate new thread - thread = GetMemory(sizeof(thread_t)); - if (!thread) Error("can't allocate memory for thread\n"); - // - thread->threadid = currentthreadid; - - thread->id = sprocsp ( (void (*)(void *, size_t))func, PR_SALL, (void *)thread->threadid, NULL, 0x100000); - if (thread->id == -1) - { - perror ("sproc"); - Error ("sproc failed"); - } - - //add the thread to the end of the list - thread->next = NULL; - if (lastthread) lastthread->next = thread; - else firstthread = thread; - lastthread = thread; - // -#ifdef THREAD_DEBUG - qprintf("added thread with id %d\n", thread->threadid); -#endif //THREAD_DEBUG - // - currentnumthreads++; - currentthreadid++; - // - ThreadUnlock(); - } //end else -} //end of the function AddThread -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void RemoveThread(int threadid) -{ - thread_t *thread, *last; - - //if a single thread - if (threadid == -1) return; - // - ThreadLock(); - last = NULL; - for (thread = firstthread; thread; thread = thread->next) - { - if (thread->threadid == threadid) - { - if (last) last->next = thread->next; - else firstthread = thread->next; - if (!thread->next) lastthread = last; - // - FreeMemory(thread); - currentnumthreads--; -#ifdef THREAD_DEBUG - qprintf("removed thread with id %d\n", threadid); -#endif //THREAD_DEBUG - break; - } //end if - last = thread; - } //end if - if (!thread) Error("couldn't find thread with id %d", threadid); - ThreadUnlock(); -} //end of the function RemoveThread -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -void WaitForAllThreadsFinished(void) -{ - ThreadLock(); - while(firstthread) - { - ThreadUnlock(); - - //wait (NULL); - - ThreadLock(); - } //end while - ThreadUnlock(); -} //end of the function WaitForAllThreadsFinished -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== -int GetNumThreads(void) -{ - return currentnumthreads; -} //end of the function GetNumThreads - -#endif //_MIPS_ISA //======================================================================= @@ -1351,7 +776,7 @@ int GetNumThreads(void) // //======================================================================= -#ifndef USED +#if ! defined MULTI_THREAD int numthreads = 1; int currentnumthreads = 0; @@ -1507,4 +932,4 @@ int GetNumThreads(void) return currentnumthreads; } //end of the function GetNumThreads -#endif //USED +#endif // MULTI_THREAD diff --git a/tools/mbspc/mbspc/l_utils.c b/tools/mbspc/mbspc/l_utils.c index 8b229aa4..49404d60 100644 --- a/tools/mbspc/mbspc/l_utils.c +++ b/tools/mbspc/mbspc/l_utils.c @@ -20,31 +20,25 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =========================================================================== */ -//#ifndef BOTLIB -//#define BOTLIB -//#endif //BOTLIB +#if 0 // ML081030 removed ******** -#ifdef BOTLIB -#include "q_shared.h" -#include "qfiles.h" -#include "botlib.h" +// #ifdef BOTLIB +#include "../qcommon/q_shared.h" +#include "../qcommon/qfiles.h" +#include "../botlib/botlib.h" #include "l_log.h" -#include "l_libvar.h" -#include "l_memory.h" -//#include "l_utils.h" -#include "be_interface.h" -#else //BOTLIB +#include "../botlib/l_libvar.h" +#include "../botlib/l_memory.h" +#include "../botlib/be_interface.h" +// #else //BOTLIB + +#endif // ************************* + #include "qbsp.h" #include "l_mem.h" -#endif //BOTLIB +#if 0 // ML081030 removed ********* #ifdef BOTLIB -//======================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//======================================================================== void Vector2Angles(vec3_t value1, vec3_t angles) { float forward; @@ -71,12 +65,8 @@ void Vector2Angles(vec3_t value1, vec3_t angles) angles[ROLL] = 0; } //end of the function Vector2Angles #endif //BOTLIB -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== + +#endif // *************************************** void ConvertPath(char *path) { while(*path) @@ -85,12 +75,6 @@ void ConvertPath(char *path) path++; } //end while } //end of the function ConvertPath -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== void AppendPathSeperator(char *path, int length) { int pathlen = strlen(path); @@ -102,14 +86,11 @@ void AppendPathSeperator(char *path, int length) } //end if } //end of the function AppenPathSeperator -#if 0 +#if 0 // Was alreqady removed in original ********** + //=========================================================================== // returns pointer to file handle // sets offset to and length of 'filename' in the pak file -// -// Parameter: - -// Returns: - -// Changes Globals: - //=========================================================================== qboolean FindFileInPak(char *pakfile, char *filename, foundfile_t *file) { @@ -170,10 +151,6 @@ qboolean FindFileInPak(char *pakfile, char *filename, foundfile_t *file) // find a Quake2 file // returns full path in 'filename' // sets offset and length of the file -// -// Parameter: - -// Returns: - -// Changes Globals: - //=========================================================================== qboolean FindQuakeFile2(char *basedir, char *gamedir, char *filename, foundfile_t *file) { @@ -237,12 +214,7 @@ qboolean FindQuakeFile2(char *basedir, char *gamedir, char *filename, foundfile_ file->length = 0; return false; } //end of the function FindQuakeFile2 -//=========================================================================== -// -// Parameter: - -// Returns: - -// Changes Globals: - -//=========================================================================== + #ifdef BOTLIB qboolean FindQuakeFile(char *filename, foundfile_t *file) { @@ -256,4 +228,4 @@ qboolean FindQuakeFile(char *basedir, char *gamedir, char *filename, foundfile_t } //end of the function FindQuakeFile #endif //BOTLIB -#endif +#endif // *************************************************** diff --git a/tools/mbspc/mbspc/l_utils.h b/tools/mbspc/mbspc/l_utils.h index ebd8dbb6..d0e165a2 100644 --- a/tools/mbspc/mbspc/l_utils.h +++ b/tools/mbspc/mbspc/l_utils.h @@ -61,13 +61,17 @@ typedef struct foundfile_s char filename[MAX_PATH]; //screw LCC, array must be at end of struct } foundfile_t; -void Vector2Angles(vec3_t value1, vec3_t angles); +// ML081030 removed +// void Vector2Angles (vec3_t value1, vec3_t angles); + //set the correct path seperators void ConvertPath(char *path); //append a path seperator to the given path not exceeding the length void AppendPathSeperator(char *path, int length); //find a file in a pak file qboolean FindFileInPak(char *pakfile, char *filename, foundfile_t *file); +#if 0 // ML081030 removed ******************** + //find a quake file #ifdef BOTLIB qboolean FindQuakeFile(char *filename, foundfile_t *file); @@ -75,5 +79,4 @@ qboolean FindQuakeFile(char *filename, foundfile_t *file); qboolean FindQuakeFile(char *basedir, char *gamedir, char *filename, foundfile_t *file); #endif //BOTLIB - - +#endif // ************************************* diff --git a/tools/mbspc/mbspc/leakfile.c b/tools/mbspc/mbspc/leakfile.c index 924b34d5..3abaeca2 100644 --- a/tools/mbspc/mbspc/leakfile.c +++ b/tools/mbspc/mbspc/leakfile.c @@ -68,8 +68,8 @@ void LeakFile (tree_t *tree) while (node->occupied > 1) { int next; - portal_t *p, *nextportal; - node_t *nextnode; + portal_t *p, *nextportal = NULL; + node_t *nextnode = NULL; int s; // find the best portal exit diff --git a/tools/mbspc/mbspc/map.c b/tools/mbspc/mbspc/map.c index e156d3a9..a65862d0 100644 --- a/tools/mbspc/mbspc/map.c +++ b/tools/mbspc/mbspc/map.c @@ -20,6 +20,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =========================================================================== */ +// ML090131 added +#include +#include +#include + #include "qbsp.h" #include "l_bsp_hl.h" #include "l_bsp_q1.h" @@ -645,6 +650,39 @@ int BrushExists(mapbrush_t *brush) return false; } //end of the function BrushExists //=========================================================================== + +q3_dshader_t * +get_shader_ptr(int bidx, int sidx) +{ + q3_dbrush_t *dbrush; + q3_dbrushside_t *dside; + + if (bidx < 0 || bidx >= q3_numbrushes) + { + logprintf("Brush index out of range"); + return NULL; + } + + dbrush = &q3_dbrushes[bidx]; + sidx += dbrush->firstSide; + + if (sidx < 0 || sidx >= q3_numbrushsides) + { + logprintf("Brush side index out of range"); + return NULL; + } + + dside = &q3_dbrushsides[sidx]; + + if (dside->shaderNum < 0 || dside->shaderNum >= q3_numShaders) + { + logprintf("Shader index out of range"); + return NULL; + } + + return &q3_dshaders[dside->shaderNum]; +} +//=========================================================================== // // Parameter: - // Returns: - @@ -726,7 +764,7 @@ qboolean WriteMapBrush(FILE *fp, mapbrush_t *brush, vec3_t origin) } //end else else if (loadedmaptype == MAPTYPE_QUAKE3) { - if (fprintf(fp, "e1u1/clip 0 0 0 1 1") < 0) return false; + if (fprintf(fp, "common/clip 0 0 0 1 1 1 0 0") < 0) return false; } //end else if else { @@ -772,9 +810,37 @@ qboolean WriteMapBrush(FILE *fp, mapbrush_t *brush, vec3_t origin) } //end if else if (loadedmaptype == MAPTYPE_QUAKE3) { - //always use the same texture - if (fprintf(fp, "e2u3/floor1_2 0 0 0 1 1 1 0 0") < 0) return false; - } //end else if + char texbuf[256], *cp; + q3_dshader_t *dshader; + + dshader = get_shader_ptr(brush->brushnum, sn); + + if (dshader == NULL) + { + if (fprintf(fp, "***unknown*** 0 0 0 1 1 1 0 0") < 0) + return false; + } + else + { + strcpy(texbuf, dshader->shader); + cp = &texbuf[0]; + while (*cp != '/' && *cp != 0) + cp++; + + if (*cp == '/') + { + cp++; + if (fprintf(fp, "%s 0 0 0 1 1 1 0 0", cp) < 0) + return false; + } + else + { + if (fprintf(fp, "***unknown*** 0 0 0 1 1 1 0 0") < 0) + return false; + } + } + } + else { //* @@ -830,7 +896,7 @@ qboolean WriteMapBrush(FILE *fp, mapbrush_t *brush, vec3_t origin) //write the extra brush side info if (loadedmaptype == MAPTYPE_QUAKE2) { - if (fprintf(fp, " %ld %ld %ld", s->contents, ti->flags, ti->value) < 0) return false; + if (fprintf(fp, " %d %d %d", s->contents, ti->flags, ti->value) < 0) return false; } //end if //*/ } //end else @@ -908,7 +974,7 @@ qboolean WriteOriginBrush(FILE *fp, vec3_t origin) mapbrush_t *GetAreaPortalBrush(entity_t *mapent) { int portalnum, bn; - mapbrush_t *brush; + mapbrush_t *brush = NULL; //the area portal number portalnum = mapent->areaportalnum; @@ -1217,7 +1283,9 @@ int LoadMapFromBSP(struct quakefile_s *qf) { ResetMapLoading(); Q3_LoadMapFromBSP(qf); - Q3_FreeMaxBSP(); + // ML081105 removed: need data for texture info + // Q3_FreeMaxBSP(); + } //end if //Quake2 BSP file else if (idheader.ident == Q2_BSPHEADER && idheader.version == Q2_BSPVERSION) @@ -1265,3 +1333,128 @@ int LoadMapFromBSP(struct quakefile_s *qf) // return true; } //end of the function LoadMapFromBSP + +//========================================================= +// ML090131 added: function for writing texture information + +static char *tex, **tex_p; + +void WriteTexinfo(char *name) +{ + FILE *f; + int i, swapped; + char *cp; + + if (loadedmaptype != MAPTYPE_QUAKE3) + { + Log_Print("Texture info extraction is implemented only for Q3A.\n"); + return; + } + + if (name == NULL || name[0] == 0) + { + Log_Print("WriteTexinfo: Bad file name.\n"); + return; + } + + /********************************/ + /* allocate string buffer array */ + /********************************/ + + tex = (char *) malloc(q3_numShaders * MAX_QPATH); + if (tex == NULL) + { + Log_Print("WriteTexinfo: memory allocation error\n"); + return; + } + + tex_p = (char **) malloc(q3_numShaders * sizeof(char *)); + if (tex_p == NULL) + { + free(tex); + Log_Print("WriteTexinfo: memory allocation error\n"); + return; + } + + for (i = 0; i < q3_numShaders; i++) + tex_p[i] = tex + i * MAX_QPATH; + + /****************************/ + /* copy & sort shader names */ + /****************************/ + + for (i = 0; i < q3_numShaders; i++) + strncpy(tex_p[i], q3_dshaders[i].shader, MAX_QPATH - 1); + + do + { + swapped = 0; + for (i = 0; i < q3_numShaders - 1; i++) + if (strcmp(tex_p[i], tex_p[i + 1]) > 0) + { + cp = tex_p[i]; + tex_p[i] = tex_p[i + 1]; + tex_p[i + 1] = cp; + swapped = 1; + } + } while (swapped); + + /**********************/ + /* create output file */ + /**********************/ + + f = fopen(name, "wt"); + if (f == NULL) + { + Log_Print("WriteTexinfo: Cannot open '%s'\n", name); + free(tex); + free(tex_p); + return; + } + + /*******************/ + /* write info file */ + /*******************/ + + for (i = 0; i < q3_numShaders; i++) + if (fprintf(f, "%s\n", tex_p[i]) < 0) + { + fclose(f); + unlink(name); + Log_Print("WriteTexinfo: I/O error when writing '%s'\n", name); + free(tex); + free(tex_p); + return; + } + + fclose(f); + Log_Print("WriteTexinfo: %d texture names to '%s'\n", i, name); + free(tex); + free(tex_p); +} +//========================================================= + +void WriteEntList(char *fname, char *ent_str, int size) +{ + FILE *f; + int i; + + if (fname == NULL || fname[0] == 0) + { + Log_Print("WriteEntList: Bad file name.\n"); + return; + } + + f = fopen(fname, "wt"); + if (f == NULL) + { + Log_Print("WriteEntList: Cannot open '%s'\n", fname); + return; + } + + for (i = 0; i < size; i++) + fputc((int) ent_str[i], f); + + fputc('\n', f); + fclose(f); +} \ No newline at end of file diff --git a/tools/mbspc/mbspc/map_hl.c b/tools/mbspc/mbspc/map_hl.c index 88e4fa79..bbd00cb5 100644 --- a/tools/mbspc/mbspc/map_hl.c +++ b/tools/mbspc/mbspc/map_hl.c @@ -506,7 +506,7 @@ bspbrush_t *HL_CreateBrushesFromBSP(int modelnum) //=========================================================================== bspbrush_t *HL_MergeBrushes(bspbrush_t *brushlist, int modelnum) { - int nummerges, merged; + int nummerges = 0, merged; bspbrush_t *b1, *b2, *tail, *newbrush, *newbrushlist; bspbrush_t *lastb2; @@ -701,7 +701,7 @@ bspbrush_t *HL_SplitBrushWithFace(bspbrush_t *brush, hl_dface_t *face) bspbrush_t *HL_TextureBrushes(bspbrush_t *brushlist, int modelnum) { float area, largestarea; - int i, n, texinfonum, sn, numbrushes, ofs; + int i, n, texinfonum, sn, numbrushes = 0, ofs; int bestfacenum, sidenodenum; side_t *side; hl_dmiptexlump_t *miptexlump; @@ -1022,7 +1022,7 @@ void HL_BSPBrushToMapBrush(bspbrush_t *bspbrush, entity_t *mapent) void HL_CreateMapBrushes(entity_t *mapent, int modelnum) { bspbrush_t *brushlist, *brush, *nextbrush; - int i; + int i = 0; //create brushes from the model BSP tree brushlist = HL_CreateBrushesFromBSP(modelnum); @@ -1038,7 +1038,7 @@ void HL_CreateMapBrushes(entity_t *mapent, int modelnum) } //end if // if (!modelnum) qprintf("converting brushes to map brushes\n"); - if (!modelnum) qprintf("%5d brushes", i = 0); + if (!modelnum) qprintf("%5d brushes", i ); for (brush = brushlist; brush; brush = nextbrush) { nextbrush = brush->next; diff --git a/tools/mbspc/mbspc/map_q1.c b/tools/mbspc/mbspc/map_q1.c index fa9d1173..0a9750e3 100644 --- a/tools/mbspc/mbspc/map_q1.c +++ b/tools/mbspc/mbspc/map_q1.c @@ -275,11 +275,11 @@ int Q1_SolidTree_r(int nodenum) case Q1_CONTENTS_SOLID: #ifdef HLCONTENTS case Q1_CONTENTS_CLIP: -#endif HLCONTENTS +#endif /* HLCONTENTS */ case Q1_CONTENTS_SKY: #ifdef HLCONTENTS case Q1_CONTENTS_TRANSLUCENT: -#endif HLCONTENTS +#endif /* HLCONTENTS */ { return true; } //end case @@ -295,7 +295,7 @@ int Q1_SolidTree_r(int nodenum) case Q1_CONTENTS_CURRENT_270: case Q1_CONTENTS_CURRENT_UP: case Q1_CONTENTS_CURRENT_DOWN: -#endif HLCONTENTS +#endif /* HLCONTENTS */ default: { return false; @@ -339,11 +339,11 @@ bspbrush_t *Q1_CreateBrushes_r(bspbrush_t *brush, int nodenum) case Q1_CONTENTS_SOLID: #ifdef HLCONTENTS case Q1_CONTENTS_CLIP: -#endif HLCONTENTS +#endif /* HLCONTENTS */ case Q1_CONTENTS_SKY: #ifdef HLCONTENTS case Q1_CONTENTS_TRANSLUCENT: -#endif HLCONTENTS +#endif /* HLCONTENTS */ { brush->side = CONTENTS_SOLID; return brush; @@ -376,7 +376,7 @@ bspbrush_t *Q1_CreateBrushes_r(bspbrush_t *brush, int nodenum) Error("Q1_CreateBrushes_r: found contents %d in Half-Life BSP", leaf->contents); return NULL; } //end case -#endif HLCONTENTS +#endif /* HLCONTENTS */ default: { Error("Q1_CreateBrushes_r: unknown contents %d in Half-Life BSP", leaf->contents); @@ -562,7 +562,7 @@ void Q1_FacePlane(q1_dface_t *face, vec3_t normal, float *dist) //=========================================================================== bspbrush_t *Q1_MergeBrushes(bspbrush_t *brushlist, int modelnum) { - int nummerges, merged; + int nummerges = 0, merged; bspbrush_t *b1, *b2, *tail, *newbrush, *newbrushlist; bspbrush_t *lastb2; @@ -757,7 +757,7 @@ bspbrush_t *Q1_SplitBrushWithFace(bspbrush_t *brush, q1_dface_t *face) bspbrush_t *Q1_TextureBrushes(bspbrush_t *brushlist, int modelnum) { float area, largestarea; - int i, n, texinfonum, sn, numbrushes, ofs; + int i, n, texinfonum, sn, numbrushes = 0, ofs; int bestfacenum, sidenodenum; side_t *side; q1_dmiptexlump_t *miptexlump; @@ -1080,7 +1080,7 @@ void Q1_BSPBrushToMapBrush(bspbrush_t *bspbrush, entity_t *mapent) void Q1_CreateMapBrushes(entity_t *mapent, int modelnum) { bspbrush_t *brushlist, *brush, *nextbrush; - int i; + int i = 0; //create brushes from the model BSP tree brushlist = Q1_CreateBrushesFromBSP(modelnum); @@ -1096,7 +1096,7 @@ void Q1_CreateMapBrushes(entity_t *mapent, int modelnum) } //end if // if (!modelnum) qprintf("converting brushes to map brushes\n"); - if (!modelnum) qprintf("%5d brushes", i = 0); + if (!modelnum) qprintf("%5d brushes", i ); for (brush = brushlist; brush; brush = nextbrush) { nextbrush = brush->next; diff --git a/tools/mbspc/mbspc/map_q2.c b/tools/mbspc/mbspc/map_q2.c index a91e78a2..58370276 100644 --- a/tools/mbspc/mbspc/map_q2.c +++ b/tools/mbspc/mbspc/map_q2.c @@ -494,7 +494,6 @@ qboolean Q2_ParseMapEntity(script_t *script) epair_t *e; side_t *s; int i, j; - int startbrush, startsides; vec_t newdist; mapbrush_t *b; token_t token; @@ -507,8 +506,6 @@ qboolean Q2_ParseMapEntity(script_t *script) if (num_entities == MAX_MAP_ENTITIES) Error ("num_entities == MAX_MAP_ENTITIES"); - startbrush = nummapbrushes; - startsides = nummapbrushsides; mapent = &entities[num_entities]; num_entities++; @@ -994,10 +991,6 @@ qboolean Q2_ParseBSPEntity(int entnum) { entity_t *mapent; char *model; - int startbrush, startsides; - - startbrush = nummapbrushes; - startsides = nummapbrushsides; mapent = &entities[entnum];//num_entities]; mapent->firstbrush = nummapbrushes; diff --git a/tools/mbspc/mbspc/map_q3.c b/tools/mbspc/mbspc/map_q3.c index 375100cb..c2781eb5 100644 --- a/tools/mbspc/mbspc/map_q3.c +++ b/tools/mbspc/mbspc/map_q3.c @@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "aas_map.h" //AAS_CreateMapBrushes #include "l_bsp_q3.h" #include "../qcommon/cm_patch.h" -#include "../game/surfaceflags.h" +#include "../qcommon/surfaceflags.h" #define NODESTACKSIZE 1024 @@ -390,10 +390,6 @@ qboolean Q3_ParseBSPEntity(int entnum) { entity_t *mapent; char *model; - int startbrush, startsides; - - startbrush = nummapbrushes; - startsides = nummapbrushsides; mapent = &entities[entnum];//num_entities]; mapent->firstbrush = nummapbrushes; @@ -609,7 +605,6 @@ void AAS_ExpandMapBrush(mapbrush_t *brush, vec3_t mins, vec3_t maxs); void Q3_LoadMapFromBSP(struct quakefile_s *qf) { int i; - vec3_t mins = {-1,-1,-1}, maxs = {1, 1, 1}; Log_Print("-- Q3_LoadMapFromBSP --\n"); //loaded map type diff --git a/tools/mbspc/mbspc/map_sin.c b/tools/mbspc/mbspc/map_sin.c index b6e67ffb..ce8d1954 100644 --- a/tools/mbspc/mbspc/map_sin.c +++ b/tools/mbspc/mbspc/map_sin.c @@ -443,7 +443,6 @@ qboolean Sin_ParseMapEntity (void) epair_t *e; side_t *s; int i, j; - int startbrush, startsides; vec_t newdist; mapbrush_t *b; @@ -456,8 +455,6 @@ qboolean Sin_ParseMapEntity (void) if (num_entities == MAX_MAP_ENTITIES) Error ("num_entities == MAX_MAP_ENTITIES"); - startbrush = nummapbrushes; - startsides = nummapbrushsides; mapent = &entities[num_entities]; num_entities++; @@ -1103,10 +1100,6 @@ qboolean Sin_ParseBSPEntity(int entnum) { entity_t *mapent; char *model; - int startbrush, startsides; - - startbrush = nummapbrushes; - startsides = nummapbrushsides; mapent = &entities[entnum];//num_entities]; mapent->firstbrush = nummapbrushes; diff --git a/tools/mbspc/mbspc/portals.c b/tools/mbspc/mbspc/portals.c index cde4f60b..3086c420 100644 --- a/tools/mbspc/mbspc/portals.c +++ b/tools/mbspc/mbspc/portals.c @@ -408,8 +408,8 @@ void MakeNodePortal (node_t *node) portal_t *new_portal, *p; winding_t *w; vec3_t normal; - float dist; - int side; + float dist = 0.f; + int side = 0; w = BaseWindingForNode (node); @@ -482,7 +482,7 @@ void SplitNodePortals (node_t *node) { portal_t *p, *next_portal, *new_portal; node_t *f, *b, *other_node; - int side; + int side = 0; plane_t *plane; winding_t *frontwinding, *backwinding; @@ -1110,7 +1110,7 @@ void SetAreaPortalAreas_r (node_t *node) // Returns: - // Changes Globals: - //=========================================================================== -/* +#if 0 // _ML_ removed void EmitAreaPortals(node_t *headnode) { int i, j; @@ -1150,7 +1150,8 @@ void EmitAreaPortals(node_t *headnode) Log_Print("%5i numareas\n", numareas); Log_Print("%5i numareaportals\n", numareaportals); } //end of the function EmitAreaPortals -*/ +#endif + //=========================================================================== // Mark each leaf with an area, bounded by CONTENTS_AREAPORTAL // diff --git a/tools/mbspc/mbspc/q3files.h b/tools/mbspc/mbspc/q3files.h index 5ed267d9..919a9489 100644 --- a/tools/mbspc/mbspc/q3files.h +++ b/tools/mbspc/mbspc/q3files.h @@ -36,13 +36,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define MAX_QPATH 64 +#if 0 // *************** + /* ======================================================================== PCX files are used for 8 bit images ======================================================================== -* +*/ typedef struct { char manufacturer; @@ -67,7 +69,7 @@ typedef struct { TGA files are used for 24/32 bit images ======================================================================== -* +*/ typedef struct _TargaHeader { unsigned char id_length, colormap_type, image_type; @@ -77,8 +79,8 @@ typedef struct _TargaHeader { unsigned char pixel_size, attributes; } TargaHeader; +#endif // **************************** -*/ /* ======================================================================== diff --git a/tools/mbspc/mbspc/qbsp.h b/tools/mbspc/mbspc/qbsp.h index dd572006..909424b6 100644 --- a/tools/mbspc/mbspc/qbsp.h +++ b/tools/mbspc/mbspc/qbsp.h @@ -22,6 +22,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #if defined(WIN32) || defined(_WIN32) +// _ML_ added + #undef QDECL + #define QDECL __cdecl +// _ML_ added end #include #endif #include @@ -37,7 +41,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "l_log.h" #include "l_qfiles.h" -#define BSPC_VERSION "2.1h" +// _ML_ added +#define Com_Memset memset +#define Com_Memcpy memcpy +#define Q_vsnprintf vsnprintf +#define Com_sprintf sprintf +#if defined __linux__ + #define stricmp strcasecmp +#endif +// _ML_ added end + +#define BSPC_VERSION "2.2" // _ML_ modified #define ME #define DEBUG @@ -228,6 +242,33 @@ extern vec_t microvolume; extern char outbase[32]; extern char source[1024]; +// _ML_ added +extern dvertex_t *dvertexes; +extern dedge_t *dedges; +extern texinfo_t texinfo[]; +extern dleaf_t *dleafs; +extern dplane_t *dplanes; +extern dmodel_t *dmodels; +extern dface_t *dfaces; +extern dnode_t *dnodes; +extern dbrush_t *dbrushes; +extern dbrushside_t *dbrushsides; +extern unsigned short *dleaffaces; +extern unsigned short *dleafbrushes; +extern int *dsurfedges; +extern int numvertexes; +extern int numedges; +extern int nummodels; +extern int numfaces; +extern int numnodes; +extern int numbrushes; +extern int numbrushsides; +extern int numleaffaces; +extern int numleafbrushes; +extern int numsurfedges; +extern int numleafs; +extern int numplanes; +// _ML_ added end //============================================================================= // map.c @@ -312,6 +353,9 @@ void ResetMapLoading(void); void PrintMapInfo(void); //writes a map file (type depending on loaded map type) void WriteMapFile(char *filename); +// ML310109 added prototype +void WriteTexinfo(char *filename); +void WriteEntList(char *filename, char *entstring, int size); //============================================================================= // map_q2.c @@ -475,3 +519,12 @@ void Tree_Print_r(node_t *node, int depth); void Tree_FreePortals_r(node_t *node); void Tree_PruneNodes_r(node_t *node); void Tree_PruneNodes(node_t *node); +// ML081030 added + +void AAS_InitBotImport(void); +void AAS_InitClustering(void); +void AAS_ShowTotals(void); + +char *Q1_UnparseEntities(int *size); +char *Q2_UnparseEntities(int *size); +char *Q3_UnparseEntities(int *size); diff --git a/tools/mbspc/mbspc/qfiles.h b/tools/mbspc/mbspc/qfiles.h index 317e47cc..237dd7b2 100644 --- a/tools/mbspc/mbspc/qfiles.h +++ b/tools/mbspc/mbspc/qfiles.h @@ -396,7 +396,7 @@ typedef struct typedef struct texinfo_s { - float vecs[2][4]; // [s/t][xyz offset] + float vecs[2][8]; // [s/t][xyz offset] int flags; // miptex flags + overrides int value; // light emission, etc char texture[32]; // texture name (textures/*.wal) diff --git a/tools/mbspc/mbspc/writebsp.c b/tools/mbspc/mbspc/writebsp.c index b6cf4e4a..0f6e24c0 100644 --- a/tools/mbspc/mbspc/writebsp.c +++ b/tools/mbspc/mbspc/writebsp.c @@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA int c_nofaces; int c_facenodes; - +int GetEdge2(int v1, int v2, face_t * f); /* ========================================================= @@ -293,8 +293,7 @@ int EmitDrawNode_r (node_t *node) } //========================================================= - - +#if 0 // _ML_ removed /* ============ WriteBSP @@ -317,6 +316,7 @@ void WriteBSP (node_t *headnode) qprintf ("%5i nodes without faces\n", c_nofaces); qprintf ("%5i faces\n", numfaces-oldfaces); } +#endif //=========================================================== @@ -506,24 +506,11 @@ EndBSPFile */ void EndBSPFile (void) { -#if 0 - char path[1024]; int len; - byte *buf; -#endif - EmitBrushes (); EmitPlanes (); - Q2_UnparseEntities (); - - // load the pop -#if 0 - sprintf (path, "%s/pics/pop.lmp", gamedir); - len = LoadFile (path, &buf); - memcpy (dpop, buf, sizeof(dpop)); - FreeMemory(buf); -#endif + Q2_UnparseEntities(&len); } diff --git a/tools/mbspc/qcommon/cm_load.c b/tools/mbspc/qcommon/cm_load.c index bc4d8bb1..5efb490f 100644 --- a/tools/mbspc/qcommon/cm_load.c +++ b/tools/mbspc/qcommon/cm_load.c @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #ifdef BSPC -#include "../bspc/l_qfiles.h" +#include "../mbspc/l_qfiles.h" void SetPlaneSignbits (cplane_t *out) { int bits, j; @@ -567,7 +567,11 @@ Loads in the map and all submodels ================== */ void CM_LoadMap( const char *name, qboolean clientload, int *checksum ) { - int *buf; + union + { + int *i; + void *v; + } buf; int i; dheader_t header; int length; @@ -606,19 +610,19 @@ void CM_LoadMap( const char *name, qboolean clientload, int *checksum ) { // load the file // #ifndef BSPC - length = FS_ReadFile( name, (void **)&buf ); + length = FS_ReadFile(name, &buf.v); #else - length = LoadQuakeFile((quakefile_t *) name, (void **)&buf); + length = LoadQuakeFile((quakefile_t *) name, &buf.v); #endif - if ( !buf ) { + if (!buf.i) { Com_Error (ERR_DROP, "Couldn't load %s", name); } - last_checksum = LittleLong (Com_BlockChecksum (buf, length)); + last_checksum = LittleLong(Com_BlockChecksum(buf.i, length)); *checksum = last_checksum; - header = *(dheader_t *)buf; + header = *(dheader_t *) buf.i; for (i=0 ; inumBorders && w ; j++ ) { if ( facet->borderPlanes[j] == -1 ) { + FreeWinding(w); return qfalse; } Vector4Copy( planes[ facet->borderPlanes[j] ].plane, plane ); @@ -980,7 +981,7 @@ CM_PatchCollideFromGrid static void CM_PatchCollideFromGrid( cGrid_t *grid, patchCollide_t *pf ) { int i, j; float *p1, *p2, *p3; - MAC_STATIC int gridPlanes[MAX_GRID_SIZE][MAX_GRID_SIZE][2]; + int gridPlanes[MAX_GRID_SIZE][MAX_GRID_SIZE][2]; facet_t *facet; int borders[4]; int noAdjust[4]; @@ -1147,12 +1148,12 @@ Points is packed as concatenated rows. */ struct patchCollide_s *CM_GeneratePatchCollide( int width, int height, vec3_t *points ) { patchCollide_t *pf; - MAC_STATIC cGrid_t grid; + cGrid_t grid; int i, j; if ( width <= 2 || height <= 2 || !points ) { Com_Error( ERR_DROP, "CM_GeneratePatchFacets: bad parameters: (%i, %i, %p)", - width, height, points ); + width, height, (void *) points ); } if ( !(width & 1) || !(height & 1) ) { @@ -1379,12 +1380,18 @@ void CM_TraceThroughPatchCollide( traceWork_t *tw, const struct patchCollide_s * float offset, enterFrac, leaveFrac, t; patchPlane_t *planes; facet_t *facet; - float plane[4], bestplane[4]; + float plane[4] = { 0, 0, 0, 0 }, bestplane[4] = { 0, 0, 0, 0 }; vec3_t startp, endp; #ifndef BSPC static cvar_t *cv; #endif //BSPC + if (!CM_BoundsIntersect(tw->bounds[0], tw->bounds[1], + pc->bounds[0], pc->bounds[1])) + { + return; + } + if (tw->isPoint) { CM_TracePointThroughPatchCollide( tw, pc ); return; diff --git a/tools/mbspc/qcommon/cm_test.c b/tools/mbspc/qcommon/cm_test.c index 10ba3298..f6d685fb 100644 --- a/tools/mbspc/qcommon/cm_test.c +++ b/tools/mbspc/qcommon/cm_test.c @@ -249,6 +249,9 @@ int CM_PointContents( const vec3_t p, clipHandle_t model ) { for (k=0 ; knumLeafBrushes ; k++) { brushnum = cm.leafbrushes[leaf->firstLeafBrush+k]; b = &cm.brushes[brushnum]; + if( !CM_BoundsIntersectPoint( b->bounds[0], b->bounds[1], p ) ) { + continue; + } // see if the point is in the brush for ( i = 0 ; i < b->numsides ; i++ ) { @@ -476,3 +479,37 @@ int CM_WriteAreaBits (byte *buffer, int area) return bytes; } +/* +==================== +CM_BoundsIntersect +==================== +*/ +qboolean CM_BoundsIntersect( const vec3_t mins, const vec3_t maxs, const vec3_t mins2, const vec3_t maxs2 ) { + if( maxs[0] < mins2[0] - SURFACE_CLIP_EPSILON || + maxs[1] < mins2[1] - SURFACE_CLIP_EPSILON || + maxs[2] < mins2[2] - SURFACE_CLIP_EPSILON || + mins[0] > maxs2[0] + SURFACE_CLIP_EPSILON || + mins[1] > maxs2[1] + SURFACE_CLIP_EPSILON || + mins[2] > maxs2[2] + SURFACE_CLIP_EPSILON ) { + return qfalse; + } + + return qtrue; +} +/* +==================== +CM_BoundsIntersectPoint +==================== +*/ +qboolean CM_BoundsIntersectPoint( const vec3_t mins, const vec3_t maxs, const vec3_t point ) { + if( maxs[0] < point[0] - SURFACE_CLIP_EPSILON || + maxs[1] < point[1] - SURFACE_CLIP_EPSILON || + maxs[2] < point[2] - SURFACE_CLIP_EPSILON || + mins[0] > point[0] + SURFACE_CLIP_EPSILON || + mins[1] > point[1] + SURFACE_CLIP_EPSILON || + mins[2] > point[2] + SURFACE_CLIP_EPSILON ) { + return qfalse; + } + + return qtrue; +} diff --git a/tools/mbspc/qcommon/cm_trace.c b/tools/mbspc/qcommon/cm_trace.c index 6eb99313..0346f572 100644 --- a/tools/mbspc/qcommon/cm_trace.c +++ b/tools/mbspc/qcommon/cm_trace.c @@ -131,15 +131,14 @@ SquareRootFloat ================ */ float SquareRootFloat(float number) { - long i; + floatint_t t; float x, y; const float f = 1.5F; x = number * 0.5F; - y = number; - i = * ( long * ) &y; - i = 0x5f3759df - ( i >> 1 ); - y = * ( float * ) &i; + t.f = number; + t.i = 0x5f3759df - ( t.i >> 1 ); + y = t.f; y = y * ( f - ( x * y * y ) ); y = y * ( f - ( x * y * y ) ); return number * y; @@ -682,6 +681,10 @@ void CM_TraceThroughLeaf( traceWork_t *tw, cLeaf_t *leaf ) { if ( !(b->contents & tw->contents) ) { continue; } + if( !CM_BoundsIntersect( tw->bounds[0], tw->bounds[1], + b->bounds[0], b->bounds[1] ) ) { + continue; + } CM_TraceThroughBrush( tw, b ); if ( !tw->trace.fraction ) { @@ -728,7 +731,7 @@ get the first intersection of the ray with the sphere */ void CM_TraceThroughSphere( traceWork_t *tw, vec3_t origin, float radius, vec3_t start, vec3_t end ) { float l1, l2, length, scale, fraction; - float a, b, c, d, sqrtd; + float b, c, d, sqrtd; vec3_t v1, dir, intersection; // if inside the sphere @@ -764,7 +767,7 @@ void CM_TraceThroughSphere( traceWork_t *tw, vec3_t origin, float radius, vec3_t // VectorSubtract(start, origin, v1); // dir is normalized so a = 1 - a = 1.0f;//dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2]; + //a = 1.0f;//dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2]; b = 2.0f * (dir[0] * v1[0] + dir[1] * v1[1] + dir[2] * v1[2]); c = v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] - (radius+RADIUS_EPSILON) * (radius+RADIUS_EPSILON); @@ -816,7 +819,7 @@ the cylinder extends halfheight above and below the origin */ void CM_TraceThroughVerticalCylinder( traceWork_t *tw, vec3_t origin, float radius, float halfheight, vec3_t start, vec3_t end) { float length, scale, fraction, l1, l2; - float a, b, c, d, sqrtd; + float b, c, d, sqrtd; vec3_t v1, dir, start2d, end2d, org2d, intersection; // 2d coordinates @@ -862,7 +865,7 @@ void CM_TraceThroughVerticalCylinder( traceWork_t *tw, vec3_t origin, float radi // VectorSubtract(start, origin, v1); // dir is normalized so we can use a = 1 - a = 1.0f;// * (dir[0] * dir[0] + dir[1] * dir[1]); + //a = 1.0f;// * (dir[0] * dir[0] + dir[1] * dir[1]); b = 2.0f * (v1[0] * dir[0] + v1[1] * dir[1]); c = v1[0] * v1[0] + v1[1] * v1[1] - (radius+RADIUS_EPSILON) * (radius+RADIUS_EPSILON); diff --git a/tools/mbspc/qcommon/md4.c b/tools/mbspc/qcommon/md4.c index 03fbcc2b..888de388 100644 --- a/tools/mbspc/qcommon/md4.c +++ b/tools/mbspc/qcommon/md4.c @@ -1,299 +1,260 @@ -/* GLOBAL.H - RSAREF types and constants */ +/* + mdfour.c -#include -#if defined(_WIN32) -#pragma warning(disable : 4711) // selected for automatic inline expansion -#endif + An implementation of MD4 designed for use in the samba SMB + authentication protocol -/* POINTER defines a generic pointer type */ -typedef unsigned char *POINTER; + Copyright (C) 1997-1998 Andrew Tridgell -/* UINT2 defines a two byte word */ -typedef unsigned short int UINT2; + 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. -/* UINT4 defines a four byte word */ -typedef unsigned long int UINT4; + 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. - -/* MD4.H - header file for MD4C.C */ + See the GNU General Public License for more details. -/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. + You should have received a copy of the GNU General Public License + along with this program; if not, write to: -All rights reserved. - -License to copy and use this software is granted provided that it is identified as the “RSA Data Security, Inc. MD4 Message-Digest Algorithm” in all material mentioning or referencing this software or this function. -License is also granted to make and use derivative works provided that such works are identified as “derived from the RSA Data Security, Inc. MD4 Message-Digest Algorithm” in all material mentioning or referencing the derived work. -RSA Data Security, Inc. makes no representations concerning either the merchantability of this software or the suitability of this software for any particular purpose. It is provided “as is” without express or implied warranty of any kind. - -These notices must be retained in any copies of any part of this documentation and/or software. */ + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA -/* MD4 context. */ -typedef struct { - UINT4 state[4]; /* state (ABCD) */ - UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ - unsigned char buffer[64]; /* input buffer */ -} MD4_CTX; + $Id: mdfour.c,v 1.1 2002/08/23 22:03:27 abster Exp $ +*/ -void MD4Init (MD4_CTX *); -void MD4Update (MD4_CTX *, const unsigned char *, unsigned int); -void MD4Final (unsigned char [16], MD4_CTX *); +#include "q_shared.h" +#include "qcommon.h" -#ifndef __VECTORC -void Com_Memset (void* dest, const int val, const size_t count); -void Com_Memcpy (void* dest, const void* src, const size_t count); -#else -#define Com_Memset memset -#define Com_Memcpy memcpy -#endif - -/* MD4C.C - RSA Data Security, Inc., MD4 message-digest algorithm */ -/* Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved. - -License to copy and use this software is granted provided that it is identified as the -RSA Data Security, Inc. MD4 Message-Digest Algorithm - in all material mentioning or referencing this software or this function. -License is also granted to make and use derivative works provided that such works are identified as -derived from the RSA Data Security, Inc. MD4 Message-Digest Algorithm -in all material mentioning or referencing the derived work. -RSA Data Security, Inc. makes no representations concerning either the merchantability of this software or the suitability of this software for any particular purpose. It is provided -as is without express or implied warranty of any kind. - -These notices must be retained in any copies of any part of this documentation and/or software. */ - -/* Constants for MD4Transform routine. */ -#define S11 3 -#define S12 7 -#define S13 11 -#define S14 19 -#define S21 3 -#define S22 5 -#define S23 9 -#define S24 13 -#define S31 3 -#define S32 9 -#define S33 11 -#define S34 15 - -static void MD4Transform (UINT4 [4], const unsigned char [64]); -static void Encode (unsigned char *, UINT4 *, unsigned int); -static void Decode (UINT4 *, const unsigned char *, unsigned int); - -static unsigned char PADDING[64] = { -0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +struct mdfour +{ + uint32_t A, B, C, D; + uint32_t totalN; }; -/* F, G and H are basic MD4 functions. */ -#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) -#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z))) -#define H(x, y, z) ((x) ^ (y) ^ (z)) -/* ROTATE_LEFT rotates x left n bits. */ -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) +/* NOTE: This code makes no attempt to be fast! -/* FF, GG and HH are transformations for rounds 1, 2 and 3 */ -/* Rotation is separate from addition to prevent recomputation */ -#define FF(a, b, c, d, x, s) {(a) += F ((b), (c), (d)) + (x); (a) = ROTATE_LEFT ((a), (s));} + It assumes that a int is at least 32 bits long +*/ -#define GG(a, b, c, d, x, s) {(a) += G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; (a) = ROTATE_LEFT ((a), (s));} +static struct mdfour *m; -#define HH(a, b, c, d, x, s) {(a) += H ((b), (c), (d)) + (x) + (UINT4)0x6ed9eba1; (a) = ROTATE_LEFT ((a), (s));} +#define F(X,Y,Z) (((X)&(Y)) | ((~(X))&(Z))) +#define G(X,Y,Z) (((X)&(Y)) | ((X)&(Z)) | ((Y)&(Z))) +#define H(X,Y,Z) ((X)^(Y)^(Z)) +#define lshift(x,s) (((x)<<(s)) | ((x)>>(32-(s)))) +#define ROUND1(a,b,c,d,k,s) a = lshift(a + F(b,c,d) + X[k], s) +#define ROUND2(a,b,c,d,k,s) a = lshift(a + G(b,c,d) + X[k] + 0x5A827999,s) +#define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + 0x6ED9EBA1,s) -/* MD4 initialization. Begins an MD4 operation, writing a new context. */ -void MD4Init (MD4_CTX *context) +/* this applies md4 to 64 byte chunks */ +static void +mdfour64(uint32_t * M) { - context->count[0] = context->count[1] = 0; + int j; + uint32_t AA, BB, CC, DD; + uint32_t X[16]; + uint32_t A, B, C, D; -/* Load magic initialization constants.*/ -context->state[0] = 0x67452301; -context->state[1] = 0xefcdab89; -context->state[2] = 0x98badcfe; -context->state[3] = 0x10325476; + for (j = 0; j < 16; j++) + X[j] = M[j]; + + A = m->A; + B = m->B; + C = m->C; + D = m->D; + AA = A; + BB = B; + CC = C; + DD = D; + + ROUND1(A, B, C, D, 0, 3); + ROUND1(D, A, B, C, 1, 7); + ROUND1(C, D, A, B, 2, 11); + ROUND1(B, C, D, A, 3, 19); + ROUND1(A, B, C, D, 4, 3); + ROUND1(D, A, B, C, 5, 7); + ROUND1(C, D, A, B, 6, 11); + ROUND1(B, C, D, A, 7, 19); + ROUND1(A, B, C, D, 8, 3); + ROUND1(D, A, B, C, 9, 7); + ROUND1(C, D, A, B, 10, 11); + ROUND1(B, C, D, A, 11, 19); + ROUND1(A, B, C, D, 12, 3); + ROUND1(D, A, B, C, 13, 7); + ROUND1(C, D, A, B, 14, 11); + ROUND1(B, C, D, A, 15, 19); + + ROUND2(A, B, C, D, 0, 3); + ROUND2(D, A, B, C, 4, 5); + ROUND2(C, D, A, B, 8, 9); + ROUND2(B, C, D, A, 12, 13); + ROUND2(A, B, C, D, 1, 3); + ROUND2(D, A, B, C, 5, 5); + ROUND2(C, D, A, B, 9, 9); + ROUND2(B, C, D, A, 13, 13); + ROUND2(A, B, C, D, 2, 3); + ROUND2(D, A, B, C, 6, 5); + ROUND2(C, D, A, B, 10, 9); + ROUND2(B, C, D, A, 14, 13); + ROUND2(A, B, C, D, 3, 3); + ROUND2(D, A, B, C, 7, 5); + ROUND2(C, D, A, B, 11, 9); + ROUND2(B, C, D, A, 15, 13); + + ROUND3(A, B, C, D, 0, 3); + ROUND3(D, A, B, C, 8, 9); + ROUND3(C, D, A, B, 4, 11); + ROUND3(B, C, D, A, 12, 15); + ROUND3(A, B, C, D, 2, 3); + ROUND3(D, A, B, C, 10, 9); + ROUND3(C, D, A, B, 6, 11); + ROUND3(B, C, D, A, 14, 15); + ROUND3(A, B, C, D, 1, 3); + ROUND3(D, A, B, C, 9, 9); + ROUND3(C, D, A, B, 5, 11); + ROUND3(B, C, D, A, 13, 15); + ROUND3(A, B, C, D, 3, 3); + ROUND3(D, A, B, C, 11, 9); + ROUND3(C, D, A, B, 7, 11); + ROUND3(B, C, D, A, 15, 15); + + A += AA; + B += BB; + C += CC; + D += DD; + + for (j = 0; j < 16; j++) + X[j] = 0; + + m->A = A; + m->B = B; + m->C = C; + m->D = D; } -/* MD4 block update operation. Continues an MD4 message-digest operation, processing another message block, and updating the context. */ -void MD4Update (MD4_CTX *context, const unsigned char *input, unsigned int inputLen) +static void +copy64(uint32_t * M, byte * in) { - unsigned int i, index, partLen; + int i; - /* Compute number of bytes mod 64 */ - index = (unsigned int)((context->count[0] >> 3) & 0x3F); + for (i = 0; i < 16; i++) + M[i] = (in[i * 4 + 3] << 24) | (in[i * 4 + 2] << 16) | + (in[i * 4 + 1] << 8) | (in[i * 4 + 0] << 0); +} - /* Update number of bits */ - if ((context->count[0] += ((UINT4)inputLen << 3))< ((UINT4)inputLen << 3)) - context->count[1]++; +static void +copy4(byte * out, uint32_t x) +{ + out[0] = x & 0xFF; + out[1] = (x >> 8) & 0xFF; + out[2] = (x >> 16) & 0xFF; + out[3] = (x >> 24) & 0xFF; +} - context->count[1] += ((UINT4)inputLen >> 29); - - partLen = 64 - index; - - /* Transform as many times as possible.*/ - if (inputLen >= partLen) - { - Com_Memcpy((POINTER)&context->buffer[index], (POINTER)input, partLen); - MD4Transform (context->state, context->buffer); - - for (i = partLen; i + 63 < inputLen; i += 64) - MD4Transform (context->state, &input[i]); - - index = 0; - } - else - i = 0; - - /* Buffer remaining input */ - Com_Memcpy ((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen-i); +void +mdfour_begin(struct mdfour *md) +{ + md->A = 0x67452301; + md->B = 0xefcdab89; + md->C = 0x98badcfe; + md->D = 0x10325476; + md->totalN = 0; } -/* MD4 finalization. Ends an MD4 message-digest operation, writing the the message digest and zeroizing the context. */ -void MD4Final (unsigned char digest[16], MD4_CTX *context) +static void +mdfour_tail(byte * in, int n) { - unsigned char bits[8]; - unsigned int index, padLen; + byte buf[128]; + uint32_t M[16]; + uint32_t b; - /* Save number of bits */ - Encode (bits, context->count, 8); + m->totalN += n; - /* Pad out to 56 mod 64.*/ - index = (unsigned int)((context->count[0] >> 3) & 0x3f); - padLen = (index < 56) ? (56 - index) : (120 - index); - MD4Update (context, PADDING, padLen); + b = m->totalN * 8; - /* Append length (before padding) */ - MD4Update (context, bits, 8); - - /* Store state in digest */ - Encode (digest, context->state, 16); + Com_Memset(buf, 0, 128); + if (n) + Com_Memcpy(buf, in, n); + buf[n] = 0x80; - /* Zeroize sensitive information.*/ - Com_Memset ((POINTER)context, 0, sizeof (*context)); + if (n <= 55) + { + copy4(buf + 56, b); + copy64(M, buf); + mdfour64(M); + } + else + { + copy4(buf + 120, b); + copy64(M, buf); + mdfour64(M); + copy64(M, buf + 64); + mdfour64(M); + } +} + +static void +mdfour_update(struct mdfour *md, byte * in, int n) +{ + uint32_t M[16]; + + m = md; + + if (n == 0) + mdfour_tail(in, n); + + while (n >= 64) + { + copy64(M, in); + mdfour64(M); + in += 64; + n -= 64; + m->totalN += 64; + } + + mdfour_tail(in, n); } -/* MD4 basic transformation. Transforms state based on block. */ -static void MD4Transform (UINT4 state[4], const unsigned char block[64]) +static void +mdfour_result(struct mdfour *md, byte * out) { - UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; + m = md; - Decode (x, block, 64); - -/* Round 1 */ -FF (a, b, c, d, x[ 0], S11); /* 1 */ -FF (d, a, b, c, x[ 1], S12); /* 2 */ -FF (c, d, a, b, x[ 2], S13); /* 3 */ -FF (b, c, d, a, x[ 3], S14); /* 4 */ -FF (a, b, c, d, x[ 4], S11); /* 5 */ -FF (d, a, b, c, x[ 5], S12); /* 6 */ -FF (c, d, a, b, x[ 6], S13); /* 7 */ -FF (b, c, d, a, x[ 7], S14); /* 8 */ -FF (a, b, c, d, x[ 8], S11); /* 9 */ -FF (d, a, b, c, x[ 9], S12); /* 10 */ -FF (c, d, a, b, x[10], S13); /* 11 */ -FF (b, c, d, a, x[11], S14); /* 12 */ -FF (a, b, c, d, x[12], S11); /* 13 */ -FF (d, a, b, c, x[13], S12); /* 14 */ -FF (c, d, a, b, x[14], S13); /* 15 */ -FF (b, c, d, a, x[15], S14); /* 16 */ - -/* Round 2 */ -GG (a, b, c, d, x[ 0], S21); /* 17 */ -GG (d, a, b, c, x[ 4], S22); /* 18 */ -GG (c, d, a, b, x[ 8], S23); /* 19 */ -GG (b, c, d, a, x[12], S24); /* 20 */ -GG (a, b, c, d, x[ 1], S21); /* 21 */ -GG (d, a, b, c, x[ 5], S22); /* 22 */ -GG (c, d, a, b, x[ 9], S23); /* 23 */ -GG (b, c, d, a, x[13], S24); /* 24 */ -GG (a, b, c, d, x[ 2], S21); /* 25 */ -GG (d, a, b, c, x[ 6], S22); /* 26 */ -GG (c, d, a, b, x[10], S23); /* 27 */ -GG (b, c, d, a, x[14], S24); /* 28 */ -GG (a, b, c, d, x[ 3], S21); /* 29 */ -GG (d, a, b, c, x[ 7], S22); /* 30 */ -GG (c, d, a, b, x[11], S23); /* 31 */ -GG (b, c, d, a, x[15], S24); /* 32 */ - -/* Round 3 */ -HH (a, b, c, d, x[ 0], S31); /* 33 */ -HH (d, a, b, c, x[ 8], S32); /* 34 */ -HH (c, d, a, b, x[ 4], S33); /* 35 */ -HH (b, c, d, a, x[12], S34); /* 36 */ -HH (a, b, c, d, x[ 2], S31); /* 37 */ -HH (d, a, b, c, x[10], S32); /* 38 */ -HH (c, d, a, b, x[ 6], S33); /* 39 */ -HH (b, c, d, a, x[14], S34); /* 40 */ -HH (a, b, c, d, x[ 1], S31); /* 41 */ -HH (d, a, b, c, x[ 9], S32); /* 42 */ -HH (c, d, a, b, x[ 5], S33); /* 43 */ -HH (b, c, d, a, x[13], S34); /* 44 */ -HH (a, b, c, d, x[ 3], S31); /* 45 */ -HH (d, a, b, c, x[11], S32); /* 46 */ -HH (c, d, a, b, x[ 7], S33); /* 47 */ -HH (b, c, d, a, x[15], S34); /* 48 */ - -state[0] += a; -state[1] += b; -state[2] += c; -state[3] += d; - - /* Zeroize sensitive information.*/ - Com_Memset ((POINTER)x, 0, sizeof (x)); + copy4(out, m->A); + copy4(out + 4, m->B); + copy4(out + 8, m->C); + copy4(out + 12, m->D); } - -/* Encodes input (UINT4) into output (unsigned char). Assumes len is a multiple of 4. */ -static void Encode (unsigned char *output, UINT4 *input, unsigned int len) +static void +mdfour(byte * out, byte * in, int n) { - unsigned int i, j; - - for (i = 0, j = 0; j < len; i++, j += 4) { - output[j] = (unsigned char)(input[i] & 0xff); - output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); - output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); - output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); - } -} - - -/* Decodes input (unsigned char) into output (UINT4). Assumes len is a multiple of 4. */ -static void Decode (UINT4 *output, const unsigned char *input, unsigned int len) -{ -unsigned int i, j; - -for (i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); + struct mdfour md; + mdfour_begin(&md); + mdfour_update(&md, in, n); + mdfour_result(&md, out); } //=================================================================== -unsigned Com_BlockChecksum (void *buffer, int length) +unsigned +Com_BlockChecksum(const void *buffer, int length) { - int digest[4]; - unsigned val; - MD4_CTX ctx; + int digest[4]; + unsigned val; - MD4Init (&ctx); - MD4Update (&ctx, (unsigned char *)buffer, length); - MD4Final ( (unsigned char *)digest, &ctx); - - val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3]; + mdfour((byte *) digest, (byte *) buffer, length); - return val; -} - -unsigned Com_BlockChecksumKey (void *buffer, int length, int key) -{ - int digest[4]; - unsigned val; - MD4_CTX ctx; - - MD4Init (&ctx); - MD4Update (&ctx, (unsigned char *)&key, 4); - MD4Update (&ctx, (unsigned char *)buffer, length); - MD4Final ( (unsigned char *)digest, &ctx); - - val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3]; - - return val; + val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3]; + + return val; } diff --git a/tools/mbspc/qcommon/q_platform.h b/tools/mbspc/qcommon/q_platform.h new file mode 100644 index 00000000..88573f2e --- /dev/null +++ b/tools/mbspc/qcommon/q_platform.h @@ -0,0 +1,341 @@ +/* +=========================================================================== +Copyright (C) 1999-2005 Id Software, Inc. + +This file is part of Quake III Arena source code. + +Quake III Arena source code 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. + +Quake III Arena source code 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 Quake III Arena source code; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +=========================================================================== +*/ + +#ifndef __Q_PLATFORM_H +#define __Q_PLATFORM_H + +// this is for determining if we have an asm version of a C function +#ifdef Q3_VM + +#define id386 0 +#define idppc 0 +#define idppc_altivec 0 +#define idsparc 0 + +#else + +#if (defined _M_IX86 || defined __i386__) && !defined(C_ONLY) +#define id386 1 +#else +#define id386 0 +#endif + +#if (defined(powerc) || defined(powerpc) || defined(ppc) || \ + defined(__ppc) || defined(__ppc__)) && !defined(C_ONLY) +#define idppc 1 +#if defined(__VEC__) +#define idppc_altivec 1 +#ifdef MACOS_X // Apple's GCC does this differently than the FSF. +#define VECCONST_UINT8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ + (vector unsigned char) (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) +#else +#define VECCONST_UINT8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ + (vector unsigned char) {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p} +#endif +#else +#define idppc_altivec 0 +#endif +#else +#define idppc 0 +#define idppc_altivec 0 +#endif + +#if defined(__sparc__) && !defined(C_ONLY) +#define idsparc 1 +#else +#define idsparc 0 +#endif + +#endif + +#ifndef __ASM_I386__ // don't include the C bits if included from qasm.h + +// for windows fastcall option +#define QDECL + +//================================================================= WIN32 === + +#ifdef _WIN32 + +#undef QDECL +#define QDECL __cdecl + +#define OS_STRING "win32" + +#define ID_INLINE __inline +#define PATH_SEP '\\' + +#if defined( _M_IX86 ) || defined( __i386__ ) +#define ARCH_STRING "x86" +#elif defined _M_ALPHA +#define ARCH_STRING "AXP" +#endif + +#define Q3_LITTLE_ENDIAN + +#define DLL_EXT ".dll" + +#endif + +//============================================================== MAC OS X === + +#if defined(MACOS_X) || defined(__APPLE_CC__) + +// make sure this is defined, just for sanity's sake... +#ifndef MACOS_X +#define MACOS_X +#endif + +#define OS_STRING "macosx" +#define ID_INLINE inline +#define PATH_SEP '/' + +#ifdef __ppc__ +#define ARCH_STRING "ppc" +#define Q3_BIG_ENDIAN +#elif defined __i386__ +#define ARCH_STRING "i386" +#define Q3_LITTLE_ENDIAN +#endif + +#define DLL_EXT ".dylib" + +#endif + +//================================================================= LINUX === + +#ifdef __linux__ + +#include + +#define OS_STRING "linux" +#define ID_INLINE inline +#define PATH_SEP '/' + +#if defined __i386__ +#define ARCH_STRING "i386" +#elif defined __x86_64__ +#define ARCH_STRING "x86_64" +#elif defined __powerpc64__ +#define ARCH_STRING "ppc64" +#elif defined __powerpc__ +#define ARCH_STRING "ppc" +#elif defined __s390__ +#define ARCH_STRING "s390" +#elif defined __s390x__ +#define ARCH_STRING "s390x" +#elif defined __ia64__ +#define ARCH_STRING "ia64" +#elif defined __alpha__ +#define ARCH_STRING "alpha" +#elif defined __sparc__ +#define ARCH_STRING "sparc" +#elif defined __arm__ +#define ARCH_STRING "arm" +#elif defined __cris__ +#define ARCH_STRING "cris" +#elif defined __hppa__ +#define ARCH_STRING "hppa" +#elif defined __mips__ +#define ARCH_STRING "mips" +#elif defined __sh__ +#define ARCH_STRING "sh" +#endif + +#if __FLOAT_WORD_ORDER == __BIG_ENDIAN +#define Q3_BIG_ENDIAN +#else +#define Q3_LITTLE_ENDIAN +#endif + +#define DLL_EXT ".so" + +#endif + +//=================================================================== BSD === + +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) + +#include +#include + +#ifndef __BSD__ +#define __BSD__ +#endif + +#if defined(__FreeBSD__) +#define OS_STRING "freebsd" +#elif defined(__OpenBSD__) +#define OS_STRING "openbsd" +#elif defined(__NetBSD__) +#define OS_STRING "netbsd" +#endif + +#define ID_INLINE inline +#define PATH_SEP '/' + +#ifdef __i386__ +#define ARCH_STRING "i386" +#elif defined __axp__ +#define ARCH_STRING "alpha" +#endif + +#if BYTE_ORDER == BIG_ENDIAN +#define Q3_BIG_ENDIAN +#else +#define Q3_LITTLE_ENDIAN +#endif + +#define DLL_EXT ".so" + +#endif + +//================================================================= SUNOS === + +#ifdef __sun + +#include +#include + +#define OS_STRING "solaris" +#define ID_INLINE inline +#define PATH_SEP '/' + +#ifdef __i386__ +#define ARCH_STRING "i386" +#elif defined __sparc +#define ARCH_STRING "sparc" +#endif + +#if defined( _BIG_ENDIAN ) +#define Q3_BIG_ENDIAN +#elif defined( _LITTLE_ENDIAN ) +#define Q3_LITTLE_ENDIAN +#endif + +#define DLL_EXT ".so" + +#endif + +//================================================================== IRIX === + +#ifdef __sgi + +#define OS_STRING "irix" +#define ID_INLINE __inline +#define PATH_SEP '/' + +#define ARCH_STRING "mips" + +#define Q3_BIG_ENDIAN // SGI's MIPS are always big endian + +#define DLL_EXT ".so" + +#endif + +//================================================================== Q3VM === + +#ifdef Q3_VM + +#define OS_STRING "q3vm" +#define ID_INLINE +#define PATH_SEP '/' + +#define ARCH_STRING "bytecode" + +#define DLL_EXT ".qvm" + +#endif + +//=========================================================================== + +//catch missing defines in above blocks +#if !defined( OS_STRING ) +#error "Operating system not supported" +#endif + +#if !defined( ARCH_STRING ) +#error "Architecture not supported" +#endif + +#ifndef ID_INLINE +#error "ID_INLINE not defined" +#endif + +#ifndef PATH_SEP +#error "PATH_SEP not defined" +#endif + +#ifndef DLL_EXT +#error "DLL_EXT not defined" +#endif + + +//endianness +short ShortSwap(short l); +int LongSwap(int l); +float FloatSwap(const float *f); + +#if defined( Q3_BIG_ENDIAN ) && defined( Q3_LITTLE_ENDIAN ) +#error "Endianness defined as both big and little" +#elif defined( Q3_BIG_ENDIAN ) + +#define LittleShort(x) ShortSwap(x) +#define LittleLong(x) LongSwap(x) +#define LittleFloat(x) FloatSwap(&x) +#define BigShort +#define BigLong +#define BigFloat + +#elif defined( Q3_LITTLE_ENDIAN ) + +#define LittleShort +#define LittleLong +#define LittleFloat +#define BigShort(x) ShortSwap(x) +#define BigLong(x) LongSwap(x) +#define BigFloat(x) FloatSwap(&x) + +#elif defined( Q3_VM ) + +#define LittleShort +#define LittleLong +#define LittleFloat +#define BigShort +#define BigLong +#define BigFloat + +#else +#error "Endianness not defined" +#endif + + +//platform string +#ifdef NDEBUG +#define PLATFORM_STRING OS_STRING "-" ARCH_STRING +#else +#define PLATFORM_STRING OS_STRING "-" ARCH_STRING "-debug" +#endif + +#endif + +#endif diff --git a/tools/mbspc/qcommon/q_shared.h b/tools/mbspc/qcommon/q_shared.h index 1cae4b23..e931a9ee 100644 --- a/tools/mbspc/qcommon/q_shared.h +++ b/tools/mbspc/qcommon/q_shared.h @@ -15,7 +15,7 @@ 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 Foobar; if not, write to the Free Software +along with Quake III Arena source code; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =========================================================================== */ @@ -26,34 +26,30 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // q_shared.h -- included first by ALL program modules. // A user mod should never modify this file -#define Q3_VERSION "Q3 1.32b" -// 1.32 released 7-10-2002 +// _ML_ modified - name & base folder +#define PRODUCT_NAME "q3min" +#define BASEGAME "baseqm" +#define CLIENT_WINDOW_TITLE "q3min" +#define CLIENT_WINDOW_MIN_TITLE "q3min" +#define GAMENAME_FOR_MASTER "q3min" +// _ML_ modified end + +// _ML_ removed +// #define Q3_VERSION PRODUCT_NAME " " PRODUCT_VERSION +// _ML_ removed end + +// _ML_ added - pak1_pure_fix +#define PAK1_CHECKSUM 89231589 +#define PAK1_PURE_CHECKSUM 87456416 +// _ML_ added end #define MAX_TEAMNAME 32 -#ifdef _WIN32 - -#pragma warning(disable : 4018) // signed/unsigned mismatch -#pragma warning(disable : 4032) -#pragma warning(disable : 4051) -#pragma warning(disable : 4057) // slightly different base types -#pragma warning(disable : 4100) // unreferenced formal parameter -#pragma warning(disable : 4115) -#pragma warning(disable : 4125) // decimal digit terminates octal escape sequence -#pragma warning(disable : 4127) // conditional expression is constant -#pragma warning(disable : 4136) -#pragma warning(disable : 4152) // nonstandard extension, function/data pointer conversion in expression -//#pragma warning(disable : 4201) -//#pragma warning(disable : 4214) -#pragma warning(disable : 4244) -#pragma warning(disable : 4142) // benign redefinition -//#pragma warning(disable : 4305) // truncation from const double to float -//#pragma warning(disable : 4310) // cast truncates constant value -//#pragma warning(disable: 4505) // unreferenced local function has been removed -#pragma warning(disable : 4514) -#pragma warning(disable : 4702) // unreachable code -#pragma warning(disable : 4711) // selected for automatic inline expansion -#pragma warning(disable : 4220) // varargs matches remaining parameters +//Ignore __attribute__ on non-gcc platforms +#ifndef __GNUC__ +#ifndef __attribute__ +#define __attribute__(x) +#endif #endif /********************************************************************** @@ -74,7 +70,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #ifdef Q3_VM -#include "bg_lib.h" +#include "../game/bg_lib.h" + +typedef int intptr_t; #else @@ -88,241 +86,25 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include -#endif - +// vsnprintf is ISO/IEC 9899:1999 +// abstracting this to make it portable #ifdef _WIN32 - -//#pragma intrinsic( memset, memcpy ) - -#endif - - -// this is the define for determining if we have an asm version of a C function -#if (defined _M_IX86 || defined __i386__) && !defined __sun__ && !defined __LCC__ -#define id386 1 +#define Q_vsnprintf _vsnprintf +#define Q_snprintf _snprintf #else -#define id386 0 +#define Q_vsnprintf vsnprintf +#define Q_snprintf snprintf #endif -#if (defined(powerc) || defined(powerpc) || defined(ppc) || defined(__ppc) || defined(__ppc__)) && !defined(C_ONLY) -#define idppc 1 -#if defined(__VEC__) -#define idppc_altivec 1 -#else -#define idppc_altivec 0 -#endif -#else -#define idppc 0 -#define idppc_altivec 0 -#endif - -// for windows fastcall option - -#define QDECL - -short ShortSwap (short l); -int LongSwap (int l); -float FloatSwap (const float *f); - -//======================= WIN32 DEFINES ================================= - -#ifdef WIN32 - -#define MAC_STATIC - -#undef QDECL -#define QDECL __cdecl - -// buildstring will be incorporated into the version string -#ifdef NDEBUG -#ifdef _M_IX86 -#define CPUSTRING "win-x86" -#elif defined _M_ALPHA -#define CPUSTRING "win-AXP" -#endif -#else -#ifdef _M_IX86 -#define CPUSTRING "win-x86-debug" -#elif defined _M_ALPHA -#define CPUSTRING "win-AXP-debug" -#endif -#endif - -#define ID_INLINE __inline - -static ID_INLINE short BigShort( short l) { return ShortSwap(l); } -#define LittleShort -static ID_INLINE int BigLong(int l) { LongSwap(l); } -#define LittleLong -static ID_INLINE float BigFloat(const float *l) { FloatSwap(l); } -#define LittleFloat - -#define PATH_SEP '\\' +#include #endif -//======================= MAC OS X DEFINES ===================== -#if defined(MACOS_X) +#include "q_platform.h" -#define MAC_STATIC -#define __cdecl -#define __declspec(x) -#define stricmp strcasecmp -#define ID_INLINE inline -#ifdef __ppc__ -#define CPUSTRING "MacOSX-ppc" -#elif defined __i386__ -#define CPUSTRING "MacOSX-i386" -#else -#define CPUSTRING "MacOSX-other" -#endif -#define PATH_SEP '/' - -#define __rlwimi(out, in, shift, maskBegin, maskEnd) asm("rlwimi %0,%1,%2,%3,%4" : "=r" (out) : "r" (in), "i" (shift), "i" (maskBegin), "i" (maskEnd)) -#define __dcbt(addr, offset) asm("dcbt %0,%1" : : "b" (addr), "r" (offset)) - -static inline unsigned int __lwbrx(register void *addr, register int offset) { - register unsigned int word; - - asm("lwbrx %0,%2,%1" : "=r" (word) : "r" (addr), "b" (offset)); - return word; -} - -static inline unsigned short __lhbrx(register void *addr, register int offset) { - register unsigned short halfword; - - asm("lhbrx %0,%2,%1" : "=r" (halfword) : "r" (addr), "b" (offset)); - return halfword; -} - -static inline float __fctiw(register float f) { - register float fi; - - asm("fctiw %0,%1" : "=f" (fi) : "f" (f)); - - return fi; -} - -#define BigShort -static inline short LittleShort(short l) { return ShortSwap(l); } -#define BigLong -static inline int LittleLong (int l) { return LongSwap(l); } -#define BigFloat -static inline float LittleFloat (const float l) { return FloatSwap(&l); } - -#endif - -//======================= MAC DEFINES ================================= - -#ifdef __MACOS__ - -#include -#define MAC_STATIC -#define ID_INLINE inline - -#define CPUSTRING "MacOS-PPC" - -#define PATH_SEP ':' - -void Sys_PumpEvents( void ); - -#define BigShort -static inline short LittleShort(short l) { return ShortSwap(l); } -#define BigLong -static inline int LittleLong (int l) { return LongSwap(l); } -#define BigFloat -static inline float LittleFloat (const float l) { return FloatSwap(&l); } - -#endif - -//======================= LINUX DEFINES ================================= - -// the mac compiler can't handle >32k of locals, so we -// just waste space and make big arrays static... -#ifdef __linux__ - -// bk001205 - from Makefile -#define stricmp strcasecmp - -#define MAC_STATIC // bk: FIXME -#define ID_INLINE inline - -#ifdef __i386__ -#define CPUSTRING "linux-i386" -#elif defined __axp__ -#define CPUSTRING "linux-alpha" -#else -#define CPUSTRING "linux-other" -#endif - -#define PATH_SEP '/' - -// bk001205 - try -#ifdef Q3_STATIC -#define GAME_HARD_LINKED -#define CGAME_HARD_LINKED -#define UI_HARD_LINKED -#define BOTLIB_HARD_LINKED -#endif - -#if !idppc -inline static short BigShort( short l) { return ShortSwap(l); } -#define LittleShort -inline static int BigLong(int l) { return LongSwap(l); } -#define LittleLong -inline static float BigFloat(const float *l) { return FloatSwap(l); } -#define LittleFloat -#else -#define BigShort -inline static short LittleShort(short l) { return ShortSwap(l); } -#define BigLong -inline static int LittleLong (int l) { return LongSwap(l); } -#define BigFloat -inline static float LittleFloat (const float *l) { return FloatSwap(l); } -#endif - -#endif - -//======================= FreeBSD DEFINES ===================== -#ifdef __FreeBSD__ // rb010123 - -#define stricmp strcasecmp - -#define MAC_STATIC -#define ID_INLINE inline - -#ifdef __i386__ -#define CPUSTRING "freebsd-i386" -#elif defined __axp__ -#define CPUSTRING "freebsd-alpha" -#else -#define CPUSTRING "freebsd-other" -#endif - -#define PATH_SEP '/' - -// bk010116 - omitted Q3STATIC (see Linux above), broken target - -#if !idppc -static short BigShort( short l) { return ShortSwap(l); } -#define LittleShort -static int BigLong(int l) { LongSwap(l); } -#define LittleLong -static float BigFloat(const float *l) { FloatSwap(l); } -#define LittleFloat -#else -#define BigShort -static short LittleShort(short l) { return ShortSwap(l); } -#define BigLong -static int LittleLong (int l) { return LongSwap(l); } -#define BigFloat -static float LittleFloat (const float *l) { return FloatSwap(l); } -#endif - -#endif //============================================================= @@ -330,15 +112,32 @@ typedef unsigned char byte; typedef enum {qfalse, qtrue} qboolean; -typedef int qhandle_t; -typedef int sfxHandle_t; -typedef int fileHandle_t; -typedef int clipHandle_t; +typedef union +{ + float f; + int i; + unsigned int ui; +} floatint_t; +typedef int qhandle_t; +typedef int sfxHandle_t; +typedef int fileHandle_t; +typedef int clipHandle_t; + +#define PAD(x,y) (((x)+(y)-1) & ~((y)-1)) + +#ifdef __GNUC__ +#define ALIGN(x) __attribute__((aligned(x))) +#else +#define ALIGN(x) +#endif #ifndef NULL #define NULL ((void *)0) #endif +#define STRING(s) #s +// expand constants before stringifying them +#define XSTRING(s) STRING(s) #define MAX_QINT 0x7fffffff #define MIN_QINT (-MAX_QINT-1) @@ -452,21 +251,8 @@ void *Hunk_AllocDebug( int size, ha_pref preference, char *label, char *file, in void *Hunk_Alloc( int size, ha_pref preference ); #endif -#ifdef __linux__ -// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=371 -// custom Snd_Memset implementation for glibc memset bug workaround -void Snd_Memset (void* dest, const int val, const size_t count); -#else -#define Snd_Memset Com_Memset -#endif - -#if !( defined __VECTORC ) -void Com_Memset (void* dest, const int val, const size_t count); -void Com_Memcpy (void* dest, const void* src, const size_t count); -#else #define Com_Memset memset #define Com_Memcpy memcpy -#endif #define CIN_system 1 #define CIN_loop 2 @@ -530,7 +316,7 @@ extern vec4_t colorMdGrey; extern vec4_t colorDkGrey; #define Q_COLOR_ESCAPE '^' -#define Q_IsColorString(p) ( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && *((p)+1) != Q_COLOR_ESCAPE ) +#define Q_IsColorString(p) ( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && isalnum(*((p)+1)) ) // ^[0-9a-zA-Z] #define COLOR_BLACK '0' #define COLOR_RED '1' @@ -570,7 +356,7 @@ extern vec3_t axisDefault[3]; #if idppc -static inline float Q_rsqrt( float number ) { +static ID_INLINE float Q_rsqrt( float number ) { float x = 0.5f * number; float y; #ifdef __GNUC__ @@ -582,7 +368,7 @@ static inline float Q_rsqrt( float number ) { } #ifdef __GNUC__ -static inline float Q_fabs(float x) { +static ID_INLINE float Q_fabs(float x) { float abs_x; asm("fabs %0,%1" : "=f" (abs_x) : "f" (x)); @@ -614,6 +400,9 @@ void ByteToDir( int b, vec3_t dir ); #define VectorCopy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2]) #define VectorScale(v, s, o) ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s)) #define VectorMA(v, s, b, o) ((o)[0]=(v)[0]+(b)[0]*(s),(o)[1]=(v)[1]+(b)[1]*(s),(o)[2]=(v)[2]+(b)[2]*(s)) +// _ML__ added - alt_fire +#define VectorReset(v) ((v)[0] = (v)[1] = (v)[2] = 0.0) +// _ML_ added end #else @@ -626,7 +415,7 @@ void ByteToDir( int b, vec3_t dir ); #endif -#ifdef __LCC__ +#ifdef Q3_VM #ifdef VectorCopy #undef VectorCopy // this is a little hack to get more efficient copies in our interpreter @@ -634,7 +423,6 @@ typedef struct { float v[3]; } vec3struct_t; #define VectorCopy(a,b) (*(vec3struct_t *)b=*(vec3struct_t *)a) -#define ID_INLINE static #endif #endif @@ -661,7 +449,7 @@ float RadiusFromBounds( const vec3_t mins, const vec3_t maxs ); void ClearBounds( vec3_t mins, vec3_t maxs ); void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs ); -#ifndef __LCC__ +#if !defined( Q3_VM ) || ( defined( Q3_VM ) && defined( __Q3_VM_MATH ) ) static ID_INLINE int VectorCompare( const vec3_t v1, const vec3_t v2 ) { if (v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2]) { return 0; @@ -759,6 +547,13 @@ void AxisCopy( vec3_t in[3], vec3_t out[3] ); void SetPlaneSignbits( struct cplane_s *out ); int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct cplane_s *plane); +qboolean BoundsIntersect(const vec3_t mins, const vec3_t maxs, + const vec3_t mins2, const vec3_t maxs2); +qboolean BoundsIntersectSphere(const vec3_t mins, const vec3_t maxs, + const vec3_t origin, vec_t radius); +qboolean BoundsIntersectPoint(const vec3_t mins, const vec3_t maxs, + const vec3_t origin); + float AngleMod(float a); float LerpAngle (float from, float to, float frac); float AngleSubtract( float a1, float a2 ); @@ -780,6 +575,7 @@ void MakeNormalVectors( const vec3_t forward, vec3_t right, vec3_t up ); void MatrixMultiply(float in1[3][3], float in2[3][3], float out[3][3]); void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up); void PerpendicularVector( vec3_t dst, const vec3_t src ); +int Q_isnan(float x); //============================================= @@ -787,7 +583,8 @@ void PerpendicularVector( vec3_t dst, const vec3_t src ); float Com_Clamp( float min, float max, float value ); char *COM_SkipPath( char *pathname ); -void COM_StripExtension( const char *in, char *out ); +const char *COM_GetExtension(const char *name); +void COM_StripExtension(const char *in, char *out, int destsize); void COM_DefaultExtension( char *path, int maxSize, const char *extension ); void COM_BeginParseSession( const char *name ); @@ -795,8 +592,9 @@ int COM_GetCurrentParseLine( void ); char *COM_Parse( char **data_p ); char *COM_ParseExt( char **data_p, qboolean allowLineBreak ); int COM_Compress( char *data_p ); -void COM_ParseError( char *format, ... ); -void COM_ParseWarning( char *format, ... ); +void COM_ParseError(char *format, ...) __attribute__ ((format(printf, 1, 2))); +void COM_ParseWarning( char *format, ... ) + __attribute__ ((format(printf, 1, 2))); //int COM_ParseInfos( char *buf, int max, char infos[][MAX_INFO_STRING] ); #define MAX_TOKENLENGTH 1024 @@ -829,9 +627,14 @@ void SkipRestOfLine ( char **data ); void Parse1DMatrix (char **buf_p, int x, float *m); void Parse2DMatrix (char **buf_p, int y, int x, float *m); void Parse3DMatrix (char **buf_p, int z, int y, int x, float *m); +int Com_HexStrToInt(const char *str); -void QDECL Com_sprintf (char *dest, int size, const char *fmt, ...); +void QDECL Com_sprintf (char *dest, int size, const char *fmt, ...) + __attribute__ ((format(printf, 3, 4))); +char *Com_SkipTokens(char *s, int numTokens, char *sep); +char *Com_SkipCharset(char *s, char *sep); +void Com_RandomBytes(byte * string, int len); // mode parm for FS_FOpenFile typedef enum { @@ -853,6 +656,8 @@ int Q_isprint( int c ); int Q_islower( int c ); int Q_isupper( int c ); int Q_isalpha( int c ); +qboolean Q_isanumber(const char *s); +qboolean Q_isintegral(float f); // portable case insensitive compare int Q_stricmp (const char *s1, const char *s2); @@ -861,6 +666,7 @@ int Q_stricmpn (const char *s1, const char *s2, int n); char *Q_strlwr( char *s1 ); char *Q_strupr( char *s1 ); char *Q_strrchr( const char* string, int c ); +const char *Q_stristr(const char *s, const char *find); // buffer size safe library replacements void Q_strncpyz( char *dest, const char *src, int destsize ); @@ -870,6 +676,8 @@ void Q_strcat( char *dest, int size, const char *src ); int Q_PrintStrlen( const char *string ); // removes color sequences from string char *Q_CleanStr( char *string ); +// Count the number of char tocount encountered in string +int Q_CountChar(const char *string, char tocount); //============================================= @@ -900,7 +708,10 @@ float LittleFloat (const float *l); void Swap_Init (void); */ -char * QDECL va(char *format, ...); +char *QDECL va(char *format, ...) __attribute__ ((format(printf, 1, 2))); + +#define TRUNCATE_LENGTH 64 +void Com_TruncateLongString(char *buffer, const char *s); //============================================= @@ -916,8 +727,10 @@ qboolean Info_Validate( const char *s ); void Info_NextPair( const char **s, char *key, char *value ); // this is only here so the functions in q_shared.c and bg_*.c can link -void QDECL Com_Error( int level, const char *error, ... ); -void QDECL Com_Printf( const char *msg, ... ); +void QDECL Com_Error( int level, const char *error, ... ) + __attribute__ ((format(printf, 2, 3))); +void QDECL Com_Printf( const char *msg, ... ) + __attribute__ ((format(printf, 1, 2))); /* @@ -949,6 +762,8 @@ default values. #define CVAR_TEMP 256 // can be set even when cheats are disabled, but is not archived #define CVAR_CHEAT 512 // can not be changed if cheats are disabled #define CVAR_NORESTART 1024 // do not clear when a cvar_restart is issued +#define CVAR_SERVER_CREATED 2048 // cvar was created by a server the client connected to. +#define CVAR_NONEXISTENT 0xFFFFFFFF // Cvar doesn't exist. // nothing outside the Cvar_*() functions should modify these fields! typedef struct cvar_s { @@ -961,6 +776,10 @@ typedef struct cvar_s { int modificationCount; // incremented each time the cvar is changed float value; // atof( string ) int integer; // atoi( string ) + qboolean validate; + qboolean integral; + float min; + float max; struct cvar_s *next; struct cvar_s *hashNext; } cvar_t; @@ -1241,6 +1060,10 @@ typedef struct playerState_s { #define BUTTON_ANY 2048 // any key whatsoever +// _ML_ added - alt_fire +#define BUTTON_ATTACK_ALT 4096 // button12 +// _ML_ added end + #define MOVE_RUN 120 // if forwardmove or rightmove are >= MOVE_RUN, // then BUTTON_WALKING should be set @@ -1428,5 +1251,51 @@ typedef enum _flag_status { #define CDKEY_LEN 16 #define CDCHKSUM_LEN 2 +// _ML_ added - utility_functions +#define MAX_DIGIT_NUM 16 +#define MAX_EXP_VALUE (308 - MAX_DIGIT_NUM) +enum { BASE_BIN, BASE_DEC, BASE_HEX }; -#endif // __Q_SHARED_H +char *Com_GetToken(char *src, char *tok, int max); +char *Com_SkipString(char *buf, char *end); +char *Com_FindDelimiterString(char *delim, char *buf, char *end); +int Com_Atoi(char *s, int base, int *dest); +int Com_Atof(char *s, double *dest); +int Com_CircIncr(int val, int min, int max); +int Com_CircDecr(int val, int min, int max); +void Com_CircIncrDirect(int *val, int min, int max); +void Com_CircDecrDirect(int *val, int min, int max); +void Com_LowerCase(char *s); +void Com_UpperCase(char *s); +void Com_Itoa(int val, int base, char *buf); +// _ML_ added end + +// _ML_ added - map_rotation +typedef enum +{ + GT_FFA, // free for all + GT_TOURNAMENT, // one on one tournament + GT_SINGLE_PLAYER, // single player ffa + + //-- team games go after this -- + + GT_TEAM, // team deathmatch + GT_CTF, // capture the flag + GT_MAX_GAME_TYPE +} gametype_t; + +typedef enum +{ + TEAM_FREE, + TEAM_RED, + TEAM_BLUE, + TEAM_SPECTATOR, + TEAM_NUM_TEAMS +} team_t; + +#define TEAM_ANY -1 +#define TEAM_AUTO -2 +#define TEAM_INVALID -100 +// _ML_ added end + +#endif // __Q_SHARED_H diff --git a/tools/mbspc/qcommon/qcommon.h b/tools/mbspc/qcommon/qcommon.h index ad175f42..24f30340 100644 --- a/tools/mbspc/qcommon/qcommon.h +++ b/tools/mbspc/qcommon/qcommon.h @@ -15,7 +15,7 @@ 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 Foobar; if not, write to the Free Software +along with Quake III Arena source code; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =========================================================================== */ @@ -23,9 +23,28 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #ifndef _QCOMMON_H_ #define _QCOMMON_H_ -#include "../qcommon/cm_public.h" +// _ML_ modified - include path +#include "cm_public.h" +// _ML_ modified end -//#define PRE_RELEASE_DEMO +//Ignore __attribute__ on non-gcc platforms +#ifndef __GNUC__ +#ifndef __attribute__ +#define __attribute__(x) +#endif +#endif + +// _ML_ added - home_path +extern cvar_t *fs_multiuser; +// _ML_ added end + +// _ML_ added - ext_checking +extern cvar_t *fs_gamedirvar; +// _ML_ added end + +// _ML_ added - safe_log +extern int do_safelog; +// _ML_ added end //============================================================================ @@ -85,7 +104,7 @@ char *MSG_ReadBigString (msg_t *sb); char *MSG_ReadStringLine (msg_t *sb); float MSG_ReadAngle16 (msg_t *sb); void MSG_ReadData (msg_t *sb, void *buffer, int size); - +int MSG_LookaheadByte(msg_t * msg); void MSG_WriteDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to ); void MSG_ReadDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to ); @@ -114,8 +133,20 @@ NET ============================================================== */ -#define PACKET_BACKUP 32 // number of old messages that must be kept on client and - // server for delta comrpession and ping estimation +#define NET_ENABLEV4 0x01 +#define NET_ENABLEV6 0x02 + +// if this flag is set, always attempt ipv6 connections instead of ipv4 if a v6 address is found. +#define NET_PRIOV6 0x04 + +// disables ipv6 multicast support if set. +#define NET_DISABLEMCAST 0x08 + + +#define PACKET_BACKUP 32 // number of old messages that must be + // kept on client and server for delta + // comrpession and ping estimation + #define PACKET_MASK (PACKET_BACKUP-1) #define MAX_PACKET_USERCMDS 32 // max number of usercmd_t in a packet @@ -124,48 +155,65 @@ NET #define MAX_RELIABLE_COMMANDS 64 // max string commands buffered for restransmit -typedef enum { +typedef enum +{ + NA_BAD = 0, // an address lookup failed NA_BOT, - NA_BAD, // an address lookup failed NA_LOOPBACK, NA_BROADCAST, NA_IP, - NA_IPX, - NA_BROADCAST_IPX + NA_IP6, + NA_MULTICAST6, + NA_UNSPEC } netadrtype_t; typedef enum { NS_CLIENT, NS_SERVER } netsrc_t; +#define NET_ADDRSTRMAXLEN 48 // maximum length of an IPv6 address string including trailing '\0' typedef struct { netadrtype_t type; byte ip[4]; - byte ipx[10]; - + byte ip6[16]; unsigned short port; + unsigned long scope_id; // Needed for IPv6 link-local addresses + +// _ML_ added - http_tunnel +// index of tunneling client, or zero for normal UDP clients + int tunnel; } netadr_t; void NET_Init( void ); +// _ML_ removed - netaddr_fix +#if 0 void NET_Shutdown( void ); -void NET_Restart( void ); +void NET_Restart_f(void); void NET_Config( qboolean enableNetworking ); +#endif +// _ML_ removed end +void NET_FlushPacketQueue(void); void NET_SendPacket (netsrc_t sock, int length, const void *data, netadr_t to); -void QDECL NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...); +void QDECL NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...) + __attribute__ ((format(printf, 3, 4))); void QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len ); qboolean NET_CompareAdr (netadr_t a, netadr_t b); +qboolean NET_CompareBaseAdrMask(netadr_t a, netadr_t b, int netmask); qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b); qboolean NET_IsLocalAddress (netadr_t adr); const char *NET_AdrToString (netadr_t a); -qboolean NET_StringToAdr ( const char *s, netadr_t *a); +const char *NET_AdrToStringwPort(netadr_t a); +int NET_StringToAdr(const char *s, netadr_t * a, netadrtype_t family); qboolean NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message); +void NET_JoinMulticast6(void); +void NET_LeaveMulticast6(void); void NET_Sleep(int msec); - +#define MAX_PACKETLEN 1300 #define MAX_MSGLEN 16384 // max length of a message, which may // be fragmented into multiple packets @@ -210,6 +258,33 @@ void Netchan_TransmitNextFragment( netchan_t *chan ); qboolean Netchan_Process( netchan_t *chan, msg_t *msg ); +// _ML_ added - http_tunnel +extern cvar_t *tun_enabled; +extern cvar_t *tun_cryptData; +extern cvar_t *tun_port; +extern cvar_t *sv_password; +extern char tun_server[]; + +#define PORT_TUNNEL 80 + +int NET_RandomPort(int min); +int NET_InitAddr(void *addr, int family, char *ip, int port); +char *NET_ErrorString(int code); + +int TUN_Init(void); +void TUN_Shutdown(void); +void TUN_TransmitPacket(int length, const void *data, netadr_t to); +void TUN_SetNetSleep(void *fdset, int *highest); +qboolean TUN_ReceivePacket(netadr_t *net_from, msg_t *net_message); +void TUN_Disconnect(int id); + +#if defined DEDICATED + extern cvar_t *tun_maxClients; + void TUN_CheckConnectRequest(void); +#else + int TUN_Connect(char *ip, char *password); +#endif +// _ML_ added end /* ============================================================== @@ -220,26 +295,34 @@ PROTOCOL */ #define PROTOCOL_VERSION 68 -// 1.31 - 67 // maintain a list of compatible protocols for demo playing // NOTE: that stuff only works with two digits protocols extern int demo_protocols[]; -#define UPDATE_SERVER_NAME "update.quake3arena.com" +// _ML_ modified - update server names +#define UPDATE_SERVER_NAME "ftp.q3min.org" +// _ML_ modified end + // override on command line, config files etc. +// _ML_ modified - master server names #ifndef MASTER_SERVER_NAME -#define MASTER_SERVER_NAME "master.quake3arena.com" +#define MASTER_SERVER_NAME "master.ioquake3.org" #endif +// _ML_ modified end + +#ifndef STANDALONE #ifndef AUTHORIZE_SERVER_NAME #define AUTHORIZE_SERVER_NAME "authorize.quake3arena.com" #endif -#define PORT_MASTER 27950 -#define PORT_UPDATE 27951 #ifndef PORT_AUTHORIZE #define PORT_AUTHORIZE 27952 #endif +#endif + +#define PORT_MASTER 27950 +#define PORT_UPDATE 27951 #define PORT_SERVER 27960 #define NUM_SERVER_PORTS 4 // broadcast scan this many ports after // PORT_SERVER so a single machine can @@ -259,7 +342,12 @@ enum svc_ops_e { svc_serverCommand, // [string] to be executed by client game module svc_download, // [short] size [size bytes] svc_snapshot, - svc_EOF + svc_EOF, + + // svc_extension follows a svc_EOF, followed by another svc_* ... + // this keeps legacy clients compatible. + svc_extension, + svc_voip, // not wrapped in USE_VOIP, so this value is reserved. }; @@ -272,7 +360,12 @@ enum clc_ops_e { clc_move, // [[usercmd_t] clc_moveNoDelta, // [[usercmd_t] clc_clientCommand, // [string] message - clc_EOF + clc_EOF, + + // clc_extension follows a clc_EOF, followed by another clc_* ... + // this keeps legacy servers compatible. + clc_extension, + clc_voip, // not wrapped in USE_VOIP, so this value is reserved. }; /* @@ -310,20 +403,33 @@ typedef enum { } sharedTraps_t; void VM_Init( void ); -vm_t *VM_Create( const char *module, int (*systemCalls)(int *), +vm_t *VM_Create( const char *module, intptr_t(*systemCalls) (intptr_t *), vmInterpret_t interpret ); // module should be bare: "cgame", not "cgame.dll" or "vm/cgame.qvm" void VM_Free( vm_t *vm ); void VM_Clear(void); +void VM_Forced_Unload_Start(void); +void VM_Forced_Unload_Done(void); vm_t *VM_Restart( vm_t *vm ); -int QDECL VM_Call( vm_t *vm, int callNum, ... ); +intptr_t QDECL VM_Call( vm_t *vm, int callNum, ... ); void VM_Debug( int level ); -void *VM_ArgPtr( int intValue ); -void *VM_ExplicitArgPtr( vm_t *vm, int intValue ); +void *VM_ArgPtr( intptr_t intValue ); +void *VM_ExplicitArgPtr( vm_t *vm, intptr_t intValue ); +#define VMA(x) VM_ArgPtr(args[x]) +static ID_INLINE float +_vmf(intptr_t x) +{ + floatint_t fi; + fi.i = (int) x; + return fi.f; +} + +#define VMF(x) _vmf(args[x]) + /* ============================================================== @@ -380,8 +486,13 @@ void Cmd_AddCommand( const char *cmd_name, xcommand_t function ); void Cmd_RemoveCommand( const char *cmd_name ); +typedef void (*completionFunc_t) (char *args, int argNum); + void Cmd_CommandCompletion( void(*callback)(const char *s) ); // callback with each valid string +void Cmd_SetCommandCompletionFunc(const char *command, completionFunc_t complete); +void Cmd_CompleteArgument(const char *command, char *args, int argNum); +void Cmd_CompleteCfgName(char *args, int argNum); int Cmd_Argc (void); char *Cmd_Argv (int arg); @@ -390,11 +501,13 @@ char *Cmd_Args (void); char *Cmd_ArgsFrom( int arg ); void Cmd_ArgsBuffer( char *buffer, int bufferLength ); char *Cmd_Cmd (void); +void Cmd_Args_Sanitize(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. void Cmd_TokenizeString( const char *text ); +void Cmd_TokenizeStringIgnoreQuotes(const char *text_in); // Takes a null terminated string. Does not need to be /n terminated. // breaks the string up into arg tokens. @@ -459,10 +572,14 @@ char *Cvar_VariableString( const char *var_name ); void Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize ); // returns an empty string if not defined +int Cvar_Flags(const char *var_name); +// returns CVAR_NONEXISTENT if cvar doesn't exist or the flags of that particular CVAR. + void Cvar_CommandCompletion( void(*callback)(const char *s) ); // callback with each valid string void Cvar_Reset( const char *var_name ); +void Cvar_ForceReset(const char *var_name); void Cvar_SetCheatState( void ); // reset all testing vars to a safe value @@ -483,9 +600,16 @@ char *Cvar_InfoString_Big( int bit ); // returns an info string containing all the cvars that have the given bit set // in their flags ( CVAR_USERINFO, CVAR_SERVERINFO, CVAR_SYSTEMINFO, etc ) void Cvar_InfoStringBuffer( int bit, char *buff, int buffsize ); +void Cvar_CheckRange(cvar_t * cv, float minVal, float maxVal, qboolean shouldBeIntegral); void Cvar_Restart_f( void ); +void Cvar_CompleteCvarName(char *args, int argNum); + +// _M_ added - cvar_new +cvar_t *Cvar_New(const char *name, const char *val, int flags); +// _ML_ added end + extern int cvar_modifiedFlags; // whenever a cvar is modifed, its flags will be OR'd into this, so // a single check can determine if any CVAR_USERINFO, CVAR_SERVERINFO, @@ -514,9 +638,13 @@ issues. #define MAX_FILE_HANDLES 64 -#define BASEGAME "baseq3" +#ifdef DEDICATED +# define Q3CONFIG_CFG "q3config_server.cfg" +#else +# define Q3CONFIG_CFG "q3config.cfg" +#endif -qboolean FS_Initialized(); +qboolean FS_Initialized(void); void FS_InitFilesystem (void); void FS_Shutdown( qboolean closemfp ); @@ -525,6 +653,8 @@ qboolean FS_ConditionalRestart( int checksumFeed ); void FS_Restart( int checksumFeed ); // shutdown and restart the filesystem so changes to fs_gamedir can take effect +void FS_AddGameDirectory(const char *path, const char *dir); + char **FS_ListFiles( const char *directory, const char *extension, int *numfiles ); // directory should not have either a leading or trailing / // if extension is "/", only subdirectories will be returned @@ -534,15 +664,17 @@ void FS_FreeFileList( char **list ); qboolean FS_FileExists( const char *file ); -int FS_LoadStack(); +char *FS_BuildOSPath(const char *base, const char *game, const char *qpath); + +int FS_LoadStack(void); int FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize ); int FS_GetModList( char *listbuf, int bufsize ); fileHandle_t FS_FOpenFileWrite( const char *qpath ); +fileHandle_t FS_FOpenFileAppend(const char *filename); // will properly create any needed paths and deal with seperater character issues -int FS_filelength( fileHandle_t f ); fileHandle_t FS_SV_FOpenFileWrite( const char *filename ); int FS_SV_FOpenFileRead( const char *filename, fileHandle_t *fp ); void FS_SV_Rename( const char *from, const char *to ); @@ -590,7 +722,8 @@ int FS_FTell( fileHandle_t f ); void FS_Flush( fileHandle_t f ); -void QDECL FS_Printf( fileHandle_t f, const char *fmt, ... ); +void QDECL FS_Printf( fileHandle_t f, const char *fmt, ... ) + __attribute__ ((format(printf, 2, 3))); // like fprintf int FS_FOpenFileByMode( const char *qpath, fileHandle_t *f, fsMode_t mode ); @@ -627,10 +760,17 @@ void FS_PureServerSetLoadedPaks( const char *pakSums, const char *pakNames ); // separated checksums will be checked for files, with the // sole exception of .cfg files. +qboolean FS_CheckDirTraversal(const char *checkdir); qboolean FS_idPak( char *pak, char *base ); qboolean FS_ComparePaks( char *neededpaks, int len, qboolean dlstring ); void FS_Rename( const char *from, const char *to ); +void FS_Remove(const char *osPath); +void FS_HomeRemove(const char *homePath); + +void FS_FilenameCompletion(const char *dir, const char *ext, + qboolean stripExt, + void (*callback) (const char *s)); /* ============================================================== @@ -647,9 +787,12 @@ typedef struct { int widthInChars; char buffer[MAX_EDIT_LINE]; } field_t; - -void Field_Clear( field_t *edit ); -void Field_CompleteCommand( field_t *edit ); +void Field_Clear(field_t * edit); +void Field_AutoComplete(field_t * edit); +void Field_CompleteKeyname(void); +void Field_CompleteFilename(const char *dir, + const char *ext, qboolean stripExt); +void Field_CompleteCommand(char *cmd, qboolean doCommands, qboolean doCvars); /* ============================================================== @@ -659,49 +802,70 @@ MISC ============================================================== */ -// TTimo -// vsnprintf is ISO/IEC 9899:1999 -// abstracting this to make it portable -#ifdef WIN32 -#define Q_vsnprintf _vsnprintf -#else -// TODO: do we need Mac define? -#define Q_vsnprintf vsnprintf -#endif - // centralizing the declarations for cl_cdkey // https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=470 extern char cl_cdkey[34]; -// returnbed by Sys_GetProcessorId -#define CPUID_GENERIC 0 // any unrecognized processor - -#define CPUID_AXP 0x10 - -#define CPUID_INTEL_UNSUPPORTED 0x20 // Intel 386/486 -#define CPUID_INTEL_PENTIUM 0x21 // Intel Pentium or PPro -#define CPUID_INTEL_MMX 0x22 // Intel Pentium/MMX or P2/MMX -#define CPUID_INTEL_KATMAI 0x23 // Intel Katmai - -#define CPUID_AMD_3DNOW 0x30 // AMD K6 3DNOW! - -// TTimo +// returned by Sys_GetProcessorFeatures +typedef enum +{ + CF_RDTSC = 1 << 0, + CF_MMX = 1 << 1, + CF_MMX_EXT = 1 << 2, + CF_3DNOW = 1 << 3, + CF_3DNOW_EXT = 1 << 4, + CF_SSE = 1 << 5, + CF_SSE2 = 1 << 6, + CF_ALTIVEC = 1 << 7 +} cpuFeatures_t; // centralized and cleaned, that's the max string you can send to a Com_Printf / Com_DPrintf (above gets truncated) -#define MAXPRINTMSG 4096 +#define MAXPRINTMSG 4096 + + +typedef enum +{ + // SE_NONE must be zero + SE_NONE = 0, // evTime is still valid + SE_KEY, // evValue is a key code, evValue2 is the down flag + SE_CHAR, // evValue is an ascii char + SE_MOUSE, // evValue and evValue2 are reletive signed x / y moves + SE_JOYSTICK_AXIS, // evValue is an axis number and evValue2 is the current state (-127 to 127) + SE_CONSOLE, // evPtr is a char* + SE_PACKET // evPtr is a netadr_t followed by data bytes to evPtrLength +} sysEventType_t; + +typedef struct +{ + int evTime; + sysEventType_t evType; + int evValue, evValue2; + int evPtrLength; // bytes of data pointed to by evPtr, for journaling + void *evPtr; // this must be manually freed if not NULL +} sysEvent_t; + +void Com_QueueEvent(int time, sysEventType_t type, int value, int value2, + + int ptrLength, void *ptr); +int Com_EventLoop(void); +sysEvent_t Com_GetSystemEvent(void); char *CopyString( const char *in ); void Info_Print( const char *s ); void Com_BeginRedirect (char *buffer, int buffersize, void (*flush)(char *)); void Com_EndRedirect( void ); -void QDECL Com_Printf( const char *fmt, ... ); -void QDECL Com_DPrintf( const char *fmt, ... ); -void QDECL Com_Error( int code, const char *fmt, ... ); +void QDECL Com_Printf( const char *fmt, ... ) + __attribute__ ((format(printf, 1, 2))); +void QDECL Com_DPrintf( const char *fmt, ... ) + __attribute__ ((format(printf, 1, 2))); +void QDECL Com_Error( int code, const char *fmt, ... ) + __attribute__ ((format(printf, 2, 3))); void Com_Quit_f( void ); -int Com_EventLoop( void ); + int Com_Milliseconds( void ); // will be journaled properly unsigned Com_BlockChecksum( const void *buffer, int length ); -unsigned Com_BlockChecksumKey (void *buffer, int length, int key); +char *Com_MD5File(const char *filename, int length, const char *prefix, + int prefix_len); int Com_HashKey(char *string, int maxlen); int Com_Filter(char *filter, char *name, int casesensitive); int Com_FilterPath(char *filter, char *name, int casesensitive); @@ -720,16 +884,32 @@ extern cvar_t *com_speeds; extern cvar_t *com_timescale; extern cvar_t *com_sv_running; extern cvar_t *com_cl_running; -extern cvar_t *com_viewlog; // 0 = hidden, 1 = visible, 2 = minimized extern cvar_t *com_version; extern cvar_t *com_blood; extern cvar_t *com_buildScript; // for building release pak files extern cvar_t *com_journal; extern cvar_t *com_cameraMode; +extern cvar_t *com_ansiColor; +extern cvar_t *com_unfocused; +extern cvar_t *com_maxfpsUnfocused; +extern cvar_t *com_minimized; +extern cvar_t *com_maxfpsMinimized; +extern cvar_t *com_altivec; // both client and server must agree to pause extern cvar_t *cl_paused; extern cvar_t *sv_paused; +extern cvar_t *cl_packetdelay; +extern cvar_t *sv_packetdelay; + +// _ML_ added - suppress_messages +extern cvar_t *com_verbose; +// _ML_ added end + +// _ML_ added - map_rotation +extern cvar_t *sv_mapRotate; +extern cvar_t *sv_mapRotateRandom; +// _ML_ added end // com_speeds times extern int time_game; @@ -865,9 +1045,12 @@ void CL_ShutdownAll( void ); void CL_FlushMemory( void ); // dump all memory on an error -void CL_StartHunkUsers( void ); +void CL_StartHunkUsers(qboolean rendererOnly); // start all the client stuff using the hunk +void Key_KeynameCompletion(void (*callback) (const char *s)); +// for keyname autocompletion + void Key_WriteBindings( fileHandle_t f ); // for writing the config files @@ -891,7 +1074,7 @@ qboolean SV_GameCommand( void ); // UI interface // qboolean UI_GameCommand( void ); -qboolean UI_usesUniqueCDKey(); +qboolean UI_usesUniqueCDKey(void); /* ============================================================== @@ -911,33 +1094,12 @@ typedef enum { MAX_JOYSTICK_AXIS } joystickAxis_t; -typedef enum { - // bk001129 - make sure SE_NONE is zero - SE_NONE = 0, // evTime is still valid - SE_KEY, // evValue is a key code, evValue2 is the down flag - SE_CHAR, // evValue is an ascii char - SE_MOUSE, // evValue and evValue2 are reletive signed x / y moves - SE_JOYSTICK_AXIS, // evValue is an axis number and evValue2 is the current state (-127 to 127) - SE_CONSOLE, // evPtr is a char* - SE_PACKET // evPtr is a netadr_t followed by data bytes to evPtrLength -} sysEventType_t; - -typedef struct { - int evTime; - sysEventType_t evType; - int evValue, evValue2; - int evPtrLength; // bytes of data pointed to by evPtr, for journaling - void *evPtr; // this must be manually freed if not NULL -} sysEvent_t; - -sysEvent_t Sys_GetEvent( void ); - void Sys_Init (void); // general development dll loading for virtual machine testing -// fqpath param added 7/20/02 by T.Ray - Sys_LoadDll is only called in vm.c at this time -void * QDECL Sys_LoadDll( const char *name, char *fqpath , int (QDECL **entryPoint)(int, ...), - int (QDECL *systemcalls)(int, ...) ); +void *QDECL Sys_LoadDll(const char *name, char *fqpath, + intptr_t(QDECL ** entryPoint) (int, ...), + intptr_t(QDECL * systemcalls) (intptr_t, ...)); void Sys_UnloadDll( void *dllHandle ); void Sys_UnloadGame( void ); @@ -955,7 +1117,8 @@ void *Sys_GetBotLibAPI( void *parms ); char *Sys_GetCurrentUser( void ); -void QDECL Sys_Error( const char *error, ...); +void QDECL Sys_Error( const char *error, ...) + __attribute__ ((format(printf, 1, 2))); void Sys_Quit (void); char *Sys_GetClipboardData( void ); // note that this isn't journaled... @@ -966,49 +1129,45 @@ void Sys_Print( const char *msg ); int Sys_Milliseconds (void); void Sys_SnapVector( float *v ); +qboolean Sys_RandomBytes(byte * string, int len); // the system console is shown when a dedicated server is running void Sys_DisplaySystemConsole( qboolean show ); -int Sys_GetProcessorId( void ); +cpuFeatures_t Sys_GetProcessorFeatures(void); -void Sys_BeginStreamedFile( fileHandle_t f, int readahead ); -void Sys_EndStreamedFile( fileHandle_t f ); -int Sys_StreamedRead( void *buffer, int size, int count, fileHandle_t f ); -void Sys_StreamSeek( fileHandle_t f, int offset, int origin ); - -void Sys_ShowConsole( int level, qboolean quitOnClose ); void Sys_SetErrorText( const char *text ); -void Sys_SendPacket( int length, const void *data, netadr_t to ); +void NET_TransmitPacket(int length, const void *data, netadr_t to); +qboolean NET_ReceivePacket(netadr_t * net_from, msg_t * net_message); -qboolean Sys_StringToAdr( const char *s, netadr_t *a ); +qboolean NET_StringToBaseAdr(const char *s, netadr_t * a, netadrtype_t family); //Does NOT parse port numbers, only base addresses. -qboolean Sys_IsLANAddress (netadr_t adr); -void Sys_ShowIP(void); - -qboolean Sys_CheckCD( void ); +qboolean NET_IsLanAddress(netadr_t adr); +void NET_ShowIP(void); void Sys_Mkdir( const char *path ); char *Sys_Cwd( void ); -void Sys_SetDefaultCDPath(const char *path); -char *Sys_DefaultCDPath(void); void Sys_SetDefaultInstallPath(const char *path); char *Sys_DefaultInstallPath(void); +#ifdef MACOS_X +char *Sys_DefaultAppPath(void); +#endif + void Sys_SetDefaultHomePath(const char *path); char *Sys_DefaultHomePath(void); +const char *Sys_Dirname(char *path); +const char *Sys_Basename(char *path); +char *Sys_ConsoleInput(void); -char **Sys_ListFiles( const char *directory, const char *extension, char *filter, int *numfiles, qboolean wantsubs ); +char **Sys_ListFiles(const char *directory, const char *extension, + char *filter, int *numfiles, qboolean wantsubs); void Sys_FreeFileList( char **list ); -void Sys_BeginProfiling( void ); -void Sys_EndProfiling( void ); +void Sys_Sleep(int msec); -qboolean Sys_LowPhysicalMemory(); -unsigned int Sys_ProcessorCount(); - -int Sys_MonkeyShouldBeSpanked( void ); +qboolean Sys_LowPhysicalMemory(void); /* This is based on the Adaptive Huffman algorithm described in Sayood's Data * Compression book. The ranks are not actually stored, but implicitly defined @@ -1056,6 +1215,10 @@ void Huff_offsetReceive (node_t *node, int *ch, byte *fin, int *offset); void Huff_offsetTransmit (huff_t *huff, int ch, byte *fout, int *offset); void Huff_putBit( int bit, byte *fout, int *offset); int Huff_getBit( byte *fout, int *offset); +// don't use if you don't know what you're doing. +int Huff_getBloc(void); +void Huff_setBloc(int _bloc); + extern huffman_t clientHuffTables; @@ -1064,4 +1227,58 @@ extern huffman_t clientHuffTables; #define CL_ENCODE_START 12 #define CL_DECODE_START 4 +// flags for sv_allowDownload and cl_allowDownload +#define DLF_ENABLE 1 +#define DLF_NO_REDIRECT 2 +#define DLF_NO_UDP 4 +#define DLF_NO_DISCONNECT 8 + +// _ML_ added - map_rotation +#if defined DEDICATED +#define MAX_MAP_ROT_NUM 32 +#define MAX_BOT_ROT_NUM 32 +#define MAX_BOT_NUM 8 +#define BOT_NAME_LEN 64 + +typedef struct +{ + char name[BOT_NAME_LEN]; + int skill; + int clinum; // client number if active, otherwise -1 + int team; // team if active, otherwise -1 +} bot_t; + +typedef struct +{ + char name[MAX_STRING_CHARS]; + int gametype; + int instagib; + int fraglimit; + int timelimit; + int minplayers; + int maxplayers; + int botskill; + bot_t bot[MAX_BOT_NUM]; +} map_t; +extern char botnames[MAX_BOT_ROT_NUM][BOT_NAME_LEN]; +extern int num_parsed_bots; + +extern map_t maprot[MAX_MAP_ROT_NUM]; +extern int maprot_num; +extern int maprot_curr; + +int Com_ParseMapRotation(char *filename); +void SV_SpawnServerEx(map_t * map); +#endif // DEDICATED +// _ML_ added end + +// _ML_ added - utility_functions +void Com_DumpSubString(char *s, int len, int newl); +void Com_LogTime(char *msg); +// _ML_ added end + +// _ML_ added - safe_log +void mlog(char *fmt, ...); +// _ML_ added end + #endif // _QCOMMON_H_ diff --git a/tools/mbspc/qcommon/qfiles.h b/tools/mbspc/qcommon/qfiles.h index cbffbedb..564b0fa5 100644 --- a/tools/mbspc/qcommon/qfiles.h +++ b/tools/mbspc/qcommon/qfiles.h @@ -26,6 +26,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // qfiles.h: quake file formats // This file must be identical in the quake and utils directories // +//Ignore __attribute__ on non-gcc platforms +#ifndef __GNUC__ +#ifndef __attribute__ +#define __attribute__(x) +#endif +#endif // surface geometry should not exceed these limits #define SHADER_MAX_VERTEXES 1000 @@ -44,6 +50,7 @@ QVM files */ #define VM_MAGIC 0x12721444 +#define VM_MAGIC_VER2 0x12721445 typedef struct { int vmMagic; @@ -56,49 +63,13 @@ typedef struct { int dataLength; int litLength; // ( dataLength - litLength ) should be byteswapped on load int bssLength; // zero filled memory appended to datalength + //!!! below here is VM_MAGIC_VER2 !!! + int jtrgLength; // number of jump table targets } vmHeader_t; -/* -======================================================================== - -PCX files are used for 8 bit images - -======================================================================== -*/ - -typedef struct { - char manufacturer; - char version; - char encoding; - char bits_per_pixel; - unsigned short xmin,ymin,xmax,ymax; - unsigned short hres,vres; - unsigned char palette[48]; - char reserved; - char color_planes; - unsigned short bytes_per_line; - unsigned short palette_type; - char filler[58]; - unsigned char data; // unbounded -} pcx_t; -/* -======================================================================== - -TGA files are used for 24/32 bit images - -======================================================================== -*/ - -typedef struct _TargaHeader { - unsigned char id_length, colormap_type, image_type; - unsigned short colormap_index, colormap_length; - unsigned char colormap_size; - unsigned short x_origin, y_origin, width, height; - unsigned char pixel_size, attributes; -} TargaHeader; @@ -298,7 +269,137 @@ typedef struct { int ofsEnd; // end of file } md4Header_t; +/* + * Here are the definitions for Ravensoft's model format of md4. Raven stores their + * playermodels in .mdr files, in some games, which are pretty much like the md4 + * format implemented by ID soft. It seems like ID's original md4 stuff is not used at all. + * MDR is being used in EliteForce, JediKnight2 and Soldiers of Fortune2 (I think). + * So this comes in handy for anyone who wants to make it possible to load player + * models from these games. + * This format has bone tags, which is similar to the thing you have in md3 I suppose. + * Raven has released their version of md3view under GPL enabling me to add support + * to this codebase. Thanks to Steven Howes aka Skinner for helping with example + * source code. + * + * - Thilo Schulz (arny@ats.s.bawue.de) + */ +// If you want to enable support for Raven's .mdr / md4 format, uncomment the next +// line. +//#define RAVENMD4 + +#ifdef RAVENMD4 + +#define MDR_IDENT (('5'<<24)+('M'<<16)+('D'<<8)+'R') +#define MDR_VERSION 2 +#define MDR_MAX_BONES 128 + +typedef struct +{ + int boneIndex; // these are indexes into the boneReferences, + float boneWeight; // not the global per-frame bone list + vec3_t offset; +} mdrWeight_t; + +typedef struct +{ + vec3_t normal; + vec2_t texCoords; + int numWeights; + mdrWeight_t weights[1]; // variable sized +} mdrVertex_t; + +typedef struct +{ + int indexes[3]; +} mdrTriangle_t; + +typedef struct +{ + int ident; + + char name[MAX_QPATH]; // polyset name + char shader[MAX_QPATH]; + int shaderIndex; // for in-game use + + int ofsHeader; // this will be a negative number + + int numVerts; + int ofsVerts; + + int numTriangles; + int ofsTriangles; + + // Bone references are a set of ints representing all the bones + // present in any vertex weights for this surface. This is + // needed because a model may have surfaces that need to be + // drawn at different sort times, and we don't want to have + // to re-interpolate all the bones for each surface. + int numBoneReferences; + int ofsBoneReferences; + + int ofsEnd; // next surface follows +} mdrSurface_t; + +typedef struct +{ + float matrix[3][4]; +} mdrBone_t; + +typedef struct +{ + vec3_t bounds[2]; // bounds of all surfaces of all LOD's for this frame + vec3_t localOrigin; // midpoint of bounds, used for sphere cull + float radius; // dist from localOrigin to corner + char name[16]; + mdrBone_t bones[1]; // [numBones] +} mdrFrame_t; + +typedef struct +{ + unsigned char Comp[24]; // MC_COMP_BYTES is in MatComp.h, but don't want to couple +} mdrCompBone_t; + +typedef struct { + vec3_t bounds[2]; // bounds of all surfaces of all LOD's for this frame + vec3_t localOrigin; // midpoint of bounds, used for sphere cull + float radius; // dist from localOrigin to corner + mdrCompBone_t bones[1]; // [numBones] +} mdrCompFrame_t; + +typedef struct { + int numSurfaces; + int ofsSurfaces; // first surface, others follow + int ofsEnd; // next lod follows +} mdrLOD_t; + +typedef struct { + int boneIndex; + char name[32]; +} mdrTag_t; + +typedef struct { + int ident; + int version; + + char name[MAX_QPATH]; // model name + + // frames and bones are shared by all levels of detail + int numFrames; + int numBones; + int ofsFrames; // mdrFrame_t[numFrames] + + // each level of detail has completely separate sets of surfaces + int numLODs; + int ofsLODs; + + int numTags; + int ofsTags; + + int ofsEnd; // end of file +} mdrHeader_t; + +#endif /* ============================================================================== @@ -453,6 +554,7 @@ typedef struct { vec3_t normal; byte color[4]; } drawVert_t; +#define drawVert_t_cleared(x) drawVert_t (x) = {{0, 0, 0}, {0, 0}, {0, 0}, {0, 0, 0}, {0, 0, 0, 0}} typedef enum { MST_BAD, diff --git a/tools/mbspc/qcommon/unzip.c b/tools/mbspc/qcommon/unzip.c index ed521ea3..7b25b985 100644 --- a/tools/mbspc/qcommon/unzip.c +++ b/tools/mbspc/qcommon/unzip.c @@ -7,7 +7,8 @@ * *****************************************************************************/ -#include "../client/client.h" +#include "q_shared.h" +#include "qcommon.h" #include "unzip.h" /* unzip.h -- IO for uncompress .zip files using zlib @@ -235,7 +236,7 @@ typedef Byte *voidp; #define Z_DEFLATED 8 /* The deflate compression method (the only one supported in this version) */ -#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ +#define Z_NULL (void *)0 /* for initializing zalloc, zfree, opaque */ #define zlib_version zlibVersion() /* for compatibility with versions < 1.0.2 */ @@ -1113,24 +1114,6 @@ static int unzlocal_getShort (FILE* fin, uLong *pX) *pX = LittleShort( v); return UNZ_OK; -/* - uLong x ; - int i; - int err; - - err = unzlocal_getByte(fin,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unzlocal_getByte(fin,&i); - x += ((uLong)i)<<8; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -*/ } static int unzlocal_getLong (FILE *fin, uLong *pX) @@ -1142,32 +1125,6 @@ static int unzlocal_getLong (FILE *fin, uLong *pX) *pX = LittleLong( v); return UNZ_OK; -/* - uLong x ; - int i; - int err; - - err = unzlocal_getByte(fin,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unzlocal_getByte(fin,&i); - x += ((uLong)i)<<8; - - if (err==UNZ_OK) - err = unzlocal_getByte(fin,&i); - x += ((uLong)i)<<16; - - if (err==UNZ_OK) - err = unzlocal_getByte(fin,&i); - x += ((uLong)i)<<24; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -*/ } @@ -2042,30 +1999,17 @@ extern int unzReadCurrentFile (unzFile file, void *buf, unsigned len) else { uLong uTotalOutBefore,uTotalOutAfter; - const Byte *bufBefore; uLong uOutThis; int flush=Z_SYNC_FLUSH; uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; - bufBefore = pfile_in_zip_read_info->stream.next_out; - /* - if ((pfile_in_zip_read_info->rest_read_uncompressed == - pfile_in_zip_read_info->stream.avail_out) && - (pfile_in_zip_read_info->rest_read_compressed == 0)) - flush = Z_FINISH; - */ err=inflate(&pfile_in_zip_read_info->stream,flush); uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; uOutThis = uTotalOutAfter-uTotalOutBefore; -// pfile_in_zip_read_info->crc32 = -// crc32(pfile_in_zip_read_info->crc32,bufBefore, -// (uInt)(uOutThis)); - - pfile_in_zip_read_info->rest_read_uncompressed -= - uOutThis; + pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis; iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); @@ -2925,8 +2869,6 @@ int inflate_flush(inflate_blocks_statef *s, z_streamp z, int r) * For conditions of distribution and use, see copyright notice in zlib.h */ -static const char inflate_copyright[] = - " inflate 1.1.3 Copyright 1995-1998 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -3034,7 +2976,7 @@ static int huft_build(uInt *b, uInt n, uInt s, const uInt *d, const uInt *e, inf uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */ register uInt *p; /* pointer into c[], b[], or v[] */ inflate_huft *q; /* points to current table */ - struct inflate_huft_s r; /* table entry for structure assignment */ + struct inflate_huft_s r = { {{0, 0}} }; /* table entry for structure assignment */ inflate_huft *u[BMAX]; /* table stack */ register int w; /* bits before this table == (l * h) */ uInt x[BMAX+1]; /* bit offsets, then code stack */ @@ -4050,7 +3992,7 @@ int inflateInit2_(z_streamp z, int w, const char *version, int stream_size) /* create inflate_blocks state */ if ((z->state->blocks = - inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w)) + inflate_blocks_new(z, z->state->nowrap ? ((check_func) 0) : adler32, (uInt)1 << w)) == Z_NULL) { inflateEnd(z);