Crossfire Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CF: Patch: speed up object dropping (no, not the bug fix)



Hi,

dropping a large number of objects tends to freeze the server for quite
some time. This has two reasons
a) the list has to be traversed for each object
b) the inventory and look windows are updated for each object

I can't do anything about a), but I fixed b). This speeds up object
dropping considerably.

It seems that the author(s) even wanted to do that, but since the
freeze_inv and freeze_look variables are booleans, freezing doesn't
nest... the original sequence of events was:
 command_drop: freezes windows
    drop-function: freezes windows
    drop-function: unfreezes windows
 command_drop: unfreezes windows

I fixed this by changing the drop-function to remember the old
state of the freeze_.* variables, then freezing the windows,
then restoring the old state. Hopefully nothing depends on
the old behavior (the patch seems to work correctly).

Christian

------------------------------ Cut ------------------------------

*** crossfire-0.93.7/server/c_object.c	Tue Jan  6 10:29:23 1998
--- /crossfire/server/c_object.c	Thu Jan 15 19:59:42 1998
***************
*** 763,786 ****
  }
  #else
  	save_player(op,1); /* To avoid cheating */
  #endif
  #endif /* SAVE_INTERVAL */
-     
-     D_LOCK(op);
  
!     floor = get_map_ob (op->map, op->x, op->y);
!     if( floor && floor->type == SHOP_FLOOR && 
!        !QUERY_FLAG(tmp, FLAG_UNPAID) && tmp->type != MONEY)
!       sell_item(tmp,op);
  
!     tmp->x = op->x;
!     tmp->y = op->y;
!     insert_ob_in_map(tmp, op->map);
!     remove_ob(op);
!     insert_ob_in_map(op, op->map);
!     D_UNLOCK(op);
  
      /* Call this before we update the various windows/players.  At least
       * that we, we know the weight is correct.
       */
      fix_player(op); /* This is overkill, fix_player() is called somewhere */ 
--- 779,810 ----
  }
  #else
  	save_player(op,1); /* To avoid cheating */
  #endif
  #endif /* SAVE_INTERVAL */
  
! 	{
! 	  int freeze_inv, freeze_look;
  
! 	  freeze_inv=op->contr->freeze_inv;
! 	  freeze_look=op->contr->freeze_look;
! 	  D_LOCK(op);
! 
! 	  floor = get_map_ob (op->map, op->x, op->y);
! 	  if( floor && floor->type == SHOP_FLOOR && 
! 	      !QUERY_FLAG(tmp, FLAG_UNPAID) && tmp->type != MONEY)
! 	    sell_item(tmp,op);
! 
! 	  tmp->x = op->x;
! 	  tmp->y = op->y;
! 	  insert_ob_in_map(tmp, op->map);
! 	  remove_ob(op);
! 	  insert_ob_in_map(op, op->map);
! 
! 	  op->contr->freeze_inv=freeze_inv;
! 	  op->contr->freeze_look=freeze_look;
! 	}
  
      /* Call this before we update the various windows/players.  At least
       * that we, we know the weight is correct.
       */
      fix_player(op); /* This is overkill, fix_player() is called somewhere */ 

[to unsubscribe etc., send mail to crossfire-request@ifi.uio.no]