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", 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";
152 if(!-f "$NEXUIZDIR/data/scripts/shaderlist.txt")
154 # possibly extract the shader list from a pk3?
155 local $ENV{D} = $NEXUIZDIR;
156 system q{cd "$D" && for X in data/data*.pk3; do unzip -o "$X" scripts/shaderlist.txt; done};
158 open my $shaderlist, "+<", "$NEXUIZDIR/data/scripts/shaderlist.txt"
159 or die "open $NEXUIZDIR/data/scripts/shaderlist.txt: $!";
160 my $previous_shaderlist = "";
163 $previous_shaderlist .= $_;
167 my $restore_shaderlist = sub
169 open $shaderlist, ">", "$NEXUIZDIR/data/scripts/shaderlist.txt";
170 print $shaderlist $previous_shaderlist;
173 local $SIG{INT} = sub
175 print "SIGINT caught, cleaning up...\n";
176 $restore_shaderlist->();
183 print $shaderlist "$_\n";
187 unlink <$m/lm_*>; # delete old external lightmaps
188 q3map2 '-bsp', '-meta', @{$options->{bsp}}, "$m.map"
192 q3map2 '-scale', $prescale, "$m.bsp"
194 rename "${m}_s.bsp", "$m.bsp"
195 or die "rename ${m}_s.bsp $m.bsp: $!";
197 if(defined $options->{light})
199 q3map2 '-light', @{$options->{light}}, "$m.map"
202 if(defined $options->{vis})
204 q3map2 '-vis', @{$options->{vis}}, "$m.map"
209 q3map2 '-scale', $postscale, "$m.bsp"
211 rename "${m}_s.bsp", "$m.bsp"
212 or die "rename ${m}_s.bsp $m.bsp: $!";
217 $restore_shaderlist->();
222 $restore_shaderlist->();