]> git.xonotic.org Git - xonotic/xonotic.git/commitdiff
Merge branch 'master' of git://de.git.xonotic.org/xonotic/xonotic xonotic-v0.5.0
authorRudolf Polzer <divVerent@xonotic.org>
Mon, 5 Sep 2011 11:09:24 +0000 (13:09 +0200)
committerRudolf Polzer <divVerent@xonotic.org>
Mon, 5 Sep 2011 11:09:24 +0000 (13:09 +0200)
misc/tools/bsptool-shaderfun.sh [new file with mode: 0755]
misc/tools/bsptool.pl

diff --git a/misc/tools/bsptool-shaderfun.sh b/misc/tools/bsptool-shaderfun.sh
new file mode 100755 (executable)
index 0000000..b6b656d
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# input: a .shader file
+# parameters: in and out .bsp file
+
+BSPTOOL="${0%/*}"/bsptool.pl
+LF="
+"
+
+in=$1
+out=$2
+
+shaders=`"$BSPTOOL" "$in" -S`
+
+newshaders=`cat | grep '^[^    {}]'`
+
+set --
+
+list=
+for shader in $shaders; do
+       if [ -z "$list" ]; then
+               echo >&2 "Filling list..."
+               list=`echo "$newshaders" | sort -R`$LF
+       fi
+       case "$shader" in
+               noshader|NULL|textures/common/*)
+                       ;;
+               *)
+                       item=${list%%$LF*}
+                       list=${list#*$LF}
+                       set -- "$@" "-S$shader=$item"
+                       ;;
+       esac
+done
+
+set -- "$BSPTOOL" "$in" "$@" -o"$out"
+"$@"
index efc6cccb2efa3a2770e7c99a4cc81cfd3d97cb81..1a4352f2bf7860dba3a626c1ba194d043cfb77b5 100755 (executable)
@@ -22,6 +22,7 @@ Operations are:
   Information requests:
     -i                print info about the BSP file
     -xlumpname        extract a lump (see -i)
+    -S                list used shaders
 
   Changes:
     -dlumpname        delete a lump (see -i)
@@ -32,6 +33,7 @@ Operations are:
     -lpng             externalize the lightmaps as PNG
     -ltga             externalize the lightmaps as TGA
     -mMESSAGE         set the BSP file comment message
+    -Sfrom=to         replace a texture (shader) by name (already replaced shaders are not touched)
 
   Save commands:
     -o                actually apply the changes to the BSP
@@ -93,7 +95,11 @@ sub DecodeLump($@)
                        $spec .= "$2$3 ";
                        my $f = $1;
                        my $n = $3;
-                       if($n eq '')
+                       if($2 eq 'a')
+                       {
+                               push @decoders, sub { ($item->{$f} = $data[$idx++]) =~ s/\0//g; };
+                       }
+                       elsif($n eq '')
                        {
                                push @decoders, sub { $item->{$f} = $data[$idx++]; };
                        }
@@ -141,7 +147,11 @@ sub EncodeLump($@)
                        my $spec = "$2$3";
                        my $f = $1;
                        my $n = $3;
-                       if($n eq '')
+                       if($2 eq 'a')
+                       {
+                               push @encoders, sub { $data .= pack $spec, $item->{$f}; };
+                       }
+                       elsif($n eq '')
                        {
                                push @encoders, sub { $data .= pack $spec, $item->{$f}; };
                        }
@@ -481,6 +491,30 @@ for(@ARGV)
                        unless defined $id;
                print $bsp[$id]->[2];
        }
+       elsif(/^-S(.*)=(.*)$/)
+       {
+               my $from = $1;
+               my $to = $2;
+               our @replaced = ();
+               my @l = DecodeLump $bsp[$lumpid{textures}]->[2], qw/name=a64 flags=V contents=V/;
+               for(0..@l-1)
+               {
+                       next if $replaced[$_];
+                       if($l[$_]->{name} eq $from)
+                       {
+                               $replaced[$_] = 1;
+                               $l[$_]->{name} = $to;
+                       }
+               }
+               $bsp[$lumpid{textures}]->[2] = EncodeLump \@l, qw/name=a64 flags=V contents=V/;
+       }
+       elsif(/^-S$/)
+       {
+               for(DecodeLump $bsp[$lumpid{textures}]->[2], qw/name=a64 flags=V contents=V/)
+               {
+                       print "$_->{name}\n";
+               }
+       }
        elsif(/^-o(.+)?$/) # write the final BSP file
        {
                my $outfile = $1;