ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/map.C
(Generate patch)

Comparing deliantra/server/common/map.C (file contents):
Revision 1.96 by root, Thu Mar 15 14:23:02 2007 UTC vs.
Revision 1.101 by root, Sat Apr 21 16:56:28 2007 UTC

344} 344}
345 345
346/* link_multipart_objects go through all the objects on the map looking 346/* link_multipart_objects go through all the objects on the map looking
347 * for objects whose arch says they are multipart yet according to the 347 * for objects whose arch says they are multipart yet according to the
348 * info we have, they only have the head (as would be expected when 348 * info we have, they only have the head (as would be expected when
349 * they are saved). We do have to look for the old maps that did save 349 * they are saved).
350 * the more sections and not re-add sections for them.
351 */ 350 */
352void 351void
353maptile::link_multipart_objects () 352maptile::link_multipart_objects ()
354{ 353{
355 if (!spaces) 354 if (!spaces)
356 return; 355 return;
357 356
358 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 357 for (mapspace *ms = spaces + size (); ms-- > spaces; )
359 for (object *tmp = ms->bot; tmp; tmp = tmp->above) 358 for (object *op = ms->bot; op; op = op->above)
360 { 359 {
361 /* already multipart - don't do anything more */ 360 /* already multipart - don't do anything more */
362 if (!tmp->head && !tmp->more) 361 if (!op->head && !op->more && op->arch->more)
363 { 362 {
364 /* If there is nothing more to this object, this for loop 363 op->remove ();
365 * won't do anything. 364 op->expand_tail ();
366 */
367 archetype *at;
368 object *last, *op;
369 for (at = tmp->arch->more, last = tmp;
370 at;
371 at = at->more, last = op)
372 {
373 op = arch_to_object (at);
374
375 /* update x,y coordinates */
376 op->x += tmp->x;
377 op->y += tmp->y;
378 op->head = tmp;
379 op->map = this;
380 last->more = op;
381 op->name = tmp->name;
382 op->title = tmp->title;
383
384 /* we could link all the parts onto tmp, and then just
385 * call insert_ob_in_map once, but the effect is the same,
386 * as insert_ob_in_map will call itself with each part, and
387 * the coding is simpler to just to it here with each part.
388 */
389 insert_ob_in_map (op, op->map, tmp, INS_NO_MERGE | INS_ABOVE_FLOOR_ONLY | INS_NO_WALK_ON); 365 insert (op, op->x, op->y, 0, INS_NO_MERGE | INS_ABOVE_FLOOR_ONLY | INS_NO_WALK_ON);
390 }
391 } 366 }
392 } 367 }
393} 368}
394 369
395/* 370/*
399bool 374bool
400maptile::_load_objects (object_thawer &f) 375maptile::_load_objects (object_thawer &f)
401{ 376{
402 for (;;) 377 for (;;)
403 { 378 {
404 coroapi::cede_every (1000); // cede once in a while 379 coroapi::cede_to_tick_every (100); // cede once in a while
405 380
406 switch (f.kw) 381 switch (f.kw)
407 { 382 {
408 case KW_arch: 383 case KW_arch:
409 if (object *op = object::read (f, this)) 384 if (object *op = object::read (f, this))
432} 407}
433 408
434void 409void
435maptile::activate () 410maptile::activate ()
436{ 411{
412 active = true;
413
437 if (!spaces) 414 if (spaces)
438 return;
439
440 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 415 for (mapspace *ms = spaces + size (); ms-- > spaces; )
441 for (object *op = ms->bot; op; op = op->above) 416 for (object *op = ms->bot; op; op = op->above)
442 op->activate_recursive (); 417 op->activate_recursive ();
443} 418}
444 419
445void 420void
446maptile::deactivate () 421maptile::deactivate ()
447{ 422{
423 active = false;
424
448 if (!spaces) 425 if (spaces)
449 return;
450
451 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 426 for (mapspace *ms = spaces + size (); ms-- > spaces; )
452 for (object *op = ms->bot; op; op = op->above) 427 for (object *op = ms->bot; op; op = op->above)
453 op->deactivate_recursive (); 428 op->deactivate_recursive ();
454} 429}
455 430
456bool 431bool
457maptile::_save_objects (object_freezer &f, int flags) 432maptile::_save_objects (object_freezer &f, int flags)
458{ 433{
459 static int cede_count = 0; 434 coroapi::cede_to_tick ();
460 435
461 if (flags & IO_HEADER) 436 if (flags & IO_HEADER)
462 _save_header (f); 437 _save_header (f);
463 438
464 if (!spaces) 439 if (!spaces)
465 return false; 440 return false;
466 441
467 for (int i = 0; i < size (); ++i) 442 for (int i = 0; i < size (); ++i)
468 { 443 {
469 if (cede_count >= 500)
470 {
471 cede_count = 0;
472 coroapi::cede ();
473 }
474
475 int unique = 0; 444 int unique = 0;
476 for (object *op = spaces [i].bot; op; op = op->above) 445 for (object *op = spaces [i].bot; op; op = op->above)
477 { 446 {
478 // count per-object, but cede only when modification-safe
479 cede_count++;
480
481 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]) 447 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR])
482 unique = 1; 448 unique = 1;
483 449
484 if (!op->can_map_save ()) 450 if (!op->can_map_save ())
485 continue; 451 continue;
491 } 457 }
492 else if (flags & IO_OBJECTS) 458 else if (flags & IO_OBJECTS)
493 op->write (f); 459 op->write (f);
494 } 460 }
495 } 461 }
462
463 coroapi::cede_to_tick ();
496 464
497 return true; 465 return true;
498} 466}
499 467
500bool 468bool

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines