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 = getcwd();
14 # Path to your q3map2 program. You find it in your netradiant/build
16 our $Q3MAP2 = getcwd() . '/netradiant/build/q3map2';
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 = '-lightmapsize 1024 -lightmapsearchpower 4 -deluxe -patchshadows -randomsamples -samples 4 -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,scale';
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],
64 timeout_stealing => 0,
72 my $enterflags = undef;
83 $enterflags = 'light';
85 elsif($_ eq '-minimap')
87 $enterflags = 'minimap';
95 $options->{scalefactor} = @ARGV ? shift(@ARGV) : 1;
96 $enterflags = 'scale';
100 $options->{vis} = undef;
102 elsif($_ eq '-nolight')
104 $options->{light} = undef;
106 elsif($_ eq '-nominimap')
108 $options->{minimap} = undef;
110 elsif($_ eq '-bsp_timeout')
112 $options->{bsp_timeout} = shift @ARGV;
114 elsif($_ eq '-vis_timeout')
116 $options->{vis_timeout} = shift @ARGV;
118 elsif($_ eq '-light_timeout')
120 $options->{light_timeout} = shift @ARGV;
122 elsif($_ eq '-minimap_timeout')
124 $options->{minimap_timeout} = shift @ARGV;
126 elsif($_ eq '-scale_timeout')
128 $options->{scale_timeout} = shift @ARGV;
130 elsif($_ eq '-timeout_stealing')
132 $options->{timeout_stealing} = shift @ARGV;
134 elsif($_ eq '-order')
136 $options->{order} = [split /\s*,\s*/, shift @ARGV];
140 push @{$options->{bsp}}, "-sRGBtex", "-sRGBcolor";
141 push @{$options->{light}}, "-sRGBtex", "-sRGBcolor", "-sRGBlight"
142 if defined $options->{light};
144 elsif($_ eq '-nosRGB')
146 push @{$options->{bsp}}, "-nosRGBtex", "-nosRGBcolor";
147 push @{$options->{light}}, "-nosRGBtex", "-nosRGBcolor", "-nosRGBlight"
148 if defined $options->{light};
150 elsif($_ =~ /^--no(-.*)/)
152 if($curmode eq 'maps')
157 @{$options->{$curmode}} = grep { (($_ eq $flag) ... /^-/) !~ /^[0-9]+$/ } @{$options->{$curmode}};
158 # so, e.g. --no-samplesize removes "-samplesize" and a following "3"
160 elsif($_ =~ /^-(-.*)/)
162 if($curmode eq 'maps')
166 push @{$options->{$curmode}}, $1;
168 elsif($_ =~ /^-/ and $curmode eq 'maps')
171 push @{$options->{$curmode}}, $_;
175 push @{$options->{$curmode}}, $_;
177 if(defined $enterflags)
179 $curmode = $enterflags;
186 $options->{$curmode} = [];
191 my $linkdir = File::Temp::tempdir("xonotic-map-compiler.XXXXXX", TMPDIR => 1, CLEANUP => 1);
192 my $starttime = time;
199 $timeout = $options->{bsp_timeout} if $mode eq '-bsp';
200 $timeout = $options->{vis_timeout} if $mode eq '-vis';
201 $timeout = $options->{light_timeout} if $mode eq '-light';
202 $timeout = $options->{minimap_timeout} if $mode eq '-minimap';
203 $timeout = $options->{scale_timeout} if $mode eq '-scale';
204 die "Invalid call: not a standard q3map2 stage" if not defined $timeout;
205 $endtime += $timeout;
206 my $stolen_timeout = $endtime - time;
207 if ($stolen_timeout > $timeout)
209 $timeout += ($stolen_timeout - $timeout) * $options->{timeout_stealing};
211 my @args = ($Q3MAP2, split(/\s+/, $Q3MAP2FLAGS), '-game', 'xonotic', '-fs_basepath', $XONOTICDIR, '-fs_basepath', $linkdir, '-v', @_);
213 print "Using timeout: $timeout\n";
214 defined(my $pid = fork())
218 local $SIG{ALRM} = sub { warn "SIGALRM caught\n"; kill TERM => $pid; };
221 if(waitpid($pid, 0) != $pid)
223 die "waitpid: did not return our child process $pid: $!";
235 if ($options->{scalefactor} =~ /^([0-9.]+):([0-9.]+)$/)
237 die "Two-scale isn't supported"
238 if $1 != 1 and $2 != 1;
239 $options->{scalefactor} = $1
241 $options->{scalefactor} = $2
245 my $origcwd = getcwd();
246 for my $m(@{$options->{maps}})
249 or die "chdir $origcwd: $!";
254 or die "chdir $predir: $!";
256 symlink getcwd() . "/..", "$linkdir/data"
257 or die "symlink $linkdir/data: $!";
259 $m =~ s/\.(?:map|bsp)$//;
261 # never hurts, may help with rtlights
262 unshift @{$options->{bsp}}, "-keeplights";
264 local $SIG{INT} = sub
266 print "SIGINT caught, cleaning up...\n";
270 unlink <$m/lm_*>; # delete old external lightmaps
271 q3map2 '-bsp', @{$options->{bsp}}, "$m.map"
273 my @o = @{$options->{order}};
274 push @o, qw/vis scale light/;
282 if(defined $options->{light})
284 q3map2 '-light', @{$options->{light}}, "$m.map"
290 if(defined $options->{vis})
292 q3map2 '-vis', @{$options->{vis}}, "$m.map"
298 if ($options->{scalefactor} != 1)
300 q3map2 '-scale', @{$options->{scale}}, $options->{scalefactor}, "$m.bsp"
302 rename "${m}_s.bsp", "$m.bsp"
303 or die "rename ${m}_s.bsp $m.bsp: $!";
308 if(defined $options->{minimap})
310 q3map2 '-minimap', @{$options->{minimap}}, "$m.map"
311 or die "-minimap: $?";