ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-world.ext
(Generate patch)

Comparing deliantra/server/ext/map-world.ext (file contents):
Revision 1.39 by root, Tue May 4 21:45:42 2010 UTC vs.
Revision 1.40 by root, Fri Apr 22 02:03:11 2011 UTC

9cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100); 9cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100);
10 10
11use Coro::Handle; 11use Coro::Handle;
12use Coro::AIO; 12use Coro::AIO;
13 13
14our $WORLD; 14my $TILE_W = 50;
15my $TILE_H = 50;
15 16
16sub load_indexed($$) { 17my $GRID_W = 30;
17 my ($path, $size) = @_; 18my $GRID_H = 30;
18 19
19 use bytes; 20our $ARCH;
20 21our $REGN;
21 0 < aio_load "$path.plt", my $plt
22 or cf::cleanup "$path.plt: $!";
23
24 my %plt;
25 my @plt;
26
27 for (split /\n/, $plt) {
28 my ($name, $rgb) = split /\s+/;
29 if (/^(\S+)\s+(\S+)$/) {
30 my ($name, $rgb) = ($1, $2);
31 $rgb = join "", map chr, map $_ * 17, map hex, split //, $rgb;
32 $plt{$rgb} = chr @plt;
33 push @plt, $name;
34 }
35 }
36
37 my $data = cf::fork_call {
38 open my $fh, "convert \Q$path.png\E -depth 8 rgb:- |"
39 or die "convert: $!";
40 binmode $fh;
41
42 $size * 3 == read $fh, my $data, $size * 3
43 or die "$path.png, expected $size rgb triplets: $!";
44
45 cf::_quantise $data, [map "$_$plt{$_}", keys %plt];
46
47 $data
48 };
49
50 $size == length $data
51 or cf::cleanup "$path.png, expected $size index octets ($!)";
52
53 ($data, \@plt)
54}
55
56sub load_gridmap($) {
57 my ($path) = @_;
58
59 my $map = cf::cache "ext::map-world/gridmap" =>
60 [
61 "$path/gridmap.meta",
62 "$path/gridmap.arch.plt",
63 "$path/gridmap.arch.png",
64 "$path/gridmap.regn.plt",
65 "$path/gridmap.regn.png",
66 ],
67 1 => sub {
68 my ($src) = @_;
69
70 my $map = cf::decode_json $src->[0];
71
72 my $size = $map->{tile_w} * $map->{tile_h} * $map->{grid_w} * $map->{grid_h}
73 or cf::cleanup "$path/gridmap.meta: empty gridmap?";
74
75 ($map->{arc_data}, $map->{arc_plt}) = load_indexed "$path/gridmap.arch", $size;
76 ($map->{reg_data}, $map->{reg_plt}) = load_indexed "$path/gridmap.regn", $size;
77
78 Coro::Storable::freeze $map
79 };
80
81 Coro::Storable::thaw $map
82}
83 22
84sub reload() { 23sub reload() {
85 $WORLD = load_gridmap "$MAPDIR/world"; 24 cf::trace "loading world+100+100 table.\n";
86 cf::trace "worldmap gridmap loaded.\n"; 25 $ARCH = cf::decode_storable cf::unlzf cf::load_file "$DATADIR/world+100+100.arch";
26 $REGN = cf::decode_storable cf::unlzf cf::load_file "$DATADIR/world+100+100.regn";
27 cf::trace "loaded world+100+100 table.\n";
87} 28}
88 29
89{ 30{
90 my $guard = cf::lock_acquire "ext::world_gridmap"; 31 my $guard = cf::lock_acquire "ext::world_gridmap";
91 32
109 50
110 my ($x, $y) = $self->wxwy; 51 my ($x, $y) = $self->wxwy;
111 52
112 my $guard = cf::lock_acquire "ext::world_gridmap"; 53 my $guard = cf::lock_acquire "ext::world_gridmap";
113 54
114 $self->width ($WORLD->{tile_w}); 55 $self->width ($TILE_W);
115 $self->height ($WORLD->{tile_h}); 56 $self->height ($TILE_H);
116 57
117 $self->name ("'The World' at +$x+$y"); 58 $self->name ("'The World' at +$x+$y");
118 $self->msg ("worldmap dynamically created by map-world extension"); 59 $self->msg ("worldmap dynamically created by map-world extension");
119 $self->outdoor (1); 60 $self->outdoor (1);
120 $self->default_region (cf::region::find "wilderness"); 61 $self->default_region (cf::region::find "wilderness");
135} 76}
136 77
137sub fill { 78sub fill {
138 my ($self) = @_; 79 my ($self) = @_;
139 80
140 $self->add_underlay ("\x00" x ($WORLD->{tile_w} * $WORLD->{tile_h}), 0, $WORLD->{tile_w}, $WORLD->{arc_plt});#d# 81 $self->add_underlay ("\x00" x ($TILE_W * $TILE_H), 0, $TILE_W, $ARCH->{plt});
141 $self->default_region (cf::region::find $WORLD->{reg_plt}[0]); 82 $self->default_region (cf::region::find $REGN->{plt}[0]);
142} 83}
143 84
144sub load { 85sub load {
145 my ($self) = @_; 86 my ($self) = @_;
146 87
161 my $guard = cf::lock_acquire "ext::world_gridmap"; 102 my $guard = cf::lock_acquire "ext::world_gridmap";
162 103
163 my ($x, $y) = $self->wxwy; 104 my ($x, $y) = $self->wxwy;
164 105
165 if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) { 106 if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) {
166 my $stride = $WORLD->{grid_w} * $WORLD->{tile_w}; 107 my $stride = $GRID_W * $TILE_W;
167 my $top = ($y - 100) * $WORLD->{tile_h} * $stride 108 my $top = ($y - 100) * $TILE_H * $stride
168 + ($x - 100) * $WORLD->{tile_w}; 109 + ($x - 100) * $TILE_W;
169 110
170 $self->add_underlay ($WORLD->{arc_data}, $top, $stride, $WORLD->{arc_plt}); 111 $self->add_underlay ($ARCH->{tbl}, $top, $stride, $ARCH->{plt});
171 $self->set_regiondata ($WORLD->{reg_data}, $top, $stride, $WORLD->{reg_plt}); 112 $self->set_regiondata ($REGN->{tbl}, $top, $stride, $REGN->{plt});
172 113
173 } else { 114 } else {
174 $self->fill; 115 $self->fill;
175 } 116 }
176 } 117 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines