Flash GUI Component
by Thomas \"Man of Ice\" Lund · 02/04/2005 (6:58 am) · 188 comments
Behold the power of flashy flash
Version history
Version 1.5 - 2005-09-05
- commented out the gameswf::clear() to get rid of exit crash bug
- updated with CVS from 5th of September 2005
- added anti alias switch
Version 1.4 - 2005-04-23
- resizing the component now reinitializes the movie to keep it from going blank
- added gotoFrame method that moves to the numbered frame
- added gotoNamedFrame method that moves to the named frame
- added callMethod method to call functionality inside flash movies
- reorganized files, so its easier to merge gameswf and base files
- Updated GameSWF files with CVS version of GameSWF from 23rd April 2005
Version 1.3 - 2005-03-02
- Fixed bug with mouse press being handled wrongly, resulting in having to double click on buttons
- Updated GameSWF files with CVS version of GameSWF from 2nd March 2005
Version 1.2 - 2005-02-08
- Fix to the command callback. Should work now
- Added stopMovie command
- Added restartMovie command
- Added stubbed out sound support
- Added setting/getting flash variables
- Fixed bug with mouse coordinates when rescaling the gui
Version 1.1 - 2004-02-05
- Little restructuring of file to be more readable
- Implemented mErrorDisplayed variable, so errors are only shown once instead of spamming the console
- Extended the loadMovie() method to take optional looping and alpha values to save some typing
- Implemented sending keyboard input to the flash movie
Version 1.0 - 2004-02-04
- First public release
What is this?
This is a GUI component that allows you to display SWF flash movies. It is based on GameSWF.
GameSWF is a public domain implementation of the SWF format, and can (and has been) used in commercial products without royalty payments. Disclaimer: I am not a lawyer, so check up yourself.
The point of using flash for things like menus, text renderers or movies is, that it has fantastic editor support and every multimedia artist out there knows it. Its very easy to make eye candy for your games - and the text scales with resolution ;-)
It does _not_ support sound. Please use the TGE sound player for that.
It does however have callbacks for action script, so you can hook your flash up to the engine. This is untested though.
It also sends mouse movement and click events to the flash, so that you can trigger buttons and similar inside the flash
Screenshots and movies
The screenshot shows a flash movie with almost 100% transparent background.
A movie showing that buttons and some animation routines work is here
www.codejar.com/tge_flash/flash_demo.wmv
Download
The file is too large for uploading here, so grab the zip containing the code + a few demo flash movies from
www.codejar.com/tge_flash/torque_gameswf.zip
Patching the Engine using STL_fix
GameSWF uses STL. So much, that there was need for an easier solution than recoding it all.
To the rescue is a unreleased (yet) resource from Dean Calver (thanks a lot!!!) that patches the engine to allow usage of STL together with still running the TGE memory manager.
In the zip file there is a stl_fix.h. Please copy this to your engine/core folder and add to the project.
Whenever you have some code that uses STL, include this stl_fix.h (and most likely also platform/platform.h) BEFORE the STL includes, and everything works like a charm.
But there are also changes to the engine to make this work. Please follow the steps outlined below.
Open platform/platform.h
Find this in line 396
Open the file platform/platformMemory.cc
Find this in line 1080
Open platformWin32/winMemory.cc
Find this in line 41
Adding GameSWF and guiFlash to the Engine
Add GameSWF folder and guiFlash.cc (from the zip) to your project somewhere in the engine/ hierachy
Recompile - easy :-)
Please note, that the code is known _not_ to compile in VC6. It is also not tested on Mac or Linux. Please contribute to this resource by getting it to run on those platforms.
How to use
Once added to your GUI, it is very easy to use this resource. The script API is below. In addition there are callback functions in the guiFlash.cc code.
Version history
Version 1.5 - 2005-09-05
- commented out the gameswf::clear() to get rid of exit crash bug
- updated with CVS from 5th of September 2005
- added anti alias switch
Version 1.4 - 2005-04-23
- resizing the component now reinitializes the movie to keep it from going blank
- added gotoFrame method that moves to the numbered frame
- added gotoNamedFrame method that moves to the named frame
- added callMethod method to call functionality inside flash movies
- reorganized files, so its easier to merge gameswf and base files
- Updated GameSWF files with CVS version of GameSWF from 23rd April 2005
Version 1.3 - 2005-03-02
- Fixed bug with mouse press being handled wrongly, resulting in having to double click on buttons
- Updated GameSWF files with CVS version of GameSWF from 2nd March 2005
Version 1.2 - 2005-02-08
- Fix to the command callback. Should work now
- Added stopMovie command
- Added restartMovie command
- Added stubbed out sound support
- Added setting/getting flash variables
- Fixed bug with mouse coordinates when rescaling the gui
Version 1.1 - 2004-02-05
- Little restructuring of file to be more readable
- Implemented mErrorDisplayed variable, so errors are only shown once instead of spamming the console
- Extended the loadMovie() method to take optional looping and alpha values to save some typing
- Implemented sending keyboard input to the flash movie
Version 1.0 - 2004-02-04
- First public release
What is this?
This is a GUI component that allows you to display SWF flash movies. It is based on GameSWF.
GameSWF is a public domain implementation of the SWF format, and can (and has been) used in commercial products without royalty payments. Disclaimer: I am not a lawyer, so check up yourself.
The point of using flash for things like menus, text renderers or movies is, that it has fantastic editor support and every multimedia artist out there knows it. Its very easy to make eye candy for your games - and the text scales with resolution ;-)
It does _not_ support sound. Please use the TGE sound player for that.
It does however have callbacks for action script, so you can hook your flash up to the engine. This is untested though.
It also sends mouse movement and click events to the flash, so that you can trigger buttons and similar inside the flash
Screenshots and movies
The screenshot shows a flash movie with almost 100% transparent background.A movie showing that buttons and some animation routines work is here
www.codejar.com/tge_flash/flash_demo.wmv
Download
The file is too large for uploading here, so grab the zip containing the code + a few demo flash movies from
www.codejar.com/tge_flash/torque_gameswf.zip
Patching the Engine using STL_fix
GameSWF uses STL. So much, that there was need for an easier solution than recoding it all.
To the rescue is a unreleased (yet) resource from Dean Calver (thanks a lot!!!) that patches the engine to allow usage of STL together with still running the TGE memory manager.
In the zip file there is a stl_fix.h. Please copy this to your engine/core folder and add to the project.
Whenever you have some code that uses STL, include this stl_fix.h (and most likely also platform/platform.h) BEFORE the STL includes, and everything works like a charm.
But there are also changes to the engine to make this work. Please follow the steps outlined below.
Open platform/platform.h
Find this in line 396
extern void* FN_CDECL operator new(dsize_t size, const char*, const U32); extern void* FN_CDECL operator new[](dsize_t size, const char*, const U32); extern void FN_CDECL operator delete(void* ptr); extern void FN_CDECL operator delete[](void* ptr); #define new new(__FILE__, __LINE__)and change to this
extern void* FN_CDECL operator new(dsize_t size); extern void* FN_CDECL operator new[](dsize_t size); extern void FN_CDECL operator delete(void* ptr); extern void FN_CDECL operator delete[](void* ptr); extern void dPopMemManFileLine( const char*&, U32& ); extern int dPushMemManFileLine( const char*, const U32 ); #define new dPushMemManFileLine( __FILE__, __LINE__ ) ? 0 : new
Open the file platform/platformMemory.cc
Find this in line 1080
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
// Manage our own memory, add overloaded memory operators and functions
void* FN_CDECL operator new(dsize_t size, const char* fileName, const U32 line)
{
return Memory::alloc(size, false, fileName, line);
}
void* FN_CDECL operator new[](dsize_t size, const char* fileName, const U32 line)
{
return Memory::alloc(size, true, fileName, line);
}
void* FN_CDECL operator new(dsize_t size)
{
return Memory::alloc(size, false, NULL, 0);
}
void* FN_CDECL operator new[](dsize_t size)
{
return Memory::alloc(size, true, NULL, 0);
}and change to this#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
static const int NUM_NEW_STACK_SIZE = 256;
static struct { const char* filename; U32 line; } g_NewStackMemDebug[NUM_NEW_STACK_SIZE];
static int g_CurStack = -1;
int dPushMemManFileLine( const char* filename, U32 line )
{
if(g_CurStack >= NUM_NEW_STACK_SIZE )
return 0;
g_CurStack++;
g_NewStackMemDebug[g_CurStack].filename = filename;
g_NewStackMemDebug[g_CurStack].line = line;
return 0; // needed for the new passthrough trick
}
void dPopMemManFileLine( const char*& filename, U32& line )
{
if( g_CurStack < 0 )
{
filename = 0;
line = 0;
return;
} else
{
filename = g_NewStackMemDebug[g_CurStack].filename;
line = g_NewStackMemDebug[g_CurStack].line;
g_CurStack--;
}
}
// Manage our own memory, add overloaded memory operators and functions
void* FN_CDECL operator new(dsize_t size)
{
const char* fileName = 0;
U32 line;
dPopMemManFileLine( fileName, line );
return Memory::alloc(size, false, fileName, line);
}
void* FN_CDECL operator new[](dsize_t size)
{
const char* fileName = 0;
U32 line;
dPopMemManFileLine( fileName, line );
return Memory::alloc(size, true, fileName, line);
}Open platformWin32/winMemory.cc
Find this in line 41
void* FN_CDECL operator new(dsize_t, void* ptr)
{
return (ptr);
}and change to thisvoid* FN_CDECL operator new(dsize_t, void* ptr)
{
const char* fileName = 0;
U32 line;
dPopMemManFileLine( fileName, line ); // dummy does nothing except keep the stack in order
return (ptr);
}Adding GameSWF and guiFlash to the Engine
Add GameSWF folder and guiFlash.cc (from the zip) to your project somewhere in the engine/ hierachy
Recompile - easy :-)
Please note, that the code is known _not_ to compile in VC6. It is also not tested on Mac or Linux. Please contribute to this resource by getting it to run on those platforms.
How to use
Once added to your GUI, it is very easy to use this resource. The script API is below. In addition there are callback functions in the guiFlash.cc code.
guiFlash.loadMovie("[i]path to flash movie relative to exe file[/i]", [i]optional looping true|false[/i], [i]optional alpha for background[/i]);Loads a flash movie. The path is relative to the exe file. If the flash file loads other movies, the paths they load are also relative to the exe file.guiFlash.playMovie();Plays the currently loaded movie
guiFlash.restartMovie();Restarts the loaded movie
guiFlash.stopMovie();Stops the currently playing movie
guiFlash.setBackgroundAlpha([i]alpha value between 0 and 1[/i]);Sets the background alpha to the specified value
guiFlash.setLooping([i]true|false[/i]);Set the flash movie to loop instead of stop after the last frame is displayed.
guiFlash.setFlashVariable([i]path to variable[/i], [i]new value[/i]);Sets a variable in the flash movie to the specified new value
guiFlash.getFlashVariable([i]path to variable[/i]);Returns the specified variable from the flash movie
#2
02/04/2005 (7:12 am)
Is there any type of performance hit? Judging from what I've seen on websites, Flash could indeed make much better menus than the current gui system. Does this also still retain cross-platform support? Pardon my ignorance, I've never really looked under the hood for flash stuff :)
#3
Is it possible to use it with a commercial project? Any problems with the GameSWF author or Micromedia?
02/04/2005 (7:35 am)
Looks like very handy library with cool functionality.Is it possible to use it with a commercial project? Any problems with the GameSWF author or Micromedia?
#4
So there is no issues with the GameSWF author. I've even mailed him, and he put a link to here from his page.
02/04/2005 (9:18 am)
GameSWF in itself is public domain. From their website "All the code so far in the gameswf project has been donated to the Public Domain. Public Domain means that the author relinquishes all copyright over the work. The work can be reused, modified (and even relicensed and sold) in any way by anyone else without restriction"So there is no issues with the GameSWF author. I've even mailed him, and he put a link to here from his page.
#5
Flashy flash flash flashy flash! Flashity flashy flash!
My only regret is having done work on my GUI's already, and now thinking of trashing them, hehe... ;)
02/04/2005 (2:57 pm)
Flash!!!Flashy flash flash flashy flash! Flashity flashy flash!
My only regret is having done work on my GUI's already, and now thinking of trashing them, hehe... ;)
#6
02/04/2005 (8:28 pm)
Be interesting to see how this runs in-game...
#7
02/04/2005 (8:29 pm)
I got the following from the author Thatcher Ulrich in regards of any legal issues:Quote:
I've been careful to try to avoid any possible legal problems with Macromedia, by not using their specs and not taking patches from anyone using their specs. I.e. as I understand it, gameswf clearly qualifies as a legal clean-room reimplementation of a SWF player. But I have not sought any professional legal opinions on this, and of course for free code I can't offer any warranty or indemnification about it.
Furthermore, anyone can file suit against anyone regardless of legal merits or lack thereoff, so I can't predict what Macromedia or others might do if they feel threatened.
#8
Keyboard input is now send to the flash (untested, as I cannot get the component to get keypresses - if anyone knows why this is, then buzz me) and less console spamming. Errors are only reported once.
Its also reported that multiple guiFlash with different flash movies can run in the same window without any problems.
02/04/2005 (11:08 pm)
Resource has been updated to version 1.1. Only the guiFlash.cc has been changedKeyboard input is now send to the flash (untested, as I cannot get the component to get keypresses - if anyone knows why this is, then buzz me) and less console spamming. Errors are only reported once.
Its also reported that multiple guiFlash with different flash movies can run in the same window without any problems.
#9
Edit : i have found the file spec license from macromedia, although flashswf is based on alex swf reference located @ sourceforge which is totaly free to use just like flashswf
if someone has some law background and is willing to look at this :
http://www.macromedia.com/software/flash/open/licensing/fileformat/license2.html i am sure we would all appreciate it
cheers.
02/04/2005 (11:38 pm)
i wonder who reported all of that ? :)Edit : i have found the file spec license from macromedia, although flashswf is based on alex swf reference located @ sourceforge which is totaly free to use just like flashswf
if someone has some law background and is willing to look at this :
http://www.macromedia.com/software/flash/open/licensing/fileformat/license2.html i am sure we would all appreciate it
cheers.
#10
02/05/2005 (7:26 am)
@Thomas - wonderful resource. How big are the gameswf libraries? Are we talking about adding a couple hundred k to the download size or a meg? Get's the imagination going either way...
#11
With GameSWF and the guiFlash a release build is 2.64 MB (incl some other stuff I got). Build in VC.net. Without its 2.40 MB.
So we talk 0.24 MB extra.
Take into account that the flash files themselves typically are very small compared to what you can cram into them, and also that you got scalable fonts. A clear winner for a lot of things.
@warpy
Thatcher has explicit NOT looked at the Macromedia filespec. And thus that license would not apply to his project, as its only applying to the Macromedia ditributed specifications. Not the SWF format itself.
02/05/2005 (8:26 am)
@ClarkWith GameSWF and the guiFlash a release build is 2.64 MB (incl some other stuff I got). Build in VC.net. Without its 2.40 MB.
So we talk 0.24 MB extra.
Take into account that the flash files themselves typically are very small compared to what you can cram into them, and also that you got scalable fonts. A clear winner for a lot of things.
@warpy
Thatcher has explicit NOT looked at the Macromedia filespec. And thus that license would not apply to his project, as its only applying to the Macromedia ditributed specifications. Not the SWF format itself.
#12
Will mean blinding bling comes to the GUI :))
Here's a question to up the ante..Can your fab code be extended to enable interactive flash in game?
Thinking here about straming flash content...
Aplogies ii this querydemonstrates im not a programmer...
Cheers
02/05/2005 (9:23 pm)
Awsome resourceWill mean blinding bling comes to the GUI :))
Here's a question to up the ante..Can your fab code be extended to enable interactive flash in game?
Thinking here about straming flash content...
Aplogies ii this querydemonstrates im not a programmer...
Cheers
#13
02/06/2005 (12:41 am)
i believe the gui is the same in game as in the menu so the short answer would be yes.
#14
02/06/2005 (4:13 am)
GameSWF has some ActionScript pieces missing, like arrays and the _global namespace. So most games which usually depend on arrays would fail. I don't think it'd be too hard to add support for that stuff, it's on my list of things to look into.
#15
02/06/2005 (4:29 am)
Also missing are GUI elements like textfields and textareas - at least in my simple tests. But one can use TGE gui elements for those things
#16
Craig
02/06/2005 (3:54 pm)
Just following your plugin instructions but cannot locate /platform/platform.cc - could this file you are refering to have a different name (??) I am working from the current standard windows SDK download build.Craig
#17
C:\Torque\SDK\engine\platform\platformMemory.cc
for a default 1.3 download / install
02/06/2005 (4:21 pm)
That should beC:\Torque\SDK\engine\platform\platformMemory.cc
for a default 1.3 download / install
#18
BTW - we are working on sound support and sending parameters to the flash. No ETA
02/06/2005 (7:46 pm)
Ouch - will fix asap. Thanks!BTW - we are working on sound support and sending parameters to the flash. No ETA
#19
It adds a stopMovie(), restartMovie() command, set/get variable support, fixes a few minor bugs and also has initial sound support. Sound doesnt play, but the files are now in place, but with methods as stubs.
For those who dont want to update all their files, the following files are changed or new:
guiFlash.cc
gameswf/gameswf.h
gameswf/gameswf_sound_handler_tge.cc
Enjoy and report bugs :-)
02/08/2005 (3:30 am)
New version added.It adds a stopMovie(), restartMovie() command, set/get variable support, fixes a few minor bugs and also has initial sound support. Sound doesnt play, but the files are now in place, but with methods as stubs.
For those who dont want to update all their files, the following files are changed or new:
guiFlash.cc
gameswf/gameswf.h
gameswf/gameswf_sound_handler_tge.cc
Enjoy and report bugs :-)
#20
02/08/2005 (4:14 am)
Windows only?
Employee Matthew Langley
Torque