doom3-bfg/neo/swf/SWF_Sprites.cpp

840 lines
23 KiB
C++
Raw Normal View History

2012-11-26 18:58:24 +00:00
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
2015-07-27 22:29:01 +00:00
Copyright (C) 2013-2015 Robert Beckebans
2012-11-26 18:58:24 +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.
===========================================================================
*/
#include "precompiled.h"
#pragma hdrstop
2012-11-26 18:58:24 +00:00
2015-07-27 22:29:01 +00:00
using namespace rapidjson;
2012-11-26 18:58:24 +00:00
/*
========================
idSWFSprite::idSWFSprite
========================
*/
idSWFSprite::idSWFSprite( idSWF* _swf ) :
swf( _swf ),
frameCount( 0 ),
commandBuffer( NULL )
2012-11-26 18:58:24 +00:00
{
}
/*
========================
idSWFSprite::~idSWFSprite
========================
*/
idSWFSprite::~idSWFSprite()
{
2012-11-26 18:58:24 +00:00
Mem_Free( commandBuffer );
}
/*
========================
idSWF::DefineSprite
========================
*/
void idSWF::DefineSprite( idSWFBitStream& bitstream )
{
2012-11-26 18:58:24 +00:00
uint16 characterID = bitstream.ReadU16();
idSWFDictionaryEntry* entry = AddDictionaryEntry( characterID, SWF_DICT_SPRITE );
if( entry == NULL )
{
2012-11-26 18:58:24 +00:00
return;
}
entry->sprite->Load( bitstream, false );
}
/*
========================
idSWFSprite::Load
========================
*/
void idSWFSprite::Load( idSWFBitStream& bitstream, bool parseDictionary )
{
2012-11-26 18:58:24 +00:00
frameCount = bitstream.ReadU16();
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// run through the file once, building the dictionary and accumulating control tags
frameOffsets.SetNum( frameCount + 1 );
frameOffsets[0] = 0;
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
unsigned int currentFrame = 1;
2019-11-11 19:27:44 +00:00
while( true )
{
2012-11-26 18:58:24 +00:00
uint16 codeAndLength = bitstream.ReadU16();
uint32 recordLength = ( codeAndLength & 0x3F );
if( recordLength == 0x3F )
{
2012-11-26 18:58:24 +00:00
recordLength = bitstream.ReadU32();
}
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
idSWFBitStream tagStream( bitstream.ReadData( recordLength ), recordLength, false );
2019-11-11 19:27:44 +00:00
swfTag_t tag = ( swfTag_t )( codeAndLength >> 6 );
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
// ----------------------
// Definition tags
// definition tags are only allowed in the main sprite
// ----------------------
if( parseDictionary )
{
2012-11-26 18:58:24 +00:00
bool handled = true;
switch( tag )
{
2012-11-26 18:58:24 +00:00
#define HANDLE_SWF_TAG( x ) case Tag_##x: swf->x( tagStream ); break;
HANDLE_SWF_TAG( FileAttributes );
HANDLE_SWF_TAG( Metadata );
HANDLE_SWF_TAG( SetBackgroundColor );
HANDLE_SWF_TAG( JPEGTables );
HANDLE_SWF_TAG( DefineBits );
HANDLE_SWF_TAG( DefineBitsJPEG2 );
HANDLE_SWF_TAG( DefineBitsJPEG3 );
HANDLE_SWF_TAG( DefineBitsLossless );
HANDLE_SWF_TAG( DefineBitsLossless2 );
HANDLE_SWF_TAG( DefineShape );
HANDLE_SWF_TAG( DefineShape2 );
HANDLE_SWF_TAG( DefineShape3 );
HANDLE_SWF_TAG( DefineShape4 );
HANDLE_SWF_TAG( DefineSprite );
HANDLE_SWF_TAG( DefineSound );
//HANDLE_SWF_TAG( DefineMorphShape ); // these don't work right
HANDLE_SWF_TAG( DefineFont2 );
HANDLE_SWF_TAG( DefineFont3 );
HANDLE_SWF_TAG( DefineText );
HANDLE_SWF_TAG( DefineText2 );
HANDLE_SWF_TAG( DefineEditText );
2012-11-26 18:58:24 +00:00
#undef HANDLE_SWF_TAG
default:
handled = false;
2012-11-26 18:58:24 +00:00
}
if( handled )
{
2012-11-26 18:58:24 +00:00
continue;
}
}
// ----------------------
// Control tags
// control tags are stored off in the commands list and processed at run time
// except for a couple really special control tags like "End" and "FrameLabel"
// ----------------------
switch( tag )
{
case Tag_End:
return;
2019-11-11 19:27:44 +00:00
case Tag_ShowFrame:
frameOffsets[ currentFrame ] = commands.Num();
currentFrame++;
break;
2019-11-11 19:27:44 +00:00
case Tag_FrameLabel:
{
swfFrameLabel_t& label = frameLabels.Alloc();
2012-11-26 18:58:24 +00:00
label.frameNum = currentFrame;
label.frameLabel = tagStream.ReadString();
}
break;
2019-11-11 19:27:44 +00:00
case Tag_DoInitAction:
{
tagStream.ReadU16();
2019-11-11 19:27:44 +00:00
idSWFBitStream& initaction = doInitActions.Alloc();
initaction.Load( tagStream.ReadData( recordLength - 2 ), recordLength - 2, true );
}
2012-11-26 18:58:24 +00:00
break;
2019-11-11 19:27:44 +00:00
case Tag_DoAction:
case Tag_PlaceObject2:
case Tag_PlaceObject3:
case Tag_RemoveObject2:
{
swfSpriteCommand_t& command = commands.Alloc();
2012-11-26 18:58:24 +00:00
command.tag = tag;
command.stream.Load( tagStream.ReadData( recordLength ), recordLength, true );
}
break;
2019-11-11 19:27:44 +00:00
default:
// We don't care, about sprite tags we don't support ... RobA
//idLib::Printf( "Load Sprite: Unhandled tag %s\n", idSWF::GetTagName( tag ) );
break;
2012-11-26 18:58:24 +00:00
}
}
}
/*
========================
idSWFSprite::Read
========================
*/
void idSWFSprite::Read( idFile* f )
{
2012-11-26 18:58:24 +00:00
int num = 0;
f->ReadBig( frameCount );
f->ReadBig( num );
frameOffsets.SetNum( num );
2012-11-26 18:58:24 +00:00
f->ReadBigArray( frameOffsets.Ptr(), frameOffsets.Num() );
f->ReadBig( num );
frameLabels.SetNum( num );
for( int i = 0; i < frameLabels.Num(); i++ )
{
2012-11-26 18:58:24 +00:00
f->ReadBig( frameLabels[i].frameNum );
f->ReadString( frameLabels[i].frameLabel );
}
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
uint32 bufferSize;
f->ReadBig( bufferSize );
2019-11-11 19:27:44 +00:00
commandBuffer = ( byte* )Mem_Alloc( bufferSize, TAG_SWF );
2012-11-26 18:58:24 +00:00
f->Read( commandBuffer, bufferSize );
2019-11-11 19:27:44 +00:00
byte* currentBuffer = commandBuffer;
2019-11-11 19:27:44 +00:00
f->ReadBig( num );
commands.SetNum( num );
for( int i = 0; i < commands.Num(); i++ )
{
2012-11-26 18:58:24 +00:00
uint32 streamLength = 0;
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
f->ReadBig( commands[i].tag );
f->ReadBig( streamLength );
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
commands[i].stream.Load( currentBuffer, streamLength, false );
currentBuffer += streamLength;
}
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
uint32 doInitActionLength = 0;
f->ReadBig( num );
doInitActions.SetNum( num );
for( int i = 0; i < num; i++ )
{
2012-11-26 18:58:24 +00:00
f->ReadBig( doInitActionLength );
idSWFBitStream& initaction = doInitActions[i];
2012-11-26 18:58:24 +00:00
initaction.Load( currentBuffer, doInitActionLength, true );
currentBuffer += doInitActionLength;
}
}
/*
========================
idSWFSprite::Write
========================
*/
void idSWFSprite::Write( idFile* f )
{
2012-11-26 18:58:24 +00:00
f->WriteBig( frameCount );
f->WriteBig( frameOffsets.Num() );
f->WriteBigArray( frameOffsets.Ptr(), frameOffsets.Num() );
f->WriteBig( frameLabels.Num() );
for( int i = 0; i < frameLabels.Num(); i++ )
{
2012-11-26 18:58:24 +00:00
f->WriteBig( frameLabels[i].frameNum );
f->WriteString( frameLabels[i].frameLabel );
}
uint32 totalLength = 0;
for( int i = 0; i < commands.Num(); i++ )
{
2012-11-26 18:58:24 +00:00
totalLength += commands[i].stream.Length();
}
for( int i = 0; i < doInitActions.Num(); i++ )
{
2012-11-26 18:58:24 +00:00
totalLength += doInitActions[i].Length();
}
f->WriteBig( totalLength );
for( int i = 0; i < commands.Num(); i++ )
{
2012-11-26 18:58:24 +00:00
f->Write( commands[i].stream.Ptr(), commands[i].stream.Length() );
}
for( int i = 0; i < doInitActions.Num(); i++ )
{
2012-11-26 18:58:24 +00:00
f->Write( doInitActions[i].Ptr(), doInitActions[i].Length() );
}
2019-11-11 19:27:44 +00:00
f->WriteBig( commands.Num() );
for( int i = 0; i < commands.Num(); i++ )
{
2012-11-26 18:58:24 +00:00
f->WriteBig( commands[i].tag );
f->WriteBig( commands[i].stream.Length() );
}
2019-11-11 19:27:44 +00:00
2012-11-26 18:58:24 +00:00
f->WriteBig( doInitActions.Num() );
for( int i = 0; i < doInitActions.Num(); i++ )
{
f->WriteBig( doInitActions[i].Length() );
2012-11-26 18:58:24 +00:00
}
}
2013-03-25 17:52:29 +00:00
// RB begin
2015-07-27 22:29:01 +00:00
void idSWFSprite::ReadJSON( rapidjson::Value& entry )
{
frameCount = entry["frameCount"].GetUint();
2019-11-11 19:27:44 +00:00
2015-07-27 22:29:01 +00:00
Value& fo = entry["frameOffsets"];
frameOffsets.SetNum( fo.Size() );
2019-11-11 19:27:44 +00:00
2015-07-27 22:29:01 +00:00
for( int i = 0; i < frameOffsets.Num(); i++ )
{
frameOffsets[i] = fo[i].GetUint();
}
2019-11-11 19:27:44 +00:00
2015-07-27 22:29:01 +00:00
if( entry.HasMember( "frameLabels" ) )
{
Value& fl = entry["frameLabels"];
frameLabels.SetNum( fl.Size() );
for( int i = 0; i < frameLabels.Num(); i++ )
{
frameLabels[i].frameNum = fl[i]["frameNum"].GetUint();
frameLabels[i].frameLabel = fl[i]["frameLabel"].GetString();
}
}
2019-11-11 19:27:44 +00:00
2015-07-27 22:29:01 +00:00
Value& c = entry["commands"];
commands.SetNum( c.Size() );
for( int i = 0; i < commands.Num(); i++ )
{
Value& command = c[i];
Value& type = command["type"];
2019-11-11 19:27:44 +00:00
2015-10-11 20:01:02 +00:00
if( type == "Tag_PlaceObject2" || type == "Tag_PlaceObject3" )
2015-07-27 22:29:01 +00:00
{
2015-10-11 20:01:02 +00:00
if( type == "Tag_PlaceObject3" )
{
commands[i].tag = Tag_PlaceObject3;
}
else
{
commands[i].tag = Tag_PlaceObject2;
}
2019-11-11 19:27:44 +00:00
2015-07-27 22:29:01 +00:00
idFile_SWF file( new idFile_Memory() );
2019-11-11 19:27:44 +00:00
2015-10-11 20:01:02 +00:00
uint8 flags1 = 0;
uint8 flags2 = 0;
if( type == "Tag_PlaceObject3" )
{
flags1 = command["flags1"].GetUint();
file.WriteU8( flags1 );
2019-11-11 19:27:44 +00:00
2015-10-11 20:01:02 +00:00
flags2 = command["flags2"].GetUint();
file.WriteU8( flags2 );
}
else
{
flags1 = command["flags"].GetUint();
file.WriteU8( flags1 );
}
2019-11-11 19:27:44 +00:00
2015-07-27 22:29:01 +00:00
uint16 depth = command["depth"].GetUint();
file.WriteU16( depth );
2019-11-11 19:27:44 +00:00
2015-07-27 22:29:01 +00:00
if( ( flags1 & PlaceFlagHasCharacter ) != 0 )
{
uint16 characterID = command["characterID"].GetUint();
file.WriteU16( characterID );
}
2019-11-11 19:27:44 +00:00
2015-07-27 22:29:01 +00:00
if( ( flags1 & PlaceFlagHasMatrix ) != 0 )
{
swfMatrix_t m;
Value& startMatrix = command["startMatrix"];
m.xx = startMatrix[0].GetDouble();
m.yy = startMatrix[1].GetDouble();
m.xy = startMatrix[2].GetDouble();
m.yx = startMatrix[3].GetDouble();
m.tx = startMatrix[4].GetDouble();
m.ty = startMatrix[5].GetDouble();
file.WriteMatrix( m );
}
2019-11-11 19:27:44 +00:00
2015-07-27 22:29:01 +00:00
if( ( flags1 & PlaceFlagHasColorTransform ) != 0 )
{
swfColorXform_t cxf;
2019-11-11 19:27:44 +00:00
2015-07-27 22:29:01 +00:00
Value& mulColor = command["mulColor"];
cxf.mul.x = mulColor[0].GetDouble();
cxf.mul.y = mulColor[1].GetDouble();
cxf.mul.z = mulColor[2].GetDouble();
cxf.mul.w = mulColor[3].GetDouble();
2019-11-11 19:27:44 +00:00
2015-07-27 22:29:01 +00:00
if( command.HasMember( "addColor" ) )
{
Value& addColor = command["addColor"];
cxf.add.x = addColor[0].GetDouble();
cxf.add.y = addColor[1].GetDouble();
cxf.add.z = addColor[2].GetDouble();
cxf.add.w = addColor[3].GetDouble();
}
2019-11-11 19:27:44 +00:00
2015-09-13 15:21:58 +00:00
file.WriteColorXFormRGBA( cxf );
}
2019-11-11 19:27:44 +00:00
2015-09-13 15:21:58 +00:00
if( ( flags1 & PlaceFlagHasRatio ) != 0 )
{
2015-11-22 16:01:43 +00:00
uint16 ratio = command["ratio"].GetUint();
file.WriteU16( ratio );
2015-09-13 15:21:58 +00:00
}
2019-11-11 19:27:44 +00:00
2015-09-13 15:21:58 +00:00
if( ( flags1 & PlaceFlagHasName ) != 0 )
{
Value& name = command["name"];
idStr string = name.GetString();
string.Append( '\0' );
int len = string.Length();
2019-11-11 19:27:44 +00:00
2015-09-13 15:21:58 +00:00
file->Write( string.c_str(), len );
2019-11-11 19:27:44 +00:00
2015-09-13 15:21:58 +00:00
// TODO
//file.writeStrin
}
2019-11-11 19:27:44 +00:00
2015-09-13 15:21:58 +00:00
if( ( flags1 & PlaceFlagHasClipDepth ) != 0 )
{
uint16 clipDepth = command["clipDepth"].GetUint();
file.WriteU16( clipDepth );
}
2019-11-11 19:27:44 +00:00
2015-10-11 20:01:02 +00:00
if( ( flags2 & PlaceFlagHasBlendMode ) != 0 )
{
uint8 blendMode = command["blendMode"].GetUint();
file.WriteU8( blendMode );
}
2019-11-11 19:27:44 +00:00
2015-09-13 15:21:58 +00:00
if( ( flags1 & PlaceFlagHasClipActions ) != 0 )
{
// FIXME: clip actions
2015-07-27 22:29:01 +00:00
}
2019-11-11 19:27:44 +00:00
2015-07-27 22:29:01 +00:00
uint32 streamLength = file->Length();
commands[i].stream.Load( ( byte* ) static_cast<idFile_Memory*>( ( idFile* )file )->GetDataPtr(), streamLength, true );
}
else if( type == "Tag_RemoveObject2" )
{
commands[i].tag = Tag_RemoveObject2;
2019-11-11 19:27:44 +00:00
idFile_SWF file( new idFile_Memory() );
2019-11-11 19:27:44 +00:00
uint16 depth = command["depth"].GetUint();
file.WriteU16( depth );
2019-11-11 19:27:44 +00:00
uint32 streamLength = file->Length();
commands[i].stream.Load( ( byte* ) static_cast<idFile_Memory*>( ( idFile* )file )->GetDataPtr(), streamLength, true );
}
else if( type == "Tag_DoAction" )
{
commands[i].tag = Tag_DoAction;
2019-11-11 19:27:44 +00:00
idFile_SWF file( new idFile_Memory() );
2019-11-11 19:27:44 +00:00
2017-08-29 14:26:03 +00:00
idBase64 base64( command["stream"].GetString() );
base64.Decode( file );
2019-11-11 19:27:44 +00:00
uint32 streamLength = file->Length() - 1; // skip trailing zero added by Decode()
commands[i].stream.Load( ( byte* ) static_cast<idFile_Memory*>( ( idFile* )file )->GetDataPtr(), streamLength, true );
}
2019-11-11 19:27:44 +00:00
2015-07-27 22:29:01 +00:00
}
}
2015-06-06 23:07:13 +00:00
void idSWFSprite::WriteJSON( idFile* f, int characterID )
2013-03-25 17:52:29 +00:00
{
2015-06-06 23:07:13 +00:00
f->WriteFloatString( "\t\t\t\"frameCount\": %i,\n", frameCount );
2019-11-11 19:27:44 +00:00
2015-06-06 23:07:13 +00:00
if( frameOffsets.Num() )
2013-03-25 17:52:29 +00:00
{
2015-06-06 23:07:13 +00:00
f->WriteFloatString( "\t\t\t\"frameOffsets\": [ " );
for( int i = 0; i < frameOffsets.Num(); i++ )
{
f->WriteFloatString( "%i%s", frameOffsets[i], ( i == frameOffsets.Num() - 1 ) ? "" : ", " );
}
f->WriteFloatString( " ],\n" );
2013-03-25 17:52:29 +00:00
}
2019-11-11 19:27:44 +00:00
2015-06-06 23:07:13 +00:00
if( frameLabels.Num() )
2013-03-25 17:52:29 +00:00
{
2015-06-06 23:07:13 +00:00
f->WriteFloatString( "\t\t\t\"frameLabels\":\n\t\t\t[\n" );
for( int i = 0; i < frameLabels.Num(); i++ )
{
2015-06-07 13:23:48 +00:00
f->WriteFloatString( "\t\t\t\t{ \"frameNum\": %i, \"frameLabel\": \"%s\" }%s\n", frameLabels[i].frameNum, frameLabels[i].frameLabel.c_str(), ( i == frameLabels.Num() - 1 ) ? "" : ", " );
2015-06-06 23:07:13 +00:00
}
f->WriteFloatString( "\t\t\t],\n" );
2013-03-25 17:52:29 +00:00
}
2019-11-11 19:27:44 +00:00
2015-06-06 23:07:13 +00:00
#if 1
2013-03-25 17:52:29 +00:00
idBase64 base64;
2019-11-11 19:27:44 +00:00
2015-06-06 23:07:13 +00:00
f->WriteFloatString( "\t\t\t\"commands\":\n\t\t\t[\n" );
2013-03-25 17:52:29 +00:00
for( int i = 0; i < commands.Num(); i++ )
{
2013-03-26 17:07:01 +00:00
idSWFSprite::swfSpriteCommand_t& command = commands[i];
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
//base64.Encode( command.stream.Ptr(), command.stream.Length() );
2013-03-25 17:52:29 +00:00
//base64.Decode( src );
2019-11-11 19:27:44 +00:00
2013-03-25 23:06:38 +00:00
//f->WriteFloatString( "%s\t<Command tag=\"%s\" streamLength=\"%i\">%s</Command>\n", indentPrefix, idSWF::GetTagName( commands[i].tag ), src.Length(), src.c_str() );
2013-03-26 17:07:01 +00:00
//f->WriteFloatString( "%s\t<Command tag=\"%s\" streamLength=\"%i\">%s</Command>\n", indentPrefix, idSWF::GetTagName( commands[i].tag ), commands[i].stream.Length(), base64.c_str() );
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
//f->WriteFloatString( "%s\t<Command tag=\"%s\" streamLength=\"%i\">\n", indentPrefix, idSWF::GetTagName( command.tag ), command.stream.Length(), base64.c_str() );
//f->WriteFloatString( "%s\t\t<Stream>%s</Stream>\n", indentPrefix, base64.c_str() );
2019-11-11 19:27:44 +00:00
2013-03-26 17:07:01 +00:00
command.stream.Rewind();
switch( command.tag )
{
//case Tag_PlaceObject2:
// WriteXML_PlaceObject2( command.stream, indentPrefix );
// break;
2019-11-11 19:27:44 +00:00
2015-06-06 23:07:13 +00:00
#define HANDLE_SWF_TAG( x ) case Tag_##x: WriteJSON_##x( f, command.stream, characterID, i ); break;
2013-03-26 17:07:01 +00:00
HANDLE_SWF_TAG( PlaceObject2 );
2013-08-10 11:51:49 +00:00
HANDLE_SWF_TAG( PlaceObject3 );
HANDLE_SWF_TAG( RemoveObject2 );
2013-03-26 17:07:01 +00:00
//HANDLE_SWF_TAG( StartSound );
2013-08-10 11:51:49 +00:00
HANDLE_SWF_TAG( DoAction );
2013-03-26 17:07:01 +00:00
#undef HANDLE_SWF_TAG
default:
break;
//idLib::Printf( "Export Sprite: Unhandled tag %s\n", idSWF::GetTagName( command.tag ) );
}
2013-03-25 17:52:29 +00:00
}
2015-06-06 23:07:13 +00:00
f->WriteFloatString( "\n\t\t\t]\n" );
2019-11-11 19:27:44 +00:00
2015-06-06 23:07:13 +00:00
if( doInitActions.Num() )
2013-03-25 17:52:29 +00:00
{
2015-06-06 23:07:13 +00:00
f->WriteFloatString( ",\n\t\t\t\"doInitActions\":\t\t\t[\n" );
for( int i = 0; i < doInitActions.Num(); i++ )
{
base64.Encode( doInitActions[i].Ptr(), doInitActions[i].Length() );
2019-11-11 19:27:44 +00:00
2015-06-06 23:07:13 +00:00
f->WriteFloatString( "\t\t\t\"DoInitAction\": { \"streamLength\": %i, \"stream\": \"%s\" }%s\n", doInitActions[i].Length(), base64.c_str(), ( i == doInitActions.Num() - 1 ) ? "" : ", " );
}
f->WriteFloatString( "\t\t\t]" );
2013-03-25 17:52:29 +00:00
}
2013-08-10 16:51:22 +00:00
#endif
2013-03-25 17:52:29 +00:00
}
2013-03-26 17:07:01 +00:00
// RB end
2015-06-06 23:07:13 +00:00
void idSWFSprite::WriteJSON_PlaceObject2( idFile* file, idSWFBitStream& bitstream, int sourceCharacterID, int commandID, const char* indentPrefix )
2013-03-26 17:07:01 +00:00
{
2015-10-11 20:01:02 +00:00
uint8 flags1 = bitstream.ReadU8();
2013-03-26 17:07:01 +00:00
int depth = bitstream.ReadU16();
2019-11-11 19:27:44 +00:00
2015-06-06 23:07:13 +00:00
file->WriteFloatString( "%s\t\t\t\t{\n", ( commandID != 0 ) ? ",\n" : "" );
file->WriteFloatString( "\t\t\t\t\t\"type\": \"Tag_PlaceObject2\",\n" );
2015-06-07 13:23:48 +00:00
file->WriteFloatString( "\t\t\t\t\t\"flags\": %i, \"depth\": %i", flags1, depth );
2019-11-11 19:27:44 +00:00
2015-06-07 13:23:48 +00:00
if( ( flags1 & PlaceFlagHasCharacter ) != 0 )
2013-03-26 17:07:01 +00:00
{
2015-06-07 13:23:48 +00:00
int characterID = bitstream.ReadU16();
2015-06-06 23:07:13 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\"characterID\": %i", characterID );
2013-03-26 17:07:01 +00:00
}
2019-11-11 19:27:44 +00:00
2015-06-07 13:23:48 +00:00
if( ( flags1 & PlaceFlagHasMatrix ) != 0 )
2013-03-26 17:07:01 +00:00
{
swfMatrix_t m;
2019-11-11 19:27:44 +00:00
2013-03-26 17:07:01 +00:00
bitstream.ReadMatrix( m );
2019-11-11 19:27:44 +00:00
2015-06-06 23:07:13 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\"startMatrix\": [ %f, %f, %f, %f, %f, %f ]", m.xx, m.yy, m.xy, m.yx, m.tx, m.ty );
2013-03-26 17:07:01 +00:00
}
2019-11-11 19:27:44 +00:00
2015-06-07 13:23:48 +00:00
if( ( flags1 & PlaceFlagHasColorTransform ) != 0 )
2013-03-26 17:07:01 +00:00
{
swfColorXform_t cxf;
bitstream.ReadColorXFormRGBA( cxf );
2019-11-11 19:27:44 +00:00
2013-03-26 17:07:01 +00:00
idVec4 color = cxf.mul;
2015-06-06 23:07:13 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\"mulColor\": [ %f, %f, %f, %f ]", color.x, color.y, color.z, color.w );
2019-11-11 19:27:44 +00:00
2013-03-26 17:07:01 +00:00
color = cxf.add;
2014-05-15 14:58:48 +00:00
if( color != vec4_origin )
{
2015-06-07 23:57:53 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\"addColor\": [ %f, %f, %f, %f ]", color.x, color.y, color.z, color.w );
2014-05-15 14:58:48 +00:00
}
2013-03-26 17:07:01 +00:00
}
2019-11-11 19:27:44 +00:00
2015-06-07 13:23:48 +00:00
if( ( flags1 & PlaceFlagHasRatio ) != 0 )
2013-03-26 17:07:01 +00:00
{
2015-11-22 16:01:43 +00:00
uint16 ratio = bitstream.ReadU16();
file->WriteFloatString( ",\n\t\t\t\t\t\"ratio\": %i", ratio );
2013-03-26 17:07:01 +00:00
}
2019-11-11 19:27:44 +00:00
2015-06-07 13:23:48 +00:00
if( ( flags1 & PlaceFlagHasName ) != 0 )
2013-03-26 17:07:01 +00:00
{
idStr name = bitstream.ReadString();
2019-11-11 19:27:44 +00:00
2015-06-06 23:07:13 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\"name\": \"%s\"", name.c_str() );
2019-11-11 19:27:44 +00:00
2013-03-26 17:07:01 +00:00
/*if( display->spriteInstance )
{
display->spriteInstance->name = name;
scriptObject->Set( name, display->spriteInstance->GetScriptObject() );
}
else if( display->textInstance )
{
scriptObject->Set( name, display->textInstance->GetScriptObject() );
}*/
}
2019-11-11 19:27:44 +00:00
2015-06-07 13:23:48 +00:00
if( ( flags1 & PlaceFlagHasClipDepth ) != 0 )
2013-03-26 17:07:01 +00:00
{
uint16 clipDepth = bitstream.ReadU16();
2015-06-06 23:07:13 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\"clipDepth\": %i", clipDepth );
2013-03-26 17:07:01 +00:00
}
2019-11-11 19:27:44 +00:00
2015-06-07 13:23:48 +00:00
if( ( flags1 & PlaceFlagHasClipActions ) != 0 )
2013-03-26 17:07:01 +00:00
{
// FIXME: clip actions
}
2019-11-11 19:27:44 +00:00
2015-06-06 23:07:13 +00:00
file->WriteFloatString( "\n\t\t\t\t}" );
2013-08-10 11:51:49 +00:00
}
2015-06-06 23:07:13 +00:00
void idSWFSprite::WriteJSON_PlaceObject3( idFile* file, idSWFBitStream& bitstream, int sourceCharacterID, int commandID, const char* indentPrefix )
2013-08-10 11:51:49 +00:00
{
2015-10-11 20:01:02 +00:00
uint8 flags1 = bitstream.ReadU8();
uint8 flags2 = bitstream.ReadU8();
uint16 depth = bitstream.ReadU16();
2019-11-11 19:27:44 +00:00
2015-06-07 13:23:48 +00:00
file->WriteFloatString( "%s\t\t\t\t{\n", ( commandID != 0 ) ? ",\n" : "" );
file->WriteFloatString( "\t\t\t\t\t\"type\": \"Tag_PlaceObject3\",\n" );
file->WriteFloatString( "\t\t\t\t\t\"flags1\": %i, \"flags2\": %i, \"depth\": %i", flags1, flags2, depth );
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
if( ( flags1 & PlaceFlagHasCharacter ) != 0 )
{
2015-06-07 13:23:48 +00:00
int characterID = bitstream.ReadU16();
file->WriteFloatString( ",\n\t\t\t\t\t\"characterID\": %i", characterID );
2013-08-10 11:51:49 +00:00
}
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
if( ( flags1 & PlaceFlagHasMatrix ) != 0 )
{
swfMatrix_t m;
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
bitstream.ReadMatrix( m );
2019-11-11 19:27:44 +00:00
2015-06-07 13:23:48 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\"startMatrix\": [ %f, %f, %f, %f, %f, %f ]", m.xx, m.yy, m.xy, m.yx, m.tx, m.ty );
2013-08-10 11:51:49 +00:00
}
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
if( ( flags1 & PlaceFlagHasColorTransform ) != 0 )
{
swfColorXform_t cxf;
bitstream.ReadColorXFormRGBA( cxf );
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
idVec4 color = cxf.mul;
2015-06-07 13:23:48 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\"mulColor\": [ %f, %f, %f, %f ]", color.x, color.y, color.z, color.w );
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
color = cxf.add;
2014-05-15 14:58:48 +00:00
if( color != vec4_origin )
{
2015-06-07 23:57:53 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\"addColor\": [ %f, %f, %f, %f ]", color.x, color.y, color.z, color.w );
2014-05-15 14:58:48 +00:00
}
2013-08-10 11:51:49 +00:00
}
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
if( ( flags1 & PlaceFlagHasRatio ) != 0 )
{
2015-11-22 16:01:43 +00:00
uint16 ratio = bitstream.ReadU16();
file->WriteFloatString( ",\n\t\t\t\t\t\"ratio\": %i", ratio );
2013-08-10 11:51:49 +00:00
}
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
if( ( flags1 & PlaceFlagHasName ) != 0 )
{
idStr name = bitstream.ReadString();
2019-11-11 19:27:44 +00:00
2015-06-07 13:23:48 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\"name\": \"%s\"", name.c_str() );
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
/*if( display->spriteInstance )
{
display->spriteInstance->name = name;
scriptObject->Set( name, display->spriteInstance->GetScriptObject() );
}
else if( display->textInstance )
{
scriptObject->Set( name, display->textInstance->GetScriptObject() );
}*/
}
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
if( ( flags1 & PlaceFlagHasClipDepth ) != 0 )
{
uint16 clipDepth = bitstream.ReadU16();
2015-06-07 13:23:48 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\"clipDepth\": %i", clipDepth );
2013-08-10 11:51:49 +00:00
}
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
if( ( flags2 & PlaceFlagHasFilterList ) != 0 )
{
// we don't support filters and because the filter list is variable length we
// can't support anything after the filter list either (blend modes and clip actions)
//idLib::Warning( "PlaceObject3: has filters" );
2015-06-07 13:23:48 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\"hasFilterList\": true" );
//return;
2013-08-10 11:51:49 +00:00
}
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
if( ( flags2 & PlaceFlagHasBlendMode ) != 0 )
{
uint8 blendMode = bitstream.ReadU8();
2015-06-07 13:23:48 +00:00
file->WriteFloatString( ",\n\t\t\t\t\t\"blendMode\": %i", blendMode );
2013-08-10 11:51:49 +00:00
}
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
if( ( flags1 & PlaceFlagHasClipActions ) != 0 )
{
// FIXME: clip actions
}
2019-11-11 19:27:44 +00:00
2015-06-07 13:23:48 +00:00
file->WriteFloatString( "\n\t\t\t\t}" );
2013-08-10 11:51:49 +00:00
}
2015-06-06 23:07:13 +00:00
void idSWFSprite::WriteJSON_RemoveObject2( idFile* file, idSWFBitStream& bitstream, int sourceCharacterID, int commandID, const char* indentPrefix )
2013-08-10 11:51:49 +00:00
{
int depth = bitstream.ReadU16();
2019-11-11 19:27:44 +00:00
2015-06-06 23:07:13 +00:00
file->WriteFloatString( "%s\t\t\t\t{\t\"type\": \"Tag_RemoveObject2\", \"depth\": %i }", ( commandID != 0 ) ? ",\n" : "", depth );
2013-08-10 11:51:49 +00:00
}
2015-06-06 23:07:13 +00:00
void idSWFSprite::WriteJSON_DoAction( idFile* file, idSWFBitStream& bitstream, int characterID, int commandID, const char* indentPrefix )
2013-08-10 11:51:49 +00:00
{
#if 1
2013-08-10 11:51:49 +00:00
idBase64 base64;
2019-11-11 19:27:44 +00:00
2013-08-10 11:51:49 +00:00
base64.Encode( bitstream.Ptr(), bitstream.Length() );
2019-11-11 19:27:44 +00:00
#if 1
file->WriteFloatString( "%s\t\t\t\t{\t\"type\": \"Tag_DoAction\", \"streamLength\": %i, \"stream\": \"%s\" }", ( commandID != 0 ) ? ",\n" : "", bitstream.Length(), base64.c_str() );
//file->WriteFloatString( "%s\t\t\t\t{\t\"type\": \"Tag_DoAction\", \"streamLength\": %i, \"stream\": \"FIXME\" }", ( commandID != 0 ) ? ",\n" : "", bitstream.Length() );
2015-10-22 21:46:52 +00:00
#else
idSWFScriptObject* scriptObject = idSWFScriptObject::Alloc();
scriptObject->SetPrototype( &spriteInstanceScriptObjectPrototype );
// scriptObject->SetSprite( this );
2019-11-11 19:27:44 +00:00
idSWFScriptFunction_Script* actionScript = idSWFScriptFunction_Script::Alloc();
2019-11-11 19:27:44 +00:00
idList<idSWFScriptObject*, TAG_SWF> scope;
//scope.Append( swf->globals );
scope.Append( scriptObject );
actionScript->SetScope( scope );
// actionScript->SetDefaultSprite( this );
2019-11-11 19:27:44 +00:00
actionScript->SetData( bitstream.Ptr(), bitstream.Length() );
2015-06-06 14:28:43 +00:00
idStr scriptText = actionScript->CallToScript( scriptObject, idSWFParmList(), file->GetName(), characterID, commandID );
2015-10-22 21:46:52 +00:00
idStr quotedText = idStr::CStyleQuote( scriptText.c_str() );
2019-11-11 19:27:44 +00:00
2015-10-22 21:46:52 +00:00
file->WriteFloatString( "%s\t\t\t\t{\n\t\t\t\t\t\"type\": \"Tag_DoAction\", \"streamLength\": %i, \"stream\": \"%s\",\n\t\t\t\t\t\"luaCode\": %s\n\t\t\t\t}", ( commandID != 0 ) ? ",\n" : "", bitstream.Length(), base64.c_str(), quotedText.c_str() );
2019-11-11 19:27:44 +00:00
//file->WriteFloatString( "%s\t<DoAction streamLength=\"%i\">%s</DoAction>\n", indentPrefix, bitstream.Length(), base64.c_str() );
2019-11-11 19:27:44 +00:00
delete actionScript;
delete scriptObject;
2015-06-06 23:07:13 +00:00
#endif
2019-11-11 19:27:44 +00:00
#endif
2013-03-26 17:07:01 +00:00
}
2013-11-12 17:17:03 +00:00
void idSWFSprite::WriteSWF( idFile_SWF& f, int characterID )
{
2013-11-12 22:05:59 +00:00
// TODO frameLabels
2019-11-11 19:27:44 +00:00
2013-11-12 22:05:59 +00:00
// TODO Tag_ShowFrames
2019-11-11 19:27:44 +00:00
2013-11-12 17:17:03 +00:00
int tagLength = 4;
2019-11-11 19:27:44 +00:00
2013-11-12 17:17:03 +00:00
for( int i = 0; i < doInitActions.Num(); i++ )
{
tagLength += idFile_SWF::GetTagHeaderSize( Tag_DoInitAction, doInitActions[i].Length() );
tagLength += doInitActions[i].Length();
}
2019-11-11 19:27:44 +00:00
2013-11-12 17:17:03 +00:00
for( int i = 0; i < commands.Num(); i++ )
{
idSWFSprite::swfSpriteCommand_t& command = commands[i];
2019-11-11 19:27:44 +00:00
2013-11-12 17:17:03 +00:00
switch( command.tag )
{
case Tag_PlaceObject2:
2013-11-12 22:05:59 +00:00
case Tag_PlaceObject3:
case Tag_RemoveObject2:
case Tag_DoAction:
2013-11-12 17:17:03 +00:00
tagLength += idFile_SWF::GetTagHeaderSize( command.tag, command.stream.Length() );
tagLength += command.stream.Length();
break;
2019-11-11 19:27:44 +00:00
2013-11-12 17:17:03 +00:00
default:
//idLib::Printf( "Export Sprite: Unhandled tag %s\n", idSWF::GetTagName( command.tag ) );
2013-11-12 22:05:59 +00:00
break;
2013-11-12 17:17:03 +00:00
}
}
2019-11-11 19:27:44 +00:00
2013-11-12 17:17:03 +00:00
f.WriteTagHeader( Tag_DefineSprite, tagLength );
2019-11-11 19:27:44 +00:00
2013-11-12 17:17:03 +00:00
f.WriteU16( characterID );
f.WriteU16( frameCount );
2019-11-11 19:27:44 +00:00
2013-11-12 17:17:03 +00:00
/*
for( int i = 0; i < frameLabels.Num(); i++ )
{
f->WriteFloatString( "%s\t<FrameLabel frameNum=\"%i\" frameLabel=\"%s\"/>\n", indentPrefix, frameLabels[i].frameNum, frameLabels[i].frameLabel.c_str() );
}
*/
2019-11-11 19:27:44 +00:00
2013-11-12 17:17:03 +00:00
for( int i = 0; i < doInitActions.Num(); i++ )
{
f.WriteTagHeader( Tag_DoInitAction, doInitActions[i].Length() );
f.Write( doInitActions[i].Ptr(), doInitActions[i].Length() );
}
2019-11-11 19:27:44 +00:00
2013-11-12 17:17:03 +00:00
for( int i = 0; i < commands.Num(); i++ )
{
idSWFSprite::swfSpriteCommand_t& command = commands[i];
2019-11-11 19:27:44 +00:00
2013-11-12 17:17:03 +00:00
command.stream.Rewind();
switch( command.tag )
{
case Tag_PlaceObject2:
2013-11-12 22:05:59 +00:00
case Tag_PlaceObject3:
case Tag_RemoveObject2:
case Tag_DoAction:
2013-11-12 17:17:03 +00:00
f.WriteTagHeader( command.tag, command.stream.Length() );
f.Write( command.stream.Ptr(), command.stream.Length() );
break;
2019-11-11 19:27:44 +00:00
2013-11-12 17:17:03 +00:00
default:
//idLib::Printf( "Export Sprite: Unhandled tag %s\n", idSWF::GetTagName( command.tag ) );
2013-11-12 22:05:59 +00:00
break;
2013-11-12 17:17:03 +00:00
}
2019-11-11 19:27:44 +00:00
2013-11-12 17:17:03 +00:00
}
2019-11-11 19:27:44 +00:00
//f.WriteTagHeader( Tag_End, 0 );
2013-11-12 17:17:03 +00:00
}
2013-03-25 17:52:29 +00:00
// RB end
2015-10-12 11:02:18 +00:00