123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- /*
- ===========================================================================
- Doom 3 BFG Edition GPL Source Code
- 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").
- 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
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
- In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
- If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
- ===========================================================================
- */
- #pragma hdrstop
- #include "../idlib/precompiled.h"
- extern idCVar swf_debugShowAddress;
- /*
- ========================
- idSWFScriptVar::idSWFScriptVar
- ========================
- */
- idSWFScriptVar::idSWFScriptVar( const idSWFScriptVar & other ) {
- type = other.type;
- value = other.value;
- if ( other.type == SWF_VAR_STRING ) {
- other.value.string->AddRef();
- } else if ( other.type == SWF_VAR_OBJECT ) {
- other.value.object->AddRef();
- } else if ( other.type == SWF_VAR_FUNCTION ) {
- other.value.function->AddRef();
- }
- }
- /*
- ========================
- idSWFScriptVar::operator=
- ========================
- */
- idSWFScriptVar & idSWFScriptVar::operator=( const idSWFScriptVar & other ) {
- if ( this != &other ) {
- Free();
- type = other.type;
- value = other.value;
- if ( other.type == SWF_VAR_STRING ) {
- other.value.string->AddRef();
- } else if ( other.type == SWF_VAR_OBJECT ) {
- other.value.object->AddRef();
- } else if ( other.type == SWF_VAR_FUNCTION ) {
- other.value.function->AddRef();
- }
- }
- return *this;
- }
- /*
- ========================
- idSWFScriptVar::~idSWFScriptVar
- ========================
- */
- idSWFScriptVar::~idSWFScriptVar() {
- Free();
- }
- /*
- ========================
- idSWFScriptVar::Free
- ========================
- */
- void idSWFScriptVar::Free() {
- if ( type == SWF_VAR_STRING ) {
- value.string->Release();
- } else if ( type == SWF_VAR_OBJECT ) {
- value.object->Release();
- } else if ( type == SWF_VAR_FUNCTION ) {
- value.function->Release();
- }
- value.string = NULL;
- value.function = NULL;
- value.object = NULL;
- type = SWF_VAR_UNDEF;
- }
- /*
- ========================
- idSWFScriptVar::SetObject
- ========================
- */
- void idSWFScriptVar::SetObject( idSWFScriptObject * o ) {
- Free();
- if ( o == NULL ) {
- type = SWF_VAR_NULL;
- } else {
- type = SWF_VAR_OBJECT;
- value.object = o;
- o->AddRef();
- }
- }
- /*
- ========================
- idSWFScriptVar::SetFunction
- ========================
- */
- void idSWFScriptVar::SetFunction( idSWFScriptFunction * f ) {
- Free();
- if ( f == NULL ) {
- type = SWF_VAR_NULL;
- } else {
- type = SWF_VAR_FUNCTION;
- value.function = f;
- f->AddRef();
- }
- }
- /*
- ========================
- idSWFScriptVar::StrictEquals
- ========================
- */
- 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;
- }
- }
- /*
- ========================
- 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;
- }
- }
- 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;
- }
- 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;
- }
- case SWF_VAR_FUNCTION: return false;
- default: assert( false ); return false;
- }
- }
- /*
- ========================
- 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() ) {
- return va( "[function:%p]", value.function );
- } else {
- return "[function]";
- }
- default: assert( false ); return "";
- }
- }
- /*
- ========================
- 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();
- case SWF_VAR_FUNCTION:
- case SWF_VAR_NULL:
- case SWF_VAR_UNDEF: return 0.0f;
- default: assert( false ); return 0.0f;
- }
- }
- /*
- ========================
- 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();
- case SWF_VAR_FUNCTION:
- case SWF_VAR_NULL:
- case SWF_VAR_UNDEF: return false;
- default: assert( false ); return false;
- }
- }
- /*
- ========================
- 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();
- case SWF_VAR_FUNCTION:
- case SWF_VAR_NULL:
- case SWF_VAR_UNDEF: return 0;
- default: assert( false ); return 0;
- }
- }
- /*
- ========================
- idSWFScriptVar::ToSprite
- ========================
- */
- idSWFSpriteInstance * idSWFScriptVar::ToSprite() {
- if ( IsObject() && value.object != NULL ) {
- return value.object->GetSprite();
- }
- return NULL;
- }
- /*
- ========================
- idSWFScriptVar::ToText
- ========================
- */
- idSWFTextInstance * idSWFScriptVar::ToText() {
- if ( IsObject() && value.object != NULL ) {
- return value.object->GetText();
- }
- return NULL;
- }
- /*
- ========================
- 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() ) {
- return idSWFScriptVar();
- }
- return GetObject()->GetNestedVar( arg1, arg2, arg3, arg4, arg5, arg6 );
- }
- /*
- ========================
- 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() ) {
- return NULL;
- }
- return GetObject()->GetNestedObj( arg1, arg2, arg3, arg4, arg5, arg6 );
- }
- /*
- ========================
- 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() ) {
- return NULL;
- }
- return GetObject()->GetNestedSprite( arg1, arg2, arg3, arg4, arg5, arg6 );
- }
- /*
- ========================
- 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() ) {
- return NULL;
- }
- return GetObject()->GetNestedText( arg1, arg2, arg3, arg4, arg5, arg6 );
- }
- /*
- ========================
- 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 "";
- }
- }
- /*
- ========================
- idSWFScriptVar::PrintToConsole
- ========================
- */
- void idSWFScriptVar::PrintToConsole() const {
- idLib::Printf( "Object type: %s\n", TypeOf() );
- if ( IsObject() ) {
- GetObject()->PrintToConsole();
- } else if ( IsNumeric() ) {
- idLib::Printf( "%d\n", ToInteger() );
- } else if ( IsString() ) {
- idLib::Printf( "%s\n", ToString().c_str() );
- } else {
- idLib::Printf( "unknown\n" );
- }
- }
|