]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
Merge commit '9c4c8b725fdca551dc9379b77ebd9c498d0c6f28' into master-merge
authorThomas Debesse <dev@illwieckz.net>
Mon, 20 Jun 2022 02:25:08 +0000 (04:25 +0200)
committerThomas Debesse <dev@illwieckz.net>
Mon, 20 Jun 2022 02:25:08 +0000 (04:25 +0200)
1  2 
Makefile
radiant/brushmanip.cpp
tools/quake3/q3map2/bsp.c
tools/quake3/q3map2/light.c
tools/quake3/q3map2/light_bounce.c
tools/quake3/q3map2/map.c
tools/quake3/q3map2/model.c
tools/quake3/q3map2/q3map2.h

diff --combined Makefile
index 4f1fc2e8a270332a039e76ce816e2956381dfd69,f71d2784641d23adb2ef06e8a57be329e4222a89..82653f830236eae69fa45afa5dd729b04bcc9cce
+++ b/Makefile
@@@ -1,13 -1,3 +1,13 @@@
 +# TODO: when deleting this Makefile, don't forget to also delete conftest.cpp
 +# which is only required by this Makefile
 +
 +ifeq ($(I_KNOW_MAKEFILE_IS_DEPRECATED),)
 +    $(shell printf 'ERROR: Makefile build is deprecated, use CMake instead, see README.md\n\n' >&2)
 +    $(error I_KNOW_MAKEFILE_IS_DEPRECATED is not set)
 +else
 +    $(shell printf 'WARNING: deprecated Makefile build enforced\n\n' >&2)
 +endif
 +
  MAKEFILE_CONF      ?= Makefile.conf
  -include $(MAKEFILE_CONF)
  
@@@ -24,8 -14,6 +24,8 @@@ CXXFLAGS           ?
  CPPFLAGS           ?=
  LIBS               ?=
  RADIANT_ABOUTMSG   ?= Custom build
 +RADIANT_NAME       ?= NetRadiant
 +RADIANT_BASENAME   ?= netradiant
  
  # warning: this directory may NOT contain any files other than the ones written by this Makefile!
  # NEVER SET THIS TO A SYSTEM WIDE "bin" DIRECTORY!
