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.109 by elmex, Sun May 27 08:08:59 2007 UTC vs.
Revision 1.113 by root, Tue Jul 3 00:16:49 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",
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
904sub construct_tilecache_pb { 912sub 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
940sub load_tilecache() { 948sub load_tilecache() {
941 require Gtk2; 949 require Gtk2;
942 950
951 if (-e "$LIB/facedata") { # Crossfire TRT faces
952 cache_file "$LIB/facedata", "$VARDIR/tilecache.pst", \&use_tilecache,
953 sub {
954 my %cache;
955 my $facedata = Storable::retrieve "$LIB/facedata";
956
957 $facedata->{version} == 2
958 or die "$LIB/facedata: version mismatch, cannot proceed.";
959
960 my $faces = $facedata->{faceinfo};
961 my $idx = 0;
962
963 for (sort keys %$faces) {
964 my ($face, $info) = ($_, $faces->{$_});
965
966 my $pb = new Gtk2::Gdk::PixbufLoader;
967 $pb->write ($info->{data32});
968 $pb->close;
969 my $pb = $pb->get_pixbuf;
970
971 my $tile = $cache{$face} = {
972 pb => $pb,
973 idx => $idx,
974 w => int $pb->get_width / TILESIZE,
975 h => int $pb->get_height / TILESIZE,
976 };
977
978 $idx += $tile->{w} * $tile->{h};
979 }
980
981 construct_tilecache_pb $idx, \%cache;
982
983 \%cache
984 };
985
986 *FACEDATA = Storable::retrieve "$LIB/facedata";
987
943 if (-e "$LIB/crossfire.0") { # Crossfire1 version 988 } elsif (-e "$LIB/crossfire.0") { # Crossfire1 version
944 cache_file "$LIB/crossfire.0", "$VARDIR/tilecache.pst", \&use_tilecache, 989 cache_file "$LIB/crossfire.0", "$VARDIR/tilecache.pst", \&use_tilecache,
945 sub { 990 sub {
946 my $tile = read_pak "$LIB/crossfire.0"; 991 my $tile = read_pak "$LIB/crossfire.0";
947 992
948 my %cache; 993 my %cache;
968 construct_tilecache_pb $idx, \%cache; 1013 construct_tilecache_pb $idx, \%cache;
969 1014
970 \%cache 1015 \%cache
971 }; 1016 };
972 1017
973 } else { # Crossfire+ version 1018 *FACEDATA = { };
974 cache_file "$LIB/facedata", "$VARDIR/tilecache.pst", \&use_tilecache,
975 sub {
976 my %cache;
977 my $facedata = Storable::retrieve "$LIB/facedata";
978
979 $facedata->{version} == 2
980 or die "$LIB/facedata: version mismatch, cannot proceed.";
981
982 my $faces = $facedata->{faceinfo};
983 my $idx = 0;
984
985 for (sort keys %$faces) {
986 my ($face, $info) = ($_, $faces->{$_});
987
988 my $pb = new Gtk2::Gdk::PixbufLoader;
989 $pb->write ($info->{data32});
990 $pb->close;
991 my $pb = $pb->get_pixbuf;
992
993 my $tile = $cache{$face} = {
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 } 1019 }
1008} 1020}
1009 1021
1010=head1 AUTHOR 1022=head1 AUTHOR
1011 1023
1016 http://www.ta-sa.org/ 1028 http://www.ta-sa.org/
1017 1029
1018=cut 1030=cut
1019 1031
10201 10321
1033

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines