OpenBarnyard
 
Loading...
Searching...
No Matches
PTRBSections Class Reference

#include <PTRB.h>

Classes

class  MemoryStream
 

Public Member Functions

 PTRBSections (Endianess a_eEndianess=Endianess_Little)
 
 ~PTRBSections ()
 
void Reset ()
 
TUINT GetStackCount () const
 
TBOOL SetEndianess (Endianess a_eEndianess)
 
PTRBSections::MemoryStreamCreateStream ()
 
PTRBSections::MemoryStreamCreateStream (const PTRBSections::MemoryStream *pStream)
 
TBOOL DeleteStack (PTRBSymbols *pSymb, PTRBSections::MemoryStream *pStream)
 
PTRBSections::MemoryStreamGetStack (TUINT index)
 
void Write (Toshi::TTSFO &ttsfo, TBOOL compress)
 
void Read (Toshi::TTSFI &ttsfi, TBOOL compressed=false, Endianess eEndianess=Endianess_Little)
 
std::vector< PTRBSections::MemoryStream * >::iterator begin ()
 
std::vector< PTRBSections::MemoryStream * >::iterator end ()
 

Detailed Description

Definition at line 53 of file PTRB.h.

Constructor & Destructor Documentation

◆ PTRBSections()

PTRBSections::PTRBSections ( Endianess a_eEndianess = Endianess_Little)
inline

Definition at line 286 of file PTRB.h.

287 : m_eEndianess( a_eEndianess )
288 {}

◆ ~PTRBSections()

PTRBSections::~PTRBSections ( )
inline

Definition at line 290 of file PTRB.h.

291 {
292 Reset();
293 }
void Reset()
Definition PTRB.h:295

Member Function Documentation

◆ begin()

std::vector< PTRBSections::MemoryStream * >::iterator PTRBSections::begin ( )
inline

Definition at line 329 of file PTRB.h.

329{ return m_Stacks.begin(); }

◆ CreateStream() [1/2]

PTRBSections::MemoryStream * PTRBSections::CreateStream ( )
inline

Definition at line 1010 of file PTRB.h.

1011{
1012 PTRBSections::MemoryStream* stack = new PTRBSections::MemoryStream( m_Stacks.size(), m_eEndianess );
1013 m_Stacks.push_back( stack );
1014 return stack;
1015}

◆ CreateStream() [2/2]

PTRBSections::MemoryStream * PTRBSections::CreateStream ( const PTRBSections::MemoryStream * pStream)
inline

Definition at line 1017 of file PTRB.h.

1018{
1019 PTRBSections::MemoryStream* stack = new PTRBSections::MemoryStream( *pStream );
1020 stack->SetIndex( m_Stacks.size() );
1021 m_Stacks.push_back( stack );
1022 return stack;
1023}
TUINT32 SetIndex(TUINT32 index)
Definition PTRB.h:192

◆ DeleteStack()

TBOOL PTRBSections::DeleteStack ( PTRBSymbols * pSymb,
PTRBSections::MemoryStream * pStream )
inline

Definition at line 1025 of file PTRB.h.

1026{
1027 auto result = std::find( m_Stacks.begin(), m_Stacks.end(), pStream );
1028
1029 if ( result != m_Stacks.end() )
1030 {
1031 pSymb->RemoveAllWithStackIndex( pStream->GetIndex() );
1032
1033 m_Stacks.erase( result );
1034 delete pStream;
1035
1036 // Update indexes
1037 TUINT32 index = 0;
1038 for ( auto it = m_Stacks.begin(); it != m_Stacks.end(); it++ )
1039 {
1040 auto stack = *it;
1041 pSymb->UpdateSymbolsIndexes( stack, index++ );
1042 }
1043
1044 return TTRUE;
1045 }
1046 else
1047 {
1048 return TFALSE;
1049 }
1050}
uint32_t TUINT32
Definition Typedefs.h:13
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
TUINT32 GetIndex() const
Definition PTRB.h:203
void UpdateSymbolsIndexes(PTRBSections::MemoryStream *pStream, TUINT32 newIndex)
Definition PTRB.h:486
void RemoveAllWithStackIndex(TINT stackIndex)
Definition PTRB.h:509

