… | |
… | |
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 | 0 < aio_load "$path/gridmap.meta", my $map |
73 | 0 < aio_load "$path/gridmap.meta", my $map |
73 | or cf::cleanup "$path/gridmap.meta: $!\n"; |
74 | or cf::cleanup "$path/gridmap.meta: $!\n"; |
74 | |
75 | |
75 | $map = cf::from_json $map; |
76 | $map = cf::from_json $map; |
76 | |
77 | |
77 | my $size = $map->{tile_w} * $map->{tile_h} * $map->{grid_w} * $map->{grid_h} |
78 | my $size = $map->{tile_w} * $map->{tile_h} * $map->{grid_w} * $map->{grid_h} |
78 | or cf::cleanup "$path/gridmap.meta: empty gridmap?"; |
79 | or cf::cleanup "$path/gridmap.meta: empty gridmap?"; |
79 | |
80 | |
80 | ($map->{arc_data}, $map->{arc_plt}) = load_indexed "$path/gridmap.arch", $size; |
81 | ($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; |
82 | ($map->{reg_data}, $map->{reg_plt}) = load_indexed "$path/gridmap.regn", $size; |
82 | |
83 | |
|
|
84 | Storable::nstore $map, "/tmp/xxxx.gridmap";#d# |
|
|
85 | |
83 | $map |
86 | $map |
|
|
87 | } else { |
|
|
88 | Storable::retrieve "/tmp/xxxx.gridmap"; |
|
|
89 | } |
84 | } |
90 | } |
85 | |
91 | |
86 | # this is contorted, but likely the correct way to acquire the lock :) |
92 | # this is contorted, but likely the correct way to acquire the lock :) |
87 | cf::sync_job { |
93 | cf::sync_job { |
88 | my $guard = cf::lock_acquire "ext::world_gridmap"; |
94 | my $guard = cf::lock_acquire "ext::world_gridmap"; |
… | |
… | |
114 | $self->name ("'The World' at +$x+$y"); |
120 | $self->name ("'The World' at +$x+$y"); |
115 | $self->msg ("worldmap dynamically created by map-world extension"); |
121 | $self->msg ("worldmap dynamically created by map-world extension"); |
116 | $self->outdoor (1); |
122 | $self->outdoor (1); |
117 | $self->default_region (undef); |
123 | $self->default_region (undef); |
118 | |
124 | |
119 | # $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; |
120 | # $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; |
121 | # $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; |
122 | # $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; |
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 | |
129 | |
128 | $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", cf::datadir, cf::mapdir, $x, $y |
129 | if $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; |
131 | if $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; |
130 | |
132 | |
131 | 1 |
133 | 1 |
|
|
134 | } |
|
|
135 | |
|
|
136 | sub fill { |
|
|
137 | my ($self) = @_; |
|
|
138 | |
|
|
139 | for my $X (0 .. $WORLD->{tile_w} - 1) { |
|
|
140 | Coro::cede; |
|
|
141 | for my $Y (0 .. $WORLD->{tile_h} - 1) { |
|
|
142 | my $ob = cf::object::new "deep_sea"; |
|
|
143 | $ob->flag (cf::FLAG_NO_MAP_SAVE, 1); |
|
|
144 | $self->insert ($ob, $X, $Y, undef, cf::INS_ABOVE_FLOOR_ONLY); |
|
|
145 | } |
|
|
146 | } |
|
|
147 | $self->set_object_flag (cf::FLAG_NO_MAP_SAVE, 1); |
|
|
148 | $self->default_region (cf::region::find "panthalassia"); |
132 | } |
149 | } |
133 | |
150 | |
134 | sub load { |
151 | sub load { |
135 | my ($self) = @_; |
152 | my ($self) = @_; |
136 | |
153 | |
137 | if ($self->{load_path}) { |
154 | if ($self->{load_path}) { |
138 | $self->SUPER::load; |
155 | $self->SUPER::load; |
139 | } else { |
156 | } else { |
140 | $self->alloc; |
157 | $self->alloc; |
141 | |
158 | $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 | |
|
|
151 | $self->in_memory (cf::MAP_IN_MEMORY); |
159 | $self->in_memory (cf::MAP_IN_MEMORY); |
152 | } |
160 | } |
153 | } |
161 | } |
154 | |
162 | |
155 | sub post_load { |
163 | sub post_load { |
… | |
… | |
157 | |
165 | |
158 | my $guard = cf::lock_acquire "ext::world_gridmap"; |
166 | my $guard = cf::lock_acquire "ext::world_gridmap"; |
159 | |
167 | |
160 | my ($x, $y) = $self->wxwy; |
168 | my ($x, $y) = $self->wxwy; |
161 | |
169 | |
162 | return |
|
|
163 | unless $x >= 100 && $x <= 129 && $y >= 100 && $y <= 129; |
170 | if ($x >= 100 && $x <= 129 && $y >= 100 && $y <= 129) { |
|
|
171 | my $stride = $WORLD->{grid_w} * $WORLD->{tile_w}; |
|
|
172 | my $top = ($y - 100) * $WORLD->{tile_h} * $stride |
|
|
173 | + ($x - 100) * $WORLD->{tile_w}; |
164 | |
174 | |
165 | my $stride = $WORLD->{grid_w} * $WORLD->{tile_w}; |
175 | my $reg; |
166 | my $top = ($y - 100) * $WORLD->{tile_h} * $stride |
|
|
167 | + ($x - 100) * $WORLD->{tile_w}; |
|
|
168 | |
176 | |
169 | my $reg; |
177 | for my $Y (0 .. $WORLD->{tile_h} - 1) { |
|
|
178 | Coro::cede; |
|
|
179 | my $row = substr $WORLD->{arc_data}, $top + $Y * $stride, $WORLD->{tile_w}; |
|
|
180 | $reg .= substr $WORLD->{reg_data}, $top + $Y * $stride, $WORLD->{tile_w}; |
|
|
181 | for my $X (0 .. $WORLD->{tile_w} - 1) { |
|
|
182 | next if grep $_->flag (cf::FLAG_IS_FLOOR), $self->at ($X, $Y); |
|
|
183 | my $ob = cf::object::new $WORLD->{arc_plt}[ord substr $row, $X]; |
|
|
184 | $ob->flag (cf::FLAG_NO_MAP_SAVE, 1); |
|
|
185 | $self->insert ($ob, $X, $Y, undef, cf::INS_ABOVE_FLOOR_ONLY); |
|
|
186 | } |
|
|
187 | } |
170 | |
188 | |
171 | for my $Y (0 .. $WORLD->{tile_h} - 1) { |
189 | $self->set_regiondata ($reg, $WORLD->{reg_plt}); |
172 | Coro::cede; |
190 | } else { |
173 | my $row = substr $WORLD->{arc_data}, $top + $Y * $stride, $WORLD->{tile_w}; |
191 | $self->fill; |
174 | $reg .= substr $WORLD->{reg_data}, $top + $Y * $stride, $WORLD->{tile_w}; |
|
|
175 | for my $X (0 .. $WORLD->{tile_w} - 1) { |
|
|
176 | next if grep $_->flag (cf::FLAG_IS_FLOOR), $self->at ($X, $Y); |
|
|
177 | my $ob = cf::object::new $WORLD->{arc_plt}[ord substr $row, $X]; |
|
|
178 | $ob->flag (cf::FLAG_NO_MAP_SAVE, 1); |
|
|
179 | $self->insert ($ob, $X, $Y, undef, cf::INS_ABOVE_FLOOR_ONLY); |
|
|
180 | } |
|
|
181 | } |
192 | } |
182 | |
|
|
183 | $self->set_regiondata ($reg, $WORLD->{reg_plt}); |
|
|
184 | } |
193 | } |
185 | |
194 | |
186 | 1 |
195 | 1 |
187 | |
196 | |