#!/usr/bin/perl use strict; use warnings; use POSIX; # change these to match your system, or define them in ~/.nexuiz-map-compiler # (just copy paste this part to the file ~/.nexuiz-map-compiler) # Path to Nexuiz (where the data directory is in) our $NEXUIZDIR = '/home/polzer/Nexvn/nexuiz'; # Path to your q3map2 program. You find it in your GtkRadiant/install # directory. our $Q3MAP2 = '/home/users4/ommz/polzer/bin/q3map2.x86'; # General flags for q3map2 (for example -threads 4) our $Q3MAP2FLAGS = ''; # Default flags for the -bsp stage our $BSPFLAGS = '-samplesize 8 -mv 1000000 -mi 6000000'; # Default flags for the -vis stage our $VISFLAGS = ''; # Default flags for the -light stage our $LIGHTFLAGS = '-deluxe -patchshadows -samples 3'; # end of user changable part do "$ENV{HOME}/.nexuiz-map-compiler"; sub Usage() { print < [split /\s+/, $BSPFLAGS], vis => [split /\s+/, $VISFLAGS], light => [split /\s+/, $LIGHTFLAGS], maps => [], scale => 1 }; my $curmode = 'maps'; while(@ARGV) { $_ = shift @ARGV; my $enterflags = undef; if($_ eq '-bsp' or $_ eq '-meta') { $enterflags = 'bsp'; } elsif($_ eq '-vis') { $enterflags = 'vis'; } elsif($_ eq '-light') { $enterflags = 'light'; } elsif($_ eq '-map') { $curmode = 'maps'; } elsif($_ eq '-scale') { $options->{scale} = (shift @ARGV) || 1; } elsif($_ eq '-novis') { $options->{vis} = undef; } elsif($_ eq '-nolight') { $options->{light} = undef; } elsif($_ =~ /^-/ and $curmode eq 'maps') { $curmode = 'bsp'; push @{$options->{$curmode}}, $_; } else { push @{$options->{$curmode}}, $_; } if(defined $enterflags) { $curmode = $enterflags; if($ARGV[0] eq '+') { shift @ARGV; } else { $options->{$curmode} = []; } } } sub q3map2(@) { my @args = ($Q3MAP2, split(/\s+/, $Q3MAP2FLAGS), '-game', 'quake3', '-fs_basepath', $NEXUIZDIR, '-fs_game', 'data', '-v', @_); print "\$ @args\n"; return !system @args; } (my $mapdir = getcwd()) =~ s!/[^/]*(?:$)!!; $mapdir = "/" if $mapdir eq ""; unlink "$ENV{HOME}/.q3a/data"; mkdir "$ENV{HOME}/.q3a"; symlink "$mapdir", "$ENV{HOME}/.q3a/data" or die "Setting up directory structure, $mapdir -> $ENV{HOME}/.q3a/data: $!"; my ($prescale, $postscale) = ($options->{scale} =~ /^([0-9.]+)(?::([0-9.]+))?$/); $postscale = 1 if not defined $postscale; for my $m(@{$options->{maps}}) { if($prescale != 1 or $postscale != 1) { open my $checkfh, "<", "$m.map" or die "open $m.map: $!"; my $keeplights = 0; while(<$checkfh>) { /^\s*"_keeplights"\s+"1"\s*$/ or next; $keeplights = 1; } close $checkfh; die "$m does not define _keeplights to 1" unless $keeplights; } my %shaders = map { m!/([^/.]*)\.shader(?:$)! ? ($1 => 1) : () } glob "../scripts/*.shader"; open my $shaderlist, "+<", "$NEXUIZDIR/data/scripts/shaderlist.txt" or die "open $NEXUIZDIR/data/scripts/shaderlist.txt: $!"; my $previous_shaderlist = ""; while(<$shaderlist>) { $previous_shaderlist .= $_; y/\r\n//d; delete $shaders{$_}; } my $restore_shaderlist = sub { open $shaderlist, ">", "$NEXUIZDIR/data/scripts/shaderlist.txt"; print $shaderlist $previous_shaderlist; close $shaderlist; }; local $SIG{INT} = sub { print "SIGINT caught, cleaning up...\n"; $restore_shaderlist->(); exit 0; }; eval { for(keys %shaders) { print $shaderlist "$_\n"; } close $shaderlist; q3map2 '-bsp', '-meta', @{$options->{bsp}}, "$m.map" or die "-bsp: $?"; if($prescale != 1) { q3map2 '-scale', $prescale, "$m.bsp" or die "-scale: $?"; rename "${m}_s.bsp", "$m.bsp" or die "rename ${m}_s.bsp $m.bsp: $!"; } if(defined $options->{vis}) { q3map2 '-vis', @{$options->{vis}}, "$m.map" or die "-vis: $?"; } if(defined $options->{light}) { q3map2 '-light', @{$options->{light}}, "$m.map" or die "-light: $?"; } if($postscale != 1) { q3map2 '-scale', $postscale, "$m.bsp" or die "-scale: $?"; rename "${m}_s.bsp", "$m.bsp" or die "rename ${m}_s.bsp $m.bsp: $!"; } unlink "$m.srf"; $restore_shaderlist->(); 1; } or do { $restore_shaderlist->(); die $@; }; }