]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/help.c
q3map2/help: only read terminal columns using ioctl on Posix systems
[xonotic/netradiant.git] / tools / quake3 / q3map2 / help.c
index 1c99d3c417b605af6ff97f614e59a2a866832117..60631e3d72f175a38c581b28a50df232ea8289ab 100644 (file)
 /* dependencies */
 #include "q3map2.h"
 
+#if GDEF_OS_POSIX
+#include <sys/ioctl.h>
+#endif // GDEF_OS_POSIX
 
+static unsigned terminalColumns = 80;
 
 struct HelpOption
 {
@@ -39,6 +43,7 @@ struct HelpOption
        const char* description;
 };
 
+// FIXME: low column width cause an endless loop
 void HelpOptions(const char* group_name, int indentation, int width, struct HelpOption* options, int count)
 {
        indentation *= 2;
@@ -68,6 +73,7 @@ void HelpOptions(const char* group_name, int indentation, int width, struct Help
                        putchar('\n');
                        printed = indentation+26;
                }
+
                if ( j == 0 )
                {
                        printf("%s\n",options[i].description+j);
@@ -97,6 +103,7 @@ void HelpBsp()
                {"-deep", "Use detail brushes in the BSP tree, but at lowest priority (should give more fps)"},
                {"-de <F>", "Distance epsilon for plane snapping etc."},
                {"-fakemap", "Write fakemap.map containing all world brushes"},
+               {"-fastmeta", "Use small lightmap/surface verts/number maximum numbers (like Q3A), to be used with `-meta`"},
                {"-flares", "Turn on support for flares"},
                {"-flat", "Enable flat shading (good for combining with -celshader)"},
                {"-fulldetail", "Treat detail brushes as structural ones"},
@@ -104,13 +111,16 @@ void HelpBsp()
                {"-leaktest", "Abort if a leak was found"},
                {"-linfile <filename.lin>", "Line file to write"},
                {"-maxarea", "Use Max Area face surface generation"},
+               {"-maxlightmapvertices <N>", "Sets the maximum number of vertices per lightmapped surface"},
+               {"-maxsurfaceindexes <N>", "Sets the maximum number of indexes per surface"},
+               {"-maxsurfacevertices <N>", "Sets the maximum number of vertices per surface"},
                {"-meta", "Combine adjacent triangles of the same texture to surfaces (ALWAYS USE THIS)"},
                {"-metaadequatescore <N>", "Adequate score for adding triangles to meta surfaces"},
                {"-metagoodscore <N>", "Good score for adding triangles to meta surfaces"},
                {"-metamaxbboxdistance <F>", "Maximum bounding box distance for meta surfaces"},
                {"-minsamplesize <N>", "Sets minimum lightmap resolution in luxels/qu"},
-               {"-mi <N>", "Sets the maximum number of indexes per surface"},
-               {"-mv <N>", "Sets the maximum number of vertices of a lightmapped surface"},
+               {"-mi <N>", "Deprecated alias for `-maxsurfaceindexes`"},
+               {"-mv <N>", "Deprecated alias for `-maxlightmapverts`"},
                {"-ne <F>", "Normal epsilon for plane snapping etc."},
                {"-nocurves", "Turn off support for patches"},
                {"-nodetail", "Leave out detail brushes"},
@@ -139,7 +149,8 @@ void HelpBsp()
                {"-tmpout", "Write the BSP file to /tmp"},
                {"-verboseentities", "Enable `-v` only for map entities, not for the world"},
        };
-       HelpOptions("BSP Stage", 0, 80, bsp, sizeof(bsp)/sizeof(struct HelpOption));
+
+       HelpOptions("BSP Stage", 0, terminalColumns, bsp, sizeof(bsp)/sizeof(struct HelpOption));
 }
 
 void HelpVis()
@@ -159,7 +170,8 @@ void HelpVis()
                {"-tmpout", "Use /tmp folder for output"},
                {"-v -v", "Extra verbose mode for cluster debug"}, // q3map2 common takes first -v
        };
-       HelpOptions("VIS Stage", 0, 80, vis, sizeof(vis)/sizeof(struct HelpOption));
+
+       HelpOptions("VIS Stage", 0, terminalColumns, vis, sizeof(vis)/sizeof(struct HelpOption));
 }
 
 void HelpLight()
