8 # change these to match your system, or define them in ~/.xonotic-map-compiler
9 # (just copy paste this part to the file ~/.xonotic-map-compiler)
11 # Path to Xonotic (where the data directory is in)
12 our $XONOTICDIR = '.';
14 # Path to your q3map2 program. You find it in your GtkRadiant/install
16 our $Q3MAP2 = './netradiant/install/q3map2.x86';
18 # General flags for q3map2 (for example -threads 4)
19 our $Q3MAP2FLAGS = '-fs_forbiddenpath xonotic*-data*.pk3* -fs_forbiddenpath xonotic*-nexcompat*.pk3*';
21 # Default flags for the -bsp stage
22 our $BSPFLAGS = '-meta -maxarea -samplesize 8 -mv 1000000 -mi 6000000';
24 # Default flags for the -vis stage
27 # Default flags for the -light stage
28 our $LIGHTFLAGS = '-lightmapsearchpower 3 -deluxe -patchshadows -randomsamples -samples 4 -lightmapsize 512 -fast -fastbounce -dirty -bouncegrid -fill';
30 # Default flags for the -minimap stage
31 our $MINIMAPFLAGS = '';
33 # Default order of commands
34 our $ORDER = 'vis,light';
36 # end of user changable part
38 do "$ENV{HOME}/.xonotic-map-compiler";
44 $0 mapname [-bsp bspflags...] [-vis visflags...] [-light lightflags...] [-minimap minimapflags]
51 bsp => [split /\s+/, $BSPFLAGS],
52 vis => [split /\s+/, $VISFLAGS],
53 light => [split /\s+/, $LIGHTFLAGS],
54 minimap => [split /\s+/, $MINIMAPFLAGS],
55 scale => [], # can't have defaults atm
56 order => [split /\s*,\s*/, $ORDER],
71 my $enterflags = undef;
82 $enterflags = 'light';
84 elsif($_ eq '-minimap')
86 $enterflags = 'minimap';
94 $options->{scalefactor} = @ARGV ? shift(@ARGV) : 1;
95 $enterflags = 'scale';
99 $options->{vis} = undef;
101 elsif($_ eq '-nolight')
103 $options->{light} = undef;
105 elsif($_ eq '-nominimap')
107 $options->{minimap} = undef;
109 elsif($_ eq '-noshaderlist')
111 $options->{noshaderlist} = 1;
113 elsif($_ eq '-bsp_timeout')
115 $options->{bsp_timeout} = shift @ARGV;
117 elsif($_ eq '-vis_timeout')
119 $options->{vis_timeout} = shift @ARGV;
121 elsif($_ eq '-light_timeout')
123 $options->{light_timeout} = shift @ARGV;
125 elsif($_ eq '-minimap_timeout')
127 $options->{minimap_timeout} = shift @ARGV;
129 elsif($_ eq '-scale_timeout')
131 $options->{scale_timeout} = shift @ARGV;
133 elsif($_ eq '-order')
135 $options->{order} = [split /\s*,\s*/, shift @ARGV];
139 push @{$options->{bsp}}, "-sRGBtex", "-sRGBcolor";
140 push @{$options->{light}}, "-sRGBtex", "-sRGBcolor", "-sRGBlight"
141 if defined $options->{light};
143 elsif($_ eq '-nosRGB')
145 push @{$options->{bsp}}, "-nosRGBtex", "-nosRGBcolor";
146 push @{$options->{light}}, "-nosRGBtex", "-nosRGBcolor", "-nosRGBlight"
147 if defined $options->{light};
149 elsif($_ =~ /^--no(-.*)/)
151 if($curmode eq 'maps')
156 @{$options->{$curmode}} = grep { (($_ eq $flag) ... /^-/) !~ /^[0-9]+$/ } @{$options->{$curmode}};
157 # so, e.g. --no-samplesize removes "-samplesize" and a following "3"
159 elsif($_ =~ /^-(-.*)/)
161 if($curmode eq 'maps')
165 push @{$options->{$curmode}}, $1;
167 elsif($_ =~ /^-/ and $curmode eq 'maps')
170 push @{$options->{$curmode}}, $_;
174 push @{$options->{$curmode}}, $_;
176 if(defined $enterflags)
178 $curmode = $enterflags;
185 $options->{$curmode} = [];
190 my $linkdir = File::Temp::tempdir("xonotic-map-compiler.XXXXXX", TMPDIR => 1, CLEANUP => 1);
196 $timeout = $options->{bsp_timeout} if $mode eq '-bsp';
197 $timeout = $options->{vis_timeout} if $mode eq '-vis';
198 $timeout = $options->{light_timeout} if $mode eq '-light';
199 $timeout = $options->{minimap_timeout} if $mode eq '-minimap';
200 $timeout = $options->{scale_timeout} if $mode eq '-scale';
201 die "Invalid call: not a standard q3map2 stage" if not defined $timeout;
202 my @args = ($Q3MAP2, split(/\s+/, $Q3MAP2FLAGS), '-game', 'xonotic', '-fs_basepath', $XONOTICDIR, '-fs_basepath', $linkdir, '-v', @_);
204 defined(my $pid = fork())
208 local $SIG{ALRM} = sub { warn "SIGALRM caught\n"; kill TERM => $pid; };
211 if(waitpid($pid, 0) != $pid)
213 die "waitpid: did not return our child process $pid: $!";
225 (my $mapdir = getcwd()) =~ s!/[^/]*(?:$)!!;
226 $mapdir = "/" if $mapdir eq "";
227 symlink "$mapdir", "$linkdir/data";
229 my ($prescale, $postscale) = ($options->{scalefactor} =~ /^([0-9.]+)(?::([0-9.]+))?$/);
230 $prescale = 1 if not defined $prescale;
231 $postscale = 1 if not defined $postscale;
233 for my $m(@{$options->{maps}})
235 $m =~ s/\.(?:map|bsp)$//;
239 unshift @{$options->{bsp}}, "-keeplights";
242 my %shaders = map { m!/([^/.]*)\.shader(?:$)! ? ($1 => 1) : () } glob "$mapdir/scripts/*.shader";
244 my $restore_shaderlist = sub { };
245 if(!$options->{noshaderlist})
247 local $ENV{mapdir} = $mapdir;
248 system 'cd $mapdir; make -C ../scripts shaderlist.txt';
250 $restore_shaderlist = sub
252 local $ENV{mapdir} = $mapdir;
253 system 'cd $mapdir; git checkout ../scripts/shaderlist.txt';
257 local $SIG{INT} = sub
259 print "SIGINT caught, cleaning up...\n";
260 $restore_shaderlist->();
266 unlink <$m/lm_*>; # delete old external lightmaps
267 q3map2 '-bsp', @{$options->{bsp}}, "$m.map"
271 q3map2 '-scale', @{$options->{scale}}, $prescale, "$m.bsp"
273 rename "${m}_s.bsp", "$m.bsp"
274 or die "rename ${m}_s.bsp $m.bsp: $!";
276 my @o = @{$options->{order}};
277 push @o, qw/light vis/;
285 if(defined $options->{light})
287 q3map2 '-light', @{$options->{light}}, "$m.map"
293 if(defined $options->{vis})
295 q3map2 '-vis', @{$options->{vis}}, "$m.map"
303 q3map2 '-scale', @{$options->{scale}}, $postscale, "$m.bsp"
305 rename "${m}_s.bsp", "$m.bsp"
306 or die "rename ${m}_s.bsp $m.bsp: $!";
309 if(defined $options->{minimap})
311 q3map2 '-minimap', @{$options->{minimap}}, "$m.map"
312 or die "-minimap: $?";
318 $restore_shaderlist->();
323 $restore_shaderlist->();