OpenBarnyard
 
Loading...
Searching...
No Matches
T2Locale.cpp
Go to the documentation of this file.
1#include "ToshiPCH.h"
2#include "T2Locale.h"
3
4//-----------------------------------------------------------------------------
5// Enables memory debugging.
6// Note: Should be the last include!
7//-----------------------------------------------------------------------------
9
11
12T2Locale::T2Locale( TINT langCount, TSIZE bufferSize, void* buffer )
13{
14 // 00662d40
15 m_pBuffer = buffer;
16 m_BufferPos = buffer;
18 m_LangId = -1;
20
21 if ( m_pBuffer == TNULL )
22 {
23 TSIZE symbolTableSize = TTRB::GetSymbolTableSize( 1 );
24 TSIZE headerSize = TTRB::GetHeaderSize( 1 );
25 m_pBuffer = TMalloc( headerSize + bufferSize + symbolTableSize );
28 }
29
30 m_Locale.SetMemoryFunctions( TRBAllocator, TRBDeallocator, this );
31}
32
34{
35 m_Locale.Close();
36
37 if ( m_bOwnsBuffer )
38 {
40 }
41}
42
43void* T2Locale::TRBAllocator( TTRB::AllocType alloctype, TSIZE size, short unk, TSIZE unk2, void* userData )
44{
45 return TSTATICCAST( T2Locale, userData )->TRBAlloc( size );
46}
47
48void T2Locale::TRBDeallocator( TTRB::AllocType alloctype, void* ptr, short unk, TSIZE unk2, void* userData )
49{
50 // T2Locale doesn't have deallocator
51}
52
54{
55 // 00662e30
56 if ( langid != m_LangId && ( m_Locale.Close(), -1 < langid ) )
57 {
58 m_Locale.Load( GetLanguageFilename( langid ) );
59 m_StringTable = m_Locale.CastSymbol<LocaleStrings>( "LocaleStrings" );
60
62 m_LangId = langid;
63 }
64}
65
66Toshi::T2Locale::Lang T2Locale::GetLanguage() const
67{
68 return m_LangId;
69}
70
72{
73 return m_StringTable->m_numstrings;
74}
75
77{
78 TASSERT( a_iNumString >= 0 && a_iNumString < GetNumStrings() );
79 return m_StringTable->Strings[ a_iNumString ];
80}
81
void * TMalloc(TSIZE a_uiSize, Toshi::TMemory::MemBlock *a_pMemBlock, const TCHAR *a_szFileName, TINT a_iLineNum)
Allocates memory from a specific memory block.
Definition TMemory.cpp:973
void TFree(void *a_pMem)
Frees previously allocated memory.
Definition TMemory.cpp:1054
Localization system for the Toshi engine.
TWCHAR * T2LocalisedString
Definition T2Locale.h:18
#define TASSERT(X,...)
Definition Defines.h:138
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
size_t TSIZE
Definition Typedefs.h:9
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
static TUINT32 GetHeaderSize(TUINT32 count)
Definition TTRB.h:352
static TUINT32 GetSymbolTableSize(TUINT32 count)
Definition TTRB.h:354
TUINT8 AllocType
Definition TTRB.h:269
TINT GetNumStrings() const
Definition T2Locale.cpp:71
virtual const TCHAR * GetLanguageFilename(Lang lang)=0
T2LocalisedString GetString(TINT a_iNumString)
Definition T2Locale.cpp:76
void * m_BufferPos
Definition T2Locale.h:60
LocaleStrings * m_StringTable
Definition T2Locale.h:61
void * m_pBuffer
Definition T2Locale.h:59
Lang m_LangId
Definition T2Locale.h:62
static void * TRBAllocator(TTRB::AllocType alloctype, size_t size, short unk, size_t unk2, void *userData)
Definition T2Locale.cpp:43
virtual ~T2Locale()
Definition T2Locale.cpp:33
TINT32 Lang
Definition T2Locale.h:23
T2Locale(const T2Locale &)=delete
static void TRBDeallocator(TTRB::AllocType alloctype, void *ptr, short unk, size_t unk2, void *userData)
Definition T2Locale.cpp:48
TTRB m_Locale
Definition T2Locale.h:58
void SetLanguage(Lang langid)
Definition T2Locale.cpp:53
TBOOL m_bOwnsBuffer
Definition T2Locale.h:63
Lang GetLanguage() const
Definition T2Locale.cpp:66