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 if($prescale != 1 or $postscale != 1)
137 open my $checkfh, "<", "$m.map"
138 or die "open $m.map: $!";
142 /^\s*"_keeplights"\s+"1"\s*$/
147 die "$m does not define _keeplights to 1"
151 my %shaders = map { m!/([^/.]*)\.shader(?:$)! ? ($1 => 1) : () } glob "../scripts/*.shader";
153 my $previous_shaderlist = undef;
155 if(open my $fh, "<", "$NEXUIZDIR/scripts/shaderlist.txt")
162 # we may have to restore the file on exit
163 $previous_shaderlist = $shaderlist
164 if "$NEXUIZDIR/data" eq $mapdir;
168 # possibly extract the shader list from a pk3?
169 local $ENV{N} = $NEXUIZDIR;
170 $shaderlist = `cd "\$N" && for X in "\$N"/data/data*.pk3; do Y=\$X; done; unzip -p "\$Y" scripts/shaderlist.txt`;
173 my $shaderlist_new = "";
174 for(split /\r?\n|\r/, $shaderlist)
177 $shaderlist_new .= "$_\n";
181 for(sort keys %shaders)
183 $shaderlist_new .= "$_\n";
188 $shaderlist_new = undef;
191 my $restore_shaderlist = sub
193 if(defined $shaderlist_new)
195 if(defined $previous_shaderlist)
197 open my $fh, ">", "$mapdir/scripts/shaderlist.txt";
198 print $fh $previous_shaderlist;
203 unlink "$mapdir/scripts/shaderlist.txt";
207 local $SIG{INT} = sub
209 print "SIGINT caught, cleaning up...\n";
210 $restore_shaderlist->();
216 if(defined $shaderlist_new)
218 mkdir "$mapdir/scripts";
219 open my $fh, ">", "$mapdir/scripts/shaderlist.txt";
220 print $fh $shaderlist_new;
224 unlink <$m/lm_*>; # delete old external lightmaps
225 q3map2 '-bsp', '-meta', @{$options->{bsp}}, "$m.map"
229 q3map2 '-scale', $prescale, "$m.bsp"
231 rename "${m}_s.bsp", "$m.bsp"
232 or die "rename ${m}_s.bsp $m.bsp: $!";
234 if(defined $options->{light})
236 q3map2 '-light', @{$options->{light}}, "$m.map"
239 if(defined $options->{vis})
241 q3map2 '-vis', @{$options->{vis}}, "$m.map"
246 q3map2 '-scale', $postscale, "$m.bsp"
248 rename "${m}_s.bsp", "$m.bsp"
249 or die "rename ${m}_s.bsp $m.bsp: $!";
254 $restore_shaderlist->();
259 $restore_shaderlist->();