◆ end()

std::vector< PTRBSections::MemoryStream * >::iterator PTRBSections::end ( )
inline

Definition at line 330 of file PTRB.h.

330{ return m_Stacks.end(); }

◆ GetStack()

PTRBSections::MemoryStream * PTRBSections::GetStack ( TUINT index)
inline

Definition at line 1052 of file PTRB.h.

1053{
1054 TASSERT( index >= 0 && index < GetStackCount(), "Index is out of bounds" );
1055 return m_Stacks[ index ];
1056}
#define TASSERT(X,...)
Definition Defines.h:138
TUINT GetStackCount() const
Definition PTRB.h:304

◆ GetStackCount()

TUINT PTRBSections::GetStackCount ( ) const
inline

Definition at line 304 of file PTRB.h.

305 {
306 return m_Stacks.size();
307 }

◆ Read()

void PTRBSections::Read ( Toshi::TTSFI & ttsfi,
TBOOL compressed = false,
Endianess eEndianess = Endianess_Little )
inline

Definition at line 1103 of file PTRB.h.

1104{
1105 m_eEndianess = eEndianess;
1106
1107 for ( auto stack : m_Stacks )
1108 {
1109 TUINT expectedSize = stack->GetExpectedSize();
1110
1111 if ( expectedSize > 0 )
1112 {
1113 stack->GrowBuffer( expectedSize );
1114
1115 if ( compressed )
1116 {
1117 Toshi::TCompress::ms_bIsBigEndian = ( eEndianess == Endianess_Big );
1118 ttsfi.ReadCompressed( stack->GetBuffer(), expectedSize );
1119 }
1120 else
1121 {
1122 ttsfi.ReadRaw( stack->GetBuffer(), expectedSize );
1123 }
1124
1125 stack->Seek( expectedSize );
1126 stack->SetExpectedSize( 0 );
1127 }
1128 }
1129}
@ Endianess_Big
Definition Endianness.h:9
unsigned int TUINT
Definition Typedefs.h:8

◆ Reset()

void PTRBSections::Reset ( )
inline

Definition at line 295 of file PTRB.h.

296 {
297 for ( auto stack : m_Stacks )
298 delete stack;
299
300 m_Stacks.clear();
301 m_eEndianess = Endianess_Little;
302 }
@ Endianess_Little
Definition Endianness.h:8

◆ SetEndianess()

TBOOL PTRBSections::SetEndianess ( Endianess a_eEndianess)
inline

Definition at line 309 of file PTRB.h.

310 {
311 if ( m_Stacks.size() == 0 )
312 {
313 m_eEndianess = a_eEndianess;
314 return TTRUE;
315 }
316
317 return TFALSE;
318 }

◆ Write()

void PTRBSections::Write ( Toshi::TTSFO & ttsfo,
TBOOL compress )
inline

Definition at line 1058 of file PTRB.h.

1059{
1060 TUINT ready = 0;
1061 TUINT count = m_Stacks.size();
1062
1063 if ( compress )
1064 {
1065 if ( count > 1 )
1066 {
1067 TTRACE( "Compressing progress: 0%\n" );
1068 }
1069 else
1070 {
1071 TTRACE( "Started BTEC compression...\n" );
1072 }
1073 }
1074
1075 for ( auto stack : m_Stacks )
1076 {
1077 stack->Unlink();
1078
1079 if ( compress )
1080 {
1081 ttsfo.WriteCompressed( stack->GetBuffer(), stack->GetUsedSize() );
1082 ready += 1;
1083
1084 if ( count > 1 )
1085 {
1086 TTRACE( "Compressing progress: %.1f\n", (double)ready / count * 100 );
1087 }
1088 else
1089 {
1090 TTRACE( "BTEC compression completed...\n" );
1091 }
1092 }
1093 else
1094 {
1095 ttsfo.WriteRaw( stack->GetBuffer(), stack->GetUsedSize() );
1096 }
1097
1098 ttsfo.WriteAlignmentPad();
1099 stack->Link();
1100 }
1101}
#define TTRACE(...)
Definition Defines.h:155

The documentation for this class was generated from the following file: