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';
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...] [-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],
66 my $enterflags = undef;
77 $enterflags = 'light';
79 elsif($_ eq '-minimap')
81 $enterflags = 'minimap';
89 $options->{scale} = (shift @ARGV) || 1;
90 $enterflags = 'scale';
94 $options->{vis} = undef;
96 elsif($_ eq '-nolight')
98 $options->{light} = undef;
100 elsif($_ eq '-nominimap')
102 $options->{minimap} = undef;
104 elsif($_ eq '-noshaderlist')
106 $options->{noshaderlist} = 1;
108 elsif($_ eq '-order')
110 $options->{order} = [split /\s*,\s*/, shift @ARGV];
112 elsif($_ =~ /^-(-.*)/)
114 if($curmode eq 'maps')
118 push @{$options->{$curmode}}, $1;
120 elsif($_ =~ /^-/ and $curmode eq 'maps')
123 push @{$options->{$curmode}}, $_;
127 push @{$options->{$curmode}}, $_;
129 if(defined $enterflags)
131 $curmode = $enterflags;
138 $options->{$curmode} = [];
143 my $linkdir = File::Temp::tempdir("xonotic-map-compiler.XXXXXX", TMPDIR => 1, CLEANUP => 1);
147 my @args = ($Q3MAP2, split(/\s+/, $Q3MAP2FLAGS), '-game', 'xonotic', '-fs_basepath', $XONOTICDIR, '-fs_basepath', $linkdir, '-v', @_);
149 return !system @args;
152 (my $mapdir = getcwd()) =~ s!/[^/]*(?:$)!!;
153 $mapdir = "/" if $mapdir eq "";
154 symlink "$mapdir", "$linkdir/data";
156 my ($prescale, $postscale) = ($options->{scale} =~ /^([0-9.]+)(?::([0-9.]+))?$/);
157 $postscale = 1 if not defined $postscale;
159 for my $m(@{$options->{maps}})
161 $m =~ s/\.(?:map|bsp)$//;
164 open my $checkfh, "<", "$m.map"
165 or die "open $m.map: $!";
169 /^\s*"_keeplights"\s+"1"\s*$/
174 die "$m does not define _keeplights to 1"
178 my %shaders = map { m!/([^/.]*)\.shader(?:$)! ? ($1 => 1) : () } glob "../scripts/*.shader";
180 my $restore_shaderlist = sub { };
181 if(!$options->{noshaderlist})
183 my $previous_shaderlist = undef;
185 if(open my $fh, "<", "$XONOTICDIR/data/scripts/shaderlist.txt")
192 # we may have to restore the file on exit
193 $previous_shaderlist = $shaderlist
194 if "$XONOTICDIR/data" eq $mapdir;
198 # possibly extract the shader list from a pk3?
199 local $ENV{N} = $XONOTICDIR;
200 $shaderlist = `cd "\$N" && for X in "\$N"/data/data*.pk3; do Y=\$X; done; unzip -p "\$Y" scripts/shaderlist.txt`;
203 my $shaderlist_new = "";
204 for(split /\r?\n|\r/, $shaderlist)
207 $shaderlist_new .= "$_\n";
211 for(sort keys %shaders)
213 $shaderlist_new .= "$_\n";
218 $shaderlist_new = undef;
221 $restore_shaderlist = sub
223 if(defined $shaderlist_new)
225 if(defined $previous_shaderlist)
227 open my $fh, ">", "$mapdir/scripts/shaderlist.txt";
228 print $fh $previous_shaderlist;
233 unlink "$mapdir/scripts/shaderlist.txt";
238 if(defined $shaderlist_new)
240 mkdir "$mapdir/scripts";
241 open my $fh, ">", "$mapdir/scripts/shaderlist.txt";
242 print $fh $shaderlist_new;
247 local $SIG{INT} = sub
249 print "SIGINT caught, cleaning up...\n";
250 $restore_shaderlist->();
256 unlink <$m/lm_*>; # delete old external lightmaps
257 q3map2 '-bsp', @{$options->{bsp}}, "$m.map"
261 q3map2 '-scale', @{$options->{scale}}, $prescale, "$m.bsp"
263 rename "${m}_s.bsp", "$m.bsp"
264 or die "rename ${m}_s.bsp $m.bsp: $!";
266 my @o = @{$options->{order}};
267 push @o, qw/light vis minimap/;
275 if(defined $options->{light})
277 q3map2 '-light', @{$options->{light}}, "$m.map"
283 if(defined $options->{vis})
285 q3map2 '-vis', @{$options->{vis}}, "$m.map"
291 if(defined $options->{minimap})
293 q3map2 '-minimap', @{$options->{minimap}}, "$m.map"
294 or die "-minimap: $?";
301 q3map2 '-scale', @{$options->{scale}}, $postscale, "$m.bsp"
303 rename "${m}_s.bsp", "$m.bsp"
304 or die "rename ${m}_s.bsp $m.bsp: $!";
310 $restore_shaderlist->();
315 $restore_shaderlist->();