SWF export empty .swf

This commit is contained in:
Robert Beckebans 2013-11-06 21:46:35 +01:00
parent b952f3c594
commit 54b2753025
6 changed files with 283 additions and 22 deletions

View file

@ -32,6 +32,9 @@ If you have questions concerning this license or the applicable additional terms
#include "SWF_Enums.h"
#include "SWF_Types.h"
#include "SWF_Bitstream.h"
// RB begin
#include "SWF_File.h"
// RB end
#include "SWF_ScriptVar.h"
#include "SWF_Sprites.h"
#include "SWF_ScriptObject.h"

118
neo/swf/SWF_File.cpp Normal file
View file

@ -0,0 +1,118 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 2013 Robert Beckebans
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 "precompiled.h"
idFile_SWF::~idFile_SWF()
{
if( file != NULL )
{
delete file;
file = NULL;
}
}
//uint idFile_SWF::GetNumBits( int64 value, bool isSigned )
//{
// //return idMath::BitCount(
//}
uint idFile_SWF::GetNumBitsInt( const int value )
{
return idMath::BitCount( value );
}
int idFile_SWF::Write( const void* buffer, int len )
{
return file->Write( buffer, len );
}
void idFile_SWF::WriteByte( byte bits )
{
file->WriteUnsignedChar( bits );
}
void idFile_SWF::WriteUBits( int value, int numBits )
{
for( int bit = 0; bit < numBits; bit++ )
{
int nb = ( int )( ( value >> ( numBits - 1 - bit ) ) & 1 );
NBits += nb * ( 1 << ( 7 - bitPos ) );
bitPos++;
if( bitPos == 8 )
{
WriteByte( NBits );
bitPos = 0;
NBits = 0;
}
}
}
void idFile_SWF::WriteSBits( int value, int numBits )
{
WriteUBits( value, numBits );
}
void idFile_SWF::WriteU16( uint16 value )
{
ByteAlign();
WriteByte( value & 0xFF );
WriteByte( value >> 8 );
}
void idFile_SWF::WriteRect( const swfRect_t& rect )
{
uint64 regCurrentBit = 0;
uint64 regCurrentByte = 0;
int nBits = rect.BitCount();
int tl_x = PIXEL2SWFTWIP( rect.tl.x );
int br_x = PIXEL2SWFTWIP( rect.br.x );
int tl_y = PIXEL2SWFTWIP( rect.tl.y );
int br_y = PIXEL2SWFTWIP( rect.br.y );
WriteUBits( nBits, 5 );
WriteSBits( tl_x, nBits );
WriteSBits( br_x, nBits );
WriteSBits( tl_y, nBits );
WriteSBits( br_y, nBits );
}

92
neo/swf/SWF_File.h Normal file
View file

@ -0,0 +1,92 @@
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2013 Robert Beckebans
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.
===========================================================================
*/
#ifndef __SWF_FILE_H__
#define __SWF_FILE_H__
class idFile_SWF// : public idFile
{
public:
// Constructor that accepts and stores the file pointer.
idFile_SWF( idFile* _file ) : file( _file )
{
bitPos = 0;
NBits = 0;
}
// Destructor that will destroy (close) the file when this wrapper class goes out of scope.
~idFile_SWF();
// Cast to a file pointer.
operator idFile* () const
{
return file;
}
// Member access operator for treating the wrapper as if it were the file, itself.
idFile* operator -> () const
{
return file;
}
void ByteAlign()
{
if( bitPos > 0 )
{
WriteByte( NBits );
}
}
uint GetNumBits( int64 value, bool isSigned );
uint GetNumBitsInt( const int value );
uint GetNumBitsFloat( const int value );
virtual int Write( const void* buffer, int len );
void WriteUBits( int value, int numBits );
void WriteSBits( int value, int numBits );
void WriteU16( uint16 value );
void WriteRect( const swfRect_t& rect );
private:
void WriteByte( byte bits );
idFile* file; // The managed file pointer.
byte bitPos;
byte NBits;
};
#endif // !__SWF_FILE_H__

View file

@ -146,9 +146,9 @@ idSWF::WriteSWF
RB: bring .bswf back to .swf
===================
*/
void idSWF::WriteSWF( const char* fullpath )
void idSWF::WriteSWF( const char* filename )
{
idFileLocal file( fileSystem->OpenFileWrite( filename, "fs_basepath" ) );
idFile_SWF file( fileSystem->OpenFileWrite( filename, "fs_basepath" ) );
if( file == NULL )
{
return;
@ -158,41 +158,35 @@ void idSWF::WriteSWF( const char* fullpath )
header.W = 'W';
header.S = 'S';
header.version = 9;
header.compression == 'F';
header.compression = 'F';
file->Write( &header, sizeof( header ) );
file.Write( &header, sizeof( header ) );
// TODO
/*
swfRect_t frameSize;
bitstream.ReadRect( frameSize );
frameSize.br.x = frameWidth;
frameSize.br.y = frameHeight;
if( !frameSize.tl.Compare( vec2_zero ) )
{
idLib::Warning( "Invalid frameSize top left" );
Mem_Free( fileData );
return false;
}
file.WriteRect( frameSize );
frameWidth = frameSize.br.x;
frameHeight = frameSize.br.y;
frameRate = bitstream.ReadU16();
file.WriteU16( frameRate );
// parse everything
mainsprite->Load( bitstream, true );
//mainsprite->Load( bitstream, true );
// now that all images have been loaded, write out the combined image
idStr atlasFileName = "generated/";
atlasFileName += fullpath;
atlasFileName.SetFileExtension( ".tga" );
//idStr atlasFileName = "generated/";
//atlasFileName += fullpath;
//atlasFileName.SetFileExtension( ".tga" );
WriteSwfImageAtlas( atlasFileName );
//WriteSwfImageAtlas( atlasFileName );
Mem_Free( fileData );
*/
//Mem_Free( fileData );
// add Tag_End
file.WriteU16( Tag_End );
// go back and write filesize into header
uint32 fileSize = file->Length();

View file

@ -35,6 +35,7 @@ If you have questions concerning this license or the applicable additional terms
idCVar swf_loadBinary( "swf_loadBinary", "1", CVAR_INTEGER, "used to set whether to load binary swf from generated" );
// RB begin
idCVar swf_exportSWF( "swf_exportSWF", "1", CVAR_INTEGER, "" );
idCVar swf_exportXML( "swf_exportXML", "1", CVAR_INTEGER, "" );
idCVar swf_exportAtlas( "swf_exportAtlas", "1", CVAR_INTEGER, "" );
// RB end
@ -45,6 +46,40 @@ bool idSWF::isMouseInClientArea = false;
extern idCVar in_useJoystick;
// RB begin
int swfRect_t::BitCount() const
{
int c = 0;
int num = idMath::BitCount( ( int ) tl.x );
if( num > c )
{
c = num;
}
num = idMath::BitCount( ( int ) tl.y );
if( num > c )
{
c = num;
}
num = idMath::BitCount( ( int ) br.x );
if( num > c )
{
c = num;
}
num = idMath::BitCount( ( int ) br.y );
if( num > c )
{
c = num;
}
return c;
}
// RB end
/*
===================
idSWF::idSWF
@ -160,6 +195,15 @@ idSWF::idSWF( const char* filename_, idSoundWorld* soundWorld_ )
WriteXML( xmlFileName );
}
if( swf_exportSWF.GetBool() )
{
idStr swfFileName = "generated/";
swfFileName += filename;
swfFileName.SetFileExtension( ".swf" );
WriteSWF( swfFileName );
}
idStr atlasFileName = binaryFileName;
atlasFileName.SetFileExtension( ".tga" );
atlasMaterial = declManager->FindMaterial( atlasFileName );

View file

@ -3,6 +3,7 @@
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2013 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -41,6 +42,11 @@ ID_INLINE float SWFFIXED8( int fixed )
return fixed * ( 1.0f / 256.0f );
}
ID_INLINE int PIXEL2SWFTWIP( float pixel )
{
return ( int )( pixel * 20 );
}
struct swfHeader_t
{
byte compression;
@ -54,6 +60,10 @@ struct swfRect_t
swfRect_t();
idVec2 tl;
idVec2 br;
// RB begin
int BitCount() const;
// RB end
};
struct swfMatrix_t
{