Formatted code using Artistic Style for better readability.

This commit is contained in:
Robert Beckebans 2012-11-28 16:47:07 +01:00
parent d40e661b3e
commit f55a763ca4
701 changed files with 206183 additions and 142961 deletions

View file

@ -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
@ -35,14 +35,20 @@ extern idCVar swf_debugShowAddress;
idSWFScriptVar::idSWFScriptVar
========================
*/
idSWFScriptVar::idSWFScriptVar( const idSWFScriptVar & other ) {
idSWFScriptVar::idSWFScriptVar( const idSWFScriptVar& other )
{
type = other.type;
value = other.value;
if ( other.type == SWF_VAR_STRING ) {
if( other.type == SWF_VAR_STRING )
{
other.value.string->AddRef();
} else if ( other.type == SWF_VAR_OBJECT ) {
}
else if( other.type == SWF_VAR_OBJECT )
{
other.value.object->AddRef();
} else if ( other.type == SWF_VAR_FUNCTION ) {
}
else if( other.type == SWF_VAR_FUNCTION )
{
other.value.function->AddRef();
}
}
@ -52,16 +58,23 @@ idSWFScriptVar::idSWFScriptVar( const idSWFScriptVar & other ) {
idSWFScriptVar::operator=
========================
*/
idSWFScriptVar & idSWFScriptVar::operator=( const idSWFScriptVar & other ) {
if ( this != &other ) {
idSWFScriptVar& idSWFScriptVar::operator=( const idSWFScriptVar& other )
{
if( this != &other )
{
Free();
type = other.type;
value = other.value;
if ( other.type == SWF_VAR_STRING ) {
if( other.type == SWF_VAR_STRING )
{
other.value.string->AddRef();
} else if ( other.type == SWF_VAR_OBJECT ) {
}
else if( other.type == SWF_VAR_OBJECT )
{
other.value.object->AddRef();
} else if ( other.type == SWF_VAR_FUNCTION ) {
}
else if( other.type == SWF_VAR_FUNCTION )
{
other.value.function->AddRef();
}
}
@ -73,7 +86,8 @@ idSWFScriptVar & idSWFScriptVar::operator=( const idSWFScriptVar & other ) {
idSWFScriptVar::~idSWFScriptVar
========================
*/
idSWFScriptVar::~idSWFScriptVar() {
idSWFScriptVar::~idSWFScriptVar()
{
Free();
}
@ -82,12 +96,18 @@ idSWFScriptVar::~idSWFScriptVar() {
idSWFScriptVar::Free
========================
*/
void idSWFScriptVar::Free() {
if ( type == SWF_VAR_STRING ) {
void idSWFScriptVar::Free()
{
if( type == SWF_VAR_STRING )
{
value.string->Release();
} else if ( type == SWF_VAR_OBJECT ) {
}
else if( type == SWF_VAR_OBJECT )
{
value.object->Release();
} else if ( type == SWF_VAR_FUNCTION ) {
}
else if( type == SWF_VAR_FUNCTION )
{
value.function->Release();
}
value.string = NULL;
@ -101,11 +121,15 @@ void idSWFScriptVar::Free() {
idSWFScriptVar::SetObject
========================
*/
void idSWFScriptVar::SetObject( idSWFScriptObject * o ) {
void idSWFScriptVar::SetObject( idSWFScriptObject* o )
{
Free();
if ( o == NULL ) {
if( o == NULL )
{
type = SWF_VAR_NULL;
} else {
}
else
{
type = SWF_VAR_OBJECT;
value.object = o;
o->AddRef();
@ -117,11 +141,15 @@ void idSWFScriptVar::SetObject( idSWFScriptObject * o ) {
idSWFScriptVar::SetFunction
========================
*/
void idSWFScriptVar::SetFunction( idSWFScriptFunction * f ) {
void idSWFScriptVar::SetFunction( idSWFScriptFunction* f )
{
Free();
if ( f == NULL ) {
if( f == NULL )
{
type = SWF_VAR_NULL;
} else {
}
else
{
type = SWF_VAR_FUNCTION;
value.function = f;
f->AddRef();
@ -133,21 +161,35 @@ void idSWFScriptVar::SetFunction( idSWFScriptFunction * f ) {
idSWFScriptVar::StrictEquals
========================
*/
bool idSWFScriptVar::StrictEquals( const idSWFScriptVar & other ) {
if ( type != other.type ) {
bool idSWFScriptVar::StrictEquals( const idSWFScriptVar& other )
{
if( type != other.type )
{
return false;
}
switch ( type ) {
case SWF_VAR_STRINGID: return ( value.i == other.value.i );
case SWF_VAR_STRING: return ( *value.string == *other.value.string );
case SWF_VAR_FLOAT: return ( value.f == other.value.f );
case SWF_VAR_BOOL: return ( value.b == other.value.b );
case SWF_VAR_INTEGER: return ( value.i == other.value.i );
case SWF_VAR_NULL: return true;
case SWF_VAR_UNDEF: return true;
case SWF_VAR_OBJECT: return ( value.object == other.value.object );
case SWF_VAR_FUNCTION: return ( value.function == other.value.function );
default: assert( false ); return false;
switch( type )
{
case SWF_VAR_STRINGID:
return ( value.i == other.value.i );
case SWF_VAR_STRING:
return ( *value.string == *other.value.string );
case SWF_VAR_FLOAT:
return ( value.f == other.value.f );
case SWF_VAR_BOOL:
return ( value.b == other.value.b );
case SWF_VAR_INTEGER:
return ( value.i == other.value.i );
case SWF_VAR_NULL:
return true;
case SWF_VAR_UNDEF:
return true;
case SWF_VAR_OBJECT:
return ( value.object == other.value.object );
case SWF_VAR_FUNCTION:
return ( value.function == other.value.function );
default:
assert( false );
return false;
}
}
@ -156,47 +198,84 @@ bool idSWFScriptVar::StrictEquals( const idSWFScriptVar & other ) {
idSWFScriptVar::AbstractEquals
========================
*/
bool idSWFScriptVar::AbstractEquals( const idSWFScriptVar & other ) {
if ( type == other.type ) {
switch ( type ) {
case SWF_VAR_STRINGID: return ( value.i == other.value.i );
case SWF_VAR_STRING: return ( *value.string == *other.value.string );
case SWF_VAR_FLOAT: return ( value.f == other.value.f );
case SWF_VAR_BOOL: return ( value.b == other.value.b );
case SWF_VAR_INTEGER: return ( value.i == other.value.i );
case SWF_VAR_NULL: return true;
case SWF_VAR_UNDEF: return true;
case SWF_VAR_OBJECT: return ( value.object == other.value.object );
case SWF_VAR_FUNCTION: return ( value.function == other.value.function );
default: assert( false ); return false;
bool idSWFScriptVar::AbstractEquals( const idSWFScriptVar& other )
{
if( type == other.type )
{
switch( type )
{
case SWF_VAR_STRINGID:
return ( value.i == other.value.i );
case SWF_VAR_STRING:
return ( *value.string == *other.value.string );
case SWF_VAR_FLOAT:
return ( value.f == other.value.f );
case SWF_VAR_BOOL:
return ( value.b == other.value.b );
case SWF_VAR_INTEGER:
return ( value.i == other.value.i );
case SWF_VAR_NULL:
return true;
case SWF_VAR_UNDEF:
return true;
case SWF_VAR_OBJECT:
return ( value.object == other.value.object );
case SWF_VAR_FUNCTION:
return ( value.function == other.value.function );
default:
assert( false );
return false;
}
}
switch ( type ) {
case SWF_VAR_STRINGID: return ToString() == other.ToString();
switch( type )
{
case SWF_VAR_STRINGID:
return ToString() == other.ToString();
case SWF_VAR_STRING:
switch ( other.type ) {
case SWF_VAR_STRINGID: return *value.string == other.ToString();
case SWF_VAR_FLOAT: return ToFloat() == other.value.f;
case SWF_VAR_BOOL: return ToBool() == other.value.b;
case SWF_VAR_INTEGER: return ToInteger() == other.value.i;
case SWF_VAR_OBJECT: return *value.string == other.ToString();
default: return false;
switch( other.type )
{
case SWF_VAR_STRINGID:
return *value.string == other.ToString();
case SWF_VAR_FLOAT:
return ToFloat() == other.value.f;
case SWF_VAR_BOOL:
return ToBool() == other.value.b;
case SWF_VAR_INTEGER:
return ToInteger() == other.value.i;
case SWF_VAR_OBJECT:
return *value.string == other.ToString();
default:
return false;
}
case SWF_VAR_FLOAT: return ( other.ToFloat() == value.f );
case SWF_VAR_BOOL: return ( other.ToBool() == value.b );
case SWF_VAR_INTEGER: return ( other.ToInteger() == value.i );
case SWF_VAR_NULL: return ( other.type == SWF_VAR_UNDEF );
case SWF_VAR_UNDEF: return ( other.type == SWF_VAR_NULL );
case SWF_VAR_FLOAT:
return ( other.ToFloat() == value.f );
case SWF_VAR_BOOL:
return ( other.ToBool() == value.b );
case SWF_VAR_INTEGER:
return ( other.ToInteger() == value.i );
case SWF_VAR_NULL:
return ( other.type == SWF_VAR_UNDEF );
case SWF_VAR_UNDEF:
return ( other.type == SWF_VAR_NULL );
case SWF_VAR_OBJECT:
switch ( other.type ) {
case SWF_VAR_STRING: return ToString() == *other.value.string;
case SWF_VAR_FLOAT: return ToFloat() == other.value.f;
case SWF_VAR_BOOL: return ToBool() == other.value.b;
case SWF_VAR_INTEGER: return ToInteger() == other.value.i;
default: return false;
switch( other.type )
{
case SWF_VAR_STRING:
return ToString() == *other.value.string;
case SWF_VAR_FLOAT:
return ToFloat() == other.value.f;
case SWF_VAR_BOOL:
return ToBool() == other.value.b;
case SWF_VAR_INTEGER:
return ToInteger() == other.value.i;
default:
return false;
}
case SWF_VAR_FUNCTION: return false;
default: assert( false ); return false;
case SWF_VAR_FUNCTION:
return false;
default:
assert( false );
return false;
}
}
@ -205,25 +284,40 @@ bool idSWFScriptVar::AbstractEquals( const idSWFScriptVar & other ) {
idSWFScriptVar::ToString
========================
*/
idStr idSWFScriptVar::ToString() const {
switch ( type ) {
case SWF_VAR_STRINGID: return idStrId( value.i ).GetLocalizedString();
case SWF_VAR_STRING: return *value.string;
case SWF_VAR_FLOAT: return va( "%g", value.f );
case SWF_VAR_BOOL: return value.b ? "true" : "false";
case SWF_VAR_INTEGER: return va( "%i", value.i );
case SWF_VAR_NULL: return "[null]";
case SWF_VAR_UNDEF: return "[undefined]";
case SWF_VAR_OBJECT: return value.object->DefaultValue( true ).ToString();
case SWF_VAR_FUNCTION:
if ( swf_debugShowAddress.GetBool() ) {
idStr idSWFScriptVar::ToString() const
{
switch( type )
{
case SWF_VAR_STRINGID:
return idStrId( value.i ).GetLocalizedString();
case SWF_VAR_STRING:
return *value.string;
case SWF_VAR_FLOAT:
return va( "%g", value.f );
case SWF_VAR_BOOL:
return value.b ? "true" : "false";
case SWF_VAR_INTEGER:
return va( "%i", value.i );
case SWF_VAR_NULL:
return "[null]";
case SWF_VAR_UNDEF:
return "[undefined]";
case SWF_VAR_OBJECT:
return value.object->DefaultValue( true ).ToString();
case SWF_VAR_FUNCTION:
if( swf_debugShowAddress.GetBool() )
{
return va( "[function:%p]", value.function );
} else {
}
else
{
return "[function]";
}
default: assert( false ); return "";
default:
assert( false );
return "";
}
}
@ -232,20 +326,30 @@ idStr idSWFScriptVar::ToString() const {
idSWFScriptVar::ToFloat
========================
*/
float idSWFScriptVar::ToFloat() const {
switch ( type ) {
case SWF_VAR_STRING: return atof( *value.string );
case SWF_VAR_FLOAT: return value.f;
case SWF_VAR_BOOL: return (float)value.b;
case SWF_VAR_INTEGER: return (float)value.i;
case SWF_VAR_OBJECT: return value.object->DefaultValue( false ).ToFloat();
float idSWFScriptVar::ToFloat() const
{
switch( type )
{
case SWF_VAR_STRING:
return atof( *value.string );
case SWF_VAR_FLOAT:
return value.f;
case SWF_VAR_BOOL:
return ( float )value.b;
case SWF_VAR_INTEGER:
return ( float )value.i;
case SWF_VAR_OBJECT:
return value.object->DefaultValue( false ).ToFloat();
case SWF_VAR_FUNCTION:
case SWF_VAR_NULL:
case SWF_VAR_UNDEF: return 0.0f;
default: assert( false ); return 0.0f;
case SWF_VAR_UNDEF:
return 0.0f;
default:
assert( false );
return 0.0f;
}
}
@ -254,20 +358,30 @@ float idSWFScriptVar::ToFloat() const {
idSWFScriptVar::ToBool
========================
*/
bool idSWFScriptVar::ToBool() const {
switch ( type ) {
case SWF_VAR_STRING: return ( value.string->Icmp( "true" ) == 0 || value.string->Icmp( "1" ) == 0 );
case SWF_VAR_FLOAT: return ( value.f != 0.0f );
case SWF_VAR_BOOL: return value.b;
case SWF_VAR_INTEGER: return value.i != 0;
case SWF_VAR_OBJECT: return value.object->DefaultValue( false ).ToBool();
bool idSWFScriptVar::ToBool() const
{
switch( type )
{
case SWF_VAR_STRING:
return ( value.string->Icmp( "true" ) == 0 || value.string->Icmp( "1" ) == 0 );
case SWF_VAR_FLOAT:
return ( value.f != 0.0f );
case SWF_VAR_BOOL:
return value.b;
case SWF_VAR_INTEGER:
return value.i != 0;
case SWF_VAR_OBJECT:
return value.object->DefaultValue( false ).ToBool();
case SWF_VAR_FUNCTION:
case SWF_VAR_NULL:
case SWF_VAR_UNDEF: return false;
default: assert( false ); return false;
case SWF_VAR_UNDEF:
return false;
default:
assert( false );
return false;
}
}
@ -276,21 +390,31 @@ bool idSWFScriptVar::ToBool() const {
idSWFScriptVar::ToInteger
========================
*/
int32 idSWFScriptVar::ToInteger() const {
switch ( type ) {
case SWF_VAR_STRING: return atoi( *value.string );
case SWF_VAR_FLOAT: return idMath::Ftoi( value.f );
case SWF_VAR_BOOL: return value.b ? 1 : 0;
case SWF_VAR_INTEGER: return value.i;
case SWF_VAR_OBJECT: return value.object->DefaultValue( false ).ToInteger();
int32 idSWFScriptVar::ToInteger() const
{
switch( type )
{
case SWF_VAR_STRING:
return atoi( *value.string );
case SWF_VAR_FLOAT:
return idMath::Ftoi( value.f );
case SWF_VAR_BOOL:
return value.b ? 1 : 0;
case SWF_VAR_INTEGER:
return value.i;
case SWF_VAR_OBJECT:
return value.object->DefaultValue( false ).ToInteger();
case SWF_VAR_FUNCTION:
case SWF_VAR_NULL:
case SWF_VAR_UNDEF: return 0;
default: assert( false ); return 0;
case SWF_VAR_UNDEF:
return 0;
default:
assert( false );
return 0;
}
}
@ -299,11 +423,13 @@ int32 idSWFScriptVar::ToInteger() const {
idSWFScriptVar::ToSprite
========================
*/
idSWFSpriteInstance * idSWFScriptVar::ToSprite() {
if ( IsObject() && value.object != NULL ) {
idSWFSpriteInstance* idSWFScriptVar::ToSprite()
{
if( IsObject() && value.object != NULL )
{
return value.object->GetSprite();
}
return NULL;
}
@ -312,11 +438,13 @@ idSWFSpriteInstance * idSWFScriptVar::ToSprite() {
idSWFScriptVar::ToText
========================
*/
idSWFTextInstance * idSWFScriptVar::ToText() {
if ( IsObject() && value.object != NULL ) {
idSWFTextInstance* idSWFScriptVar::ToText()
{
if( IsObject() && value.object != NULL )
{
return value.object->GetText();
}
return NULL;
}
@ -325,11 +453,13 @@ idSWFTextInstance * idSWFScriptVar::ToText() {
idSWFScriptVar::GetNestedVar
========================
*/
idSWFScriptVar idSWFScriptVar::GetNestedVar( const char * arg1, const char * arg2, const char * arg3, const char * arg4, const char * arg5, const char * arg6 ) {
if ( !IsObject() ) {
idSWFScriptVar idSWFScriptVar::GetNestedVar( const char* arg1, const char* arg2, const char* arg3, const char* arg4, const char* arg5, const char* arg6 )
{
if( !IsObject() )
{
return idSWFScriptVar();
}
return GetObject()->GetNestedVar( arg1, arg2, arg3, arg4, arg5, arg6 );
}
@ -338,11 +468,13 @@ idSWFScriptVar idSWFScriptVar::GetNestedVar( const char * arg1, const char * arg
idSWFScriptVar::GetNestedObj
========================
*/
idSWFScriptObject * idSWFScriptVar::GetNestedObj( const char * arg1, const char * arg2, const char * arg3, const char * arg4, const char * arg5, const char * arg6 ) {
if ( !IsObject() ) {
idSWFScriptObject* idSWFScriptVar::GetNestedObj( const char* arg1, const char* arg2, const char* arg3, const char* arg4, const char* arg5, const char* arg6 )
{
if( !IsObject() )
{
return NULL;
}
return GetObject()->GetNestedObj( arg1, arg2, arg3, arg4, arg5, arg6 );
}
@ -351,11 +483,13 @@ idSWFScriptObject * idSWFScriptVar::GetNestedObj( const char * arg1, const char
idSWFScriptVar::GetNestedSprite
========================
*/
idSWFSpriteInstance * idSWFScriptVar::GetNestedSprite( const char * arg1, const char * arg2, const char * arg3, const char * arg4, const char * arg5, const char * arg6 ) {
if ( !IsObject() ) {
idSWFSpriteInstance* idSWFScriptVar::GetNestedSprite( const char* arg1, const char* arg2, const char* arg3, const char* arg4, const char* arg5, const char* arg6 )
{
if( !IsObject() )
{
return NULL;
}
return GetObject()->GetNestedSprite( arg1, arg2, arg3, arg4, arg5, arg6 );
}
@ -364,11 +498,13 @@ idSWFSpriteInstance * idSWFScriptVar::GetNestedSprite( const char * arg1, const
idSWFScriptVar::GetNestedSprite
========================
*/
idSWFTextInstance * idSWFScriptVar::GetNestedText( const char * arg1, const char * arg2, const char * arg3, const char * arg4, const char * arg5, const char * arg6 ) {
if ( !IsObject() ) {
idSWFTextInstance* idSWFScriptVar::GetNestedText( const char* arg1, const char* arg2, const char* arg3, const char* arg4, const char* arg5, const char* arg6 )
{
if( !IsObject() )
{
return NULL;
}
return GetObject()->GetNestedText( arg1, arg2, arg3, arg4, arg5, arg6 );
}
@ -377,28 +513,45 @@ idSWFTextInstance * idSWFScriptVar::GetNestedText( const char * arg1, const char
idSWFScriptVar::TypeOf
========================
*/
const char * idSWFScriptVar::TypeOf() const {
switch ( type ) {
case SWF_VAR_STRINGID: return "stringid";
case SWF_VAR_STRING: return "string";
case SWF_VAR_FLOAT: return "number";
case SWF_VAR_BOOL: return "boolean";
case SWF_VAR_INTEGER: return "number";
case SWF_VAR_OBJECT:
if ( value.object->GetSprite() != NULL ) {
return "movieclip";
} else if ( value.object->GetText() != NULL ) {
return "text";
} else {
return "object";
}
case SWF_VAR_FUNCTION: return "function";
case SWF_VAR_NULL: return "null";
case SWF_VAR_UNDEF: return "undefined";
default: assert( false ); return "";
const char* idSWFScriptVar::TypeOf() const
{
switch( type )
{
case SWF_VAR_STRINGID:
return "stringid";
case SWF_VAR_STRING:
return "string";
case SWF_VAR_FLOAT:
return "number";
case SWF_VAR_BOOL:
return "boolean";
case SWF_VAR_INTEGER:
return "number";
case SWF_VAR_OBJECT:
if( value.object->GetSprite() != NULL )
{
return "movieclip";
}
else if( value.object->GetText() != NULL )
{
return "text";
}
else
{
return "object";
}
case SWF_VAR_FUNCTION:
return "function";
case SWF_VAR_NULL:
return "null";
case SWF_VAR_UNDEF:
return "undefined";
default:
assert( false );
return "";
}
}
@ -407,16 +560,24 @@ const char * idSWFScriptVar::TypeOf() const {
idSWFScriptVar::PrintToConsole
========================
*/
void idSWFScriptVar::PrintToConsole() const {
void idSWFScriptVar::PrintToConsole() const
{
idLib::Printf( "Object type: %s\n", TypeOf() );
if ( IsObject() ) {
if( IsObject() )
{
GetObject()->PrintToConsole();
} else if ( IsNumeric() ) {
}
else if( IsNumeric() )
{
idLib::Printf( "%d\n", ToInteger() );
} else if ( IsString() ) {
}
else if( IsString() )
{
idLib::Printf( "%s\n", ToString().c_str() );
} else {
}
else
{
idLib::Printf( "unknown\n" );
}
}