/** ** StreamObjects ** Streams objects for a player. ** ** Parameters: ** - player: The player who needs to get the objects streamed **/ public function StreamObjects(Player $player, Position $position, Sector $sector) { if ($this->sight != -1) { $last_object = $player->object; $nearest = null; $distance = 0; $sector->FindNearestObject($position, &$nearest, &$distance); $player->object = $nearest; if ($last_object != null && $player->object != null && $last_object->Equals($player->object)) { return; } if ($last_object == null) { if ($player->object != null) { foreach ($player->object->Nearest() as $o) { $o->CreateForPlayer($player); } } } else { if ($player->object == null) { if ($last_object != null) { foreach ($last_object->Nearest() as $o) { $o->DestroyForPlayer($player); } } } else { $oldobjs = $last_object->Nearest(); $newobjs = $player->object->Nearest(); reset($oldobjs); reset($newobjs); $cur = current($newobjs); do { for ($old = current($oldobjs); $old && $old->ID() < $cur->ID(); $old = next($oldobjs)) { $old->DestroyForPlayer($player); } if ($old && $old->ID() == $cur->ID()) { next($oldobjs); } $cur->CreateForPlayer($player); $cur = next($newobjs); } while ($cur); for ($old = current($oldobjs); $old; $old = next($oldobjs)) { $old->DestroyForPlayer($player); } /* while ($oldobjs != null && $oldobjs->object->ID() < $newobjs->object->ID()) { $oldobjs->object->DestroyForPlayer($player); $oldobjs = $oldobjs->next; } if ($oldobjs != null && $oldobjs->object->ID() == $newobjs->object->ID()) $oldobjs = $oldobjs->next; $newobjs->object->CreateForPlayer($player); $newobjs = $newobjs->next; } while ($newobjs != null); while ($oldobjs != null) { $oldobjs->object->DestroyForPlayer($player); $oldobjs = $oldobjs->next; }*/ } } } }