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

Comparing deliantra/server/ext/00_map_handling.ext (file contents):
Revision 1.7 by root, Sat Dec 30 21:15:59 2006 UTC vs.
Revision 1.8 by root, Sun Dec 31 10:28:36 2006 UTC

138 exit 1; 138 exit 1;
139 } 139 }
140})->prio (Coro::PRIO_MAX); 140})->prio (Coro::PRIO_MAX);
141 141
142our $SCHEDULER = cf::coro { 142our $SCHEDULER = cf::coro {
143 Coro::Timer::sleep 3600;#d#TODO#for debugging only
143 while () { 144 while () {
144 Coro::Timer::sleep $SCHEDULE_INTERVAL; 145 Coro::Timer::sleep $SCHEDULE_INTERVAL;
145 146
146 write_runtime 147 write_runtime
147 or warn "unable to write runtime file: $!"; 148 or warn "unable to write runtime file: $!";
172 } 173 }
173 } 174 }
174}; 175};
175$SCHEDULER->prio (-2); 176$SCHEDULER->prio (-2);
176 177
178sub generate_random_map {
179 my ($path, $rmp) = @_;
180
181 # mit "rum" bekleckert, nicht
182 cf::map::_create_random_map
183 $path,
184 $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle},
185 $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle},
186 $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map},
187 $rmp->{exit_on_final_map},
188 $rmp->{xsize}, $rmp->{ysize},
189 $rmp->{expand2x}, $rmp->{layoutoptions1}, $rmp->{layoutoptions2}, $rmp->{layoutoptions3},
190 $rmp->{symmetry}, $rmp->{difficulty}, $rmp->{difficulty_given}, $rmp->{difficulty_increase},
191 $rmp->{dungeon_level}, $rmp->{dungeon_depth}, $rmp->{decoroptions}, $rmp->{orientation},
192 $rmp->{origin_y}, $rmp->{origin_x}, $rmp->{random_seed}, $rmp->{total_map_hp},
193 $rmp->{map_layout_style}, $rmp->{treasureoptions}, $rmp->{symmetry_used},
194 $rmp->{region}
195}
196
197sub parse_random_map_params {
198 my ($spec) = @_;
199
200 my $rmp;
201
202 for (split /\n/, $spec) {
203 my ($k, $v) = split /\s+/, $_, 2;
204
205 $rmp->{lc $k} = $v if (length $k) && (length $v);
206 }
207
208 $rmp
209}
210
211sub prepare_random_map {
212 my ($exit) = @_;
213
214 my $rmp = parse_random_map_params $exit->msg;
215 use Data::Dumper;
216 die Dumper $rmp;
217}
218
177sub sync_job(&) { 219sub sync_job(&) {
178 my ($job) = @_; 220 my ($job) = @_;
179 221
180 my $done; 222 my $done;
181 my @res; 223 my @res;
193 while (!$done) { 235 while (!$done) {
194 Coro::cede_notself; 236 Coro::cede_notself;
195 Event::one_event unless Coro::nready; 237 Event::one_event unless Coro::nready;
196 } 238 }
197 239
240 warn "sync<@res>\n";#d#
198 wantarray ? @res : $res[0] 241 wantarray ? @res : $res[0]
199} 242}
200 243
201# and all this just because we cannot iterate over 244# and all this just because we cannot iterate over
202# all maps in C++... 245# all maps in C++...
225 $map->{load_path} = $path; 268 $map->{load_path} = $path;
226 269
227 $map 270 $map
228} 271}
229 272
230sub cf::map::find_map_nb { 273sub cf::map::find_map {
231 my ($path, $origin) = @_; 274 my ($path, $origin) = @_;
232 275
233 warn "find_map_nb<$path,$origin>\n";#d# 276 warn "find_map<$path,$origin>\n";#d#
234 277
235 $path = ref $path ? $path : new cf::path $path, $origin && $origin->path; 278 $path = ref $path ? $path : new cf::path $path, $origin && $origin->path;
236 my $key = $path->as_string; 279 my $key = $path->as_string;
237 280
238 $cf::MAP{$key} || do { 281 $cf::MAP{$key} || do {
240 my $map = try_load_header $path->save_path; 283 my $map = try_load_header $path->save_path;
241 284
242 if (!$map) { 285 if (!$map) {
243 $map = try_load_header $path->load_path 286 $map = try_load_header $path->load_path
244 or return; 287 or return;
245 }
246 288
247 $map or return;
248
249 $map->instantiate; 289 $map->instantiate;
290
291 # per-player maps become, after loading, normal maps
292 $map->per_player (0) if $path->{user_rel};
293 }
294
250 $map->path ($key); 295 $map->path ($key);
251 $map->{path} = $path; 296 $map->{path} = $path;
252 297
253 $map->per_player (0) if $path->{user_rel};
254
255 $map->reset if $map->should_reset; 298 $map->reset if $map->should_reset;
256 299
257 $cf::MAP{$key} = $map 300 $cf::MAP{$key} = $map
258 } 301 }
259} 302}
260 303
261sub cf::map::find_map {
262 my ($path, $origin) = @_;
263
264 $path = new cf::path $path, $origin && $origin->path;
265 my $key = $path->as_string;
266
267 $cf::MAP{$key} || sync_job {
268 cf::map::find_map_nb $path;
269 }
270}
271
272sub cf::map::do_load_nb { 304sub cf::map::load {
273 my ($self) = @_; 305 my ($self) = @_;
274 306
275 return 0 unless $self->in_memory == cf::MAP_SWAPPED; 307 return if $self->in_memory != cf::MAP_SWAPPED;
276 308
277 $self->in_memory (cf::MAP_LOADING); 309 $self->in_memory (cf::MAP_LOADING);
278 310
279 my $path = $self->{path}; 311 my $path = $self->{path};
280 312
301 $self->activate; 333 $self->activate;
302 334
303 $self->in_memory (cf::MAP_IN_MEMORY); 335 $self->in_memory (cf::MAP_IN_MEMORY);
304} 336}
305 337
306sub cf::map::do_load { 338sub cf::map::load_map_sync {
307 my ($self) = @_; 339 my ($path, $origin) = @_;
308 340
309 warn "do_load<$self>\n";#d# 341 warn "load_map_sync<$path, $origin>\n";#d#
310 342
311 sync_job { 343 sync_job {
312 cf::map::do_load_nb $self; 344 my $map = cf::map::find_map $path, $origin
345 or return;
346 $map->load;
347 $map
313 }; 348 }
314} 349}
315 350
316sub cf::map::save { 351sub cf::map::save {
317 my ($self) = @_; 352 my ($self) = @_;
318 353
334 369
335sub cf::map::swap_out { 370sub cf::map::swap_out {
336 my ($self) = @_; 371 my ($self) = @_;
337 372
338 return if $self->players; 373 return if $self->players;
339
340 $self->save if $self->in_memory == cf::MAP_IN_MEMORY; 374 return if $self->in_memory != cf::MAP_IN_MEMORY;
375
376 $self->save;
341 $self->clear; 377 $self->clear;
342 $self->in_memory (cf::MAP_SWAPPED); 378 $self->in_memory (cf::MAP_SWAPPED);
343} 379}
344 380
345sub cf::map::should_reset { 381sub cf::map::should_reset {
346 my ($map) = @_; 382 my ($map) = @_;
347 383
348 # TODO: safety, remove and allow resettable per-player maps 384 # TODO: safety, remove and allow resettable per-player maps
349 return if $map->{path}{user_rel};#d# 385 return if $map->{path}{user_rel};#d#
350 return if $map->per_player;
351 return unless $map->reset_timeout; 386 return unless $map->reset_timeout;
352 387
353 my $time = $map->fixed_resettime ? $map->reset_time : $map->last_access; 388 my $time = $map->fixed_resettime ? $map->reset_time : $map->last_access;
354 389
355 $time + $map->reset_timeout < $cf::RUNTIME 390 $time + $map->reset_timeout < $cf::RUNTIME
381 416
382 #TODO: do this in the background, freeze the player if required 417 #TODO: do this in the background, freeze the player if required
383 sync_job { 418 sync_job {
384 my ($map, $x, $y); 419 my ($map, $x, $y);
385 420
386 if ($exit->slaying eq "!") { 421 if ($exit->slaying eq "/!") {
387 } else { 422 prepare_random_map $exit;
423 }
424
388 my $path = new cf::path $exit->slaying, $exit->map && $exit->map->path; 425 my $path = new cf::path $exit->slaying, $exit->map && $exit->map->path;
389 426
390 $map = cf::map::find_map_nb $path->as_string; 427 $map = cf::map::find_map $path->as_string;
391 $map = $map->customise_for ($ob) if $map; 428 $map = $map->customise_for ($ob) if $map;
392 ($x, $y) = ($exit->stats->hp, $exit->stats->sp); 429 ($x, $y) = ($exit->stats->hp, $exit->stats->sp);
393 }
394 430
395 unless ($map) { 431 unless ($map) {
396 $ob->message ("The exit is closed", cf::NDI_UNIQUE | cf::NDI_RED); 432 $ob->message ("The exit is closed", cf::NDI_UNIQUE | cf::NDI_RED);
397 433
398 # restore original map position 434 # restore original map position
399 ($map, $x, $y) = ($oldmap, $oldx, $oldy); 435 ($map, $x, $y) = ($oldmap, $oldx, $oldy);
400 436
401 unless ($map) { 437 unless ($map) {
402 $map = cf::map::find_map_nb $emergency_position->[0] 438 $map = cf::map::find_map $emergency_position->[0]
403 or die "FATAL: cannot load emergency map\n"; 439 or die "FATAL: cannot load emergency map\n";
404 $x = $emergency_position->[1]; 440 $x = $emergency_position->[1];
405 $y = $emergency_position->[2]; 441 $y = $emergency_position->[2];
406 } 442 }
407 } 443 }
409 # use -1, -1 as default coordinates, not 0, 0 445 # use -1, -1 as default coordinates, not 0, 0
410 ($x, $y) = ($map->enter_x, $map->enter_y) 446 ($x, $y) = ($map->enter_x, $map->enter_y)
411 if $x <=0 && $y <= 0; 447 if $x <=0 && $y <= 0;
412 448
413 warn "entering ", $map->path, " at ($x, $y)\n";#d# 449 warn "entering ", $map->path, " at ($x, $y)\n";#d#
414 $map->do_load_nb; 450 $map->load;
415 $ob->enter_map ($map, $x, $y); 451 $ob->enter_map ($map, $x, $y);
416 } 452 }
417} 453}
418 454
419sub cf::map::customise_for { 455sub cf::map::customise_for {
420 my ($map, $ob) = @_; 456 my ($map, $ob) = @_;
421 457
422 if ($map->per_player) { 458 if ($map->per_player) {
423 return cf::map::find_map_nb "~" . $ob->name . "/" . $map->{path}{path}; 459 return cf::map::find_map "~" . $ob->name . "/" . $map->{path}{path};
424 } 460 }
425 461
426 $map 462 $map
427} 463}
428 464

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines