2012-11-26 18:58:24 +00:00
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Doom 3 BFG Edition GPL Source Code
2012-11-28 15:47:07 +00:00
Copyright ( C ) 1993 - 2012 id Software LLC , a ZeniMax Media company .
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
This file is part of the Doom 3 BFG Edition GPL Source Code ( " Doom 3 BFG Edition Source Code " ) .
2012-11-26 18:58:24 +00:00
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"
idSWFScriptObject_SpriteInstancePrototype spriteInstanceScriptObjectPrototype ;
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : idSWFSpriteInstance
= = = = = = = = = = = = = = = = = = = = = = = =
*/
idSWFSpriteInstance : : idSWFSpriteInstance ( ) :
2012-11-28 15:47:07 +00:00
isPlaying ( true ) ,
isVisible ( true ) ,
childrenRunning ( true ) ,
2012-12-11 22:48:55 +00:00
firstRun ( false ) ,
2012-11-28 15:47:07 +00:00
currentFrame ( 0 ) ,
2012-12-11 22:48:55 +00:00
frameCount ( 0 ) ,
sprite ( NULL ) ,
parent ( NULL ) ,
depth ( 0 ) ,
2012-11-28 15:47:07 +00:00
itemIndex ( 0 ) ,
materialOverride ( NULL ) ,
materialWidth ( 0 ) ,
materialHeight ( 0 ) ,
xOffset ( 0.0f ) ,
yOffset ( 0.0f ) ,
moveToXScale ( 1.0f ) ,
moveToYScale ( 1.0f ) ,
moveToSpeed ( 1.0f ) ,
stereoDepth ( 0 )
2012-11-26 18:58:24 +00:00
{
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : Init
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : Init ( idSWFSprite * _sprite , idSWFSpriteInstance * _parent , int _depth )
{
2012-11-26 18:58:24 +00:00
sprite = _sprite ;
parent = _parent ;
depth = _depth ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
frameCount = sprite - > frameCount ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
scriptObject = idSWFScriptObject : : Alloc ( ) ;
scriptObject - > SetPrototype ( & spriteInstanceScriptObjectPrototype ) ;
scriptObject - > SetSprite ( this ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
firstRun = true ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
actionScript = idSWFScriptFunction_Script : : Alloc ( ) ;
2012-11-28 15:47:07 +00:00
idList < idSWFScriptObject * , TAG_SWF > scope ;
2012-11-26 18:58:24 +00:00
scope . Append ( sprite - > swf - > globals ) ;
scope . Append ( scriptObject ) ;
actionScript - > SetScope ( scope ) ;
actionScript - > SetDefaultSprite ( this ) ;
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < sprite - > doInitActions . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
actionScript - > SetData ( sprite - > doInitActions [ i ] . Ptr ( ) , sprite - > doInitActions [ i ] . Length ( ) ) ;
actionScript - > Call ( scriptObject , idSWFParmList ( ) ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Play ( ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : ~ idSWFSpriteInstance
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idSWFSpriteInstance : : ~ idSWFSpriteInstance ( )
{
if ( parent ! = NULL )
{
2012-11-26 18:58:24 +00:00
parent - > scriptObject - > Set ( name , idSWFScriptVar ( ) ) ;
}
FreeDisplayList ( ) ;
displayList . Clear ( ) ;
scriptObject - > SetSprite ( NULL ) ;
scriptObject - > Clear ( ) ;
scriptObject - > Release ( ) ;
actionScript - > Release ( ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : FreeDisplayList
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : FreeDisplayList ( )
{
for ( int i = 0 ; i < displayList . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
sprite - > swf - > spriteInstanceAllocator . Free ( displayList [ i ] . spriteInstance ) ;
sprite - > swf - > textInstanceAllocator . Free ( displayList [ i ] . textInstance ) ;
}
displayList . SetNum ( 0 ) ; // not calling Clear() so we don't continuously re-allocate memory
currentFrame = 0 ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : FindDisplayEntry
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * idSWFSpriteInstance : : FindDisplayEntry ( int depth )
{
2012-11-26 18:58:24 +00:00
int len = displayList . Num ( ) ;
int mid = len ;
int offset = 0 ;
2012-11-28 15:47:07 +00:00
while ( mid > 0 )
{
2012-11-26 18:58:24 +00:00
mid = len > > 1 ;
2012-11-28 15:47:07 +00:00
if ( displayList [ offset + mid ] . depth < = depth )
{
2012-11-26 18:58:24 +00:00
offset + = mid ;
}
len - = mid ;
}
2012-11-28 15:47:07 +00:00
if ( displayList [ offset ] . depth = = depth )
{
2012-11-26 18:58:24 +00:00
return & displayList [ offset ] ;
}
return NULL ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : AddDisplayEntry
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * idSWFSpriteInstance : : AddDisplayEntry ( int depth , int characterID )
{
2012-11-26 18:58:24 +00:00
int i = 0 ;
2012-11-28 15:47:07 +00:00
for ( ; i < displayList . Num ( ) ; i + + )
{
if ( displayList [ i ] . depth = = depth )
{
2012-11-26 18:58:24 +00:00
return NULL ;
}
2012-11-28 15:47:07 +00:00
if ( displayList [ i ] . depth > depth )
{
2012-11-26 18:58:24 +00:00
break ;
}
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t & display = displayList [ displayList . Insert ( swfDisplayEntry_t ( ) , i ) ] ;
2012-11-26 18:58:24 +00:00
display . depth = depth ;
display . characterID = characterID ;
2012-11-28 15:47:07 +00:00
idSWFDictionaryEntry * dictEntry = sprite - > swf - > FindDictionaryEntry ( characterID ) ;
if ( dictEntry ! = NULL )
{
if ( dictEntry - > type = = SWF_DICT_SPRITE )
{
2012-11-26 18:58:24 +00:00
display . spriteInstance = sprite - > swf - > spriteInstanceAllocator . Alloc ( ) ;
display . spriteInstance - > Init ( dictEntry - > sprite , this , depth ) ;
display . spriteInstance - > RunTo ( 1 ) ;
2012-11-28 15:47:07 +00:00
}
else if ( dictEntry - > type = = SWF_DICT_EDITTEXT )
{
2012-11-26 18:58:24 +00:00
display . textInstance = sprite - > swf - > textInstanceAllocator . Alloc ( ) ;
display . textInstance - > Init ( dictEntry - > edittext , sprite - > GetSWF ( ) ) ;
}
}
return & display ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : RemoveDisplayEntry
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : RemoveDisplayEntry ( int depth )
{
swfDisplayEntry_t * entry = FindDisplayEntry ( depth ) ;
if ( entry ! = NULL )
{
2012-11-26 18:58:24 +00:00
sprite - > swf - > spriteInstanceAllocator . Free ( entry - > spriteInstance ) ;
sprite - > swf - > textInstanceAllocator . Free ( entry - > textInstance ) ;
displayList . RemoveIndex ( displayList . IndexOf ( entry ) ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
2012-11-28 15:47:07 +00:00
idSort_SpriteDepth
2012-11-26 18:58:24 +00:00
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
class idSort_SpriteDepth : public idSort_Quick < swfDisplayEntry_t , idSort_SpriteDepth >
{
2012-11-26 18:58:24 +00:00
public :
2012-11-28 15:47:07 +00:00
int Compare ( const swfDisplayEntry_t & a , const swfDisplayEntry_t & b ) const
{
return a . depth - b . depth ;
}
2012-11-26 18:58:24 +00:00
} ;
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : SwapDepths
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : SwapDepths ( int depth1 , int depth2 )
{
for ( int i = 0 ; i < displayList . Num ( ) ; i + + )
{
if ( displayList [ i ] . depth = = depth1 )
{
2012-11-26 18:58:24 +00:00
displayList [ i ] . depth = depth2 ;
2012-11-28 15:47:07 +00:00
}
else if ( displayList [ i ] . depth = = depth2 )
{
2012-11-26 18:58:24 +00:00
displayList [ i ] . depth = depth1 ;
}
2012-11-28 15:47:07 +00:00
if ( displayList [ i ] . spriteInstance ! = NULL )
{
2012-11-26 18:58:24 +00:00
displayList [ i ] . spriteInstance - > depth = displayList [ i ] . depth ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
displayList . SortWithTemplate ( idSort_SpriteDepth ( ) ) ;
}
/*
= = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : Run
= = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idSWFSpriteInstance : : Run ( )
{
if ( ! isVisible )
{
2012-11-26 18:58:24 +00:00
return false ;
}
2012-11-28 15:47:07 +00:00
if ( childrenRunning )
{
2012-11-26 18:58:24 +00:00
childrenRunning = false ;
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < displayList . Num ( ) ; i + + )
{
if ( displayList [ i ] . spriteInstance ! = NULL )
{
2012-11-26 18:58:24 +00:00
Prefetch ( displayList [ i ] . spriteInstance , 0 ) ;
}
}
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < displayList . Num ( ) ; i + + )
{
if ( displayList [ i ] . spriteInstance ! = NULL )
{
2012-11-26 18:58:24 +00:00
childrenRunning | = displayList [ i ] . spriteInstance - > Run ( ) ;
}
}
}
2012-11-28 15:47:07 +00:00
if ( isPlaying )
{
if ( currentFrame = = frameCount )
{
if ( frameCount > 1 )
{
2012-11-26 18:58:24 +00:00
FreeDisplayList ( ) ;
RunTo ( 1 ) ;
}
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
RunTo ( currentFrame + 1 ) ;
}
}
return childrenRunning | | isPlaying ;
}
/*
= = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : RunActions
= = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idSWFSpriteInstance : : RunActions ( )
{
if ( ! isVisible )
{
2012-11-26 18:58:24 +00:00
actions . SetNum ( 0 ) ;
return false ;
}
2012-11-28 15:47:07 +00:00
if ( firstRun & & scriptObject - > HasProperty ( " onLoad " ) )
{
2012-11-26 18:58:24 +00:00
firstRun = false ;
idSWFScriptVar onLoad = scriptObject - > Get ( " onLoad " ) ;
onLoad . GetFunction ( ) - > Call ( scriptObject , idSWFParmList ( ) ) ;
}
2012-11-28 15:47:07 +00:00
if ( onEnterFrame . IsFunction ( ) )
{
2012-11-26 18:58:24 +00:00
onEnterFrame . GetFunction ( ) - > Call ( scriptObject , idSWFParmList ( ) ) ;
}
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < actions . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
actionScript - > SetData ( actions [ i ] . data , actions [ i ] . dataLength ) ;
actionScript - > Call ( scriptObject , idSWFParmList ( ) ) ;
}
actions . SetNum ( 0 ) ;
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < displayList . Num ( ) ; i + + )
{
if ( displayList [ i ] . spriteInstance ! = NULL )
{
2012-11-26 18:58:24 +00:00
Prefetch ( displayList [ i ] . spriteInstance , 0 ) ;
}
}
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < displayList . Num ( ) ; i + + )
{
if ( displayList [ i ] . spriteInstance ! = NULL )
{
2012-11-26 18:58:24 +00:00
displayList [ i ] . spriteInstance - > RunActions ( ) ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
return true ;
}
/*
= = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : NextFrame
= = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : NextFrame ( )
{
if ( currentFrame < frameCount )
{
2012-11-26 18:58:24 +00:00
RunTo ( currentFrame + 1 ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : PrevFrame
= = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : PrevFrame ( )
{
if ( currentFrame > 1 )
{
2012-11-26 18:58:24 +00:00
RunTo ( currentFrame - 1 ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : Play
= = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : Play ( )
{
for ( idSWFSpriteInstance * p = parent ; p ! = NULL ; p = p - > parent )
{
2012-11-26 18:58:24 +00:00
p - > childrenRunning = true ;
}
isPlaying = true ;
}
/*
= = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : Stop
= = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : Stop ( )
{
2012-11-26 18:58:24 +00:00
isPlaying = false ;
}
/*
= = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : RunTo
= = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : RunTo ( int targetFrame )
{
if ( targetFrame = = currentFrame )
{
2012-11-26 18:58:24 +00:00
return ; // otherwise we'll re-run the current frame
}
2012-11-28 15:47:07 +00:00
if ( targetFrame < currentFrame )
{
2012-11-26 18:58:24 +00:00
FreeDisplayList ( ) ;
}
2012-11-28 15:47:07 +00:00
if ( targetFrame < 1 )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
if ( targetFrame > sprite - > frameOffsets . Num ( ) - 1 )
{
2012-11-26 18:58:24 +00:00
targetFrame = sprite - > frameOffsets . Num ( ) - 1 ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
//actions.Clear();
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
uint32 firstActionCommand = sprite - > frameOffsets [ targetFrame - 1 ] ;
2012-11-28 15:47:07 +00:00
for ( uint32 c = sprite - > frameOffsets [ currentFrame ] ; c < sprite - > frameOffsets [ targetFrame ] ; c + + )
{
idSWFSprite : : swfSpriteCommand_t & command = sprite - > commands [ c ] ;
if ( command . tag = = Tag_DoAction & & c < firstActionCommand )
{
2012-11-26 18:58:24 +00:00
// Skip DoAction up to the firstActionCommand
// This is to properly support skipping to a specific frame
// for example if we're on frame 3 and skipping to frame 10, we want
// to run all the commands PlaceObject commands for frames 4-10 but
// only the DoAction commands for frame 10
continue ;
}
command . stream . Rewind ( ) ;
2012-11-28 15:47:07 +00:00
switch ( command . tag )
{
2012-11-26 18:58:24 +00:00
# define HANDLE_SWF_TAG( x ) case Tag_##x: x( command.stream ); break;
2012-11-28 15:47:07 +00:00
HANDLE_SWF_TAG ( PlaceObject2 ) ;
HANDLE_SWF_TAG ( PlaceObject3 ) ;
HANDLE_SWF_TAG ( RemoveObject2 ) ;
HANDLE_SWF_TAG ( StartSound ) ;
HANDLE_SWF_TAG ( DoAction ) ;
2012-11-26 18:58:24 +00:00
# undef HANDLE_SWF_TAG
2012-11-28 15:47:07 +00:00
default :
idLib : : Printf ( " Run Sprite: Unhandled tag %s \n " , idSWF : : GetTagName ( command . tag ) ) ;
2012-11-26 18:58:24 +00:00
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
currentFrame = targetFrame ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : DoAction
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : DoAction ( idSWFBitStream & bitstream )
{
swfAction_t & action = actions . Alloc ( ) ;
2012-11-26 18:58:24 +00:00
action . data = bitstream . ReadData ( bitstream . Length ( ) ) ;
action . dataLength = bitstream . Length ( ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : FindChildSprite
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idSWFSpriteInstance * idSWFSpriteInstance : : FindChildSprite ( const char * targetName )
{
for ( int i = 0 ; i < displayList . Num ( ) ; i + + )
{
if ( displayList [ i ] . spriteInstance ! = NULL )
{
if ( displayList [ i ] . spriteInstance - > name . Icmp ( targetName ) = = 0 )
{
2012-11-26 18:58:24 +00:00
return displayList [ i ] . spriteInstance ;
}
}
}
return NULL ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : ResolveTarget
Gets the sprite instance for names like :
. . / foo / bar
/ foo / bar
foo / bar
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idSWFSpriteInstance * idSWFSpriteInstance : : ResolveTarget ( const char * targetName )
{
if ( targetName [ 0 ] = = 0 )
{
2012-11-26 18:58:24 +00:00
return this ;
}
2012-11-28 15:47:07 +00:00
idSWFSpriteInstance * target = this ;
const char * c = targetName ;
if ( c [ 0 ] = = ' / ' )
{
while ( target - > parent ! = NULL )
{
2012-11-26 18:58:24 +00:00
target = target - > parent ;
}
c + + ;
}
idStrList spriteNames ;
spriteNames . Append ( c ) ;
2012-11-28 15:47:07 +00:00
for ( int index = 0 , ofs = spriteNames [ index ] . Find ( ' / ' ) ; ofs ! = - 1 ; index + + , ofs = spriteNames [ index ] . Find ( ' / ' ) )
{
2012-11-26 18:58:24 +00:00
spriteNames . Append ( spriteNames [ index ] . c_str ( ) + ofs + 1 ) ;
spriteNames [ index ] . CapLength ( ofs ) ;
}
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < spriteNames . Num ( ) ; i + + )
{
if ( spriteNames [ i ] = = " .. " )
{
2012-11-26 18:58:24 +00:00
target = target - > parent ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
target = target - > FindChildSprite ( spriteNames [ i ] ) ;
}
2012-11-28 15:47:07 +00:00
if ( target = = NULL )
{
2012-11-26 18:58:24 +00:00
// Everything is likely to fail after this point
idLib : : Warning ( " SWF: Could not resolve %s, %s not found " , targetName , spriteNames [ i ] . c_str ( ) ) ;
return this ;
}
}
return target ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : FindFrame
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
uint32 idSWFSpriteInstance : : FindFrame ( const char * labelName ) const
{
2012-11-26 18:58:24 +00:00
int frameNum = atoi ( labelName ) ;
2012-11-28 15:47:07 +00:00
if ( frameNum > 0 )
{
2012-11-26 18:58:24 +00:00
return frameNum ;
}
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < sprite - > frameLabels . Num ( ) ; i + + )
{
if ( sprite - > frameLabels [ i ] . frameLabel . Icmp ( labelName ) = = 0 )
{
2012-11-26 18:58:24 +00:00
return sprite - > frameLabels [ i ] . frameNum ;
}
}
idLib : : Warning ( " Could not find frame '%s' in sprite '%s' " , labelName , GetName ( ) ) ;
return currentFrame ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : FrameExists
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idSWFSpriteInstance : : FrameExists ( const char * labelName ) const
{
2012-11-26 18:58:24 +00:00
int frameNum = atoi ( labelName ) ;
2012-11-28 15:47:07 +00:00
if ( frameNum > 0 )
{
2012-11-26 18:58:24 +00:00
return frameNum < = sprite - > frameCount ;
}
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < sprite - > frameLabels . Num ( ) ; i + + )
{
if ( sprite - > frameLabels [ i ] . frameLabel . Icmp ( labelName ) = = 0 )
{
2012-11-26 18:58:24 +00:00
return true ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
return false ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : IsBetweenFrames
Checks if the current frame is between the given inclusive range .
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idSWFSpriteInstance : : IsBetweenFrames ( const char * frameLabel1 , const char * frameLabel2 ) const
{
2012-11-26 18:58:24 +00:00
return currentFrame > = FindFrame ( frameLabel1 ) & & currentFrame < = FindFrame ( frameLabel2 ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : SetMaterial
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : SetMaterial ( const idMaterial * material , int width , int height )
{
2012-11-26 18:58:24 +00:00
materialOverride = material ;
2012-11-28 15:47:07 +00:00
if ( materialOverride ! = NULL )
{
2012-11-26 18:58:24 +00:00
// Converting this to a short should be safe since we don't support images larger than 8k anyway
2012-11-28 15:47:07 +00:00
if ( materialOverride - > GetStage ( 0 ) ! = NULL & & materialOverride - > GetStage ( 0 ) - > texture . cinematic ! = NULL )
{
2012-11-26 18:58:24 +00:00
materialWidth = 256 ;
materialHeight = 256 ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
assert ( materialOverride - > GetImageWidth ( ) > 0 & & materialOverride - > GetImageHeight ( ) > 0 ) ;
assert ( materialOverride - > GetImageWidth ( ) < = 8192 & & materialOverride - > GetImageHeight ( ) < = 8192 ) ;
2012-11-28 15:47:07 +00:00
materialWidth = ( uint16 ) materialOverride - > GetImageWidth ( ) ;
materialHeight = ( uint16 ) materialOverride - > GetImageHeight ( ) ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
materialWidth = 0 ;
materialHeight = 0 ;
}
2012-11-28 15:47:07 +00:00
if ( width > = 0 )
{
materialWidth = ( uint16 ) width ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
if ( height > = 0 )
{
materialHeight = ( uint16 ) height ;
2012-11-26 18:58:24 +00:00
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : SetVisible
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : SetVisible ( bool visible )
{
2012-11-26 18:58:24 +00:00
isVisible = visible ;
2012-11-28 15:47:07 +00:00
if ( isVisible )
{
for ( idSWFSpriteInstance * p = parent ; p ! = NULL ; p = p - > parent )
{
2012-11-26 18:58:24 +00:00
p - > childrenRunning = true ;
}
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : PlayFrame
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : PlayFrame ( const idSWFParmList & parms )
{
if ( parms . Num ( ) > 0 )
{
2012-11-26 18:58:24 +00:00
actions . Clear ( ) ;
RunTo ( FindFrame ( parms [ 0 ] . ToString ( ) ) ) ;
Play ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " gotoAndPlay: expected 1 paramater " ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : StopFrame
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : StopFrame ( const idSWFParmList & parms )
{
if ( parms . Num ( ) > 0 )
{
if ( parms [ 0 ] . IsNumeric ( ) & & parms [ 0 ] . ToInteger ( ) < 1 )
{
2012-11-26 18:58:24 +00:00
RunTo ( FindFrame ( " 1 " ) ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
RunTo ( FindFrame ( parms [ 0 ] . ToString ( ) ) ) ;
}
Stop ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " gotoAndStop: expected 1 paramater " ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : GetXPos
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
float idSWFSpriteInstance : : GetXPos ( ) const
{
if ( parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return 0.0f ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = parent - > FindDisplayEntry ( depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = this )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " GetXPos: Couldn't find our display entry in our parent's display list for depth %d " , depth ) ;
return 0.0f ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
return thisDisplayEntry - > matrix . tx ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : GetYPos
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
float idSWFSpriteInstance : : GetYPos ( bool overallPos ) const
{
if ( parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return 0.0f ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = parent - > FindDisplayEntry ( depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = this )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " GetYPos: Couldn't find our display entry in our parents display list for depth %d " , depth ) ;
return 0.0f ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
return thisDisplayEntry - > matrix . ty ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : SetXPos
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : SetXPos ( float xPos )
{
if ( parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = parent - > FindDisplayEntry ( depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = this )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _y: Couldn't find our display entry in our parents display list " ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
thisDisplayEntry - > matrix . tx = xPos ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : SetYPos
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : SetYPos ( float yPos )
{
if ( parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = parent - > FindDisplayEntry ( depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = this )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _y: Couldn't find our display entry in our parents display list " ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
thisDisplayEntry - > matrix . ty = yPos ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : SetPos
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : SetPos ( float xPos , float yPos )
{
if ( parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = parent - > FindDisplayEntry ( depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = this )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _y: Couldn't find our display entry in our parents display list " ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
thisDisplayEntry - > matrix . tx = xPos ;
thisDisplayEntry - > matrix . ty = yPos ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : SetRotation
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : SetRotation ( float rot )
{
if ( parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = parent - > FindDisplayEntry ( depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = this )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _rotation: Couldn't find our display entry in our parents display list " ) ;
return ;
}
2012-11-28 15:47:07 +00:00
swfMatrix_t & matrix = thisDisplayEntry - > matrix ;
float xscale = matrix . Scale ( idVec2 ( 1.0f , 0.0f ) ) . Length ( ) ;
float yscale = matrix . Scale ( idVec2 ( 0.0f , 1.0f ) ) . Length ( ) ;
2012-11-26 18:58:24 +00:00
float s , c ;
2012-11-28 15:47:07 +00:00
idMath : : SinCos ( DEG2RAD ( rot ) , s , c ) ;
2012-11-26 18:58:24 +00:00
matrix . xx = c * xscale ;
matrix . yx = s * xscale ;
matrix . xy = - s * yscale ;
matrix . yy = c * yscale ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : SetScale
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : SetScale ( float x , float y )
{
if ( parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = parent - > FindDisplayEntry ( depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = this )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " scale: Couldn't find our display entry in our parents display list " ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
float newScale = x / 100.0f ;
// this is done funky to maintain the current rotation
idVec2 currentScale = thisDisplayEntry - > matrix . Scale ( idVec2 ( 1.0f , 0.0f ) ) ;
2012-11-28 15:47:07 +00:00
if ( currentScale . Normalize ( ) = = 0.0f )
{
2012-11-26 18:58:24 +00:00
thisDisplayEntry - > matrix . xx = newScale ;
thisDisplayEntry - > matrix . yx = 0.0f ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
thisDisplayEntry - > matrix . xx = currentScale . x * newScale ;
thisDisplayEntry - > matrix . yx = currentScale . y * newScale ;
}
newScale = y / 100.0f ;
// this is done funky to maintain the current rotation
currentScale = thisDisplayEntry - > matrix . Scale ( idVec2 ( 0.0f , 1.0f ) ) ;
2012-11-28 15:47:07 +00:00
if ( currentScale . Normalize ( ) = = 0.0f )
{
2012-11-26 18:58:24 +00:00
thisDisplayEntry - > matrix . yy = newScale ;
thisDisplayEntry - > matrix . xy = 0.0f ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
thisDisplayEntry - > matrix . yy = currentScale . y * newScale ;
thisDisplayEntry - > matrix . xy = currentScale . x * newScale ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : SetMoveToScale
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : SetMoveToScale ( float x , float y )
{
2012-11-26 18:58:24 +00:00
moveToXScale = x ;
moveToYScale = y ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : SetMoveToScale
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idSWFSpriteInstance : : UpdateMoveToScale ( float speed )
{
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
if ( parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return false ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = parent - > FindDisplayEntry ( depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = this )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " SetMoveToScale: Couldn't find our display entry in our parents display list " ) ;
return false ;
}
2012-11-28 15:47:07 +00:00
swfMatrix_t & matrix = thisDisplayEntry - > matrix ;
float xscale = matrix . Scale ( idVec2 ( 1.0f , 0.0f ) ) . Length ( ) * 100.0f ;
2012-11-26 18:58:24 +00:00
float yscale = matrix . Scale ( idVec2 ( 0.0f , 1.0f ) ) . Length ( ) * 100.0f ;
float toX = xscale ;
2012-11-28 15:47:07 +00:00
if ( moveToXScale > = 0.0f )
{
2012-11-26 18:58:24 +00:00
toX = moveToXScale * 100.0f ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
float toY = yscale ;
2012-11-28 15:47:07 +00:00
if ( moveToYScale > = 0.0f )
{
2012-11-26 18:58:24 +00:00
toY = moveToYScale * 100.0f ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
int rXTo = idMath : : Ftoi ( toX + 0.5f ) ;
int rYTo = idMath : : Ftoi ( toY + 0.5f ) ;
int rXScale = idMath : : Ftoi ( xscale + 0.5f ) ;
int rYScale = idMath : : Ftoi ( yscale + 0.5f ) ;
2012-11-28 15:47:07 +00:00
if ( rXTo = = rXScale & & rYTo = = rYScale )
{
2012-11-26 18:58:24 +00:00
return false ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
float newXScale = xscale ;
float newYScale = yscale ;
2012-11-28 15:47:07 +00:00
if ( rXTo ! = rXScale & & toX > = 0.0f )
{
if ( toX < xscale )
{
2012-11-26 18:58:24 +00:00
newXScale - = speed ;
newXScale = idMath : : ClampFloat ( toX , 100.0f , newXScale ) ;
2012-11-28 15:47:07 +00:00
}
else if ( toX > xscale )
{
2012-11-26 18:58:24 +00:00
newXScale + = speed ;
newXScale = idMath : : ClampFloat ( 0.0f , toX , newXScale ) ;
}
}
2012-11-28 15:47:07 +00:00
if ( rYTo ! = rYScale & & toY > = 0.0f )
{
if ( toY < yscale )
{
2012-11-26 18:58:24 +00:00
newYScale - = speed ;
newYScale = idMath : : ClampFloat ( toY , 100.0f , newYScale ) ;
2012-11-28 15:47:07 +00:00
}
else if ( toY > yscale )
{
2012-11-26 18:58:24 +00:00
newYScale + = speed ;
newYScale = idMath : : ClampFloat ( 0.0f , toY , newYScale ) ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
SetScale ( newXScale , newYScale ) ;
return true ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFSpriteInstance : : SetAlpha
= = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSWFSpriteInstance : : SetAlpha ( float val )
{
if ( parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = parent - > FindDisplayEntry ( depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = this )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _alpha: Couldn't find our display entry in our parents display list " ) ;
return ;
}
thisDisplayEntry - > cxf . mul . w = val ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = =
idSWFScriptObject_SpriteInstancePrototype
= = = = = = = = = = = = = = = = = = = = = = = =
*/
# define SWF_SPRITE_FUNCTION_DEFINE( x ) idSWFScriptVar idSWFScriptObject_SpriteInstancePrototype::idSWFScriptFunction_##x::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms )
# define SWF_SPRITE_NATIVE_VAR_DEFINE_GET( x ) idSWFScriptVar idSWFScriptObject_SpriteInstancePrototype::idSWFScriptNativeVar_##x::Get( class idSWFScriptObject * object )
# define SWF_SPRITE_NATIVE_VAR_DEFINE_SET( x ) void idSWFScriptObject_SpriteInstancePrototype::idSWFScriptNativeVar_##x::Set( class idSWFScriptObject * object, const idSWFScriptVar & value )
# define SWF_SPRITE_PTHIS_FUNC( x ) idSWFSpriteInstance * pThis = thisObject ? thisObject->GetSprite() : NULL; if ( !verify( pThis != NULL ) ) { idLib::Warning( "SWF: tried to call " x " on NULL sprite" ); return idSWFScriptVar(); }
# define SWF_SPRITE_PTHIS_GET( x ) idSWFSpriteInstance * pThis = object ? object->GetSprite() : NULL; if ( pThis == NULL ) { return idSWFScriptVar(); }
# define SWF_SPRITE_PTHIS_SET( x ) idSWFSpriteInstance * pThis = object ? object->GetSprite() : NULL; if ( pThis == NULL ) { return; }
# define SWF_SPRITE_FUNCTION_SET( x ) scriptFunction_##x.AddRef(); Set( #x, &scriptFunction_##x );
# define SWF_SPRITE_NATIVE_VAR_SET( x ) SetNative( #x, &swfScriptVar_##x );
2012-11-28 15:47:07 +00:00
idSWFScriptObject_SpriteInstancePrototype : : idSWFScriptObject_SpriteInstancePrototype ( )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_FUNCTION_SET ( duplicateMovieClip ) ;
SWF_SPRITE_FUNCTION_SET ( gotoAndPlay ) ;
SWF_SPRITE_FUNCTION_SET ( gotoAndStop ) ;
SWF_SPRITE_FUNCTION_SET ( swapDepths ) ;
SWF_SPRITE_FUNCTION_SET ( nextFrame ) ;
SWF_SPRITE_FUNCTION_SET ( prevFrame ) ;
SWF_SPRITE_FUNCTION_SET ( play ) ;
SWF_SPRITE_FUNCTION_SET ( stop ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
SWF_SPRITE_NATIVE_VAR_SET ( _x ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _y ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _xscale ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _yscale ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _alpha ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _brightness ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _visible ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _width ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _height ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _rotation ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _name ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _currentframe ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _totalframes ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _target ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _framesloaded ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _droptarget ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _url ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _highquality ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _focusrect ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _soundbuftime ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _quality ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _mousex ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _mousey ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
SWF_SPRITE_NATIVE_VAR_SET ( _stereoDepth ) ;
SWF_SPRITE_NATIVE_VAR_SET ( _itemindex ) ;
SWF_SPRITE_NATIVE_VAR_SET ( material ) ;
SWF_SPRITE_NATIVE_VAR_SET ( materialWidth ) ;
SWF_SPRITE_NATIVE_VAR_SET ( materialHeight ) ;
SWF_SPRITE_NATIVE_VAR_SET ( xOffset ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
SWF_SPRITE_NATIVE_VAR_SET ( onEnterFrame ) ;
//SWF_SPRITE_NATIVE_VAR_SET( onLoad );
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _target )
{
return " " ;
}
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _droptarget )
{
return " " ;
}
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _url )
{
return " " ;
}
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _highquality )
{
return 2 ;
}
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _focusrect )
{
return true ;
}
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _soundbuftime )
{
return 0 ;
}
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _quality )
{
return " BEST " ;
}
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _width )
{
return 0.0f ;
}
2012-11-26 18:58:24 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( _width ) { }
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _height )
{
return 0.0f ;
}
2012-11-26 18:58:24 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( _height ) { }
2012-11-28 15:47:07 +00:00
SWF_SPRITE_FUNCTION_DEFINE ( duplicateMovieClip )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_FUNC ( " duplicateMovieClip " ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > parent = = NULL )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " Tried to duplicate root movie clip " ) ;
return idSWFScriptVar ( ) ;
}
2012-11-28 15:47:07 +00:00
if ( parms . Num ( ) < 2 )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " duplicateMovieClip: expected 2 parameters " ) ;
return idSWFScriptVar ( ) ;
2012-11-28 15:47:07 +00:00
}
swfDisplayEntry_t * thisDisplayEntry = pThis - > parent - > FindDisplayEntry ( pThis - > depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = pThis )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " duplicateMovieClip: Couldn't find our display entry in our parents display list " ) ;
return idSWFScriptVar ( ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
swfMatrix_t matrix = thisDisplayEntry - > matrix ;
swfColorXform_t cxf = thisDisplayEntry - > cxf ;
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * display = pThis - > parent - > AddDisplayEntry ( 16384 + parms [ 1 ] . ToInteger ( ) , thisDisplayEntry - > characterID ) ;
if ( display = = NULL )
{
2012-11-26 18:58:24 +00:00
return idSWFScriptVar ( ) ;
}
display - > matrix = matrix ;
display - > cxf = cxf ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idStr name = parms [ 0 ] . ToString ( ) ;
pThis - > parent - > scriptObject - > Set ( name , display - > spriteInstance - > scriptObject ) ;
display - > spriteInstance - > name = name ;
display - > spriteInstance - > RunTo ( 1 ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
return display - > spriteInstance - > scriptObject ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_FUNCTION_DEFINE ( gotoAndPlay )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_FUNC ( " gotoAndPlay " ) ;
2012-11-28 15:47:07 +00:00
if ( parms . Num ( ) > 0 )
{
2012-11-26 18:58:24 +00:00
pThis - > actions . Clear ( ) ;
pThis - > RunTo ( pThis - > FindFrame ( parms [ 0 ] . ToString ( ) ) ) ;
pThis - > Play ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " gotoAndPlay: expected 1 paramater " ) ;
}
return idSWFScriptVar ( ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_FUNCTION_DEFINE ( gotoAndStop )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_FUNC ( " gotoAndStop " ) ;
2012-11-28 15:47:07 +00:00
if ( parms . Num ( ) > 0 )
{
2012-11-26 18:58:24 +00:00
// Flash forces frames values less than 1 to 1.
2012-11-28 15:47:07 +00:00
if ( parms [ 0 ] . IsNumeric ( ) & & parms [ 0 ] . ToInteger ( ) < 1 )
{
2012-11-26 18:58:24 +00:00
pThis - > RunTo ( pThis - > FindFrame ( " 1 " ) ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
pThis - > RunTo ( pThis - > FindFrame ( parms [ 0 ] . ToString ( ) ) ) ;
}
pThis - > Stop ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " gotoAndStop: expected 1 paramater " ) ;
}
return idSWFScriptVar ( ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_FUNCTION_DEFINE ( swapDepths )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_FUNC ( " swapDepths " ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > parent = = NULL )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " Tried to swap depths on root movie clip " ) ;
return idSWFScriptVar ( ) ;
}
2012-11-28 15:47:07 +00:00
if ( parms . Num ( ) < 1 )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " swapDepths: expected 1 parameters " ) ;
return idSWFScriptVar ( ) ;
}
pThis - > parent - > SwapDepths ( pThis - > depth , parms [ 0 ] . ToInteger ( ) ) ;
return idSWFScriptVar ( ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_FUNCTION_DEFINE ( nextFrame )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_FUNC ( " nextFrame " ) ;
pThis - > NextFrame ( ) ;
return idSWFScriptVar ( ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_FUNCTION_DEFINE ( prevFrame )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_FUNC ( " prevFrame " ) ;
pThis - > PrevFrame ( ) ;
return idSWFScriptVar ( ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_FUNCTION_DEFINE ( play )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_FUNC ( " play " ) ;
pThis - > Play ( ) ;
return idSWFScriptVar ( ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_FUNCTION_DEFINE ( stop )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_FUNC ( " stop " ) ;
pThis - > Stop ( ) ;
return idSWFScriptVar ( ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _x )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _x " ) ;
return pThis - > GetXPos ( ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( _x )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " _x " ) ;
pThis - > SetXPos ( value . ToFloat ( ) ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _y )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _y " ) ;
return pThis - > GetYPos ( ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( _y )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " _y " ) ;
pThis - > SetYPos ( value . ToFloat ( ) ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _xscale )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _xscale " ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return 1.0f ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = pThis - > parent - > FindDisplayEntry ( pThis - > depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = pThis )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _xscale: Couldn't find our display entry in our parents display list " ) ;
return 1.0f ;
}
return thisDisplayEntry - > matrix . Scale ( idVec2 ( 1.0f , 0.0f ) ) . Length ( ) * 100.0f ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( _xscale )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " _xscale " ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = pThis - > parent - > FindDisplayEntry ( pThis - > depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = pThis )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _xscale: Couldn't find our display entry in our parents display list " ) ;
return ;
}
float newScale = value . ToFloat ( ) / 100.0f ;
// this is done funky to maintain the current rotation
idVec2 currentScale = thisDisplayEntry - > matrix . Scale ( idVec2 ( 1.0f , 0.0f ) ) ;
2012-11-28 15:47:07 +00:00
if ( currentScale . Normalize ( ) = = 0.0f )
{
2012-11-26 18:58:24 +00:00
thisDisplayEntry - > matrix . xx = newScale ;
thisDisplayEntry - > matrix . yx = 0.0f ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
thisDisplayEntry - > matrix . xx = currentScale . x * newScale ;
thisDisplayEntry - > matrix . yx = currentScale . y * newScale ;
}
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _yscale )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _yscale " ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return 1.0f ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = pThis - > parent - > FindDisplayEntry ( pThis - > depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = pThis )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _yscale: Couldn't find our display entry in our parents display list " ) ;
return 1.0f ;
}
return thisDisplayEntry - > matrix . Scale ( idVec2 ( 0.0f , 1.0f ) ) . Length ( ) * 100.0f ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( _yscale )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " _yscale " ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = pThis - > parent - > FindDisplayEntry ( pThis - > depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = pThis )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _yscale: Couldn't find our display entry in our parents display list " ) ;
return ;
}
float newScale = value . ToFloat ( ) / 100.0f ;
// this is done funky to maintain the current rotation
idVec2 currentScale = thisDisplayEntry - > matrix . Scale ( idVec2 ( 0.0f , 1.0f ) ) ;
2012-11-28 15:47:07 +00:00
if ( currentScale . Normalize ( ) = = 0.0f )
{
2012-11-26 18:58:24 +00:00
thisDisplayEntry - > matrix . yy = newScale ;
thisDisplayEntry - > matrix . xy = 0.0f ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
thisDisplayEntry - > matrix . yy = currentScale . y * newScale ;
thisDisplayEntry - > matrix . xy = currentScale . x * newScale ;
}
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _alpha )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _alpha " ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return 1.0f ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = pThis - > parent - > FindDisplayEntry ( pThis - > depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = pThis )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _alpha: Couldn't find our display entry in our parents display list " ) ;
return 1.0f ;
}
return thisDisplayEntry - > cxf . mul . w ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( _alpha )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " _alpha " ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
pThis - > SetAlpha ( value . ToFloat ( ) ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _brightness )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _brightness " ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return 1.0f ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = pThis - > parent - > FindDisplayEntry ( pThis - > depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = pThis )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _brightness: Couldn't find our display entry in our parents display list " ) ;
return 1.0f ;
}
// This works as long as the user only used the "brightess" control in the editor
// If they used anything else (tint/advanced) then this will return fairly random values
2012-11-28 15:47:07 +00:00
const idVec4 & mul = thisDisplayEntry - > cxf . mul ;
const idVec4 & add = thisDisplayEntry - > cxf . add ;
2012-11-26 18:58:24 +00:00
float avgMul = ( mul . x + mul . y + mul . z ) / 3.0f ;
float avgAdd = ( add . x + add . y + add . z ) / 3.0f ;
2012-11-28 15:47:07 +00:00
if ( avgAdd > 1.0f )
{
2012-11-26 18:58:24 +00:00
return avgAdd ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
return avgMul - 1.0f ;
}
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( _brightness )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " _brightness " ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = pThis - > parent - > FindDisplayEntry ( pThis - > depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = pThis )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _brightness: Couldn't find our display entry in our parents display list " ) ;
return ;
}
// This emulates adjusting the "brightness" slider in the editor
// Although the editor forces alpha to 100%
float b = value . ToFloat ( ) ;
float c = 1.0f - b ;
2012-11-28 15:47:07 +00:00
if ( b < 0.0f )
{
2012-11-26 18:58:24 +00:00
c = 1.0f + b ;
b = 0.0f ;
}
thisDisplayEntry - > cxf . add . Set ( b , b , b , thisDisplayEntry - > cxf . add . w ) ;
thisDisplayEntry - > cxf . mul . Set ( c , c , c , thisDisplayEntry - > cxf . mul . w ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _visible )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _visible " ) ;
return pThis - > isVisible ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( _visible )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " _visible " ) ;
pThis - > isVisible = value . ToBool ( ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > isVisible )
{
for ( idSWFSpriteInstance * p = pThis - > parent ; p ! = NULL ; p = p - > parent )
{
2012-11-26 18:58:24 +00:00
p - > childrenRunning = true ;
}
}
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _rotation )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _rotation " ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return 0.0f ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = pThis - > parent - > FindDisplayEntry ( pThis - > depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = pThis )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _rotation: Couldn't find our display entry in our parents display list " ) ;
return 0.0f ;
}
idVec2 scale = thisDisplayEntry - > matrix . Scale ( idVec2 ( 0.0f , 1.0f ) ) ;
scale . Normalize ( ) ;
float rotation = RAD2DEG ( idMath : : ACos ( scale . y ) ) ;
2012-11-28 15:47:07 +00:00
if ( scale . x < 0.0f )
{
2012-11-26 18:58:24 +00:00
rotation = - rotation ;
}
return rotation ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( _rotation )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " _rotation " ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = pThis - > parent - > FindDisplayEntry ( pThis - > depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = pThis )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _rotation: Couldn't find our display entry in our parents display list " ) ;
return ;
}
2012-11-28 15:47:07 +00:00
swfMatrix_t & matrix = thisDisplayEntry - > matrix ;
float xscale = matrix . Scale ( idVec2 ( 1.0f , 0.0f ) ) . Length ( ) ;
float yscale = matrix . Scale ( idVec2 ( 0.0f , 1.0f ) ) . Length ( ) ;
2012-11-26 18:58:24 +00:00
float s , c ;
2012-11-28 15:47:07 +00:00
idMath : : SinCos ( DEG2RAD ( value . ToFloat ( ) ) , s , c ) ;
2012-11-26 18:58:24 +00:00
matrix . xx = c * xscale ;
matrix . yx = s * xscale ;
matrix . xy = - s * yscale ;
matrix . yy = c * yscale ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _name )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _name " ) ;
return pThis - > name . c_str ( ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _currentframe )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _currentframe " ) ;
return pThis - > currentFrame ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _totalframes )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _totalframes " ) ;
return pThis - > frameCount ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _framesloaded )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _framesloaded " ) ;
return pThis - > frameCount ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _mousex )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _mousex " ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return pThis - > sprite - > GetSWF ( ) - > GetMouseX ( ) ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = pThis - > parent - > FindDisplayEntry ( pThis - > depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = pThis )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _mousex: Couldn't find our display entry in our parents display list " ) ;
return pThis - > sprite - > GetSWF ( ) - > GetMouseX ( ) ;
}
return pThis - > sprite - > GetSWF ( ) - > GetMouseX ( ) - thisDisplayEntry - > matrix . ty ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _mousey )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _mousey " ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > parent = = NULL )
{
2012-11-26 18:58:24 +00:00
return pThis - > sprite - > GetSWF ( ) - > GetMouseY ( ) ;
}
2012-11-28 15:47:07 +00:00
swfDisplayEntry_t * thisDisplayEntry = pThis - > parent - > FindDisplayEntry ( pThis - > depth ) ;
if ( thisDisplayEntry = = NULL | | thisDisplayEntry - > spriteInstance ! = pThis )
{
2012-11-26 18:58:24 +00:00
idLib : : Warning ( " _mousey: Couldn't find our display entry in our parents display list " ) ;
return pThis - > sprite - > GetSWF ( ) - > GetMouseY ( ) ;
}
return pThis - > sprite - > GetSWF ( ) - > GetMouseY ( ) - thisDisplayEntry - > matrix . ty ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _itemindex )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _itemindex " ) ;
return pThis - > itemIndex ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( _itemindex )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " _itemindex " ) ;
pThis - > itemIndex = value . ToInteger ( ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( _stereoDepth )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " _stereoDepth " ) ;
pThis - > stereoDepth = value . ToInteger ( ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( _stereoDepth )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " _stereoDepth " ) ;
return pThis - > stereoDepth ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( material )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " material " ) ;
2012-11-28 15:47:07 +00:00
if ( pThis - > materialOverride = = NULL )
{
2012-11-26 18:58:24 +00:00
return idSWFScriptVar ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
return pThis - > materialOverride - > GetName ( ) ;
}
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( material )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " material " ) ;
2012-11-28 15:47:07 +00:00
if ( ! value . IsString ( ) )
{
2012-11-26 18:58:24 +00:00
pThis - > materialOverride = NULL ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// God I hope this material was referenced during map load
pThis - > SetMaterial ( declManager - > FindMaterial ( value . ToString ( ) , false ) ) ;
}
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( materialWidth )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " materialWidth " ) ;
return pThis - > materialWidth ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( materialWidth )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " materialWidth " ) ;
assert ( value . ToInteger ( ) > 0 ) ;
assert ( value . ToInteger ( ) < = 8192 ) ;
2012-11-28 15:47:07 +00:00
pThis - > materialWidth = ( uint16 ) value . ToInteger ( ) ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( materialHeight )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " materialHeight " ) ;
return pThis - > materialHeight ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( materialHeight )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " materialHeight " ) ;
assert ( value . ToInteger ( ) > 0 ) ;
assert ( value . ToInteger ( ) < = 8192 ) ;
2012-11-28 15:47:07 +00:00
pThis - > materialHeight = ( uint16 ) value . ToInteger ( ) ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( xOffset )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " xOffset " ) ;
return pThis - > xOffset ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( xOffset )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " xOffset " ) ;
pThis - > xOffset = value . ToFloat ( ) ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_GET ( onEnterFrame )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_GET ( " onEnterFrame " ) ;
return pThis - > onEnterFrame ;
}
2012-11-28 15:47:07 +00:00
SWF_SPRITE_NATIVE_VAR_DEFINE_SET ( onEnterFrame )
{
2012-11-26 18:58:24 +00:00
SWF_SPRITE_PTHIS_SET ( " onEnterFrame " ) ;
pThis - > onEnterFrame = value ;
2012-12-11 22:48:55 +00:00
}