@@ -207,13 +219,14 @@ void HelpLight()
                {"-extravisnudge", "Broken feature to nudge the luxel origin to a better vis cluster"},
                {"-extrawide", "Deprecated alias for `-super 2 -filter`"},
                {"-extra", "Deprecated alias for `-super 2`"},
-               {"-fastallocate", "Use `-fastallocate` to trade lightmap size against allocation time (useful with hi res lightmaps on large maps: reduce allocation time from days to minutes for only some extra bytes)"},
+               {"-fastallocate",  "Trade lightmap size against packing time (useful with hi res lightmaps on large maps: reduce allocation time from days to minutes for only some extra bytes)"},
                {"-fastbounce", "Use `-fast` style lighting for radiosity"},
                {"-faster", "Use a faster falloff curve for lighting; also implies `-fast`"},
                {"-fastgrid", "Use `-fast` style lighting for the light grid"},
+               {"-fastlightmapsearch", "Deprecated alias for `-fastallocate`"},
                {"-fast", "Ignore tiny light contributions"},
                {"-fill", "Fill lightmap colors from surrounding pixels to improve JPEG compression"},
-               {"-filter", "Lightmap filtering"},
+               {"-filter", "Lightmap filtering, doesn't play nice with some other effects, don't use it, use `-samples` instead"},
                {"-floodlight", "Enable floodlight (zero-effort somewhat decent lighting)"},
                {"-gamma <F>", "Lightmap gamma"},
                {"-gridambientdirectionality <F>", "Ambient directional lighting received (default: 0.0)"},
@@ -230,6 +243,7 @@ void HelpLight()
                {"-lomem", "Low memory but slower lighting mode"},
                {"-lowquality", "Low quality floodlight (appears to currently break floodlight)"},
                {"-minsamplesize <N>", "Sets minimum lightmap resolution in luxels/qu"},
+               {"-nobouncestore", "Do not store BSP, lightmap and shader files between bounces"},
                {"-nocollapse", "Do not collapse identical lightmaps"},
                {"-nodeluxe, -nodeluxemap", "Disable deluxemapping"},
                {"-nofastpoint", "Disable fast point light calculation"},
@@ -257,6 +271,7 @@ void HelpLight()
                {"-shadeangle <A>", "Angle for phong shading"},
                {"-shade", "Enable phong shading at default shade angle"},
                {"-skyscale <F, `-sky` F>", "Scaling factor for sky and sun light"},
+               {"-slowallocate", "Use old (a bit more careful, but much slower) lightmaps packing algorithm (default)"},
                {"-smooth", "Deprecated alias for `-samples 2`"},
                {"-sphericalscale <F, `-spherical` F>", "Scaling factor for spherical point light entities"},
                {"-spotscale <F, `-spot` F>", "Scaling factor for spot point light entities"},
@@ -267,14 +282,14 @@ void HelpLight()
                {"-sRGBtex", "Treat textures as sRGB colorspace"},
                {"-style, -styles", "Enable support for light styles"},
                {"-sunonly", "Only compute sun light"},
-               {"-super <N, `-supersample` N>", "Ordered grid supersampling quality"},
+               {"-super <N, `-supersample` N>", "Ordered grid supersampling quality, much slower than `-samples`"},
                {"-thresh <F>", "Triangle subdivision threshold"},
                {"-trianglecheck", "Broken check that should ensure luxels apply to the right triangle"},
                {"-trisoup", "Convert brush faces to triangle soup"},
                {"-wolf", "Use linear falloff curve by default (like W:ET)"},
        };
 
-       HelpOptions("Light Stage", 0, 80, light, sizeof(light)/sizeof(struct HelpOption));
+       HelpOptions("Light Stage", 0, terminalColumns, light, sizeof(light)/sizeof(struct HelpOption));
 }
 
 void HelpAnalyze()
@@ -284,7 +299,7 @@ void HelpAnalyze()
                {"-lumpswap", "Swap byte order in the lumps"},
        };
 
