wavelength 1.0.0
Loading...
Searching...
No Matches
DataArray Class Reference

Reference-counted array of script data nodes. More...

#include <dataarray.h>

Classes

union  Node
 A node's value, read as the member its NodeType selects. More...
union  DataNode
 One node. More...

Public Types

enum  NodeType { kNodeInt = 0 , kNodeSymbol = 1 , kNodeFloat = 2 , kNodeArray = 3 }
 Kinds of node Type() reports, two bits each. More...
enum  DataType { kDataInt = 0 , kDataSymbol = 1 , kDataFloat = 2 , kDataArray = 3 }
 The type of a node. More...

Public Member Functions

 DataArray (int nSize)
 Construct an array of cleared integer nodes with one reference.
 DataArray (BinStream &stream, const std::vector< const char * > &files)
 Read an array the compiler wrote, with one reference.
 ~DataArray ()
 Release the child arrays and the node storage.
void Merge (const DataArray *pOther)
 Add the child arrays of another array whose tags this array lacks, and merge the children whose tags both have.
void SetFileLine (const char *pszFile, int nLine)
 Record the file and the line the array was read from.
void SortByKey ()
 Sort the child arrays by the value of their first nodes, and mark the array as sorted.
void Resize (int nSize)
 Change the number of nodes, releasing the child arrays of the nodes removed.
Node Value (int nIndex) const
 Report a node's value without regard to its kind.
void AddRef ()
 Take one more reference.
int Size () const
 Report the number of nodes.
int Type (int nIndex) const
 Report the kind of a node.
bool FindVector (const char *pszName, Vector3 *pValue, bool bFail) const
 Find the three numbers that follow a tag.
bool FindVector (const char *pszName, Vector2 *pValue, bool bFail) const
 Find the two numbers that follow a tag.
void Release ()
 Drop one reference and destroy the array when none remains.
DataArray * FindArray (const char *pszTag, bool bFail) const
 Find the child array whose first node is a tag.
DataArray * FindArray (int nTag) const
 Find the child array whose first node is an integer tag.
bool FindString (const char *pszName, String *pValue, bool bFail) const
 Find the symbol that follows a tag and copy it into a string.
bool FindColor (const char *pszName, Color *pValue, bool bFail) const
 Find the colour that follows a tag.
bool FindSymbol (const char *pszName, const char **ppszValue, bool bFail) const
 Find the symbol that follows a tag.
bool FindInt (const char *pszName, int *pnValue, bool bFail) const
 Find the integer that follows a tag.
bool FindFloat (const char *pszName, float *pfValue, bool bFail) const
 Find the floating-point number that follows a tag.
bool FindBool (const char *pszName, int *pnValue, bool bFail) const
 Find the truth value that follows a tag.
const char * Sym (int nIndex) const
 Report a node as a symbol.
int Int (int nIndex) const
 Report a node as an integer.
float Float (int nIndex) const
 Report a node as a float.
DataArray * Array (int nIndex) const
 Report a node as an array.
void SetNode (int nIndex, Node value, int nType)
 Replace a node with a value of a kind.
void Print (PrnStream &stream) const
 Write the array as script text.
const char * GetFile () const
short GetLine () const
 DataArray (int size)
 Create an array of integer zeroes, with one reference.
 DataArray (BinStream &bs, std::vector< const char * > &filenames)
 Read an array, with one reference, as a compiled script stores it.
 ~DataArray ()
 Release the child arrays and free the nodes.
void * operator new (size_t size)
 Allocate from the pool allocator under the name DataArray.
void operator delete (void *mem)
 Return memory to the pool allocator.
void Print (PrnStream &s)
 Write the array in script syntax.
void Resize (int size)
 Change the number of nodes.
void AddRef ()
 Take a reference.
void Release ()
 Drop a reference, deleting the array with its last one.
DataArray * FindArray (int tag)
 Find the nested array whose first node equals a value.
DataArray * FindArray (const char *tag, bool fail)
 Find the nested array whose first node is a symbol.
bool FindSymbol (const char *tag, const char **value, bool fail)
 Read the symbol after a tag.
bool FindInt (const char *tag, int *value, bool fail)
 Read the integer after a tag.
bool FindFloat (const char *tag, float *value, bool fail)
 Read the real number after a tag.
bool FindBool (const char *tag, bool *value, bool fail)
 Read the integer after a tag as a truth value.
int Type (int i)
 Report the type of a node.
const char * Sym (int i)
 Read a symbol node.
DataNode Node (int i)
 Read a node of any type.
int Int (int i)
 Read an integer node.
float Float (int i)
 Read a real number node.
DataArray * Array (int i)
 Read an array node.
void SetNode (int i, DataNode value, int type)
 Replace a node.
void SetFileLine (const char *file, int line)
 Record where the array was defined.
int Size () const

Static Public Member Functions

static void * operator new (size_t)
 Allocate an array from the pool of 16-byte blocks.
static void operator delete (void *pBlock)
 Return an array to the pool of 16-byte blocks.
static DataArray * Concat (const std::vector< DataArray * > &arrays, bool bRelease)
 Join the nodes of several arrays into a new array.
static DataArray * Read (const char *pszPath, BinStream *pStream)
 Parse script text into an array.
static DataArray * ReadText (const char *pszPath, BinStream *pStream)
 Parse script text into an array, never the compiled form Read() prefers on the disc.
static void MakeCompiledPath (char *pszOut, const char *pszPath, bool bCompiled)
 Build the path of the compiled copy of a data file.
static DataArray * New (int nSize)
 Create an array of nodes with one reference.
static void DefineMacro (const char *pszName, DataArray *pValue)
 Define a script macro, taking a reference on its value.
static DataArray * FindMacro (const char *pszName)
 Find the value of a script macro.

Detailed Description

Reference-counted array of script data nodes.

Array of script data: integers, real numbers, symbols, and nested arrays.

The configuration file and every script command arrive as one of these. The class is not polymorphic. The name is inferred from the allocation tag "DataArray".

The RTTI records the class. The object is 0x10 bytes. The nodes and a table of their 2-bit types share one pool allocation, the types packed 16 to a word after the last node. An array is reference counted and deletes itself when its last reference is released. The name of the member that marks an array sorted is inferred.

Member Enumeration Documentation

◆ NodeType

Kinds of node Type() reports, two bits each.

Enumerator
kNodeInt 

An integer.

kNodeSymbol 

A symbol.

kNodeFloat 

A floating-point number.

kNodeArray 

A child array.

◆ DataType

The type of a node.

Enumerator
kDataInt 

DataNode::i.

kDataSymbol 

DataNode::sym.

kDataFloat 

DataNode::f.

kDataArray 

DataNode::array.

Constructor & Destructor Documentation

◆ DataArray() [1/4]

DataArray::DataArray ( int nSize)
explicit

Construct an array of cleared integer nodes with one reference.

Parameters
nSizeThe number of nodes.
Ghidra address:
NTSC-U/C: 0x002965b8
Ghidra address:
PAL: 0x002a01d0

◆ DataArray() [2/4]

DataArray::DataArray ( BinStream & stream,
const std::vector< const char * > & files )

Read an array the compiler wrote, with one reference.

Parameters
streamThe stream.
filesThe files the array and its children name by index.
Ghidra address:
NTSC-U/C: 0x00296c08
Ghidra address:
PAL: 0x002a0820

◆ ~DataArray() [1/2]

DataArray::~DataArray ( )

Release the child arrays and the node storage.

Ghidra address:
NTSC-U/C: 0x00296638
Ghidra address:
PAL: 0x002a0250

◆ DataArray() [3/4]

DataArray::DataArray ( int size)

Create an array of integer zeroes, with one reference.

Parameters
sizeThe number of nodes.
Ghidra address:
0x10012670

◆ DataArray() [4/4]

DataArray::DataArray ( BinStream & bs,
std::vector< const char * > & filenames )

Read an array, with one reference, as a compiled script stores it.

Parameters
bsThe stream.
filenamesThe script file names, which the stored file index selects from.
Ghidra address:
0x10012ca0

◆ ~DataArray() [2/2]

DataArray::~DataArray ( )

Release the child arrays and free the nodes.

Ghidra address:
0x100126d0

Member Function Documentation

◆ operator new() [1/2]

void * DataArray::operator new ( size_t )
inlinestatic

Allocate an array from the pool of 16-byte blocks.

Returns
The block.

◆ operator delete() [1/2]

void DataArray::operator delete ( void * pBlock)
inlinestatic

Return an array to the pool of 16-byte blocks.

Parameters
pBlockThe block.

◆ Concat()

DataArray * DataArray::Concat ( const std::vector< DataArray * > & arrays,
bool bRelease )
static

Join the nodes of several arrays into a new array.

Parameters
arraysThe arrays, in order.
bReleaseWhether each array loses a reference once its nodes are copied.
Returns
The new array, with one reference.
Ghidra address:
NTSC-U/C: 0x002968e8
Ghidra address:
PAL: 0x002a0500

◆ Merge()

void DataArray::Merge ( const DataArray * pOther)

Add the child arrays of another array whose tags this array lacks, and merge the children whose tags both have.

Parameters
pOtherThe other array, or null.
Ghidra address:
NTSC-U/C: 0x00296a18
Ghidra address:
PAL: 0x002a0630

◆ SetFileLine() [1/2]

void DataArray::SetFileLine ( const char * pszFile,
int nLine )

Record the file and the line the array was read from.

Parameters
pszFileThe file, interned as a symbol.
nLineThe line.
Ghidra address:
NTSC-U/C: 0x00296b08
Ghidra address:
PAL: 0x002a0720

◆ SortByKey()

void DataArray::SortByKey ( )

Sort the child arrays by the value of their first nodes, and mark the array as sorted.

FindArray() then searches the array by halves.

Ghidra address:
NTSC-U/C: 0x00296bc0
Ghidra address:
PAL: 0x002a07d8

◆ Resize() [1/2]

void DataArray::Resize ( int nSize)

Change the number of nodes, releasing the child arrays of the nodes removed.

New nodes are cleared integers.

Parameters
nSizeThe number of nodes.
Ghidra address:
NTSC-U/C: 0x00295ed0
Ghidra address:
PAL: 0x0029fae8

◆ Value()

Node DataArray::Value ( int nIndex) const

Report a node's value without regard to its kind.

Parameters
nIndexThe node.
Returns
The value.
Ghidra address:
NTSC-U/C: 0x00296738
Ghidra address:
PAL: 0x002a0350

◆ AddRef() [1/2]

void DataArray::AddRef ( )

Take one more reference.

Ghidra address:
NTSC-U/C: 0x002960a0
Ghidra address:
PAL: 0x0029fcb8

◆ Size() [1/2]

int DataArray::Size ( ) const
inline

Report the number of nodes.

Returns
mSize.

◆ Type() [1/2]

int DataArray::Type ( int nIndex) const

Report the kind of a node.

Parameters
nIndexThe node.
Returns
One of NodeType.
Ghidra address:
NTSC-U/C: 0x002966f0
Ghidra address:
PAL: 0x002a0308

◆ FindVector() [1/2]

bool DataArray::FindVector ( const char * pszName,
Vector3 * pValue,
bool bFail ) const

Find the three numbers that follow a tag.

The fourth word of the vector is left as it was.

Parameters
pszNameThe symbol that starts the child array.
pValueReceives the numbers at indices 1 to 3 of the child array when it exists.
bFailPassed to FindArray().
Returns
Whether the child array exists.
Ghidra address:
NTSC-U/C: 0x002964a8
Ghidra address:
PAL: 0x002a00c0

◆ FindVector() [2/2]

bool DataArray::FindVector ( const char * pszName,
Vector2 * pValue,
bool bFail ) const

Find the two numbers that follow a tag.

Parameters
pszNameThe symbol that starts the child array.
pValueReceives the numbers at indices 1 and 2 of the child array when it exists.
bFailPassed to FindArray().
Returns
Whether the child array exists.
Ghidra address:
NTSC-U/C: 0x00296440
Ghidra address:
PAL: 0x002a0058

◆ Release() [1/2]

void DataArray::Release ( )

Drop one reference and destroy the array when none remains.

Ghidra address:
NTSC-U/C: 0x002960b0
Ghidra address:
PAL: 0x0029fcc8

◆ Read()

DataArray * DataArray::Read ( const char * pszPath,
BinStream * pStream )
static

Parse script text into an array.

Parameters
pszPathThe file to read when pStream is null, and the name errors give.
pStreamThe stream to read, or null to read the file.
Returns
The array, with one reference.
Ghidra address:
NTSC-U/C: 0x00297ee0
Ghidra address:
PAL: 0x002a1ae0

◆ ReadText()

DataArray * DataArray::ReadText ( const char * pszPath,
BinStream * pStream )
static

Parse script text into an array, never the compiled form Read() prefers on the disc.

The name is inferred.

Parameters
pszPathThe file to read when pStream is null, and the name errors give.
pStreamThe stream to read, or null to read the file.
Returns
The array, with one reference.
Ghidra address:
NTSC-U/C: 0x002980d8
Ghidra address:
PAL: 0x002a1ce0

◆ FindArray() [1/4]

DataArray * DataArray::FindArray ( const char * pszTag,
bool bFail ) const

Find the child array whose first node is a tag.

Parameters
pszTagThe tag.
bFailTreat a missing child as an error.
Returns
The child, or null when none has the tag.
Ghidra address:
NTSC-U/C: 0x00296280
Ghidra address:
PAL: 0x0029fe98

◆ FindArray() [2/4]

DataArray * DataArray::FindArray ( int nTag) const

Find the child array whose first node is an integer tag.

An array marked as sorted is searched by halves.

Parameters
nTagThe tag.
Returns
The child, or null when none has the tag.
Ghidra address:
NTSC-U/C: 0x002960e8
Ghidra address:
PAL: 0x0029fd00

◆ FindString()

bool DataArray::FindString ( const char * pszName,
String * pValue,
bool bFail ) const

Find the symbol that follows a tag and copy it into a string.

Parameters
pszNameThe symbol that starts the child array.
pValueReceives the symbol at index 1 of the child array when it exists.
bFailPassed to FindArray().
Returns
Whether the child array exists.
Ghidra address:
NTSC-U/C: 0x00296310
Ghidra address:
PAL: 0x0029ff28

◆ FindColor()

bool DataArray::FindColor ( const char * pszName,
Color * pValue,
bool bFail ) const

Find the colour that follows a tag.

The alpha is read only when the child array has a fourth component.

Parameters
pszNameThe symbol that starts the child array.
pValueReceives the colour at indices 1 to 4 of the child array when it exists.
bFailPassed to FindArray().
Returns
Whether the child array exists.
Ghidra address:
NTSC-U/C: 0x00296520
Ghidra address:
PAL: 0x002a0138

◆ FindSymbol() [1/2]

bool DataArray::FindSymbol ( const char * pszName,
const char ** ppszValue,
bool bFail ) const

Find the symbol that follows a tag.

Parameters
pszNameThe symbol that starts the child array.
ppszValueReceives the symbol at index 1 of the child array when it exists.
bFailPassed to FindArray().
Returns
Whether the child array exists.
Ghidra address:
NTSC-U/C: 0x002962c8
Ghidra address:
PAL: 0x0029fee0

◆ FindInt() [1/2]

bool DataArray::FindInt ( const char * pszName,
int * pnValue,
bool bFail ) const

Find the integer that follows a tag.

Parameters
pszNameThe symbol that starts the child array.
pnValueReceives the integer at index 1 of the child array when it exists.
bFailPassed to FindArray().
Returns
Whether the child array exists.
Ghidra address:
NTSC-U/C: 0x00296360
Ghidra address:
PAL: 0x0029ff78

◆ FindFloat() [1/2]

bool DataArray::FindFloat ( const char * pszName,
float * pfValue,
bool bFail ) const

Find the floating-point number that follows a tag.

Parameters
pszNameThe symbol that starts the child array.
pfValueReceives the number at index 1 of the child array when it exists.
bFailPassed to FindArray().
Returns
Whether the child array exists.
Ghidra address:
NTSC-U/C: 0x002963a8
Ghidra address:
PAL: 0x0029ffc0

◆ FindBool() [1/2]

bool DataArray::FindBool ( const char * pszName,
int * pnValue,
bool bFail ) const

Find the truth value that follows a tag.

Parameters
pszNameThe symbol that starts the child array.
pnValueReceives 1 when the integer at index 1 of the child array is not zero and 0 otherwise, when the child array exists.
bFailPassed to FindArray().
Returns
Whether the child array exists.
Ghidra address:
NTSC-U/C: 0x002963f0
Ghidra address:
PAL: 0x002a0008

◆ Sym() [1/2]

const char * DataArray::Sym ( int nIndex) const

Report a node as a symbol.

Parameters
nIndexThe node.
Returns
The interned symbol text.
Ghidra address:
NTSC-U/C: 0x00296720
Ghidra address:
PAL: 0x002a0338

◆ Int() [1/2]

int DataArray::Int ( int nIndex) const

Report a node as an integer.

Parameters
nIndexThe node.
Returns
The value.
Ghidra address:
NTSC-U/C: 0x00296750
Ghidra address:
PAL: 0x002a0368

◆ Float() [1/2]

float DataArray::Float ( int nIndex) const

Report a node as a float.

Parameters
nIndexThe node.
Returns
The value.
Ghidra address:
NTSC-U/C: 0x00296768
Ghidra address:
PAL: 0x002a0380

◆ Array() [1/2]

DataArray * DataArray::Array ( int nIndex) const

Report a node as an array.

Parameters
nIndexThe node.
Returns
The array.
Ghidra address:
NTSC-U/C: 0x002967c0
Ghidra address:
PAL: 0x002a03d8

◆ SetNode() [1/2]

void DataArray::SetNode ( int nIndex,
Node value,
int nType )

Replace a node with a value of a kind.

Parameters
nIndexThe node. The child array a node replaces loses a reference and a new child array gains one. Symbol text is interned.
nIndexThe node.
valueThe value.
nTypeThe kind of the value, one of NodeType.
Ghidra address:
NTSC-U/C: 0x00296820
Ghidra address:
PAL: 0x002a0438

◆ Print() [1/2]

void DataArray::Print ( PrnStream & stream) const

Write the array as script text.

Parameters
streamThe stream to write to.
Ghidra address:
NTSC-U/C: 0x00295cb0
Ghidra address:
PAL: 0x0029f8c8

◆ MakeCompiledPath()

void DataArray::MakeCompiledPath ( char * pszOut,
const char * pszPath,
bool bCompiled )
static

Build the path of the compiled copy of a data file.

The compiled copy is <directory>/gen/<base>.<extension>.bin. It is used when the game runs from the disc or when bCompiled asks for it, and the path is copied unchanged otherwise.

Parameters
pszOutReceives the path.
pszPathThe path of the data file.
bCompiledUse the compiled copy even when the game does not run from the disc.
Ghidra address:
NTSC-U/C: 0x00298208
Ghidra address:
PAL: 0x002a1e10

◆ New()

DataArray * DataArray::New ( int nSize)
static

Create an array of nodes with one reference.

Parameters
nSizeThe number of nodes.
Returns
The array.
Ghidra address:
NTSC-U/C: 0x00295e88
Ghidra address:
PAL: 0x0029faa0

◆ DefineMacro()

void DataArray::DefineMacro ( const char * pszName,
DataArray * pValue )
static

Define a script macro, taking a reference on its value.

Parameters
pszNameThe name of the macro.
pValueThe value of the macro.
Ghidra address:
NTSC-U/C: 0x002973a8
Ghidra address:
PAL: 0x002a0fb8

◆ FindMacro()

DataArray * DataArray::FindMacro ( const char * pszName)
static

Find the value of a script macro.

Parameters
pszNameThe name of the macro.
Returns
The value, or null when no macro has the name.
Ghidra address:
NTSC-U/C: 0x002974b0
Ghidra address:
PAL: 0x002a10c0

◆ GetFile()

const char * DataArray::GetFile ( ) const
inline
Returns
The file the array was read from.

◆ GetLine()

short DataArray::GetLine ( ) const
inline
Returns
The line of GetFile() the array starts at.

◆ operator new() [2/2]

void * DataArray::operator new ( size_t size)

Allocate from the pool allocator under the name DataArray.

The control compiles this inline.

Parameters
sizeThe size of the object.
Returns
The memory.

◆ operator delete() [2/2]

void DataArray::operator delete ( void * mem)

Return memory to the pool allocator.

Parameters
memThe memory.
Ghidra address:
0x100122b0

◆ Print() [2/2]

void DataArray::Print ( PrnStream & s)

Write the array in script syntax.

An array with nested arrays is written one node to a line, indented.

Parameters
sThe stream.
Ghidra address:
0x10012140

◆ Resize() [2/2]

void DataArray::Resize ( int size)

Change the number of nodes.

Removed nested arrays are released; added nodes are integer zeroes.

Parameters
sizeThe new number of nodes.
Ghidra address:
0x100122c0

◆ AddRef() [2/2]

void DataArray::AddRef ( )

Take a reference.

Ghidra address:
0x100123d0

◆ Release() [2/2]

void DataArray::Release ( )

Drop a reference, deleting the array with its last one.

Ghidra address:
0x100123e0

◆ FindArray() [3/4]

DataArray * DataArray::FindArray ( int tag)

Find the nested array whose first node equals a value.

A sorted array is searched by bisection, an unsorted one from the start.

Parameters
tagThe value of the first node.
Returns
The array, or null.
Ghidra address:
0x10012410

◆ FindArray() [4/4]

DataArray * DataArray::FindArray ( const char * tag,
bool fail )

Find the nested array whose first node is a symbol.

Parameters
tagThe symbol's text.
failWhether a missing array is a failure.
Returns
The array, or null.
Ghidra address:
0x10012520

◆ FindSymbol() [2/2]

bool DataArray::FindSymbol ( const char * tag,
const char ** value,
bool fail )

Read the symbol after a tag.

Parameters
tagThe tag.
valueReceives the symbol.
failWhether a missing tag is a failure.
Returns
Whether the tag was found.
Ghidra address:
0x100125a0

◆ FindInt() [2/2]

bool DataArray::FindInt ( const char * tag,
int * value,
bool fail )

Read the integer after a tag.

Parameters
tagThe tag.
valueReceives the integer.
failWhether a missing tag is a failure.
Returns
Whether the tag was found.
Ghidra address:
0x100125d0

◆ FindFloat() [2/2]

bool DataArray::FindFloat ( const char * tag,
float * value,
bool fail )

Read the real number after a tag.

An integer converts.

Parameters
tagThe tag.
valueReceives the number.
failWhether a missing tag is a failure.
Returns
Whether the tag was found.
Ghidra address:
0x10012600

◆ FindBool() [2/2]

bool DataArray::FindBool ( const char * tag,
bool * value,
bool fail )

Read the integer after a tag as a truth value.

Parameters
tagThe tag.
valueReceives whether the integer is nonzero.
failWhether a missing tag is a failure.
Returns
Whether the tag was found.
Ghidra address:
0x10012630

◆ Type() [2/2]

int DataArray::Type ( int i)

Report the type of a node.

Parameters
iThe node.
Returns
A DataType.
Ghidra address:
0x10012720

◆ Sym() [2/2]

const char * DataArray::Sym ( int i)

Read a symbol node.

Another type is a failure.

Parameters
iThe node.
Returns
The symbol.
Ghidra address:
0x10012780

◆ Node()

DataNode DataArray::Node ( int i)

Read a node of any type.

Parameters
iThe node.
Returns
The node.
Ghidra address:
0x10012840

◆ Int() [2/2]

int DataArray::Int ( int i)

Read an integer node.

Another type is a failure.

Parameters
iThe node.
Returns
The integer.
Ghidra address:
0x10012890

◆ Float() [2/2]

float DataArray::Float ( int i)

Read a real number node.

An integer converts; another type is a failure.

Parameters
iThe node.
Returns
The number.
Ghidra address:
0x10012950

◆ Array() [2/2]

DataArray * DataArray::Array ( int i)

Read an array node.

Another type is a failure.

Parameters
iThe node.
Returns
The array.
Ghidra address:
0x10012a20

◆ SetNode() [2/2]

void DataArray::SetNode ( int i,
DataNode value,
int type )

Replace a node.

A symbol is entered into the shared string table, and an array gains a reference; the array the node held loses one.

Parameters
iThe node.
valueThe value.
typeThe value's DataType.
Ghidra address:
0x10012b20

◆ SetFileLine() [2/2]

void DataArray::SetFileLine ( const char * file,
int line )

Record where the array was defined.

Parameters
fileThe script file.
lineThe line.
Ghidra address:
0x10012c60

◆ Size() [2/2]

int DataArray::Size ( ) const
inline
Returns
The number of nodes.

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