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.107 by root, Wed May 9 11:44:40 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",
347 } else { 352 } else {
348 warn "object $ob->{_name} has unknown material ($ob->{material}) set.\n"; 353 warn "object $ob->{_name} has unknown material ($ob->{material}) set.\n";
349 } 354 }
350 } 355 }
351 356
357 # check whether attachment is the same as in the archetype
358 if (exists $ob->{attach}) {
359 my $arch = $ARCH{$ob->{_name}};
360 my $js = JSON::XS->new->utf8->canonical (1);
361
362 if (defined $arch->{attach}
363 && $js->encode ($js->decode ($ob->{attach})) eq $js->encode ($arch->{attach})) {
364 delete $ob->{attach}
365 }
366 }
367
352 # 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
353 $ob->{magicmap} ||= delete $ob->{color_fg} if exists $ob->{color_fg}; 369 $ob->{magicmap} ||= delete $ob->{color_fg} if exists $ob->{color_fg};
354 370
355 # nuke outdated or never supported fields 371 # nuke outdated or never supported fields
356 delete @$ob{qw( 372 delete @$ob{qw(
891} 907}
892 908
893sub construct_tilecache_pb { 909sub construct_tilecache_pb {
894 my ($idx, $cache) = @_; 910 my ($idx, $cache) = @_;
895 911
896 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;
897 913
898 while (my ($name, $tile) = each %$cache) { 914 while (my ($name, $tile) = each %$cache) {
899 my $tpb = delete $tile->{pb}; 915 my $tpb = delete $tile->{pb};
900 my $ofs = $tile->{idx}; 916 my $ofs = $tile->{idx};
901 917
902 for my $x (0 .. $tile->{w} - 1) { 918 for my $x (0 .. $tile->{w} - 1) {
903 for my $y (0 .. $tile->{h} - 1) { 919 for my $y (0 .. $tile->{h} - 1) {
904 my $idx = $ofs + $x + $y * $tile->{w}; 920 my $idx = $ofs + $x + $y * $tile->{w};
905 $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE, 921 $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE,
906 $pb, ($idx % 64) * TILESIZE, TILESIZE * int $idx / 64); 922 $pb, ($idx % CACHESTRIDE) * TILESIZE, TILESIZE * int $idx / CACHESTRIDE);
907 } 923 }
908 } 924 }
909 } 925 }
910 926
911 $pb->save ("$VARDIR/tilecache.png", "png", compression => 1); 927 $pb->save ("$VARDIR/tilecache.png", "png", compression => 1);
927=cut 943=cut
928 944
929sub load_tilecache() { 945sub load_tilecache() {
930 require Gtk2; 946 require Gtk2;
931 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
932 if (-e "$LIB/crossfire.0") { # Crossfire1 version 985 } elsif (-e "$LIB/crossfire.0") { # Crossfire1 version
933 cache_file "$LIB/crossfire.0", "$VARDIR/tilecache.pst", \&use_tilecache, 986 cache_file "$LIB/crossfire.0", "$VARDIR/tilecache.pst", \&use_tilecache,
934 sub { 987 sub {
935 my $tile = read_pak "$LIB/crossfire.0"; 988 my $tile = read_pak "$LIB/crossfire.0";
936 989
937 my %cache; 990 my %cache;
957 construct_tilecache_pb $idx, \%cache; 1010 construct_tilecache_pb $idx, \%cache;
958 1011
959 \%cache 1012 \%cache
960 }; 1013 };
961 1014
962 } else { # Crossfire+ version 1015 *FACEDATA = { };
963 cache_file "$LIB/facedata", "$VARDIR/tilecache.pst", \&use_tilecache,
964 sub {
965 my %cache;
966 my $facedata = Storable::retrieve "$LIB/facedata";
967
968 $facedata->{version} == 2
969 or die "$LIB/facedata: version mismatch, cannot proceed.";
970
971 my $faces = $facedata->{faceinfo};
972 my $idx = 0;
973
974 for (sort keys %$faces) {
975 my ($face, $info) = ($_, $faces->{$_});
976
977 my $pb = new Gtk2::Gdk::PixbufLoader;
978 $pb->write ($info->{data32});
979 $pb->close;
980 my $pb = $pb->get_pixbuf;
981
982 my $tile = $cache{$face} = {
983 pb => $pb,
984 idx => $idx,
985 w => int $pb->get_width / TILESIZE,
986 h => int $pb->get_height / TILESIZE,
987 };
988
989 $idx += $tile->{w} * $tile->{h};
990 }
991
992 construct_tilecache_pb $idx, \%cache;
993
994 \%cache
995 };
996 } 1016 }
997} 1017}
998 1018
999=head1 AUTHOR 1019=head1 AUTHOR
1000 1020
1005 http://www.ta-sa.org/ 1025 http://www.ta-sa.org/
1006 1026
1007=cut 1027=cut
1008 1028
10091 10291
1030

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines