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 # end of user changable part
32 do "$ENV{HOME}/.nexuiz-map-compiler";
38 $0 mapname [-bsp bspflags...] [-vis visflags...] [-light lightflags...]
45 bsp => [split /\s+/, $BSPFLAGS],
46 vis => [split /\s+/, $VISFLAGS],
47 light => [split /\s+/, $LIGHTFLAGS],
57 my $enterflags = undef;
58 if($_ eq '-bsp' or $_ eq '-meta')
68 $enterflags = 'light';
76 $options->{scale} = (shift @ARGV) || 1;
80 $options->{vis} = undef;
82 elsif($_ eq '-nolight')
84 $options->{light} = undef;
86 elsif($_ =~ /^-(-.*)/)
88 if($curmode eq 'maps')
92 push @{$options->{$curmode}}, $1;
94 elsif($_ =~ /^-/ and $curmode eq 'maps')
97 push @{$options->{$curmode}}, $_;
101 push @{$options->{$curmode}}, $_;
103 if(defined $enterflags)
105 $curmode = $enterflags;
112 $options->{$curmode} = [];
117 my $linkdir = File::Temp::tempdir("nexuiz-map-compiler.XXXXXX", TMPDIR => 1, CLEANUP => 1);
121 my @args = ($Q3MAP2, split(/\s+/, $Q3MAP2FLAGS), '-game', 'nexuiz', '-fs_basepath', $NEXUIZDIR, '-fs_basepath', $linkdir, '-v', @_);
123 return !system @args;
126 (my $mapdir = getcwd()) =~ s!/[^/]*(?:$)!!;
127 $mapdir = "/" if $mapdir eq "";
128 symlink "$mapdir", "$linkdir/data";
130 my ($prescale, $postscale) = ($options->{scale} =~ /^([0-9.]+)(?::([0-9.]+))?$/);
131 $postscale = 1 if not defined $postscale;
133 for my $m(@{$options->{maps}})
135 $m =~ s/\.(?:map|bsp)$//;
136 if($prescale != 1 or $postscale != 1)
138 open my $checkfh, "<", "$m.map"
139 or die "open $m.map: $!";
143 /^\s*"_keeplights"\s+"1"\s*$/
148 die "$m does not define _keeplights to 1"
152 my %shaders = map { m!/([^/.]*)\.shader(?:$)! ? ($1 => 1) : () } glob "../scripts/*.shader";
154 my $previous_shaderlist = undef;
156 if(open my $fh, "<", "$NEXUIZDIR/scripts/shaderlist.txt")
163 # we may have to restore the file on exit
164 $previous_shaderlist = $shaderlist
165 if "$NEXUIZDIR/data" eq $mapdir;
169 # possibly extract the shader list from a pk3?
170 local $ENV{N} = $NEXUIZDIR;
171 $shaderlist = `cd "\$N" && for X in "\$N"/data/data*.pk3; do Y=\$X; done; unzip -p "\$Y" scripts/shaderlist.txt`;
174 my $shaderlist_new = "";
175 for(split /\r?\n|\r/, $shaderlist)
178 $shaderlist_new .= "$_\n";
182 for(sort keys %shaders)
184 $shaderlist_new .= "$_\n";
189 $shaderlist_new = undef;
192 my $restore_shaderlist = sub
194 if(defined $shaderlist_new)
196 if(defined $previous_shaderlist)
198 open my $fh, ">", "$mapdir/scripts/shaderlist.txt";
199 print $fh $previous_shaderlist;
204 unlink "$mapdir/scripts/shaderlist.txt";
208 local $SIG{INT} = sub
210 print "SIGINT caught, cleaning up...\n";
211 $restore_shaderlist->();
217 if(defined $shaderlist_new)
219 mkdir "$mapdir/scripts";
220 open my $fh, ">", "$mapdir/scripts/shaderlist.txt";
221 print $fh $shaderlist_new;
225 unlink <$m/lm_*>; # delete old external lightmaps
226 q3map2 '-bsp', '-meta', @{$options->{bsp}}, "$m.map"
230 q3map2 '-scale', $prescale, "$m.bsp"
232 rename "${m}_s.bsp", "$m.bsp"
233 or die "rename ${m}_s.bsp $m.bsp: $!";
235 if(defined $options->{light})
237 q3map2 '-light', @{$options->{light}}, "$m.map"
240 if(defined $options->{vis})
242 q3map2 '-vis', @{$options->{vis}}, "$m.map"
247 q3map2 '-scale', $postscale, "$m.bsp"
249 rename "${m}_s.bsp", "$m.bsp"
250 or die "rename ${m}_s.bsp $m.bsp: $!";
255 $restore_shaderlist->();
260 $restore_shaderlist->();