… | |
… | |
4 | |
4 | |
5 | =cut |
5 | =cut |
6 | |
6 | |
7 | package Crossfire; |
7 | package Crossfire; |
8 | |
8 | |
9 | our $VERSION = '0.99'; |
9 | our $VERSION = '1.11'; |
10 | |
10 | |
11 | use strict; |
11 | use strict; |
12 | |
12 | |
13 | use base 'Exporter'; |
13 | use base 'Exporter'; |
14 | |
14 | |
… | |
… | |
16 | use File::Spec; |
16 | use File::Spec; |
17 | use List::Util qw(min max); |
17 | use List::Util qw(min max); |
18 | use Storable qw(freeze thaw); |
18 | use Storable qw(freeze thaw); |
19 | |
19 | |
20 | our @EXPORT = qw( |
20 | our @EXPORT = qw( |
21 | read_pak read_arch *ARCH TILESIZE $TILE *FACE editor_archs arch_extents |
21 | read_pak read_arch |
|
|
22 | *ARCH $TILE *FACE *FACEDATA |
|
|
23 | TILESIZE CACHESTRIDE |
|
|
24 | editor_archs arch_extents |
22 | ); |
25 | ); |
23 | |
26 | |
24 | use JSON::XS qw(from_json to_json); |
27 | use JSON::XS qw(from_json to_json); |
25 | |
28 | |
26 | our $LIB = $ENV{CROSSFIRE_LIBDIR}; |
29 | our $LIB = $ENV{CROSSFIRE_LIBDIR}; |
… | |
… | |
29 | : $ENV{AppData} ? "$ENV{APPDATA}/crossfire" |
32 | : $ENV{AppData} ? "$ENV{APPDATA}/crossfire" |
30 | : File::Spec->tmpdir . "/crossfire"; |
33 | : File::Spec->tmpdir . "/crossfire"; |
31 | |
34 | |
32 | mkdir $VARDIR, 0777; |
35 | mkdir $VARDIR, 0777; |
33 | |
36 | |
34 | sub TILESIZE (){ 32 } |
37 | sub TILESIZE (){ 32 } |
|
|
38 | sub CACHESTRIDE (){ 64 } |
35 | |
39 | |
36 | our %ARCH; |
40 | our %ARCH; |
|
|
41 | our %FACE; # face32 |
37 | our %FACE; |
42 | our %FACEDATA; |
38 | our $TILE; |
43 | our $TILE; |
39 | |
44 | |
40 | our %FIELD_MULTILINE = ( |
45 | our %FIELD_MULTILINE = ( |
41 | msg => "endmsg", |
46 | msg => "endmsg", |
42 | lore => "endlore", |
47 | lore => "endlore", |
… | |
… | |
803 | |
808 | |
804 | my (%ignore); |
809 | my (%ignore); |
805 | my (@section_order, %section, @attr_order); |
810 | my (@section_order, %section, @attr_order); |
806 | |
811 | |
807 | while (my $type = shift @import) { |
812 | while (my $type = shift @import) { |
|
|
813 | push @import, |
|
|
814 | grep $_, |
|
|
815 | map $Crossfire::Data::TYPE{$_}, |
808 | push @import, @{$type->{import} || []}; |
816 | @{$type->{import} || []}; |
809 | |
817 | |
810 | $attr->{$_} ||= $type->{$_} |
818 | $attr->{$_} ||= $type->{$_} |
811 | for qw(name desc use); |
819 | for qw(name desc use); |
812 | |
820 | |
813 | for (@{$type->{ignore} || []}) { |
821 | for (@{$type->{ignore} || []}) { |
… | |
… | |
902 | } |
910 | } |
903 | |
911 | |
904 | sub construct_tilecache_pb { |
912 | sub construct_tilecache_pb { |
905 | my ($idx, $cache) = @_; |
913 | my ($idx, $cache) = @_; |
906 | |
914 | |
907 | my $pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, 64 * TILESIZE, TILESIZE * int +($idx + 63) / 64; |
915 | my $pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, CACHESTRIDE * TILESIZE, TILESIZE * int +($idx + CACHESTRIDE - 1) / CACHESTRIDE; |
908 | |
916 | |
909 | while (my ($name, $tile) = each %$cache) { |
917 | while (my ($name, $tile) = each %$cache) { |
910 | my $tpb = delete $tile->{pb}; |
918 | my $tpb = delete $tile->{pb}; |
911 | my $ofs = $tile->{idx}; |
919 | my $ofs = $tile->{idx}; |
912 | |
920 | |
913 | for my $x (0 .. $tile->{w} - 1) { |
921 | for my $x (0 .. $tile->{w} - 1) { |
914 | for my $y (0 .. $tile->{h} - 1) { |
922 | for my $y (0 .. $tile->{h} - 1) { |
915 | my $idx = $ofs + $x + $y * $tile->{w}; |
923 | my $idx = $ofs + $x + $y * $tile->{w}; |
916 | $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE, |
924 | $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE, |
917 | $pb, ($idx % 64) * TILESIZE, TILESIZE * int $idx / 64); |
925 | $pb, ($idx % CACHESTRIDE) * TILESIZE, TILESIZE * int $idx / CACHESTRIDE); |
918 | } |
926 | } |
919 | } |
927 | } |
920 | } |
928 | } |
921 | |
929 | |
922 | $pb->save ("$VARDIR/tilecache.png", "png", compression => 1); |
930 | $pb->save ("$VARDIR/tilecache.png", "png", compression => 1); |
… | |
… | |
938 | =cut |
946 | =cut |
939 | |
947 | |
940 | sub load_tilecache() { |
948 | sub load_tilecache() { |
941 | require Gtk2; |
949 | require Gtk2; |
942 | |
950 | |
943 | if (-e "$LIB/facedata") { # Crossfire TRT faces |
|
|
944 | cache_file "$LIB/facedata", "$VARDIR/tilecache.pst", \&use_tilecache, |
951 | cache_file "$LIB/facedata", "$VARDIR/tilecache.pst", \&use_tilecache, |
945 | sub { |
952 | sub { |
946 | my %cache; |
953 | my %cache; |
947 | my $facedata = Storable::retrieve "$LIB/facedata"; |
954 | my $facedata = Storable::retrieve "$LIB/facedata"; |
948 | |
955 | |
949 | $facedata->{version} == 2 |
956 | $facedata->{version} == 2 |
950 | or die "$LIB/facedata: version mismatch, cannot proceed."; |
957 | or die "$LIB/facedata: version mismatch, cannot proceed."; |
951 | |
958 | |
952 | my $faces = $facedata->{faceinfo}; |
959 | my $faces = $facedata->{faceinfo}; |
953 | my $idx = 0; |
960 | my $idx = 0; |
954 | |
961 | |
955 | for (sort keys %$faces) { |
962 | for (sort keys %$faces) { |
956 | my ($face, $info) = ($_, $faces->{$_}); |
963 | my ($face, $info) = ($_, $faces->{$_}); |
957 | |
964 | |
958 | my $pb = new Gtk2::Gdk::PixbufLoader; |
965 | my $pb = new Gtk2::Gdk::PixbufLoader; |
959 | $pb->write ($info->{data32}); |
966 | $pb->write ($info->{data32}); |
960 | $pb->close; |
967 | $pb->close; |
961 | my $pb = $pb->get_pixbuf; |
968 | my $pb = $pb->get_pixbuf; |
962 | |
969 | |
963 | my $tile = $cache{$face} = { |
970 | my $tile = $cache{$face} = { |
964 | pb => $pb, |
971 | pb => $pb, |
965 | idx => $idx, |
972 | idx => $idx, |
966 | w => int $pb->get_width / TILESIZE, |
973 | w => int $pb->get_width / TILESIZE, |
967 | h => int $pb->get_height / TILESIZE, |
974 | h => int $pb->get_height / TILESIZE, |
968 | }; |
975 | }; |
969 | |
976 | |
970 | $idx += $tile->{w} * $tile->{h}; |
977 | $idx += $tile->{w} * $tile->{h}; |
971 | } |
978 | } |
972 | |
979 | |
973 | construct_tilecache_pb $idx, \%cache; |
980 | construct_tilecache_pb $idx, \%cache; |
974 | |
981 | |
975 | \%cache |
982 | \%cache |
976 | }; |
983 | }; |
977 | |
|
|
978 | } elsif (-e "$LIB/crossfire.0") { # Crossfire1 version |
|
|
979 | cache_file "$LIB/crossfire.0", "$VARDIR/tilecache.pst", \&use_tilecache, |
|
|
980 | sub { |
|
|
981 | my $tile = read_pak "$LIB/crossfire.0"; |
|
|
982 | |
|
|
983 | my %cache; |
|
|
984 | |
|
|
985 | my $idx = 0; |
|
|
986 | |
|
|
987 | for my $name (sort keys %$tile) { |
|
|
988 | my $pb = new Gtk2::Gdk::PixbufLoader; |
|
|
989 | $pb->write ($tile->{$name}); |
|
|
990 | $pb->close; |
|
|
991 | my $pb = $pb->get_pixbuf; |
|
|
992 | |
|
|
993 | my $tile = $cache{$name} = { |
|
|
994 | pb => $pb, |
|
|
995 | idx => $idx, |
|
|
996 | w => int $pb->get_width / TILESIZE, |
|
|
997 | h => int $pb->get_height / TILESIZE, |
|
|
998 | }; |
|
|
999 | |
|
|
1000 | $idx += $tile->{w} * $tile->{h}; |
|
|
1001 | } |
|
|
1002 | |
|
|
1003 | construct_tilecache_pb $idx, \%cache; |
|
|
1004 | |
|
|
1005 | \%cache |
|
|
1006 | }; |
|
|
1007 | |
|
|
1008 | } |
|
|
1009 | } |
984 | } |
1010 | |
985 | |
1011 | =head1 AUTHOR |
986 | =head1 AUTHOR |
1012 | |
987 | |
1013 | Marc Lehmann <schmorp@schmorp.de> |
988 | Marc Lehmann <schmorp@schmorp.de> |
… | |
… | |
1017 | http://www.ta-sa.org/ |
992 | http://www.ta-sa.org/ |
1018 | |
993 | |
1019 | =cut |
994 | =cut |
1020 | |
995 | |
1021 | 1 |
996 | 1 |
|
|
997 | |