… | |
… | |
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.0'; |
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", |
… | |
… | |
902 | } |
907 | } |
903 | |
908 | |
904 | sub construct_tilecache_pb { |
909 | sub construct_tilecache_pb { |
905 | my ($idx, $cache) = @_; |
910 | my ($idx, $cache) = @_; |
906 | |
911 | |
907 | my $pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, 64 * TILESIZE, TILESIZE * int +($idx + 63) / 64; |
912 | my $pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, CACHESTRIDE * TILESIZE, TILESIZE * int +($idx + CACHESTRIDE - 1) / CACHESTRIDE; |
908 | |
913 | |
909 | while (my ($name, $tile) = each %$cache) { |
914 | while (my ($name, $tile) = each %$cache) { |
910 | my $tpb = delete $tile->{pb}; |
915 | my $tpb = delete $tile->{pb}; |
911 | my $ofs = $tile->{idx}; |
916 | my $ofs = $tile->{idx}; |
912 | |
917 | |
913 | for my $x (0 .. $tile->{w} - 1) { |
918 | for my $x (0 .. $tile->{w} - 1) { |
914 | for my $y (0 .. $tile->{h} - 1) { |
919 | for my $y (0 .. $tile->{h} - 1) { |
915 | my $idx = $ofs + $x + $y * $tile->{w}; |
920 | my $idx = $ofs + $x + $y * $tile->{w}; |
916 | $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE, |
921 | $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE, |
917 | $pb, ($idx % 64) * TILESIZE, TILESIZE * int $idx / 64); |
922 | $pb, ($idx % CACHESTRIDE) * TILESIZE, TILESIZE * int $idx / CACHESTRIDE); |
918 | } |
923 | } |
919 | } |
924 | } |
920 | } |
925 | } |
921 | |
926 | |
922 | $pb->save ("$VARDIR/tilecache.png", "png", compression => 1); |
927 | $pb->save ("$VARDIR/tilecache.png", "png", compression => 1); |
… | |
… | |
973 | construct_tilecache_pb $idx, \%cache; |
978 | construct_tilecache_pb $idx, \%cache; |
974 | |
979 | |
975 | \%cache |
980 | \%cache |
976 | }; |
981 | }; |
977 | |
982 | |
|
|
983 | *FACEDATA = Storable::retrieve "$LIB/facedata"; |
|
|
984 | |
978 | } elsif (-e "$LIB/crossfire.0") { # Crossfire1 version |
985 | } elsif (-e "$LIB/crossfire.0") { # Crossfire1 version |
979 | cache_file "$LIB/crossfire.0", "$VARDIR/tilecache.pst", \&use_tilecache, |
986 | cache_file "$LIB/crossfire.0", "$VARDIR/tilecache.pst", \&use_tilecache, |
980 | sub { |
987 | sub { |
981 | my $tile = read_pak "$LIB/crossfire.0"; |
988 | my $tile = read_pak "$LIB/crossfire.0"; |
982 | |
989 | |
… | |
… | |
1003 | construct_tilecache_pb $idx, \%cache; |
1010 | construct_tilecache_pb $idx, \%cache; |
1004 | |
1011 | |
1005 | \%cache |
1012 | \%cache |
1006 | }; |
1013 | }; |
1007 | |
1014 | |
|
|
1015 | *FACEDATA = { }; |
1008 | } |
1016 | } |
1009 | } |
1017 | } |
1010 | |
1018 | |
1011 | =head1 AUTHOR |
1019 | =head1 AUTHOR |
1012 | |
1020 | |
… | |
… | |
1017 | http://www.ta-sa.org/ |
1025 | http://www.ta-sa.org/ |
1018 | |
1026 | |
1019 | =cut |
1027 | =cut |
1020 | |
1028 | |
1021 | 1 |
1029 | 1 |
|
|
1030 | |