--- deliantra/server/socket/item.C 2006/12/20 01:19:11 1.27 +++ deliantra/server/socket/item.C 2006/12/20 09:14:22 1.28 @@ -39,6 +39,146 @@ /** This is the maximum number of bytes we expect any one item to take up */ #define MAXITEMLEN 300 +#if 0 +tag_t +client_container::tag () const +{ + switch (type) + { + case CC_INVENTORY: + return ns->pl->count; + case CC_MAPSPACE: + return 0; + case CC_CONTAINER: + return env->count; + } + + abort (); +} + +void +client_container::clear () +{ + switch (type) + { + case CC_INVENTORY: + abort (); + + case CC_MAPSPACE: + case CC_CONTAINER: + ns->send_packet_printf ("delinv %d", tag ()); + break; + } + + for (iterator i = begin (); i != end (); ++i) + i->op->seen_by = 0; + + vector< refitem, slice_allocator >::clear (); +} + +inline iterator +client_container::merge_item (iterator i, object *op) +{ + if (i != end () && i->op == op) + return ++i; + + if (op->seen_by) + return; // seen by another entity already + + op->seen_by = this; + + refitem ref; + ref.op = op; + + return insert (i, ref); +} + +void +client_container::update (int offset) +{ + iterator i = begin (); + + switch (type) + { + case CC_INVENTORY: + case CC_CONTAINER: + { + object *env = type == CC_INVENTORY + ? ns->pl->ob + : this->env; + + // pass 1, erase all objects no longer in container + for (iterator j = begin (); j != end (); ++j) + if (j->op->env != env) + { + j->op->seen_by = 0; + erase (j); + } + + // pass 2 merge items + for (object *op = env->inv; op; op = op->below) + { + if (--offset < 0) + i = merge_item (i, op); + else if (offset < -FLOORBOX_PAGESIZE) + break; + } + } + break; + + case CC_MAPSPACE: + { + // pass 1, erase all objects no longer on space + for (iterator j = begin (); j != end (); ++j) + if (j->op->x != x || j->op->y != y || j->op->map != map) + { + j->op->seen_by = 0; + erase (j); + } + + // pass 2 merge items + for (object *op = GET_MAP_OB (map, x, y); op; op = op->above) + { + if (--offset < 0) + i = merge_item (i, op); + else if (offset < -FLOORBOX_PAGESIZE) + break; + } + } + break; + } + + // pass 3, erase all extra items + for (iterator j = i; j != end (); ++j) + j->op->seen_by = 0; + + if (i != end ()) + erase (i, end ()); +} + +void +client_container::set_mapspace (maptile *map, int x, int y) +{ + if (type == CC_MAPSPACE + && this->map == map + && this->x == x + && this->y == y) + return; + + clear (); + + type = CC_MAPSPACE; + this->map = map; + this->x = x; + this->y = y; +} + +void +client_container::set_container (object *env) +{ +} +#endif + /******************************************************************************* * * Functions related to sending object data to the client. @@ -213,7 +353,7 @@ || out_of_map (pl->map, pl->x, pl->y)) return; - for (tmp = get_map_ob (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above) + for (tmp = GET_MAP_OB (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above) ; pl->contr->socket->send_packet ("delinv 0"); @@ -565,7 +705,7 @@ if (tmp->count == count) return tmp; - for (op = get_map_ob (pl->map, pl->x, pl->y); op; op = op->above) + for (op = GET_MAP_OB (pl->map, pl->x, pl->y); op; op = op->above) if (op->head && op->head->count == count) return op; else if (op->count == count) @@ -694,7 +834,7 @@ if (!m) return; - for (tmp = get_map_ob (m, x, y); tmp != NULL && tmp->above != NULL; tmp = tmp->above); + for (tmp = GET_MAP_OB (m, x, y); tmp != NULL && tmp->above != NULL; tmp = tmp->above); for (; tmp != NULL; tmp = tmp->below) {