@@ -139,9 +139,7 @@ void ATerrainInterface::Update()
139139 TINT iCurrentGroup = m_fnGetCurrentVISGroup ();
140140
141141 if ( iCurrentGroup != -1 )
142- {
143142 m_iCurrentSection = iCurrentGroup;
144- }
145143 }
146144
147145 if ( m_iCurrentSection >= 0 )
@@ -223,7 +221,8 @@ void ATerrainInterface::Update()
223221 pGroups[ i ].LoadModels ( ATerrainLODType_High );
224222 break ;
225223 }
226- else if ( pGroups[ i ].IsLODQueued ( ATerrainLODType_Low ) )
224+
225+ if ( pGroups[ i ].IsLODQueued ( ATerrainLODType_Low ) )
227226 {
228227 pGroups[ i ].LoadModels ( ATerrainLODType_Low );
229228 break ;
@@ -308,32 +307,67 @@ void ATerrainInterface::Render()
308307 m_fUnused3 = 1 .0f ;
309308 m_bUnused4 = TTRUE;
310309
311- auto pTerrainVIS = m_pTerrainVIS;
312-
313- if ( TNULL != pTerrainVIS )
310+ if ( m_pTerrainVIS )
314311 {
315312 // Reset current section if it is out of range
316- if ( pTerrainVIS->m_iNumSections <= m_iCurrentSection || m_iCurrentSection < 0 )
317- {
313+ if ( m_pTerrainVIS->m_iNumSections <= m_iCurrentSection || m_iCurrentSection < 0 )
318314 m_iCurrentSection = 0 ;
319- }
320315
321- auto pSections = pTerrainVIS ->m_pSections ;
316+ auto pSections = m_pTerrainVIS ->m_pSections ;
322317 auto iCurrentSection = m_iCurrentSection;
323318 auto pCurrentSection = &pSections[ iCurrentSection ];
324319
325- if ( TNULL == m_pOrderDVIS )
320+ if ( ! m_pOrderDVIS )
326321 {
327- pCurrentSection->Draw ( ATerrainLODType_High );
322+ if ( pCurrentSection->IsLODLoaded ( ATerrainLODType_High ) )
323+ {
324+ // Draw models of the high LOD
325+ for ( TINT i = 0 ; i < pCurrentSection->m_iNumHighModelFiles ; i++ )
326+ {
327+ pCurrentSection->m_ppLODModelsData [ ATerrainLODType_High ][ i ]->Render ();
328+ }
329+ }
330+ else if ( pCurrentSection->IsLODLoaded ( ATerrainLODType_Low ) )
331+ {
332+ // High LOD is still loading so let's render low LOD instead
333+ for ( TINT i = 0 ; i < pCurrentSection->m_iNumLowModelFiles ; i++ )
334+ {
335+ pCurrentSection->m_ppLODModelsData [ ATerrainLODType_Low ][ i ]->Render ();
336+ }
337+ }
328338 }
329339
330340 for ( TINT i = 0 ; i < m_pTerrainVIS->m_iNumSections ; i++ )
331341 {
332- ATerrainLODType eSectionVisibility = pCurrentSection-> m_pVisibility [ i ];
342+ ATerrainLODType eSectionVisibility = pSections[ iCurrentSection ]. m_pVisibility [ i ];
333343
334344 if ( eSectionVisibility != ATerrainLODType_None )
335345 {
336- pSections[ i ].Draw ( eSectionVisibility );
346+ TINT iTargetNumModels = ( eSectionVisibility == ATerrainLODType_High ) ? pSections[ i ].m_iNumHighModelFiles : pSections[ i ].m_iNumLowModelFiles ;
347+
348+ if ( !pSections[ i ].IsLODLoaded ( eSectionVisibility ) ||
349+ !pSections[ i ].IsLODEmpty ( eSectionVisibility ) ||
350+ iTargetNumModels < 1 )
351+ {
352+ if ( pSections[ i ].IsLODLoaded ( ATerrainLODType_Low ) )
353+ {
354+ // Target LOD is still loading, so let's see if we can render low LOD instead
355+ for ( TINT k = 0 ; k < pSections[ i ].m_iNumLowModelFiles ; k++ )
356+ {
357+ if ( !pSections[ i ].m_ppLODModelsData [ ATerrainLODType_Low ][ k ]->IsGlow () )
358+ pSections[ i ].m_ppLODModelsData [ ATerrainLODType_Low ][ k ]->Render ();
359+ }
360+ }
361+ }
362+ else
363+ {
364+ // Draw models of the target LOD, since it is loaded
365+ for ( TINT k = 0 ; k < iTargetNumModels; k++ )
366+ {
367+ if ( !pSections[ i ].m_ppLODModelsData [ eSectionVisibility ][ k ]->IsGlow () )
368+ pSections[ i ].m_ppLODModelsData [ eSectionVisibility ][ k ]->Render ();
369+ }
370+ }
337371 }
338372 }
339373 }
@@ -635,81 +669,85 @@ ATerrainLODBlock* ATerrainInterface::AllocateLODBlock( ATerrainLODType a_eLODTyp
635669 ppBlocks = m_pTerrainVIS->m_ppLowBlocks ;
636670 }
637671
638- TFLOAT fMinAccessTime = TMath::MAXFLOAT;
639- TINT iPrevFoundIndex = -1 ;
640- TINT iFoundIndex;
641-
642- for ( TINT i = 0 ; i < iNumBlocks; i++ )
672+ if ( iNumBlocks > 0 )
643673 {
644- auto pBlock = ppBlocks[ i ];
645- iFoundIndex = iPrevFoundIndex;
674+ TFLOAT fMinAccessTime = TMath::MAXFLOAT;
675+ TINT iPrevFoundIndex = -1 ;
676+ TINT iFoundIndex = -1 ;
646677
647- if ( !pBlock-> IsUsed () )
678+ for ( TINT i = 0 ; i < iNumBlocks; i++ )
648679 {
649- iFoundIndex = i;
650- if ( pBlock->m_pVISGroup == TNULL ) break ;
651-
680+ auto pBlock = ppBlocks[ i ];
652681 iFoundIndex = iPrevFoundIndex;
653- if ( !pBlock->m_pVISGroup ->IsLODLoading ( a_eLODType ) )
682+
683+ if ( !pBlock->IsUsed () )
654684 {
655685 iFoundIndex = i;
656- if ( pBlock->m_pVISGroup = TNULL ) break ;
686+ if ( pBlock->m_pVISGroup == TNULL ) break ;
657687
658688 iFoundIndex = iPrevFoundIndex;
659- if ( pBlock->m_fLastAccessTime < fMinAccessTime )
689+ if ( ! pBlock->m_pVISGroup -> IsLODLoading ( a_eLODType ) )
660690 {
661- fMinAccessTime = pBlock->m_fLastAccessTime ;
662- iFoundIndex = i;
691+ iFoundIndex = i;
692+ if ( pBlock->m_pVISGroup == TNULL ) break ;
693+
694+ iFoundIndex = iPrevFoundIndex;
695+ if ( pBlock->m_fLastAccessTime < fMinAccessTime )
696+ {
697+ fMinAccessTime = pBlock->m_fLastAccessTime ;
698+ iFoundIndex = i;
699+ }
663700 }
664701 }
665- }
666702
667- iPrevFoundIndex = iFoundIndex;
668- }
669-
670- if ( iFoundIndex >= 0 )
671- {
672- auto pBlock = ppBlocks[ iFoundIndex ];
673- auto pVISGroup = pBlock->m_pVISGroup ;
703+ iPrevFoundIndex = iFoundIndex;
704+ }
674705
675- if ( pVISGroup )
706+ if ( iFoundIndex >= 0 )
676707 {
677- if ( pVISGroup->IsLODEmpty ( pBlock->m_eLODType ) )
678- {
679- pVISGroup->SetLODEmpty ( pBlock->m_eLODType , TFALSE );
680- return TNULL;
681- }
708+ auto pBlock = ppBlocks[ iFoundIndex ];
709+ auto pVISGroup = pBlock->m_pVISGroup ;
682710
683711 if ( pVISGroup )
684712 {
685- if ( ( pVISGroup->m_eFlags & ( 21 << a_eLODType ) ) != 0 )
713+ if ( pVISGroup->IsLODEmpty ( pBlock->m_eLODType ) )
714+ {
715+ pVISGroup->SetLODEmpty ( pBlock->m_eLODType , TFALSE );
716+ return TNULL;
717+ }
718+
719+ if ( pVISGroup )
686720 {
687- if ( pVISGroup->IsMatLibLoaded ( pBlock-> m_eLODType ) )
721+ if ( ( pVISGroup->m_eFlags & ( 21 << a_eLODType ) ) != 0 )
688722 {
689- pVISGroup->SetLODEmpty ( pBlock->m_eLODType , TFALSE );
723+ if ( pVISGroup->IsMatLibLoaded ( pBlock->m_eLODType ) )
724+ {
725+ pVISGroup->SetLODEmpty ( pBlock->m_eLODType , TFALSE );
690726
691- if ( pBlock->m_pVISGroup )
727+ if ( pBlock->m_pVISGroup )
728+ {
729+ pBlock->m_pVISGroup ->UnloadMatlib ( pBlock->m_eLODType );
730+ return TNULL;
731+ }
732+ }
733+ else if ( pBlock->m_pVISGroup )
692734 {
693- pBlock->m_pVISGroup ->UnloadMatlib ( pBlock->m_eLODType );
735+ pBlock->m_pVISGroup ->DestroyLOD ( pBlock->m_eLODType );
694736 }
737+
738+ return TNULL;
695739 }
696- else if ( pBlock->m_pVISGroup )
740+
741+ if ( pVISGroup )
697742 {
698- pBlock-> m_pVISGroup ->DestroyLOD ( pBlock->m_eLODType );
743+ pVISGroup ->DestroyLOD ( pBlock->m_eLODType );
699744 }
700-
701- return TNULL;
702- }
703-
704- if ( pVISGroup )
705- {
706- pVISGroup->DestroyLOD ( pBlock->m_eLODType );
707745 }
708746 }
709- }
710747
711- pBlock->Assign ( a_pVISGroup, a_eLODType );
712- return pBlock;
748+ pBlock->Assign ( a_pVISGroup, a_eLODType );
749+ return pBlock;
750+ }
713751 }
714752
715753 return TNULL;
@@ -1135,7 +1173,7 @@ void ATerrainInterface::CancelUnrequiredJobs()
11351173 if ( pGroup->m_eFlags & ( ATerrainSection::FLAGS_HIGH_LOD_LOADING | ATerrainSection::FLAGS_LOW_LOD_LOADING ) )
11361174 {
11371175 if ( i < 0 ) return ;
1138- if ( pGroup-> m_pVisibility [ i ] == ( ( pGroup->m_eFlags >> 2 ) - 1 ) % ATerrainLODType_NUMOF ) return ;
1176+ if ( m_pTerrainVIS-> m_pSections [ m_iCurrentSection ]. m_pVisibility [ i ] == ( ( pGroup->m_eFlags >> 2 ) - 1 ) % ATerrainLODType_NUMOF ) return ;
11391177 if ( i == m_iCurrentSection ) return ;
11401178
11411179 AAssetStreaming::GetSingleton ()->CancelAllJobs ();
0 commit comments