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 = '/home/rpolzer/Games/Xonotic';
14 # Path to your q3map2 program. You find it in your GtkRadiant/install
16 our $Q3MAP2 = '/home/rpolzer/Games/Xonotic/netradiant/install/q3map2.x86';
18 # General flags for q3map2 (for example -threads 4)
19 our $Q3MAP2FLAGS = '';
21 # Default flags for the -bsp stage
22 our $BSPFLAGS = '-meta -samplesize 8 -minsamplesize 4 -mv 1000000 -mi 6000000';
24 # Default flags for the -vis stage
27 # Default flags for the -light stage
28 our $LIGHTFLAGS = '-deluxe -patchshadows -samples 3 -lightmapsize 512 -bounce 8 -fastbounce -bouncegrid';
30 # Default flags for the -minimap stage
31 our $MINIMAPFLAGS = '';
33 # Default order of commands
34 our $ORDER = 'light,vis,minimap';
36 # end of user changable part
38 do "$ENV{HOME}/.xonotic-map-compiler";
44 $0 mapname [-bsp bspflags...] [-vis visflags...] [-light lightflags...]
51 bsp => [split /\s+/, $BSPFLAGS],
52 vis => [split /\s+/, $VISFLAGS],
53 light => [split /\s+/, $LIGHTFLAGS],
54 minimap => [split /\s+/, $MINIMAPFLAGS],
55 order => [split /\s*,\s*/, $ORDER],
65 my $enterflags = undef;
76 $enterflags = 'light';
78 elsif($_ eq '-minimap')
80 $enterflags = 'minimap';
88 $options->{scale} = (shift @ARGV) || 1;
92 $options->{vis} = undef;
94 elsif($_ eq '-nolight')
96 $options->{light} = undef;
98 elsif($_ eq '-nominimap')
100 $options->{minimap} = undef;
102 elsif($_ eq '-noshaderlist')
104 $options->{noshaderlist} = 1;
106 elsif($_ eq '-order')
108 $options->{order} = [split /\s*,\s*/, shift @ARGV];
110 elsif($_ =~ /^-(-.*)/)
112 if($curmode eq 'maps')
116 push @{$options->{$curmode}}, $1;
118 elsif($_ =~ /^-/ and $curmode eq 'maps')
121 push @{$options->{$curmode}}, $_;
125 push @{$options->{$curmode}}, $_;
127 if(defined $enterflags)
129 $curmode = $enterflags;
136 $options->{$curmode} = [];
141 my $linkdir = File::Temp::tempdir("xonotic-map-compiler.XXXXXX", TMPDIR => 1, CLEANUP => 1);
145 my @args = ($Q3MAP2, split(/\s+/, $Q3MAP2FLAGS), '-game', 'xonotic', '-fs_basepath', $XONOTICDIR, '-fs_basepath', $linkdir, '-v', @_);
147 return !system @args;
150 (my $mapdir = getcwd()) =~ s!/[^/]*(?:$)!!;
151 $mapdir = "/" if $mapdir eq "";
152 symlink "$mapdir", "$linkdir/data";
154 my ($prescale, $postscale) = ($options->{scale} =~ /^([0-9.]+)(?::([0-9.]+))?$/);
155 $postscale = 1 if not defined $postscale;
157 for my $m(@{$options->{maps}})
159 $m =~ s/\.(?:map|bsp)$//;
162 open my $checkfh, "<", "$m.map"
163 or die "open $m.map: $!";
167 /^\s*"_keeplights"\s+"1"\s*$/
172 die "$m does not define _keeplights to 1"
176 my %shaders = map { m!/([^/.]*)\.shader(?:$)! ? ($1 => 1) : () } glob "../scripts/*.shader";
178 my $restore_shaderlist = sub { };
179 if(!$options->{noshaderlist})
181 my $previous_shaderlist = undef;
183 if(open my $fh, "<", "$XONOTICDIR/data/xonotic-maps.pk3dir/scripts/shaderlist.txt")
190 # we may have to restore the file on exit
191 $previous_shaderlist = $shaderlist
192 if "$XONOTICDIR/data" eq $mapdir;
196 # possibly extract the shader list from a pk3?
197 local $ENV{N} = $XONOTICDIR;
198 $shaderlist = `cd "\$N" && for X in "\$N"/data/data*.pk3; do Y=\$X; done; unzip -p "\$Y" scripts/shaderlist.txt`;
201 my $shaderlist_new = "";
202 for(split /\r?\n|\r/, $shaderlist)
205 $shaderlist_new .= "$_\n";
209 for(sort keys %shaders)
211 $shaderlist_new .= "$_\n";
216 $shaderlist_new = undef;
219 $restore_shaderlist = sub
221 if(defined $shaderlist_new)
223 if(defined $previous_shaderlist)
225 open my $fh, ">", "$mapdir/scripts/shaderlist.txt";
226 print $fh $previous_shaderlist;
231 unlink "$mapdir/scripts/shaderlist.txt";
236 if(defined $shaderlist_new)
238 mkdir "$mapdir/scripts";
239 open my $fh, ">", "$mapdir/scripts/shaderlist.txt";
240 print $fh $shaderlist_new;
245 local $SIG{INT} = sub
247 print "SIGINT caught, cleaning up...\n";
248 $restore_shaderlist->();
254 unlink <$m/lm_*>; # delete old external lightmaps
255 q3map2 '-bsp', @{$options->{bsp}}, "$m.map"
259 q3map2 '-scale', $prescale, "$m.bsp"
261 rename "${m}_s.bsp", "$m.bsp"
262 or die "rename ${m}_s.bsp $m.bsp: $!";
264 my @o = @{$options->{order}};
265 push @o, qw/light vis minimap/;
273 if(defined $options->{light})
275 q3map2 '-light', @{$options->{light}}, "$m.map"
281 if(defined $options->{vis})
283 q3map2 '-vis', @{$options->{vis}}, "$m.map"
289 if(defined $options->{minimap})
291 q3map2 '-minimap', @{$options->{minimap}}, "$m.map"
292 or die "-minimap: $?";
299 q3map2 '-scale', $postscale, "$m.bsp"
301 rename "${m}_s.bsp", "$m.bsp"
302 or die "rename ${m}_s.bsp $m.bsp: $!";
308 $restore_shaderlist->();
313 $restore_shaderlist->();