ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/Deliantra/Tilecache.pm
Revision: 1.12
Committed: Mon Mar 20 01:12:23 2006 UTC (18 years, 2 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.11: +0 -0 lines
State: FILE REMOVED
Log Message:
*** empty log message ***

File Contents

# Content
1 =head1 NAME
2
3 Crossfire::Tilecache - Tile Cache using Gtk2::Gdk::Pixbuf
4
5 =cut
6
7 package Crossfire::Tilecache;
8
9 our $VERSION = '0.1';
10
11 use strict;
12
13 use Gtk2;
14 use File::Temp;
15
16 use Crossfire;
17
18 sub init_tilecache($) {
19 my ($cacheprefix) = @_;
20
21 eval {
22 -M "$cacheprefix.pst" < -M "$Crossfire::LIB/crossfire.0"
23 && ($Crossfire::TILE = new_from_file Gtk2::Gdk::Pixbuf "$cacheprefix.png")
24 && (*Crossfire::FACE = Crossfire::load_ref "$cacheprefix.pst")
25 } or do {
26 my $tile = read_pak "$Crossfire::LIB/crossfire.0";
27
28 my %cache;
29
30 my $idx = 0;
31
32 for my $name (sort keys %$tile) {
33 my ($fh, $filename) = File::Temp::tempfile;
34 print $fh $tile->{$name};
35 close $fh;
36 my $pb = new_from_file Gtk2::Gdk::Pixbuf $filename;
37 unlink $filename;
38
39 my $tile = $cache{$name} = {
40 pb => $pb,
41 idx => $idx,
42 w => int $pb->get_width / TILESIZE,
43 h => int $pb->get_height / TILESIZE,
44 };
45
46
47 $idx += $tile->{w} * $tile->{h};
48 }
49
50 my $pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, 64 * TILESIZE, TILESIZE * int +($idx + 63) / 64;
51
52 while (my ($name, $tile) = each %cache) {
53 my $tpb = delete $tile->{pb};
54 my $ofs = $tile->{idx};
55
56 for my $x (0 .. $tile->{w} - 1) {
57 for my $y (0 .. $tile->{h} - 1) {
58 my $idx = $ofs + $x + $y * $tile->{w};
59 $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE,
60 $pb, ($idx % 64) * TILESIZE, TILESIZE * int $idx / 64);
61 }
62 }
63 }
64
65 $pb->save ("$cacheprefix.png", "png");
66 Crossfire::save_ref \%cache, "$cacheprefix.pst";
67
68 $Crossfire::TILE = $pb;
69 *Crossfire::FACE = \%cache;
70 }
71 }
72
73 init_tilecache "$Crossfire::VARDIR/tilecache";
74
75 =head1 AUTHOR
76
77 Marc Lehmann <schmorp@schmorp.de>
78 http://home.schmorp.de/
79
80 Robin Redeker <elmex@ta-sa.org>
81 http://www.ta-sa.org/
82
83 =cut
84
85 1