8 # change these to match your system, or define them in ~/.nexuiz-map-compiler
9 # (just copy paste this part to the file ~/.nexuiz-map-compiler)
11 # Path to Nexuiz (where the data directory is in)
12 our $NEXUIZDIR = '/home/polzer/Nexvn/nexuiz';
14 # Path to your q3map2 program. You find it in your GtkRadiant/install
16 our $Q3MAP2 = '/home/users4/ommz/polzer/bin/q3map2.x86';
18 # General flags for q3map2 (for example -threads 4)
19 our $Q3MAP2FLAGS = '';
21 # Default flags for the -bsp stage
22 our $BSPFLAGS = '-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 # end of user changable part
35 do "$ENV{HOME}/.nexuiz-map-compiler";
41 $0 mapname [-bsp bspflags...] [-vis visflags...] [-light lightflags...]
48 bsp => [split /\s+/, $BSPFLAGS],
49 vis => [split /\s+/, $VISFLAGS],
50 light => [split /\s+/, $LIGHTFLAGS],
51 minimap => [split /\s+/, $MINIMAPFLAGS],
61 my $enterflags = undef;
62 if($_ eq '-bsp' or $_ eq '-meta')
72 $enterflags = 'light';
74 elsif($_ eq '-minimap')
76 $enterflags = 'minimap';
84 $options->{scale} = (shift @ARGV) || 1;
88 $options->{vis} = undef;
90 elsif($_ eq '-nolight')
92 $options->{light} = undef;
94 elsif($_ eq '-nominimap')
96 $options->{minimap} = undef;
98 elsif($_ =~ /^-(-.*)/)
100 if($curmode eq 'maps')
104 push @{$options->{$curmode}}, $1;
106 elsif($_ =~ /^-/ and $curmode eq 'maps')
109 push @{$options->{$curmode}}, $_;
113 push @{$options->{$curmode}}, $_;
115 if(defined $enterflags)
117 $curmode = $enterflags;
124 $options->{$curmode} = [];
129 my $linkdir = File::Temp::tempdir("nexuiz-map-compiler.XXXXXX", TMPDIR => 1, CLEANUP => 1);
133 my @args = ($Q3MAP2, split(/\s+/, $Q3MAP2FLAGS), '-game', 'nexuiz', '-fs_basepath', $NEXUIZDIR, '-fs_basepath', $linkdir, '-v', @_);
135 return !system @args;
138 (my $mapdir = getcwd()) =~ s!/[^/]*(?:$)!!;
139 $mapdir = "/" if $mapdir eq "";
140 symlink "$mapdir", "$linkdir/data";
142 my ($prescale, $postscale) = ($options->{scale} =~ /^([0-9.]+)(?::([0-9.]+))?$/);
143 $postscale = 1 if not defined $postscale;
145 for my $m(@{$options->{maps}})
147 $m =~ s/\.(?:map|bsp)$//;
148 if($prescale != 1 or $postscale != 1)
150 open my $checkfh, "<", "$m.map"
151 or die "open $m.map: $!";
155 /^\s*"_keeplights"\s+"1"\s*$/
160 die "$m does not define _keeplights to 1"
164 my %shaders = map { m!/([^/.]*)\.shader(?:$)! ? ($1 => 1) : () } glob "../scripts/*.shader";
166 my $previous_shaderlist = undef;
168 if(open my $fh, "<", "$NEXUIZDIR/scripts/shaderlist.txt")
175 # we may have to restore the file on exit
176 $previous_shaderlist = $shaderlist
177 if "$NEXUIZDIR/data" eq $mapdir;
181 # possibly extract the shader list from a pk3?
182 local $ENV{N} = $NEXUIZDIR;
183 $shaderlist = `cd "\$N" && for X in "\$N"/data/data*.pk3; do Y=\$X; done; unzip -p "\$Y" scripts/shaderlist.txt`;
186 my $shaderlist_new = "";
187 for(split /\r?\n|\r/, $shaderlist)
190 $shaderlist_new .= "$_\n";
194 for(sort keys %shaders)
196 $shaderlist_new .= "$_\n";
201 $shaderlist_new = undef;
204 my $restore_shaderlist = sub
206 if(defined $shaderlist_new)
208 if(defined $previous_shaderlist)
210 open my $fh, ">", "$mapdir/scripts/shaderlist.txt";
211 print $fh $previous_shaderlist;
216 unlink "$mapdir/scripts/shaderlist.txt";
220 local $SIG{INT} = sub
222 print "SIGINT caught, cleaning up...\n";
223 $restore_shaderlist->();
229 if(defined $shaderlist_new)
231 mkdir "$mapdir/scripts";
232 open my $fh, ">", "$mapdir/scripts/shaderlist.txt";
233 print $fh $shaderlist_new;
237 unlink <$m/lm_*>; # delete old external lightmaps
238 q3map2 '-bsp', '-meta', @{$options->{bsp}}, "$m.map"
242 q3map2 '-scale', $prescale, "$m.bsp"
244 rename "${m}_s.bsp", "$m.bsp"
245 or die "rename ${m}_s.bsp $m.bsp: $!";
247 if(defined $options->{light})
249 q3map2 '-light', @{$options->{light}}, "$m.map"
252 if(defined $options->{vis})
254 q3map2 '-vis', @{$options->{vis}}, "$m.map"
259 q3map2 '-scale', $postscale, "$m.bsp"
261 rename "${m}_s.bsp", "$m.bsp"
262 or die "rename ${m}_s.bsp $m.bsp: $!";
264 if(defined $options->{minimap})
266 q3map2 '-minimap', @{$options->{minimap}}, "$m.map"
267 or die "-minimap: $?";
272 $restore_shaderlist->();
277 $restore_shaderlist->();