-       HelpOptions("Analyzing BSP-like file structure", 0, 80, analyze, sizeof(analyze)/sizeof(struct HelpOption));
+       HelpOptions("Analyzing BSP-like file structure", 0, terminalColumns, analyze, sizeof(analyze)/sizeof(struct HelpOption));
 }
 
 void HelpScale()
@@ -295,7 +310,8 @@ void HelpScale()
                {"-tex", "Scale without texture lock"},
                {"-spawn_ref <F>", "Vertical offset for info_player_* entities (adds spawn_ref, scales, subtracts spawn_ref)"},
        };
-       HelpOptions("Scaling", 0, 80, scale, sizeof(scale)/sizeof(struct HelpOption));
+
+       HelpOptions("Scaling", 0, terminalColumns, scale, sizeof(scale)/sizeof(struct HelpOption));
 }
 
 void HelpConvert()
@@ -314,16 +330,16 @@ void HelpConvert()
                {"-shadersasbitmap", "Save shader names as bitmap names in the model so it works as a prefab (only when writing ase and obj)"},
        };
 
-       HelpOptions("Converting & Decompiling", 0, 80, convert, sizeof(convert)/sizeof(struct HelpOption));
+       HelpOptions("Converting & Decompiling", 0, terminalColumns, convert, sizeof(convert)/sizeof(struct HelpOption));
 }
 
 void HelpExport()
 {
        struct HelpOption exportl[] = {
-               {"-export <filename.bsp>", "Copies lightmaps from the BSP to `filename/lightmap_0000.tga` ff"}
+               {"-export <filename.bsp>", "Copies lightmaps from the BSP to `filename/lightmap_0000.tga`"}
        };
 
-       HelpOptions("Exporting lightmaps", 0, 80, exportl, sizeof(exportl)/sizeof(struct HelpOption));
+       HelpOptions("Exporting lightmaps", 0, terminalColumns, exportl, sizeof(exportl)/sizeof(struct HelpOption));
 }
 
 void HelpExportEnts()
@@ -331,7 +347,7 @@ void HelpExportEnts()
        struct HelpOption exportents[] = {
                {"-exportents <filename.bsp>", "Exports the entities to a text file (.ent)"},
        };
-       HelpOptions("ExportEnts Stage", 0, 80, exportents, sizeof(exportents)/sizeof(struct HelpOption));
+       HelpOptions("ExportEnts Stage", 0, terminalColumns, exportents, sizeof(exportents)/sizeof(struct HelpOption));
 }
 
 void HelpFixaas()
@@ -340,7 +356,7 @@ void HelpFixaas()
                {"-fixaas <filename.bsp>", "Switch that enters this mode"},
        };
 
-       HelpOptions("Fixing AAS checksum", 0, 80, fixaas, sizeof(fixaas)/sizeof(struct HelpOption));
+       HelpOptions("Fixing AAS checksum", 0, terminalColumns, fixaas, sizeof(fixaas)/sizeof(struct HelpOption));
 }
 
 void HelpInfo()
@@ -349,7 +365,7 @@ void HelpInfo()
                {"-info <filename.bsp>", "Switch that enters this mode"},
        };
 
-       HelpOptions("Get info about BSP file", 0, 80, info, sizeof(info)/sizeof(struct HelpOption));
+       HelpOptions("Get info about BSP file", 0, terminalColumns, info, sizeof(info)/sizeof(struct HelpOption));
 }
 
 void HelpImport()
@@ -358,7 +374,7 @@ void HelpImport()
                {"-import <filename.bsp>", "Copies lightmaps from `filename/lightmap_0000.tga` ff into the BSP"},
        };
 
-       HelpOptions("Importing lightmaps", 0, 80, import, sizeof(import)/sizeof(struct HelpOption));
+       HelpOptions("Importing lightmaps", 0, terminalColumns, import, sizeof(import)/sizeof(struct HelpOption));
 }
 
 void HelpMinimap()
@@ -384,7 +400,7 @@ void HelpMinimap()
                {"-white", "Write the minimap as a white-on-transparency RGBA32 image"},
        };
 
