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.10 by root, Sat Feb 10 01:52:27 2007 UTC vs.
Revision 1.23 by root, Wed Apr 18 17:32:06 2007 UTC

30 $plt{$rgb} = chr @plt; 30 $plt{$rgb} = chr @plt;
31 push @plt, $name; 31 push @plt, $name;
32 } 32 }
33 } 33 }
34 34
35 my $pid = open my $pipe, "-|"; 35 my $data = cf::fork_call {
36 open my $fh, "convert \Q$path.png\E -depth 8 rgb:- |"
37 or die "convert: $!";
38 binmode $fh;
36 39
37 defined $pid 40 $size * 3 == read $fh, my $data, $size * 3
38 or cf::cleanup "fork: $!"; 41 or die "$path.png, expected $size rgb triplets: $!";
39 42
40 unless ($pid) { 43 cf::_quantise $data, [map "$_$plt{$_}", keys %plt];
41 eval {
42 open my $fh, "convert \Q$path.png\E -depth 8 rgb:- |"
43 or die "convert: $!";
44 binmode $fh;
45 44
46 binmode $fh; 45 $data
47 $size * 3 == read $fh, my $data, $size * 3 46 };
48 or die "$path.png, expected $size rgb triplets: $!";
49 47
50 $data =~ s{(...)}{ 48 $size == length $data
51 $plt{$1} or die "$path.png: color not in palette: #" . unpack "H*", $1
52 }sge;
53
54 binmode STDOUT;
55 syswrite STDOUT, $data;
56 };
57 warn $@ if $@;
58 cf::_exit;
59 }
60
61 $pipe = Coro::Handle::unblock $pipe;
62 binmode $pipe;
63 $size == read $pipe, my $data, $size
64 or cf::cleanup "$path.png, expected $size index octets ($!)"; 49 or cf::cleanup "$path.png, expected $size index octets ($!)";
65 50
66 ($data, \@plt) 51 ($data, \@plt)
67} 52}
68 53
69sub load_gridmap($) { 54sub load_gridmap($) {
70 my ($path) = @_; 55 my ($path) = @_;
71 56
72 0 < aio_load "$path/gridmap.meta", my $map 57 my $map = cf::cache "ext::map-world/gridmap" =>
73 or cf::cleanup "$path/gridmap.meta: $!\n"; 58 [
59 "$path/gridmap.meta",
60 "$path/gridmap.arch.plt",
61 "$path/gridmap.arch.png",
62 "$path/gridmap.regn.plt",
63 "$path/gridmap.regn.png",
64 ],
65 1 => sub {
66 my ($src) = @_;
74 67
75 $map = cf::from_json $map; 68 my $map = cf::from_json $src->[0];
76 69
77 my $size = $map->{tile_w} * $map->{tile_h} * $map->{grid_w} * $map->{grid_h} 70 my $size = $map->{tile_w} * $map->{tile_h} * $map->{grid_w} * $map->{grid_h}
78 or cf::cleanup "$path/gridmap.meta: empty gridmap?"; 71 or cf::cleanup "$path/gridmap.meta: empty gridmap?";
79 72
80 ($map->{arc_data}, $map->{arc_plt}) = load_indexed "$path/gridmap.arch", $size; 73 ($map->{arc_data}, $map->{arc_plt}) = load_indexed "$path/gridmap.arch", $size;
81 ($map->{reg_data}, $map->{reg_plt}) = load_indexed "$path/gridmap.regn", $size; 74 ($map->{reg_data}, $map->{reg_plt}) = load_indexed "$path/gridmap.regn", $size;
82 75
83 $map 76 Coro::Storable::freeze $map
77 };
78
79 Coro::Storable::thaw $map
80}
81
82sub reload() {
83 $WORLD = load_gridmap "$MAPDIR/world";
84 warn "worldmap gridmap loaded.";
84} 85}
85 86
86# this is contorted, but likely the correct way to acquire the lock :) 87# this is contorted, but likely the correct way to acquire the lock :)
87cf::sync_job { 88cf::sync_job {
88 my $guard = cf::lock_acquire "ext::world_gridmap"; 89 my $guard = cf::lock_acquire "ext::world_gridmap";
89 cf::async_ext { 90 cf::async_ext {
90 $WORLD = load_gridmap sprintf "%s/%s/%s", cf::datadir, cf::mapdir, "world"; 91 reload;
91 warn "worldmap gridmap loaded.";
92 undef $guard; 92 undef $guard;
93 } 93 };
94}; 94};
95 95
96cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100); 96cf::map->register (qr{^/world/world_(\d\d\d)_(\d\d\d)$}, 100);
97 97
98sub wxwy { 98sub wxwy {
112 $self->height ($WORLD->{tile_h}); 112 $self->height ($WORLD->{tile_h});
113 113
114 $self->name ("'The World' at +$x+$y"); 114 $self->name ("'The World' at +$x+$y");
115 $self->msg ("worldmap dynamically created by map-world extension"); 115 $self->msg ("worldmap dynamically created by map-world extension");
116 $self->outdoor (1); 116 $self->outdoor (1);
117 $self->default_region (undef); 117 $self->default_region (cf::region::find "wilderness");
118 118
119# $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0; 119 $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0;
120# $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999; 120 $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999;
121# $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999; 121 $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999;
122# $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0; 122 $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0;
123 $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 100;
124 $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 129;
125 $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 129;
126 $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 100;
127 123
128 $self->{load_path} = sprintf "%s/%s/world-overlay/world_%03d_%03d", cf::datadir, cf::mapdir, $x, $y 124 $self->{load_path} = sprintf "%s/world-overlay/world_%03d_%03d.map", $cf::MAPDIR, $x, $y
129 if $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; 125 if $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129;
130 126
131 1 127 1
128}
129
130sub fill {
131 my ($self) = @_;
132
133 $self->add_underlay ("\x00" x ($WORLD->{tile_w} * $WORLD->{tile_h}), 0, $WORLD->{tile_w}, $WORLD->{arc_plt});
134 $self->default_region (cf::region::find $WORLD->{reg_plt}[0]);
132} 135}
133 136
134sub load { 137sub load {
135 my ($self) = @_; 138 my ($self) = @_;
136 139
137 if ($self->{load_path}) { 140 if ($self->{load_path}) {
138 $self->SUPER::load; 141 $self->SUPER::load;
139 } else { 142 } else {
140 $self->alloc; 143 $self->alloc;
141 144 $self->fill;
142 for my $X (0 .. $WORLD->{tile_w} - 1) {
143 Coro::cede;
144 for my $Y (0 .. $WORLD->{tile_h} - 1) {
145 my $ob = cf::object::new "deep_sea";
146 $self->insert ($ob, $X, $Y);
147 }
148 }
149 $self->set_object_flag (cf::FLAG_NO_MAP_SAVE, 1);
150 $self->default_region (cf::region::find "ocean");
151
152 $self->in_memory (cf::MAP_IN_MEMORY); 145 $self->in_memory (cf::MAP_IN_MEMORY);
153 } 146 }
154} 147}
155 148
156sub post_load { 149sub post_load {
158 151
159 my $guard = cf::lock_acquire "ext::world_gridmap"; 152 my $guard = cf::lock_acquire "ext::world_gridmap";
160 153
161 my ($x, $y) = $self->wxwy; 154 my ($x, $y) = $self->wxwy;
162 155
163 return
164 unless $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; 156 if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) {
157 my $stride = $WORLD->{grid_w} * $WORLD->{tile_w};
158 my $top = ($y - 100) * $WORLD->{tile_h} * $stride
159 + ($x - 100) * $WORLD->{tile_w};
165 160
166 my $stride = $WORLD->{grid_w} * $WORLD->{tile_w}; 161 $self->add_underlay ($WORLD->{arc_data}, $top, $stride, $WORLD->{arc_plt});
167 my $top = ($y - 100) * $WORLD->{tile_h} * $stride 162 $self->set_regiondata ($WORLD->{reg_data}, $top, $stride, $WORLD->{reg_plt});
168 + ($x - 100) * $WORLD->{tile_w};
169 163
170 my $reg; 164 } else {
171 165 $self->fill;
172 for my $Y (0 .. $WORLD->{tile_h} - 1) {
173 Coro::cede;
174 my $row = substr $WORLD->{arc_data}, $top + $Y * $stride, $WORLD->{tile_w};
175 $reg .= substr $WORLD->{reg_data}, $top + $Y * $stride, $WORLD->{tile_w};
176 for my $X (0 .. $WORLD->{tile_w} - 1) {
177 next if grep $_->flag (cf::FLAG_IS_FLOOR), $self->at ($X, $Y);
178 my $ob = cf::object::new $WORLD->{arc_plt}[ord substr $row, $X];
179 $ob->flag (cf::FLAG_NO_MAP_SAVE, 1);
180 $self->insert ($ob, $X, $Y, undef, cf::INS_ABOVE_FLOOR_ONLY);
181 }
182 } 166 }
183
184 $self->set_regiondata ($reg, $WORLD->{reg_plt});
185} 167}
186 168
1871 1691
188 170

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines