X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=misc%2Ftools%2Fxonotic-map-compiler;h=371de70514562d3accd1cbc1397baaa428760999;hb=af69a7de874832eca1be0c176c3f57d45d8c4e80;hp=c4f59a9ab30531e4e1d09fe72106df5d88c56bdc;hpb=aae67351ae7bde60f8e1d3dac21af45930151f43;p=xonotic%2Fxonotic.git diff --git a/misc/tools/xonotic-map-compiler b/misc/tools/xonotic-map-compiler index c4f59a9a..371de705 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'; @@ -55,7 +55,7 @@ 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, @@ -91,8 +91,8 @@ while(@ARGV) } elsif($_ eq '-scale') { - $options->{scale} = (shift @ARGV) || 1; - #$enterflags = 'scale'; + $options->{scalefactor} = @ARGV ? shift(@ARGV) : 1; + $enterflags = 'scale'; } elsif($_ eq '-novis') { @@ -106,10 +106,6 @@ while(@ARGV) { $options->{minimap} = undef; } - elsif($_ eq '-noshaderlist') - { - $options->{noshaderlist} = 1; - } elsif($_ eq '-bsp_timeout') { $options->{bsp_timeout} = shift @ARGV; @@ -128,12 +124,24 @@ while(@ARGV) } elsif($_ eq '-scale_timeout') { - $options->{minimap_timeout} = shift @ARGV; + $options->{scale_timeout} = 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') @@ -210,159 +218,86 @@ sub q3map2(@) } } -(my $mapdir = getcwd()) =~ s!/[^/]*(?:$)!!; -$mapdir = "/" if $mapdir eq ""; -symlink "$mapdir", "$linkdir/data"; - -my ($prescale, $postscale) = ($options->{scale} =~ /^([0-9.]+)(?::([0-9.]+))?$/); +my ($prescale, $postscale) = ($options->{scalefactor} =~ /^([0-9.]+)(?::([0-9.]+))?$/); $prescale = 1 if not defined $prescale; $postscale = 1 if not defined $postscale; +my $origcwd = getcwd(); for my $m(@{$options->{maps}}) { - $m =~ s/\.(?:map|bsp)$//; - - if($prescale != 1) + chdir $origcwd + or die "chdir $origcwd: $!"; + if($m =~ s!(.*)/!!) { - unshift @{$options->{bsp}}, "-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"; + $m =~ s/\.(?:map|bsp)$//; - my $restore_shaderlist = sub { }; - if(!$options->{noshaderlist}) + if($prescale != 1) { - 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"; - } - } - }; - - if(defined $shaderlist_new) - { - mkdir "$mapdir/scripts"; - open my $fh, ">", "$mapdir/scripts/shaderlist.txt"; - print $fh $shaderlist_new; - close $fh; - } + 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) { - 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/; - my %o = (); + 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/; + my %o = (); - for(@o) + for(@o) + { + next if $o{$_}++; + if($_ eq 'light') { - next if $o{$_}++; - if($_ eq 'light') + if(defined $options->{light}) { - if(defined $options->{light}) - { - q3map2 '-light', @{$options->{light}}, "$m.map" - or die "-light: $?"; - } + q3map2 '-light', @{$options->{light}}, "$m.map" + or die "-light: $?"; } - if($_ eq 'vis') - { - if(defined $options->{vis}) - { - q3map2 '-vis', @{$options->{vis}}, "$m.map" - or die "-vis: $?"; - } - } - } - - if($postscale != 1) - { - 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(defined $options->{minimap}) + if($_ eq 'vis') { - q3map2 '-minimap', @{$options->{minimap}}, "$m.map" - or die "-minimap: $?"; + if(defined $options->{vis}) + { + q3map2 '-vis', @{$options->{vis}}, "$m.map" + or die "-vis: $?"; + } } + } - unlink "$m.srf"; - unlink "$m.prt"; - - $restore_shaderlist->(); - 1; + if($postscale != 1) + { + q3map2 '-scale', @{$options->{scale}}, $postscale, "$m.bsp" + or die "-scale: $?"; + rename "${m}_s.bsp", "$m.bsp" + or die "rename ${m}_s.bsp $m.bsp: $!"; } - or do + + if(defined $options->{minimap}) { - $restore_shaderlist->(); - die $@; - }; + q3map2 '-minimap', @{$options->{minimap}}, "$m.map" + or die "-minimap: $?"; + } + + unlink "$m.srf"; + unlink "$m.prt"; }