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

Comparing deliantra/server/common/object.C (file contents):
Revision 1.97 by elmex, Sat Dec 30 21:07:46 2006 UTC vs.
Revision 1.99 by root, Sun Dec 31 18:10:40 2006 UTC

564 } 564 }
565 565
566 this->speed = speed; 566 this->speed = speed;
567 567
568 if (has_active_speed ()) 568 if (has_active_speed ())
569 activate (false); 569 activate ();
570 else 570 else
571 deactivate (false); 571 deactivate ();
572} 572}
573 573
574/* 574/*
575 * update_object() updates the the map. 575 * update_object() updates the the map.
576 * It takes into account invisible objects (and represent squares covered 576 * It takes into account invisible objects (and represent squares covered
624 return; 624 return;
625 } 625 }
626 626
627 mapspace &m = op->ms (); 627 mapspace &m = op->ms ();
628 628
629 if (m.flags_ & P_NEED_UPDATE) 629 if (!(m.flags_ & P_UPTODATE))
630 /* nop */; 630 /* nop */;
631 else if (action == UP_OBJ_INSERT) 631 else if (action == UP_OBJ_INSERT)
632 { 632 {
633 // this is likely overkill, TODO: revisit (schmorp) 633 // this is likely overkill, TODO: revisit (schmorp)
634 if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW)) 634 if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW))
643 /* This isn't perfect, but I don't expect a lot of objects to 643 /* This isn't perfect, but I don't expect a lot of objects to
644 * to have move_allow right now. 644 * to have move_allow right now.
645 */ 645 */
646 || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block 646 || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block
647 || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp) 647 || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp)
648 m.flags_ = P_NEED_UPDATE; 648 m.flags_ = 0;
649 } 649 }
650 /* if the object is being removed, we can't make intelligent 650 /* if the object is being removed, we can't make intelligent
651 * decisions, because remove_ob can't really pass the object 651 * decisions, because remove_ob can't really pass the object
652 * that is being removed. 652 * that is being removed.
653 */ 653 */
654 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) 654 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE)
655 m.flags_ = P_NEED_UPDATE; 655 m.flags_ = 0;
656 else if (action == UP_OBJ_FACE) 656 else if (action == UP_OBJ_FACE)
657 /* Nothing to do for that case */ ; 657 /* Nothing to do for that case */ ;
658 else 658 else
659 LOG (llevError, "update_object called with invalid action: %d\n", action); 659 LOG (llevError, "update_object called with invalid action: %d\n", action);
660 660
661 if (op->more) 661 if (op->more)
662 update_object (op->more, action); 662 update_object (op->more, action);
663} 663}
664 664
665object::vector object::objects; // not yet used
666object *object::first; 665object *object::first;
667 666
668object::object () 667object::object ()
669{ 668{
670 SET_FLAG (this, FLAG_REMOVED); 669 SET_FLAG (this, FLAG_REMOVED);
703 702
704 prev = 0; 703 prev = 0;
705 next = 0; 704 next = 0;
706} 705}
707 706
707bool
708object::active () const
709{
710 return active_next || active_prev || this == active_objects;
711}
712
708void 713void
709object::activate (bool recursive) 714object::activate ()
710{ 715{
716 /* If already on active list, don't do anything */
717 if (active ())
718 return;
719
711 if (has_active_speed ()) 720 if (has_active_speed ())
712 { 721 {
713 /* If already on active list, don't do anything */
714 if (active_next || active_prev || this == active_objects)
715 return;
716
717 /* process_events() expects us to insert the object at the beginning 722 /* process_events() expects us to insert the object at the beginning
718 * of the list. */ 723 * of the list. */
719 active_next = active_objects; 724 active_next = active_objects;
720 725
721 if (active_next) 726 if (active_next)
722 active_next->active_prev = this; 727 active_next->active_prev = this;
723 728
724 active_objects = this; 729 active_objects = this;
725 } 730 }
731}
726 732
727 if (recursive) 733void
734object::activate_recursive ()
735{
736 activate ();
737
728 for (object *op = inv; op; op = op->above) 738 for (object *op = inv; op; op = op->above)
729 op->activate (1); 739 op->activate_recursive ();
730} 740}
731 741
732/* This function removes object 'op' from the list of active 742/* This function removes object 'op' from the list of active
733 * objects. 743 * objects.
734 * This should only be used for style maps or other such 744 * This should only be used for style maps or other such
736 * in play chewing up cpu time getting processed. 746 * in play chewing up cpu time getting processed.
737 * The reverse of this is to call update_ob_speed, which 747 * The reverse of this is to call update_ob_speed, which
738 * will do the right thing based on the speed of the object. 748 * will do the right thing based on the speed of the object.
739 */ 749 */
740void 750void
741object::deactivate (bool recursive) 751object::deactivate ()
742{ 752{
743 /* If not on the active list, nothing needs to be done */ 753 /* If not on the active list, nothing needs to be done */
744 if (!active_next && !active_prev && this != active_objects) 754 if (!active ())
745 return; 755 return;
746 756
747 if (active_prev == 0) 757 if (active_prev == 0)
748 { 758 {
749 active_objects = active_next; 759 active_objects = active_next;
757 active_next->active_prev = active_prev; 767 active_next->active_prev = active_prev;
758 } 768 }
759 769
760 active_next = 0; 770 active_next = 0;
761 active_prev = 0; 771 active_prev = 0;
772}
762 773
763 if (recursive) 774void
775object::deactivate_recursive ()
776{
764 for (object *op = inv; op; op = op->above) 777 for (object *op = inv; op; op = op->above)
778 op->deactivate_recursive ();
779
765 op->deactivate (1); 780 deactivate ();
766} 781}
767 782
768/* 783/*
769 * Remove and free all objects in the inventory of the given object. 784 * Remove and free all objects in the inventory of the given object.
770 * object.c ? 785 * object.c ?
974 { 989 {
975 --map->players; 990 --map->players;
976 map->last_access = runtime; 991 map->last_access = runtime;
977 } 992 }
978 993
994 map->dirty = true;
979 995
980 /* link the object above us */ 996 /* link the object above us */
981 if (above) 997 if (above)
982 above->below = below; 998 above->below = below;
983 else 999 else
1056 } 1072 }
1057 1073
1058 /* last == NULL if there are no objects on this space */ 1074 /* last == NULL if there are no objects on this space */
1059 //TODO: this makes little sense, why only update the topmost object? 1075 //TODO: this makes little sense, why only update the topmost object?
1060 if (!last) 1076 if (!last)
1061 map->at (x, y).flags_ = P_NEED_UPDATE; 1077 map->at (x, y).flags_ = 0;
1062 else 1078 else
1063 update_object (last, UP_OBJ_REMOVE); 1079 update_object (last, UP_OBJ_REMOVE);
1064 1080
1065 if (flag [FLAG_BLOCKSVIEW] || glow_radius) 1081 if (flag [FLAG_BLOCKSVIEW] || glow_radius)
1066 update_all_los (map, x, y); 1082 update_all_los (map, x, y);
1363 op->contr->do_los = 1; 1379 op->contr->do_los = 1;
1364 ++op->map->players; 1380 ++op->map->players;
1365 op->map->last_access = runtime; 1381 op->map->last_access = runtime;
1366 } 1382 }
1367 1383
1384 op->map->dirty = true;
1385
1368 /* If we have a floor, we know the player, if any, will be above 1386 /* If we have a floor, we know the player, if any, will be above
1369 * it, so save a few ticks and start from there. 1387 * it, so save a few ticks and start from there.
1370 */ 1388 */
1371 if (!(flag & INS_MAP_LOAD)) 1389 if (!(flag & INS_MAP_LOAD))
1372 if (object *pl = op->ms ().player ()) 1390 if (object *pl = op->ms ().player ())
1377 * visible to others on this map. But update_all_los is really 1395 * visible to others on this map. But update_all_los is really
1378 * an inefficient way to do this, as it means los for all players 1396 * an inefficient way to do this, as it means los for all players
1379 * on the map will get recalculated. The players could very well 1397 * on the map will get recalculated. The players could very well
1380 * be far away from this change and not affected in any way - 1398 * be far away from this change and not affected in any way -
1381 * this should get redone to only look for players within range, 1399 * this should get redone to only look for players within range,
1382 * or just updating the P_NEED_UPDATE for spaces within this area 1400 * or just updating the P_UPTODATE for spaces within this area
1383 * of effect may be sufficient. 1401 * of effect may be sufficient.
1384 */ 1402 */
1385 if (op->map->darkness && (op->glow_radius != 0)) 1403 if (op->map->darkness && (op->glow_radius != 0))
1386 update_all_los (op->map, op->x, op->y); 1404 update_all_los (op->map, op->x, op->y);
1387 1405

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines