@@ -173,6 +173,8 @@ void CClientStreamer::SetDimension(unsigned short usDimension)
173173
174174 if (element->IsStreamedIn ())
175175 m_ToStreamOut.push_back (element);
176+ else if (sector->IsActivated ())
177+ m_ActiveElements.remove (element);
176178 }
177179 }
178180 }
@@ -186,9 +188,11 @@ void CClientStreamer::SetDimension(unsigned short usDimension)
186188 return ;
187189
188190 auto iter = m_outsideCurrentDimensionElements.begin ();
189-
190- while (*iter != lastOutsideElement)
191+ bool isLast = false ;
192+ do
191193 {
194+ isLast = *iter == lastOutsideElement;
195+
192196 CClientStreamElement* element = *iter;
193197 if (element->GetDimension () == usDimension)
194198 {
@@ -199,7 +203,7 @@ void CClientStreamer::SetDimension(unsigned short usDimension)
199203 {
200204 iter++;
201205 }
202- }
206+ } while (!isLast);
203207}
204208
205209CClientStreamSectorRow* CClientStreamer::FindOrCreateRow (CVector& vecPosition, CClientStreamSectorRow* pSurrounding)
@@ -331,7 +335,10 @@ void CClientStreamer::AddElement(CClientStreamElement* pElement)
331335void CClientStreamer::RemoveElement (CClientStreamElement* pElement)
332336{
333337 if (pElement->GetStreamSector ())
338+ {
334339 RemoveElementFromSectors (pElement);
340+ m_ActiveElements.remove (pElement);
341+ }
335342 else
336343 m_outsideCurrentDimensionElements.remove (pElement);
337344}
@@ -419,6 +426,10 @@ void CClientStreamer::Restream(bool bMovedFar)
419426 // Stream out 1 of them per frame
420427 pElement->InternalStreamOut ();
421428 iMaxOut--;
429+
430+ CClientStreamSector* streamSector = pElement->GetStreamSector ();
431+ if (!streamSector || !streamSector->IsActivated () || !ShouldElementBeVisibleInCurrentDimension (pElement))
432+ m_ActiveElements.remove (pElement);
422433 }
423434 m_ToStreamOut.remove (pElement);
424435
@@ -442,6 +453,12 @@ void CClientStreamer::Restream(bool bMovedFar)
442453 // Is this element streamed in?
443454 if (pElement->IsStreamedIn ())
444455 {
456+ if (!ShouldElementBeVisibleInCurrentDimension (pElement))
457+ {
458+ m_ToStreamOut.push_back (pElement);
459+ continue ;
460+ }
461+
445462 if (IS_VEHICLE (pElement))
446463 {
447464 CClientVehicle* pVehicle = DynamicCast<CClientVehicle>(pElement);
@@ -701,10 +718,6 @@ void CClientStreamer::OnElementEnterSector(CClientStreamElement* pElement, CClie
701718 }
702719 else
703720 {
704- // Should we deactivate the element?
705- if (pPreviousSector && pPreviousSector->IsActivated ())
706- m_ActiveElements.remove (pElement);
707-
708721 // Should we activate this sector?
709722 if (pSector->IsExtra () && (m_pSector->IsMySurroundingSector (pSector) || m_pSector == pSector))
710723 {
@@ -713,17 +726,19 @@ void CClientStreamer::OnElementEnterSector(CClientStreamElement* pElement, CClie
713726 }
714727 // If we're in a deactivated sector and streamed in, stream us out
715728 else if (pElement->IsStreamedIn ())
716- {
717729 m_ToStreamOut.push_back (pElement);
718- }
730+ else if (pPreviousSector && pPreviousSector->IsActivated ())
731+ m_ActiveElements.remove (pElement);
719732 }
720733 }
721- else if (pPreviousSector && pPreviousSector-> IsActivated ())
734+ else
722735 {
723- // The element was removed from sectors.
724- // Remove it from active elements too.
725- m_ActiveElements.remove (pElement);
736+ if (pElement->IsStreamedIn ())
737+ m_ToStreamOut.push_back (pElement);
738+ else if (pPreviousSector && pPreviousSector->IsActivated ())
739+ m_ActiveElements.remove (pElement);
726740 }
741+
727742 pElement->SetStreamSector (pSector);
728743}
729744
0 commit comments