-       HelpOptions("MiniMap", 0, 80, minimap, sizeof(minimap)/sizeof(struct HelpOption));
+       HelpOptions("MiniMap", 0, terminalColumns, minimap, sizeof(minimap)/sizeof(struct HelpOption));
 }
 
 void HelpCommon()
@@ -403,23 +419,65 @@ void HelpCommon()
                {"-fs_nohomepath", "Do not load home path in VFS"},
                {"-fs_pakpath <path>", "Specify a package directory (can be used more than once to look in multiple paths)"},
                {"-game <gamename>", "Load settings for the given game (default: quake3)"},
-               {"-subdivisions <F>", "multiplier for patch subdivisions quality"},
-               {"-threads <N>", "number of threads to use"},
+               {"-subdivisions <F>", "Multiplier for patch subdivisions quality"},
+               {"-threads <N>", "Number of threads to use"},
                {"-v", "Verbose mode"},
                {"-werror", "Make all warnings into errors"}
        };
 
-       HelpOptions("Common Options", 0, 80, common, sizeof(common)/sizeof(struct HelpOption));
+       HelpOptions("Common Options", 0, terminalColumns, common, sizeof(common)/sizeof(struct HelpOption));
+}
+
+void HelpGames()
+{
+       printf("Games:\n");
+       qboolean begin = qtrue;
+
+       // TODO: sort alphabetically
+       for ( unsigned i = 0, length = 0; games[ i ].arg != NULL; i++ )
+       {
+               // 3 for two whitespaces at the beginning and one (optional) comma a the end
+               if ( length + 3 + strlen( games[ i ].arg ) > terminalColumns )
+               {
+                       printf(",\n");
+                       length = 0;
+                       begin = qtrue;
+               }
+
+               if ( begin )
+               {
+                       printf("  %s", games[ i ].arg );
+                       begin = qfalse;
+               }
+               else
+               {
+                       printf(", %s", games[ i ].arg );
+               }
+
+               length += 2 + strlen( games[ i ].arg );
+       }
 
+       printf("\n\n");
 }
 
 void HelpMain(const char* arg)
 {
        printf("Usage: q3map2 [stage] [common options...] [stage options...] [stage source file]\n");
-       printf("       q3map2 -help [stage]\n\n");
+       printf("       q3map2 -help [stage]\n");
+       printf("       q3map2 -help all\n\n");
+
+#if GDEF_OS_POSIX
+       struct winsize ws;
+       ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
+       if (ws.ws_col > 60) {
+               terminalColumns = ws.ws_col;
+       }
+#endif // GDEF_OS_POSIX
 
        HelpCommon();
 
+       HelpGames();
+
        struct HelpOption stages[] = {
                {"-bsp", "BSP Stage"},
                {"-vis", "VIS Stage"},
@@ -434,6 +492,7 @@ void HelpMain(const char* arg)
                {"-import", "Importing lightmaps"},
                {"-minimap", "MiniMap"},
        };
+
        void(*help_funcs[])() = {
                HelpBsp,
                HelpVis,
@@ -452,16 +511,30 @@ void HelpMain(const char* arg)
        if ( arg && strlen(arg) > 0 )
        {
                if ( arg[0] == '-' )
+               {
                        arg++;
+               }
+
+               if ( strcmp(arg, "all") == 0 )
+               {
+                       HelpOptions("Stages", 0, terminalColumns, stages, sizeof(stages)/sizeof(struct HelpOption));
+
+                       for ( unsigned i = 0; i < sizeof(stages)/sizeof(struct HelpOption); i++ )
+                       {
+                               help_funcs[i]();
+                       }
+                       return;
+               }
 
-               unsigned i;
-               for ( i = 0; i < sizeof(stages)/sizeof(struct HelpOption); i++ )
+               for ( unsigned i = 0; i < sizeof(stages)/sizeof(struct HelpOption); i++ )
+               {
                        if ( strcmp(arg, stages[i].name+1) == 0 )
                        {
                                help_funcs[i]();
                                return;
                        }
+               }
        }
 
-       HelpOptions("Stages", 0, 80, stages, sizeof(stages)/sizeof(struct HelpOption));
+       HelpOptions("Stages", 0, terminalColumns, stages, sizeof(stages)/sizeof(struct HelpOption));
 }