OpenBarnyard
 
Loading...
Searching...
No Matches
ATerrainInterface.h
Go to the documentation of this file.
1#pragma once
2#include "ATerrainVIS.h"
9
10class ATerrainInterface : public Toshi::TSingleton<ATerrainInterface>
11{
12public:
13 constexpr static TUINT MAX_NUM_MODEL_LOADER_JOBS = 128;
14 constexpr static TUINT MAX_NUM_MATLIB_LOADER_JOBS = 10;
15 constexpr static TUINT MAX_NUM_KEYLIB_LOADER_JOBS = 10;
16 constexpr static TUINT MAX_NUM_SECTION_LOADER_JOBS = 32;
17 constexpr static TUINT MAX_NUM_TRB_LOADER_JOBS = 2;
18 constexpr static TUINT MAX_NUM_SKELETON_LOADER_JOBS = 2;
19 constexpr static TUINT MAX_NUM_COLLISION_LOADER_JOBS = 64;
20 constexpr static TUINT NUM_TOTAL_JOBS =
28
29 using JobSlot = Toshi::T2SListNodeWrapper<AMainThreadJob>;
30
33
34 using t_GetCurrentVISGroup = TINT ( * )();
35 using t_OnVISGroupChanged = void ( * )( ATerrainSection* a_pCurrent, ATerrainSection* a_pPrevious );
36 using t_OnModelNodeReady = void ( * )( ATerrainSection::ModelNode* a_pModelNode );
37
38public:
39 ATerrainInterface( TINT a_iUnused1, TINT a_iUnused2, TINT a_iPreloadTerrainBlockSize, TINT a_iStartVISGroup );
40 virtual ~ATerrainInterface();
41
42 // Updates the current state of terrain including loading
43 void Update();
44
45 // Renders current section
46 void Render();
47
48 // Return TTRUE if no any assets are in loading at the current moment
49 TBOOL IsLoaded() const;
50
57 void LoadFromFile( const TCHAR* a_szFilePath, TBOOL a_bLoadLater, TBOOL a_bStreamCollision );
58
59 /* Blocks the thread until terrain is completely loaded. */
60 void WaitUntilLoaded();
61
62 /* Destroys terrain model */
63 void DestroyModelData( ATerrainSection::ModelNode* a_pModelData );
64
69 void UpdateUsedBlocks( ATerrainLODType a_eLODType );
70
71 /* Queues needed LODs to be loaded based on the current section. */
73
74 /* Cancels streaming of LODs in the current section. */
76
81
82 /* Cancels jobs that are not needed anymore (can happen after moving to other section). */
84
85 // Creates a model and setups rendering methods for it
86 ATerrainSection::ModelNode* CreateModelInstance( ATerrainSection::ModelNode* a_pModelNode, const char* a_szModelName, const char* a_szType );
87
95
99 TBOOL IsCollisionStreamed() const { return m_bStreamCollision; }
100
104 ATerrainVIS* GetVIS() const { return m_pTerrainVIS; }
105
109 void GetLocatorTransform( const TCHAR* a_pszLocatorName, Toshi::TMatrix44& a_rOutTransform );
110
114 Toshi::TVector4 GetLocatorPos( const TCHAR* a_pszLocatorName );
115
119 void GetLocatorPosAndRot( const TCHAR* a_pszLocatorName, Toshi::TVector4& a_rOutPosition, Toshi::TQuaternion& a_rOutRotation );
120
124 ATerrainLocator* FindLocator( const TCHAR* a_pszLocatorName );
125
132
134 {
135 TVALIDPTR( m_pTerrainVIS );
136 return m_pTerrainVIS->GetLocatorList();
137 }
138
139 const Toshi::TVector4& GetDefaultShadowColor() const { return m_DefaultShadowColor; }
140 const Toshi::TVector4& GetDefaultAmbientColor() const { return m_DefaultAmbientColor; }
141 const Toshi::TVector4& GetLitShadowColor() const { return m_LitShadowColor; }
142 const Toshi::TVector4& GetLitAmbientColor() const { return m_LitAmbientColor; }
143
144 t_OnModelNodeReady GetOnModelNodeReadyCallback() const { return m_cbOnModelLoaded; }
145
146private:
147 void UpdateNightMaterials();
148 void MoveAllFinishedJobs( Toshi::T2SList<JobSlot>& a_rFreeJobs, Toshi::T2SList<JobSlot>& a_rUsedJobs );
149
150 /* Moves all finished jobs from used lists to free lists */
151 void FlushJobs();
152
153private:
154 static TINT GetCurrentSectionID();
155 static TINT GetPersistantSectionID();
156
157 inline static TINT ms_iPersistantVISGroupIndex = -1;
158 inline static TBOOL ms_bAutoVIS = TFALSE;
159
160private:
161 Toshi::TVector4 m_LitShadowColor;
162 Toshi::TVector4 m_LitAmbientColor;
163 Toshi::TVector4 m_DefaultShadowColor;
164 Toshi::TVector4 m_DefaultAmbientColor;
165 TFLOAT m_fUnused3;
166 TBOOL m_bUnused4;
167 Toshi::T2SList<ATerrainSection::ModelNode> m_llModelNodes;
168 t_OnModelNodeReady m_cbOnCollsionModelLoaded;
169 t_OnModelNodeReady m_cbOnModelLoaded;
170 t_OnVISGroupChanged m_cbOnVISGroupChanged;
171 AModelLoaderJob m_aModelLoaderJobs[ MAX_NUM_MODEL_LOADER_JOBS ];
172 AMatLibLoaderJob m_aMatlibLoaderJobs[ MAX_NUM_MATLIB_LOADER_JOBS ];
173 AKeyLibLoaderJob m_aKeylibLoaderJobs[ MAX_NUM_KEYLIB_LOADER_JOBS ];
174 ASectionDoneJob m_aSectionDoneJobs[ MAX_NUM_SECTION_LOADER_JOBS ];
175 ATRBLoaderJob m_aTRBLoaderJobs[ MAX_NUM_TRB_LOADER_JOBS ];
176 ASkeletonDoneJob m_aSkeletonDoneJobs[ MAX_NUM_SKELETON_LOADER_JOBS ];
177 ACollisionDoneJob m_aCollisionDoneJobs[ MAX_NUM_COLLISION_LOADER_JOBS ];
178 JobSlot* m_pJobs;
179 Toshi::T2SList<JobSlot> m_UsedModelLoaderJobs;
180 Toshi::T2SList<JobSlot> m_FreeModelLoaderJobs;
181 Toshi::T2SList<JobSlot> m_UsedUnknownLoaderJobs;
182 Toshi::T2SList<JobSlot> m_FreeUnknownLoaderJobs;
183 Toshi::T2SList<JobSlot> m_UsedSectionLoaderJobs;
184 Toshi::T2SList<JobSlot> m_FreeSectionLoaderJobs;
185 Toshi::T2SList<JobSlot> m_UsedKeylibLoaderJobs;
186 Toshi::T2SList<JobSlot> m_FreeKeylibLoaderJobs;
187 Toshi::T2SList<JobSlot> m_UsedMatlibLoaderJobs;
188 Toshi::T2SList<JobSlot> m_FreeMatlibLoaderJobs;
189 Toshi::T2SList<JobSlot> m_UsedTRBLoaderJobs;
190 Toshi::T2SList<JobSlot> m_FreeTRBLoaderJobs;
191 Toshi::T2SList<JobSlot> m_UsedSkeletonLoaderJobs;
192 Toshi::T2SList<JobSlot> m_FreeSkeletonLoaderJobs;
193 Toshi::T2SList<JobSlot> m_UsedCollisionLoaderJobs;
194 Toshi::T2SList<JobSlot> m_FreeCollisionLoaderJobs;
195 TBOOL m_bStreamCollision;
196 TBOOL m_bIsLoaded;
197 Toshi::TTRB m_VISTRB;
198 Toshi::TTRB m_TRB2;
199 ATerrainVIS* m_pTerrainVIS;
200 ATerrainOrderDVIS* m_pOrderDVIS;
201 // ...
202 TINT m_iCurrentSection;
203 TINT m_iPreviousSection;
204 TINT m_iPreloadTerrainBlockSize;
205 t_GetCurrentVISGroup m_fnGetCurrentVISGroup;
206 // ...
207 TINT m_iNumChunks;
208};
#define TVALIDPTR(PTR)
Definition Defines.h:139
unsigned int TUINT
Definition Typedefs.h:8
char TCHAR
Definition Typedefs.h:20
float TFLOAT
Definition Typedefs.h:4
int TINT
Definition Typedefs.h:7
#define TFALSE
Definition Typedefs.h:24
bool TBOOL
Definition Typedefs.h:6
TINT8 ATerrainLODType
ASectionDoneJob * GetFreeSectionLoaderJob()
static constexpr TUINT MAX_NUM_SECTION_LOADER_JOBS
AMatLibLoaderJob * GetFreeMatlibLoaderJob()
friend class ABYardTerrainManager
ATerrainLocator * FindLocator(const TCHAR *a_pszLocatorName)
Finds a locator (bone) by the specified name and returns it if found.
void UpdateUsedBlocks(ATerrainLODType a_eLODType)
Sets visible blocks of specified LOD type to be used.
ATerrainVIS * GetVIS() const
const Toshi::TVector4 & GetDefaultAmbientColor() const
void LoadFromFile(const TCHAR *a_szFilePath, TBOOL a_bLoadLater, TBOOL a_bStreamCollision)
Loads information about terrain.
TINT(*)() t_GetCurrentVISGroup
Toshi::TVector4 GetLocatorPos(const TCHAR *a_pszLocatorName)
Finds a locator (bone) by the specified name and obtains it current position if found.
static constexpr TUINT MAX_NUM_TRB_LOADER_JOBS
const Toshi::TVector4 & GetLitShadowColor() const
ASkeletonDoneJob * GetFreeSkeletonLoaderJob()
void DestroyModelData(ATerrainSection::ModelNode *a_pModelData)
void GetLocatorTransform(const TCHAR *a_pszLocatorName, Toshi::TMatrix44 &a_rOutTransform)
Finds a locator (bone) by the specified name and obtains it current transform if found.
static constexpr TUINT MAX_NUM_MATLIB_LOADER_JOBS
const Toshi::TVector4 & GetLitAmbientColor() const
void(*)(ATerrainSection *a_pCurrent, ATerrainSection *a_pPrevious) t_OnVISGroupChanged
TBOOL IsCollisionStreamed() const
ACollisionDoneJob * GetFreeCollisionLoaderJob()
ATerrainSection::ModelNode * CreateModelInstance(ATerrainSection::ModelNode *a_pModelNode, const char *a_szModelName, const char *a_szType)
static constexpr TUINT MAX_NUM_MODEL_LOADER_JOBS
ATerrainLocatorList * GetLocatorList() const
ATerrainLODBlock * AllocateLODBlock(ATerrainLODType a_eLODType, ATerrainSection *a_pVISGroup)
Allocates free LODBlock of specified type and assigns it to the section.
static constexpr TUINT MAX_NUM_SKELETON_LOADER_JOBS
static constexpr TUINT NUM_TOTAL_JOBS
ATerrainInterface(TINT a_iUnused1, TINT a_iUnused2, TINT a_iPreloadTerrainBlockSize, TINT a_iStartVISGroup)
const Toshi::TVector4 & GetDefaultShadowColor() const
static constexpr TUINT MAX_NUM_COLLISION_LOADER_JOBS
void GetLocatorPosAndRot(const TCHAR *a_pszLocatorName, Toshi::TVector4 &a_rOutPosition, Toshi::TQuaternion &a_rOutRotation)
Finds a locator (bone) by the specified name and obtains it current position and rotation if found.
AModelLoaderJob * GetFreeModelLoaderJob()
static constexpr TUINT MAX_NUM_KEYLIB_LOADER_JOBS
void(*)(ATerrainSection::ModelNode *a_pModelNode) t_OnModelNodeReady
t_OnModelNodeReady GetOnModelNodeReadyCallback() const
Toshi::T2SListNodeWrapper< AMainThreadJob > JobSlot
ATRBLoaderJob * GetFreeTRBLoaderJob()