… | |
… | |
67 | } |
67 | } |
68 | |
68 | |
69 | sub load_gridmap($) { |
69 | sub load_gridmap($) { |
70 | my ($path) = @_; |
70 | my ($path) = @_; |
71 | |
71 | |
72 | if (! -e "/tmp/xxxx.gridmap") { |
72 | if (1 || ! -e "/tmp/xxxx.gridmap") { |
73 | 0 < aio_load "$path/gridmap.meta", my $map |
73 | 0 < aio_load "$path/gridmap.meta", my $map |
74 | or cf::cleanup "$path/gridmap.meta: $!\n"; |
74 | or cf::cleanup "$path/gridmap.meta: $!\n"; |
75 | |
75 | |
76 | $map = cf::from_json $map; |
76 | $map = cf::from_json $map; |
77 | |
77 | |
… | |
… | |
125 | $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0; |
125 | $self->tile_path (0, sprintf "/world/world_%03d_%03d", $x, $y - 1) if $y > 0; |
126 | $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999; |
126 | $self->tile_path (1, sprintf "/world/world_%03d_%03d", $x + 1, $y) if $x < 999; |
127 | $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999; |
127 | $self->tile_path (2, sprintf "/world/world_%03d_%03d", $x, $y + 1) if $y < 999; |
128 | $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0; |
128 | $self->tile_path (3, sprintf "/world/world_%03d_%03d", $x - 1, $y) if $x > 0; |
129 | |
129 | |
130 | $self->{load_path} = sprintf "%s/%s/world-overlay/world_%03d_%03d", cf::datadir, cf::mapdir, $x, $y |
130 | $self->{load_path} = sprintf "%s/%s/world-overlay/world_%03d_%03d.map", cf::datadir, cf::mapdir, $x, $y |
131 | if $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; |
131 | if $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; |
132 | |
132 | |
133 | 1 |
133 | 1 |
|
|
134 | } |
|
|
135 | |
|
|
136 | sub fill { |
|
|
137 | my ($self) = @_; |
|
|
138 | |
|
|
139 | $self->add_underlay ("\x00" x ($WORLD->{tile_w} * $WORLD->{tile_h}), 0, $WORLD->{tile_w}, $WORLD->{arc_plt}); |
|
|
140 | $self->default_region (cf::region::find $WORLD->{reg_plt}[0]); |
134 | } |
141 | } |
135 | |
142 | |
136 | sub load { |
143 | sub load { |
137 | my ($self) = @_; |
144 | my ($self) = @_; |
138 | |
145 | |
139 | if ($self->{load_path}) { |
146 | if ($self->{load_path}) { |
140 | $self->SUPER::load; |
147 | $self->SUPER::load; |
141 | } else { |
148 | } else { |
142 | $self->alloc; |
149 | $self->alloc; |
143 | |
150 | $self->fill; |
144 | for my $X (0 .. $WORLD->{tile_w} - 1) { |
|
|
145 | Coro::cede; |
|
|
146 | for my $Y (0 .. $WORLD->{tile_h} - 1) { |
|
|
147 | my $ob = cf::object::new "deep_sea"; |
|
|
148 | $ob->flag (cf::FLAG_NO_MAP_SAVE, 1); |
|
|
149 | $self->insert ($ob, $X, $Y); |
|
|
150 | } |
|
|
151 | } |
|
|
152 | $self->set_object_flag (cf::FLAG_NO_MAP_SAVE, 1); |
|
|
153 | $self->default_region (cf::region::find "panthalassia"); |
|
|
154 | |
|
|
155 | $self->in_memory (cf::MAP_IN_MEMORY); |
151 | $self->in_memory (cf::MAP_IN_MEMORY); |
156 | } |
152 | } |
157 | } |
153 | } |
158 | |
154 | |
159 | sub post_load { |
155 | sub post_load { |
… | |
… | |
161 | |
157 | |
162 | my $guard = cf::lock_acquire "ext::world_gridmap"; |
158 | my $guard = cf::lock_acquire "ext::world_gridmap"; |
163 | |
159 | |
164 | my ($x, $y) = $self->wxwy; |
160 | my ($x, $y) = $self->wxwy; |
165 | |
161 | |
166 | return |
|
|
167 | unless $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; |
162 | if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) { |
|
|
163 | my $stride = $WORLD->{grid_w} * $WORLD->{tile_w}; |
|
|
164 | my $top = ($y - 100) * $WORLD->{tile_h} * $stride |
|
|
165 | + ($x - 100) * $WORLD->{tile_w}; |
168 | |
166 | |
169 | my $stride = $WORLD->{grid_w} * $WORLD->{tile_w}; |
167 | $self->add_underlay ($WORLD->{arc_data}, $top, $stride, $WORLD->{arc_plt}); |
170 | my $top = ($y - 100) * $WORLD->{tile_h} * $stride |
168 | $self->set_regiondata ($WORLD->{reg_data}, $top, $stride, $WORLD->{reg_plt}); |
171 | + ($x - 100) * $WORLD->{tile_w}; |
|
|
172 | |
169 | |
173 | my $reg; |
170 | } else { |
174 | |
171 | $self->fill; |
175 | for my $Y (0 .. $WORLD->{tile_h} - 1) { |
|
|
176 | Coro::cede; |
|
|
177 | my $row = substr $WORLD->{arc_data}, $top + $Y * $stride, $WORLD->{tile_w}; |
|
|
178 | $reg .= substr $WORLD->{reg_data}, $top + $Y * $stride, $WORLD->{tile_w}; |
|
|
179 | for my $X (0 .. $WORLD->{tile_w} - 1) { |
|
|
180 | next if grep $_->flag (cf::FLAG_IS_FLOOR), $self->at ($X, $Y); |
|
|
181 | my $ob = cf::object::new $WORLD->{arc_plt}[ord substr $row, $X]; |
|
|
182 | $ob->flag (cf::FLAG_NO_MAP_SAVE, 1); |
|
|
183 | $self->insert ($ob, $X, $Y, undef, cf::INS_ABOVE_FLOOR_ONLY); |
|
|
184 | } |
|
|
185 | } |
172 | } |
186 | |
|
|
187 | $self->set_regiondata ($reg, $WORLD->{reg_plt}); |
|
|
188 | } |
173 | } |
189 | |
174 | |
190 | 1 |
175 | 1 |
191 | |
176 | |