99 *****************************************************************************/
1010
1111#include " StdInc.h"
12+ #include " CClientGame.h"
13+
14+ extern CClientGame* g_pClientGame;
1215using std::list;
1316
1417void * CClientStreamer::pAddingElement = NULL ;
@@ -107,51 +110,8 @@ void CClientStreamer::ConnectRow(CClientStreamSectorRow* pRow)
107110 pRow->m_pBottom ->m_pTop = pRow;
108111}
109112
110- #include " ..\deathmatch\logic\CClientGame.h"
111- extern CClientGame* g_pClientGame;
112- void CClientStreamer::DoPulse (CVector& vecPosition)
113+ void CClientStreamer::DoPulse (CVector& vecPosition)
113114{
114- /* Debug code
115- CClientStreamSector * pSector;
116- list < CClientStreamSector * > ::iterator iterSector;
117- list < CClientStreamSectorRow * > ::iterator iterRow = m_WorldRows.begin ();
118- for ( ; iterRow != m_WorldRows.end () ; iterRow++ )
119- {
120- iterSector = (*iterRow)->Begin ();
121- for ( ; iterSector != (*iterRow)->End () ; iterSector++ )
122- {
123- pSector = *iterSector;
124- if ( !pSector->m_pArea )
125- {
126- pSector->m_pArea = new CClientRadarArea ( g_pClientGame->GetManager (), INVALID_ELEMENT_ID );
127- pSector->m_pArea->SetPosition ( pSector->m_vecBottomLeft );
128- CVector2D vecSize ( pSector->m_vecTopRight.fX - pSector->m_vecBottomLeft.fX, pSector->m_vecTopRight.fY - pSector->m_vecBottomLeft.fY );
129- pSector->m_pArea->SetSize ( vecSize );
130- pSector->m_pArea->SetColor ( 255, 0, 0, 50 );
131- }
132- pSector->m_pArea->SetColor ( 255, 0, 0, 50 );
133- }
134- }
135- iterRow = m_ExtraRows.begin ();
136- for ( ; iterRow != m_ExtraRows.end () ; iterRow++ )
137- {
138- iterSector = (*iterRow)->Begin ();
139- for ( ; iterSector != (*iterRow)->End () ; iterSector++ )
140- {
141- pSector = *iterSector;
142- if ( !pSector->m_pArea )
143- {
144- pSector->m_pArea = new CClientRadarArea ( g_pClientGame->GetManager (), INVALID_ELEMENT_ID );
145- pSector->m_pArea->SetPosition ( pSector->m_vecBottomLeft );
146- CVector2D vecSize ( pSector->m_vecTopRight.fX - pSector->m_vecBottomLeft.fX, pSector->m_vecTopRight.fY - pSector->m_vecBottomLeft.fY );
147- pSector->m_pArea->SetSize ( vecSize );
148- pSector->m_pArea->SetColor ( 255, 0, 0, 50 );
149- }
150- pSector->m_pArea->SetColor ( 255, 0, 0, 50 );
151- }
152- }
153- */
154-
155115 bool bMovedFar = false ;
156116 // Has our position changed?
157117 if (vecPosition != m_vecPosition)
@@ -183,27 +143,62 @@ void CClientStreamer::DoPulse(CVector& vecPosition)
183143void CClientStreamer::SetDimension (unsigned short usDimension)
184144{
185145 // Different dimension than before?
186- if (usDimension != m_usDimension)
146+ if (usDimension == m_usDimension)
147+ return ;
148+
149+ // Set the new dimension
150+ m_usDimension = usDimension;
151+
152+ const CClientStreamElement* lastOutsideElement = m_outsideCurrentDimensionElements.empty () ? nullptr : m_outsideCurrentDimensionElements.back ();
153+
154+ auto filterElementInRows = [this ](list<CClientStreamSectorRow*>& list)
187155 {
188- // Set the new dimension
189- m_usDimension = usDimension;
190-
191- // That means all of the currently streamed in elements will have to
192- // go. Unstream all elements that are streamed in.
193- CClientStreamElement* pElement = NULL ;
194- list<CClientStreamElement*>::iterator iter = m_ActiveElements.begin ();
195- for (; iter != m_ActiveElements.end (); iter++)
156+ for (CClientStreamSectorRow* sectorRow : list)
196157 {
197- pElement = *iter;
198- if (pElement->IsStreamedIn ())
158+ for (CClientStreamSector* sector : sectorRow->GetList ())
199159 {
200- if (!pElement->IsVisibleInAllDimensions ())
160+ auto & elements = sector->GetElements ();
161+ auto iter = elements.begin ();
162+ while (iter != sector->End ())
201163 {
202- // Unstream it
203- m_ToStreamOut.push_back (pElement);
164+ CClientStreamElement* element = *iter;
165+
166+ if (IsElementShouldVisibleInCurrentDimesnion (element))
167+ iter++;
168+ else
169+ {
170+ iter = elements.erase (iter);
171+ m_outsideCurrentDimensionElements.push_back (element);
172+ element->SetStreamSector (nullptr );
173+
174+ if (element->IsStreamedIn ())
175+ m_ToStreamOut.push_back (element);
176+ }
204177 }
205178 }
206179 }
180+ };
181+
182+ filterElementInRows (m_WorldRows);
183+ filterElementInRows (m_ExtraRows);
184+
185+ if (!lastOutsideElement)
186+ return ;
187+
188+ auto iter = m_outsideCurrentDimensionElements.begin ();
189+
190+ while (*iter != lastOutsideElement)
191+ {
192+ CClientStreamElement* element = *iter;
193+ if (element->GetDimension () == usDimension)
194+ {
195+ iter = m_outsideCurrentDimensionElements.erase (iter);
196+ AddElementInSectors (element);
197+ }
198+ else
199+ {
200+ iter++;
201+ }
207202 }
208203}
209204
@@ -281,6 +276,9 @@ CClientStreamSectorRow* CClientStreamer::FindRow(float fY)
281276
282277void CClientStreamer::OnUpdateStreamPosition (CClientStreamElement* pElement)
283278{
279+ if (!pElement->GetStreamSector ())
280+ return ;
281+
284282 CVector vecPosition = pElement->GetStreamPosition ();
285283 CClientStreamSectorRow* pRow = pElement->GetStreamRow ();
286284 CClientStreamSector* pSector = pElement->GetStreamSector ();
@@ -305,7 +303,7 @@ void CClientStreamer::OnUpdateStreamPosition(CClientStreamElement* pElement)
305303 }
306304}
307305
308- void CClientStreamer::AddElement (CClientStreamElement* pElement)
306+ void CClientStreamer::AddElementInSectors (CClientStreamElement* pElement)
309307{
310308 assert (pAddingElement == NULL );
311309 pAddingElement = pElement;
@@ -316,13 +314,28 @@ void CClientStreamer::AddElement(CClientStreamElement* pElement)
316314 pAddingElement = NULL ;
317315}
318316
319- void CClientStreamer::RemoveElement (CClientStreamElement* pElement)
317+ void CClientStreamer::RemoveElementFromSectors (CClientStreamElement* pElement)
320318{
321- OnElementEnterSector (pElement, NULL );
322- m_ActiveElements.remove (pElement);
319+ OnElementEnterSector (pElement, nullptr );
323320 m_ToStreamOut.remove (pElement);
324321}
325322
323+ void CClientStreamer::AddElement (CClientStreamElement* pElement)
324+ {
325+ if (IsElementShouldVisibleInCurrentDimesnion (pElement))
326+ AddElementInSectors (pElement);
327+ else
328+ m_outsideCurrentDimensionElements.push_back (pElement);
329+ }
330+
331+ void CClientStreamer::RemoveElement (CClientStreamElement* pElement)
332+ {
333+ if (pElement->GetStreamSector ())
334+ RemoveElementFromSectors (pElement);
335+ else
336+ m_outsideCurrentDimensionElements.remove (pElement);
337+ }
338+
326339void CClientStreamer::SetExpDistances (list<CClientStreamElement*>* pList)
327340{
328341 // Run through our list setting distances to world center
@@ -735,16 +748,23 @@ void CClientStreamer::OnElementForceStreamOut(CClientStreamElement* pElement)
735748
736749void CClientStreamer::OnElementDimension (CClientStreamElement* pElement)
737750{
738- // Grab its new dimenson
739- unsigned short usDimension = pElement->GetDimension ();
740- // Is it streamed in?
741- if (pElement->IsStreamedIn ())
751+ if (IsElementShouldVisibleInCurrentDimesnion (pElement))
752+ {
753+ if (!pElement->GetStreamSector ())
754+ {
755+ AddElementInSectors (pElement);
756+ m_outsideCurrentDimensionElements.remove (pElement);
757+ }
758+ }
759+ else
742760 {
743- // Has it moved to a different dimension to us?
744- if (usDimension != m_usDimension)
761+ if (pElement->GetStreamSector ())
745762 {
746- // Stream it out
747- m_ToStreamOut.push_back (pElement);
763+ m_outsideCurrentDimensionElements.push_back (pElement);
764+ RemoveElementFromSectors (pElement);
765+
766+ if (pElement->IsStreamedIn ())
767+ m_ToStreamOut.push_back (pElement);
748768 }
749769 }
750770}
0 commit comments