# (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/build/q3map2';
# General flags for q3map2 (for example -threads 4)
- our $Q3MAP2FLAGS = '';
+ our $Q3MAP2FLAGS = '-fs_forbiddenpath xonotic*-data*.pk3* -fs_forbiddenpath xonotic*-nexcompat*.pk3*';
# Default flags for the -bsp stage
- our $BSPFLAGS = '-meta -samplesize 8 -minsamplesize 4 -mv 1000000 -mi 6000000';
+ our $BSPFLAGS = '-meta -maxarea -samplesize 8 -mv 1000000 -mi 6000000';
# Default flags for the -vis stage
our $VISFLAGS = '';
# Default flags for the -light stage
- our $LIGHTFLAGS = '-deluxe -patchshadows -samples 3 -lightmapsize 512';
+ 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
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';
}
elsif($_ eq '-scale')
{
- $options->{scale} = (shift @ARGV) || 1;
+ $options->{scalefactor} = @ARGV ? shift(@ARGV) : 1;
$enterflags = 'scale';
}
elsif($_ eq '-novis')
{
$options->{minimap} = undef;
}
- elsif($_ eq '-noshaderlist')
- {
- $options->{noshaderlist} = 1;
- }
elsif($_ eq '-bsp_timeout')
{
$options->{bsp_timeout} = shift @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')
+ {
+ $curmode = 'bsp';
+ }
+ my $flag = $1;
+ @{$options->{$curmode}} = grep { (($_ eq $flag) ... /^-/) !~ /^[0-9]+$/ } @{$options->{$curmode}};
+ # so, e.g. --no-samplesize removes "-samplesize" and a following "3"
+ }
elsif($_ =~ /^-(-.*)/)
{
if($curmode eq 'maps')
}
my $linkdir = File::Temp::tempdir("xonotic-map-compiler.XXXXXX", TMPDIR => 1, CLEANUP => 1);
+my $starttime = time;
+my $endtime = time;
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
{
- local $SIG{ALRM} = sub { kill $pid; };
+ local $SIG{ALRM} = sub { warn "SIGALRM caught\n"; kill TERM => $pid; };
alarm $timeout
if $timeout;
if(waitpid($pid, 0) != $pid)
die "waitpid: did not return our child process $pid: $!";
}
alarm 0;
- return $? == 0;
+ return ($? == 0);
}
else # child
{
}
}
-(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})
{
- 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($_ 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";
}