@@@ -210,7 -198,7 +210,7 @@@ ifeq ($(OS),Linux
  else
  
  ifeq ($(OS),Win32)
 -      CPPFLAGS_COMMON += -DWIN32 -D_WIN32 -D_inline=inline
 +      CPPFLAGS_COMMON += -DWIN32 -D_WIN32 -D_inline=inline -DWORKAROUND_WINDOWS_FLOATING_WINDOW=1 -DWORKAROUND_WINDOWS_GTK2_GLWIDGET=1
        CFLAGS_COMMON += -mms-bitfields
        LDFLAGS_DLL = -Wl,--add-stdcall-alias
        LIBS_COMMON = -lws2_32 -luser32 -lgdi32 -lole32
@@@ -264,13 -252,16 +264,13 @@@ RADIANT_VERSION_NUMBER = $(RADIANT_MAJO
  RADIANT_VERSION = $(RADIANT_VERSION_NUMBER)n
  Q3MAP_VERSION = 2.5.17n
  
 -# Executable extension
 -RADIANT_EXECUTABLE := $(EXE)
 -
  GIT_VERSION := $(shell $(GIT) rev-parse --short HEAD $(STDERR_TO_DEVNULL))
  ifneq ($(GIT_VERSION),)
        RADIANT_VERSION := $(RADIANT_VERSION)-git-$(GIT_VERSION)
        Q3MAP_VERSION := $(Q3MAP_VERSION)-git-$(GIT_VERSION)
  endif
  
 -CPPFLAGS += -DRADIANT_VERSION="\"$(RADIANT_VERSION)\"" -DRADIANT_MAJOR_VERSION="\"$(RADIANT_MAJOR_VERSION)\"" -DRADIANT_MINOR_VERSION="\"$(RADIANT_MINOR_VERSION)\"" -DRADIANT_PATCH_VERSION="\"$(RADIANT_PATCH_VERSION)\"" -DRADIANT_ABOUTMSG="\"$(RADIANT_ABOUTMSG)\"" -DQ3MAP_VERSION="\"$(Q3MAP_VERSION)\"" -DRADIANT_EXECUTABLE="\"$(RADIANT_EXECUTABLE)\""
 +CPPFLAGS += -DRADIANT_VERSION="\"$(RADIANT_VERSION)\"" -DRADIANT_VERSION_STRING="\"$(RADIANT_VERSION_STRING)\"" -DRADIANT_ABOUTMSG="\"$(RADIANT_ABOUTMSG)\"" -DRADIANT_NAME="\"${RADIANT_NAME}\"" -DRADIANT_BASENAME="\"${RADIANT_BASENAME}\"" -DQ3MAP_VERSION="\"$(Q3MAP_VERSION)\""
  CPPFLAGS += -DGTK_TARGET=2
  
  .PHONY: all
@@@ -441,8 -432,8 +441,8 @@@ binaries-qdata3: 
  
  .PHONY: binaries-h2data
  binaries-h2data: \
 -      $(INSTALLDIR)/heretic2/h2data.$(EXE) \
 -      $(INSTALLDIR)/heretic2/h2data \
 +      $(INSTALLDIR)/h2data.$(EXE) \
 +      $(INSTALLDIR)/h2data \
  
  .PHONY: binaries-tools-quake3
  binaries-tools-quake3: \
@@@ -498,7 -489,7 +498,7 @@@ endi
  %.o: %.c $(if $(findstring $(DEPEND_ON_MAKEFILE),yes),$(wildcard Makefile*),) | dependencies-check
        $(CC) $< $(CFLAGS) $(CFLAGS_COMMON) $(CPPFLAGS_EXTRA) $(CPPFLAGS_COMMON) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@
  
+ $(INSTALLDIR)/q3map2.$(EXE): LDFLAGS_EXTRA := -Wl,--large-address-aware
  $(INSTALLDIR)/q3map2.$(EXE): LIBS_EXTRA := $(LIBS_XML) $(LIBS_GLIB) $(LIBS_PNG) $(LIBS_JPEG) $(LIBS_WEBP) $(LIBS_ZLIB)
  $(INSTALLDIR)/q3map2.$(EXE): CPPFLAGS_EXTRA := $(CPPFLAGS_XML) $(CPPFLAGS_GLIB) $(CPPFLAGS_PNG) $(CPPFLAGS_JPEG) $(CPPFLAGS_WEBP) -Itools/quake3/common -Ilibs -Iinclude
  $(INSTALLDIR)/q3map2.$(EXE): \
@@@ -1025,45 -1016,46 +1025,45 @@@ $(INSTALLDIR)/plugins/bkgrnd2d.$(DLL): 
        contrib/bkgrnd2d/dialog.o \
        contrib/bkgrnd2d/plugin.o \
  
 -$(INSTALLDIR)/heretic2/h2data.$(EXE): LIBS_EXTRA := $(LIBS_XML)
 -$(INSTALLDIR)/heretic2/h2data.$(EXE): CPPFLAGS_EXTRA := $(CPPFLAGS_XML) -Itools/quake2/qdata_heretic2/common -Itools/quake2/qdata_heretic2/qcommon -Itools/quake2/qdata_heretic2 -Itools/quake2/common -Ilibs -Iinclude
 -$(INSTALLDIR)/heretic2/h2data.$(EXE): \
 -      tools/quake2/qdata_heretic2/common/bspfile.o \
 -      tools/quake2/qdata_heretic2/common/cmdlib.o \
 -      tools/quake2/qdata_heretic2/common/inout.o \
 -      tools/quake2/qdata_heretic2/common/l3dslib.o \
 -      tools/quake2/qdata_heretic2/common/lbmlib.o \
 -      tools/quake2/qdata_heretic2/common/mathlib.o \
 -      tools/quake2/qdata_heretic2/common/md4.o \
 -      tools/quake2/qdata_heretic2/common/path_init.o \
 -      tools/quake2/qdata_heretic2/common/qfiles.o \
 -      tools/quake2/qdata_heretic2/common/scriplib.o \
 -      tools/quake2/qdata_heretic2/common/threads.o \
 -      tools/quake2/qdata_heretic2/common/token.o \
 -      tools/quake2/qdata_heretic2/common/trilib.o \
 -      tools/quake2/qdata_heretic2/qcommon/reference.o \
 -      tools/quake2/qdata_heretic2/qcommon/resourcemanager.o \
 -      tools/quake2/qdata_heretic2/qcommon/skeletons.o \
 -      tools/quake2/qdata_heretic2/animcomp.o \
 -      tools/quake2/qdata_heretic2/book.o \
 -      tools/quake2/qdata_heretic2/fmodels.o \
 -      tools/quake2/qdata_heretic2/images.o \
 -      tools/quake2/qdata_heretic2/jointed.o \
 -      tools/quake2/qdata_heretic2/models.o \
 -      tools/quake2/qdata_heretic2/pics.o \
 -      tools/quake2/qdata_heretic2/qdata.o \
 -      tools/quake2/qdata_heretic2/qd_skeletons.o \
 -      tools/quake2/qdata_heretic2/sprites.o \
 -      tools/quake2/qdata_heretic2/svdcmp.o \
 -      tools/quake2/qdata_heretic2/tables.o \
 -      tools/quake2/qdata_heretic2/tmix.o \
 -      tools/quake2/qdata_heretic2/video.o \
 +$(INSTALLDIR)/h2data.$(EXE): LIBS_EXTRA := $(LIBS_XML)
 +$(INSTALLDIR)/h2data.$(EXE): CPPFLAGS_EXTRA := $(CPPFLAGS_XML) -Itools/heretic2/common -Itools/heretic2/qcommon -Itools/heretic2/h2data -Itools/quake2/common -Ilibs -Iinclude
 +$(INSTALLDIR)/h2data.$(EXE): \
 +      tools/heretic2/common/bspfile.o \
 +      tools/heretic2/common/cmdlib.o \
 +      tools/heretic2/common/inout.o \
 +      tools/heretic2/common/l3dslib.o \
 +      tools/heretic2/common/lbmlib.o \
 +      tools/heretic2/common/mathlib.o \
 +      tools/heretic2/common/md4.o \
 +      tools/heretic2/common/path_init.o \
 +      tools/heretic2/common/qfiles.o \
 +      tools/heretic2/common/scriplib.o \
 +      tools/heretic2/common/threads.o \
 +      tools/heretic2/common/token.o \
 +      tools/heretic2/common/trilib.o \
 +      tools/heretic2/qcommon/reference.o \
 +      tools/heretic2/qcommon/resourcemanager.o \
 +      tools/heretic2/qcommon/skeletons.o \
 +      tools/heretic2/h2data/animcomp.o \
 +      tools/heretic2/h2data/book.o \
 +      tools/heretic2/h2data/fmodels.o \
 +      tools/heretic2/h2data/images.o \
 +      tools/heretic2/h2data/jointed.o \
 +      tools/heretic2/h2data/models.o \
 +      tools/heretic2/h2data/pics.o \
 +      tools/heretic2/h2data/qdata.o \
 +      tools/heretic2/h2data/qd_skeletons.o \
 +      tools/heretic2/h2data/sprites.o \
 +      tools/heretic2/h2data/svdcmp.o \
 +      tools/heretic2/h2data/tables.o \
 +      tools/heretic2/h2data/tmix.o \
 +      tools/heretic2/h2data/video.o \
        libl_net.$(A) \
        $(if $(findstring $(OS),Win32),icons/h2data.o,) \
  
  .PHONY: install-data
  install-data: binaries
 -      $(MKDIR) $(INSTALLDIR)/games
 -      DOWNLOAD_GAMEPACKS="$(DOWNLOAD_GAMEPACKS)" DOWNLOADDIR="$(DOWNLOADDIR)" INSTALLDIR="$(INSTALLDIR)" GIT="$(GIT)" SVN="$(SVN)" WGET="$(WGET)" RM_R="$(RM_R)" MV="$(MV)" UNZIPPER="$(UNZIPPER)" ECHO="$(ECHO)" SH="$(SH)" CP="$(CP)" CP_R="$(CP_R)" $(SH) gamepack-manager
 +      DOWNLOAD_GAMEPACKS="$(DOWNLOAD_GAMEPACKS)" DOWNLOADDIR="$(DOWNLOADDIR)" INSTALLDIR="$(INSTALLDIR)/gamepacks" GIT="$(GIT)" SVN="$(SVN)" WGET="$(WGET)" RM_R="$(RM_R)" MV="$(MV)" UNZIPPER="$(UNZIPPER)" ECHO="$(ECHO)" CP="$(CP)" CP_R="$(CP_R)" ./gamepack-manager
        $(ECHO) $(RADIANT_MAJOR_VERSION) > $(INSTALLDIR)/RADIANT_MAJOR
        $(ECHO) $(RADIANT_MINOR_VERSION) > $(INSTALLDIR)/RADIANT_MINOR
        $(ECHO) $(RADIANT_PATCH_VERSION) > $(INSTALLDIR)/RADIANT_PATCH
diff --combined radiant/brushmanip.cpp
index 77baf50e40a55041a3654ead1ce92410fc56a3f2,d73450a5cc330e5a59c40c47f0a469f7b4877ee4..d424bb2be84874bb3ae9b3a52aa20731457cfc68
@@@ -895,15 -895,15 +895,18 @@@ filter_brush_any_face g_filter_brush_li
  filter_face_shader g_filter_face_hint( "textures/common/hint" );
  filter_brush_any_face g_filter_brush_hint( &g_filter_face_hint );
  
+ filter_face_shader g_filter_face_hintlocal( "textures/common/hintlocal" );
+ filter_brush_any_face g_filter_brush_hintlocal( &g_filter_face_hintlocal );
  filter_face_shader g_filter_face_hint_q2( "textures/hint" );
  filter_brush_any_face g_filter_brush_hint_q2( &g_filter_face_hint_q2 );
  
  filter_face_shader g_filter_face_hint_ja( "textures/system/hint" );
  filter_brush_any_face g_filter_brush_hint_ja( &g_filter_face_hint_ja );
  
 +filter_face_shader g_filter_face_subtlehint( "textures/common/subtlehint" );
 +filter_brush_any_face g_filter_brush_subtlehint( &g_filter_face_subtlehint );
 +
  filter_face_shader g_filter_face_areaportal( "textures/common/areaportal" );
  filter_brush_all_faces g_filter_brush_areaportal( &g_filter_face_areaportal );
  
@@@ -939,9 -939,9 +942,10 @@@ void BrushFilters_construct()
        add_face_filter( g_filter_face_caulk_ja, EXCLUDE_CAULK );
        add_brush_filter( g_filter_brush_liquids, EXCLUDE_LIQUIDS );
        add_brush_filter( g_filter_brush_hint, EXCLUDE_HINTSSKIPS );
+       add_brush_filter( g_filter_brush_hintlocal, EXCLUDE_HINTSSKIPS );
        add_brush_filter( g_filter_brush_hint_q2, EXCLUDE_HINTSSKIPS );
        add_brush_filter( g_filter_brush_hint_ja, EXCLUDE_HINTSSKIPS );
 +      add_brush_filter( g_filter_brush_subtlehint, EXCLUDE_HINTSSKIPS );
        add_brush_filter( g_filter_brush_clusterportal, EXCLUDE_CLUSTERPORTALS );
        add_brush_filter( g_filter_brush_visportal, EXCLUDE_VISPORTALS );
        add_brush_filter( g_filter_brush_areaportal, EXCLUDE_AREAPORTALS );
index a5032b7bef670c07528f8a6a78ec301d27e4e41f,1ed218963b8e47feec10b87bebc9a8e429c30361..0f62ba14bf5e14124db5312ae6197c5a414ce171
@@@ -319,6 -319,10 +319,10 @@@ void ProcessWorldModel( const char *por
        /* check for patches with adjacent edges that need to lod together */
        PatchMapDrawSurfs( e );
  
+       if ( debugClip ) {
+               AddTriangleModels( e );
+       }
        /* build an initial bsp tree using all of the sides of all of the structural brushes */
        faces = MakeStructuralBSPFaceList( entities[ 0 ].brushes );
        tree = FaceBSP( faces );
                Sys_FPrintf( SYS_NOXML, "**********************\n" );
                polyline = LeakFile( tree, lineFilePath );
                leaknode = xmlNewNode( NULL, (xmlChar*)"message" );
 -              xmlNodeSetContent( leaknode, (xmlChar*)"MAP LEAKED\n" );
 +              xmlNodeAddContent( leaknode, (xmlChar*)"MAP LEAKED\n" );
                xmlAddChild( leaknode, polyline );
                level[0] = (int) '0' + SYS_ERR;
                level[1] = 0;
        FloodAreas( tree );
  
        /* create drawsurfs for triangle models */
-       AddTriangleModels( e );
+       if ( !debugClip ) {
+               AddTriangleModels( e );
+       }
  
        /* create drawsurfs for surface models */
        AddEntitySurfaceModels( e );
@@@ -708,17 -714,14 +714,17 @@@ int BSPMain( int argc, char **argv )
        portalFilePath[0] = 0;
        surfaceFilePath[0] = 0;
  
 +      if ( argc >= 2 && !strcmp( argv[ 1 ], "-bsp" ) ) {
 +              argv++;
 +              argc--;
 +      }
  
        /* note it */
        Sys_Printf( "--- BSP ---\n" );
  
        doingBSP = qtrue;
        SetDrawSurfacesBuffer();
 -      mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
 -      memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
 +      mapDrawSurfs = safe_malloc0( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
        numMapDrawSurfs = 0;
  
        tempSource[ 0 ] = '\0';
                        i++;
                        Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
                }
 -              else if ( !strcmp( argv[ i ],  "-mv" ) ) {
 +              else if ( !strcmp( argv[ i ], "-fastmeta" ) ) {
 +                      maxLMSurfaceVerts = 64;
 +                      maxSurfaceVerts = 999;
 +                      maxSurfaceIndexes = 6000;
 +                      Sys_Printf( "Maximum per-surface vertex count set to %d\n", maxSurfaceVerts );
 +                      Sys_Printf( "Maximum per-surface index count set to %d\n", maxSurfaceIndexes );
 +                      Sys_Printf( "Maximum lightmapped surface vertex count set to %d\n", maxLMSurfaceVerts );
 +              }
 +              else if ( !strcmp( argv[ i ], "-maxsurfacevertices" ) ) {
 +                      maxSurfaceVerts = atoi( argv[ i + 1 ] );
 +                      if ( maxSurfaceVerts < 3 ) {
 +                              maxSurfaceVerts = 3;
 +                      }
 +                      i++;
 +                      Sys_Printf( "Maximum per-surface vertex count set to %d\n", maxSurfaceVerts );
 +              }
 +              else if ( !strcmp( argv[ i ], "-maxsurfaceindexes" ) || !strcmp( argv[ i ], "-mi" ) ) {
 +                      maxSurfaceIndexes = atoi( argv[ i + 1 ] );
 +                      if ( maxSurfaceIndexes < 3 ) {
 +                              maxSurfaceIndexes = 3;
 +                      }
 +                      i++;
 +
 +                      if ( !strcmp( argv[ i ], "-mi" ) ) {
 +                              Sys_Printf( "The -mi argument is deprecated, use \"-maxsurfaceindexes\" instead\n" );
 +                      }
 +                      else {
 +                              Sys_Printf( "Maximum per-surface index count set to %d\n", maxSurfaceIndexes );
 +                      }
 +              }
 +              else if ( !strcmp( argv[ i ], "-maxlightmapvertices" ) || !strcmp( argv[ i ], "-mv" ) ) {
                        maxLMSurfaceVerts = atoi( argv[ i + 1 ] );
                        if ( maxLMSurfaceVerts < 3 ) {
                                maxLMSurfaceVerts = 3;
                                maxSurfaceVerts = maxLMSurfaceVerts;
                        }
                        i++;
 +
 +                      if ( !strcmp( argv[ i ], "-mv" ) ) {
 +                              Sys_Printf( "The -mv argument is deprecated, use \"-maxlightmapvertices\" instead\n" );
 +                      }
 +                      else {
                        Sys_Printf( "Maximum lightmapped surface vertex count set to %d\n", maxLMSurfaceVerts );
                }
 -              else if ( !strcmp( argv[ i ],  "-mi" ) ) {
 -                      maxSurfaceIndexes = atoi( argv[ i + 1 ] );
 -                      if ( maxSurfaceIndexes < 3 ) {
 -                              maxSurfaceIndexes = 3;
 -                      }
 -                      i++;
 -                      Sys_Printf( "Maximum per-surface index count set to %d\n", maxSurfaceIndexes );
                }
                else if ( !strcmp( argv[ i ], "-np" ) ) {
                        npDegrees = atof( argv[ i + 1 ] );
                        Sys_Printf( "Debug portal surfaces enabled\n" );
                        debugPortals = qtrue;
                }
+               else if ( !strcmp( argv[ i ], "-debugclip" ) ) {
+                       Sys_Printf( "Debug model clip enabled\n" );
+                       debugClip = qtrue;
+               }
+               else if ( !strcmp( argv[ i ], "-snapmodelclip" ) ) {
+                       Sys_Printf( "Snapping model clip enabled\n" );
+                       snapModelClip = qtrue;
+               }
                else if ( !strcmp( argv[ i ], "-sRGBtex" ) ) {
                        texturesRGB = qtrue;
                        Sys_Printf( "Textures are in sRGB\n" );
                else if ( !strcmp( argv[ i ], "-bspfile" ) )
                {
                        strcpy( BSPFilePath, argv[i + 1] );
 +                      argv[ i ] = NULL;
                        i++;
 +                      argv[ i ] = NULL;
                        Sys_Printf( "Use %s as bsp file\n", BSPFilePath );
                }
                else if ( !strcmp( argv[ i ], "-linfile" ) )
                {
                        strcpy( lineFilePath, argv[i + 1] );
 +                      argv[ i ] = NULL;
                        i++;
 +                      argv[ i ] = NULL;
                        Sys_Printf( "Use %s as line file\n", lineFilePath );
                }
                else if ( !strcmp( argv[ i ], "-prtfile" ) )
                {
                        strcpy( portalFilePath, argv[i + 1] );
 +                      argv[ i ] = NULL;
                        i++;
 +                      argv[ i ] = NULL;
                        Sys_Printf( "Use %s as portal file\n", portalFilePath );
                }
                else if ( !strcmp( argv[ i ], "-srffile" ) )
                {
                        strcpy( surfaceFilePath, argv[i + 1] );
 +                      argv[ i ] = NULL;
                        i++;
 +                      argv[ i ] = NULL;
                        Sys_Printf( "Use %s as surface file\n", surfaceFilePath );
                }
 -              else if ( !strcmp( argv[ i ], "-bsp" ) ) {
 -                      Sys_Printf( "-bsp argument unnecessary\n" );
 -              }
                else if ( !strcmp( argv[ i ], "-noob" ) ) {
                        Sys_Printf( "No oBs!\n" );
                        noob = qtrue;
index dd5554f81fd24db4d2eaeca9dbfbd93420594723,a99dbd9c2da1a1adce4a14c9cd7ee3e3a076998c..1d8cfb5e2a574afb189f205369ab33a32c90281f
@@@ -107,7 -107,8 +107,7 @@@ static void CreateSunLight( sun_t *sun 
  
                /* create a light */
                numSunLights++;
 -              light = safe_malloc( sizeof( *light ) );
 -              memset( light, 0, sizeof( *light ) );
 +              light = safe_malloc0( sizeof( *light ) );
                light->next = lights;
                lights = light;
  
@@@ -253,7 -254,8 +253,7 @@@ void CreateEntityLights( void )
  
                /* create a light */
                numPointLights++;
 -              light = safe_malloc( sizeof( *light ) );
 -              memset( light, 0, sizeof( *light ) );
 +              light = safe_malloc0( sizeof( *light ) );
                light->next = lights;
                lights = light;
  
@@@ -590,7 -592,8 +590,7 @@@ void CreateSurfaceLights( void )
                        VectorScale( origin, 0.5f, origin );
  
                        /* create a light */
 -                      light = safe_malloc( sizeof( *light ) );
 -                      memset( light, 0, sizeof( *light ) );
 +                      light = safe_malloc0( sizeof( *light ) );
                        light->next = lights;
                        lights = light;
  
@@@ -717,7 -720,7 +717,7 @@@ float PointToPolygonFormFactor( const v
        for ( i = 0; i < w->numpoints; i++ )
        {
                VectorSubtract( w->p[ i ], point, dirs[ i ] );
-               VectorNormalize( dirs[ i ], dirs[ i ] );
+               VectorFastNormalize( dirs[ i ], dirs[ i ] );
        }
  
        /* duplicate first vertex to avoid mod operation */
                angle = acos( dot );
  
                CrossProduct( dirs[ i ], dirs[ j ], triVector );
-               if ( VectorNormalize( triVector, triNormal ) < 0.0001f ) {
+               if ( VectorFastNormalize( triVector, triNormal ) < 0.0001f ) {
                        continue;
                }
  
@@@ -1771,17 -1774,7 +1771,17 @@@ void TraceGrid( int num )
                        }
  
                /* vortex: apply gridscale and gridambientscale here */
 -              ColorToBytes( color, bgp->ambient[ i ], gridScale * gridAmbientScale );
 +              if (gp->directed[i][0] || gp->directed[i][1] || gp->directed[i][2]) {
 +                      /*
 +                       * HACK: if there's a non-zero directed component, this
 +                       * lightgrid cell is useful. However, ioq3 skips grid
 +                       * cells with zero ambient. So let's force ambient to be
 +                       * nonzero unless directed is zero too.
 +                       */
 +                      ColorToBytesNonZero(color, bgp->ambient[i], gridScale * gridAmbientScale);
 +              } else {
 +                      ColorToBytes(color, bgp->ambient[i], gridScale * gridAmbientScale);
 +              }
                ColorToBytes( gp->directed[ i ], bgp->directed[ i ], gridScale );
        }
  
@@@ -1864,12 -1857,14 +1864,12 @@@ void SetupGrid( void )
        numBSPGridPoints = numRawGridPoints;
  
        /* allocate lightgrid */
 -      rawGridPoints = safe_malloc( numRawGridPoints * sizeof( *rawGridPoints ) );
 -      memset( rawGridPoints, 0, numRawGridPoints * sizeof( *rawGridPoints ) );
 +      rawGridPoints = safe_malloc0( numRawGridPoints * sizeof( *rawGridPoints ) );
  
        if ( bspGridPoints != NULL ) {
                free( bspGridPoints );
        }
 -      bspGridPoints = safe_malloc( numBSPGridPoints * sizeof( *bspGridPoints ) );
 -      memset( bspGridPoints, 0, numBSPGridPoints * sizeof( *bspGridPoints ) );
 +      bspGridPoints = safe_malloc0( numBSPGridPoints * sizeof( *bspGridPoints ) );
  
        /* clear lightgrid */
        for ( i = 0; i < numRawGridPoints; i++ )
     does what it says...
   */
  
 -void LightWorld( const char *BSPFilePath, qboolean fastAllocate ){
 +void LightWorld( const char *BSPFilePath, qboolean fastAllocate, qboolean noBounceStore ){
        vec3_t color;
        float f;
        int b, bt;
        qboolean minVertex, minGrid;
        const char  *value;
  
 -
        /* ydnar: smooth normals */
        if ( shade ) {
                Sys_Printf( "--- SmoothNormals ---\n" );
        /* radiosity */
        b = 1;
        bt = bounce;
 +
        while ( bounce > 0 )
        {
 +              qboolean storeForReal = !noBounceStore;
 +
                /* store off the bsp between bounces */
 -              StoreSurfaceLightmaps( fastAllocate );
 +              StoreSurfaceLightmaps( fastAllocate, storeForReal );
                UnparseEntities();
 -              Sys_Printf( "Writing %s\n", BSPFilePath );
 -              WriteBSPFile( BSPFilePath );
 +
 +              if ( storeForReal ) {
 +                      Sys_Printf( "Writing %s\n", BSPFilePath );
 +                      WriteBSPFile( BSPFilePath );
 +              }
  
                /* note it */
                Sys_Printf( "\n--- Radiosity (bounce %d of %d) ---\n", b, bt );
                SetupEnvelopes( qfalse, fastbounce );
                if ( numLights == 0 ) {
                        Sys_Printf( "No diffuse light to calculate, ending radiosity.\n" );
 +                      if ( noBounceStore ) {
 +                              break;
 +                      }
                        return;
                }
  
                bounce--;
                b++;
        }
 +
        /* ydnar: store off lightmaps */
 -      StoreSurfaceLightmaps( fastAllocate );
 +      StoreSurfaceLightmaps( fastAllocate, qtrue );
 +}
 +
 +
 +
 +/*
 +   LoadSurfaceFlags()
 +   added by spoon to get back the changed surfaceflags
 +   from tex file
 +*/
 +
 +void LoadSurfaceFlags( char *filename ) {
 +      int i;
 +
 +      for( i = 0; i < numBSPShaders; i++ ) {
 +              shaderInfo_t *si;
 +
 +              si = ShaderInfoForShader( bspShaders[i].shader );
 +
 +              bspShaders[ i ].surfaceFlags = si->surfaceFlags;
 +      }
  }
  
  
@@@ -2154,7 -2120,6 +2154,7 @@@ int LightMain( int argc, char **argv )
        int lightmapMergeSize = 0;
        qboolean lightSamplesInsist = qfalse;
        qboolean fastAllocate = qfalse;
 +      qboolean noBounceStore = qfalse;
  
        /* note it */
        Sys_Printf( "--- Light ---\n" );
                        Sys_Printf( "No lightmaps yo\n" );
                }
  
+               else if ( !strcmp( argv[ i ], "-bouncecolorratio" ) ) {
+                       f = atof( argv[ i + 1 ] );
+                       bounceColorRatio *= f;
+                       if ( bounceColorRatio > 1 ) {
+                               bounceColorRatio = 1;
+                       }
+                       if ( bounceColorRatio < 0 ) {
+                               bounceColorRatio = 0;
+                       }
+                       Sys_Printf( "Bounce color ratio set to %f\n", bounceColorRatio );
+                       i++;
+               }
                else if ( !strcmp( argv[ i ], "-bouncescale" ) ) {
                        f = atof( argv[ i + 1 ] );
                        bounceScale *= f;
  
                else if ( !strcmp( argv[ i ], "-lightmapdir" ) ) {
                        lmCustomDir = argv[i + 1];
 +                      argv[ i ] = NULL;
                        i++;
 +                      argv[ i ] = NULL;
                        Sys_Printf( "Lightmap directory set to %s\n", lmCustomDir );
                        externalLightmaps = qtrue;
                        Sys_Printf( "Storing all lightmaps externally\n" );
                        Sys_Printf( "Storing bounced light (radiosity) only\n" );
                }
  
 +              else if ( !strcmp( argv[ i ], "-nobouncestore" ) ) {
 +                      noBounceStore = qtrue;
 +                      Sys_Printf( "Do not store BSP, lightmap and shader files between bounces\n" );
 +              }
 +
                else if ( !strcmp( argv[ i ], "-nocollapse" ) ) {
                        noCollapse = qtrue;
                        Sys_Printf( "Identical lightmap collapsing disabled\n" );
                        Sys_Printf( "Faster mode enabled\n" );
                }
  
 -              else if ( !strcmp( argv[ i ], "-fastallocate" ) ) {
 +              else if ( !strcmp( argv[ i ], "-fastallocate" ) || !strcmp( argv[ i ], "-fastlightmapsearch" ) ) {
                        fastAllocate = qtrue;
 -                      Sys_Printf( "Fast allocation mode enabled\n" );
 +
 +                      if ( !strcmp( argv[ i ], "-fastlightmapsearch" ) ) {
 +                              Sys_Printf( "The -fastlightmapsearch argument is deprecated, use \"-fastallocate\" instead\n" );
 +                      }
 +                      else {
 +                              Sys_Printf( "Fast lightmap allocation mode enabled\n" );
 +                      }
 +              }
 +
 +              else if ( !strcmp( argv[ i ], "-slowallocate" ) ) {
 +                      fastAllocate = qfalse;
 +                      Sys_Printf( "Slow lightmap allocation mode enabled (default)\n" );
                }
  
                else if ( !strcmp( argv[ i ], "-fastgrid" ) ) {
                        if ( ( atof( argv[ i + 1 ] ) != 0 ) && ( atof( argv[ i + 1 ] )) < 1 ) {
                                noVertexLighting = ( atof( argv[ i + 1 ] ) );
                                i++;
-                               Sys_Printf( "Setting vertex lighting globally to %d\n", noVertexLighting );
+                               Sys_Printf( "Setting vertex lighting globally to %f\n", noVertexLighting );
                        }
                        else{
                                Sys_Printf( "Disabling vertex lighting\n" );
                else if ( !strcmp( argv[ i ], "-bspfile" ) )
                {
                        strcpy( BSPFilePath, argv[i + 1] );
 +                      argv[ i ] = NULL;
                        i++;
 +                      argv[ i ] = NULL;
                        Sys_Printf( "Use %s as bsp file\n", BSPFilePath );
                }
                else if ( !strcmp( argv[ i ], "-srffile" ) )
                {
                        strcpy( surfaceFilePath, argv[i + 1] );
 +                      argv[ i ] = NULL;
                        i++;
 +                      argv[ i ] = NULL;
                        Sys_Printf( "Use %s as surface file\n", surfaceFilePath );
                }
                /* unhandled args */
                Sys_Printf( "Restricted lightmap searching enabled - block size adjusted to %d\n", lightmapSearchBlockSize );
        }
  
 +      /* arg checking */
 +      if ( i != ( argc - 1 ) ) {
 +              Error( "usage: q3map -light [options] <bspfile>" );
 +      }
 +
        strcpy( source, ExpandArg( argv[ i ] ) );
        StripExtension( source );
        DefaultExtension( source, ".map" );
        SetupTraceNodes();
  
        /* light the world */
 -      LightWorld( BSPFilePath, fastAllocate );
 +      LightWorld( BSPFilePath, fastAllocate, noBounceStore );
  
        /* write out the bsp */
        UnparseEntities();
index 3245ad5380a473f465ef94da5e42143b00afc9cb,d1b3fbd24be03c629ca15b7700c98a40f41ccd12..18d1f0a4c236650d2de4e718fe58ca581efdde24
@@@ -195,23 -195,6 +195,23 @@@ static void RadClipWindingEpsilon( radW
  
  
  
 +/*
 +   Modulo1IfNegative()
 +   Previously the bias computation was doing:
 +
 +      while ( f < 0.0f ) {
 +         f += 1.0f;
 +      }
 +
 +   That may end in infinite loop in some case.
 +   It may also be slower because of useless loops.
 +   I don't know what that computation is for.
 +   -- illwieckz
 +*/
 +float Modulo1IfNegative( float f ){
 +      return f < 0.0f ? f - floor( f ) : f;
 +}
 +
  
  
  /*
   */
  
  qboolean RadSampleImage( byte *pixels, int width, int height, float st[ 2 ], float color[ 4 ] ){
 -      float sto[ 2 ];
        int x, y;
  
 -
        /* clear color first */
        color[ 0 ] = color[ 1 ] = color[ 2 ] = color[ 3 ] = 255;
  
                return qfalse;
        }
  
 -      /* bias st */
 -      sto[ 0 ] = st[ 0 ];
 -      while ( sto[ 0 ] < 0.0f )
 -              sto[ 0 ] += 1.0f;
 -      sto[ 1 ] = st[ 1 ];
 -      while ( sto[ 1 ] < 0.0f )
 -              sto[ 1 ] += 1.0f;
 -
        /* get offsets */
 -      x = ( (float) width * sto[ 0 ] ) + 0.5f;
 +      x = ( (float) width * Modulo1IfNegative( st[ 0 ] ) ) + 0.5f;
        x %= width;
 -      y = ( (float) height * sto[ 1 ] )  + 0.5f;
 +      y = ( (float) height * Modulo1IfNegative( st[ 1 ] ) ) + 0.5f;
        y %= height;
  
        /* get pixel */
  #define SAMPLE_GRANULARITY  6
  
  static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm, shaderInfo_t *si, radWinding_t *rw, vec3_t average, vec3_t gradient, int *style ){
-       int i, j, k, l, v, x, y, samples;
+       int i, j, k, l, v, x, y, samples, avgcolor;
        vec3_t color, mins, maxs;
        vec4_t textureColor;
        float alpha, alphaI, bf;
                                VectorCopy( si->averageColor, textureColor );
                                textureColor[ 4 ] = 255.0f;
                        }
+                       avgcolor = ( textureColor[ 0 ] + textureColor[ 1 ] + textureColor[ 2 ] ) / 3;
                        for ( i = 0; i < 3; i++ )
-                               color[ i ] = ( textureColor[ i ] / 255 ) * ( rw->verts[ samples ].color[ lightmapNum ][ i ] / 255.0f );
+                               color[ i ] = ( ( textureColor[ i ] * bounceColorRatio + ( avgcolor * ( 1 - bounceColorRatio ) ) ) / 255 ) * ( rw->verts[ samples ].color[ lightmapNum ][ i ] / 255.0f );
+ //                            color[ i ] = ( textureColor[ i ] / 255 ) * ( rw->verts[ samples ].color[ lightmapNum ][ i ] / 255.0f );
  
                        AddPointToBounds( color, mins, maxs );
                        VectorAdd( average, color, average );
                                                        VectorCopy( si->averageColor, textureColor );
                                                        textureColor[ 4 ] = 255;
                                                }
-                                               for ( i = 0; i < 3; i++ )
-                                                       color[ i ] = ( textureColor[ i ] / 255 ) * ( radLuxel[ i ] / 255 );
+                                               avgcolor = ( textureColor[ 0 ] + textureColor[ 1 ] + textureColor[ 2 ] ) / 3;
+                                               for ( l = 0; l < 3; l++ ){
+                                                       color[ l ] = ( ( textureColor[ l ] * bounceColorRatio + ( avgcolor * ( 1 - bounceColorRatio ) ) ) / 255 ) * ( radLuxel[ l ] / 255 );
+                                               //Sys_Printf( "%i %i %i %i %i \n", (int) textureColor[ 0 ], (int) textureColor[ 1 ], (int) textureColor[ 2 ], (int) avgcolor, (int) color[ i ] );
+                                               }
                                                AddPointToBounds( color, mins, maxs );
                                                VectorAdd( average, color, average );
  
@@@ -539,7 -536,8 +543,7 @@@ static void RadSubdivideDiffuseLight( i
        }
  
        /* create a light */
 -      light = safe_malloc( sizeof( *light ) );
 -      memset( light, 0, sizeof( *light ) );
 +      light = safe_malloc0( sizeof( *light ) );
  
        /* attach it */
        ThreadLock();
                /* optionally create a point splashsplash light for first pass */
                if ( original && si->backsplashFraction > 0 ) {
                        /* allocate a new point light */
 -                      splash = safe_malloc( sizeof( *splash ) );
 -                      memset( splash, 0, sizeof( *splash ) );
 +                      splash = safe_malloc0( sizeof( *splash ) );
                        splash->next = lights;
                        lights = splash;
  
index 5336c9c5bc0ce96be089b78c0a25cc2a50c98b54,8bfb5b044eb5f98b18599ccb88df2f319553e46a..08d0a56899bf74c98c7319115220a353696b7c7f
@@@ -237,7 -237,7 +237,7 @@@ qboolean SnapNormal( vec3_t normal )
     snaps a plane to normal/distance epsilons
   */
  
- void SnapPlane( vec3_t normal, vec_t *dist, vec3_t center ){
+ void SnapPlane( vec3_t normal, vec_t *dist ){
  // SnapPlane disabled by LordHavoc because it often messes up collision
  // brushes made from triangles of embedded models, and it has little effect
  // on anything else (axial planes are usually derived from snapped points)
@@@ -326,7 -326,12 +326,12 @@@ int FindFloatPlane( vec3_t innormal, ve
  
        VectorCopy( innormal, normal );
  #if Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX
-       SnapPlaneImproved( normal, &dist, numPoints, (const vec3_t *) points );
+       if ( !doingModelClip ) {
+               SnapPlaneImproved( normal, &dist, numPoints, (const vec3_t *) points );
+       }
+       if ( doingModelClip && snapModelClip ) {
+               SnapPlane( normal, &dist );
+       }
  #else
        SnapPlane( normal, &dist );
  #endif
@@@ -1523,7 -1528,8 +1528,7 @@@ void LoadEntityIndexMap( entity_t *e )
        }
  
        /* create a new index map */
 -      im = safe_malloc( sizeof( *im ) );
 -      memset( im, 0, sizeof( *im ) );
 +      im = safe_malloc0( sizeof( *im ) );
  
        /* set it up */
        im->w = w;
index 1b88f3273b4b32c2758034a16ef008ac26d686cb,1343ac049b2895a8e6a10ec12e49354391e6676a..8f70094a89ba1f6bef39a15a63e4ed8357b2dc83
@@@ -449,10 -449,12 +449,10 @@@ void InsertModel( const char *name, in
  
                /* set particulars */
                ds->numVerts = PicoGetSurfaceNumVertexes( surface );
 -              ds->verts = safe_malloc( ds->numVerts * sizeof( ds->verts[ 0 ] ) );
 -              memset( ds->verts, 0, ds->numVerts * sizeof( ds->verts[ 0 ] ) );
 +              ds->verts = safe_malloc0( ds->numVerts * sizeof( ds->verts[ 0 ] ) );
  
                ds->numIndexes = PicoGetSurfaceNumIndexes( surface );
 -              ds->indexes = safe_malloc( ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
 -              memset( ds->indexes, 0, ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
 +              ds->indexes = safe_malloc0( ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
  
                /* copy vertexes */
                for ( i = 0; i < ds->numVerts; i++ )
                                                /* set up brush sides */
                                                buildBrush->numsides = 5;
                                                buildBrush->sides[ 0 ].shaderInfo = si;
-                                               for ( j = 1; j < buildBrush->numsides; j++ )
-                                                       buildBrush->sides[ j ].shaderInfo = NULL;  // don't emit these faces as draw surfaces, should make smaller BSPs; hope this works
+                                               for ( j = 1; j < buildBrush->numsides; j++ ) {
+                                                       if ( debugClip ) {
+                                                               buildBrush->sides[ 0 ].shaderInfo = ShaderInfoForShader( "debugclip2" );
+                                                               buildBrush->sides[ j ].shaderInfo = ShaderInfoForShader( "debugclip" );
+                                                       }
+                                                       else {
+                                                               buildBrush->sides[ j ].shaderInfo = NULL;  // don't emit these faces as draw surfaces, should make smaller BSPs; hope this works
+                                                       }
+                                               }
  
                                                buildBrush->sides[ 0 ].planenum = FindFloatPlane( plane, plane[ 3 ], 3, points );
                                                buildBrush->sides[ 1 ].planenum = FindFloatPlane( pa, pa[ 3 ], 2, &points[ 1 ] ); // pa contains points[1] and points[2]
@@@ -712,6 -721,8 +719,8 @@@ void AddTriangleModels( entity_t *e )
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- AddTriangleModels ---\n" );
  
+       doingModelClip = qtrue;
        /* get current brush entity targetname */
        if ( e == entities ) {
                targetName = "";
                        remap = remap2;
                }
        }
+       doingModelClip = qfalse;
  }
index 267a0e6601651f7e07b9174924acdf0d4f9932f3,7f132007ca33ed057b6f0ba3bd853b7999fdcd3f..509cb9270ec810ab8a91cda1ce01e665a180d806
     ------------------------------------------------------------------------------- */
  
  /* platform-specific */
 -#if GDEF_OS_LINUX || GDEF_OS_MACOS
 -      #define Q_UNIX
 -#endif
 -
 -#ifdef Q_UNIX
 +#if GDEF_OS_POSIX
        #include <unistd.h>
        #include <pwd.h>
        #include <limits.h>
@@@ -62,6 -66,8 +62,6 @@@
  
  
  /* general */
 -#include "version.h"            /* ttimo: might want to guard that if built outside of the GtkRadiant tree */
 -
  #include "cmdlib.h"
  #include "mathlib.h"
  #include "md5lib.h"
  
     ------------------------------------------------------------------------------- */
  
 -#define MAC_STATIC_HACK         0
 -#if GDEF_OS_MACOS && MAC_STATIC_HACK
 -      #define MAC_STATIC          static
 -#else
 -      #define MAC_STATIC
 -#endif
 -
 -#if 1
        #if GDEF_OS_WINDOWS
                #define Q_stricmp           stricmp
                #define Q_strncasecmp       strnicmp
                #define Q_stricmp           strcasecmp
                #define Q_strncasecmp       strncasecmp
        #endif
 +
 +// hack to declare and define in the same file
 +#ifdef MAIN_C
 +      #define Q_EXTERN
 +      #define Q_ASSIGN( a )   = a
 +#else
 +      #define Q_EXTERN extern
 +      #define Q_ASSIGN( a )
  #endif
  
  /* macro version */
  /* general */
  #define MAX_QPATH               64
  
 -#define MAX_IMAGES              512
 +#define MAX_IMAGES              2048
  #define DEFAULT_IMAGE           "*default"
  
 -#define MAX_MODELS              512
 +#define MAX_MODELS              2048
  
  #define DEF_BACKSPLASH_FRACTION 0.05f   /* 5% backsplash by default */
  #define DEF_BACKSPLASH_DISTANCE 23
  #define C_DETAIL                0x08000000  /* THIS MUST BE THE SAME AS IN RADIANT! */
  
  
 +/* new tex surface flags, like Smokin'Guns */
 +#define TEX_SURF_METAL             0x00001000
 +#define TEX_SURF_WOOD              0x00080000
 +#define TEX_SURF_CLOTH             0x00100000
 +#define TEX_SURF_DIRT              0x00200000
 +#define TEX_SURF_GLASS             0x00400000
 +#define TEX_SURF_PLANT             0x00800000
 +#define TEX_SURF_SAND              0x01000000
 +#define TEX_SURF_SNOW              0x02000000
 +#define TEX_SURF_STONE             0x04000000
 +#define TEX_SURF_WATER             0x08000000
 +#define TEX_SURF_GRASS             0x10000000
 +#define TEX_SURF_BREAKABLE         0x20000000
 +
 +
  /* shadow flags */
  #define WORLDSPAWN_CAST_SHADOWS 1
  #define WORLDSPAWN_RECV_SHADOWS 1
  #define HINT_PRIORITY           1000        /* ydnar: force hint splits first and antiportal/areaportal splits last */
  #define ANTIPORTAL_PRIORITY     -1000
  #define AREAPORTAL_PRIORITY     -1000
 -#define DETAIL_PRIORITY     -3000
 +#define DETAIL_PRIORITY         -3000
  
  #define PSIDE_FRONT             1
  #define PSIDE_BACK              2
  #define RAD_LUXEL_SIZE          3
  #define SUPER_LUXEL_SIZE        4
  #define SUPER_FLAG_SIZE         4
 -#define FLAG_FORCE_SUBSAMPLING 1
 +#define FLAG_FORCE_SUBSAMPLING  1
  #define FLAG_ALREADY_SUBSAMPLED 2
  #define SUPER_ORIGIN_SIZE       3
  #define SUPER_NORMAL_SIZE       4
@@@ -560,13 -551,6 +560,13 @@@ typedef enu
  }
  miniMapMode_t;
  
 +typedef enum
 +{
 +      MINIMAP_SIDECAR_NONE,
 +      MINIMAP_SIDECAR_UNVANQUISHED
 +}
 +miniMapSidecarFormat_t;
 +
  typedef struct game_s
  {
        char                *arg;                           /* -game matches this */
        int maxLMSurfaceVerts;                              /* default maximum meta surface verts */
        int maxSurfaceVerts;                                /* default maximum surface verts */
        int maxSurfaceIndexes;                              /* default maximum surface indexes (tris * 3) */
 +      qboolean texFile;                                   /* enable per shader prefix surface flags and .tex file */
        qboolean emitFlares;                                /* when true, emit flare surfaces */
        char                *flareShader;                   /* default flare shader (MUST BE SET) */
        qboolean wolfLight;                                 /* when true, lights work like wolf q3map  */
        qboolean miniMapKeepAspect;                         /* minimap keep aspect ratio by letterboxing */
        miniMapMode_t miniMapMode;                          /* minimap mode */
        char                *miniMapNameFormat;             /* minimap name format */
 +      miniMapSidecarFormat_t miniMapSidecarFormat;        /* minimap sidecar format */
        char                *bspIdent;                      /* 4-letter bsp file prefix */
        int bspVersion;                                     /* bsp version to use */
        qboolean lumpSwap;                                  /* cod-style len/ofs order */
@@@ -848,7 -830,7 +848,7 @@@ typedef struct face_
        struct face_s       *next;
        int planenum;
        int priority;
 -      //qboolean                      checked;
 +      //qboolean checked;
        int compileFlags;
        winding_t           *w;
  }
@@@ -1024,7 -1006,7 +1024,7 @@@ typedef enu
  }
  surfaceType_t;
  
 -char            *surfaceTypes[ NUM_SURFACE_TYPES ]
 +Q_EXTERN char *surfaceTypes[ NUM_SURFACE_TYPES ]
  #ifndef MAIN_C
  ;
  #else
@@@ -1490,7 -1472,7 +1490,7 @@@ typedef struct rawLightmap_
        float                   *bspLuxels[ MAX_LIGHTMAPS ];
        float                   *radLuxels[ MAX_LIGHTMAPS ];
        float                   *superLuxels[ MAX_LIGHTMAPS ];
 -      unsigned char               *superFlags;
 +      unsigned char           *superFlags;
        float                   *superOrigins;
        float                   *superNormals;
        int                     *superClusters;
@@@ -1837,7 -1819,6 +1837,7 @@@ void                        RadFreeLigh
  
  /* light_ydnar.c */
  void                        ColorToBytes( const float *color, byte *colorBytes, float scale );
 +void                        ColorToBytesNonZero( const float *color, byte *colorBytes, float scale );
  void                        SmoothNormals( void );
  
  void                        MapRawLightmap( int num );
@@@ -1878,7 -1859,7 +1878,7 @@@ int                         ImportLight
  
  void                        SetupSurfaceLightmaps( void );
  void                        StitchSurfaceLightmaps( void );
 -void                        StoreSurfaceLightmaps( qboolean fastAllocate );
 +void                        StoreSurfaceLightmaps( qboolean fastAllocate, qboolean storeForReal );
  
  
  /* exportents.c */
@@@ -1934,11 -1915,6 +1934,11 @@@ void                        LoadBSPFile
  void                        WriteBSPFile( const char *filename );
  void                        PrintBSPFileSizes( void );
  
 +void                        WriteTexFile( char *name );
 +void                        LoadSurfaceFlags( char *filename );
 +int                         GetSurfaceParm( const char *tex );
 +void                        RestoreSurfaceFlags( char *filename );
 +
  epair_t                     *ParseEPair( void );
  void                        ParseEntities( void );
  void                        UnparseEntities( void );
@@@ -1972,6 -1948,14 +1972,6 @@@ void                        WriteRBSPFi
  
     ------------------------------------------------------------------------------- */
  
 -#ifdef MAIN_C
 -      #define Q_EXTERN
 -      #define Q_ASSIGN( a )   = a
 -#else
 -      #define Q_EXTERN extern
 -      #define Q_ASSIGN( a )
 -#endif
 -
  /* game support */
  Q_EXTERN game_t games[]
  #ifndef MAIN_C
        =
        {
                                                                #include "game_quake3.h"
 +      ,
 +                                                              #include "game_nexuiz.h" /* must be after game_quake3.h as they share defines! */
 +      ,
 +                                                              #include "game_oa.h" /* must be after game_quake3.h as they share defines! */
 +      ,
 +                                                              #include "game_q3rally.h" /* must be after game_quake3.h as they share defines! */
        ,
                                                                #include "game_quakelive.h" /* must be after game_quake3.h as they share defines! */
        ,
 -                                                              #include "game_nexuiz.h" /* must be after game_quake3.h as they share defines! */
 +                                                              #include "game_reaction.h" /* must be after game_quake3.h */
        ,
 -                                                              #include "game_xonotic.h" /* must be after game_quake3.h as they share defines! */
 +                                                              #include "game_smokinguns.h" /* must be after game_quake3.h */
        ,
                                                                #include "game_tremulous.h" /*LinuxManMikeC: must be after game_quake3.h, depends on #define's set in it */
        ,
                                                                #include "game_unvanquished.h" /* must be after game_tremulous.h as they share defines! */
 +      ,
 +                                                              #include "game_wop.h" /* must be after game_quake3.h as they share defines! */
 +      ,
 +                                                              #include "game_xonotic.h" /* must be after game_quake3.h as they share defines! */
        ,
                                                                #include "game_tenebrae.h"
        ,
        ,
                                                                #include "game_qfusion.h"   /* qfusion game */
        ,
 -                                                              #include "game_reaction.h" /* must be after game_quake3.h */
 +                                                              #include "game_warsow.h" /* must be after game_qfusion.h as they share defines! */
 +      ,
 +                                                              #include "game_warfork.h" /* must be after game_qfusion.h as they share defines! */
        ,
 -                                                              #include "game_darkplaces.h"    /* vortex: darkplaces q1 engine */
 +                                                              #include "game_darkplaces.h" /* darkplaces q1 engine */
        ,
 -                                                              #include "game_dq.h"    /* vortex: deluxe quake game ( darkplaces q1 engine) */
 +                                                              #include "game_dq.h" /* deluxe quake game ( darkplaces q1 engine) */
        ,
                                                                #include "game_prophecy.h"  /* vortex: prophecy game ( darkplaces q1 engine) */
        ,
@@@ -2058,10 -2030,12 +2058,11 @@@ Q_EXTERN float jitters[ MAX_JITTERS ]
  
  /*can't code*/
  Q_EXTERN qboolean doingBSP Q_ASSIGN( qfalse );
+ Q_EXTERN qboolean doingModelClip Q_ASSIGN( qfalse );
+ Q_EXTERN qboolean snapModelClip Q_ASSIGN( qfalse );
  
  /* commandline arguments */
  Q_EXTERN qboolean nocmdline Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean verbose;
  Q_EXTERN qboolean verboseEntities Q_ASSIGN( qfalse );
  Q_EXTERN qboolean force Q_ASSIGN( qfalse );
  Q_EXTERN qboolean infoMode Q_ASSIGN( qfalse );
@@@ -2080,8 -2054,8 +2081,8 @@@ Q_EXTERN qboolean nofog Q_ASSIGN( qfals
  Q_EXTERN qboolean noHint Q_ASSIGN( qfalse );                        /* ydnar */
  Q_EXTERN qboolean renameModelShaders Q_ASSIGN( qfalse );            /* ydnar */
  Q_EXTERN qboolean skyFixHack Q_ASSIGN( qfalse );                    /* ydnar */
 -Q_EXTERN qboolean bspAlternateSplitWeights Q_ASSIGN( qfalse );                      /* 27 */
 -Q_EXTERN qboolean deepBSP Q_ASSIGN( qfalse );                   /* div0 */
 +Q_EXTERN qboolean bspAlternateSplitWeights Q_ASSIGN( qfalse );      /* 27 */
 +Q_EXTERN qboolean deepBSP Q_ASSIGN( qfalse );                       /* div0 */
  Q_EXTERN qboolean maxAreaFaceSurface Q_ASSIGN( qfalse );                    /* divVerent */
  
  Q_EXTERN int patchSubdivisions Q_ASSIGN( 8 );                       /* ydnar: -patchmeta subdivisions */
@@@ -2099,6 -2073,7 +2100,7 @@@ Q_EXTERN qboolean emitFlares Q_ASSIGN( 
  Q_EXTERN qboolean debugSurfaces Q_ASSIGN( qfalse );
  Q_EXTERN qboolean debugInset Q_ASSIGN( qfalse );
  Q_EXTERN qboolean debugPortals Q_ASSIGN( qfalse );
+ Q_EXTERN qboolean debugClip Q_ASSIGN( qfalse );                       /* debug model autoclipping */
  Q_EXTERN qboolean lightmapTriangleCheck Q_ASSIGN( qfalse );
  Q_EXTERN qboolean lightmapExtraVisClusterNudge Q_ASSIGN( qfalse );
  Q_EXTERN qboolean lightmapFill Q_ASSIGN( qfalse );
@@@ -2358,6 -2333,7 +2360,7 @@@ Q_EXTERN float spotScale Q_ASSIGN( 7500
  Q_EXTERN float areaScale Q_ASSIGN( 0.25f );
  Q_EXTERN float skyScale Q_ASSIGN( 1.0f );
  Q_EXTERN float bounceScale Q_ASSIGN( 0.25f );
+ Q_EXTERN float bounceColorRatio Q_ASSIGN( 1.0f );
  Q_EXTERN float vertexglobalscale Q_ASSIGN( 1.0f );
  
  /* jal: alternative angle attenuation curve */
@@@ -2569,7 -2545,7 +2572,7 @@@ Q_EXTERN int allocatedBSPBrushSides Q_A
  Q_EXTERN bspBrushSide_t*    bspBrushSides Q_ASSIGN( NULL );
  
  Q_EXTERN int numBSPLightBytes Q_ASSIGN( 0 );
 -Q_EXTERN byte               *bspLightBytes Q_ASSIGN( NULL );
 +Q_EXTERN byte *bspLightBytes Q_ASSIGN( NULL );
  
  //%   Q_EXTERN int                            numBSPGridPoints Q_ASSIGN( 0 );
  //%   Q_EXTERN byte                           *bspGridPoints Q_ASSIGN( NULL );
@@@ -2581,11 -2557,11 +2584,11 @@@ Q_EXTERN int numBSPVisBytes Q_ASSIGN( 
  Q_EXTERN byte bspVisBytes[ MAX_MAP_VISIBILITY ];
  
  Q_EXTERN int numBSPDrawVerts Q_ASSIGN( 0 );
 -Q_EXTERN bspDrawVert_t          *bspDrawVerts Q_ASSIGN( NULL );
 +Q_EXTERN bspDrawVert_t *bspDrawVerts Q_ASSIGN( NULL );
  
  Q_EXTERN int numBSPDrawIndexes Q_ASSIGN( 0 );
  Q_EXTERN int allocatedBSPDrawIndexes Q_ASSIGN( 0 );
 -Q_EXTERN int                *bspDrawIndexes Q_ASSIGN( NULL );
 +Q_EXTERN int *bspDrawIndexes Q_ASSIGN( NULL );
  
  Q_EXTERN int numBSPDrawSurfaces Q_ASSIGN( 0 );
  Q_EXTERN bspDrawSurface_t   *bspDrawSurfaces Q_ASSIGN( NULL );
@@@ -2596,45 -2572,27 +2599,45 @@@ Q_EXTERN bspFog_t bspFogs[ MAX_MAP_FOG
  Q_EXTERN int numBSPAds Q_ASSIGN( 0 );
  Q_EXTERN bspAdvertisement_t bspAds[ MAX_MAP_ADVERTISEMENTS ];
  
 -#define AUTOEXPAND_BY_REALLOC( ptr, reqitem, allocated, def ) \
 +// Used for tex file support, Smokin'Guns globals
 +Q_EXTERN qboolean compile_map;
 +
 +#define _AUTOEXPAND_BY_REALLOC( ptr, reqitem, allocated, def, fillWithZeros ) \
        do \
        { \
 +              int prevAllocated = allocated; \
                if ( reqitem >= allocated )     \
                { \
                        if ( allocated == 0 ) { \
 -                              allocated = def; } \
 +                              allocated = def; \
 +                      } \
                        while ( reqitem >= allocated && allocated )     \
 +                      { \
                                allocated *= 2; \
 +                      } \
                        if ( !allocated || allocated > 2147483647 / (int)sizeof( *ptr ) ) \
                        { \
 -                              Error( # ptr " over 2 GB" ); \
 +                              Error( #ptr " over 2 GB" ); \
                        } \
                        ptr = realloc( ptr, sizeof( *ptr ) * allocated ); \
                        if ( !ptr ) { \
 -                              Error( # ptr " out of memory" ); } \
 +                              Error( #ptr " out of memory" ); \
 +                      } \
 +                      if ( fillWithZeros ) \
 +                      { \
 +                              memset( ptr + ( sizeof( *ptr ) * prevAllocated ), 0 , sizeof( *ptr ) * ( allocated - prevAllocated ) ); \
 +                      } \
                } \
        } \
        while ( 0 )
  
 -#define AUTOEXPAND_BY_REALLOC_BSP( suffix, def ) AUTOEXPAND_BY_REALLOC( bsp ## suffix, numBSP ## suffix, allocatedBSP ## suffix, def )
 +#define AUTOEXPAND_BY_REALLOC( ptr, reqitem, allocated, def ) _AUTOEXPAND_BY_REALLOC( ptr, reqitem, allocated, def, qfalse )
 +
 +#define AUTOEXPAND_BY_REALLOC0( ptr, reqitem, allocated, def ) _AUTOEXPAND_BY_REALLOC( ptr, reqitem, allocated, def, qtrue )
 +
 +#define AUTOEXPAND_BY_REALLOC_BSP( suffix, def ) AUTOEXPAND_BY_REALLOC( bsp##suffix, numBSP##suffix, allocatedBSP##suffix, def )
 +
 +#define AUTOEXPAND_BY_REALLOC0_BSP( suffix, def ) AUTOEXPAND_BY_REALLOC0( bsp##suffix, numBSP##suffix, allocatedBSP##suffix, def )
  
  #define Image_LinearFloatFromsRGBFloat( c ) ( ( ( c ) <= 0.04045f ) ? ( c ) * ( 1.0f / 12.92f ) : (float)pow( ( ( c ) + 0.055f ) * ( 1.0f / 1.055f ), 2.4f ) )
  #define Image_sRGBFloatFromLinearFloat( c ) ( ( ( c ) < 0.0031308f ) ? ( c ) * 12.92f : 1.055f * (float)pow( ( c ), 1.0f / 2.4f ) - 0.055f )