X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fxonotic.git;a=blobdiff_plain;f=misc%2Ftools%2Fxonotic-map-compiler;h=f21daaf8dd6d9a6f591d757a6341fa4fb149492a;hp=ec69572c123de842f25f13491e0340a22ded41be;hb=37e3d71e28441abac3bc00682559b0076fe8dde2;hpb=89d512f6bdbb7b730b0e95765ef6e9181adc4069 diff --git a/misc/tools/xonotic-map-compiler b/misc/tools/xonotic-map-compiler index ec69572c..f21daaf8 100755 --- a/misc/tools/xonotic-map-compiler +++ b/misc/tools/xonotic-map-compiler @@ -9,14 +9,14 @@ use File::Temp; # (just copy paste this part to the file ~/.xonotic-map-compiler) # Path to Xonotic (where the data directory is in) - our $XONOTICDIR = '/home/rpolzer/Games/Xonotic'; + our $XONOTICDIR = getcwd(); # Path to your q3map2 program. You find it in your GtkRadiant/install # directory. - our $Q3MAP2 = '/home/rpolzer/Games/Xonotic/netradiant/install/q3map2.x86'; + our $Q3MAP2 = getcwd() . '/netradiant/install/q3map2'; # General flags for q3map2 (for example -threads 4) - our $Q3MAP2FLAGS = '-fs_forbiddenpath xonotic-data.pk3 -fs_forbiddenpath xonotic-data.pk3dir -fs_forbiddenpath xonotic-nexcompat.pk3 -fs_forbiddenpath xonotic-nexcompat.pk3dir'; + our $Q3MAP2FLAGS = '-fs_forbiddenpath xonotic*-data*.pk3* -fs_forbiddenpath xonotic*-nexcompat*.pk3*'; # Default flags for the -bsp stage our $BSPFLAGS = '-meta -maxarea -samplesize 8 -mv 1000000 -mi 6000000'; @@ -25,13 +25,13 @@ use File::Temp; our $VISFLAGS = ''; # Default flags for the -light stage - our $LIGHTFLAGS = '-lightmapsearchpower 3 -deluxe -patchshadows -randomsamples -samples 128 -lightmapsize 512 -fast -fastbounce -dirty -bouncegrid'; + our $LIGHTFLAGS = '-lightmapsize 1024 -lightmapsearchpower 4 -deluxe -patchshadows -randomsamples -samples 4 -fast -fastbounce -dirty -bouncegrid -fill'; # Default flags for the -minimap stage our $MINIMAPFLAGS = ''; # Default order of commands - our $ORDER = 'light,vis,minimap'; + our $ORDER = 'vis,light,scale'; # end of user changable part @@ -55,12 +55,13 @@ my $options = scale => [], # can't have defaults atm order => [split /\s*,\s*/, $ORDER], maps => [], - scale => 1, + scalefactor => 1, bsp_timeout => 0, vis_timeout => 0, light_timeout => 0, minimap_timeout => 0, - scale_timeout => 0 + scale_timeout => 0, + timeout_stealing => 0, }; my $curmode = 'maps'; @@ -91,7 +92,7 @@ while(@ARGV) } elsif($_ eq '-scale') { - $options->{scale} = (shift @ARGV) || 1; + $options->{scalefactor} = @ARGV ? shift(@ARGV) : 1; $enterflags = 'scale'; } elsif($_ eq '-novis') @@ -106,10 +107,6 @@ while(@ARGV) { $options->{minimap} = undef; } - elsif($_ eq '-noshaderlist') - { - $options->{noshaderlist} = 1; - } elsif($_ eq '-bsp_timeout') { $options->{bsp_timeout} = shift @ARGV; @@ -128,12 +125,28 @@ while(@ARGV) } elsif($_ eq '-scale_timeout') { - $options->{minimap_timeout} = shift @ARGV; + $options->{scale_timeout} = shift @ARGV; + } + elsif($_ eq '-timeout_stealing') + { + $options->{timeout_stealing} = shift @ARGV; } elsif($_ eq '-order') { $options->{order} = [split /\s*,\s*/, shift @ARGV]; } + elsif($_ eq '-sRGB') + { + push @{$options->{bsp}}, "-sRGBtex", "-sRGBcolor"; + push @{$options->{light}}, "-sRGBtex", "-sRGBcolor", "-sRGBlight" + if defined $options->{light}; + } + elsif($_ eq '-nosRGB') + { + push @{$options->{bsp}}, "-nosRGBtex", "-nosRGBcolor"; + push @{$options->{light}}, "-nosRGBtex", "-nosRGBcolor", "-nosRGBlight" + if defined $options->{light}; + } elsif($_ =~ /^--no(-.*)/) { if($curmode eq 'maps') @@ -176,6 +189,8 @@ while(@ARGV) } my $linkdir = File::Temp::tempdir("xonotic-map-compiler.XXXXXX", TMPDIR => 1, CLEANUP => 1); +my $starttime = time; +my $endtime = time; sub q3map2(@) { @@ -187,8 +202,15 @@ sub q3map2(@) $timeout = $options->{minimap_timeout} if $mode eq '-minimap'; $timeout = $options->{scale_timeout} if $mode eq '-scale'; die "Invalid call: not a standard q3map2 stage" if not defined $timeout; + $endtime += $timeout; + my $stolen_timeout = $endtime - time; + if ($stolen_timeout > $timeout) + { + $timeout += ($stolen_timeout - $timeout) * $options->{timeout_stealing}; + } my @args = ($Q3MAP2, split(/\s+/, $Q3MAP2FLAGS), '-game', 'xonotic', '-fs_basepath', $XONOTICDIR, '-fs_basepath', $linkdir, '-v', @_); print "\$ @args\n"; + print "Using timeout: $timeout\n"; defined(my $pid = fork()) or die "fork: $!"; if($pid) # parent @@ -210,170 +232,85 @@ sub q3map2(@) } } -(my $mapdir = getcwd()) =~ s!/[^/]*(?:$)!!; -$mapdir = "/" if $mapdir eq ""; -symlink "$mapdir", "$linkdir/data"; - -my ($prescale, $postscale) = ($options->{scale} =~ /^([0-9.]+)(?::([0-9.]+))?$/); -$postscale = 1 if not defined $postscale; +if ($options->{scalefactor} =~ /^([0-9.]+):([0-9.]+)$/) +{ + die "Two-scale isn't supported" + if $1 != 1 and $2 != 1; + $options->{scalefactor} = $1 + if $2 == 1; + $options->{scalefactor} = $2 + if $1 == 1; +} +my $origcwd = getcwd(); for my $m(@{$options->{maps}}) { - $m =~ s/\.(?:map|bsp)$//; - if($prescale != 1) + chdir $origcwd + or die "chdir $origcwd: $!"; + if($m =~ s!(.*)/!!) { - open my $checkfh, "<", "$m.map" - or die "open $m.map: $!"; - my $keeplights = 0; - while(<$checkfh>) - { - /^\s*"_keeplights"\s+"1"\s*$/ - or next; - $keeplights = 1; - } - close $checkfh; - die "$m does not define _keeplights to 1" - unless $keeplights; + my $predir = $1; + chdir $predir + or die "chdir $predir: $!"; } + symlink getcwd() . "/..", "$linkdir/data" + or die "symlink $linkdir/data: $!"; - my %shaders = map { m!/([^/.]*)\.shader(?:$)! ? ($1 => 1) : () } glob "../scripts/*.shader"; - - my $restore_shaderlist = sub { }; - if(!$options->{noshaderlist}) - { - my $previous_shaderlist = undef; - my $shaderlist = ""; - if(open my $fh, "<", "$XONOTICDIR/data/scripts/shaderlist.txt") - { - while(<$fh>) - { - $shaderlist .= $_; - } - - # we may have to restore the file on exit - $previous_shaderlist = $shaderlist - if "$XONOTICDIR/data" eq $mapdir; - } - else - { - # possibly extract the shader list from a pk3? - local $ENV{N} = $XONOTICDIR; - $shaderlist = `cd "\$N" && for X in "\$N"/data/data*.pk3; do Y=\$X; done; unzip -p "\$Y" scripts/shaderlist.txt`; - } - - my $shaderlist_new = ""; - for(split /\r?\n|\r/, $shaderlist) - { - delete $shaders{$_}; - $shaderlist_new .= "$_\n"; - } - if(%shaders) - { - for(sort keys %shaders) - { - $shaderlist_new .= "$_\n"; - } - } - else - { - $shaderlist_new = undef; - } - - $restore_shaderlist = sub - { - if(defined $shaderlist_new) - { - if(defined $previous_shaderlist) - { - open my $fh, ">", "$mapdir/scripts/shaderlist.txt"; - print $fh $previous_shaderlist; - close $fh; - } - else - { - unlink "$mapdir/scripts/shaderlist.txt"; - } - } - }; + $m =~ s/\.(?:map|bsp)$//; - if(defined $shaderlist_new) - { - mkdir "$mapdir/scripts"; - open my $fh, ">", "$mapdir/scripts/shaderlist.txt"; - print $fh $shaderlist_new; - close $fh; - } - } + # never hurts, may help with rtlights + unshift @{$options->{bsp}}, "-keeplights"; local $SIG{INT} = sub { print "SIGINT caught, cleaning up...\n"; - $restore_shaderlist->(); exit 0; }; - eval - { - unlink <$m/lm_*>; # delete old external lightmaps - q3map2 '-bsp', @{$options->{bsp}}, "$m.map" - or die "-bsp: $?"; - if($prescale != 1) - { - q3map2 '-scale', @{$options->{scale}}, $prescale, "$m.bsp" - or die "-scale: $?"; - rename "${m}_s.bsp", "$m.bsp" - or die "rename ${m}_s.bsp $m.bsp: $!"; - } - my @o = @{$options->{order}}; - push @o, qw/light vis minimap/; - my %o = (); + unlink <$m/lm_*>; # delete old external lightmaps + q3map2 '-bsp', @{$options->{bsp}}, "$m.map" + or die "-bsp: $?"; + my @o = @{$options->{order}}; + push @o, qw/vis scale light/; + my %o = (); - for(@o) + for(@o) + { + next if $o{$_}++; + if($_ eq 'light') { - next if $o{$_}++; - if($_ eq 'light') - { - if(defined $options->{light}) - { - q3map2 '-light', @{$options->{light}}, "$m.map" - or die "-light: $?"; - } - } - if($_ eq 'vis') + if(defined $options->{light}) { - if(defined $options->{vis}) - { - q3map2 '-vis', @{$options->{vis}}, "$m.map" - or die "-vis: $?"; - } + q3map2 '-light', @{$options->{light}}, "$m.map" + or die "-light: $?"; } - if($_ eq 'minimap') + } + if($_ eq 'vis') + { + if(defined $options->{vis}) { - if(defined $options->{minimap}) - { - q3map2 '-minimap', @{$options->{minimap}}, "$m.map" - or die "-minimap: $?"; - } + q3map2 '-vis', @{$options->{vis}}, "$m.map" + or die "-vis: $?"; } } - - if($postscale != 1) + if($_ eq 'scale') { - q3map2 '-scale', @{$options->{scale}}, $postscale, "$m.bsp" - or die "-scale: $?"; - rename "${m}_s.bsp", "$m.bsp" - or die "rename ${m}_s.bsp $m.bsp: $!"; + if ($options->{scalefactor} != 1) + { + q3map2 '-scale', @{$options->{scale}}, $options->{scalefactor}, "$m.bsp" + or die "-scale: $?"; + rename "${m}_s.bsp", "$m.bsp" + or die "rename ${m}_s.bsp $m.bsp: $!"; + } } - - unlink "$m.srf"; - unlink "$m.prt"; - - $restore_shaderlist->(); - 1; } - or do + + if(defined $options->{minimap}) { - $restore_shaderlist->(); - die $@; - }; + q3map2 '-minimap', @{$options->{minimap}}, "$m.map" + or die "-minimap: $?"; + } + + unlink "$m.srf"; + unlink "$m.prt"; }