OpenBarnyard
 
Loading...
Searching...
No Matches
ATerrainLocator.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "ATerrainLocator.h"
4
5//-----------------------------------------------------------------------------
6// Enables memory debugging.
7// Note: Should be the last include!
8//-----------------------------------------------------------------------------
10
12
13// $Barnyard: FUNCTION 005ec800
15 : m_pTRB( TNULL )
16 , m_pLocatorsHeader( TNULL )
17 , m_pLocatorVISHeader( TNULL )
18 , m_bCreatedGrowings( TFALSE )
19{
20 m_oWorldTransform.SetMatrix( TMatrix44{
21 1.0f,
22 0.0f,
23 0.0f,
24 0.0f,
25 0.0f,
26 0.0f,
27 1.0f,
28 0.0f,
29 0.0f,
30 -1.0f,
31 0.0f,
32 0.0f,
33 0.0f,
34 0.0f,
35 0.0f,
36 1.0f,
37 } );
38}
39
43
44// $Barnyard: FUNCTION 005ec8b0
46{
47 TVALIDPTR( m_pLocatorsHeader );
48
49 if ( m_pLocatorVISHeader == TNULL )
50 // No VIS data is provided, look for all the locators
51 {
52 for ( TINT i = 0; i < m_pLocatorsHeader->iNumLocators; i++ )
53 {
54 ATerrainLocator* pLocator = &m_pLocatorsHeader->pLocators[ i ];
55
56 if ( !TStringManager::String8Compare( m_pLocatorsHeader->ppNames[ pLocator->uiNameId ], a_pszLocatorName ) )
57 return &m_pLocatorsHeader->pLocators[ i ];
58 }
59 }
60 else
61 // We have VIS data, so it's easier to find the locator using binary search
62 {
63 for ( TINT i = 0; i < m_pLocatorVISHeader->iNumSections; i++ )
64 {
65 ATerrainLocatorVISSection* pSection = &m_pLocatorVISHeader->pSections[ i ];
66
67 // Do binary search
68 TUINT uiBase = pSection->uiFirstLocator;
69 TUINT uiEnd = uiBase + pSection->uiNumLocators;
70 TUINT uiCurrent = ( ( uiEnd - uiBase ) / 2 ) + uiBase;
71
72 while ( uiBase <= uiCurrent && uiCurrent < uiEnd )
73 {
74 ATerrainLocator* pLocator = &m_pLocatorsHeader->pLocators[ uiCurrent ];
75 TINT iCmpRes = TStringManager::String8Compare( m_pLocatorsHeader->ppNames[ pLocator->uiNameId ], a_pszLocatorName );
76
77 if ( iCmpRes == 0 ) return pLocator;
78
79 if ( iCmpRes < 1 )
80 // Check the right side of array
81 {
82 uiBase = uiCurrent + 1;
83 uiCurrent = ( ( uiEnd - uiBase ) / 2 ) + uiBase;
84 }
85 else
86 // Check the left side of array
87 {
88 uiEnd = uiCurrent;
89 uiCurrent = ( ( uiCurrent - uiBase ) / 2 ) + uiBase;
90 }
91 }
92 }
93 }
94
95 return TNULL;
96}
97
98// $Barnyard: FUNCTION 005ecad0
100{
101 m_pTRB = a_pTRB;
102 m_pLocatorsHeader = a_pTRB->CastSymbol<ATerrainLocatorTRBHeader>( "Locators" );
103 m_pLocatorVISHeader = a_pTRB->CastSymbol<ATerrainLocatorVISTRBHeader>( "LocatorVIS" );
104
105 TASSERT( m_pLocatorsHeader && m_pLocatorVISHeader );
106
107 ATreeManager::GetSingleton()->CreateInstances( this );
108 TTODO( "Create regrowths, instances and other things from locators" );
109}
110
111// $Barnyard: FUNCTION 005ec9f0
112void ATerrainLocator::GetMatrix( Toshi::TMatrix44& a_rOutMatrix )
113{
114 a_rOutMatrix.SetFromQuaternion( quatRotation );
115 a_rOutMatrix.AsBasisVector3( BASISVECTOR_TRANSLATION ) = vecPosition;
116}
@ BASISVECTOR_TRANSLATION
Definition TMatrix44.h:28
#define TASSERT(X,...)
Definition Defines.h:138
#define TOSHI_NAMESPACE_USING
Definition Defines.h:46
#define TTODO(DESC)
Definition Defines.h:134
#define TVALIDPTR(PTR)
Definition Defines.h:139
unsigned int TUINT
Definition Typedefs.h:8
char TCHAR
Definition Typedefs.h:20
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
#define TFALSE
Definition Typedefs.h:24
Definition TTRB.h:253
T * CastSymbol(const TCHAR *symbName)
Definition TTRB.h:334
static TINT String8Compare(const TCHAR *str1, const TCHAR *str2, TSIZE size=-1)
Toshi::TQuaternion quatRotation
void GetMatrix(Toshi::TMatrix44 &a_rOutMatrix)
Toshi::TVector3 vecPosition
ATerrainLocator * FindLocator(const TCHAR *a_pszLocatorName)
void LoadFromTRB(Toshi::TTRB *a_pTRB)