7 # change these to match your system, or define them in ~/.nexuiz-map-compiler
8 # (just copy paste this part to the file ~/.nexuiz-map-compiler)
10 # Path to Nexuiz (where the data directory is in)
11 our $NEXUIZDIR = '/home/polzer/Nexvn/nexuiz';
13 # Path to your q3map2 program. You find it in your GtkRadiant/install
15 our $Q3MAP2 = '/home/users4/ommz/polzer/bin/q3map2.x86';
17 # General flags for q3map2 (for example -threads 4)
18 our $Q3MAP2FLAGS = '';
20 # Default flags for the -bsp stage
21 our $BSPFLAGS = '-samplesize 8 -minsamplesize 4 -mv 1000000 -mi 6000000';
23 # Default flags for the -vis stage
26 # Default flags for the -light stage
27 our $LIGHTFLAGS = '-deluxe -patchshadows -samples 3 -lightmapsize 512 -bounce 8 -fastbounce -bouncegrid';
29 # end of user changable part
31 do "$ENV{HOME}/.nexuiz-map-compiler";
37 $0 mapname [-bsp bspflags...] [-vis visflags...] [-light lightflags...]
44 bsp => [split /\s+/, $BSPFLAGS],
45 vis => [split /\s+/, $VISFLAGS],
46 light => [split /\s+/, $LIGHTFLAGS],
56 my $enterflags = undef;
57 if($_ eq '-bsp' or $_ eq '-meta')
67 $enterflags = 'light';
75 $options->{scale} = (shift @ARGV) || 1;
79 $options->{vis} = undef;
81 elsif($_ eq '-nolight')
83 $options->{light} = undef;
85 elsif($_ =~ /^-(-.*)/)
87 if($curmode eq 'maps')
91 push @{$options->{$curmode}}, $1;
93 elsif($_ =~ /^-/ and $curmode eq 'maps')
96 push @{$options->{$curmode}}, $_;
100 push @{$options->{$curmode}}, $_;
102 if(defined $enterflags)
104 $curmode = $enterflags;
111 $options->{$curmode} = [];
116 my $game = 'compile.' . int rand 99999999; # mktemp on win32?
120 my @args = ($Q3MAP2, split(/\s+/, $Q3MAP2FLAGS), '-game', 'nexuiz', '-fs_basepath', $NEXUIZDIR, '-fs_game', $game, '-v', @_);
122 return !system @args;
125 (my $mapdir = getcwd()) =~ s!/[^/]*(?:$)!!;
126 $mapdir = "/" if $mapdir eq "";
128 unlink "$NEXUIZDIR/$game";
132 symlink "$mapdir", "$NEXUIZDIR/$game"
133 or die "THROW: Setting up directory structure, $mapdir -> $NEXUIZDIR/$game: $!";
139 if $@ =~ /^THROW: (.*)/s;
140 # if we get here, symlinks do not work, as symlink() itself raised the exception
141 # this should only happen on Win32
144 die "Symlinks not supported ($@) but invalid OS signature, this must be MSWin32, but $^O got reported";
147 # TODO support Windows here somehow
148 # maybe by copying all files and copying back the finished compile? (ugh)
149 die "Windows is not supported yet.";
152 my ($prescale, $postscale) = ($options->{scale} =~ /^([0-9.]+)(?::([0-9.]+))?$/);
153 $postscale = 1 if not defined $postscale;
155 for my $m(@{$options->{maps}})
157 if($prescale != 1 or $postscale != 1)
159 open my $checkfh, "<", "$m.map"
160 or die "open $m.map: $!";
164 /^\s*"_keeplights"\s+"1"\s*$/
169 die "$m does not define _keeplights to 1"
173 my %shaders = map { m!/([^/.]*)\.shader(?:$)! ? ($1 => 1) : () } glob "../scripts/*.shader";
174 open my $shaderlist, "+<", "$NEXUIZDIR/data/scripts/shaderlist.txt"
175 or die "open $NEXUIZDIR/data/scripts/shaderlist.txt: $!";
176 my $previous_shaderlist = "";
179 $previous_shaderlist .= $_;
183 my $restore_shaderlist = sub
185 open $shaderlist, ">", "$NEXUIZDIR/data/scripts/shaderlist.txt";
186 print $shaderlist $previous_shaderlist;
189 local $SIG{INT} = sub
191 print "SIGINT caught, cleaning up...\n";
192 $restore_shaderlist->();
199 print $shaderlist "$_\n";
203 unlink <$m/lm_*>; # delete old external lightmaps
204 q3map2 '-bsp', '-meta', @{$options->{bsp}}, "$m.map"
208 q3map2 '-scale', $prescale, "$m.bsp"
210 rename "${m}_s.bsp", "$m.bsp"
211 or die "rename ${m}_s.bsp $m.bsp: $!";
213 if(defined $options->{vis})
215 q3map2 '-vis', @{$options->{vis}}, "$m.map"
218 if(defined $options->{light})
220 q3map2 '-light', @{$options->{light}}, "$m.map"
225 q3map2 '-scale', $postscale, "$m.bsp"
227 rename "${m}_s.bsp", "$m.bsp"
228 or die "rename ${m}_s.bsp $m.bsp: $!";
233 $restore_shaderlist->();
238 $restore_shaderlist->();