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.117 by root, Wed Dec 5 11:03:08 2007 UTC

4 4
5=cut 5=cut
6 6
7package Crossfire; 7package Crossfire;
8 8
9our $VERSION = '0.98'; 9our $VERSION = '1.12';
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
802 808
803 my (%ignore); 809 my (%ignore);
804 my (@section_order, %section, @attr_order); 810 my (@section_order, %section, @attr_order);
805 811
806 while (my $type = shift @import) { 812 while (my $type = shift @import) {
813 push @import,
814 grep $_,
815 map $Crossfire::Data::TYPE{$_},
807 push @import, @{$type->{import} || []}; 816 @{$type->{import} || []};
808 817
809 $attr->{$_} ||= $type->{$_} 818 $attr->{$_} ||= $type->{$_}
810 for qw(name desc use); 819 for qw(name desc use);
811 820
812 for (@{$type->{ignore} || []}) { 821 for (@{$type->{ignore} || []}) {
901} 910}
902 911
903sub construct_tilecache_pb { 912sub construct_tilecache_pb {
904 my ($idx, $cache) = @_; 913 my ($idx, $cache) = @_;
905 914
906 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;
907 916
908 while (my ($name, $tile) = each %$cache) { 917 while (my ($name, $tile) = each %$cache) {
909 my $tpb = delete $tile->{pb}; 918 my $tpb = delete $tile->{pb};
910 my $ofs = $tile->{idx}; 919 my $ofs = $tile->{idx};
911 920
912 for my $x (0 .. $tile->{w} - 1) { 921 for my $x (0 .. $tile->{w} - 1) {
913 for my $y (0 .. $tile->{h} - 1) { 922 for my $y (0 .. $tile->{h} - 1) {
914 my $idx = $ofs + $x + $y * $tile->{w}; 923 my $idx = $ofs + $x + $y * $tile->{w};
915 $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE, 924 $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE,
916 $pb, ($idx % 64) * TILESIZE, TILESIZE * int $idx / 64); 925 $pb, ($idx % CACHESTRIDE) * TILESIZE, TILESIZE * int $idx / CACHESTRIDE);
917 } 926 }
918 } 927 }
919 } 928 }
920 929
921 $pb->save ("$VARDIR/tilecache.png", "png", compression => 1); 930 $pb->save ("$VARDIR/tilecache.png", "png", compression => 1);
937=cut 946=cut
938 947
939sub load_tilecache() { 948sub load_tilecache() {
940 require Gtk2; 949 require Gtk2;
941 950
942 if (-e "$LIB/crossfire.0") { # Crossfire1 version
943 cache_file "$LIB/crossfire.0", "$VARDIR/tilecache.pst", \&use_tilecache,
944 sub {
945 my $tile = read_pak "$LIB/crossfire.0";
946
947 my %cache;
948
949 my $idx = 0;
950
951 for my $name (sort keys %$tile) {
952 my $pb = new Gtk2::Gdk::PixbufLoader;
953 $pb->write ($tile->{$name});
954 $pb->close;
955 my $pb = $pb->get_pixbuf;
956
957 my $tile = $cache{$name} = {
958 pb => $pb,
959 idx => $idx,
960 w => int $pb->get_width / TILESIZE,
961 h => int $pb->get_height / TILESIZE,
962 };
963
964 $idx += $tile->{w} * $tile->{h};
965 }
966
967 construct_tilecache_pb $idx, \%cache;
968
969 \%cache
970 };
971
972 } else { # Crossfire+ version
973 cache_file "$LIB/facedata", "$VARDIR/tilecache.pst", \&use_tilecache, 951 cache_file "$LIB/facedata", "$VARDIR/tilecache.pst", \&use_tilecache,
974 sub { 952 sub {
975 my %cache; 953 my %cache;
976 my $facedata = Storable::retrieve "$LIB/facedata"; 954 my $facedata = Storable::retrieve "$LIB/facedata";
977 955
978 $facedata->{version} == 2 956 $facedata->{version} == 2
979 or die "$LIB/facedata: version mismatch, cannot proceed."; 957 or die "$LIB/facedata: version mismatch, cannot proceed.";
980 958
981 my $faces = $facedata->{faceinfo}; 959 my $faces = $facedata->{faceinfo};
982 my $idx = 0; 960 my $idx = 0;
983 961
984 for (sort keys %$faces) { 962 for (sort keys %$faces) {
985 my ($face, $info) = ($_, $faces->{$_}); 963 my ($face, $info) = ($_, $faces->{$_});
986 964
987 my $pb = new Gtk2::Gdk::PixbufLoader; 965 my $pb = new Gtk2::Gdk::PixbufLoader;
988 $pb->write ($info->{data32}); 966 $pb->write ($info->{data32});
989 $pb->close; 967 $pb->close;
990 my $pb = $pb->get_pixbuf; 968 my $pb = $pb->get_pixbuf;
991 969
992 my $tile = $cache{$face} = { 970 my $tile = $cache{$face} = {
993 pb => $pb, 971 pb => $pb,
994 idx => $idx, 972 idx => $idx,
995 w => int $pb->get_width / TILESIZE, 973 w => int $pb->get_width / TILESIZE,
996 h => int $pb->get_height / TILESIZE, 974 h => int $pb->get_height / TILESIZE,
997 }; 975 };
998 976
999 $idx += $tile->{w} * $tile->{h}; 977 $idx += $tile->{w} * $tile->{h};
1000 } 978 }
1001 979
1002 construct_tilecache_pb $idx, \%cache; 980 construct_tilecache_pb $idx, \%cache;
1003 981
1004 \%cache 982 \%cache
1005 }; 983 };
1006 }
1007} 984}
1008 985
1009=head1 AUTHOR 986=head1 AUTHOR
1010 987
1011 Marc Lehmann <schmorp@schmorp.de> 988 Marc Lehmann <schmorp@schmorp.de>
1015 http://www.ta-sa.org/ 992 http://www.ta-sa.org/
1016 993
1017=cut 994=cut
1018 995
10191 9961
997

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines