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.9 by root, Sat Feb 3 21:41:06 2007 UTC vs.
Revision 1.21 by root, Tue Apr 17 20:41:15 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines