ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/Deliantra.pm
(Generate patch)

Comparing deliantra/Deliantra/Deliantra.pm (file contents):
Revision 1.108 by elmex, Wed May 23 20:21:28 2007 UTC vs.
Revision 1.112 by root, Thu Jun 21 00:07:54 2007 UTC

4 4
5=cut 5=cut
6 6
7package Crossfire; 7package Crossfire;
8 8
9our $VERSION = '0.98'; 9our $VERSION = '1.0';
10 10
11use strict; 11use strict;
12 12
13use base 'Exporter'; 13use base 'Exporter';
14 14
16use File::Spec; 16use File::Spec;
17use List::Util qw(min max); 17use List::Util qw(min max);
18use Storable qw(freeze thaw); 18use Storable qw(freeze thaw);
19 19
20our @EXPORT = qw( 20our @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
24use JSON::XS qw(from_json to_json); 27use JSON::XS qw(from_json to_json);
25 28
26our $LIB = $ENV{CROSSFIRE_LIBDIR}; 29our $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
32mkdir $VARDIR, 0777; 35mkdir $VARDIR, 0777;
33 36
34sub TILESIZE (){ 32 } 37sub TILESIZE (){ 32 }
38sub CACHESTRIDE (){ 64 }
35 39
36our %ARCH; 40our %ARCH;
41our %FACE; # face32
37our %FACE; 42our %FACEDATA;
38our $TILE; 43our $TILE;
39 44
40our %FIELD_MULTILINE = ( 45our %FIELD_MULTILINE = (
41 msg => "endmsg", 46 msg => "endmsg",
42 lore => "endlore", 47 lore => "endlore",
352 # check whether attachment is the same as in the archetype 357 # check whether attachment is the same as in the archetype
353 if (exists $ob->{attach}) { 358 if (exists $ob->{attach}) {
354 my $arch = $ARCH{$ob->{_name}}; 359 my $arch = $ARCH{$ob->{_name}};
355 my $js = JSON::XS->new->utf8->canonical (1); 360 my $js = JSON::XS->new->utf8->canonical (1);
356 361
362 if (defined $arch->{attach}
357 if ($js->encode ($js->decode ($ob->{attach})) eq $js->encode ($arch->{attach})) { 363 && $js->encode ($js->decode ($ob->{attach})) eq $js->encode ($arch->{attach})) {
358 delete $ob->{attach} 364 delete $ob->{attach}
359 } 365 }
360 } 366 }
361 367
362 # color_fg is used as default for magicmap if magicmap does not exist 368 # color_fg is used as default for magicmap if magicmap does not exist
901} 907}
902 908
903sub construct_tilecache_pb { 909sub construct_tilecache_pb {
904 my ($idx, $cache) = @_; 910 my ($idx, $cache) = @_;
905 911
906 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;
907 913
908 while (my ($name, $tile) = each %$cache) { 914 while (my ($name, $tile) = each %$cache) {
909 my $tpb = delete $tile->{pb}; 915 my $tpb = delete $tile->{pb};
910 my $ofs = $tile->{idx}; 916 my $ofs = $tile->{idx};
911 917
912 for my $x (0 .. $tile->{w} - 1) { 918 for my $x (0 .. $tile->{w} - 1) {
913 for my $y (0 .. $tile->{h} - 1) { 919 for my $y (0 .. $tile->{h} - 1) {
914 my $idx = $ofs + $x + $y * $tile->{w}; 920 my $idx = $ofs + $x + $y * $tile->{w};
915 $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE, 921 $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE,
916 $pb, ($idx % 64) * TILESIZE, TILESIZE * int $idx / 64); 922 $pb, ($idx % CACHESTRIDE) * TILESIZE, TILESIZE * int $idx / CACHESTRIDE);
917 } 923 }
918 } 924 }
919 } 925 }
920 926
921 $pb->save ("$VARDIR/tilecache.png", "png", compression => 1); 927 $pb->save ("$VARDIR/tilecache.png", "png", compression => 1);
937=cut 943=cut
938 944
939sub load_tilecache() { 945sub load_tilecache() {
940 require Gtk2; 946 require Gtk2;
941 947
948 if (-e "$LIB/facedata") { # Crossfire TRT faces
949 cache_file "$LIB/facedata", "$VARDIR/tilecache.pst", \&use_tilecache,
950 sub {
951 my %cache;
952 my $facedata = Storable::retrieve "$LIB/facedata";
953
954 $facedata->{version} == 2
955 or die "$LIB/facedata: version mismatch, cannot proceed.";
956
957 my $faces = $facedata->{faceinfo};
958 my $idx = 0;
959
960 for (sort keys %$faces) {
961 my ($face, $info) = ($_, $faces->{$_});
962
963 my $pb = new Gtk2::Gdk::PixbufLoader;
964 $pb->write ($info->{data32});
965 $pb->close;
966 my $pb = $pb->get_pixbuf;
967
968 my $tile = $cache{$face} = {
969 pb => $pb,
970 idx => $idx,
971 w => int $pb->get_width / TILESIZE,
972 h => int $pb->get_height / TILESIZE,
973 };
974
975 $idx += $tile->{w} * $tile->{h};
976 }
977
978 construct_tilecache_pb $idx, \%cache;
979
980 \%cache
981 };
982
983 *FACEDATA = Storable::retrieve "$LIB/facedata";
984
942 if (-e "$LIB/crossfire.0") { # Crossfire1 version 985 } elsif (-e "$LIB/crossfire.0") { # Crossfire1 version
943 cache_file "$LIB/crossfire.0", "$VARDIR/tilecache.pst", \&use_tilecache, 986 cache_file "$LIB/crossfire.0", "$VARDIR/tilecache.pst", \&use_tilecache,
944 sub { 987 sub {
945 my $tile = read_pak "$LIB/crossfire.0"; 988 my $tile = read_pak "$LIB/crossfire.0";
946 989
947 my %cache; 990 my %cache;
967 construct_tilecache_pb $idx, \%cache; 1010 construct_tilecache_pb $idx, \%cache;
968 1011
969 \%cache 1012 \%cache
970 }; 1013 };
971 1014
972 } else { # Crossfire+ version 1015 *FACEDATA = { };
973 cache_file "$LIB/facedata", "$VARDIR/tilecache.pst", \&use_tilecache,
974 sub {
975 my %cache;
976 my $facedata = Storable::retrieve "$LIB/facedata";
977
978 $facedata->{version} == 2
979 or die "$LIB/facedata: version mismatch, cannot proceed.";
980
981 my $faces = $facedata->{faceinfo};
982 my $idx = 0;
983
984 for (sort keys %$faces) {
985 my ($face, $info) = ($_, $faces->{$_});
986
987 my $pb = new Gtk2::Gdk::PixbufLoader;
988 $pb->write ($info->{data32});
989 $pb->close;
990 my $pb = $pb->get_pixbuf;
991
992 my $tile = $cache{$face} = {
993 pb => $pb,
994 idx => $idx,
995 w => int $pb->get_width / TILESIZE,
996 h => int $pb->get_height / TILESIZE,
997 };
998
999 $idx += $tile->{w} * $tile->{h};
1000 }
1001
1002 construct_tilecache_pb $idx, \%cache;
1003
1004 \%cache
1005 };
1006 } 1016 }
1007} 1017}
1008 1018
1009=head1 AUTHOR 1019=head1 AUTHOR
1010 1020
1015 http://www.ta-sa.org/ 1025 http://www.ta-sa.org/
1016 1026
1017=cut 1027=cut
1018 1028
10191 10291
1030

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines