mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-05-31 08:50:54 +00:00
Formatted code using Artistic Style for better readability.
This commit is contained in:
parent
d40e661b3e
commit
f55a763ca4
701 changed files with 206183 additions and 142961 deletions
|
@ -2,9 +2,9 @@
|
|||
===========================================================================
|
||||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -36,7 +36,8 @@ idCVar swf_debugShowAddress( "swf_debugShowAddress", "0", CVAR_BOOL, "shows addr
|
|||
idSWFScriptObject::swfNamedVar_t::~swfNamedVar_t
|
||||
========================
|
||||
*/
|
||||
idSWFScriptObject::swfNamedVar_t::~swfNamedVar_t() {
|
||||
idSWFScriptObject::swfNamedVar_t::~swfNamedVar_t()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -44,8 +45,10 @@ idSWFScriptObject::swfNamedVar_t::~swfNamedVar_t() {
|
|||
idSWFScriptObject::swfNamedVar_t::operator=
|
||||
========================
|
||||
*/
|
||||
idSWFScriptObject::swfNamedVar_t & idSWFScriptObject::swfNamedVar_t::operator=( const swfNamedVar_t & other ) {
|
||||
if ( &other != this ) {
|
||||
idSWFScriptObject::swfNamedVar_t& idSWFScriptObject::swfNamedVar_t::operator=( const swfNamedVar_t& other )
|
||||
{
|
||||
if( &other != this )
|
||||
{
|
||||
index = other.index;
|
||||
name = other.name;
|
||||
hashNext = other.hashNext;
|
||||
|
@ -61,7 +64,8 @@ idSWFScriptObject::swfNamedVar_t & idSWFScriptObject::swfNamedVar_t::operator=(
|
|||
idSWFScriptObject::idSWFScriptObject
|
||||
========================
|
||||
*/
|
||||
idSWFScriptObject::idSWFScriptObject() : prototype( NULL ), refCount( 1 ), noAutoDelete( false ), objectType( SWF_OBJECT_OBJECT ) {
|
||||
idSWFScriptObject::idSWFScriptObject() : prototype( NULL ), refCount( 1 ), noAutoDelete( false ), objectType( SWF_OBJECT_OBJECT )
|
||||
{
|
||||
data.sprite = NULL;
|
||||
data.text = NULL;
|
||||
Clear();
|
||||
|
@ -73,8 +77,10 @@ idSWFScriptObject::idSWFScriptObject() : prototype( NULL ), refCount( 1 ), noAut
|
|||
idSWFScriptObject::~idSWFScriptObject
|
||||
========================
|
||||
*/
|
||||
idSWFScriptObject::~idSWFScriptObject() {
|
||||
if ( prototype != NULL ) {
|
||||
idSWFScriptObject::~idSWFScriptObject()
|
||||
{
|
||||
if( prototype != NULL )
|
||||
{
|
||||
prototype->Release();
|
||||
}
|
||||
}
|
||||
|
@ -84,8 +90,9 @@ idSWFScriptObject::~idSWFScriptObject() {
|
|||
idSWFScriptObject::Alloc
|
||||
========================
|
||||
*/
|
||||
idSWFScriptObject * idSWFScriptObject::Alloc() {
|
||||
return new (TAG_SWF) idSWFScriptObject;
|
||||
idSWFScriptObject* idSWFScriptObject::Alloc()
|
||||
{
|
||||
return new( TAG_SWF ) idSWFScriptObject;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -93,7 +100,8 @@ idSWFScriptObject * idSWFScriptObject::Alloc() {
|
|||
idSWFScriptObject::AddRef
|
||||
========================
|
||||
*/
|
||||
void idSWFScriptObject::AddRef() {
|
||||
void idSWFScriptObject::AddRef()
|
||||
{
|
||||
refCount++;
|
||||
}
|
||||
|
||||
|
@ -102,8 +110,10 @@ void idSWFScriptObject::AddRef() {
|
|||
idSWFScriptObject::Release
|
||||
========================
|
||||
*/
|
||||
void idSWFScriptObject::Release() {
|
||||
if ( --refCount == 0 && !noAutoDelete ) {
|
||||
void idSWFScriptObject::Release()
|
||||
{
|
||||
if( --refCount == 0 && !noAutoDelete )
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
@ -113,9 +123,11 @@ void idSWFScriptObject::Release() {
|
|||
idSWFScriptObject::Clear
|
||||
========================
|
||||
*/
|
||||
void idSWFScriptObject::Clear() {
|
||||
void idSWFScriptObject::Clear()
|
||||
{
|
||||
variables.Clear();
|
||||
for ( int i = 0; i < VARIABLE_HASH_BUCKETS; i++ ) {
|
||||
for( int i = 0; i < VARIABLE_HASH_BUCKETS; i++ )
|
||||
{
|
||||
variablesHash[i] = -1;
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +137,8 @@ void idSWFScriptObject::Clear() {
|
|||
idSWFScriptObject::HasProperty
|
||||
========================
|
||||
*/
|
||||
bool idSWFScriptObject::HasProperty( const char * name ) {
|
||||
bool idSWFScriptObject::HasProperty( const char* name )
|
||||
{
|
||||
return ( GetVariable( name, false ) != NULL );
|
||||
}
|
||||
|
||||
|
@ -134,18 +147,25 @@ bool idSWFScriptObject::HasProperty( const char * name ) {
|
|||
idSWFScriptObject::HasValidProperty
|
||||
========================
|
||||
*/
|
||||
bool idSWFScriptObject::HasValidProperty( const char * name ) {
|
||||
idSWFScriptObject::swfNamedVar_t * const variable = GetVariable( name, false );
|
||||
if ( variable == NULL ) {
|
||||
bool idSWFScriptObject::HasValidProperty( const char* name )
|
||||
{
|
||||
idSWFScriptObject::swfNamedVar_t* const variable = GetVariable( name, false );
|
||||
if( variable == NULL )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( variable->native != NULL ) {
|
||||
if( variable->native != NULL )
|
||||
{
|
||||
idSWFScriptVar nv = variable->native->Get( this );
|
||||
if ( nv.IsNULL() || nv.IsUndefined() ) {
|
||||
if( nv.IsNULL() || nv.IsUndefined() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ( variable->value.IsNULL() || variable->value.IsUndefined() ) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if( variable->value.IsNULL() || variable->value.IsUndefined() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -157,14 +177,21 @@ bool idSWFScriptObject::HasValidProperty( const char * name ) {
|
|||
idSWFScriptObject::Get
|
||||
========================
|
||||
*/
|
||||
idSWFScriptVar idSWFScriptObject::Get( const char * name ) {
|
||||
swfNamedVar_t * variable = GetVariable( name, false );
|
||||
if ( variable == NULL ) {
|
||||
idSWFScriptVar idSWFScriptObject::Get( const char* name )
|
||||
{
|
||||
swfNamedVar_t* variable = GetVariable( name, false );
|
||||
if( variable == NULL )
|
||||
{
|
||||
return idSWFScriptVar();
|
||||
} else {
|
||||
if ( variable->native ) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if( variable->native )
|
||||
{
|
||||
return variable->native->Get( this );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return variable->value;
|
||||
}
|
||||
}
|
||||
|
@ -175,14 +202,21 @@ idSWFScriptVar idSWFScriptObject::Get( const char * name ) {
|
|||
idSWFScriptObject::Get
|
||||
========================
|
||||
*/
|
||||
idSWFScriptVar idSWFScriptObject::Get( int index ) {
|
||||
swfNamedVar_t * variable = GetVariable( index, false );
|
||||
if ( variable == NULL ) {
|
||||
idSWFScriptVar idSWFScriptObject::Get( int index )
|
||||
{
|
||||
swfNamedVar_t* variable = GetVariable( index, false );
|
||||
if( variable == NULL )
|
||||
{
|
||||
return idSWFScriptVar();
|
||||
} else {
|
||||
if ( variable->native ) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if( variable->native )
|
||||
{
|
||||
return variable->native->Get( this );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return variable->value;
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +227,8 @@ idSWFScriptVar idSWFScriptObject::Get( int index ) {
|
|||
idSWFScriptObject::GetSprite
|
||||
========================
|
||||
*/
|
||||
idSWFSpriteInstance * idSWFScriptObject::GetSprite( int index ) {
|
||||
idSWFSpriteInstance* idSWFScriptObject::GetSprite( int index )
|
||||
{
|
||||
idSWFScriptVar var = Get( index );
|
||||
return var.ToSprite();
|
||||
}
|
||||
|
@ -203,7 +238,8 @@ idSWFSpriteInstance * idSWFScriptObject::GetSprite( int index ) {
|
|||
idSWFScriptObject::GetSprite
|
||||
========================
|
||||
*/
|
||||
idSWFSpriteInstance * idSWFScriptObject::GetSprite( const char * name ) {
|
||||
idSWFSpriteInstance* idSWFScriptObject::GetSprite( const char* name )
|
||||
{
|
||||
idSWFScriptVar var = Get( name );
|
||||
return var.ToSprite();
|
||||
}
|
||||
|
@ -213,9 +249,11 @@ idSWFSpriteInstance * idSWFScriptObject::GetSprite( const char * name ) {
|
|||
idSWFScriptObject::GetObject
|
||||
========================
|
||||
*/
|
||||
idSWFScriptObject * idSWFScriptObject::GetObject( int index ) {
|
||||
idSWFScriptObject* idSWFScriptObject::GetObject( int index )
|
||||
{
|
||||
idSWFScriptVar var = Get( index );
|
||||
if ( var.IsObject() ) {
|
||||
if( var.IsObject() )
|
||||
{
|
||||
return var.GetObject();
|
||||
}
|
||||
return NULL;
|
||||
|
@ -226,9 +264,11 @@ idSWFScriptObject * idSWFScriptObject::GetObject( int index ) {
|
|||
idSWFScriptObject::GetObject
|
||||
========================
|
||||
*/
|
||||
idSWFScriptObject * idSWFScriptObject::GetObject( const char * name ) {
|
||||
idSWFScriptObject* idSWFScriptObject::GetObject( const char* name )
|
||||
{
|
||||
idSWFScriptVar var = Get( name );
|
||||
if ( var.IsObject() ) {
|
||||
if( var.IsObject() )
|
||||
{
|
||||
return var.GetObject();
|
||||
}
|
||||
return NULL;
|
||||
|
@ -239,9 +279,11 @@ idSWFScriptObject * idSWFScriptObject::GetObject( const char * name ) {
|
|||
idSWFScriptObject::GetText
|
||||
========================
|
||||
*/
|
||||
idSWFTextInstance * idSWFScriptObject::GetText( int index ) {
|
||||
idSWFTextInstance* idSWFScriptObject::GetText( int index )
|
||||
{
|
||||
idSWFScriptVar var = Get( index );
|
||||
if ( var.IsObject() ) {
|
||||
if( var.IsObject() )
|
||||
{
|
||||
return var.GetObject()->GetText();
|
||||
}
|
||||
return NULL;
|
||||
|
@ -252,9 +294,11 @@ idSWFTextInstance * idSWFScriptObject::GetText( int index ) {
|
|||
idSWFScriptObject::GetText
|
||||
========================
|
||||
*/
|
||||
idSWFTextInstance * idSWFScriptObject::GetText( const char * name ) {
|
||||
idSWFTextInstance* idSWFScriptObject::GetText( const char* name )
|
||||
{
|
||||
idSWFScriptVar var = Get( name );
|
||||
if ( var.IsObject() ) {
|
||||
if( var.IsObject() )
|
||||
{
|
||||
return var.GetObject()->GetText();
|
||||
}
|
||||
return NULL;
|
||||
|
@ -265,40 +309,54 @@ idSWFTextInstance * idSWFScriptObject::GetText( const char * name ) {
|
|||
idSWFScriptObject::Set
|
||||
========================
|
||||
*/
|
||||
void idSWFScriptObject::Set( const char * name, const idSWFScriptVar & value ) {
|
||||
if ( objectType == SWF_OBJECT_ARRAY ) {
|
||||
if ( idStr::Cmp( name, "length" ) == 0 ) {
|
||||
void idSWFScriptObject::Set( const char* name, const idSWFScriptVar& value )
|
||||
{
|
||||
if( objectType == SWF_OBJECT_ARRAY )
|
||||
{
|
||||
if( idStr::Cmp( name, "length" ) == 0 )
|
||||
{
|
||||
int newLength = value.ToInteger();
|
||||
for ( int i = 0; i < variables.Num(); i++ ) {
|
||||
if ( variables[i].index >= newLength ) {
|
||||
for( int i = 0; i < variables.Num(); i++ )
|
||||
{
|
||||
if( variables[i].index >= newLength )
|
||||
{
|
||||
variables.RemoveIndexFast( i );
|
||||
i--;
|
||||
}
|
||||
}
|
||||
// rebuild the hash table
|
||||
for ( int i = 0; i < VARIABLE_HASH_BUCKETS; i++ ) {
|
||||
for( int i = 0; i < VARIABLE_HASH_BUCKETS; i++ )
|
||||
{
|
||||
variablesHash[i] = -1;
|
||||
}
|
||||
for ( int i = 0; i < variables.Num(); i++ ) {
|
||||
for( int i = 0; i < variables.Num(); i++ )
|
||||
{
|
||||
int hash = idStr::Hash( variables[i].name.c_str() ) & ( VARIABLE_HASH_BUCKETS - 1 );
|
||||
variables[i].hashNext = variablesHash[hash];
|
||||
variablesHash[hash] = i;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
int iName = atoi( name );
|
||||
if ( iName > 0 || ( iName == 0 && idStr::Cmp( name, "0" ) == 0 ) ) {
|
||||
swfNamedVar_t * lengthVar = GetVariable( "length", true );
|
||||
if ( lengthVar->value.ToInteger() <= iName ) {
|
||||
if( iName > 0 || ( iName == 0 && idStr::Cmp( name, "0" ) == 0 ) )
|
||||
{
|
||||
swfNamedVar_t* lengthVar = GetVariable( "length", true );
|
||||
if( lengthVar->value.ToInteger() <= iName )
|
||||
{
|
||||
lengthVar->value = idSWFScriptVar( iName + 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
swfNamedVar_t * variable = GetVariable( name, true );
|
||||
if ( variable->native ) {
|
||||
|
||||
swfNamedVar_t* variable = GetVariable( name, true );
|
||||
if( variable->native )
|
||||
{
|
||||
variable->native->Set( this, value );
|
||||
} else if ( ( variable->flags & SWF_VAR_FLAG_READONLY ) == 0 ) {
|
||||
}
|
||||
else if( ( variable->flags & SWF_VAR_FLAG_READONLY ) == 0 )
|
||||
{
|
||||
variable->value = value;
|
||||
}
|
||||
}
|
||||
|
@ -308,25 +366,33 @@ void idSWFScriptObject::Set( const char * name, const idSWFScriptVar & value ) {
|
|||
idSWFScriptObject::Set
|
||||
========================
|
||||
*/
|
||||
void idSWFScriptObject::Set( int index, const idSWFScriptVar & value ) {
|
||||
if ( index < 0 ) {
|
||||
void idSWFScriptObject::Set( int index, const idSWFScriptVar& value )
|
||||
{
|
||||
if( index < 0 )
|
||||
{
|
||||
extern idCVar swf_debug;
|
||||
if ( swf_debug.GetBool() ) {
|
||||
if( swf_debug.GetBool() )
|
||||
{
|
||||
idLib::Printf( "SWF: Trying to set a negative array index.\n" );
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ( objectType == SWF_OBJECT_ARRAY ) {
|
||||
swfNamedVar_t * lengthVar = GetVariable( "length", true );
|
||||
if ( lengthVar->value.ToInteger() <= index ) {
|
||||
if( objectType == SWF_OBJECT_ARRAY )
|
||||
{
|
||||
swfNamedVar_t* lengthVar = GetVariable( "length", true );
|
||||
if( lengthVar->value.ToInteger() <= index )
|
||||
{
|
||||
lengthVar->value = idSWFScriptVar( index + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
swfNamedVar_t * variable = GetVariable( index, true );
|
||||
if ( variable->native ) {
|
||||
|
||||
swfNamedVar_t* variable = GetVariable( index, true );
|
||||
if( variable->native )
|
||||
{
|
||||
variable->native->Set( this, value );
|
||||
} else if ( ( variable->flags & SWF_VAR_FLAG_READONLY ) == 0 ) {
|
||||
}
|
||||
else if( ( variable->flags & SWF_VAR_FLAG_READONLY ) == 0 )
|
||||
{
|
||||
variable->value = value;
|
||||
}
|
||||
}
|
||||
|
@ -336,11 +402,13 @@ void idSWFScriptObject::Set( int index, const idSWFScriptVar & value ) {
|
|||
idSWFScriptObject::SetNative
|
||||
========================
|
||||
*/
|
||||
void idSWFScriptObject::SetNative( const char * name, idSWFScriptNativeVariable * native ) {
|
||||
swfNamedVar_t * variable = GetVariable( name, true );
|
||||
void idSWFScriptObject::SetNative( const char* name, idSWFScriptNativeVariable* native )
|
||||
{
|
||||
swfNamedVar_t* variable = GetVariable( name, true );
|
||||
variable->flags = SWF_VAR_FLAG_DONTENUM;
|
||||
variable->native = native;
|
||||
if ( native->IsReadOnly() ) {
|
||||
if( native->IsReadOnly() )
|
||||
{
|
||||
variable->flags |= SWF_VAR_FLAG_READONLY;
|
||||
}
|
||||
}
|
||||
|
@ -350,49 +418,70 @@ void idSWFScriptObject::SetNative( const char * name, idSWFScriptNativeVariable
|
|||
idSWFScriptObject::DefaultValue
|
||||
========================
|
||||
*/
|
||||
idSWFScriptVar idSWFScriptObject::DefaultValue( bool stringHint ) {
|
||||
const char * methods[2] = { "toString", "valueOf" };
|
||||
if ( !stringHint ) {
|
||||
idSWFScriptVar idSWFScriptObject::DefaultValue( bool stringHint )
|
||||
{
|
||||
const char* methods[2] = { "toString", "valueOf" };
|
||||
if( !stringHint )
|
||||
{
|
||||
SwapValues( methods[0], methods[1] );
|
||||
}
|
||||
for ( int i = 0; i < 2; i++ ) {
|
||||
for( int i = 0; i < 2; i++ )
|
||||
{
|
||||
idSWFScriptVar method = Get( methods[i] );
|
||||
if ( method.IsFunction() ) {
|
||||
if( method.IsFunction() )
|
||||
{
|
||||
idSWFScriptVar value = method.GetFunction()->Call( this, idSWFParmList() );
|
||||
if ( !value.IsObject() && !value.IsFunction() ) {
|
||||
if( !value.IsObject() && !value.IsFunction() )
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch ( objectType ) {
|
||||
case SWF_OBJECT_OBJECT:
|
||||
if ( swf_debugShowAddress.GetBool() ) {
|
||||
return idSWFScriptVar( va( "[object:%p]", this ) );
|
||||
} else {
|
||||
return idSWFScriptVar( "[object]" );
|
||||
}
|
||||
case SWF_OBJECT_ARRAY:
|
||||
if ( swf_debugShowAddress.GetBool() ) {
|
||||
return idSWFScriptVar( va( "[array:%p]", this ) );
|
||||
} else {
|
||||
return idSWFScriptVar( "[array]" );
|
||||
}
|
||||
case SWF_OBJECT_SPRITE:
|
||||
if ( data.sprite != NULL ) {
|
||||
if ( data.sprite->parent == NULL ) {
|
||||
return idSWFScriptVar( "[_root]" );
|
||||
} else {
|
||||
return idSWFScriptVar( va( "[%s]", data.sprite->GetName() ) );
|
||||
switch( objectType )
|
||||
{
|
||||
case SWF_OBJECT_OBJECT:
|
||||
if( swf_debugShowAddress.GetBool() )
|
||||
{
|
||||
return idSWFScriptVar( va( "[object:%p]", this ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return idSWFScriptVar( "[object]" );
|
||||
}
|
||||
case SWF_OBJECT_ARRAY:
|
||||
if( swf_debugShowAddress.GetBool() )
|
||||
{
|
||||
return idSWFScriptVar( va( "[array:%p]", this ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return idSWFScriptVar( "[array]" );
|
||||
}
|
||||
case SWF_OBJECT_SPRITE:
|
||||
if( data.sprite != NULL )
|
||||
{
|
||||
if( data.sprite->parent == NULL )
|
||||
{
|
||||
return idSWFScriptVar( "[_root]" );
|
||||
}
|
||||
else
|
||||
{
|
||||
return idSWFScriptVar( va( "[%s]", data.sprite->GetName() ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return idSWFScriptVar( "[NULL]" );
|
||||
}
|
||||
case SWF_OBJECT_TEXT:
|
||||
if( swf_debugShowAddress.GetBool() )
|
||||
{
|
||||
return idSWFScriptVar( va( "[edittext:%p]", this ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return idSWFScriptVar( "[edittext]" );
|
||||
}
|
||||
} else {
|
||||
return idSWFScriptVar( "[NULL]" );
|
||||
}
|
||||
case SWF_OBJECT_TEXT:
|
||||
if ( swf_debugShowAddress.GetBool() ) {
|
||||
return idSWFScriptVar( va( "[edittext:%p]", this ) );
|
||||
} else {
|
||||
return idSWFScriptVar( "[edittext]" );
|
||||
}
|
||||
}
|
||||
return idSWFScriptVar( "[unknown]" );
|
||||
}
|
||||
|
@ -402,14 +491,18 @@ idSWFScriptVar idSWFScriptObject::DefaultValue( bool stringHint ) {
|
|||
idSWFScriptObject::GetVariable
|
||||
========================
|
||||
*/
|
||||
idSWFScriptObject::swfNamedVar_t * idSWFScriptObject::GetVariable( int index, bool create ) {
|
||||
for ( int i = 0; i < variables.Num(); i++ ) {
|
||||
if ( variables[i].index == index ) {
|
||||
idSWFScriptObject::swfNamedVar_t* idSWFScriptObject::GetVariable( int index, bool create )
|
||||
{
|
||||
for( int i = 0; i < variables.Num(); i++ )
|
||||
{
|
||||
if( variables[i].index == index )
|
||||
{
|
||||
return &variables[i];
|
||||
}
|
||||
}
|
||||
if ( create ) {
|
||||
swfNamedVar_t * variable = &variables.Alloc();
|
||||
if( create )
|
||||
{
|
||||
swfNamedVar_t* variable = &variables.Alloc();
|
||||
variable->flags = SWF_VAR_FLAG_NONE;
|
||||
variable->index = index;
|
||||
variable->name = va( "%d", index );
|
||||
|
@ -427,27 +520,34 @@ idSWFScriptObject::swfNamedVar_t * idSWFScriptObject::GetVariable( int index, bo
|
|||
idSWFScriptObject::GetVariable
|
||||
========================
|
||||
*/
|
||||
idSWFScriptObject::swfNamedVar_t * idSWFScriptObject::GetVariable( const char * name, bool create ) {
|
||||
idSWFScriptObject::swfNamedVar_t* idSWFScriptObject::GetVariable( const char* name, bool create )
|
||||
{
|
||||
int hash = idStr::Hash( name ) & ( VARIABLE_HASH_BUCKETS - 1 );
|
||||
for ( int i = variablesHash[hash]; i >= 0; i = variables[i].hashNext ) {
|
||||
if ( variables[i].name == name ) {
|
||||
for( int i = variablesHash[hash]; i >= 0; i = variables[i].hashNext )
|
||||
{
|
||||
if( variables[i].name == name )
|
||||
{
|
||||
return &variables[i];
|
||||
}
|
||||
}
|
||||
|
||||
if ( prototype != NULL ) {
|
||||
swfNamedVar_t * variable = prototype->GetVariable( name, false );
|
||||
if ( ( variable != NULL ) && ( variable->native || !create ) ) {
|
||||
|
||||
if( prototype != NULL )
|
||||
{
|
||||
swfNamedVar_t* variable = prototype->GetVariable( name, false );
|
||||
if( ( variable != NULL ) && ( variable->native || !create ) )
|
||||
{
|
||||
// If the variable is native, we want to pull it from the prototype even if we're going to set it
|
||||
return variable;
|
||||
}
|
||||
}
|
||||
|
||||
if ( create ) {
|
||||
swfNamedVar_t * variable = &variables.Alloc();
|
||||
|
||||
if( create )
|
||||
{
|
||||
swfNamedVar_t* variable = &variables.Alloc();
|
||||
variable->flags = SWF_VAR_FLAG_NONE;
|
||||
variable->index = atoi( name );
|
||||
if ( variable->index == 0 && idStr::Cmp( name, "0" ) != 0 ) {
|
||||
if( variable->index == 0 && idStr::Cmp( name, "0" ) != 0 )
|
||||
{
|
||||
variable->index = -1;
|
||||
}
|
||||
variable->name = name;
|
||||
|
@ -464,9 +564,10 @@ idSWFScriptObject::swfNamedVar_t * idSWFScriptObject::GetVariable( const char *
|
|||
idSWFScriptObject::MakeArray
|
||||
========================
|
||||
*/
|
||||
void idSWFScriptObject::MakeArray() {
|
||||
void idSWFScriptObject::MakeArray()
|
||||
{
|
||||
objectType = SWF_OBJECT_ARRAY;
|
||||
swfNamedVar_t * variable = GetVariable( "length", true );
|
||||
swfNamedVar_t* variable = GetVariable( "length", true );
|
||||
variable->value = idSWFScriptVar( 0 );
|
||||
variable->flags = SWF_VAR_FLAG_DONTENUM;
|
||||
}
|
||||
|
@ -476,36 +577,41 @@ void idSWFScriptObject::MakeArray() {
|
|||
idSWFScriptObject::GetNestedVar
|
||||
========================
|
||||
*/
|
||||
idSWFScriptVar idSWFScriptObject::GetNestedVar( const char * arg1, const char * arg2, const char * arg3, const char * arg4, const char * arg5, const char * arg6 ) {
|
||||
const char * const args[] = { arg1, arg2, arg3, arg4, arg5, arg6 };
|
||||
const int numArgs = sizeof( args ) / sizeof( const char * );
|
||||
|
||||
idStaticList< const char *, numArgs > vars;
|
||||
for ( int i = 0; i < numArgs && args[ i ] != NULL; ++i ) {
|
||||
idSWFScriptVar idSWFScriptObject::GetNestedVar( const char* arg1, const char* arg2, const char* arg3, const char* arg4, const char* arg5, const char* arg6 )
|
||||
{
|
||||
const char* const args[] = { arg1, arg2, arg3, arg4, arg5, arg6 };
|
||||
const int numArgs = sizeof( args ) / sizeof( const char* );
|
||||
|
||||
idStaticList< const char*, numArgs > vars;
|
||||
for( int i = 0; i < numArgs && args[ i ] != NULL; ++i )
|
||||
{
|
||||
vars.Append( args[ i ] );
|
||||
}
|
||||
|
||||
idSWFScriptObject * baseObject = this;
|
||||
|
||||
idSWFScriptObject* baseObject = this;
|
||||
idSWFScriptVar retVal;
|
||||
|
||||
for ( int i = 0; i < vars.Num(); ++i ) {
|
||||
|
||||
for( int i = 0; i < vars.Num(); ++i )
|
||||
{
|
||||
idSWFScriptVar var = baseObject->Get( vars[ i ] );
|
||||
|
||||
|
||||
// when at the end of object path just use the latest value as result
|
||||
if ( i == vars.Num() - 1 ) {
|
||||
if( i == vars.Num() - 1 )
|
||||
{
|
||||
retVal = var;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// encountered variable in path that wasn't an object
|
||||
if ( !var.IsObject() ) {
|
||||
if( !var.IsObject() )
|
||||
{
|
||||
retVal = idSWFScriptVar();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
baseObject = var.GetObject();
|
||||
}
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
@ -514,13 +620,15 @@ idSWFScriptVar idSWFScriptObject::GetNestedVar( const char * arg1, const char *
|
|||
idSWFScriptObject::GetNestedObj
|
||||
========================
|
||||
*/
|
||||
idSWFScriptObject * idSWFScriptObject::GetNestedObj( const char * arg1, const char * arg2, const char * arg3, const char * arg4, const char * arg5, const char * arg6 ) {
|
||||
idSWFScriptObject* idSWFScriptObject::GetNestedObj( const char* arg1, const char* arg2, const char* arg3, const char* arg4, const char* arg5, const char* arg6 )
|
||||
{
|
||||
idSWFScriptVar var = GetNestedVar( arg1, arg2, arg3, arg4, arg5, arg6 );
|
||||
|
||||
if ( !var.IsObject() ) {
|
||||
|
||||
if( !var.IsObject() )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
return var.GetObject();
|
||||
}
|
||||
|
||||
|
@ -529,10 +637,11 @@ idSWFScriptObject * idSWFScriptObject::GetNestedObj( const char * arg1, const ch
|
|||
idSWFScriptObject::GetNestedSprite
|
||||
========================
|
||||
*/
|
||||
idSWFSpriteInstance * idSWFScriptObject::GetNestedSprite( const char * arg1, const char * arg2, const char * arg3, const char * arg4, const char * arg5, const char * arg6 ) {
|
||||
idSWFSpriteInstance* idSWFScriptObject::GetNestedSprite( const char* arg1, const char* arg2, const char* arg3, const char* arg4, const char* arg5, const char* arg6 )
|
||||
{
|
||||
idSWFScriptVar var = GetNestedVar( arg1, arg2, arg3, arg4, arg5, arg6 );
|
||||
return var.ToSprite();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -540,10 +649,11 @@ idSWFSpriteInstance * idSWFScriptObject::GetNestedSprite( const char * arg1, con
|
|||
idSWFScriptObject::GetNestedText
|
||||
========================
|
||||
*/
|
||||
idSWFTextInstance * idSWFScriptObject::GetNestedText( const char * arg1, const char * arg2, const char * arg3, const char * arg4, const char * arg5, const char * arg6 ) {
|
||||
idSWFTextInstance* idSWFScriptObject::GetNestedText( const char* arg1, const char* arg2, const char* arg3, const char* arg4, const char* arg5, const char* arg6 )
|
||||
{
|
||||
idSWFScriptVar var = GetNestedVar( arg1, arg2, arg3, arg4, arg5, arg6 );
|
||||
return var.ToText();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -551,30 +661,37 @@ idSWFTextInstance * idSWFScriptObject::GetNestedText( const char * arg1, const c
|
|||
idSWFScriptObject::PrintToConsole
|
||||
========================
|
||||
*/
|
||||
void idSWFScriptObject::PrintToConsole() const {
|
||||
if ( variables.Num() > 0 ) {
|
||||
void idSWFScriptObject::PrintToConsole() const
|
||||
{
|
||||
if( variables.Num() > 0 )
|
||||
{
|
||||
idLib::Printf( "%d subelements:\n", variables.Num() );
|
||||
int maxVarLength = 0;
|
||||
|
||||
for ( int i = 0; i < variables.Num(); ++i ) {
|
||||
const idSWFScriptObject::swfNamedVar_t & nv = variables[ i ];
|
||||
|
||||
for( int i = 0; i < variables.Num(); ++i )
|
||||
{
|
||||
const idSWFScriptObject::swfNamedVar_t& nv = variables[ i ];
|
||||
const int nameLength = idStr::Length( nv.name );
|
||||
if ( maxVarLength < nameLength ) {
|
||||
if( maxVarLength < nameLength )
|
||||
{
|
||||
maxVarLength = nameLength;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
maxVarLength += 2; // a little extra padding
|
||||
|
||||
const char * const fmt = va( "%%-%ds %%-10s %%-s\n", maxVarLength );
|
||||
|
||||
const char* const fmt = va( "%%-%ds %%-10s %%-s\n", maxVarLength );
|
||||
idLib::Printf( fmt, "Name", "Type", "Value" );
|
||||
idLib::Printf( "------------------------------------------------------------\n" );
|
||||
for ( int i = 0; i < variables.Num(); ++i ) {
|
||||
const idSWFScriptObject::swfNamedVar_t & nv = variables[ i ];
|
||||
for( int i = 0; i < variables.Num(); ++i )
|
||||
{
|
||||
const idSWFScriptObject::swfNamedVar_t& nv = variables[ i ];
|
||||
idLib::Printf( fmt, nv.name.c_str(), nv.value.TypeOf(),
|
||||
nv.value.ToString().c_str() );
|
||||
nv.value.ToString().c_str() );
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
idLib::Printf( "No subelements\n" );
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue