=head1 NAME Crossfire::Tilecache - Tile Cache using Gtk2::Gdk::Pixbuf =cut package Crossfire::Tilecache; our $VERSION = '0.1'; use strict; use Gtk2; use File::Temp; use Crossfire; sub init_tilecache($) { my ($cacheprefix) = @_; eval { -M "$cacheprefix.pst" < -M "$Crossfire::LIB/crossfire.0" && ($Crossfire::TILE = new_from_file Gtk2::Gdk::Pixbuf "$cacheprefix.png") && (*Crossfire::FACE = Crossfire::load_ref "$cacheprefix.pst") } or do { my $tile = read_pak "$Crossfire::LIB/crossfire.0"; my %cache; my $idx = 0; for my $name (sort keys %$tile) { my ($fh, $filename) = File::Temp::tempfile; print $fh $tile->{$name}; close $fh; my $tile = $cache{$name} = {}; my $pb = $tile->{$name} = new_from_file Gtk2::Gdk::Pixbuf $filename; unlink $filename; $tile->{pb} = $pb; $tile->{idx} = $idx; $tile->{w} = int $pb->get_width / TILESIZE; $tile->{h} = int $pb->get_height / TILESIZE; $idx += $tile->{w} * $tile->{h}; } my $pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, 64 * TILESIZE, TILESIZE * int +($idx + 63) / 64; while (my ($name, $tile) = each %cache) { my $tpb = delete $tile->{pb}; my $ofs = $tile->{idx}; for my $x (0 .. $tile->{w} - 1) { for my $y (0 .. $tile->{h} - 1) { my $idx = $ofs + $x + $y * $tile->{w}; $tpb->copy_area ($x * TILESIZE, $y * TILESIZE, TILESIZE, TILESIZE, $pb, ($idx % 64) * TILESIZE, TILESIZE * int $idx / 64); } } } $pb->save ("$cacheprefix.png", "png"); Crossfire::save_ref \%cache, "$cacheprefix.pst"; $Crossfire::TILE = $pb; *Crossfire::FACE = \%cache; } } init_tilecache "$Crossfire::CACHEDIR/tilecache"; =head1 AUTHOR Marc Lehmann http://home.schmorp.de/ Robin Redeker http://www.ta-sa.org/ =cut 1