]> icculus.org git repositories - divverent/nexuiz.git/blob - misc/nexuiz-map-compiler
added my map compile script to svn
[divverent/nexuiz.git] / misc / nexuiz-map-compiler
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use POSIX;
6
7 # change these to match your system
8
9         # Path to Nexuiz (where the data directory is in)
10         my $NEXUIZDIR   = '/home/polzer/Nexvn/nexuiz';
11
12         # Path to your q3map2 program. You find it in your GtkRadiant/install
13         # directory.
14         my $Q3MAP2      = '/home/users4/ommz/polzer/bin/q3map2.x86';
15
16         # General flags for q3map2 (for example -threads 4)
17         my $Q3MAP2FLAGS = '';
18
19         # Default flags for the -bsp stage
20         my $BSPFLAGS    = '-samplesize 8';
21
22         # Default flags for the -vis stage
23         my $VISFLAGS    = '';
24
25         # Default flags for the -light stage
26         my $LIGHTFLAGS  = '-deluxe -patchshadows -samples 3';
27
28 # end of user changable part
29
30 sub Usage()
31 {
32         print <<EOF;
33 Usage:
34 $0 mapname [-bsp bspflags...] [-vis visflags...] [-light lightflags...]
35 EOF
36         exit 1;
37 }
38
39 my $options =
40 {
41         bsp => [split /\s+/, $BSPFLAGS],
42         vis => [split /\s+/, $VISFLAGS],
43         light => [split /\s+/, $LIGHTFLAGS],
44         maps => [],
45         scale => 1
46 };
47
48 my $curmode = 'maps';
49
50 while(@ARGV)
51 {
52         $_ = shift @ARGV;
53         my $enterflags = undef;
54         if($_ eq '-bsp' or $_ eq '-meta')
55         {
56                 $enterflags = 'bsp';
57         }
58         elsif($_ eq '-vis')
59         {
60                 $enterflags = 'vis';
61         }
62         elsif($_ eq '-light')
63         {
64                 $enterflags = 'light';
65         }
66         elsif($_ eq '-map')
67         {
68                 $curmode = 'maps';
69         }
70         elsif($_ eq '-scale')
71         {
72                 $options->{scale} = (shift @ARGV) || 1;
73         }
74         elsif($_ =~ /^-/ and $curmode eq 'maps')
75         {
76                 $curmode = 'bsp';
77                 push @{$options->{$curmode}}, $_;
78         }
79         else
80         {
81                 push @{$options->{$curmode}}, $_;
82         }
83         if(defined $enterflags)
84         {
85                 $curmode = $enterflags;
86                 if($ARGV[0] eq '+')
87                 {
88                         shift @ARGV;
89                 }
90                 else
91                 {
92                         $options->{$curmode} = [];
93                 }
94         }
95 }
96
97 sub q3map2(@)
98 {
99         my @args = @_;
100         return !system $Q3MAP2, '-game', 'quake3', '-fs_basepath', $NEXUIZDIR, '-fs_game', 'data', '-v', @_;
101 }
102
103 (my $mapdir = getcwd()) =~ s!/[^/]*(?:$)!!;
104
105 unlink "$ENV{HOME}/.q3a/data";
106 mkdir "$ENV{HOME}/.q3a";
107 symlink "$mapdir", "$ENV{HOME}/.q3a/data"
108         or die "Setting up directory structure, $mapdir -> $ENV{HOME}/.q3a/data: $!";
109
110 for my $m(@{$options->{maps}})
111 {
112         if($options->{scale} != 1)
113         {
114                 open my $checkfh, "<", "$m.map"
115                         or die "open $m.map: $!";
116                 my $keeplights = 0;
117                 while(<$checkfh>)
118                 {
119                         /^\s*"_keeplights"\s+"1"\s*$/
120                                 or next;
121                         $keeplights = 1;
122                 }
123                 close $checkfh;
124                 die "$m does not define _keeplights to 1"
125                         unless $keeplights;
126         }
127
128         my %shaders = map { m!/([^/.]*)\.shader(?:$)! ? ($1 => 1) : () } glob "../scripts/*.shader";
129         open my $shaderlist, "+<", "$NEXUIZDIR/data/scripts/shaderlist.txt"
130                 or die "open $NEXUIZDIR/data/scripts/shaderlist.txt: $!";
131         while(<$shaderlist>)
132         {
133                 y/\r\n//d;
134                 delete $shaders{$_};
135         }
136         for(keys %shaders)
137         {
138                 print $shaderlist "$_\n";
139         }
140         close $shaderlist;
141
142         q3map2 '-bsp', '-meta', @{$options->{bsp}},   "$m.map"
143                 or die "-bsp: $?";
144         if($options->{scale} != 1)
145         {
146                 q3map2 '-scale', $options->{scale}, "$m.bsp"
147                         or die "-scale: $?";
148                 rename "${m}_s.bsp", "$m.bsp"
149                         or die "rename ${m}_s.bsp $m.bsp: $!";
150         }
151         q3map2 '-vis',          @{$options->{vis}},   "$m.map"
152                 or die "-vis: $?";
153         q3map2 '-light',        @{$options->{light}}, "$m.map"
154                 or die "-light: $?";
155
156         unlink "$m.srf";
157 }