diff --git a/Makefile b/Makefile index cf8fbc13..0a1011ef 100644 --- a/Makefile +++ b/Makefile @@ -465,29 +465,31 @@ $(BIN_DIR)/$(BIN_PFX)bsputil$(EXT): $(patsubst %,$(BUILD_DIR)/%,$(BSPUTIL_OBJS)) ######## QBSP_OBJS = \ - brush.o \ - bspfile.o \ - cmdlib.o \ - csg4.o \ - file.o \ - globals.o \ - map.o \ - mathlib.o \ - merge.o \ - outside.o \ - parser.o \ - portals.o \ - qbsp.o \ - solidbsp.o \ - surfaces.o \ - tjunc.o \ - util.o \ - wad.o \ - winding.o \ - writebsp.o + common/threads.o \ + common/log.o \ + qbsp/brush.o \ + qbsp/bspfile.o \ + qbsp/cmdlib.o \ + qbsp/csg4.o \ + qbsp/file.o \ + qbsp/globals.o \ + qbsp/map.o \ + qbsp/mathlib.o \ + qbsp/merge.o \ + qbsp/outside.o \ + qbsp/parser.o \ + qbsp/portals.o \ + qbsp/qbsp.o \ + qbsp/solidbsp.o \ + qbsp/surfaces.o \ + qbsp/tjunc.o \ + qbsp/util.o \ + qbsp/wad.o \ + qbsp/winding.o \ + qbsp/writebsp.o -$(BIN_DIR)/$(BIN_PFX)qbsp$(EXT): $(patsubst %,$(BUILD_DIR)/qbsp/%,$(QBSP_OBJS)) - $(call do_cc_link,-lm) +$(BIN_DIR)/$(BIN_PFX)qbsp$(EXT): $(patsubst %,$(BUILD_DIR)/%,$(QBSP_OBJS)) + $(call do_cc_link,-lm $(LPTHREAD)) $(call do_strip,$@) clean: @@ -580,8 +582,8 @@ $(1)/bin/$$(BIN_PFX)bsputil$$(EXT): $$(patsubst %,$(1)/%,$$(BSPUTIL_OBJS)) $$(call do_cc_link,-lm $$(LPTHREAD) $(2)) $$(call do_strip,$$@) -$(1)/bin/$$(BIN_PFX)qbsp$$(EXT): $$(patsubst %,$(1)/qbsp/%,$$(QBSP_OBJS)) - $$(call do_cc_link,-lm $(2)) +$(1)/bin/$$(BIN_PFX)qbsp$$(EXT): $$(patsubst %,$(1)/%,$$(QBSP_OBJS)) + $$(call do_cc_link,-lm $$(LPTHREAD) $(2)) $$(call do_strip,$$@) endef @@ -637,8 +639,8 @@ $(BUILD_DIR)/win32/bin/$(BIN_PFX)bsputil$(EXT): $(patsubst %,$(BUILD_DIR)/win32/ $(call do_cc_link,-lm $(LPTHREAD)) $(call do_strip,$@) -$(BUILD_DIR)/win32/bin/$(BIN_PFX)qbsp$(EXT): $(patsubst %,$(BUILD_DIR)/win32/qbsp/%,$(QBSP_OBJS)) - $(call do_cc_link,-lm) +$(BUILD_DIR)/win32/bin/$(BIN_PFX)qbsp$(EXT): $(patsubst %,$(BUILD_DIR)/win32/%,$(QBSP_OBJS)) + $(call do_cc_link,-lm $(LPTHREAD)) $(call do_strip,$@) # Simple rules to copy distribution files diff --git a/qbsp/qbsp.c b/qbsp/qbsp.c index 2d8b8c3e..5a0d426e 100644 --- a/qbsp/qbsp.c +++ b/qbsp/qbsp.c @@ -21,6 +21,7 @@ #include +#include "common/log.h" #include "qbsp.h" #include "wad.h" @@ -515,8 +516,6 @@ InitQBSP(int argc, char **argv) char *szBuf; int length; - logfile = NULL; - // Initial values options.dxLeakDist = 2; options.dxSubdivide = 240; @@ -566,11 +565,9 @@ InitQBSP(int argc, char **argv) /* Start logging to .log */ StripExtension(options.szBSPName); strcat(options.szBSPName, ".log"); - logfile = fopen(options.szBSPName, "wt"); - if (!logfile) - Message(msgWarning, warnNoLogFile); - else - Message(msgFile, IntroString); + init_log(options.szBSPName); + + Message(msgFile, IntroString); /* If no wadpath given, default to the map directory */ if (options.wadPath[0] == 0) { @@ -627,7 +624,7 @@ main(int argc, char **argv) // FreeAllMem(); // PrintMem(); - fclose(logfile); + close_log(); return 0; } diff --git a/qbsp/qbsp.h b/qbsp/qbsp.h index 62d352a0..672ee350 100644 --- a/qbsp/qbsp.h +++ b/qbsp/qbsp.h @@ -686,6 +686,4 @@ void Message(int MsgType, ...); void Error(const char *error, ...) __attribute__((format(printf,1,2),noreturn)); -extern FILE *logfile; - #endif diff --git a/qbsp/util.c b/qbsp/util.c index b1ef4f61..963195d2 100644 --- a/qbsp/util.c +++ b/qbsp/util.c @@ -23,6 +23,9 @@ #include #include +#include "common/threads.h" +#include "common/log.h" + #include "qbsp.h" static int rgMemTotal[GLOBAL + 1]; @@ -205,17 +208,15 @@ void Error(const char *error, ...) { va_list argptr; - char message[512]; + + /* Using lockless prints so we can error out while holding the lock */ + InterruptThreadProgress__(); + logprint_locked__("************ ERROR ************\n"); va_start(argptr, error); - vsnprintf(message, sizeof(message), error, argptr); + logvprint(error, argptr); va_end(argptr); - - fprintf(stderr, "\nERROR: %s\n\n", message); - if (logfile) { - fprintf(logfile, "\nERROR: %s\n\n", message); - fclose(logfile); - } + logprint_locked__("\n"); exit(1); } @@ -313,11 +314,12 @@ Message(int msgType, ...) return; } - if (msgType != msgFile) + if (msgType == msgScreen) printf("%s", szBuffer); - if (msgType != msgScreen && logfile) - fprintf(logfile, "%s", szBuffer); + else if (msgType == msgFile) + logprint_silent("%s", szBuffer); + else + logprint("%s", szBuffer); va_end(argptr); - fflush(stdout); }